@wafertools/wafermap 0.30.3 → 0.30.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +2 -2
  3. package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
  4. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  5. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +1 -1
  6. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
  8. package/dist/packages/canvas-adapter/charts/scatter.d.ts +5 -1
  9. package/dist/packages/canvas-adapter/charts/scatter.js +1 -1
  10. package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
  11. package/dist/packages/canvas-adapter/charts/testPassRate.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/trend.js +1 -1
  13. package/dist/packages/canvas-adapter/insightsTab.d.ts +11 -1
  14. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  15. package/dist/packages/canvas-adapter/maplessSummary.js +1 -1
  16. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  17. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  18. package/dist/packages/canvas-adapter/summaryPanel.js +3 -3
  19. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  20. package/dist/packages/canvas-adapter/toolbar.js +1 -1
  21. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  22. package/dist/packages/canvas-adapter/userGuideHtml.js +38 -36
  23. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  24. package/dist/packages/canvas-adapter/version.js +1 -1
  25. package/dist/packages/canvas-adapter/warnings.js +1 -1
  26. package/dist/packages/core/dies.d.ts +1 -1
  27. package/dist/packages/renderer/binColors.js +1 -1
  28. package/dist/packages/renderer/buildView.js +1 -1
  29. package/dist/packages/renderer/buildWaferMap.d.ts +40 -12
  30. package/dist/packages/renderer/buildWaferMap.js +1 -1
  31. package/dist/packages/renderer/derivedTests/apply.js +1 -1
  32. package/dist/packages/renderer/derivedTests/parser.js +1 -1
  33. package/dist/packages/renderer/spec.d.ts +17 -0
  34. package/dist/packages/renderer/spec.js +1 -1
  35. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  36. package/dist/packages/stats/capability.d.ts +4 -2
  37. package/dist/packages/stats/capability.js +1 -1
  38. package/dist/packages/stats/correlation.d.ts +1 -1
  39. package/dist/packages/stats/deprecated.d.ts +1 -1
  40. package/dist/packages/stats/deprecated.js +1 -1
  41. package/dist/packages/stats/mergeTestDefs.d.ts +1 -1
  42. package/dist/packages/stats/mergeTestDefs.js +1 -1
  43. package/dist/packages/stats/renderSummaryReport.js +11 -11
  44. package/dist/packages/stats/sweep.d.ts +8 -0
  45. package/dist/packages/stats/sweep.js +1 -1
  46. package/dist/packages/stats/types.d.ts +9 -3
  47. package/package.json +1 -1
@@ -1,3 +1,3 @@
1
- import{waferDisplayLabel as ve}from"../core/waferLabel.js";import{itemPassBins as Se,passBinsLabel as lt}from"../core/passBins.js";import{isParametricTest as dt}from"../renderer/buildWaferMap.js";import{testLabel as ct,markedTestLabel as pt,unmarkedLabel as ut,derivedFields as we,derivedKeyText as ft,derivedCsvCell as Ne,isDerivedTest as Te,DERIVED_CSV_HEADER as De}from"../renderer/testLabel.js";import{buildRingRegions as mt,buildQuadrantRegions as gt,buildRegionYieldData as ht}from"../stats/regions.js";import{computeFunctionalYield as bt}from"../stats/analyzeWaferMap.js";import{renderWaferReportHtml as xt,renderLotReportHtml as yt}from"../stats/renderSummaryReport.js";import{buildFindingsNarrative as Ct}from"../stats/findingsNarrative.js";import{formatFindingTooltip as vt}from"../stats/reportHtml.js";import{filterFindings as St}from"../stats/filterFindings.js";import{buildFacetTable as wt,prettyKey as Ee}from"../stats/facets.js";import{commonMetadata as Fe}from"../stats/facets.js";import{resolveMetadataColumns as $t}from"../stats/metadataColumns.js";import{resolveBinColors as Re,resolveBinColorsByWafer as kt}from"../renderer/binColors.js";import{NO_DATA_FILL as Lt}from"../renderer/colorMap.js";import{describeWaferPopulation as Me,populationLabel as Bt}from"../stats/population.js";import{buildWarningsBanner as $e,collectWarnings as Ie}from"./warnings.js";export{$e as buildWarningsBanner};import{fmt as Ae,fmtAggregationMethod as Nt,plainBinTerms as de}from"../renderer/fmt.js";import{getUniqueTestNumbers as Tt}from"../renderer/buildView.js";import{describeSorted as Dt,quantile as We}from"../stats/math.js";import{pooledTestStatsSteps as Et}from"../stats/capability.js";import{sortBinsForDisplay as Ft}from"../stats/binPareto.js";import{poolFunctionalYield as Rt}from"../stats/testPassRate.js";import{makeLabeledSelect as Pe,makeSegmented as ke}from"./charts/chartShell.js";import{SHADOW as ze,MOTION as He,LEADING as ne,TRACKING as fe,wireControlHover as G,controlStyle as me,SPACE as x,RADIUS as q,FONT as T,CLR as $,sevColor as ge,openModal as Oe,openReportModal as Ye,saveTextFile as _e,wireTooltip as ce}from"./toolbar.js";import{buildDieListSection as Mt}from"./dieList.js";export{csvField}from"../core/utils.js";import{csvField as he,drain as be,maxOf as It,medianOfSorted as At,minOf as Wt}from"../core/utils.js";import{metadataDisplayValue as Pt}from"../core/metadata.js";const zt=$.panelBg,je=`1px solid ${$.menuBorder}`,Ht="12px",Y=$.label,ie=$.value,Ke="10px";function l(e,t,i,n=document){const o=n.createElement(e);return t&&Object.assign(o.style,t),i!==void 0&&(o.textContent=i),o}function se(e){return l("div",{fontSize:Ke,fontWeight:"700",letterSpacing:fe,textTransform:"uppercase",color:Y,marginBottom:x.sm},e)}const Ve=new WeakMap,qe=["regionYield","testValues","functionalTests"];function xe(e){if(!e)return{collapsed:new Set(qe),regionMode:"ring",waferSort:"slot"};let t=Ve.get(e);return t||(t={collapsed:new Set(qe),regionMode:"ring",waferSort:"slot"},Ve.set(e,t)),t}function oe(e,t=!0,i,n){const o=l("div"),u=xe(n?.panel);n?.stateKey&&n.panel&&(t=!u.collapsed.has(n.stateKey));const s=document.createElement("button");s.type="button",Object.assign(s.style,{display:"flex",alignItems:"center",gap:x.xs,width:"100%",background:"none",border:"none",cursor:"pointer",padding:"0 0 6px",textAlign:"left"});const m=l("span",{fontSize:T.meta,color:Y,transition:`transform ${He.base}`,transform:t?"rotate(90deg)":"rotate(0deg)",display:"inline-block",lineHeight:ne.none,marginRight:"1px"},"\u25B6"),p=l("span",{fontSize:Ke,fontWeight:"700",letterSpacing:fe,textTransform:"uppercase",color:Y,flex:"1"},e);if(G(s,"bare"),s.setAttribute("aria-expanded",t?"true":"false"),s.appendChild(m),s.appendChild(p),i){const b=l("span",{fontSize:T.meta,fontWeight:"700",background:$.warnBg,color:$.warnText,borderRadius:q.pill,padding:"1px 5px"},i);s.appendChild(b)}const r=l("div");r.style.display=t?"block":"none";let a=t;if(s.addEventListener("click",()=>{a=!a,r.style.display=a?"block":"none",m.style.transform=a?"rotate(90deg)":"rotate(0deg)",s.setAttribute("aria-expanded",a?"true":"false"),n?.stateKey&&n.panel&&(a?u.collapsed.delete(n.stateKey):u.collapsed.add(n.stateKey))}),n?.control){const b=l("div",{display:"flex",alignItems:"center",gap:x.sm});s.style.width="auto",s.style.flex="1",b.appendChild(s);const f=()=>{r.innerHTML="",n.render?.(r)},w=n.control(f);w&&(w.style.marginBottom="6px",w.addEventListener("click",k=>k.stopPropagation()),b.appendChild(w)),o.appendChild(b)}else o.appendChild(s);return o.appendChild(r),n?.render?.(r),{outer:o,content:r}}function Ge(){return l("div",{height:"1px",background:$.separator,margin:`${Ht} 0`,flexShrink:"0"})}function Le(e,t,i=$.barFill,n,o){const u=l("div",{marginBottom:"5px"}),s=l("div",{display:"flex",justifyContent:"space-between",fontSize:T.body,color:ie,marginBottom:x.xxs}),m=l("span",{color:Y},e),p=l("span",{fontWeight:"600"},`${t.toFixed(1)}%`);s.appendChild(m),s.appendChild(p);const r=n!==void 0?n:Math.min(100,Math.max(0,t)),a=i,b=l("div",{position:"relative",height:"9px",background:$.bgActive,borderRadius:q.control,overflow:"hidden"}),f=l("div",{height:"100%",width:`${r}%`,background:a,borderRadius:q.control,transition:`width ${He.base}`});if(b.appendChild(f),o!==void 0){const w=l("div",{position:"absolute",top:"0",bottom:"0",left:`${o}%`,width:"2px",marginLeft:"-1px",background:$.value,opacity:"0.8"});b.appendChild(w)}return u.appendChild(s),u.appendChild(b),u}function Ue(){const e=l("div",{display:"flex",gap:x.sm,marginBottom:x.md});return e.finish=()=>{const t=e.lastElementChild;t&&Object.assign(t.style,{borderRight:"none",paddingRight:"0"})},e}function pe(e,t,i){const n=l("div",{padding:`${x.xxs} ${x.md} ${x.xxs} 0`,borderRight:je,textAlign:"center",flex:"1"}),o=l("div",{fontSize:T.heading,fontWeight:"700",color:ie,lineHeight:ne.tight},e),u=l("div",{fontSize:T.body,color:Y,marginTop:x.xxs},t);return n.appendChild(o),n.appendChild(u),i&&n.appendChild(l("div",{fontSize:T.body,color:Y,opacity:"0.85"},i)),n}function Qe(e,t){const i=l("div",{display:"flex",justifyContent:"space-between",fontSize:T.body,gap:x.md,marginBottom:"3px"}),n=l("span",{color:Y,flexShrink:"0"},e),o=l("span",{color:ie,textAlign:"right",fontWeight:"500",wordBreak:"break-all"},t);return i.appendChild(n),i.appendChild(o),i}function Ot(e,t){const i=l("div",{display:"flex",fontSize:T.body,gap:x.sm,marginBottom:"3px"}),n=l("span",{color:Y,flexShrink:"0"},`${e}:`),o=l("span",{color:ie,fontWeight:"500",wordBreak:"break-all"},t);return i.appendChild(n),i.appendChild(o),i}export function metadataEntries(e){const t=[];for(const[i,n]of Object.entries(e)){const o=Pt(n);o!==void 0&&t.push([i,o])}return t}const Yt=["lot","product","testprogram","split"],ye=e=>{const t=Yt.indexOf(e.toLowerCase().replace(/[^a-z]/g,""));return t===-1?Number.MAX_SAFE_INTEGER:t};export function buildFacetSummaryChips(e,t=3){if(!e.length)return null;const i=l("div",{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:`${x.xs} ${x.lg}`}),n=[...e].sort((m,p)=>ye(m.key)-ye(p.key)),o=n.filter(m=>ye(m.key)!==Number.MAX_SAFE_INTEGER),u=n.filter(m=>ye(m.key)===Number.MAX_SAFE_INTEGER),s=m=>{const p=l("span",{whiteSpace:"nowrap"}),r=l("span",{color:Y},`${Ee(m.key)}: `);p.appendChild(r);const a=m.values.slice(0,t),b=m.values.length-a.length;let f=a.map(w=>w.value).join(", ");return b>0&&(f+=` +${b} more`),p.appendChild(document.createTextNode(f)),p};for(const m of o)i.appendChild(s(m));if(u.length){const m=l("span",{display:"none",flexWrap:"wrap",alignItems:"baseline",gap:`${x.xs} ${x.lg}`});for(const a of u)m.appendChild(s(a));const p=l("button",{background:"none",border:"none",padding:"0",cursor:"pointer",color:$.iconActive,fontSize:T.body,whiteSpace:"nowrap"});p.type="button",G(p,"bare");const r=a=>{m.style.display=a?"contents":"none",p.textContent=a?"less":`+${u.length} more`,p.setAttribute("aria-expanded",String(a))};r(!1),p.addEventListener("click",()=>r(p.getAttribute("aria-expanded")!=="true")),i.appendChild(m),i.appendChild(p)}return i}export function buildMetadataStripRow(e,t,i){const n=wt(e,i),o=buildFacetSummaryChips(n);if(!o&&!t)return null;const u=l("div",{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"4px 14px"});if(t){const s=l("span",{fontWeight:"500",whiteSpace:"nowrap"},t.aggrMethod?`${t.lotSize} wafers stacked \xB7 ${t.aggrMethod}`:`${t.lotSize} wafers stacked`);u.appendChild(s)}return o&&u.appendChild(o),u}const _t={display:"flex",flexDirection:"column",gap:x.sm,background:$.menuBg,border:`1px solid ${$.menuBorder}`,borderRadius:q.container,padding:`${x.sm} ${x.lg}`,boxShadow:ze.panel,fontSize:T.body,lineHeight:ne.none,boxSizing:"border-box",width:"100%",minWidth:"0"};export function buildMetadataStripBox(e,t,i){const n=buildMetadataStripRow(e,t,i);if(!n)return null;const o=l("div",_t);return o.appendChild(n),o}export function buildCompactMetadataRows(e){const t=metadataEntries(e);if(!t.length)return null;const i=l("div");for(const[n,o]of t)i.appendChild(Ot(Ee(n),o));return i}export function buildMetadataInfoSection(e,t){const i=buildMetadataStripRow(e,t,{facetableOnly:e.length>1});if(!i)return null;const n=l("div");return n.appendChild(se("Wafer Info")),n.appendChild(i),n}export function buildYieldSection(e,t,i=[1]){const n=l("div");n.appendChild(se("Summary"));const o=Ue();if(o.appendChild(pe(String(e.totalDies),"Total dies")),e.partialDies>0&&o.appendChild(pe(String(e.partialDies),"Partial")),e.yieldPercent!==null){const u=lt([i]);o.appendChild(pe(`${e.yieldPercent.toFixed(1)}%`,"Yield",`pass: ${u}`))}return o.finish(),n.appendChild(o),e.edgeExcludedDies>0&&n.appendChild(Qe("Edge excluded (outer zone)",String(e.edgeExcludedDies))),n}export function buildBinSection(e,t,i,n,o,u){const s=new Map;if(o)for(const[r,a]of Object.entries(o))s.set(Number(r),a);else for(const r of e){if(r.partial||r.edgeExcluded)continue;const a=i==="hard"?r.hbin:r.sbin;a!=null&&s.set(a,(s.get(a)??0)+1)}if(!s.size)return null;const m=n??Re(e,{passBins:u,...i==="hard"?{hbinDefs:t}:{sbinDefs:t}}),p=l("div");p.appendChild(se(Xe(i,[...s.values()].reduce((r,a)=>r+a,0))));for(const r of Ze(s,t,m[i],m.pass[i]))p.appendChild(r);return p}function Xe(e,t){return`${e==="hard"?"Hard":"Soft"} Bin Breakdown \u2014 % of dies (N=${t})`}function Ze(e,t,i,n){const o=[...e.values()].reduce((m,p)=>m+p,0),u=t?new Map(t.map(m=>[m.bin,m])):null;return Ft(e.entries(),n).map(([m,p])=>{const r=u?.get(m),a=r?.name?`Bin ${m} \xB7 ${r.name}`:`Bin ${m}`,b=p/o*100,f=i.get(m)??Lt;return Le(`${a} (${p})`,b,f)})}export function buildBinBreakdownSection(e){const{dies:t,hbinDefs:i,sbinDefs:n,hardCounts:o,softCounts:u,plotMode:s,passBins:m=[1],panel:p}=e,r=e.binColors??Re(t,{passBins:m,hbinDefs:i,sbinDefs:n}),a=v=>{const g=v==="hard"?o:u,h=new Map;if(g){for(const[y,S]of Object.entries(g))h.set(Number(y),S);return h}for(const y of t){if(y.partial||y.edgeExcluded)continue;const S=v==="hard"?y.hbin:y.sbin;S!=null&&h.set(S,(h.get(S)??0)+1)}return h},b=a("hard"),f=a("soft"),w=b.size>0,k=f.size>0;if(!w&&!k)return null;const F=xe(p),H=s==="softBin"||s==="stackedSoftBins"?"soft":s==="hardBin"||s==="stackedBins"?"hard":void 0;let I=F.binMode??H??(w?"hard":"soft");I==="hard"&&!w&&(I="soft"),I==="soft"&&!k&&(I="hard");const O=I==="hard"?b:f,z=I==="hard"?i:n,C=[...O.values()].reduce((v,g)=>v+g,0),{outer:d}=oe(Xe(I,C),!0,void 0,{stateKey:"bins",panel:p,render:v=>{const g=I==="hard"?r.hard:r.soft;for(const h of Ze(O,z,g,r.pass[I]))v.appendChild(h)},control:w&&k&&p?()=>ke([["hard","Hard"],["soft","Soft"]],I,v=>{F.binMode=v;const g=buildBinBreakdownSection(e);g&&d.replaceWith(g)},p.ownerDocument,!0):void 0});return d}export function buildLotBinSection(e,t,i,n){return buildBinSection(e,t,i,n)}export function buildRegionYieldPanelSection(e){const{diesByWafer:t,allWafers:i,ringCount:n,passBins:o,panel:u}=e,s=xe(u),m=a=>ht(t,i,n,o,a==="ring"?mt:gt);if(!m("ring").length&&!m("quadrant").length)return null;const p=s.regionMode,{outer:r}=oe(p==="ring"?"Ring Yield":"Quadrant Yield",!0,void 0,{stateKey:"regionYield",panel:u,render:a=>{const b=m(p);if(!b.length){a.appendChild(l("div",{fontSize:T.body,color:Y},"No positioned dies for this breakdown."));return}for(const{label:f,n:w,yieldPercent:k}of b)a.appendChild(Le(`${f} (N=${w})`,k))},control:u?()=>ke([["ring","Ring"],["quadrant","Quadrant"]],p,a=>{s.regionMode=a;const b=buildRegionYieldPanelSection(e);b&&r.replaceWith(b)},u.ownerDocument,!0):void 0});return r}export function buildLotOverviewSection(e,t=[]){const i=l("div"),n=Me(e.perWafer.map(s=>s.summary.wafer));i.appendChild(se(n.lotId!==void 0?"Lot Summary":"Summary"));const o=Ue();o.appendChild(pe(String(e.stats.waferCount),"Wafers"));const u=e.perWafer.map(s=>s.summary.stats.yieldPercent).filter(s=>s!==null);if(u.length){const s=u.reduce((m,p)=>m+p,0)/u.length;o.appendChild(pe(`${s.toFixed(1)}%`,"Mean per-wafer yield"))}if(o.finish(),i.appendChild(o),t.length){const s=t.reduce((p,r)=>p+r.stats.analyzedDies,0),m=t.reduce((p,r)=>p+r.stats.excludedDies,0);(s||m)&&i.appendChild(Qe("Dies analysed",m?`${s.toLocaleString()} (${m.toLocaleString()} excluded)`:s.toLocaleString()))}return i}export function buildPerWaferYieldSection(e,t,i,n,o){const u=e.perWafer.map(C=>({waferIndex:C.waferIndex,label:ve(t[C.waferIndex],C.waferIndex).replace(/\s*·\s*\d+(\.\d+)?%$/,""),yieldPct:C.summary.stats.yieldPercent})).filter(C=>C.yieldPct!==null);if(!u.length)return null;const s=Wt(u.map(C=>C.yieldPct)),m=It(u.map(C=>C.yieldPct)),p=s===m?"":` (${s.toFixed(1)}\u2013${m.toFixed(1)}%)`,r=[...u.map(C=>C.yieldPct)].sort((C,d)=>C-d),a=At(r),b=We(r,.25),f=We(r,.75),w=u.length>=5?b-1.5*(f-b):-1/0,k=xe(n),F=C=>{const d=k.waferSort==="yield"?[...u].sort((v,g)=>v.yieldPct-g.yieldPct):u;for(const{waferIndex:v,label:g,yieldPct:h}of d){const S=h<w?`${g} \xB7 low outlier`:g,L=Le(S,h,void 0,void 0,a),A=o?.(v);A?.total&&O(L,A),z(L,v,g,h,A),C.appendChild(L)}},H=` \xB7 median ${a.toFixed(1)}%`,{outer:I}=oe("Wafer Yield"+p+H,!0,void 0,{stateKey:"waferYield",panel:n,render:F,control:n?C=>ke([["slot","Slot"],["yield","Yield"]],k.waferSort,d=>{k.waferSort=d,C()},n.ownerDocument,!0):void 0});return I;function O(C,d){const v=d.unusual?"unusual":d.notable?"notable":"info",g=l("span",{marginLeft:x.sm,flexShrink:"0",background:ge(v),color:"#fff",borderRadius:q.container,padding:"0 5px",fontSize:T.body,fontWeight:"600"},`${d.total}`);g.setAttribute("aria-hidden","true"),ce(g,`${d.total} finding${d.total===1?"":"s"}`+(d.unusual?`, ${d.unusual} unusual`:"")+(d.notable?`, ${d.notable} notable`:"")),C.firstElementChild?.firstElementChild?.appendChild(g)}function z(C,d,v,g,h){i&&(C.style.cursor="pointer",C.style.borderRadius="4px",C.style.padding="2px 3px",C.style.marginLeft="-3px",C.style.marginRight="-3px",C.setAttribute("role","button"),C.setAttribute("aria-label",`${v}, ${g.toFixed(1)}% yield`+(h?.total?`, ${h.total} finding${h.total===1?"":"s"}${h.unusual?`, ${h.unusual} unusual`:""}`:"")+" \u2014 open wafer"),C.tabIndex=0,C.addEventListener("mouseenter",()=>{C.style.background=$.bgHover}),C.addEventListener("mouseleave",()=>{C.style.background=""}),C.addEventListener("focus",()=>{C.style.background=$.bgHover}),C.addEventListener("blur",()=>{C.style.background=""}),C.addEventListener("click",()=>i(d)),C.addEventListener("keydown",y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),i(d))}))}}function jt(e){return Dt([...e].sort((t,i)=>t-i))}function Je(e,t){if(!e)return[];const i=e.waferMetadata??(e.perWaferMetadata?Fe(e.perWaferMetadata.map(n=>({metadata:n}))):void 0);return!i||!Object.keys(i).length?[]:$t({waferMetadata:i,waferKeys:"identity",waferPlacement:"csv",reservedLabels:t}).columns}function et(e){return e?.populationLabel?[{key:"population",label:"Population",scope:"wafer",constant:e.populationLabel,get:()=>e.populationLabel,csvOnly:!0}]:[]}export function buildTestSection(...e){return be(buildTestSectionSteps(...e))}export function*buildTestSectionSteps(e,t,i,n,o,u,s,m,p="full"){const r=e.filter(c=>!c.partial&&!c.edgeExcluded),a=new Map((n?.perTestStats??[]).map(c=>[c.testNumber,c])),b=new Map((n?.testSpecYield??[]).map(c=>[c.testNumber,c]));let f;if(t?.length?f=t.filter(dt).map(c=>({testNumber:c.testNumber,name:c.name,unit:c.unit,limitLow:c.limitLow,limitHigh:c.limitHigh,...we(c)})):f=Tt(r).map(W=>({testNumber:W,name:ct(void 0,W)})),!f.length)return null;const w=f.filter(c=>r.some(W=>{const j=W.testValues?.[c.testNumber];return j!==void 0&&isFinite(j)}));if(!w.length)return null;const k=w.some(c=>c.limitLow!==void 0||c.limitHigh!==void 0),F=[],H=c=>!!c&&c.stddev!==void 0&&c.median!==void 0&&c.q1!==void 0&&c.q3!==void 0,I=c=>c.limitLow!==void 0||c.limitHigh!==void 0,O=!!(s?.length&&t?.length),C=(O||w.some(c=>!H(a.get(c.testNumber))||I(c)&&!b.has(c.testNumber)))&&t?.length?yield*Et(s??[{dies:e}],t):void 0;for(const c of w){yield;const W=a.get(c.testNumber),j=C?.specTally.get(c.testNumber),ee=C?.stats.get(c.testNumber),K=()=>r.map(E=>E.testValues?.[c.testNumber]).filter(E=>E!==void 0&&isFinite(E));let Q;if(H(W)){const E=W;Q={testNumber:c.testNumber,min:E.min,max:E.max,mean:E.mean,count:E.count,stddev:E.stddev,median:E.median,q1:E.q1,q3:E.q3}}else if(ee)Q={testNumber:c.testNumber,...ee};else{const E=K();if(!E.length)continue;Q={testNumber:c.testNumber,...jt(E)}}let M=null,B=0;if(I(c)){const E=b.get(c.testNumber);if(E)({yieldPercent:M,totalDies:B}=E);else if(j)B=j.n,M=B>0?(B-j.fail)/B*100:null;else{const X=K();let ue=0;for(const te of X)(c.limitLow!==void 0&&te<c.limitLow||c.limitHigh!==void 0&&te>c.limitHigh)&&ue++;B=X.length,M=X.length>0?(X.length-ue)/X.length*100:null}}F.push({entry:c,stats:Q,specYieldPct:M,specN:B})}if(!F.length)return null;const d=new Map;for(const c of(O?C?.capability:void 0)??[])c.hasSpec&&d.set(c.testNumber,c.ppk);const v=d.size>0,h=new Set(F.map(c=>c.stats.count)).size===1?F[0].stats.count:null,y=l("div"),S=l("div",{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:x.sm}),L=h!==null?` \xB7 N=${h.toLocaleString()}`:"",A=u?.populationLabel?`Test Values (${F.length}) \u2014 ${u.populationLabel}${L}`:`Test Values (${F.length})${L}`,D=se(A);D.style.marginBottom="0",S.appendChild(D);const R=document.createElement("button");R.type="button",R.textContent="Test values CSV",Object.assign(R.style,{...me("outlined")}),G(R),R.addEventListener("click",()=>{const c=["Test","Unit","N","Min","Q1","Median","Mean","Q3","Max","StdDev"];v&&c.push("Ppk");const W=F.some(B=>B.specYieldPct!==null&&B.specN!==B.stats.count);k&&(c.push("LSL","USL","Spec Yield %"),W&&c.push("Spec Yield N"));const j=F.some(B=>Te(B.entry));j&&c.push(De);const ee=[...Je(u,c),...et(u)],Q=[[...ee.map(B=>B.label),...c].map(he).join(",")],M=B=>Ae(B,void 0,"engineering");for(const{entry:B,stats:E,specYieldPct:X,specN:ue}of F){const te=[...ee.map(le=>le.constant??""),B.name,B.unit??"",String(E.count),M(E.min),M(E.q1),M(E.median),M(E.mean),M(E.q3),M(E.max),M(E.stddev)];if(v){const le=d.get(B.testNumber);te.push(le==null?"":le.toFixed(3))}k&&(te.push(B.limitLow!==void 0?M(B.limitLow):"",B.limitHigh!==void 0?M(B.limitHigh):"",X!==null?X.toFixed(1):""),W&&te.push(B.limitLow!==void 0||B.limitHigh!==void 0?String(ue):"")),j&&te.push(Ne(B)),Q.push(te.map(he).join(","))}_e(Q.join(`
2
- `),"test-values.csv","text/csv",o)}),S.appendChild(R),y.appendChild(S);const P=l("table",{width:"100%",borderCollapse:"collapse",fontSize:T.body}),Z=document.createElement("thead"),J=document.createElement("tr"),_=["Test"];h===null&&_.push("N"),p==="full"&&_.push("Min","Q1","Median"),_.push("Mean"),p==="full"&&_.push("Q3","Max","StdDev"),v&&_.push("Ppk"),p==="full"&&k&&_.push("LSL","USL"),k&&_.push("Spec yield");for(const c of _){const W=l("th",{textAlign:c==="Test"?"left":"right",fontWeight:"600",fontSize:T.meta,letterSpacing:fe,textTransform:"uppercase",color:Y,padding:"3px 8px 5px",borderBottom:`1px solid ${$.menuBorder}`,whiteSpace:"nowrap"},c);J.appendChild(W)}Z.appendChild(J),P.appendChild(Z);const U=document.createElement("tbody");for(const{entry:c,stats:W,specYieldPct:j,specN:ee}of F){const K=B=>Ae(B,c.unit,i),Q=document.createElement("tr"),M=(B,E="right")=>{const X=l("td",{textAlign:E,padding:`${x.xs} ${x.md}`,borderBottom:`1px solid ${$.menuBorder}`,color:$.text,whiteSpace:"nowrap"},B);Q.appendChild(X)};if(M(pt(c,c.testNumber),"left"),h===null&&M(`${W.count}`),p==="full"&&(M(K(W.min)),M(K(W.q1)),M(K(W.median))),M(K(W.mean)),p==="full"&&(M(K(W.q3)),M(K(W.max)),M(K(W.stddev))),v){const B=d.get(c.testNumber);M(B==null?"\u2014":B.toFixed(2))}p==="full"&&k&&(M(c.limitLow!==void 0?K(c.limitLow):"\u2014"),M(c.limitHigh!==void 0?K(c.limitHigh):"\u2014")),k&&M(j!==null?h!==null&&ee===h?`${j.toFixed(1)}%`:`${j.toFixed(1)}% (N=${ee})`:"\u2014"),U.appendChild(Q)}P.appendChild(U);const N=l("div",{overflowX:"auto"});N.appendChild(P);const V=ot(N,F.map(c=>({label:c.entry.name,...we(c.entry)})));if(!m)return y.appendChild(V),y;S.remove();const{outer:re}=oe(A,!0,void 0,{stateKey:"testValues",panel:m,render:c=>c.appendChild(V),control:()=>R});return re}export function buildFunctionalTestSection(e,t,i,n,o,u){const s=i??bt(e,t);if(!s?.length)return null;const p=new Set(s.map(g=>g.totalDies)).size===1?s[0].totalDies:null,r=p!==null?` \xB7 N=${p.toLocaleString()}`:"",a=l("div"),b=l("div",{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:x.sm}),f=o?.populationLabel?`Functional Tests (${s.length}) \u2014 ${o.populationLabel}${r}`:`Functional Tests (${s.length})${r}`,w=se(f);w.style.marginBottom="0",b.appendChild(w);const k=document.createElement("button");k.type="button",k.textContent="Functional CSV",Object.assign(k.style,{...me("outlined")}),G(k),k.addEventListener("click",()=>{const g=["Test","N","Pass","Fail","Pass Rate %"],h=s.some(L=>Te(L));h&&g.push(De);const y=[...Je(o,g),...et(o)],S=[[...y.map(L=>L.label),...g].map(he).join(",")];for(const L of s)S.push([...y.map(A=>A.constant??""),ut(L.label),String(L.totalDies),String(L.passDies),String(L.failDies),L.passRatePercent!==null?L.passRatePercent.toFixed(1):"",...h?[Ne(L)]:[]].map(he).join(","));_e(S.join(`
3
- `),"functional-tests.csv","text/csv",n)}),b.appendChild(k),a.appendChild(b);const F=l("table",{width:"100%",borderCollapse:"collapse",fontSize:T.body}),H=document.createElement("thead"),I=document.createElement("tr"),O=p===null?["Test","N","Pass","Fail","Pass rate"]:["Test","Pass","Fail","Pass rate"];for(const g of O)I.appendChild(l("th",{textAlign:g==="Test"?"left":"right",fontWeight:"700",fontSize:T.body,letterSpacing:fe,textTransform:"uppercase",color:Y,padding:"3px 8px 5px",borderBottom:`1px solid ${$.menuBorder}`,whiteSpace:"nowrap"},g));H.appendChild(I),F.appendChild(H);const z=document.createElement("tbody");for(const g of s){const h=document.createElement("tr"),y=(S,L="right")=>{h.appendChild(l("td",{textAlign:L,padding:`${x.xs} ${x.md}`,borderBottom:`1px solid ${$.menuBorder}`,color:ie,whiteSpace:"nowrap"},S))};y(g.label,"left"),p===null&&y(String(g.totalDies)),y(String(g.passDies)),y(String(g.failDies)),y(g.passRatePercent!==null?`${g.passRatePercent.toFixed(1)}%`:"\u2014"),z.appendChild(h)}F.appendChild(z);const C=l("div",{overflowX:"auto"});C.appendChild(F);const d=ot(C,s);if(!u)return a.appendChild(d),a;b.remove();const{outer:v}=oe(f,!0,void 0,{stateKey:"functionalTests",panel:u,render:g=>g.appendChild(d),control:()=>k});return v}export function buildLotFunctionalSection(e,t,i,n,o){const u=i?.length?{perWaferMetadata:i.map(m=>m.wafer??{}),populationLabel:`${i.length} wafer${i.length===1?"":"s"} pooled`}:void 0,s=Rt(i);return s?buildFunctionalTestSection(e,t,s,n,u,o):buildFunctionalTestSection(e,t,void 0,n,u,o)}const ae={unusual:0,notable:1,info:2};function Be(e){return l("span",{display:"inline-block",width:"7px",height:"7px",borderRadius:q.pill,background:ge(e),flexShrink:"0"})}function tt(e,t){let i=e.summary;if(t){const n=[" has "," have "].find(o=>i.startsWith(`${t}${o}`));n?i=i.slice(t.length+n.length):i.startsWith(`${t} `)&&(i=i.slice(t.length+1))}return i=de(i),i.length?i[0].toUpperCase()+i.slice(1):i}function nt(e){return it(e.map(t=>({label:t.variable.label,...we(t.variable)})))}function it(e){const t=ft(e);return t?l("div",{fontSize:T.body,color:Y,marginTop:x.sm,lineHeight:ne.base},t):null}function ot(e,t){const i=it(t);if(!i)return e;const n=l("div",{});return n.append(e,i),n}export function buildFindingsSection(e,t,i,n,o=!1){if(!e.length)return null;const u=e.some(d=>d.severity==="unusual"||d.severity==="notable"),s=u?e.filter(d=>d.severity!=="info").length.toString():void 0,{outer:m,content:p}=o?(()=>{const d=l("div");return{outer:d,content:d}})():oe(`Findings (${e.length})`,u,s);function r(d){return d.reduce((v,g)=>ae[g.severity]<ae[v]?g.severity:v,"info")}function a(d){const v=new Map;for(const h of d){const y=`${h.comparison.family}\0${h.comparison.left}`,S=v.get(y)??[];S.push(h),v.set(y,S)}const g=[...v.entries()].map(([h,y])=>{const S=[...y].sort((L,A)=>ae[L.severity]-ae[A.severity]);return{key:h,findings:S,worst:r(S)}});return g.sort((h,y)=>ae[h.worst]-ae[y.worst]),g}function b(d,v){const h={ring:"Ring",quadrant:"Quadrant",sector:"Sector","reticle-position":"Reticle","test-site":"Test site",cluster:"Cluster","edge-arc":"Edge arc",wafer:"Wafer"}[d]??d;return v.toLowerCase().startsWith(h.toLowerCase())?v:`${h}: ${v}`}const f=e.filter(d=>d.comparison.family==="spatial-pattern"),w=new Set([...f.flatMap(d=>d.relatedIds??[]),...e.flatMap(d=>d.absorbedIds??[])]),k=e.filter(d=>d.comparison.family!=="spatial-pattern"&&!w.has(d.id)),F=a(k),H=()=>[...F.flatMap(d=>d.findings),...f.flatMap(d=>e.filter(v=>d.relatedIds?.includes(v.id)))];function I(d,v=!1,g){const h=n===d.id,y=document.createElement("button");return y.type="button",y.dataset.wmapFinding=d.id,y.textContent=tt(d,g),ce(y,vt(d)),y.setAttribute("aria-current",h?"true":"false"),Object.assign(y.style,{border:`1px solid ${$.menuBorder}`,borderLeft:`3px solid ${ge(d.severity)}`,background:h?$.bgActive:$.menuBg,borderRadius:q.container,padding:v?"6px 10px":"8px 10px",textAlign:"left",fontSize:v?"10px":"11px",fontWeight:h?"600":"400",color:$.text,cursor:"pointer",width:"100%",marginBottom:x.xs}),G(y,"bare"),y.addEventListener("click",()=>i(d,y)),y}const O=de(Ct(e)??"");if(O){const d=l("div",{background:$.bgActive,borderRadius:q.container,padding:`${x.md} ${x.lg}`,marginBottom:x.md,display:"flex",gap:x.md,alignItems:"flex-start"}),v=l("span",{flex:"1",fontSize:T.body,lineHeight:ne.base,color:$.text},O);d.appendChild(v);const g=l("button",{flexShrink:"0",border:"none",background:"none",fontSize:T.body,color:$.icon,cursor:"pointer",padding:"0",lineHeight:ne.base,whiteSpace:"nowrap"},"Detail \u25B8");g.type="button",G(g,"bare"),g.addEventListener("click",()=>{const h=Oe({title:"Findings Summary",onClose:()=>{},anchor:g}),y=l("p",{fontSize:"16px",lineHeight:ne.base,color:$.text,padding:`${x.xxl} ${x.xxxl} ${x.xxl}`,margin:"0",borderBottom:`1px solid ${$.menuBorder}`,flexShrink:"0"},O);h.contentWrap.appendChild(y);const S=l("div",{overflowY:"auto",padding:`${x.xxl} ${x.xxxl}`,flex:"1"}),L=(D,R)=>{const P=l("div",{display:"flex",alignItems:"center",gap:"7px",fontSize:T.sub,fontWeight:"600",color:ie,marginTop:x.lg,marginBottom:x.xs});return P.appendChild(Be(D)),P.appendChild(l("span",{},R)),P};for(const D of f){S.appendChild(L(D.severity,D.comparison.left)),S.appendChild(l("div",{fontSize:T.body,color:$.text,padding:"4px 0 4px 15px",marginBottom:x.xxs},de(D.summary)));const R=e.filter(P=>D.relatedIds?.includes(P.id));for(const P of R)S.appendChild(l("div",{fontSize:T.body,color:Y,padding:"2px 0 2px 23px",marginBottom:x.xxs},de(P.summary)))}for(const D of F){const[R,P]=D.key.split("\0");S.appendChild(L(D.worst,b(R,P)));for(const Z of D.findings)S.appendChild(l("div",{fontSize:T.body,color:$.text,padding:"4px 0 4px 15px",marginBottom:x.xxs},tt(Z,P)))}const A=nt(H());A&&S.appendChild(A),h.contentWrap.appendChild(S),Object.assign(h.contentWrap.style,{flexDirection:"column",overflow:"hidden"})}),d.appendChild(g),p.appendChild(d)}let z=!0;for(const d of f){z||p.appendChild(l("div",{height:"1px",background:$.separator,margin:"4px 0"})),z=!1;const v=e.filter(L=>d.relatedIds?.includes(L.id)),g=v.length>0,h=l("div",{position:"relative",marginBottom:g?"2px":"4px"}),y=n===d.id,S=document.createElement("button");if(S.type="button",S.dataset.wmapFinding=d.id,Object.assign(S.style,{border:`1px solid ${$.menuBorder}`,borderLeft:`3px solid ${ge(d.severity)}`,background:y?$.bgActive:$.menuBg,borderRadius:q.container,padding:"8px 32px 8px 10px",textAlign:"left",fontSize:T.body,fontWeight:y?"600":"500",color:$.text,cursor:"pointer",width:"100%"}),S.textContent=de(d.summary),ce(S,d.summary),S.setAttribute("aria-current",y?"true":"false"),G(S,"bare"),S.addEventListener("click",()=>i(d,S)),h.appendChild(S),g){const L=l("div",{display:"none",paddingLeft:"12px",marginBottom:x.xs});for(const R of v)L.appendChild(I(R,!0));h.appendChild(L);let A=!1;const D=l("button",{position:"absolute",top:"50%",right:"8px",transform:"translateY(-50%)",border:"none",background:"none",fontSize:T.body,color:$.icon,cursor:"pointer",padding:`${x.xxs} ${x.xs}`,lineHeight:ne.none},"\u25B8");G(D,"bare"),D.type="button",ce(D),D.setAttribute("aria-label","Show supporting findings"),D.setAttribute("aria-expanded","false"),D.addEventListener("click",R=>{R.stopPropagation(),A=!A,L.style.display=A?"block":"none",D.textContent=A?"\u25BE":"\u25B8";const P=A?"Hide supporting findings":"Show supporting findings";D.setAttribute("aria-label",P),D.setAttribute("aria-expanded",String(A))}),h.appendChild(D)}p.appendChild(h)}for(const d of F){z||p.appendChild(l("div",{height:"1px",background:$.separator,margin:"4px 0"})),z=!1;const[v,g]=d.key.split("\0"),h=l("div",{display:"flex",alignItems:"center",gap:x.sm,fontSize:T.body,fontWeight:"600",color:ie,margin:"2px 0 4px"});h.appendChild(Be(d.worst)),h.appendChild(l("span",{},b(v,g))),p.appendChild(h);for(const y of d.findings)p.appendChild(I(y,!1,g))}const C=nt(H());return C&&p.appendChild(C),m}const Kt=[{value:"",label:"All kinds"},{value:"yield",label:"Yield"},{value:"hardBin",label:"Hard bin"},{value:"softBin",label:"Soft bin"},{value:"test",label:"Test value"},{value:"functionalTest",label:"Functional test"},{value:"spatialPattern",label:"Spatial pattern"}],Vt=[{value:"",label:"All regions"},{value:"ring",label:"Ring"},{value:"quadrant",label:"Quadrant"},{value:"reticle-position",label:"Reticle position"},{value:"test-site",label:"Test site"},{value:"wafer",label:"Wafer"},{value:"sector",label:"Sector"},{value:"cluster",label:"Cluster"},{value:"edge-arc",label:"Edge arc"},{value:"spatial-pattern",label:"Spatial pattern"}],qt=["unusual","notable","info"],Gt={unusual:"Unusual",notable:"Notable",info:"Info"};function Ut(e,t,i){const n=l("div",{display:"flex",flexWrap:"wrap",alignItems:"center",gap:x.lg,marginBottom:x.lg,paddingBottom:"10px",borderBottom:`1px solid ${$.separator}`}),o={unusual:0,notable:0,info:0};for(const r of e)o[r.severity]++;const u=qt.filter(r=>o[r]>0),s=new Set(t.severity===void 0?u:Array.isArray(t.severity)?t.severity:[t.severity]),m=l("div",{display:"flex",gap:x.xs,flexWrap:"wrap"});for(const r of u){const a=document.createElement("button");a.type="button";const b=()=>{const f=s.has(r);a.setAttribute("aria-pressed",f?"true":"false"),Object.assign(a.style,{display:"inline-flex",alignItems:"center",gap:"5px",border:`1px solid ${$.menuBorder}`,borderRadius:q.pill,background:f?$.bgActive:"none",opacity:f?"1":"0.5",color:$.text,fontSize:T.body,padding:`${x.xxs} ${x.md}`,cursor:"pointer"}),a.dataset.on=f?"true":"false"};a.appendChild(Be(r)),a.appendChild(l("span",{},`${Gt[r]} ${o[r]}`)),ce(a,()=>s.has(r)?"Click to hide these findings":"Click to show these findings"),b(),G(a,"bare"),a.addEventListener("click",()=>{s.has(r)?s.delete(r):s.add(r),t.severity=s.size===u.length?void 0:[...s],i()}),m.appendChild(a)}n.appendChild(m);const p=t.kind!==void 0||t.family!==void 0;return(e.length>=Qt||p)&&(n.appendChild(Pe("Kind:",Kt,t.kind??"",r=>{t.kind=r||void 0,i()},{maxWidth:"130px"})),n.appendChild(Pe("Region:",Vt,t.family??"",r=>{t.family=r||void 0,i()},{maxWidth:"150px"}))),n}const Qt=8;function Xt(e,t){const i=l("div",{display:"flex",flexDirection:"column",gap:x.xs,padding:x.md,marginBottom:x.md,background:$.bgHover,borderRadius:q.control},void 0,t);if(i.appendChild(l("div",{fontSize:T.body,color:$.value},e.message,t)),e.detail&&i.appendChild(l("div",{fontSize:T.meta,color:Y},e.detail,t)),e.actionLabel&&e.onAction){const n=l("button",me("outlined"),e.actionLabel,t);n.type="button",n.style.alignSelf="flex-start",n.style.marginTop=x.xs,G(n),n.addEventListener("click",e.onAction),i.appendChild(n)}return i}export function buildFindingsSectionWithFilter(e,t,i,n,o,u,s){if(!e.findings.length&&!s)return null;const m=e.findings.some(k=>k.severity==="unusual"||k.severity==="notable"),p=m?e.findings.filter(k=>k.severity!=="info").length.toString():void 0,r=u?.ownerDocument??document,{outer:a,content:b}=oe(`Findings (${e.findings.length})`,m||!!s,p,{stateKey:"findings",panel:u});if(s&&b.appendChild(Xt(s,r)),!e.findings.length)return a;b.appendChild(Ut(e.findings,n,o));const f=St(e,n);if(!f.length)return b.appendChild(l("div",{color:Y,fontSize:T.body,textAlign:"center",padding:`${x.xxl} ${x.md}`},"No findings match the current filter.")),a;const w=buildFindingsSection(f,e,t,i,!0);return w&&b.appendChild(w),a}export function buildLotTestSection(...e){return be(buildLotTestSectionSteps(...e))}export function*buildLotTestSectionSteps(e,t,i,n,o,u,s,m="full"){const p=n?.length?{perWaferMetadata:n.map(a=>a.wafer??{}),populationLabel:`${n.length} wafer${n.length===1?"":"s"} pooled`}:void 0;let r;if(n?.length&&n.every(a=>a.stats.perTestStats!==void 0)){const a=new Map;for(const b of n)for(const f of b.stats.perTestStats??[]){const w=a.get(f.testNumber);w?(w.n+=f.count,w.sum+=f.mean*f.count,w.min=Math.min(w.min,f.min),w.max=Math.max(w.max,f.max)):a.set(f.testNumber,{n:f.count,sum:f.mean*f.count,min:f.min,max:f.max})}r={perTestStats:[...a.entries()].map(([b,f])=>({testNumber:b,count:f.n,min:f.min,max:f.max,mean:f.sum/f.n}))}}if(n?.length&&n.every(a=>a.stats.testSpecYield!==void 0)){const a=new Map;for(const b of n)for(const f of b.stats.testSpecYield??[]){const w=a.get(f.testNumber);w?(w.passDies+=f.passDies,w.totalDies+=f.totalDies):a.set(f.testNumber,{passDies:f.passDies,totalDies:f.totalDies})}r={...r,testSpecYield:[...a.entries()].map(([b,f])=>({testNumber:b,totalDies:f.totalDies,yieldPercent:f.totalDies>0?f.passDies/f.totalDies*100:null}))}}return yield*buildTestSectionSteps(e,t,i,r,o,p,u,s,m)}export function createSummaryPanelEl(e,t,i=document){const n=e==="top"||e==="bottom",o=l("div",{background:zt,color:$.text,fontVariantNumeric:"tabular-nums",border:je,borderRadius:q.container,padding:x.xl,overflowY:"auto",overflowX:n?"auto":"hidden",flexShrink:"0",boxSizing:"border-box",fontFamily:T.family,fontSize:T.sub,boxShadow:ze.panel},void 0,i);return e==="right"&&(o.style.marginRight=t),e==="left"&&(o.style.marginLeft=t),e==="bottom"&&(o.style.marginBottom=t),n?(o.style.height="180px",o.style.width="100%"):(o.style.width="300px",o.style.maxHeight="100%"),o}export function wrapWithSummaryPanel(e,t,i){const n=i==="top"||i==="bottom",o=l("div",{display:"flex",flexDirection:n?"column":"row",gap:x.md,width:"100%",height:"100%",flex:"1 1 0",minHeight:"0",boxSizing:"border-box",alignItems:n?"flex-start":"stretch"});return e.style.flex="1 1 0",e.style.minWidth="0",e.style.minHeight="0",i==="right"||i==="bottom"?(o.appendChild(e),o.appendChild(t)):(o.appendChild(t),o.appendChild(e)),o}function st(e){return l("div",{fontSize:T.heading,fontWeight:"600",color:ie,marginBottom:x.lg},e)}function Ce(e,t){const i=l("button",me("outlined"),e);return i.type="button",G(i),i.addEventListener("click",t),i}function at(...e){const t=e.filter(n=>!!n);if(!t.length)return null;const i=l("div",{display:"flex",flexWrap:"wrap",gap:x.sm,marginBottom:x.lg});for(const n of t)i.appendChild(n);return i}function rt(e,t,i,n,o,u,s,m,p,r,a){const b=e.ownerDocument,f=Oe({title:"Die list",onClose:()=>{},anchor:e,ownerDocument:b});f.contentWrap.style.padding="14px 16px";const w=Mt(t,i,{...s,title:n,onSaveText:m,waferMetadata:o,metadataFields:u,extraColumn:p,getWafer:r,ringCount:a,ownerDocument:b});w&&f.contentWrap.appendChild(w)}export function renderWaferSummaryContent(...e){be(renderWaferSummaryContentSteps(...e))}export function*renderWaferSummaryContentSteps(e,t){const i=e.scrollTop;e.innerHTML="";const{wafer:n,dies:o,yieldSummary:u,dataCoverage:s,hbinDefs:m,sbinDefs:p,testDefs:r,statsSummary:a,passBins:b=[1],ringCount:f=4,binColors:w,plotMode:k,fallbackFormat:F,onFindingClick:H,activeFindingId:I=null,findingsFilter:O,onFindingsFilterChange:z,findingsNotice:C,onSaveText:d,metadataFields:v,dieListOptions:g,metadataShownElsewhere:h}=t;e.appendChild(st("Wafer Summary"));const y=t.warnings??Ie({statsSummary:a});y.length&&e.appendChild($e(y,e.ownerDocument));const S=u&&s?Ce("Summary report",()=>{Ye(xt({wafer:n,dies:o,yield:u,dataCoverage:s,hbinDefs:m,sbinDefs:p,testDefs:r,passBins:b,ringCount:f},a),{anchor:e})}):null,L=(g?.enabled??!0)&&o.length?Ce("View die list",()=>{rt(e,o,r,`Die list \u2014 ${o.length} dies`,n.metadata,v,g,d,void 0,()=>n,f)}):null,A=at(S,L);A&&e.appendChild(A);let D=!0;const R=_=>{_&&(D||e.appendChild(Ge()),D=!1,e.appendChild(_))},P=a?.stats.isLotStack?a.stats:void 0,Z=P?.lotSize!==void 0?{lotSize:P.lotSize,aggrMethod:Nt(P.aggregationMethod)}:void 0;h||R(buildMetadataInfoSection([{metadata:n.metadata??void 0}],Z)),u&&s&&R(buildYieldSection(u,s,b)),yield,a&&H&&O&&z&&(R(buildFindingsSectionWithFilter(a,H,I,O,z,e,C)),yield),R(buildBinBreakdownSection({dies:o,hbinDefs:m,sbinDefs:p,binColors:w,hardCounts:a?.stats.hardBinCounts,softCounts:a?.stats.softBinCounts,plotMode:k,passBins:b,panel:e})),yield,R(buildRegionYieldPanelSection({diesByWafer:[o],allWafers:[n],ringCount:f,passBins:b,panel:e})),yield;const J=n.metadata?{waferMetadata:n.metadata}:void 0;R(yield*buildTestSectionSteps(o,r,F,a?.stats,d,J,[{dies:o}],e,"compact")),yield,R(buildFunctionalTestSection(o,r,a?.stats.functionalYield,d,J,e)),e.appendChild(l("div",{height:"12px",flexShrink:"0"})),e.scrollTop=i}export function reportMapsFromItems(e,t,i){const n=[];return e.forEach((o,u)=>{!o?.wafer||!o.dies||n.push({...o,wafer:o.wafer,dies:o.dies,label:ve(o,u),passBins:[...Se(o,t)],ringCount:o.ringCount??i})}),n}export function renderLotSummaryContent(...e){be(renderLotSummaryContentSteps(...e))}export function*renderLotSummaryContentSteps(e,t){const i=e.scrollTop;e.innerHTML="";const{lotSummary:n,items:o,hbinDefs:u,sbinDefs:s,testDefs:m,passBins:p=[1],ringCount:r=4,binColors:a,plotMode:b,fallbackFormat:f,onFindingClick:w,activeFindingId:k=null,onWaferClick:F,findingsFilter:H,onFindingsFilterChange:I,findingsNotice:O,onSaveText:z,dieListOptions:C,findingsFor:d}=t;e.appendChild(st(`Summary \u2014 ${Bt(Me(n.perWafer.map(N=>N.summary.wafer)))}`));const v=t.warnings??Ie({lotStatsSummary:n});v.length&&e.appendChild($e(v,e.ownerDocument));const g=Ce("Summary report",()=>{Ye(yt(reportMapsFromItems(o,p,r)),{anchor:e})}),h=[],y=[],S=[],L=[],A=[],D=new WeakMap,R=new WeakMap;for(let N=0;N<o.length;N++){yield;const V=o[N];if(!V){y.push([]);continue}V.wafer&&(h.push(V.wafer),L.push(V.dies??[]),A.push(Se(V,p)));const re=V.dies??[],c=ve(V,N);for(const W of re)D.set(W,c),V.wafer&&R.set(W,V.wafer);y.push(re);for(const W of re)S.push(W)}const P=C?.enabled??!0?Ce("View die list",()=>{S.length&&rt(e,S,m,`Die list \u2014 ${S.length} dies across ${o.length} wafer${o.length===1?"":"s"}`,Fe(o.filter(N=>!!N).map(N=>({metadata:N.wafer?.metadata}))),o.find(N=>N?.metadataFields?.length)?.metadataFields,C,z,{label:"Wafer",get:N=>D.get(N)},N=>R.get(N),r)}):null,Z=at(g,P);Z&&e.appendChild(Z);const J=o.map(N=>N?.statsSummary).filter(N=>!!N);let _=!0;const U=N=>{N&&(_||e.appendChild(Ge()),_=!1,e.appendChild(N))};U(buildLotOverviewSection(n,J)),yield,w&&H&&I&&(U(buildFindingsSectionWithFilter(n,w,k,H,I,e,O)),yield),U(buildPerWaferYieldSection(n,o,F,e,d)),yield,U(buildBinBreakdownSection({dies:S,hbinDefs:u,sbinDefs:s,plotMode:b,passBins:p,panel:e,binColors:a??kt(o.flatMap(N=>N?[{dies:N.dies??[],passBins:Se(N,p)}]:[]),{hbinDefs:u,sbinDefs:s}).colors})),yield,U(buildRegionYieldPanelSection({diesByWafer:L,allWafers:h,ringCount:r,passBins:N=>A[N],panel:e})),yield,m?.length&&(U(yield*buildLotTestSectionSteps(S,m,f,J,z,y.map(N=>({dies:N})),e,"compact")),yield,U(buildLotFunctionalSection(S,m,J,z,e))),e.appendChild(l("div",{height:"12px",flexShrink:"0"})),e.scrollTop=i}
1
+ import{waferDisplayLabel as ve}from"../core/waferLabel.js";import{itemPassBins as Se,passBinsLabel as lt}from"../core/passBins.js";import{isParametricTest as dt}from"../renderer/buildWaferMap.js";import{testLabel as ct,markedTestLabel as pt,unmarkedLabel as ut,derivedFields as we,derivedKeyText as ft,derivedCsvCell as Ne,isDerivedTest as Te,DERIVED_CSV_HEADER as De}from"../renderer/testLabel.js";import{buildRingRegions as mt,buildQuadrantRegions as gt,buildRegionYieldData as ht}from"../stats/regions.js";import{computeFunctionalYield as bt}from"../stats/analyzeWaferMap.js";import{renderWaferReportHtml as xt,renderLotReportHtml as yt}from"../stats/renderSummaryReport.js";import{buildFindingsNarrative as Ct}from"../stats/findingsNarrative.js";import{formatFindingTooltip as vt}from"../stats/reportHtml.js";import{filterFindings as St}from"../stats/filterFindings.js";import{buildFacetTable as wt,prettyKey as Ee}from"../stats/facets.js";import{commonMetadata as Fe}from"../stats/facets.js";import{resolveMetadataColumns as $t}from"../stats/metadataColumns.js";import{resolveBinColors as Re,resolveBinColorsByWafer as kt}from"../renderer/binColors.js";import{NO_DATA_FILL as Lt}from"../renderer/colorMap.js";import{classifySpec as Bt,isOutOfSpec as Nt}from"../renderer/spec.js";import{describeWaferPopulation as Me,populationLabel as Tt}from"../stats/population.js";import{buildWarningsBanner as $e,collectWarnings as Ie}from"./warnings.js";export{$e as buildWarningsBanner};import{fmt as Ae,fmtAggregationMethod as Dt,plainBinTerms as de}from"../renderer/fmt.js";import{getUniqueTestNumbers as Et}from"../renderer/buildView.js";import{describeSorted as Ft,quantile as We}from"../stats/math.js";import{pooledTestStatsSteps as Rt}from"../stats/capability.js";import{sortBinsForDisplay as Mt}from"../stats/binPareto.js";import{poolFunctionalYield as It}from"../stats/testPassRate.js";import{makeLabeledSelect as Pe,makeSegmented as ke}from"./charts/chartShell.js";import{SHADOW as ze,MOTION as He,LEADING as te,TRACKING as fe,wireControlHover as G,controlStyle as me,SPACE as x,RADIUS as q,FONT as T,CLR as $,sevColor as ge,openModal as Oe,openReportModal as Ye,saveTextFile as _e,wireTooltip as ce}from"./toolbar.js";import{buildDieListSection as At}from"./dieList.js";export{csvField}from"../core/utils.js";import{csvField as he,drain as be,maxOf as Wt,medianOfSorted as Pt,minOf as zt}from"../core/utils.js";import{metadataDisplayValue as Ht}from"../core/metadata.js";const Ot=$.panelBg,je=`1px solid ${$.menuBorder}`,Yt="12px",Y=$.label,ne=$.value,Ke="10px";function l(e,t,i,n=document){const o=n.createElement(e);return t&&Object.assign(o.style,t),i!==void 0&&(o.textContent=i),o}function se(e){return l("div",{fontSize:Ke,fontWeight:"700",letterSpacing:fe,textTransform:"uppercase",color:Y,marginBottom:x.sm},e)}const Ve=new WeakMap,qe=["regionYield","testValues","functionalTests"];function xe(e){if(!e)return{collapsed:new Set(qe),regionMode:"ring",waferSort:"slot"};let t=Ve.get(e);return t||(t={collapsed:new Set(qe),regionMode:"ring",waferSort:"slot"},Ve.set(e,t)),t}function oe(e,t=!0,i,n){const o=l("div"),u=xe(n?.panel);n?.stateKey&&n.panel&&(t=!u.collapsed.has(n.stateKey));const s=document.createElement("button");s.type="button",Object.assign(s.style,{display:"flex",alignItems:"center",gap:x.xs,width:"100%",background:"none",border:"none",cursor:"pointer",padding:"0 0 6px",textAlign:"left"});const m=l("span",{fontSize:T.meta,color:Y,transition:`transform ${He.base}`,transform:t?"rotate(90deg)":"rotate(0deg)",display:"inline-block",lineHeight:te.none,marginRight:"1px"},"\u25B6"),p=l("span",{fontSize:Ke,fontWeight:"700",letterSpacing:fe,textTransform:"uppercase",color:Y,flex:"1"},e);if(G(s,"bare"),s.setAttribute("aria-expanded",t?"true":"false"),s.appendChild(m),s.appendChild(p),i){const b=l("span",{fontSize:T.meta,fontWeight:"700",background:$.warnBg,color:$.warnText,borderRadius:q.pill,padding:"1px 5px"},i);s.appendChild(b)}const r=l("div");r.style.display=t?"block":"none";let a=t;if(s.addEventListener("click",()=>{a=!a,r.style.display=a?"block":"none",m.style.transform=a?"rotate(90deg)":"rotate(0deg)",s.setAttribute("aria-expanded",a?"true":"false"),n?.stateKey&&n.panel&&(a?u.collapsed.delete(n.stateKey):u.collapsed.add(n.stateKey))}),n?.control){const b=l("div",{display:"flex",alignItems:"center",gap:x.sm});s.style.width="auto",s.style.flex="1",b.appendChild(s);const f=()=>{r.innerHTML="",n.render?.(r)},w=n.control(f);w&&(w.style.marginBottom="6px",w.addEventListener("click",k=>k.stopPropagation()),b.appendChild(w)),o.appendChild(b)}else o.appendChild(s);return o.appendChild(r),n?.render?.(r),{outer:o,content:r}}function Ge(){return l("div",{height:"1px",background:$.separator,margin:`${Yt} 0`,flexShrink:"0"})}function Le(e,t,i=$.barFill,n,o){const u=l("div",{marginBottom:"5px"}),s=l("div",{display:"flex",justifyContent:"space-between",fontSize:T.body,color:ne,marginBottom:x.xxs}),m=l("span",{color:Y},e),p=l("span",{fontWeight:"600"},`${t.toFixed(1)}%`);s.appendChild(m),s.appendChild(p);const r=n!==void 0?n:Math.min(100,Math.max(0,t)),a=i,b=l("div",{position:"relative",height:"9px",background:$.bgActive,borderRadius:q.control,overflow:"hidden"}),f=l("div",{height:"100%",width:`${r}%`,background:a,borderRadius:q.control,transition:`width ${He.base}`});if(b.appendChild(f),o!==void 0){const w=l("div",{position:"absolute",top:"0",bottom:"0",left:`${o}%`,width:"2px",marginLeft:"-1px",background:$.value,opacity:"0.8"});b.appendChild(w)}return u.appendChild(s),u.appendChild(b),u}function Ue(){const e=l("div",{display:"flex",gap:x.sm,marginBottom:x.md});return e.finish=()=>{const t=e.lastElementChild;t&&Object.assign(t.style,{borderRight:"none",paddingRight:"0"})},e}function pe(e,t,i){const n=l("div",{padding:`${x.xxs} ${x.md} ${x.xxs} 0`,borderRight:je,textAlign:"center",flex:"1"}),o=l("div",{fontSize:T.heading,fontWeight:"700",color:ne,lineHeight:te.tight},e),u=l("div",{fontSize:T.body,color:Y,marginTop:x.xxs},t);return n.appendChild(o),n.appendChild(u),i&&n.appendChild(l("div",{fontSize:T.body,color:Y,opacity:"0.85"},i)),n}function Qe(e,t){const i=l("div",{display:"flex",justifyContent:"space-between",fontSize:T.body,gap:x.md,marginBottom:"3px"}),n=l("span",{color:Y,flexShrink:"0"},e),o=l("span",{color:ne,textAlign:"right",fontWeight:"500",wordBreak:"break-all"},t);return i.appendChild(n),i.appendChild(o),i}function _t(e,t){const i=l("div",{display:"flex",fontSize:T.body,gap:x.sm,marginBottom:"3px"}),n=l("span",{color:Y,flexShrink:"0"},`${e}:`),o=l("span",{color:ne,fontWeight:"500",wordBreak:"break-all"},t);return i.appendChild(n),i.appendChild(o),i}export function metadataEntries(e){const t=[];for(const[i,n]of Object.entries(e)){const o=Ht(n);o!==void 0&&t.push([i,o])}return t}const jt=["lot","product","testprogram","split"],ye=e=>{const t=jt.indexOf(e.toLowerCase().replace(/[^a-z]/g,""));return t===-1?Number.MAX_SAFE_INTEGER:t};export function buildFacetSummaryChips(e,t=3){if(!e.length)return null;const i=l("div",{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:`${x.xs} ${x.lg}`}),n=[...e].sort((m,p)=>ye(m.key)-ye(p.key)),o=n.filter(m=>ye(m.key)!==Number.MAX_SAFE_INTEGER),u=n.filter(m=>ye(m.key)===Number.MAX_SAFE_INTEGER),s=m=>{const p=l("span",{whiteSpace:"nowrap"}),r=l("span",{color:Y},`${Ee(m.key)}: `);p.appendChild(r);const a=m.values.slice(0,t),b=m.values.length-a.length;let f=a.map(w=>w.value).join(", ");return b>0&&(f+=` +${b} more`),p.appendChild(document.createTextNode(f)),p};for(const m of o)i.appendChild(s(m));if(u.length){const m=l("span",{display:"none",flexWrap:"wrap",alignItems:"baseline",gap:`${x.xs} ${x.lg}`});for(const a of u)m.appendChild(s(a));const p=l("button",{background:"none",border:"none",padding:"0",cursor:"pointer",color:$.iconActive,fontSize:T.body,whiteSpace:"nowrap"});p.type="button",G(p,"bare");const r=a=>{m.style.display=a?"contents":"none",p.textContent=a?"less":`+${u.length} more`,p.setAttribute("aria-expanded",String(a))};r(!1),p.addEventListener("click",()=>r(p.getAttribute("aria-expanded")!=="true")),i.appendChild(m),i.appendChild(p)}return i}export function buildMetadataStripRow(e,t,i){const n=wt(e,i),o=buildFacetSummaryChips(n);if(!o&&!t)return null;const u=l("div",{display:"flex",flexWrap:"wrap",alignItems:"baseline",gap:"4px 14px"});if(t){const s=l("span",{fontWeight:"500",whiteSpace:"nowrap"},t.aggrMethod?`${t.lotSize} wafers stacked \xB7 ${t.aggrMethod}`:`${t.lotSize} wafers stacked`);u.appendChild(s)}return o&&u.appendChild(o),u}const Kt={display:"flex",flexDirection:"column",gap:x.sm,background:$.menuBg,border:`1px solid ${$.menuBorder}`,borderRadius:q.container,padding:`${x.sm} ${x.lg}`,boxShadow:ze.panel,fontSize:T.body,lineHeight:te.none,boxSizing:"border-box",width:"100%",minWidth:"0"};export function buildMetadataStripBox(e,t,i){const n=buildMetadataStripRow(e,t,i);if(!n)return null;const o=l("div",Kt);return o.appendChild(n),o}export function buildCompactMetadataRows(e){const t=metadataEntries(e);if(!t.length)return null;const i=l("div");for(const[n,o]of t)i.appendChild(_t(Ee(n),o));return i}export function buildMetadataInfoSection(e,t){const i=buildMetadataStripRow(e,t,{facetableOnly:e.length>1});if(!i)return null;const n=l("div");return n.appendChild(se("Wafer Info")),n.appendChild(i),n}export function buildYieldSection(e,t,i=[1]){const n=l("div");n.appendChild(se("Summary"));const o=Ue();if(o.appendChild(pe(String(e.totalDies),"Total dies")),e.partialDies>0&&o.appendChild(pe(String(e.partialDies),"Partial")),e.yieldPercent!==null){const u=lt([i]);o.appendChild(pe(`${e.yieldPercent.toFixed(1)}%`,"Yield",`pass: ${u}`))}return o.finish(),n.appendChild(o),e.edgeExcludedDies>0&&n.appendChild(Qe("Edge excluded (outer zone)",String(e.edgeExcludedDies))),n}export function buildBinSection(e,t,i,n,o,u){const s=new Map;if(o)for(const[r,a]of Object.entries(o))s.set(Number(r),a);else for(const r of e){if(r.partial||r.edgeExcluded)continue;const a=i==="hard"?r.hbin:r.sbin;a!=null&&s.set(a,(s.get(a)??0)+1)}if(!s.size)return null;const m=n??Re(e,{passBins:u,...i==="hard"?{hbinDefs:t}:{sbinDefs:t}}),p=l("div");p.appendChild(se(Xe(i,[...s.values()].reduce((r,a)=>r+a,0))));for(const r of Ze(s,t,m[i],m.pass[i]))p.appendChild(r);return p}function Xe(e,t){return`${e==="hard"?"Hard":"Soft"} Bin Breakdown \u2014 % of dies (N=${t})`}function Ze(e,t,i,n){const o=[...e.values()].reduce((m,p)=>m+p,0),u=t?new Map(t.map(m=>[m.bin,m])):null;return Mt(e.entries(),n).map(([m,p])=>{const r=u?.get(m),a=r?.name?`Bin ${m} \xB7 ${r.name}`:`Bin ${m}`,b=p/o*100,f=i.get(m)??Lt;return Le(`${a} (${p})`,b,f)})}export function buildBinBreakdownSection(e){const{dies:t,hbinDefs:i,sbinDefs:n,hardCounts:o,softCounts:u,plotMode:s,passBins:m=[1],panel:p}=e,r=e.binColors??Re(t,{passBins:m,hbinDefs:i,sbinDefs:n}),a=v=>{const g=v==="hard"?o:u,h=new Map;if(g){for(const[y,S]of Object.entries(g))h.set(Number(y),S);return h}for(const y of t){if(y.partial||y.edgeExcluded)continue;const S=v==="hard"?y.hbin:y.sbin;S!=null&&h.set(S,(h.get(S)??0)+1)}return h},b=a("hard"),f=a("soft"),w=b.size>0,k=f.size>0;if(!w&&!k)return null;const F=xe(p),H=s==="softBin"||s==="stackedSoftBins"?"soft":s==="hardBin"||s==="stackedBins"?"hard":void 0;let I=F.binMode??H??(w?"hard":"soft");I==="hard"&&!w&&(I="soft"),I==="soft"&&!k&&(I="hard");const O=I==="hard"?b:f,z=I==="hard"?i:n,C=[...O.values()].reduce((v,g)=>v+g,0),{outer:d}=oe(Xe(I,C),!0,void 0,{stateKey:"bins",panel:p,render:v=>{const g=I==="hard"?r.hard:r.soft;for(const h of Ze(O,z,g,r.pass[I]))v.appendChild(h)},control:w&&k&&p?()=>ke([["hard","Hard"],["soft","Soft"]],I,v=>{F.binMode=v;const g=buildBinBreakdownSection(e);g&&d.replaceWith(g)},p.ownerDocument,!0):void 0});return d}export function buildLotBinSection(e,t,i,n){return buildBinSection(e,t,i,n)}export function buildRegionYieldPanelSection(e){const{diesByWafer:t,allWafers:i,ringCount:n,passBins:o,panel:u}=e,s=xe(u),m=a=>ht(t,i,n,o,a==="ring"?mt:gt);if(!m("ring").length&&!m("quadrant").length)return null;const p=s.regionMode,{outer:r}=oe(p==="ring"?"Ring Yield":"Quadrant Yield",!0,void 0,{stateKey:"regionYield",panel:u,render:a=>{const b=m(p);if(!b.length){a.appendChild(l("div",{fontSize:T.body,color:Y},"No positioned dies for this breakdown."));return}for(const{label:f,n:w,yieldPercent:k}of b)a.appendChild(Le(`${f} (N=${w})`,k))},control:u?()=>ke([["ring","Ring"],["quadrant","Quadrant"]],p,a=>{s.regionMode=a;const b=buildRegionYieldPanelSection(e);b&&r.replaceWith(b)},u.ownerDocument,!0):void 0});return r}export function buildLotOverviewSection(e,t=[]){const i=l("div"),n=Me(e.perWafer.map(s=>s.summary.wafer));i.appendChild(se(n.lotId!==void 0?"Lot Summary":"Summary"));const o=Ue();o.appendChild(pe(String(e.stats.waferCount),"Wafers"));const u=e.perWafer.map(s=>s.summary.stats.yieldPercent).filter(s=>s!==null);if(u.length){const s=u.reduce((m,p)=>m+p,0)/u.length;o.appendChild(pe(`${s.toFixed(1)}%`,"Mean per-wafer yield"))}if(o.finish(),i.appendChild(o),t.length){const s=t.reduce((p,r)=>p+r.stats.analyzedDies,0),m=t.reduce((p,r)=>p+r.stats.excludedDies,0);(s||m)&&i.appendChild(Qe("Dies analysed",m?`${s.toLocaleString()} (${m.toLocaleString()} excluded)`:s.toLocaleString()))}return i}export function buildPerWaferYieldSection(e,t,i,n,o){const u=e.perWafer.map(C=>({waferIndex:C.waferIndex,label:ve(t[C.waferIndex],C.waferIndex).replace(/\s*·\s*\d+(\.\d+)?%$/,""),yieldPct:C.summary.stats.yieldPercent})).filter(C=>C.yieldPct!==null);if(!u.length)return null;const s=zt(u.map(C=>C.yieldPct)),m=Wt(u.map(C=>C.yieldPct)),p=s===m?"":` (${s.toFixed(1)}\u2013${m.toFixed(1)}%)`,r=[...u.map(C=>C.yieldPct)].sort((C,d)=>C-d),a=Pt(r),b=We(r,.25),f=We(r,.75),w=u.length>=5?b-1.5*(f-b):-1/0,k=xe(n),F=C=>{const d=k.waferSort==="yield"?[...u].sort((v,g)=>v.yieldPct-g.yieldPct):u;for(const{waferIndex:v,label:g,yieldPct:h}of d){const S=h<w?`${g} \xB7 low outlier`:g,L=Le(S,h,void 0,void 0,a),A=o?.(v);A?.total&&O(L,A),z(L,v,g,h,A),C.appendChild(L)}},H=` \xB7 median ${a.toFixed(1)}%`,{outer:I}=oe("Wafer Yield"+p+H,!0,void 0,{stateKey:"waferYield",panel:n,render:F,control:n?C=>ke([["slot","Slot"],["yield","Yield"]],k.waferSort,d=>{k.waferSort=d,C()},n.ownerDocument,!0):void 0});return I;function O(C,d){const v=d.unusual?"unusual":d.notable?"notable":"info",g=l("span",{marginLeft:x.sm,flexShrink:"0",background:ge(v),color:"#fff",borderRadius:q.container,padding:"0 5px",fontSize:T.body,fontWeight:"600"},`${d.total}`);g.setAttribute("aria-hidden","true"),ce(g,`${d.total} finding${d.total===1?"":"s"}`+(d.unusual?`, ${d.unusual} unusual`:"")+(d.notable?`, ${d.notable} notable`:"")),C.firstElementChild?.firstElementChild?.appendChild(g)}function z(C,d,v,g,h){i&&(C.style.cursor="pointer",C.style.borderRadius="4px",C.style.padding="2px 3px",C.style.marginLeft="-3px",C.style.marginRight="-3px",C.setAttribute("role","button"),C.setAttribute("aria-label",`${v}, ${g.toFixed(1)}% yield`+(h?.total?`, ${h.total} finding${h.total===1?"":"s"}${h.unusual?`, ${h.unusual} unusual`:""}`:"")+" \u2014 open wafer"),C.tabIndex=0,C.addEventListener("mouseenter",()=>{C.style.background=$.bgHover}),C.addEventListener("mouseleave",()=>{C.style.background=""}),C.addEventListener("focus",()=>{C.style.background=$.bgHover}),C.addEventListener("blur",()=>{C.style.background=""}),C.addEventListener("click",()=>i(d)),C.addEventListener("keydown",y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),i(d))}))}}function Vt(e){return Ft([...e].sort((t,i)=>t-i))}function Je(e,t){if(!e)return[];const i=e.waferMetadata??(e.perWaferMetadata?Fe(e.perWaferMetadata.map(n=>({metadata:n}))):void 0);return!i||!Object.keys(i).length?[]:$t({waferMetadata:i,waferKeys:"identity",waferPlacement:"csv",reservedLabels:t}).columns}function et(e){return e?.populationLabel?[{key:"population",label:"Population",scope:"wafer",constant:e.populationLabel,get:()=>e.populationLabel,csvOnly:!0}]:[]}export function buildTestSection(...e){return be(buildTestSectionSteps(...e))}export function*buildTestSectionSteps(e,t,i,n,o,u,s,m,p="full"){const r=e.filter(c=>!c.partial&&!c.edgeExcluded),a=new Map((n?.perTestStats??[]).map(c=>[c.testNumber,c])),b=new Map((n?.testSpecYield??[]).map(c=>[c.testNumber,c]));let f;if(t?.length?f=t.filter(dt).map(c=>({testNumber:c.testNumber,name:c.name,unit:c.unit,limitLow:c.limitLow,limitHigh:c.limitHigh,limitLowInclusive:c.limitLowInclusive,limitHighInclusive:c.limitHighInclusive,...we(c)})):f=Et(r).map(W=>({testNumber:W,name:ct(void 0,W)})),!f.length)return null;const w=f.filter(c=>r.some(W=>{const j=W.testValues?.[c.testNumber];return j!==void 0&&isFinite(j)}));if(!w.length)return null;const k=w.some(c=>c.limitLow!==void 0||c.limitHigh!==void 0),F=[],H=c=>!!c&&c.stddev!==void 0&&c.median!==void 0&&c.q1!==void 0&&c.q3!==void 0,I=c=>c.limitLow!==void 0||c.limitHigh!==void 0,O=!!(s?.length&&t?.length),C=(O||w.some(c=>!H(a.get(c.testNumber))||I(c)&&!b.has(c.testNumber)))&&t?.length?yield*Rt(s??[{dies:e}],t):void 0;for(const c of w){yield;const W=a.get(c.testNumber),j=C?.specTally.get(c.testNumber),ee=C?.stats.get(c.testNumber),K=()=>r.map(E=>E.testValues?.[c.testNumber]).filter(E=>E!==void 0&&isFinite(E));let Q;if(H(W)){const E=W;Q={testNumber:c.testNumber,min:E.min,max:E.max,mean:E.mean,count:E.count,stddev:E.stddev,median:E.median,q1:E.q1,q3:E.q3}}else if(ee)Q={testNumber:c.testNumber,...ee};else{const E=K();if(!E.length)continue;Q={testNumber:c.testNumber,...Vt(E)}}let M=null,B=0;if(I(c)){const E=b.get(c.testNumber);if(E)({yieldPercent:M,totalDies:B}=E);else if(j)B=j.n,M=B>0?(B-j.fail)/B*100:null;else{const X=K();let ue=0;for(const ie of X)Nt(Bt(ie,c))&&ue++;B=X.length,M=X.length>0?(X.length-ue)/X.length*100:null}}F.push({entry:c,stats:Q,specYieldPct:M,specN:B})}if(!F.length)return null;const d=new Map;for(const c of(O?C?.capability:void 0)??[])c.hasSpec&&d.set(c.testNumber,c.ppk);const v=d.size>0,h=new Set(F.map(c=>c.stats.count)).size===1?F[0].stats.count:null,y=l("div"),S=l("div",{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:x.sm}),L=h!==null?` \xB7 N=${h.toLocaleString()}`:"",A=u?.populationLabel?`Test Values (${F.length}) \u2014 ${u.populationLabel}${L}`:`Test Values (${F.length})${L}`,D=se(A);D.style.marginBottom="0",S.appendChild(D);const R=document.createElement("button");R.type="button",R.textContent="Test values CSV",Object.assign(R.style,{...me("outlined")}),G(R),R.addEventListener("click",()=>{const c=["Test","Unit","N","Min","Q1","Median","Mean","Q3","Max","StdDev"];v&&c.push("Ppk");const W=F.some(B=>B.specYieldPct!==null&&B.specN!==B.stats.count);k&&(c.push("Lo limit","Hi limit","Limit Yield %"),W&&c.push("Limit Yield N"));const j=F.some(B=>Te(B.entry));j&&c.push(De);const ee=[...Je(u,c),...et(u)],Q=[[...ee.map(B=>B.label),...c].map(he).join(",")],M=B=>Ae(B,void 0,"engineering");for(const{entry:B,stats:E,specYieldPct:X,specN:ue}of F){const ie=[...ee.map(le=>le.constant??""),B.name,B.unit??"",String(E.count),M(E.min),M(E.q1),M(E.median),M(E.mean),M(E.q3),M(E.max),M(E.stddev)];if(v){const le=d.get(B.testNumber);ie.push(le==null?"":le.toFixed(3))}k&&(ie.push(B.limitLow!==void 0?M(B.limitLow):"",B.limitHigh!==void 0?M(B.limitHigh):"",X!==null?X.toFixed(1):""),W&&ie.push(B.limitLow!==void 0||B.limitHigh!==void 0?String(ue):"")),j&&ie.push(Ne(B)),Q.push(ie.map(he).join(","))}_e(Q.join(`
2
+ `),"test-values.csv","text/csv",o)}),S.appendChild(R),y.appendChild(S);const P=l("table",{width:"100%",borderCollapse:"collapse",fontSize:T.body}),Z=document.createElement("thead"),J=document.createElement("tr"),_=["Test"];h===null&&_.push("N"),p==="full"&&_.push("Min","Q1","Median"),_.push("Mean"),p==="full"&&_.push("Q3","Max","StdDev"),v&&_.push("Ppk"),p==="full"&&k&&_.push("Lo limit","Hi limit"),k&&_.push("Limit yield");for(const c of _){const W=l("th",{textAlign:c==="Test"?"left":"right",fontWeight:"600",fontSize:T.meta,letterSpacing:fe,textTransform:"uppercase",color:Y,padding:"3px 8px 5px",borderBottom:`1px solid ${$.menuBorder}`,whiteSpace:"nowrap"},c);J.appendChild(W)}Z.appendChild(J),P.appendChild(Z);const U=document.createElement("tbody");for(const{entry:c,stats:W,specYieldPct:j,specN:ee}of F){const K=B=>Ae(B,c.unit,i),Q=document.createElement("tr"),M=(B,E="right")=>{const X=l("td",{textAlign:E,padding:`${x.xs} ${x.md}`,borderBottom:`1px solid ${$.menuBorder}`,color:$.text,whiteSpace:"nowrap"},B);Q.appendChild(X)};if(M(pt(c,c.testNumber),"left"),h===null&&M(`${W.count}`),p==="full"&&(M(K(W.min)),M(K(W.q1)),M(K(W.median))),M(K(W.mean)),p==="full"&&(M(K(W.q3)),M(K(W.max)),M(K(W.stddev))),v){const B=d.get(c.testNumber);M(B==null?"\u2014":B.toFixed(2))}p==="full"&&k&&(M(c.limitLow!==void 0?K(c.limitLow):"\u2014"),M(c.limitHigh!==void 0?K(c.limitHigh):"\u2014")),k&&M(j!==null?h!==null&&ee===h?`${j.toFixed(1)}%`:`${j.toFixed(1)}% (N=${ee})`:"\u2014"),U.appendChild(Q)}P.appendChild(U);const N=l("div",{overflowX:"auto"});N.appendChild(P);const V=ot(N,F.map(c=>({label:c.entry.name,...we(c.entry)})));if(!m)return y.appendChild(V),y;S.remove();const{outer:re}=oe(A,!0,void 0,{stateKey:"testValues",panel:m,render:c=>c.appendChild(V),control:()=>R});return re}export function buildFunctionalTestSection(e,t,i,n,o,u){const s=i??bt(e,t);if(!s?.length)return null;const p=new Set(s.map(g=>g.totalDies)).size===1?s[0].totalDies:null,r=p!==null?` \xB7 N=${p.toLocaleString()}`:"",a=l("div"),b=l("div",{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:x.sm}),f=o?.populationLabel?`Functional Tests (${s.length}) \u2014 ${o.populationLabel}${r}`:`Functional Tests (${s.length})${r}`,w=se(f);w.style.marginBottom="0",b.appendChild(w);const k=document.createElement("button");k.type="button",k.textContent="Functional CSV",Object.assign(k.style,{...me("outlined")}),G(k),k.addEventListener("click",()=>{const g=["Test","N","Pass","Fail","Pass Rate %"],h=s.some(L=>Te(L));h&&g.push(De);const y=[...Je(o,g),...et(o)],S=[[...y.map(L=>L.label),...g].map(he).join(",")];for(const L of s)S.push([...y.map(A=>A.constant??""),ut(L.label),String(L.totalDies),String(L.passDies),String(L.failDies),L.passRatePercent!==null?L.passRatePercent.toFixed(1):"",...h?[Ne(L)]:[]].map(he).join(","));_e(S.join(`
3
+ `),"functional-tests.csv","text/csv",n)}),b.appendChild(k),a.appendChild(b);const F=l("table",{width:"100%",borderCollapse:"collapse",fontSize:T.body}),H=document.createElement("thead"),I=document.createElement("tr"),O=p===null?["Test","N","Pass","Fail","Pass rate"]:["Test","Pass","Fail","Pass rate"];for(const g of O)I.appendChild(l("th",{textAlign:g==="Test"?"left":"right",fontWeight:"700",fontSize:T.body,letterSpacing:fe,textTransform:"uppercase",color:Y,padding:"3px 8px 5px",borderBottom:`1px solid ${$.menuBorder}`,whiteSpace:"nowrap"},g));H.appendChild(I),F.appendChild(H);const z=document.createElement("tbody");for(const g of s){const h=document.createElement("tr"),y=(S,L="right")=>{h.appendChild(l("td",{textAlign:L,padding:`${x.xs} ${x.md}`,borderBottom:`1px solid ${$.menuBorder}`,color:ne,whiteSpace:"nowrap"},S))};y(g.label,"left"),p===null&&y(String(g.totalDies)),y(String(g.passDies)),y(String(g.failDies)),y(g.passRatePercent!==null?`${g.passRatePercent.toFixed(1)}%`:"\u2014"),z.appendChild(h)}F.appendChild(z);const C=l("div",{overflowX:"auto"});C.appendChild(F);const d=ot(C,s);if(!u)return a.appendChild(d),a;b.remove();const{outer:v}=oe(f,!0,void 0,{stateKey:"functionalTests",panel:u,render:g=>g.appendChild(d),control:()=>k});return v}export function buildLotFunctionalSection(e,t,i,n,o){const u=i?.length?{perWaferMetadata:i.map(m=>m.wafer??{}),populationLabel:`${i.length} wafer${i.length===1?"":"s"} pooled`}:void 0,s=It(i);return s?buildFunctionalTestSection(e,t,s,n,u,o):buildFunctionalTestSection(e,t,void 0,n,u,o)}const ae={unusual:0,notable:1,info:2};function Be(e){return l("span",{display:"inline-block",width:"7px",height:"7px",borderRadius:q.pill,background:ge(e),flexShrink:"0"})}function tt(e,t){let i=e.summary;if(t){const n=[" has "," have "].find(o=>i.startsWith(`${t}${o}`));n?i=i.slice(t.length+n.length):i.startsWith(`${t} `)&&(i=i.slice(t.length+1))}return i=de(i),i.length?i[0].toUpperCase()+i.slice(1):i}function nt(e){return it(e.map(t=>({label:t.variable.label,...we(t.variable)})))}function it(e){const t=ft(e);return t?l("div",{fontSize:T.body,color:Y,marginTop:x.sm,lineHeight:te.base},t):null}function ot(e,t){const i=it(t);if(!i)return e;const n=l("div",{});return n.append(e,i),n}export function buildFindingsSection(e,t,i,n,o=!1){if(!e.length)return null;const u=e.some(d=>d.severity==="unusual"||d.severity==="notable"),s=u?e.filter(d=>d.severity!=="info").length.toString():void 0,{outer:m,content:p}=o?(()=>{const d=l("div");return{outer:d,content:d}})():oe(`Findings (${e.length})`,u,s);function r(d){return d.reduce((v,g)=>ae[g.severity]<ae[v]?g.severity:v,"info")}function a(d){const v=new Map;for(const h of d){const y=`${h.comparison.family}\0${h.comparison.left}`,S=v.get(y)??[];S.push(h),v.set(y,S)}const g=[...v.entries()].map(([h,y])=>{const S=[...y].sort((L,A)=>ae[L.severity]-ae[A.severity]);return{key:h,findings:S,worst:r(S)}});return g.sort((h,y)=>ae[h.worst]-ae[y.worst]),g}function b(d,v){const h={ring:"Ring",quadrant:"Quadrant",sector:"Sector","reticle-position":"Reticle","test-site":"Test site",cluster:"Cluster","edge-arc":"Edge arc",wafer:"Wafer"}[d]??d;return v.toLowerCase().startsWith(h.toLowerCase())?v:`${h}: ${v}`}const f=e.filter(d=>d.comparison.family==="spatial-pattern"),w=new Set([...f.flatMap(d=>d.relatedIds??[]),...e.flatMap(d=>d.absorbedIds??[])]),k=e.filter(d=>d.comparison.family!=="spatial-pattern"&&!w.has(d.id)),F=a(k),H=()=>[...F.flatMap(d=>d.findings),...f.flatMap(d=>e.filter(v=>d.relatedIds?.includes(v.id)))];function I(d,v=!1,g){const h=n===d.id,y=document.createElement("button");return y.type="button",y.dataset.wmapFinding=d.id,y.textContent=tt(d,g),ce(y,vt(d)),y.setAttribute("aria-current",h?"true":"false"),Object.assign(y.style,{border:`1px solid ${$.menuBorder}`,borderLeft:`3px solid ${ge(d.severity)}`,background:h?$.bgActive:$.menuBg,borderRadius:q.container,padding:v?"6px 10px":"8px 10px",textAlign:"left",fontSize:v?"10px":"11px",fontWeight:h?"600":"400",color:$.text,cursor:"pointer",width:"100%",marginBottom:x.xs}),G(y,"bare"),y.addEventListener("click",()=>i(d,y)),y}const O=de(Ct(e)??"");if(O){const d=l("div",{background:$.bgActive,borderRadius:q.container,padding:`${x.md} ${x.lg}`,marginBottom:x.md,display:"flex",gap:x.md,alignItems:"flex-start"}),v=l("span",{flex:"1",fontSize:T.body,lineHeight:te.base,color:$.text},O);d.appendChild(v);const g=l("button",{flexShrink:"0",border:"none",background:"none",fontSize:T.body,color:$.icon,cursor:"pointer",padding:"0",lineHeight:te.base,whiteSpace:"nowrap"},"Detail \u25B8");g.type="button",G(g,"bare"),g.addEventListener("click",()=>{const h=Oe({title:"Findings Summary",onClose:()=>{},anchor:g}),y=l("p",{fontSize:"16px",lineHeight:te.base,color:$.text,padding:`${x.xxl} ${x.xxxl} ${x.xxl}`,margin:"0",borderBottom:`1px solid ${$.menuBorder}`,flexShrink:"0"},O);h.contentWrap.appendChild(y);const S=l("div",{overflowY:"auto",padding:`${x.xxl} ${x.xxxl}`,flex:"1"}),L=(D,R)=>{const P=l("div",{display:"flex",alignItems:"center",gap:"7px",fontSize:T.sub,fontWeight:"600",color:ne,marginTop:x.lg,marginBottom:x.xs});return P.appendChild(Be(D)),P.appendChild(l("span",{},R)),P};for(const D of f){S.appendChild(L(D.severity,D.comparison.left)),S.appendChild(l("div",{fontSize:T.body,color:$.text,padding:"4px 0 4px 15px",marginBottom:x.xxs},de(D.summary)));const R=e.filter(P=>D.relatedIds?.includes(P.id));for(const P of R)S.appendChild(l("div",{fontSize:T.body,color:Y,padding:"2px 0 2px 23px",marginBottom:x.xxs},de(P.summary)))}for(const D of F){const[R,P]=D.key.split("\0");S.appendChild(L(D.worst,b(R,P)));for(const Z of D.findings)S.appendChild(l("div",{fontSize:T.body,color:$.text,padding:"4px 0 4px 15px",marginBottom:x.xxs},tt(Z,P)))}const A=nt(H());A&&S.appendChild(A),h.contentWrap.appendChild(S),Object.assign(h.contentWrap.style,{flexDirection:"column",overflow:"hidden"})}),d.appendChild(g),p.appendChild(d)}let z=!0;for(const d of f){z||p.appendChild(l("div",{height:"1px",background:$.separator,margin:"4px 0"})),z=!1;const v=e.filter(L=>d.relatedIds?.includes(L.id)),g=v.length>0,h=l("div",{position:"relative",marginBottom:g?"2px":"4px"}),y=n===d.id,S=document.createElement("button");if(S.type="button",S.dataset.wmapFinding=d.id,Object.assign(S.style,{border:`1px solid ${$.menuBorder}`,borderLeft:`3px solid ${ge(d.severity)}`,background:y?$.bgActive:$.menuBg,borderRadius:q.container,padding:"8px 32px 8px 10px",textAlign:"left",fontSize:T.body,fontWeight:y?"600":"500",color:$.text,cursor:"pointer",width:"100%"}),S.textContent=de(d.summary),ce(S,d.summary),S.setAttribute("aria-current",y?"true":"false"),G(S,"bare"),S.addEventListener("click",()=>i(d,S)),h.appendChild(S),g){const L=l("div",{display:"none",paddingLeft:"12px",marginBottom:x.xs});for(const R of v)L.appendChild(I(R,!0));h.appendChild(L);let A=!1;const D=l("button",{position:"absolute",top:"50%",right:"8px",transform:"translateY(-50%)",border:"none",background:"none",fontSize:T.body,color:$.icon,cursor:"pointer",padding:`${x.xxs} ${x.xs}`,lineHeight:te.none},"\u25B8");G(D,"bare"),D.type="button",ce(D),D.setAttribute("aria-label","Show supporting findings"),D.setAttribute("aria-expanded","false"),D.addEventListener("click",R=>{R.stopPropagation(),A=!A,L.style.display=A?"block":"none",D.textContent=A?"\u25BE":"\u25B8";const P=A?"Hide supporting findings":"Show supporting findings";D.setAttribute("aria-label",P),D.setAttribute("aria-expanded",String(A))}),h.appendChild(D)}p.appendChild(h)}for(const d of F){z||p.appendChild(l("div",{height:"1px",background:$.separator,margin:"4px 0"})),z=!1;const[v,g]=d.key.split("\0"),h=l("div",{display:"flex",alignItems:"center",gap:x.sm,fontSize:T.body,fontWeight:"600",color:ne,margin:"2px 0 4px"});h.appendChild(Be(d.worst)),h.appendChild(l("span",{},b(v,g))),p.appendChild(h);for(const y of d.findings)p.appendChild(I(y,!1,g))}const C=nt(H());return C&&p.appendChild(C),m}const qt=[{value:"",label:"All kinds"},{value:"yield",label:"Yield"},{value:"hardBin",label:"Hard bin"},{value:"softBin",label:"Soft bin"},{value:"test",label:"Test value"},{value:"functionalTest",label:"Functional test"},{value:"spatialPattern",label:"Spatial pattern"}],Gt=[{value:"",label:"All regions"},{value:"ring",label:"Ring"},{value:"quadrant",label:"Quadrant"},{value:"reticle-position",label:"Reticle position"},{value:"test-site",label:"Test site"},{value:"wafer",label:"Wafer"},{value:"sector",label:"Sector"},{value:"cluster",label:"Cluster"},{value:"edge-arc",label:"Edge arc"},{value:"spatial-pattern",label:"Spatial pattern"}],Ut=["unusual","notable","info"],Qt={unusual:"Unusual",notable:"Notable",info:"Info"};function Xt(e,t,i){const n=l("div",{display:"flex",flexWrap:"wrap",alignItems:"center",gap:x.lg,marginBottom:x.lg,paddingBottom:"10px",borderBottom:`1px solid ${$.separator}`}),o={unusual:0,notable:0,info:0};for(const r of e)o[r.severity]++;const u=Ut.filter(r=>o[r]>0),s=new Set(t.severity===void 0?u:Array.isArray(t.severity)?t.severity:[t.severity]),m=l("div",{display:"flex",gap:x.xs,flexWrap:"wrap"});for(const r of u){const a=document.createElement("button");a.type="button";const b=()=>{const f=s.has(r);a.setAttribute("aria-pressed",f?"true":"false"),Object.assign(a.style,{display:"inline-flex",alignItems:"center",gap:"5px",border:`1px solid ${$.menuBorder}`,borderRadius:q.pill,background:f?$.bgActive:"none",opacity:f?"1":"0.5",color:$.text,fontSize:T.body,padding:`${x.xxs} ${x.md}`,cursor:"pointer"}),a.dataset.on=f?"true":"false"};a.appendChild(Be(r)),a.appendChild(l("span",{},`${Qt[r]} ${o[r]}`)),ce(a,()=>s.has(r)?"Click to hide these findings":"Click to show these findings"),b(),G(a,"bare"),a.addEventListener("click",()=>{s.has(r)?s.delete(r):s.add(r),t.severity=s.size===u.length?void 0:[...s],i()}),m.appendChild(a)}n.appendChild(m);const p=t.kind!==void 0||t.family!==void 0;return(e.length>=Zt||p)&&(n.appendChild(Pe("Kind:",qt,t.kind??"",r=>{t.kind=r||void 0,i()},{maxWidth:"130px"})),n.appendChild(Pe("Region:",Gt,t.family??"",r=>{t.family=r||void 0,i()},{maxWidth:"150px"}))),n}const Zt=8;function Jt(e,t){const i=l("div",{display:"flex",flexDirection:"column",gap:x.xs,padding:x.md,marginBottom:x.md,background:$.bgHover,borderRadius:q.control},void 0,t);if(i.appendChild(l("div",{fontSize:T.body,color:$.value},e.message,t)),e.detail&&i.appendChild(l("div",{fontSize:T.meta,color:Y},e.detail,t)),e.actionLabel&&e.onAction){const n=l("button",me("outlined"),e.actionLabel,t);n.type="button",n.style.alignSelf="flex-start",n.style.marginTop=x.xs,G(n),n.addEventListener("click",e.onAction),i.appendChild(n)}return i}export function buildFindingsSectionWithFilter(e,t,i,n,o,u,s){if(!e.findings.length&&!s)return null;const m=e.findings.some(k=>k.severity==="unusual"||k.severity==="notable"),p=m?e.findings.filter(k=>k.severity!=="info").length.toString():void 0,r=u?.ownerDocument??document,{outer:a,content:b}=oe(`Findings (${e.findings.length})`,m||!!s,p,{stateKey:"findings",panel:u});if(s&&b.appendChild(Jt(s,r)),!e.findings.length)return a;b.appendChild(Xt(e.findings,n,o));const f=St(e,n);if(!f.length)return b.appendChild(l("div",{color:Y,fontSize:T.body,textAlign:"center",padding:`${x.xxl} ${x.md}`},"No findings match the current filter.")),a;const w=buildFindingsSection(f,e,t,i,!0);return w&&b.appendChild(w),a}export function buildLotTestSection(...e){return be(buildLotTestSectionSteps(...e))}export function*buildLotTestSectionSteps(e,t,i,n,o,u,s,m="full"){const p=n?.length?{perWaferMetadata:n.map(a=>a.wafer??{}),populationLabel:`${n.length} wafer${n.length===1?"":"s"} pooled`}:void 0;let r;if(n?.length&&n.every(a=>a.stats.perTestStats!==void 0)){const a=new Map;for(const b of n)for(const f of b.stats.perTestStats??[]){const w=a.get(f.testNumber);w?(w.n+=f.count,w.sum+=f.mean*f.count,w.min=Math.min(w.min,f.min),w.max=Math.max(w.max,f.max)):a.set(f.testNumber,{n:f.count,sum:f.mean*f.count,min:f.min,max:f.max})}r={perTestStats:[...a.entries()].map(([b,f])=>({testNumber:b,count:f.n,min:f.min,max:f.max,mean:f.sum/f.n}))}}if(n?.length&&n.every(a=>a.stats.testSpecYield!==void 0)){const a=new Map;for(const b of n)for(const f of b.stats.testSpecYield??[]){const w=a.get(f.testNumber);w?(w.passDies+=f.passDies,w.totalDies+=f.totalDies):a.set(f.testNumber,{passDies:f.passDies,totalDies:f.totalDies})}r={...r,testSpecYield:[...a.entries()].map(([b,f])=>({testNumber:b,totalDies:f.totalDies,yieldPercent:f.totalDies>0?f.passDies/f.totalDies*100:null}))}}return yield*buildTestSectionSteps(e,t,i,r,o,p,u,s,m)}export function createSummaryPanelEl(e,t,i=document){const n=e==="top"||e==="bottom",o=l("div",{background:Ot,color:$.text,fontVariantNumeric:"tabular-nums",border:je,borderRadius:q.container,padding:x.xl,overflowY:"auto",overflowX:n?"auto":"hidden",flexShrink:"0",boxSizing:"border-box",fontFamily:T.family,fontSize:T.sub,boxShadow:ze.panel},void 0,i);return e==="right"&&(o.style.marginRight=t),e==="left"&&(o.style.marginLeft=t),e==="bottom"&&(o.style.marginBottom=t),n?(o.style.height="180px",o.style.width="100%"):(o.style.width="300px",o.style.maxHeight="100%"),o}export function wrapWithSummaryPanel(e,t,i){const n=i==="top"||i==="bottom",o=l("div",{display:"flex",flexDirection:n?"column":"row",gap:x.md,width:"100%",height:"100%",flex:"1 1 0",minHeight:"0",boxSizing:"border-box",alignItems:n?"flex-start":"stretch"});return e.style.flex="1 1 0",e.style.minWidth="0",e.style.minHeight="0",i==="right"||i==="bottom"?(o.appendChild(e),o.appendChild(t)):(o.appendChild(t),o.appendChild(e)),o}function st(e){return l("div",{fontSize:T.heading,fontWeight:"600",color:ne,marginBottom:x.lg},e)}function Ce(e,t){const i=l("button",me("outlined"),e);return i.type="button",G(i),i.addEventListener("click",t),i}function at(...e){const t=e.filter(n=>!!n);if(!t.length)return null;const i=l("div",{display:"flex",flexWrap:"wrap",gap:x.sm,marginBottom:x.lg});for(const n of t)i.appendChild(n);return i}function rt(e,t,i,n,o,u,s,m,p,r,a){const b=e.ownerDocument,f=Oe({title:"Die list",onClose:()=>{},anchor:e,ownerDocument:b});f.contentWrap.style.padding="14px 16px";const w=At(t,i,{...s,title:n,onSaveText:m,waferMetadata:o,metadataFields:u,extraColumn:p,getWafer:r,ringCount:a,ownerDocument:b});w&&f.contentWrap.appendChild(w)}export function renderWaferSummaryContent(...e){be(renderWaferSummaryContentSteps(...e))}export function*renderWaferSummaryContentSteps(e,t){const i=e.scrollTop;e.innerHTML="";const{wafer:n,dies:o,yieldSummary:u,dataCoverage:s,hbinDefs:m,sbinDefs:p,testDefs:r,statsSummary:a,passBins:b=[1],ringCount:f=4,binColors:w,plotMode:k,fallbackFormat:F,onFindingClick:H,activeFindingId:I=null,findingsFilter:O,onFindingsFilterChange:z,findingsNotice:C,onSaveText:d,metadataFields:v,dieListOptions:g,metadataShownElsewhere:h}=t;e.appendChild(st("Wafer Summary"));const y=t.warnings??Ie({statsSummary:a});y.length&&e.appendChild($e(y,e.ownerDocument));const S=u&&s?Ce("Summary report",()=>{Ye(xt({wafer:n,dies:o,yield:u,dataCoverage:s,hbinDefs:m,sbinDefs:p,testDefs:r,passBins:b,ringCount:f},a),{anchor:e})}):null,L=(g?.enabled??!0)&&o.length?Ce("View die list",()=>{rt(e,o,r,`Die list \u2014 ${o.length} dies`,n.metadata,v,g,d,void 0,()=>n,f)}):null,A=at(S,L);A&&e.appendChild(A);let D=!0;const R=_=>{_&&(D||e.appendChild(Ge()),D=!1,e.appendChild(_))},P=a?.stats.isLotStack?a.stats:void 0,Z=P?.lotSize!==void 0?{lotSize:P.lotSize,aggrMethod:Dt(P.aggregationMethod)}:void 0;h||R(buildMetadataInfoSection([{metadata:n.metadata??void 0}],Z)),u&&s&&R(buildYieldSection(u,s,b)),yield,a&&H&&O&&z&&(R(buildFindingsSectionWithFilter(a,H,I,O,z,e,C)),yield),R(buildBinBreakdownSection({dies:o,hbinDefs:m,sbinDefs:p,binColors:w,hardCounts:a?.stats.hardBinCounts,softCounts:a?.stats.softBinCounts,plotMode:k,passBins:b,panel:e})),yield,R(buildRegionYieldPanelSection({diesByWafer:[o],allWafers:[n],ringCount:f,passBins:b,panel:e})),yield;const J=n.metadata?{waferMetadata:n.metadata}:void 0;R(yield*buildTestSectionSteps(o,r,F,a?.stats,d,J,[{dies:o}],e,"compact")),yield,R(buildFunctionalTestSection(o,r,a?.stats.functionalYield,d,J,e)),e.appendChild(l("div",{height:"12px",flexShrink:"0"})),e.scrollTop=i}export function reportMapsFromItems(e,t,i){const n=[];return e.forEach((o,u)=>{!o?.wafer||!o.dies||n.push({...o,wafer:o.wafer,dies:o.dies,label:ve(o,u),passBins:[...Se(o,t)],ringCount:o.ringCount??i})}),n}export function renderLotSummaryContent(...e){be(renderLotSummaryContentSteps(...e))}export function*renderLotSummaryContentSteps(e,t){const i=e.scrollTop;e.innerHTML="";const{lotSummary:n,items:o,hbinDefs:u,sbinDefs:s,testDefs:m,passBins:p=[1],ringCount:r=4,binColors:a,plotMode:b,fallbackFormat:f,onFindingClick:w,activeFindingId:k=null,onWaferClick:F,findingsFilter:H,onFindingsFilterChange:I,findingsNotice:O,onSaveText:z,dieListOptions:C,findingsFor:d}=t;e.appendChild(st(`Summary \u2014 ${Tt(Me(n.perWafer.map(N=>N.summary.wafer)))}`));const v=t.warnings??Ie({lotStatsSummary:n});v.length&&e.appendChild($e(v,e.ownerDocument));const g=Ce("Summary report",()=>{Ye(yt(reportMapsFromItems(o,p,r)),{anchor:e})}),h=[],y=[],S=[],L=[],A=[],D=new WeakMap,R=new WeakMap;for(let N=0;N<o.length;N++){yield;const V=o[N];if(!V){y.push([]);continue}V.wafer&&(h.push(V.wafer),L.push(V.dies??[]),A.push(Se(V,p)));const re=V.dies??[],c=ve(V,N);for(const W of re)D.set(W,c),V.wafer&&R.set(W,V.wafer);y.push(re);for(const W of re)S.push(W)}const P=C?.enabled??!0?Ce("View die list",()=>{S.length&&rt(e,S,m,`Die list \u2014 ${S.length} dies across ${o.length} wafer${o.length===1?"":"s"}`,Fe(o.filter(N=>!!N).map(N=>({metadata:N.wafer?.metadata}))),o.find(N=>N?.metadataFields?.length)?.metadataFields,C,z,{label:"Wafer",get:N=>D.get(N)},N=>R.get(N),r)}):null,Z=at(g,P);Z&&e.appendChild(Z);const J=o.map(N=>N?.statsSummary).filter(N=>!!N);let _=!0;const U=N=>{N&&(_||e.appendChild(Ge()),_=!1,e.appendChild(N))};U(buildLotOverviewSection(n,J)),yield,w&&H&&I&&(U(buildFindingsSectionWithFilter(n,w,k,H,I,e,O)),yield),U(buildPerWaferYieldSection(n,o,F,e,d)),yield,U(buildBinBreakdownSection({dies:S,hbinDefs:u,sbinDefs:s,plotMode:b,passBins:p,panel:e,binColors:a??kt(o.flatMap(N=>N?[{dies:N.dies??[],passBins:Se(N,p)}]:[]),{hbinDefs:u,sbinDefs:s}).colors})),yield,U(buildRegionYieldPanelSection({diesByWafer:L,allWafers:h,ringCount:r,passBins:N=>A[N],panel:e})),yield,m?.length&&(U(yield*buildLotTestSectionSteps(S,m,f,J,z,y.map(N=>({dies:N})),e,"compact")),yield,U(buildLotFunctionalSection(S,m,J,z,e))),e.appendChild(l("div",{height:"12px",flexShrink:"0"})),e.scrollTop=i}
@@ -1 +1 @@
1
- import{fontPx as Wt}from"./toolbar.js";import{findTestDef as We,buildMapTitle as Fe}from"../renderer/buildView.js";import{niceStep as Ft}from"../renderer/axisTicks.js";import{sortBinsForDisplay as lo}from"../stats/binPareto.js";import{affineInvert as io,affineVector as Oe}from"../core/transforms.js";import{compareNatural as ao,maxOf as zt,minOf as Ne}from"../core/utils.js";import{resolveValueColorFn as co}from"../renderer/colorSchemes.js";import{NO_DATA_FILL as ro}from"../renderer/colorMap.js";import{SPEC_PASS_FILL as Ee,SPEC_FAIL_LOW as fo,SPEC_FAIL_HIGH as He,contrastTextColor as Ye}from"../renderer/colorMap.js";import{fmt as Xe,fmtColorbarAxis as Ge}from"../renderer/fmt.js";import{resolveCanvasTheme as ho}from"./canvasTheme.js";import{hitGridDims as go}from"./hitGrid.js";function $e(g,e,X,x,c){g.moveTo(e,X+c*x),g.lineTo(e-x*.9,X-c*x*.6),g.lineTo(e+x*.9,X-c*x*.6),g.closePath()}const mo=new Set(["value","stackedValues","stackedBins","stackedSoftBins"]),uo=new Set(["hardBin","softBin","metadata"]),v=()=>`${Wt(-2)}px system-ui, sans-serif`,we=3,Jt=2,po=6,xo=20,bo=()=>`600 ${Wt()}px system-ui, sans-serif`,Ve=36,ue=()=>`${Wt(-1)}px system-ui, sans-serif`,Mo=()=>`600 ${Wt(-1)}px system-ui, sans-serif`,Zt=128,yo=()=>`${Wt(-2)}px system-ui, sans-serif`,Ue=4,E=17,$=11;export const BIN_LEGEND_W=110,BIN_LEGEND_W_COMPACT=64,BIN_LEGEND_ADAPT_COMPACT=280,BIN_LEGEND_ADAPT_FLOATING=180,BIN_LEGEND_MIN_CANVAS_W=150,BIN_LEGEND_MIN_CANVAS_H=120;const jt=28,ut=5,ht=8,Ke=15,qe=12,ze=6;export function toCanvas(g,e,X={}){return drawMapCanvas(g,e,X)}export function drawMapCanvas(g,e,X={}){const x=ho(g.parentElement??g),{padding:c=16,showColorbar:V=!0,markFailingDies:U=!1,colorbarWidth:D=16,background:pt=x.background,legendPosition:tt="default",legendOffset:xt,showAxes:bt=!1,diePitchMm:q,viewport:Z,activeBin:Y,hoverBin:j,fallbackFormat:Mt,minRightReserve:Ot,hbinDefs:ct,sbinDefs:yt,metadataFields:Tt,showTitle:z=!0}=X,F=Math.floor(g.clientWidth||g.width),G=Math.floor(g.clientHeight||g.height),St=F>=BIN_LEGEND_MIN_CANVAS_W&&G>=BIN_LEGEND_MIN_CANVAS_H,At=V&&St&&mo.has(e.plotMode)&&e.passFailDisplay==="off",Rt=V&&St&&uo.has(e.plotMode),ot=V&&St&&e.plotMode==="value"&&(e.passFailDisplay==="spec"&&e.specCounts!==void 0||e.passFailDisplay==="test"&&e.passFailCounts!==void 0),nt=Rt||ot,Nt=Rt&&e.plotMode!=="metadata"&&e.binCounts?lo(e.binCounts.entries(),e.plotMode==="softBin"?e.binColors.pass.soft:e.binColors.pass.hard):[],Et=Rt&&e.plotMode==="metadata"&&e.metadataCounts?[...e.metadataColorMap?.keys()??[...e.metadataCounts.keys()].sort(ao)].map(o=>[o,e.metadataCounts.get(o)??0]):[],st=[];if(ot&&e.passFailDisplay==="test"){const o=e.passFailCounts;st.push({key:-1,color:Ee,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),st.push({key:-2,color:He,label:"Fail",compactLabel:"Fail",count:o.fail,tooltip:`Fail \xB7 ${o.fail} dies`})}else if(ot){const o=e.specCounts,f=We(e.testDefs,e.activeTest);st.push({key:-1,color:Ee,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),f?.limitHigh!==void 0&&st.push({key:-2,color:He,label:"Fail high",compactLabel:"Fail hi",count:o.failHigh,tooltip:`Fail high \xB7 ${o.failHigh} dies`}),f?.limitLow!==void 0&&st.push({key:-3,color:fo,label:"Fail low",compactLabel:"Fail lo",count:o.failLow,tooltip:`Fail low \xB7 ${o.failLow} dies`})}const Ht=ot?st.length:e.plotMode==="metadata"?Et.length:Nt.length,u=(g.ownerDocument.defaultView??window).devicePixelRatio??1;if(F<=0||G<=0)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const k=tt!=="default"?tt:F<BIN_LEGEND_ADAPT_FLOATING?"floating":F<BIN_LEGEND_ADAPT_COMPACT?"compact":"default",dt=k==="default"||k==="compact",pe=k==="left",Qt=k==="bottom",_t=k==="top",Ct=k==="floating",Yt=k==="compact"||k==="floating"?BIN_LEGEND_W_COMPACT:BIN_LEGEND_W,xe=Math.floor((G-2*c)/E),be=Ht>xe?xe-1:Ht,Me=nt&&Qt?be*E:0,vt=nt&&_t?be*E:0,te=e.plotMode==="stackedBins"||e.plotMode==="stackedSoftBins",ee=We(e.testDefs,e.activeTest),ye=te?"Count":ee?.name??(e.activeTest!=null?`Test ${e.activeTest}`:void 0),Te=te?void 0:ee?.unit,[Bt,Pt]=e.valueRange,oe=o=>String(Math.round(o)),Je=e.logScale||e.allIntegerValues?void 0:Ft(Math.max(0,Pt-Bt)*Ve/Math.max(1,G))||void 0,ne=e.allIntegerValues?oe:Ge(Pt,ye,Te,Mt,Je).edgeFmt;let se=0;if(At){const o=g.getContext("2d");o.font=v();const f=[ne(Bt),ne(Pt)];Bt<0&&f.push(ne(-Math.max(Math.abs(Bt),Math.abs(Pt))));for(const n of f)se=Math.max(se,o.measureText(n).width)}const Se=Math.max(xo,Math.ceil(se)+we+Jt+po-c),le=At?D+Se+8:nt&&dt?Yt:0,ie=nt&&pe?Yt:0,ae=bt?32:0,Xt=bt?36:0,Ze=Ot!=null?Math.max(le,Ot):le,je=F-2*c-Ze-Xt-ie,Le=G-2*c-ae-Me-vt;g.width=Math.round(F*u),g.height=Math.round(G*u);const t=g.getContext("2d");t.scale(u,u),t.fillStyle=pt,t.fillRect(0,0,F,G);const K=e.hoverPoints;if(!K.length)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const Gt=e.rectangles[0],ce=Gt?Gt.width/2:0,re=Gt?Gt.height/2:0,$t=e.dieBounds,ke=($t?.minX??0)-ce,Qe=($t?.maxX??0)+ce,ve=($t?.minY??0)-re,Ae=($t?.maxY??0)+re,Re=Qe-ke,_e=Ae-ve;let lt,it,A;if(Z)({originX:lt,originY:it,ppm:A}=Z);else{const f=e.notchDir,n=f&&f.y>.1?13:0,a=f&&f.y<-.1?13:0,r=f&&f.x<-.1?13:0,h=f&&f.x>.1?13:0,d=je-r-h,s=Le-n-a;A=Math.min(d/Re,s/_e),lt=c+Xt+ie+r+(d-Re*A)/2-ke*A,it=c+vt+n+(s-_e*A)/2+Ae*A}const wt=Z?.snapDist??Math.max(ce,re,1)*1.5,Vt=lt+e.waferCenter.x*A,to=it-e.waferCenter.y*A,fe=e.waferRadius*A,rt=o=>{const f=Math.abs(o-to);return f>=fe?0:Math.sqrt(fe*fe-f*f)},gt=(o,f,n,a,r,h,d=bo(),s=x.text)=>{if(!o)return;t.save(),t.fillStyle=s,t.font=d,t.textAlign=a,t.textBaseline=r;const p=a==="right"?f-h:h-f;let l=o;if(p>8&&t.measureText(l).width>p){for(;l.length>1&&t.measureText(l+"\u2026").width>p;)l=l.slice(0,-1);l=l+"\u2026"}p>8&&t.fillText(l,f,n),t.restore()};t.save(),t.setTransform(A*u,0,0,-A*u,lt*u,it*u);const mt=1/A,eo=1/(A*u);if(e.rectangles.length>0){const o=new Map;for(const n of e.rectangles){const a=String(n.fill);let r=o.get(a);r||(r=[],o.set(a,r)),r.push(n)}for(const[n,a]of o){t.beginPath();for(const r of a)t.rect(r.x-r.width/2,r.y-r.height/2,r.width,r.height);t.fillStyle=n,t.fill()}t.strokeStyle="rgba(0,0,0,0.18)",t.lineWidth=.5*eo,t.beginPath();for(const n of e.rectangles)t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height);if(t.stroke(),U){const n=e.rectangles.filter(a=>a.binFail);if(n.length>0){const a=new Map;for(const r of n){const h=Ye(String(r.fill));let d=a.get(h);d||(d=[],a.set(h,d)),d.push(r)}t.save(),t.lineCap="butt";for(const[r,h]of a){t.strokeStyle=r,t.globalAlpha=.55,t.lineWidth=Math.max(.6*mt,Math.min(h[0].width,h[0].height)*.1);for(const d of h){const s=d.width/2,p=d.height/2,l=Math.max(1.6*mt,Math.min(d.width,d.height)/3);t.save(),t.beginPath(),t.rect(d.x-s,d.y-p,d.width,d.height),t.clip(),t.beginPath();for(let M=-(s+p);M<=s+p;M+=l)t.moveTo(d.x-s+M,d.y-p),t.lineTo(d.x-s+M+d.height,d.y+p);t.stroke(),t.restore()}}t.restore()}}const f=e.rectangles.filter(n=>n.specMark);if(f.length>0){const n=new Map;for(const r of f){const h=Ye(String(r.fill)),d=`${r.specMark}|${h}`;let s=n.get(d);s||(s=[],n.set(d,s)),s.push(r)}const a=2.5*mt;t.lineJoin="round";for(const[r,h]of n){const[d,s]=r.split("|"),p=s==="#000000"?"#ffffff":"#000000",l=d==="failHigh"?1:-1,M=Math.min(h[0].width,h[0].height),H=Math.max(2.5*mt,M*.3);t.beginPath();for(const I of h)$e(t,I.x,I.y,H,l);t.strokeStyle=p,t.lineWidth=a,t.stroke(),t.fillStyle=s,t.fill()}}}for(const o of e.overlays){t.beginPath();for(const f of o.points){for(let n=0;n<f.length;n++)n===0?t.moveTo(f[n].x,f[n].y):t.lineTo(f[n].x,f[n].y);o.closed&&t.closePath()}o.fill&&!o.fill.startsWith("rgba(0,0,0,0)")&&(t.fillStyle=o.fill,t.fill()),o.kind==="ring-boundary"||o.kind==="quadrant-boundary"||o.kind==="reticle"?(t.strokeStyle="rgba(0,0,0,0.45)",t.lineWidth=3*mt,t.stroke(),t.strokeStyle="rgba(255,255,255,0.8)",t.lineWidth=1*mt,t.stroke()):(t.strokeStyle=o.lineColor,t.lineWidth=o.lineWidth*mt,t.stroke())}if(t.restore(),e.notchDir){const o=lt+e.waferCenter.x*A,f=it-e.waferCenter.y*A,n=e.notchDir.x,a=-e.notchDir.y,r=e.waferRadius*A,h=4,d=9,s=5,p=o+n*(r+h),l=f+a*(r+h),M=p+n*d,H=l+a*d,I={x:-a,y:n},L=c+Xt+ie,w=F-c-le,J=c+vt,at=G-c-Me-ae;t.save(),t.beginPath(),t.rect(L,J,w-L,at-J),t.clip(),t.beginPath(),t.moveTo(p,l),t.lineTo(M+I.x*s,H+I.y*s),t.lineTo(M-I.x*s,H-I.y*s),t.closePath(),t.fillStyle=x.text,t.fill(),t.restore()}t.save(),t.textAlign="center",t.textBaseline="middle";let Ce=0;if(e.rectangles.length>0){let o=1;for(const h of e.texts)h.role!=="indicator"&&h.text.length>o&&(o=h.text.length);const f=e.rectangles[0].width*A,n=e.rectangles[0].height*A,a=Math.min(f,n),r=f/o;Ce=Math.max(8,Math.min(64,Math.round(Math.min(a*.55,r*1.8))))}for(const o of e.texts){const f=lt+o.x*A,n=it-o.y*A;t.font=`${o.role==="indicator"?o.fontSize:Ce}px system-ui, sans-serif`,t.fillStyle=o.color,t.fillText(o.text,f,n)}if(t.restore(),bt&&To(t,F,G,lt,it,A,c,ae,Xt,q,e.gridToScreen,e.rotation,x),At){const o=co(e.valueColorScheme,e.reverseValueScheme),f=Se,n=Le,a=Math.round(n*.75),r=c+Math.round((n-a)/2),h=F-c-D-f,d=Bt,s=Pt,p=s-d,l=e.plotMode==="stackedSoftBins"?yt:ct,{primary:M,secondary:H,note:I}=z?Fe(e,Mt,l):{primary:"",secondary:"",note:void 0};if(z){const i=Math.max(r-6,c+11),P=Vt+Math.max(rt(i),rt(i-12))+8;gt(M,F-c,i,"right","bottom",P)}let L=r+a+4;const w=i=>Vt+Math.max(rt(i),rt(i+12))+8,J=e.logScale&&d>0?Math.log10(d):0,at=e.logScale&&s>0?Math.log10(s)-J:1,_=i=>e.logScale?(1-(Math.log10(i)-J)/at)*a:(1-(i-d)/p)*a;for(let i=0;i<Zt;i++){const P=1-i/(Zt-1),W=r+i/Zt*a,m=a/Zt+1;t.fillStyle=o(P),t.fillRect(h,W,D,m)}t.strokeStyle="rgba(0,0,0,0.25)",t.lineWidth=.5,t.strokeRect(h,r,D,a),t.fillStyle=x.text,t.font=v(),t.textAlign="left",t.strokeStyle="rgba(0,0,0,0.35)",t.lineWidth=.5;const C=we,It=Ve,et=14;let O;const B=e.logScale&&at>0?So(d,s,a,It,et,J,at):e.allIntegerValues?(()=>{const i=Math.max(1,Ft(p*It/a)),P=[],W=Math.ceil(d/i)*i;for(let m=W;m<=s+i*1e-6;m+=i){const R=(1-(m-d)/p)*a;R>et&&R<a-et&&P.push(Math.round(m))}return P})():(()=>{const i=p>0?Ft(p*It/a):0,P=[];if(i>0){O=i;const W=Math.ceil(d/i)*i;for(let m=W;m<=s+i*1e-6;m+=i){const R=(1-(m-d)/p)*a;R>et&&R<a-et&&P.push(m)}}return P})(),b=ee,S=te,y=Ge(s,ye,Te,Mt,O),N=e.allIntegerValues?oe:y.tickFmt,T=e.allIntegerValues?oe:y.edgeFmt;t.textBaseline="middle";for(const i of B){const P=r+_(i);t.beginPath(),t.moveTo(h+D,P),t.lineTo(h+D+C,P),t.stroke(),t.fillText(N(i),h+D+C+Jt,P)}if(t.beginPath(),t.moveTo(h+D,r),t.lineTo(h+D+C,r),t.stroke(),t.textBaseline="top",t.fillText(T(s),h+D+C+Jt,r),t.beginPath(),t.moveTo(h+D,r+a),t.lineTo(h+D+C,r+a),t.stroke(),t.textBaseline="bottom",t.fillText(T(d),h+D+C+Jt,r+a),!S&&b&&(b.limitLow!==void 0||b.limitHigh!==void 0)){const i=[],P=e.colorbarRangeMode==="spec";for(const[W,m]of[[b.limitLow,"LSL"],[b.limitHigh,"USL"]]){if(W===void 0||e.logScale&&W<=0)continue;const R=_(W);!P&&(R<-et||R>a+et)||i.push({value:W,label:m,py:Math.max(0,Math.min(a,R))})}if(i.length>0){t.save(),t.font=v(),t.textAlign="right",t.textBaseline="middle";for(const{py:W,label:m}of i){const R=r+W;P||(t.strokeStyle="rgba(255,255,255,0.85)",t.lineWidth=3,t.beginPath(),t.moveTo(h,R),t.lineTo(h+D,R),t.stroke(),t.strokeStyle="rgba(0,0,0,0.7)",t.lineWidth=1,t.beginPath(),t.moveTo(h,R),t.lineTo(h+D,R),t.stroke()),t.fillStyle=x.text,t.fillText(m,h-3,R);const Lt=m==="USL"?-1:1,kt=4,qt=h-3-t.measureText(m).width-kt-4;t.beginPath(),$e(t,qt,R,kt,Lt),t.strokeStyle="#fff",t.lineWidth=2,t.lineJoin="round",t.stroke(),t.fillStyle=x.text,t.fill()}t.restore()}}if(!S){const i=e.logScale?"log\u2081\u2080":e.logScaleRequested?"linear \u2014 log n/a":null;i&&(t.save(),t.fillStyle=x.text,t.font=Mo(),t.textAlign="right",t.textBaseline="top",t.fillText(i,F-c,L),t.restore(),L+=15)}z&&H&&(gt(H,F-c,L,"right","top",w(L),ue(),x.text),L+=15),z&&I&&gt(I,F-c,L,"right","top",w(L),ue(),x.text)}const he=[];let Q;if(nt){const o=k==="compact",f=e.plotMode==="softBin"?yt:ct,n=f?new Map(f.map(l=>[l.bin,l])):null,a=e.plotMode==="softBin"?e.binColors.soft:e.binColors.hard,r=l=>a.get(l)??ro,h=(l,M)=>{const H=t.measureText(l).width,I=o?0:t.measureText(String(M)).width,L=$+ut+H+(I?jt:0);return{labelWidth:H,countWidth:I,totalWidth:L}},d=Tt?.find(l=>l.key===e.activeMetadataKey),s=ot?st.map(l=>{const M=o?l.compactLabel:l.label;return{key:l.key,color:l.color,count:l.count,label:M,tooltipLabel:l.tooltip,...h(M,l.count)}}):e.plotMode==="metadata"?Et.map(([l,M])=>{const I=d?.values?.find(J=>J.value===l)?.label??l,L=o?l:I,w=e.metadataColorMap?.get(l)??"#d6d9dd";return{key:l,color:w,count:M,label:L,tooltipLabel:`${I} \xB7 ${M} dies`,...h(L,M)}}):Nt.map(([l,M])=>{const H=n?.get(l),I=H?.name?`${l} \xB7 ${H.name}`:`Bin ${l}`,L=o?String(l):I;return{key:l,color:r(l),count:M,label:L,tooltipLabel:`${I} \xB7 ${M} dies`,...h(L,M)}}),p=F-c*2;if(s.length>0){const l=Ct?ht*2+(z?Ke:0):z&&!_t?qe+ze:0,M=Math.max(1,Math.floor((G-2*c-l)/E));let H=s.length,I=1,L=H*E,w=[],J=0;const at=Qt||_t;if(at){const O=zt(s.map(b=>b.totalWidth)),B=Math.max(1,Math.min(s.length,Math.floor((p+8)/(O+8))));for(let b=B;b>=1;b--){const S=Math.ceil(s.length/b);if(S>M)continue;const y=new Array(b).fill(0);for(let T=0;T<s.length;T++){const i=T%b;y[i]=Math.max(y[i],s[T].totalWidth)}if(y.reduce((T,i)=>T+i,0)+(b-1)*8<=p||b===1){I=b,w=y,H=S,L=S*E;break}}}else H=Math.min(s.length,M),L=H*E,s.length>M&&(J=s.length-(M-1)),w=[Yt];let _,C;if(Ct){const O=zt(s.map(i=>$+ut+t.measureText(i.label).width+jt)),B=Math.ceil(O);w=[B];const b=z?Ke:0,S=B+ht*2,y=L+b+ht*2,N=xt?.x??0,T=xt?.y??0;_=Math.min(Math.max(F-c-S+N,c),F-c-S),C=Math.min(Math.max(G-c-y+T,c),G-c-y),Q={x:_,y:C,w:S,h:y},t.save(),t.globalAlpha=.92,t.fillStyle=x.surface,t.fillRect(_,C,S,y),t.globalAlpha=1,t.strokeStyle=x.axisLine,t.lineWidth=1,t.strokeRect(_,C,S,y),t.restore(),_+=ht,C+=ht+b}else Qt?(_=c,C=G-c-L):_t?(_=c,C=c):pe?(_=c+4,C=Math.max(c+Math.round((G-2*c-L)/2),c+l)):(_=F-c-Yt+4,C=Math.max(c+Math.round((G-2*c-L)/2),c+l));if(z){const O=e.plotMode==="softBin"?yt:ct,{primary:B,secondary:b,note:S}=Fe(e,Mt,O),y=ze,N=[b,S].filter(m=>!!m),T=(m,R,Lt)=>N.forEach((kt,qt)=>gt(kt,m,R+qt*16,"left","top",Lt(R+qt*16),ue(),x.text)),i=m=>Vt-Math.max(rt(m),rt(m-12))-8,P=m=>dt?F-c:i(m),W=Ct?Q.y+Q.h:C+L;if(_t){const m=W+y;gt(B,_,m,"left","top",Vt-Math.max(rt(m),rt(m+12))-8),T(_,m+16,i)}else if(Ct)gt(B,Q.x+ht,Q.y+ht,"left","top",Q.x+Q.w-ht),T(Q.x,W+y,()=>Q.x+Q.w);else{const m=Math.max(C-y,c+qe);gt(B,_,m,"left","bottom",P(m)),T(_,W+y,P)}}t.save(),t.font=v();const It=at?8:0,et=(O,B)=>{if(t.measureText(O).width<=B)return O;let b=0,S=O.length;const y="\u2026",N=t.measureText(y).width;for(;b<S;){const T=b+S+1>>1;t.measureText(O.slice(0,T)).width+N<=B?b=T:S=T-1}return b===0?y:O.slice(0,b)+y};if(at){let O=0;for(let B=0;B<H;B++){let b=_;for(let S=0;S<I;S++){const y=s[O++];if(!y)break;const N=y.key===Y,T=!N&&y.key===j,i=b,P=b+$+ut,W=C+B*E+E/2,m=C+B*E+Math.round((E-$)/2),R=w[S]-$-ut-jt;T&&(t.fillStyle=x.hoverRow,t.fillRect(b,C+B*E,w[S],E)),t.fillStyle=y.color,t.fillRect(i,m,$,$),t.strokeStyle=N?x.accent:"rgba(0,0,0,0.25)",t.lineWidth=N?2:.75,t.strokeRect(i,m,$,$),t.fillStyle=N?x.accent:x.text,t.font=N?`bold ${v()}`:v(),t.textAlign="left",t.textBaseline="middle",t.fillText(et(y.label,R),P,W),t.fillStyle=x.textMuted,t.font=v(),t.textAlign="right",t.fillText(String(y.count),b+w[S]-2,W),he.push({bin:y.key,x:b,y:C+B*E,w:w[S],h:E,label:y.tooltipLabel}),b+=w[S]+It}}}else{const O=w[0],B=k!=="compact",b=O-$-ut-(B?jt:0),S=_+O-2;let y=s;J>0&&(y=s.slice(0,M-1));let N=C;for(const T of y){const i=T.key===Y,P=!i&&T.key===j,W=_,m=_+$+ut,R=N+E/2,Lt=N+Math.round((E-$)/2),kt=T.label;P&&(t.fillStyle=x.hoverRow,t.fillRect(_-3,N,O+3,E)),t.fillStyle=T.color,t.fillRect(W,Lt,$,$),t.strokeStyle=i?x.accent:"rgba(0,0,0,0.25)",t.lineWidth=i?2:.75,t.strokeRect(W,Lt,$,$),t.fillStyle=i?x.accent:x.text,t.font=i?`bold ${v()}`:v(),t.textAlign="left",t.textBaseline="middle",t.fillText(et(kt,b),m,R),(B||Ct)&&(t.fillStyle=x.textMuted,t.font=v(),t.textAlign="right",t.fillText(String(T.count),S,R)),he.push({bin:T.key,x:_,y:N,w:O,h:E,label:T.tooltipLabel}),N+=E}J>0&&(t.fillStyle=x.textMuted,t.font=v(),t.textAlign="left",t.textBaseline="middle",t.fillText(`+ ${J} more`,_+$+ut,N+E/2))}}s.length>0&&t.restore()}const oo={originX:lt,originY:it,ppm:A,snapDist:wt},Be=e.rectangles[0]?.width??1,Pe=e.rectangles[0]?.height??1,ft=e.dieBounds,Ut=ft?ft.minX:K.length?Ne(K.map(o=>o.x)):0,Kt=ft?ft.minY:K.length?Ne(K.map(o=>o.y)):0,no=ft?ft.maxX:K.length?zt(K.map(o=>o.x)):1,so=ft?ft.maxY:K.length?zt(K.map(o=>o.y)):1,{cellW:de,cellH:ge,nCols:Dt,nRows:me}=go(no-Ut,so-Kt,Be*1.5,Pe*1.5,K.length),De=Array.from({length:Dt*me},()=>[]);for(let o=0;o<K.length;o++){const f=Math.floor((K[o].x-Ut)/de),n=Math.floor((K[o].y-Kt)/ge),a=Number.isFinite(f)?Math.max(0,Math.min(Dt-1,f)):0,r=Number.isFinite(n)?Math.max(0,Math.min(me-1,n)):0;De[r*Dt+a].push(o)}function Ie(o,f,n){const a=Math.max(0,Math.floor((o-n-Ut)/de)),r=Math.min(Dt-1,Math.floor((o+n-Ut)/de)),h=Math.max(0,Math.floor((f-n-Kt)/ge)),d=Math.min(me-1,Math.floor((f+n-Kt)/ge)),s=[];for(let p=h;p<=d;p++)for(let l=a;l<=r;l++)for(const M of De[p*Dt+l])s.push(M);return s}return{hitTarget:{getDieAtPoint(o,f){const n=(o-lt)/A,a=(it-f)/A,r=Math.max(Be,Pe);for(const s of Ie(n,a,r)){const p=e.rectangles[s];if(p&&Math.abs(n-p.x)<=p.width/2&&Math.abs(a-p.y)<=p.height/2)return e.dies[s]??null}let h=null,d=wt*wt;for(const s of Ie(n,a,wt)){const p=K[s].x-n,l=K[s].y-a,M=p*p+l*l;M<d&&(d=M,h=e.dies[s]??null)}return h}},viewport:oo,binLegendRows:he,legendBox:Q}}function To(g,e,X,x,c,V,U,D,pt,tt,xt,bt,q){g.save(),g.font=yo(),g.fillStyle=q.text,g.strokeStyle=q.axisLine,g.lineWidth=.5;const Z=X-D+4,Y=U+pt-4,j=io(xt),Mt=Oe(j,1,0),Ot=Oe(j,0,1),ct=1e-9;function yt(u){return tt?Math.abs(u.y)<ct&&Math.abs(u.x)>ct?{pitch:tt.x,sign:Math.sign(u.x)}:Math.abs(u.x)<ct&&Math.abs(u.y)>ct?{pitch:tt.y,sign:Math.sign(u.y)}:null:null}const Tt=yt(Mt),z=yt(Ot);function F(u){return Tt?Math.round(u*Tt.sign/Tt.pitch):u}function G(u){return z?Math.round(u*z.sign/z.pitch):u}function St(u){if(!u)return Ft(50/V);const k=50/(u*V);return Math.max(1,Math.round(k))*u}const At=Tt?.pitch,Rt=z?.pitch,ot=St(At),nt=St(Rt);g.textAlign="center",g.textBaseline="top";const Nt=Math.ceil((U-x)/V/ot)*ot,Et=(e-U-x)/V;for(let u=Nt;u<=Et;u+=ot){const k=x+u*V;if(k<U||k>e-U)continue;g.beginPath(),g.moveTo(k,Z-Ue),g.lineTo(k,Z),g.stroke();const dt=tt?String(F(u)):Xe(u);g.fillText(dt,k,Z+2)}g.textAlign="right",g.textBaseline="middle";const st=Math.ceil((c-(X-U))/V/nt)*nt,Ht=(c-U)/V;for(let u=st;u<=Ht;u+=nt){const k=c-u*V;if(k<U||k>X-U)continue;g.beginPath(),g.moveTo(Y,k),g.lineTo(Y+Ue,k),g.stroke();const dt=tt?String(G(u)):Xe(u);g.fillText(dt,Y-2,k)}g.restore()}function So(g,e,X,x,c,V,U){const D=[],pt=U;if(pt<1){const q=Ft((e-g)*x/X);if(q>0){const Z=Math.ceil(g/q)*q;for(let Y=Z;Y<=e+q*1e-6;Y+=q){if(Y<=g||Y>=e)continue;const j=(1-(Math.log10(Y)-V)/U)*X;j>c&&j<X-c&&D.push(Y)}}return D}const tt=pt<3?[1,2,5]:[1],xt=Math.floor(Math.log10(g)),bt=Math.ceil(Math.log10(e));for(let q=xt;q<=bt;q++)for(const Z of tt){const Y=Z*Math.pow(10,q);if(Y<=g||Y>=e)continue;const j=(1-(Math.log10(Y)-V)/U)*X;j>c&&j<X-c&&D.push(Y)}return D}export{fmt,fmtColorbarAxis}from"../renderer/fmt.js";
1
+ import{fontPx as Wt}from"./toolbar.js";import{findTestDef as We,buildMapTitle as Fe}from"../renderer/buildView.js";import{niceStep as Ft}from"../renderer/axisTicks.js";import{sortBinsForDisplay as lo}from"../stats/binPareto.js";import{affineInvert as io,affineVector as Oe}from"../core/transforms.js";import{compareNatural as ao,maxOf as zt,minOf as Ne}from"../core/utils.js";import{resolveValueColorFn as co}from"../renderer/colorSchemes.js";import{NO_DATA_FILL as ro}from"../renderer/colorMap.js";import{SPEC_PASS_FILL as Ee,SPEC_FAIL_LOW as fo,SPEC_FAIL_HIGH as He,contrastTextColor as Ye}from"../renderer/colorMap.js";import{fmt as Xe,fmtColorbarAxis as Ge}from"../renderer/fmt.js";import{resolveCanvasTheme as ho}from"./canvasTheme.js";import{hitGridDims as go}from"./hitGrid.js";function $e(g,e,X,x,c){g.moveTo(e,X+c*x),g.lineTo(e-x*.9,X-c*x*.6),g.lineTo(e+x*.9,X-c*x*.6),g.closePath()}const mo=new Set(["value","stackedValues","stackedBins","stackedSoftBins"]),uo=new Set(["hardBin","softBin","metadata"]),v=()=>`${Wt(-2)}px system-ui, sans-serif`,we=3,Jt=2,po=6,xo=20,bo=()=>`600 ${Wt()}px system-ui, sans-serif`,Ve=36,ue=()=>`${Wt(-1)}px system-ui, sans-serif`,Mo=()=>`600 ${Wt(-1)}px system-ui, sans-serif`,Zt=128,yo=()=>`${Wt(-2)}px system-ui, sans-serif`,Ke=4,E=17,$=11;export const BIN_LEGEND_W=110,BIN_LEGEND_W_COMPACT=64,BIN_LEGEND_ADAPT_COMPACT=280,BIN_LEGEND_ADAPT_FLOATING=180,BIN_LEGEND_MIN_CANVAS_W=150,BIN_LEGEND_MIN_CANVAS_H=120;const jt=28,ut=5,ht=8,Ue=15,qe=12,ze=6;export function toCanvas(g,e,X={}){return drawMapCanvas(g,e,X)}export function drawMapCanvas(g,e,X={}){const x=ho(g.parentElement??g),{padding:c=16,showColorbar:V=!0,markFailingDies:K=!1,colorbarWidth:D=16,background:pt=x.background,legendPosition:tt="default",legendOffset:xt,showAxes:bt=!1,diePitchMm:q,viewport:Z,activeBin:Y,hoverBin:j,fallbackFormat:Mt,minRightReserve:Ot,hbinDefs:ct,sbinDefs:yt,metadataFields:Tt,showTitle:z=!0}=X,F=Math.floor(g.clientWidth||g.width),G=Math.floor(g.clientHeight||g.height),St=F>=BIN_LEGEND_MIN_CANVAS_W&&G>=BIN_LEGEND_MIN_CANVAS_H,At=V&&St&&mo.has(e.plotMode)&&e.passFailDisplay==="off",Rt=V&&St&&uo.has(e.plotMode),ot=V&&St&&e.plotMode==="value"&&(e.passFailDisplay==="spec"&&e.specCounts!==void 0||e.passFailDisplay==="test"&&e.passFailCounts!==void 0),nt=Rt||ot,Nt=Rt&&e.plotMode!=="metadata"&&e.binCounts?lo(e.binCounts.entries(),e.plotMode==="softBin"?e.binColors.pass.soft:e.binColors.pass.hard):[],Et=Rt&&e.plotMode==="metadata"&&e.metadataCounts?[...e.metadataColorMap?.keys()??[...e.metadataCounts.keys()].sort(ao)].map(o=>[o,e.metadataCounts.get(o)??0]):[],st=[];if(ot&&e.passFailDisplay==="test"){const o=e.passFailCounts;st.push({key:-1,color:Ee,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),st.push({key:-2,color:He,label:"Fail",compactLabel:"Fail",count:o.fail,tooltip:`Fail \xB7 ${o.fail} dies`})}else if(ot){const o=e.specCounts,f=We(e.testDefs,e.activeTest);st.push({key:-1,color:Ee,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),f?.limitHigh!==void 0&&st.push({key:-2,color:He,label:"Fail high",compactLabel:"Fail hi",count:o.failHigh,tooltip:`Fail high \xB7 ${o.failHigh} dies`}),f?.limitLow!==void 0&&st.push({key:-3,color:fo,label:"Fail low",compactLabel:"Fail lo",count:o.failLow,tooltip:`Fail low \xB7 ${o.failLow} dies`})}const Ht=ot?st.length:e.plotMode==="metadata"?Et.length:Nt.length,u=(g.ownerDocument.defaultView??window).devicePixelRatio??1;if(F<=0||G<=0)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const k=tt!=="default"?tt:F<BIN_LEGEND_ADAPT_FLOATING?"floating":F<BIN_LEGEND_ADAPT_COMPACT?"compact":"default",dt=k==="default"||k==="compact",pe=k==="left",Qt=k==="bottom",_t=k==="top",Ct=k==="floating",Yt=k==="compact"||k==="floating"?BIN_LEGEND_W_COMPACT:BIN_LEGEND_W,xe=Math.floor((G-2*c)/E),be=Ht>xe?xe-1:Ht,Me=nt&&Qt?be*E:0,vt=nt&&_t?be*E:0,te=e.plotMode==="stackedBins"||e.plotMode==="stackedSoftBins",ee=We(e.testDefs,e.activeTest),ye=te?"Count":ee?.name??(e.activeTest!=null?`Test ${e.activeTest}`:void 0),Te=te?void 0:ee?.unit,[Bt,Pt]=e.valueRange,oe=o=>String(Math.round(o)),Je=e.logScale||e.allIntegerValues?void 0:Ft(Math.max(0,Pt-Bt)*Ve/Math.max(1,G))||void 0,ne=e.allIntegerValues?oe:Ge(Pt,ye,Te,Mt,Je).edgeFmt;let se=0;if(At){const o=g.getContext("2d");o.font=v();const f=[ne(Bt),ne(Pt)];Bt<0&&f.push(ne(-Math.max(Math.abs(Bt),Math.abs(Pt))));for(const n of f)se=Math.max(se,o.measureText(n).width)}const Se=Math.max(xo,Math.ceil(se)+we+Jt+po-c),le=At?D+Se+8:nt&&dt?Yt:0,ie=nt&&pe?Yt:0,ae=bt?32:0,Xt=bt?36:0,Ze=Ot!=null?Math.max(le,Ot):le,je=F-2*c-Ze-Xt-ie,Le=G-2*c-ae-Me-vt;g.width=Math.round(F*u),g.height=Math.round(G*u);const t=g.getContext("2d");t.scale(u,u),t.fillStyle=pt,t.fillRect(0,0,F,G);const U=e.hoverPoints;if(!U.length)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const Gt=e.rectangles[0],ce=Gt?Gt.width/2:0,re=Gt?Gt.height/2:0,$t=e.dieBounds,ke=($t?.minX??0)-ce,Qe=($t?.maxX??0)+ce,ve=($t?.minY??0)-re,Ae=($t?.maxY??0)+re,Re=Qe-ke,_e=Ae-ve;let lt,it,A;if(Z)({originX:lt,originY:it,ppm:A}=Z);else{const f=e.notchDir,n=f&&f.y>.1?13:0,a=f&&f.y<-.1?13:0,r=f&&f.x<-.1?13:0,h=f&&f.x>.1?13:0,d=je-r-h,s=Le-n-a;A=Math.min(d/Re,s/_e),lt=c+Xt+ie+r+(d-Re*A)/2-ke*A,it=c+vt+n+(s-_e*A)/2+Ae*A}const wt=Z?.snapDist??Math.max(ce,re,1)*1.5,Vt=lt+e.waferCenter.x*A,to=it-e.waferCenter.y*A,fe=e.waferRadius*A,rt=o=>{const f=Math.abs(o-to);return f>=fe?0:Math.sqrt(fe*fe-f*f)},gt=(o,f,n,a,r,h,d=bo(),s=x.text)=>{if(!o)return;t.save(),t.fillStyle=s,t.font=d,t.textAlign=a,t.textBaseline=r;const p=a==="right"?f-h:h-f;let l=o;if(p>8&&t.measureText(l).width>p){for(;l.length>1&&t.measureText(l+"\u2026").width>p;)l=l.slice(0,-1);l=l+"\u2026"}p>8&&t.fillText(l,f,n),t.restore()};t.save(),t.setTransform(A*u,0,0,-A*u,lt*u,it*u);const mt=1/A,eo=1/(A*u);if(e.rectangles.length>0){const o=new Map;for(const n of e.rectangles){const a=String(n.fill);let r=o.get(a);r||(r=[],o.set(a,r)),r.push(n)}for(const[n,a]of o){t.beginPath();for(const r of a)t.rect(r.x-r.width/2,r.y-r.height/2,r.width,r.height);t.fillStyle=n,t.fill()}t.strokeStyle="rgba(0,0,0,0.18)",t.lineWidth=.5*eo,t.beginPath();for(const n of e.rectangles)t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height);if(t.stroke(),K){const n=e.rectangles.filter(a=>a.binFail);if(n.length>0){const a=new Map;for(const r of n){const h=Ye(String(r.fill));let d=a.get(h);d||(d=[],a.set(h,d)),d.push(r)}t.save(),t.lineCap="butt";for(const[r,h]of a){t.strokeStyle=r,t.globalAlpha=.55,t.lineWidth=Math.max(.6*mt,Math.min(h[0].width,h[0].height)*.1);for(const d of h){const s=d.width/2,p=d.height/2,l=Math.max(1.6*mt,Math.min(d.width,d.height)/3);t.save(),t.beginPath(),t.rect(d.x-s,d.y-p,d.width,d.height),t.clip(),t.beginPath();for(let M=-(s+p);M<=s+p;M+=l)t.moveTo(d.x-s+M,d.y-p),t.lineTo(d.x-s+M+d.height,d.y+p);t.stroke(),t.restore()}}t.restore()}}const f=e.rectangles.filter(n=>n.specMark);if(f.length>0){const n=new Map;for(const r of f){const h=Ye(String(r.fill)),d=`${r.specMark}|${h}`;let s=n.get(d);s||(s=[],n.set(d,s)),s.push(r)}const a=2.5*mt;t.lineJoin="round";for(const[r,h]of n){const[d,s]=r.split("|"),p=s==="#000000"?"#ffffff":"#000000",l=d==="failHigh"?1:-1,M=Math.min(h[0].width,h[0].height),H=Math.max(2.5*mt,M*.3);t.beginPath();for(const I of h)$e(t,I.x,I.y,H,l);t.strokeStyle=p,t.lineWidth=a,t.stroke(),t.fillStyle=s,t.fill()}}}for(const o of e.overlays){t.beginPath();for(const f of o.points){for(let n=0;n<f.length;n++)n===0?t.moveTo(f[n].x,f[n].y):t.lineTo(f[n].x,f[n].y);o.closed&&t.closePath()}o.fill&&!o.fill.startsWith("rgba(0,0,0,0)")&&(t.fillStyle=o.fill,t.fill()),o.kind==="ring-boundary"||o.kind==="quadrant-boundary"||o.kind==="reticle"?(t.strokeStyle="rgba(0,0,0,0.45)",t.lineWidth=3*mt,t.stroke(),t.strokeStyle="rgba(255,255,255,0.8)",t.lineWidth=1*mt,t.stroke()):(t.strokeStyle=o.lineColor,t.lineWidth=o.lineWidth*mt,t.stroke())}if(t.restore(),e.notchDir){const o=lt+e.waferCenter.x*A,f=it-e.waferCenter.y*A,n=e.notchDir.x,a=-e.notchDir.y,r=e.waferRadius*A,h=4,d=9,s=5,p=o+n*(r+h),l=f+a*(r+h),M=p+n*d,H=l+a*d,I={x:-a,y:n},L=c+Xt+ie,w=F-c-le,J=c+vt,at=G-c-Me-ae;t.save(),t.beginPath(),t.rect(L,J,w-L,at-J),t.clip(),t.beginPath(),t.moveTo(p,l),t.lineTo(M+I.x*s,H+I.y*s),t.lineTo(M-I.x*s,H-I.y*s),t.closePath(),t.fillStyle=x.text,t.fill(),t.restore()}t.save(),t.textAlign="center",t.textBaseline="middle";let Ce=0;if(e.rectangles.length>0){let o=1;for(const h of e.texts)h.role!=="indicator"&&h.text.length>o&&(o=h.text.length);const f=e.rectangles[0].width*A,n=e.rectangles[0].height*A,a=Math.min(f,n),r=f/o;Ce=Math.max(8,Math.min(64,Math.round(Math.min(a*.55,r*1.8))))}for(const o of e.texts){const f=lt+o.x*A,n=it-o.y*A;t.font=`${o.role==="indicator"?o.fontSize:Ce}px system-ui, sans-serif`,t.fillStyle=o.color,t.fillText(o.text,f,n)}if(t.restore(),bt&&To(t,F,G,lt,it,A,c,ae,Xt,q,e.gridToScreen,e.rotation,x),At){const o=co(e.valueColorScheme,e.reverseValueScheme),f=Se,n=Le,a=Math.round(n*.75),r=c+Math.round((n-a)/2),h=F-c-D-f,d=Bt,s=Pt,p=s-d,l=e.plotMode==="stackedSoftBins"?yt:ct,{primary:M,secondary:H,note:I}=z?Fe(e,Mt,l):{primary:"",secondary:"",note:void 0};if(z){const i=Math.max(r-6,c+11),P=Vt+Math.max(rt(i),rt(i-12))+8;gt(M,F-c,i,"right","bottom",P)}let L=r+a+4;const w=i=>Vt+Math.max(rt(i),rt(i+12))+8,J=e.logScale&&d>0?Math.log10(d):0,at=e.logScale&&s>0?Math.log10(s)-J:1,_=i=>e.logScale?(1-(Math.log10(i)-J)/at)*a:(1-(i-d)/p)*a;for(let i=0;i<Zt;i++){const P=1-i/(Zt-1),W=r+i/Zt*a,m=a/Zt+1;t.fillStyle=o(P),t.fillRect(h,W,D,m)}t.strokeStyle="rgba(0,0,0,0.25)",t.lineWidth=.5,t.strokeRect(h,r,D,a),t.fillStyle=x.text,t.font=v(),t.textAlign="left",t.strokeStyle="rgba(0,0,0,0.35)",t.lineWidth=.5;const C=we,It=Ve,et=14;let O;const B=e.logScale&&at>0?So(d,s,a,It,et,J,at):e.allIntegerValues?(()=>{const i=Math.max(1,Ft(p*It/a)),P=[],W=Math.ceil(d/i)*i;for(let m=W;m<=s+i*1e-6;m+=i){const R=(1-(m-d)/p)*a;R>et&&R<a-et&&P.push(Math.round(m))}return P})():(()=>{const i=p>0?Ft(p*It/a):0,P=[];if(i>0){O=i;const W=Math.ceil(d/i)*i;for(let m=W;m<=s+i*1e-6;m+=i){const R=(1-(m-d)/p)*a;R>et&&R<a-et&&P.push(m)}}return P})(),b=ee,S=te,y=Ge(s,ye,Te,Mt,O),N=e.allIntegerValues?oe:y.tickFmt,T=e.allIntegerValues?oe:y.edgeFmt;t.textBaseline="middle";for(const i of B){const P=r+_(i);t.beginPath(),t.moveTo(h+D,P),t.lineTo(h+D+C,P),t.stroke(),t.fillText(N(i),h+D+C+Jt,P)}if(t.beginPath(),t.moveTo(h+D,r),t.lineTo(h+D+C,r),t.stroke(),t.textBaseline="top",t.fillText(T(s),h+D+C+Jt,r),t.beginPath(),t.moveTo(h+D,r+a),t.lineTo(h+D+C,r+a),t.stroke(),t.textBaseline="bottom",t.fillText(T(d),h+D+C+Jt,r+a),!S&&b&&(b.limitLow!==void 0||b.limitHigh!==void 0)){const i=[],P=e.colorbarRangeMode==="spec";for(const[W,m]of[[b.limitLow,"Lo limit"],[b.limitHigh,"Hi limit"]]){if(W===void 0||e.logScale&&W<=0)continue;const R=_(W);!P&&(R<-et||R>a+et)||i.push({value:W,label:m,py:Math.max(0,Math.min(a,R))})}if(i.length>0){t.save(),t.font=v(),t.textAlign="right",t.textBaseline="middle";for(const{py:W,label:m}of i){const R=r+W;P||(t.strokeStyle="rgba(255,255,255,0.85)",t.lineWidth=3,t.beginPath(),t.moveTo(h,R),t.lineTo(h+D,R),t.stroke(),t.strokeStyle="rgba(0,0,0,0.7)",t.lineWidth=1,t.beginPath(),t.moveTo(h,R),t.lineTo(h+D,R),t.stroke()),t.fillStyle=x.text,t.fillText(m,h-3,R);const Lt=m==="Hi limit"?-1:1,kt=4,qt=h-3-t.measureText(m).width-kt-4;t.beginPath(),$e(t,qt,R,kt,Lt),t.strokeStyle="#fff",t.lineWidth=2,t.lineJoin="round",t.stroke(),t.fillStyle=x.text,t.fill()}t.restore()}}if(!S){const i=e.logScale?"log\u2081\u2080":e.logScaleRequested?"linear \u2014 log n/a":null;i&&(t.save(),t.fillStyle=x.text,t.font=Mo(),t.textAlign="right",t.textBaseline="top",t.fillText(i,F-c,L),t.restore(),L+=15)}z&&H&&(gt(H,F-c,L,"right","top",w(L),ue(),x.text),L+=15),z&&I&&gt(I,F-c,L,"right","top",w(L),ue(),x.text)}const he=[];let Q;if(nt){const o=k==="compact",f=e.plotMode==="softBin"?yt:ct,n=f?new Map(f.map(l=>[l.bin,l])):null,a=e.plotMode==="softBin"?e.binColors.soft:e.binColors.hard,r=l=>a.get(l)??ro,h=(l,M)=>{const H=t.measureText(l).width,I=o?0:t.measureText(String(M)).width,L=$+ut+H+(I?jt:0);return{labelWidth:H,countWidth:I,totalWidth:L}},d=Tt?.find(l=>l.key===e.activeMetadataKey),s=ot?st.map(l=>{const M=o?l.compactLabel:l.label;return{key:l.key,color:l.color,count:l.count,label:M,tooltipLabel:l.tooltip,...h(M,l.count)}}):e.plotMode==="metadata"?Et.map(([l,M])=>{const I=d?.values?.find(J=>J.value===l)?.label??l,L=o?l:I,w=e.metadataColorMap?.get(l)??"#d6d9dd";return{key:l,color:w,count:M,label:L,tooltipLabel:`${I} \xB7 ${M} dies`,...h(L,M)}}):Nt.map(([l,M])=>{const H=n?.get(l),I=H?.name?`${l} \xB7 ${H.name}`:`Bin ${l}`,L=o?String(l):I;return{key:l,color:r(l),count:M,label:L,tooltipLabel:`${I} \xB7 ${M} dies`,...h(L,M)}}),p=F-c*2;if(s.length>0){const l=Ct?ht*2+(z?Ue:0):z&&!_t?qe+ze:0,M=Math.max(1,Math.floor((G-2*c-l)/E));let H=s.length,I=1,L=H*E,w=[],J=0;const at=Qt||_t;if(at){const O=zt(s.map(b=>b.totalWidth)),B=Math.max(1,Math.min(s.length,Math.floor((p+8)/(O+8))));for(let b=B;b>=1;b--){const S=Math.ceil(s.length/b);if(S>M)continue;const y=new Array(b).fill(0);for(let T=0;T<s.length;T++){const i=T%b;y[i]=Math.max(y[i],s[T].totalWidth)}if(y.reduce((T,i)=>T+i,0)+(b-1)*8<=p||b===1){I=b,w=y,H=S,L=S*E;break}}}else H=Math.min(s.length,M),L=H*E,s.length>M&&(J=s.length-(M-1)),w=[Yt];let _,C;if(Ct){const O=zt(s.map(i=>$+ut+t.measureText(i.label).width+jt)),B=Math.ceil(O);w=[B];const b=z?Ue:0,S=B+ht*2,y=L+b+ht*2,N=xt?.x??0,T=xt?.y??0;_=Math.min(Math.max(F-c-S+N,c),F-c-S),C=Math.min(Math.max(G-c-y+T,c),G-c-y),Q={x:_,y:C,w:S,h:y},t.save(),t.globalAlpha=.92,t.fillStyle=x.surface,t.fillRect(_,C,S,y),t.globalAlpha=1,t.strokeStyle=x.axisLine,t.lineWidth=1,t.strokeRect(_,C,S,y),t.restore(),_+=ht,C+=ht+b}else Qt?(_=c,C=G-c-L):_t?(_=c,C=c):pe?(_=c+4,C=Math.max(c+Math.round((G-2*c-L)/2),c+l)):(_=F-c-Yt+4,C=Math.max(c+Math.round((G-2*c-L)/2),c+l));if(z){const O=e.plotMode==="softBin"?yt:ct,{primary:B,secondary:b,note:S}=Fe(e,Mt,O),y=ze,N=[b,S].filter(m=>!!m),T=(m,R,Lt)=>N.forEach((kt,qt)=>gt(kt,m,R+qt*16,"left","top",Lt(R+qt*16),ue(),x.text)),i=m=>Vt-Math.max(rt(m),rt(m-12))-8,P=m=>dt?F-c:i(m),W=Ct?Q.y+Q.h:C+L;if(_t){const m=W+y;gt(B,_,m,"left","top",Vt-Math.max(rt(m),rt(m+12))-8),T(_,m+16,i)}else if(Ct)gt(B,Q.x+ht,Q.y+ht,"left","top",Q.x+Q.w-ht),T(Q.x,W+y,()=>Q.x+Q.w);else{const m=Math.max(C-y,c+qe);gt(B,_,m,"left","bottom",P(m)),T(_,W+y,P)}}t.save(),t.font=v();const It=at?8:0,et=(O,B)=>{if(t.measureText(O).width<=B)return O;let b=0,S=O.length;const y="\u2026",N=t.measureText(y).width;for(;b<S;){const T=b+S+1>>1;t.measureText(O.slice(0,T)).width+N<=B?b=T:S=T-1}return b===0?y:O.slice(0,b)+y};if(at){let O=0;for(let B=0;B<H;B++){let b=_;for(let S=0;S<I;S++){const y=s[O++];if(!y)break;const N=y.key===Y,T=!N&&y.key===j,i=b,P=b+$+ut,W=C+B*E+E/2,m=C+B*E+Math.round((E-$)/2),R=w[S]-$-ut-jt;T&&(t.fillStyle=x.hoverRow,t.fillRect(b,C+B*E,w[S],E)),t.fillStyle=y.color,t.fillRect(i,m,$,$),t.strokeStyle=N?x.accent:"rgba(0,0,0,0.25)",t.lineWidth=N?2:.75,t.strokeRect(i,m,$,$),t.fillStyle=N?x.accent:x.text,t.font=N?`bold ${v()}`:v(),t.textAlign="left",t.textBaseline="middle",t.fillText(et(y.label,R),P,W),t.fillStyle=x.textMuted,t.font=v(),t.textAlign="right",t.fillText(String(y.count),b+w[S]-2,W),he.push({bin:y.key,x:b,y:C+B*E,w:w[S],h:E,label:y.tooltipLabel}),b+=w[S]+It}}}else{const O=w[0],B=k!=="compact",b=O-$-ut-(B?jt:0),S=_+O-2;let y=s;J>0&&(y=s.slice(0,M-1));let N=C;for(const T of y){const i=T.key===Y,P=!i&&T.key===j,W=_,m=_+$+ut,R=N+E/2,Lt=N+Math.round((E-$)/2),kt=T.label;P&&(t.fillStyle=x.hoverRow,t.fillRect(_-3,N,O+3,E)),t.fillStyle=T.color,t.fillRect(W,Lt,$,$),t.strokeStyle=i?x.accent:"rgba(0,0,0,0.25)",t.lineWidth=i?2:.75,t.strokeRect(W,Lt,$,$),t.fillStyle=i?x.accent:x.text,t.font=i?`bold ${v()}`:v(),t.textAlign="left",t.textBaseline="middle",t.fillText(et(kt,b),m,R),(B||Ct)&&(t.fillStyle=x.textMuted,t.font=v(),t.textAlign="right",t.fillText(String(T.count),S,R)),he.push({bin:T.key,x:_,y:N,w:O,h:E,label:T.tooltipLabel}),N+=E}J>0&&(t.fillStyle=x.textMuted,t.font=v(),t.textAlign="left",t.textBaseline="middle",t.fillText(`+ ${J} more`,_+$+ut,N+E/2))}}s.length>0&&t.restore()}const oo={originX:lt,originY:it,ppm:A,snapDist:wt},Be=e.rectangles[0]?.width??1,Pe=e.rectangles[0]?.height??1,ft=e.dieBounds,Kt=ft?ft.minX:U.length?Ne(U.map(o=>o.x)):0,Ut=ft?ft.minY:U.length?Ne(U.map(o=>o.y)):0,no=ft?ft.maxX:U.length?zt(U.map(o=>o.x)):1,so=ft?ft.maxY:U.length?zt(U.map(o=>o.y)):1,{cellW:de,cellH:ge,nCols:Dt,nRows:me}=go(no-Kt,so-Ut,Be*1.5,Pe*1.5,U.length),De=Array.from({length:Dt*me},()=>[]);for(let o=0;o<U.length;o++){const f=Math.floor((U[o].x-Kt)/de),n=Math.floor((U[o].y-Ut)/ge),a=Number.isFinite(f)?Math.max(0,Math.min(Dt-1,f)):0,r=Number.isFinite(n)?Math.max(0,Math.min(me-1,n)):0;De[r*Dt+a].push(o)}function Ie(o,f,n){const a=Math.max(0,Math.floor((o-n-Kt)/de)),r=Math.min(Dt-1,Math.floor((o+n-Kt)/de)),h=Math.max(0,Math.floor((f-n-Ut)/ge)),d=Math.min(me-1,Math.floor((f+n-Ut)/ge)),s=[];for(let p=h;p<=d;p++)for(let l=a;l<=r;l++)for(const M of De[p*Dt+l])s.push(M);return s}return{hitTarget:{getDieAtPoint(o,f){const n=(o-lt)/A,a=(it-f)/A,r=Math.max(Be,Pe);for(const s of Ie(n,a,r)){const p=e.rectangles[s];if(p&&Math.abs(n-p.x)<=p.width/2&&Math.abs(a-p.y)<=p.height/2)return e.dies[s]??null}let h=null,d=wt*wt;for(const s of Ie(n,a,wt)){const p=U[s].x-n,l=U[s].y-a,M=p*p+l*l;M<d&&(d=M,h=e.dies[s]??null)}return h}},viewport:oo,binLegendRows:he,legendBox:Q}}function To(g,e,X,x,c,V,K,D,pt,tt,xt,bt,q){g.save(),g.font=yo(),g.fillStyle=q.text,g.strokeStyle=q.axisLine,g.lineWidth=.5;const Z=X-D+4,Y=K+pt-4,j=io(xt),Mt=Oe(j,1,0),Ot=Oe(j,0,1),ct=1e-9;function yt(u){return tt?Math.abs(u.y)<ct&&Math.abs(u.x)>ct?{pitch:tt.x,sign:Math.sign(u.x)}:Math.abs(u.x)<ct&&Math.abs(u.y)>ct?{pitch:tt.y,sign:Math.sign(u.y)}:null:null}const Tt=yt(Mt),z=yt(Ot);function F(u){return Tt?Math.round(u*Tt.sign/Tt.pitch):u}function G(u){return z?Math.round(u*z.sign/z.pitch):u}function St(u){if(!u)return Ft(50/V);const k=50/(u*V);return Math.max(1,Math.round(k))*u}const At=Tt?.pitch,Rt=z?.pitch,ot=St(At),nt=St(Rt);g.textAlign="center",g.textBaseline="top";const Nt=Math.ceil((K-x)/V/ot)*ot,Et=(e-K-x)/V;for(let u=Nt;u<=Et;u+=ot){const k=x+u*V;if(k<K||k>e-K)continue;g.beginPath(),g.moveTo(k,Z-Ke),g.lineTo(k,Z),g.stroke();const dt=tt?String(F(u)):Xe(u);g.fillText(dt,k,Z+2)}g.textAlign="right",g.textBaseline="middle";const st=Math.ceil((c-(X-K))/V/nt)*nt,Ht=(c-K)/V;for(let u=st;u<=Ht;u+=nt){const k=c-u*V;if(k<K||k>X-K)continue;g.beginPath(),g.moveTo(Y,k),g.lineTo(Y+Ke,k),g.stroke();const dt=tt?String(G(u)):Xe(u);g.fillText(dt,Y-2,k)}g.restore()}function So(g,e,X,x,c,V,K){const D=[],pt=K;if(pt<1){const q=Ft((e-g)*x/X);if(q>0){const Z=Math.ceil(g/q)*q;for(let Y=Z;Y<=e+q*1e-6;Y+=q){if(Y<=g||Y>=e)continue;const j=(1-(Math.log10(Y)-V)/K)*X;j>c&&j<X-c&&D.push(Y)}}return D}const tt=pt<3?[1,2,5]:[1],xt=Math.floor(Math.log10(g)),bt=Math.ceil(Math.log10(e));for(let q=xt;q<=bt;q++)for(const Z of tt){const Y=Z*Math.pow(10,q);if(Y<=g||Y>=e)continue;const j=(1-(Math.log10(Y)-V)/K)*X;j>c&&j<X-c&&D.push(Y)}return D}export{fmt,fmtColorbarAxis}from"../renderer/fmt.js";
@@ -6,4 +6,4 @@ body>*:not(.wmap-overlay-box):not(#wmap-modal-backdrop):not(.wmap-overlay-ancest
6
6
  .wmap-overlay-box>div:first-child{display:none!important}
7
7
  .wmap-overlay-box>div:nth-child(2){display:block!important;overflow:visible!important;height:auto!important;flex:none!important;min-height:0!important;min-width:0!important}
8
8
  .wmap-overlay-box>div:nth-child(3){display:none!important}
9
- }`,n.head.appendChild(te),reparentTooltip(i),t?(l.addEventListener("click",v=>{v.target===l&&I()}),n.addEventListener("keydown",z)):(i.addEventListener("keydown",z),i.addEventListener("mousedown",Y),Y()),nextFrame(()=>(m.isConnected?m:i).focus(),o);function ye(v){d=v,!u&&!E&&(i.style.height=v)}return{backdrop:l,box:i,contentWrap:$,close:I,bringToFront:Y,setNaturalHeight:ye}}export function openModal(e){return me({...e,mode:"modal"})}export function openFloatingWindow(e){return me({...e,mode:"window"})}const le=new WeakSet;export function openReparentedModal(e,t={}){if(e.length===0||e.some(r=>le.has(r)))return null;const n=e.map(r=>({el:r,parent:r.parentElement,next:r.nextSibling})),o=openModal({ownerDocument:t.ownerDocument,title:t.title,boxSize:t.boxSize,anchor:t.anchor??e[0],onClose:()=>{for(const r of n){if(le.delete(r.el),!r.parent)continue;const l=r.next&&r.next.parentNode===r.parent?r.next:null;r.parent.insertBefore(r.el,l)}t.onClosed?.()}});for(const r of n)le.add(r.el),o.contentWrap.appendChild(r.el);return o}export function makePaletteBtn(e,t,n,o){const r=e.makeCheckMenuBtn("palette","Colour scheme",()=>{const p=t(),i=[];if(p.plotMode==="hardBin"||p.plotMode==="softBin"){const b=p.binColorScheme??"default";i.push({section:"Bin colours"});for(const d of Ae())i.push({label:d.label,active:b===d.name,onClick:()=>o({binColorScheme:d.name})});if(n()){const d=p.useDefinedBinColors??!0;i.push({section:"Bin definitions"}),i.push({label:"Use colours from bin definitions",active:d,onClick:()=>o({useDefinedBinColors:!d})})}}else{const b=p.valueColorScheme??"default";i.push({section:"Value colours"});for(const a of Me())i.push({label:a.label,active:b===a.name,onClick:()=>o({valueColorScheme:a.name})});const d=p.reverseValueScheme??!1;i.push({section:"Direction"}),i.push({label:"Reverse gradient",active:d,onClick:()=>o({reverseValueScheme:!d})})}return i},()=>{});function l(){r.style.display=t().plotMode==="metadata"?"none":""}return{btn:r,sync:l}}export function requestedPassFailDisplay(e){return e.passFailDisplay??"off"}export function overlayMenuRows(e,t,n,o){return[{label:"Ring boundaries",active:!!e.showRingBoundaries,onClick:()=>o({showRingBoundaries:!e.showRingBoundaries})},{label:"Quadrant lines",active:!!e.showQuadrantBoundaries,onClick:()=>o({showQuadrantBoundaries:!e.showQuadrantBoundaries})},{label:"Die labels",active:!!e.showDieLabels,onClick:()=>o({showDieLabels:!e.showDieLabels})},{label:"Reticle grid",active:!!e.showReticle,enabled:t,onClick:()=>o({showReticle:!e.showReticle})},{label:"XY indicator",active:!!e.showXYIndicator,onClick:()=>o({showXYIndicator:!e.showXYIndicator})},...passFailMenuRows({...n,display:requestedPassFailDisplay(e)},r=>o({passFailDisplay:r})),{label:"Mark failing dies",active:!!e.markFailingDies,enabled:n.binMode,disabledHint:n.binMode?void 0:"Available on hard/soft bin maps",onClick:()=>o({markFailingDies:!e.markFailingDies})},{section:""},{label:"Clear overlays",active:!1,action:!0,enabled:anyOverlayActive(e),disabledHint:"No overlays are active",onClick:()=>o({showRingBoundaries:!1,showQuadrantBoundaries:!1,showDieLabels:!1,showReticle:!1,showXYIndicator:!1,passFailDisplay:"off",markFailingDies:!1})}]}export function anyOverlayActive(e){return!!(e.showRingBoundaries||e.showQuadrantBoundaries||e.showDieLabels||e.showReticle||e.showXYIndicator||e.markFailingDies||requestedPassFailDisplay(e)!=="off")}export function passFailMenuRows(e,t){if(e.functionalActive)return[];const n=[];return e.hasLimits&&n.push({label:"Spec pass/fail",active:e.display==="spec",onClick:()=>t(e.display==="spec"?"off":"spec")}),e.hasRecorded&&n.push({label:"Test pass/fail",active:e.display==="test",onClick:()=>t(e.display==="test"?"off":"test")}),n}export function makeLogScaleBtn(e,t,n){const o=e.makeBtn("logScale","Toggle log scale",()=>{n({logScale:!t().logScale})});function r(){const l=t(),p=l.plotMode,i=p==="value"||p==="stackedValues";o.style.display=i&&requestedPassFailDisplay(l)==="off"&&!l.functionalActive?"":"none",e.setActive(o,!!l.logScale)}return{btn:o,sync:r}}const Fe=[{value:"default",label:"Default (right)"},{value:"compact",label:"Compact (right)"},{value:"left",label:"Left"},{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"floating",label:"Floating"}];export function makeLegendStyleBtn(e,t,n,o){const r=e.makeCheckMenuBtn("legend","Legend style",()=>{const p=t().legendPosition??"default",i=[];let b=!0;if(o){const d=o.blockedReason();b=d?!0:o.get(),i.push({label:"Legend on each map",active:b,enabled:!d,disabledHint:d??void 0,onClick:()=>o.set(!o.get())})}if(be(t().plotMode)){o&&i.push({section:"Position on each map"});for(const d of Fe)i.push({label:d.label,active:b&&p===d.value,enabled:b,disabledHint:b?void 0:'Turn on "Legend on each map" to position it',onClick:()=>n(d.value)})}return i},()=>{});function l(){r.style.display=o||be(t().plotMode)?"":"none"}return{btn:r,sync:l}}function be(e){return e==="hardBin"||e==="softBin"||e==="metadata"}export function makeOverlaysBtn(e,t,n){return e.makeCheckMenuBtn("overlays","Overlays",()=>t(),o=>e.setActive(o,n()))}export function makeOrientationBtn(e,t,n){return e.makeCheckMenuBtn("orient","Orientation",()=>[{section:"Rotate"},{label:"Rotate 90\xB0 clockwise",active:!1,onClick:()=>{const o=t().rotation??0;n({rotation:ROTATIONS[(ROTATIONS.indexOf(o)+1)%4]})}},{section:"Flip"},{label:"Flip horizontal",active:!!t().flipX,onClick:()=>n({flipX:!t().flipX})},{label:"Flip vertical",active:!!t().flipY,onClick:()=>n({flipY:!t().flipY})},{section:""},{label:"Reset orientation",active:!1,action:!0,enabled:!!(t().rotation||t().flipX||t().flipY),disabledHint:"Already in the original orientation",onClick:()=>n({rotation:0,flipX:!1,flipY:!1})}],o=>{const{rotation:r,flipX:l,flipY:p}=t();e.setActive(o,!!(r||l||p))})}let j=null;const he=40,je=he+8;function Ve(e,t){const n=e.createElement("div");n.classList.add("wmap-guide-search"),n.style.cssText="display:flex;align-items:center;gap:2px;margin-left:10px;flex:1;min-width:80px;max-width:260px;";const o=e.createElement("input");o.type="text",o.placeholder="Search guide\u2026",o.setAttribute("aria-label","Search guide"),o.style.cssText=`flex:1;min-width:0;padding:4px 8px;font-size:12px;background:${CLR.menuBg};color:${CLR.text};border:1px solid ${CLR.menuBorder};border-radius:${RADIUS.control};outline:none;`,o.addEventListener("focus",()=>{o.style.borderColor=CLR.iconActive}),o.addEventListener("blur",()=>{o.style.borderColor=CLR.menuBorder});const r=e.createElement("span");r.setAttribute("role","status"),r.setAttribute("aria-live","polite"),r.style.cssText=`font-size:12px;color:${CLR.label};min-width:44px;text-align:center;flex-shrink:0;white-space:nowrap;`;function l(x,c){const m=e.createElement("button");return m.type="button",m.textContent=x,m.setAttribute("aria-label",c),m.disabled=!0,m.style.cssText=`border:none;background:none;cursor:pointer;padding:4px 6px;border-radius:${RADIUS.control};font-size:12px;color:${CLR.label};flex-shrink:0;opacity:0.4;`,m.addEventListener("mouseenter",()=>{m.disabled||(m.style.background=CLR.bgHover)}),m.addEventListener("mouseleave",()=>{m.style.background="none"}),m}const p=l("\u25B2","Previous match"),i=l("\u25BC","Next match");let b=[],d=-1;function a(){const x=b.length===0;p.disabled=x,i.disabled=x,p.style.opacity=x?"0.4":"",i.style.opacity=x?"0.4":""}function y(){for(const x of b)x.parentNode?.replaceChild(e.createTextNode(x.textContent??""),x);t.normalize(),b=[],d=-1}function s(x){if(b.length===0)return;d>=0&&(b[d].style.outline="none"),d=(x%b.length+b.length)%b.length;const c=b[d];c.style.outline=`2px solid ${CLR.iconActive}`,c.style.outlineOffset="1px",c.scrollIntoView({behavior:"smooth",block:"center"}),r.textContent=`${d+1}/${b.length}`}function f(x){y();const c=x.trim();if(!c){r.textContent="",a();return}const m=c.toLowerCase(),u=e.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(A){const E=A.parentElement;return!E||E.closest("script,style,.wmap-guide-toc")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),h=[];let w;for(;w=u.nextNode();)h.push(w);for(const A of h){const E=A.textContent??"",C=E.toLowerCase();if(!C.includes(m))continue;const T=e.createDocumentFragment();let D=0,S=C.indexOf(m);for(;S!==-1;){S>D&&T.appendChild(e.createTextNode(E.slice(D,S)));const g=e.createElement("mark");g.textContent=E.slice(S,S+c.length),T.appendChild(g),b.push(g),D=S+c.length,S=C.indexOf(m,D)}D<E.length&&T.appendChild(e.createTextNode(E.slice(D))),A.parentNode?.replaceChild(T,A)}a(),b.length===0?r.textContent="No matches":s(0)}return o.addEventListener("input",()=>f(o.value)),o.addEventListener("keydown",x=>{x.key==="Enter"?(x.preventDefault(),s(d+(x.shiftKey?-1:1))):x.key==="Escape"&&(o.value?(o.value="",f("")):o.blur())}),p.addEventListener("click",()=>s(d-1)),i.addEventListener("click",()=>s(d+1)),n.append(o,r,p,i),n}function Ue(e,t,n){const o=[...t.querySelectorAll("h2[id]")];if(o.length<2)return;for(const c of t.querySelectorAll("h1[id],h2[id],h3[id],h4[id]"))c.style.scrollMarginTop=`${je}px`;const r=e.createElement("div");r.classList.add("wmap-guide-toc"),r.style.cssText=`position:sticky;top:0;z-index:2;background:${CLR.menuBg};border-bottom:1px solid ${CLR.menuBorder};font-family:system-ui,-apple-system,"Segoe UI",sans-serif;`;const l=e.createElement("div");l.style.cssText=`display:flex;align-items:center;gap:4px;height:${he}px;padding:0 12px;box-sizing:border-box;`;const p=e.createElement("span");p.innerHTML='<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>',p.style.cssText=`display:inline-flex;transition:transform ${MOTION.base};flex-shrink:0;`;const i=e.createElement("button");i.type="button";const b="wmap-guide-toc-panel";i.setAttribute("aria-expanded","false"),i.setAttribute("aria-controls",b),i.style.cssText=`display:flex;align-items:center;gap:6px;border:none;background:none;cursor:pointer;padding:6px 8px;margin:0 -8px 0 -8px;border-radius:${RADIUS.control};font-size:13px;font-weight:600;color:${CLR.text};`;const d=e.createElement("span");d.textContent=`Contents (${o.length})`,i.append(p,d),i.addEventListener("mouseenter",()=>{i.style.background=CLR.bgHover}),i.addEventListener("mouseleave",()=>{i.style.background="none"});const a=e.createElement("button");a.type="button",a.textContent="\u2191 Top",a.style.cssText=`margin-left:auto;border:none;background:none;cursor:pointer;padding:6px 8px;border-radius:${RADIUS.control};font-size:12px;color:${CLR.label};`,a.addEventListener("mouseenter",()=>{a.style.background=CLR.bgHover}),a.addEventListener("mouseleave",()=>{a.style.background="none"}),a.addEventListener("click",()=>{x.close(),t.scrollTo({top:0,behavior:"smooth"})}),n?l.append(i,Ve(e,t),a):l.append(i,a);const y=e.createElement("div");y.id=b,y.hidden=!0,y.style.cssText="padding:2px 12px 12px;max-height:min(60vh,440px);overflow-y:auto;";const s=/^\s*\d+(?:\.\d+)*\.\s+/;for(const c of t.querySelectorAll("h2[id],h3[id],h4[id]")){const m=c.firstChild;m?.nodeType===Node.TEXT_NODE&&(m.textContent=(m.textContent??"").replace(s,""))}const f=e.createElement("ul");f.setAttribute("role","list"),f.style.cssText="list-style:none;margin:0;padding:0;columns:200px;column-gap:24px;";for(const c of o){const m=e.createElement("li");m.style.cssText="break-inside:avoid;";const u=e.createElement("a");u.href=`#${c.id}`,u.textContent=c.textContent??"",u.style.cssText=`display:block;padding:4px 6px;margin:0 -6px;border-radius:${RADIUS.control};font-size:12.5px;color:${CLR.iconActive};text-decoration:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;`,u.addEventListener("mouseenter",()=>{u.style.background=CLR.bgHover}),u.addEventListener("mouseleave",()=>{u.style.background="none"}),u.addEventListener("click",h=>{h.preventDefault(),x.close(),c.scrollIntoView({behavior:"smooth",block:"start"})}),m.appendChild(u),f.appendChild(m)}y.appendChild(f);const x=wireExpandToggle(i,c=>{y.hidden=!c,i.setAttribute("aria-expanded",String(c)),p.style.transform=c?"rotate(180deg)":"none"});r.append(l,y),t.prepend(r)}function xe(e,t,n,o,r){const l=t,p=l.__wmapDemoApi;l.__wmapDemoApi=o;const i=e.createElement("div");return i.classList.add("wmap-guide-content"),i.innerHTML=n,Ue(e,i,r),{content:i,restoreApi:()=>{l.__wmapDemoApi===o&&(l.__wmapDemoApi=p)}}}function ve(e,t){const n=t,o=e.querySelector("script");if(o){const r=e.ownerDocument.createElement("script");r.textContent=o.textContent,e.appendChild(r);const l=e.querySelector(".wmap-guide");return l&&n.__wmapPopulateGuideDemos?.(l),n.__wmapDestroyGuideDemos}}function Ge(e,t,n,o){const r=o?.ownerDocument??document,l=r.defaultView??window,{content:p,restoreApi:i}=xe(r,l,t,n,!0);Object.assign(p.style,{flex:"1",overflow:"auto",minHeight:"0",minWidth:"0"});let b;const d=openFloatingWindow({title:e,anchor:o,ownerDocument:r,printable:!0,onMaximizeChange:a=>{p.style.setProperty("--wmap-guide-reading-width",a?"1000px":"720px")},onClose:()=>{j===d&&(j=null),b?.(),i()}});return d.contentWrap.appendChild(p),b=ve(p,l),d}function Xe(e,t,n,o){const r=e.document;r.title=t,Object.assign(r.documentElement.style,{height:"100%"}),Object.assign(r.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:FONT.family}),copyWmapThemeTokens(document.documentElement,r.documentElement);const l=syncWmapPopupTheme(document.documentElement,r.documentElement),{content:p,restoreApi:i}=xe(r,e,n,o,!1);Object.assign(p.style,{flex:"1",overflow:"auto",minHeight:"0",minWidth:"0"}),r.body.appendChild(p);const b=ve(p,e);let d=!1;const a=()=>{if(!d){d=!0,clearInterval(y),l();try{b?.()}catch{}i(),j===s&&(j=null)}},y=setInterval(()=>{e.closed&&a()},400);e.addEventListener("pagehide",a);const s={close:()=>{e.closed||e.close(),a()}};return s}export function openUserGuideWindow(e,t,n,o){j&&(j.close(),j=null);const r=n?.title??"Wafer Map \u2014 User Guide",l=(n?.html??"")+t,i=(o?.ownerDocument.defaultView??window).open("","_blank","width=800,height=820");j=i?Xe(i,r,l,e):Ge(r,l,e,o)}export function openWaferMapGuide(e,t){Promise.all([import("./userGuideHtml.js"),import("./renderWaferMap.js"),import("./renderWaferGallery.js")]).then(([n,o,r])=>{openUserGuideWindow({buildWaferMap:Te,renderWaferMap:o.renderWaferMap,renderWaferGallery:r.renderWaferGallery,analyzeWaferMap:He},n.USER_GUIDE_HTML,e,t)})}export function openReportModal(e,t){const n=t?.ownerDocument??document,o=n.createElement("iframe");o.srcdoc=e,o.title="Summary report",Object.assign(o.style,{border:"0",width:"100%",flex:"1",minHeight:"0",background:"#fff"});const r=n.createElement("div");Object.assign(r.style,{display:"flex",justifyContent:"flex-end",padding:"6px 14px",borderBottom:`1px solid ${CLR.menuBorder}`,flexShrink:"0"});const l=n.createElement("button");l.type="button",wireControlHover(l,"bare"),l.textContent="Open as full page \u2197",Object.assign(l.style,{border:"none",background:"none",color:CLR.iconActive,cursor:"pointer",fontSize:FONT.body,textDecoration:"underline",padding:"0"}),l.addEventListener("click",()=>De(e)),r.appendChild(l);const p=openModal({title:"Summary report",anchor:t?.anchor,ownerDocument:n,printable:()=>o.contentWindow?.print(),onClose:()=>{}});return p.contentWrap.style.flexDirection="column",p.contentWrap.appendChild(r),p.contentWrap.appendChild(o),p}
9
+ }`,n.head.appendChild(te),reparentTooltip(i),t?(l.addEventListener("click",v=>{v.target===l&&I()}),n.addEventListener("keydown",z)):(i.addEventListener("keydown",z),i.addEventListener("mousedown",Y),Y()),nextFrame(()=>(m.isConnected?m:i).focus(),o);function ye(v){d=v,!u&&!E&&(i.style.height=v)}return{backdrop:l,box:i,contentWrap:$,close:I,bringToFront:Y,setNaturalHeight:ye}}export function openModal(e){return me({...e,mode:"modal"})}export function openFloatingWindow(e){return me({...e,mode:"window"})}const le=new WeakSet;export function openReparentedModal(e,t={}){if(e.length===0||e.some(r=>le.has(r)))return null;const n=e.map(r=>({el:r,parent:r.parentElement,next:r.nextSibling})),o=openModal({ownerDocument:t.ownerDocument,title:t.title,boxSize:t.boxSize,anchor:t.anchor??e[0],onClose:()=>{for(const r of n){if(le.delete(r.el),!r.parent)continue;const l=r.next&&r.next.parentNode===r.parent?r.next:null;r.parent.insertBefore(r.el,l)}t.onClosed?.()}});for(const r of n)le.add(r.el),o.contentWrap.appendChild(r.el);return o}export function makePaletteBtn(e,t,n,o){const r=e.makeCheckMenuBtn("palette","Colour scheme",()=>{const p=t(),i=[];if(p.plotMode==="hardBin"||p.plotMode==="softBin"){const b=p.binColorScheme??"default";i.push({section:"Bin colours"});for(const d of Ae())i.push({label:d.label,active:b===d.name,onClick:()=>o({binColorScheme:d.name})});if(n()){const d=p.useDefinedBinColors??!0;i.push({section:"Bin definitions"}),i.push({label:"Use colours from bin definitions",active:d,onClick:()=>o({useDefinedBinColors:!d})})}}else{const b=p.valueColorScheme??"default";i.push({section:"Value colours"});for(const a of Me())i.push({label:a.label,active:b===a.name,onClick:()=>o({valueColorScheme:a.name})});const d=p.reverseValueScheme??!1;i.push({section:"Direction"}),i.push({label:"Reverse gradient",active:d,onClick:()=>o({reverseValueScheme:!d})})}return i},()=>{});function l(){r.style.display=t().plotMode==="metadata"?"none":""}return{btn:r,sync:l}}export function requestedPassFailDisplay(e){return e.passFailDisplay??"off"}export function overlayMenuRows(e,t,n,o){return[{label:"Ring boundaries",active:!!e.showRingBoundaries,onClick:()=>o({showRingBoundaries:!e.showRingBoundaries})},{label:"Quadrant lines",active:!!e.showQuadrantBoundaries,onClick:()=>o({showQuadrantBoundaries:!e.showQuadrantBoundaries})},{label:"Die labels",active:!!e.showDieLabels,onClick:()=>o({showDieLabels:!e.showDieLabels})},{label:"Reticle grid",active:!!e.showReticle,enabled:t,onClick:()=>o({showReticle:!e.showReticle})},{label:"XY indicator",active:!!e.showXYIndicator,onClick:()=>o({showXYIndicator:!e.showXYIndicator})},...passFailMenuRows({...n,display:requestedPassFailDisplay(e)},r=>o({passFailDisplay:r})),{label:"Mark failing dies",active:!!e.markFailingDies,enabled:n.binMode,disabledHint:n.binMode?void 0:"Available on hard/soft bin maps",onClick:()=>o({markFailingDies:!e.markFailingDies})},{section:""},{label:"Clear overlays",active:!1,action:!0,enabled:anyOverlayActive(e),disabledHint:"No overlays are active",onClick:()=>o({showRingBoundaries:!1,showQuadrantBoundaries:!1,showDieLabels:!1,showReticle:!1,showXYIndicator:!1,passFailDisplay:"off",markFailingDies:!1})}]}export function anyOverlayActive(e){return!!(e.showRingBoundaries||e.showQuadrantBoundaries||e.showDieLabels||e.showReticle||e.showXYIndicator||e.markFailingDies||requestedPassFailDisplay(e)!=="off")}export function passFailMenuRows(e,t){if(e.functionalActive)return[];const n=[];return e.hasLimits&&n.push({label:"Limit pass/fail",active:e.display==="spec",onClick:()=>t(e.display==="spec"?"off":"spec")}),e.hasRecorded&&n.push({label:"Test pass/fail",active:e.display==="test",onClick:()=>t(e.display==="test"?"off":"test")}),n}export function makeLogScaleBtn(e,t,n){const o=e.makeBtn("logScale","Toggle log scale",()=>{n({logScale:!t().logScale})});function r(){const l=t(),p=l.plotMode,i=p==="value"||p==="stackedValues";o.style.display=i&&requestedPassFailDisplay(l)==="off"&&!l.functionalActive?"":"none",e.setActive(o,!!l.logScale)}return{btn:o,sync:r}}const Fe=[{value:"default",label:"Default (right)"},{value:"compact",label:"Compact (right)"},{value:"left",label:"Left"},{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"floating",label:"Floating"}];export function makeLegendStyleBtn(e,t,n,o){const r=e.makeCheckMenuBtn("legend","Legend style",()=>{const p=t().legendPosition??"default",i=[];let b=!0;if(o){const d=o.blockedReason();b=d?!0:o.get(),i.push({label:"Legend on each map",active:b,enabled:!d,disabledHint:d??void 0,onClick:()=>o.set(!o.get())})}if(be(t().plotMode)){o&&i.push({section:"Position on each map"});for(const d of Fe)i.push({label:d.label,active:b&&p===d.value,enabled:b,disabledHint:b?void 0:'Turn on "Legend on each map" to position it',onClick:()=>n(d.value)})}return i},()=>{});function l(){r.style.display=o||be(t().plotMode)?"":"none"}return{btn:r,sync:l}}function be(e){return e==="hardBin"||e==="softBin"||e==="metadata"}export function makeOverlaysBtn(e,t,n){return e.makeCheckMenuBtn("overlays","Overlays",()=>t(),o=>e.setActive(o,n()))}export function makeOrientationBtn(e,t,n){return e.makeCheckMenuBtn("orient","Orientation",()=>[{section:"Rotate"},{label:"Rotate 90\xB0 clockwise",active:!1,onClick:()=>{const o=t().rotation??0;n({rotation:ROTATIONS[(ROTATIONS.indexOf(o)+1)%4]})}},{section:"Flip"},{label:"Flip horizontal",active:!!t().flipX,onClick:()=>n({flipX:!t().flipX})},{label:"Flip vertical",active:!!t().flipY,onClick:()=>n({flipY:!t().flipY})},{section:""},{label:"Reset orientation",active:!1,action:!0,enabled:!!(t().rotation||t().flipX||t().flipY),disabledHint:"Already in the original orientation",onClick:()=>n({rotation:0,flipX:!1,flipY:!1})}],o=>{const{rotation:r,flipX:l,flipY:p}=t();e.setActive(o,!!(r||l||p))})}let j=null;const he=40,je=he+8;function Ve(e,t){const n=e.createElement("div");n.classList.add("wmap-guide-search"),n.style.cssText="display:flex;align-items:center;gap:2px;margin-left:10px;flex:1;min-width:80px;max-width:260px;";const o=e.createElement("input");o.type="text",o.placeholder="Search guide\u2026",o.setAttribute("aria-label","Search guide"),o.style.cssText=`flex:1;min-width:0;padding:4px 8px;font-size:12px;background:${CLR.menuBg};color:${CLR.text};border:1px solid ${CLR.menuBorder};border-radius:${RADIUS.control};outline:none;`,o.addEventListener("focus",()=>{o.style.borderColor=CLR.iconActive}),o.addEventListener("blur",()=>{o.style.borderColor=CLR.menuBorder});const r=e.createElement("span");r.setAttribute("role","status"),r.setAttribute("aria-live","polite"),r.style.cssText=`font-size:12px;color:${CLR.label};min-width:44px;text-align:center;flex-shrink:0;white-space:nowrap;`;function l(x,c){const m=e.createElement("button");return m.type="button",m.textContent=x,m.setAttribute("aria-label",c),m.disabled=!0,m.style.cssText=`border:none;background:none;cursor:pointer;padding:4px 6px;border-radius:${RADIUS.control};font-size:12px;color:${CLR.label};flex-shrink:0;opacity:0.4;`,m.addEventListener("mouseenter",()=>{m.disabled||(m.style.background=CLR.bgHover)}),m.addEventListener("mouseleave",()=>{m.style.background="none"}),m}const p=l("\u25B2","Previous match"),i=l("\u25BC","Next match");let b=[],d=-1;function a(){const x=b.length===0;p.disabled=x,i.disabled=x,p.style.opacity=x?"0.4":"",i.style.opacity=x?"0.4":""}function y(){for(const x of b)x.parentNode?.replaceChild(e.createTextNode(x.textContent??""),x);t.normalize(),b=[],d=-1}function s(x){if(b.length===0)return;d>=0&&(b[d].style.outline="none"),d=(x%b.length+b.length)%b.length;const c=b[d];c.style.outline=`2px solid ${CLR.iconActive}`,c.style.outlineOffset="1px",c.scrollIntoView({behavior:"smooth",block:"center"}),r.textContent=`${d+1}/${b.length}`}function f(x){y();const c=x.trim();if(!c){r.textContent="",a();return}const m=c.toLowerCase(),u=e.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(A){const E=A.parentElement;return!E||E.closest("script,style,.wmap-guide-toc")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),h=[];let w;for(;w=u.nextNode();)h.push(w);for(const A of h){const E=A.textContent??"",C=E.toLowerCase();if(!C.includes(m))continue;const T=e.createDocumentFragment();let D=0,S=C.indexOf(m);for(;S!==-1;){S>D&&T.appendChild(e.createTextNode(E.slice(D,S)));const g=e.createElement("mark");g.textContent=E.slice(S,S+c.length),T.appendChild(g),b.push(g),D=S+c.length,S=C.indexOf(m,D)}D<E.length&&T.appendChild(e.createTextNode(E.slice(D))),A.parentNode?.replaceChild(T,A)}a(),b.length===0?r.textContent="No matches":s(0)}return o.addEventListener("input",()=>f(o.value)),o.addEventListener("keydown",x=>{x.key==="Enter"?(x.preventDefault(),s(d+(x.shiftKey?-1:1))):x.key==="Escape"&&(o.value?(o.value="",f("")):o.blur())}),p.addEventListener("click",()=>s(d-1)),i.addEventListener("click",()=>s(d+1)),n.append(o,r,p,i),n}function Ue(e,t,n){const o=[...t.querySelectorAll("h2[id]")];if(o.length<2)return;for(const c of t.querySelectorAll("h1[id],h2[id],h3[id],h4[id]"))c.style.scrollMarginTop=`${je}px`;const r=e.createElement("div");r.classList.add("wmap-guide-toc"),r.style.cssText=`position:sticky;top:0;z-index:2;background:${CLR.menuBg};border-bottom:1px solid ${CLR.menuBorder};font-family:system-ui,-apple-system,"Segoe UI",sans-serif;`;const l=e.createElement("div");l.style.cssText=`display:flex;align-items:center;gap:4px;height:${he}px;padding:0 12px;box-sizing:border-box;`;const p=e.createElement("span");p.innerHTML='<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>',p.style.cssText=`display:inline-flex;transition:transform ${MOTION.base};flex-shrink:0;`;const i=e.createElement("button");i.type="button";const b="wmap-guide-toc-panel";i.setAttribute("aria-expanded","false"),i.setAttribute("aria-controls",b),i.style.cssText=`display:flex;align-items:center;gap:6px;border:none;background:none;cursor:pointer;padding:6px 8px;margin:0 -8px 0 -8px;border-radius:${RADIUS.control};font-size:13px;font-weight:600;color:${CLR.text};`;const d=e.createElement("span");d.textContent=`Contents (${o.length})`,i.append(p,d),i.addEventListener("mouseenter",()=>{i.style.background=CLR.bgHover}),i.addEventListener("mouseleave",()=>{i.style.background="none"});const a=e.createElement("button");a.type="button",a.textContent="\u2191 Top",a.style.cssText=`margin-left:auto;border:none;background:none;cursor:pointer;padding:6px 8px;border-radius:${RADIUS.control};font-size:12px;color:${CLR.label};`,a.addEventListener("mouseenter",()=>{a.style.background=CLR.bgHover}),a.addEventListener("mouseleave",()=>{a.style.background="none"}),a.addEventListener("click",()=>{x.close(),t.scrollTo({top:0,behavior:"smooth"})}),n?l.append(i,Ve(e,t),a):l.append(i,a);const y=e.createElement("div");y.id=b,y.hidden=!0,y.style.cssText="padding:2px 12px 12px;max-height:min(60vh,440px);overflow-y:auto;";const s=/^\s*\d+(?:\.\d+)*\.\s+/;for(const c of t.querySelectorAll("h2[id],h3[id],h4[id]")){const m=c.firstChild;m?.nodeType===Node.TEXT_NODE&&(m.textContent=(m.textContent??"").replace(s,""))}const f=e.createElement("ul");f.setAttribute("role","list"),f.style.cssText="list-style:none;margin:0;padding:0;columns:200px;column-gap:24px;";for(const c of o){const m=e.createElement("li");m.style.cssText="break-inside:avoid;";const u=e.createElement("a");u.href=`#${c.id}`,u.textContent=c.textContent??"",u.style.cssText=`display:block;padding:4px 6px;margin:0 -6px;border-radius:${RADIUS.control};font-size:12.5px;color:${CLR.iconActive};text-decoration:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;`,u.addEventListener("mouseenter",()=>{u.style.background=CLR.bgHover}),u.addEventListener("mouseleave",()=>{u.style.background="none"}),u.addEventListener("click",h=>{h.preventDefault(),x.close(),c.scrollIntoView({behavior:"smooth",block:"start"})}),m.appendChild(u),f.appendChild(m)}y.appendChild(f);const x=wireExpandToggle(i,c=>{y.hidden=!c,i.setAttribute("aria-expanded",String(c)),p.style.transform=c?"rotate(180deg)":"none"});r.append(l,y),t.prepend(r)}function xe(e,t,n,o,r){const l=t,p=l.__wmapDemoApi;l.__wmapDemoApi=o;const i=e.createElement("div");return i.classList.add("wmap-guide-content"),i.innerHTML=n,Ue(e,i,r),{content:i,restoreApi:()=>{l.__wmapDemoApi===o&&(l.__wmapDemoApi=p)}}}function ve(e,t){const n=t,o=e.querySelector("script");if(o){const r=e.ownerDocument.createElement("script");r.textContent=o.textContent,e.appendChild(r);const l=e.querySelector(".wmap-guide");return l&&n.__wmapPopulateGuideDemos?.(l),n.__wmapDestroyGuideDemos}}function Ge(e,t,n,o){const r=o?.ownerDocument??document,l=r.defaultView??window,{content:p,restoreApi:i}=xe(r,l,t,n,!0);Object.assign(p.style,{flex:"1",overflow:"auto",minHeight:"0",minWidth:"0"});let b;const d=openFloatingWindow({title:e,anchor:o,ownerDocument:r,printable:!0,onMaximizeChange:a=>{p.style.setProperty("--wmap-guide-reading-width",a?"1000px":"720px")},onClose:()=>{j===d&&(j=null),b?.(),i()}});return d.contentWrap.appendChild(p),b=ve(p,l),d}function Xe(e,t,n,o){const r=e.document;r.title=t,Object.assign(r.documentElement.style,{height:"100%"}),Object.assign(r.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:FONT.family}),copyWmapThemeTokens(document.documentElement,r.documentElement);const l=syncWmapPopupTheme(document.documentElement,r.documentElement),{content:p,restoreApi:i}=xe(r,e,n,o,!1);Object.assign(p.style,{flex:"1",overflow:"auto",minHeight:"0",minWidth:"0"}),r.body.appendChild(p);const b=ve(p,e);let d=!1;const a=()=>{if(!d){d=!0,clearInterval(y),l();try{b?.()}catch{}i(),j===s&&(j=null)}},y=setInterval(()=>{e.closed&&a()},400);e.addEventListener("pagehide",a);const s={close:()=>{e.closed||e.close(),a()}};return s}export function openUserGuideWindow(e,t,n,o){j&&(j.close(),j=null);const r=n?.title??"Wafer Map \u2014 User Guide",l=(n?.html??"")+t,i=(o?.ownerDocument.defaultView??window).open("","_blank","width=800,height=820");j=i?Xe(i,r,l,e):Ge(r,l,e,o)}export function openWaferMapGuide(e,t){Promise.all([import("./userGuideHtml.js"),import("./renderWaferMap.js"),import("./renderWaferGallery.js")]).then(([n,o,r])=>{openUserGuideWindow({buildWaferMap:Te,renderWaferMap:o.renderWaferMap,renderWaferGallery:r.renderWaferGallery,analyzeWaferMap:He},n.USER_GUIDE_HTML,e,t)})}export function openReportModal(e,t){const n=t?.ownerDocument??document,o=n.createElement("iframe");o.srcdoc=e,o.title="Summary report",Object.assign(o.style,{border:"0",width:"100%",flex:"1",minHeight:"0",background:"#fff"});const r=n.createElement("div");Object.assign(r.style,{display:"flex",justifyContent:"flex-end",padding:"6px 14px",borderBottom:`1px solid ${CLR.menuBorder}`,flexShrink:"0"});const l=n.createElement("button");l.type="button",wireControlHover(l,"bare"),l.textContent="Open as full page \u2197",Object.assign(l.style,{border:"none",background:"none",color:CLR.iconActive,cursor:"pointer",fontSize:FONT.body,textDecoration:"underline",padding:"0"}),l.addEventListener("click",()=>De(e)),r.appendChild(l);const p=openModal({title:"Summary report",anchor:t?.anchor,ownerDocument:n,printable:()=>o.contentWindow?.print(),onClose:()=>{}});return p.contentWrap.style.flexDirection="column",p.contentWrap.appendChild(r),p.contentWrap.appendChild(o),p}