@wafertools/wafermap 0.32.0 → 0.33.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/AGENTS.md +1 -1
- package/CHANGELOG.md +162 -1
- package/README.md +2 -2
- package/dist/packages/canvas-adapter/charts/chartShell.d.ts +2 -12
- package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
- package/dist/packages/canvas-adapter/insightsTab.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferMap.d.ts +30 -0
- package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
- package/dist/packages/canvas-adapter/summaryPanel.d.ts +22 -3
- package/dist/packages/canvas-adapter/summaryPanel.js +4 -3
- package/dist/packages/canvas-adapter/toCanvas.js +1 -1
- package/dist/packages/canvas-adapter/toolbar.d.ts +54 -1
- 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 +76 -13
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/core/aggregates.d.ts +6 -0
- package/dist/packages/core/aggregates.js +1 -1
- package/dist/packages/core/compact.d.ts +205 -0
- package/dist/packages/core/compact.js +3 -0
- package/dist/packages/core/passBins.d.ts +6 -0
- package/dist/packages/core/passBins.js +1 -1
- package/dist/packages/renderer/axisTicks.d.ts +14 -0
- package/dist/packages/renderer/axisTicks.js +1 -1
- package/dist/packages/renderer/buildView.d.ts +26 -1
- package/dist/packages/renderer/buildView.js +1 -1
- package/dist/packages/renderer/buildWaferMap.js +1 -1
- package/dist/packages/renderer/compactView.d.ts +22 -0
- package/dist/packages/renderer/compactView.js +1 -0
- package/dist/packages/renderer/xyIndicator.d.ts +27 -0
- package/dist/packages/renderer/xyIndicator.js +1 -0
- package/dist/packages/stats/analyzeWaferLot.d.ts +28 -0
- package/dist/packages/stats/analyzeWaferLot.js +1 -1
- package/dist/packages/stats/analyzeWaferMap.d.ts +36 -1
- package/dist/packages/stats/analyzeWaferMap.js +1 -1
- package/dist/packages/stats/binRows.d.ts +38 -0
- package/dist/packages/stats/binRows.js +1 -0
- package/dist/packages/stats/filterFindings.d.ts +25 -0
- package/dist/packages/stats/filterFindings.js +1 -1
- package/dist/packages/stats/findingText.d.ts +9 -0
- package/dist/packages/stats/findingText.js +2 -0
- package/dist/packages/stats/lotDrift.d.ts +16 -0
- package/dist/packages/stats/lotDrift.js +1 -0
- package/dist/packages/stats/lotPattern.d.ts +33 -0
- package/dist/packages/stats/lotPattern.js +1 -0
- package/dist/packages/stats/math.d.ts +51 -0
- package/dist/packages/stats/math.js +1 -1
- package/dist/packages/stats/patternClassification.d.ts +31 -0
- package/dist/packages/stats/patternClassification.js +1 -1
- package/dist/packages/stats/presentation.d.ts +42 -0
- package/dist/packages/stats/presentation.js +1 -0
- package/dist/packages/stats/regions.d.ts +9 -0
- package/dist/packages/stats/regions.js +1 -1
- package/dist/packages/stats/renderSummaryReport.d.ts +15 -2
- package/dist/packages/stats/renderSummaryReport.js +32 -27
- package/dist/packages/stats/reportHtml.d.ts +54 -9
- package/dist/packages/stats/reportHtml.js +130 -47
- package/dist/packages/stats/synthesis.d.ts +66 -0
- package/dist/packages/stats/synthesis.js +2 -0
- package/dist/packages/stats/types.d.ts +1 -1
- package/dist/packages/stats/yieldRows.d.ts +31 -0
- package/dist/packages/stats/yieldRows.js +1 -0
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/dist/packages/stats/findingsNarrative.d.ts +0 -3
- package/dist/packages/stats/findingsNarrative.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getUniqueTestNumbers as Ro,resolveTestNumber as Wo,findTestDef as Io,collectMetadataValues as $o}from"../renderer/buildView.js";import{metadataCategoricalValue as Ao}from"../core/metadata.js";import{resolveBinColorsForMaps as Po,mergeBinDefs as Ze,binColorWarning as Fo,mixedPassBinsWarning as Ho,binColorsEqual as jo}from"../renderer/binColors.js";import{itemPassBins as Vo,INPUT_DEFAULT_PASS_BINS as No}from"../core/passBins.js";import{NO_DATA_FILL as zo}from"../renderer/colorMap.js";import{metadataValueColor as _o}from"../renderer/colorMap.js";import{resolveCanvasTheme as Ko}from"./canvasTheme.js";import{ICONS as $e}from"./icons.js";import{SHADOW as Ae,LEADING as Qe,TRACKING as Go,controlStyle as qo,wireControlHover as Mt,SPACE as w,EDGE_GUTTER as oe,MAP_CHROME_INSET as Uo,RADIUS as z,FONT as T,CLR as g,sevColor as vn,MODE_LABELS as Xo,BIN_LEGEND_MODES as xn,STACKED_MODES as be,Z_ABOVE as Cn,applyOverlayZ as Yo,getTooltip as Zo,hideTooltip as Sn,createToolbarHelpers as Qo,buildModeMenuEl as Jo,openDetachWindow as ei,openFloatingWindow as ti,openModal as ni,openReportModal as oi,copyWmapThemeTokens as ii,syncWmapPopupTheme as li,openUserGuideWindow as si,makePaletteBtn as ai,makeLogScaleBtn as ri,makeLegendStyleBtn as di,makeOverlaysBtn as ci,makeOrientationBtn as ui,menuLayerFor as Mn,saveImageBlob as fi,markMenuTrigger as Pe,wireMenuA11y as Dn,wireExpandToggle as En,wireTooltip as kn,requestedPassFailDisplay as Bn,overlayMenuRows as pi,anyOverlayActive as mi,logWmapVersionOnce as gi,buildDataModeEntries as hi,metadataKeyHasData as yi,metadataModeEntry as bi}from"./toolbar.js";import{waferDisplayLabel as Je,waferIdentityLabel as On}from"../core/waferLabel.js";import{metadataDisplayValue as wi}from"../core/metadata.js";import{withExportContext as vi}from"./exportName.js";import{sortBinsForDisplay as xi}from"../stats/binPareto.js";import{diePassStatus as Ci}from"../core/dies.js";import{aggregateValues as Si,aggregateBinCounts as Tn}from"../core/aggregates.js";import{renderWaferMap as Mi,renderWaferMapCard as Ln,toPublicViewOptions as Rn}from"./renderWaferMap.js";import{hasDrilldownTargets as Di,waferPopulation as Ei}from"./chartPopulation.js";import{classifyChanged as ki,COLOR_KEYS as Bi,findingBin as Oi}from"./renderWaferMap.js";import{findingPatternKey as Wn}from"../stats/filterFindings.js";import{buildWaferMap as Ti,getTestPassStatus as In,isParametricTest as Dt,getDieTestValue as Li}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as et}from"../stats/analyzeWaferMap.js";import{collectWarnings as Ri,buildWarningsMenuEl as Wi,severityOf as Ii}from"./warnings.js";import{asList as $n,compareNatural as Et,arrayEqual as An,toggleHighlight as Pn}from"../core/utils.js";import{createSummaryPanelEl as kt,buildMetadataStripRow as $i,buildCompactMetadataRows as Fn,metadataEntries as Hn,renderLotSummaryContentSteps as Ai,reportMapsFromItems as Pi}from"./summaryPanel.js";import{renderLotReportHtml as Fi}from"../stats/renderSummaryReport.js";import{prettyKey as Hi}from"../stats/facets.js";import{testLabel as ji,markedTestLabel as Vi,derivedFields as Ni}from"../renderer/testLabel.js";import{mergeTestDefs as zi}from"../stats/mergeTestDefs.js";import{getDieKey as _i,hasPosition as Ki}from"../core/dies.js";import{testValue as Gi}from"../core/dieTable.js";import{runChunked as qi}from"./chunked.js";function jn(f){if(typeof f!="number"||!Number.isFinite(f))return;const C=Math.round(f);return C>=1?C:void 0}const Bt=12;function Ui(f,C,p){let A=C;if(C.length>Bt){const S=C.slice(0,Bt-1),W=C.slice(Bt-1),F=W.reduce((X,ie)=>X+ie.count,0);A=[...S,{color:g.label,count:F,label:`Other (${W.length} bins)`}]}const E=f.createElement("div");Object.assign(E.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:z.control,overflow:"hidden",border:`1px solid ${g.menuBorder}`,boxSizing:"border-box",marginTop:w.xs,flexShrink:"0"}),E.setAttribute("role","img"),E.setAttribute("aria-label",`Population split: ${A.map(S=>`${S.label} ${tt(S.count/p*100)}`).join(", ")}`);for(const S of A){const W=S.count/p*100,F=f.createElement("div");Object.assign(F.style,{flex:`${W} 1 0`,minWidth:W>0?"2px":"0",background:S.color}),kn(F,`${S.label} \xB7 ${S.count.toLocaleString()} dies \xB7 ${tt(W)}`),E.appendChild(F)}return E}function tt(f){return f>0&&f<.1?"<0.1%":`${f.toFixed(1)}%`}function Vn(f,C,p){const A=new Map;let E=0,S=0;for(const W of f){const F=p?new Set(p(W)):void 0;for(const X of W.dies){if(X.partial||X.edgeExcluded)continue;const ie=C(X);ie!==void 0&&(A.set(ie,(A.get(ie)??0)+1),E++,F&&Ci(X,F)&&S++)}}return{counts:A,total:E,pass:S}}function Nn(f,C){const p=f.ownerDocument.createElement("div");Object.assign(p.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${w.xxs} ${w.xs}`,borderRadius:z.control});const A=f.ownerDocument.createElement("span");Object.assign(A.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:C.color,border:C.isActive?`2px solid ${g.iconActive}`:`1px solid ${g.menuBorder}`,borderRadius:z.control,boxSizing:"border-box"});const E=f.ownerDocument.createElement("span");if(E.textContent=C.label,Object.assign(E.style,{fontWeight:C.isActive?"700":"400",color:C.isActive?g.iconActive:g.text,whiteSpace:"nowrap"}),p.appendChild(A),p.appendChild(E),C.count!==void 0){const S=f.ownerDocument.createElement("span");if(S.textContent=C.count.toLocaleString(),Object.assign(S.style,{color:C.isActive?g.iconActive:g.text,fontWeight:C.isActive?"700":"400",whiteSpace:"nowrap"}),p.appendChild(S),C.percent!==void 0){const W=f.ownerDocument.createElement("span");W.textContent=tt(C.percent),Object.assign(W.style,{color:g.label,whiteSpace:"nowrap"}),p.appendChild(W)}}p.setAttribute("role","button"),p.setAttribute("aria-pressed",C.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",S=>C.onClick(S.ctrlKey||S.metaKey)),p.addEventListener("keydown",S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),C.onClick(S.ctrlKey||S.metaKey))}),f.appendChild(p)}export function renderWaferGallery(f,C,p={}){gi();const A=6;let E=jn(p.columns);const S=p.showHelpButton??!1,W=p.userGuideExtension,F=p.insights?.enabled??!1,X=p.insights?.sweeps?{sweeps:p.insights.sweeps}:void 0,ie=Yo(p.zIndex),de=p.summaryPanel,zn=e=>[...Vo(e)],Ot=()=>v.flatMap(e=>e?[e.ringCount??4]:[]),nt=()=>Ot()[0]??4;function _n(e){const t=[...new Set(e)].sort((n,o)=>n-o);return t.length<2?null:{code:"ring-count-mixed",severity:"warning",message:`These wafers were built with different ring counts (${t.join(", ")}). Each card and each wafer's findings use their own; the lot's ring yield in the Summary panel, report and Insights uses ${e[0]} rings.`}}let N=p.lotStatsSummary,we=p.viewOptions?.legendPosition??"default",Fe=p.perCardLegend??!1;function ve(){const e=c.plotMode??"hardBin";return xn.has(e)?null:c.colorbarRangeMode==="data"?"Each map has its own value range, so it keeps its own colour bar":"These wafers have no shared colour bar for value mode, so each map keeps its own"}function Tt(){const e=Fe||ve()!==null;for(const t of M)t&&t.setOptions({showLegend:e})}let c={plotMode:"hardBin",showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...p.viewOptions},M=[],le=[],ce=[],L=[];const He=vi(()=>{const e=L.filter(n=>n!=null),t=[...new Set(e.map(n=>wi(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort(Et);return{prefix:p.downloadFilename,lots:t,...e.length===1?{wafer:On(e[0])}:{waferCount:e.length}}},p.onSaveImage,p.onSaveText);let v=C.map(e=>typeof e=="function"?null:e);function Lt(){return zi(v)}function xe(){if(v.some(e=>e?.testDefs?.length))return Lt().defs}let Ce=0,je=0;const _=new Map;let Kn=0,P=null,se=null,Rt=new Set,y=null,Gn={};function Wt(e){return v[e]?.statsSummary??N?.perWafer.find(t=>t.waferIndex===e)?.summary}function ot(){return!!(v.some(e=>e?.statsSummary?.findings.length)||N?.perWafer.some(e=>e.summary.findings.length))}const qn=Zo(),ue=Qo(qn),{makeBtn:Q,setActive:Se,makeSep:K,makeMenuRow:Un,makeMenuSection:Xn,makeDropdown:It,closeOpenMenu:Ve,getOpenMenu:Me,setOpenMenu:De}=ue;f.ownerDocument.addEventListener("click",Ve,!0);const $t=()=>Sn();window.addEventListener("blur",$t);let At=p.findingsNotice;function Pt(e){Rt=new Set(e);const t=[...$.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,d)=>{const s=Rt.has(d);o.style.outline=s?`3px solid ${g.findingHighlight}`:"",o.style.outlineOffset=s?"-3px":"",s&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function Ft(){Pt([])}let it=!1;function Ht(){it=!0;for(const e of M)e&&e.clearSelection();it=!1}function jt(e){return t=>{!it&&se!==null&&(ke(),H()),e.onSelect?.(t)}}function lt(e,t){const n=new Set(e),o=t??M.map((d,s)=>s);for(const d of o){const s=L[d],l=M[d];if(!s||!l)continue;const a=s.dies.filter(i=>n.has(_i(i)));l.setSelection(a)}}function Yn(){const e=[];for(let t=0;t<v.length;t++){const n=v[t];if(!n)continue;const o=Wt(t)?.findings??[];o.length&&e.push({index:t,item:n,unusualCount:o.filter(d=>d.severity==="unusual").length,notableCount:o.filter(d=>d.severity==="notable").length,totalCount:o.length})}return e}function Zn(e){const t=L[e]??v[e];t&&Ie(e,t)}function Qn(e){const t=Wt(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 Jn(){oi(Fi(Pi(v,No,nt())),{anchor:f})}function eo(){if(!y)return;y.innerHTML="";const e=Yn();if(v.length>0){const n=f.ownerDocument.createElement("div"),o=e.length,d=v.filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${d} wafers`:`${o} of ${d} wafer${d===1?"":"s"} with findings`,Object.assign(n.style,{fontSize:T.body,color:g.label,marginBottom:w.md}),y.appendChild(n)}if(e.length>0){const n=f.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...qo("outlined"),marginBottom:w.lg,display:"block",width:"100%",textAlign:"left"}),Mt(n),n.addEventListener("click",Jn),y.appendChild(n)}if(e.length===0){const n=f.ownerDocument.createElement("div");Object.assign(n.style,{color:g.icon,fontSize:T.body,padding:"4px 0"}),n.textContent="No findings on any wafer.",y.appendChild(n)}else for(const{index:n,item:o,unusualCount:d,notableCount:s,totalCount:l}of e){const a=d?"unusual":s?"notable":"info",i=d+s||l,r=f.ownerDocument.createElement("button");r.type="button",Object.assign(r.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:w.xs,border:"none",borderLeft:`3px solid ${vn(a)}`,borderRadius:z.control,background:g.bgHover,cursor:"pointer",fontSize:T.body,textAlign:"left",boxSizing:"border-box"}),r.addEventListener("mouseover",()=>{r.style.background=g.bgActive}),r.addEventListener("mouseout",()=>{r.style.background=g.bgHover});const u=f.ownerDocument.createElement("span");u.textContent=Je(o,n),Object.assign(u.style,{color:g.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const m=f.ownerDocument.createElement("span");m.textContent=String(i),r.setAttribute("aria-label",`${Je(o,n)} \u2014 ${i} finding${i===1?"":"s"}${d?`, ${d} unusual`:""} \u2014 view wafer`),Object.assign(m.style,{marginLeft:w.sm,flexShrink:"0",background:vn(a),color:"#fff",borderRadius:z.container,padding:"1px 5px",fontSize:T.body,fontWeight:"600"}),r.appendChild(u),r.appendChild(m),r.addEventListener("click",()=>Ie(n,o)),y.appendChild(r)}const t=f.ownerDocument.createElement("div");t.style.height="12px",y.appendChild(t)}let fe=null,Ee=null;function H(){if(y)if(fe?.cancel(),fe=null,N){const e=Ze(v.map(n=>n?.hbinDefs)),t=Ze(v.map(n=>n?.sbinDefs));fe=qi(Ai(y,{lotSummary:N,items:v,hbinDefs:e.length?e:void 0,sbinDefs:t.length?t:void 0,testDefs:xe(),ringCount:nt(),binColors:c.binColors,plotMode:c.plotMode??"hardBin",fallbackFormat:c.fallbackFormat,activeFindingId:se,warnings:p.warnings?.display??!0?J:[],findingsFilter:Gn,findingsNotice:At,onFindingsFilterChange:H,onSaveText:He.onSaveText,onFindingClick:(n,o)=>{se===n.id?ke():no(n,o),H()},onWaferClick:Zn,findingsFor:Qn,dieListOptions:p.dieList}),{onDone:()=>{const n=Ee;Ee=null,n?.()}})}else eo()}function to(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}let Ne=[];function Vt(){if(Ne.length!==0){for(const e of Ne)M[e]?.setOptions({plotMode:c.plotMode,activeTest:c.activeTest});Ne=[]}}function ke(){se=null,Ft(),Ht(),Vt(),R({highlightBin:void 0},{fireCallback:!1})}function Nt(){se!==null&&(ke(),H())}function no(e,t){if(se===e.id){ke();return}se=e.id,t.style.background=g.bgActive,t.style.fontWeight="600",Vt();const{kind:n,index:o}=e.variable;if(n==="test"){const s=o??0,l=xe();if(l===void 0||l.some(i=>i.testNumber===s))R({plotMode:"value",activeTest:s,highlightBin:void 0},{fireCallback:!1});else{R({highlightBin:void 0},{fireCallback:!1});const r=be.has(c.plotMode??"hardBin")?null:to(e);if(r){for(const u of r)M[u]?.setOptions({plotMode:"value",activeTest:s});Ne=[...r]}}}else R({plotMode:n==="softBin"?"softBin":"hardBin",highlightBin:Oi(e)},{fireCallback:!1});Ft(),Ht();const d=e.highlight;if(d.kind==="wafer"){Pt(d.waferIndices);const s=Wn(e);for(const l of d.waferIndices){const a=d.dieKeysByWafer?void 0:L[l]?.statsSummary?.findings.find(r=>Wn(r)===s),i=d.dieKeysByWafer?.[l]??a?.highlight?.dieKeys;i?.length&<(i,[l])}}else d.kind==="bin"?d.dieKeys?.length&<(d.dieKeys):(d.kind==="region"||d.kind==="dies")&&d.dieKeys?.length&<(d.dieKeys)}function ae(){if(!P)return;const e=!!y;P.style.display=(N||ot())&&e&&!Le?"flex":"none";const t=y?y.style.display!=="none":!1;(N?.hasNotableFindings||v.some(o=>o?.statsSummary?.hasNotableFindings))&&!t?P.style.color=g.findingIndicator:P.dataset.active||(P.style.color=g.icon)}const I=f.ownerDocument.createElement("div");I.dataset.wmapToolbar="gallery",Object.assign(I.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:Ae.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const zt=()=>{const e=Me();e&&(e.remove(),De(null)),Pe(Y,!1)},Y=Q("mode","Plot mode",()=>{if(Me()){zt();return}const e=v.flatMap(b=>b?.dies??[]),t=xe(),{testEntries:n,binEntries:o,stackedEntries:d}=hi(e,t,{includeStacked:!0}),s=v.filter(Boolean).length,l=b=>{if(b===void 0)return s;let B=0;for(const j of v)j?.dies?.some(U=>In(U,b)!==void 0||Gi(U,b)!==void 0)&&B++;return B},a=s<2?n:n.map(b=>{const B=l(b.activeTest);return B===s?b:{...b,label:`${b.label} \u2014 ${B} of ${s} wafers`}}),i=c.plotMode??"hardBin",r=c.activeTest??0;function u(b){return b.plotMode!==i?!1:b.plotMode==="value"?r===(b.activeTest??0):b.plotMode==="metadata"?c.activeMetadataKey===b.activeMetadataKey:!0}function m(b,B){b.activeTest!==void 0?R({plotMode:"value",activeTest:b.activeTest,activeMetadataKey:void 0,logScale:b.logScale}):b.activeMetadataKey!==void 0?R({plotMode:b.plotMode,activeTest:void 0,activeMetadataKey:b.activeMetadataKey,passFailDisplay:"off"}):R({plotMode:b.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),B.remove(),De(null),Pe(Y,!1)}const D=new Set,k=v.flatMap(b=>b?.metadataFields??[]).filter(b=>!D.has(b.key)&&D.add(b.key)).filter(b=>yi(e,b.key)).map(bi),x=Jo(Y.getBoundingClientRect(),a,o,d,u,m,{makeMenuRow:Un,makeMenuSection:Xn},i,Y.ownerDocument.defaultView??window,k);Mn(Y).appendChild(x),De(x),Pe(Y,!0),Dn(x,Y,zt)});Pe(Y,!1);const oo=()=>L.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:io,sync:_t}=ai(ue,()=>({...c,plotMode:c.plotMode??"hardBin"}),oo,e=>R(e));_t();const lo=C.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function ze(){const e=xe(),{testNumber:t}=Wo(c.activeTest??0,e);return{testNumber:t,td:Io(e,t)}}function Kt(){if((c.plotMode??"hardBin")!=="value")return!1;const{td:e}=ze();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function Be(){if((c.plotMode??"hardBin")!=="value")return!1;const{td:e}=ze();return e!==void 0&&!Dt(e)}function so(){if((c.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=ze();return v.some(n=>n?.dies?.some(o=>In(o,e,t)!==void 0))}function ao(e,t){if(!t||!Dt(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((Bn(c)==="spec"&&n?"spec":c.colorbarRangeMode??"spec")==="spec"&&n)return;let s=1/0,l=-1/0;for(const a of v)if(a)for(const i of a.dies){const r=Li(i,e);r!==void 0&&(r<s&&(s=r),r>l&&(l=r))}if(isFinite(s))return s===l?[s,s+1]:[s,l]}function st(e,t,n){const o=c[e];if(o===t||o!=null&&t!=null&&n(o,t))return!1;c={...c,[e]:t};for(const d of M)d&&d.setOptions({[e]:t});return!0}function Gt(){if((c.plotMode??"hardBin")!=="metadata")return;const e=c.activeMetadataKey;if(!e)return;const t=new Set;for(const n of v)if(n)for(const o of $o(n.dies,e))t.add(o);return{key:e,values:[...t].sort(Et)}}function at(){st("metadataValueOrder",Gt(),(e,t)=>e.key===t.key&&An(e.values,t.values))}function rt(){if((c.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=ze(),n=ao(e,t);st("valueRange",n?{test:e,range:n}:void 0,(d,s)=>{const l=r=>Array.isArray(r)?{test:void 0,range:r}:{test:r.test,range:r.range},a=l(d),i=l(s);return a.test===i.test&&An(a.range,i.range)})}let dt=!1;function ro(){if(dt)return;dt=!0,(f.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{dt=!1,rt(),at(),Ut()})}let ct=!1;function co(){if(ct)return;ct=!0,(f.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{ct=!1,Ue()})}let qt=[];function pe(){const{colors:e,mixedHardBins:t}=Po(v.filter(n=>n!=null),{binColorScheme:c.binColorScheme,useDefinedBinColors:c.useDefinedBinColors});return qt=t,e}function Ut(){st("binColors",pe(),jo),Oe()}const uo=ci(ue,()=>pi(c,lo,{functionalActive:Be(),hasLimits:Kt()&&!Be(),hasRecorded:so()&&!Be(),binMode:(c.plotMode??"hardBin")==="hardBin"||(c.plotMode??"hardBin")==="softBin"},e=>R(e)),()=>mi(c)),{btn:fo,sync:Xt}=di(ue,()=>({plotMode:c.plotMode,legendPosition:we}),e=>{we=e;for(const t of M)t&&t.setOptions({legendPosition:we})},{get:()=>Fe,set:e=>{Fe=e,Tt()},blockedReason:ve});Xt();const po=[{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"}],Yt=It("aggr","Aggregation method",()=>po,()=>c.aggregationMethod??"mean",e=>R({aggregationMethod:e}));function Zt(){const e=c.plotMode==="stackedValues";Yt.style.display=e?"":"none"}Zt();const{btn:mo,sync:Qt}=ri(ue,()=>({...c,functionalActive:Be()}),e=>R(e));Qt();const _e=Q("specRange","Colorbar range: test limits",()=>{const e=c.colorbarRangeMode==="data"?"spec":"data";R({colorbarRangeMode:e})});function Jt(){const e=(c.plotMode??"hardBin")==="value"&&Kt()&&Bn(c)==="off"&&!Be();_e.style.display=e?"":"none";const t=(c.colorbarRangeMode??"spec")==="spec";Se(_e,t),_e.ariaLabel=t?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"}Jt();const go=ui(ue,()=>c,e=>R(e)),ho=Q("downloadAll","Download gallery PNG",Oo),yo=It("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"}],()=>E!=null?String(E):"auto",e=>cn(e==="auto"?void 0:Number(e))),O=f.ownerDocument.createElement("div");Object.assign(O.style,{display:"inline-flex",alignItems:"center",gap:"0"}),I.appendChild(O),O.appendChild(Y),O.appendChild(io),O.appendChild(Yt),O.appendChild(mo),O.appendChild(_e),O.appendChild(K()),O.appendChild(uo),O.appendChild(K()),O.appendChild(fo),O.appendChild(K()),O.appendChild(go),O.appendChild(K()),O.appendChild(yo),O.appendChild(K()),O.appendChild(ho),(N||ot())&&(P=Q("findings","Summary panel",()=>{if(!y)return;const e=y.style.display!=="none";e||H(),y.style.display=e?"none":"flex",Se(P,!e),ae()}),I.appendChild(K()),I.appendChild(P));let G=null,Ke=null,J=[],en=!1;function Oe(){const e=Ri({lotStatsSummary:N,result:{warnings:[...v.flatMap(n=>n?.warnings??[]),...Lt().warnings]},extra:[c.binColors&&Fo(c.binColors,c.plotMode),Ho(qt),_n(Ot())].filter(n=>!!n)}),t=e.length!==J.length||e.some((n,o)=>n.code!==J[o]?.code||n.message!==J[o]?.message);J=e,(t||!en)&&(en=!0,p.warnings?.onWarning?.(e)),bo()}function bo(){if(!G||!Ke)return;const e=J.length,t=e>0;if(G.style.display=t?"flex":"none",Ke.style.display=t?"":"none",!t)return;const n=Ii(J[0]),o=`${e} data ${e===1?"warning":"warnings"}`;G.style.color=n==="error"?g.errText:g.warnText,G.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(p.warnings?.display??!0)&&(Ke=K(),G=Q("warning","Data warnings",()=>{const e=Me();if(Ve(new MouseEvent("click")),e)return;const t=Wi(G.getBoundingClientRect(),J,G.ownerDocument.defaultView??window);Mn(f).appendChild(t),De(t),Dn(t,G,()=>Ve(new MouseEvent("click")))}),Pe(G,!1),I.appendChild(Ke),I.appendChild(G)),Oe();let re=null;F&&(re=Q("analysis","Insights",()=>{on(!Le)}),re.dataset.wmapInsightsBtn="1",I.appendChild(K()),I.appendChild(re));function tn(){import("./userGuideHtml.js").then(e=>si({buildWaferMap:Ti,renderWaferMap:Mi,renderWaferGallery,analyzeWaferMap:et},e.USER_GUIDE_HTML,W,f))}S&&(I.appendChild(K()),I.appendChild(Q("help","User guide",()=>tn())));const me=f.ownerDocument.createElement("div");me.dataset.wmapGalleryMeta="1",Object.assign(me.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${w.sm} ${w.lg}`,fontSize:T.sub,lineHeight:Qe.none,boxSizing:"border-box"});const Ge=f.ownerDocument.createElement("div");Object.assign(Ge.style,{background:g.canvasBg,display:"flex",alignItems:"stretch",gap:w.lg,paddingBottom:w.lg,minWidth:"0"});const ee=f.ownerDocument.createElement("div");ee.dataset.wmapGalleryLegend="1",Object.assign(ee.style,{display:"flex",flexDirection:"column",gap:w.sm,background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:z.container,padding:`${w.sm} ${w.lg}`,marginBottom:w.lg,boxShadow:Ae.panel,fontSize:T.body,lineHeight:Qe.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const q=f.ownerDocument.createElement("div");Object.assign(q.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let ge=null,Te=null,nn=null;function wo(){return F?ge?Promise.resolve(ge):(nn??=import("./insightsTab.js").then(({createInsightsTab:e})=>(ge=e({getItems:()=>v,getLotStats:()=>N,getBinColors:()=>c.binColors??pe(),getRingCount:nt,defaultView:p.insights?.defaultView,sweeps:p.insights?.sweeps,onRemoveSweeps:p.insights?.onRemoveSweeps,onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:He.onSaveImage,onSaveText:He.onSaveText,ownerDocument:f.ownerDocument,openWafer:(t,n,o)=>{const d=v[t];if(!d)return;let s=null;const l=ni({title:n,onClose:()=>s?.destroy(),anchor:f});pn(l,n,d.wafer.metadata??void 0),s=yt(l.contentWrap,d,o)}}),Te=ge.el,Te.style.display="none",f.appendChild(Te),ge)),nn):Promise.resolve(null)}let Le=!1;function on(e){F&&(Le=e,Te&&(Te.style.display=e?"flex":"none"),q.style.display=e?"none":"flex",O.style.display=e?"none":"inline-flex",I.style.display="inline-flex",re&&(Se(re,e),re.innerHTML=e?$e.wafer:$e.analysis,re.ariaLabel=e?"Back to gallery view":"Insights"),ae(),Ue(),e&&wo().then(t=>{!t||!Le||(t.el.style.display="flex",t.render())}))}F&&p.insights?.defaultOpen&&queueMicrotask(()=>on(!0));const vo=4,ut=240,ln=480,xo=720,Co=1.25;let he=ln;function sn(e){const t=A*2+110+2;let n=null;for(const o of e){if(o==null||!o.dies?.length)continue;const d=o.dies[0].width;if(!(d>0))continue;const s=o.wafer.radius*2*(vo/d),l=Math.ceil(s+t);(n==null||l>n)&&(n=l)}return n}function So(e){const t=sn(e);return t==null?ut:Math.min(he,Math.max(ut,t))}function Mo(e){const t=sn(e);if(t==null)return!1;const n=Math.min(xo,Math.max(ln,t));return n<=he?!1:(he=n,!0)}function ft(){return E!=null?"none":`${he}px`}function an(){const e=ft();for(const t of Array.from($.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let qe=ut,rn=0;function dn(e){if(Mo(e)&&an(),E==null){const n=So(e);n>qe&&(qe=n)}mt()}function cn(e){E=jn(e),an(),mt()}function pt(e){return`repeat(${e}, minmax(0, ${E!=null?"1fr":`${he}px`}))`}function un(e){$.style.gridTemplateColumns!==e&&($.style.gridTemplateColumns=e)}function mt(){if(E!=null){un(pt(E));return}const e=Math.max(1,rn),t=12,n=$.clientWidth||0,o=s=>(n-t*(s-1))/s;let d=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const s=Math.min(he,qe*Co),l=a=>{let i=0;for(;i<e&&o(i+1)>=a;)i++;return i};d=l(s)||l(qe)||1}un(pt(d))}const $=f.ownerDocument.createElement("div");if(Object.assign($.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:pt(1),gap:w.xl,paddingLeft:oe,paddingRight:oe,justifyContent:"start",alignContent:"start",isolation:"isolate"}),de?.placement){const e=de.placement;y=kt(e,oe,f.ownerDocument),y.style.maxHeight="calc(100vh - 80px)",y.style.position="sticky",y.style.top="8px",y.style.display="flex",y.style.flexDirection="column"}else if(N||ot()){const e=!!de?.defaultOpen;y=kt("right",oe,f.ownerDocument),y.style.maxHeight="calc(100vh - 80px)",y.style.position="sticky",y.style.top="8px",y.style.flexDirection="column",y.style.display=e?"flex":"none",H()}ae(),y?.style.display!=="none"&&P&&Se(P,!0),(de?.placement??"right")==="left"?(y&&q.appendChild(y),q.appendChild($)):(q.appendChild($),y&&q.appendChild(y));const Re=f.ownerDocument.createElement("div");Object.assign(Re.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:oe,paddingRight:oe,paddingTop:oe,zIndex:"1",background:g.menuBg}),Ge.appendChild(me),Ge.appendChild(I),Re.appendChild(Ge),Re.appendChild(ee),f.appendChild(Re),f.appendChild(q);function Ue(){ee.innerHTML="";const e=c.plotMode??"hardBin",t=!Le&&xn.has(e),n=L.filter(h=>h!=null),o=n.find(h=>h.isLotStack),d=$i(n.map(h=>({metadata:h.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0),s=e==="metadata",l=c.activeMetadataKey,a=t&&!s?Vn(n,h=>(e==="softBin"?h.sbin:h.hbin)??void 0,zn):{counts:new Map,total:0,pass:0},i=t&&!s?c.binColors??pe():void 0,r=i?e==="softBin"?i.pass.soft:i.pass.hard:new Set,u=xi(a.counts.entries(),r).map(([h])=>h),m=t&&s&&l?Vn(n,h=>Ao(h.metadata?.[l])):{counts:new Map,total:0,pass:0},D=s?Gt()?.values:void 0,k=t&&s?(D??[...m.counts.keys()].sort(Et)).filter(h=>m.counts.has(h)):[];if(me.innerHTML="",d&&me.appendChild(d),me.style.display=d?"flex":"none",!u.length&&!k.length){ee.style.display="none";return}ee.style.display="flex";const x=f.ownerDocument.createElement("div");Object.assign(x.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${w.sm} ${w.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),ee.appendChild(x);const b=$n(c.highlightBin),B=L.flatMap(h=>h?.metadataFields??[]).find(h=>h.key===l),j=s?B?.label??(l?Hi(l):"Metadata"):Xo[e],U=f.ownerDocument.createElement("span");if(U.textContent=j,Object.assign(U.style,{fontSize:T.body,fontWeight:"700",letterSpacing:Go,textTransform:"uppercase",color:g.label,flexShrink:"0"}),x.appendChild(U),!s&&a.total>0){const h=a.pass,V=h/a.total*100,te=f.ownerDocument.createElement("span");te.textContent=`Yield ${tt(V)}`,Object.assign(te.style,{fontSize:T.body,fontWeight:"700",color:g.value,whiteSpace:"nowrap",flexShrink:"0"});const ne=f.ownerDocument.createElement("span");ne.textContent=`${h.toLocaleString()} / ${a.total.toLocaleString()} dies`,Object.assign(ne.style,{fontSize:T.body,color:g.label,whiteSpace:"nowrap",flexShrink:"0"}),x.appendChild(te),x.appendChild(ne)}if(s){const h=$n(c.highlightMetadataValue);k.forEach((V,te)=>{const ne=h.includes(V),Ye=B?.values?.find(St=>St.value===V),Ct=Ye?.color??_o(te),wn=m.counts.get(V)??0;Nn(x,{color:Ct,isActive:ne,label:Ye?.label??V,count:wn,percent:m.total>0?wn/m.total*100:void 0,onClick:St=>{const Lo=Pn(c.highlightMetadataValue,V,St);Nt(),R({highlightMetadataValue:Lo})}})});return}const wt=e==="softBin"?L.flatMap(h=>h?.sbinDefs??[]):L.flatMap(h=>h?.hbinDefs??[]),hn=new Set,vt=[];for(const h of wt)hn.has(h.bin)||(hn.add(h.bin),vt.push(h));const xt=vt.length>0?new Map(vt.map(h=>[h.bin,h])):null,yn=i??c.binColors??pe(),To=e==="softBin"?yn.soft:yn.hard,bn=h=>To.get(h)??zo;for(const h of u){const V=b.includes(h),te=xt?.get(h),ne=a.counts.get(h)??0;Nn(x,{color:bn(h),isActive:V,label:te?.name?`${h} \xB7 ${te.name}`:`Bin ${h}`,count:ne,percent:a.total>0?ne/a.total*100:void 0,onClick:Ye=>{const Ct=Pn(c.highlightBin,h,Ye);Nt(),R({highlightBin:Ct})}})}a.total>0&&u.length>1&&ee.appendChild(Ui(f.ownerDocument,[...a.counts.entries()].sort(([,h],[,V])=>V-h).map(([h,V])=>({color:bn(h),count:V,label:xt?.get(h)?.name?`${h} \xB7 ${xt.get(h).name}`:`Bin ${h}`})),a.total))}function We(e){const t=v.filter(a=>a!==null);if(!t.length)return[];const n=t.map(a=>a.dies.filter(Ki)),o=t[0].wafer,d=t.length,s=o.metadata?{...o,metadata:(({wafer:a,waferId:i,...r})=>r)(o.metadata)}:o;function l(a,i){return{...a,stats:{...a.stats,isLotStack:!0,aggregationMethod:i,lotSize:d}}}if(e==="stackedValues"){const a=xe();let i=a?.filter(Dt);if(a!==void 0&&i?.length===0)return[];if(a?.length||(i=Ro(t.flatMap(m=>m.dies)).map(m=>({testNumber:m,name:ji(void 0,m)}))),!i?.length)return[];const r=c.aggregationMethod??"mean";return i.map(u=>{const m=Si(n,r,u.testNumber),D={testNumber:0,name:u.name,unit:u.unit,...Ni(u)};return{wafer:s,dies:m,testDefs:[D],label:`${Vi(u,u.testNumber)} \xB7 ${r}`,isLotStack:!0,aggrMethod:r,lotSize:d,statsSummary:l(et({wafer:s,dies:m,testDefs:[D]},{testNumbers:[0]}),r)}})}if(e==="stackedBins"){let a=Ze(t.map(i=>i?.hbinDefs));return(!a||a.length===0)&&(a=[...new Set(t.flatMap(r=>r.dies.map(u=>u.hbin).filter(u=>u!=null)))].sort((r,u)=>r-u).map(r=>({bin:r,name:`Bin ${r}`}))),a.map(i=>{const r=Tn(n,i.bin,"hard"),u=[{bin:i.bin,name:i.name}];return{wafer:s,dies:r,hbinDefs:u,label:`${i.bin} \xB7 ${i.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:d,statsSummary:l(et({wafer:s,dies:r,hbinDefs:u}),"countBin")}})}if(e==="stackedSoftBins"){let a=Ze(t.map(i=>i?.sbinDefs));return(!a||a.length===0)&&(a=[...new Set(t.flatMap(r=>r.dies.map(u=>u.sbin).filter(u=>u!=null)))].sort((r,u)=>r-u).map(r=>({bin:r,name:`Bin ${r}`}))),a.map(i=>{const r=Tn(n,i.bin,"soft"),u=[{bin:i.bin,name:i.name}];return{wafer:s,dies:r,sbinDefs:u,label:`${i.bin} \xB7 ${i.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:d,statsSummary:l(et({wafer:s,dies:r,sbinDefs:u}),"countBin")}})}return t}function gt(e){const t=v.length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:c.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}function R(e,{fireCallback:t=!0}={}){const n=Object.keys(e),o=c.plotMode,d=ve()!==null;c={...c,...e};const s=c.plotMode,l=be.has(s),a=o!==void 0&&be.has(o),i=je>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const u=pe();c={...c,binColors:u},e={...e,binColors:u}}if(e.plotMode!==void 0)if(l){const u=gt(s);if(c={...c,...u},i)for(const m of M)m&&m.setOptions(e);else Z(We(s))}else if(a){const{valueRange:u,lotSize:m,aggregationMethod:D,...k}=c;if(c=k,i)for(const x of M)x&&x.setOptions(e);else Z(v.filter(x=>x!==null))}else for(const u of M)u&&u.setOptions(e);else if(e.aggregationMethod!==void 0&&s==="stackedValues")if(i)for(const u of M)u&&u.setOptions(e);else Z(We("stackedValues"));else for(const u of M)u&&u.setOptions(e);ve()!==null!==d&&Tt(),Ue(),Zt(),Xt(),_t();const r=e.plotMode!==void 0&&e.plotMode!==o;(Bi.some(u=>u in e)||r)&&H(),Oe(),Qt(),Jt(),rt(),at(),t&&p.onViewOptionsChange?.(Rn(c),n,ki(n))}function fn(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:w.xs,flex:"1",minWidth:"0"});const d=e.createElement("span");d.textContent=t,Object.assign(d.style,{fontWeight:"700",fontSize:T.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(d);const s=Hn(n??{});let l=null;if(s.length>0){const a=e.createElement("span");Object.assign(a.style,{fontSize:T.body,lineHeight:Qe.none,color:g.label,flexShrink:"0"}),a.textContent="\u25BE",o.appendChild(a),Object.assign(o.style,{cursor:"pointer",borderRadius:z.control}),o.addEventListener("mouseenter",()=>{o.style.background=g.bgHover}),o.addEventListener("mouseleave",()=>{o.style.background="none"}),l=e.createElement("div"),l.dataset.wmapCardMetaPanel="1",Object.assign(l.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:Cn,background:g.menuBg,borderBottom:`1px solid ${g.menuBorder}`,boxShadow:Ae.menu,padding:`${w.md} ${w.lg}`,fontSize:T.body,display:"none"});const i=Fn(n??{});i&&l.appendChild(i),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`Wafer info for ${t||"this card"}. Click to expand.`),En(o,r=>{a.textContent=r?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(r)),l&&(l.style.display=r?"block":"none")})}return{wrap:o,metaPanel:l}}function pn(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]"),d=Hn(n??{});if(!o||d.length===0)return;const s=o.parentElement,l=f.ownerDocument.createElement("div");Object.assign(l.style,{display:"flex",alignItems:"center",gap:w.xs,flex:"1",minWidth:"0",cursor:"pointer"}),Mt(l,"bare"),s?.insertBefore(l,o),l.appendChild(o);const a=f.ownerDocument.createElement("span");Object.assign(a.style,{fontSize:T.body,lineHeight:Qe.none,color:g.label,flexShrink:"0"}),a.textContent="\u25BE",l.appendChild(a);const i=f.ownerDocument.createElement("div");i.dataset.wmapCardMetaPanel="1",Object.assign(i.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:Cn,background:g.menuBg,borderBottom:`1px solid ${g.menuBorder}`,boxShadow:Ae.menu,padding:`${w.md} ${w.lg}`,fontSize:T.body,display:"none"});const r=Fn(n??{});r&&i.appendChild(r),e.contentWrap.style.position="relative",e.contentWrap.appendChild(i),l.setAttribute("aria-expanded","false"),l.setAttribute("aria-label",`Wafer info for ${t}. Click to expand.`),En(l,u=>{a.textContent=u?"\u25B4":"\u25BE",l.setAttribute("aria-expanded",String(u)),i.style.display=u?"block":"none"})}function ht(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:z.container,boxShadow:Ae.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:ft(),maxHeight:ft()});const d=f.ownerDocument.createElement("div");Object.assign(d.style,{display:"flex",alignItems:"center",padding:`${w.md} ${w.lg} ${w.sm}`,borderBottom:`1px solid ${g.menuBorder}`,flexShrink:"0",gap:w.sm});const{wrap:s,metaPanel:l}=fn(document,Je(e,t),e.wafer.metadata??void 0);d.appendChild(s);const a=f.ownerDocument.createElement("button");a.dataset.wmapExpandBtn="1",a.setAttribute("aria-label","Open full view"),kn(a),a.innerHTML=$e.expand,Object.assign(a.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"}),Mt(a),d.appendChild(a),o.appendChild(d);const i=f.ownerDocument.createElement("div");Object.assign(i.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(i),l&&i.appendChild(l),$.appendChild(o),o.addEventListener("contextmenu",D=>{if(D.defaultPrevented)return;const k=p.insights?.sweeps;if(!Di(e.testDefs,k))return;D.preventDefault();const x=e.viewOptions?{...c,...e.viewOptions}:c,b=Ei(e.dies,{waferLabel:On(e),testDefs:e.testDefs,isLotStack:e.isLotStack,activeTest:x.plotMode==="value"?x.activeTest:void 0,waferIndex:t}),B={x:D.clientX,y:D.clientY};import("./drilldown.js").then(({openDrilldownMenu:j})=>{o.isConnected&&j(B,o,b,{sweeps:k,onSaveImage:m.getSaveImageHook()})})});const r=Fe||ve()!==null,u=e.viewOptions?{...c,...e.viewOptions}:c,m=Ln(i,e,{viewOptions:{...u,showLegend:r,legendPosition:we},showTooltip:!0,padding:A,statsSummary:e.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,downloadFilename:p.downloadFilename,onClick:e.onClick,onSelect:jt(e),insights:X,onExpand:()=>Ie(t,e),showIdentity:!1,chromeInset:Uo,drawWhenVisible:!0});return m.setViewControlsVisible(!1),m.setSummaryVisible(!1),a.onclick=()=>Ie(t,e),{card:o,ctrl:m,canvasWrapper:i,expandBtn:a}}function Do(e){const t=ce[e];if(!t)return;const n=[..._.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=$e.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>ko(n.id)):(t.innerHTML=$e.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>Ie(e,L[e]))}function Z(e){Bo(),Me()?.remove(),De(null),ke(),L=[];for(const i of M)i&&i.destroy();M=[],le=[],ce=[],je=0,$.innerHTML="",rn=e.length,dn(e.map(i=>typeof i=="function"?null:i));const t=[];for(let i=0;i<e.length;i++){const r=e[i];if(typeof r=="function"){const u=f.ownerDocument.createElement("div");u.className="wmap-gallery-card",Object.assign(u.style,{background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:z.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const m=f.ownerDocument.createElement("span");m.textContent="\u2026",Object.assign(m.style,{color:g.label,fontSize:"18px"}),u.appendChild(m),$.appendChild(u),L.push(null),M.push(null),le.push(null),ce.push(null),t.push({index:i,factory:r,placeholder:u}),je++}else{const{ctrl:u,canvasWrapper:m,expandBtn:D}=ht(r,i,e.length);L.push(r),M.push(u),le.push(m),ce.push(D)}}Ut(),Ue(),rt(),at();const n=++Ce,o=()=>{setTimeout(()=>{n===Ce&&p.onItemsResolved?.()},0)},d=i=>{setTimeout(()=>{n===Ce&&p.onItemResolved?.(i,e.length)},0)};let s=e.length-t.length;s>0&&d(s);let l=0;function a(){if(n!==Ce)return;if(l>=t.length){if(be.has(c.plotMode)){const B=c.plotMode;Z(We(B));return}Ee=o,H(),fe||(Ee=null,o());return}const{index:i,factory:r,placeholder:u}=t[l++],m=r();L[i]=m,v[i]=m,dn([m]);const{card:D,ctrl:k,canvasWrapper:x,expandBtn:b}=ht(m,i,e.length);M[i]=k,le[i]=x,ce[i]=b,je--,u.replaceWith(D),d(++s),co(),ro(),!y&&!de?.placement&&m.statsSummary?.findings.length&&(y=kt("right",oe,f.ownerDocument),y.style.maxHeight="calc(100vh - 80px)",y.style.position="sticky",y.style.top="8px",y.style.flexDirection="column",y.style.display="none",(de?.placement??"right")==="left"?q.insertBefore(y,$):q.appendChild(y),H(),P||(P=Q("findings","Summary panel",()=>{if(!y)return;const j=y.style.display!=="none";j||H(),y.style.display=j?"none":"flex",Se(P,!j),ae()}),I.appendChild(K()),I.appendChild(P)),ae()),ae(),setTimeout(a,0)}t.length>0?setTimeout(a,0):o()}if(be.has(c.plotMode)&&v.length>0){const e=gt(c.plotMode);c={...c,...e},Z(We(c.plotMode))}else Z(C);Oe();let ye=0;const mn=new(f.ownerDocument.defaultView??window).ResizeObserver(()=>{if(ye)return;ye=(f.ownerDocument.defaultView??window).requestAnimationFrame(()=>{ye=0,E==null&&mt()})});mn.observe($),y&&H();function Eo(e,t){const n=le[e];if(!n)return;n.innerHTML="",Object.assign(n.style,{alignItems:"center",justifyContent:"center"});const o=f.ownerDocument.createElement("span");o.textContent=t?"Opened in its own window":"Opened in the wafer viewer",Object.assign(o.style,{color:g.label,fontSize:T.body,textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function Ie(e,t){for(const l of _.values())if(l.cardIndex===e)return;const n=Je(t,e),o=Kn++,d=M[e]?.getOptions(),s=ei(n);if(s){const l=s.document;l.title=n,Object.assign(l.documentElement.style,{height:"100%"}),Object.assign(l.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:T.family}),ii(f,l.documentElement);const a=li(f,l.documentElement,()=>x.setOptions({})),i=l.createElement("div");i.dataset.wmapWindowBanner="1",i.textContent=n,Object.assign(i.style,{display:"none",padding:`${w.sm} ${w.xl}`,fontSize:T.body,fontWeight:"700",background:g.warnBg,color:g.warnText,borderBottom:`1px solid ${g.warnBorder}`,flexShrink:"0"}),l.body.appendChild(i);const r=l.createElement("div");Object.assign(r.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),l.body.appendChild(r);const{wrap:u,metaPanel:m}=fn(l,n,t.wafer.metadata??void 0),D=l.createElement("div");Object.assign(D.style,{display:"flex",alignItems:"center",padding:`${w.md} ${w.lg} ${w.sm}`,borderBottom:`1px solid ${g.menuBorder}`,flexShrink:"0",gap:w.sm}),D.appendChild(u),r.appendChild(D);const k=l.createElement("div");Object.assign(k.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),m&&k.appendChild(m),r.appendChild(k);const x=yt(k,t,void 0,d),b=setInterval(()=>{s.closed&&Xe(o)},400);s.addEventListener("pagehide",()=>Xe(o)),_.set(o,{id:o,ctrl:x,cardIndex:e,label:n,closePollId:b,stopThemeSync:a,close:()=>{s.closed||s.close()},setTitle:B=>{l.title=B,i.textContent=B,i.style.display="block"}})}else{const l=ti({title:n,onClose:()=>Xe(o),anchor:f});l.contentWrap.style.flexDirection="column",pn(l,n,t.wafer.metadata??void 0);const a=yt(l.contentWrap,t,void 0,d);_.set(o,{id:o,ctrl:a,cardIndex:e,label:n,closePollId:null,close:()=>l.close(),setTitle:i=>{const r=l.box.querySelector("[data-wmap-window-title]");r&&(r.textContent=i,r.title=i)}})}M[e]?.destroy(),M[e]=null,Eo(e,s!==null),Do(e)}function yt(e,t,n,o){const d=t.viewOptions?{...c,...t.viewOptions}:c,s=o?{...d,...o}:d,a={...n!==void 0?{...s,plotMode:"value",activeTest:n}:s,showLegend:!0,legendPosition:we},i=Ln(e,t,{viewOptions:a,showTooltip:!0,padding:A,statsSummary:t.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,downloadFilename:p.downloadFilename,onClick:t.onClick,onSelect:jt(t),insights:X,showExpandButton:!1,showIdentity:!1});return i.setViewControlsVisible(!0),i.setSummaryVisible(!0),i.setExpandVisible(!1),i}function Xe(e){const t=_.get(e);if(!t||(_.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.(),t.ctrl.destroy(),t.cardIndex===null))return;const n=t.cardIndex,o=L[n];if(!o)return;const{card:d,ctrl:s,canvasWrapper:l,expandBtn:a}=ht(o,n,L.length);le[n]?.parentElement?.replaceWith(d),M[n]=s,le[n]=l,ce[n]=a}function ko(e){const t=_.get(e);t&&(t.close(),Xe(e))}function Bo(){for(const e of _.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function bt(){for(const e of M)e?.drawPendingNow()}const gn=f.ownerDocument.defaultView??window;gn.addEventListener("beforeprint",bt);function Oo(){bt();const e=[...$.querySelectorAll("canvas")];if(!e.length)return;const t=e.length,n=Math.ceil(Math.sqrt(t)),o=Math.ceil(t/n),d=e[0].width,s=e[0].height,l=8,a=(f.ownerDocument.defaultView??window).devicePixelRatio||1,i=Math.round(26*a),r=Math.round(12*a),u=f.ownerDocument.createElement("canvas");u.width=n*d+(n-1)*l,u.height=o*(s+i)+(o-1)*l;const m=u.getContext("2d"),D=Ko($);m.fillStyle=D.background,m.fillRect(0,0,u.width,u.height),e.forEach((k,x)=>{const b=x%n,B=Math.floor(x/n),j=b*(d+l),U=B*(s+i+l),wt=k.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";m.fillStyle=D.surface,m.fillRect(j,U,d,i),m.fillStyle=D.text,m.font=`700 ${r}px system-ui, sans-serif`,m.textAlign="left",m.textBaseline="middle",m.fillText(wt,j+Math.round(10*a),U+i/2,d-Math.round(20*a)),m.drawImage(k,j,U+i)}),u.toBlob(k=>{if(!k)return;const x=M.find(b=>b!=null)?.getExportTitle();fi(k,["gallery",x].filter(Boolean).join(" "),He.onSaveImage)})}return{setItems(e){v=e.map(n=>typeof n=="function"?null:n);const t=c.plotMode;if(be.has(t))if(e.some(o=>typeof o=="function"))Z(e);else{const o=gt(t);c={...c,...o},Z(We(t))}else Z(e)},setOptions(e){R(e,{fireCallback:!1})},getOptions(){return Rn(c)},setFindingsNotice(e){At=e,H()},setColumns(e){cn(e)},getBinColors(){return c.binColors??pe()},setLotStatsSummary(e){N=e,Oe(),y&&H(),ae()},openUserGuide:tn,destroy(){Ce++,gn.removeEventListener("beforeprint",bt),fe?.cancel(),fe=null,Ee=null;for(const e of[..._.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();_.clear();for(const e of M)e&&e.destroy();M=[],Me()?.remove(),mn.disconnect(),ye&&((f.ownerDocument.defaultView??window).cancelAnimationFrame(ye),ye=0),f.ownerDocument.removeEventListener("click",Ve,!0),window.removeEventListener("blur",$t),ie(),Sn(),Re.remove(),q.remove(),y?.remove(),ge?.destroy()}}}
|
|
1
|
+
import{getUniqueTestNumbers as No,resolveTestNumber as zo,findTestDef as _o,collectMetadataValues as Ko}from"../renderer/buildView.js";import{metadataCategoricalValue as Go}from"../core/metadata.js";import{resolveBinColorsForMaps as qo,mergeBinDefs as et,binColorWarning as Xo,mixedPassBinsWarning as Uo,binColorsEqual as Yo}from"../renderer/binColors.js";import{itemPassBins as Zo,INPUT_DEFAULT_PASS_BINS as Qo}from"../core/passBins.js";import{NO_DATA_FILL as Jo}from"../renderer/colorMap.js";import{metadataValueColor as ei}from"../renderer/colorMap.js";import{resolveCanvasTheme as ti}from"./canvasTheme.js";import{ICONS as Fe}from"./icons.js";import{SHADOW as He,LEADING as tt,TRACKING as ni,controlStyle as oi,wireControlHover as Ot,SPACE as w,EDGE_GUTTER as ie,MAP_CHROME_INSET as ii,RADIUS as _,FONT as I,CLR as g,sevColor as kn,MODE_LABELS as si,BIN_LEGEND_MODES as On,STACKED_MODES as be,Z_ABOVE as Tn,applyOverlayZ as ai,getTooltip as li,hideTooltip as Ln,createToolbarHelpers as ri,buildModeMenuEl as di,openDetachWindow as ci,openFloatingWindow as ui,openModal as fi,openReportModal as pi,copyWmapThemeTokens as mi,syncWmapPopupTheme as gi,openUserGuideWindow as hi,makePaletteBtn as yi,makeLogScaleBtn as bi,makeLegendStyleBtn as wi,makeOverlaysBtn as vi,makeOrientationBtn as Ci,menuLayerFor as Rn,saveImageBlob as xi,markMenuTrigger as je,wireMenuA11y as In,wireExpandToggle as Wn,wireTooltip as $n,requestedPassFailDisplay as An,overlayMenuRows as Si,anyOverlayActive as Mi,openCompactDiagnostics as Di,roomForPanel as Pn,logWmapVersionOnce as Ei,buildDataModeEntries as Bi,metadataKeyHasData as ki,metadataModeEntry as Oi}from"./toolbar.js";import{waferDisplayLabel as nt,waferIdentityLabel as Fn}from"../core/waferLabel.js";import{metadataDisplayValue as Ti}from"../core/metadata.js";import{withExportContext as Li}from"./exportName.js";import{sortBinsForDisplay as Ri}from"../stats/binPareto.js";import{diePassStatus as Ii}from"../core/dies.js";import{aggregateValues as Wi,aggregateBinCounts as Hn}from"../core/aggregates.js";import{renderWaferMap as $i,renderWaferMapCard as jn,toPublicViewOptions as Vn}from"./renderWaferMap.js";import{hasDrilldownTargets as Ai,waferPopulation as Pi}from"./chartPopulation.js";import{classifyChanged as Fi,COLOR_KEYS as Hi,findingBin as ji}from"./renderWaferMap.js";import{findingPatternKey as Nn}from"../stats/filterFindings.js";import{buildWaferMap as Vi,getTestPassStatus as zn,isParametricTest as Tt,getDieTestValue as Ni}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as ot}from"../stats/analyzeWaferMap.js";import{collectWarnings as zi,buildWarningsMenuEl as _i,severityOf as Ki}from"./warnings.js";import{asList as _n,compareNatural as Lt,arrayEqual as it,toggleHighlight as Kn}from"../core/utils.js";import{buildCompactMap as Gi,compactLayoutOffered as qi}from"../core/compact.js";import{createSummaryPanelEl as Rt,buildMetadataStripRow as Xi,buildCompactMetadataRows as Gn,metadataEntries as qn,renderLotSummaryContentSteps as Ui,reportMapsFromItems as Yi}from"./summaryPanel.js";import{prettyKey as Zi}from"../stats/facets.js";import{testLabel as Qi,markedTestLabel as Ji,derivedFields as es}from"../renderer/testLabel.js";import{mergeTestDefs as ts}from"../stats/mergeTestDefs.js";import{getDieKey as ns,hasPosition as os}from"../core/dies.js";import{testValue as is}from"../core/dieTable.js";import{runChunked as ss}from"./chunked.js";function Xn(f){if(typeof f!="number"||!Number.isFinite(f))return;const x=Math.round(f);return x>=1?x:void 0}const It=12;function as(f,x,p){let P=x;if(x.length>It){const S=x.slice(0,It-1),W=x.slice(It-1),H=W.reduce((U,se)=>U+se.count,0);P=[...S,{color:g.label,count:H,label:`Other (${W.length} bins)`}]}const E=f.createElement("div");Object.assign(E.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:_.control,overflow:"hidden",border:`1px solid ${g.menuBorder}`,boxSizing:"border-box",marginTop:w.xs,flexShrink:"0"}),E.setAttribute("role","img"),E.setAttribute("aria-label",`Population split: ${P.map(S=>`${S.label} ${st(S.count/p*100)}`).join(", ")}`);for(const S of P){const W=S.count/p*100,H=f.createElement("div");Object.assign(H.style,{flex:`${W} 1 0`,minWidth:W>0?"2px":"0",background:S.color}),$n(H,`${S.label} \xB7 ${S.count.toLocaleString()} dies \xB7 ${st(W)}`),E.appendChild(H)}return E}function st(f){return f>0&&f<.1?"<0.1%":`${f.toFixed(1)}%`}function Un(f,x,p){const P=new Map;let E=0,S=0;for(const W of f){const H=p?new Set(p(W)):void 0;for(const U of W.dies){if(U.partial||U.edgeExcluded)continue;const se=x(U);se!==void 0&&(P.set(se,(P.get(se)??0)+1),E++,H&&Ii(U,H)&&S++)}}return{counts:P,total:E,pass:S}}function Yn(f,x){const p=f.ownerDocument.createElement("div");Object.assign(p.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${w.xxs} ${w.xs}`,borderRadius:_.control});const P=f.ownerDocument.createElement("span");Object.assign(P.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:x.color,border:x.isActive?`2px solid ${g.iconActive}`:`1px solid ${g.menuBorder}`,borderRadius:_.control,boxSizing:"border-box"});const E=f.ownerDocument.createElement("span");if(E.textContent=x.label,Object.assign(E.style,{fontWeight:x.isActive?"700":"400",color:x.isActive?g.iconActive:g.text,whiteSpace:"nowrap"}),p.appendChild(P),p.appendChild(E),x.count!==void 0){const S=f.ownerDocument.createElement("span");if(S.textContent=x.count.toLocaleString(),Object.assign(S.style,{color:x.isActive?g.iconActive:g.text,fontWeight:x.isActive?"700":"400",whiteSpace:"nowrap"}),p.appendChild(S),x.percent!==void 0){const W=f.ownerDocument.createElement("span");W.textContent=st(x.percent),Object.assign(W.style,{color:g.label,whiteSpace:"nowrap"}),p.appendChild(W)}}p.setAttribute("role","button"),p.setAttribute("aria-pressed",x.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",S=>x.onClick(S.ctrlKey||S.metaKey)),p.addEventListener("keydown",S=>{(S.key==="Enter"||S.key===" ")&&(S.preventDefault(),x.onClick(S.ctrlKey||S.metaKey))}),f.appendChild(p)}export function renderWaferGallery(f,x,p={}){Ei();const P=6;let E=Xn(p.columns);const S=p.showHelpButton??!1,W=p.userGuideExtension,H=p.insights?.enabled??!1,U=p.insights?.sweeps?{sweeps:p.insights.sweeps}:void 0,se=ai(p.zIndex),ce=p.summaryPanel,Zn=e=>[...Zo(e)],Wt=()=>v.flatMap(e=>e?[e.ringCount??4]:[]),at=()=>Wt()[0]??4;function Qn(e){const t=[...new Set(e)].sort((n,o)=>n-o);return t.length<2?null:{code:"ring-count-mixed",severity:"warning",message:`These wafers were built with different ring counts (${t.join(", ")}). Each card and each wafer's findings use their own; the lot's ring yield in the Summary panel, report and Insights uses ${e[0]} rings.`}}let z=p.lotStatsSummary,we=p.viewOptions?.legendPosition??"default",Ve=p.perCardLegend??!1;function ve(){const e=l.plotMode??"hardBin";return On.has(e)?null:l.colorbarRangeMode==="data"?"Each map has its own value range, so it keeps its own colour bar":"These wafers have no shared colour bar for value mode, so each map keeps its own"}function $t(){const e=Ve||ve()!==null;for(const t of M)t&&t.setOptions({showLegend:e})}let l={plotMode:"hardBin",showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...p.viewOptions},M=[],Q=[],ue=[],k=[];const Ce=Li(()=>{const e=k.filter(n=>n!=null),t=[...new Set(e.map(n=>Ti(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort(Lt);return{prefix:p.downloadFilename,lots:t,...e.length===1?{wafer:Fn(e[0])}:{waferCount:e.length}}},p.onSaveImage,p.onSaveText);let v=x.map(e=>typeof e=="function"?null:e);function At(){return ts(v)}function xe(){if(v.some(e=>e?.testDefs?.length))return At().defs}let Se=0,Ne=0;const K=new Map;let Jn=0,F=null,ae=null,Pt=new Set,y=null,eo={};function Ft(e){return v[e]?.statsSummary??z?.perWafer.find(t=>t.waferIndex===e)?.summary}function lt(){return!!(v.some(e=>e?.statsSummary?.findings.length)||z?.perWafer.some(e=>e.summary.findings.length))}const to=li(),fe=ri(to),{makeBtn:J,setActive:Me,makeSep:G,makeMenuRow:no,makeMenuSection:oo,makeDropdown:Ht,closeOpenMenu:ze,getOpenMenu:De,setOpenMenu:Ee}=fe;f.ownerDocument.addEventListener("click",ze,!0);const jt=()=>Ln();window.addEventListener("blur",jt);let Vt=p.findingsNotice;function Nt(e){Pt=new Set(e);const t=[...A.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,c)=>{const r=Pt.has(c);o.style.outline=r?`3px solid ${g.findingHighlight}`:"",o.style.outlineOffset=r?"-3px":"",r&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function zt(){Nt([])}let rt=!1;function _t(){rt=!0;for(const e of M)e&&e.clearSelection();rt=!1}function Kt(e){return t=>{!rt&&ae!==null&&(ke(),j()),e.onSelect?.(t)}}function dt(e,t){const n=new Set(e),o=t??M.map((c,r)=>r);for(const c of o){const r=k[c],s=M[c];if(!r||!s)continue;const d=r.dies.filter(i=>n.has(ns(i)));s.setSelection(d)}}function io(){const e=[];for(let t=0;t<v.length;t++){const n=v[t];if(!n)continue;const o=Ft(t)?.findings??[];o.length&&e.push({index:t,item:n,unusualCount:o.filter(c=>c.severity==="unusual").length,notableCount:o.filter(c=>c.severity==="notable").length,totalCount:o.length})}return e}function so(e){const t=k[e]??v[e];t&&Ae(e,t)}function ao(e){const t=Ft(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 lo(){import("../stats/renderSummaryReport.js").then(({renderLotReportHtml:e})=>{pi(e(Yi(v,Qo,at())),{anchor:f})})}function ro(){if(!y)return;y.innerHTML="";const e=io();if(v.length>0){const n=f.ownerDocument.createElement("div"),o=e.length,c=v.filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${c} wafers`:`${o} of ${c} wafer${c===1?"":"s"} with findings`,Object.assign(n.style,{fontSize:I.body,color:g.label,marginBottom:w.md}),y.appendChild(n)}if(e.length>0){const n=f.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...oi("outlined"),marginBottom:w.lg,display:"block",width:"100%",textAlign:"left"}),Ot(n),n.addEventListener("click",lo),y.appendChild(n)}if(e.length===0){const n=f.ownerDocument.createElement("div");Object.assign(n.style,{color:g.icon,fontSize:I.body,padding:"4px 0"}),n.textContent="No findings on any wafer.",y.appendChild(n)}else for(const{index:n,item:o,unusualCount:c,notableCount:r,totalCount:s}of e){const d=c?"unusual":r?"notable":"info",i=c+r||s,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:w.xs,border:"none",borderLeft:`3px solid ${kn(d)}`,borderRadius:_.control,background:g.bgHover,cursor:"pointer",fontSize:I.body,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=nt(o,n),Object.assign(u.style,{color:g.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const m=f.ownerDocument.createElement("span");m.textContent=String(i),a.setAttribute("aria-label",`${nt(o,n)} \u2014 ${i} finding${i===1?"":"s"}${c?`, ${c} unusual`:""} \u2014 view wafer`),Object.assign(m.style,{marginLeft:w.sm,flexShrink:"0",background:kn(d),color:"#fff",borderRadius:_.container,padding:"1px 5px",fontSize:I.body,fontWeight:"600"}),a.appendChild(u),a.appendChild(m),a.addEventListener("click",()=>Ae(n,o)),y.appendChild(a)}const t=f.ownerDocument.createElement("div");t.style.height="12px",y.appendChild(t)}let pe=null,Be=null;function j(){if(y)if(pe?.cancel(),pe=null,z){const e=et(v.map(n=>n?.hbinDefs)),t=et(v.map(n=>n?.sbinDefs));pe=ss(Ui(y,{lotSummary:z,items:v,hbinDefs:e.length?e:void 0,sbinDefs:t.length?t:void 0,testDefs:xe(),ringCount:at(),binColors:l.binColors,plotMode:l.plotMode??"hardBin",fallbackFormat:l.fallbackFormat,activeFindingId:ae,warnings:p.warnings?.display??!0?ee:[],findingsFilter:eo,findingsNotice:Vt,onFindingsFilterChange:j,onSaveText:Ce.onSaveText,onFindingClick:(n,o)=>{ae===n.id?ke():uo(n,o),j()},onWaferClick:so,findingsFor:ao,dieListOptions:p.dieList}),{onDone:()=>{const n=Be;Be=null,n?.()}})}else ro()}function co(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}let _e=[];function Gt(){if(_e.length!==0){for(const e of _e)M[e]?.setOptions({plotMode:l.plotMode,activeTest:l.activeTest});_e=[]}}function ke(){ae=null,zt(),_t(),Gt(),R({highlightBin:void 0},{fireCallback:!1})}function qt(){ae!==null&&(ke(),j())}function uo(e,t){if(ae===e.id){ke();return}ae=e.id,t.style.background=g.bgActive,t.style.fontWeight="600",Gt();const{kind:n,index:o}=e.variable;if(n==="test"){const r=o??0,s=xe();if(s===void 0||s.some(i=>i.testNumber===r))R({plotMode:"value",activeTest:r,highlightBin:void 0},{fireCallback:!1});else{R({highlightBin:void 0},{fireCallback:!1});const a=be.has(l.plotMode??"hardBin")?null:co(e);if(a){for(const u of a)M[u]?.setOptions({plotMode:"value",activeTest:r});_e=[...a]}}}else R({plotMode:n==="softBin"?"softBin":"hardBin",highlightBin:ji(e)},{fireCallback:!1});zt(),_t();const c=e.highlight;if(c.kind==="wafer"){Nt(c.waferIndices);const r=Nn(e);for(const s of c.waferIndices){const d=c.dieKeysByWafer?void 0:k[s]?.statsSummary?.findings.find(a=>Nn(a)===r),i=c.dieKeysByWafer?.[s]??d?.highlight?.dieKeys;i?.length&&dt(i,[s])}}else c.kind==="bin"?c.dieKeys?.length&&dt(c.dieKeys):(c.kind==="region"||c.kind==="dies")&&c.dieKeys?.length&&dt(c.dieKeys)}function le(){if(!F)return;const e=!!y;F.style.display=(z||lt())&&e&&!Re?"flex":"none";const t=y?y.style.display!=="none":!1;(z?.hasNotableFindings||v.some(o=>o?.statsSummary?.hasNotableFindings))&&!t?F.style.color=g.findingIndicator:F.dataset.active||(F.style.color=g.icon)}const $=f.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:_.control,padding:"0",boxShadow:He.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const Xt=()=>{const e=De();e&&(e.remove(),Ee(null)),je(Y,!1)},Y=J("mode","Plot mode",()=>{if(De()){Xt();return}const e=v.flatMap(b=>b?.dies??[]),t=xe(),{testEntries:n,binEntries:o,stackedEntries:c}=Bi(e,t,{includeStacked:!0}),r=v.filter(Boolean).length,s=b=>{if(b===void 0)return r;let O=0;for(const T of v)T?.dies?.some(V=>zn(V,b)!==void 0||is(V,b)!==void 0)&&O++;return O},d=r<2?n:n.map(b=>{const O=s(b.activeTest);return O===r?b:{...b,label:`${b.label} \u2014 ${O} of ${r} wafers`}}),i=l.plotMode??"hardBin",a=l.activeTest??0;function u(b){return b.plotMode!==i?!1:b.plotMode==="value"?a===(b.activeTest??0):b.plotMode==="metadata"?l.activeMetadataKey===b.activeMetadataKey:!0}function m(b,O){b.activeTest!==void 0?R({plotMode:"value",activeTest:b.activeTest,activeMetadataKey:void 0,logScale:b.logScale}):b.activeMetadataKey!==void 0?R({plotMode:b.plotMode,activeTest:void 0,activeMetadataKey:b.activeMetadataKey,passFailDisplay:"off"}):R({plotMode:b.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),O.remove(),Ee(null),je(Y,!1)}const D=new Set,B=v.flatMap(b=>b?.metadataFields??[]).filter(b=>!D.has(b.key)&&D.add(b.key)).filter(b=>ki(e,b.key)).map(Oi),C=di(Y.getBoundingClientRect(),d,o,c,u,m,{makeMenuRow:no,makeMenuSection:oo},i,Y.ownerDocument.defaultView??window,B);Rn(Y).appendChild(C),Ee(C),je(Y,!0),In(C,Y,Xt)});je(Y,!1);const fo=()=>k.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:po,sync:Ut}=yi(fe,()=>({...l,plotMode:l.plotMode??"hardBin"}),fo,e=>R(e));Ut();const mo=x.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function Ke(){const e=xe(),{testNumber:t}=zo(l.activeTest??0,e);return{testNumber:t,td:_o(e,t)}}function Yt(){if((l.plotMode??"hardBin")!=="value")return!1;const{td:e}=Ke();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function Oe(){if((l.plotMode??"hardBin")!=="value")return!1;const{td:e}=Ke();return e!==void 0&&!Tt(e)}function go(){if((l.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=Ke();return v.some(n=>n?.dies?.some(o=>zn(o,e,t)!==void 0))}function ho(e,t){if(!t||!Tt(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((An(l)==="spec"&&n?"spec":l.colorbarRangeMode??"spec")==="spec"&&n)return;let r=1/0,s=-1/0;for(const d of v)if(d)for(const i of d.dies){const a=Ni(i,e);a!==void 0&&(a<r&&(r=a),a>s&&(s=a))}if(isFinite(r))return r===s?[r,r+1]:[r,s]}function Ge(e,t,n){const o=l[e];if(o===t||o!=null&&t!=null&&n(o,t))return!1;l={...l,[e]:t};for(const c of M)c&&c.setOptions({[e]:t});return!0}function Zt(){if((l.plotMode??"hardBin")!=="metadata")return;const e=l.activeMetadataKey;if(!e)return;const t=new Set;for(const n of v)if(n)for(const o of Ko(n.dies,e))t.add(o);return{key:e,values:[...t].sort(Lt)}}function ct(){Ge("metadataValueOrder",Zt(),(e,t)=>e.key===t.key&&it(e.values,t.values))}function ut(){if((l.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=Ke(),n=ho(e,t);Ge("valueRange",n?{test:e,range:n}:void 0,(c,r)=>{const s=a=>Array.isArray(a)?{test:void 0,range:a}:{test:a.test,range:a.range},d=s(c),i=s(r);return d.test===i.test&&it(d.range,i.range)})}let ft=!1;function yo(){if(ft)return;ft=!0,(f.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{ft=!1,ut(),ct(),tn(),en()})}let pt=!1;function bo(){if(pt)return;pt=!0,(f.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{pt=!1,Ze()})}let Qt=[];function me(){const{colors:e,mixedHardBins:t}=qo(v.filter(n=>n!=null),{binColorScheme:l.binColorScheme,useDefinedBinColors:l.useDefinedBinColors});return Qt=t,e}function mt(){return k.filter(e=>e!=null).flatMap(e=>e.dies)}function Jt(){return l.compact?Gi(mt()):void 0}const wo=(e,t)=>it(e.columns,t.columns)&&it(e.rows,t.rows);function en(){Ge("compactMap",Jt(),wo)&&hn()}function vo(){return qi(mt(),k.filter(e=>e!=null).map(e=>e.reticleConfig))}function tn(){Ge("binColors",me(),Yo),Te()}const Co=vi(fe,()=>Si(l,mo,{functionalActive:Oe(),hasLimits:Yt()&&!Oe(),hasRecorded:go()&&!Oe(),binMode:(l.plotMode??"hardBin")==="hardBin"||(l.plotMode??"hardBin")==="softBin"},e=>R(e),{on:!!l.compact,offered:vo(),onChange:e=>R({compact:e}),onDiagnostics:()=>Di(mt(),k.filter(e=>e!=null).map(e=>e.reticleConfig),{anchor:f,onSaveText:Ce.onSaveText})}),()=>Mi(l)),{btn:xo,sync:nn}=wi(fe,()=>({plotMode:l.plotMode,legendPosition:we}),e=>{we=e;for(const t of M)t&&t.setOptions({legendPosition:we})},{get:()=>Ve,set:e=>{Ve=e,$t()},blockedReason:ve});nn();const So=[{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"}],on=Ht("aggr","Aggregation method",()=>So,()=>l.aggregationMethod??"mean",e=>R({aggregationMethod:e}));function sn(){const e=l.plotMode==="stackedValues";on.style.display=e?"":"none"}sn();const{btn:Mo,sync:an}=bi(fe,()=>({...l,functionalActive:Oe()}),e=>R(e));an();const qe=J("specRange","Colorbar range: test limits",()=>{const e=l.colorbarRangeMode==="data"?"spec":"data";R({colorbarRangeMode:e})});function ln(){const e=(l.plotMode??"hardBin")==="value"&&Yt()&&An(l)==="off"&&!Oe();qe.style.display=e?"":"none";const t=(l.colorbarRangeMode??"spec")==="spec";Me(qe,t),qe.ariaLabel=t?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"}ln();const Do=Ci(fe,()=>l,e=>R(e)),Eo=J("downloadAll","Download gallery PNG",Ho),Bo=Ht("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"}],()=>E!=null?String(E):"auto",e=>bn(e==="auto"?void 0:Number(e))),L=f.ownerDocument.createElement("div");Object.assign(L.style,{display:"inline-flex",alignItems:"center",gap:"0"}),$.appendChild(L),L.appendChild(Y),L.appendChild(po),L.appendChild(on),L.appendChild(Mo),L.appendChild(qe),L.appendChild(G()),L.appendChild(Co),L.appendChild(G()),L.appendChild(xo),L.appendChild(G()),L.appendChild(Do),L.appendChild(G()),L.appendChild(Bo),L.appendChild(G()),L.appendChild(Eo),(z||lt())&&(F=J("findings","Summary panel",()=>{if(!y)return;const e=y.style.display!=="none";e||j(),y.style.display=e?"none":"flex",Me(F,!e),le()}),$.appendChild(G()),$.appendChild(F));let q=null,Xe=null,ee=[],rn=!1;function Te(){const e=zi({lotStatsSummary:z,result:{warnings:[...v.flatMap(n=>n?.warnings??[]),...At().warnings]},extra:[l.binColors&&Xo(l.binColors,l.plotMode),Uo(Qt),Qn(Wt())].filter(n=>!!n)}),t=e.length!==ee.length||e.some((n,o)=>n.code!==ee[o]?.code||n.message!==ee[o]?.message);ee=e,(t||!rn)&&(rn=!0,p.warnings?.onWarning?.(e)),ko()}function ko(){if(!q||!Xe)return;const e=ee.length,t=e>0;if(q.style.display=t?"flex":"none",Xe.style.display=t?"":"none",!t)return;const n=Ki(ee[0]),o=`${e} data ${e===1?"warning":"warnings"}`;q.style.color=n==="error"?g.errText:g.warnText,q.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(p.warnings?.display??!0)&&(Xe=G(),q=J("warning","Data warnings",()=>{const e=De();if(ze(new MouseEvent("click")),e)return;const t=_i(q.getBoundingClientRect(),ee,q.ownerDocument.defaultView??window);Rn(f).appendChild(t),Ee(t),In(t,q,()=>ze(new MouseEvent("click")))}),je(q,!1),$.appendChild(Xe),$.appendChild(q)),Te();let re=null;H&&(re=J("analysis","Insights",()=>{un(!Re)}),re.dataset.wmapInsightsBtn="1",$.appendChild(G()),$.appendChild(re));function dn(){import("./userGuideHtml.js").then(e=>hi({buildWaferMap:Vi,renderWaferMap:$i,renderWaferGallery,analyzeWaferMap:ot},e.USER_GUIDE_HTML,W,f))}S&&($.appendChild(G()),$.appendChild(J("help","User guide",()=>dn())));const ge=f.ownerDocument.createElement("div");ge.dataset.wmapGalleryMeta="1",Object.assign(ge.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${w.sm} ${w.lg}`,fontSize:I.sub,lineHeight:tt.none,boxSizing:"border-box"});const Ue=f.ownerDocument.createElement("div");Object.assign(Ue.style,{background:g.canvasBg,display:"flex",alignItems:"stretch",gap:w.lg,paddingBottom:w.lg,minWidth:"0"});const te=f.ownerDocument.createElement("div");te.dataset.wmapGalleryLegend="1",Object.assign(te.style,{display:"flex",flexDirection:"column",gap:w.sm,background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:_.container,padding:`${w.sm} ${w.lg}`,marginBottom:w.lg,boxShadow:He.panel,fontSize:I.body,lineHeight:tt.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const X=f.ownerDocument.createElement("div");Object.assign(X.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let he=null,Le=null,cn=null;function Oo(){return H?he?Promise.resolve(he):(cn??=import("./insightsTab.js").then(({createInsightsTab:e})=>(he=e({getItems:()=>v,getLotStats:()=>z,getBinColors:()=>l.binColors??me(),getRingCount:at,defaultView:p.insights?.defaultView,sweeps:p.insights?.sweeps,onRemoveSweeps:p.insights?.onRemoveSweeps,onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:Ce.onSaveImage,onSaveText:Ce.onSaveText,ownerDocument:f.ownerDocument,openWafer:(t,n,o)=>{const c=v[t];if(!c)return;let r=null;const s=fi({title:n,onClose:()=>r?.destroy(),anchor:f});Cn(s,n,c.wafer.metadata??void 0),r=St(s.contentWrap,c,o,void 0,Pn(s))}}),Le=he.el,Le.style.display="none",f.appendChild(Le),he)),cn):Promise.resolve(null)}let Re=!1;function un(e){H&&(Re=e,Le&&(Le.style.display=e?"flex":"none"),X.style.display=e?"none":"flex",L.style.display=e?"none":"inline-flex",$.style.display="inline-flex",re&&(Me(re,e),re.innerHTML=e?Fe.wafer:Fe.analysis,re.ariaLabel=e?"Back to gallery view":"Insights"),le(),Ze(),e&&Oo().then(t=>{!t||!Re||(t.el.style.display="flex",t.render())}))}H&&p.insights?.defaultOpen&&queueMicrotask(()=>un(!0));const fn=4,Ye=240,gt=480,To=720,Lo=1.25;let de=gt;function pn(e){const t=P*2+110+2,n=mn();if(n)return Math.ceil(n.across*fn+t);let o=null;for(const c of e){if(c==null||!c.dies?.length)continue;const r=c.dies[0].width;if(!(r>0))continue;const s=c.wafer.radius*2*(fn/r),d=Math.ceil(s+t);(o==null||d>o)&&(o=d)}return o}function Ro(e){const t=pn(e);return t==null?Ye:Math.min(de,Math.max(Ye,t))}function Io(e){const t=pn(e);if(t==null)return!1;const n=Math.min(To,Math.max(gt,t));return n<=de?!1:(de=n,!0)}function mn(){const e=l.compact?l.compactMap:void 0,t=k.find(c=>c?.dies?.length)?.dies[0];if(!e||!t||e.columns.length===0||e.rows.length===0||!(t.width>0)||!(t.height>0))return;const n=(l.rotation??0)%180!==0,o=l.showXYIndicator?2.5:0;return{across:(n?e.rows.length:e.columns.length)+o,down:(n?e.columns.length:e.rows.length)+o,cellAspect:n?t.height/t.width:t.width/t.height}}function gn(e,t){const n=mn();if(!n){e.style.aspectRatio="1",t.style.flex="1",t.style.width="",t.style.aspectRatio="";return}e.style.aspectRatio="auto",t.style.flex="none",t.style.width="100%",t.style.aspectRatio=String(n.across*n.cellAspect/n.down)}function Wo(){for(const e of Q)e?.parentElement&&gn(e.parentElement,e)}function hn(){de=gt,Ie=Ye,bt(k.map(e=>e??null)),yt(),Wo()}function ht(){return E!=null?"none":`${de}px`}function yt(){const e=ht();for(const t of Array.from(A.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let Ie=Ye,yn=0;function bt(e){if(Io(e)&&yt(),E==null){const n=Ro(e);n>Ie&&(Ie=n)}vt()}function bn(e){E=Xn(e),yt(),vt()}function wt(e){return`repeat(${e}, minmax(0, ${E!=null?"1fr":`${de}px`}))`}function wn(e){A.style.gridTemplateColumns!==e&&(A.style.gridTemplateColumns=e)}function vt(){if(E!=null){wn(wt(E));return}const e=Math.max(1,yn),t=12,n=A.clientWidth||0,o=r=>(n-t*(r-1))/r;let c=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const r=Math.min(de,Ie*Lo),s=d=>{let i=0;for(;i<e&&o(i+1)>=d;)i++;return i};c=s(r)||s(Ie)||1}wn(wt(c))}const A=f.ownerDocument.createElement("div");if(Object.assign(A.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:wt(1),gap:w.xl,paddingLeft:ie,paddingRight:ie,justifyContent:"start",alignContent:"start",isolation:"isolate"}),ce?.placement){const e=ce.placement;y=Rt(e,ie,f.ownerDocument),y.style.maxHeight="calc(100vh - 80px)",y.style.position="sticky",y.style.top="8px",y.style.display="flex",y.style.flexDirection="column"}else if(z||lt()){const e=!!ce?.defaultOpen;y=Rt("right",ie,f.ownerDocument),y.style.maxHeight="calc(100vh - 80px)",y.style.position="sticky",y.style.top="8px",y.style.flexDirection="column",y.style.display=e?"flex":"none",j()}le(),y?.style.display!=="none"&&F&&Me(F,!0),(ce?.placement??"right")==="left"?(y&&X.appendChild(y),X.appendChild(A)):(X.appendChild(A),y&&X.appendChild(y));const We=f.ownerDocument.createElement("div");Object.assign(We.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:ie,paddingRight:ie,paddingTop:ie,zIndex:"1",background:g.menuBg}),Ue.appendChild(ge),Ue.appendChild($),We.appendChild(Ue),We.appendChild(te),f.appendChild(We),f.appendChild(X);function Ze(){te.innerHTML="";const e=l.plotMode??"hardBin",t=!Re&&On.has(e),n=k.filter(h=>h!=null),o=n.find(h=>h.isLotStack),c=Xi(n.map(h=>({metadata:h.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0),r=e==="metadata",s=l.activeMetadataKey,d=t&&!r?Un(n,h=>(e==="softBin"?h.sbin:h.hbin)??void 0,Zn):{counts:new Map,total:0,pass:0},i=t&&!r?l.binColors??me():void 0,a=i?e==="softBin"?i.pass.soft:i.pass.hard:new Set,u=Ri(d.counts.entries(),a).map(([h])=>h),m=t&&r&&s?Un(n,h=>Go(h.metadata?.[s])):{counts:new Map,total:0,pass:0},D=r?Zt()?.values:void 0,B=t&&r?(D??[...m.counts.keys()].sort(Lt)).filter(h=>m.counts.has(h)):[];if(ge.innerHTML="",c&&ge.appendChild(c),ge.style.display=c?"flex":"none",!u.length&&!B.length){te.style.display="none";return}te.style.display="flex";const C=f.ownerDocument.createElement("div");Object.assign(C.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${w.sm} ${w.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),te.appendChild(C);const b=_n(l.highlightBin),O=k.flatMap(h=>h?.metadataFields??[]).find(h=>h.key===s),T=r?O?.label??(s?Zi(s):"Metadata"):si[e],V=f.ownerDocument.createElement("span");if(V.textContent=T,Object.assign(V.style,{fontSize:I.body,fontWeight:"700",letterSpacing:ni,textTransform:"uppercase",color:g.label,flexShrink:"0"}),C.appendChild(V),!r&&d.total>0){const h=d.pass,N=h/d.total*100,ne=f.ownerDocument.createElement("span");ne.textContent=`Yield ${st(N)}`,Object.assign(ne.style,{fontSize:I.body,fontWeight:"700",color:g.value,whiteSpace:"nowrap",flexShrink:"0"});const oe=f.ownerDocument.createElement("span");oe.textContent=`${h.toLocaleString()} / ${d.total.toLocaleString()} dies`,Object.assign(oe.style,{fontSize:I.body,color:g.label,whiteSpace:"nowrap",flexShrink:"0"}),C.appendChild(ne),C.appendChild(oe)}if(r){const h=_n(l.highlightMetadataValue);B.forEach((N,ne)=>{const oe=h.includes(N),Je=O?.values?.find(kt=>kt.value===N),Bt=Je?.color??ei(ne),Bn=m.counts.get(N)??0;Yn(C,{color:Bt,isActive:oe,label:Je?.label??N,count:Bn,percent:m.total>0?Bn/m.total*100:void 0,onClick:kt=>{const Vo=Kn(l.highlightMetadataValue,N,kt);qt(),R({highlightMetadataValue:Vo})}})});return}const Pe=e==="softBin"?k.flatMap(h=>h?.sbinDefs??[]):k.flatMap(h=>h?.hbinDefs??[]),Mn=new Set,Dt=[];for(const h of Pe)Mn.has(h.bin)||(Mn.add(h.bin),Dt.push(h));const Et=Dt.length>0?new Map(Dt.map(h=>[h.bin,h])):null,Dn=i??l.binColors??me(),jo=e==="softBin"?Dn.soft:Dn.hard,En=h=>jo.get(h)??Jo;for(const h of u){const N=b.includes(h),ne=Et?.get(h),oe=d.counts.get(h)??0;Yn(C,{color:En(h),isActive:N,label:ne?.name?`${h} \xB7 ${ne.name}`:`Bin ${h}`,count:oe,percent:d.total>0?oe/d.total*100:void 0,onClick:Je=>{const Bt=Kn(l.highlightBin,h,Je);qt(),R({highlightBin:Bt})}})}d.total>0&&u.length>1&&te.appendChild(as(f.ownerDocument,[...d.counts.entries()].sort(([,h],[,N])=>N-h).map(([h,N])=>({color:En(h),count:N,label:Et?.get(h)?.name?`${h} \xB7 ${Et.get(h).name}`:`Bin ${h}`})),d.total))}function $e(e){const t=v.filter(d=>d!==null);if(!t.length)return[];const n=t.map(d=>d.dies.filter(os)),o=t[0].wafer,c=t.length,r=o.metadata?{...o,metadata:(({wafer:d,waferId:i,...a})=>a)(o.metadata)}:o;function s(d,i){return{...d,stats:{...d.stats,isLotStack:!0,aggregationMethod:i,lotSize:c}}}if(e==="stackedValues"){const d=xe();let i=d?.filter(Tt);if(d!==void 0&&i?.length===0)return[];if(d?.length||(i=No(t.flatMap(m=>m.dies)).map(m=>({testNumber:m,name:Qi(void 0,m)}))),!i?.length)return[];const a=l.aggregationMethod??"mean";return i.map(u=>{const m=Wi(n,a,u.testNumber),D={testNumber:0,name:u.name,unit:u.unit,...es(u)};return{wafer:r,dies:m,testDefs:[D],label:`${Ji(u,u.testNumber)} \xB7 ${a}`,isLotStack:!0,aggrMethod:a,lotSize:c,statsSummary:s(ot({wafer:r,dies:m,testDefs:[D]},{testNumbers:[0]}),a)}})}if(e==="stackedBins"){let d=et(t.map(i=>i?.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(i=>{const a=Hn(n,i.bin,"hard"),u=[{bin:i.bin,name:i.name}];return{wafer:r,dies:a,hbinDefs:u,label:`${i.bin} \xB7 ${i.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:c,statsSummary:s(ot({wafer:r,dies:a,hbinDefs:u}),"countBin")}})}if(e==="stackedSoftBins"){let d=et(t.map(i=>i?.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(i=>{const a=Hn(n,i.bin,"soft"),u=[{bin:i.bin,name:i.name}];return{wafer:r,dies:a,sbinDefs:u,label:`${i.bin} \xB7 ${i.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:c,statsSummary:s(ot({wafer:r,dies:a,sbinDefs:u}),"countBin")}})}return t}function Ct(e){const t=v.length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:l.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}function R(e,{fireCallback:t=!0}={}){const n=Object.keys(e),o=l.plotMode,c=ve()!==null;l={...l,...e};const r=l.plotMode,s=be.has(r),d=o!==void 0&&be.has(o),i=Ne>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const u=me();l={...l,binColors:u},e={...e,binColors:u}}if("compact"in e){const u=Jt();l={...l,compactMap:u},e={...e,compactMap:u}}if(("compact"in e||l.compact&&("rotation"in e||"showXYIndicator"in e))&&hn(),e.plotMode!==void 0)if(s){const u=Ct(r);if(l={...l,...u},i)for(const m of M)m&&m.setOptions(e);else Z($e(r))}else if(d){const{valueRange:u,lotSize:m,aggregationMethod:D,...B}=l;if(l=B,i)for(const C of M)C&&C.setOptions(e);else Z(v.filter(C=>C!==null))}else for(const u of M)u&&u.setOptions(e);else if(e.aggregationMethod!==void 0&&r==="stackedValues")if(i)for(const u of M)u&&u.setOptions(e);else Z($e("stackedValues"));else for(const u of M)u&&u.setOptions(e);ve()!==null!==c&&$t(),Ze(),sn(),nn(),Ut();const a=e.plotMode!==void 0&&e.plotMode!==o;(Hi.some(u=>u in e)||a)&&j(),Te(),an(),ln(),ut(),ct(),t&&p.onViewOptionsChange?.(Vn(l),n,Fi(n))}function vn(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:w.xs,flex:"1",minWidth:"0"});const c=e.createElement("span");c.textContent=t,Object.assign(c.style,{fontWeight:"700",fontSize:I.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(c);const r=qn(n??{});let s=null;if(r.length>0){const d=e.createElement("span");Object.assign(d.style,{fontSize:I.body,lineHeight:tt.none,color:g.label,flexShrink:"0"}),d.textContent="\u25BE",o.appendChild(d),Object.assign(o.style,{cursor:"pointer",borderRadius:_.control}),o.addEventListener("mouseenter",()=>{o.style.background=g.bgHover}),o.addEventListener("mouseleave",()=>{o.style.background="none"}),s=e.createElement("div"),s.dataset.wmapCardMetaPanel="1",Object.assign(s.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:Tn,background:g.menuBg,borderBottom:`1px solid ${g.menuBorder}`,boxShadow:He.menu,padding:`${w.md} ${w.lg}`,fontSize:I.body,display:"none"});const i=Gn(n??{});i&&s.appendChild(i),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`Wafer info for ${t||"this card"}. Click to expand.`),Wn(o,a=>{d.textContent=a?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(a)),s&&(s.style.display=a?"block":"none")})}return{wrap:o,metaPanel:s}}function Cn(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]"),c=qn(n??{});if(!o||c.length===0)return;const r=o.parentElement,s=f.ownerDocument.createElement("div");Object.assign(s.style,{display:"flex",alignItems:"center",gap:w.xs,flex:"1",minWidth:"0",cursor:"pointer"}),Ot(s,"bare"),r?.insertBefore(s,o),s.appendChild(o);const d=f.ownerDocument.createElement("span");Object.assign(d.style,{fontSize:I.body,lineHeight:tt.none,color:g.label,flexShrink:"0"}),d.textContent="\u25BE",s.appendChild(d);const i=f.ownerDocument.createElement("div");i.dataset.wmapCardMetaPanel="1",Object.assign(i.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:Tn,background:g.menuBg,borderBottom:`1px solid ${g.menuBorder}`,boxShadow:He.menu,padding:`${w.md} ${w.lg}`,fontSize:I.body,display:"none"});const a=Gn(n??{});a&&i.appendChild(a),e.contentWrap.style.position="relative",e.contentWrap.appendChild(i),s.setAttribute("aria-expanded","false"),s.setAttribute("aria-label",`Wafer info for ${t}. Click to expand.`),Wn(s,u=>{d.textContent=u?"\u25B4":"\u25BE",s.setAttribute("aria-expanded",String(u)),i.style.display=u?"block":"none"})}function xt(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:_.container,boxShadow:He.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:ht(),maxHeight:ht()});const c=f.ownerDocument.createElement("div");Object.assign(c.style,{display:"flex",alignItems:"center",padding:`${w.md} ${w.lg} ${w.sm}`,borderBottom:`1px solid ${g.menuBorder}`,flexShrink:"0",gap:w.sm});const{wrap:r,metaPanel:s}=vn(document,nt(e,t),e.wafer.metadata??void 0);c.appendChild(r);const d=f.ownerDocument.createElement("button");d.dataset.wmapExpandBtn="1",d.setAttribute("aria-label","Open full view"),$n(d),d.innerHTML=Fe.expand,Object.assign(d.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${g.menuBorder}`,borderRadius:_.control,background:g.panelBg,color:g.label,padding:w.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),Ot(d),c.appendChild(d),o.appendChild(c);const i=f.ownerDocument.createElement("div");Object.assign(i.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(i),gn(o,i),s&&i.appendChild(s),A.appendChild(o),o.addEventListener("contextmenu",D=>{if(D.defaultPrevented)return;const B=p.insights?.sweeps;if(!Ai(e.testDefs,B))return;D.preventDefault();const C=e.viewOptions?{...l,...e.viewOptions}:l,b=Pi(e.dies,{waferLabel:Fn(e),testDefs:e.testDefs,isLotStack:e.isLotStack,activeTest:C.plotMode==="value"?C.activeTest:void 0,waferIndex:t}),O={x:D.clientX,y:D.clientY};import("./drilldown.js").then(({openDrilldownMenu:T})=>{o.isConnected&&T(O,o,b,{sweeps:B,onSaveImage:m.getSaveImageHook()})})});const a=Ve||ve()!==null,u=e.viewOptions?{...l,...e.viewOptions}:l,m=jn(i,e,{viewOptions:{...u,showLegend:a,legendPosition:we},showTooltip:!0,padding:P,statsSummary:e.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,downloadFilename:p.downloadFilename,onClick:e.onClick,onSelect:Kt(e),insights:U,onExpand:()=>Ae(t,e),showIdentity:!1,chromeInset:ii,drawWhenVisible:!0});return m.setViewControlsVisible(!1),m.setSummaryVisible(!1),d.onclick=()=>Ae(t,e),{card:o,ctrl:m,canvasWrapper:i,expandBtn:d}}function $o(e){const t=ue[e];if(!t)return;const n=[...K.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=Fe.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>Po(n.id)):(t.innerHTML=Fe.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>Ae(e,k[e]))}function Z(e){Fo(),De()?.remove(),Ee(null),ke(),k=[];for(const i of M)i&&i.destroy();M=[],Q=[],ue=[],Ne=0,A.innerHTML="",yn=e.length,bt(e.map(i=>typeof i=="function"?null:i));const t=[];for(let i=0;i<e.length;i++){const a=e[i];if(typeof a=="function"){const u=f.ownerDocument.createElement("div");u.className="wmap-gallery-card",Object.assign(u.style,{background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:_.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const m=f.ownerDocument.createElement("span");m.textContent="\u2026",Object.assign(m.style,{color:g.label,fontSize:"18px"}),u.appendChild(m),A.appendChild(u),k.push(null),M.push(null),Q.push(null),ue.push(null),t.push({index:i,factory:a,placeholder:u}),Ne++}else{const{ctrl:u,canvasWrapper:m,expandBtn:D}=xt(a,i,e.length);k.push(a),M.push(u),Q.push(m),ue.push(D)}}tn(),Ze(),ut(),ct(),en();const n=++Se,o=()=>{setTimeout(()=>{n===Se&&p.onItemsResolved?.()},0)},c=i=>{setTimeout(()=>{n===Se&&p.onItemResolved?.(i,e.length)},0)};let r=e.length-t.length;r>0&&c(r);let s=0;function d(){if(n!==Se)return;if(s>=t.length){if(be.has(l.plotMode)){const O=l.plotMode;Z($e(O));return}Be=o,j(),pe||(Be=null,o());return}const{index:i,factory:a,placeholder:u}=t[s++],m=a();k[i]=m,v[i]=m,bt([m]);const{card:D,ctrl:B,canvasWrapper:C,expandBtn:b}=xt(m,i,e.length);M[i]=B,Q[i]=C,ue[i]=b,Ne--,u.replaceWith(D),c(++r),bo(),yo(),!y&&!ce?.placement&&m.statsSummary?.findings.length&&(y=Rt("right",ie,f.ownerDocument),y.style.maxHeight="calc(100vh - 80px)",y.style.position="sticky",y.style.top="8px",y.style.flexDirection="column",y.style.display="none",(ce?.placement??"right")==="left"?X.insertBefore(y,A):X.appendChild(y),j(),F||(F=J("findings","Summary panel",()=>{if(!y)return;const T=y.style.display!=="none";T||j(),y.style.display=T?"none":"flex",Me(F,!T),le()}),$.appendChild(G()),$.appendChild(F)),le()),le(),setTimeout(d,0)}t.length>0?setTimeout(d,0):o()}if(be.has(l.plotMode)&&v.length>0){const e=Ct(l.plotMode);l={...l,...e},Z($e(l.plotMode))}else Z(x);Te();let ye=0;const xn=new(f.ownerDocument.defaultView??window).ResizeObserver(()=>{if(ye)return;ye=(f.ownerDocument.defaultView??window).requestAnimationFrame(()=>{ye=0,E==null&&vt()})});xn.observe(A),y&&j();function Ao(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:I.body,textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function Ae(e,t){for(const s of K.values())if(s.cardIndex===e)return;const n=nt(t,e),o=Jn++,c=M[e]?.getOptions(),r=ci(n);if(r){const s=r.document;s.title=n,Object.assign(s.documentElement.style,{height:"100%"}),Object.assign(s.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:I.family}),mi(f,s.documentElement);const d=gi(f,s.documentElement,()=>b.setOptions({})),i=s.createElement("div");i.dataset.wmapWindowBanner="1",i.textContent=n,Object.assign(i.style,{display:"none",padding:`${w.sm} ${w.xl}`,fontSize:I.body,fontWeight:"700",background:g.warnBg,color:g.warnText,borderBottom:`1px solid ${g.warnBorder}`,flexShrink:"0"}),s.body.appendChild(i);const a=s.createElement("div");Object.assign(a.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),s.body.appendChild(a);const{wrap:u,metaPanel:m}=vn(s,n,t.wafer.metadata??void 0),D=s.createElement("div");Object.assign(D.style,{display:"flex",alignItems:"center",padding:`${w.md} ${w.lg} ${w.sm}`,borderBottom:`1px solid ${g.menuBorder}`,flexShrink:"0",gap:w.sm}),D.appendChild(u),a.appendChild(D);const B=s.createElement("div");Object.assign(B.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),m&&B.appendChild(m),a.appendChild(B);let C=0;const b=St(B,t,void 0,c,(T,V)=>{const Pe=T?V:-C;try{r.resizeBy(Pe,0),C=T?V:0}catch{}}),O=setInterval(()=>{r.closed&&Qe(o)},400);r.addEventListener("pagehide",()=>Qe(o)),K.set(o,{id:o,ctrl:b,cardIndex:e,label:n,closePollId:O,stopThemeSync:d,close:()=>{r.closed||r.close()},setTitle:T=>{s.title=T,i.textContent=T,i.style.display="block"}})}else{const s=ui({title:n,onClose:()=>Qe(o),anchor:f});s.contentWrap.style.flexDirection="column",Cn(s,n,t.wafer.metadata??void 0);const d=St(s.contentWrap,t,void 0,c,Pn(s));K.set(o,{id:o,ctrl:d,cardIndex:e,label:n,closePollId:null,close:()=>s.close(),setTitle:i=>{const a=s.box.querySelector("[data-wmap-window-title]");a&&(a.textContent=i,a.title=i)}})}M[e]?.destroy(),M[e]=null,Ao(e,r!==null),$o(e)}function St(e,t,n,o,c){const r=t.viewOptions?{...l,...t.viewOptions}:l,s=o?{...r,...o}:r,i={...n!==void 0?{...s,plotMode:"value",activeTest:n}:s,showLegend:!0,legendPosition:we},a=jn(e,t,{viewOptions:i,showTooltip:!0,padding:P,statsSummary:t.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,downloadFilename:p.downloadFilename,onClick:t.onClick,onSelect:Kt(t),insights:U,showExpandButton:!1,onSummaryPanelChange:c,showIdentity:!1});return a.setViewControlsVisible(!0),a.setSummaryVisible(!0),a.setExpandVisible(!1),a}function Qe(e){const t=K.get(e);if(!t||(K.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.(),t.ctrl.destroy(),t.cardIndex===null))return;const n=t.cardIndex,o=k[n];if(!o)return;const{card:c,ctrl:r,canvasWrapper:s,expandBtn:d}=xt(o,n,k.length);Q[n]?.parentElement?.replaceWith(c),M[n]=r,Q[n]=s,ue[n]=d}function Po(e){const t=K.get(e);t&&(t.close(),Qe(e))}function Fo(){for(const e of K.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function Mt(){for(const e of M)e?.drawPendingNow()}const Sn=f.ownerDocument.defaultView??window;Sn.addEventListener("beforeprint",Mt);function Ho(){Mt();const e=[...A.querySelectorAll("canvas")];if(!e.length)return;const t=e.length,n=Math.ceil(Math.sqrt(t)),o=Math.ceil(t/n),c=e[0].width,r=e[0].height,s=8,d=(f.ownerDocument.defaultView??window).devicePixelRatio||1,i=Math.round(26*d),a=Math.round(12*d),u=f.ownerDocument.createElement("canvas");u.width=n*c+(n-1)*s,u.height=o*(r+i)+(o-1)*s;const m=u.getContext("2d"),D=ti(A);m.fillStyle=D.background,m.fillRect(0,0,u.width,u.height),e.forEach((B,C)=>{const b=C%n,O=Math.floor(C/n),T=b*(c+s),V=O*(r+i+s),Pe=B.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";m.fillStyle=D.surface,m.fillRect(T,V,c,i),m.fillStyle=D.text,m.font=`700 ${a}px system-ui, sans-serif`,m.textAlign="left",m.textBaseline="middle",m.fillText(Pe,T+Math.round(10*d),V+i/2,c-Math.round(20*d)),m.drawImage(B,T,V+i)}),u.toBlob(B=>{if(!B)return;const C=M.find(b=>b!=null)?.getExportTitle();xi(B,["gallery",C].filter(Boolean).join(" "),Ce.onSaveImage)})}return{setItems(e){v=e.map(n=>typeof n=="function"?null:n);const t=l.plotMode;if(be.has(t))if(e.some(o=>typeof o=="function"))Z(e);else{const o=Ct(t);l={...l,...o},Z($e(t))}else Z(e)},setOptions(e){R(e,{fireCallback:!1})},getOptions(){return Vn(l)},setFindingsNotice(e){Vt=e,j()},setColumns(e){bn(e)},getBinColors(){return l.binColors??me()},setLotStatsSummary(e){z=e,Te(),y&&j(),le()},openUserGuide:dn,destroy(){Se++,Sn.removeEventListener("beforeprint",Mt),pe?.cancel(),pe=null,Be=null;for(const e of[...K.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();K.clear();for(const e of M)e&&e.destroy();M=[],De()?.remove(),xn.disconnect(),ye&&((f.ownerDocument.defaultView??window).cancelAnimationFrame(ye),ye=0),f.ownerDocument.removeEventListener("click",ze,!0),window.removeEventListener("blur",jt),se(),Ln(),We.remove(),X.remove(),y?.remove(),he?.destroy()}}}
|
|
@@ -9,6 +9,7 @@ import { type WarningsOptions } from './warnings.js';
|
|
|
9
9
|
import type { InsightsOptions } from './insightsTab.js';
|
|
10
10
|
import { type DieListDisplayOptions } from './dieList.js';
|
|
11
11
|
import { type BinColors } from '../renderer/binColors.js';
|
|
12
|
+
import { type CompactMap } from '../core/compact.js';
|
|
12
13
|
/**
|
|
13
14
|
* Stable display preferences — worth persisting to localStorage or a user profile.
|
|
14
15
|
* These describe how the user wants to view wafer maps in general.
|
|
@@ -46,6 +47,23 @@ export interface WaferPreferences {
|
|
|
46
47
|
showQuadrantBoundaries?: boolean;
|
|
47
48
|
showReticle?: boolean;
|
|
48
49
|
showXYIndicator?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Draw the axis labels (original die coordinates along the bottom and left edges). Unset, they
|
|
52
|
+
* appear while the map is zoomed and not otherwise; `true` shows them always, `false` never.
|
|
53
|
+
* The Overlays menu's **Axis labels** row sets it. Showing them reserves room for the labels,
|
|
54
|
+
* so the map is a little smaller.
|
|
55
|
+
*/
|
|
56
|
+
showAxes?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Draw the dies on a compact grid with the empty rows and columns removed and each group of
|
|
59
|
+
* dies outlined, instead of at their physical positions. Default false. The toolbar offers
|
|
60
|
+
* the toggle when the occupied rows and columns repeat at a regular pitch (a multi-project
|
|
61
|
+
* wafer), or at the supplied `reticleConfig` width and height; setting it here applies it
|
|
62
|
+
* regardless. Only the layout changes: every die is still drawn and counted, and axis labels
|
|
63
|
+
* stay original die coordinates. The wafer outline, rings, quadrants, reticle grid and XY
|
|
64
|
+
* indicator are not drawn in this layout.
|
|
65
|
+
*/
|
|
66
|
+
compact?: boolean;
|
|
49
67
|
/** Legend position for bin modes. Default 'default'. */
|
|
50
68
|
legendPosition?: 'default' | 'compact' | 'bottom' | 'top' | 'left' | 'floating';
|
|
51
69
|
/**
|
|
@@ -411,6 +429,11 @@ export interface CardSharedState {
|
|
|
411
429
|
* `stackedBins`/`stackedSoftBins` hover tooltips.
|
|
412
430
|
*/
|
|
413
431
|
lotSize?: number;
|
|
432
|
+
/**
|
|
433
|
+
* The compact layout to draw when `compact` is on, built over every die the gallery shows,
|
|
434
|
+
* so all cards share one grid and stay comparable. A lone map builds its own from its dies.
|
|
435
|
+
*/
|
|
436
|
+
compactMap?: CompactMap;
|
|
414
437
|
}
|
|
415
438
|
/** @internal */
|
|
416
439
|
export type CardViewOptions = WaferViewOptions & CardSharedState;
|
|
@@ -439,6 +462,13 @@ export interface CardRenderOptions extends Omit<RenderOptions, 'viewOptions'> {
|
|
|
439
462
|
* spent most of a mode switch drawing cards nobody could see.
|
|
440
463
|
*/
|
|
441
464
|
drawWhenVisible?: boolean;
|
|
465
|
+
/**
|
|
466
|
+
* Told when the Summary panel opens or closes beside the map, with the width it took from the
|
|
467
|
+
* map when it opened. For a host that owns the box this map sits in and can widen it by that
|
|
468
|
+
* much, so the map keeps its size (`renderWaferGallery` does this for its detached windows).
|
|
469
|
+
* Without it a map expanded by its own Expand button does the same for its own modal.
|
|
470
|
+
*/
|
|
471
|
+
onSummaryPanelChange?: (open: boolean, widthPx: number) => void;
|
|
442
472
|
}
|
|
443
473
|
/** @internal */
|
|
444
474
|
export interface CardController extends WaferMapController {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{buildView as Hi,buildHoverText as Vi,findTestDef as vt,resolveTestNumber as qt,buildMapTitle as Yi}from"../renderer/buildView.js";import{drawMapCanvas as Xi,BIN_LEGEND_W as Jn,BIN_LEGEND_W_COMPACT as Ni,BIN_LEGEND_ADAPT_COMPACT as ji,BIN_LEGEND_ADAPT_FLOATING as _i,PATH_SHAPES as Ki}from"./toCanvas.js";import{buildWaferMap as $i,getTestPassStatus as Gi,isParametricTest as Jt}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Ui}from"../stats/analyzeWaferMap.js";import{SHADOW as Zi,LEADING as ei,wireControlHover as ti,SPACE as Y,EDGE_GUTTER as Qi,RADIUS as ni,FONT as xt,CLR as M,applyOverlayZ as qi,getTooltip as ii,hideTooltip as wt,positionTooltip as oi,createToolbarHelpers as Ji,buildModeMenuEl as eo,openReparentedModal as to,openUserGuideWindow as no,makePaletteBtn as io,makeLogScaleBtn as oo,makeLegendStyleBtn as so,makeOverlaysBtn as lo,makeOrientationBtn as ao,menuLayerFor as si,saveImageBlob as ro,markMenuTrigger as nt,wireMenuA11y as li,wireExpandToggle as co,nextFrame as en,requestedPassFailDisplay as fo,overlayMenuRows as po,anyOverlayActive as uo,logWmapVersionOnce as go,buildDataModeEntries as ho,metadataKeyHasData as mo,metadataModeEntry as yo}from"./toolbar.js";import{waferIdentityLabel as bo}from"../core/waferLabel.js";import{metadataDisplayValue as vo}from"../core/metadata.js";import{withExportContext as xo}from"./exportName.js";import{createSummaryPanelEl as tn,wrapWithSummaryPanel as nn,renderWaferSummaryContentSteps as wo}from"./summaryPanel.js";import{runChunked as Co}from"./chunked.js";import{collectWarnings as So,buildWarningsMenuEl as Mo,severityOf as Eo}from"./warnings.js";import{ICONS as ai}from"./icons.js";import{hasDrilldownTargets as Do,selectionPopulation as ko,waferPopulation as Bo}from"./chartPopulation.js";import{createIdentityHeader as Lo,collapsedLabel as on}from"./identityHeader.js";import{getDieKey as he,hasPosition as ri,isPositionedDie as To}from"../core/dies.js";import{buildDieListSection as Po}from"./dieList.js";import{buildMaplessSummary as Oo}from"./maplessSummary.js";import{resolveBinColors as Ro,binColorWarning as Io}from"../renderer/binColors.js";import{INPUT_DEFAULT_PASS_BINS as Wo}from"../core/passBins.js";import{toggleHighlight as di}from"../core/utils.js";const ci=new Set(["binColorScheme","valueColorScheme","reverseValueScheme","useDefinedBinColors","rotation","flipX","flipY","showDieLabels","showRingBoundaries","showQuadrantBoundaries","showReticle","showXYIndicator","legendPosition","logScale","colorbarRangeMode","markFailingDies","fallbackFormat"]);export const COLOR_KEYS=["binColorScheme","valueColorScheme","reverseValueScheme","useDefinedBinColors","binColors"];export function classifyChanged(L){const m=L.some(p=>ci.has(p)),S=L.some(p=>!ci.has(p));return m&&S?"mixed":m?"preference":"state"}export function findingBin(L){const{kind:m,bin:S}=L.variable;return m==="hardBin"||m==="softBin"?S:void 0}export function toPublicViewOptions(L){const{metadataValueOrder:m,binColors:S,lotSize:p,...B}=L;return B}export function renderWaferMap(L,m,S={}){return renderWaferMapCard(L,m,S)}export function renderWaferMapCard(L,m,S={}){go();const p=L.ownerDocument,B=p.defaultView??window,sn=()=>ie.label,ln=()=>bo({label:sn(),wafer:_}),me=xo(()=>{const e=vo(_.metadata?.lot);return{prefix:S.downloadFilename,lots:e!==void 0?[e]:[],...ie.isLotStack?{stackedWafers:h?.lotSize??!0}:{wafer:ln()}}},S.onSaveImage,S.onSaveText);function an(){const e=h.plotMode==="softBin"||h.plotMode==="stackedSoftBins"?J:q,{primary:t,secondary:n}=Yi(h,c.fallbackFormat,e);return[t,ie.isLotStack?"":n].filter(Boolean).join(" ")||"wafer-map"}B.getComputedStyle(L).position==="static"&&(L.style.position="relative");const fi=L.clientHeight;S.height!=null&&(L.style.height=typeof S.height=="number"?`${S.height}px`:S.height);const Ct=m.dataCoverage?m.dataCoverage.unpositionedDies:m.dies.filter(e=>!ri(e)).length,Ae=(m.dataCoverage?m.dataCoverage.totalDies:m.dies.length-Ct)===0&&Ct>0,Fe=p.createElement("div");Object.assign(Fe.style,{display:"flex",flexDirection:"column",width:"100%",height:"100%"}),L.appendChild(Fe);const De=p.createElement("div");Object.assign(De.style,{position:"relative",width:"100%",flex:"1 1 auto",minHeight:"0"});const ye=S.chromeInset??Qi,Q=p.createElement("div");Object.assign(Q.style,{display:"flex",alignItems:"stretch",gap:Y.sm,background:M.canvasBg,paddingBottom:Y.lg,paddingTop:ye,paddingLeft:ye,paddingRight:ye,flexShrink:"0",minWidth:"0"}),Fe.appendChild(Q),Fe.appendChild(De);function ze(){const e=[...Q.children].some(t=>t.style.display!=="none");Q.style.display=e?"flex":"none"}const k=p.createElement("div");Object.assign(k.style,{position:"relative",width:"100%",height:"100%"});const s=p.createElement("canvas");Object.assign(s.style,{width:"100%",height:"100%",display:"block"}),k.appendChild(s),De.appendChild(k);let it=null;if(Ct>0){let n=function(){if(t){const r=Po(e,m.testDefs,{...S.dieList,onSaveText:me.onSaveText,waferMetadata:_.metadata,metadataFields:xe,ownerDocument:p});if(r)return r}const o=vt(m.testDefs,c.activeTest??0),a=Jt(o)?c.logScale??o?.logScale??!1:!1;return Oo(e,m.testDefs,{plotMode:c.plotMode??"hardBin",activeTest:c.activeTest,hbinDefs:q,sbinDefs:J,binColors:h.binColors,valueColorScheme:c.valueColorScheme,reverseValueScheme:c.reverseValueScheme,logScale:a,colorbarRangeMode:c.colorbarRangeMode,valueRangeDies:m.dies})},i=function(o){const a=p.createElement("button");return a.type="button",ti(a),Object.assign(a.style,{fontSize:xt.body,padding:`${Y.xxs} ${Y.sm}`,borderRadius:ni.control,flexShrink:"0",border:`1px solid ${M.menuBorder}`,background:M.menuBg,color:M.text,cursor:"pointer"}),a.textContent=t?"View chart":"View die list",a.addEventListener("click",r=>{r.stopPropagation(),t=!t,a.textContent=t?"View chart":"View die list",o()}),a};const e=m.dies.filter(o=>!ri(o));let t=!1;if(Ae){const o=p.createElement("div");Object.assign(o.style,{position:"absolute",inset:"0",background:M.panelBg,padding:Y.xl,boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",gap:Y.md,zIndex:"1"});const a=p.createElement("div");Object.assign(a.style,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:Y.md});const r=p.createElement("span");Object.assign(r.style,{fontSize:xt.body,color:M.label,lineHeight:ei.base}),r.textContent="No die position data for this wafer.",a.appendChild(r);const l=p.createElement("div");Object.assign(l.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),a.appendChild(i(()=>l.replaceChildren(n()))),o.appendChild(a),o.appendChild(l),k.appendChild(o),it=()=>{t||l.replaceChildren(n())}}else{const o=p.createElement("div");Object.assign(o.style,{position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"3",background:M.panelBg,borderTop:`1px solid ${M.menuBorder}`,fontSize:xt.body,color:M.text,cursor:"pointer",padding:`${Y.xs} ${Y.md}`,display:"flex",alignItems:"center",justifyContent:"space-between",gap:Y.md}),ti(o,"bare");const a=p.createElement("span");a.textContent=`+${e.length} ${e.length===1?"die":"dies"} without position data`,o.appendChild(a);const r=p.createElement("span");r.textContent="\u25BE",Object.assign(r.style,{fontSize:xt.body,lineHeight:ei.none,color:M.label,flexShrink:"0"}),o.appendChild(r),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`${e.length} dies without position data. Click to view.`);let l=null,d=null;co(o,f=>{if(r.textContent=f?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(f)),f){l=p.createElement("div");const g=o.getBoundingClientRect().height||28;Object.assign(l.style,{position:"absolute",left:"0",right:"0",bottom:`${g}px`,top:"20%",zIndex:"2",background:M.panelBg,borderTop:`1px solid ${M.menuBorder}`,padding:Y.md,boxSizing:"border-box",display:"flex",flexDirection:"column",gap:Y.md}),l.addEventListener("click",N=>N.stopPropagation());const v=p.createElement("div");Object.assign(v.style,{display:"flex",justifyContent:"flex-end"}),v.appendChild(i(()=>{d&&d.replaceChildren(n())})),l.appendChild(v),d=p.createElement("div"),Object.assign(d.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),d.appendChild(n()),l.appendChild(d),k.appendChild(l)}else l&&(l.remove(),l=null,d=null)}),k.appendChild(o),it=()=>{d&&!t&&d.replaceChildren(n())}}}const{onHover:ot,onClick:pi,onSelect:ae,onViewOptionsChange:ui,showTooltip:gi=!0,showToolbar:He=!0,showIdentity:rn=!0,summaryPanel:Ve,showHelpButton:dn=!1,userGuideExtension:hi,onExpand:cn,showExpandButton:fn=!0,zIndex:mi,insights:be,warnings:pn,viewOptions:yi={},...ke}=S,Ye=be?.enabled??!1,bi=.4,vi=20,st=[...m.passBins??Wo],un=pn?.display??!0,xi=qi(mi);let fe=S.statsSummary,pe=[],gn=!1,lt=null,hn=!1;function St(){const e=So({result:m,statsSummary:fe,extra:lt?[lt]:[]}),t=e.length!==pe.length||e.some((n,i)=>n.code!==pe[i]?.code||n.message!==pe[i]?.message);pe=e,(t||!gn)&&(gn=!0,pn?.onWarning?.(e))}St();let ie=m,_=m.wafer,ve=m.dies,x=new Set;const wi={sweeps:be?.sweeps,onSaveImage:me.onSaveImage},Mt=()=>!Ae&&Do(ee,be?.sweeps);let mn=null,at=null,rt=!1,yn=!1,q=m.hbinDefs,J=m.sbinDefs,ee=m.testDefs,xe=m.metadataFields,bn=m.reticles?.length?m.reticles:void 0,vn=m.reticleConfig,xn=m.dataAxisFlip,Et=m.isLotStack??!1,Dt=m.aggrMethod,kt=m.lotSize;const Ci=He&&Ye;let K=null,oe=null,se=null;rn&&(K=Lo(on(_.metadata??{},Xe())??"",_.metadata,{lotStack:Xe(),ownerDocument:p}),k.appendChild(K.metaPanel),K.metaPanel.style.visibility="visible",K.isEmpty()||(oe=wn(K.wrap),Q.insertBefore(oe,Q.firstChild),ze()));function wn(e){const t=p.createElement("div");return Object.assign(t.style,{display:"flex",alignItems:"center",padding:`${Y.sm} ${Y.lg}`,flex:"1 1 auto",minWidth:"0",overflow:"hidden",gap:Y.sm}),Object.assign(e.style,{flex:"1",minWidth:"0"}),t.appendChild(e),t}function Xe(){return Et?{lotSize:kt??1,aggrMethod:Dt}:void 0}function Si(){if(!K)return;K.update(on(_.metadata??{},Xe())??"",_.metadata,Xe());const e=oe?.isConnected??!1,t=!K.isEmpty();!t&&e?(oe.remove(),oe=null):t&&!e&&(oe=wn(K.wrap),oe.style.display="",Q.insertBefore(oe,Q.firstChild),ze())}const Mi=[...q??[],...J??[]].some(e=>e.color);let c={plotMode:"hardBin",showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,showReticle:!1,showXYIndicator:!1,rotation:0,flipX:!1,flipY:!1,legendPosition:"default",...yi},$=null,le=!1,Cn=null;function Ei(){return Ye?$?Promise.resolve($):(Cn??=import("./insightsTab.js").then(({createInsightsTab:e})=>($=e({getItems:()=>[{wafer:_,dies:ve,hbinDefs:q,sbinDefs:J,testDefs:ee,label:sn(),passBins:st,statsSummary:fe}],getBinColors:()=>h.binColors,getRingCount:()=>ie.ringCount??4,onSaveImage:me.onSaveImage,onSaveText:me.onSaveText,defaultView:be?.defaultView,sweeps:be?.sweeps,onRemoveSweeps:be?.onRemoveSweeps,showMetadataStrip:!1,contentInset:ye,backTab:Ci?void 0:{label:"Map",onBack:()=>Ne(!1)},onOpenGuide:dn&&!He?()=>Gt():void 0,focusTest:t=>{R({plotMode:"value",activeTest:t,highlightBin:void 0}),Ne(!1)},ownerDocument:p}),Object.assign($.el.style,{position:"absolute",inset:"0",background:M.canvasBg,overflowY:"auto",paddingTop:"0"}),$.el.style.display="none",De.appendChild($.el),$)),Cn):Promise.resolve(null)}let Sn=0;const Bt=["wheel","touchstart","pointerdown","keydown"];function Di(e,t){if(t<=0)return;let n=!1;const i=[],o=()=>{n=!0;for(const r of i)B.clearTimeout(r);i.length=0;for(const r of Bt)e.removeEventListener(r,o)},a=()=>n||!le?!0:(e.scrollTop=t,e.scrollTop>=t);if(!a()){for(const r of Bt)e.addEventListener(r,o,{passive:!0,once:!0});for(const r of[0,50,150,300,600])i.push(B.setTimeout(()=>{a()},r));i.push(B.setTimeout(()=>{for(const r of Bt)e.removeEventListener(r,o)},700))}}function Ne(e){if(!Ye)return;const t=le;le=e,$&&!e&&t&&(Sn=$.el.scrollTop),$&&($.el.style.display=e?"flex":"none"),k.style.visibility=e?"hidden":"",H&&(H.style.display=e||Ae?"none":"flex"),O&&(O.style.display=e?"none":"flex"),se&&(se.style.display=Me?"none":"flex"),re&&(re.style.display="flex"),oe&&(oe.style.display=""),ze(),K&&e&&K.collapse(),pt(),X&&(X.innerHTML=e?ai.wafer:ai.analysis,X.ariaLabel=e?"Back to wafer view":"Insights"),e&&Ei().then(n=>{!n||!le||(n.el.style.display="flex",n.render(),Di(n.el,Sn))})}Ye&&be?.defaultOpen&&queueMicrotask(()=>Ne(!0));let h,je,G=null,T=null,Lt=[],Tt;function Mn(e){Tt!==e&&(Tt=e,C())}let we=null,Pt=ke.legendOffset??{x:0,y:0},_e=!1,Be=!1,Ke={x:0,y:0},Ot={x:0,y:0},Ce=!1,Le=!1,j="select",Te={x:0,y:0},dt={x:0,y:0},W={x:0,y:0},A={x:0,y:0},$e=!1,Pe=!1;function Rt(){const e=c;h=Hi(_,ve.filter(To),{plotMode:e.plotMode,binColorScheme:e.binColorScheme,valueColorScheme:e.valueColorScheme,reverseValueScheme:e.reverseValueScheme,useDefinedBinColors:e.useDefinedBinColors,binColors:e.binColors??Ro(ve,{passBins:st,binColorScheme:e.binColorScheme,hbinDefs:q,sbinDefs:J,useDefinedBinColors:e.useDefinedBinColors}),passBins:st,showDieLabels:e.showDieLabels,showRingBoundaries:e.showRingBoundaries,showQuadrantBoundaries:e.showQuadrantBoundaries,showReticle:e.showReticle,showXYIndicator:e.showXYIndicator,reticles:bn,ringCount:ie.ringCount??4,highlightBin:e.highlightBin,highlightMetadataValue:e.highlightMetadataValue,activeTest:e.activeTest,activeMetadataKey:e.activeMetadataKey,testDefs:ee,valueRange:e.valueRange,metadataValueOrder:e.metadataValueOrder,logScale:e.logScale,isLotStack:Et,aggregationMethod:Dt??e.aggregationMethod,lotSize:kt??e.lotSize,dataAxisFlip:xn,colorbarRangeMode:e.colorbarRangeMode,passFailDisplay:e.passFailDisplay,fallbackFormat:e.fallbackFormat,interactiveTransform:{rotation:e.rotation??0,flipX:e.flipX??!1,flipY:e.flipY??!1}},{hbinDefs:q,sbinDefs:J,metadataFields:xe}),je=void 0;const t=e.binColors?null:Io(h.binColors,h.plotMode);t?.message!==lt?.message&&(lt=t,St(),hn&&At())}Rt();let te=null,Oe=null,Re=null,En=S.findingsNotice,ki={},F=null,ue=null;function Bi(e){const{kind:t,index:n}=e.variable;R(t==="test"?{plotMode:"value",activeTest:n??0,highlightBin:void 0}:{plotMode:t==="softBin"?"softBin":"hardBin",highlightBin:findingBin(e)});const i=e.highlight;(i.kind==="bin"||i.kind==="region"||i.kind==="dies")&&Bn(i.dieKeys)}const Ge=new Map,It=new WeakSet;function Wt(e){if(Ge.get(e)?.cancel(),Ge.delete(e),e.style.display==="none"){It.add(e);return}It.delete(e);const t=Co(wo(e,{wafer:_,dies:ve,yieldSummary:ie.yield,dataCoverage:ie.dataCoverage,hbinDefs:q,sbinDefs:J,testDefs:ee,statsSummary:fe,warnings:un?pe:[],passBins:st,ringCount:ie.ringCount??4,binColors:h.binColors,plotMode:c.plotMode??"hardBin",metadataShownElsewhere:rn,fallbackFormat:c.fallbackFormat,activeFindingId:Re,findingsFilter:ki,findingsNotice:En,onFindingsFilterChange:ge,onSaveText:me.onSaveText,metadataFields:xe,dieListOptions:S.dieList,onFindingClick:(n,i)=>{Re===n.id?(Re=null,Bn([]),R({highlightBin:void 0})):(Re=n.id,Bi(n)),ge()}}));t.done||Ge.set(e,t)}function ge(){te&&Wt(te)}function Ue(){F&&Wt(F)}if(Ve?.placement){const e=Ve.placement;te=tn(e,ye,p);const t=k.parentElement,n=k.nextSibling;Oe=nn(k,te,e),t?.insertBefore(Oe,n),ge()}else if(fe){const e=Ve?.defaultOpen??!He;F=tn("right",ye,p),F.style.display=e?"block":"none";const t=k.parentElement,n=k.nextSibling;ue=nn(k,F,"right"),t?.insertBefore(ue,n),Ue()}const z=gi?ii(p):null;let re=null,P=null,H=null,O=null,ct=null,U=null,Dn=null,X=null,de=null,ft=null;hn=!0;function At(){if(!de||!ft)return;const e=pe.length,t=e>0;if(de.style.display=t?"flex":"none",ft.style.display=t?"":"none",!t)return;const n=Eo(pe[0]),i=`${e} data ${e===1?"warning":"warnings"}`;de.style.color=n==="error"?M.errText:M.warnText,de.ariaLabel=n==="error"?`${i} \u2014 the map may be positionally wrong`:i}let Ft=null,kn=null,zt=null,Ht=null,Vt=null,Yt=null;function Se(e="selection"){Re!==null&&(Re=null,e==="selection"?R({highlightBin:void 0}):(x=new Set,ae?.([])),ge())}function Bn(e){x=new Set(e??[]),ae&&ae(Ze()),C()}function pt(){if(!U)return;const e=!!(te??F);U.style.display=fe&&e&&!le?"flex":"none";const t=te??F,n=t?t.style.display!=="none":!1;fe?.hasNotableFindings&&!n?U.style.color=M.findingIndicator:U.dataset.active||(U.style.color=M.icon)}let Ln=null;function Tn(e){const t=te??F;t&&(t.style.display=e?"block":"none",e&&It.has(t)&&Wt(t),U&&Ln?.(U,e),pt())}if(He){let g=function(y){j=y,i(N,y==="zoom"),i(w,y==="pan"),ct&&i(ct,y==="select"),s.style.cursor=y==="pan"?"grab":"crosshair"};re=p.createElement("div"),re.dataset.wmapToolbar="single",Object.assign(re.style,{marginLeft:"auto",flexShrink:"0",display:"flex",flexDirection:"row",alignItems:"center",flexWrap:"wrap-reverse",justifyContent:"flex-end",maxWidth:"100%",background:M.menuBg,border:`1px solid ${M.menuBorder}`,borderRadius:ni.control,boxShadow:Zi.panel,pointerEvents:"auto"});const e=ii(p),t=Ji(e),{makeBtn:n,setActive:i,makeSep:o,makeMenuRow:a,makeMenuSection:r,closeOpenMenu:l,getOpenMenu:d,setOpenMenu:f}=t;Ln=i,Ft=l,kn=d,p.addEventListener("click",l,!0),H=p.createElement("div"),Object.assign(H.style,{display:Ae?"none":"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),re.appendChild(H);const v=n("download","Download PNG",Oi);H.appendChild(v),H.appendChild(o());const N=n("zoomMode","Zoom (drag to zoom region)",()=>g("zoom")),ne=n("zoomIn","Zoom in",()=>We(s.clientWidth/2,s.clientHeight/2,1.2)),b=n("zoomOut","Zoom out",()=>We(s.clientWidth/2,s.clientHeight/2,1/1.2)),E=n("reset","Reset zoom (double-click)",()=>ht());H.appendChild(N),H.appendChild(ne),H.appendChild(b),H.appendChild(E),H.appendChild(o());const w=n("pan","Pan (drag to move)",()=>g("pan"));H.appendChild(w),ct=n("boxSelect","Select (drag to select dies)",()=>g("select")),H.appendChild(ct);{const y=n("drilldown","Chart this wafer",()=>{const V=y.getBoundingClientRect();Vn({x:V.left,y:V.bottom+4},y)});y.setAttribute("aria-haspopup","menu"),at=y,Hn(),H.appendChild(y)}g(j);{let y=function(u){return u.plotMode!==(c.plotMode??"hardBin")?!1:u.plotMode==="value"?(c.activeTest??0)===(u.activeTest??0):u.plotMode==="metadata"?c.activeMetadataKey===u.activeMetadataKey:!0},V=function(u,D){u.activeTest!==void 0?R({plotMode:u.plotMode,activeTest:u.activeTest,activeMetadataKey:void 0,logScale:u.logScale}):u.activeMetadataKey!==void 0?R({plotMode:u.plotMode,activeTest:void 0,activeMetadataKey:u.activeMetadataKey,passFailDisplay:"off"}):R({plotMode:u.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),D.remove(),f(null),nt(I,!1)};P=p.createElement("div"),Object.assign(P.style,{display:"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),re.appendChild(P),O=p.createElement("div"),Object.assign(O.style,{display:"flex",alignItems:"center",gap:"0"}),P.appendChild(O),O.appendChild(o());const ce=()=>{const u=d();u&&(u.remove(),f(null)),nt(I,!1)},I=n("mode","Plot mode",()=>{if(d()){ce();return}const u=ve,D=h.testDefs,{testEntries:bt,binEntries:Ee,stackedEntries:Je}=ho(u,D,{includeStacked:h.isLotStack}),Qt=(xe??[]).filter(tt=>mo(u,tt.key)).map(yo),et=eo(I.getBoundingClientRect(),bt,Ee,Je,y,V,{makeMenuRow:a,makeMenuSection:r},c.plotMode??"hardBin",I.ownerDocument.defaultView??window,Qt);si(I).appendChild(et),f(et),nt(I,!0),li(et,I,ce)});nt(I,!1);const{btn:mt,sync:qe}=io(t,()=>({...c,plotMode:c.plotMode??"hardBin"}),()=>Mi,R);Ht=qe,Ht();const Ut=lo(t,()=>{const u=!!h.hasReticle,D=(c.plotMode??"hardBin")==="value",{testNumber:bt}=qt(c.activeTest??0,h.testDefs),Ee=vt(h.testDefs,bt),Je=D&&Ee!==void 0&&!Jt(Ee),Qt=D&&!Je&&(Ee?.limitLow!==void 0||Ee?.limitHigh!==void 0),et=D&&!Je&&h.dies.some(tt=>Gi(tt,bt,Ee)!==void 0);return po(c,u,{functionalActive:Je,hasLimits:Qt,hasRecorded:et,binMode:(c.plotMode??"hardBin")==="hardBin"||(c.plotMode??"hardBin")==="softBin"},tt=>R(tt))},()=>uo(c)),{btn:Zt,sync:Ii}=so(t,()=>c,u=>R({legendPosition:u}));zt=Ii,zt();const qn=()=>{const{testNumber:u}=qt(c.activeTest??0,ee),D=vt(ee,u);return D!==void 0&&!Jt(D)},{btn:Wi,sync:Ai}=oo(t,()=>({...c,functionalActive:qn()}),u=>R(u));Vt=Ai,Vt();const Fi=()=>{const{testNumber:u}=qt(c.activeTest??0,ee),D=vt(ee,u);return D!==void 0&&(D.limitLow!==void 0||D.limitHigh!==void 0)},yt=n("specRange","Colorbar range: test limits",()=>{const u=c.colorbarRangeMode==="data"?"spec":"data";R({colorbarRangeMode:u})});Yt=()=>{const u=c.plotMode==="value"&&Fi()&&fo(c)==="off"&&!qn();yt.style.display=u?"":"none";const D=(c.colorbarRangeMode??"spec")==="spec";i(yt,D),yt.ariaLabel=D?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"},Yt();const zi=ao(t,()=>c,u=>R(u));O.appendChild(I),O.appendChild(mt),O.appendChild(Wi),O.appendChild(yt),Ae||(O.appendChild(o()),O.appendChild(Ut),O.appendChild(o()),O.appendChild(Zt),O.appendChild(o()),O.appendChild(zi)),fe&&(U=n("findings","Summary panel",()=>{const u=te??F;u&&Tn(u.style.display==="none")}),P.appendChild(o()),P.appendChild(U),F?.style.display!=="none"&&i(U,!0),pt()),un&&(ft=o(),de=n("warning","Data warnings",()=>{const u=d();if(l(new MouseEvent("click")),u)return;const D=Mo(de.getBoundingClientRect(),pe,B);si(De).appendChild(D),f(D),li(D,de,()=>l(new MouseEvent("click")))}),nt(de,!1),P.appendChild(ft),P.appendChild(de),At()),Ye&&(P.appendChild(o()),X=n("analysis","Insights",()=>{Ne(!le),i(X,le)}),X.dataset.wmapInsightsBtn="1",P.appendChild(X)),fn&&(P.appendChild(o()),se=n("expand","Expand (E)",cn??Pn),P.appendChild(se)),dn&&(P.appendChild(o()),Dn=n("help","User guide",()=>Gt()),P.appendChild(Dn))}Q.appendChild(re),ze()}let Me=null;function Pn(){Me&&(Me.close(),Me=null);const e=De;e.style.flex="1",e.style.minWidth="0",e.style.minHeight="0";const t=on(_.metadata??{},Xe()),n=Q.childElementCount>0?[Q,e]:[e],i=to(n,{ownerDocument:p,boxSize:le?{width:"min(96vw, 1600px)",height:"min(92vh, 1000px)"}:void 0,onClosed:()=>{Me=null,se&&(se.style.display="flex"),le||s.focus({preventScroll:!0})}});i&&(i.box.setAttribute("aria-label",t??"Expanded wafer map"),n.length>1&&(i.contentWrap.style.flexDirection="column"),Me=i,se&&(se.style.display="none"))}function On(e){("binColorScheme"in e||"useDefinedBinColors"in e)&&!("binColors"in e)&&c.binColors!==void 0&&(e={...e,binColors:void 0});const t=c.plotMode;c={...c,...e},e.plotMode!==void 0&&e.plotMode,Object.keys(e).every(a=>a==="legendPosition"||a==="showLegend"||a==="markFailingDies")||Rt(),zt?.(),Ht?.(),Vt?.(),Yt?.(),C();const i=e.plotMode!==void 0&&e.plotMode!==t,o=COLOR_KEYS.some(a=>a in e);(o||i)&&(ge(),Ue()),(o||i||e.activeTest!==void 0||e.logScale!==void 0||e.colorbarRangeMode!==void 0)&&it?.()}function R(e){On(e);const t=Object.keys(e);ui?.(c,t,classifyChanged(t))}let Xt=!1;const Nt=S.drawWhenVisible&&B.IntersectionObserver?new B.IntersectionObserver(e=>{Ie=e[e.length-1].isIntersecting,Ie&&ut&&C()},{rootMargin:"25%"}):null;let Ie=Nt===null,ut=!1;Nt?.observe(s);function jt(){Xt||(Xt=!0,en(()=>{Xt=!1,C()},B))}function C(){if(!Ie){ut=!0;return}ut=!1;const e=T??void 0,t=h.dies[0],n=t?{x:t.width,y:t.height}:ke.diePitchMm,i=Math.floor(s.clientWidth||s.width),o=!!(q?.length||J?.length||h.dies.some(v=>v.hbin!=null||v.sbin!=null)),a=c.legendPosition??"default",r=c.showLegend??!0,l=a==="default"||a==="compact",d=(ke.colorbarWidth??16)+28,f=o&&l?a!=="default"?Math.max(Jn,d):i<_i?0:i<ji?Math.max(Ni,d):Math.max(Jn,d):void 0,g=Xi(s,h,{...ke,minRightReserve:r?f:0,showColorbar:r&&(ke.showColorbar??!0),markFailingDies:c.markFailingDies??!1,legendPosition:a,legendOffset:Pt,diePitchMm:n,fallbackFormat:c.fallbackFormat,showAxes:ke.showAxes??T!==null,viewport:e,activeBin:c.plotMode==="metadata"?c.highlightMetadataValue:c.highlightBin,hoverBin:Tt,afterDies:x.size>0?Li:void 0,hbinDefs:q,sbinDefs:J,metadataFields:xe});Lt=g.binLegendRows,we=g.legendBox??null,T===null&&(G=g.viewport),Le&&Pi(),Hn()}function Li(e,t,n){const i=h.hoverPoints,o=h.rectangles[0],a=o?o.width/2*t.ppm:t.ppm*.5,r=o?o.height/2*t.ppm:t.ppm*.5,l=new Set;x.size>0&&(je??=new Map(h.dies.map((b,E)=>[he(b),E])));for(const b of x){const E=je.get(b);E!==void 0&&l.add(E)}if(!l.size)return;e.save(),e.setLineDash([]),e.fillStyle=n.background,e.globalAlpha=.7;let d=0;e.beginPath();for(let b=0;b<i.length;b++)l.has(b)||(e.rect(t.originX+i[b].x*t.ppm-a,t.originY-i[b].y*t.ppm-r,a*2,r*2),++d===Ki&&(e.fill(),e.beginPath(),d=0));d&&e.fill(),e.globalAlpha=1;const{cw:f,ch:g}=Ti(t,a,r),v=new Map,N=b=>Math.round(b*100),ne=(b,E,w,y)=>{const V=`${N(b)},${N(E)},${N(w)},${N(y)}`;v.has(V)?v.delete(V):v.set(V,[b,E,w,y])};for(const b of l){const E=t.originX+i[b].x*t.ppm,w=t.originY-i[b].y*t.ppm,y=E-f,V=E+f,ce=w-g,I=w+g;ne(y,ce,V,ce),ne(y,I,V,I),ne(y,ce,y,I),ne(V,ce,V,I)}e.strokeStyle=n.text,e.lineWidth=2,e.lineCap="square",e.beginPath();for(const[b,E,w,y]of v.values())e.moveTo(b,E),e.lineTo(w,y);e.stroke(),e.restore()}function Ti(e,t,n){const i=h.hoverPoints,o=h.dies;let a=0,r=0;for(let l=0;l<o.length&&(!a||!r);l++){const d=o[l];if(!(d.x==null||d.y==null))for(const f of[je.get(`${d.x+1},${d.y}`),je.get(`${d.x},${d.y+1}`)]){if(f===void 0)continue;const g=Math.abs(i[f].x-i[l].x)*e.ppm,v=Math.abs(i[f].y-i[l].y)*e.ppm;g>v?a||=g/2:r||=v/2}}return{cw:a||t,ch:r||n}}function Pi(){const e=s.getContext("2d"),t=Math.min(W.x,A.x),n=Math.min(W.y,A.y),i=Math.abs(A.x-W.x),o=Math.abs(A.y-W.y);e.save(),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(t,n,i,o),e.setLineDash([5,3]),e.strokeStyle="rgba(255,255,255,0.9)",e.lineWidth=3,e.strokeRect(t,n,i,o),e.strokeStyle="rgba(0,0,0,0.9)",e.lineWidth=1.5,e.strokeRect(t,n,i,o),e.restore()}function Rn(){if(!ut)return;const e=Ie;Ie=!0,C(),Ie=e}function Oi(){Rn(),s.toBlob(e=>{e&&ro(e,an(),me.onSaveImage)})}function In(e){return G?Math.max(G.ppm*bi,Math.min(G.ppm*vi,e)):e}function We(e,t,n){const i=T??G;if(!i)return;const o=In(i.ppm*n),a=o/i.ppm,r=e-(e-i.originX)*a,l=t-(t-i.originY)*a,d=(G?.snapDist??1)/(o/(G?.ppm??o));T={originX:r,originY:l,ppm:o,snapDist:d},C()}function Z(){return T??G}function Wn(e){if(e.ctrlKey||e.metaKey){e.preventDefault();const t=s.getBoundingClientRect(),n=e.deltaY<0?1.12:1/1.12;We(e.clientX-t.left,e.clientY-t.top,n)}else if(T!==null){e.preventDefault();const t=Z(),n=T.snapDist;T={originX:t.originX-e.deltaX,originY:t.originY-e.deltaY,ppm:t.ppm,snapDist:n},C()}}function _t(e,t,n){return e>=n.x&&e<n.x+n.w&&t>=n.y&&t<n.y+n.h}function An(e){if(rt=!1,e.button!==0||!Z())return;s.focus({preventScroll:!0}),s.setPointerCapture(e.pointerId);const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;if(we&&c.legendPosition==="floating"&&_t(n,i,we)){Be=!0,Ke={x:n,y:i},Ot={...Pt};return}if($e&&j!=="pan"){Pe=!0,Ce=!0,Te={x:n,y:i},dt={x:Z().originX,y:Z().originY},s.style.cursor="grabbing";return}if(j==="zoom"||j==="select"){Le=!0,W=A={x:n,y:i};return}Ce=!0,Te={x:n,y:i},dt={x:Z().originX,y:Z().originY},s.style.cursor="grabbing"}function Fn(e){const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;if(Le){A={x:n,y:i},jt();return}if(Be){const g=n-Ke.x,v=i-Ke.y;g*g+v*v>16&&(Be=!1,_e=!0,s.style.cursor="grabbing")}if(_e){Pt={x:Ot.x+(n-Ke.x),y:Ot.y+(i-Ke.y)},jt();return}if(Ce){const g=Z(),v=T?.snapDist??G?.snapDist??1;T={originX:dt.x+(n-Te.x),originY:dt.y+(i-Te.y),ppm:g.ppm,snapDist:v},jt();return}const o=Z();if(!o)return;const a=(n-o.originX)/o.ppm,r=(o.originY-i)/o.ppm,d=$t(a,r,o.snapDist)?.die??null,f=Lt.find(g=>n>=g.x&&n<g.x+g.w&&i>=g.y&&i<g.y+g.h);if(Mn(f?f.bin:void 0),f){s.style.cursor="pointer",z&&(z.textContent=f.label??`Bin ${f.bin}`,z.style.display="block",oi(z,s,e.clientX,e.clientY,{followPointer:!0})),ot?.(null,e);return}j==="pan"&&(s.style.cursor=d?"crosshair":"grab"),z&&(d?(z.innerHTML=Vi(d,h.plotMode,{testDefs:ee,hbinDefs:q,sbinDefs:J,fallbackFormat:c.fallbackFormat,aggrMethod:h.aggrMethod,lotSize:h.lotSize,metadataFields:xe,activeTest:h.activeTest,reticleConfig:vn}),z.style.display="block",oi(z,s,e.clientX,e.clientY,{followPointer:!0})):z.style.display="none"),ot?.(d,e)}function zn(e){const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top,o=e.ctrlKey||e.metaKey;if(z&&(n<0||i<0||n>t.width||i>t.height)&&(z.style.display="none"),Le){Le=!1,A={x:n,y:i};const l=n-W.x,d=i-W.y,f=Z();if(j==="zoom"){if(l*l+d*d<25)We(n,i,2);else if(f){const g=Math.min(W.x,A.x),v=Math.max(W.x,A.x),N=Math.min(W.y,A.y),ne=Math.max(W.y,A.y),b=v-g,E=ne-N;if(b>4&&E>4){const w=s.clientWidth,y=s.clientHeight,V=w/b,ce=y/E,I=Math.min(V,ce),mt=In(f.ppm*I),qe=mt/f.ppm,Ut=(g+v)/2,Zt=(N+ne)/2;T={originX:w/2-(Ut-f.originX)*qe,originY:y/2-(Zt-f.originY)*qe,ppm:mt,snapDist:f.snapDist/qe}}}C(),s.style.cursor="crosshair";return}if(l*l+d*d<25)Kt(n,i,o,e);else if(f){const g=(Math.min(W.x,A.x)-f.originX)/f.ppm,v=(Math.max(W.x,A.x)-f.originX)/f.ppm,N=(f.originY-Math.max(W.y,A.y))/f.ppm,ne=(f.originY-Math.min(W.y,A.y))/f.ppm,b=h.hoverPoints,E=[];for(let w=0;w<b.length;w++)if(b[w].x>=g&&b[w].x<=v&&b[w].y>=N&&b[w].y<=ne){const y=h.dies[w];y&&E.push(y)}if(o)for(const w of E){const y=he(w);x.has(y)?x.delete(y):x.add(y)}else x=new Set(E.map(w=>he(w)));Se(),ae?.(Ze())}C(),s.style.cursor="crosshair";return}if(Be){Be=!1,Kt(n,i,o,e);return}if(_e){_e=!1,s.style.cursor="grab";return}if(!Ce)return;if(Ce=!1,Pe){Pe=!1,s.style.cursor=$e||j==="pan"?"grab":"crosshair";return}s.style.cursor=j==="pan"?"grab":"crosshair";const a=n-Te.x,r=i-Te.y;a*a+r*r<25&&Kt(n,i,o,e)}function Kt(e,t,n,i){for(const l of Lt)if(e>=l.x&&e<l.x+l.w&&t>=l.y&&t<l.y+l.h){Se("legend"),typeof l.bin=="number"?R({highlightBin:di(c.highlightBin,l.bin,n)}):R({highlightMetadataValue:di(c.highlightMetadataValue,l.bin,n)});return}if(we&&_t(e,t,we))return;const o=Z();if(!o)return;const r=$t((e-o.originX)/o.ppm,(o.originY-t)/o.ppm,o.snapDist)?.die??null;if(r){pi?.(r,i);const l=he(r);n?x.has(l)?x.delete(l):x.add(l):x.size===1&&x.has(l)?x=new Set:x=new Set([l]),Se(),ae?.(Ze()),C()}else n||(x=new Set,Se(),ae?.([]),C())}function Ze(){const e=[],t=h.hoverPoints;for(let n=0;n<t.length;n++){const i=h.dies[n];i&&x.has(he(i))&&e.push(i)}return e}function Hn(){at&&(at.style.display=Mt()?"flex":"none",at.ariaLabel=x.size>0?"Chart the selected dies (or right-click)":"Chart this wafer (or right-click)")}function Ri(){const e={waferLabel:ln(),testDefs:ee,isLotStack:ie.isLotStack,activeTest:c.plotMode==="value"?c.activeTest:void 0};return x.size>0?ko(Ze(),e):Bo(ve,e)}function Vn(e,t){if(!Mt())return;const n=Ri();import("./drilldown.js").then(({openDrilldownMenu:i})=>{yn||(mn=i(e,t,n,wi))})}function Yn(e){e.stopPropagation();const t=rt;if(rt=!1,!Mt()||le)return;const n=s.getBoundingClientRect();if(!t){const o=e.clientX-n.left,a=e.clientY-n.top;if(we&&_t(o,a,we))return;const r=Z(),l=r?$t((o-r.originX)/r.ppm,(r.originY-a)/r.ppm,r.snapDist)?.die:void 0;l&&!x.has(he(l))&&(x=new Set([he(l)]),Se(),ae?.(Ze()),C())}e.preventDefault();const i=t?{x:n.left+n.width/2,y:n.top+n.height/2}:{x:e.clientX,y:e.clientY};Vn(i,s)}function Xn(){Mn(void 0),z&&wt(p),ot?.(null,new MouseEvent("mouseleave")),s.style.cursor=j==="pan"?"grab":"crosshair"}function Nn(){Ce=!1,Pe=!1,Le=!1,Be=!1,_e=!1,z&&wt(p),ot?.(null,new MouseEvent("mouseleave")),s.style.cursor=j==="pan"?"grab":"crosshair",C()}function $t(e,t,n){const i=h.hoverPoints,o=h.rectangles;for(let d=0;d<o.length;d++){const f=o[d];if(Math.abs(e-f.x)<=f.width/2&&Math.abs(t-f.y)<=f.height/2){const g=h.dies[d];return g?{die:g,index:d}:null}}let a=null,r=-1,l=n*n;for(let d=0;d<i.length;d++){const f=i[d].x-e,g=i[d].y-t,v=f*f+g*g;v<l&&(l=v,a=h.dies[d]??null,r=d)}return a?{die:a,index:r}:null}const jn=new B.ResizeObserver(()=>{G=null,T=null,C()});jn.observe(s),S.height==null&&fi<=0&&en(()=>en(()=>{L.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 Qe=B.matchMedia(`(resolution: ${B.devicePixelRatio}dppx)`);const gt=()=>{Qe.removeEventListener("change",gt),Qe=B.matchMedia(`(resolution: ${B.devicePixelRatio}dppx)`),Qe.addEventListener("change",gt),C()};Qe.addEventListener("change",gt);const _n=B.matchMedia("(prefers-color-scheme: dark)"),Kn=()=>C();_n.addEventListener("change",Kn);const $n=()=>{z&&wt(p)};B.addEventListener("blur",$n);function Gn(e){if((e.key==="ContextMenu"||e.shiftKey&&e.key==="F10")&&(rt=!0),e.key==="Escape"&&x.size>0&&(x=new Set,Se(),ae?.([]),C()),(e.key==="e"||e.key==="E")&&fn&&(e.stopPropagation(),(cn??Pn)()),(e.ctrlKey||e.metaKey)&&(e.key==="="||e.key==="+"?(e.preventDefault(),We(s.clientWidth/2,s.clientHeight/2,1.2)):e.key==="-"?(e.preventDefault(),We(s.clientWidth/2,s.clientHeight/2,1/1.2)):e.key==="0"&&(e.preventDefault(),ht())),!e.ctrlKey&&!e.metaKey&&!e.shiftKey){const n=Z();if(n){const i=T?.snapDist??G?.snapDist??1;let o=0,a=0;e.key==="ArrowLeft"&&(o=20,e.preventDefault()),e.key==="ArrowRight"&&(o=-20,e.preventDefault()),e.key==="ArrowUp"&&(a=20,e.preventDefault()),e.key==="ArrowDown"&&(a=-20,e.preventDefault()),(o||a)&&(T={originX:n.originX+o,originY:n.originY+a,ppm:n.ppm,snapDist:i},C())}e.key===" "&&!$e&&(e.preventDefault(),$e=!0,j!=="pan"&&(s.style.cursor="grab"))}}function Un(e){e.key===" "&&($e=!1,Pe&&(Ce=!1,Pe=!1),s.style.cursor=j==="pan"?"grab":"crosshair")}s.style.cursor="crosshair",s.setAttribute("tabindex","0"),s.addEventListener("wheel",Wn,{passive:!1}),s.addEventListener("pointerdown",An),s.addEventListener("pointermove",Fn),s.addEventListener("pointerup",zn),s.addEventListener("pointerleave",Xn),s.addEventListener("pointercancel",Nn);const Zn=()=>ht();s.addEventListener("dblclick",Zn),s.addEventListener("keydown",Gn),s.addEventListener("keyup",Un),s.addEventListener("contextmenu",Yn);const Qn=e=>{e.stopPropagation()};s.addEventListener("click",Qn),s.clientWidth,C(),it?.();function ht(){G=null,T=null,C()}function Gt(){import("./userGuideHtml.js").then(e=>no({buildWaferMap:$i,renderWaferMap,renderWaferGallery:void 0,analyzeWaferMap:Ui},e.USER_GUIDE_HTML,hi,L))}return ze(),{setResult(e){ie=e,_=e.wafer,ve=e.dies,q=e.hbinDefs,J=e.sbinDefs,ee=e.testDefs,xe=e.metadataFields,bn=e.reticles?.length?e.reticles:void 0,vn=e.reticleConfig,xn=e.dataAxisFlip,Et=e.isLotStack,Dt=e.aggrMethod,kt=e.lotSize,Si(),Rt(),C(),te&&ge()},setOptions(e){On(e)},getOptions(){return{...c}},resetZoom:ht,setSelection(e){x=new Set(e.map(t=>he(t))),C()},clearSelection(){x=new Set,Se(),ae?.([]),C()},setFindingsNotice(e){En=e,te?ge():F&&Ue()},setStatsSummary(e){if(fe=e,St(),At(),te)ge();else if(F)Ue();else if(e&&!Ve?.placement){const t=Ve?.defaultOpen??!He;F=tn("right",ye,p),F.style.display=t?"block":"none";const n=k.parentElement,i=k.nextSibling;ue=nn(k,F,"right"),n?.insertBefore(ue,i),Ue()}pt()},closeSummaryPanel(){Tn(!1)},getExportTitle(){return an()},getSaveImageHook(){return me.onSaveImage},drawPendingNow:Rn,getBinColors(){return h.binColors},setSummaryVisible(e){U&&(U.style.display=e?"flex":"none")},setViewControlsVisible(e){P&&(P.style.display=e?"flex":"none")},setExpandVisible(e){se&&(se.style.display=e?"flex":"none")},openUserGuide:Gt,setInsightsOpen(e){Ne(e),X&&(e?(X.dataset.active="1",X.style.background=M.bgActive,X.style.color=M.iconActive):(delete X.dataset.active,X.style.background="transparent",X.style.color=M.icon))},destroy(){yn=!0;for(const e of Ge.values())e.cancel();Ge.clear(),Me?.close(),kn?.()?.remove(),Ft&&p.removeEventListener("click",Ft,!0),s.removeEventListener("wheel",Wn),s.removeEventListener("pointerdown",An),s.removeEventListener("pointermove",Fn),s.removeEventListener("pointerup",zn),s.removeEventListener("pointerleave",Xn),s.removeEventListener("pointercancel",Nn),s.removeEventListener("dblclick",Zn),s.removeEventListener("keydown",Gn),s.removeEventListener("keyup",Un),s.removeEventListener("contextmenu",Yn),mn?.(),s.removeEventListener("click",Qn),jn.disconnect(),Nt?.disconnect(),Qe.removeEventListener("change",gt),_n.removeEventListener("change",Kn),B.removeEventListener("blur",$n),xi(),z&&wt(p),re?.remove(),Oe&&(Oe.parentElement?.insertBefore(k,Oe),Oe.remove()),ue&&(ue.parentElement?.insertBefore(k,ue),ue.remove()),k.remove(),s.style.cursor="",$?.destroy(),K?.destroy(),Fe.remove()}}}
|
|
1
|
+
import{buildView as Xi,buildHoverText as Ni,findTestDef as Ct,resolveTestNumber as tn,buildMapTitle as _i}from"../renderer/buildView.js";import{drawMapCanvas as ji,BIN_LEGEND_W as ti,BIN_LEGEND_W_COMPACT as Ki,BIN_LEGEND_ADAPT_COMPACT as $i,BIN_LEGEND_ADAPT_FLOATING as Gi,PATH_SHAPES as Ui}from"./toCanvas.js";import{buildWaferMap as Zi,getTestPassStatus as Qi,isParametricTest as nn}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as qi}from"../stats/analyzeWaferMap.js";import{SHADOW as Ji,LEADING as ni,wireControlHover as ii,SPACE as Y,EDGE_GUTTER as eo,RADIUS as oi,FONT as St,CLR as E,applyOverlayZ as to,getTooltip as si,hideTooltip as Mt,positionTooltip as li,createToolbarHelpers as no,buildModeMenuEl as io,openReparentedModal as oo,openUserGuideWindow as so,makePaletteBtn as lo,makeLogScaleBtn as ao,makeLegendStyleBtn as ro,makeOverlaysBtn as co,makeOrientationBtn as fo,menuLayerFor as ai,saveImageBlob as po,markMenuTrigger as nt,wireMenuA11y as ri,wireExpandToggle as uo,nextFrame as on,requestedPassFailDisplay as go,overlayMenuRows as ho,anyOverlayActive as mo,openCompactDiagnostics as yo,roomForPanel as bo,logWmapVersionOnce as vo,buildDataModeEntries as xo,metadataKeyHasData as wo,metadataModeEntry as Co}from"./toolbar.js";import{waferIdentityLabel as So}from"../core/waferLabel.js";import{metadataDisplayValue as Mo}from"../core/metadata.js";import{withExportContext as Eo}from"./exportName.js";import{createSummaryPanelEl as sn,wrapWithSummaryPanel as ln,renderWaferSummaryContentSteps as Do}from"./summaryPanel.js";import{runChunked as Bo}from"./chunked.js";import{collectWarnings as ko,buildWarningsMenuEl as Lo,severityOf as To}from"./warnings.js";import{ICONS as di}from"./icons.js";import{hasDrilldownTargets as Po,selectionPopulation as Oo,waferPopulation as Ro}from"./chartPopulation.js";import{createIdentityHeader as Io,collapsedLabel as an}from"./identityHeader.js";import{getDieKey as ye,hasPosition as ci,isPositionedDie as Ao}from"../core/dies.js";import{buildDieListSection as Wo}from"./dieList.js";import{buildMaplessSummary as Fo}from"./maplessSummary.js";import{resolveBinColors as zo,binColorWarning as Ho}from"../renderer/binColors.js";import{INPUT_DEFAULT_PASS_BINS as Vo}from"../core/passBins.js";import{toggleHighlight as fi}from"../core/utils.js";import{buildCompactMap as Yo,compactLayoutOffered as Xo}from"../core/compact.js";const pi=new Set(["binColorScheme","valueColorScheme","reverseValueScheme","useDefinedBinColors","rotation","flipX","flipY","showDieLabels","showRingBoundaries","showQuadrantBoundaries","showReticle","showXYIndicator","compact","showAxes","legendPosition","logScale","colorbarRangeMode","markFailingDies","fallbackFormat"]);export const COLOR_KEYS=["binColorScheme","valueColorScheme","reverseValueScheme","useDefinedBinColors","binColors"];export function classifyChanged(k){const m=k.some(p=>pi.has(p)),S=k.some(p=>!pi.has(p));return m&&S?"mixed":m?"preference":"state"}export function findingBin(k){const{kind:m,bin:S}=k.variable;return m==="hardBin"||m==="softBin"?S:void 0}export function toPublicViewOptions(k){const{metadataValueOrder:m,binColors:S,lotSize:p,compactMap:L,...it}=k;return it}export function renderWaferMap(k,m,S={}){return renderWaferMapCard(k,m,S)}export function renderWaferMapCard(k,m,S={}){vo();const p=k.ownerDocument,L=p.defaultView??window,it=()=>ie.label,rn=()=>So({label:it(),wafer:K}),ue=Eo(()=>{const e=Mo(K.metadata?.lot);return{prefix:S.downloadFilename,lots:e!==void 0?[e]:[],...ie.isLotStack?{stackedWafers:h?.lotSize??!0}:{wafer:rn()}}},S.onSaveImage,S.onSaveText);function dn(){const e=h.plotMode==="softBin"||h.plotMode==="stackedSoftBins"?ee:J,{primary:t,secondary:n}=_i(h,d.fallbackFormat,e);return[t,ie.isLotStack?"":n].filter(Boolean).join(" ")||"wafer-map"}L.getComputedStyle(k).position==="static"&&(k.style.position="relative");const ui=k.clientHeight;S.height!=null&&(k.style.height=typeof S.height=="number"?`${S.height}px`:S.height);const Et=m.dataCoverage?m.dataCoverage.unpositionedDies:m.dies.filter(e=>!ci(e)).length,Fe=(m.dataCoverage?m.dataCoverage.totalDies:m.dies.length-Et)===0&&Et>0,ze=p.createElement("div");Object.assign(ze.style,{display:"flex",flexDirection:"column",width:"100%",height:"100%"}),k.appendChild(ze);const ke=p.createElement("div");Object.assign(ke.style,{position:"relative",width:"100%",flex:"1 1 auto",minHeight:"0"});const be=S.chromeInset??eo,q=p.createElement("div");Object.assign(q.style,{display:"flex",alignItems:"stretch",gap:Y.sm,background:E.canvasBg,paddingBottom:Y.lg,paddingTop:be,paddingLeft:be,paddingRight:be,flexShrink:"0",minWidth:"0"}),ze.appendChild(q),ze.appendChild(ke);function He(){const e=[...q.children].some(t=>t.style.display!=="none");q.style.display=e?"flex":"none"}const M=p.createElement("div");Object.assign(M.style,{position:"relative",width:"100%",height:"100%"});const s=p.createElement("canvas");Object.assign(s.style,{width:"100%",height:"100%",display:"block"}),M.appendChild(s),ke.appendChild(M);let ot=null;if(Et>0){let n=function(){if(t){const r=Wo(e,m.testDefs,{...S.dieList,onSaveText:ue.onSaveText,waferMetadata:K.metadata,metadataFields:xe,ownerDocument:p});if(r)return r}const o=Ct(m.testDefs,d.activeTest??0),l=nn(o)?d.logScale??o?.logScale??!1:!1;return Fo(e,m.testDefs,{plotMode:d.plotMode??"hardBin",activeTest:d.activeTest,hbinDefs:J,sbinDefs:ee,binColors:h.binColors,valueColorScheme:d.valueColorScheme,reverseValueScheme:d.reverseValueScheme,logScale:l,colorbarRangeMode:d.colorbarRangeMode,valueRangeDies:m.dies})},i=function(o){const l=p.createElement("button");return l.type="button",ii(l),Object.assign(l.style,{fontSize:St.body,padding:`${Y.xxs} ${Y.sm}`,borderRadius:oi.control,flexShrink:"0",border:`1px solid ${E.menuBorder}`,background:E.menuBg,color:E.text,cursor:"pointer"}),l.textContent=t?"View chart":"View die list",l.addEventListener("click",r=>{r.stopPropagation(),t=!t,l.textContent=t?"View chart":"View die list",o()}),l};const e=m.dies.filter(o=>!ci(o));let t=!1;if(Fe){const o=p.createElement("div");Object.assign(o.style,{position:"absolute",inset:"0",background:E.panelBg,padding:Y.xl,boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",gap:Y.md,zIndex:"1"});const l=p.createElement("div");Object.assign(l.style,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:Y.md});const r=p.createElement("span");Object.assign(r.style,{fontSize:St.body,color:E.label,lineHeight:ni.base}),r.textContent="No die position data for this wafer.",l.appendChild(r);const a=p.createElement("div");Object.assign(a.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),l.appendChild(i(()=>a.replaceChildren(n()))),o.appendChild(l),o.appendChild(a),M.appendChild(o),ot=()=>{t||a.replaceChildren(n())}}else{const o=p.createElement("div");Object.assign(o.style,{position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"3",background:E.panelBg,borderTop:`1px solid ${E.menuBorder}`,fontSize:St.body,color:E.text,cursor:"pointer",padding:`${Y.xs} ${Y.md}`,display:"flex",alignItems:"center",justifyContent:"space-between",gap:Y.md}),ii(o,"bare");const l=p.createElement("span");l.textContent=`+${e.length} ${e.length===1?"die":"dies"} without position data`,o.appendChild(l);const r=p.createElement("span");r.textContent="\u25BE",Object.assign(r.style,{fontSize:St.body,lineHeight:ni.none,color:E.label,flexShrink:"0"}),o.appendChild(r),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`${e.length} dies without position data. Click to view.`);let a=null,c=null;uo(o,f=>{if(r.textContent=f?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(f)),f){a=p.createElement("div");const g=o.getBoundingClientRect().height||28;Object.assign(a.style,{position:"absolute",left:"0",right:"0",bottom:`${g}px`,top:"20%",zIndex:"2",background:E.panelBg,borderTop:`1px solid ${E.menuBorder}`,padding:Y.md,boxSizing:"border-box",display:"flex",flexDirection:"column",gap:Y.md}),a.addEventListener("click",N=>N.stopPropagation());const v=p.createElement("div");Object.assign(v.style,{display:"flex",justifyContent:"flex-end"}),v.appendChild(i(()=>{c&&c.replaceChildren(n())})),a.appendChild(v),c=p.createElement("div"),Object.assign(c.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),c.appendChild(n()),a.appendChild(c),M.appendChild(a)}else a&&(a.remove(),a=null,c=null)}),M.appendChild(o),ot=()=>{c&&!t&&c.replaceChildren(n())}}}const{onHover:st,onClick:gi,onSelect:ae,onViewOptionsChange:hi,showTooltip:mi=!0,showToolbar:Ve=!0,showIdentity:cn=!0,summaryPanel:Ye,showHelpButton:fn=!1,userGuideExtension:yi,onExpand:pn,showExpandButton:un=!0,zIndex:bi,insights:ve,warnings:gn,viewOptions:vi={},...Le}=S,Xe=ve?.enabled??!1,xi=.4,wi=20,lt=[...m.passBins??Vo],hn=gn?.display??!0,Ci=to(bi);let ge=S.statsSummary,he=[],mn=!1,at=null,yn=!1;function Dt(){const e=ko({result:m,statsSummary:ge,extra:at?[at]:[]}),t=e.length!==he.length||e.some((n,i)=>n.code!==he[i]?.code||n.message!==he[i]?.message);he=e,(t||!mn)&&(mn=!0,gn?.onWarning?.(e))}Dt();let ie=m,K=m.wafer,re=m.dies,x=new Set;const Si={sweeps:ve?.sweeps,onSaveImage:ue.onSaveImage},Bt=()=>!Fe&&Po(te,ve?.sweeps);let bn=null,rt=null,dt=!1,vn=!1,J=m.hbinDefs,ee=m.sbinDefs,te=m.testDefs,xe=m.metadataFields,xn=m.reticles?.length?m.reticles:void 0,ct=m.reticleConfig,wn=m.dataAxisFlip,kt=m.isLotStack??!1,Lt=m.aggrMethod,Tt=m.lotSize;const Mi=Ve&&Xe;let $=null,oe=null,se=null;cn&&($=Io(an(K.metadata??{},Ne())??"",K.metadata,{lotStack:Ne(),ownerDocument:p}),M.appendChild($.metaPanel),$.metaPanel.style.visibility="visible",$.isEmpty()||(oe=Cn($.wrap),q.insertBefore(oe,q.firstChild),He()));function Cn(e){const t=p.createElement("div");return Object.assign(t.style,{display:"flex",alignItems:"center",padding:`${Y.sm} ${Y.lg}`,flex:"1 1 auto",minWidth:"0",overflow:"hidden",gap:Y.sm}),Object.assign(e.style,{flex:"1",minWidth:"0"}),t.appendChild(e),t}function Ne(){return kt?{lotSize:Tt??1,aggrMethod:Lt}:void 0}function Ei(){if(!$)return;$.update(an(K.metadata??{},Ne())??"",K.metadata,Ne());const e=oe?.isConnected??!1,t=!$.isEmpty();!t&&e?(oe.remove(),oe=null):t&&!e&&(oe=Cn($.wrap),oe.style.display="",q.insertBefore(oe,q.firstChild),He())}const Di=[...J??[],...ee??[]].some(e=>e.color);let d={plotMode:"hardBin",showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,showReticle:!1,showXYIndicator:!1,compact:!1,rotation:0,flipX:!1,flipY:!1,legendPosition:"default",...vi},G=null,le=!1,Sn=null;function Bi(){return Xe?G?Promise.resolve(G):(Sn??=import("./insightsTab.js").then(({createInsightsTab:e})=>(G=e({getItems:()=>[{wafer:K,dies:re,hbinDefs:J,sbinDefs:ee,testDefs:te,label:it(),passBins:lt,statsSummary:ge}],getBinColors:()=>h.binColors,getRingCount:()=>ie.ringCount??4,onSaveImage:ue.onSaveImage,onSaveText:ue.onSaveText,defaultView:ve?.defaultView,sweeps:ve?.sweeps,onRemoveSweeps:ve?.onRemoveSweeps,showMetadataStrip:!1,contentInset:be,backTab:Mi?void 0:{label:"Map",onBack:()=>_e(!1)},onOpenGuide:fn&&!Ve?()=>Qt():void 0,focusTest:t=>{P({plotMode:"value",activeTest:t,highlightBin:void 0}),_e(!1)},ownerDocument:p}),Object.assign(G.el.style,{position:"absolute",inset:"0",background:E.canvasBg,overflowY:"auto",paddingTop:"0"}),G.el.style.display="none",ke.appendChild(G.el),G)),Sn):Promise.resolve(null)}let Mn=0;const Pt=["wheel","touchstart","pointerdown","keydown"];function ki(e,t){if(t<=0)return;let n=!1;const i=[],o=()=>{n=!0;for(const r of i)L.clearTimeout(r);i.length=0;for(const r of Pt)e.removeEventListener(r,o)},l=()=>n||!le?!0:(e.scrollTop=t,e.scrollTop>=t);if(!l()){for(const r of Pt)e.addEventListener(r,o,{passive:!0,once:!0});for(const r of[0,50,150,300,600])i.push(L.setTimeout(()=>{l()},r));i.push(L.setTimeout(()=>{for(const r of Pt)e.removeEventListener(r,o)},700))}}function _e(e){if(!Xe)return;const t=le;le=e,G&&!e&&t&&(Mn=G.el.scrollTop),G&&(G.el.style.display=e?"flex":"none"),M.style.visibility=e?"hidden":"",H&&(H.style.display=e||Fe?"none":"flex"),I&&(I.style.display=e?"none":"flex"),se&&(se.style.display=Ee?"none":"flex"),ce&&(ce.style.display="flex"),oe&&(oe.style.display=""),He(),$&&e&&$.collapse(),gt(),X&&(X.innerHTML=e?di.wafer:di.analysis,X.ariaLabel=e?"Back to wafer view":"Insights"),e&&Bi().then(n=>{!n||!le||(n.el.style.display="flex",n.render(),ki(n.el,Mn))})}Xe&&ve?.defaultOpen&&queueMicrotask(()=>_e(!0));let h,je,_=null,T=null,Ot=[],Rt;function En(e){Rt!==e&&(Rt=e,C())}let we=null,It=Le.legendOffset??{x:0,y:0},Ke=!1,Te=!1,$e={x:0,y:0},At={x:0,y:0},Ce=!1,Pe=!1,j="select",Oe={x:0,y:0},ft={x:0,y:0},W={x:0,y:0},F={x:0,y:0},Ge=!1,Re=!1;function Wt(){const e=d,t=re.filter(Ao);h=Xi(K,t,{compact:d.compact?d.compactMap??Yo(t):void 0,plotMode:e.plotMode,binColorScheme:e.binColorScheme,valueColorScheme:e.valueColorScheme,reverseValueScheme:e.reverseValueScheme,useDefinedBinColors:e.useDefinedBinColors,binColors:e.binColors??zo(re,{passBins:lt,binColorScheme:e.binColorScheme,hbinDefs:J,sbinDefs:ee,useDefinedBinColors:e.useDefinedBinColors}),passBins:lt,showDieLabels:e.showDieLabels,showRingBoundaries:e.showRingBoundaries,showQuadrantBoundaries:e.showQuadrantBoundaries,showReticle:e.showReticle,showXYIndicator:e.showXYIndicator,reticles:xn,ringCount:ie.ringCount??4,highlightBin:e.highlightBin,highlightMetadataValue:e.highlightMetadataValue,activeTest:e.activeTest,activeMetadataKey:e.activeMetadataKey,testDefs:te,valueRange:e.valueRange,metadataValueOrder:e.metadataValueOrder,logScale:e.logScale,isLotStack:kt,aggregationMethod:Lt??e.aggregationMethod,lotSize:Tt??e.lotSize,dataAxisFlip:wn,colorbarRangeMode:e.colorbarRangeMode,passFailDisplay:e.passFailDisplay,fallbackFormat:e.fallbackFormat,interactiveTransform:{rotation:e.rotation??0,flipX:e.flipX??!1,flipY:e.flipY??!1}},{hbinDefs:J,sbinDefs:ee,metadataFields:xe}),je=void 0;const n=e.binColors?null:Ho(h.binColors,h.plotMode);n?.message!==at?.message&&(at=n,Dt(),yn&&Ht())}Wt();function Dn(){return d.showAxes??Le.showAxes??T!==null}function Li(){return Xo(re,[ct])}let U=null,Se=null,Ie=null,Bn=S.findingsNotice,Ti={},O=null,de=null;function Pi(e){const{kind:t,index:n}=e.variable;P(t==="test"?{plotMode:"value",activeTest:n??0,highlightBin:void 0}:{plotMode:t==="softBin"?"softBin":"hardBin",highlightBin:findingBin(e)});const i=e.highlight;(i.kind==="bin"||i.kind==="region"||i.kind==="dies")&&Tn(i.dieKeys)}const Ue=new Map,Ft=new WeakSet;function zt(e){if(Ue.get(e)?.cancel(),Ue.delete(e),e.style.display==="none"){Ft.add(e);return}Ft.delete(e);const t=Bo(Do(e,{wafer:K,dies:re,yieldSummary:ie.yield,dataCoverage:ie.dataCoverage,hbinDefs:J,sbinDefs:ee,testDefs:te,statsSummary:ge,warnings:hn?he:[],passBins:lt,ringCount:ie.ringCount??4,binColors:h.binColors,plotMode:d.plotMode??"hardBin",metadataShownElsewhere:cn,fallbackFormat:d.fallbackFormat,activeFindingId:Ie,findingsFilter:Ti,findingsNotice:Bn,onFindingsFilterChange:me,onSaveText:ue.onSaveText,metadataFields:xe,dieListOptions:S.dieList,onFindingClick:(n,i)=>{Ie===n.id?(Ie=null,Tn([]),P({highlightBin:void 0})):(Ie=n.id,Pi(n)),me()}}));t.done||Ue.set(e,t)}function me(){U&&zt(U)}function Ze(){O&&zt(O)}if(Ye?.placement){const e=Ye.placement;U=sn(e,be,p);const t=M.parentElement,n=M.nextSibling;Se=ln(M,U,e),t?.insertBefore(Se,n),me()}else if(ge){const e=Ye?.defaultOpen??!Ve;O=sn("right",be,p),O.style.display=e?"block":"none";const t=M.parentElement,n=M.nextSibling;de=ln(M,O,"right"),t?.insertBefore(de,n),Ze()}const z=mi?si(p):null;let ce=null,R=null,H=null,I=null,pt=null,Z=null,kn=null,X=null,fe=null,ut=null;yn=!0;function Ht(){if(!fe||!ut)return;const e=he.length,t=e>0;if(fe.style.display=t?"flex":"none",ut.style.display=t?"":"none",!t)return;const n=To(he[0]),i=`${e} data ${e===1?"warning":"warnings"}`;fe.style.color=n==="error"?E.errText:E.warnText,fe.ariaLabel=n==="error"?`${i} \u2014 the map may be positionally wrong`:i}let Vt=null,Ln=null,Yt=null,Xt=null,Nt=null,_t=null;function Me(e="selection"){Ie!==null&&(Ie=null,e==="selection"?P({highlightBin:void 0}):(x=new Set,ae?.([])),me())}function Tn(e){x=new Set(e??[]),ae&&ae(Qe()),C()}function gt(){if(!Z)return;const e=!!(U??O);Z.style.display=ge&&e&&!le?"flex":"none";const t=U??O,n=t?t.style.display!=="none":!1;ge?.hasNotableFindings&&!n?Z.style.color=E.findingIndicator:Z.dataset.active||(Z.style.color=E.icon)}let Pn=null;function On(e){const t=U??O;if(!t)return;const n=t.style.display!=="none",i=M.getBoundingClientRect().width;if(t.style.display=e?"block":"none",e!==n){const o=i-M.getBoundingClientRect().width;(S.onSummaryPanelChange??ht)?.(e,e?o:0)}e&&Ft.has(t)&&zt(t),Z&&Pn?.(Z,e),gt()}if(Ve){let g=function(y){j=y,i(N,y==="zoom"),i(w,y==="pan"),pt&&i(pt,y==="select"),s.style.cursor=y==="pan"?"grab":"crosshair"};ce=p.createElement("div"),ce.dataset.wmapToolbar="single",Object.assign(ce.style,{marginLeft:"auto",flexShrink:"0",display:"flex",flexDirection:"row",alignItems:"center",flexWrap:"wrap-reverse",justifyContent:"flex-end",maxWidth:"100%",background:E.menuBg,border:`1px solid ${E.menuBorder}`,borderRadius:oi.control,boxShadow:Ji.panel,pointerEvents:"auto"});const e=si(p),t=no(e),{makeBtn:n,setActive:i,makeSep:o,makeMenuRow:l,makeMenuSection:r,closeOpenMenu:a,getOpenMenu:c,setOpenMenu:f}=t;Pn=i,Vt=a,Ln=c,p.addEventListener("click",a,!0),H=p.createElement("div"),Object.assign(H.style,{display:Fe?"none":"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),ce.appendChild(H);const v=n("download","Download PNG",Ai);H.appendChild(v),H.appendChild(o());const N=n("zoomMode","Zoom (drag to zoom region)",()=>g("zoom")),ne=n("zoomIn","Zoom in",()=>We(s.clientWidth/2,s.clientHeight/2,1.2)),b=n("zoomOut","Zoom out",()=>We(s.clientWidth/2,s.clientHeight/2,1/1.2)),D=n("reset","Reset zoom (double-click)",()=>bt());H.appendChild(N),H.appendChild(ne),H.appendChild(b),H.appendChild(D),H.appendChild(o());const w=n("pan","Pan (drag to move)",()=>g("pan"));H.appendChild(w),pt=n("boxSelect","Select (drag to select dies)",()=>g("select")),H.appendChild(pt);{const y=n("drilldown","Chart this wafer",()=>{const V=y.getBoundingClientRect();Xn({x:V.left,y:V.bottom+4},y)});y.setAttribute("aria-haspopup","menu"),rt=y,Yn(),H.appendChild(y)}g(j);{let y=function(u){return u.plotMode!==(d.plotMode??"hardBin")?!1:u.plotMode==="value"?(d.activeTest??0)===(u.activeTest??0):u.plotMode==="metadata"?d.activeMetadataKey===u.activeMetadataKey:!0},V=function(u,B){u.activeTest!==void 0?P({plotMode:u.plotMode,activeTest:u.activeTest,activeMetadataKey:void 0,logScale:u.logScale}):u.activeMetadataKey!==void 0?P({plotMode:u.plotMode,activeTest:void 0,activeMetadataKey:u.activeMetadataKey,passFailDisplay:"off"}):P({plotMode:u.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),B.remove(),f(null),nt(A,!1)};R=p.createElement("div"),Object.assign(R.style,{display:"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),ce.appendChild(R),I=p.createElement("div"),Object.assign(I.style,{display:"flex",alignItems:"center",gap:"0"}),R.appendChild(I),I.appendChild(o());const pe=()=>{const u=c();u&&(u.remove(),f(null)),nt(A,!1)},A=n("mode","Plot mode",()=>{if(c()){pe();return}const u=re,B=h.testDefs,{testEntries:wt,binEntries:De,stackedEntries:et}=xo(u,B,{includeStacked:h.isLotStack}),en=(xe??[]).filter(Be=>wo(u,Be.key)).map(Co),tt=io(A.getBoundingClientRect(),wt,De,et,y,V,{makeMenuRow:l,makeMenuSection:r},d.plotMode??"hardBin",A.ownerDocument.defaultView??window,en);ai(A).appendChild(tt),f(tt),nt(A,!0),ri(tt,A,pe)});nt(A,!1);const{btn:vt,sync:Je}=lo(t,()=>({...d,plotMode:d.plotMode??"hardBin"}),()=>Di,P);Xt=Je,Xt();const qt=co(t,()=>{const u=!!h.hasReticle,B=(d.plotMode??"hardBin")==="value",{testNumber:wt}=tn(d.activeTest??0,h.testDefs),De=Ct(h.testDefs,wt),et=B&&De!==void 0&&!nn(De),en=B&&!et&&(De?.limitLow!==void 0||De?.limitHigh!==void 0),tt=B&&!et&&h.dies.some(Be=>Qi(Be,wt,De)!==void 0);return ho({...d,showAxes:Dn()},u,{functionalActive:et,hasLimits:en,hasRecorded:tt,binMode:(d.plotMode??"hardBin")==="hardBin"||(d.plotMode??"hardBin")==="softBin"},Be=>P(Be),{on:!!d.compact,offered:Li(),onChange:Be=>P({compact:Be}),onDiagnostics:()=>yo(re,[ct],{anchor:s,onSaveText:ue.onSaveText})})},()=>mo(d)),{btn:Jt,sync:Fi}=ro(t,()=>d,u=>P({legendPosition:u}));Yt=Fi,Yt();const ei=()=>{const{testNumber:u}=tn(d.activeTest??0,te),B=Ct(te,u);return B!==void 0&&!nn(B)},{btn:zi,sync:Hi}=ao(t,()=>({...d,functionalActive:ei()}),u=>P(u));Nt=Hi,Nt();const Vi=()=>{const{testNumber:u}=tn(d.activeTest??0,te),B=Ct(te,u);return B!==void 0&&(B.limitLow!==void 0||B.limitHigh!==void 0)},xt=n("specRange","Colorbar range: test limits",()=>{const u=d.colorbarRangeMode==="data"?"spec":"data";P({colorbarRangeMode:u})});_t=()=>{const u=d.plotMode==="value"&&Vi()&&go(d)==="off"&&!ei();xt.style.display=u?"":"none";const B=(d.colorbarRangeMode??"spec")==="spec";i(xt,B),xt.ariaLabel=B?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"},_t();const Yi=fo(t,()=>d,u=>P(u));I.appendChild(A),I.appendChild(vt),I.appendChild(zi),I.appendChild(xt),Fe||(I.appendChild(o()),I.appendChild(qt),I.appendChild(o()),I.appendChild(Jt),I.appendChild(o()),I.appendChild(Yi)),ge&&(Z=n("findings","Summary panel",()=>{const u=U??O;u&&On(u.style.display==="none")}),R.appendChild(o()),R.appendChild(Z),O?.style.display!=="none"&&i(Z,!0),gt()),hn&&(ut=o(),fe=n("warning","Data warnings",()=>{const u=c();if(a(new MouseEvent("click")),u)return;const B=Lo(fe.getBoundingClientRect(),he,L);ai(ke).appendChild(B),f(B),ri(B,fe,()=>a(new MouseEvent("click")))}),nt(fe,!1),R.appendChild(ut),R.appendChild(fe),Ht()),Xe&&(R.appendChild(o()),X=n("analysis","Insights",()=>{_e(!le),i(X,le)}),X.dataset.wmapInsightsBtn="1",R.appendChild(X)),un&&(R.appendChild(o()),se=n("expand","Expand (E)",pn??Rn),R.appendChild(se)),fn&&(R.appendChild(o()),kn=n("help","User guide",()=>Qt()),R.appendChild(kn))}q.appendChild(ce),He()}let Ee=null,ht=null;function Rn(){Ee&&(Ee.close(),Ee=null);const e=ke;e.style.flex="1",e.style.minWidth="0",e.style.minHeight="0";const t=an(K.metadata??{},Ne()),n=q.childElementCount>0?[q,e]:[e],i=oo(n,{ownerDocument:p,boxSize:le?{width:"min(96vw, 1600px)",height:"min(92vh, 1000px)"}:void 0,onClosed:()=>{Ee=null,ht=null,se&&(se.style.display="flex"),le||s.focus({preventScroll:!0})}});if(!i)return;i.box.setAttribute("aria-label",t??"Expanded wafer map"),n.length>1&&(i.contentWrap.style.flexDirection="column"),Ee=i,ht=bo(i);const o=U??O,l=Se??de;if(o&&l&&o.style.display!=="none"){const r=parseFloat(p.defaultView?.getComputedStyle(l).columnGap??"")||0,a=o.getBoundingClientRect().width+r;a>0&&ht(!0,a)}se&&(se.style.display="none")}function In(e){("binColorScheme"in e||"useDefinedBinColors"in e)&&!("binColors"in e)&&d.binColors!==void 0&&(e={...e,binColors:void 0});const t=d.plotMode;d={...d,...e},("compact"in e||"compactMap"in e)&&(_=null,T=null),e.plotMode!==void 0&&e.plotMode,Object.keys(e).every(l=>l==="legendPosition"||l==="showLegend"||l==="markFailingDies"||l==="showAxes")||Wt(),Yt?.(),Xt?.(),Nt?.(),_t?.(),C();const i=e.plotMode!==void 0&&e.plotMode!==t,o=COLOR_KEYS.some(l=>l in e);(o||i)&&(me(),Ze()),(o||i||e.activeTest!==void 0||e.logScale!==void 0||e.colorbarRangeMode!==void 0)&&ot?.()}function P(e){In(e);const t=Object.keys(e);hi?.(d,t,classifyChanged(t))}let jt=!1;const Kt=S.drawWhenVisible&&L.IntersectionObserver?new L.IntersectionObserver(e=>{Ae=e[e.length-1].isIntersecting,Ae&&mt&&C()},{rootMargin:"25%"}):null;let Ae=Kt===null,mt=!1;Kt?.observe(s);function $t(){jt||(jt=!0,on(()=>{jt=!1,C()},L))}function C(){if(!Ae){mt=!0;return}mt=!1;const e=T??void 0,t=h.dies[0],n=t?{x:t.width,y:t.height}:Le.diePitchMm,i=Math.floor(s.clientWidth||s.width),o=!!(J?.length||ee?.length||h.dies.some(v=>v.hbin!=null||v.sbin!=null)),l=d.legendPosition??"default",r=d.showLegend??!0,a=l==="default"||l==="compact",c=(Le.colorbarWidth??16)+28,f=o&&a?l!=="default"?Math.max(ti,c):i<Gi?0:i<$i?Math.max(Ki,c):Math.max(ti,c):void 0,g=ji(s,h,{...Le,minRightReserve:r?f:0,showColorbar:r&&(Le.showColorbar??!0),markFailingDies:d.markFailingDies??!1,legendPosition:l,legendOffset:It,diePitchMm:n,fallbackFormat:d.fallbackFormat,showAxes:Dn(),viewport:e,activeBin:d.plotMode==="metadata"?d.highlightMetadataValue:d.highlightBin,hoverBin:Rt,afterDies:x.size>0?Oi:void 0,hbinDefs:J,sbinDefs:ee,metadataFields:xe});Ot=g.binLegendRows,we=g.legendBox??null,T===null&&(_=g.viewport),Pe&&Ii(),Yn()}function Oi(e,t,n){const i=h.hoverPoints,o=h.rectangles[0],l=o?o.width/2*t.ppm:t.ppm*.5,r=o?o.height/2*t.ppm:t.ppm*.5,a=new Set;x.size>0&&(je??=new Map(h.dies.map((b,D)=>[ye(b),D])));for(const b of x){const D=je.get(b);D!==void 0&&a.add(D)}if(!a.size)return;e.save(),e.setLineDash([]),e.fillStyle=n.background,e.globalAlpha=.7;let c=0;e.beginPath();for(let b=0;b<i.length;b++)a.has(b)||(e.rect(t.originX+i[b].x*t.ppm-l,t.originY-i[b].y*t.ppm-r,l*2,r*2),++c===Ui&&(e.fill(),e.beginPath(),c=0));c&&e.fill(),e.globalAlpha=1;const{cw:f,ch:g}=Ri(t,l,r),v=new Map,N=b=>Math.round(b*100),ne=(b,D,w,y)=>{const V=`${N(b)},${N(D)},${N(w)},${N(y)}`;v.has(V)?v.delete(V):v.set(V,[b,D,w,y])};for(const b of a){const D=t.originX+i[b].x*t.ppm,w=t.originY-i[b].y*t.ppm,y=D-f,V=D+f,pe=w-g,A=w+g;ne(y,pe,V,pe),ne(y,A,V,A),ne(y,pe,y,A),ne(V,pe,V,A)}e.strokeStyle=n.text,e.lineWidth=2,e.lineCap="square",e.beginPath();for(const[b,D,w,y]of v.values())e.moveTo(b,D),e.lineTo(w,y);e.stroke(),e.restore()}function Ri(e,t,n){const i=h.hoverPoints,o=h.dies;let l=0,r=0;for(let a=0;a<o.length&&(!l||!r);a++){const c=o[a];if(!(c.x==null||c.y==null))for(const f of[je.get(`${c.x+1},${c.y}`),je.get(`${c.x},${c.y+1}`)]){if(f===void 0)continue;const g=Math.abs(i[f].x-i[a].x)*e.ppm,v=Math.abs(i[f].y-i[a].y)*e.ppm;g>v?l||=g/2:r||=v/2}}return{cw:l||t,ch:r||n}}function Ii(){const e=s.getContext("2d"),t=Math.min(W.x,F.x),n=Math.min(W.y,F.y),i=Math.abs(F.x-W.x),o=Math.abs(F.y-W.y);e.save(),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(t,n,i,o),e.setLineDash([5,3]),e.strokeStyle="rgba(255,255,255,0.9)",e.lineWidth=3,e.strokeRect(t,n,i,o),e.strokeStyle="rgba(0,0,0,0.9)",e.lineWidth=1.5,e.strokeRect(t,n,i,o),e.restore()}function An(){if(!mt)return;const e=Ae;Ae=!0,C(),Ae=e}function Ai(){An(),s.toBlob(e=>{e&&po(e,dn(),ue.onSaveImage)})}function Wn(e){return _?Math.max(_.ppm*xi,Math.min(_.ppm*wi,e)):e}function We(e,t,n){const i=T??_;if(!i)return;const o=Wn(i.ppm*n),l=o/i.ppm,r=e-(e-i.originX)*l,a=t-(t-i.originY)*l,c=(_?.snapDist??1)/(o/(_?.ppm??o));T={originX:r,originY:a,ppm:o,snapDist:c},C()}function Q(){return T??_}function Fn(e){if(e.ctrlKey||e.metaKey){e.preventDefault();const t=s.getBoundingClientRect(),n=e.deltaY<0?1.12:1/1.12;We(e.clientX-t.left,e.clientY-t.top,n)}else if(T!==null){e.preventDefault();const t=Q(),n=T.snapDist;T={originX:t.originX-e.deltaX,originY:t.originY-e.deltaY,ppm:t.ppm,snapDist:n},C()}}function Gt(e,t,n){return e>=n.x&&e<n.x+n.w&&t>=n.y&&t<n.y+n.h}function zn(e){if(dt=!1,e.button!==0||!Q())return;s.focus({preventScroll:!0}),s.setPointerCapture(e.pointerId);const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;if(we&&d.legendPosition==="floating"&&Gt(n,i,we)){Te=!0,$e={x:n,y:i},At={...It};return}if(Ge&&j!=="pan"){Re=!0,Ce=!0,Oe={x:n,y:i},ft={x:Q().originX,y:Q().originY},s.style.cursor="grabbing";return}if(j==="zoom"||j==="select"){Pe=!0,W=F={x:n,y:i};return}Ce=!0,Oe={x:n,y:i},ft={x:Q().originX,y:Q().originY},s.style.cursor="grabbing"}function Hn(e){const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;if(Pe){F={x:n,y:i},$t();return}if(Te){const g=n-$e.x,v=i-$e.y;g*g+v*v>16&&(Te=!1,Ke=!0,s.style.cursor="grabbing")}if(Ke){It={x:At.x+(n-$e.x),y:At.y+(i-$e.y)},$t();return}if(Ce){const g=Q(),v=T?.snapDist??_?.snapDist??1;T={originX:ft.x+(n-Oe.x),originY:ft.y+(i-Oe.y),ppm:g.ppm,snapDist:v},$t();return}const o=Q();if(!o)return;const l=(n-o.originX)/o.ppm,r=(o.originY-i)/o.ppm,c=Zt(l,r,o.snapDist)?.die??null,f=Ot.find(g=>n>=g.x&&n<g.x+g.w&&i>=g.y&&i<g.y+g.h);if(En(f?f.bin:void 0),f){s.style.cursor="pointer",z&&(z.textContent=f.label??`Bin ${f.bin}`,z.style.display="block",li(z,s,e.clientX,e.clientY,{followPointer:!0})),st?.(null,e);return}j==="pan"&&(s.style.cursor=c?"crosshair":"grab"),z&&(c?(z.innerHTML=Ni(c,h.plotMode,{testDefs:te,hbinDefs:J,sbinDefs:ee,fallbackFormat:d.fallbackFormat,aggrMethod:h.aggrMethod,lotSize:h.lotSize,metadataFields:xe,activeTest:h.activeTest,reticleConfig:ct}),z.style.display="block",li(z,s,e.clientX,e.clientY,{followPointer:!0})):z.style.display="none"),st?.(c,e)}function Vn(e){const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top,o=e.ctrlKey||e.metaKey;if(z&&(n<0||i<0||n>t.width||i>t.height)&&(z.style.display="none"),Pe){Pe=!1,F={x:n,y:i};const a=n-W.x,c=i-W.y,f=Q();if(j==="zoom"){if(a*a+c*c<25)We(n,i,2);else if(f){const g=Math.min(W.x,F.x),v=Math.max(W.x,F.x),N=Math.min(W.y,F.y),ne=Math.max(W.y,F.y),b=v-g,D=ne-N;if(b>4&&D>4){const w=s.clientWidth,y=s.clientHeight,V=w/b,pe=y/D,A=Math.min(V,pe),vt=Wn(f.ppm*A),Je=vt/f.ppm,qt=(g+v)/2,Jt=(N+ne)/2;T={originX:w/2-(qt-f.originX)*Je,originY:y/2-(Jt-f.originY)*Je,ppm:vt,snapDist:f.snapDist/Je}}}C(),s.style.cursor="crosshair";return}if(a*a+c*c<25)Ut(n,i,o,e);else if(f){const g=(Math.min(W.x,F.x)-f.originX)/f.ppm,v=(Math.max(W.x,F.x)-f.originX)/f.ppm,N=(f.originY-Math.max(W.y,F.y))/f.ppm,ne=(f.originY-Math.min(W.y,F.y))/f.ppm,b=h.hoverPoints,D=[];for(let w=0;w<b.length;w++)if(b[w].x>=g&&b[w].x<=v&&b[w].y>=N&&b[w].y<=ne){const y=h.dies[w];y&&D.push(y)}if(o)for(const w of D){const y=ye(w);x.has(y)?x.delete(y):x.add(y)}else x=new Set(D.map(w=>ye(w)));Me(),ae?.(Qe())}C(),s.style.cursor="crosshair";return}if(Te){Te=!1,Ut(n,i,o,e);return}if(Ke){Ke=!1,s.style.cursor="grab";return}if(!Ce)return;if(Ce=!1,Re){Re=!1,s.style.cursor=Ge||j==="pan"?"grab":"crosshair";return}s.style.cursor=j==="pan"?"grab":"crosshair";const l=n-Oe.x,r=i-Oe.y;l*l+r*r<25&&Ut(n,i,o,e)}function Ut(e,t,n,i){for(const a of Ot)if(e>=a.x&&e<a.x+a.w&&t>=a.y&&t<a.y+a.h){Me("legend"),typeof a.bin=="number"?P({highlightBin:fi(d.highlightBin,a.bin,n)}):P({highlightMetadataValue:fi(d.highlightMetadataValue,a.bin,n)});return}if(we&&Gt(e,t,we))return;const o=Q();if(!o)return;const r=Zt((e-o.originX)/o.ppm,(o.originY-t)/o.ppm,o.snapDist)?.die??null;if(r){gi?.(r,i);const a=ye(r);n?x.has(a)?x.delete(a):x.add(a):x.size===1&&x.has(a)?x=new Set:x=new Set([a]),Me(),ae?.(Qe()),C()}else n||(x=new Set,Me(),ae?.([]),C())}function Qe(){const e=[],t=h.hoverPoints;for(let n=0;n<t.length;n++){const i=h.dies[n];i&&x.has(ye(i))&&e.push(i)}return e}function Yn(){rt&&(rt.style.display=Bt()?"flex":"none",rt.ariaLabel=x.size>0?"Chart the selected dies (or right-click)":"Chart this wafer (or right-click)")}function Wi(){const e={waferLabel:rn(),testDefs:te,isLotStack:ie.isLotStack,activeTest:d.plotMode==="value"?d.activeTest:void 0};return x.size>0?Oo(Qe(),e):Ro(re,e)}function Xn(e,t){if(!Bt())return;const n=Wi();import("./drilldown.js").then(({openDrilldownMenu:i})=>{vn||(bn=i(e,t,n,Si))})}function Nn(e){e.stopPropagation();const t=dt;if(dt=!1,!Bt()||le)return;const n=s.getBoundingClientRect();if(!t){const o=e.clientX-n.left,l=e.clientY-n.top;if(we&&Gt(o,l,we))return;const r=Q(),a=r?Zt((o-r.originX)/r.ppm,(r.originY-l)/r.ppm,r.snapDist)?.die:void 0;a&&!x.has(ye(a))&&(x=new Set([ye(a)]),Me(),ae?.(Qe()),C())}e.preventDefault();const i=t?{x:n.left+n.width/2,y:n.top+n.height/2}:{x:e.clientX,y:e.clientY};Xn(i,s)}function _n(){En(void 0),z&&Mt(p),st?.(null,new MouseEvent("mouseleave")),s.style.cursor=j==="pan"?"grab":"crosshair"}function jn(){Ce=!1,Re=!1,Pe=!1,Te=!1,Ke=!1,z&&Mt(p),st?.(null,new MouseEvent("mouseleave")),s.style.cursor=j==="pan"?"grab":"crosshair",C()}function Zt(e,t,n){const i=h.hoverPoints,o=h.rectangles;for(let c=0;c<o.length;c++){const f=o[c];if(Math.abs(e-f.x)<=f.width/2&&Math.abs(t-f.y)<=f.height/2){const g=h.dies[c];return g?{die:g,index:c}:null}}let l=null,r=-1,a=n*n;for(let c=0;c<i.length;c++){const f=i[c].x-e,g=i[c].y-t,v=f*f+g*g;v<a&&(a=v,l=h.dies[c]??null,r=c)}return l?{die:l,index:r}:null}const Kn=new L.ResizeObserver(()=>{_=null,T=null,C()});Kn.observe(s),S.height==null&&ui<=0&&on(()=>on(()=>{k.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 qe=L.matchMedia(`(resolution: ${L.devicePixelRatio}dppx)`);const yt=()=>{qe.removeEventListener("change",yt),qe=L.matchMedia(`(resolution: ${L.devicePixelRatio}dppx)`),qe.addEventListener("change",yt),C()};qe.addEventListener("change",yt);const $n=L.matchMedia("(prefers-color-scheme: dark)"),Gn=()=>C();$n.addEventListener("change",Gn);const Un=()=>{z&&Mt(p)};L.addEventListener("blur",Un);function Zn(e){if((e.key==="ContextMenu"||e.shiftKey&&e.key==="F10")&&(dt=!0),e.key==="Escape"&&x.size>0&&(x=new Set,Me(),ae?.([]),C()),(e.key==="e"||e.key==="E")&&un&&(e.stopPropagation(),(pn??Rn)()),(e.ctrlKey||e.metaKey)&&(e.key==="="||e.key==="+"?(e.preventDefault(),We(s.clientWidth/2,s.clientHeight/2,1.2)):e.key==="-"?(e.preventDefault(),We(s.clientWidth/2,s.clientHeight/2,1/1.2)):e.key==="0"&&(e.preventDefault(),bt())),!e.ctrlKey&&!e.metaKey&&!e.shiftKey){const n=Q();if(n){const i=T?.snapDist??_?.snapDist??1;let o=0,l=0;e.key==="ArrowLeft"&&(o=20,e.preventDefault()),e.key==="ArrowRight"&&(o=-20,e.preventDefault()),e.key==="ArrowUp"&&(l=20,e.preventDefault()),e.key==="ArrowDown"&&(l=-20,e.preventDefault()),(o||l)&&(T={originX:n.originX+o,originY:n.originY+l,ppm:n.ppm,snapDist:i},C())}e.key===" "&&!Ge&&(e.preventDefault(),Ge=!0,j!=="pan"&&(s.style.cursor="grab"))}}function Qn(e){e.key===" "&&(Ge=!1,Re&&(Ce=!1,Re=!1),s.style.cursor=j==="pan"?"grab":"crosshair")}s.style.cursor="crosshair",s.setAttribute("tabindex","0"),s.addEventListener("wheel",Fn,{passive:!1}),s.addEventListener("pointerdown",zn),s.addEventListener("pointermove",Hn),s.addEventListener("pointerup",Vn),s.addEventListener("pointerleave",_n),s.addEventListener("pointercancel",jn);const qn=()=>bt();s.addEventListener("dblclick",qn),s.addEventListener("keydown",Zn),s.addEventListener("keyup",Qn),s.addEventListener("contextmenu",Nn);const Jn=e=>{e.stopPropagation()};s.addEventListener("click",Jn),s.clientWidth,C(),ot?.();function bt(){_=null,T=null,C()}function Qt(){import("./userGuideHtml.js").then(e=>so({buildWaferMap:Zi,renderWaferMap,renderWaferGallery:void 0,analyzeWaferMap:qi},e.USER_GUIDE_HTML,yi,k))}return He(),{setResult(e){ie=e,K=e.wafer,re=e.dies,J=e.hbinDefs,ee=e.sbinDefs,te=e.testDefs,xe=e.metadataFields,xn=e.reticles?.length?e.reticles:void 0,ct=e.reticleConfig,wn=e.dataAxisFlip,kt=e.isLotStack,Lt=e.aggrMethod,Tt=e.lotSize,Ei(),Wt(),C(),U&&me()},setOptions(e){In(e)},getOptions(){return{...d}},resetZoom:bt,setSelection(e){x=new Set(e.map(t=>ye(t))),C()},clearSelection(){x=new Set,Me(),ae?.([]),C()},setFindingsNotice(e){Bn=e,U?me():O&&Ze()},setStatsSummary(e){if(ge=e,Dt(),Ht(),U)me();else if(O)Ze();else if(e&&!Ye?.placement){const t=Ye?.defaultOpen??!Ve;O=sn("right",be,p),O.style.display=t?"block":"none";const n=M.parentElement,i=M.nextSibling;de=ln(M,O,"right"),n?.insertBefore(de,i),Ze()}gt()},closeSummaryPanel(){On(!1)},getExportTitle(){return dn()},getSaveImageHook(){return ue.onSaveImage},drawPendingNow:An,getBinColors(){return h.binColors},setSummaryVisible(e){Z&&(Z.style.display=e?"flex":"none")},setViewControlsVisible(e){R&&(R.style.display=e?"flex":"none")},setExpandVisible(e){se&&(se.style.display=e?"flex":"none")},openUserGuide:Qt,setInsightsOpen(e){_e(e),X&&(e?(X.dataset.active="1",X.style.background=E.bgActive,X.style.color=E.iconActive):(delete X.dataset.active,X.style.background="transparent",X.style.color=E.icon))},destroy(){vn=!0;for(const e of Ue.values())e.cancel();Ue.clear(),Ee?.close(),Ln?.()?.remove(),Vt&&p.removeEventListener("click",Vt,!0),s.removeEventListener("wheel",Fn),s.removeEventListener("pointerdown",zn),s.removeEventListener("pointermove",Hn),s.removeEventListener("pointerup",Vn),s.removeEventListener("pointerleave",_n),s.removeEventListener("pointercancel",jn),s.removeEventListener("dblclick",qn),s.removeEventListener("keydown",Zn),s.removeEventListener("keyup",Qn),s.removeEventListener("contextmenu",Nn),bn?.(),s.removeEventListener("click",Jn),Kn.disconnect(),Kt?.disconnect(),qe.removeEventListener("change",yt),$n.removeEventListener("change",Gn),L.removeEventListener("blur",Un),Ci(),z&&Mt(p),ce?.remove(),Se&&(Se.parentElement?.insertBefore(M,Se),Se.remove()),de&&(de.parentElement?.insertBefore(M,de),de.remove()),M.remove(),s.style.cursor="",G?.destroy(),$?.destroy(),ze.remove()}}}
|
|
@@ -2,7 +2,7 @@ import type { Wafer } from '../core/wafer.js';
|
|
|
2
2
|
import type { Die } from '../core/dies.js';
|
|
3
3
|
import { type BinDef, type TestDef, type YieldSummary, type MetadataFieldDef } from '../renderer/buildWaferMap.js';
|
|
4
4
|
import type { StatsFinding, StatsSummary, LotStatsSummary } from '../stats/types.js';
|
|
5
|
-
import {
|
|
5
|
+
import type { ReportMap } from '../stats/renderSummaryReport.js';
|
|
6
6
|
import { type FindingsFilter } from '../stats/filterFindings.js';
|
|
7
7
|
import { type BinColors } from '../renderer/binColors.js';
|
|
8
8
|
import { buildWarningsBanner, type WaferWarning } from './warnings.js';
|
|
@@ -336,7 +336,24 @@ export declare function buildFindingsSection(findings: StatsFinding[], statsSumm
|
|
|
336
336
|
* thread a `panel` through and give it a `stateKey`, or it will be the one
|
|
337
337
|
* section that forgets whether the reader collapsed it.
|
|
338
338
|
*/
|
|
339
|
-
standalone?: boolean
|
|
339
|
+
standalone?: boolean,
|
|
340
|
+
/** The pass bins every wafer was judged by, for the synthesis the Detail modal opens with; omitted when they differ. */
|
|
341
|
+
passBins?: readonly number[]): HTMLDivElement | null;
|
|
342
|
+
/**
|
|
343
|
+
* The first section of both panels: what the wafer or lot did and what stands out, from the same
|
|
344
|
+
* `buildSynthesis` the HTML reports open with. A clean one says so ("Nothing stands out"), which a
|
|
345
|
+
* list of findings cannot, so this is its own section and not a part of the Findings one — that
|
|
346
|
+
* section is absent when there are no findings.
|
|
347
|
+
*
|
|
348
|
+
* Linked names (a region, a bin) select that finding, exactly as its row in the list below does.
|
|
349
|
+
*/
|
|
350
|
+
export declare function buildSynthesisSection(source: StatsSummary | LotStatsSummary,
|
|
351
|
+
/** The pass bins every wafer was judged by; omitted when they differ, and the items then rest on yield alone. */
|
|
352
|
+
passBins: readonly number[] | undefined, onFindingClick: ((finding: StatsFinding, row: HTMLButtonElement) => void) | undefined, activeFindingId: string | null,
|
|
353
|
+
/** Panel element owning the collapsed state. Omit for a stateless render. */
|
|
354
|
+
panel?: HTMLElement,
|
|
355
|
+
/** Opens the full report, which begins with this same section. Omitted ⇒ no link. */
|
|
356
|
+
onOpenReport?: () => void): HTMLDivElement;
|
|
340
357
|
/**
|
|
341
358
|
* Findings section with severity/kind/region filter controls — the
|
|
342
359
|
* panel-level entry point (wraps `buildFindingsSection(..., standalone:
|
|
@@ -371,7 +388,9 @@ export declare function buildFindingsSectionWithFilter(source: StatsSummary | Lo
|
|
|
371
388
|
/** Panel element owning the collapsed state. Omit for a stateless render. */
|
|
372
389
|
panel?: HTMLElement,
|
|
373
390
|
/** See {@link FindingsNotice}. Rendered above the filter row. */
|
|
374
|
-
notice?: FindingsNotice
|
|
391
|
+
notice?: FindingsNotice,
|
|
392
|
+
/** The pass bins every wafer was judged by; omitted when they differ. See {@link buildSynthesisSection}. */
|
|
393
|
+
passBins?: readonly number[]): HTMLDivElement | null;
|
|
375
394
|
/**
|
|
376
395
|
* Aggregate test value stats across all wafers in the lot. When every
|
|
377
396
|
* wafer's `StatsSummary.stats.perTestStats`/`.testSpecYield` is available
|