@wafertools/wafermap 0.30.1 → 0.30.2

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 (38) hide show
  1. package/AGENTS.md +59 -10
  2. package/CHANGELOG.md +80 -8
  3. package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
  4. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  5. package/dist/packages/canvas-adapter/charts/correlation.js +2 -2
  6. package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/scatter.js +1 -1
  8. package/dist/packages/canvas-adapter/chunked.d.ts +45 -0
  9. package/dist/packages/canvas-adapter/chunked.js +1 -0
  10. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  11. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +55 -0
  12. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  13. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  14. package/dist/packages/canvas-adapter/summaryPanel.d.ts +55 -9
  15. package/dist/packages/canvas-adapter/summaryPanel.js +3 -3
  16. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  17. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  18. package/dist/packages/canvas-adapter/userGuideHtml.js +1 -1
  19. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  20. package/dist/packages/canvas-adapter/version.js +1 -1
  21. package/dist/packages/core/aggregates.js +1 -1
  22. package/dist/packages/core/utils.d.ts +55 -0
  23. package/dist/packages/core/utils.js +1 -1
  24. package/dist/packages/renderer/binColors.d.ts +14 -0
  25. package/dist/packages/renderer/binColors.js +1 -1
  26. package/dist/packages/renderer/buildView.js +1 -1
  27. package/dist/packages/renderer/buildWaferMap.js +1 -1
  28. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  29. package/dist/packages/stats/capability.d.ts +56 -0
  30. package/dist/packages/stats/capability.js +1 -1
  31. package/dist/packages/stats/correlation.d.ts +30 -0
  32. package/dist/packages/stats/correlation.js +1 -1
  33. package/dist/packages/stats/findingsNarrative.js +1 -1
  34. package/dist/packages/stats/math.d.ts +27 -2
  35. package/dist/packages/stats/math.js +1 -1
  36. package/dist/packages/stats/renderSummaryReport.js +4 -4
  37. package/llms.txt +12 -7
  38. package/package.json +2 -2
@@ -1 +1 @@
1
- import{buildFacetTable as De,facetValueOf as $e,FACET_NONE_VALUE as Le}from"../stats/facets.js";import{mergeTestDefs as Ee}from"../stats/mergeTestDefs.js";import{isParametricTest as Ie}from"../renderer/buildWaferMap.js";import{waferDisplayLabel as Oe}from"../core/waferLabel.js";import{INPUT_DEFAULT_PASS_BINS as A,itemPassBins as Pe,passBinsLabel as ne}from"../core/passBins.js";import{NO_DATA_FILL as ae}from"../renderer/colorMap.js";import{describeWaferPopulation as Ae,populationStat as Re}from"../stats/population.js";import{LEADING as We,ALPHA as je,SPACE as S,EDGE_GUTTER as K,FONT as G,CLR as k,RADIUS as Ge,SHADOW as He,controlStyle as Ye,wireControlHover as oe,wireTooltip as Fe}from"./toolbar.js";import{ICONS as Ne}from"./icons.js";import{renderCapabilityPanel as Me}from"./charts/capability.js";import{renderBoxplotPanel as Ve}from"./charts/boxplot.js";import{renderTrendPanel as _e}from"./charts/trend.js";import{renderHistogramPanel as Ue}from"./charts/histogram.js";import{renderCorrelationPanel as ze}from"./charts/correlation.js";import{renderScatterPanel as qe}from"./charts/scatter.js";import{renderBarPanel as re}from"./charts/barPanel.js";import{renderBinClusterPanel as Qe}from"./charts/binCluster.js";import{renderTestPassRatePanel as Ke}from"./charts/testPassRate.js";import{QUANTITY as Xe}from"./charts/palette.js";import{cardFrameStyle as Je,makeChartGridWrap as X,makeLabeledSelect as Ze,makeLinkedGroupSelect as et}from"./charts/chartShell.js";import{buildYieldData as M,buildYieldDataCombined as se}from"../stats/yield.js";import{buildBinParetoData as tt}from"../stats/binPareto.js";import{buildLotTestSection as nt,buildLotFunctionalSection as at,buildMetadataStripBox as ot}from"./summaryPanel.js";import{buildRegionYieldData as ie,buildRingRegions as rt,buildQuadrantRegions as st}from"../stats/regions.js";import{renderRegionYieldDiagram as le}from"./charts/regionYieldDiagram.js";const it=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}];export function createInsightsTab(D){const{getItems:de,getLotStats:ce,getBinColors:J,getRingCount:pe,onSaveImage:T,onSaveText:V,openWafer:H,focusTest:Z}=D,ue=D.showMetadataStrip??!0,R=D.contentInset??K,d=D.ownerDocument??document,I=d.createElement("div");Object.assign(I.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const fe=K,O=d.createElement("div");Object.assign(O.style,{paddingLeft:fe});const B=d.createElement("div");Object.assign(B.style,{display:"flex",gap:S.xs,alignItems:"center",background:k.menuBg,border:`1px solid ${k.menuBorder}`,borderRadius:Ge.container,boxShadow:He.panel,padding:`0 ${S.lg}`,marginBottom:S.lg,marginLeft:R,marginRight:R}),B.setAttribute("role","tablist"),B.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const n=Array.from(B.querySelectorAll('[role="tab"]')),o=n.indexOf(d.activeElement);if(o===-1)return;e.preventDefault();const c=n[(o+(e.key==="ArrowRight"?1:-1)+n.length)%n.length];c.focus(),c.click()});const W=d.createElement("div");Object.assign(W.style,{display:"flex",flexDirection:"column",gap:S.lg,marginTop:"0",paddingLeft:R,paddingRight:R}),I.appendChild(O),I.appendChild(B),I.appendChild(W);let j=D.defaultView??"overview",P,L=null,$=null,Y={includeLimits:void 0,clipOutliers:!1};const _=e=>{$!==e&&($=e,N())};let F=[];function U(e,n,o){H?.(e,n,o)}function me(e){return H?{open:(n,o)=>U(n,`Wafer ${e.find(c=>c.waferIndex===n)?.label??n}`,o)}:Z&&e.length===1?{open:(n,o)=>Z(o),label:"show this test on the map"}:null}function be(){return de().map((e,n)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:Oe(e,n),waferIndex:n,passBins:Pe(e),statsSummary:e.statsSummary,testDefs:e.testDefs}).filter(e=>e!=null)}function ee(e,n){Object.assign(e.style,{background:"none",border:"none",borderBottom:n?`2px solid ${k.iconActive}`:"2px solid transparent",color:n?k.iconActive:k.label,fontWeight:n?"700":"500",fontSize:G.body,padding:`${S.sm} ${K} ${S.md}`,cursor:"pointer",marginBottom:"-1px"})}function ge(e,n){const o=d.createElement("button");o.type="button",o.textContent=n;const c=e===j;return ee(o,c),o.dataset.on=c?"true":"false",oe(o,"bare"),o.dataset.wmapInsightsTab=e,o.setAttribute("role","tab"),o.setAttribute("aria-selected",c?"true":"false"),o.tabIndex=c?0:-1,o.addEventListener("click",()=>{j!==e&&(j=e,N())}),o}function ye(e){const n=d.createElement("button");return n.type="button",n.textContent=`\u2039 ${e.label}`,ee(n,!1),n.dataset.wmapInsightsBack="1",n.addEventListener("click",e.onBack),n}function he(e,n,o,c=!0){const l=X(d),f=J();let y="label";const u=o??"group",m=ne(e.map(s=>s.passBins)),i=ce?.(),b=new Map(i?.lotYieldSeries.map(s=>[s.waferIndex,s.yieldPercent])),h=s=>({...s,label:s.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),yieldPercent:b.get(s.waferIndex),key:s.waferIndex}),g=e.map(h),p=n?.map(s=>({key:s.key,items:s.items.map(h)})),t=()=>p?se(p,A,y):M(g,A,y),x={title:n?`Yield by ${u} (pass: ${m})`:`Yield by wafer (pass: ${m})`,data:t(),selfControl:{current:y,options:[["yield","Sort: yield"],["label",n?`Sort: ${u}`:"Sort: wafer ID"]],onChange:s=>(y=s,{data:t()})},barColor:()=>Xe,valueLabel:s=>`${s.percent.toFixed(1)}%`,reference:s=>{if(s.length<3)return null;const v=s.map(Q=>Q.percent).sort((Q,ke)=>Q-ke),E=v.length%2?v[(v.length-1)/2]:(v[v.length/2-1]+v[v.length/2])/2;return{value:E,label:`median ${E.toFixed(1)}%`}},drill:p?{onOpenGroup:s=>{const v=p.find(E=>E.key===s.label)?.items??[];return{data:M(v,A,y),title:`Yield by wafer \u2014 ${u}: ${s.label} (pass: ${m})`}},onBack:()=>({data:t(),title:`Yield by ${u} (pass: ${m})`}),groupLabelText:u}:void 0,onOpen:H?s=>{typeof s.key=="number"&&U(s.key,`Wafer ${s.label}`)}:void 0,ownerDocument:d};let C=null;if(c&&(C=re(x,T),C.card.style.minHeight="360px",l.appendChild(C.card)),n){const s=Qe({title:"Hard bin pareto",groups:n.map(v=>({key:v.key,items:v.items.map(E=>({dies:E.dies,hardBinCounts:E.statsSummary?.stats.hardBinCounts,softBinCounts:E.statsSummary?.stats.softBinCounts}))})),onSaveImage:T,ownerDocument:d});return s.card.style.minHeight="360px",l.appendChild(s.card),{card:l,destroy:()=>{C?.destroy(),s.destroy()}}}let a="hbin";const r=s=>s===void 0?ae:(a==="hbin"?f.hard:f.soft).get(s)??ae,w=e.map(s=>({dies:s.dies,hardBinCounts:s.statsSummary?.stats.hardBinCounts,softBinCounts:s.statsSummary?.stats.softBinCounts})),te=()=>tt(w,a),Be={title:"Hard bin pareto",data:te(),selfControl:{current:a,options:[["hbin","Hard bins"],["sbin","Soft bins"]],onChange:s=>(a=s,{data:te(),title:`${a==="hbin"?"Hard":"Soft"} bin pareto`})},barColor:s=>r(s.binCode),ownerDocument:d},q=re(Be,T);return q.card.style.minHeight="360px",l.appendChild(q.card),{card:l,destroy:()=>{C?.destroy(),q.destroy()}}}function z(){const e=d.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...Je(),display:"flex",flexDirection:"column",gap:S.lg,minWidth:"0"}),e}function Ce(e){if(O.innerHTML="",O.style.marginBottom="0",!ue)return;const n=ot(e.map(o=>({metadata:o.metadata})),void 0,{facetableOnly:!1});n&&(n.style.marginBottom="0",O.appendChild(n),O.style.marginBottom=S.xs)}function xe(e,n,o,c){if(!e.length)return{elements:[],testValuesCard:null,functionalCard:null,destroy:()=>{}};const l=e.map(r=>r.wafer),f=e.map(r=>r.dies),y=e.flatMap(r=>r.dies),u=e.map(r=>r.statsSummary),m=u.every(r=>r!==void 0)?u:void 0,i=pe?.()??4,b=[],h=[],p=Ke({groups:(c??[{key:"",items:e}]).map(r=>({key:r.key,items:r.items.map(w=>({dies:w.dies,testSpecYield:w.statsSummary?.stats.testSpecYield,functionalYield:w.statsSummary?.stats.functionalYield}))})),testDefs:o,onSaveImage:T,ownerDocument:d});p.card.style.minHeight="300px",b.push(p.card),h.push(p.destroy);const t=ie(f,l,i,r=>e[r].passBins,rt);if(t.length){const r=le({title:"Ring yield",mode:"ring",rows:t,onSaveImage:T,ownerDocument:d});b.push(r.card),h.push(r.destroy)}const x=ie(f,l,i,r=>e[r].passBins,st);if(x.length){const r=le({title:"Quadrant yield",mode:"quadrant",rows:x,onSaveImage:T,ownerDocument:d});b.push(r.card),h.push(r.destroy)}let C=null;if(n.length){const r=nt(y,n,void 0,m,V,f.map(w=>({dies:w})),void 0,"full");if(r){const w=z();w.appendChild(r),C=w}}let a=null;if(o.length){const r=at(y,o,m,V);if(r){const w=z();w.appendChild(r),a=w}}return{elements:b,testValuesCard:C,functionalCard:a,destroy:()=>{for(const r of h)r()}}}function Se(e){const n=ne(e.map(i=>i.passBins)),o=e.length===1,c=e[0],l=z();Object.assign(l.style,{flexDirection:"row",flexWrap:"wrap",gap:S.md});const f=i=>{const b=i.lastElementChild;return b&&Object.assign(b.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),i};function y(i,b,h){const g=d.createElement("div");Object.assign(g.style,{display:"flex",alignItems:"baseline",gap:S.sm,paddingRight:S.xxl,marginRight:S.md,borderRight:`1px solid ${k.menuBorder}`});const p=d.createElement("div");p.textContent=i,Object.assign(p.style,{fontSize:G.heading,fontWeight:"700",color:k.value,lineHeight:We.tight});const t=d.createElement("div");if(t.textContent=b,Object.assign(t.style,{fontSize:G.body,color:k.label}),g.append(p,t),h){const x=d.createElement("div");x.textContent=h,Object.assign(x.style,{fontSize:G.meta,color:k.label,opacity:je.muted}),g.appendChild(x)}return g}if(o){const i=M([{...c,key:c.waferIndex}],A)[0]?.percent;return i!==void 0&&l.appendChild(y(`${i.toFixed(1)}%`,`Yield \xB7 pass: ${n}`)),l.appendChild(y(String(c.dies.length),"Total dies")),f(l)}l.appendChild(y(String(e.length),"Wafers"));const u=M(e.map(i=>({...i,key:i.waferIndex})),A).map(i=>i.percent).filter(i=>Number.isFinite(i));if(u.length){const i=u.reduce((g,p)=>g+p,0)/u.length,b=se([{key:"all",items:e.map(g=>({...g,key:g.waferIndex}))}],A)[0]?.percent,h=b!==void 0&&b.toFixed(1)!==i.toFixed(1);l.appendChild(y(`${i.toFixed(1)}%`,`Mean per-wafer yield \xB7 pass: ${n}`,h?`${b.toFixed(1)}% by dies`:void 0))}const m=e.map(i=>i.statsSummary);if(m.every(i=>i!==void 0)){const i=m.reduce((h,g)=>h+g.stats.analyzedDies,0),b=m.reduce((h,g)=>h+g.stats.excludedDies,0);l.appendChild(y(i.toLocaleString(),"Dies analysed",b?`${b.toLocaleString()} excluded`:void 0))}else l.appendChild(y(e.reduce((i,b)=>i+b.dies.length,0).toLocaleString(),"Total dies"));return f(l)}function we(e,n,o,c,l){const f=d.createElement("div");Object.assign(f.style,{display:"flex",flexDirection:"column",gap:S.lg});const y=e.length===1&&!c;e.length&&!c&&f.appendChild(Se(e));const u=he(e,c,l,!y);f.appendChild(u.card);const m=xe(e,n,o,c);for(const i of m.elements)u.card.appendChild(i);return m.testValuesCard&&f.appendChild(m.testValuesCard),m.functionalCard&&f.appendChild(m.functionalCard),{card:f,destroy:()=>{u.destroy(),m.destroy()}}}function Te(e,n,o,c){const l=X(d),f=me(e),y=a=>{Y=a;for(const r of[g,p,t])r!==u&&r?.setAxisPrefs(a)};let u=null;const m=a=>r=>{u=a(),y(r),u=null},i=a=>({...a,testStats:a.statsSummary?.stats.perTestStats}),b=e.map(i),h=o?.map(a=>({key:a.key,items:a.items.map(i)})),g=Ve({title:"Test value distribution",axisPrefs:Y,onAxisPrefsChange:m(()=>g),onTestChange:a=>x(a),selectedTestNumber:L??void 0,items:b,testDefs:n,groups:h,groupLabelText:c,onSaveImage:T,onGroupChange:a=>_(a),onOpen:f?.open,openActionLabel:f?.label,ownerDocument:d}),p=Ue({title:"Value histogram",axisPrefs:Y,onAxisPrefsChange:m(()=>p),onTestChange:a=>x(a),selectedTestNumber:L??void 0,items:e,testDefs:n,groups:o,onGroupChange:a=>_(a),onSaveImage:T,ownerDocument:d}),t=_e({title:"Wafer-to-wafer trend",axisPrefs:Y,onAxisPrefsChange:m(()=>t),onTestChange:a=>x(a),selectedTestNumber:L??void 0,items:e.map(a=>({label:a.label,key:a.waferIndex,dies:a.dies,testStats:a.statsSummary?.stats.perTestStats})),testDefs:n,onSaveImage:T,centreLabel:Re(Ae(e.map(a=>a.wafer.metadata)),"mean"),onOpen:H?(a,r)=>U(a,`Wafer ${e.find(w=>w.waferIndex===a)?.label??a}`,r):void 0,ownerDocument:d}),x=a=>{L=a,g.setTest(a),p.setTest(a),t.setTest(a),C.setTest(a)},C=Me({title:"Process capability",items:e,testDefs:n,onSaveImage:T,selectedTestNumber:L??void 0,onSelectTest:a=>x(a),ownerDocument:d});return l.append(C.card,g.card,p.card,t.card),{card:l,destroy:()=>{C.destroy(),g.destroy(),p.destroy(),t.destroy()}}}function ve(e,n,o){const c=X(d),l=qe({title:"Test scatter",items:e,testDefs:n,groups:o,binColors:J().hard,onSaveImage:T,ownerDocument:d}),f=ze({title:"Test correlation matrix",items:e,testDefs:n,onSaveImage:T,onSaveText:V,onSelectPair:(y,u)=>l.setXY(y,u),ownerDocument:d});return c.append(f.card,l.card),{card:c,destroy:()=>{f.destroy(),l.destroy()}}}function N(){for(const t of F)t.destroy();F=[],W.innerHTML="",B.innerHTML="",D.backTab&&B.appendChild(ye(D.backTab));for(const t of it)B.appendChild(ge(t.key,t.label));const e=be();Ce(e);const n=De(e,{facetableOnly:!0}).filter(t=>t.splittable),o=d.createElement("div");Object.assign(o.style,{display:"flex",gap:S.md,alignItems:"center",marginLeft:S.xxl,paddingBottom:S.xs});let c;n.length>0?(o.appendChild(Ze("Group by:",[{value:"",label:"None"},...n.map(t=>({value:t.key,label:`${t.label} (${t.values.length})`}))],P??"",t=>{P=t||void 0,$=null,N()},{hook:"group-by",ownerDocument:d})),c=n.find(t=>t.key===P)?.label):P=void 0;let l;if(P){const t=new Map,x=[];for(const C of e){const a=$e(C.metadata,P)??Le;t.has(a)||(t.set(a,[]),x.push(a)),t.get(a).push(C)}l=x.map(C=>({key:C,items:t.get(C)}))}$!==null&&!l?.some(t=>t.key===$)&&($=null),l&&l.length>0&&o.appendChild(et(l.map(t=>t.key),"Show:",$,t=>_(t),{ownerDocument:d}).el);let f=null;if(D.onOpenGuide){const t=d.createElement("button");t.type="button",t.innerHTML=Ne.help,t.setAttribute("aria-label","User guide"),Object.assign(t.style,{...Ye("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),oe(t,"bare"),Fe(t,"User guide"),t.addEventListener("click",()=>D.onOpenGuide()),Object.assign(t.style,{marginLeft:"auto"}),f=t}B.appendChild(o),f&&B.appendChild(f);const y=$!==null?l?.find(t=>t.key===$):void 0,u=y?.items??e,m=y?void 0:l,i=Ee(u),b=i.defs,h=b.filter(Ie);L!==null&&!h.some(t=>t.testNumber===L)&&(L=null);const g=j==="overview"?we(u,h,b,m,c):j==="distributions"?Te(u,h,m,c):ve(u,h,m),p=i.conflicts.filter(t=>t.excluded);if(p.length>0){const t=d.createElement("div");Object.assign(t.style,{color:k.label,fontSize:G.body,padding:`0 ${R} ${S.sm}`});const x=p.slice(0,6).map(r=>r.testNumber).join(", "),C=p.length>6?`, and ${p.length-6} more`:"",a=p.length===1?"it":"them";t.textContent=`${p.length} test ${p.length===1?"number is":"numbers are"} hidden (${x}${C}) \u2014 the wafers in view describe ${a} differently, so their values cannot be pooled. `+(l&&l.length>0?`Pick one ${c??"group"} under "Show:" to analyse ${a}.`:"Load one test program at a time to analyse them."),t.dataset.wmapWithheldTests=String(p.length),W.appendChild(t)}F.push(g),W.appendChild(g.card)}return{el:I,render:N,destroy:()=>{for(const e of F)e.destroy();I.remove()}}}
1
+ import{buildFacetTable as $e,facetValueOf as Le,FACET_NONE_VALUE as Ee}from"../stats/facets.js";import{mergeTestDefs as Ie}from"../stats/mergeTestDefs.js";import{isParametricTest as Oe}from"../renderer/buildWaferMap.js";import{waferDisplayLabel as Pe}from"../core/waferLabel.js";import{INPUT_DEFAULT_PASS_BINS as R,itemPassBins as Ae,passBinsLabel as ae}from"../core/passBins.js";import{NO_DATA_FILL as oe}from"../renderer/colorMap.js";import{describeWaferPopulation as Re,populationStat as We}from"../stats/population.js";import{LEADING as je,ALPHA as Ge,SPACE as w,EDGE_GUTTER as X,FONT as G,CLR as B,RADIUS as Ye,SHADOW as He,controlStyle as Fe,wireControlHover as re,wireTooltip as Me}from"./toolbar.js";import{ICONS as Ne}from"./icons.js";import{renderCapabilityPanel as Ve}from"./charts/capability.js";import{renderBoxplotPanel as _e}from"./charts/boxplot.js";import{renderTrendPanel as Ue}from"./charts/trend.js";import{renderHistogramPanel as ze}from"./charts/histogram.js";import{renderCorrelationPanel as qe}from"./charts/correlation.js";import{renderScatterPanel as Qe}from"./charts/scatter.js";import{renderBarPanel as se}from"./charts/barPanel.js";import{renderBinClusterPanel as Ke}from"./charts/binCluster.js";import{renderTestPassRatePanel as Xe}from"./charts/testPassRate.js";import{QUANTITY as Je}from"./charts/palette.js";import{cardFrameStyle as Ze,makeChartGridWrap as J,makeLabeledSelect as et,makeLinkedGroupSelect as tt}from"./charts/chartShell.js";import{buildYieldData as V,buildYieldDataCombined as ie}from"../stats/yield.js";import{buildBinParetoData as nt}from"../stats/binPareto.js";import{buildLotTestSection as at,buildLotFunctionalSection as ot,buildMetadataStripBox as rt}from"./summaryPanel.js";import{buildRegionYieldData as le,buildRingRegions as st,buildQuadrantRegions as it}from"../stats/regions.js";import{renderRegionYieldDiagram as de}from"./charts/regionYieldDiagram.js";const lt=[{key:"overview",label:"Overview"},{key:"distributions",label:"Distributions"},{key:"correlation",label:"Correlation"}];export function createInsightsTab(D){const{getItems:ce,getLotStats:pe,getBinColors:Z,getRingCount:ue,onSaveImage:T,onSaveText:_,openWafer:Y,focusTest:ee}=D,fe=D.showMetadataStrip??!0,W=D.contentInset??X,l=D.ownerDocument??document,O=l.createElement("div");Object.assign(O.style,{display:"none",flexDirection:"column",width:"100%",paddingTop:"0"});const me=X,P=l.createElement("div");Object.assign(P.style,{paddingLeft:me});const k=l.createElement("div");Object.assign(k.style,{display:"flex",gap:w.xs,alignItems:"center",background:B.menuBg,border:`1px solid ${B.menuBorder}`,borderRadius:Ye.container,boxShadow:He.panel,padding:`0 ${w.lg}`,marginBottom:w.lg,marginLeft:W,marginRight:W}),k.setAttribute("role","tablist"),k.addEventListener("keydown",e=>{if(e.key!=="ArrowLeft"&&e.key!=="ArrowRight")return;const t=Array.from(k.querySelectorAll('[role="tab"]')),r=t.indexOf(l.activeElement);if(r===-1)return;e.preventDefault();const d=t[(r+(e.key==="ArrowRight"?1:-1)+t.length)%t.length];d.focus(),d.click()});const j=l.createElement("div");Object.assign(j.style,{display:"flex",flexDirection:"column",gap:w.lg,marginTop:"0",paddingLeft:W,paddingRight:W}),O.appendChild(P),O.appendChild(k),O.appendChild(j);let I=D.defaultView??"overview",A,L=null,$=null,H={includeLimits:void 0,clipOutliers:!1};const U=e=>{$!==e&&($=e,M())};let F=new Map;function te(){for(const e of F.values())e.destroy();F=new Map}function z(e,t,r){Y?.(e,t,r)}function be(e){return Y?{open:(t,r)=>z(t,`Wafer ${e.find(d=>d.waferIndex===t)?.label??t}`,r)}:ee&&e.length===1?{open:(t,r)=>ee(r),label:"show this test on the map"}:null}function ge(){return ce().map((e,t)=>e==null?null:{metadata:e.wafer.metadata??void 0,dies:e.dies,wafer:e.wafer,label:Pe(e,t),waferIndex:t,passBins:Ae(e),statsSummary:e.statsSummary,testDefs:e.testDefs}).filter(e=>e!=null)}function ne(e,t){Object.assign(e.style,{background:"none",border:"none",borderBottom:t?`2px solid ${B.iconActive}`:"2px solid transparent",color:t?B.iconActive:B.label,fontWeight:t?"700":"500",fontSize:G.body,padding:`${w.sm} ${X} ${w.md}`,cursor:"pointer",marginBottom:"-1px"})}function ye(e,t){const r=l.createElement("button");r.type="button",r.textContent=t;const d=e===I;return ne(r,d),r.dataset.on=d?"true":"false",re(r,"bare"),r.dataset.wmapInsightsTab=e,r.setAttribute("role","tab"),r.setAttribute("aria-selected",d?"true":"false"),r.tabIndex=d?0:-1,r.addEventListener("click",()=>{I!==e&&(I=e,M({keepSections:!0}))}),r}function he(e){const t=l.createElement("button");return t.type="button",t.textContent=`\u2039 ${e.label}`,ne(t,!1),t.dataset.wmapInsightsBack="1",t.addEventListener("click",e.onBack),t}function Ce(e,t,r,d=!0){const c=J(l),p=Z();let m="label";const b=r??"group",u=ae(e.map(i=>i.passBins)),s=pe?.(),g=new Map(s?.lotYieldSeries.map(i=>[i.waferIndex,i.yieldPercent])),S=i=>({...i,label:i.label.replace(/\s*·\s*\d+(\.\d+)?%$/,""),yieldPercent:g.get(i.waferIndex),key:i.waferIndex}),f=e.map(S),y=t?.map(i=>({key:i.key,items:i.items.map(S)})),x=()=>y?ie(y,R,m):V(f,R,m),C={title:t?`Yield by ${b} (pass: ${u})`:`Yield by wafer (pass: ${u})`,data:x(),selfControl:{current:m,options:[["yield","Sort: yield"],["label",t?`Sort: ${b}`:"Sort: wafer ID"]],onChange:i=>(m=i,{data:x()})},barColor:()=>Je,valueLabel:i=>`${i.percent.toFixed(1)}%`,reference:i=>{if(i.length<3)return null;const v=i.map(K=>K.percent).sort((K,De)=>K-De),E=v.length%2?v[(v.length-1)/2]:(v[v.length/2-1]+v[v.length/2])/2;return{value:E,label:`median ${E.toFixed(1)}%`}},drill:y?{onOpenGroup:i=>{const v=y.find(E=>E.key===i.label)?.items??[];return{data:V(v,R,m),title:`Yield by wafer \u2014 ${b}: ${i.label} (pass: ${u})`}},onBack:()=>({data:x(),title:`Yield by ${b} (pass: ${u})`}),groupLabelText:b}:void 0,onOpen:Y?i=>{typeof i.key=="number"&&z(i.key,`Wafer ${i.label}`)}:void 0,ownerDocument:l};let n=null;if(d&&(n=se(C,T),n.card.style.minHeight="360px",c.appendChild(n.card)),t){const i=Ke({title:"Hard bin pareto",groups:t.map(v=>({key:v.key,items:v.items.map(E=>({dies:E.dies,hardBinCounts:E.statsSummary?.stats.hardBinCounts,softBinCounts:E.statsSummary?.stats.softBinCounts}))})),onSaveImage:T,ownerDocument:l});return i.card.style.minHeight="360px",c.appendChild(i.card),{card:c,destroy:()=>{n?.destroy(),i.destroy()}}}let a="hbin";const o=i=>i===void 0?oe:(a==="hbin"?p.hard:p.soft).get(i)??oe,h=e.map(i=>({dies:i.dies,hardBinCounts:i.statsSummary?.stats.hardBinCounts,softBinCounts:i.statsSummary?.stats.softBinCounts})),N=()=>nt(h,a),Be={title:"Hard bin pareto",data:N(),selfControl:{current:a,options:[["hbin","Hard bins"],["sbin","Soft bins"]],onChange:i=>(a=i,{data:N(),title:`${a==="hbin"?"Hard":"Soft"} bin pareto`})},barColor:i=>o(i.binCode),ownerDocument:l},Q=se(Be,T);return Q.card.style.minHeight="360px",c.appendChild(Q.card),{card:c,destroy:()=>{n?.destroy(),Q.destroy()}}}function q(){const e=l.createElement("div");return e.dataset.wmapChartCard="1",Object.assign(e.style,{...Ze(),display:"flex",flexDirection:"column",gap:w.lg,minWidth:"0"}),e}function Se(e){if(P.innerHTML="",P.style.marginBottom="0",!fe)return;const t=rt(e.map(r=>({metadata:r.metadata})),void 0,{facetableOnly:!1});t&&(t.style.marginBottom="0",P.appendChild(t),P.style.marginBottom=w.xs)}function xe(e,t,r,d){if(!e.length)return{elements:[],testValuesCard:null,functionalCard:null,destroy:()=>{}};const c=e.map(o=>o.wafer),p=e.map(o=>o.dies),m=e.flatMap(o=>o.dies),b=e.map(o=>o.statsSummary),u=b.every(o=>o!==void 0)?b:void 0,s=ue?.()??4,g=[],S=[],y=Xe({groups:(d??[{key:"",items:e}]).map(o=>({key:o.key,items:o.items.map(h=>({dies:h.dies,testSpecYield:h.statsSummary?.stats.testSpecYield,functionalYield:h.statsSummary?.stats.functionalYield}))})),testDefs:r,onSaveImage:T,ownerDocument:l});y.card.style.minHeight="300px",g.push(y.card),S.push(y.destroy);const x=le(p,c,s,o=>e[o].passBins,st);if(x.length){const o=de({title:"Ring yield",mode:"ring",rows:x,onSaveImage:T,ownerDocument:l});g.push(o.card),S.push(o.destroy)}const C=le(p,c,s,o=>e[o].passBins,it);if(C.length){const o=de({title:"Quadrant yield",mode:"quadrant",rows:C,onSaveImage:T,ownerDocument:l});g.push(o.card),S.push(o.destroy)}let n=null;if(t.length){const o=at(m,t,void 0,u,_,p.map(h=>({dies:h})),void 0,"full");if(o){const h=q();h.appendChild(o),n=h}}let a=null;if(r.length){const o=ot(m,r,u,_);if(o){const h=q();h.appendChild(o),a=h}}return{elements:g,testValuesCard:n,functionalCard:a,destroy:()=>{for(const o of S)o()}}}function we(e){const t=ae(e.map(s=>s.passBins)),r=e.length===1,d=e[0],c=q();Object.assign(c.style,{flexDirection:"row",flexWrap:"wrap",gap:w.md});const p=s=>{const g=s.lastElementChild;return g&&Object.assign(g.style,{borderRight:"none",paddingRight:"0",marginRight:"0"}),s};function m(s,g,S){const f=l.createElement("div");Object.assign(f.style,{display:"flex",alignItems:"baseline",gap:w.sm,paddingRight:w.xxl,marginRight:w.md,borderRight:`1px solid ${B.menuBorder}`});const y=l.createElement("div");y.textContent=s,Object.assign(y.style,{fontSize:G.heading,fontWeight:"700",color:B.value,lineHeight:je.tight});const x=l.createElement("div");if(x.textContent=g,Object.assign(x.style,{fontSize:G.body,color:B.label}),f.append(y,x),S){const C=l.createElement("div");C.textContent=S,Object.assign(C.style,{fontSize:G.meta,color:B.label,opacity:Ge.muted}),f.appendChild(C)}return f}if(r){const s=V([{...d,key:d.waferIndex}],R)[0]?.percent;return s!==void 0&&c.appendChild(m(`${s.toFixed(1)}%`,`Yield \xB7 pass: ${t}`)),c.appendChild(m(String(d.dies.length),"Total dies")),p(c)}c.appendChild(m(String(e.length),"Wafers"));const b=V(e.map(s=>({...s,key:s.waferIndex})),R).map(s=>s.percent).filter(s=>Number.isFinite(s));if(b.length){const s=b.reduce((f,y)=>f+y,0)/b.length,g=ie([{key:"all",items:e.map(f=>({...f,key:f.waferIndex}))}],R)[0]?.percent,S=g!==void 0&&g.toFixed(1)!==s.toFixed(1);c.appendChild(m(`${s.toFixed(1)}%`,`Mean per-wafer yield \xB7 pass: ${t}`,S?`${g.toFixed(1)}% by dies`:void 0))}const u=e.map(s=>s.statsSummary);if(u.every(s=>s!==void 0)){const s=u.reduce((S,f)=>S+f.stats.analyzedDies,0),g=u.reduce((S,f)=>S+f.stats.excludedDies,0);c.appendChild(m(s.toLocaleString(),"Dies analysed",g?`${g.toLocaleString()} excluded`:void 0))}else c.appendChild(m(e.reduce((s,g)=>s+g.dies.length,0).toLocaleString(),"Total dies"));return p(c)}function Te(e,t,r,d,c){const p=l.createElement("div");Object.assign(p.style,{display:"flex",flexDirection:"column",gap:w.lg});const m=e.length===1&&!d;e.length&&!d&&p.appendChild(we(e));const b=Ce(e,d,c,!m);p.appendChild(b.card);const u=xe(e,t,r,d);for(const s of u.elements)b.card.appendChild(s);return u.testValuesCard&&p.appendChild(u.testValuesCard),u.functionalCard&&p.appendChild(u.functionalCard),{card:p,destroy:()=>{b.destroy(),u.destroy()}}}function ve(e,t,r,d){const c=J(l),p=be(e),m=a=>{H=a;for(const o of[f,y,x])o!==b&&o?.setAxisPrefs(a)};let b=null;const u=a=>o=>{b=a(),m(o),b=null},s=a=>({...a,testStats:a.statsSummary?.stats.perTestStats}),g=e.map(s),S=r?.map(a=>({key:a.key,items:a.items.map(s)})),f=_e({title:"Test value distribution",axisPrefs:H,onAxisPrefsChange:u(()=>f),onTestChange:a=>C(a),selectedTestNumber:L??void 0,items:g,testDefs:t,groups:S,groupLabelText:d,onSaveImage:T,onGroupChange:a=>U(a),onOpen:p?.open,openActionLabel:p?.label,ownerDocument:l}),y=ze({title:"Value histogram",axisPrefs:H,onAxisPrefsChange:u(()=>y),onTestChange:a=>C(a),selectedTestNumber:L??void 0,items:e,testDefs:t,groups:r,onGroupChange:a=>U(a),onSaveImage:T,ownerDocument:l}),x=Ue({title:"Wafer-to-wafer trend",axisPrefs:H,onAxisPrefsChange:u(()=>x),onTestChange:a=>C(a),selectedTestNumber:L??void 0,items:e.map(a=>({label:a.label,key:a.waferIndex,dies:a.dies,testStats:a.statsSummary?.stats.perTestStats})),testDefs:t,onSaveImage:T,centreLabel:We(Re(e.map(a=>a.wafer.metadata)),"mean"),onOpen:Y?(a,o)=>z(a,`Wafer ${e.find(h=>h.waferIndex===a)?.label??a}`,o):void 0,ownerDocument:l}),C=a=>{L=a,f.setTest(a),y.setTest(a),x.setTest(a),n.setTest(a)},n=Ve({title:"Process capability",items:e,testDefs:t,onSaveImage:T,selectedTestNumber:L??void 0,onSelectTest:a=>C(a),ownerDocument:l});return c.append(n.card,f.card,y.card,x.card),{card:c,destroy:()=>{n.destroy(),f.destroy(),y.destroy(),x.destroy()}}}function ke(e,t,r){const d=J(l),c=Qe({title:"Test scatter",items:e,testDefs:t,groups:r,binColors:Z().hard,onSaveImage:T,ownerDocument:l}),p=qe({title:"Test correlation matrix",items:e,testDefs:t,onSaveImage:T,onSaveText:_,onSelectPair:(m,b)=>c.setXY(m,b),ownerDocument:l});return d.append(p.card,c.card),{card:d,destroy:()=>{p.destroy(),c.destroy()}}}function M(e){e?.keepSections||te(),j.innerHTML="",k.innerHTML="",D.backTab&&k.appendChild(he(D.backTab));for(const n of lt)k.appendChild(ye(n.key,n.label));const t=ge();Se(t);const r=$e(t,{facetableOnly:!0}).filter(n=>n.splittable),d=l.createElement("div");Object.assign(d.style,{display:"flex",gap:w.md,alignItems:"center",marginLeft:w.xxl,paddingBottom:w.xs});let c;r.length>0?(d.appendChild(et("Group by:",[{value:"",label:"None"},...r.map(n=>({value:n.key,label:`${n.label} (${n.values.length})`}))],A??"",n=>{A=n||void 0,$=null,M()},{hook:"group-by",ownerDocument:l})),c=r.find(n=>n.key===A)?.label):A=void 0;let p;if(A){const n=new Map,a=[];for(const o of t){const h=Le(o.metadata,A)??Ee;n.has(h)||(n.set(h,[]),a.push(h)),n.get(h).push(o)}p=a.map(o=>({key:o,items:n.get(o)}))}$!==null&&!p?.some(n=>n.key===$)&&($=null),p&&p.length>0&&d.appendChild(tt(p.map(n=>n.key),"Show:",$,n=>U(n),{ownerDocument:l}).el);let m=null;if(D.onOpenGuide){const n=l.createElement("button");n.type="button",n.innerHTML=Ne.help,n.setAttribute("aria-label","User guide"),Object.assign(n.style,{...Fe("bare"),display:"inline-flex",alignItems:"center",justifyContent:"center",width:"24px",height:"24px",flexShrink:"0"}),re(n,"bare"),Me(n,"User guide"),n.addEventListener("click",()=>D.onOpenGuide()),Object.assign(n.style,{marginLeft:"auto"}),m=n}k.appendChild(d),m&&k.appendChild(m);const b=$!==null?p?.find(n=>n.key===$):void 0,u=b?.items??t,s=b?void 0:p,g=Ie(u),S=g.defs,f=S.filter(Oe);L!==null&&!f.some(n=>n.testNumber===L)&&(L=null);const y=e?.keepSections?F.get(I):void 0,x=y??(I==="overview"?Te(u,f,S,s,c):I==="distributions"?ve(u,f,s,c):ke(u,f,s));y||F.set(I,x);const C=g.conflicts.filter(n=>n.excluded);if(C.length>0){const n=l.createElement("div");Object.assign(n.style,{color:B.label,fontSize:G.body,padding:`0 ${W} ${w.sm}`});const a=C.slice(0,6).map(N=>N.testNumber).join(", "),o=C.length>6?`, and ${C.length-6} more`:"",h=C.length===1?"it":"them";n.textContent=`${C.length} test ${C.length===1?"number is":"numbers are"} hidden (${a}${o}) \u2014 the wafers in view describe ${h} differently, so their values cannot be pooled. `+(p&&p.length>0?`Pick one ${c??"group"} under "Show:" to analyse ${h}.`:"Load one test program at a time to analyse them."),n.dataset.wmapWithheldTests=String(C.length),j.appendChild(n)}j.appendChild(x.card)}return{el:O,render:M,destroy:()=>{te(),O.remove()}}}
@@ -41,6 +41,61 @@ export interface GalleryOptions {
41
41
  viewOptions?: WaferViewOptions;
42
42
  /** Called whenever a shared gallery option changes. */
43
43
  onViewOptionsChange?: (opts: WaferViewOptions, changed: (keyof WaferViewOptions)[], category: 'preference' | 'state' | 'mixed') => void;
44
+ /**
45
+ * Called once the gallery has finished building: every factory resolved, and
46
+ * the lot-wide surfaces (legend, shared colours, summary panel) settled.
47
+ *
48
+ * Exists so a host can hold its own progress indicator over a large lot's
49
+ * load without polling the gallery's DOM. **Always fires, and always
50
+ * asynchronously, whichever form the items took** — a host passing factories
51
+ * and a host passing pre-built items get the same one signal, so neither has
52
+ * to know which path the gallery took. With factories it fires after the last
53
+ * card; with pre-built items, on the next task after mount (never before
54
+ * `renderWaferGallery` returns, so the controller is always in hand).
55
+ *
56
+ * **It waits for the Summary panel's own render to finish**, which on a large
57
+ * lot is seconds after the last card appears — the panel is staged across
58
+ * tasks, and on 50 wafers x 8,000 dies x 50 tests in Chrome the cards are in
59
+ * at 3.6 s and the panel at 8.2 s. That is the point of it: a host clearing
60
+ * its indicator when the cards land would leave the rest of the wait
61
+ * unexplained, which is the failure this signal exists to prevent. There is
62
+ * deliberately no earlier "cards are in" variant — one settle signal, one
63
+ * meaning.
64
+ *
65
+ * Fires once per build, so a rebuild fires it again — `setItems`, and the
66
+ * internal rebuild that switching into a stacked mode does. It says "the
67
+ * gallery is settled", not "this happened for the first time".
68
+ */
69
+ onItemsResolved?: () => void;
70
+ /**
71
+ * Called as each card is built, with how many of the expected items now
72
+ * exist and how many there will be. `total` is the count `setItems` was
73
+ * given, so it is correct from the first call and a progress bar can be
74
+ * sized before anything arrives.
75
+ *
76
+ * This is the *advance* signal; `onItemsResolved` is the *settled* one, and
77
+ * they are not interchangeable. A progressive mount of a large lot runs for
78
+ * 10-25 s, and a host indicator that can only say "loading" for that long
79
+ * reads as a hang — which is the failure the progressive path exists to
80
+ * prevent, reintroduced one layer up.
81
+ *
82
+ * **Fires on the pre-built path too**, so no host has to branch on which
83
+ * form it passed: a fully pre-built mount is one call with
84
+ * `resolved === total`. A mixed set reports its pre-built items in one call
85
+ * and then one call per factory.
86
+ *
87
+ * It covers the cards only. On a large lot the Summary panel keeps filling
88
+ * in for seconds after the last card, with no card activity to report —
89
+ * `onItemsResolved` is what marks the end of *that*. There is deliberately
90
+ * no third callback between them: if a host needs to name that phase, it
91
+ * knows it has begun when `resolved === total` and ended when
92
+ * `onItemsResolved` fires.
93
+ *
94
+ * Deferred a task and generation-guarded like every callback here, so a
95
+ * gallery rebuilt or destroyed before the turn arrives stays quiet. Not
96
+ * called at all for an empty item list.
97
+ */
98
+ onItemResolved?: (resolved: number, total: number) => void;
44
99
  /**
45
100
  * Draw a legend on every card as well as the lot-level one. Default false.
46
101
  *
@@ -1 +1 @@
1
- import{getUniqueTestNumbers as bo,resolveTestNumber as yo,findTestDef as wo,collectMetadataValues as xo}from"../renderer/buildView.js";import{metadataCategoricalValue as vo}from"../core/metadata.js";import{resolveBinColorsForMaps as Co,mergeBinDefs as Ke,binColorWarning as So,mixedPassBinsWarning as Mo}from"../renderer/binColors.js";import{itemPassBins as Do,INPUT_DEFAULT_PASS_BINS as Bo}from"../core/passBins.js";import{NO_DATA_FILL as ko}from"../renderer/colorMap.js";import{metadataValueColor as Eo}from"../renderer/colorMap.js";import{resolveCanvasTheme as Oo}from"./canvasTheme.js";import{ICONS as Te}from"./icons.js";import{SHADOW as Le,LEADING as qe,TRACKING as To,controlStyle as Lo,wireControlHover as ht,SPACE as w,EDGE_GUTTER as oe,MAP_CHROME_INSET as $o,RADIUS as N,FONT as T,CLR as g,sevColor as cn,MODE_LABELS as Wo,BIN_LEGEND_MODES as un,STACKED_MODES as ge,Z_ABOVE as fn,applyOverlayZ as Ro,getTooltip as Io,hideTooltip as pn,createToolbarHelpers as Ao,buildModeMenuEl as Po,openDetachWindow as Fo,openFloatingWindow as Ho,openModal as jo,openReportModal as Vo,copyWmapThemeTokens as zo,syncWmapPopupTheme as No,openUserGuideWindow as _o,makePaletteBtn as Go,makeLogScaleBtn as Ko,makeLegendStyleBtn as qo,makeOverlaysBtn as Uo,makeOrientationBtn as Xo,menuLayerFor as mn,saveImageBlob as gn,markMenuTrigger as $e,wireMenuA11y as hn,wireExpandToggle as bn,wireTooltip as yn,requestedPassFailDisplay as wn,overlayMenuRows as Zo,anyOverlayActive as Yo,logWmapVersionOnce as Qo,buildDataModeEntries as Jo,metadataKeyHasData as ei,metadataModeEntry as ti}from"./toolbar.js";import{waferDisplayLabel as Ue,waferIdentityLabel as ni}from"../core/waferLabel.js";import{metadataDisplayValue as oi}from"../core/metadata.js";import{withExportContext as ii,noticeDownloadFilenameChange as ai}from"./exportName.js";import{sortBinsForDisplay as li}from"../stats/binPareto.js";import{diePassStatus as si}from"../core/dies.js";import{aggregateValues as ri,aggregateBinCounts as xn}from"../core/aggregates.js";import{renderWaferMap as di,renderWaferMapCard as vn,toPublicViewOptions as Cn}from"./renderWaferMap.js";import{classifyChanged as ci,COLOR_KEYS as ui}from"./renderWaferMap.js";import{buildWaferMap as fi,getTestPassStatus as Sn,isParametricTest as bt,getDieTestValue as pi}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Xe}from"../stats/analyzeWaferMap.js";import{collectWarnings as mi,buildWarningsMenuEl as gi,severityOf as hi}from"./warnings.js";import{compareNatural as yt}from"../core/utils.js";import{createSummaryPanelEl as wt,buildMetadataStripRow as bi,buildCompactMetadataRows as Mn,metadataEntries as Dn,renderLotSummaryContent as yi,reportMapsFromItems as wi}from"./summaryPanel.js";import{renderLotReportHtml as xi}from"../stats/renderSummaryReport.js";import{prettyKey as vi}from"../stats/facets.js";import{mergeTestDefs as Ci}from"../stats/mergeTestDefs.js";import{getDieKey as Si,hasPosition as Mi}from"../core/dies.js";function Bn(u){if(typeof u!="number"||!Number.isFinite(u))return;const v=Math.round(u);return v>=1?v:void 0}const xt=12;function Di(u,v,p){let A=v;if(v.length>xt){const D=v.slice(0,xt-1),$=v.slice(xt-1),H=$.reduce((Y,j)=>Y+j.count,0);A=[...D,{color:g.label,count:H,label:`Other (${$.length} bins)`}]}const M=u.createElement("div");Object.assign(M.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:N.control,overflow:"hidden",border:`1px solid ${g.menuBorder}`,boxSizing:"border-box",marginTop:w.xs,flexShrink:"0"}),M.setAttribute("role","img"),M.setAttribute("aria-label",`Population split: ${A.map(D=>`${D.label} ${Ze(D.count/p*100)}`).join(", ")}`);for(const D of A){const $=D.count/p*100,H=u.createElement("div");Object.assign(H.style,{flex:`${$} 1 0`,minWidth:$>0?"2px":"0",background:D.color}),yn(H,`${D.label} \xB7 ${D.count.toLocaleString()} dies \xB7 ${Ze($)}`),M.appendChild(H)}return M}function Ze(u){return u>0&&u<.1?"<0.1%":`${u.toFixed(1)}%`}function kn(u,v,p){const A=new Map;let M=0,D=0;for(const $ of u){const H=p?new Set(p($)):void 0;for(const Y of $.dies){if(Y.partial||Y.edgeExcluded)continue;const j=v(Y);j!==void 0&&(A.set(j,(A.get(j)??0)+1),M++,H&&si(Y,H)&&D++)}}return{counts:A,total:M,pass:D}}function En(u,v){const p=u.ownerDocument.createElement("div");Object.assign(p.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${w.xxs} ${w.xs}`,borderRadius:N.control});const A=u.ownerDocument.createElement("span");Object.assign(A.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:v.color,border:v.isActive?`2px solid ${g.iconActive}`:`1px solid ${g.menuBorder}`,borderRadius:N.control,boxSizing:"border-box"});const M=u.ownerDocument.createElement("span");if(M.textContent=v.label,Object.assign(M.style,{fontWeight:v.isActive?"700":"400",color:v.isActive?g.iconActive:g.text,whiteSpace:"nowrap"}),p.appendChild(A),p.appendChild(M),v.count!==void 0){const D=u.ownerDocument.createElement("span");if(D.textContent=v.count.toLocaleString(),Object.assign(D.style,{color:v.isActive?g.iconActive:g.text,fontWeight:v.isActive?"700":"400",whiteSpace:"nowrap"}),p.appendChild(D),v.percent!==void 0){const $=u.ownerDocument.createElement("span");$.textContent=Ze(v.percent),Object.assign($.style,{color:g.label,whiteSpace:"nowrap"}),p.appendChild($)}}p.setAttribute("role","button"),p.setAttribute("aria-pressed",v.isActive?"true":"false"),p.tabIndex=0,p.addEventListener("mouseenter",()=>{p.style.background=g.bgHover}),p.addEventListener("mouseleave",()=>{p.style.background="transparent"}),p.addEventListener("focus",()=>{p.style.background=g.bgHover}),p.addEventListener("blur",()=>{p.style.background="transparent"}),p.addEventListener("click",v.onClick),p.addEventListener("keydown",D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),v.onClick())}),u.appendChild(p)}export function renderWaferGallery(u,v,p={}){Qo();const A=6;let M=Bn(p.columns);const D=p.showHelpButton??!1,$=p.userGuideExtension,H=p.insights?.enabled??!1,Y=Ro(p.zIndex),j=p.summaryPanel,On=e=>[...Do(e)],vt=()=>x.flatMap(e=>e?[e.ringCount??4]:[]),Ye=()=>vt()[0]??4;function Tn(e){const t=[...new Set(e)].sort((n,o)=>n-o);return t.length<2?null:{code:"ring-count-mixed",severity:"warning",message:`These wafers were built with different ring counts (${t.join(", ")}). Each card and each wafer's findings use their own; the lot's ring yield in the Summary panel, report and Insights uses ${e[0]} rings.`}}let V=p.lotStatsSummary,he=p.viewOptions?.legendPosition??"default",We=p.perCardLegend??!1;function be(){const e=r.plotMode??"hardBin";return un.has(e)?null:r.colorbarRangeMode==="data"?"Each map has its own value range, so it keeps its own colour bar":"These wafers have no shared colour bar for value mode, so each map keeps its own"}function Ct(){const e=We||be()!==null;for(const t of S)t&&t.setOptions({showLegend:e})}let r={plotMode:"hardBin",showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...p.viewOptions},S=[],ie=[],re=[],L=[];const Re=ii(()=>{const e=L.filter(n=>n!=null);return{lots:[...new Set(e.map(n=>oi(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort(yt),...e.length===1?{wafer:ni(e[0])}:{waferCount:e.length}}},p.onSaveImage,p.onSaveText);ai(p.downloadFilename);let x=v.map(e=>typeof e=="function"?null:e);function St(){return Ci(x)}function ye(){if(x.some(e=>e?.testDefs?.length))return St().defs}let Qe=0,Ie=0;const _=new Map;let Ln=0,P=null,we=null,Mt=new Set,h=null,$n={};function Dt(e){return x[e]?.statsSummary??V?.perWafer.find(t=>t.waferIndex===e)?.summary}function Je(){return!!(x.some(e=>e?.statsSummary?.findings.length)||V?.perWafer.some(e=>e.summary.findings.length))}const Wn=Io(),de=Ao(Wn),{makeBtn:Q,setActive:xe,makeSep:G,makeMenuRow:Rn,makeMenuSection:In,makeDropdown:Bt,closeOpenMenu:Ae,getOpenMenu:ve,setOpenMenu:Ce}=de;u.ownerDocument.addEventListener("click",Ae,!0);const kt=()=>pn();window.addEventListener("blur",kt);let Et=p.findingsNotice;function Ot(e){Mt=new Set(e);const t=[...R.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,d)=>{const i=Mt.has(d);o.style.outline=i?`3px solid ${g.findingHighlight}`:"",o.style.outlineOffset=i?"-3px":"",i&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function Tt(){Ot([])}function Lt(){for(const e of S)e&&e.clearSelection()}function et(e,t){const n=new Set(e),o=t??S.map((d,i)=>i);for(const d of o){const i=L[d],l=S[d];if(!i||!l)continue;const s=i.dies.filter(a=>n.has(Si(a)));l.setSelection(s)}}function An(){const e=[];for(let t=0;t<x.length;t++){const n=x[t];if(!n)continue;const o=Dt(t)?.findings??[];o.length&&e.push({index:t,item:n,unusualCount:o.filter(d=>d.severity==="unusual").length,notableCount:o.filter(d=>d.severity==="notable").length,totalCount:o.length})}return e}function Pn(e){const t=L[e]??x[e];t&&Oe(e,t)}function Fn(e){const t=Dt(e)?.findings??[];if(t.length)return{total:t.length,unusual:t.filter(n=>n.severity==="unusual").length,notable:t.filter(n=>n.severity==="notable").length}}function Hn(){Vo(xi(wi(x,Bo,Ye())),{anchor:u})}function jn(){if(!h)return;h.innerHTML="";const e=An();if(x.length>0){const n=u.ownerDocument.createElement("div"),o=e.length,d=x.filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${d} wafers`:`${o} of ${d} wafer${d===1?"":"s"} with findings`,Object.assign(n.style,{fontSize:T.body,color:g.label,marginBottom:w.md}),h.appendChild(n)}if(e.length>0){const n=u.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...Lo("outlined"),marginBottom:w.lg,display:"block",width:"100%",textAlign:"left"}),ht(n),n.addEventListener("click",Hn),h.appendChild(n)}if(e.length===0){const n=u.ownerDocument.createElement("div");Object.assign(n.style,{color:g.icon,fontSize:T.body,padding:"4px 0"}),n.textContent="No findings on any wafer.",h.appendChild(n)}else for(const{index:n,item:o,unusualCount:d,notableCount:i,totalCount:l}of e){const s=d?"unusual":i?"notable":"info",a=d+i||l,c=u.ownerDocument.createElement("button");c.type="button",Object.assign(c.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:w.xs,border:"none",borderLeft:`3px solid ${cn(s)}`,borderRadius:N.control,background:g.bgHover,cursor:"pointer",fontSize:T.body,textAlign:"left",boxSizing:"border-box"}),c.addEventListener("mouseover",()=>{c.style.background=g.bgActive}),c.addEventListener("mouseout",()=>{c.style.background=g.bgHover});const f=u.ownerDocument.createElement("span");f.textContent=Ue(o,n),Object.assign(f.style,{color:g.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const b=u.ownerDocument.createElement("span");b.textContent=String(a),c.setAttribute("aria-label",`${Ue(o,n)} \u2014 ${a} finding${a===1?"":"s"}${d?`, ${d} unusual`:""} \u2014 view wafer`),Object.assign(b.style,{marginLeft:w.sm,flexShrink:"0",background:cn(s),color:"#fff",borderRadius:N.container,padding:"1px 5px",fontSize:T.body,fontWeight:"600"}),c.appendChild(f),c.appendChild(b),c.addEventListener("click",()=>Oe(n,o)),h.appendChild(c)}const t=u.ownerDocument.createElement("div");t.style.height="12px",h.appendChild(t)}function z(){if(h)if(V){const e=Ke(x.map(n=>n?.hbinDefs)),t=Ke(x.map(n=>n?.sbinDefs));yi(h,{lotSummary:V,items:x,hbinDefs:e.length?e:void 0,sbinDefs:t.length?t:void 0,testDefs:ye(),ringCount:Ye(),binColors:r.binColors,plotMode:r.plotMode??"hardBin",fallbackFormat:r.fallbackFormat,activeFindingId:we,warnings:p.warnings?.display??!0?J:[],findingsFilter:$n,findingsNotice:Et,onFindingsFilterChange:z,onSaveText:Re.onSaveText,onFindingClick:(n,o)=>{we===n.id?tt():zn(n,o),z()},onWaferClick:Pn,findingsFor:Fn,dieListOptions:p.dieList})}else jn()}function Vn(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}function $t(e){return[e.variable.kind,e.variable.index??"",e.variable.bin??"",e.comparison.family,e.comparison.left,e.effect.direction].join("|")}let Pe=[];function Wt(){if(Pe.length!==0){for(const e of Pe)S[e]?.setOptions({plotMode:r.plotMode,activeTest:r.activeTest});Pe=[]}}function tt(){we=null,Tt(),Lt(),Wt(),O({highlightBin:void 0},{fireCallback:!1})}function zn(e,t){if(we===e.id){tt();return}we=e.id,t.style.background=g.bgActive,t.style.fontWeight="600",Wt();const{kind:n,index:o}=e.variable;if(n==="test"){const i=o??0,l=ye();if(l===void 0||l.some(a=>a.testNumber===i))O({plotMode:"value",activeTest:i,highlightBin:void 0},{fireCallback:!1});else{O({highlightBin:void 0},{fireCallback:!1});const c=ge.has(r.plotMode??"hardBin")?null:Vn(e);if(c){for(const f of c)S[f]?.setOptions({plotMode:"value",activeTest:i});Pe=[...c]}}}else n==="softBin"?O({plotMode:"softBin",highlightBin:void 0},{fireCallback:!1}):O({plotMode:"hardBin",highlightBin:void 0},{fireCallback:!1});Tt(),Lt();const d=e.highlight;if(d.kind==="wafer"){Ot(d.waferIndices);const i=$t(e);for(const l of d.waferIndices){const c=L[l]?.statsSummary?.findings.find(f=>$t(f)===i)?.highlight?.dieKeys;c?.length&&et(c,[l])}}else d.kind==="bin"?d.dieKeys?.length&&et(d.dieKeys):(d.kind==="region"||d.kind==="dies")&&d.dieKeys?.length&&et(d.dieKeys)}function ae(){if(!P)return;const e=!!h;P.style.display=(V||Je())&&e&&!Be?"flex":"none";const t=h?h.style.display!=="none":!1;(V?.hasNotableFindings||x.some(o=>o?.statsSummary?.hasNotableFindings))&&!t?P.style.color=g.findingIndicator:P.dataset.active||(P.style.color=g.icon)}const W=u.ownerDocument.createElement("div");W.dataset.wmapToolbar="gallery",Object.assign(W.style,{flexShrink:"0",marginLeft:"auto",display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:N.control,padding:"0",boxShadow:Le.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const Rt=()=>{const e=ve();e&&(e.remove(),Ce(null)),$e(X,!1)},X=Q("mode","Plot mode",()=>{if(ve()){Rt();return}const e=x.flatMap(y=>y?.dies??[]),t=ye(),{testEntries:n,binEntries:o,stackedEntries:d}=Jo(e,t,{includeStacked:!0}),i=x.filter(Boolean).length,l=y=>{if(y===void 0)return i;let I=0;for(const se of x)se?.dies?.some(U=>Sn(U,y)!==void 0||U.testValues?.[y]!==void 0)&&I++;return I},s=i<2?n:n.map(y=>{const I=l(y.activeTest);return I===i?y:{...y,label:`${y.label} \u2014 ${I} of ${i} wafers`}}),a=r.plotMode??"hardBin",c=r.activeTest??0;function f(y){return y.plotMode!==a?!1:y.plotMode==="value"?c===(y.activeTest??0):y.plotMode==="metadata"?r.activeMetadataKey===y.activeMetadataKey:!0}function b(y,I){y.activeTest!==void 0?O({plotMode:"value",activeTest:y.activeTest,activeMetadataKey:void 0,logScale:y.logScale}):y.activeMetadataKey!==void 0?O({plotMode:y.plotMode,activeTest:void 0,activeMetadataKey:y.activeMetadataKey,passFailDisplay:"off"}):O({plotMode:y.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),I.remove(),Ce(null),$e(X,!1)}const E=new Set,B=x.flatMap(y=>y?.metadataFields??[]).filter(y=>!E.has(y.key)&&E.add(y.key)).filter(y=>ei(e,y.key)).map(ti),C=Po(X.getBoundingClientRect(),s,o,d,f,b,{makeMenuRow:Rn,makeMenuSection:In},a,X.ownerDocument.defaultView??window,B);mn(X).appendChild(C),Ce(C),$e(X,!0),hn(C,X,Rt)});$e(X,!1);const Nn=()=>L.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:_n,sync:It}=Go(de,()=>({...r,plotMode:r.plotMode??"hardBin"}),Nn,e=>O(e));It();const Gn=v.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function Fe(){const e=ye(),{testNumber:t}=yo(r.activeTest??0,e);return{testNumber:t,td:wo(e,t)}}function At(){if((r.plotMode??"hardBin")!=="value")return!1;const{td:e}=Fe();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function Se(){if((r.plotMode??"hardBin")!=="value")return!1;const{td:e}=Fe();return e!==void 0&&!bt(e)}function Kn(){if((r.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=Fe();return x.some(n=>n?.dies?.some(o=>Sn(o,e,t)!==void 0))}function qn(e,t){if(!t||!bt(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((wn(r)==="spec"&&n?"spec":r.colorbarRangeMode??"spec")==="spec"&&n)return;let i=1/0,l=-1/0;for(const s of x)if(s)for(const a of s.dies){const c=pi(a,e);c!==void 0&&(c<i&&(i=c),c>l&&(l=c))}if(isFinite(i))return i===l?[i,i+1]:[i,l]}function Pt(){if((r.plotMode??"hardBin")!=="metadata")return;const e=r.activeMetadataKey;if(!e)return;const t=new Set;for(const n of x)if(n)for(const o of xo(n.dies,e))t.add(o);return{key:e,values:[...t].sort(yt)}}function nt(){const e=Pt();if(!(e===void 0&&r.metadataValueOrder===void 0)){r={...r,metadataValueOrder:e};for(const t of S)t&&t.setOptions({metadataValueOrder:e})}}function ot(){if((r.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=Fe(),n=qn(e,t),o=n?{test:e,range:n}:void 0;r={...r,valueRange:o};for(const d of S)d&&d.setOptions({valueRange:o})}let it=!1;function Un(){if(it)return;it=!0,(u.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{it=!1,ot(),nt(),Ht()})}let Ft=[];function ce(){const{colors:e,mixedHardBins:t}=Co(x.filter(n=>n!=null),{binColorScheme:r.binColorScheme,useDefinedBinColors:r.useDefinedBinColors});return Ft=t,e}function Ht(){const e=ce();r={...r,binColors:e};for(const t of S)t&&t.setOptions({binColors:e});Me()}const Xn=Uo(de,()=>Zo(r,Gn,{functionalActive:Se(),hasLimits:At()&&!Se(),hasRecorded:Kn()&&!Se(),binMode:(r.plotMode??"hardBin")==="hardBin"||(r.plotMode??"hardBin")==="softBin"},e=>O(e)),()=>Yo(r)),{btn:Zn,sync:jt}=qo(de,()=>({plotMode:r.plotMode,legendPosition:he}),e=>{he=e;for(const t of S)t&&t.setOptions({legendPosition:he})},{get:()=>We,set:e=>{We=e,Ct()},blockedReason:be});jt();const Yn=[{value:"mean",label:"Mean"},{value:"median",label:"Median"},{value:"stddev",label:"Std Dev"},{value:"min",label:"Min"},{value:"max",label:"Max"},{value:"count",label:"Count"}],Vt=Bt("aggr","Aggregation method",()=>Yn,()=>r.aggregationMethod??"mean",e=>O({aggregationMethod:e}));function zt(){const e=r.plotMode==="stackedValues";Vt.style.display=e?"":"none"}zt();const{btn:Qn,sync:Nt}=Ko(de,()=>({...r,functionalActive:Se()}),e=>O(e));Nt();const He=Q("specRange","Colorbar range: spec limits",()=>{const e=r.colorbarRangeMode==="data"?"spec":"data";O({colorbarRangeMode:e})});function _t(){const e=(r.plotMode??"hardBin")==="value"&&At()&&wn(r)==="off"&&!Se();He.style.display=e?"":"none";const t=(r.colorbarRangeMode??"spec")==="spec";xe(He,t),He.ariaLabel=t?"Colorbar range: spec limits (click for data range)":"Colorbar range: data range (click for spec limits)"}_t();const Jn=Xo(de,()=>r,e=>O(e)),eo=Q("downloadAll","Download gallery PNG",mo),to=Bt("columns","Columns",()=>[{value:"auto",label:"Auto"},{value:"1",label:"1 column"},{value:"2",label:"2 columns"},{value:"3",label:"3 columns"},{value:"4",label:"4 columns"},{value:"5",label:"5 columns"}],()=>M!=null?String(M):"auto",e=>en(e==="auto"?void 0:Number(e))),k=u.ownerDocument.createElement("div");Object.assign(k.style,{display:"inline-flex",alignItems:"center",gap:"0"}),W.appendChild(k),k.appendChild(X),k.appendChild(_n),k.appendChild(Vt),k.appendChild(Qn),k.appendChild(He),k.appendChild(G()),k.appendChild(Xn),k.appendChild(G()),k.appendChild(Zn),k.appendChild(G()),k.appendChild(Jn),k.appendChild(G()),k.appendChild(to),k.appendChild(G()),k.appendChild(eo),(V||Je())&&(P=Q("findings","Summary panel",()=>{if(!h)return;const e=h.style.display!=="none";e||z(),h.style.display=e?"none":"flex",xe(P,!e),ae()}),W.appendChild(G()),W.appendChild(P));let K=null,je=null,J=[],Gt=!1;function Me(){const e=mi({lotStatsSummary:V,result:{warnings:[...x.flatMap(n=>n?.warnings??[]),...St().warnings]},extra:[r.binColors&&So(r.binColors,r.plotMode),Mo(Ft),Tn(vt())].filter(n=>!!n)}),t=e.length!==J.length||e.some((n,o)=>n.code!==J[o]?.code||n.message!==J[o]?.message);J=e,(t||!Gt)&&(Gt=!0,p.warnings?.onWarning?.(e)),no()}function no(){if(!K||!je)return;const e=J.length,t=e>0;if(K.style.display=t?"flex":"none",je.style.display=t?"":"none",!t)return;const n=hi(J[0]),o=`${e} data ${e===1?"warning":"warnings"}`;K.style.color=n==="error"?g.errText:g.warnText,K.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(p.warnings?.display??!0)&&(je=G(),K=Q("warning","Data warnings",()=>{const e=ve();if(Ae(new MouseEvent("click")),e)return;const t=gi(K.getBoundingClientRect(),J,K.ownerDocument.defaultView??window);mn(u).appendChild(t),Ce(t),hn(t,K,()=>Ae(new MouseEvent("click")))}),$e(K,!1),W.appendChild(je),W.appendChild(K)),Me();let le=null;H&&(le=Q("analysis","Insights",()=>{Ut(!Be)}),le.dataset.wmapInsightsBtn="1",W.appendChild(G()),W.appendChild(le));function Kt(){import("./userGuideHtml.js").then(e=>_o({buildWaferMap:fi,renderWaferMap:di,renderWaferGallery,analyzeWaferMap:Xe},e.USER_GUIDE_HTML,$,u))}D&&(W.appendChild(G()),W.appendChild(Q("help","User guide",()=>Kt())));const ue=u.ownerDocument.createElement("div");ue.dataset.wmapGalleryMeta="1",Object.assign(ue.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${w.sm} ${w.lg}`,fontSize:T.sub,lineHeight:qe.none,boxSizing:"border-box"});const Ve=u.ownerDocument.createElement("div");Object.assign(Ve.style,{background:g.canvasBg,display:"flex",alignItems:"stretch",gap:w.lg,paddingBottom:w.lg,minWidth:"0"});const ee=u.ownerDocument.createElement("div");ee.dataset.wmapGalleryLegend="1",Object.assign(ee.style,{display:"flex",flexDirection:"column",gap:w.sm,background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:N.container,padding:`${w.sm} ${w.lg}`,marginBottom:w.lg,boxShadow:Le.panel,fontSize:T.body,lineHeight:qe.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const q=u.ownerDocument.createElement("div");Object.assign(q.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let fe=null,De=null,qt=null;function oo(){return H?fe?Promise.resolve(fe):(qt??=import("./insightsTab.js").then(({createInsightsTab:e})=>(fe=e({getItems:()=>x,getLotStats:()=>V,getBinColors:()=>r.binColors??ce(),getRingCount:Ye,defaultView:p.insights?.defaultView,onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:Re.onSaveImage,onSaveText:Re.onSaveText,ownerDocument:u.ownerDocument,openWafer:(t,n,o)=>{const d=x[t];if(!d)return;let i=null;const l=jo({title:n,onClose:()=>i?.destroy(),anchor:u});on(l,n,d.wafer.metadata??void 0),i=ut(l.contentWrap,d,o)}}),De=fe.el,De.style.display="none",u.appendChild(De),fe)),qt):Promise.resolve(null)}let Be=!1;function Ut(e){H&&(Be=e,De&&(De.style.display=e?"flex":"none"),q.style.display=e?"none":"flex",k.style.display=e?"none":"inline-flex",W.style.display="inline-flex",le&&(xe(le,e),le.innerHTML=e?Te.wafer:Te.analysis,le.ariaLabel=e?"Back to gallery view":"Insights"),ae(),Ne(),e&&oo().then(t=>{!t||!Be||(t.el.style.display="flex",t.render())}))}H&&p.insights?.defaultOpen&&queueMicrotask(()=>Ut(!0));const io=4,at=240,Xt=480,ao=720,lo=1.25;let pe=Xt;function Zt(e){const t=A*2+110+2;let n=null;for(const o of e){if(o==null||!o.dies?.length)continue;const d=o.dies[0].width;if(!(d>0))continue;const i=o.wafer.radius*2*(io/d),l=Math.ceil(i+t);(n==null||l>n)&&(n=l)}return n}function so(e){const t=Zt(e);return t==null?at:Math.min(pe,Math.max(at,t))}function ro(e){const t=Zt(e);if(t==null)return!1;const n=Math.min(ao,Math.max(Xt,t));return n<=pe?!1:(pe=n,!0)}function lt(){return M!=null?"none":`${pe}px`}function Yt(){const e=lt();for(const t of Array.from(R.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let ze=at,Qt=0;function Jt(e){if(ro(e)&&Yt(),M==null){const n=so(e);n>ze&&(ze=n)}rt()}function en(e){M=Bn(e),Yt(),rt()}function st(e){return`repeat(${e}, minmax(0, ${M!=null?"1fr":`${pe}px`}))`}function tn(e){R.style.gridTemplateColumns!==e&&(R.style.gridTemplateColumns=e)}function rt(){if(M!=null){tn(st(M));return}const e=Math.max(1,Qt),t=12,n=R.clientWidth||0,o=i=>(n-t*(i-1))/i;let d=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const i=Math.min(pe,ze*lo),l=s=>{let a=0;for(;a<e&&o(a+1)>=s;)a++;return a};d=l(i)||l(ze)||1}tn(st(d))}const R=u.ownerDocument.createElement("div");if(Object.assign(R.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:st(1),gap:w.xl,paddingLeft:oe,paddingRight:oe,justifyContent:"start",alignContent:"start",isolation:"isolate"}),j?.placement){const e=j.placement;h=wt(e,oe,u.ownerDocument),h.style.maxHeight="calc(100vh - 80px)",h.style.position="sticky",h.style.top="8px",h.style.display="flex",h.style.flexDirection="column"}else if(V||Je()){const e=!!j?.defaultOpen;h=wt("right",oe,u.ownerDocument),h.style.maxHeight="calc(100vh - 80px)",h.style.position="sticky",h.style.top="8px",h.style.flexDirection="column",h.style.display=e?"flex":"none",z()}ae(),h?.style.display!=="none"&&P&&xe(P,!0),(j?.placement??"right")==="left"?(h&&q.appendChild(h),q.appendChild(R)):(q.appendChild(R),h&&q.appendChild(h));const ke=u.ownerDocument.createElement("div");Object.assign(ke.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:oe,paddingRight:oe,paddingTop:oe,zIndex:"1",background:g.menuBg}),Ve.appendChild(ue),Ve.appendChild(W),ke.appendChild(Ve),ke.appendChild(ee),u.appendChild(ke),u.appendChild(q);function Ne(){ee.innerHTML="";const e=r.plotMode??"hardBin",t=!Be&&un.has(e),n=L.filter(m=>m!=null),o=n.find(m=>m.isLotStack),d=bi(n.map(m=>({metadata:m.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0),i=e==="metadata",l=r.activeMetadataKey,s=t&&!i?kn(n,m=>(e==="softBin"?m.sbin:m.hbin)??void 0,On):{counts:new Map,total:0,pass:0},a=t&&!i?r.binColors??ce():void 0,c=a?e==="softBin"?a.pass.soft:a.pass.hard:new Set,f=li(s.counts.entries(),c).map(([m])=>m),b=t&&i&&l?kn(n,m=>vo(m.metadata?.[l])):{counts:new Map,total:0,pass:0},E=i?Pt()?.values:void 0,B=t&&i?(E??[...b.counts.keys()].sort(yt)).filter(m=>b.counts.has(m)):[];if(ue.innerHTML="",d&&ue.appendChild(d),ue.style.display=d?"flex":"none",!f.length&&!B.length){ee.style.display="none";return}ee.style.display="flex";const C=u.ownerDocument.createElement("div");Object.assign(C.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${w.sm} ${w.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),ee.appendChild(C);const y=r.highlightBin,I=L.flatMap(m=>m?.metadataFields??[]).find(m=>m.key===l),se=i?I?.label??(l?vi(l):"Metadata"):Wo[e],U=u.ownerDocument.createElement("span");if(U.textContent=se,Object.assign(U.style,{fontSize:T.body,fontWeight:"700",letterSpacing:To,textTransform:"uppercase",color:g.label,flexShrink:"0"}),C.appendChild(U),!i&&s.total>0){const m=s.pass,F=m/s.total*100,te=u.ownerDocument.createElement("span");te.textContent=`Yield ${Ze(F)}`,Object.assign(te.style,{fontSize:T.body,fontWeight:"700",color:g.value,whiteSpace:"nowrap",flexShrink:"0"});const ne=u.ownerDocument.createElement("span");ne.textContent=`${m.toLocaleString()} / ${s.total.toLocaleString()} dies`,Object.assign(ne.style,{fontSize:T.body,color:g.label,whiteSpace:"nowrap",flexShrink:"0"}),C.appendChild(te),C.appendChild(ne)}if(i){const m=r.highlightMetadataValue;B.forEach((F,te)=>{const ne=m===F,Ge=I?.values?.find(gt=>gt.value===F),ho=Ge?.color??Eo(te),dn=b.counts.get(F)??0;En(C,{color:ho,isActive:ne,label:Ge?.label??F,count:dn,percent:b.total>0?dn/b.total*100:void 0,onClick:()=>{const gt=r.highlightMetadataValue===F?void 0:F;O({highlightMetadataValue:gt})}})});return}const ft=e==="softBin"?L.flatMap(m=>m?.sbinDefs??[]):L.flatMap(m=>m?.hbinDefs??[]),ln=new Set,pt=[];for(const m of ft)ln.has(m.bin)||(ln.add(m.bin),pt.push(m));const mt=pt.length>0?new Map(pt.map(m=>[m.bin,m])):null,sn=a??r.binColors??ce(),go=e==="softBin"?sn.soft:sn.hard,rn=m=>go.get(m)??ko;for(const m of f){const F=y===m,te=mt?.get(m),ne=s.counts.get(m)??0;En(C,{color:rn(m),isActive:F,label:te?.name?`${m} \xB7 ${te.name}`:`Bin ${m}`,count:ne,percent:s.total>0?ne/s.total*100:void 0,onClick:()=>{const Ge=r.highlightBin===m?void 0:m;O({highlightBin:Ge})}})}s.total>0&&f.length>1&&ee.appendChild(Di(u.ownerDocument,[...s.counts.entries()].sort(([,m],[,F])=>F-m).map(([m,F])=>({color:rn(m),count:F,label:mt?.get(m)?.name?`${m} \xB7 ${mt.get(m).name}`:`Bin ${m}`})),s.total))}function Ee(e){const t=x.filter(s=>s!==null);if(!t.length)return[];const n=t.map(s=>s.dies.filter(Mi)),o=t[0].wafer,d=t.length,i=o.metadata?{...o,metadata:(({wafer:s,waferId:a,...c})=>c)(o.metadata)}:o;function l(s,a){return{...s,stats:{...s.stats,isLotStack:!0,aggregationMethod:a,lotSize:d}}}if(e==="stackedValues"){const s=ye();let a=s?.filter(bt);if(s!==void 0&&a?.length===0)return[];if(s?.length||(a=bo(t.flatMap(b=>b.dies)).map(b=>({testNumber:b,name:`Test ${b}`}))),!a?.length)return[];const c=r.aggregationMethod??"mean";return a.map(f=>{const b=ri(n,c,f.testNumber),E={testNumber:0,name:f.name,unit:f.unit};return{wafer:i,dies:b,testDefs:[E],label:`${f.name} \xB7 ${c}`,isLotStack:!0,aggrMethod:c,lotSize:d,statsSummary:l(Xe({wafer:i,dies:b,testDefs:[E]},{testNumbers:[0]}),c)}})}if(e==="stackedBins"){let s=Ke(t.map(a=>a?.hbinDefs));return(!s||s.length===0)&&(s=[...new Set(t.flatMap(c=>c.dies.map(f=>f.hbin).filter(f=>f!=null)))].sort((c,f)=>c-f).map(c=>({bin:c,name:`Bin ${c}`}))),s.map(a=>{const c=xn(n,a.bin,"hard"),f=[{bin:a.bin,name:a.name}];return{wafer:i,dies:c,hbinDefs:f,label:`${a.bin} \xB7 ${a.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:d,statsSummary:l(Xe({wafer:i,dies:c,hbinDefs:f}),"countBin")}})}if(e==="stackedSoftBins"){let s=Ke(t.map(a=>a?.sbinDefs));return(!s||s.length===0)&&(s=[...new Set(t.flatMap(c=>c.dies.map(f=>f.sbin).filter(f=>f!=null)))].sort((c,f)=>c-f).map(c=>({bin:c,name:`Bin ${c}`}))),s.map(a=>{const c=xn(n,a.bin,"soft"),f=[{bin:a.bin,name:a.name}];return{wafer:i,dies:c,sbinDefs:f,label:`${a.bin} \xB7 ${a.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:d,statsSummary:l(Xe({wafer:i,dies:c,sbinDefs:f}),"countBin")}})}return t}function dt(e){const t=x.length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:r.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}function O(e,{fireCallback:t=!0}={}){const n=Object.keys(e),o=r.plotMode,d=be()!==null;r={...r,...e};const i=r.plotMode,l=ge.has(i),s=o!==void 0&&ge.has(o),a=Ie>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const f=ce();r={...r,binColors:f},e={...e,binColors:f}}if(e.plotMode!==void 0)if(l){const f=dt(i);if(r={...r,...f},a)for(const b of S)b&&b.setOptions(e);else Z(Ee(i))}else if(s){const{valueRange:f,lotSize:b,aggregationMethod:E,...B}=r;if(r=B,a)for(const C of S)C&&C.setOptions(e);else Z(x.filter(C=>C!==null))}else for(const f of S)f&&f.setOptions(e);else if(e.aggregationMethod!==void 0&&i==="stackedValues")if(a)for(const f of S)f&&f.setOptions(e);else Z(Ee("stackedValues"));else for(const f of S)f&&f.setOptions(e);be()!==null!==d&&Ct(),Ne(),zt(),jt(),It();const c=e.plotMode!==void 0&&e.plotMode!==o;(ui.some(f=>f in e)||c)&&z(),Me(),Nt(),_t(),ot(),nt(),t&&p.onViewOptionsChange?.(Cn(r),n,ci(n))}function nn(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:w.xs,flex:"1",minWidth:"0"});const d=e.createElement("span");d.textContent=t,Object.assign(d.style,{fontWeight:"700",fontSize:T.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(d);const i=Dn(n??{});let l=null;if(i.length>0){const s=e.createElement("span");Object.assign(s.style,{fontSize:T.body,lineHeight:qe.none,color:g.label,flexShrink:"0"}),s.textContent="\u25BE",o.appendChild(s),Object.assign(o.style,{cursor:"pointer",borderRadius:N.control}),o.addEventListener("mouseenter",()=>{o.style.background=g.bgHover}),o.addEventListener("mouseleave",()=>{o.style.background="none"}),l=e.createElement("div"),l.dataset.wmapCardMetaPanel="1",Object.assign(l.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:fn,background:g.menuBg,borderBottom:`1px solid ${g.menuBorder}`,boxShadow:Le.menu,padding:`${w.md} ${w.lg}`,fontSize:T.body,display:"none"});const a=Mn(n??{});a&&l.appendChild(a),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`Wafer info for ${t||"this card"}. Click to expand.`),bn(o,c=>{s.textContent=c?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(c)),l&&(l.style.display=c?"block":"none")})}return{wrap:o,metaPanel:l}}function on(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]"),d=Dn(n??{});if(!o||d.length===0)return;const i=o.parentElement,l=u.ownerDocument.createElement("div");Object.assign(l.style,{display:"flex",alignItems:"center",gap:w.xs,flex:"1",minWidth:"0",cursor:"pointer"}),ht(l,"bare"),i?.insertBefore(l,o),l.appendChild(o);const s=u.ownerDocument.createElement("span");Object.assign(s.style,{fontSize:T.body,lineHeight:qe.none,color:g.label,flexShrink:"0"}),s.textContent="\u25BE",l.appendChild(s);const a=u.ownerDocument.createElement("div");a.dataset.wmapCardMetaPanel="1",Object.assign(a.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:fn,background:g.menuBg,borderBottom:`1px solid ${g.menuBorder}`,boxShadow:Le.menu,padding:`${w.md} ${w.lg}`,fontSize:T.body,display:"none"});const c=Mn(n??{});c&&a.appendChild(c),e.contentWrap.style.position="relative",e.contentWrap.appendChild(a),l.setAttribute("aria-expanded","false"),l.setAttribute("aria-label",`Wafer info for ${t}. Click to expand.`),bn(l,f=>{s.textContent=f?"\u25B4":"\u25BE",l.setAttribute("aria-expanded",String(f)),a.style.display=f?"block":"none"})}function ct(e,t,n){const o=u.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:N.container,boxShadow:Le.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:lt(),maxHeight:lt()});const d=u.ownerDocument.createElement("div");Object.assign(d.style,{display:"flex",alignItems:"center",padding:`${w.md} ${w.lg} ${w.sm}`,borderBottom:`1px solid ${g.menuBorder}`,flexShrink:"0",gap:w.sm});const{wrap:i,metaPanel:l}=nn(document,Ue(e,t),e.wafer.metadata??void 0);d.appendChild(i);const s=u.ownerDocument.createElement("button");s.dataset.wmapExpandBtn="1",s.setAttribute("aria-label","Open full view"),yn(s),s.innerHTML=Te.expand,Object.assign(s.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${g.menuBorder}`,borderRadius:N.control,background:g.panelBg,color:g.label,padding:w.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),ht(s),d.appendChild(s),o.appendChild(d);const a=u.ownerDocument.createElement("div");Object.assign(a.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(a),l&&a.appendChild(l),R.appendChild(o);const c=We||be()!==null,f=e.viewOptions?{...r,...e.viewOptions}:r,b=vn(a,e,{viewOptions:{...f,showLegend:c,legendPosition:he},showTooltip:!0,padding:A,statsSummary:e.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,onClick:e.onClick,onSelect:e.onSelect,onExpand:()=>Oe(t,e),showIdentity:!1,chromeInset:$o});return b.setViewControlsVisible(!1),b.setSummaryVisible(!1),s.onclick=()=>Oe(t,e),{card:o,ctrl:b,canvasWrapper:a,expandBtn:s}}function co(e){const t=re[e];if(!t)return;const n=[..._.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=Te.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>fo(n.id)):(t.innerHTML=Te.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>Oe(e,L[e]))}function Z(e){po(),ve()?.remove(),Ce(null),tt(),L=[];for(const i of S)i&&i.destroy();S=[],ie=[],re=[],Ie=0,R.innerHTML="",Qt=e.length,Jt(e.map(i=>typeof i=="function"?null:i));const t=[];for(let i=0;i<e.length;i++){const l=e[i];if(typeof l=="function"){const s=u.ownerDocument.createElement("div");s.className="wmap-gallery-card",Object.assign(s.style,{background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:N.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const a=u.ownerDocument.createElement("span");a.textContent="\u2026",Object.assign(a.style,{color:g.label,fontSize:"18px"}),s.appendChild(a),R.appendChild(s),L.push(null),S.push(null),ie.push(null),re.push(null),t.push({index:i,factory:l,placeholder:s}),Ie++}else{const{ctrl:s,canvasWrapper:a,expandBtn:c}=ct(l,i,e.length);L.push(l),S.push(s),ie.push(a),re.push(c)}}Ht(),Ne(),ot(),nt();const n=++Qe;let o=0;function d(){if(n!==Qe)return;if(o>=t.length){if(ge.has(r.plotMode)){const B=r.plotMode;Z(Ee(B))}return}const{index:i,factory:l,placeholder:s}=t[o++],a=l();L[i]=a,x[i]=a,Jt([a]);const{card:c,ctrl:f,canvasWrapper:b,expandBtn:E}=ct(a,i,e.length);S[i]=f,ie[i]=b,re[i]=E,Ie--,s.replaceWith(c),Ne(),Un(),!h&&!j?.placement&&a.statsSummary?.findings.length?(h=wt("right",oe,u.ownerDocument),h.style.maxHeight="calc(100vh - 80px)",h.style.position="sticky",h.style.top="8px",h.style.flexDirection="column",h.style.display="none",(j?.placement??"right")==="left"?q.insertBefore(h,R):q.appendChild(h),z(),P||(P=Q("findings","Summary panel",()=>{if(!h)return;const C=h.style.display!=="none";C||z(),h.style.display=C?"none":"flex",xe(P,!C),ae()}),W.appendChild(G()),W.appendChild(P)),ae()):h&&h.style.display!=="none"&&z(),ae(),setTimeout(d,0)}t.length>0&&setTimeout(d,0)}if(ge.has(r.plotMode)&&x.length>0){const e=dt(r.plotMode);r={...r,...e},Z(Ee(r.plotMode))}else Z(v);Me();let me=0;const an=new(u.ownerDocument.defaultView??window).ResizeObserver(()=>{if(me)return;me=(u.ownerDocument.defaultView??window).requestAnimationFrame(()=>{me=0,M==null&&rt()})});an.observe(R),h&&z();function uo(e,t){const n=ie[e];if(!n)return;n.innerHTML="",Object.assign(n.style,{alignItems:"center",justifyContent:"center"});const o=u.ownerDocument.createElement("span");o.textContent=t?"Opened in its own window":"Opened in the wafer viewer",Object.assign(o.style,{color:g.label,fontSize:T.body,textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function Oe(e,t){for(const l of _.values())if(l.cardIndex===e)return;const n=Ue(t,e),o=Ln++,d=S[e]?.getOptions(),i=Fo(n);if(i){const l=i.document;l.title=n,Object.assign(l.documentElement.style,{height:"100%"}),Object.assign(l.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:T.family}),zo(u,l.documentElement);const s=No(u,l.documentElement,()=>C.setOptions({})),a=l.createElement("div");a.dataset.wmapWindowBanner="1",a.textContent=n,Object.assign(a.style,{display:"none",padding:`${w.sm} ${w.xl}`,fontSize:T.body,fontWeight:"700",background:g.warnBg,color:g.warnText,borderBottom:`1px solid ${g.warnBorder}`,flexShrink:"0"}),l.body.appendChild(a);const c=l.createElement("div");Object.assign(c.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),l.body.appendChild(c);const{wrap:f,metaPanel:b}=nn(l,n,t.wafer.metadata??void 0),E=l.createElement("div");Object.assign(E.style,{display:"flex",alignItems:"center",padding:`${w.md} ${w.lg} ${w.sm}`,borderBottom:`1px solid ${g.menuBorder}`,flexShrink:"0",gap:w.sm}),E.appendChild(f),c.appendChild(E);const B=l.createElement("div");Object.assign(B.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),b&&B.appendChild(b),c.appendChild(B);const C=ut(B,t,void 0,d),y=setInterval(()=>{i.closed&&_e(o)},400);i.addEventListener("pagehide",()=>_e(o)),_.set(o,{id:o,ctrl:C,cardIndex:e,label:n,closePollId:y,stopThemeSync:s,close:()=>{i.closed||i.close()},setTitle:I=>{l.title=I,a.textContent=I,a.style.display="block"}})}else{const l=Ho({title:n,onClose:()=>_e(o),anchor:u});l.contentWrap.style.flexDirection="column",on(l,n,t.wafer.metadata??void 0);const s=ut(l.contentWrap,t,void 0,d);_.set(o,{id:o,ctrl:s,cardIndex:e,label:n,closePollId:null,close:()=>l.close(),setTitle:a=>{const c=l.box.querySelector("[data-wmap-window-title]");c&&(c.textContent=a,c.title=a)}})}S[e]?.destroy(),S[e]=null,uo(e,i!==null),co(e)}function ut(e,t,n,o){const d=t.viewOptions?{...r,...t.viewOptions}:r,i=o?{...d,...o}:d,s={...n!==void 0?{...i,plotMode:"value",activeTest:n}:i,showLegend:!0,legendPosition:he},a=vn(e,t,{viewOptions:s,showTooltip:!0,padding:A,statsSummary:t.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,onClick:t.onClick,onSelect:t.onSelect,showExpandButton:!1,showIdentity:!1});return a.setViewControlsVisible(!0),a.setSummaryVisible(!0),a.setExpandVisible(!1),a}function _e(e){const t=_.get(e);if(!t||(_.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.(),t.ctrl.destroy(),t.cardIndex===null))return;const n=t.cardIndex,o=L[n];if(!o)return;const{card:d,ctrl:i,canvasWrapper:l,expandBtn:s}=ct(o,n,L.length);ie[n]?.parentElement?.replaceWith(d),S[n]=i,ie[n]=l,re[n]=s}function fo(e){const t=_.get(e);t&&(t.close(),_e(e))}function po(){for(const e of _.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function mo(){const e=[...R.querySelectorAll("canvas")];if(!e.length)return;const t=e.length,n=Math.ceil(Math.sqrt(t)),o=Math.ceil(t/n),d=e[0].width,i=e[0].height,l=8,s=(u.ownerDocument.defaultView??window).devicePixelRatio||1,a=Math.round(26*s),c=Math.round(12*s),f=u.ownerDocument.createElement("canvas");f.width=n*d+(n-1)*l,f.height=o*(i+a)+(o-1)*l;const b=f.getContext("2d"),E=Oo(R);b.fillStyle=E.background,b.fillRect(0,0,f.width,f.height),e.forEach((B,C)=>{const y=C%n,I=Math.floor(C/n),se=y*(d+l),U=I*(i+a+l),ft=B.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";b.fillStyle=E.surface,b.fillRect(se,U,d,a),b.fillStyle=E.text,b.font=`700 ${c}px system-ui, sans-serif`,b.textAlign="left",b.textBaseline="middle",b.fillText(ft,se+Math.round(10*s),U+a/2,d-Math.round(20*s)),b.drawImage(B,se,U+a)}),f.toBlob(B=>{if(!B)return;if(p.downloadFilename!=null){gn(B,p.downloadFilename,p.onSaveImage);return}const C=S.find(y=>y!=null)?.getExportTitle();gn(B,["gallery",C].filter(Boolean).join(" "),Re.onSaveImage)})}return{setItems(e){x=e.map(n=>typeof n=="function"?null:n);const t=r.plotMode;if(ge.has(t))if(e.some(o=>typeof o=="function"))Z(e);else{const o=dt(t);r={...r,...o},Z(Ee(t))}else Z(e)},setOptions(e){O(e,{fireCallback:!1})},getOptions(){return Cn(r)},setFindingsNotice(e){Et=e,z()},setColumns(e){en(e)},getBinColors(){return r.binColors??ce()},setLotStatsSummary(e){V=e,Me(),h&&z(),ae()},openUserGuide:Kt,destroy(){Qe++;for(const e of[..._.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();_.clear();for(const e of S)e&&e.destroy();S=[],ve()?.remove(),an.disconnect(),me&&((u.ownerDocument.defaultView??window).cancelAnimationFrame(me),me=0),u.ownerDocument.removeEventListener("click",Ae,!0),window.removeEventListener("blur",kt),Y(),pn(),ke.remove(),q.remove(),h?.remove(),fe?.destroy()}}}
1
+ import{getUniqueTestNumbers as So,resolveTestNumber as Mo,findTestDef as Do,collectMetadataValues as ko}from"../renderer/buildView.js";import{metadataCategoricalValue as Bo}from"../core/metadata.js";import{resolveBinColorsForMaps as Eo,mergeBinDefs as Xe,binColorWarning as Oo,mixedPassBinsWarning as To,binColorsEqual as Lo}from"../renderer/binColors.js";import{itemPassBins as Ro,INPUT_DEFAULT_PASS_BINS as $o}from"../core/passBins.js";import{NO_DATA_FILL as Wo}from"../renderer/colorMap.js";import{metadataValueColor as Io}from"../renderer/colorMap.js";import{resolveCanvasTheme as Ao}from"./canvasTheme.js";import{ICONS as $e}from"./icons.js";import{SHADOW as We,LEADING as Ze,TRACKING as Po,controlStyle as Fo,wireControlHover as vt,SPACE as w,EDGE_GUTTER as ie,MAP_CHROME_INSET as Ho,RADIUS as _,FONT as L,CLR as h,sevColor as mn,MODE_LABELS as jo,BIN_LEGEND_MODES as gn,STACKED_MODES as he,Z_ABOVE as hn,applyOverlayZ as Vo,getTooltip as zo,hideTooltip as bn,createToolbarHelpers as No,buildModeMenuEl as _o,openDetachWindow as Go,openFloatingWindow as Ko,openModal as qo,openReportModal as Uo,copyWmapThemeTokens as Xo,syncWmapPopupTheme as Zo,openUserGuideWindow as Yo,makePaletteBtn as Qo,makeLogScaleBtn as Jo,makeLegendStyleBtn as ei,makeOverlaysBtn as ti,makeOrientationBtn as ni,menuLayerFor as yn,saveImageBlob as wn,markMenuTrigger as Ie,wireMenuA11y as vn,wireExpandToggle as xn,wireTooltip as Cn,requestedPassFailDisplay as Sn,overlayMenuRows as oi,anyOverlayActive as ii,logWmapVersionOnce as li,buildDataModeEntries as ai,metadataKeyHasData as si,metadataModeEntry as ri}from"./toolbar.js";import{waferDisplayLabel as Ye,waferIdentityLabel as di}from"../core/waferLabel.js";import{metadataDisplayValue as ci}from"../core/metadata.js";import{withExportContext as ui,noticeDownloadFilenameChange as fi}from"./exportName.js";import{sortBinsForDisplay as pi}from"../stats/binPareto.js";import{diePassStatus as mi}from"../core/dies.js";import{aggregateValues as gi,aggregateBinCounts as Mn}from"../core/aggregates.js";import{renderWaferMap as hi,renderWaferMapCard as Dn,toPublicViewOptions as kn}from"./renderWaferMap.js";import{classifyChanged as bi,COLOR_KEYS as yi}from"./renderWaferMap.js";import{buildWaferMap as wi,getTestPassStatus as Bn,isParametricTest as xt,getDieTestValue as vi}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Qe}from"../stats/analyzeWaferMap.js";import{collectWarnings as xi,buildWarningsMenuEl as Ci,severityOf as Si}from"./warnings.js";import{compareNatural as Ct,arrayEqual as En}from"../core/utils.js";import{createSummaryPanelEl as St,buildMetadataStripRow as Mi,buildCompactMetadataRows as On,metadataEntries as Tn,renderLotSummaryContentSteps as Di,reportMapsFromItems as ki}from"./summaryPanel.js";import{renderLotReportHtml as Bi}from"../stats/renderSummaryReport.js";import{prettyKey as Ei}from"../stats/facets.js";import{mergeTestDefs as Oi}from"../stats/mergeTestDefs.js";import{getDieKey as Ti,hasPosition as Li}from"../core/dies.js";import{runChunked as Ri}from"./chunked.js";function Ln(f){if(typeof f!="number"||!Number.isFinite(f))return;const x=Math.round(f);return x>=1?x:void 0}const Mt=12;function $i(f,x,p){let A=x;if(x.length>Mt){const D=x.slice(0,Mt-1),$=x.slice(Mt-1),H=$.reduce((Q,j)=>Q+j.count,0);A=[...D,{color:h.label,count:H,label:`Other (${$.length} bins)`}]}const M=f.createElement("div");Object.assign(M.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:_.control,overflow:"hidden",border:`1px solid ${h.menuBorder}`,boxSizing:"border-box",marginTop:w.xs,flexShrink:"0"}),M.setAttribute("role","img"),M.setAttribute("aria-label",`Population split: ${A.map(D=>`${D.label} ${Je(D.count/p*100)}`).join(", ")}`);for(const D of A){const $=D.count/p*100,H=f.createElement("div");Object.assign(H.style,{flex:`${$} 1 0`,minWidth:$>0?"2px":"0",background:D.color}),Cn(H,`${D.label} \xB7 ${D.count.toLocaleString()} dies \xB7 ${Je($)}`),M.appendChild(H)}return M}function Je(f){return f>0&&f<.1?"<0.1%":`${f.toFixed(1)}%`}function Rn(f,x,p){const A=new Map;let M=0,D=0;for(const $ of f){const H=p?new Set(p($)):void 0;for(const Q of $.dies){if(Q.partial||Q.edgeExcluded)continue;const j=x(Q);j!==void 0&&(A.set(j,(A.get(j)??0)+1),M++,H&&mi(Q,H)&&D++)}}return{counts:A,total:M,pass:D}}function $n(f,x){const p=f.ownerDocument.createElement("div");Object.assign(p.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${w.xxs} ${w.xs}`,borderRadius:_.control});const A=f.ownerDocument.createElement("span");Object.assign(A.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:x.color,border:x.isActive?`2px solid ${h.iconActive}`:`1px solid ${h.menuBorder}`,borderRadius:_.control,boxSizing:"border-box"});const M=f.ownerDocument.createElement("span");if(M.textContent=x.label,Object.assign(M.style,{fontWeight:x.isActive?"700":"400",color:x.isActive?h.iconActive:h.text,whiteSpace:"nowrap"}),p.appendChild(A),p.appendChild(M),x.count!==void 0){const D=f.ownerDocument.createElement("span");if(D.textContent=x.count.toLocaleString(),Object.assign(D.style,{color:x.isActive?h.iconActive:h.text,fontWeight:x.isActive?"700":"400",whiteSpace:"nowrap"}),p.appendChild(D),x.percent!==void 0){const $=f.ownerDocument.createElement("span");$.textContent=Je(x.percent),Object.assign($.style,{color:h.label,whiteSpace:"nowrap"}),p.appendChild($)}}p.setAttribute("role","button"),p.setAttribute("aria-pressed",x.isActive?"true":"false"),p.tabIndex=0,p.addEventListener("mouseenter",()=>{p.style.background=h.bgHover}),p.addEventListener("mouseleave",()=>{p.style.background="transparent"}),p.addEventListener("focus",()=>{p.style.background=h.bgHover}),p.addEventListener("blur",()=>{p.style.background="transparent"}),p.addEventListener("click",x.onClick),p.addEventListener("keydown",D=>{(D.key==="Enter"||D.key===" ")&&(D.preventDefault(),x.onClick())}),f.appendChild(p)}export function renderWaferGallery(f,x,p={}){li();const A=6;let M=Ln(p.columns);const D=p.showHelpButton??!1,$=p.userGuideExtension,H=p.insights?.enabled??!1,Q=Vo(p.zIndex),j=p.summaryPanel,Wn=e=>[...Ro(e)],Dt=()=>v.flatMap(e=>e?[e.ringCount??4]:[]),et=()=>Dt()[0]??4;function In(e){const t=[...new Set(e)].sort((n,o)=>n-o);return t.length<2?null:{code:"ring-count-mixed",severity:"warning",message:`These wafers were built with different ring counts (${t.join(", ")}). Each card and each wafer's findings use their own; the lot's ring yield in the Summary panel, report and Insights uses ${e[0]} rings.`}}let V=p.lotStatsSummary,be=p.viewOptions?.legendPosition??"default",Ae=p.perCardLegend??!1;function ye(){const e=c.plotMode??"hardBin";return gn.has(e)?null:c.colorbarRangeMode==="data"?"Each map has its own value range, so it keeps its own colour bar":"These wafers have no shared colour bar for value mode, so each map keeps its own"}function kt(){const e=Ae||ye()!==null;for(const t of S)t&&t.setOptions({showLegend:e})}let c={plotMode:"hardBin",showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...p.viewOptions},S=[],le=[],re=[],R=[];const Pe=ui(()=>{const e=R.filter(n=>n!=null);return{lots:[...new Set(e.map(n=>ci(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort(Ct),...e.length===1?{wafer:di(e[0])}:{waferCount:e.length}}},p.onSaveImage,p.onSaveText);fi(p.downloadFilename);let v=x.map(e=>typeof e=="function"?null:e);function Bt(){return Oi(v)}function we(){if(v.some(e=>e?.testDefs?.length))return Bt().defs}let ve=0,Fe=0;const G=new Map;let An=0,P=null,xe=null,Et=new Set,b=null,Pn={};function Ot(e){return v[e]?.statsSummary??V?.perWafer.find(t=>t.waferIndex===e)?.summary}function tt(){return!!(v.some(e=>e?.statsSummary?.findings.length)||V?.perWafer.some(e=>e.summary.findings.length))}const Fn=zo(),de=No(Fn),{makeBtn:J,setActive:Ce,makeSep:K,makeMenuRow:Hn,makeMenuSection:jn,makeDropdown:Tt,closeOpenMenu:He,getOpenMenu:Se,setOpenMenu:Me}=de;f.ownerDocument.addEventListener("click",He,!0);const Lt=()=>bn();window.addEventListener("blur",Lt);let Rt=p.findingsNotice;function $t(e){Et=new Set(e);const t=[...I.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,d)=>{const a=Et.has(d);o.style.outline=a?`3px solid ${h.findingHighlight}`:"",o.style.outlineOffset=a?"-3px":"",a&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function Wt(){$t([])}function It(){for(const e of S)e&&e.clearSelection()}function nt(e,t){const n=new Set(e),o=t??S.map((d,a)=>a);for(const d of o){const a=R[d],l=S[d];if(!a||!l)continue;const r=a.dies.filter(i=>n.has(Ti(i)));l.setSelection(r)}}function Vn(){const e=[];for(let t=0;t<v.length;t++){const n=v[t];if(!n)continue;const o=Ot(t)?.findings??[];o.length&&e.push({index:t,item:n,unusualCount:o.filter(d=>d.severity==="unusual").length,notableCount:o.filter(d=>d.severity==="notable").length,totalCount:o.length})}return e}function zn(e){const t=R[e]??v[e];t&&Re(e,t)}function Nn(e){const t=Ot(e)?.findings??[];if(t.length)return{total:t.length,unusual:t.filter(n=>n.severity==="unusual").length,notable:t.filter(n=>n.severity==="notable").length}}function _n(){Uo(Bi(ki(v,$o,et())),{anchor:f})}function Gn(){if(!b)return;b.innerHTML="";const e=Vn();if(v.length>0){const n=f.ownerDocument.createElement("div"),o=e.length,d=v.filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${d} wafers`:`${o} of ${d} wafer${d===1?"":"s"} with findings`,Object.assign(n.style,{fontSize:L.body,color:h.label,marginBottom:w.md}),b.appendChild(n)}if(e.length>0){const n=f.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...Fo("outlined"),marginBottom:w.lg,display:"block",width:"100%",textAlign:"left"}),vt(n),n.addEventListener("click",_n),b.appendChild(n)}if(e.length===0){const n=f.ownerDocument.createElement("div");Object.assign(n.style,{color:h.icon,fontSize:L.body,padding:"4px 0"}),n.textContent="No findings on any wafer.",b.appendChild(n)}else for(const{index:n,item:o,unusualCount:d,notableCount:a,totalCount:l}of e){const r=d?"unusual":a?"notable":"info",i=d+a||l,s=f.ownerDocument.createElement("button");s.type="button",Object.assign(s.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:w.xs,border:"none",borderLeft:`3px solid ${mn(r)}`,borderRadius:_.control,background:h.bgHover,cursor:"pointer",fontSize:L.body,textAlign:"left",boxSizing:"border-box"}),s.addEventListener("mouseover",()=>{s.style.background=h.bgActive}),s.addEventListener("mouseout",()=>{s.style.background=h.bgHover});const u=f.ownerDocument.createElement("span");u.textContent=Ye(o,n),Object.assign(u.style,{color:h.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const m=f.ownerDocument.createElement("span");m.textContent=String(i),s.setAttribute("aria-label",`${Ye(o,n)} \u2014 ${i} finding${i===1?"":"s"}${d?`, ${d} unusual`:""} \u2014 view wafer`),Object.assign(m.style,{marginLeft:w.sm,flexShrink:"0",background:mn(r),color:"#fff",borderRadius:_.container,padding:"1px 5px",fontSize:L.body,fontWeight:"600"}),s.appendChild(u),s.appendChild(m),s.addEventListener("click",()=>Re(n,o)),b.appendChild(s)}const t=f.ownerDocument.createElement("div");t.style.height="12px",b.appendChild(t)}let ce=null,De=null;function z(){if(b)if(ce?.cancel(),ce=null,V){const e=Xe(v.map(n=>n?.hbinDefs)),t=Xe(v.map(n=>n?.sbinDefs));ce=Ri(Di(b,{lotSummary:V,items:v,hbinDefs:e.length?e:void 0,sbinDefs:t.length?t:void 0,testDefs:we(),ringCount:et(),binColors:c.binColors,plotMode:c.plotMode??"hardBin",fallbackFormat:c.fallbackFormat,activeFindingId:xe,warnings:p.warnings?.display??!0?ee:[],findingsFilter:Pn,findingsNotice:Rt,onFindingsFilterChange:z,onSaveText:Pe.onSaveText,onFindingClick:(n,o)=>{xe===n.id?ot():qn(n,o),z()},onWaferClick:zn,findingsFor:Nn,dieListOptions:p.dieList}),{onDone:()=>{const n=De;De=null,n?.()}})}else Gn()}function Kn(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}function At(e){return[e.variable.kind,e.variable.index??"",e.variable.bin??"",e.comparison.family,e.comparison.left,e.effect.direction].join("|")}let je=[];function Pt(){if(je.length!==0){for(const e of je)S[e]?.setOptions({plotMode:c.plotMode,activeTest:c.activeTest});je=[]}}function ot(){xe=null,Wt(),It(),Pt(),T({highlightBin:void 0},{fireCallback:!1})}function qn(e,t){if(xe===e.id){ot();return}xe=e.id,t.style.background=h.bgActive,t.style.fontWeight="600",Pt();const{kind:n,index:o}=e.variable;if(n==="test"){const a=o??0,l=we();if(l===void 0||l.some(i=>i.testNumber===a))T({plotMode:"value",activeTest:a,highlightBin:void 0},{fireCallback:!1});else{T({highlightBin:void 0},{fireCallback:!1});const s=he.has(c.plotMode??"hardBin")?null:Kn(e);if(s){for(const u of s)S[u]?.setOptions({plotMode:"value",activeTest:a});je=[...s]}}}else n==="softBin"?T({plotMode:"softBin",highlightBin:void 0},{fireCallback:!1}):T({plotMode:"hardBin",highlightBin:void 0},{fireCallback:!1});Wt(),It();const d=e.highlight;if(d.kind==="wafer"){$t(d.waferIndices);const a=At(e);for(const l of d.waferIndices){const s=R[l]?.statsSummary?.findings.find(u=>At(u)===a)?.highlight?.dieKeys;s?.length&&nt(s,[l])}}else d.kind==="bin"?d.dieKeys?.length&&nt(d.dieKeys):(d.kind==="region"||d.kind==="dies")&&d.dieKeys?.length&&nt(d.dieKeys)}function ae(){if(!P)return;const e=!!b;P.style.display=(V||tt())&&e&&!Oe?"flex":"none";const t=b?b.style.display!=="none":!1;(V?.hasNotableFindings||v.some(o=>o?.statsSummary?.hasNotableFindings))&&!t?P.style.color=h.findingIndicator:P.dataset.active||(P.style.color=h.icon)}const W=f.ownerDocument.createElement("div");W.dataset.wmapToolbar="gallery",Object.assign(W.style,{flexShrink:"0",marginLeft:"auto",display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:h.menuBg,border:`1px solid ${h.menuBorder}`,borderRadius:_.control,padding:"0",boxShadow:We.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const Ft=()=>{const e=Se();e&&(e.remove(),Me(null)),Ie(Z,!1)},Z=J("mode","Plot mode",()=>{if(Se()){Ft();return}const e=v.flatMap(y=>y?.dies??[]),t=we(),{testEntries:n,binEntries:o,stackedEntries:d}=ai(e,t,{includeStacked:!0}),a=v.filter(Boolean).length,l=y=>{if(y===void 0)return a;let O=0;for(const N of v)N?.dies?.some(X=>Bn(X,y)!==void 0||X.testValues?.[y]!==void 0)&&O++;return O},r=a<2?n:n.map(y=>{const O=l(y.activeTest);return O===a?y:{...y,label:`${y.label} \u2014 ${O} of ${a} wafers`}}),i=c.plotMode??"hardBin",s=c.activeTest??0;function u(y){return y.plotMode!==i?!1:y.plotMode==="value"?s===(y.activeTest??0):y.plotMode==="metadata"?c.activeMetadataKey===y.activeMetadataKey:!0}function m(y,O){y.activeTest!==void 0?T({plotMode:"value",activeTest:y.activeTest,activeMetadataKey:void 0,logScale:y.logScale}):y.activeMetadataKey!==void 0?T({plotMode:y.plotMode,activeTest:void 0,activeMetadataKey:y.activeMetadataKey,passFailDisplay:"off"}):T({plotMode:y.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),O.remove(),Me(null),Ie(Z,!1)}const k=new Set,B=v.flatMap(y=>y?.metadataFields??[]).filter(y=>!k.has(y.key)&&k.add(y.key)).filter(y=>si(e,y.key)).map(ri),C=_o(Z.getBoundingClientRect(),r,o,d,u,m,{makeMenuRow:Hn,makeMenuSection:jn},i,Z.ownerDocument.defaultView??window,B);yn(Z).appendChild(C),Me(C),Ie(Z,!0),vn(C,Z,Ft)});Ie(Z,!1);const Un=()=>R.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:Xn,sync:Ht}=Qo(de,()=>({...c,plotMode:c.plotMode??"hardBin"}),Un,e=>T(e));Ht();const Zn=x.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function Ve(){const e=we(),{testNumber:t}=Mo(c.activeTest??0,e);return{testNumber:t,td:Do(e,t)}}function jt(){if((c.plotMode??"hardBin")!=="value")return!1;const{td:e}=Ve();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function ke(){if((c.plotMode??"hardBin")!=="value")return!1;const{td:e}=Ve();return e!==void 0&&!xt(e)}function Yn(){if((c.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=Ve();return v.some(n=>n?.dies?.some(o=>Bn(o,e,t)!==void 0))}function Qn(e,t){if(!t||!xt(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((Sn(c)==="spec"&&n?"spec":c.colorbarRangeMode??"spec")==="spec"&&n)return;let a=1/0,l=-1/0;for(const r of v)if(r)for(const i of r.dies){const s=vi(i,e);s!==void 0&&(s<a&&(a=s),s>l&&(l=s))}if(isFinite(a))return a===l?[a,a+1]:[a,l]}function it(e,t,n){const o=c[e];if(o===t||o!=null&&t!=null&&n(o,t))return!1;c={...c,[e]:t};for(const d of S)d&&d.setOptions({[e]:t});return!0}function Vt(){if((c.plotMode??"hardBin")!=="metadata")return;const e=c.activeMetadataKey;if(!e)return;const t=new Set;for(const n of v)if(n)for(const o of ko(n.dies,e))t.add(o);return{key:e,values:[...t].sort(Ct)}}function lt(){it("metadataValueOrder",Vt(),(e,t)=>e.key===t.key&&En(e.values,t.values))}function at(){if((c.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=Ve(),n=Qn(e,t);it("valueRange",n?{test:e,range:n}:void 0,(d,a)=>{const l=s=>Array.isArray(s)?{test:void 0,range:s}:{test:s.test,range:s.range},r=l(d),i=l(a);return r.test===i.test&&En(r.range,i.range)})}let st=!1;function Jn(){if(st)return;st=!0,(f.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{st=!1,at(),lt(),Nt()})}let rt=!1;function eo(){if(rt)return;rt=!0,(f.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{rt=!1,Ke()})}let zt=[];function ue(){const{colors:e,mixedHardBins:t}=Eo(v.filter(n=>n!=null),{binColorScheme:c.binColorScheme,useDefinedBinColors:c.useDefinedBinColors});return zt=t,e}function Nt(){it("binColors",ue(),Lo),Be()}const to=ti(de,()=>oi(c,Zn,{functionalActive:ke(),hasLimits:jt()&&!ke(),hasRecorded:Yn()&&!ke(),binMode:(c.plotMode??"hardBin")==="hardBin"||(c.plotMode??"hardBin")==="softBin"},e=>T(e)),()=>ii(c)),{btn:no,sync:_t}=ei(de,()=>({plotMode:c.plotMode,legendPosition:be}),e=>{be=e;for(const t of S)t&&t.setOptions({legendPosition:be})},{get:()=>Ae,set:e=>{Ae=e,kt()},blockedReason:ye});_t();const oo=[{value:"mean",label:"Mean"},{value:"median",label:"Median"},{value:"stddev",label:"Std Dev"},{value:"min",label:"Min"},{value:"max",label:"Max"},{value:"count",label:"Count"}],Gt=Tt("aggr","Aggregation method",()=>oo,()=>c.aggregationMethod??"mean",e=>T({aggregationMethod:e}));function Kt(){const e=c.plotMode==="stackedValues";Gt.style.display=e?"":"none"}Kt();const{btn:io,sync:qt}=Jo(de,()=>({...c,functionalActive:ke()}),e=>T(e));qt();const ze=J("specRange","Colorbar range: spec limits",()=>{const e=c.colorbarRangeMode==="data"?"spec":"data";T({colorbarRangeMode:e})});function Ut(){const e=(c.plotMode??"hardBin")==="value"&&jt()&&Sn(c)==="off"&&!ke();ze.style.display=e?"":"none";const t=(c.colorbarRangeMode??"spec")==="spec";Ce(ze,t),ze.ariaLabel=t?"Colorbar range: spec limits (click for data range)":"Colorbar range: data range (click for spec limits)"}Ut();const lo=ni(de,()=>c,e=>T(e)),ao=J("downloadAll","Download gallery PNG",vo),so=Tt("columns","Columns",()=>[{value:"auto",label:"Auto"},{value:"1",label:"1 column"},{value:"2",label:"2 columns"},{value:"3",label:"3 columns"},{value:"4",label:"4 columns"},{value:"5",label:"5 columns"}],()=>M!=null?String(M):"auto",e=>ln(e==="auto"?void 0:Number(e))),E=f.ownerDocument.createElement("div");Object.assign(E.style,{display:"inline-flex",alignItems:"center",gap:"0"}),W.appendChild(E),E.appendChild(Z),E.appendChild(Xn),E.appendChild(Gt),E.appendChild(io),E.appendChild(ze),E.appendChild(K()),E.appendChild(to),E.appendChild(K()),E.appendChild(no),E.appendChild(K()),E.appendChild(lo),E.appendChild(K()),E.appendChild(so),E.appendChild(K()),E.appendChild(ao),(V||tt())&&(P=J("findings","Summary panel",()=>{if(!b)return;const e=b.style.display!=="none";e||z(),b.style.display=e?"none":"flex",Ce(P,!e),ae()}),W.appendChild(K()),W.appendChild(P));let q=null,Ne=null,ee=[],Xt=!1;function Be(){const e=xi({lotStatsSummary:V,result:{warnings:[...v.flatMap(n=>n?.warnings??[]),...Bt().warnings]},extra:[c.binColors&&Oo(c.binColors,c.plotMode),To(zt),In(Dt())].filter(n=>!!n)}),t=e.length!==ee.length||e.some((n,o)=>n.code!==ee[o]?.code||n.message!==ee[o]?.message);ee=e,(t||!Xt)&&(Xt=!0,p.warnings?.onWarning?.(e)),ro()}function ro(){if(!q||!Ne)return;const e=ee.length,t=e>0;if(q.style.display=t?"flex":"none",Ne.style.display=t?"":"none",!t)return;const n=Si(ee[0]),o=`${e} data ${e===1?"warning":"warnings"}`;q.style.color=n==="error"?h.errText:h.warnText,q.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(p.warnings?.display??!0)&&(Ne=K(),q=J("warning","Data warnings",()=>{const e=Se();if(He(new MouseEvent("click")),e)return;const t=Ci(q.getBoundingClientRect(),ee,q.ownerDocument.defaultView??window);yn(f).appendChild(t),Me(t),vn(t,q,()=>He(new MouseEvent("click")))}),Ie(q,!1),W.appendChild(Ne),W.appendChild(q)),Be();let se=null;H&&(se=J("analysis","Insights",()=>{Qt(!Oe)}),se.dataset.wmapInsightsBtn="1",W.appendChild(K()),W.appendChild(se));function Zt(){import("./userGuideHtml.js").then(e=>Yo({buildWaferMap:wi,renderWaferMap:hi,renderWaferGallery,analyzeWaferMap:Qe},e.USER_GUIDE_HTML,$,f))}D&&(W.appendChild(K()),W.appendChild(J("help","User guide",()=>Zt())));const fe=f.ownerDocument.createElement("div");fe.dataset.wmapGalleryMeta="1",Object.assign(fe.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${w.sm} ${w.lg}`,fontSize:L.sub,lineHeight:Ze.none,boxSizing:"border-box"});const _e=f.ownerDocument.createElement("div");Object.assign(_e.style,{background:h.canvasBg,display:"flex",alignItems:"stretch",gap:w.lg,paddingBottom:w.lg,minWidth:"0"});const te=f.ownerDocument.createElement("div");te.dataset.wmapGalleryLegend="1",Object.assign(te.style,{display:"flex",flexDirection:"column",gap:w.sm,background:h.menuBg,border:`1px solid ${h.menuBorder}`,borderRadius:_.container,padding:`${w.sm} ${w.lg}`,marginBottom:w.lg,boxShadow:We.panel,fontSize:L.body,lineHeight:Ze.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const U=f.ownerDocument.createElement("div");Object.assign(U.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let pe=null,Ee=null,Yt=null;function co(){return H?pe?Promise.resolve(pe):(Yt??=import("./insightsTab.js").then(({createInsightsTab:e})=>(pe=e({getItems:()=>v,getLotStats:()=>V,getBinColors:()=>c.binColors??ue(),getRingCount:et,defaultView:p.insights?.defaultView,onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:Pe.onSaveImage,onSaveText:Pe.onSaveText,ownerDocument:f.ownerDocument,openWafer:(t,n,o)=>{const d=v[t];if(!d)return;let a=null;const l=qo({title:n,onClose:()=>a?.destroy(),anchor:f});rn(l,n,d.wafer.metadata??void 0),a=gt(l.contentWrap,d,o)}}),Ee=pe.el,Ee.style.display="none",f.appendChild(Ee),pe)),Yt):Promise.resolve(null)}let Oe=!1;function Qt(e){H&&(Oe=e,Ee&&(Ee.style.display=e?"flex":"none"),U.style.display=e?"none":"flex",E.style.display=e?"none":"inline-flex",W.style.display="inline-flex",se&&(Ce(se,e),se.innerHTML=e?$e.wafer:$e.analysis,se.ariaLabel=e?"Back to gallery view":"Insights"),ae(),Ke(),e&&co().then(t=>{!t||!Oe||(t.el.style.display="flex",t.render())}))}H&&p.insights?.defaultOpen&&queueMicrotask(()=>Qt(!0));const uo=4,dt=240,Jt=480,fo=720,po=1.25;let me=Jt;function en(e){const t=A*2+110+2;let n=null;for(const o of e){if(o==null||!o.dies?.length)continue;const d=o.dies[0].width;if(!(d>0))continue;const a=o.wafer.radius*2*(uo/d),l=Math.ceil(a+t);(n==null||l>n)&&(n=l)}return n}function mo(e){const t=en(e);return t==null?dt:Math.min(me,Math.max(dt,t))}function go(e){const t=en(e);if(t==null)return!1;const n=Math.min(fo,Math.max(Jt,t));return n<=me?!1:(me=n,!0)}function ct(){return M!=null?"none":`${me}px`}function tn(){const e=ct();for(const t of Array.from(I.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let Ge=dt,nn=0;function on(e){if(go(e)&&tn(),M==null){const n=mo(e);n>Ge&&(Ge=n)}ft()}function ln(e){M=Ln(e),tn(),ft()}function ut(e){return`repeat(${e}, minmax(0, ${M!=null?"1fr":`${me}px`}))`}function an(e){I.style.gridTemplateColumns!==e&&(I.style.gridTemplateColumns=e)}function ft(){if(M!=null){an(ut(M));return}const e=Math.max(1,nn),t=12,n=I.clientWidth||0,o=a=>(n-t*(a-1))/a;let d=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const a=Math.min(me,Ge*po),l=r=>{let i=0;for(;i<e&&o(i+1)>=r;)i++;return i};d=l(a)||l(Ge)||1}an(ut(d))}const I=f.ownerDocument.createElement("div");if(Object.assign(I.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:ut(1),gap:w.xl,paddingLeft:ie,paddingRight:ie,justifyContent:"start",alignContent:"start",isolation:"isolate"}),j?.placement){const e=j.placement;b=St(e,ie,f.ownerDocument),b.style.maxHeight="calc(100vh - 80px)",b.style.position="sticky",b.style.top="8px",b.style.display="flex",b.style.flexDirection="column"}else if(V||tt()){const e=!!j?.defaultOpen;b=St("right",ie,f.ownerDocument),b.style.maxHeight="calc(100vh - 80px)",b.style.position="sticky",b.style.top="8px",b.style.flexDirection="column",b.style.display=e?"flex":"none",z()}ae(),b?.style.display!=="none"&&P&&Ce(P,!0),(j?.placement??"right")==="left"?(b&&U.appendChild(b),U.appendChild(I)):(U.appendChild(I),b&&U.appendChild(b));const Te=f.ownerDocument.createElement("div");Object.assign(Te.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:ie,paddingRight:ie,paddingTop:ie,zIndex:"1",background:h.menuBg}),_e.appendChild(fe),_e.appendChild(W),Te.appendChild(_e),Te.appendChild(te),f.appendChild(Te),f.appendChild(U);function Ke(){te.innerHTML="";const e=c.plotMode??"hardBin",t=!Oe&&gn.has(e),n=R.filter(g=>g!=null),o=n.find(g=>g.isLotStack),d=Mi(n.map(g=>({metadata:g.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0),a=e==="metadata",l=c.activeMetadataKey,r=t&&!a?Rn(n,g=>(e==="softBin"?g.sbin:g.hbin)??void 0,Wn):{counts:new Map,total:0,pass:0},i=t&&!a?c.binColors??ue():void 0,s=i?e==="softBin"?i.pass.soft:i.pass.hard:new Set,u=pi(r.counts.entries(),s).map(([g])=>g),m=t&&a&&l?Rn(n,g=>Bo(g.metadata?.[l])):{counts:new Map,total:0,pass:0},k=a?Vt()?.values:void 0,B=t&&a?(k??[...m.counts.keys()].sort(Ct)).filter(g=>m.counts.has(g)):[];if(fe.innerHTML="",d&&fe.appendChild(d),fe.style.display=d?"flex":"none",!u.length&&!B.length){te.style.display="none";return}te.style.display="flex";const C=f.ownerDocument.createElement("div");Object.assign(C.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${w.sm} ${w.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),te.appendChild(C);const y=c.highlightBin,O=R.flatMap(g=>g?.metadataFields??[]).find(g=>g.key===l),N=a?O?.label??(l?Ei(l):"Metadata"):jo[e],X=f.ownerDocument.createElement("span");if(X.textContent=N,Object.assign(X.style,{fontSize:L.body,fontWeight:"700",letterSpacing:Po,textTransform:"uppercase",color:h.label,flexShrink:"0"}),C.appendChild(X),!a&&r.total>0){const g=r.pass,F=g/r.total*100,ne=f.ownerDocument.createElement("span");ne.textContent=`Yield ${Je(F)}`,Object.assign(ne.style,{fontSize:L.body,fontWeight:"700",color:h.value,whiteSpace:"nowrap",flexShrink:"0"});const oe=f.ownerDocument.createElement("span");oe.textContent=`${g.toLocaleString()} / ${r.total.toLocaleString()} dies`,Object.assign(oe.style,{fontSize:L.body,color:h.label,whiteSpace:"nowrap",flexShrink:"0"}),C.appendChild(ne),C.appendChild(oe)}if(a){const g=c.highlightMetadataValue;B.forEach((F,ne)=>{const oe=g===F,Ue=O?.values?.find(wt=>wt.value===F),Co=Ue?.color??Io(ne),pn=m.counts.get(F)??0;$n(C,{color:Co,isActive:oe,label:Ue?.label??F,count:pn,percent:m.total>0?pn/m.total*100:void 0,onClick:()=>{const wt=c.highlightMetadataValue===F?void 0:F;T({highlightMetadataValue:wt})}})});return}const ht=e==="softBin"?R.flatMap(g=>g?.sbinDefs??[]):R.flatMap(g=>g?.hbinDefs??[]),cn=new Set,bt=[];for(const g of ht)cn.has(g.bin)||(cn.add(g.bin),bt.push(g));const yt=bt.length>0?new Map(bt.map(g=>[g.bin,g])):null,un=i??c.binColors??ue(),xo=e==="softBin"?un.soft:un.hard,fn=g=>xo.get(g)??Wo;for(const g of u){const F=y===g,ne=yt?.get(g),oe=r.counts.get(g)??0;$n(C,{color:fn(g),isActive:F,label:ne?.name?`${g} \xB7 ${ne.name}`:`Bin ${g}`,count:oe,percent:r.total>0?oe/r.total*100:void 0,onClick:()=>{const Ue=c.highlightBin===g?void 0:g;T({highlightBin:Ue})}})}r.total>0&&u.length>1&&te.appendChild($i(f.ownerDocument,[...r.counts.entries()].sort(([,g],[,F])=>F-g).map(([g,F])=>({color:fn(g),count:F,label:yt?.get(g)?.name?`${g} \xB7 ${yt.get(g).name}`:`Bin ${g}`})),r.total))}function Le(e){const t=v.filter(r=>r!==null);if(!t.length)return[];const n=t.map(r=>r.dies.filter(Li)),o=t[0].wafer,d=t.length,a=o.metadata?{...o,metadata:(({wafer:r,waferId:i,...s})=>s)(o.metadata)}:o;function l(r,i){return{...r,stats:{...r.stats,isLotStack:!0,aggregationMethod:i,lotSize:d}}}if(e==="stackedValues"){const r=we();let i=r?.filter(xt);if(r!==void 0&&i?.length===0)return[];if(r?.length||(i=So(t.flatMap(m=>m.dies)).map(m=>({testNumber:m,name:`Test ${m}`}))),!i?.length)return[];const s=c.aggregationMethod??"mean";return i.map(u=>{const m=gi(n,s,u.testNumber),k={testNumber:0,name:u.name,unit:u.unit};return{wafer:a,dies:m,testDefs:[k],label:`${u.name} \xB7 ${s}`,isLotStack:!0,aggrMethod:s,lotSize:d,statsSummary:l(Qe({wafer:a,dies:m,testDefs:[k]},{testNumbers:[0]}),s)}})}if(e==="stackedBins"){let r=Xe(t.map(i=>i?.hbinDefs));return(!r||r.length===0)&&(r=[...new Set(t.flatMap(s=>s.dies.map(u=>u.hbin).filter(u=>u!=null)))].sort((s,u)=>s-u).map(s=>({bin:s,name:`Bin ${s}`}))),r.map(i=>{const s=Mn(n,i.bin,"hard"),u=[{bin:i.bin,name:i.name}];return{wafer:a,dies:s,hbinDefs:u,label:`${i.bin} \xB7 ${i.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:d,statsSummary:l(Qe({wafer:a,dies:s,hbinDefs:u}),"countBin")}})}if(e==="stackedSoftBins"){let r=Xe(t.map(i=>i?.sbinDefs));return(!r||r.length===0)&&(r=[...new Set(t.flatMap(s=>s.dies.map(u=>u.sbin).filter(u=>u!=null)))].sort((s,u)=>s-u).map(s=>({bin:s,name:`Bin ${s}`}))),r.map(i=>{const s=Mn(n,i.bin,"soft"),u=[{bin:i.bin,name:i.name}];return{wafer:a,dies:s,sbinDefs:u,label:`${i.bin} \xB7 ${i.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:d,statsSummary:l(Qe({wafer:a,dies:s,sbinDefs:u}),"countBin")}})}return t}function pt(e){const t=v.length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:c.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}function T(e,{fireCallback:t=!0}={}){const n=Object.keys(e),o=c.plotMode,d=ye()!==null;c={...c,...e};const a=c.plotMode,l=he.has(a),r=o!==void 0&&he.has(o),i=Fe>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const u=ue();c={...c,binColors:u},e={...e,binColors:u}}if(e.plotMode!==void 0)if(l){const u=pt(a);if(c={...c,...u},i)for(const m of S)m&&m.setOptions(e);else Y(Le(a))}else if(r){const{valueRange:u,lotSize:m,aggregationMethod:k,...B}=c;if(c=B,i)for(const C of S)C&&C.setOptions(e);else Y(v.filter(C=>C!==null))}else for(const u of S)u&&u.setOptions(e);else if(e.aggregationMethod!==void 0&&a==="stackedValues")if(i)for(const u of S)u&&u.setOptions(e);else Y(Le("stackedValues"));else for(const u of S)u&&u.setOptions(e);ye()!==null!==d&&kt(),Ke(),Kt(),_t(),Ht();const s=e.plotMode!==void 0&&e.plotMode!==o;(yi.some(u=>u in e)||s)&&z(),Be(),qt(),Ut(),at(),lt(),t&&p.onViewOptionsChange?.(kn(c),n,bi(n))}function sn(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:w.xs,flex:"1",minWidth:"0"});const d=e.createElement("span");d.textContent=t,Object.assign(d.style,{fontWeight:"700",fontSize:L.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(d);const a=Tn(n??{});let l=null;if(a.length>0){const r=e.createElement("span");Object.assign(r.style,{fontSize:L.body,lineHeight:Ze.none,color:h.label,flexShrink:"0"}),r.textContent="\u25BE",o.appendChild(r),Object.assign(o.style,{cursor:"pointer",borderRadius:_.control}),o.addEventListener("mouseenter",()=>{o.style.background=h.bgHover}),o.addEventListener("mouseleave",()=>{o.style.background="none"}),l=e.createElement("div"),l.dataset.wmapCardMetaPanel="1",Object.assign(l.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:hn,background:h.menuBg,borderBottom:`1px solid ${h.menuBorder}`,boxShadow:We.menu,padding:`${w.md} ${w.lg}`,fontSize:L.body,display:"none"});const i=On(n??{});i&&l.appendChild(i),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`Wafer info for ${t||"this card"}. Click to expand.`),xn(o,s=>{r.textContent=s?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(s)),l&&(l.style.display=s?"block":"none")})}return{wrap:o,metaPanel:l}}function rn(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]"),d=Tn(n??{});if(!o||d.length===0)return;const a=o.parentElement,l=f.ownerDocument.createElement("div");Object.assign(l.style,{display:"flex",alignItems:"center",gap:w.xs,flex:"1",minWidth:"0",cursor:"pointer"}),vt(l,"bare"),a?.insertBefore(l,o),l.appendChild(o);const r=f.ownerDocument.createElement("span");Object.assign(r.style,{fontSize:L.body,lineHeight:Ze.none,color:h.label,flexShrink:"0"}),r.textContent="\u25BE",l.appendChild(r);const i=f.ownerDocument.createElement("div");i.dataset.wmapCardMetaPanel="1",Object.assign(i.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:hn,background:h.menuBg,borderBottom:`1px solid ${h.menuBorder}`,boxShadow:We.menu,padding:`${w.md} ${w.lg}`,fontSize:L.body,display:"none"});const s=On(n??{});s&&i.appendChild(s),e.contentWrap.style.position="relative",e.contentWrap.appendChild(i),l.setAttribute("aria-expanded","false"),l.setAttribute("aria-label",`Wafer info for ${t}. Click to expand.`),xn(l,u=>{r.textContent=u?"\u25B4":"\u25BE",l.setAttribute("aria-expanded",String(u)),i.style.display=u?"block":"none"})}function mt(e,t,n){const o=f.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:h.menuBg,border:`1px solid ${h.menuBorder}`,borderRadius:_.container,boxShadow:We.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:ct(),maxHeight:ct()});const d=f.ownerDocument.createElement("div");Object.assign(d.style,{display:"flex",alignItems:"center",padding:`${w.md} ${w.lg} ${w.sm}`,borderBottom:`1px solid ${h.menuBorder}`,flexShrink:"0",gap:w.sm});const{wrap:a,metaPanel:l}=sn(document,Ye(e,t),e.wafer.metadata??void 0);d.appendChild(a);const r=f.ownerDocument.createElement("button");r.dataset.wmapExpandBtn="1",r.setAttribute("aria-label","Open full view"),Cn(r),r.innerHTML=$e.expand,Object.assign(r.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${h.menuBorder}`,borderRadius:_.control,background:h.panelBg,color:h.label,padding:w.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),vt(r),d.appendChild(r),o.appendChild(d);const i=f.ownerDocument.createElement("div");Object.assign(i.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(i),l&&i.appendChild(l),I.appendChild(o);const s=Ae||ye()!==null,u=e.viewOptions?{...c,...e.viewOptions}:c,m=Dn(i,e,{viewOptions:{...u,showLegend:s,legendPosition:be},showTooltip:!0,padding:A,statsSummary:e.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,onClick:e.onClick,onSelect:e.onSelect,onExpand:()=>Re(t,e),showIdentity:!1,chromeInset:Ho});return m.setViewControlsVisible(!1),m.setSummaryVisible(!1),r.onclick=()=>Re(t,e),{card:o,ctrl:m,canvasWrapper:i,expandBtn:r}}function ho(e){const t=re[e];if(!t)return;const n=[...G.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=$e.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>yo(n.id)):(t.innerHTML=$e.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>Re(e,R[e]))}function Y(e){wo(),Se()?.remove(),Me(null),ot(),R=[];for(const i of S)i&&i.destroy();S=[],le=[],re=[],Fe=0,I.innerHTML="",nn=e.length,on(e.map(i=>typeof i=="function"?null:i));const t=[];for(let i=0;i<e.length;i++){const s=e[i];if(typeof s=="function"){const u=f.ownerDocument.createElement("div");u.className="wmap-gallery-card",Object.assign(u.style,{background:h.menuBg,border:`1px solid ${h.menuBorder}`,borderRadius:_.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const m=f.ownerDocument.createElement("span");m.textContent="\u2026",Object.assign(m.style,{color:h.label,fontSize:"18px"}),u.appendChild(m),I.appendChild(u),R.push(null),S.push(null),le.push(null),re.push(null),t.push({index:i,factory:s,placeholder:u}),Fe++}else{const{ctrl:u,canvasWrapper:m,expandBtn:k}=mt(s,i,e.length);R.push(s),S.push(u),le.push(m),re.push(k)}}Nt(),Ke(),at(),lt();const n=++ve,o=()=>{setTimeout(()=>{n===ve&&p.onItemsResolved?.()},0)},d=i=>{setTimeout(()=>{n===ve&&p.onItemResolved?.(i,e.length)},0)};let a=e.length-t.length;a>0&&d(a);let l=0;function r(){if(n!==ve)return;if(l>=t.length){if(he.has(c.plotMode)){const O=c.plotMode;Y(Le(O));return}De=o,z(),ce||(De=null,o());return}const{index:i,factory:s,placeholder:u}=t[l++],m=s();R[i]=m,v[i]=m,on([m]);const{card:k,ctrl:B,canvasWrapper:C,expandBtn:y}=mt(m,i,e.length);S[i]=B,le[i]=C,re[i]=y,Fe--,u.replaceWith(k),d(++a),eo(),Jn(),!b&&!j?.placement&&m.statsSummary?.findings.length&&(b=St("right",ie,f.ownerDocument),b.style.maxHeight="calc(100vh - 80px)",b.style.position="sticky",b.style.top="8px",b.style.flexDirection="column",b.style.display="none",(j?.placement??"right")==="left"?U.insertBefore(b,I):U.appendChild(b),z(),P||(P=J("findings","Summary panel",()=>{if(!b)return;const N=b.style.display!=="none";N||z(),b.style.display=N?"none":"flex",Ce(P,!N),ae()}),W.appendChild(K()),W.appendChild(P)),ae()),ae(),setTimeout(r,0)}t.length>0?setTimeout(r,0):o()}if(he.has(c.plotMode)&&v.length>0){const e=pt(c.plotMode);c={...c,...e},Y(Le(c.plotMode))}else Y(x);Be();let ge=0;const dn=new(f.ownerDocument.defaultView??window).ResizeObserver(()=>{if(ge)return;ge=(f.ownerDocument.defaultView??window).requestAnimationFrame(()=>{ge=0,M==null&&ft()})});dn.observe(I),b&&z();function bo(e,t){const n=le[e];if(!n)return;n.innerHTML="",Object.assign(n.style,{alignItems:"center",justifyContent:"center"});const o=f.ownerDocument.createElement("span");o.textContent=t?"Opened in its own window":"Opened in the wafer viewer",Object.assign(o.style,{color:h.label,fontSize:L.body,textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function Re(e,t){for(const l of G.values())if(l.cardIndex===e)return;const n=Ye(t,e),o=An++,d=S[e]?.getOptions(),a=Go(n);if(a){const l=a.document;l.title=n,Object.assign(l.documentElement.style,{height:"100%"}),Object.assign(l.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:L.family}),Xo(f,l.documentElement);const r=Zo(f,l.documentElement,()=>C.setOptions({})),i=l.createElement("div");i.dataset.wmapWindowBanner="1",i.textContent=n,Object.assign(i.style,{display:"none",padding:`${w.sm} ${w.xl}`,fontSize:L.body,fontWeight:"700",background:h.warnBg,color:h.warnText,borderBottom:`1px solid ${h.warnBorder}`,flexShrink:"0"}),l.body.appendChild(i);const s=l.createElement("div");Object.assign(s.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),l.body.appendChild(s);const{wrap:u,metaPanel:m}=sn(l,n,t.wafer.metadata??void 0),k=l.createElement("div");Object.assign(k.style,{display:"flex",alignItems:"center",padding:`${w.md} ${w.lg} ${w.sm}`,borderBottom:`1px solid ${h.menuBorder}`,flexShrink:"0",gap:w.sm}),k.appendChild(u),s.appendChild(k);const B=l.createElement("div");Object.assign(B.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),m&&B.appendChild(m),s.appendChild(B);const C=gt(B,t,void 0,d),y=setInterval(()=>{a.closed&&qe(o)},400);a.addEventListener("pagehide",()=>qe(o)),G.set(o,{id:o,ctrl:C,cardIndex:e,label:n,closePollId:y,stopThemeSync:r,close:()=>{a.closed||a.close()},setTitle:O=>{l.title=O,i.textContent=O,i.style.display="block"}})}else{const l=Ko({title:n,onClose:()=>qe(o),anchor:f});l.contentWrap.style.flexDirection="column",rn(l,n,t.wafer.metadata??void 0);const r=gt(l.contentWrap,t,void 0,d);G.set(o,{id:o,ctrl:r,cardIndex:e,label:n,closePollId:null,close:()=>l.close(),setTitle:i=>{const s=l.box.querySelector("[data-wmap-window-title]");s&&(s.textContent=i,s.title=i)}})}S[e]?.destroy(),S[e]=null,bo(e,a!==null),ho(e)}function gt(e,t,n,o){const d=t.viewOptions?{...c,...t.viewOptions}:c,a=o?{...d,...o}:d,r={...n!==void 0?{...a,plotMode:"value",activeTest:n}:a,showLegend:!0,legendPosition:be},i=Dn(e,t,{viewOptions:r,showTooltip:!0,padding:A,statsSummary:t.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,onClick:t.onClick,onSelect:t.onSelect,showExpandButton:!1,showIdentity:!1});return i.setViewControlsVisible(!0),i.setSummaryVisible(!0),i.setExpandVisible(!1),i}function qe(e){const t=G.get(e);if(!t||(G.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.(),t.ctrl.destroy(),t.cardIndex===null))return;const n=t.cardIndex,o=R[n];if(!o)return;const{card:d,ctrl:a,canvasWrapper:l,expandBtn:r}=mt(o,n,R.length);le[n]?.parentElement?.replaceWith(d),S[n]=a,le[n]=l,re[n]=r}function yo(e){const t=G.get(e);t&&(t.close(),qe(e))}function wo(){for(const e of G.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function vo(){const e=[...I.querySelectorAll("canvas")];if(!e.length)return;const t=e.length,n=Math.ceil(Math.sqrt(t)),o=Math.ceil(t/n),d=e[0].width,a=e[0].height,l=8,r=(f.ownerDocument.defaultView??window).devicePixelRatio||1,i=Math.round(26*r),s=Math.round(12*r),u=f.ownerDocument.createElement("canvas");u.width=n*d+(n-1)*l,u.height=o*(a+i)+(o-1)*l;const m=u.getContext("2d"),k=Ao(I);m.fillStyle=k.background,m.fillRect(0,0,u.width,u.height),e.forEach((B,C)=>{const y=C%n,O=Math.floor(C/n),N=y*(d+l),X=O*(a+i+l),ht=B.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";m.fillStyle=k.surface,m.fillRect(N,X,d,i),m.fillStyle=k.text,m.font=`700 ${s}px system-ui, sans-serif`,m.textAlign="left",m.textBaseline="middle",m.fillText(ht,N+Math.round(10*r),X+i/2,d-Math.round(20*r)),m.drawImage(B,N,X+i)}),u.toBlob(B=>{if(!B)return;if(p.downloadFilename!=null){wn(B,p.downloadFilename,p.onSaveImage);return}const C=S.find(y=>y!=null)?.getExportTitle();wn(B,["gallery",C].filter(Boolean).join(" "),Pe.onSaveImage)})}return{setItems(e){v=e.map(n=>typeof n=="function"?null:n);const t=c.plotMode;if(he.has(t))if(e.some(o=>typeof o=="function"))Y(e);else{const o=pt(t);c={...c,...o},Y(Le(t))}else Y(e)},setOptions(e){T(e,{fireCallback:!1})},getOptions(){return kn(c)},setFindingsNotice(e){Rt=e,z()},setColumns(e){ln(e)},getBinColors(){return c.binColors??ue()},setLotStatsSummary(e){V=e,Be(),b&&z(),ae()},openUserGuide:Zt,destroy(){ve++,ce?.cancel(),ce=null,De=null;for(const e of[...G.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();G.clear();for(const e of S)e&&e.destroy();S=[],Se()?.remove(),dn.disconnect(),ge&&((f.ownerDocument.defaultView??window).cancelAnimationFrame(ge),ge=0),f.ownerDocument.removeEventListener("click",He,!0),window.removeEventListener("blur",Lt),Q(),bn(),Te.remove(),U.remove(),b?.remove(),pe?.destroy()}}}
@@ -1 +1 @@
1
- import{buildView as vi,buildHoverText as xi,findTestDef as dt,resolveTestNumber as zt,buildMapTitle as Ci}from"../renderer/buildView.js";import{drawMapCanvas as wi,BIN_LEGEND_W as Fn,BIN_LEGEND_W_COMPACT as Si,BIN_LEGEND_ADAPT_COMPACT as Mi,BIN_LEGEND_ADAPT_FLOATING as Ei}from"./toCanvas.js";import{buildWaferMap as Di,getTestPassStatus as Bi,isParametricTest as Yt}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as ki}from"../stats/analyzeWaferMap.js";import{SHADOW as Li,LEADING as An,wireControlHover as Hn,SPACE as F,EDGE_GUTTER as Ti,RADIUS as Vn,FONT as ct,CLR as v,applyOverlayZ as Pi,getTooltip as zn,hideTooltip as ft,positionTooltip as Yn,createToolbarHelpers as Oi,buildModeMenuEl as Ri,openReparentedModal as Ii,openUserGuideWindow as Wi,makePaletteBtn as Fi,makeLogScaleBtn as Ai,makeLegendStyleBtn as Hi,makeOverlaysBtn as Vi,makeOrientationBtn as zi,menuLayerFor as Nn,saveImageBlob as Xn,markMenuTrigger as Ke,wireMenuA11y as jn,wireExpandToggle as Yi,nextFrame as Nt,requestedPassFailDisplay as Ni,overlayMenuRows as Xi,anyOverlayActive as ji,logWmapVersionOnce as _i,buildDataModeEntries as Ki,metadataKeyHasData as $i,metadataModeEntry as Gi}from"./toolbar.js";import{waferDisplayLabel as Ui,waferIdentityLabel as Zi}from"../core/waferLabel.js";import{metadataDisplayValue as Qi}from"../core/metadata.js";import{withExportContext as qi,noticeDownloadFilenameChange as Ji}from"./exportName.js";import{createSummaryPanelEl as Xt,wrapWithSummaryPanel as jt,renderWaferSummaryContent as eo}from"./summaryPanel.js";import{collectWarnings as to,buildWarningsMenuEl as no,severityOf as io}from"./warnings.js";import{ICONS as _n}from"./icons.js";import{createIdentityHeader as oo,collapsedLabel as _t}from"./identityHeader.js";import{getDieKey as Be,hasPosition as Kn,isPositionedDie as so}from"../core/dies.js";import{buildDieListSection as lo}from"./dieList.js";import{buildMaplessSummary as ao}from"./maplessSummary.js";import{resolveBinColors as ro,binColorWarning as co}from"../renderer/binColors.js";import{INPUT_DEFAULT_PASS_BINS as fo}from"../core/passBins.js";const $n=new Set(["binColorScheme","valueColorScheme","reverseValueScheme","useDefinedBinColors","rotation","flipX","flipY","showDieLabels","showPartialDies","showRingBoundaries","showQuadrantBoundaries","showReticle","showXYIndicator","legendPosition","logScale","colorbarRangeMode","markFailingDies","fallbackFormat"]);export const COLOR_KEYS=["binColorScheme","valueColorScheme","reverseValueScheme","useDefinedBinColors","binColors"];export function classifyChanged(P){const m=P.some(p=>$n.has(p)),b=P.some(p=>!$n.has(p));return m&&b?"mixed":m?"preference":"state"}export function toPublicViewOptions(P){const{metadataValueOrder:m,binColors:b,lotSize:p,...B}=P;return B}export function renderWaferMap(P,m,b={}){return renderWaferMapCard(P,m,b)}export function renderWaferMapCard(P,m,b={}){_i();const p=P.ownerDocument,B=p.defaultView??window,ke=qi(()=>{const e=Qi(V.metadata?.lot);return{lots:e!==void 0?[e]:[],...ee.isLotStack?{stackedWafers:h?.lotSize??!0}:{wafer:Zi({label:ee.label,wafer:V})}}},b.onSaveImage,b.onSaveText);Ji(b.downloadFilename);function Kt(){const e=h.plotMode==="softBin"||h.plotMode==="stackedSoftBins"?G:$,{primary:t,secondary:n}=Ci(h,d.fallbackFormat,e);return[t,ee.isLotStack?"":n].filter(Boolean).join(" ")||"wafer-map"}B.getComputedStyle(P).position==="static"&&(P.style.position="relative");const Gn=P.clientHeight;b.height!=null&&(P.style.height=typeof b.height=="number"?`${b.height}px`:b.height);const pt=m.dataCoverage?m.dataCoverage.unpositionedDies:m.dies.filter(e=>!Kn(e)).length,$e=(m.dataCoverage?m.dataCoverage.totalDies:m.dies.length-pt)===0&&pt>0,Le=p.createElement("div");Object.assign(Le.style,{display:"flex",flexDirection:"column",width:"100%",height:"100%"}),P.appendChild(Le);const ye=p.createElement("div");Object.assign(ye.style,{position:"relative",width:"100%",flex:"1 1 auto",minHeight:"0"});const ce=b.chromeInset??Ti,K=p.createElement("div");Object.assign(K.style,{display:"flex",alignItems:"stretch",gap:F.sm,background:v.canvasBg,paddingBottom:F.lg,paddingTop:ce,paddingLeft:ce,paddingRight:ce,flexShrink:"0",minWidth:"0"}),Le.appendChild(K),Le.appendChild(ye);function Te(){const e=[...K.children].some(t=>t.style.display!=="none");K.style.display=e?"flex":"none"}const w=p.createElement("div");Object.assign(w.style,{position:"relative",width:"100%",height:"100%"});const s=p.createElement("canvas");Object.assign(s.style,{width:"100%",height:"100%",display:"block"}),w.appendChild(s),ye.appendChild(w);let Ge=null;if(pt>0){let n=function(){if(t){const f=lo(e,m.testDefs,{...b.dieList,onSaveText:ke.onSaveText,waferMetadata:V.metadata,metadataFields:pe,ownerDocument:p});if(f)return f}const o=dt(m.testDefs,d.activeTest??0),r=Yt(o)?d.logScale??o?.logScale??!1:!1;return ao(e,m.testDefs,{plotMode:d.plotMode??"hardBin",activeTest:d.activeTest,hbinDefs:$,sbinDefs:G,binColors:h.binColors,valueColorScheme:d.valueColorScheme,reverseValueScheme:d.reverseValueScheme,logScale:r,colorbarRangeMode:d.colorbarRangeMode,valueRangeDies:m.dies})},i=function(o){const r=p.createElement("button");return r.type="button",Hn(r),Object.assign(r.style,{fontSize:ct.body,padding:`${F.xxs} ${F.sm}`,borderRadius:Vn.control,flexShrink:"0",border:`1px solid ${v.menuBorder}`,background:v.menuBg,color:v.text,cursor:"pointer"}),r.textContent=t?"View chart":"View die list",r.addEventListener("click",f=>{f.stopPropagation(),t=!t,r.textContent=t?"View chart":"View die list",o()}),r};const e=m.dies.filter(o=>!Kn(o));let t=!1;if($e){const o=p.createElement("div");Object.assign(o.style,{position:"absolute",inset:"0",background:v.panelBg,padding:F.xl,boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",gap:F.md,zIndex:"1"});const r=p.createElement("div");Object.assign(r.style,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:F.md});const f=p.createElement("span");Object.assign(f.style,{fontSize:ct.body,color:v.label,lineHeight:An.base}),f.textContent="No die position data for this wafer.",r.appendChild(f);const l=p.createElement("div");Object.assign(l.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),r.appendChild(i(()=>l.replaceChildren(n()))),o.appendChild(r),o.appendChild(l),w.appendChild(o),Ge=()=>{t||l.replaceChildren(n())}}else{const o=p.createElement("div");Object.assign(o.style,{position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"3",background:v.panelBg,borderTop:`1px solid ${v.menuBorder}`,fontSize:ct.body,color:v.text,cursor:"pointer",padding:`${F.xs} ${F.md}`,display:"flex",alignItems:"center",justifyContent:"space-between",gap:F.md}),Hn(o,"bare");const r=p.createElement("span");r.textContent=`+${e.length} ${e.length===1?"die":"dies"} without position data`,o.appendChild(r);const f=p.createElement("span");f.textContent="\u25BE",Object.assign(f.style,{fontSize:ct.body,lineHeight:An.none,color:v.label,flexShrink:"0"}),o.appendChild(f),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`${e.length} dies without position data. Click to view.`);let l=null,a=null;Yi(o,c=>{if(f.textContent=c?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(c)),c){l=p.createElement("div");const g=o.getBoundingClientRect().height||28;Object.assign(l.style,{position:"absolute",left:"0",right:"0",bottom:`${g}px`,top:"20%",zIndex:"2",background:v.panelBg,borderTop:`1px solid ${v.menuBorder}`,padding:F.md,boxSizing:"border-box",display:"flex",flexDirection:"column",gap:F.md}),l.addEventListener("click",se=>se.stopPropagation());const y=p.createElement("div");Object.assign(y.style,{display:"flex",justifyContent:"flex-end"}),y.appendChild(i(()=>{a&&a.replaceChildren(n())})),l.appendChild(y),a=p.createElement("div"),Object.assign(a.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),a.appendChild(n()),l.appendChild(a),w.appendChild(l)}else l&&(l.remove(),l=null,a=null)}),w.appendChild(o),Ge=()=>{a&&!t&&a.replaceChildren(n())}}}const{onHover:Ue,onClick:Un,onSelect:fe,onViewOptionsChange:Zn,showTooltip:Qn=!0,showToolbar:Pe=!0,showIdentity:$t=!0,summaryPanel:Oe,showHelpButton:Gt=!1,userGuideExtension:qn,onExpand:Ut,showExpandButton:Zt=!0,zIndex:Jn,insights:ut,warnings:Qt,viewOptions:ei={},...be}=b,Re=ut?.enabled??!1,ti=.4,ni=20,Ze=[...m.passBins??fo],qt=Qt?.display??!0,ii=Pi(Jn);let le=b.statsSummary,ae=[],Jt=!1,Qe=null,en=!1;function gt(){const e=to({result:m,statsSummary:le,extra:Qe?[Qe]:[]}),t=e.length!==ae.length||e.some((n,i)=>n.code!==ae[i]?.code||n.message!==ae[i]?.message);ae=e,(t||!Jt)&&(Jt=!0,Qt?.onWarning?.(e))}gt();let ee=m,V=m.wafer,ve=m.dies,M=new Set,$=m.hbinDefs,G=m.sbinDefs,te=m.testDefs,pe=m.metadataFields,tn=m.reticles?.length?m.reticles:void 0,nn=m.reticleConfig,on=m.view?.dataAxisFlip,ht=m.isLotStack??!1,mt=m.aggrMethod,yt=m.lotSize;const oi=Pe&&Re;let z=null,Q=null,q=null;$t&&(z=oo(_t(V.metadata??{},Ie())??"",V.metadata,{lotStack:Ie(),ownerDocument:p}),w.appendChild(z.metaPanel),z.metaPanel.style.visibility="visible",z.isEmpty()||(Q=sn(z.wrap),K.insertBefore(Q,K.firstChild),Te()));function sn(e){const t=p.createElement("div");return Object.assign(t.style,{display:"flex",alignItems:"center",padding:`${F.sm} ${F.lg}`,flex:"1 1 auto",minWidth:"0",overflow:"hidden",gap:F.sm}),Object.assign(e.style,{flex:"1",minWidth:"0"}),t.appendChild(e),t}function Ie(){return ht?{lotSize:yt??1,aggrMethod:mt}:void 0}function si(){if(!z)return;z.update(_t(V.metadata??{},Ie())??"",V.metadata,Ie());const e=Q?.isConnected??!1,t=!z.isEmpty();!t&&e?(Q.remove(),Q=null):t&&!e&&(Q=sn(z.wrap),Q.style.display="",K.insertBefore(Q,K.firstChild),Te())}const li=[...$??[],...G??[]].some(e=>e.color);let d={plotMode:"hardBin",showDieLabels:!1,showPartialDies:!0,showRingBoundaries:!1,showQuadrantBoundaries:!1,showReticle:!1,showXYIndicator:!1,rotation:0,flipX:!1,flipY:!1,legendPosition:"default",...ei},Y=null,ne=!1,ln=null;function ai(){return Re?Y?Promise.resolve(Y):(ln??=import("./insightsTab.js").then(({createInsightsTab:e})=>(Y=e({getItems:()=>[{wafer:V,dies:ve,hbinDefs:$,sbinDefs:G,testDefs:te,label:Ui({wafer:V},0),passBins:Ze,statsSummary:le}],getBinColors:()=>h.binColors,getRingCount:()=>ee.ringCount??4,onSaveImage:ke.onSaveImage,onSaveText:ke.onSaveText,defaultView:ut?.defaultView,showMetadataStrip:!1,contentInset:ce,backTab:oi?void 0:{label:"Map",onBack:()=>We(!1)},onOpenGuide:Gt&&!Pe?()=>Wt():void 0,focusTest:t=>{E({plotMode:"value",activeTest:t,highlightBin:void 0}),We(!1)},ownerDocument:p}),Object.assign(Y.el.style,{position:"absolute",inset:"0",background:v.canvasBg,overflowY:"auto",paddingTop:"0"}),Y.el.style.display="none",ye.appendChild(Y.el),Y)),ln):Promise.resolve(null)}let an=0;const bt=["wheel","touchstart","pointerdown","keydown"];function ri(e,t){if(t<=0)return;let n=!1;const i=[],o=()=>{n=!0;for(const f of i)B.clearTimeout(f);i.length=0;for(const f of bt)e.removeEventListener(f,o)},r=()=>n||!ne?!0:(e.scrollTop=t,e.scrollTop>=t);if(!r()){for(const f of bt)e.addEventListener(f,o,{passive:!0,once:!0});for(const f of[0,50,150,300,600])i.push(B.setTimeout(()=>{r()},f));i.push(B.setTimeout(()=>{for(const f of bt)e.removeEventListener(f,o)},700))}}function We(e){if(!Re)return;const t=ne;ne=e,Y&&!e&&t&&(an=Y.el.scrollTop),Y&&(Y.el.style.display=e?"flex":"none"),w.style.visibility=e?"hidden":"",A&&(A.style.display=e||$e?"none":"flex"),T&&(T.style.display=e?"none":"flex"),q&&(q.style.display=he?"none":"flex"),ie&&(ie.style.display="flex"),Q&&(Q.style.display=""),Te(),z&&e&&z.collapse(),nt(),H&&(H.innerHTML=e?_n.wafer:_n.analysis,H.ariaLabel=e?"Back to wafer view":"Insights"),e&&ai().then(n=>{!n||!ne||(n.el.style.display="flex",n.render(),ri(n.el,an))})}Re&&ut?.defaultOpen&&queueMicrotask(()=>We(!0));let h,rn,N=null,k=null,vt=[],xt;function dn(e){xt!==e&&(xt=e,x())}let Fe=null,Ct=be.legendOffset??{x:0,y:0},Ae=!1,xe=!1,He={x:0,y:0},wt={x:0,y:0},ue=!1,Ce=!1,X="pan",we={x:0,y:0},qe={x:0,y:0},O={x:0,y:0},R={x:0,y:0},Ve=!1,Se=!1;function St(){const e=d;h=vi(V,ve.filter(so),{plotMode:e.plotMode,binColorScheme:e.binColorScheme,valueColorScheme:e.valueColorScheme,reverseValueScheme:e.reverseValueScheme,useDefinedBinColors:e.useDefinedBinColors,binColors:e.binColors??ro(ve,{passBins:Ze,binColorScheme:e.binColorScheme,hbinDefs:$,sbinDefs:G,useDefinedBinColors:e.useDefinedBinColors}),passBins:Ze,showDieLabels:e.showDieLabels,showPartialDies:e.showPartialDies,showRingBoundaries:e.showRingBoundaries,showQuadrantBoundaries:e.showQuadrantBoundaries,showReticle:e.showReticle,showXYIndicator:e.showXYIndicator,reticles:tn,ringCount:ee.ringCount??4,highlightBin:e.highlightBin,highlightMetadataValue:e.highlightMetadataValue,activeTest:e.activeTest,activeMetadataKey:e.activeMetadataKey,testDefs:te,valueRange:e.valueRange,metadataValueOrder:e.metadataValueOrder,logScale:e.logScale,isLotStack:ht,aggregationMethod:mt??e.aggregationMethod,lotSize:yt??e.lotSize,dataAxisFlip:on,colorbarRangeMode:e.colorbarRangeMode,passFailDisplay:e.passFailDisplay,fallbackFormat:e.fallbackFormat,interactiveTransform:{rotation:e.rotation??0,flipX:e.flipX??!1,flipY:e.flipY??!1}},{hbinDefs:$,sbinDefs:G,metadataFields:pe}),rn=new Map(h.dies.map((n,i)=>[Be(n),i]));const t=e.binColors?null:co(h.binColors,h.plotMode);t?.message!==Qe?.message&&(Qe=t,gt(),en&&Mt())}St();let U=null,Me=null,Je=null,cn=b.findingsNotice,di={},I=null,re=null;function ci(e){const{kind:t,index:n}=e.variable;E(t==="test"?{plotMode:"value",activeTest:n??0,highlightBin:void 0}:t==="softBin"?{plotMode:"softBin",highlightBin:void 0}:{plotMode:"hardBin",highlightBin:void 0});const i=e.highlight;i.kind==="bin"?(Tt(i.dieKeys),E({highlightBin:i.bin})):(i.kind==="region"||i.kind==="dies")&&Tt(i.dieKeys)}function fn(e){eo(e,{wafer:V,dies:ve,yieldSummary:ee.yield,dataCoverage:ee.dataCoverage,hbinDefs:$,sbinDefs:G,testDefs:te,statsSummary:le,warnings:qt?ae:[],passBins:Ze,ringCount:ee.ringCount??4,binColors:h.binColors,plotMode:d.plotMode??"hardBin",metadataShownElsewhere:$t,fallbackFormat:d.fallbackFormat,activeFindingId:Je,findingsFilter:di,findingsNotice:cn,onFindingsFilterChange:ge,onSaveText:ke.onSaveText,metadataFields:pe,dieListOptions:b.dieList,onFindingClick:(t,n)=>{Je===t.id?(Je=null,Tt([]),E({highlightBin:void 0})):(Je=t.id,ci(t)),ge()}})}function ge(){U&&fn(U)}function ze(){I&&fn(I)}if(Oe?.placement){const e=Oe.placement;U=Xt(e,ce,p);const t=w.parentElement,n=w.nextSibling;Me=jt(w,U,e),t?.insertBefore(Me,n),ge()}else if(le){const e=Oe?.defaultOpen??!Pe;I=Xt("right",ce,p),I.style.display=e?"block":"none";const t=w.parentElement,n=w.nextSibling;re=jt(w,I,"right"),t?.insertBefore(re,n),ze()}const W=Qn?zn(p):null;let ie=null,L=null,A=null,T=null,et=null,j=null,pn=null,H=null,oe=null,tt=null;en=!0;function Mt(){if(!oe||!tt)return;const e=ae.length,t=e>0;if(oe.style.display=t?"flex":"none",tt.style.display=t?"":"none",!t)return;const n=io(ae[0]),i=`${e} data ${e===1?"warning":"warnings"}`;oe.style.color=n==="error"?v.errText:v.warnText,oe.ariaLabel=n==="error"?`${i} \u2014 the map may be positionally wrong`:i}let Et=null,un=null,Dt=null,Bt=null,kt=null,Lt=null;function Tt(e){M=new Set(e??[]),fe&&fe(It()),x()}function nt(){if(!j)return;const e=!!(U??I);j.style.display=le&&e&&!ne?"flex":"none";const t=U??I,n=t?t.style.display!=="none":!1;le?.hasNotableFindings&&!n?j.style.color=v.findingIndicator:j.dataset.active||(j.style.color=v.icon)}let gn=null;function hn(e){const t=U??I;t&&(t.style.display=e?"block":"none",j&&gn?.(j,e),nt())}if(Pe){let g=function(D){X=D,i(se,D==="zoom"),i(S,D==="pan"),et&&i(et,D==="select"),s.style.cursor=D==="pan"?"grab":"crosshair"};ie=p.createElement("div"),ie.dataset.wmapToolbar="single",Object.assign(ie.style,{marginLeft:"auto",flexShrink:"0",display:"flex",flexDirection:"row",alignItems:"center",flexWrap:"wrap-reverse",justifyContent:"flex-end",maxWidth:"100%",background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:Vn.control,boxShadow:Li.panel,pointerEvents:"auto"});const e=zn(p),t=Oi(e),{makeBtn:n,setActive:i,makeSep:o,makeMenuRow:r,makeMenuSection:f,closeOpenMenu:l,getOpenMenu:a,setOpenMenu:c}=t;gn=i,Et=l,un=a,p.addEventListener("click",l,!0),A=p.createElement("div"),Object.assign(A.style,{display:$e?"none":"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),ie.appendChild(A);const y=n("download","Download PNG",ui);A.appendChild(y),A.appendChild(o());const se=n("zoomMode","Zoom (drag to zoom region)",()=>g("zoom")),De=n("zoomIn","Zoom in",()=>Ee(s.clientWidth/2,s.clientHeight/2,1.2)),J=n("zoomOut","Zoom out",()=>Ee(s.clientWidth/2,s.clientHeight/2,1/1.2)),de=n("reset","Reset zoom (double-click)",()=>ot());A.appendChild(se),A.appendChild(De),A.appendChild(J),A.appendChild(de),A.appendChild(o());const S=n("pan","Pan (drag to move)",()=>g("pan"));A.appendChild(S),et=n("boxSelect","Select (drag to select dies)",()=>g("select")),A.appendChild(et),i(S,!0);{let D=function(u){return u.plotMode!==(d.plotMode??"hardBin")?!1:u.plotMode==="value"?(d.activeTest??0)===(u.activeTest??0):u.plotMode==="metadata"?d.activeMetadataKey===u.activeMetadataKey:!0},Ft=function(u,C){u.activeTest!==void 0?E({plotMode:u.plotMode,activeTest:u.activeTest,activeMetadataKey:void 0,logScale:u.logScale}):u.activeMetadataKey!==void 0?E({plotMode:u.plotMode,activeTest:void 0,activeMetadataKey:u.activeMetadataKey,passFailDisplay:"off"}):E({plotMode:u.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),C.remove(),c(null),Ke(Z,!1)};L=p.createElement("div"),Object.assign(L.style,{display:"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),ie.appendChild(L),T=p.createElement("div"),Object.assign(T.style,{display:"flex",alignItems:"center",gap:"0"}),L.appendChild(T),T.appendChild(o());const st=()=>{const u=a();u&&(u.remove(),c(null)),Ke(Z,!1)},Z=n("mode","Plot mode",()=>{if(a()){st();return}const u=ve,C=h.testDefs,{testEntries:rt,binEntries:me,stackedEntries:Xe}=Ki(u,C,{includeStacked:h.isLotStack}),Vt=(pe??[]).filter(_e=>$i(u,_e.key)).map(Gi),je=Ri(Z.getBoundingClientRect(),rt,me,Xe,D,Ft,{makeMenuRow:r,makeMenuSection:f},d.plotMode??"hardBin",Z.ownerDocument.defaultView??window,Vt);Nn(Z).appendChild(je),c(je),Ke(Z,!0),jn(je,Z,st)});Ke(Z,!1);const{btn:lt,sync:Ne}=Fi(t,()=>({...d,plotMode:d.plotMode??"hardBin"}),()=>li,E);Bt=Ne,Bt();const At=Vi(t,()=>{const u=!!h.hasReticle,C=(d.plotMode??"hardBin")==="value",{testNumber:rt}=zt(d.activeTest??0,h.testDefs),me=dt(h.testDefs,rt),Xe=C&&me!==void 0&&!Yt(me),Vt=C&&!Xe&&(me?.limitLow!==void 0||me?.limitHigh!==void 0),je=C&&!Xe&&h.dies.some(_e=>Bi(_e,rt,me)!==void 0);return Xi(d,u,{functionalActive:Xe,hasLimits:Vt,hasRecorded:je,binMode:(d.plotMode??"hardBin")==="hardBin"||(d.plotMode??"hardBin")==="softBin"},_e=>E(_e))},()=>ji(d)),{btn:Ht,sync:gi}=Hi(t,()=>d,u=>E({legendPosition:u}));Dt=gi,Dt();const Wn=()=>{const{testNumber:u}=zt(d.activeTest??0,te),C=dt(te,u);return C!==void 0&&!Yt(C)},{btn:hi,sync:mi}=Ai(t,()=>({...d,functionalActive:Wn()}),u=>E(u));kt=mi,kt();const yi=()=>{const{testNumber:u}=zt(d.activeTest??0,te),C=dt(te,u);return C!==void 0&&(C.limitLow!==void 0||C.limitHigh!==void 0)},at=n("specRange","Colorbar range: spec limits",()=>{const u=d.colorbarRangeMode==="data"?"spec":"data";E({colorbarRangeMode:u})});Lt=()=>{const u=d.plotMode==="value"&&yi()&&Ni(d)==="off"&&!Wn();at.style.display=u?"":"none";const C=(d.colorbarRangeMode??"spec")==="spec";i(at,C),at.ariaLabel=C?"Colorbar range: spec limits (click for data range)":"Colorbar range: data range (click for spec limits)"},Lt();const bi=zi(t,()=>d,u=>E(u));T.appendChild(Z),T.appendChild(lt),T.appendChild(hi),T.appendChild(at),$e||(T.appendChild(o()),T.appendChild(At),T.appendChild(o()),T.appendChild(Ht),T.appendChild(o()),T.appendChild(bi)),le&&(j=n("findings","Summary panel",()=>{const u=U??I;u&&hn(u.style.display==="none")}),L.appendChild(o()),L.appendChild(j),I?.style.display!=="none"&&i(j,!0),nt()),qt&&(tt=o(),oe=n("warning","Data warnings",()=>{const u=a();if(l(new MouseEvent("click")),u)return;const C=no(oe.getBoundingClientRect(),ae,B);Nn(ye).appendChild(C),c(C),jn(C,oe,()=>l(new MouseEvent("click")))}),Ke(oe,!1),L.appendChild(tt),L.appendChild(oe),Mt()),Re&&(L.appendChild(o()),H=n("analysis","Insights",()=>{We(!ne),i(H,ne)}),H.dataset.wmapInsightsBtn="1",L.appendChild(H)),Zt&&(L.appendChild(o()),q=n("expand","Expand (E)",Ut??mn),L.appendChild(q)),Gt&&(L.appendChild(o()),pn=n("help","User guide",()=>Wt()),L.appendChild(pn))}K.appendChild(ie),Te()}let he=null;function mn(){he&&(he.close(),he=null);const e=ye;e.style.flex="1",e.style.minWidth="0",e.style.minHeight="0";const t=_t(V.metadata??{},Ie()),n=K.childElementCount>0?[K,e]:[e],i=Ii(n,{ownerDocument:p,boxSize:ne?{width:"min(96vw, 1600px)",height:"min(92vh, 1000px)"}:void 0,onClosed:()=>{he=null,q&&(q.style.display="flex"),ne||s.focus({preventScroll:!0})}});i&&(i.box.setAttribute("aria-label",t??"Expanded wafer map"),n.length>1&&(i.contentWrap.style.flexDirection="column"),he=i,q&&(q.style.display="none"))}function yn(e){("binColorScheme"in e||"useDefinedBinColors"in e)&&!("binColors"in e)&&d.binColors!==void 0&&(e={...e,binColors:void 0});const t=d.plotMode;d={...d,...e},e.plotMode!==void 0&&e.plotMode,Object.keys(e).every(r=>r==="legendPosition"||r==="showLegend"||r==="markFailingDies")||St(),Dt?.(),Bt?.(),kt?.(),Lt?.(),x();const i=e.plotMode!==void 0&&e.plotMode!==t,o=COLOR_KEYS.some(r=>r in e);(o||i)&&(ge(),ze()),(o||i||e.activeTest!==void 0||e.logScale!==void 0||e.colorbarRangeMode!==void 0)&&Ge?.()}function E(e){yn(e);const t=Object.keys(e);Zn?.(d,t,classifyChanged(t))}let Pt=!1;function Ot(){Pt||(Pt=!0,Nt(()=>{Pt=!1,x()},B))}function x(){const e=k??void 0,t=h.dies[0],n=t?{x:t.width,y:t.height}:be.diePitchMm,i=Math.floor(s.clientWidth||s.width),o=!!($?.length||G?.length||h.dies.some(y=>y.hbin!=null||y.sbin!=null)),r=d.legendPosition??"default",f=d.showLegend??!0,l=r==="default"||r==="compact",a=(be.colorbarWidth??16)+28,c=o&&l?r!=="default"?Math.max(Fn,a):i<Ei?0:i<Mi?Math.max(Si,a):Math.max(Fn,a):void 0,g=wi(s,h,{...be,minRightReserve:f?c:0,showColorbar:f&&(be.showColorbar??!0),markFailingDies:d.markFailingDies??!1,legendPosition:r,legendOffset:Ct,diePitchMm:n,fallbackFormat:d.fallbackFormat,showAxes:be.showAxes??k!==null,viewport:e,activeBin:d.plotMode==="metadata"?d.highlightMetadataValue:d.highlightBin,hoverBin:xt,hbinDefs:$,sbinDefs:G,metadataFields:pe});vt=g.binLegendRows,Fe=g.legendBox??null,k===null&&(N=g.viewport),M.size>0&&fi(),Ce&&pi()}function fi(){const e=_();if(!e)return;const t=s.getContext("2d"),n=h.hoverPoints,i=h.rectangles[0],o=i?i.width/2*e.ppm:e.ppm*.5,r=i?i.height/2*e.ppm:e.ppm*.5,f=Math.max(1,Math.min(3,o*.08)),l=o-f,a=r-f,c=[];for(const g of M){const y=rn.get(g);y!==void 0&&c.push({sx:e.originX+n[y].x*e.ppm,sy:e.originY-n[y].y*e.ppm})}if(c.length){t.save(),t.setLineDash([]),t.fillStyle="rgba(0,0,0,0.12)",t.beginPath();for(const{sx:g,sy:y}of c)t.rect(g-l,y-a,l*2,a*2);t.fill(),t.strokeStyle="rgba(255,255,255,0.9)",t.lineWidth=3,t.beginPath();for(const{sx:g,sy:y}of c)t.rect(g-l,y-a,l*2,a*2);t.stroke(),t.strokeStyle="rgba(0,0,0,0.9)",t.lineWidth=1.5,t.beginPath();for(const{sx:g,sy:y}of c)t.rect(g-l,y-a,l*2,a*2);t.stroke(),t.restore()}}function pi(){const e=s.getContext("2d"),t=Math.min(O.x,R.x),n=Math.min(O.y,R.y),i=Math.abs(R.x-O.x),o=Math.abs(R.y-O.y);e.save(),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(t,n,i,o),e.setLineDash([5,3]),e.strokeStyle="rgba(255,255,255,0.9)",e.lineWidth=3,e.strokeRect(t,n,i,o),e.strokeStyle="rgba(0,0,0,0.9)",e.lineWidth=1.5,e.strokeRect(t,n,i,o),e.restore()}function ui(){s.toBlob(e=>{e&&(b.downloadFilename!=null?Xn(e,b.downloadFilename,b.onSaveImage):Xn(e,Kt(),ke.onSaveImage))})}function bn(e){return N?Math.max(N.ppm*ti,Math.min(N.ppm*ni,e)):e}function Ee(e,t,n){const i=k??N;if(!i)return;const o=bn(i.ppm*n),r=o/i.ppm,f=e-(e-i.originX)*r,l=t-(t-i.originY)*r,a=(N?.snapDist??1)/(o/(N?.ppm??o));k={originX:f,originY:l,ppm:o,snapDist:a},x()}function _(){return k??N}function vn(e){if(e.ctrlKey||e.metaKey){e.preventDefault();const t=s.getBoundingClientRect(),n=e.deltaY<0?1.12:1/1.12;Ee(e.clientX-t.left,e.clientY-t.top,n)}else if(k!==null){e.preventDefault();const t=_(),n=k.snapDist;k={originX:t.originX-e.deltaX,originY:t.originY-e.deltaY,ppm:t.ppm,snapDist:n},x()}}function xn(e,t,n){return e>=n.x&&e<n.x+n.w&&t>=n.y&&t<n.y+n.h}function Cn(e){if(e.button!==0||!_())return;s.focus({preventScroll:!0}),s.setPointerCapture(e.pointerId);const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;if(Fe&&d.legendPosition==="floating"&&xn(n,i,Fe)){xe=!0,He={x:n,y:i},wt={...Ct};return}if(Ve&&X!=="pan"){Se=!0,ue=!0,we={x:n,y:i},qe={x:_().originX,y:_().originY},s.style.cursor="grabbing";return}if(X==="zoom"||X==="select"){Ce=!0,O=R={x:n,y:i};return}ue=!0,we={x:n,y:i},qe={x:_().originX,y:_().originY},s.style.cursor="grabbing"}function wn(e){const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;if(Ce){R={x:n,y:i},Ot();return}if(xe){const g=n-He.x,y=i-He.y;g*g+y*y>16&&(xe=!1,Ae=!0,s.style.cursor="grabbing")}if(Ae){Ct={x:wt.x+(n-He.x),y:wt.y+(i-He.y)},Ot();return}if(ue){const g=_(),y=k?.snapDist??N?.snapDist??1;k={originX:qe.x+(n-we.x),originY:qe.y+(i-we.y),ppm:g.ppm,snapDist:y},Ot();return}const o=_();if(!o)return;const r=(n-o.originX)/o.ppm,f=(o.originY-i)/o.ppm,a=Dn(r,f,o.snapDist)?.die??null,c=vt.find(g=>n>=g.x&&n<g.x+g.w&&i>=g.y&&i<g.y+g.h);if(dn(c?c.bin:void 0),c){s.style.cursor="pointer",W&&(W.textContent=c.label??`Bin ${c.bin}`,W.style.display="block",Yn(W,s,e.clientX,e.clientY)),Ue?.(null,e);return}X==="pan"&&(s.style.cursor=a?"crosshair":"grab"),W&&(a?(W.innerHTML=xi(a,h.plotMode,{testDefs:te,hbinDefs:$,sbinDefs:G,fallbackFormat:d.fallbackFormat,aggrMethod:h.aggrMethod,lotSize:h.lotSize,metadataFields:pe,activeTest:h.activeTest,reticleConfig:nn}),W.style.display="block",Yn(W,s,e.clientX,e.clientY)):W.style.display="none"),Ue?.(a,e)}function Sn(e){const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top,o=e.ctrlKey||e.metaKey;if(W&&(n<0||i<0||n>t.width||i>t.height)&&(W.style.display="none"),Ce){Ce=!1,R={x:n,y:i};const l=n-O.x,a=i-O.y,c=_();if(X==="zoom"){if(l*l+a*a<25)Ee(n,i,2);else if(c){const g=Math.min(O.x,R.x),y=Math.max(O.x,R.x),se=Math.min(O.y,R.y),De=Math.max(O.y,R.y),J=y-g,de=De-se;if(J>4&&de>4){const S=s.clientWidth,D=s.clientHeight,Ft=S/J,st=D/de,Z=Math.min(Ft,st),lt=bn(c.ppm*Z),Ne=lt/c.ppm,At=(g+y)/2,Ht=(se+De)/2;k={originX:S/2-(At-c.originX)*Ne,originY:D/2-(Ht-c.originY)*Ne,ppm:lt,snapDist:c.snapDist/Ne}}}x(),s.style.cursor="crosshair";return}if(l*l+a*a<25)Rt(n,i,o,e);else if(c){const g=(Math.min(O.x,R.x)-c.originX)/c.ppm,y=(Math.max(O.x,R.x)-c.originX)/c.ppm,se=(c.originY-Math.max(O.y,R.y))/c.ppm,De=(c.originY-Math.min(O.y,R.y))/c.ppm,J=h.hoverPoints,de=[];for(let S=0;S<J.length;S++)if(J[S].x>=g&&J[S].x<=y&&J[S].y>=se&&J[S].y<=De){const D=h.dies[S];D&&de.push(D)}if(o)for(const S of de){const D=Be(S);M.has(D)?M.delete(D):M.add(D)}else M=new Set(de.map(S=>Be(S)));fe?.(It())}x(),s.style.cursor="crosshair";return}if(xe){xe=!1,Rt(n,i,o,e);return}if(Ae){Ae=!1,s.style.cursor="grab";return}if(!ue)return;if(ue=!1,Se){Se=!1,s.style.cursor=Ve||X==="pan"?"grab":"crosshair";return}s.style.cursor=X==="pan"?"grab":"crosshair";const r=n-we.x,f=i-we.y;r*r+f*f<25&&Rt(n,i,o,e)}function Rt(e,t,n,i){for(const l of vt)if(e>=l.x&&e<l.x+l.w&&t>=l.y&&t<l.y+l.h){if(typeof l.bin=="number"){const a=d.highlightBin===l.bin?void 0:l.bin;E({highlightBin:a})}else{const a=d.highlightMetadataValue===l.bin?void 0:l.bin;E({highlightMetadataValue:a})}return}if(Fe&&xn(e,t,Fe))return;const o=_();if(!o)return;const f=Dn((e-o.originX)/o.ppm,(o.originY-t)/o.ppm,o.snapDist)?.die??null;if(f){Un?.(f,i);const l=Be(f);n?M.has(l)?M.delete(l):M.add(l):M=new Set([l]),fe?.(It()),x()}else n||(M=new Set,fe?.([]),x())}function It(){const e=[],t=h.hoverPoints;for(let n=0;n<t.length;n++){const i=h.dies[n];i&&M.has(Be(i))&&e.push(i)}return e}function Mn(){dn(void 0),W&&ft(p),Ue?.(null,new MouseEvent("mouseleave")),s.style.cursor=X==="pan"?"grab":"crosshair"}function En(){ue=!1,Se=!1,Ce=!1,xe=!1,Ae=!1,W&&ft(p),Ue?.(null,new MouseEvent("mouseleave")),s.style.cursor=X==="pan"?"grab":"crosshair",x()}function Dn(e,t,n){const i=h.hoverPoints,o=h.rectangles;for(let a=0;a<o.length;a++){const c=o[a];if(Math.abs(e-c.x)<=c.width/2&&Math.abs(t-c.y)<=c.height/2){const g=h.dies[a];return g?{die:g,index:a}:null}}let r=null,f=-1,l=n*n;for(let a=0;a<i.length;a++){const c=i[a].x-e,g=i[a].y-t,y=c*c+g*g;y<l&&(l=y,r=h.dies[a]??null,f=a)}return r?{die:r,index:f}:null}const Bn=new B.ResizeObserver(()=>{N=null,k=null,x()});Bn.observe(s),b.height==null&&Gn<=0&&Nt(()=>Nt(()=>{P.clientHeight>0||console.warn("[wafermap] The map container has zero height, so the map cannot render. renderWaferMap fills its container \u2014 give the container a resolved height: an explicit CSS `height` (e.g. 600px), a height-resolved flex/grid parent, or `position:absolute; inset:0`. Alternatively pass `{ height: 600 }` in the render options and the library will size it for you.")}));let Ye=B.matchMedia(`(resolution: ${B.devicePixelRatio}dppx)`);const it=()=>{Ye.removeEventListener("change",it),Ye=B.matchMedia(`(resolution: ${B.devicePixelRatio}dppx)`),Ye.addEventListener("change",it),x()};Ye.addEventListener("change",it);const kn=B.matchMedia("(prefers-color-scheme: dark)"),Ln=()=>x();kn.addEventListener("change",Ln);const Tn=()=>{W&&ft(p)};B.addEventListener("blur",Tn);function Pn(e){if(e.key==="Escape"&&M.size>0&&(M=new Set,fe?.([]),x()),(e.key==="e"||e.key==="E")&&Zt&&(e.stopPropagation(),(Ut??mn)()),(e.ctrlKey||e.metaKey)&&(e.key==="="||e.key==="+"?(e.preventDefault(),Ee(s.clientWidth/2,s.clientHeight/2,1.2)):e.key==="-"?(e.preventDefault(),Ee(s.clientWidth/2,s.clientHeight/2,1/1.2)):e.key==="0"&&(e.preventDefault(),ot())),!e.ctrlKey&&!e.metaKey&&!e.shiftKey){const n=_();if(n){const i=k?.snapDist??N?.snapDist??1;let o=0,r=0;e.key==="ArrowLeft"&&(o=20,e.preventDefault()),e.key==="ArrowRight"&&(o=-20,e.preventDefault()),e.key==="ArrowUp"&&(r=20,e.preventDefault()),e.key==="ArrowDown"&&(r=-20,e.preventDefault()),(o||r)&&(k={originX:n.originX+o,originY:n.originY+r,ppm:n.ppm,snapDist:i},x())}e.key===" "&&!Ve&&(e.preventDefault(),Ve=!0,X!=="pan"&&(s.style.cursor="grab"))}}function On(e){e.key===" "&&(Ve=!1,Se&&(ue=!1,Se=!1),s.style.cursor=X==="pan"?"grab":"crosshair")}s.style.cursor="grab",s.setAttribute("tabindex","0"),s.addEventListener("wheel",vn,{passive:!1}),s.addEventListener("pointerdown",Cn),s.addEventListener("pointermove",wn),s.addEventListener("pointerup",Sn),s.addEventListener("pointerleave",Mn),s.addEventListener("pointercancel",En);const Rn=()=>ot();s.addEventListener("dblclick",Rn),s.addEventListener("keydown",Pn),s.addEventListener("keyup",On);const In=e=>{e.stopPropagation()};s.addEventListener("click",In),s.clientWidth,x(),Ge?.();function ot(){N=null,k=null,x()}function Wt(){import("./userGuideHtml.js").then(e=>Wi({buildWaferMap:Di,renderWaferMap,renderWaferGallery:void 0,analyzeWaferMap:ki},e.USER_GUIDE_HTML,qn,P))}return Te(),{setResult(e){ee=e,V=e.wafer,ve=e.dies,$=e.hbinDefs,G=e.sbinDefs,te=e.testDefs,pe=e.metadataFields,tn=e.reticles?.length?e.reticles:void 0,nn=e.reticleConfig,on=e.view?.dataAxisFlip,ht=e.isLotStack,mt=e.aggrMethod,yt=e.lotSize,si(),St(),x(),U&&ge()},setOptions(e){yn(e)},getOptions(){return{...d}},resetZoom:ot,setSelection(e){M=new Set(e.map(t=>Be(t))),x()},clearSelection(){M=new Set,fe?.([]),x()},setFindingsNotice(e){cn=e,U?ge():I&&ze()},setStatsSummary(e){if(le=e,gt(),Mt(),U)ge();else if(I)ze();else if(e&&!Oe?.placement){const t=Oe?.defaultOpen??!Pe;I=Xt("right",ce,p),I.style.display=t?"block":"none";const n=w.parentElement,i=w.nextSibling;re=jt(w,I,"right"),n?.insertBefore(re,i),ze()}nt()},closeSummaryPanel(){hn(!1)},getExportTitle(){return Kt()},getBinColors(){return h.binColors},setSummaryVisible(e){j&&(j.style.display=e?"flex":"none")},setViewControlsVisible(e){L&&(L.style.display=e?"flex":"none")},setExpandVisible(e){q&&(q.style.display=e?"flex":"none")},openUserGuide:Wt,setInsightsOpen(e){We(e),H&&(e?(H.dataset.active="1",H.style.background=v.bgActive,H.style.color=v.iconActive):(delete H.dataset.active,H.style.background="transparent",H.style.color=v.icon))},destroy(){he?.close(),un?.()?.remove(),Et&&p.removeEventListener("click",Et,!0),s.removeEventListener("wheel",vn),s.removeEventListener("pointerdown",Cn),s.removeEventListener("pointermove",wn),s.removeEventListener("pointerup",Sn),s.removeEventListener("pointerleave",Mn),s.removeEventListener("pointercancel",En),s.removeEventListener("dblclick",Rn),s.removeEventListener("keydown",Pn),s.removeEventListener("keyup",On),s.removeEventListener("click",In),Bn.disconnect(),Ye.removeEventListener("change",it),kn.removeEventListener("change",Ln),B.removeEventListener("blur",Tn),ii(),W&&ft(p),ie?.remove(),Me&&(Me.parentElement?.insertBefore(w,Me),Me.remove()),re&&(re.parentElement?.insertBefore(w,re),re.remove()),w.remove(),s.style.cursor="",Y?.destroy(),z?.destroy(),Le.remove()}}}
1
+ import{buildView as xi,buildHoverText as Ci,findTestDef as ct,resolveTestNumber as Yt,buildMapTitle as wi}from"../renderer/buildView.js";import{drawMapCanvas as Si,BIN_LEGEND_W as An,BIN_LEGEND_W_COMPACT as Mi,BIN_LEGEND_ADAPT_COMPACT as Ei,BIN_LEGEND_ADAPT_FLOATING as Di}from"./toCanvas.js";import{buildWaferMap as Bi,getTestPassStatus as ki,isParametricTest as Nt}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Li}from"../stats/analyzeWaferMap.js";import{SHADOW as Ti,LEADING as Hn,wireControlHover as Vn,SPACE as F,EDGE_GUTTER as Pi,RADIUS as zn,FONT as ft,CLR as v,applyOverlayZ as Oi,getTooltip as Yn,hideTooltip as pt,positionTooltip as Nn,createToolbarHelpers as Ri,buildModeMenuEl as Ii,openReparentedModal as Wi,openUserGuideWindow as Fi,makePaletteBtn as Ai,makeLogScaleBtn as Hi,makeLegendStyleBtn as Vi,makeOverlaysBtn as zi,makeOrientationBtn as Yi,menuLayerFor as Xn,saveImageBlob as jn,markMenuTrigger as $e,wireMenuA11y as _n,wireExpandToggle as Ni,nextFrame as Xt,requestedPassFailDisplay as Xi,overlayMenuRows as ji,anyOverlayActive as _i,logWmapVersionOnce as Ki,buildDataModeEntries as $i,metadataKeyHasData as Gi,metadataModeEntry as Ui}from"./toolbar.js";import{waferDisplayLabel as Zi,waferIdentityLabel as Qi}from"../core/waferLabel.js";import{metadataDisplayValue as qi}from"../core/metadata.js";import{withExportContext as Ji,noticeDownloadFilenameChange as eo}from"./exportName.js";import{createSummaryPanelEl as jt,wrapWithSummaryPanel as _t,renderWaferSummaryContentSteps as to}from"./summaryPanel.js";import{runChunked as no}from"./chunked.js";import{collectWarnings as io,buildWarningsMenuEl as oo,severityOf as so}from"./warnings.js";import{ICONS as Kn}from"./icons.js";import{createIdentityHeader as lo,collapsedLabel as Kt}from"./identityHeader.js";import{getDieKey as Be,hasPosition as $n,isPositionedDie as ao}from"../core/dies.js";import{buildDieListSection as ro}from"./dieList.js";import{buildMaplessSummary as co}from"./maplessSummary.js";import{resolveBinColors as fo,binColorWarning as po}from"../renderer/binColors.js";import{INPUT_DEFAULT_PASS_BINS as uo}from"../core/passBins.js";const Gn=new Set(["binColorScheme","valueColorScheme","reverseValueScheme","useDefinedBinColors","rotation","flipX","flipY","showDieLabels","showPartialDies","showRingBoundaries","showQuadrantBoundaries","showReticle","showXYIndicator","legendPosition","logScale","colorbarRangeMode","markFailingDies","fallbackFormat"]);export const COLOR_KEYS=["binColorScheme","valueColorScheme","reverseValueScheme","useDefinedBinColors","binColors"];export function classifyChanged(P){const m=P.some(p=>Gn.has(p)),b=P.some(p=>!Gn.has(p));return m&&b?"mixed":m?"preference":"state"}export function toPublicViewOptions(P){const{metadataValueOrder:m,binColors:b,lotSize:p,...B}=P;return B}export function renderWaferMap(P,m,b={}){return renderWaferMapCard(P,m,b)}export function renderWaferMapCard(P,m,b={}){Ki();const p=P.ownerDocument,B=p.defaultView??window,ke=Ji(()=>{const e=qi(V.metadata?.lot);return{lots:e!==void 0?[e]:[],...ee.isLotStack?{stackedWafers:h?.lotSize??!0}:{wafer:Qi({label:ee.label,wafer:V})}}},b.onSaveImage,b.onSaveText);eo(b.downloadFilename);function $t(){const e=h.plotMode==="softBin"||h.plotMode==="stackedSoftBins"?G:$,{primary:t,secondary:n}=wi(h,d.fallbackFormat,e);return[t,ee.isLotStack?"":n].filter(Boolean).join(" ")||"wafer-map"}B.getComputedStyle(P).position==="static"&&(P.style.position="relative");const Un=P.clientHeight;b.height!=null&&(P.style.height=typeof b.height=="number"?`${b.height}px`:b.height);const ut=m.dataCoverage?m.dataCoverage.unpositionedDies:m.dies.filter(e=>!$n(e)).length,Ge=(m.dataCoverage?m.dataCoverage.totalDies:m.dies.length-ut)===0&&ut>0,Le=p.createElement("div");Object.assign(Le.style,{display:"flex",flexDirection:"column",width:"100%",height:"100%"}),P.appendChild(Le);const ye=p.createElement("div");Object.assign(ye.style,{position:"relative",width:"100%",flex:"1 1 auto",minHeight:"0"});const ce=b.chromeInset??Pi,K=p.createElement("div");Object.assign(K.style,{display:"flex",alignItems:"stretch",gap:F.sm,background:v.canvasBg,paddingBottom:F.lg,paddingTop:ce,paddingLeft:ce,paddingRight:ce,flexShrink:"0",minWidth:"0"}),Le.appendChild(K),Le.appendChild(ye);function Te(){const e=[...K.children].some(t=>t.style.display!=="none");K.style.display=e?"flex":"none"}const w=p.createElement("div");Object.assign(w.style,{position:"relative",width:"100%",height:"100%"});const s=p.createElement("canvas");Object.assign(s.style,{width:"100%",height:"100%",display:"block"}),w.appendChild(s),ye.appendChild(w);let Ue=null;if(ut>0){let n=function(){if(t){const f=ro(e,m.testDefs,{...b.dieList,onSaveText:ke.onSaveText,waferMetadata:V.metadata,metadataFields:pe,ownerDocument:p});if(f)return f}const o=ct(m.testDefs,d.activeTest??0),r=Nt(o)?d.logScale??o?.logScale??!1:!1;return co(e,m.testDefs,{plotMode:d.plotMode??"hardBin",activeTest:d.activeTest,hbinDefs:$,sbinDefs:G,binColors:h.binColors,valueColorScheme:d.valueColorScheme,reverseValueScheme:d.reverseValueScheme,logScale:r,colorbarRangeMode:d.colorbarRangeMode,valueRangeDies:m.dies})},i=function(o){const r=p.createElement("button");return r.type="button",Vn(r),Object.assign(r.style,{fontSize:ft.body,padding:`${F.xxs} ${F.sm}`,borderRadius:zn.control,flexShrink:"0",border:`1px solid ${v.menuBorder}`,background:v.menuBg,color:v.text,cursor:"pointer"}),r.textContent=t?"View chart":"View die list",r.addEventListener("click",f=>{f.stopPropagation(),t=!t,r.textContent=t?"View chart":"View die list",o()}),r};const e=m.dies.filter(o=>!$n(o));let t=!1;if(Ge){const o=p.createElement("div");Object.assign(o.style,{position:"absolute",inset:"0",background:v.panelBg,padding:F.xl,boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",gap:F.md,zIndex:"1"});const r=p.createElement("div");Object.assign(r.style,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:F.md});const f=p.createElement("span");Object.assign(f.style,{fontSize:ft.body,color:v.label,lineHeight:Hn.base}),f.textContent="No die position data for this wafer.",r.appendChild(f);const l=p.createElement("div");Object.assign(l.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),r.appendChild(i(()=>l.replaceChildren(n()))),o.appendChild(r),o.appendChild(l),w.appendChild(o),Ue=()=>{t||l.replaceChildren(n())}}else{const o=p.createElement("div");Object.assign(o.style,{position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"3",background:v.panelBg,borderTop:`1px solid ${v.menuBorder}`,fontSize:ft.body,color:v.text,cursor:"pointer",padding:`${F.xs} ${F.md}`,display:"flex",alignItems:"center",justifyContent:"space-between",gap:F.md}),Vn(o,"bare");const r=p.createElement("span");r.textContent=`+${e.length} ${e.length===1?"die":"dies"} without position data`,o.appendChild(r);const f=p.createElement("span");f.textContent="\u25BE",Object.assign(f.style,{fontSize:ft.body,lineHeight:Hn.none,color:v.label,flexShrink:"0"}),o.appendChild(f),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`${e.length} dies without position data. Click to view.`);let l=null,a=null;Ni(o,c=>{if(f.textContent=c?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(c)),c){l=p.createElement("div");const g=o.getBoundingClientRect().height||28;Object.assign(l.style,{position:"absolute",left:"0",right:"0",bottom:`${g}px`,top:"20%",zIndex:"2",background:v.panelBg,borderTop:`1px solid ${v.menuBorder}`,padding:F.md,boxSizing:"border-box",display:"flex",flexDirection:"column",gap:F.md}),l.addEventListener("click",se=>se.stopPropagation());const y=p.createElement("div");Object.assign(y.style,{display:"flex",justifyContent:"flex-end"}),y.appendChild(i(()=>{a&&a.replaceChildren(n())})),l.appendChild(y),a=p.createElement("div"),Object.assign(a.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),a.appendChild(n()),l.appendChild(a),w.appendChild(l)}else l&&(l.remove(),l=null,a=null)}),w.appendChild(o),Ue=()=>{a&&!t&&a.replaceChildren(n())}}}const{onHover:Ze,onClick:Zn,onSelect:fe,onViewOptionsChange:Qn,showTooltip:qn=!0,showToolbar:Pe=!0,showIdentity:Gt=!0,summaryPanel:Oe,showHelpButton:Ut=!1,userGuideExtension:Jn,onExpand:Zt,showExpandButton:Qt=!0,zIndex:ei,insights:gt,warnings:qt,viewOptions:ti={},...be}=b,Re=gt?.enabled??!1,ni=.4,ii=20,Qe=[...m.passBins??uo],Jt=qt?.display??!0,oi=Oi(ei);let le=b.statsSummary,ae=[],en=!1,qe=null,tn=!1;function ht(){const e=io({result:m,statsSummary:le,extra:qe?[qe]:[]}),t=e.length!==ae.length||e.some((n,i)=>n.code!==ae[i]?.code||n.message!==ae[i]?.message);ae=e,(t||!en)&&(en=!0,qt?.onWarning?.(e))}ht();let ee=m,V=m.wafer,ve=m.dies,M=new Set,$=m.hbinDefs,G=m.sbinDefs,te=m.testDefs,pe=m.metadataFields,nn=m.reticles?.length?m.reticles:void 0,on=m.reticleConfig,sn=m.view?.dataAxisFlip,mt=m.isLotStack??!1,yt=m.aggrMethod,bt=m.lotSize;const si=Pe&&Re;let z=null,Q=null,q=null;Gt&&(z=lo(Kt(V.metadata??{},Ie())??"",V.metadata,{lotStack:Ie(),ownerDocument:p}),w.appendChild(z.metaPanel),z.metaPanel.style.visibility="visible",z.isEmpty()||(Q=ln(z.wrap),K.insertBefore(Q,K.firstChild),Te()));function ln(e){const t=p.createElement("div");return Object.assign(t.style,{display:"flex",alignItems:"center",padding:`${F.sm} ${F.lg}`,flex:"1 1 auto",minWidth:"0",overflow:"hidden",gap:F.sm}),Object.assign(e.style,{flex:"1",minWidth:"0"}),t.appendChild(e),t}function Ie(){return mt?{lotSize:bt??1,aggrMethod:yt}:void 0}function li(){if(!z)return;z.update(Kt(V.metadata??{},Ie())??"",V.metadata,Ie());const e=Q?.isConnected??!1,t=!z.isEmpty();!t&&e?(Q.remove(),Q=null):t&&!e&&(Q=ln(z.wrap),Q.style.display="",K.insertBefore(Q,K.firstChild),Te())}const ai=[...$??[],...G??[]].some(e=>e.color);let d={plotMode:"hardBin",showDieLabels:!1,showPartialDies:!0,showRingBoundaries:!1,showQuadrantBoundaries:!1,showReticle:!1,showXYIndicator:!1,rotation:0,flipX:!1,flipY:!1,legendPosition:"default",...ti},Y=null,ne=!1,an=null;function ri(){return Re?Y?Promise.resolve(Y):(an??=import("./insightsTab.js").then(({createInsightsTab:e})=>(Y=e({getItems:()=>[{wafer:V,dies:ve,hbinDefs:$,sbinDefs:G,testDefs:te,label:Zi({wafer:V},0),passBins:Qe,statsSummary:le}],getBinColors:()=>h.binColors,getRingCount:()=>ee.ringCount??4,onSaveImage:ke.onSaveImage,onSaveText:ke.onSaveText,defaultView:gt?.defaultView,showMetadataStrip:!1,contentInset:ce,backTab:si?void 0:{label:"Map",onBack:()=>We(!1)},onOpenGuide:Ut&&!Pe?()=>Ft():void 0,focusTest:t=>{E({plotMode:"value",activeTest:t,highlightBin:void 0}),We(!1)},ownerDocument:p}),Object.assign(Y.el.style,{position:"absolute",inset:"0",background:v.canvasBg,overflowY:"auto",paddingTop:"0"}),Y.el.style.display="none",ye.appendChild(Y.el),Y)),an):Promise.resolve(null)}let rn=0;const vt=["wheel","touchstart","pointerdown","keydown"];function di(e,t){if(t<=0)return;let n=!1;const i=[],o=()=>{n=!0;for(const f of i)B.clearTimeout(f);i.length=0;for(const f of vt)e.removeEventListener(f,o)},r=()=>n||!ne?!0:(e.scrollTop=t,e.scrollTop>=t);if(!r()){for(const f of vt)e.addEventListener(f,o,{passive:!0,once:!0});for(const f of[0,50,150,300,600])i.push(B.setTimeout(()=>{r()},f));i.push(B.setTimeout(()=>{for(const f of vt)e.removeEventListener(f,o)},700))}}function We(e){if(!Re)return;const t=ne;ne=e,Y&&!e&&t&&(rn=Y.el.scrollTop),Y&&(Y.el.style.display=e?"flex":"none"),w.style.visibility=e?"hidden":"",A&&(A.style.display=e||Ge?"none":"flex"),T&&(T.style.display=e?"none":"flex"),q&&(q.style.display=he?"none":"flex"),ie&&(ie.style.display="flex"),Q&&(Q.style.display=""),Te(),z&&e&&z.collapse(),it(),H&&(H.innerHTML=e?Kn.wafer:Kn.analysis,H.ariaLabel=e?"Back to wafer view":"Insights"),e&&ri().then(n=>{!n||!ne||(n.el.style.display="flex",n.render(),di(n.el,rn))})}Re&&gt?.defaultOpen&&queueMicrotask(()=>We(!0));let h,dn,N=null,k=null,xt=[],Ct;function cn(e){Ct!==e&&(Ct=e,x())}let Fe=null,wt=be.legendOffset??{x:0,y:0},Ae=!1,xe=!1,He={x:0,y:0},St={x:0,y:0},ue=!1,Ce=!1,X="pan",we={x:0,y:0},Je={x:0,y:0},O={x:0,y:0},R={x:0,y:0},Ve=!1,Se=!1;function Mt(){const e=d;h=xi(V,ve.filter(ao),{plotMode:e.plotMode,binColorScheme:e.binColorScheme,valueColorScheme:e.valueColorScheme,reverseValueScheme:e.reverseValueScheme,useDefinedBinColors:e.useDefinedBinColors,binColors:e.binColors??fo(ve,{passBins:Qe,binColorScheme:e.binColorScheme,hbinDefs:$,sbinDefs:G,useDefinedBinColors:e.useDefinedBinColors}),passBins:Qe,showDieLabels:e.showDieLabels,showPartialDies:e.showPartialDies,showRingBoundaries:e.showRingBoundaries,showQuadrantBoundaries:e.showQuadrantBoundaries,showReticle:e.showReticle,showXYIndicator:e.showXYIndicator,reticles:nn,ringCount:ee.ringCount??4,highlightBin:e.highlightBin,highlightMetadataValue:e.highlightMetadataValue,activeTest:e.activeTest,activeMetadataKey:e.activeMetadataKey,testDefs:te,valueRange:e.valueRange,metadataValueOrder:e.metadataValueOrder,logScale:e.logScale,isLotStack:mt,aggregationMethod:yt??e.aggregationMethod,lotSize:bt??e.lotSize,dataAxisFlip:sn,colorbarRangeMode:e.colorbarRangeMode,passFailDisplay:e.passFailDisplay,fallbackFormat:e.fallbackFormat,interactiveTransform:{rotation:e.rotation??0,flipX:e.flipX??!1,flipY:e.flipY??!1}},{hbinDefs:$,sbinDefs:G,metadataFields:pe}),dn=new Map(h.dies.map((n,i)=>[Be(n),i]));const t=e.binColors?null:po(h.binColors,h.plotMode);t?.message!==qe?.message&&(qe=t,ht(),tn&&Et())}Mt();let U=null,Me=null,et=null,fn=b.findingsNotice,ci={},I=null,re=null;function fi(e){const{kind:t,index:n}=e.variable;E(t==="test"?{plotMode:"value",activeTest:n??0,highlightBin:void 0}:t==="softBin"?{plotMode:"softBin",highlightBin:void 0}:{plotMode:"hardBin",highlightBin:void 0});const i=e.highlight;i.kind==="bin"?(Pt(i.dieKeys),E({highlightBin:i.bin})):(i.kind==="region"||i.kind==="dies")&&Pt(i.dieKeys)}const ze=new Map;function pn(e){ze.get(e)?.cancel(),ze.delete(e);const t=no(to(e,{wafer:V,dies:ve,yieldSummary:ee.yield,dataCoverage:ee.dataCoverage,hbinDefs:$,sbinDefs:G,testDefs:te,statsSummary:le,warnings:Jt?ae:[],passBins:Qe,ringCount:ee.ringCount??4,binColors:h.binColors,plotMode:d.plotMode??"hardBin",metadataShownElsewhere:Gt,fallbackFormat:d.fallbackFormat,activeFindingId:et,findingsFilter:ci,findingsNotice:fn,onFindingsFilterChange:ge,onSaveText:ke.onSaveText,metadataFields:pe,dieListOptions:b.dieList,onFindingClick:(n,i)=>{et===n.id?(et=null,Pt([]),E({highlightBin:void 0})):(et=n.id,fi(n)),ge()}}));t.done||ze.set(e,t)}function ge(){U&&pn(U)}function Ye(){I&&pn(I)}if(Oe?.placement){const e=Oe.placement;U=jt(e,ce,p);const t=w.parentElement,n=w.nextSibling;Me=_t(w,U,e),t?.insertBefore(Me,n),ge()}else if(le){const e=Oe?.defaultOpen??!Pe;I=jt("right",ce,p),I.style.display=e?"block":"none";const t=w.parentElement,n=w.nextSibling;re=_t(w,I,"right"),t?.insertBefore(re,n),Ye()}const W=qn?Yn(p):null;let ie=null,L=null,A=null,T=null,tt=null,j=null,un=null,H=null,oe=null,nt=null;tn=!0;function Et(){if(!oe||!nt)return;const e=ae.length,t=e>0;if(oe.style.display=t?"flex":"none",nt.style.display=t?"":"none",!t)return;const n=so(ae[0]),i=`${e} data ${e===1?"warning":"warnings"}`;oe.style.color=n==="error"?v.errText:v.warnText,oe.ariaLabel=n==="error"?`${i} \u2014 the map may be positionally wrong`:i}let Dt=null,gn=null,Bt=null,kt=null,Lt=null,Tt=null;function Pt(e){M=new Set(e??[]),fe&&fe(Wt()),x()}function it(){if(!j)return;const e=!!(U??I);j.style.display=le&&e&&!ne?"flex":"none";const t=U??I,n=t?t.style.display!=="none":!1;le?.hasNotableFindings&&!n?j.style.color=v.findingIndicator:j.dataset.active||(j.style.color=v.icon)}let hn=null;function mn(e){const t=U??I;t&&(t.style.display=e?"block":"none",j&&hn?.(j,e),it())}if(Pe){let g=function(D){X=D,i(se,D==="zoom"),i(S,D==="pan"),tt&&i(tt,D==="select"),s.style.cursor=D==="pan"?"grab":"crosshair"};ie=p.createElement("div"),ie.dataset.wmapToolbar="single",Object.assign(ie.style,{marginLeft:"auto",flexShrink:"0",display:"flex",flexDirection:"row",alignItems:"center",flexWrap:"wrap-reverse",justifyContent:"flex-end",maxWidth:"100%",background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:zn.control,boxShadow:Ti.panel,pointerEvents:"auto"});const e=Yn(p),t=Ri(e),{makeBtn:n,setActive:i,makeSep:o,makeMenuRow:r,makeMenuSection:f,closeOpenMenu:l,getOpenMenu:a,setOpenMenu:c}=t;hn=i,Dt=l,gn=a,p.addEventListener("click",l,!0),A=p.createElement("div"),Object.assign(A.style,{display:Ge?"none":"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),ie.appendChild(A);const y=n("download","Download PNG",gi);A.appendChild(y),A.appendChild(o());const se=n("zoomMode","Zoom (drag to zoom region)",()=>g("zoom")),De=n("zoomIn","Zoom in",()=>Ee(s.clientWidth/2,s.clientHeight/2,1.2)),J=n("zoomOut","Zoom out",()=>Ee(s.clientWidth/2,s.clientHeight/2,1/1.2)),de=n("reset","Reset zoom (double-click)",()=>st());A.appendChild(se),A.appendChild(De),A.appendChild(J),A.appendChild(de),A.appendChild(o());const S=n("pan","Pan (drag to move)",()=>g("pan"));A.appendChild(S),tt=n("boxSelect","Select (drag to select dies)",()=>g("select")),A.appendChild(tt),i(S,!0);{let D=function(u){return u.plotMode!==(d.plotMode??"hardBin")?!1:u.plotMode==="value"?(d.activeTest??0)===(u.activeTest??0):u.plotMode==="metadata"?d.activeMetadataKey===u.activeMetadataKey:!0},At=function(u,C){u.activeTest!==void 0?E({plotMode:u.plotMode,activeTest:u.activeTest,activeMetadataKey:void 0,logScale:u.logScale}):u.activeMetadataKey!==void 0?E({plotMode:u.plotMode,activeTest:void 0,activeMetadataKey:u.activeMetadataKey,passFailDisplay:"off"}):E({plotMode:u.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),C.remove(),c(null),$e(Z,!1)};L=p.createElement("div"),Object.assign(L.style,{display:"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),ie.appendChild(L),T=p.createElement("div"),Object.assign(T.style,{display:"flex",alignItems:"center",gap:"0"}),L.appendChild(T),T.appendChild(o());const lt=()=>{const u=a();u&&(u.remove(),c(null)),$e(Z,!1)},Z=n("mode","Plot mode",()=>{if(a()){lt();return}const u=ve,C=h.testDefs,{testEntries:dt,binEntries:me,stackedEntries:je}=$i(u,C,{includeStacked:h.isLotStack}),zt=(pe??[]).filter(Ke=>Gi(u,Ke.key)).map(Ui),_e=Ii(Z.getBoundingClientRect(),dt,me,je,D,At,{makeMenuRow:r,makeMenuSection:f},d.plotMode??"hardBin",Z.ownerDocument.defaultView??window,zt);Xn(Z).appendChild(_e),c(_e),$e(Z,!0),_n(_e,Z,lt)});$e(Z,!1);const{btn:at,sync:Xe}=Ai(t,()=>({...d,plotMode:d.plotMode??"hardBin"}),()=>ai,E);kt=Xe,kt();const Ht=zi(t,()=>{const u=!!h.hasReticle,C=(d.plotMode??"hardBin")==="value",{testNumber:dt}=Yt(d.activeTest??0,h.testDefs),me=ct(h.testDefs,dt),je=C&&me!==void 0&&!Nt(me),zt=C&&!je&&(me?.limitLow!==void 0||me?.limitHigh!==void 0),_e=C&&!je&&h.dies.some(Ke=>ki(Ke,dt,me)!==void 0);return ji(d,u,{functionalActive:je,hasLimits:zt,hasRecorded:_e,binMode:(d.plotMode??"hardBin")==="hardBin"||(d.plotMode??"hardBin")==="softBin"},Ke=>E(Ke))},()=>_i(d)),{btn:Vt,sync:hi}=Vi(t,()=>d,u=>E({legendPosition:u}));Bt=hi,Bt();const Fn=()=>{const{testNumber:u}=Yt(d.activeTest??0,te),C=ct(te,u);return C!==void 0&&!Nt(C)},{btn:mi,sync:yi}=Hi(t,()=>({...d,functionalActive:Fn()}),u=>E(u));Lt=yi,Lt();const bi=()=>{const{testNumber:u}=Yt(d.activeTest??0,te),C=ct(te,u);return C!==void 0&&(C.limitLow!==void 0||C.limitHigh!==void 0)},rt=n("specRange","Colorbar range: spec limits",()=>{const u=d.colorbarRangeMode==="data"?"spec":"data";E({colorbarRangeMode:u})});Tt=()=>{const u=d.plotMode==="value"&&bi()&&Xi(d)==="off"&&!Fn();rt.style.display=u?"":"none";const C=(d.colorbarRangeMode??"spec")==="spec";i(rt,C),rt.ariaLabel=C?"Colorbar range: spec limits (click for data range)":"Colorbar range: data range (click for spec limits)"},Tt();const vi=Yi(t,()=>d,u=>E(u));T.appendChild(Z),T.appendChild(at),T.appendChild(mi),T.appendChild(rt),Ge||(T.appendChild(o()),T.appendChild(Ht),T.appendChild(o()),T.appendChild(Vt),T.appendChild(o()),T.appendChild(vi)),le&&(j=n("findings","Summary panel",()=>{const u=U??I;u&&mn(u.style.display==="none")}),L.appendChild(o()),L.appendChild(j),I?.style.display!=="none"&&i(j,!0),it()),Jt&&(nt=o(),oe=n("warning","Data warnings",()=>{const u=a();if(l(new MouseEvent("click")),u)return;const C=oo(oe.getBoundingClientRect(),ae,B);Xn(ye).appendChild(C),c(C),_n(C,oe,()=>l(new MouseEvent("click")))}),$e(oe,!1),L.appendChild(nt),L.appendChild(oe),Et()),Re&&(L.appendChild(o()),H=n("analysis","Insights",()=>{We(!ne),i(H,ne)}),H.dataset.wmapInsightsBtn="1",L.appendChild(H)),Qt&&(L.appendChild(o()),q=n("expand","Expand (E)",Zt??yn),L.appendChild(q)),Ut&&(L.appendChild(o()),un=n("help","User guide",()=>Ft()),L.appendChild(un))}K.appendChild(ie),Te()}let he=null;function yn(){he&&(he.close(),he=null);const e=ye;e.style.flex="1",e.style.minWidth="0",e.style.minHeight="0";const t=Kt(V.metadata??{},Ie()),n=K.childElementCount>0?[K,e]:[e],i=Wi(n,{ownerDocument:p,boxSize:ne?{width:"min(96vw, 1600px)",height:"min(92vh, 1000px)"}:void 0,onClosed:()=>{he=null,q&&(q.style.display="flex"),ne||s.focus({preventScroll:!0})}});i&&(i.box.setAttribute("aria-label",t??"Expanded wafer map"),n.length>1&&(i.contentWrap.style.flexDirection="column"),he=i,q&&(q.style.display="none"))}function bn(e){("binColorScheme"in e||"useDefinedBinColors"in e)&&!("binColors"in e)&&d.binColors!==void 0&&(e={...e,binColors:void 0});const t=d.plotMode;d={...d,...e},e.plotMode!==void 0&&e.plotMode,Object.keys(e).every(r=>r==="legendPosition"||r==="showLegend"||r==="markFailingDies")||Mt(),Bt?.(),kt?.(),Lt?.(),Tt?.(),x();const i=e.plotMode!==void 0&&e.plotMode!==t,o=COLOR_KEYS.some(r=>r in e);(o||i)&&(ge(),Ye()),(o||i||e.activeTest!==void 0||e.logScale!==void 0||e.colorbarRangeMode!==void 0)&&Ue?.()}function E(e){bn(e);const t=Object.keys(e);Qn?.(d,t,classifyChanged(t))}let Ot=!1;function Rt(){Ot||(Ot=!0,Xt(()=>{Ot=!1,x()},B))}function x(){const e=k??void 0,t=h.dies[0],n=t?{x:t.width,y:t.height}:be.diePitchMm,i=Math.floor(s.clientWidth||s.width),o=!!($?.length||G?.length||h.dies.some(y=>y.hbin!=null||y.sbin!=null)),r=d.legendPosition??"default",f=d.showLegend??!0,l=r==="default"||r==="compact",a=(be.colorbarWidth??16)+28,c=o&&l?r!=="default"?Math.max(An,a):i<Di?0:i<Ei?Math.max(Mi,a):Math.max(An,a):void 0,g=Si(s,h,{...be,minRightReserve:f?c:0,showColorbar:f&&(be.showColorbar??!0),markFailingDies:d.markFailingDies??!1,legendPosition:r,legendOffset:wt,diePitchMm:n,fallbackFormat:d.fallbackFormat,showAxes:be.showAxes??k!==null,viewport:e,activeBin:d.plotMode==="metadata"?d.highlightMetadataValue:d.highlightBin,hoverBin:Ct,hbinDefs:$,sbinDefs:G,metadataFields:pe});xt=g.binLegendRows,Fe=g.legendBox??null,k===null&&(N=g.viewport),M.size>0&&pi(),Ce&&ui()}function pi(){const e=_();if(!e)return;const t=s.getContext("2d"),n=h.hoverPoints,i=h.rectangles[0],o=i?i.width/2*e.ppm:e.ppm*.5,r=i?i.height/2*e.ppm:e.ppm*.5,f=Math.max(1,Math.min(3,o*.08)),l=o-f,a=r-f,c=[];for(const g of M){const y=dn.get(g);y!==void 0&&c.push({sx:e.originX+n[y].x*e.ppm,sy:e.originY-n[y].y*e.ppm})}if(c.length){t.save(),t.setLineDash([]),t.fillStyle="rgba(0,0,0,0.12)",t.beginPath();for(const{sx:g,sy:y}of c)t.rect(g-l,y-a,l*2,a*2);t.fill(),t.strokeStyle="rgba(255,255,255,0.9)",t.lineWidth=3,t.beginPath();for(const{sx:g,sy:y}of c)t.rect(g-l,y-a,l*2,a*2);t.stroke(),t.strokeStyle="rgba(0,0,0,0.9)",t.lineWidth=1.5,t.beginPath();for(const{sx:g,sy:y}of c)t.rect(g-l,y-a,l*2,a*2);t.stroke(),t.restore()}}function ui(){const e=s.getContext("2d"),t=Math.min(O.x,R.x),n=Math.min(O.y,R.y),i=Math.abs(R.x-O.x),o=Math.abs(R.y-O.y);e.save(),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(t,n,i,o),e.setLineDash([5,3]),e.strokeStyle="rgba(255,255,255,0.9)",e.lineWidth=3,e.strokeRect(t,n,i,o),e.strokeStyle="rgba(0,0,0,0.9)",e.lineWidth=1.5,e.strokeRect(t,n,i,o),e.restore()}function gi(){s.toBlob(e=>{e&&(b.downloadFilename!=null?jn(e,b.downloadFilename,b.onSaveImage):jn(e,$t(),ke.onSaveImage))})}function vn(e){return N?Math.max(N.ppm*ni,Math.min(N.ppm*ii,e)):e}function Ee(e,t,n){const i=k??N;if(!i)return;const o=vn(i.ppm*n),r=o/i.ppm,f=e-(e-i.originX)*r,l=t-(t-i.originY)*r,a=(N?.snapDist??1)/(o/(N?.ppm??o));k={originX:f,originY:l,ppm:o,snapDist:a},x()}function _(){return k??N}function xn(e){if(e.ctrlKey||e.metaKey){e.preventDefault();const t=s.getBoundingClientRect(),n=e.deltaY<0?1.12:1/1.12;Ee(e.clientX-t.left,e.clientY-t.top,n)}else if(k!==null){e.preventDefault();const t=_(),n=k.snapDist;k={originX:t.originX-e.deltaX,originY:t.originY-e.deltaY,ppm:t.ppm,snapDist:n},x()}}function Cn(e,t,n){return e>=n.x&&e<n.x+n.w&&t>=n.y&&t<n.y+n.h}function wn(e){if(e.button!==0||!_())return;s.focus({preventScroll:!0}),s.setPointerCapture(e.pointerId);const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;if(Fe&&d.legendPosition==="floating"&&Cn(n,i,Fe)){xe=!0,He={x:n,y:i},St={...wt};return}if(Ve&&X!=="pan"){Se=!0,ue=!0,we={x:n,y:i},Je={x:_().originX,y:_().originY},s.style.cursor="grabbing";return}if(X==="zoom"||X==="select"){Ce=!0,O=R={x:n,y:i};return}ue=!0,we={x:n,y:i},Je={x:_().originX,y:_().originY},s.style.cursor="grabbing"}function Sn(e){const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;if(Ce){R={x:n,y:i},Rt();return}if(xe){const g=n-He.x,y=i-He.y;g*g+y*y>16&&(xe=!1,Ae=!0,s.style.cursor="grabbing")}if(Ae){wt={x:St.x+(n-He.x),y:St.y+(i-He.y)},Rt();return}if(ue){const g=_(),y=k?.snapDist??N?.snapDist??1;k={originX:Je.x+(n-we.x),originY:Je.y+(i-we.y),ppm:g.ppm,snapDist:y},Rt();return}const o=_();if(!o)return;const r=(n-o.originX)/o.ppm,f=(o.originY-i)/o.ppm,a=Bn(r,f,o.snapDist)?.die??null,c=xt.find(g=>n>=g.x&&n<g.x+g.w&&i>=g.y&&i<g.y+g.h);if(cn(c?c.bin:void 0),c){s.style.cursor="pointer",W&&(W.textContent=c.label??`Bin ${c.bin}`,W.style.display="block",Nn(W,s,e.clientX,e.clientY)),Ze?.(null,e);return}X==="pan"&&(s.style.cursor=a?"crosshair":"grab"),W&&(a?(W.innerHTML=Ci(a,h.plotMode,{testDefs:te,hbinDefs:$,sbinDefs:G,fallbackFormat:d.fallbackFormat,aggrMethod:h.aggrMethod,lotSize:h.lotSize,metadataFields:pe,activeTest:h.activeTest,reticleConfig:on}),W.style.display="block",Nn(W,s,e.clientX,e.clientY)):W.style.display="none"),Ze?.(a,e)}function Mn(e){const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top,o=e.ctrlKey||e.metaKey;if(W&&(n<0||i<0||n>t.width||i>t.height)&&(W.style.display="none"),Ce){Ce=!1,R={x:n,y:i};const l=n-O.x,a=i-O.y,c=_();if(X==="zoom"){if(l*l+a*a<25)Ee(n,i,2);else if(c){const g=Math.min(O.x,R.x),y=Math.max(O.x,R.x),se=Math.min(O.y,R.y),De=Math.max(O.y,R.y),J=y-g,de=De-se;if(J>4&&de>4){const S=s.clientWidth,D=s.clientHeight,At=S/J,lt=D/de,Z=Math.min(At,lt),at=vn(c.ppm*Z),Xe=at/c.ppm,Ht=(g+y)/2,Vt=(se+De)/2;k={originX:S/2-(Ht-c.originX)*Xe,originY:D/2-(Vt-c.originY)*Xe,ppm:at,snapDist:c.snapDist/Xe}}}x(),s.style.cursor="crosshair";return}if(l*l+a*a<25)It(n,i,o,e);else if(c){const g=(Math.min(O.x,R.x)-c.originX)/c.ppm,y=(Math.max(O.x,R.x)-c.originX)/c.ppm,se=(c.originY-Math.max(O.y,R.y))/c.ppm,De=(c.originY-Math.min(O.y,R.y))/c.ppm,J=h.hoverPoints,de=[];for(let S=0;S<J.length;S++)if(J[S].x>=g&&J[S].x<=y&&J[S].y>=se&&J[S].y<=De){const D=h.dies[S];D&&de.push(D)}if(o)for(const S of de){const D=Be(S);M.has(D)?M.delete(D):M.add(D)}else M=new Set(de.map(S=>Be(S)));fe?.(Wt())}x(),s.style.cursor="crosshair";return}if(xe){xe=!1,It(n,i,o,e);return}if(Ae){Ae=!1,s.style.cursor="grab";return}if(!ue)return;if(ue=!1,Se){Se=!1,s.style.cursor=Ve||X==="pan"?"grab":"crosshair";return}s.style.cursor=X==="pan"?"grab":"crosshair";const r=n-we.x,f=i-we.y;r*r+f*f<25&&It(n,i,o,e)}function It(e,t,n,i){for(const l of xt)if(e>=l.x&&e<l.x+l.w&&t>=l.y&&t<l.y+l.h){if(typeof l.bin=="number"){const a=d.highlightBin===l.bin?void 0:l.bin;E({highlightBin:a})}else{const a=d.highlightMetadataValue===l.bin?void 0:l.bin;E({highlightMetadataValue:a})}return}if(Fe&&Cn(e,t,Fe))return;const o=_();if(!o)return;const f=Bn((e-o.originX)/o.ppm,(o.originY-t)/o.ppm,o.snapDist)?.die??null;if(f){Zn?.(f,i);const l=Be(f);n?M.has(l)?M.delete(l):M.add(l):M=new Set([l]),fe?.(Wt()),x()}else n||(M=new Set,fe?.([]),x())}function Wt(){const e=[],t=h.hoverPoints;for(let n=0;n<t.length;n++){const i=h.dies[n];i&&M.has(Be(i))&&e.push(i)}return e}function En(){cn(void 0),W&&pt(p),Ze?.(null,new MouseEvent("mouseleave")),s.style.cursor=X==="pan"?"grab":"crosshair"}function Dn(){ue=!1,Se=!1,Ce=!1,xe=!1,Ae=!1,W&&pt(p),Ze?.(null,new MouseEvent("mouseleave")),s.style.cursor=X==="pan"?"grab":"crosshair",x()}function Bn(e,t,n){const i=h.hoverPoints,o=h.rectangles;for(let a=0;a<o.length;a++){const c=o[a];if(Math.abs(e-c.x)<=c.width/2&&Math.abs(t-c.y)<=c.height/2){const g=h.dies[a];return g?{die:g,index:a}:null}}let r=null,f=-1,l=n*n;for(let a=0;a<i.length;a++){const c=i[a].x-e,g=i[a].y-t,y=c*c+g*g;y<l&&(l=y,r=h.dies[a]??null,f=a)}return r?{die:r,index:f}:null}const kn=new B.ResizeObserver(()=>{N=null,k=null,x()});kn.observe(s),b.height==null&&Un<=0&&Xt(()=>Xt(()=>{P.clientHeight>0||console.warn("[wafermap] The map container has zero height, so the map cannot render. renderWaferMap fills its container \u2014 give the container a resolved height: an explicit CSS `height` (e.g. 600px), a height-resolved flex/grid parent, or `position:absolute; inset:0`. Alternatively pass `{ height: 600 }` in the render options and the library will size it for you.")}));let Ne=B.matchMedia(`(resolution: ${B.devicePixelRatio}dppx)`);const ot=()=>{Ne.removeEventListener("change",ot),Ne=B.matchMedia(`(resolution: ${B.devicePixelRatio}dppx)`),Ne.addEventListener("change",ot),x()};Ne.addEventListener("change",ot);const Ln=B.matchMedia("(prefers-color-scheme: dark)"),Tn=()=>x();Ln.addEventListener("change",Tn);const Pn=()=>{W&&pt(p)};B.addEventListener("blur",Pn);function On(e){if(e.key==="Escape"&&M.size>0&&(M=new Set,fe?.([]),x()),(e.key==="e"||e.key==="E")&&Qt&&(e.stopPropagation(),(Zt??yn)()),(e.ctrlKey||e.metaKey)&&(e.key==="="||e.key==="+"?(e.preventDefault(),Ee(s.clientWidth/2,s.clientHeight/2,1.2)):e.key==="-"?(e.preventDefault(),Ee(s.clientWidth/2,s.clientHeight/2,1/1.2)):e.key==="0"&&(e.preventDefault(),st())),!e.ctrlKey&&!e.metaKey&&!e.shiftKey){const n=_();if(n){const i=k?.snapDist??N?.snapDist??1;let o=0,r=0;e.key==="ArrowLeft"&&(o=20,e.preventDefault()),e.key==="ArrowRight"&&(o=-20,e.preventDefault()),e.key==="ArrowUp"&&(r=20,e.preventDefault()),e.key==="ArrowDown"&&(r=-20,e.preventDefault()),(o||r)&&(k={originX:n.originX+o,originY:n.originY+r,ppm:n.ppm,snapDist:i},x())}e.key===" "&&!Ve&&(e.preventDefault(),Ve=!0,X!=="pan"&&(s.style.cursor="grab"))}}function Rn(e){e.key===" "&&(Ve=!1,Se&&(ue=!1,Se=!1),s.style.cursor=X==="pan"?"grab":"crosshair")}s.style.cursor="grab",s.setAttribute("tabindex","0"),s.addEventListener("wheel",xn,{passive:!1}),s.addEventListener("pointerdown",wn),s.addEventListener("pointermove",Sn),s.addEventListener("pointerup",Mn),s.addEventListener("pointerleave",En),s.addEventListener("pointercancel",Dn);const In=()=>st();s.addEventListener("dblclick",In),s.addEventListener("keydown",On),s.addEventListener("keyup",Rn);const Wn=e=>{e.stopPropagation()};s.addEventListener("click",Wn),s.clientWidth,x(),Ue?.();function st(){N=null,k=null,x()}function Ft(){import("./userGuideHtml.js").then(e=>Fi({buildWaferMap:Bi,renderWaferMap,renderWaferGallery:void 0,analyzeWaferMap:Li},e.USER_GUIDE_HTML,Jn,P))}return Te(),{setResult(e){ee=e,V=e.wafer,ve=e.dies,$=e.hbinDefs,G=e.sbinDefs,te=e.testDefs,pe=e.metadataFields,nn=e.reticles?.length?e.reticles:void 0,on=e.reticleConfig,sn=e.view?.dataAxisFlip,mt=e.isLotStack,yt=e.aggrMethod,bt=e.lotSize,li(),Mt(),x(),U&&ge()},setOptions(e){bn(e)},getOptions(){return{...d}},resetZoom:st,setSelection(e){M=new Set(e.map(t=>Be(t))),x()},clearSelection(){M=new Set,fe?.([]),x()},setFindingsNotice(e){fn=e,U?ge():I&&Ye()},setStatsSummary(e){if(le=e,ht(),Et(),U)ge();else if(I)Ye();else if(e&&!Oe?.placement){const t=Oe?.defaultOpen??!Pe;I=jt("right",ce,p),I.style.display=t?"block":"none";const n=w.parentElement,i=w.nextSibling;re=_t(w,I,"right"),n?.insertBefore(re,i),Ye()}it()},closeSummaryPanel(){mn(!1)},getExportTitle(){return $t()},getBinColors(){return h.binColors},setSummaryVisible(e){j&&(j.style.display=e?"flex":"none")},setViewControlsVisible(e){L&&(L.style.display=e?"flex":"none")},setExpandVisible(e){q&&(q.style.display=e?"flex":"none")},openUserGuide:Ft,setInsightsOpen(e){We(e),H&&(e?(H.dataset.active="1",H.style.background=v.bgActive,H.style.color=v.iconActive):(delete H.dataset.active,H.style.background="transparent",H.style.color=v.icon))},destroy(){for(const e of ze.values())e.cancel();ze.clear(),he?.close(),gn?.()?.remove(),Dt&&p.removeEventListener("click",Dt,!0),s.removeEventListener("wheel",xn),s.removeEventListener("pointerdown",wn),s.removeEventListener("pointermove",Sn),s.removeEventListener("pointerup",Mn),s.removeEventListener("pointerleave",En),s.removeEventListener("pointercancel",Dn),s.removeEventListener("dblclick",In),s.removeEventListener("keydown",On),s.removeEventListener("keyup",Rn),s.removeEventListener("click",Wn),kn.disconnect(),Ne.removeEventListener("change",ot),Ln.removeEventListener("change",Tn),B.removeEventListener("blur",Pn),oi(),W&&pt(p),ie?.remove(),Me&&(Me.parentElement?.insertBefore(w,Me),Me.remove()),re&&(re.parentElement?.insertBefore(w,re),re.remove()),w.remove(),s.style.cursor="",Y?.destroy(),z?.destroy(),Le.remove()}}}