@wafertools/wafermap 0.26.0 → 0.27.0
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.
- package/CHANGELOG.md +367 -0
- package/README.md +46 -3
- package/dist/packages/canvas-adapter/canvasTheme.d.ts +4 -0
- package/dist/packages/canvas-adapter/canvasTheme.js +1 -1
- package/dist/packages/canvas-adapter/charts/barPanel.d.ts +16 -0
- package/dist/packages/canvas-adapter/charts/barPanel.js +1 -1
- package/dist/packages/canvas-adapter/charts/binCluster.js +1 -1
- package/dist/packages/canvas-adapter/charts/boxplot.d.ts +13 -1
- package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
- package/dist/packages/canvas-adapter/charts/capability.d.ts +10 -10
- package/dist/packages/canvas-adapter/charts/capability.js +1 -1
- package/dist/packages/canvas-adapter/charts/chartShell.d.ts +337 -3
- package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
- package/dist/packages/canvas-adapter/charts/correlation.d.ts +8 -9
- package/dist/packages/canvas-adapter/charts/correlation.js +2 -1
- package/dist/packages/canvas-adapter/charts/groupedBarPlot.d.ts +50 -0
- package/dist/packages/canvas-adapter/charts/groupedBarPlot.js +1 -0
- package/dist/packages/canvas-adapter/charts/histogram.d.ts +12 -1
- package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
- package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
- package/dist/packages/canvas-adapter/charts/scatter.js +1 -1
- package/dist/packages/canvas-adapter/charts/testPassRate.d.ts +20 -0
- package/dist/packages/canvas-adapter/charts/testPassRate.js +1 -0
- package/dist/packages/canvas-adapter/charts/trend.d.ts +30 -0
- package/dist/packages/canvas-adapter/charts/trend.js +1 -0
- package/dist/packages/canvas-adapter/dieList.js +7 -7
- package/dist/packages/canvas-adapter/identityHeader.d.ts +46 -0
- package/dist/packages/canvas-adapter/identityHeader.js +1 -0
- package/dist/packages/canvas-adapter/index.d.ts +1 -1
- package/dist/packages/canvas-adapter/insightsTab.d.ts +27 -3
- package/dist/packages/canvas-adapter/insightsTab.js +1 -1
- package/dist/packages/canvas-adapter/maplessSummary.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +15 -2
- package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -20
- package/dist/packages/canvas-adapter/renderWaferMap.d.ts +72 -17
- package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
- package/dist/packages/canvas-adapter/summaryPanel.d.ts +219 -33
- package/dist/packages/canvas-adapter/summaryPanel.js +3 -3
- package/dist/packages/canvas-adapter/toCanvas.d.ts +6 -0
- package/dist/packages/canvas-adapter/toCanvas.js +1 -1
- package/dist/packages/canvas-adapter/toolbar.d.ts +310 -6
- package/dist/packages/canvas-adapter/toolbar.js +2 -2
- package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
- package/dist/packages/canvas-adapter/userGuideHtml.js +98 -35
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/canvas-adapter/warnings.d.ts +0 -4
- package/dist/packages/canvas-adapter/warnings.js +1 -1
- package/dist/packages/core/utils.d.ts +11 -0
- package/dist/packages/core/utils.js +1 -1
- package/dist/packages/renderer/buildView.d.ts +34 -1
- package/dist/packages/renderer/buildView.js +1 -1
- package/dist/packages/renderer/buildWaferMap.d.ts +104 -5
- package/dist/packages/renderer/buildWaferMap.js +1 -1
- package/dist/packages/renderer/colorSchemes.js +1 -1
- package/dist/packages/stats/analyzeWaferMap.js +1 -1
- package/dist/packages/stats/binPareto.d.ts +15 -0
- package/dist/packages/stats/binPareto.js +1 -1
- package/dist/packages/stats/clusterDetection.js +1 -1
- package/dist/packages/stats/connectedComponents.d.ts +14 -0
- package/dist/packages/stats/connectedComponents.js +1 -0
- package/dist/packages/stats/correlation.d.ts +26 -0
- package/dist/packages/stats/correlation.js +1 -1
- package/dist/packages/stats/facets.js +1 -1
- package/dist/packages/stats/filterFindings.d.ts +18 -0
- package/dist/packages/stats/filterFindings.js +1 -1
- package/dist/packages/stats/findingsNarrative.js +1 -1
- package/dist/packages/stats/histogram.d.ts +19 -1
- package/dist/packages/stats/histogram.js +1 -1
- package/dist/packages/stats/index.d.ts +6 -0
- package/dist/packages/stats/index.js +1 -1
- package/dist/packages/stats/mergeTestDefs.d.ts +44 -0
- package/dist/packages/stats/mergeTestDefs.js +1 -0
- package/dist/packages/stats/metadataColumns.d.ts +20 -4
- package/dist/packages/stats/metadataColumns.js +1 -1
- package/dist/packages/stats/patternClassification.js +1 -1
- package/dist/packages/stats/renderFindingsReport.js +14 -14
- package/dist/packages/stats/renderSummaryReport.js +32 -29
- package/dist/packages/stats/reportHtml.js +38 -13
- package/dist/packages/stats/testPassRate.d.ts +85 -0
- package/dist/packages/stats/testPassRate.js +1 -0
- package/dist/packages/stats/trend.d.ts +40 -0
- package/dist/packages/stats/trend.js +1 -0
- package/dist/packages/stats/types.d.ts +117 -6
- package/llms.txt +6 -0
- package/package.json +7 -5
- package/dist/packages/canvas-adapter/metadataBadge.d.ts +0 -30
- package/dist/packages/canvas-adapter/metadataBadge.js +0 -1
|
@@ -1,20 +1 @@
|
|
|
1
|
-
import{getUniqueTestNumbers as kn,resolveTestNumber as Dn,findTestDef as Bn}from"../renderer/buildView.js";import{getColorScheme as En}from"../renderer/colorSchemes.js";import{metadataValueColor as On}from"../renderer/colorMap.js";import{resolveCanvasTheme as Tn}from"./canvasTheme.js";import{ICONS as ge}from"./icons.js";import{CLR as g,sevColor as Tt,BIN_LEGEND_MODES as Lt,STACKED_MODES as he,Z_ABOVE as Wt,applyOverlayZ as Ln,getTooltip as Wn,hideTooltip as Rt,createToolbarHelpers as Rn,buildModeMenuEl as In,openDetachWindow as $n,openFloatingWindow as Pn,openModal as Fn,openReportModal as An,copyWmapThemeTokens as Hn,syncWmapPopupTheme as jn,openUserGuideWindow as zn,makePaletteBtn as Vn,makeLogScaleBtn as Nn,makeLegendStyleBtn as _n,makeOverlaysBtn as Gn,makeOrientationBtn as Kn,menuLayerFor as It,saveImageBlob as qn,markMenuTrigger as be,wireMenuA11y as $t,wireExpandToggle as Pt,passFailMenuRows as Xn,requestedPassFailDisplay as Ue,logWmapVersionOnce as Un,buildDataModeEntries as Qn,metadataKeyHasData as Yn,metadataModeEntry as Zn}from"./toolbar.js";import{aggregateValues as Jn,aggregateBinCounts as Ft}from"../core/aggregates.js";import{renderWaferMap as Qe}from"./renderWaferMap.js";import{classifyChanged as eo}from"./renderWaferMap.js";import{buildWaferMap as to,getTestPassStatus as no,isParametricTest as At}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Le}from"../stats/analyzeWaferMap.js";import{collectWarnings as oo,buildWarningsMenuEl as io,severityOf as ao}from"./warnings.js";import{compareNatural as lo}from"../core/utils.js";import{createSummaryPanelEl as Ye,buildMetadataStripRow as so,buildCompactMetadataRows as Ht,metadataEntries as jt,renderLotSummaryContent as ro}from"./summaryPanel.js";import"../stats/facets.js";import{escHtml as ye,renderSection as co,renderSeverityBadge as uo,reportStyles as fo}from"../stats/reportHtml.js";import{createInsightsTab as po}from"./insightsTab.js";import{getDieKey as mo,hasPosition as go}from"../core/dies.js";function We(f){const D=new Set;return f.filter(p=>D.has(p.bin)?!1:(D.add(p.bin),!0))}function zt(f,D){const p=f.ownerDocument.createElement("div");Object.assign(p.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:"2px 4px",borderRadius:"3px"});const Q=f.ownerDocument.createElement("span");Object.assign(Q.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:D.color,border:D.isActive?`2px solid ${g.iconActive}`:`1px solid ${g.menuBorder}`,borderRadius:"2px",boxSizing:"border-box"});const ne=f.ownerDocument.createElement("span");ne.textContent=D.label,Object.assign(ne.style,{fontWeight:D.isActive?"700":"400",color:D.isActive?g.iconActive:g.text,whiteSpace:"nowrap"}),p.appendChild(Q),p.appendChild(ne),p.setAttribute("role","button"),p.setAttribute("aria-pressed",D.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",D.onClick),p.addEventListener("keydown",W=>{(W.key==="Enter"||W.key===" ")&&(W.preventDefault(),D.onClick())}),f.appendChild(p)}export function renderWaferGallery(f,D,p={}){Un();const Q=p.cardPadding??6,ne=p.downloadFilename??"wafer-gallery";let W=p.columns;const Vt=p.showPlotModeSelector??!0,Nt=p.showHelpButton??!1,_t=p.userGuideExtension,Ze=p.insights?.enabled??!1,Gt=Ln(p.zIndex),Y=p.summaryPanel,Je=p.passBins??[1];let we=p.fallbackFormat,E=p.lotStatsSummary,oe=p.legendPosition??"default",xe=p.perCardLegend??!1;function ie(){const e=r.plotMode??"hardBin";return Lt.has(e)?null:r.colorbarRangeMode==="data"?"Each map has its own value range, so it keeps its own colour bar":"This lot has no shared colour bar for value mode, so each map keeps its own"}function et(){const e=xe||ie()!==null;for(const t of v)t&&t.setOptions({showLegend:e})}let r={plotMode:"hardBin",colorScheme:"default",showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,ringCount:4,rotation:0,flipX:!1,flipY:!1,...p.viewOptions},v=[],q=[],Z=[],k=[],w=D.map(e=>typeof e=="function"?null:e),Re=0,ve=0;const I=new Map;let Kt=0,O=null,ae=null,tt=new Set,m=null,le="lot",qt={};function nt(e){return w[e]?.statsSummary??E?.perWafer.find(t=>t.waferIndex===e)?.summary}function Ce(){return!!(w.some(e=>e?.statsSummary?.findings.length)||E?.perWafer.some(e=>e.summary.findings.length))}const Xt=Wn(),J=Rn(Xt),{makeBtn:N,setActive:se,makeSep:$,makeMenuRow:Ut,makeMenuSection:Qt,makeDropdown:ot,makeCheckMenuBtn:ho,closeOpenMenu:Se,getOpenMenu:re,setOpenMenu:de}=J;f.ownerDocument.addEventListener("click",Se,!0);const it=()=>Rt();window.addEventListener("blur",it);function Ie(e){tt=new Set(e);const t=[...B.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,s)=>{const c=tt.has(s);o.style.outline=c?`3px solid ${g.findingHighlight}`:"",o.style.outlineOffset=c?"-3px":"",c&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function $e(){Ie([])}function Pe(){for(const e of v)e&&e.clearSelection()}function Fe(e,t){const n=new Set(e),o=t??v.map((s,c)=>c);for(const s of o){const c=k[s],i=v[s];if(!c||!i)continue;const d=c.dies.filter(l=>n.has(mo(l)));i.setSelection(d)}}function at(){const e=f.ownerDocument.createElement("div");Object.assign(e.style,{display:"flex",gap:"4px",marginBottom:"10px",borderBottom:`1px solid ${g.menuBorder}`,paddingBottom:"8px"});for(const t of["lot","wafers"]){const n=f.ownerDocument.createElement("button");n.type="button",n.textContent=t==="lot"?"Lot":"Findings";const o=le===t;Object.assign(n.style,{border:"none",borderRadius:"4px",padding:"2px 8px",fontSize:"11px",cursor:"pointer",fontWeight:o?"600":"400",background:o?g.bgActive:"transparent",color:o?g.iconHover:g.icon}),n.addEventListener("click",()=>{le=t,$e(),Pe(),R()}),e.appendChild(n)}return e}function Yt(){if(!m)return;m.innerHTML="",E&&m.appendChild(at());const e=[];for(let n=0;n<w.length;n++){const o=w[n];if(!o)continue;const s=nt(n)?.findings??[];if(!s.length)continue;const c=s.filter(d=>d.severity==="unusual").length,i=s.filter(d=>d.severity==="notable").length;e.push({index:n,item:o,unusualCount:c,notableCount:i,totalCount:s.length})}if(w.length>0){const n=f.ownerDocument.createElement("div"),o=e.length,s=w.filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${s} wafers`:`${o} of ${s} wafer${s===1?"":"s"} with findings`,Object.assign(n.style,{fontSize:"11px",color:g.label,marginBottom:"8px"}),m.appendChild(n)}if(e.length>0){const n=f.ownerDocument.createElement("button");n.type="button",n.textContent="Findings report",Object.assign(n.style,{border:`1px solid ${g.menuBorder}`,borderRadius:"4px",padding:"3px 8px",marginBottom:"10px",fontSize:"10px",color:g.iconHover,background:"none",cursor:"pointer",display:"block",width:"100%",textAlign:"left"}),n.addEventListener("click",()=>{const o=`Findings report \u2014 ${e.length} wafer${e.length>1?"s":""}`,s=new Date().toLocaleString(),c=e.map(({item:d,index:l})=>{const a=nt(l),u=d.label??`W${l+1}`,h=a.findings.map(b=>`<li>${uo(b.severity)} ${ye(b.summary)}</li>`).join("");return co(ye(u),`<ul style="margin:0;padding-left:18px;list-style:none">${h}</ul>`)}).join(`
|
|
2
|
-
`),i=`<!DOCTYPE html>
|
|
3
|
-
<html lang="en">
|
|
4
|
-
<head>
|
|
5
|
-
<meta charset="UTF-8">
|
|
6
|
-
<title>${ye(o)}</title>
|
|
7
|
-
<style>
|
|
8
|
-
${fo()}
|
|
9
|
-
</style>
|
|
10
|
-
</head>
|
|
11
|
-
<body>
|
|
12
|
-
<main class="report">
|
|
13
|
-
<header class="report-header">
|
|
14
|
-
<h1>${ye(o)}</h1>
|
|
15
|
-
<p class="report-subtitle">Generated ${ye(s)}</p>
|
|
16
|
-
</header>
|
|
17
|
-
${c}
|
|
18
|
-
</main>
|
|
19
|
-
</body>
|
|
20
|
-
</html>`;An(i,{anchor:f})}),m.appendChild(n)}if(e.length===0){const n=f.ownerDocument.createElement("div");Object.assign(n.style,{color:g.icon,fontSize:"11px",padding:"4px 0"}),n.textContent="No findings on any wafer.",m.appendChild(n)}else for(const{index:n,item:o,unusualCount:s,notableCount:c,totalCount:i}of e){const d=s?"unusual":c?"notable":"info",l=s+c||i,a=f.ownerDocument.createElement("button");a.type="button",Object.assign(a.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:"4px",border:"none",borderLeft:`3px solid ${Tt(d)}`,borderRadius:"3px",background:g.bgHover,cursor:"pointer",fontSize:"11px",textAlign:"left",boxSizing:"border-box"}),a.addEventListener("mouseover",()=>{a.style.background=g.bgActive}),a.addEventListener("mouseout",()=>{a.style.background=g.bgHover});const u=f.ownerDocument.createElement("span");u.textContent=o.label??`W${n+1}`,Object.assign(u.style,{color:g.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const h=f.ownerDocument.createElement("span");h.textContent=String(l),a.setAttribute("aria-label",`${o.label??`W${n+1}`} \u2014 ${l} finding${l===1?"":"s"}${s?`, ${s} unusual`:""} \u2014 view wafer`),Object.assign(h.style,{marginLeft:"6px",flexShrink:"0",background:Tt(d),color:"#fff",borderRadius:"8px",padding:"1px 5px",fontSize:"10px",fontWeight:"600"}),a.appendChild(u),a.appendChild(h),a.addEventListener("click",()=>Oe(n,o)),m.appendChild(a)}const t=f.ownerDocument.createElement("div");t.style.height="12px",m.appendChild(t)}function R(){if(m)if(le==="lot"&&E){const e=We(w.flatMap(n=>n?.hbinDefs??[])),t=We(w.flatMap(n=>n?.sbinDefs??[]));ro(m,{lotSummary:E,items:w,hbinDefs:e.length?e:void 0,sbinDefs:t.length?t:void 0,testDefs:w.find(n=>n?.testDefs?.length)?.testDefs,passBins:Je,ringCount:r.ringCount,colorScheme:r.colorScheme,fallbackFormat:we,activeFindingId:ae,warnings:p.warnings?.display??!0?_:[],findingsFilter:qt,onFindingsFilterChange:R,onSaveText:p.onSaveText,onFindingClick:(n,o)=>{ae===n.id?Ae():Zt(n,o),R()},onWaferClick:n=>{Ie([n])},dieListOptions:p.dieList}),Ce()&&m.insertBefore(at(),m.firstChild)}else Yt()}function lt(e){return[e.variable.kind,e.variable.index??"",e.variable.bin??"",e.comparison.family,e.comparison.left,e.effect.direction].join("|")}function Ae(){ae=null,$e(),Pe(),C({highlightBin:void 0},{fireCallback:!1})}function Zt(e,t){if(ae===e.id){Ae();return}ae=e.id,t.style.background=g.bgActive,t.style.fontWeight="600";const{kind:n,index:o}=e.variable;n==="test"?C({plotMode:"value",activeTest:o??0,highlightBin:void 0},{fireCallback:!1}):n==="softBin"?C({plotMode:"softBin",highlightBin:void 0},{fireCallback:!1}):C({plotMode:"hardBin",highlightBin:void 0},{fireCallback:!1}),$e(),Pe();const s=e.highlight;if(s.kind==="wafer"){Ie(s.waferIndices);const c=lt(e);for(const i of s.waferIndices){const a=k[i]?.statsSummary?.findings.find(u=>lt(u)===c)?.highlight?.dieKeys;a?.length&&Fe(a,[i])}}else s.kind==="bin"?s.dieKeys?.length&&Fe(s.dieKeys):(s.kind==="region"||s.kind==="dies")&&s.dieKeys?.length&&Fe(s.dieKeys)}function X(){if(!O)return;const e=!!m;O.style.display=(E||Ce())&&e&&!je?"flex":"none";const t=m?m.style.display!=="none":!1;(E?.hasNotableFindings||w.some(o=>o?.statsSummary?.hasNotableFindings))&&!t?O.style.color=g.findingIndicator:O.dataset.active||(O.style.color=g.icon)}const T=f.ownerDocument.createElement("div");T.dataset.wmapToolbar="gallery",Object.assign(T.style,{display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:"6px",padding:"3px 4px",marginBottom:"10px",boxShadow:"0 1px 4px rgba(0,0,0,0.10)",flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const st=()=>{const e=re();e&&(e.remove(),de(null)),be(j,!1)},j=N("mode","Plot mode",()=>{if(re()){st();return}const e=w.flatMap(b=>b?.dies??[]),t=w.find(b=>b?.testDefs?.length)?.testDefs,{testEntries:n,binEntries:o,stackedEntries:s}=Qn(e,t,{includeStacked:!0}),c=r.plotMode??"hardBin",i=r.activeTest??0;function d(b){return b.plotMode!==c?!1:b.plotMode==="value"?i===(b.activeTest??0):b.plotMode==="metadata"?r.activeMetadataKey===b.activeMetadataKey:!0}function l(b,S){b.activeTest!==void 0?C({plotMode:"value",activeTest:b.activeTest,activeMetadataKey:void 0,logScale:b.logScale}):b.activeMetadataKey!==void 0?C({plotMode:b.plotMode,activeTest:void 0,activeMetadataKey:b.activeMetadataKey,passFailDisplay:"off"}):C({plotMode:b.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),S.remove(),de(null),be(j,!1)}const a=new Set,u=w.flatMap(b=>b?.metadataFields??[]).filter(b=>!a.has(b.key)&&a.add(b.key)).filter(b=>Yn(e,b.key)).map(Zn),h=In(j.getBoundingClientRect(),n,o,s,d,l,{makeMenuRow:Ut,makeMenuSection:Qt},c,j.ownerDocument.defaultView??window,u);It(j).appendChild(h),de(h),be(j,!0),$t(h,j,st)});be(j,!1);const Jt=()=>k.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:en,sync:rt}=Vn(J,()=>r.plotMode??"hardBin",()=>r.colorScheme??"default",Jt,e=>C({colorScheme:e}),{get:()=>r.markFailingDies??!1,set:e=>C({markFailingDies:e})});rt();const tn=D.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function He(){const e=w.find(n=>n?.testDefs?.length)?.testDefs,{testNumber:t}=Dn(r.activeTest??0,e);return{testNumber:t,td:Bn(e,t)}}function dt(){if((r.plotMode??"hardBin")!=="value")return!1;const{td:e}=He();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function ce(){if((r.plotMode??"hardBin")!=="value")return!1;const{td:e}=He();return e!==void 0&&!At(e)}function nn(){if((r.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=He();return w.some(n=>n?.dies?.some(o=>no(o,e,t)!==void 0))}const on=Gn(J,()=>[{label:"Ring boundaries",active:!!r.showRingBoundaries,onClick:()=>C({showRingBoundaries:!r.showRingBoundaries})},{label:"Quadrant lines",active:!!r.showQuadrantBoundaries,onClick:()=>C({showQuadrantBoundaries:!r.showQuadrantBoundaries})},{label:"Die labels",active:!!r.showDieLabels,onClick:()=>C({showDieLabels:!r.showDieLabels})},{label:"Reticle grid",active:!!r.showReticle,enabled:tn,onClick:()=>C({showReticle:!r.showReticle})},{label:"XY indicator",active:!!r.showXYIndicator,onClick:()=>C({showXYIndicator:!r.showXYIndicator})},...Xn({functionalActive:ce(),hasLimits:dt()&&!ce(),hasRecorded:nn()&&!ce(),display:Ue(r)},e=>C({passFailDisplay:e}))],()=>!!(r.showRingBoundaries||r.showQuadrantBoundaries||r.showDieLabels||r.showReticle||r.showXYIndicator||Ue(r)!=="off")),{btn:an,sync:ct}=_n(J,()=>({plotMode:r.plotMode,legendPosition:oe}),e=>{oe=e;for(const t of v)t&&t.setOptions({legendPosition:oe})},{get:()=>xe,set:e=>{xe=e,et()},blockedReason:ie});ct();const ln=[{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"}],ut=ot("aggr","Aggregation method",()=>ln,()=>r.aggregationMethod??"mean",e=>C({aggregationMethod:e}));function ft(){const e=r.plotMode==="stackedValues";ut.style.display=e?"":"none"}ft();const{btn:sn,sync:pt}=Nn(J,()=>({...r,functionalActive:ce()}),e=>C(e));pt();const Me=N("specRange","Colorbar range: spec limits",()=>{const e=r.colorbarRangeMode==="data"?"spec":"data";C({colorbarRangeMode:e})});function mt(){const e=(r.plotMode??"hardBin")==="value"&&dt()&&Ue(r)==="off"&&!ce();Me.style.display=e?"":"none";const t=(r.colorbarRangeMode??"spec")==="spec";se(Me,t),Me.ariaLabel=t?"Colorbar range: spec limits (click for data range)":"Colorbar range: data range (click for spec limits)"}mt();const rn=Kn(J,()=>r,e=>C(e)),dn=N("downloadAll","Download gallery PNG",Sn),cn=ot("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"}],()=>W!=null?String(W):"auto",e=>Mt(e==="auto"?void 0:Number(e))),M=f.ownerDocument.createElement("div");Object.assign(M.style,{display:"inline-flex",alignItems:"center",gap:"0"}),T.appendChild(M),Vt&&M.appendChild(j),M.appendChild(en),M.appendChild(ut),M.appendChild(sn),M.appendChild(Me),M.appendChild($()),M.appendChild(on),M.appendChild($()),M.appendChild(an),M.appendChild($()),M.appendChild(rn),M.appendChild($()),M.appendChild(cn),M.appendChild($()),M.appendChild(dn),(E||Ce())&&(O=N("findings","Summary panel",()=>{if(!m)return;const e=m.style.display!=="none";e||R(),m.style.display=e?"none":"flex",se(O,!e),X()}),T.appendChild($()),T.appendChild(O));let P=null,ke=null,_=[],gt=!1;function ht(){const e=oo({lotStatsSummary:E,result:{warnings:w.flatMap(n=>n?.warnings??[])}}),t=e.length!==_.length||e.some((n,o)=>n.code!==_[o]?.code||n.message!==_[o]?.message);_=e,(t||!gt)&&(gt=!0,p.warnings?.onWarning?.(e)),un()}function un(){if(!P||!ke)return;const e=_.length,t=e>0;if(P.style.display=t?"flex":"none",ke.style.display=t?"":"none",!t)return;const n=ao(_[0]),o=`${e} data ${e===1?"warning":"warnings"}`;P.style.color=n==="error"?g.errText:g.warnText,P.ariaLabel=n==="error"?`${o} \u2014 wafers in this lot may be positionally wrong`:o}(p.warnings?.display??!0)&&(ke=$(),P=N("warning","Data warnings",()=>{const e=re();if(Se(new MouseEvent("click")),e)return;const t=io(P.getBoundingClientRect(),_,P.ownerDocument.defaultView??window);It(f).appendChild(t),de(t),$t(t,P,()=>Se(new MouseEvent("click")))}),be(P,!1),T.appendChild(ke),T.appendChild(P)),ht();let U=null;Ze&&(U=N("analysis","Insights",()=>{const e=ee?.style.display!=="none";yt(!e)}),U.dataset.wmapInsightsBtn="1",T.appendChild($()),T.appendChild(U));function bt(){import("./userGuideHtml.js").then(e=>zn({buildWaferMap:to,renderWaferMap:Qe,renderWaferGallery,analyzeWaferMap:Le},e.USER_GUIDE_HTML,_t,f))}Nt&&(T.appendChild($()),T.appendChild(N("help","User guide",()=>bt())));const G=f.ownerDocument.createElement("div");G.dataset.wmapGalleryLegend="1",Object.assign(G.style,{display:"flex",flexDirection:"column",gap:"6px",background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:"6px",padding:"6px 10px",marginBottom:"10px",boxShadow:"0 1px 4px rgba(0,0,0,0.10)",fontSize:"12px",lineHeight:"1",boxSizing:"border-box",width:"100%",minWidth:"0"});const F=f.ownerDocument.createElement("div");Object.assign(F.style,{display:"flex",flexDirection:"row",gap:"12px",alignItems:"flex-start"});let ue=null,ee=null;Ze&&(ue=po({getItems:()=>w,getLotStats:()=>E,getColorSchemeName:()=>r.colorScheme??"default",passBins:Je,getRingCount:()=>r.ringCount??4,defaultView:p.insights?.defaultView,backTab:{label:"Gallery",onBack:()=>yt(!1)},showMetadataStrip:!1,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,ownerDocument:f.ownerDocument,openWafer:(e,t,n)=>{const o=w[e];if(!o)return;let s=null;const c=Fn({title:t,onClose:()=>s?.destroy(),anchor:f});Bt(c,t,o.wafer.metadata??void 0),s=Ge(c.contentWrap,o,n)}}),ee=ue.el);let je=!1;function yt(e){!ue||!ee||(je=e,ee.style.display=e?"flex":"none",F.style.display=e?"none":"flex",M.style.display=e?"none":"inline-flex",U&&(se(U,e),U.innerHTML=e?ge.wafer:ge.analysis,U.ariaLabel=e?"Back to gallery view":"Insights"),X(),Ee(),e&&ue.render())}const fn=4,ze=240,wt=480,pn=720,mn=1.25,xt=p.maxSize;let z=xt??wt;function vt(e){const t=Q*2+110+2;let n=null;for(const o of e){if(o==null||!o.dies?.length)continue;const s=o.dies[0].width;if(!(s>0))continue;const c=o.wafer.radius*2*(fn/s),i=Math.ceil(c+t);(n==null||i>n)&&(n=i)}return n}function gn(e){const t=vt(e);return t==null?ze:Math.min(z,Math.max(ze,t))}function hn(e){if(xt!=null)return!1;const t=vt(e);if(t==null)return!1;const n=Math.min(pn,Math.max(wt,t));return n<=z?!1:(z=n,!0)}function bn(){for(const e of Array.from(B.children))e.classList.contains("wmap-gallery-card")&&(e.style.maxWidth=`${z}px`,e.style.maxHeight=`${z}px`)}let De=ze,Ct=0;function St(e){const t=hn(e);if(t&&bn(),W!=null){t&&Be();return}const n=gn(e);n>De&&(De=n),Be()}function Mt(e){W=e,Be()}function Ve(e){return`repeat(${e}, minmax(0, ${z}px))`}function kt(e){B.style.gridTemplateColumns!==e&&(B.style.gridTemplateColumns=e)}function Be(){if(W!=null){kt(Ve(W));return}const e=Math.max(1,Ct),t=12,n=B.clientWidth||0,o=c=>(n-t*(c-1))/c;let s=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const c=Math.min(z,De*mn),i=d=>{let l=0;for(;l<e&&o(l+1)>=d;)l++;return l};s=i(c)||i(De)||1}kt(Ve(s))}const B=f.ownerDocument.createElement("div");if(Object.assign(B.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:Ve(1),gap:"12px",justifyContent:"start",alignContent:"start",isolation:"isolate"}),le=E?"lot":"wafers",Y?.placement){const e=Y.placement;m=Ye(e,f.ownerDocument),m.style.maxHeight="calc(100vh - 80px)",m.style.position="sticky",m.style.top="8px",m.style.display="flex",m.style.flexDirection="column"}else if(E||Ce()){const e=!!Y?.defaultOpen;m=Ye("right",f.ownerDocument),m.style.maxHeight="calc(100vh - 80px)",m.style.position="sticky",m.style.top="8px",m.style.flexDirection="column",m.style.display=e?"flex":"none",R()}X(),m?.style.display!=="none"&&O&&se(O,!0),(Y?.placement??"right")==="left"?(m&&F.appendChild(m),F.appendChild(B)):(F.appendChild(B),m&&F.appendChild(m));const fe=f.ownerDocument.createElement("div");Object.assign(fe.style,{position:"sticky",top:"0",zIndex:"1",background:g.menuBg}),fe.appendChild(T),fe.appendChild(G),f.appendChild(fe),f.appendChild(F),ee&&f.appendChild(ee);function Ee(){G.innerHTML="";const e=r.plotMode??"hardBin",t=!je&&Lt.has(e),n=k.filter(y=>y!=null),o=n.find(y=>y.isLotStack),s=so(n.map(y=>({metadata:y.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0),c=e==="metadata",i=r.activeMetadataKey,d=new Set;if(t&&!c)for(const y of n)for(const L of y.dies){if(L.partial)continue;const x=e==="softBin"?L.sbin:L.hbin;x!=null&&d.add(x)}const l=t&&!c?[...d].sort((y,L)=>y-L):[],a=new Set;if(t&&c&&i)for(const y of n)for(const L of y.dies){if(L.partial)continue;const x=L.metadata?.[i];x!=null&&(typeof x=="string"||typeof x=="number"||typeof x=="boolean")&&a.add(String(x))}const u=t&&c?[...a].sort(lo):[];if(!s&&!l.length&&!u.length){G.style.display="none";return}if(G.style.display="flex",s&&G.appendChild(s),!l.length&&!u.length)return;const h=f.ownerDocument.createElement("div");Object.assign(h.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:"6px 14px"}),s&&Object.assign(h.style,{borderTop:`1px solid ${g.separator}`,paddingTop:"6px"}),G.appendChild(h);const b=En(r.colorScheme),S=r.highlightBin;if(c){const y=r.highlightMetadataValue,L=k.flatMap(x=>x?.metadataFields??[]).find(x=>x.key===i);u.forEach((x,Ke)=>{const qe=y===x,Ot=L?.values?.find(Xe=>Xe.value===x),Mn=Ot?.color??On(Ke);zt(h,{color:Mn,isActive:qe,label:Ot?.label??x,onClick:()=>{const Xe=r.highlightMetadataValue===x?void 0:x;C({highlightMetadataValue:Xe})}})});return}const A=e==="softBin"?k.flatMap(y=>y?.sbinDefs??[]):k.flatMap(y=>y?.hbinDefs??[]),H=new Set,K=[];for(const y of A)H.has(y.bin)||(H.add(y.bin),K.push(y));const me=K.length>0?new Map(K.map(y=>[y.bin,y])):null;for(const y of l){const L=S===y,x=me?.get(y),Ke=(r.colorScheme==="custom"?x?.color:void 0)??b.forBin(y);zt(h,{color:Ke,isActive:L,label:x?.name?`${y} \xB7 ${x.name}`:`Bin ${y}`,onClick:()=>{const qe=r.highlightBin===y?void 0:y;C({highlightBin:qe})}})}}function pe(e){const t=w.filter(d=>d!==null);if(!t.length)return[];const n=t.map(d=>d.dies.filter(go)),o=t[0].wafer,s=t.length,c=o.metadata?{...o,metadata:(({wafer:d,waferId:l,...a})=>a)(o.metadata)}:o;function i(d,l){return{...d,stats:{...d.stats,isLotStack:!0,aggregationMethod:l,lotSize:s}}}if(e==="stackedValues"){const d=t.find(u=>u.testDefs?.length)?.testDefs;let l=d?.filter(At);if(d?.length||(l=kn(t.flatMap(h=>h.dies)).map(h=>({testNumber:h,name:`Test ${h}`}))),!l?.length)return[];const a=r.aggregationMethod??"mean";return l.map(u=>{const h=Jn(n,a,u.testNumber),b={testNumber:0,name:u.name,unit:u.unit};return{wafer:c,dies:h,testDefs:[b],label:`${u.name} \xB7 ${a}`,isLotStack:!0,aggrMethod:a,lotSize:s,statsSummary:i(Le({wafer:c,dies:h,testDefs:[b]},{testNumbers:[0]}),a)}})}if(e==="stackedBins"){let d=We(t.flatMap(l=>l.hbinDefs??[]));return(!d||d.length===0)&&(d=[...new Set(t.flatMap(a=>a.dies.map(u=>u.hbin).filter(u=>u!=null)))].sort((a,u)=>a-u).map(a=>({bin:a,name:`Bin ${a}`}))),d.map(l=>{const a=Ft(n,l.bin,"hard"),u=[{bin:l.bin,name:l.name}];return{wafer:c,dies:a,hbinDefs:u,label:`${l.bin} \xB7 ${l.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:s,statsSummary:i(Le({wafer:c,dies:a,hbinDefs:u}),"countBin")}})}if(e==="stackedSoftBins"){let d=We(t.flatMap(l=>l.sbinDefs??[]));return(!d||d.length===0)&&(d=[...new Set(t.flatMap(a=>a.dies.map(u=>u.sbin).filter(u=>u!=null)))].sort((a,u)=>a-u).map(a=>({bin:a,name:`Bin ${a}`}))),d.map(l=>{const a=Ft(n,l.bin,"soft"),u=[{bin:l.bin,name:l.name}];return{wafer:c,dies:a,sbinDefs:u,label:`${l.bin} \xB7 ${l.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:s,statsSummary:i(Le({wafer:c,dies:a,sbinDefs:u}),"countBin")}})}return t}function Ne(e){const t=w.length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:r.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}const yn=new Set(["default","accessible","custom"]);function C(e,{fireCallback:t=!0}={}){const n=r.plotMode,o=ie()!==null;r={...r,...e};const s=r.plotMode,c=he.has(s),i=n!==void 0&&he.has(n),d=ve>0;if(e.plotMode!==void 0&&e.plotMode!==n&&(s==="hardBin"||s==="softBin")&&!yn.has(r.colorScheme??"")&&(r={...r,colorScheme:"default"}),e.plotMode!==void 0)if(c){const a=Ne(s);if(r={...r,...a},d)for(const u of v)u&&u.setOptions(e);else V(pe(s))}else if(i){const{valueRange:a,lotSize:u,aggregationMethod:h,...b}=r;if(r=b,d)for(const S of v)S&&S.setOptions(e);else V(w.filter(S=>S!==null))}else for(const a of v)a&&a.setOptions(e);else if(e.aggregationMethod!==void 0&&s==="stackedValues")if(d)for(const a of v)a&&a.setOptions(e);else V(pe("stackedValues"));else for(const a of v)a&&a.setOptions(e);ie()!==null!==o&&et(),Ee(),ft(),ct(),rt();const l=e.plotMode!==void 0&&e.plotMode!==n;if((e.colorScheme!==void 0||l)&&R(),pt(),mt(),t){const a=Object.keys(e);p.onViewOptionsChange?.(r,a,eo(a))}}function Dt(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:"4px",flex:"1",minWidth:"0"});const s=e.createElement("span");s.textContent=t,Object.assign(s.style,{fontWeight:"700",fontSize:"13px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(s);const c=jt(n??{});let i=null;if(c.length>0){const d=e.createElement("span");Object.assign(d.style,{fontSize:"12px",lineHeight:"1",color:g.label,flexShrink:"0"}),d.textContent="\u25BE",o.appendChild(d),Object.assign(o.style,{cursor:"pointer"}),i=e.createElement("div"),i.dataset.wmapCardMetaPanel="1",Object.assign(i.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:Wt,background:g.menuBg,borderBottom:`1px solid ${g.menuBorder}`,boxShadow:"0 2px 6px rgba(0,0,0,0.15)",padding:"8px 10px",fontSize:"11px",display:"none"});const l=Ht(n??{});l&&i.appendChild(l),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`Wafer info for ${t||"this card"}. Click to expand.`),Pt(o,a=>{d.textContent=a?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(a)),i&&(i.style.display=a?"block":"none")})}return{wrap:o,metaPanel:i}}function Bt(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]"),s=jt(n??{});if(!o||s.length===0)return;const c=o.parentElement,i=f.ownerDocument.createElement("div");Object.assign(i.style,{display:"flex",alignItems:"center",gap:"4px",flex:"1",minWidth:"0",cursor:"pointer"}),c?.insertBefore(i,o),i.appendChild(o);const d=f.ownerDocument.createElement("span");Object.assign(d.style,{fontSize:"12px",lineHeight:"1",color:g.label,flexShrink:"0"}),d.textContent="\u25BE",i.appendChild(d);const l=f.ownerDocument.createElement("div");l.dataset.wmapCardMetaPanel="1",Object.assign(l.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:Wt,background:g.menuBg,borderBottom:`1px solid ${g.menuBorder}`,boxShadow:"0 2px 6px rgba(0,0,0,0.15)",padding:"8px 10px",fontSize:"11px",display:"none"});const a=Ht(n??{});a&&l.appendChild(a),e.contentWrap.style.position="relative",e.contentWrap.appendChild(l),i.setAttribute("aria-expanded","false"),i.setAttribute("aria-label",`Wafer info for ${t}. Click to expand.`),Pt(i,u=>{d.textContent=u?"\u25B4":"\u25BE",i.setAttribute("aria-expanded",String(u)),l.style.display=u?"block":"none"})}function _e(e,t,n){const o=f.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:"10px",overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:`${z}px`,maxHeight:`${z}px`});const s=f.ownerDocument.createElement("div");Object.assign(s.style,{display:"flex",alignItems:"center",padding:"8px 10px 6px",borderBottom:`1px solid ${g.menuBorder}`,flexShrink:"0",gap:"6px"});const{wrap:c,metaPanel:i}=Dt(document,e.label??"",e.wafer.metadata??void 0);s.appendChild(c);const d=f.ownerDocument.createElement("button");d.dataset.wmapExpandBtn="1",d.title="Open full view",d.innerHTML=ge.expand,Object.assign(d.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${g.menuBorder}`,borderRadius:"4px",background:g.panelBg,color:g.label,padding:"2px",cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),s.appendChild(d),o.appendChild(s);const l=f.ownerDocument.createElement("div");Object.assign(l.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(l),i&&l.appendChild(i),B.appendChild(o);const a=xe||ie()!==null,u=e.viewOptions?{...r,...e.viewOptions}:r,h=Qe(l,e,{viewOptions:{...u,showLegend:a},toolbarControls:"full",showTooltip:!0,padding:Q,legendPosition:oe,fallbackFormat:we,statsSummary:e.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,onClick:e.onClick,onSelect:e.onSelect,onExpand:()=>Oe(t,e),showMetadataBadge:!1});return h.setViewControlsVisible(!1),h.setSummaryVisible(!1),d.onclick=()=>Oe(t,e),{card:o,ctrl:h,canvasWrapper:l,expandBtn:d}}function wn(e){const t=Z[e];if(!t)return;const n=[...I.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=ge.minimize,t.title="Reattach to gallery",t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>vn(n.id)):(t.innerHTML=ge.expand,t.title="Open full view",t.setAttribute("aria-label","Open full view"),t.onclick=()=>Oe(e,k[e]))}function V(e){Cn(),re()?.remove(),de(null),Ae(),k=[];for(const i of v)i&&i.destroy();v=[],q=[],Z=[],ve=0,B.innerHTML="",Ct=e.length,St(e.map(i=>typeof i=="function"?null:i));const t=[];for(let i=0;i<e.length;i++){const d=e[i];if(typeof d=="function"){const l=f.ownerDocument.createElement("div");l.className="wmap-gallery-card",Object.assign(l.style,{background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:"10px",aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const a=f.ownerDocument.createElement("span");a.textContent="\u2026",Object.assign(a.style,{color:g.label,fontSize:"18px"}),l.appendChild(a),B.appendChild(l),k.push(null),v.push(null),q.push(null),Z.push(null),t.push({index:i,factory:d,placeholder:l}),ve++}else{const{ctrl:l,canvasWrapper:a,expandBtn:u}=_e(d,i,e.length);k.push(d),v.push(l),q.push(a),Z.push(u)}}k.flatMap(i=>i?[...i.hbinDefs??[],...i.sbinDefs??[]]:[]).some(i=>i.color)&&!p.viewOptions?.colorScheme&&(r={...r,colorScheme:"custom"}),Ee();const o=++Re;let s=0;function c(){if(o!==Re)return;if(s>=t.length){if(he.has(r.plotMode)){const A=r.plotMode;V(pe(A))}return}const{index:i,factory:d,placeholder:l}=t[s++],a=d();k[i]=a,w[i]=a,St([a]);const{card:u,ctrl:h,canvasWrapper:b,expandBtn:S}=_e(a,i,e.length);v[i]=h,q[i]=b,Z[i]=S,ve--,l.replaceWith(u),Ee(),!m&&!Y?.placement&&a.statsSummary?.findings.length?(E||(le="wafers"),m=Ye("right",f.ownerDocument),m.style.maxHeight="calc(100vh - 80px)",m.style.position="sticky",m.style.top="8px",m.style.flexDirection="column",m.style.display="none",(Y?.placement??"right")==="left"?F.insertBefore(m,B):F.appendChild(m),R(),O||(O=N("findings","Summary panel",()=>{if(!m)return;const H=m.style.display!=="none";H||R(),m.style.display=H?"none":"flex",se(O,!H),X()}),T.appendChild($()),T.appendChild(O)),X()):m&&m.style.display!=="none"&&R(),X(),setTimeout(c,0)}t.length>0&&setTimeout(c,0)}if(he.has(r.plotMode)&&w.length>0){const e=Ne(r.plotMode);r={...r,...e},V(pe(r.plotMode))}else V(D);let te=0;const Et=new(f.ownerDocument.defaultView??window).ResizeObserver(()=>{if(te)return;te=(f.ownerDocument.defaultView??window).requestAnimationFrame(()=>{te=0,W==null&&Be()})});Et.observe(B),m&&R();function xn(e,t){const n=q[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:g.label,fontSize:"12px",textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function Oe(e,t){for(const i of I.values())if(i.cardIndex===e)return;const n=t.label??"Wafer map",o=Kt++,s=v[e]?.getOptions(),c=$n(n);if(c){const i=c.document;i.title=n,Object.assign(i.documentElement.style,{height:"100%"}),Object.assign(i.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:'system-ui, -apple-system, "Segoe UI", sans-serif'}),Hn(f,i.documentElement);const d=jn(f,i.documentElement,()=>A.setOptions({})),l=i.createElement("div");l.dataset.wmapWindowBanner="1",l.textContent=n,Object.assign(l.style,{display:"none",padding:"6px 12px",fontSize:"12px",fontWeight:"700",background:g.warnBg,color:g.warnText,borderBottom:`1px solid ${g.warnBorder}`,flexShrink:"0"}),i.body.appendChild(l);const a=i.createElement("div");Object.assign(a.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),i.body.appendChild(a);const{wrap:u,metaPanel:h}=Dt(i,n,t.wafer.metadata??void 0),b=i.createElement("div");Object.assign(b.style,{display:"flex",alignItems:"center",padding:"8px 10px 6px",borderBottom:`1px solid ${g.menuBorder}`,flexShrink:"0",gap:"6px"}),b.appendChild(u),a.appendChild(b);const S=i.createElement("div");Object.assign(S.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),h&&S.appendChild(h),a.appendChild(S);const A=Ge(S,t,void 0,s),H=setInterval(()=>{c.closed&&Te(o)},400);c.addEventListener("pagehide",()=>Te(o)),I.set(o,{id:o,ctrl:A,cardIndex:e,label:n,closePollId:H,stopThemeSync:d,close:()=>{c.closed||c.close()},setTitle:K=>{i.title=K,l.textContent=K,l.style.display="block"}})}else{const i=Pn({title:n,onClose:()=>Te(o),anchor:f});i.contentWrap.style.flexDirection="column",Bt(i,n,t.wafer.metadata??void 0);const d=Ge(i.contentWrap,t,void 0,s);I.set(o,{id:o,ctrl:d,cardIndex:e,label:n,closePollId:null,close:()=>i.close(),setTitle:l=>{const a=i.box.querySelector("[data-wmap-window-title]");a&&(a.textContent=l,a.title=l)}})}v[e]?.destroy(),v[e]=null,xn(e,c!==null),wn(e)}function Ge(e,t,n,o){const s=t.viewOptions?{...r,...t.viewOptions}:r,c=o?{...s,...o}:s,d={...n!==void 0?{...c,plotMode:"value",activeTest:n}:c,showLegend:!0},l=Qe(e,t,{viewOptions:d,toolbarControls:"full",showTooltip:!0,padding:Q,legendPosition:oe,fallbackFormat:we,statsSummary:t.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,onClick:t.onClick,onSelect:t.onSelect,showExpandButton:!1,showMetadataBadge:!1});return l.setViewControlsVisible(!0),l.setSummaryVisible(!0),l.setExpandVisible(!1),l}function Te(e){const t=I.get(e);if(!t)return;I.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.();const n=t.ctrl.getOptions();if(t.ctrl.destroy(),t.cardIndex===null)return;const o=t.cardIndex,s=k[o];if(!s)return;const c={...s,viewOptions:n};k[o]=c;const{card:i,ctrl:d,canvasWrapper:l,expandBtn:a}=_e(c,o,k.length);q[o]?.parentElement?.replaceWith(i),v[o]=d,q[o]=l,Z[o]=a}function vn(e){const t=I.get(e);t&&(t.close(),Te(e))}function Cn(){for(const e of I.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function Sn(){const e=[...B.querySelectorAll("canvas")];if(!e.length)return;const t=e.length,n=Math.ceil(Math.sqrt(t)),o=Math.ceil(t/n),s=e[0].width,c=e[0].height,i=8,d=window.devicePixelRatio||1,l=Math.round(26*d),a=Math.round(12*d),u=f.ownerDocument.createElement("canvas");u.width=n*s+(n-1)*i,u.height=o*(c+l)+(o-1)*i;const h=u.getContext("2d"),b=Tn(B);h.fillStyle=b.background,h.fillRect(0,0,u.width,u.height),e.forEach((S,A)=>{const H=A%n,K=Math.floor(A/n),me=H*(s+i),y=K*(c+l+i),L=S.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";h.fillStyle=b.surface,h.fillRect(me,y,s,l),h.fillStyle=b.text,h.font=`700 ${a}px system-ui, sans-serif`,h.textAlign="left",h.textBaseline="middle",h.fillText(L,me+Math.round(10*d),y+l/2,s-Math.round(20*d)),h.drawImage(S,me,y+l)}),u.toBlob(S=>{S&&qn(S,ne,p.onSaveImage)})}return{setItems(e){w=e.map(n=>typeof n=="function"?null:n);const t=r.plotMode;if(he.has(t))if(e.some(o=>typeof o=="function"))V(e);else{const o=Ne(t);r={...r,...o},V(pe(t))}else V(e)},setOptions(e){C(e,{fireCallback:!1})},getOptions(){return{...r}},setFallbackFormat(e){we=e;for(const t of v)t&&t.setFallbackFormat(e)},setLotStatsSummary(e){E=e,ht(),m&&R(),X()},setColumns(e){Mt(e)},openUserGuide:bt,destroy(){Re++;for(const e of[...I.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();I.clear();for(const e of v)e&&e.destroy();v=[],re()?.remove(),Et.disconnect(),te&&((f.ownerDocument.defaultView??window).cancelAnimationFrame(te),te=0),f.ownerDocument.removeEventListener("click",Se,!0),window.removeEventListener("blur",it),Gt(),Rt(),fe.remove(),F.remove(),m?.remove(),ue?.destroy()}}}
|
|
1
|
+
import{getUniqueTestNumbers as oo,resolveTestNumber as io,findTestDef as lo}from"../renderer/buildView.js";import{getColorScheme as ao}from"../renderer/colorSchemes.js";import{metadataValueColor as so}from"../renderer/colorMap.js";import{resolveCanvasTheme as ro}from"./canvasTheme.js";import{ICONS as Te}from"./icons.js";import{SHADOW as Le,LEADING as Xe,TRACKING as co,controlStyle as uo,wireControlHover as pt,SPACE as w,EDGE_GUTTER as ne,MAP_CHROME_INSET as fo,RADIUS as z,FONT as T,CLR as g,sevColor as tn,MODE_LABELS as po,BIN_LEGEND_MODES as nn,STACKED_MODES as he,Z_ABOVE as on,applyOverlayZ as go,getTooltip as mo,hideTooltip as ln,createToolbarHelpers as ho,buildModeMenuEl as bo,openDetachWindow as yo,openFloatingWindow as wo,openModal as xo,openReportModal as vo,copyWmapThemeTokens as So,syncWmapPopupTheme as Co,openUserGuideWindow as Mo,makePaletteBtn as Do,makeLogScaleBtn as ko,makeLegendStyleBtn as Eo,makeOverlaysBtn as Bo,makeOrientationBtn as Oo,menuLayerFor as an,saveImageBlob as To,markMenuTrigger as $e,wireMenuA11y as sn,wireExpandToggle as rn,wireTooltip as dn,requestedPassFailDisplay as cn,overlayMenuRows as Lo,anyOverlayActive as $o,logWmapVersionOnce as Wo,buildDataModeEntries as Ro,metadataKeyHasData as Io,metadataModeEntry as Ao}from"./toolbar.js";import{aggregateValues as Po,aggregateBinCounts as un}from"../core/aggregates.js";import{renderWaferMap as gt}from"./renderWaferMap.js";import{classifyChanged as Fo}from"./renderWaferMap.js";import{buildWaferMap as Ho,getTestPassStatus as fn,isParametricTest as mt,getDieTestValue as jo}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Ze}from"../stats/analyzeWaferMap.js";import{collectWarnings as zo,buildWarningsMenuEl as No,severityOf as Vo}from"./warnings.js";import{compareNatural as _o}from"../core/utils.js";import{createSummaryPanelEl as ht,buildMetadataStripRow as Go,buildCompactMetadataRows as pn,metadataEntries as gn,renderLotSummaryContent as Ko}from"./summaryPanel.js";import{renderLotSummaryReportHtml as qo}from"../stats/renderSummaryReport.js";import{prettyKey as Uo}from"../stats/facets.js";import{mergeTestDefs as Xo}from"../stats/mergeTestDefs.js";import{getDieKey as Zo,hasPosition as Yo}from"../core/dies.js";function be(u){const S=new Set;return u.filter(f=>S.has(f.bin)?!1:(S.add(f.bin),!0))}const bt=12;function Qo(u,S,f){let P=S;if(S.length>bt){const v=S.slice(0,bt-1),L=S.slice(bt-1),oe=L.reduce((Qe,se)=>Qe+se.count,0);P=[...v,{color:g.label,count:oe,label:`Other (${L.length} bins)`}]}const F=u.createElement("div");Object.assign(F.style,{display:"flex",width:"100%",height:"8px",borderRadius:z.control,overflow:"hidden",border:`1px solid ${g.menuBorder}`,boxSizing:"border-box",marginTop:w.xs,flexShrink:"0"}),F.setAttribute("role","img"),F.setAttribute("aria-label",`Population split: ${P.map(v=>`${v.label} ${Ye(v.count/f*100)}`).join(", ")}`);for(const v of P){const L=v.count/f*100,oe=u.createElement("div");Object.assign(oe.style,{flex:`${L} 1 0`,minWidth:L>0?"2px":"0",background:v.color}),dn(oe,`${v.label} \xB7 ${v.count.toLocaleString()} dies \xB7 ${Ye(L)}`),F.appendChild(oe)}return F}function Ye(u){return u>0&&u<.1?"<0.1%":`${u.toFixed(1)}%`}function mn(u,S){const f=new Map;let P=0;for(const F of u)for(const v of F.dies){if(v.partial||v.edgeExcluded)continue;const L=S(v);L!==void 0&&(f.set(L,(f.get(L)??0)+1),P++)}return{counts:f,total:P}}function hn(u,S){const f=u.ownerDocument.createElement("div");Object.assign(f.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${w.xxs} ${w.xs}`,borderRadius:z.control});const P=u.ownerDocument.createElement("span");Object.assign(P.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:S.color,border:S.isActive?`2px solid ${g.iconActive}`:`1px solid ${g.menuBorder}`,borderRadius:z.control,boxSizing:"border-box"});const F=u.ownerDocument.createElement("span");if(F.textContent=S.label,Object.assign(F.style,{fontWeight:S.isActive?"700":"400",color:S.isActive?g.iconActive:g.text,whiteSpace:"nowrap"}),f.appendChild(P),f.appendChild(F),S.count!==void 0){const v=u.ownerDocument.createElement("span");if(v.textContent=S.count.toLocaleString(),Object.assign(v.style,{color:S.isActive?g.iconActive:g.text,fontWeight:S.isActive?"700":"400",whiteSpace:"nowrap"}),f.appendChild(v),S.percent!==void 0){const L=u.ownerDocument.createElement("span");L.textContent=Ye(S.percent),Object.assign(L.style,{color:g.label,whiteSpace:"nowrap"}),f.appendChild(L)}}f.setAttribute("role","button"),f.setAttribute("aria-pressed",S.isActive?"true":"false"),f.tabIndex=0,f.addEventListener("mouseenter",()=>{f.style.background=g.bgHover}),f.addEventListener("mouseleave",()=>{f.style.background="transparent"}),f.addEventListener("focus",()=>{f.style.background=g.bgHover}),f.addEventListener("blur",()=>{f.style.background="transparent"}),f.addEventListener("click",S.onClick),f.addEventListener("keydown",v=>{(v.key==="Enter"||v.key===" ")&&(v.preventDefault(),S.onClick())}),u.appendChild(f)}export function renderWaferGallery(u,S,f={}){Wo();const P=f.cardPadding??6,F=f.downloadFilename??"wafer-gallery";let v=f.columns;const L=f.showPlotModeSelector??!0,oe=f.showHelpButton??!1,Qe=f.userGuideExtension,se=f.insights?.enabled??!1,bn=go(f.zIndex),re=f.summaryPanel,We=f.passBins??[1];let Re=f.fallbackFormat,H=f.lotStatsSummary,ye=f.legendPosition??"default",Ie=f.perCardLegend??!1;function we(){const e=c.plotMode??"hardBin";return nn.has(e)?null:c.colorbarRangeMode==="data"?"Each map has its own value range, so it keeps its own colour bar":"This lot has no shared colour bar for value mode, so each map keeps its own"}function yt(){const e=Ie||we()!==null;for(const t of C)t&&t.setOptions({showLegend:e})}let c={plotMode:"hardBin",colorScheme:"default",showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,ringCount:4,rotation:0,flipX:!1,flipY:!1,...f.viewOptions},C=[],ie=[],de=[],O=[],x=S.map(e=>typeof e=="function"?null:e);function wt(){return Xo(x)}function ce(){if(x.some(e=>e?.testDefs?.length))return wt().defs}let Je=0,Ae=0;const N=new Map;let yn=0,R=null,xe=null,xt=new Set,h=null,wn={};function vt(e){return x[e]?.statsSummary??H?.perWafer.find(t=>t.waferIndex===e)?.summary}function et(){return!!(x.some(e=>e?.statsSummary?.findings.length)||H?.perWafer.some(e=>e.summary.findings.length))}const xn=mo(),ue=ho(xn),{makeBtn:Z,setActive:ve,makeSep:V,makeMenuRow:vn,makeMenuSection:Sn,makeDropdown:St,closeOpenMenu:Pe,getOpenMenu:Se,setOpenMenu:Ce}=ue;u.ownerDocument.addEventListener("click",Pe,!0);const Ct=()=>ln();window.addEventListener("blur",Ct);let Mt=f.findingsNotice;function Dt(e){xt=new Set(e);const t=[...W.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,r)=>{const d=xt.has(r);o.style.outline=d?`3px solid ${g.findingHighlight}`:"",o.style.outlineOffset=d?"-3px":"",d&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function kt(){Dt([])}function Et(){for(const e of C)e&&e.clearSelection()}function tt(e,t){const n=new Set(e),o=t??C.map((r,d)=>d);for(const r of o){const d=O[r],i=C[r];if(!d||!i)continue;const s=d.dies.filter(a=>n.has(Zo(a)));i.setSelection(s)}}function Cn(){const e=[];for(let t=0;t<x.length;t++){const n=x[t];if(!n)continue;const o=vt(t)?.findings??[];o.length&&e.push({index:t,item:n,unusualCount:o.filter(r=>r.severity==="unusual").length,notableCount:o.filter(r=>r.severity==="notable").length,totalCount:o.length})}return e}function Mn(e){const t=O[e]??x[e];t&&Oe(e,t)}function Dn(e){const t=vt(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 kn(){const e=be(x.flatMap(n=>n?.hbinDefs??[])),t=be(x.flatMap(n=>n?.sbinDefs??[]));vo(qo({items:x.map((n,o)=>({label:n?.label??`W${o+1}`,wafer:n?.wafer,dies:n?.dies,statsSummary:n?.statsSummary})),hbinDefs:e.length?e:void 0,sbinDefs:t.length?t:void 0,testDefs:ce(),passBins:We,ringCount:c.ringCount}),{anchor:u})}function En(){if(!h)return;h.innerHTML="";const e=Cn();if(x.length>0){const n=u.ownerDocument.createElement("div"),o=e.length,r=x.filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${r} wafers`:`${o} of ${r} wafer${r===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,{...uo("outlined"),marginBottom:w.lg,display:"block",width:"100%",textAlign:"left"}),pt(n),n.addEventListener("click",kn),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:r,notableCount:d,totalCount:i}of e){const s=r?"unusual":d?"notable":"info",a=r+d||i,l=u.ownerDocument.createElement("button");l.type="button",Object.assign(l.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:w.xs,border:"none",borderLeft:`3px solid ${tn(s)}`,borderRadius:z.control,background:g.bgHover,cursor:"pointer",fontSize:T.body,textAlign:"left",boxSizing:"border-box"}),l.addEventListener("mouseover",()=>{l.style.background=g.bgActive}),l.addEventListener("mouseout",()=>{l.style.background=g.bgHover});const p=u.ownerDocument.createElement("span");p.textContent=o.label??`W${n+1}`,Object.assign(p.style,{color:g.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const y=u.ownerDocument.createElement("span");y.textContent=String(a),l.setAttribute("aria-label",`${o.label??`W${n+1}`} \u2014 ${a} finding${a===1?"":"s"}${r?`, ${r} unusual`:""} \u2014 view wafer`),Object.assign(y.style,{marginLeft:w.sm,flexShrink:"0",background:tn(s),color:"#fff",borderRadius:z.container,padding:"1px 5px",fontSize:T.body,fontWeight:"600"}),l.appendChild(p),l.appendChild(y),l.addEventListener("click",()=>Oe(n,o)),h.appendChild(l)}const t=u.ownerDocument.createElement("div");t.style.height="12px",h.appendChild(t)}function j(){if(h)if(H){const e=be(x.flatMap(n=>n?.hbinDefs??[])),t=be(x.flatMap(n=>n?.sbinDefs??[]));Ko(h,{lotSummary:H,items:x,hbinDefs:e.length?e:void 0,sbinDefs:t.length?t:void 0,testDefs:ce(),passBins:We,ringCount:c.ringCount,colorScheme:c.colorScheme,plotMode:c.plotMode??"hardBin",fallbackFormat:Re,activeFindingId:xe,warnings:f.warnings?.display??!0?Y:[],findingsFilter:wn,findingsNotice:Mt,onFindingsFilterChange:j,onSaveText:f.onSaveText,onFindingClick:(n,o)=>{xe===n.id?nt():On(n,o),j()},onWaferClick:Mn,findingsFor:Dn,dieListOptions:f.dieList})}else En()}function Bn(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}function Bt(e){return[e.variable.kind,e.variable.index??"",e.variable.bin??"",e.comparison.family,e.comparison.left,e.effect.direction].join("|")}let Fe=[];function Ot(){if(Fe.length!==0){for(const e of Fe)C[e]?.setOptions({plotMode:c.plotMode,activeTest:c.activeTest});Fe=[]}}function nt(){xe=null,kt(),Et(),Ot(),B({highlightBin:void 0},{fireCallback:!1})}function On(e,t){if(xe===e.id){nt();return}xe=e.id,t.style.background=g.bgActive,t.style.fontWeight="600",Ot();const{kind:n,index:o}=e.variable;if(n==="test"){const d=o??0,i=ce();if(i===void 0||i.some(a=>a.testNumber===d))B({plotMode:"value",activeTest:d,highlightBin:void 0},{fireCallback:!1});else{B({highlightBin:void 0},{fireCallback:!1});const l=he.has(c.plotMode??"hardBin")?null:Bn(e);if(l){for(const p of l)C[p]?.setOptions({plotMode:"value",activeTest:d});Fe=[...l]}}}else n==="softBin"?B({plotMode:"softBin",highlightBin:void 0},{fireCallback:!1}):B({plotMode:"hardBin",highlightBin:void 0},{fireCallback:!1});kt(),Et();const r=e.highlight;if(r.kind==="wafer"){Dt(r.waferIndices);const d=Bt(e);for(const i of r.waferIndices){const l=O[i]?.statsSummary?.findings.find(p=>Bt(p)===d)?.highlight?.dieKeys;l?.length&&tt(l,[i])}}else r.kind==="bin"?r.dieKeys?.length&&tt(r.dieKeys):(r.kind==="region"||r.kind==="dies")&&r.dieKeys?.length&&tt(r.dieKeys)}function le(){if(!R)return;const e=!!h;R.style.display=(H||et())&&e&&!ke?"flex":"none";const t=h?h.style.display!=="none":!1;(H?.hasNotableFindings||x.some(o=>o?.statsSummary?.hasNotableFindings))&&!t?R.style.color=g.findingIndicator:R.dataset.active||(R.style.color=g.icon)}const $=u.ownerDocument.createElement("div");$.dataset.wmapToolbar="gallery",Object.assign($.style,{flexShrink:"0",marginLeft:"auto",display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:z.control,padding:"0",boxShadow:Le.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const Tt=()=>{const e=Se();e&&(e.remove(),Ce(null)),$e(K,!1)},K=Z("mode","Plot mode",()=>{if(Se()){Tt();return}const e=x.flatMap(b=>b?.dies??[]),t=ce(),{testEntries:n,binEntries:o,stackedEntries:r}=Ro(e,t,{includeStacked:!0}),d=x.filter(Boolean).length,i=b=>{if(b===void 0)return d;let A=0;for(const X of x)X?.dies?.some(J=>fn(J,b)!==void 0||J.testValues?.[b]!==void 0)&&A++;return A},s=d<2?n:n.map(b=>{const A=i(b.activeTest);return A===d?b:{...b,label:`${b.label} \u2014 ${A} of ${d} wafers`}}),a=c.plotMode??"hardBin",l=c.activeTest??0;function p(b){return b.plotMode!==a?!1:b.plotMode==="value"?l===(b.activeTest??0):b.plotMode==="metadata"?c.activeMetadataKey===b.activeMetadataKey:!0}function y(b,A){b.activeTest!==void 0?B({plotMode:"value",activeTest:b.activeTest,activeMetadataKey:void 0,logScale:b.logScale}):b.activeMetadataKey!==void 0?B({plotMode:b.plotMode,activeTest:void 0,activeMetadataKey:b.activeMetadataKey,passFailDisplay:"off"}):B({plotMode:b.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),A.remove(),Ce(null),$e(K,!1)}const M=new Set,k=x.flatMap(b=>b?.metadataFields??[]).filter(b=>!M.has(b.key)&&M.add(b.key)).filter(b=>Io(e,b.key)).map(Ao),I=bo(K.getBoundingClientRect(),s,o,r,p,y,{makeMenuRow:vn,makeMenuSection:Sn},a,K.ownerDocument.defaultView??window,k);an(K).appendChild(I),Ce(I),$e(K,!0),sn(I,K,Tt)});$e(K,!1);const Tn=()=>O.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:Ln,sync:Lt}=Do(ue,()=>c.plotMode??"hardBin",()=>c.colorScheme??"default",Tn,e=>B({colorScheme:e}),{get:()=>c.markFailingDies??!1,set:e=>B({markFailingDies:e})});Lt();const $n=S.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function He(){const e=ce(),{testNumber:t}=io(c.activeTest??0,e);return{testNumber:t,td:lo(e,t)}}function $t(){if((c.plotMode??"hardBin")!=="value")return!1;const{td:e}=He();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function Me(){if((c.plotMode??"hardBin")!=="value")return!1;const{td:e}=He();return e!==void 0&&!mt(e)}function Wn(){if((c.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=He();return x.some(n=>n?.dies?.some(o=>fn(o,e,t)!==void 0))}function Rn(e,t){if(!t||!mt(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((cn(c)==="spec"&&n?"spec":c.colorbarRangeMode??"spec")==="spec"&&n)return;let d=1/0,i=-1/0;for(const s of x)if(s)for(const a of s.dies){const l=jo(a,e);l!==void 0&&(l<d&&(d=l),l>i&&(i=l))}if(isFinite(d))return d===i?[d,d+1]:[d,i]}function ot(){if((c.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=He(),n=Rn(e,t),o=n?{test:e,range:n}:void 0;c={...c,valueRange:o};for(const r of C)r&&r.setOptions({valueRange:o})}let it=!1;function In(){if(it)return;it=!0,(u.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{it=!1,ot()})}const An=Bo(ue,()=>Lo(c,$n,{functionalActive:Me(),hasLimits:$t()&&!Me(),hasRecorded:Wn()&&!Me()},e=>B(e)),()=>$o(c)),{btn:Pn,sync:Wt}=Eo(ue,()=>({plotMode:c.plotMode,legendPosition:ye}),e=>{ye=e;for(const t of C)t&&t.setOptions({legendPosition:ye})},{get:()=>Ie,set:e=>{Ie=e,yt()},blockedReason:we});Wt();const Fn=[{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"}],Rt=St("aggr","Aggregation method",()=>Fn,()=>c.aggregationMethod??"mean",e=>B({aggregationMethod:e}));function It(){const e=c.plotMode==="stackedValues";Rt.style.display=e?"":"none"}It();const{btn:Hn,sync:At}=ko(ue,()=>({...c,functionalActive:Me()}),e=>B(e));At();const je=Z("specRange","Colorbar range: spec limits",()=>{const e=c.colorbarRangeMode==="data"?"spec":"data";B({colorbarRangeMode:e})});function Pt(){const e=(c.plotMode??"hardBin")==="value"&&$t()&&cn(c)==="off"&&!Me();je.style.display=e?"":"none";const t=(c.colorbarRangeMode??"spec")==="spec";ve(je,t),je.ariaLabel=t?"Colorbar range: spec limits (click for data range)":"Colorbar range: data range (click for spec limits)"}Pt();const jn=Oo(ue,()=>c,e=>B(e)),zn=Z("downloadAll","Download gallery PNG",no),Nn=St("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"}],()=>v!=null?String(v):"auto",e=>Ut(e==="auto"?void 0:Number(e))),E=u.ownerDocument.createElement("div");Object.assign(E.style,{display:"inline-flex",alignItems:"center",gap:"0"}),$.appendChild(E),L&&E.appendChild(K),E.appendChild(Ln),E.appendChild(Rt),E.appendChild(Hn),E.appendChild(je),E.appendChild(V()),E.appendChild(An),E.appendChild(V()),E.appendChild(Pn),E.appendChild(V()),E.appendChild(jn),E.appendChild(V()),E.appendChild(Nn),E.appendChild(V()),E.appendChild(zn),(H||et())&&(R=Z("findings","Summary panel",()=>{if(!h)return;const e=h.style.display!=="none";e||j(),h.style.display=e?"none":"flex",ve(R,!e),le()}),$.appendChild(V()),$.appendChild(R));let _=null,ze=null,Y=[],Ft=!1;function Ht(){const e=zo({lotStatsSummary:H,result:{warnings:[...x.flatMap(n=>n?.warnings??[]),...wt().warnings]}}),t=e.length!==Y.length||e.some((n,o)=>n.code!==Y[o]?.code||n.message!==Y[o]?.message);Y=e,(t||!Ft)&&(Ft=!0,f.warnings?.onWarning?.(e)),Vn()}function Vn(){if(!_||!ze)return;const e=Y.length,t=e>0;if(_.style.display=t?"flex":"none",ze.style.display=t?"":"none",!t)return;const n=Vo(Y[0]),o=`${e} data ${e===1?"warning":"warnings"}`;_.style.color=n==="error"?g.errText:g.warnText,_.ariaLabel=n==="error"?`${o} \u2014 wafers in this lot may be positionally wrong`:o}(f.warnings?.display??!0)&&(ze=V(),_=Z("warning","Data warnings",()=>{const e=Se();if(Pe(new MouseEvent("click")),e)return;const t=No(_.getBoundingClientRect(),Y,_.ownerDocument.defaultView??window);an(u).appendChild(t),Ce(t),sn(t,_,()=>Pe(new MouseEvent("click")))}),$e(_,!1),$.appendChild(ze),$.appendChild(_)),Ht();let ae=null;se&&(ae=Z("analysis","Insights",()=>{Nt(!ke)}),ae.dataset.wmapInsightsBtn="1",$.appendChild(V()),$.appendChild(ae));function jt(){import("./userGuideHtml.js").then(e=>Mo({buildWaferMap:Ho,renderWaferMap:gt,renderWaferGallery,analyzeWaferMap:Ze},e.USER_GUIDE_HTML,Qe,u))}oe&&($.appendChild(V()),$.appendChild(Z("help","User guide",()=>jt())));const fe=u.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:T.sub,lineHeight:Xe.none,boxSizing:"border-box"});const Ne=u.ownerDocument.createElement("div");Object.assign(Ne.style,{background:g.canvasBg,display:"flex",alignItems:"stretch",gap:w.lg,paddingBottom:w.lg,minWidth:"0"});const Q=u.ownerDocument.createElement("div");Q.dataset.wmapGalleryLegend="1",Object.assign(Q.style,{display:"flex",flexDirection:"column",gap:w.sm,background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:z.container,padding:`${w.sm} ${w.lg}`,marginBottom:w.lg,boxShadow:Le.panel,fontSize:T.body,lineHeight:Xe.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const G=u.ownerDocument.createElement("div");Object.assign(G.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let pe=null,De=null,zt=null;function _n(){return se?pe?Promise.resolve(pe):(zt??=import("./insightsTab.js").then(({createInsightsTab:e})=>(pe=e({getItems:()=>x,getLotStats:()=>H,getColorSchemeName:()=>c.colorScheme??"default",passBins:We,getRingCount:()=>c.ringCount??4,defaultView:f.insights?.defaultView,onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:f.onSaveImage,onSaveText:f.onSaveText,ownerDocument:u.ownerDocument,openWafer:(t,n,o)=>{const r=x[t];if(!r)return;let d=null;const i=xo({title:n,onClose:()=>d?.destroy(),anchor:u});Yt(i,n,r.wafer.metadata??void 0),d=dt(i.contentWrap,r,o)}}),De=pe.el,De.style.display="none",u.appendChild(De),pe)),zt):Promise.resolve(null)}let ke=!1;function Nt(e){se&&(ke=e,De&&(De.style.display=e?"flex":"none"),G.style.display=e?"none":"flex",E.style.display=e?"none":"inline-flex",$.style.display="inline-flex",ae&&(ve(ae,e),ae.innerHTML=e?Te.wafer:Te.analysis,ae.ariaLabel=e?"Back to gallery view":"Insights"),le(),Ge(),e&&_n().then(t=>{!t||!ke||(t.el.style.display="flex",t.render())}))}se&&f.insights?.defaultOpen&&queueMicrotask(()=>Nt(!0));const Gn=4,lt=240,Vt=480,Kn=720,qn=1.25,_t=f.maxSize;let q=_t??Vt;function Gt(e){const t=P*2+110+2;let n=null;for(const o of e){if(o==null||!o.dies?.length)continue;const r=o.dies[0].width;if(!(r>0))continue;const d=o.wafer.radius*2*(Gn/r),i=Math.ceil(d+t);(n==null||i>n)&&(n=i)}return n}function Un(e){const t=Gt(e);return t==null?lt:Math.min(q,Math.max(lt,t))}function Xn(e){if(_t!=null)return!1;const t=Gt(e);if(t==null)return!1;const n=Math.min(Kn,Math.max(Vt,t));return n<=q?!1:(q=n,!0)}function Zn(){for(const e of Array.from(W.children))e.classList.contains("wmap-gallery-card")&&(e.style.maxWidth=`${q}px`,e.style.maxHeight=`${q}px`)}let Ve=lt,Kt=0;function qt(e){const t=Xn(e);if(t&&Zn(),v!=null){t&&_e();return}const n=Un(e);n>Ve&&(Ve=n),_e()}function Ut(e){v=e,_e()}function at(e){return`repeat(${e}, minmax(0, ${q}px))`}function Xt(e){W.style.gridTemplateColumns!==e&&(W.style.gridTemplateColumns=e)}function _e(){if(v!=null){Xt(at(v));return}const e=Math.max(1,Kt),t=12,n=W.clientWidth||0,o=d=>(n-t*(d-1))/d;let r=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const d=Math.min(q,Ve*qn),i=s=>{let a=0;for(;a<e&&o(a+1)>=s;)a++;return a};r=i(d)||i(Ve)||1}Xt(at(r))}const W=u.ownerDocument.createElement("div");if(Object.assign(W.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:at(1),gap:w.xl,paddingLeft:ne,paddingRight:ne,justifyContent:"start",alignContent:"start",isolation:"isolate"}),re?.placement){const e=re.placement;h=ht(e,ne,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(H||et()){const e=!!re?.defaultOpen;h=ht("right",ne,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",j()}le(),h?.style.display!=="none"&&R&&ve(R,!0),(re?.placement??"right")==="left"?(h&&G.appendChild(h),G.appendChild(W)):(G.appendChild(W),h&&G.appendChild(h));const Ee=u.ownerDocument.createElement("div");Object.assign(Ee.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:ne,paddingRight:ne,paddingTop:ne,zIndex:"1",background:g.menuBg}),Ne.appendChild(fe),Ne.appendChild($),Ee.appendChild(Ne),Ee.appendChild(Q),u.appendChild(Ee),u.appendChild(G);function Ge(){Q.innerHTML="";const e=c.plotMode??"hardBin",t=!ke&&nn.has(e),n=O.filter(m=>m!=null),o=n.find(m=>m.isLotStack),r=Go(n.map(m=>({metadata:m.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0),d=e==="metadata",i=c.activeMetadataKey,s=t&&!d?mn(n,m=>(e==="softBin"?m.sbin:m.hbin)??void 0):{counts:new Map,total:0},a=[...s.counts.keys()].sort((m,D)=>m-D),l=t&&d&&i?mn(n,m=>{const D=m.metadata?.[i];return D!=null&&(typeof D=="string"||typeof D=="number"||typeof D=="boolean")?String(D):void 0}):{counts:new Map,total:0},p=new Set(l.counts.keys()),y=t&&d?[...p].sort(_o):[];if(fe.innerHTML="",r&&fe.appendChild(r),fe.style.display=r?"flex":"none",!a.length&&!y.length){Q.style.display="none";return}Q.style.display="flex";const M=u.ownerDocument.createElement("div");Object.assign(M.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${w.sm} ${w.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),Q.appendChild(M);const k=ao(c.colorScheme),I=c.highlightBin,b=O.flatMap(m=>m?.metadataFields??[]).find(m=>m.key===i),A=d?b?.label??(i?Uo(i):"Metadata"):po[e],X=u.ownerDocument.createElement("span");if(X.textContent=A,Object.assign(X.style,{fontSize:T.body,fontWeight:"700",letterSpacing:co,textTransform:"uppercase",color:g.label,flexShrink:"0"}),M.appendChild(X),!d&&s.total>0){const m=We.reduce((me,ut)=>me+(s.counts.get(ut)??0),0),D=m/s.total*100,ee=u.ownerDocument.createElement("span");ee.textContent=`Yield ${Ye(D)}`,Object.assign(ee.style,{fontSize:T.body,fontWeight:"700",color:g.value,whiteSpace:"nowrap",flexShrink:"0"});const te=u.ownerDocument.createElement("span");te.textContent=`${m.toLocaleString()} / ${s.total.toLocaleString()} dies`,Object.assign(te.style,{fontSize:T.body,color:g.label,whiteSpace:"nowrap",flexShrink:"0"}),M.appendChild(ee),M.appendChild(te)}if(d){const m=c.highlightMetadataValue;y.forEach((D,ee)=>{const te=m===D,me=b?.values?.find(ft=>ft.value===D),ut=me?.color??so(ee),en=l.counts.get(D)??0;hn(M,{color:ut,isActive:te,label:me?.label??D,count:en,percent:l.total>0?en/l.total*100:void 0,onClick:()=>{const ft=c.highlightMetadataValue===D?void 0:D;B({highlightMetadataValue:ft})}})});return}const J=e==="softBin"?O.flatMap(m=>m?.sbinDefs??[]):O.flatMap(m=>m?.hbinDefs??[]),qe=new Set,ct=[];for(const m of J)qe.has(m.bin)||(qe.add(m.bin),ct.push(m));const Ue=ct.length>0?new Map(ct.map(m=>[m.bin,m])):null,Jt=m=>{const D=Ue?.get(m);return(c.colorScheme==="custom"?D?.color:void 0)??k.forBin(m)};for(const m of a){const D=I===m,ee=Ue?.get(m),te=s.counts.get(m)??0;hn(M,{color:Jt(m),isActive:D,label:ee?.name?`${m} \xB7 ${ee.name}`:`Bin ${m}`,count:te,percent:s.total>0?te/s.total*100:void 0,onClick:()=>{const me=c.highlightBin===m?void 0:m;B({highlightBin:me})}})}s.total>0&&a.length>1&&Q.appendChild(Qo(u.ownerDocument,[...s.counts.entries()].sort(([,m],[,D])=>D-m).map(([m,D])=>({color:Jt(m),count:D,label:Ue?.get(m)?.name?`${m} \xB7 ${Ue.get(m).name}`:`Bin ${m}`})),s.total))}function Be(e){const t=x.filter(s=>s!==null);if(!t.length)return[];const n=t.map(s=>s.dies.filter(Yo)),o=t[0].wafer,r=t.length,d=o.metadata?{...o,metadata:(({wafer:s,waferId:a,...l})=>l)(o.metadata)}:o;function i(s,a){return{...s,stats:{...s.stats,isLotStack:!0,aggregationMethod:a,lotSize:r}}}if(e==="stackedValues"){const s=ce();let a=s?.filter(mt);if(s!==void 0&&a?.length===0)return[];if(s?.length||(a=oo(t.flatMap(y=>y.dies)).map(y=>({testNumber:y,name:`Test ${y}`}))),!a?.length)return[];const l=c.aggregationMethod??"mean";return a.map(p=>{const y=Po(n,l,p.testNumber),M={testNumber:0,name:p.name,unit:p.unit};return{wafer:d,dies:y,testDefs:[M],label:`${p.name} \xB7 ${l}`,isLotStack:!0,aggrMethod:l,lotSize:r,statsSummary:i(Ze({wafer:d,dies:y,testDefs:[M]},{testNumbers:[0]}),l)}})}if(e==="stackedBins"){let s=be(t.flatMap(a=>a.hbinDefs??[]));return(!s||s.length===0)&&(s=[...new Set(t.flatMap(l=>l.dies.map(p=>p.hbin).filter(p=>p!=null)))].sort((l,p)=>l-p).map(l=>({bin:l,name:`Bin ${l}`}))),s.map(a=>{const l=un(n,a.bin,"hard"),p=[{bin:a.bin,name:a.name}];return{wafer:d,dies:l,hbinDefs:p,label:`${a.bin} \xB7 ${a.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:r,statsSummary:i(Ze({wafer:d,dies:l,hbinDefs:p}),"countBin")}})}if(e==="stackedSoftBins"){let s=be(t.flatMap(a=>a.sbinDefs??[]));return(!s||s.length===0)&&(s=[...new Set(t.flatMap(l=>l.dies.map(p=>p.sbin).filter(p=>p!=null)))].sort((l,p)=>l-p).map(l=>({bin:l,name:`Bin ${l}`}))),s.map(a=>{const l=un(n,a.bin,"soft"),p=[{bin:a.bin,name:a.name}];return{wafer:d,dies:l,sbinDefs:p,label:`${a.bin} \xB7 ${a.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:r,statsSummary:i(Ze({wafer:d,dies:l,sbinDefs:p}),"countBin")}})}return t}function st(e){const t=x.length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:c.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}const Yn=new Set(["default","accessible","custom"]);function B(e,{fireCallback:t=!0}={}){const n=c.plotMode,o=we()!==null;c={...c,...e};const r=c.plotMode,d=he.has(r),i=n!==void 0&&he.has(n),s=Ae>0;if(e.plotMode!==void 0&&e.plotMode!==n&&(r==="hardBin"||r==="softBin")&&!Yn.has(c.colorScheme??"")&&(c={...c,colorScheme:"default"}),e.plotMode!==void 0)if(d){const l=st(r);if(c={...c,...l},s)for(const p of C)p&&p.setOptions(e);else U(Be(r))}else if(i){const{valueRange:l,lotSize:p,aggregationMethod:y,...M}=c;if(c=M,s)for(const k of C)k&&k.setOptions(e);else U(x.filter(k=>k!==null))}else for(const l of C)l&&l.setOptions(e);else if(e.aggregationMethod!==void 0&&r==="stackedValues")if(s)for(const l of C)l&&l.setOptions(e);else U(Be("stackedValues"));else for(const l of C)l&&l.setOptions(e);we()!==null!==o&&yt(),Ge(),It(),Wt(),Lt();const a=e.plotMode!==void 0&&e.plotMode!==n;if((e.colorScheme!==void 0||a)&&j(),At(),Pt(),ot(),t){const l=Object.keys(e);f.onViewOptionsChange?.(c,l,Fo(l))}}function Zt(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:w.xs,flex:"1",minWidth:"0"});const r=e.createElement("span");r.textContent=t,Object.assign(r.style,{fontWeight:"700",fontSize:T.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(r);const d=gn(n??{});let i=null;if(d.length>0){const s=e.createElement("span");Object.assign(s.style,{fontSize:T.body,lineHeight:Xe.none,color:g.label,flexShrink:"0"}),s.textContent="\u25BE",o.appendChild(s),Object.assign(o.style,{cursor:"pointer",borderRadius:z.control}),o.addEventListener("mouseenter",()=>{o.style.background=g.bgHover}),o.addEventListener("mouseleave",()=>{o.style.background="none"}),i=e.createElement("div"),i.dataset.wmapCardMetaPanel="1",Object.assign(i.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:on,background:g.menuBg,borderBottom:`1px solid ${g.menuBorder}`,boxShadow:Le.menu,padding:`${w.md} ${w.lg}`,fontSize:T.body,display:"none"});const a=pn(n??{});a&&i.appendChild(a),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`Wafer info for ${t||"this card"}. Click to expand.`),rn(o,l=>{s.textContent=l?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(l)),i&&(i.style.display=l?"block":"none")})}return{wrap:o,metaPanel:i}}function Yt(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]"),r=gn(n??{});if(!o||r.length===0)return;const d=o.parentElement,i=u.ownerDocument.createElement("div");Object.assign(i.style,{display:"flex",alignItems:"center",gap:w.xs,flex:"1",minWidth:"0",cursor:"pointer"}),pt(i,"bare"),d?.insertBefore(i,o),i.appendChild(o);const s=u.ownerDocument.createElement("span");Object.assign(s.style,{fontSize:T.body,lineHeight:Xe.none,color:g.label,flexShrink:"0"}),s.textContent="\u25BE",i.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:on,background:g.menuBg,borderBottom:`1px solid ${g.menuBorder}`,boxShadow:Le.menu,padding:`${w.md} ${w.lg}`,fontSize:T.body,display:"none"});const l=pn(n??{});l&&a.appendChild(l),e.contentWrap.style.position="relative",e.contentWrap.appendChild(a),i.setAttribute("aria-expanded","false"),i.setAttribute("aria-label",`Wafer info for ${t}. Click to expand.`),rn(i,p=>{s.textContent=p?"\u25B4":"\u25BE",i.setAttribute("aria-expanded",String(p)),a.style.display=p?"block":"none"})}function rt(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:z.container,boxShadow:Le.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:`${q}px`,maxHeight:`${q}px`});const r=u.ownerDocument.createElement("div");Object.assign(r.style,{display:"flex",alignItems:"center",padding:`${w.md} ${w.lg} ${w.sm}`,borderBottom:`1px solid ${g.menuBorder}`,flexShrink:"0",gap:w.sm});const{wrap:d,metaPanel:i}=Zt(document,e.label??"",e.wafer.metadata??void 0);r.appendChild(d);const s=u.ownerDocument.createElement("button");s.dataset.wmapExpandBtn="1",s.setAttribute("aria-label","Open full view"),dn(s),s.innerHTML=Te.expand,Object.assign(s.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${g.menuBorder}`,borderRadius:z.control,background:g.panelBg,color:g.label,padding:w.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),pt(s),r.appendChild(s),o.appendChild(r);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),i&&a.appendChild(i),W.appendChild(o);const l=Ie||we()!==null,p=e.viewOptions?{...c,...e.viewOptions}:c,y=gt(a,e,{viewOptions:{...p,showLegend:l},toolbarControls:"full",showTooltip:!0,padding:P,legendPosition:ye,fallbackFormat:Re,statsSummary:e.statsSummary,onSaveImage:f.onSaveImage,onSaveText:f.onSaveText,onClick:e.onClick,onSelect:e.onSelect,onExpand:()=>Oe(t,e),showIdentity:!1,chromeInset:fo});return y.setViewControlsVisible(!1),y.setSummaryVisible(!1),s.onclick=()=>Oe(t,e),{card:o,ctrl:y,canvasWrapper:a,expandBtn:s}}function Qn(e){const t=de[e];if(!t)return;const n=[...N.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=Te.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>eo(n.id)):(t.innerHTML=Te.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>Oe(e,O[e]))}function U(e){to(),Se()?.remove(),Ce(null),nt(),O=[];for(const i of C)i&&i.destroy();C=[],ie=[],de=[],Ae=0,W.innerHTML="",Kt=e.length,qt(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 a=u.ownerDocument.createElement("div");a.className="wmap-gallery-card",Object.assign(a.style,{background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:z.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const l=u.ownerDocument.createElement("span");l.textContent="\u2026",Object.assign(l.style,{color:g.label,fontSize:"18px"}),a.appendChild(l),W.appendChild(a),O.push(null),C.push(null),ie.push(null),de.push(null),t.push({index:i,factory:s,placeholder:a}),Ae++}else{const{ctrl:a,canvasWrapper:l,expandBtn:p}=rt(s,i,e.length);O.push(s),C.push(a),ie.push(l),de.push(p)}}O.flatMap(i=>i?[...i.hbinDefs??[],...i.sbinDefs??[]]:[]).some(i=>i.color)&&!f.viewOptions?.colorScheme&&(c={...c,colorScheme:"custom"}),Ge(),ot();const o=++Je;let r=0;function d(){if(o!==Je)return;if(r>=t.length){if(he.has(c.plotMode)){const I=c.plotMode;U(Be(I))}return}const{index:i,factory:s,placeholder:a}=t[r++],l=s();O[i]=l,x[i]=l,qt([l]);const{card:p,ctrl:y,canvasWrapper:M,expandBtn:k}=rt(l,i,e.length);C[i]=y,ie[i]=M,de[i]=k,Ae--,a.replaceWith(p),Ge(),In(),!h&&!re?.placement&&l.statsSummary?.findings.length?(h=ht("right",ne,u.ownerDocument),h.style.maxHeight="calc(100vh - 80px)",h.style.position="sticky",h.style.top="8px",h.style.flexDirection="column",h.style.display="none",(re?.placement??"right")==="left"?G.insertBefore(h,W):G.appendChild(h),j(),R||(R=Z("findings","Summary panel",()=>{if(!h)return;const b=h.style.display!=="none";b||j(),h.style.display=b?"none":"flex",ve(R,!b),le()}),$.appendChild(V()),$.appendChild(R)),le()):h&&h.style.display!=="none"&&j(),le(),setTimeout(d,0)}t.length>0&&setTimeout(d,0)}if(he.has(c.plotMode)&&x.length>0){const e=st(c.plotMode);c={...c,...e},U(Be(c.plotMode))}else U(S);let ge=0;const Qt=new(u.ownerDocument.defaultView??window).ResizeObserver(()=>{if(ge)return;ge=(u.ownerDocument.defaultView??window).requestAnimationFrame(()=>{ge=0,v==null&&_e()})});Qt.observe(W),h&&j();function Jn(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 i of N.values())if(i.cardIndex===e)return;const n=t.label??"Wafer map",o=yn++,r=C[e]?.getOptions(),d=yo(n);if(d){const i=d.document;i.title=n,Object.assign(i.documentElement.style,{height:"100%"}),Object.assign(i.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:T.family}),So(u,i.documentElement);const s=Co(u,i.documentElement,()=>I.setOptions({})),a=i.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"}),i.body.appendChild(a);const l=i.createElement("div");Object.assign(l.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),i.body.appendChild(l);const{wrap:p,metaPanel:y}=Zt(i,n,t.wafer.metadata??void 0),M=i.createElement("div");Object.assign(M.style,{display:"flex",alignItems:"center",padding:`${w.md} ${w.lg} ${w.sm}`,borderBottom:`1px solid ${g.menuBorder}`,flexShrink:"0",gap:w.sm}),M.appendChild(p),l.appendChild(M);const k=i.createElement("div");Object.assign(k.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),y&&k.appendChild(y),l.appendChild(k);const I=dt(k,t,void 0,r),b=setInterval(()=>{d.closed&&Ke(o)},400);d.addEventListener("pagehide",()=>Ke(o)),N.set(o,{id:o,ctrl:I,cardIndex:e,label:n,closePollId:b,stopThemeSync:s,close:()=>{d.closed||d.close()},setTitle:A=>{i.title=A,a.textContent=A,a.style.display="block"}})}else{const i=wo({title:n,onClose:()=>Ke(o),anchor:u});i.contentWrap.style.flexDirection="column",Yt(i,n,t.wafer.metadata??void 0);const s=dt(i.contentWrap,t,void 0,r);N.set(o,{id:o,ctrl:s,cardIndex:e,label:n,closePollId:null,close:()=>i.close(),setTitle:a=>{const l=i.box.querySelector("[data-wmap-window-title]");l&&(l.textContent=a,l.title=a)}})}C[e]?.destroy(),C[e]=null,Jn(e,d!==null),Qn(e)}function dt(e,t,n,o){const r=t.viewOptions?{...c,...t.viewOptions}:c,d=o?{...r,...o}:r,s={...n!==void 0?{...d,plotMode:"value",activeTest:n}:d,showLegend:!0},a=gt(e,t,{viewOptions:s,toolbarControls:"full",showTooltip:!0,padding:P,legendPosition:ye,fallbackFormat:Re,statsSummary:t.statsSummary,onSaveImage:f.onSaveImage,onSaveText:f.onSaveText,onClick:t.onClick,onSelect:t.onSelect,showExpandButton:!1,showIdentity:!1});return a.setViewControlsVisible(!0),a.setSummaryVisible(!0),a.setExpandVisible(!1),a}function Ke(e){const t=N.get(e);if(!t)return;N.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.();const n=t.ctrl.getOptions();if(t.ctrl.destroy(),t.cardIndex===null)return;const o=t.cardIndex,r=O[o];if(!r)return;const d={...r,viewOptions:n};O[o]=d;const{card:i,ctrl:s,canvasWrapper:a,expandBtn:l}=rt(d,o,O.length);ie[o]?.parentElement?.replaceWith(i),C[o]=s,ie[o]=a,de[o]=l}function eo(e){const t=N.get(e);t&&(t.close(),Ke(e))}function to(){for(const e of N.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function no(){const e=[...W.querySelectorAll("canvas")];if(!e.length)return;const t=e.length,n=Math.ceil(Math.sqrt(t)),o=Math.ceil(t/n),r=e[0].width,d=e[0].height,i=8,s=(u.ownerDocument.defaultView??window).devicePixelRatio||1,a=Math.round(26*s),l=Math.round(12*s),p=u.ownerDocument.createElement("canvas");p.width=n*r+(n-1)*i,p.height=o*(d+a)+(o-1)*i;const y=p.getContext("2d"),M=ro(W);y.fillStyle=M.background,y.fillRect(0,0,p.width,p.height),e.forEach((k,I)=>{const b=I%n,A=Math.floor(I/n),X=b*(r+i),J=A*(d+a+i),qe=k.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";y.fillStyle=M.surface,y.fillRect(X,J,r,a),y.fillStyle=M.text,y.font=`700 ${l}px system-ui, sans-serif`,y.textAlign="left",y.textBaseline="middle",y.fillText(qe,X+Math.round(10*s),J+a/2,r-Math.round(20*s)),y.drawImage(k,X,J+a)}),p.toBlob(k=>{k&&To(k,F,f.onSaveImage)})}return{setItems(e){x=e.map(n=>typeof n=="function"?null:n);const t=c.plotMode;if(he.has(t))if(e.some(o=>typeof o=="function"))U(e);else{const o=st(t);c={...c,...o},U(Be(t))}else U(e)},setOptions(e){B(e,{fireCallback:!1})},getOptions(){return{...c}},setFallbackFormat(e){Re=e;for(const t of C)t&&t.setFallbackFormat(e)},setFindingsNotice(e){Mt=e,j()},setLotStatsSummary(e){H=e,Ht(),h&&j(),le()},setColumns(e){Ut(e)},openUserGuide:jt,destroy(){Je++;for(const e of[...N.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();N.clear();for(const e of C)e&&e.destroy();C=[],Se()?.remove(),Qt.disconnect(),ge&&((u.ownerDocument.defaultView??window).cancelAnimationFrame(ge),ge=0),u.ownerDocument.removeEventListener("click",Pe,!0),window.removeEventListener("blur",Ct),bn(),ln(),Ee.remove(),G.remove(),h?.remove(),pe?.destroy()}}}
|
|
@@ -4,9 +4,9 @@ import { type ToCanvasOptions } from './toCanvas.js';
|
|
|
4
4
|
import type { WaferMapResult } from '../renderer/buildWaferMap.js';
|
|
5
5
|
import type { StatsSummary } from '../stats/types.js';
|
|
6
6
|
import { type SaveImageHandler, type SaveTextHandler, type UserGuideExtension } from './toolbar.js';
|
|
7
|
-
import type { SummaryPanelOptions } from './summaryPanel.js';
|
|
7
|
+
import type { SummaryPanelOptions, FindingsNotice } from './summaryPanel.js';
|
|
8
8
|
import { type WarningsOptions } from './warnings.js';
|
|
9
|
-
import {
|
|
9
|
+
import type { InsightsOptions } from './insightsTab.js';
|
|
10
10
|
import { type DieListDisplayOptions } from './dieList.js';
|
|
11
11
|
/**
|
|
12
12
|
* Stable display preferences — worth persisting to localStorage or a user profile.
|
|
@@ -131,7 +131,30 @@ export interface WaferDisplayState {
|
|
|
131
131
|
* whether a change is worth persisting.
|
|
132
132
|
*/
|
|
133
133
|
export type WaferViewOptions = WaferPreferences & WaferDisplayState;
|
|
134
|
-
|
|
134
|
+
/**
|
|
135
|
+
* The drawing parameters `renderWaferMap` forwards to the canvas. Declared
|
|
136
|
+
* explicitly rather than inherited from `ToCanvasOptions`, which is what this
|
|
137
|
+
* interface used to do.
|
|
138
|
+
*
|
|
139
|
+
* That inheritance leaked 16 low-level fields onto the top-level render API, and
|
|
140
|
+
* five of them were **accepted and silently ignored** — `renderWaferMap` computes
|
|
141
|
+
* or overrides them on every draw (`topClearance` is hardcoded to 0,
|
|
142
|
+
* `minRightReserve` is derived from the legend, and `markFailingDies`/`activeBin`/
|
|
143
|
+
* `hoverBin` are read from `viewOptions` and internal hover state instead). An
|
|
144
|
+
* option that is typed, documented and ignored costs a caller a debugging session
|
|
145
|
+
* to discover the API lied, so they are gone rather than merely undocumented.
|
|
146
|
+
*
|
|
147
|
+
* Listing the fields also stops future `ToCanvasOptions` additions arriving here
|
|
148
|
+
* by accident: `toCanvas` is the low-level surface and is free to grow, and a
|
|
149
|
+
* caller who genuinely needs that level of control should call it directly.
|
|
150
|
+
*
|
|
151
|
+
* These stay at the top level of `RenderOptions` rather than moving under a
|
|
152
|
+
* nested `draw` key. Grouping would read better, but it would break every caller
|
|
153
|
+
* of the ten options that DO work in exchange for tidiness alone, and the defect
|
|
154
|
+
* here was the five that don't.
|
|
155
|
+
*/
|
|
156
|
+
type ForwardedDrawOptions = Pick<ToCanvasOptions, 'padding' | 'background' | 'showColorbar' | 'colorbarWidth' | 'showAxes' | 'showTitle' | 'legendPosition' | 'legendOffset' | 'diePitchMm' | 'fallbackFormat' | 'metadataFields'>;
|
|
157
|
+
export interface RenderOptions extends ForwardedDrawOptions {
|
|
135
158
|
/** Initial scene display options. All are overridable via the toolbar. */
|
|
136
159
|
viewOptions?: WaferViewOptions;
|
|
137
160
|
/** Called when the user hovers over a die. Null when leaving a die. */
|
|
@@ -153,16 +176,31 @@ export interface RenderOptions extends Omit<ToCanvasOptions, 'viewport' | 'hbinD
|
|
|
153
176
|
/** Show the built-in toolbar. Default true. */
|
|
154
177
|
showToolbar?: boolean;
|
|
155
178
|
/**
|
|
156
|
-
* Show
|
|
157
|
-
* program, temperature, etc.)
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
179
|
+
* Show an always-visible identity header row (lot, wafer ID, product, test
|
|
180
|
+
* program, temperature, etc.) above the canvas. Default true. Independent
|
|
181
|
+
* of `showToolbar` and the Insights tab — this exists so basic wafer/lot
|
|
182
|
+
* identity is never hidden behind a mode or toggle. A real layout row, not
|
|
183
|
+
* an overlay, so it can never collide with anything the canvas draws
|
|
184
|
+
* (colorbar, legend, toolbar) regardless of `legendPosition`. Carries identity
|
|
185
|
+
* and nothing else — Expand lives in the toolbar with the other view
|
|
186
|
+
* controls, so turning this off costs only the identity text. Collapsed by
|
|
187
|
+
* default to a single identifying line; click/Enter/Space expands a panel
|
|
188
|
+
* over the top of the canvas to the full field set. Renders nothing when the
|
|
189
|
+
* result has no metadata/lot-stack context.
|
|
190
|
+
*/
|
|
191
|
+
showIdentity?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Inset for this map's own chrome row (identity + toolbar) and for a Summary
|
|
194
|
+
* panel docked inside the map area, from the edge of the map area.
|
|
195
|
+
*
|
|
196
|
+
* Defaults to `EDGE_GUTTER` — correct for a standalone map, where the map
|
|
197
|
+
* area IS the region and its chrome is a bounded surface against that edge.
|
|
198
|
+
* Pass the smaller `MAP_CHROME_INSET` when the map is embedded in a surface
|
|
199
|
+
* that already provides its own inset (this is what `renderWaferGallery`
|
|
200
|
+
* passes for its cards); a second full gutter inside one stacks two, which
|
|
201
|
+
* reads as a toolbar standing well off the side of the card.
|
|
164
202
|
*/
|
|
165
|
-
|
|
203
|
+
chromeInset?: string;
|
|
166
204
|
/** Optional precomputed wafer-level stats summary. Enables the summary panel toggle button in the toolbar. */
|
|
167
205
|
statsSummary?: StatsSummary;
|
|
168
206
|
/**
|
|
@@ -214,6 +252,14 @@ export interface RenderOptions extends Omit<ToCanvasOptions, 'viewport' | 'hbinD
|
|
|
214
252
|
* Insights has no map for a finding to highlight against.
|
|
215
253
|
*/
|
|
216
254
|
summaryPanel?: SummaryPanelOptions;
|
|
255
|
+
/**
|
|
256
|
+
* A row at the top of the Findings section stating that a category of finding
|
|
257
|
+
* is not present, and optionally offering to compute it — see
|
|
258
|
+
* {@link FindingsNotice}. wmap never raises this itself: only the host knows
|
|
259
|
+
* what analysis it chose to skip and what running it would cost. Replaceable
|
|
260
|
+
* afterwards via the controller's `setFindingsNotice`.
|
|
261
|
+
*/
|
|
262
|
+
findingsNotice?: FindingsNotice;
|
|
217
263
|
/**
|
|
218
264
|
* Display preferences for every built-in die-list surface: the
|
|
219
265
|
* coordinate-less map replacement, the "+N dies without position data"
|
|
@@ -246,9 +292,11 @@ export interface RenderOptions extends Omit<ToCanvasOptions, 'viewport' | 'hbinD
|
|
|
246
292
|
/** Override the expand action for both the expand button and the E key. Used by the gallery to route through its own modal logic. */
|
|
247
293
|
onExpand?: () => void;
|
|
248
294
|
/**
|
|
249
|
-
* Show the
|
|
250
|
-
*
|
|
251
|
-
*
|
|
295
|
+
* Show the expand button in the toolbar and enable the E-key shortcut.
|
|
296
|
+
* Default true. Independent of `showIdentity` — expand is a view control,
|
|
297
|
+
* not part of the wafer's identity. Set false when the host already renders
|
|
298
|
+
* the map inside its own expanded/modal context, where wmap's built-in
|
|
299
|
+
* expand modal would be redundant.
|
|
252
300
|
*/
|
|
253
301
|
showExpandButton?: boolean;
|
|
254
302
|
/**
|
|
@@ -314,6 +362,12 @@ export interface WaferMapController {
|
|
|
314
362
|
/** Return current scene options snapshot. */
|
|
315
363
|
getOptions(): WaferViewOptions;
|
|
316
364
|
/** Programmatically set the selected dies (renders highlight overlay). */
|
|
365
|
+
/**
|
|
366
|
+
* Replace the Findings-section notice (see `FindingsNotice`). Pass `undefined`
|
|
367
|
+
* to clear it — which is what a host does once it has run the analysis the
|
|
368
|
+
* notice was offering.
|
|
369
|
+
*/
|
|
370
|
+
setFindingsNotice(notice: FindingsNotice | undefined): void;
|
|
317
371
|
setSelection(dies: Die[]): void;
|
|
318
372
|
/** Clear the current selection. */
|
|
319
373
|
clearSelection(): void;
|
|
@@ -331,8 +385,8 @@ export interface WaferMapController {
|
|
|
331
385
|
setExpandVisible(visible: boolean): void;
|
|
332
386
|
/** Show or hide the help toolbar button. */
|
|
333
387
|
setHelpButtonVisible(visible: boolean): void;
|
|
334
|
-
/** Show or hide the
|
|
335
|
-
|
|
388
|
+
/** Show or hide the identity header without affecting its content. */
|
|
389
|
+
setIdentityVisible(visible: boolean): void;
|
|
336
390
|
/**
|
|
337
391
|
* Opens the built-in end-user guide window — the same action the help
|
|
338
392
|
* toolbar button performs, but callable directly. Works regardless of
|
|
@@ -378,4 +432,5 @@ export declare function classifyChanged(keys: (keyof WaferViewOptions)[]): 'pref
|
|
|
378
432
|
*/
|
|
379
433
|
export type RenderableWaferMap = Pick<WaferMapResult, 'wafer' | 'dies'> & Partial<Omit<WaferMapResult, 'wafer' | 'dies'>>;
|
|
380
434
|
export declare function renderWaferMap(container: HTMLElement, result: RenderableWaferMap, options?: RenderOptions): WaferMapController;
|
|
435
|
+
export {};
|
|
381
436
|
//# sourceMappingURL=renderWaferMap.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{buildView as oi,buildHoverText as ai,findTestDef as it,resolveTestNumber as Dt}from"../renderer/buildView.js";import{toCanvas as si,BIN_LEGEND_W as wn,BIN_LEGEND_W_COMPACT as li,BIN_LEGEND_ADAPT_COMPACT as ri,BIN_LEGEND_ADAPT_FLOATING as di}from"./toCanvas.js";import{buildWaferMap as ci,getTestPassStatus as pi,isParametricTest as Bt}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as fi}from"../stats/analyzeWaferMap.js";import{CLR as S,Z_BASE as ui,applyOverlayZ as gi,getTooltip as Sn,hideTooltip as ot,reparentTooltip as hi,positionTooltip as kt,createToolbarHelpers as mi,buildModeMenuEl as yi,openReparentedModal as bi,openUserGuideWindow as vi,makePaletteBtn as xi,makeLogScaleBtn as wi,makeLegendStyleBtn as Si,makeOverlaysBtn as Ci,makeOrientationBtn as Mi,menuLayerFor as Cn,saveImageBlob as Ei,markMenuTrigger as Ye,wireMenuA11y as Mn,wireExpandToggle as Di,nextFrame as Lt,passFailMenuRows as Bi,requestedPassFailDisplay as Tt,logWmapVersionOnce as ki,buildDataModeEntries as Li,metadataKeyHasData as Ti,metadataModeEntry as Pi}from"./toolbar.js";import{createSummaryPanelEl as Pt,wrapWithSummaryPanel as Ot,renderWaferSummaryContent as Oi}from"./summaryPanel.js";import{collectWarnings as Ri,buildWarningsMenuEl as Ii,severityOf as Fi}from"./warnings.js";import"../stats/facets.js";import{ICONS as En}from"./icons.js";import{hardBinColor as Wi,softBinColor as Hi,metadataValueColor as Ai}from"../renderer/colorMap.js";import{createInsightsTab as Yi}from"./insightsTab.js";import{createMetadataBadge as zi}from"./metadataBadge.js";import{getDieKey as Ee,hasPosition as Dn,isPositionedDie as Xi}from"../core/dies.js";import{buildDieListSection as Ni}from"./dieList.js";import{buildMaplessSummary as Ki}from"./maplessSummary.js";const Bn=new Set(["colorScheme","rotation","flipX","flipY","showDieLabels","showPartialDies","showRingBoundaries","showQuadrantBoundaries","showReticle","showXYIndicator","ringCount","legendPosition","logScale","colorbarRangeMode","markFailingDies"]);export function classifyChanged(N){const m=N.some(g=>Bn.has(g)),C=N.some(g=>!Bn.has(g));return m&&C?"mixed":m?"preference":"state"}export function renderWaferMap(N,m,C={}){ki();const g=N.ownerDocument,K=g.defaultView??window;K.getComputedStyle(N).position==="static"&&(N.style.position="relative");const kn=N.clientHeight;C.height!=null&&(N.style.height=typeof C.height=="number"?`${C.height}px`:C.height);const at=m.dataCoverage?m.dataCoverage.unpositionedDies:m.dies.filter(e=>!Dn(e)).length,ze=(m.dataCoverage?m.dataCoverage.totalDies:m.dies.length-at)===0&&at>0,q=g.createElement("div");Object.assign(q.style,{position:"relative",width:"100%",height:"100%"}),C.maxSize!=null&&(q.style.maxWidth=`${C.maxSize}px`,q.style.maxHeight=`${C.maxSize}px`),N.appendChild(q);const M=g.createElement("div");Object.assign(M.style,{position:"relative",width:"100%",height:"100%"});const a=g.createElement("canvas");Object.assign(a.style,{width:"100%",height:"100%",display:"block"}),M.appendChild(a),q.appendChild(M);let Xe=null;if(at>0){let n=function(){if(t){const u=Ni(e,m.testDefs,{...C.dieList,onSaveText:C.onSaveText,waferMetadata:J.metadata,metadataFields:le,ownerDocument:g});if(u)return u}const i=it(m.testDefs,l.activeTest??0),d=Bt(i)?l.logScale??i?.logScale??!1:!1;return Ki(e,m.testDefs,{plotMode:l.plotMode??"hardBin",activeTest:l.activeTest,hbinDefs:$,sbinDefs:G,colorScheme:l.colorScheme,logScale:d,colorbarRangeMode:l.colorbarRangeMode,valueRangeDies:m.dies})},o=function(i){const d=g.createElement("button");return d.type="button",Object.assign(d.style,{fontSize:"10px",padding:"2px 6px",borderRadius:"4px",flexShrink:"0",border:`1px solid ${S.menuBorder}`,background:S.menuBg,color:S.text,cursor:"pointer"}),d.textContent=t?"View chart":"View die list",d.addEventListener("click",u=>{u.stopPropagation(),t=!t,d.textContent=t?"View chart":"View die list",i()}),d};const e=m.dies.filter(i=>!Dn(i));let t=!1;if(ze){const i=g.createElement("div");Object.assign(i.style,{position:"absolute",inset:"0",background:S.panelBg,padding:"12px",paddingTop:C.showToolbar??!0?"44px":"12px",boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",gap:"8px",zIndex:"1"});const d=g.createElement("div");Object.assign(d.style,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:"8px"});const u=g.createElement("span");Object.assign(u.style,{fontSize:"11px",color:S.label,lineHeight:"1.4"}),u.textContent="No die position data for this wafer.",d.appendChild(u);const s=g.createElement("div");Object.assign(s.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),d.appendChild(o(()=>s.replaceChildren(n()))),i.appendChild(d),i.appendChild(s),M.appendChild(i),Xe=()=>{t||s.replaceChildren(n())}}else{const i=g.createElement("div");Object.assign(i.style,{position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"3",background:S.panelBg,borderTop:`1px solid ${S.menuBorder}`,fontSize:"11px",color:S.text,cursor:"pointer",padding:"4px 8px",display:"flex",alignItems:"center",justifyContent:"space-between",gap:"8px"});const d=g.createElement("span");d.textContent=`+${e.length} ${e.length===1?"die":"dies"} without position data`,i.appendChild(d);const u=g.createElement("span");u.textContent="\u25BE",Object.assign(u.style,{fontSize:"12px",lineHeight:"1",color:S.label,flexShrink:"0"}),i.appendChild(u),i.setAttribute("aria-expanded","false"),i.setAttribute("aria-label",`${e.length} dies without position data. Click to view.`);let s=null,r=null;Di(i,p=>{if(u.textContent=p?"\u25B4":"\u25BE",i.setAttribute("aria-expanded",String(p)),p){s=g.createElement("div");const c=i.getBoundingClientRect().height||28;Object.assign(s.style,{position:"absolute",left:"0",right:"0",bottom:`${c}px`,top:"20%",zIndex:"2",background:S.panelBg,borderTop:`1px solid ${S.menuBorder}`,padding:"8px",boxSizing:"border-box",display:"flex",flexDirection:"column",gap:"8px"}),s.addEventListener("click",Q=>Q.stopPropagation());const h=g.createElement("div");Object.assign(h.style,{display:"flex",justifyContent:"flex-end"}),h.appendChild(o(()=>{r&&r.replaceChildren(n())})),s.appendChild(h),r=g.createElement("div"),Object.assign(r.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),r.appendChild(n()),s.appendChild(r),M.appendChild(s)}else s&&(s.remove(),s=null,r=null)}),M.appendChild(i),Xe=()=>{r&&!t&&r.replaceChildren(n())}}}const{onHover:Ne,onClick:Ln,onSelect:ce,onViewOptionsChange:Tn,showTooltip:Pn=!0,showToolbar:he=!0,showMetadataBadge:On=!0,toolbarControls:Rt="full",showPlotModeSelector:Rn=!0,minZoom:In=.4,maxZoom:Fn=20,summaryPanel:De,renderTooltip:It,passBins:st=[1],showHelpButton:Wn=!1,userGuideExtension:Hn,onExpand:Ft,showExpandButton:Wt=!0,zIndex:An,insights:Ht,warnings:At,viewOptions:Yn={},...ie}=C,zn=Ht?.enabled??!1,Yt=At?.display??!0,Xn=gi(An);let Be=ie.fallbackFormat,oe=C.statsSummary,ae=[],zt=!1;function Xt(){const e=Ri({result:m,statsSummary:oe}),t=e.length!==ae.length||e.some((n,o)=>n.code!==ae[o]?.code||n.message!==ae[o]?.message);ae=e,(t||!zt)&&(zt=!0,At?.onWarning?.(e))}Xt();let lt=m,J=m.wafer,se=m.dies,E=new Set,$=m.hbinDefs,G=m.sbinDefs,ee=m.testDefs,le=m.metadataFields,Nt=m.reticles?.length?m.reticles:void 0,Kt=m.reticleConfig,Vt=m.view?.dataAxisFlip,rt=m.isLotStack??!1,dt=m.aggrMethod,ct=m.lotSize,jt=!1,T=null;On&&(T=zi(J.metadata,{lotStack:_t(),ownerDocument:g}),T.isEmpty()||M.appendChild(T.el));function _t(){return rt?{lotSize:ct??1,aggrMethod:dt}:void 0}function Nn(){if(!T)return;T.update(J.metadata,_t());const e=T.el.isConnected;T.isEmpty()&&e?T.el.remove():!T.isEmpty()&&!e&&M.appendChild(T.el)}const $t=[...$??[],...G??[]].some(e=>e.color);let l={plotMode:"hardBin",colorScheme:$t?"custom":"default",showDieLabels:!1,showPartialDies:!0,showRingBoundaries:!1,showQuadrantBoundaries:!1,showReticle:!1,showXYIndicator:!1,ringCount:4,rotation:0,flipX:!1,flipY:!1,legendPosition:ie.legendPosition??"default",...Yn},re=null,me=!1;zn&&(re=Yi({getItems:()=>[{wafer:J,dies:se,hbinDefs:$,sbinDefs:G,testDefs:ee,label:String(J.metadata?.waferId??""),statsSummary:oe}],getColorSchemeName:()=>l.colorScheme??"default",passBins:st,getRingCount:()=>l.ringCount??4,onSaveImage:C.onSaveImage,onSaveText:C.onSaveText,defaultView:Ht?.defaultView,backTab:{label:"Map",onBack:()=>pt(!1)},ownerDocument:g}),Object.assign(re.el.style,{position:"absolute",inset:"0",background:S.panelBg,overflowY:"auto",paddingTop:he?"44px":"0"}),q.appendChild(re.el));function pt(e){re&&(me=e,re.el.style.display=e?"flex":"none",H&&(H.style.display=e||ze?"none":"flex"),k&&(k.style.display=e?"none":"flex"),Z&&(Z.style.display=e?"none":"flex"),T&&(T.el.style.display=e||jt?"none":""),Ze(),A&&(A.innerHTML=e?En.wafer:En.analysis,A.ariaLabel=e?"Back to wafer view":"Insights"),e&&re.render())}let y,Gt,W=null,P=null,ft=[],ke=null,ut=ie.legendOffset??{x:0,y:0},Le=!1,ye=!1,Te={x:0,y:0},gt={x:0,y:0},pe=!1,be=!1,Y="pan",ve={x:0,y:0},Ke={x:0,y:0},O={x:0,y:0},R={x:0,y:0},Pe=!1,xe=!1;function Oe(){const e=l;y=oi(J,se.filter(Xi),{plotMode:e.plotMode,colorScheme:e.colorScheme,passBins:st,showDieLabels:e.showDieLabels,showPartialDies:e.showPartialDies,showRingBoundaries:e.showRingBoundaries,showQuadrantBoundaries:e.showQuadrantBoundaries,showReticle:e.showReticle,showXYIndicator:e.showXYIndicator,reticles:Nt,ringCount:e.ringCount,highlightBin:e.highlightBin,highlightMetadataValue:e.highlightMetadataValue,activeTest:e.activeTest,activeMetadataKey:e.activeMetadataKey,testDefs:ee,valueRange:e.valueRange,logScale:e.logScale,isLotStack:rt,aggregationMethod:dt??e.aggregationMethod,lotSize:ct??e.lotSize,dataAxisFlip:Vt,colorbarRangeMode:e.colorbarRangeMode,passFailDisplay:e.passFailDisplay,fallbackFormat:Be,interactiveTransform:{rotation:e.rotation??0,flipX:e.flipX??!1,flipY:e.flipY??!1}},{hbinDefs:$,sbinDefs:G,metadataFields:le}),Gt=new Map(y.dies.map((t,n)=>[Ee(t),n]))}Oe();let z=null,fe=null,Ve=null,Kn={},I=null,te=null;function Vn(e){const{kind:t,index:n}=e.variable;x(t==="test"?{plotMode:"value",activeTest:n??0,highlightBin:void 0}:t==="softBin"?{plotMode:"softBin",highlightBin:void 0}:{plotMode:"hardBin",highlightBin:void 0});const o=e.highlight;o.kind==="bin"?(xt(o.dieKeys),x({highlightBin:o.bin})):(o.kind==="region"||o.kind==="dies")&&xt(o.dieKeys)}function Zt(e){Oi(e,{wafer:J,dies:se,yieldSummary:lt.yield,dataCoverage:lt.dataCoverage,hbinDefs:$,sbinDefs:G,testDefs:ee,statsSummary:oe,warnings:Yt?ae:[],passBins:st,ringCount:l.ringCount??4,colorScheme:l.colorScheme,fallbackFormat:Be,activeFindingId:Ve,findingsFilter:Kn,onFindingsFilterChange:ue,onSaveText:C.onSaveText,metadataFields:le,dieListOptions:C.dieList,onFindingClick:(t,n)=>{Ve===t.id?(Ve=null,xt([]),x({highlightBin:void 0})):(Ve=t.id,Vn(t)),ue()}})}function ue(){z&&Zt(z)}function je(){I&&Zt(I)}function Qt(e,t){he&&(t==="right"||t==="top")&&(e.style.paddingTop="44px")}if(De?.placement){const e=De.placement;z=Pt(e,g),Qt(z,e);const t=M.parentElement,n=M.nextSibling;fe=Ot(M,z,e),t?.insertBefore(fe,n),ue()}else if(oe){const e=De?.defaultOpen??!he;I=Pt("right",g),Qt(I,"right"),I.style.display=e?"block":"none";const t=M.parentElement,n=M.nextSibling;te=Ot(M,I,"right"),t?.insertBefore(te,n),je()}const v=Pn?Sn(g):null;let D=null,B=null,H=null,k=null,_e=null,F=null,Z=null,$e=null,A=null,ne=null,Ge=null;function Ut(){if(!ne||!Ge)return;const e=ae.length,t=e>0;if(ne.style.display=t?"flex":"none",Ge.style.display=t?"":"none",!t)return;const n=Fi(ae[0]),o=`${e} data ${e===1?"warning":"warnings"}`;ne.style.color=n==="error"?S.errText:S.warnText,ne.ariaLabel=n==="error"?`${o} \u2014 the map may be positionally wrong`:o}const jn=24;let we=null,ht=null,qt=null,mt=null,yt=null,bt=null,vt=null;function xt(e){E=new Set(e??[]),ce&&ce(Mt()),w()}function Ze(){if(!F)return;const e=!!(z??I);F.style.display=oe&&e&&!me?"flex":"none";const t=z??I,n=t?t.style.display!=="none":!1;oe?.hasNotableFindings&&!n?F.style.color=S.findingIndicator:F.dataset.active||(F.style.color=S.icon)}if(he){let Q=function(U){Y=U,o(V,U==="zoom"),o(Ie,U==="pan"),_e&&o(_e,U==="select"),a.style.cursor=U==="pan"?"grab":"crosshair"},qe=function(){we&&(clearTimeout(we),we=null),D&&(D.style.opacity="1")},Je=function(){we=setTimeout(()=>{D&&(D.style.opacity="0.35")},600)};D=g.createElement("div"),D.dataset.wmapToolbar="single",Object.assign(D.style,{position:"absolute",top:"4px",right:"4px",display:"flex",flexDirection:"row",alignItems:"center",flexWrap:"wrap-reverse",justifyContent:"flex-end",maxWidth:"calc(100% - 8px)",background:S.menuBg,border:`1px solid ${S.menuBorder}`,borderRadius:"4px",boxShadow:"0 1px 4px rgba(0,0,0,0.12)",zIndex:ui,opacity:"0.35",transition:"opacity 0.2s ease",pointerEvents:"auto"});const e=Sn(g),t=mi(e),{makeBtn:n,setActive:o,makeSep:i,makeMenuRow:d,makeMenuSection:u,makeDropdown:s,makeCheckMenuBtn:r,closeOpenMenu:p,getOpenMenu:c,setOpenMenu:h}=t;ht=p,qt=c,g.addEventListener("click",p,!0),H=g.createElement("div"),Object.assign(H.style,{display:ze?"none":"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),D.appendChild(H);const Me=n("download","Download PNG",Gn);H.appendChild(Me),H.appendChild(i());const V=n("zoomMode","Zoom (drag to zoom region)",()=>Q("zoom")),de=n("zoomIn","Zoom in",()=>Ce(a.clientWidth/2,a.clientHeight/2,1.2)),L=n("zoomOut","Zoom out",()=>Ce(a.clientWidth/2,a.clientHeight/2,1/1.2)),j=n("reset","Reset zoom (double-click)",()=>Ue());H.appendChild(V),H.appendChild(de),H.appendChild(L),H.appendChild(j),H.appendChild(i());const Ie=n("pan","Pan (drag to move)",()=>Q("pan"));if(H.appendChild(Ie),_e=n("boxSelect","Select (drag to select dies)",()=>Q("select")),H.appendChild(_e),o(Ie,!0),Rt!=="view-only"){let U=function(f){return f.plotMode!==(l.plotMode??"hardBin")?!1:f.plotMode==="value"?(l.activeTest??0)===(f.activeTest??0):f.plotMode==="metadata"?l.activeMetadataKey===f.activeMetadataKey:!0},Fe=function(f,b){f.activeTest!==void 0?x({plotMode:f.plotMode,activeTest:f.activeTest,activeMetadataKey:void 0,logScale:f.logScale}):f.activeMetadataKey!==void 0?x({plotMode:f.plotMode,activeTest:void 0,activeMetadataKey:f.activeMetadataKey,passFailDisplay:"off"}):x({plotMode:f.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),b.remove(),h(null),Ye(_,!1)};B=g.createElement("div"),Object.assign(B.style,{display:"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),D.appendChild(B),k=g.createElement("div"),Object.assign(k.style,{display:"flex",alignItems:"center",gap:"0"}),B.appendChild(k),k.appendChild(i());const et=()=>{const f=c();f&&(f.remove(),h(null)),Ye(_,!1)},_=n("mode","Plot mode",()=>{if(c()){et();return}const f=se,b=y.testDefs,{testEntries:nt,binEntries:ge,stackedEntries:We}=Li(f,b,{includeStacked:y.isLotStack}),Et=(le??[]).filter(Ae=>Ti(f,Ae.key)).map(Pi),He=yi(_.getBoundingClientRect(),nt,ge,We,U,Fe,{makeMenuRow:d,makeMenuSection:u},l.plotMode??"hardBin",_.ownerDocument.defaultView??window,Et);Cn(_).appendChild(He),h(He),Ye(_,!0),Mn(He,_,et)});Ye(_,!1);const{btn:Zn,sync:Qn}=xi(t,()=>l.plotMode??"hardBin",()=>l.colorScheme??"default",()=>$t,f=>x({colorScheme:f}),{get:()=>l.markFailingDies??!1,set:f=>x({markFailingDies:f})});yt=Qn,yt();const Un=Ci(t,()=>{const f=!!y.hasReticle,b=(l.plotMode??"hardBin")==="value",{testNumber:nt}=Dt(l.activeTest??0,y.testDefs),ge=it(y.testDefs,nt),We=b&&ge!==void 0&&!Bt(ge),Et=b&&!We&&(ge?.limitLow!==void 0||ge?.limitHigh!==void 0),He=b&&!We&&y.dies.some(Ae=>pi(Ae,nt,ge)!==void 0);return[{label:"Ring boundaries",active:!!l.showRingBoundaries,onClick:()=>x({showRingBoundaries:!l.showRingBoundaries})},{label:"Quadrant lines",active:!!l.showQuadrantBoundaries,onClick:()=>x({showQuadrantBoundaries:!l.showQuadrantBoundaries})},{label:"Die labels",active:!!l.showDieLabels,onClick:()=>x({showDieLabels:!l.showDieLabels})},{label:"Reticle grid",active:!!l.showReticle,enabled:f,onClick:()=>x({showReticle:!l.showReticle})},{label:"XY indicator",active:!!l.showXYIndicator,onClick:()=>x({showXYIndicator:!l.showXYIndicator})},...Bi({functionalActive:We,hasLimits:Et,hasRecorded:He,display:Tt(l)},Ae=>x({passFailDisplay:Ae}))]},()=>!!(l.showRingBoundaries||l.showQuadrantBoundaries||l.showDieLabels||l.showReticle||l.showXYIndicator||Tt(l)!=="off")),{btn:qn,sync:Jn}=Si(t,()=>l,f=>x({legendPosition:f}));mt=Jn,mt();const xn=()=>{const{testNumber:f}=Dt(l.activeTest??0,ee),b=it(ee,f);return b!==void 0&&!Bt(b)},{btn:ei,sync:ti}=wi(t,()=>({...l,functionalActive:xn()}),f=>x(f));bt=ti,bt();const ni=()=>{const{testNumber:f}=Dt(l.activeTest??0,ee),b=it(ee,f);return b!==void 0&&(b.limitLow!==void 0||b.limitHigh!==void 0)},tt=n("specRange","Colorbar range: spec limits",()=>{const f=l.colorbarRangeMode==="data"?"spec":"data";x({colorbarRangeMode:f})});vt=()=>{const f=l.plotMode==="value"&&ni()&&Tt(l)==="off"&&!xn();tt.style.display=f?"":"none";const b=(l.colorbarRangeMode??"spec")==="spec";o(tt,b),tt.ariaLabel=b?"Colorbar range: spec limits (click for data range)":"Colorbar range: data range (click for spec limits)"},vt();const ii=Mi(t,()=>l,f=>x(f));Rn&&k.appendChild(_),k.appendChild(Zn),k.appendChild(ei),k.appendChild(tt),ze||(k.appendChild(i()),k.appendChild(Un),k.appendChild(i()),k.appendChild(qn),k.appendChild(i()),k.appendChild(ii)),oe&&(F=n("findings","Summary panel",()=>{const f=z??I;if(!f)return;const b=f.style.display!=="none";f.style.display=b?"none":"block",o(F,!b),Ze()}),B.appendChild(i()),B.appendChild(F),I?.style.display!=="none"&&o(F,!0),Ze()),Yt&&(Ge=i(),ne=n("warning","Data warnings",()=>{const f=c();if(p(new MouseEvent("click")),f)return;const b=Ii(ne.getBoundingClientRect(),ae,K);Cn(q).appendChild(b),h(b),Mn(b,ne,()=>p(new MouseEvent("click")))}),Ye(ne,!1),B.appendChild(Ge),B.appendChild(ne),Ut()),Wt&&(B.appendChild(i()),Z=n("expand","Expand (E)",Ft??Jt),B.appendChild(Z)),re&&(B.appendChild(i()),A=n("analysis","Insights",()=>{pt(!me),o(A,me)}),A.dataset.wmapInsightsBtn="1",B.appendChild(A)),Wn&&(B.appendChild(i()),$e=n("help","User guide",()=>vn()),B.appendChild($e))}q.appendChild(D),a.addEventListener("mouseenter",qe),a.addEventListener("mouseleave",Je),D.addEventListener("mouseenter",qe),D.addEventListener("mouseleave",Je)}let Se=null;function Jt(){Se&&(Se.close(),Se=null);const e=fe??te??M;e.style.flex="1",e.style.minWidth="0",e.style.minHeight="0";const t=bi(D?[e,D]:[e],{ownerDocument:g,onClosed:()=>{Se=null,Z&&(Z.style.display="flex"),a.focus({preventScroll:!0})}});t&&(D&&(t.contentWrap.style.position="relative"),Se=t,Z&&(Z.style.display="none"))}function en(e){const t=l.plotMode;if(l={...l,...e},e.plotMode!==void 0&&e.plotMode!==t){W=null;const i=l.plotMode;(i==="hardBin"||i==="softBin")&&!new Set(["default","accessible","custom"]).has(l.colorScheme??"")&&(l={...l,colorScheme:"default"})}Object.keys(e).every(i=>i==="legendPosition"||i==="showLegend"||i==="markFailingDies")||Oe(),mt?.(),yt?.(),bt?.(),vt?.(),w();const o=e.plotMode!==void 0&&e.plotMode!==t;(e.colorScheme!==void 0||o)&&(ue(),je()),(e.colorScheme!==void 0||o||e.activeTest!==void 0||e.logScale!==void 0||e.colorbarRangeMode!==void 0)&&Xe?.()}function x(e){en(e);const t=Object.keys(e);Tn?.(l,t,classifyChanged(t))}let wt=!1;function St(){wt||(wt=!0,Lt(()=>{wt=!1,w()},K))}function w(){const e=P??void 0,t=y.dies[0],n=t?{x:t.width,y:t.height}:ie.diePitchMm,o=Math.floor(a.clientWidth||a.width),i=!!($?.length||G?.length||y.dies.some(h=>h.hbin!=null||h.sbin!=null)),d=l.legendPosition??"default",u=l.showLegend??!0,s=d==="default"||d==="compact",r=(ie.colorbarWidth??16)+28,p=i&&s?d!=="default"?Math.max(wn,r):o<di?0:o<ri?Math.max(li,r):Math.max(wn,r):void 0,c=si(a,y,{...ie,topClearance:he?jn:0,minRightReserve:u?p:0,showColorbar:u&&(ie.showColorbar??!0),markFailingDies:l.markFailingDies??!1,legendPosition:d,legendOffset:ut,diePitchMm:n,fallbackFormat:Be,showAxes:ie.showAxes??P!==null,viewport:e,activeBin:l.plotMode==="metadata"?l.highlightMetadataValue:l.highlightBin,hbinDefs:$,sbinDefs:G,metadataFields:le});ft=c.binLegendRows,ke=c.legendBox??null,W||(W=c.viewport),E.size>0&&_n(),be&&$n()}function _n(){const e=X();if(!e)return;const t=a.getContext("2d"),n=y.hoverPoints,o=y.rectangles[0],i=o?o.width/2*e.ppm:e.ppm*.5,d=o?o.height/2*e.ppm:e.ppm*.5,u=Math.max(1,Math.min(3,i*.08)),s=i-u,r=d-u,p=[];for(const c of E){const h=Gt.get(c);h!==void 0&&p.push({sx:e.originX+n[h].x*e.ppm,sy:e.originY-n[h].y*e.ppm})}if(p.length){t.save(),t.setLineDash([]),t.fillStyle="rgba(0,0,0,0.12)",t.beginPath();for(const{sx:c,sy:h}of p)t.rect(c-s,h-r,s*2,r*2);t.fill(),t.strokeStyle="rgba(255,255,255,0.9)",t.lineWidth=3,t.beginPath();for(const{sx:c,sy:h}of p)t.rect(c-s,h-r,s*2,r*2);t.stroke(),t.strokeStyle="rgba(0,0,0,0.9)",t.lineWidth=1.5,t.beginPath();for(const{sx:c,sy:h}of p)t.rect(c-s,h-r,s*2,r*2);t.stroke(),t.restore()}}function $n(){const e=a.getContext("2d"),t=Math.min(O.x,R.x),n=Math.min(O.y,R.y),o=Math.abs(R.x-O.x),i=Math.abs(R.y-O.y);e.save(),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(t,n,o,i),e.setLineDash([5,3]),e.strokeStyle="rgba(255,255,255,0.9)",e.lineWidth=3,e.strokeRect(t,n,o,i),e.strokeStyle="rgba(0,0,0,0.9)",e.lineWidth=1.5,e.strokeRect(t,n,o,i),e.restore()}function Gn(){a.toBlob(e=>{e&&Ei(e,C.downloadFilename??"wafermap",C.onSaveImage)})}function tn(e){return W?Math.max(W.ppm*In,Math.min(W.ppm*Fn,e)):e}function Ce(e,t,n){const o=P??W;if(!o)return;const i=tn(o.ppm*n),d=i/o.ppm,u=e-(e-o.originX)*d,s=t-(t-o.originY)*d,r=(W?.snapDist??1)/(i/(W?.ppm??i));P={originX:u,originY:s,ppm:i,snapDist:r},w()}function X(){return P??W}function nn(e){if(e.ctrlKey||e.metaKey){e.preventDefault();const t=a.getBoundingClientRect(),n=e.deltaY<0?1.12:1/1.12;Ce(e.clientX-t.left,e.clientY-t.top,n)}else if(P!==null){e.preventDefault();const t=X(),n=P.snapDist;P={originX:t.originX-e.deltaX,originY:t.originY-e.deltaY,ppm:t.ppm,snapDist:n},w()}}function on(e,t,n){return e>=n.x&&e<n.x+n.w&&t>=n.y&&t<n.y+n.h}function an(e){if(e.button!==0||!X())return;a.focus({preventScroll:!0}),a.setPointerCapture(e.pointerId);const t=a.getBoundingClientRect(),n=e.clientX-t.left,o=e.clientY-t.top;if(ke&&l.legendPosition==="floating"&&on(n,o,ke)){ye=!0,Te={x:n,y:o},gt={...ut};return}if(Pe&&Y!=="pan"){xe=!0,pe=!0,ve={x:n,y:o},Ke={x:X().originX,y:X().originY},a.style.cursor="grabbing";return}if(Y==="zoom"||Y==="select"){be=!0,O=R={x:n,y:o};return}pe=!0,ve={x:n,y:o},Ke={x:X().originX,y:X().originY},a.style.cursor="grabbing"}function sn(e){const t=a.getBoundingClientRect(),n=e.clientX-t.left,o=e.clientY-t.top;if(be){R={x:n,y:o},St();return}if(ye){const c=n-Te.x,h=o-Te.y;c*c+h*h>16&&(ye=!1,Le=!0,a.style.cursor="grabbing")}if(Le){ut={x:gt.x+(n-Te.x),y:gt.y+(o-Te.y)},St();return}if(pe){const c=X(),h=P?.snapDist??W?.snapDist??1;P={originX:Ke.x+(n-ve.x),originY:Ke.y+(o-ve.y),ppm:c.ppm,snapDist:h},St();return}const i=X();if(!i)return;const d=(n-i.originX)/i.ppm,u=(i.originY-o)/i.ppm,r=cn(d,u,i.snapDist)?.die??null,p=ft.find(c=>n>=c.x&&n<c.x+c.w&&o>=c.y&&o<c.y+c.h);if(p){a.style.cursor="pointer",v&&(v.innerHTML=p.label??`Bin ${p.bin}`,v.style.display="block",kt(v,a,e.clientX,e.clientY)),Ne?.(null,e);return}if(Y==="pan"&&(a.style.cursor=r?"crosshair":"grab"),v)if(r)if(It){const c=It(r);c===null?v.style.display="none":(typeof c=="string"?v.innerHTML=c:(v.innerHTML="",v.appendChild(c)),v.style.display="block",kt(v,a,e.clientX,e.clientY))}else v.innerHTML=ai(r,y.plotMode,{testDefs:ee,hbinDefs:$,sbinDefs:G,fallbackFormat:Be,aggrMethod:y.aggrMethod,lotSize:y.lotSize,waferMeta:J.metadata,metadataFields:le,activeTest:y.activeTest,reticleConfig:Kt}),v.style.display="block",kt(v,a,e.clientX,e.clientY);else v.style.display="none";Ne?.(r,e)}function ln(e){const t=a.getBoundingClientRect(),n=e.clientX-t.left,o=e.clientY-t.top,i=e.ctrlKey||e.metaKey;if(v&&(n<0||o<0||n>t.width||o>t.height)&&(v.style.display="none"),be){be=!1,R={x:n,y:o};const s=n-O.x,r=o-O.y,p=X();if(Y==="zoom"){if(s*s+r*r<25)Ce(n,o,2);else if(p){const c=Math.min(O.x,R.x),h=Math.max(O.x,R.x),Q=Math.min(O.y,R.y),Me=Math.max(O.y,R.y),V=h-c,de=Me-Q;if(V>4&&de>4){const L=a.clientWidth,j=a.clientHeight,Ie=L/V,qe=j/de,Je=Math.min(Ie,qe),U=tn(p.ppm*Je),Fe=U/p.ppm,et=(c+h)/2,_=(Q+Me)/2;P={originX:L/2-(et-p.originX)*Fe,originY:j/2-(_-p.originY)*Fe,ppm:U,snapDist:p.snapDist/Fe}}}w(),a.style.cursor="crosshair";return}if(s*s+r*r<25)Ct(n,o,i,e);else if(p){const c=(Math.min(O.x,R.x)-p.originX)/p.ppm,h=(Math.max(O.x,R.x)-p.originX)/p.ppm,Q=(p.originY-Math.max(O.y,R.y))/p.ppm,Me=(p.originY-Math.min(O.y,R.y))/p.ppm,V=y.hoverPoints,de=[];for(let L=0;L<V.length;L++)if(V[L].x>=c&&V[L].x<=h&&V[L].y>=Q&&V[L].y<=Me){const j=y.dies[L];j&&de.push(j)}if(i)for(const L of de){const j=Ee(L);E.has(j)?E.delete(j):E.add(j)}else E=new Set(de.map(L=>Ee(L)));ce?.(Mt())}w(),a.style.cursor="crosshair";return}if(ye){ye=!1,Ct(n,o,i,e);return}if(Le){Le=!1,a.style.cursor="grab";return}if(!pe)return;if(pe=!1,xe){xe=!1,a.style.cursor=Pe||Y==="pan"?"grab":"crosshair";return}a.style.cursor=Y==="pan"?"grab":"crosshair";const d=n-ve.x,u=o-ve.y;d*d+u*u<25&&Ct(n,o,i,e)}function Ct(e,t,n,o){for(const s of ft)if(e>=s.x&&e<s.x+s.w&&t>=s.y&&t<s.y+s.h){if(typeof s.bin=="number"){const r=l.highlightBin===s.bin?void 0:s.bin;x({highlightBin:r})}else{const r=l.highlightMetadataValue===s.bin?void 0:s.bin;x({highlightMetadataValue:r})}return}if(ke&&on(e,t,ke))return;const i=X();if(!i)return;const u=cn((e-i.originX)/i.ppm,(i.originY-t)/i.ppm,i.snapDist)?.die??null;if(u){Ln?.(u,o);const s=Ee(u);n?E.has(s)?E.delete(s):E.add(s):E=new Set([s]),ce?.(Mt()),w()}else n||(E=new Set,ce?.([]),w())}function Mt(){const e=[],t=y.hoverPoints;for(let n=0;n<t.length;n++){const o=y.dies[n];o&&E.has(Ee(o))&&e.push(o)}return e}function rn(){v&&ot(g),Ne?.(null,new MouseEvent("mouseleave")),a.style.cursor=Y==="pan"?"grab":"crosshair"}function dn(){pe=!1,xe=!1,be=!1,ye=!1,Le=!1,v&&ot(g),Ne?.(null,new MouseEvent("mouseleave")),a.style.cursor=Y==="pan"?"grab":"crosshair",w()}function cn(e,t,n){const o=y.hoverPoints,i=y.rectangles;for(let r=0;r<i.length;r++){const p=i[r];if(Math.abs(e-p.x)<=p.width/2&&Math.abs(t-p.y)<=p.height/2){const c=y.dies[r];return c?{die:c,index:r}:null}}let d=null,u=-1,s=n*n;for(let r=0;r<o.length;r++){const p=o[r].x-e,c=o[r].y-t,h=p*p+c*c;h<s&&(s=h,d=y.dies[r]??null,u=r)}return d?{die:d,index:u}:null}const pn=new K.ResizeObserver(()=>{W=null,P=null,w()});pn.observe(a),C.height==null&&kn<=0&&Lt(()=>Lt(()=>{N.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 Re=K.matchMedia(`(resolution: ${K.devicePixelRatio}dppx)`);const Qe=()=>{Re.removeEventListener("change",Qe),Re=K.matchMedia(`(resolution: ${K.devicePixelRatio}dppx)`),Re.addEventListener("change",Qe),w()};Re.addEventListener("change",Qe);const fn=K.matchMedia("(prefers-color-scheme: dark)"),un=()=>w();fn.addEventListener("change",un);const gn=()=>{v&&ot(g)};K.addEventListener("blur",gn);function hn(e){if(e.key==="Escape"&&E.size>0&&(E=new Set,ce?.([]),w()),(e.key==="e"||e.key==="E")&&Rt!=="view-only"&&Wt&&!me&&(e.stopPropagation(),(Ft??Jt)()),(e.ctrlKey||e.metaKey)&&(e.key==="="||e.key==="+"?(e.preventDefault(),Ce(a.clientWidth/2,a.clientHeight/2,1.2)):e.key==="-"?(e.preventDefault(),Ce(a.clientWidth/2,a.clientHeight/2,1/1.2)):e.key==="0"&&(e.preventDefault(),Ue())),!e.ctrlKey&&!e.metaKey&&!e.shiftKey){const n=X();if(n){const o=P?.snapDist??W?.snapDist??1;let i=0,d=0;e.key==="ArrowLeft"&&(i=20,e.preventDefault()),e.key==="ArrowRight"&&(i=-20,e.preventDefault()),e.key==="ArrowUp"&&(d=20,e.preventDefault()),e.key==="ArrowDown"&&(d=-20,e.preventDefault()),(i||d)&&(P={originX:n.originX+i,originY:n.originY+d,ppm:n.ppm,snapDist:o},w())}e.key===" "&&!Pe&&(e.preventDefault(),Pe=!0,Y!=="pan"&&(a.style.cursor="grab"))}}function mn(e){e.key===" "&&(Pe=!1,xe&&(pe=!1,xe=!1),a.style.cursor=Y==="pan"?"grab":"crosshair")}a.style.cursor="grab",a.setAttribute("tabindex","0"),a.addEventListener("wheel",nn,{passive:!1}),a.addEventListener("pointerdown",an),a.addEventListener("pointermove",sn),a.addEventListener("pointerup",ln),a.addEventListener("pointerleave",rn),a.addEventListener("pointercancel",dn);const yn=()=>Ue();a.addEventListener("dblclick",yn),a.addEventListener("keydown",hn),a.addEventListener("keyup",mn);const bn=e=>{e.stopPropagation()};a.addEventListener("click",bn),a.clientWidth,w(),Xe?.();function Ue(){W=null,P=null,w()}function vn(){import("./userGuideHtml.js").then(e=>vi({buildWaferMap:ci,renderWaferMap,renderWaferGallery:void 0,analyzeWaferMap:fi},e.USER_GUIDE_HTML,Hn,N))}return{setDies(e){se=e,Oe(),w(),z&&ue()},setResult(e){lt=e,J=e.wafer,se=e.dies,$=e.hbinDefs,G=e.sbinDefs,ee=e.testDefs,le=e.metadataFields,Nt=e.reticles?.length?e.reticles:void 0,Kt=e.reticleConfig,Vt=e.view?.dataAxisFlip,rt=e.isLotStack,dt=e.aggrMethod,ct=e.lotSize,Nn(),Oe(),w(),z&&ue()},setOptions(e){en(e)},getOptions(){return{...l}},resetZoom:Ue,setSelection(e){E=new Set(e.map(t=>Ee(t))),w()},clearSelection(){E=new Set,ce?.([]),w()},setFallbackFormat(e){Be=e,Oe(),w()},setStatsSummary(e){if(oe=e,Xt(),Ut(),z)ue();else if(I)je();else if(e&&!De?.placement){const t=De?.defaultOpen??!he;I=Pt("right",g),I.style.display=t?"block":"none";const n=M.parentElement,o=M.nextSibling;te=Ot(M,I,"right"),n?.insertBefore(te,o),je()}Ze()},setSummaryVisible(e){F&&(F.style.display=e?"flex":"none")},setViewControlsVisible(e){B&&(B.style.display=e?"flex":"none")},setExpandVisible(e){Z&&(Z.style.display=e?"flex":"none")},setHelpButtonVisible(e){$e&&($e.style.display=e?"flex":"none")},setMetadataBadgeVisible(e){jt=!e,T&&(T.el.style.display=e&&!me?"":"none")},openUserGuide:vn,setInsightsOpen(e){pt(e),A&&(e?(A.dataset.active="1",A.style.background=S.bgActive,A.style.color=S.iconActive):(delete A.dataset.active,A.style.background="transparent",A.style.color=S.icon))},closeSummaryPanel(){const e=z??I;!e||e.style.display==="none"||(e.style.display="none",F&&(delete F.dataset.active,F.style.background="transparent",F.style.color=S.icon))},setTooltipParent(e){v&&hi(e)},getActiveLegend(){const e=l.plotMode;if(e==="metadata"){const i=l.activeMetadataKey;if(!i)return null;const d=le?.find(s=>s.key===i),u=[...new Set(se.map(s=>s.metadata?.[i]).filter(s=>s!=null&&(typeof s=="string"||typeof s=="number"||typeof s=="boolean")).map(String))].sort();return u.length?u.map((s,r)=>{const p=d?.values?.find(h=>h.value===s),c=p?.color??Ai(r);return{bin:s,name:p?.label??s,color:c}}):null}if(e!=="hardBin"&&e!=="softBin")return null;const t=e==="hardBin",n=t?$:G,o=[...new Set(se.map(i=>t?i.hbin:i.sbin).filter(i=>i!==void 0))].sort((i,d)=>i-d);return o.length?o.map(i=>{const d=n?.find(s=>s.bin===i),u=d?.color??(t?Wi(i):Hi(i));return{bin:i,name:d?.name??`Bin ${i}`,color:u}}):null},destroy(){Se?.close(),we&&clearTimeout(we),qt?.()?.remove(),ht&&g.removeEventListener("click",ht,!0),a.removeEventListener("wheel",nn),a.removeEventListener("pointerdown",an),a.removeEventListener("pointermove",sn),a.removeEventListener("pointerup",ln),a.removeEventListener("pointerleave",rn),a.removeEventListener("pointercancel",dn),a.removeEventListener("dblclick",yn),a.removeEventListener("keydown",hn),a.removeEventListener("keyup",mn),a.removeEventListener("click",bn),pn.disconnect(),Re.removeEventListener("change",Qe),fn.removeEventListener("change",un),K.removeEventListener("blur",gn),Xn(),v&&ot(g),D?.remove(),fe&&(fe.parentElement?.insertBefore(M,fe),fe.remove()),te&&(te.parentElement?.insertBefore(M,te),te.remove()),M.remove(),a.style.cursor="",re?.destroy(),T?.destroy(),q.remove()}}}
|
|
1
|
+
import{buildView as ui,buildHoverText as gi,findTestDef as st,resolveTestNumber as At}from"../renderer/buildView.js";import{toCanvas as hi,BIN_LEGEND_W as Rn,BIN_LEGEND_W_COMPACT as mi,BIN_LEGEND_ADAPT_COMPACT as yi,BIN_LEGEND_ADAPT_FLOATING as bi}from"./toCanvas.js";import{buildWaferMap as vi,getTestPassStatus as xi,isParametricTest as zt}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as wi}from"../stats/analyzeWaferMap.js";import{SHADOW as Si,LEADING as In,wireControlHover as Hn,SPACE as H,EDGE_GUTTER as Mi,RADIUS as Wn,FONT as rt,CLR as x,applyOverlayZ as Ci,getTooltip as Fn,hideTooltip as dt,reparentTooltip as Ei,positionTooltip as Yt,createToolbarHelpers as Di,buildModeMenuEl as ki,openReparentedModal as Bi,openUserGuideWindow as Li,makePaletteBtn as Pi,makeLogScaleBtn as Ti,makeLegendStyleBtn as Oi,makeOverlaysBtn as Ri,makeOrientationBtn as Ii,menuLayerFor as An,saveImageBlob as Hi,markMenuTrigger as Ve,wireMenuA11y as zn,wireExpandToggle as Wi,nextFrame as Nt,requestedPassFailDisplay as Fi,overlayMenuRows as Ai,anyOverlayActive as zi,logWmapVersionOnce as Yi,buildDataModeEntries as Ni,metadataKeyHasData as Xi,metadataModeEntry as ji}from"./toolbar.js";import{createSummaryPanelEl as Xt,wrapWithSummaryPanel as jt,renderWaferSummaryContent as Vi}from"./summaryPanel.js";import{collectWarnings as Ki,buildWarningsMenuEl as $i,severityOf as _i}from"./warnings.js";import{ICONS as Yn}from"./icons.js";import{hardBinColor as Gi,softBinColor as Zi,metadataValueColor as Ui}from"../renderer/colorMap.js";import{createIdentityHeader as Qi,collapsedLabel as Vt}from"./identityHeader.js";import{getDieKey as De,hasPosition as Nn,isPositionedDie as qi}from"../core/dies.js";import{buildDieListSection as Ji}from"./dieList.js";import{buildMaplessSummary as eo}from"./maplessSummary.js";const Xn=new Set(["colorScheme","rotation","flipX","flipY","showDieLabels","showPartialDies","showRingBoundaries","showQuadrantBoundaries","showReticle","showXYIndicator","ringCount","legendPosition","logScale","colorbarRangeMode","markFailingDies"]);export function classifyChanged(j){const m=j.some(u=>Xn.has(u)),w=j.some(u=>!Xn.has(u));return m&&w?"mixed":m?"preference":"state"}export function renderWaferMap(j,m,w={}){Yi();const u=j.ownerDocument,V=u.defaultView??window;V.getComputedStyle(j).position==="static"&&(j.style.position="relative");const jn=j.clientHeight;w.height!=null&&(j.style.height=typeof w.height=="number"?`${w.height}px`:w.height);const ct=m.dataCoverage?m.dataCoverage.unpositionedDies:m.dies.filter(e=>!Nn(e)).length,Ke=(m.dataCoverage?m.dataCoverage.totalDies:m.dies.length-ct)===0&&ct>0,ke=u.createElement("div");Object.assign(ke.style,{display:"flex",flexDirection:"column",width:"100%",height:"100%"}),j.appendChild(ke);const oe=u.createElement("div");Object.assign(oe.style,{position:"relative",width:"100%",flex:"1 1 auto",minHeight:"0"}),w.maxSize!=null&&(oe.style.maxWidth=`${w.maxSize}px`,oe.style.maxHeight=`${w.maxSize}px`);const ue=w.chromeInset??Mi,J=u.createElement("div");Object.assign(J.style,{display:"flex",alignItems:"stretch",gap:H.sm,background:x.canvasBg,paddingBottom:H.lg,paddingTop:ue,paddingLeft:ue,paddingRight:ue,flexShrink:"0",minWidth:"0"}),ke.appendChild(J),ke.appendChild(oe);const M=u.createElement("div");Object.assign(M.style,{position:"relative",width:"100%",height:"100%"});const a=u.createElement("canvas");Object.assign(a.style,{width:"100%",height:"100%",display:"block"}),M.appendChild(a),oe.appendChild(M);let $e=null;if(ct>0){let n=function(){if(t){const g=Ji(e,m.testDefs,{...w.dieList,onSaveText:w.onSaveText,waferMetadata:K.metadata,metadataFields:de,ownerDocument:u});if(g)return g}const i=st(m.testDefs,d.activeTest??0),s=zt(i)?d.logScale??i?.logScale??!1:!1;return eo(e,m.testDefs,{plotMode:d.plotMode??"hardBin",activeTest:d.activeTest,hbinDefs:G,sbinDefs:Z,colorScheme:d.colorScheme,logScale:s,colorbarRangeMode:d.colorbarRangeMode,valueRangeDies:m.dies})},o=function(i){const s=u.createElement("button");return s.type="button",Hn(s),Object.assign(s.style,{fontSize:rt.body,padding:`${H.xxs} ${H.sm}`,borderRadius:Wn.control,flexShrink:"0",border:`1px solid ${x.menuBorder}`,background:x.menuBg,color:x.text,cursor:"pointer"}),s.textContent=t?"View chart":"View die list",s.addEventListener("click",g=>{g.stopPropagation(),t=!t,s.textContent=t?"View chart":"View die list",i()}),s};const e=m.dies.filter(i=>!Nn(i));let t=!1;if(Ke){const i=u.createElement("div");Object.assign(i.style,{position:"absolute",inset:"0",background:x.panelBg,padding:H.xl,boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",gap:H.md,zIndex:"1"});const s=u.createElement("div");Object.assign(s.style,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:H.md});const g=u.createElement("span");Object.assign(g.style,{fontSize:rt.body,color:x.label,lineHeight:In.base}),g.textContent="No die position data for this wafer.",s.appendChild(g);const l=u.createElement("div");Object.assign(l.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),s.appendChild(o(()=>l.replaceChildren(n()))),i.appendChild(s),i.appendChild(l),M.appendChild(i),$e=()=>{t||l.replaceChildren(n())}}else{const i=u.createElement("div");Object.assign(i.style,{position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"3",background:x.panelBg,borderTop:`1px solid ${x.menuBorder}`,fontSize:rt.body,color:x.text,cursor:"pointer",padding:`${H.xs} ${H.md}`,display:"flex",alignItems:"center",justifyContent:"space-between",gap:H.md}),Hn(i,"bare");const s=u.createElement("span");s.textContent=`+${e.length} ${e.length===1?"die":"dies"} without position data`,i.appendChild(s);const g=u.createElement("span");g.textContent="\u25BE",Object.assign(g.style,{fontSize:rt.body,lineHeight:In.none,color:x.label,flexShrink:"0"}),i.appendChild(g),i.setAttribute("aria-expanded","false"),i.setAttribute("aria-label",`${e.length} dies without position data. Click to view.`);let l=null,r=null;Wi(i,c=>{if(g.textContent=c?"\u25B4":"\u25BE",i.setAttribute("aria-expanded",String(c)),c){l=u.createElement("div");const p=i.getBoundingClientRect().height||28;Object.assign(l.style,{position:"absolute",left:"0",right:"0",bottom:`${p}px`,top:"20%",zIndex:"2",background:x.panelBg,borderTop:`1px solid ${x.menuBorder}`,padding:H.md,boxSizing:"border-box",display:"flex",flexDirection:"column",gap:H.md}),l.addEventListener("click",ie=>ie.stopPropagation());const h=u.createElement("div");Object.assign(h.style,{display:"flex",justifyContent:"flex-end"}),h.appendChild(o(()=>{r&&r.replaceChildren(n())})),l.appendChild(h),r=u.createElement("div"),Object.assign(r.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),r.appendChild(n()),l.appendChild(r),M.appendChild(l)}else l&&(l.remove(),l=null,r=null)}),M.appendChild(i),$e=()=>{r&&!t&&r.replaceChildren(n())}}}const{onHover:_e,onClick:Vn,onSelect:ge,onViewOptionsChange:Kn,showTooltip:$n=!0,showToolbar:Be=!0,showIdentity:Kt=!0,toolbarControls:pt="full",showPlotModeSelector:_n=!0,minZoom:Gn=.4,maxZoom:Zn=20,summaryPanel:Le,renderTooltip:$t,passBins:ft=[1],showHelpButton:_t=!1,userGuideExtension:Un,onExpand:Gt,showExpandButton:Zt=!0,zIndex:Qn,insights:ut,warnings:Ut,viewOptions:qn={},...le}=w,Pe=ut?.enabled??!1,Qt=Ut?.display??!0,Jn=Ci(Qn);let Te=le.fallbackFormat,ae=w.statsSummary,se=[],qt=!1;function Jt(){const e=Ki({result:m,statsSummary:ae}),t=e.length!==se.length||e.some((n,o)=>n.code!==se[o]?.code||n.message!==se[o]?.message);se=e,(t||!qt)&&(qt=!0,Ut?.onWarning?.(e))}Jt();let gt=m,K=m.wafer,re=m.dies,E=new Set,G=m.hbinDefs,Z=m.sbinDefs,ee=m.testDefs,de=m.metadataFields,en=m.reticles?.length?m.reticles:void 0,tn=m.reticleConfig,nn=m.view?.dataAxisFlip,ht=m.isLotStack??!1,mt=m.aggrMethod,yt=m.lotSize;const ei=Be&&pt!=="view-only"&&Pe;let bt=!1,$=null,A=null,U=null;Kt&&($=Qi(Vt(K.metadata??{},Oe())??"",K.metadata,{lotStack:Oe(),ownerDocument:u}),M.appendChild($.metaPanel),$.isEmpty()||(A=on($.wrap),J.insertBefore(A,J.firstChild)));function on(e){const t=u.createElement("div");return Object.assign(t.style,{display:"flex",alignItems:"center",padding:`${H.sm} ${H.lg}`,flex:"1 1 auto",minWidth:"0",overflow:"hidden",gap:H.sm}),Object.assign(e.style,{flex:"1",minWidth:"0"}),t.appendChild(e),t}function Oe(){return ht?{lotSize:yt??1,aggrMethod:mt}:void 0}function ti(){if(!$)return;$.update(Vt(K.metadata??{},Oe())??"",K.metadata,Oe());const e=A?.isConnected??!1,t=!$.isEmpty();!t&&e?(A.remove(),A=null):t&&!e&&(A=on($.wrap),A.style.display=bt?"none":"",J.insertBefore(A,J.firstChild))}const ln=[...G??[],...Z??[]].some(e=>e.color);let d={plotMode:"hardBin",colorScheme:ln?"custom":"default",showDieLabels:!1,showPartialDies:!0,showRingBoundaries:!1,showQuadrantBoundaries:!1,showReticle:!1,showXYIndicator:!1,ringCount:4,rotation:0,flipX:!1,flipY:!1,legendPosition:le.legendPosition??"default",...qn},Q=null,he=!1,an=null;function ni(){return Pe?Q?Promise.resolve(Q):(an??=import("./insightsTab.js").then(({createInsightsTab:e})=>(Q=e({getItems:()=>[{wafer:K,dies:re,hbinDefs:G,sbinDefs:Z,testDefs:ee,label:String(K.metadata?.waferId??""),statsSummary:ae}],getColorSchemeName:()=>d.colorScheme??"default",passBins:ft,getRingCount:()=>d.ringCount??4,onSaveImage:w.onSaveImage,onSaveText:w.onSaveText,defaultView:ut?.defaultView,showMetadataStrip:!1,contentInset:ue,backTab:ei?void 0:{label:"Map",onBack:()=>Ge(!1)},onOpenGuide:_t&&!Be?()=>Rt():void 0,ownerDocument:u}),Object.assign(Q.el.style,{position:"absolute",inset:"0",background:x.canvasBg,overflowY:"auto",paddingTop:"0"}),Q.el.style.display="none",oe.appendChild(Q.el),Q)),an):Promise.resolve(null)}function Ge(e){Pe&&(he=e,Q&&(Q.el.style.display=e?"flex":"none"),W&&(W.style.display=e||Ke?"none":"flex"),P&&(P.style.display=e?"none":"flex"),U&&(U.style.display=ye?"none":"flex"),te&&(te.style.display="flex"),A&&(A.style.display=bt?"none":""),$&&e&&$.collapse(),et(),F&&(F.innerHTML=e?Yn.wafer:Yn.analysis,F.ariaLabel=e?"Back to wafer view":"Insights"),e&&ni().then(t=>{!t||!he||(t.el.style.display="flex",t.render())}))}Pe&&ut?.defaultOpen&&queueMicrotask(()=>Ge(!0));let y,sn,z=null,B=null,vt=[],xt;function rn(e){xt!==e&&(xt=e,v())}let Re=null,wt=le.legendOffset??{x:0,y:0},Ie=!1,ve=!1,He={x:0,y:0},St={x:0,y:0},me=!1,xe=!1,Y="pan",we={x:0,y:0},Ze={x:0,y:0},T={x:0,y:0},O={x:0,y:0},We=!1,Se=!1;function Fe(){const e=d;y=ui(K,re.filter(qi),{plotMode:e.plotMode,colorScheme:e.colorScheme,passBins:ft,showDieLabels:e.showDieLabels,showPartialDies:e.showPartialDies,showRingBoundaries:e.showRingBoundaries,showQuadrantBoundaries:e.showQuadrantBoundaries,showReticle:e.showReticle,showXYIndicator:e.showXYIndicator,reticles:en,ringCount:e.ringCount,highlightBin:e.highlightBin,highlightMetadataValue:e.highlightMetadataValue,activeTest:e.activeTest,activeMetadataKey:e.activeMetadataKey,testDefs:ee,valueRange:e.valueRange,logScale:e.logScale,isLotStack:ht,aggregationMethod:mt??e.aggregationMethod,lotSize:yt??e.lotSize,dataAxisFlip:nn,colorbarRangeMode:e.colorbarRangeMode,passFailDisplay:e.passFailDisplay,fallbackFormat:Te,interactiveTransform:{rotation:e.rotation??0,flipX:e.flipX??!1,flipY:e.flipY??!1}},{hbinDefs:G,sbinDefs:Z,metadataFields:de}),sn=new Map(y.dies.map((t,n)=>[De(t),n]))}Fe();let N=null,Me=null,Ue=null,dn=w.findingsNotice,ii={},R=null,ce=null;function oi(e){const{kind:t,index:n}=e.variable;D(t==="test"?{plotMode:"value",activeTest:n??0,highlightBin:void 0}:t==="softBin"?{plotMode:"softBin",highlightBin:void 0}:{plotMode:"hardBin",highlightBin:void 0});const o=e.highlight;o.kind==="bin"?(Bt(o.dieKeys),D({highlightBin:o.bin})):(o.kind==="region"||o.kind==="dies")&&Bt(o.dieKeys)}function cn(e){Vi(e,{wafer:K,dies:re,yieldSummary:gt.yield,dataCoverage:gt.dataCoverage,hbinDefs:G,sbinDefs:Z,testDefs:ee,statsSummary:ae,warnings:Qt?se:[],passBins:ft,ringCount:d.ringCount??4,colorScheme:d.colorScheme,plotMode:d.plotMode??"hardBin",metadataShownElsewhere:Kt,fallbackFormat:Te,activeFindingId:Ue,findingsFilter:ii,findingsNotice:dn,onFindingsFilterChange:pe,onSaveText:w.onSaveText,metadataFields:de,dieListOptions:w.dieList,onFindingClick:(t,n)=>{Ue===t.id?(Ue=null,Bt([]),D({highlightBin:void 0})):(Ue=t.id,oi(t)),pe()}})}function pe(){N&&cn(N)}function Ae(){R&&cn(R)}if(Le?.placement){const e=Le.placement;N=Xt(e,ue,u);const t=M.parentElement,n=M.nextSibling;Me=jt(M,N,e),t?.insertBefore(Me,n),pe()}else if(ae){const e=Le?.defaultOpen??!Be;R=Xt("right",ue,u),R.style.display=e?"block":"none";const t=M.parentElement,n=M.nextSibling;ce=jt(M,R,"right"),t?.insertBefore(ce,n),Ae()}const S=$n?Fn(u):null;let te=null,L=null,W=null,P=null,Qe=null,I=null,qe=null,F=null,ne=null,Je=null;function pn(){if(!ne||!Je)return;const e=se.length,t=e>0;if(ne.style.display=t?"flex":"none",Je.style.display=t?"":"none",!t)return;const n=_i(se[0]),o=`${e} data ${e===1?"warning":"warnings"}`;ne.style.color=n==="error"?x.errText:x.warnText,ne.ariaLabel=n==="error"?`${o} \u2014 the map may be positionally wrong`:o}let Mt=null,fn=null,Ct=null,Et=null,Dt=null,kt=null;function Bt(e){E=new Set(e??[]),ge&&ge(Ot()),v()}function et(){if(!I)return;const e=!!(N??R);I.style.display=ae&&e&&!he?"flex":"none";const t=N??R,n=t?t.style.display!=="none":!1;ae?.hasNotableFindings&&!n?I.style.color=x.findingIndicator:I.dataset.active||(I.style.color=x.icon)}if(Be){let p=function(k){Y=k,o(ie,k==="zoom"),o(C,k==="pan"),Qe&&o(Qe,k==="select"),a.style.cursor=k==="pan"?"grab":"crosshair"};te=u.createElement("div"),te.dataset.wmapToolbar="single",Object.assign(te.style,{marginLeft:"auto",flexShrink:"0",display:"flex",flexDirection:"row",alignItems:"center",flexWrap:"wrap-reverse",justifyContent:"flex-end",maxWidth:"100%",background:x.menuBg,border:`1px solid ${x.menuBorder}`,borderRadius:Wn.control,boxShadow:Si.panel,pointerEvents:"auto"});const e=Fn(u),t=Di(e),{makeBtn:n,setActive:o,makeSep:i,makeMenuRow:s,makeMenuSection:g,closeOpenMenu:l,getOpenMenu:r,setOpenMenu:c}=t;Mt=l,fn=r,u.addEventListener("click",l,!0),W=u.createElement("div"),Object.assign(W.style,{display:Ke?"none":"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),te.appendChild(W);const h=n("download","Download PNG",si);W.appendChild(h),W.appendChild(i());const ie=n("zoomMode","Zoom (drag to zoom region)",()=>p("zoom")),Ee=n("zoomIn","Zoom in",()=>Ce(a.clientWidth/2,a.clientHeight/2,1.2)),q=n("zoomOut","Zoom out",()=>Ce(a.clientWidth/2,a.clientHeight/2,1/1.2)),fe=n("reset","Reset zoom (double-click)",()=>nt());W.appendChild(ie),W.appendChild(Ee),W.appendChild(q),W.appendChild(fe),W.appendChild(i());const C=n("pan","Pan (drag to move)",()=>p("pan"));if(W.appendChild(C),Qe=n("boxSelect","Select (drag to select dies)",()=>p("select")),W.appendChild(Qe),o(C,!0),pt!=="view-only"){let k=function(f){return f.plotMode!==(d.plotMode??"hardBin")?!1:f.plotMode==="value"?(d.activeTest??0)===(f.activeTest??0):f.plotMode==="metadata"?d.activeMetadataKey===f.activeMetadataKey:!0},It=function(f,b){f.activeTest!==void 0?D({plotMode:f.plotMode,activeTest:f.activeTest,activeMetadataKey:void 0,logScale:f.logScale}):f.activeMetadataKey!==void 0?D({plotMode:f.plotMode,activeTest:void 0,activeMetadataKey:f.activeMetadataKey,passFailDisplay:"off"}):D({plotMode:f.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),b.remove(),c(null),Ve(_,!1)};L=u.createElement("div"),Object.assign(L.style,{display:"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),te.appendChild(L),P=u.createElement("div"),Object.assign(P.style,{display:"flex",alignItems:"center",gap:"0"}),L.appendChild(P),P.appendChild(i());const it=()=>{const f=r();f&&(f.remove(),c(null)),Ve(_,!1)},_=n("mode","Plot mode",()=>{if(r()){it();return}const f=re,b=y.testDefs,{testEntries:at,binEntries:be,stackedEntries:Ne}=Ni(f,b,{includeStacked:y.isLotStack}),Ft=(de??[]).filter(je=>Xi(f,je.key)).map(ji),Xe=ki(_.getBoundingClientRect(),at,be,Ne,k,It,{makeMenuRow:s,makeMenuSection:g},d.plotMode??"hardBin",_.ownerDocument.defaultView??window,Ft);An(_).appendChild(Xe),c(Xe),Ve(_,!0),zn(Xe,_,it)});Ve(_,!1);const{btn:ot,sync:Ye}=Pi(t,()=>d.plotMode??"hardBin",()=>d.colorScheme??"default",()=>ln,f=>D({colorScheme:f}),{get:()=>d.markFailingDies??!1,set:f=>D({markFailingDies:f})});Et=Ye,Et();const Ht=Ri(t,()=>{const f=!!y.hasReticle,b=(d.plotMode??"hardBin")==="value",{testNumber:at}=At(d.activeTest??0,y.testDefs),be=st(y.testDefs,at),Ne=b&&be!==void 0&&!zt(be),Ft=b&&!Ne&&(be?.limitLow!==void 0||be?.limitHigh!==void 0),Xe=b&&!Ne&&y.dies.some(je=>xi(je,at,be)!==void 0);return Ai(d,f,{functionalActive:Ne,hasLimits:Ft,hasRecorded:Xe},je=>D(je))},()=>zi(d)),{btn:Wt,sync:ri}=Oi(t,()=>d,f=>D({legendPosition:f}));Ct=ri,Ct();const On=()=>{const{testNumber:f}=At(d.activeTest??0,ee),b=st(ee,f);return b!==void 0&&!zt(b)},{btn:di,sync:ci}=Ti(t,()=>({...d,functionalActive:On()}),f=>D(f));Dt=ci,Dt();const pi=()=>{const{testNumber:f}=At(d.activeTest??0,ee),b=st(ee,f);return b!==void 0&&(b.limitLow!==void 0||b.limitHigh!==void 0)},lt=n("specRange","Colorbar range: spec limits",()=>{const f=d.colorbarRangeMode==="data"?"spec":"data";D({colorbarRangeMode:f})});kt=()=>{const f=d.plotMode==="value"&&pi()&&Fi(d)==="off"&&!On();lt.style.display=f?"":"none";const b=(d.colorbarRangeMode??"spec")==="spec";o(lt,b),lt.ariaLabel=b?"Colorbar range: spec limits (click for data range)":"Colorbar range: data range (click for spec limits)"},kt();const fi=Ii(t,()=>d,f=>D(f));_n&&P.appendChild(_),P.appendChild(ot),P.appendChild(di),P.appendChild(lt),Ke||(P.appendChild(i()),P.appendChild(Ht),P.appendChild(i()),P.appendChild(Wt),P.appendChild(i()),P.appendChild(fi)),ae&&(I=n("findings","Summary panel",()=>{const f=N??R;if(!f)return;const b=f.style.display!=="none";f.style.display=b?"none":"block",o(I,!b),et()}),L.appendChild(i()),L.appendChild(I),R?.style.display!=="none"&&o(I,!0),et()),Qt&&(Je=i(),ne=n("warning","Data warnings",()=>{const f=r();if(l(new MouseEvent("click")),f)return;const b=$i(ne.getBoundingClientRect(),se,V);An(oe).appendChild(b),c(b),zn(b,ne,()=>l(new MouseEvent("click")))}),Ve(ne,!1),L.appendChild(Je),L.appendChild(ne),pn()),Pe&&(L.appendChild(i()),F=n("analysis","Insights",()=>{Ge(!he),o(F,he)}),F.dataset.wmapInsightsBtn="1",L.appendChild(F)),Zt&&(L.appendChild(i()),U=n("expand","Expand (E)",Gt??un),L.appendChild(U)),_t&&(L.appendChild(i()),qe=n("help","User guide",()=>Rt()),L.appendChild(qe))}J.appendChild(te)}let ye=null;function un(){ye&&(ye.close(),ye=null);const e=oe;e.style.flex="1",e.style.minWidth="0",e.style.minHeight="0";const t=e.style.maxWidth,n=e.style.maxHeight;e.style.maxWidth="none",e.style.maxHeight="none";const o=Vt(K.metadata??{},Oe()),i=J.childElementCount>0?[J,e]:[e],s=Bi(i,{ownerDocument:u,boxSize:he?{width:"min(96vw, 1600px)",height:"min(92vh, 1000px)"}:void 0,onClosed:()=>{ye=null,e.style.maxWidth=t,e.style.maxHeight=n,U&&(U.style.display="flex"),he||a.focus({preventScroll:!0})}});s&&(s.box.setAttribute("aria-label",o??"Expanded wafer map"),i.length>1&&(s.contentWrap.style.flexDirection="column"),ye=s,U&&(U.style.display="none"))}function gn(e){const t=d.plotMode;if(d={...d,...e},e.plotMode!==void 0&&e.plotMode!==t){const i=d.plotMode;(i==="hardBin"||i==="softBin")&&!new Set(["default","accessible","custom"]).has(d.colorScheme??"")&&(d={...d,colorScheme:"default"})}Object.keys(e).every(i=>i==="legendPosition"||i==="showLegend"||i==="markFailingDies")||Fe(),Ct?.(),Et?.(),Dt?.(),kt?.(),v();const o=e.plotMode!==void 0&&e.plotMode!==t;(e.colorScheme!==void 0||o)&&(pe(),Ae()),(e.colorScheme!==void 0||o||e.activeTest!==void 0||e.logScale!==void 0||e.colorbarRangeMode!==void 0)&&$e?.()}function D(e){gn(e);const t=Object.keys(e);Kn?.(d,t,classifyChanged(t))}let Lt=!1;function Pt(){Lt||(Lt=!0,Nt(()=>{Lt=!1,v()},V))}function v(){const e=B??void 0,t=y.dies[0],n=t?{x:t.width,y:t.height}:le.diePitchMm,o=Math.floor(a.clientWidth||a.width),i=!!(G?.length||Z?.length||y.dies.some(h=>h.hbin!=null||h.sbin!=null)),s=d.legendPosition??"default",g=d.showLegend??!0,l=s==="default"||s==="compact",r=(le.colorbarWidth??16)+28,c=i&&l?s!=="default"?Math.max(Rn,r):o<bi?0:o<yi?Math.max(mi,r):Math.max(Rn,r):void 0,p=hi(a,y,{...le,topClearance:0,minRightReserve:g?c:0,showColorbar:g&&(le.showColorbar??!0),markFailingDies:d.markFailingDies??!1,legendPosition:s,legendOffset:wt,diePitchMm:n,fallbackFormat:Te,showAxes:le.showAxes??B!==null,viewport:e,activeBin:d.plotMode==="metadata"?d.highlightMetadataValue:d.highlightBin,hoverBin:xt,hbinDefs:G,sbinDefs:Z,metadataFields:de});vt=p.binLegendRows,Re=p.legendBox??null,B===null&&(z=p.viewport),E.size>0&&li(),xe&&ai()}function li(){const e=X();if(!e)return;const t=a.getContext("2d"),n=y.hoverPoints,o=y.rectangles[0],i=o?o.width/2*e.ppm:e.ppm*.5,s=o?o.height/2*e.ppm:e.ppm*.5,g=Math.max(1,Math.min(3,i*.08)),l=i-g,r=s-g,c=[];for(const p of E){const h=sn.get(p);h!==void 0&&c.push({sx:e.originX+n[h].x*e.ppm,sy:e.originY-n[h].y*e.ppm})}if(c.length){t.save(),t.setLineDash([]),t.fillStyle="rgba(0,0,0,0.12)",t.beginPath();for(const{sx:p,sy:h}of c)t.rect(p-l,h-r,l*2,r*2);t.fill(),t.strokeStyle="rgba(255,255,255,0.9)",t.lineWidth=3,t.beginPath();for(const{sx:p,sy:h}of c)t.rect(p-l,h-r,l*2,r*2);t.stroke(),t.strokeStyle="rgba(0,0,0,0.9)",t.lineWidth=1.5,t.beginPath();for(const{sx:p,sy:h}of c)t.rect(p-l,h-r,l*2,r*2);t.stroke(),t.restore()}}function ai(){const e=a.getContext("2d"),t=Math.min(T.x,O.x),n=Math.min(T.y,O.y),o=Math.abs(O.x-T.x),i=Math.abs(O.y-T.y);e.save(),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(t,n,o,i),e.setLineDash([5,3]),e.strokeStyle="rgba(255,255,255,0.9)",e.lineWidth=3,e.strokeRect(t,n,o,i),e.strokeStyle="rgba(0,0,0,0.9)",e.lineWidth=1.5,e.strokeRect(t,n,o,i),e.restore()}function si(){a.toBlob(e=>{e&&Hi(e,w.downloadFilename??"wafermap",w.onSaveImage)})}function hn(e){return z?Math.max(z.ppm*Gn,Math.min(z.ppm*Zn,e)):e}function Ce(e,t,n){const o=B??z;if(!o)return;const i=hn(o.ppm*n),s=i/o.ppm,g=e-(e-o.originX)*s,l=t-(t-o.originY)*s,r=(z?.snapDist??1)/(i/(z?.ppm??i));B={originX:g,originY:l,ppm:i,snapDist:r},v()}function X(){return B??z}function mn(e){if(e.ctrlKey||e.metaKey){e.preventDefault();const t=a.getBoundingClientRect(),n=e.deltaY<0?1.12:1/1.12;Ce(e.clientX-t.left,e.clientY-t.top,n)}else if(B!==null){e.preventDefault();const t=X(),n=B.snapDist;B={originX:t.originX-e.deltaX,originY:t.originY-e.deltaY,ppm:t.ppm,snapDist:n},v()}}function yn(e,t,n){return e>=n.x&&e<n.x+n.w&&t>=n.y&&t<n.y+n.h}function bn(e){if(e.button!==0||!X())return;a.focus({preventScroll:!0}),a.setPointerCapture(e.pointerId);const t=a.getBoundingClientRect(),n=e.clientX-t.left,o=e.clientY-t.top;if(Re&&d.legendPosition==="floating"&&yn(n,o,Re)){ve=!0,He={x:n,y:o},St={...wt};return}if(We&&Y!=="pan"){Se=!0,me=!0,we={x:n,y:o},Ze={x:X().originX,y:X().originY},a.style.cursor="grabbing";return}if(Y==="zoom"||Y==="select"){xe=!0,T=O={x:n,y:o};return}me=!0,we={x:n,y:o},Ze={x:X().originX,y:X().originY},a.style.cursor="grabbing"}function vn(e){const t=a.getBoundingClientRect(),n=e.clientX-t.left,o=e.clientY-t.top;if(xe){O={x:n,y:o},Pt();return}if(ve){const p=n-He.x,h=o-He.y;p*p+h*h>16&&(ve=!1,Ie=!0,a.style.cursor="grabbing")}if(Ie){wt={x:St.x+(n-He.x),y:St.y+(o-He.y)},Pt();return}if(me){const p=X(),h=B?.snapDist??z?.snapDist??1;B={originX:Ze.x+(n-we.x),originY:Ze.y+(o-we.y),ppm:p.ppm,snapDist:h},Pt();return}const i=X();if(!i)return;const s=(n-i.originX)/i.ppm,g=(i.originY-o)/i.ppm,r=Mn(s,g,i.snapDist)?.die??null,c=vt.find(p=>n>=p.x&&n<p.x+p.w&&o>=p.y&&o<p.y+p.h);if(rn(c?c.bin:void 0),c){a.style.cursor="pointer",S&&(S.innerHTML=c.label??`Bin ${c.bin}`,S.style.display="block",Yt(S,a,e.clientX,e.clientY)),_e?.(null,e);return}if(Y==="pan"&&(a.style.cursor=r?"crosshair":"grab"),S)if(r)if($t){const p=$t(r);p===null?S.style.display="none":(typeof p=="string"?S.innerHTML=p:(S.innerHTML="",S.appendChild(p)),S.style.display="block",Yt(S,a,e.clientX,e.clientY))}else S.innerHTML=gi(r,y.plotMode,{testDefs:ee,hbinDefs:G,sbinDefs:Z,fallbackFormat:Te,aggrMethod:y.aggrMethod,lotSize:y.lotSize,metadataFields:de,activeTest:y.activeTest,reticleConfig:tn}),S.style.display="block",Yt(S,a,e.clientX,e.clientY);else S.style.display="none";_e?.(r,e)}function xn(e){const t=a.getBoundingClientRect(),n=e.clientX-t.left,o=e.clientY-t.top,i=e.ctrlKey||e.metaKey;if(S&&(n<0||o<0||n>t.width||o>t.height)&&(S.style.display="none"),xe){xe=!1,O={x:n,y:o};const l=n-T.x,r=o-T.y,c=X();if(Y==="zoom"){if(l*l+r*r<25)Ce(n,o,2);else if(c){const p=Math.min(T.x,O.x),h=Math.max(T.x,O.x),ie=Math.min(T.y,O.y),Ee=Math.max(T.y,O.y),q=h-p,fe=Ee-ie;if(q>4&&fe>4){const C=a.clientWidth,k=a.clientHeight,It=C/q,it=k/fe,_=Math.min(It,it),ot=hn(c.ppm*_),Ye=ot/c.ppm,Ht=(p+h)/2,Wt=(ie+Ee)/2;B={originX:C/2-(Ht-c.originX)*Ye,originY:k/2-(Wt-c.originY)*Ye,ppm:ot,snapDist:c.snapDist/Ye}}}v(),a.style.cursor="crosshair";return}if(l*l+r*r<25)Tt(n,o,i,e);else if(c){const p=(Math.min(T.x,O.x)-c.originX)/c.ppm,h=(Math.max(T.x,O.x)-c.originX)/c.ppm,ie=(c.originY-Math.max(T.y,O.y))/c.ppm,Ee=(c.originY-Math.min(T.y,O.y))/c.ppm,q=y.hoverPoints,fe=[];for(let C=0;C<q.length;C++)if(q[C].x>=p&&q[C].x<=h&&q[C].y>=ie&&q[C].y<=Ee){const k=y.dies[C];k&&fe.push(k)}if(i)for(const C of fe){const k=De(C);E.has(k)?E.delete(k):E.add(k)}else E=new Set(fe.map(C=>De(C)));ge?.(Ot())}v(),a.style.cursor="crosshair";return}if(ve){ve=!1,Tt(n,o,i,e);return}if(Ie){Ie=!1,a.style.cursor="grab";return}if(!me)return;if(me=!1,Se){Se=!1,a.style.cursor=We||Y==="pan"?"grab":"crosshair";return}a.style.cursor=Y==="pan"?"grab":"crosshair";const s=n-we.x,g=o-we.y;s*s+g*g<25&&Tt(n,o,i,e)}function Tt(e,t,n,o){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 r=d.highlightBin===l.bin?void 0:l.bin;D({highlightBin:r})}else{const r=d.highlightMetadataValue===l.bin?void 0:l.bin;D({highlightMetadataValue:r})}return}if(Re&&yn(e,t,Re))return;const i=X();if(!i)return;const g=Mn((e-i.originX)/i.ppm,(i.originY-t)/i.ppm,i.snapDist)?.die??null;if(g){Vn?.(g,o);const l=De(g);n?E.has(l)?E.delete(l):E.add(l):E=new Set([l]),ge?.(Ot()),v()}else n||(E=new Set,ge?.([]),v())}function Ot(){const e=[],t=y.hoverPoints;for(let n=0;n<t.length;n++){const o=y.dies[n];o&&E.has(De(o))&&e.push(o)}return e}function wn(){rn(void 0),S&&dt(u),_e?.(null,new MouseEvent("mouseleave")),a.style.cursor=Y==="pan"?"grab":"crosshair"}function Sn(){me=!1,Se=!1,xe=!1,ve=!1,Ie=!1,S&&dt(u),_e?.(null,new MouseEvent("mouseleave")),a.style.cursor=Y==="pan"?"grab":"crosshair",v()}function Mn(e,t,n){const o=y.hoverPoints,i=y.rectangles;for(let r=0;r<i.length;r++){const c=i[r];if(Math.abs(e-c.x)<=c.width/2&&Math.abs(t-c.y)<=c.height/2){const p=y.dies[r];return p?{die:p,index:r}:null}}let s=null,g=-1,l=n*n;for(let r=0;r<o.length;r++){const c=o[r].x-e,p=o[r].y-t,h=c*c+p*p;h<l&&(l=h,s=y.dies[r]??null,g=r)}return s?{die:s,index:g}:null}const Cn=new V.ResizeObserver(()=>{z=null,B=null,v()});Cn.observe(a),w.height==null&&jn<=0&&Nt(()=>Nt(()=>{j.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 ze=V.matchMedia(`(resolution: ${V.devicePixelRatio}dppx)`);const tt=()=>{ze.removeEventListener("change",tt),ze=V.matchMedia(`(resolution: ${V.devicePixelRatio}dppx)`),ze.addEventListener("change",tt),v()};ze.addEventListener("change",tt);const En=V.matchMedia("(prefers-color-scheme: dark)"),Dn=()=>v();En.addEventListener("change",Dn);const kn=()=>{S&&dt(u)};V.addEventListener("blur",kn);function Bn(e){if(e.key==="Escape"&&E.size>0&&(E=new Set,ge?.([]),v()),(e.key==="e"||e.key==="E")&&pt!=="view-only"&&Zt&&(e.stopPropagation(),(Gt??un)()),(e.ctrlKey||e.metaKey)&&(e.key==="="||e.key==="+"?(e.preventDefault(),Ce(a.clientWidth/2,a.clientHeight/2,1.2)):e.key==="-"?(e.preventDefault(),Ce(a.clientWidth/2,a.clientHeight/2,1/1.2)):e.key==="0"&&(e.preventDefault(),nt())),!e.ctrlKey&&!e.metaKey&&!e.shiftKey){const n=X();if(n){const o=B?.snapDist??z?.snapDist??1;let i=0,s=0;e.key==="ArrowLeft"&&(i=20,e.preventDefault()),e.key==="ArrowRight"&&(i=-20,e.preventDefault()),e.key==="ArrowUp"&&(s=20,e.preventDefault()),e.key==="ArrowDown"&&(s=-20,e.preventDefault()),(i||s)&&(B={originX:n.originX+i,originY:n.originY+s,ppm:n.ppm,snapDist:o},v())}e.key===" "&&!We&&(e.preventDefault(),We=!0,Y!=="pan"&&(a.style.cursor="grab"))}}function Ln(e){e.key===" "&&(We=!1,Se&&(me=!1,Se=!1),a.style.cursor=Y==="pan"?"grab":"crosshair")}a.style.cursor="grab",a.setAttribute("tabindex","0"),a.addEventListener("wheel",mn,{passive:!1}),a.addEventListener("pointerdown",bn),a.addEventListener("pointermove",vn),a.addEventListener("pointerup",xn),a.addEventListener("pointerleave",wn),a.addEventListener("pointercancel",Sn);const Pn=()=>nt();a.addEventListener("dblclick",Pn),a.addEventListener("keydown",Bn),a.addEventListener("keyup",Ln);const Tn=e=>{e.stopPropagation()};a.addEventListener("click",Tn),a.clientWidth,v(),$e?.();function nt(){z=null,B=null,v()}function Rt(){import("./userGuideHtml.js").then(e=>Li({buildWaferMap:vi,renderWaferMap,renderWaferGallery:void 0,analyzeWaferMap:wi},e.USER_GUIDE_HTML,Un,j))}return{setDies(e){re=e,Fe(),v(),N&&pe()},setResult(e){gt=e,K=e.wafer,re=e.dies,G=e.hbinDefs,Z=e.sbinDefs,ee=e.testDefs,de=e.metadataFields,en=e.reticles?.length?e.reticles:void 0,tn=e.reticleConfig,nn=e.view?.dataAxisFlip,ht=e.isLotStack,mt=e.aggrMethod,yt=e.lotSize,ti(),Fe(),v(),N&&pe()},setOptions(e){gn(e)},getOptions(){return{...d}},resetZoom:nt,setSelection(e){E=new Set(e.map(t=>De(t))),v()},clearSelection(){E=new Set,ge?.([]),v()},setFallbackFormat(e){Te=e,Fe(),v()},setFindingsNotice(e){dn=e,N?pe():R&&Ae()},setStatsSummary(e){if(ae=e,Jt(),pn(),N)pe();else if(R)Ae();else if(e&&!Le?.placement){const t=Le?.defaultOpen??!Be;R=Xt("right",ue,u),R.style.display=t?"block":"none";const n=M.parentElement,o=M.nextSibling;ce=jt(M,R,"right"),n?.insertBefore(ce,o),Ae()}et()},setSummaryVisible(e){I&&(I.style.display=e?"flex":"none")},setViewControlsVisible(e){L&&(L.style.display=e?"flex":"none")},setExpandVisible(e){U&&(U.style.display=e?"flex":"none")},setHelpButtonVisible(e){qe&&(qe.style.display=e?"flex":"none")},setIdentityVisible(e){bt=!e,A&&(A.style.display=e?"":"none")},openUserGuide:Rt,setInsightsOpen(e){Ge(e),F&&(e?(F.dataset.active="1",F.style.background=x.bgActive,F.style.color=x.iconActive):(delete F.dataset.active,F.style.background="transparent",F.style.color=x.icon))},closeSummaryPanel(){const e=N??R;!e||e.style.display==="none"||(e.style.display="none",I&&(delete I.dataset.active,I.style.background="transparent",I.style.color=x.icon))},setTooltipParent(e){S&&Ei(e)},getActiveLegend(){const e=d.plotMode;if(e==="metadata"){const i=d.activeMetadataKey;if(!i)return null;const s=de?.find(l=>l.key===i),g=[...new Set(re.map(l=>l.metadata?.[i]).filter(l=>l!=null&&(typeof l=="string"||typeof l=="number"||typeof l=="boolean")).map(String))].sort();return g.length?g.map((l,r)=>{const c=s?.values?.find(h=>h.value===l),p=c?.color??Ui(r);return{bin:l,name:c?.label??l,color:p}}):null}if(e!=="hardBin"&&e!=="softBin")return null;const t=e==="hardBin",n=t?G:Z,o=[...new Set(re.map(i=>t?i.hbin:i.sbin).filter(i=>i!==void 0))].sort((i,s)=>i-s);return o.length?o.map(i=>{const s=n?.find(l=>l.bin===i),g=s?.color??(t?Gi(i):Zi(i));return{bin:i,name:s?.name??`Bin ${i}`,color:g}}):null},destroy(){ye?.close(),fn?.()?.remove(),Mt&&u.removeEventListener("click",Mt,!0),a.removeEventListener("wheel",mn),a.removeEventListener("pointerdown",bn),a.removeEventListener("pointermove",vn),a.removeEventListener("pointerup",xn),a.removeEventListener("pointerleave",wn),a.removeEventListener("pointercancel",Sn),a.removeEventListener("dblclick",Pn),a.removeEventListener("keydown",Bn),a.removeEventListener("keyup",Ln),a.removeEventListener("click",Tn),Cn.disconnect(),ze.removeEventListener("change",tt),En.removeEventListener("change",Dn),V.removeEventListener("blur",kn),Jn(),S&&dt(u),te?.remove(),Me&&(Me.parentElement?.insertBefore(M,Me),Me.remove()),ce&&(ce.parentElement?.insertBefore(M,ce),ce.remove()),M.remove(),a.style.cursor="",Q?.destroy(),$?.destroy(),ke.remove()}}}
|