@wafertools/wafermap 0.31.0 → 0.32.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 +12 -12
- package/CHANGELOG.md +172 -0
- package/README.md +3 -3
- package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
- package/dist/packages/canvas-adapter/dieList.js +7 -7
- package/dist/packages/canvas-adapter/drilldown.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 +17 -4
- package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
- package/dist/packages/canvas-adapter/summaryPanel.js +3 -3
- package/dist/packages/canvas-adapter/toCanvas.d.ts +23 -2
- package/dist/packages/canvas-adapter/toCanvas.js +1 -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 +25 -15
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/core/aggregates.js +1 -1
- package/dist/packages/core/dieTable.d.ts +137 -0
- package/dist/packages/core/dieTable.js +1 -0
- package/dist/packages/core/dies.d.ts +22 -0
- package/dist/packages/core/dies.js +1 -1
- package/dist/packages/core/utils.d.ts +14 -0
- package/dist/packages/core/utils.js +1 -1
- package/dist/packages/renderer/buildView.d.ts +3 -3
- package/dist/packages/renderer/buildView.js +1 -1
- package/dist/packages/renderer/buildWaferMap.d.ts +29 -11
- package/dist/packages/renderer/buildWaferMap.js +1 -1
- package/dist/packages/renderer/columnarInput.d.ts +87 -0
- package/dist/packages/renderer/columnarInput.js +1 -0
- package/dist/packages/renderer/derivedTests/apply.d.ts +8 -6
- package/dist/packages/renderer/derivedTests/apply.js +1 -1
- package/dist/packages/renderer/index.d.ts +1 -0
- package/dist/packages/renderer/spec.d.ts +3 -7
- package/dist/packages/renderer/spec.js +1 -1
- package/dist/packages/stats/analyzeWaferLot.js +1 -1
- package/dist/packages/stats/analyzeWaferMap.d.ts +134 -2
- package/dist/packages/stats/analyzeWaferMap.js +1 -1
- package/dist/packages/stats/boxplot.js +1 -1
- package/dist/packages/stats/capability.d.ts +7 -7
- package/dist/packages/stats/capability.js +1 -1
- package/dist/packages/stats/clusterDetection.js +1 -1
- package/dist/packages/stats/connectedComponents.js +1 -1
- package/dist/packages/stats/correlation.js +1 -1
- package/dist/packages/stats/filterFindings.d.ts +5 -0
- package/dist/packages/stats/filterFindings.js +1 -1
- package/dist/packages/stats/histogram.js +1 -1
- package/dist/packages/stats/math.d.ts +22 -6
- package/dist/packages/stats/math.js +1 -1
- package/dist/packages/stats/normalizeInput.js +1 -1
- package/dist/packages/stats/patternClassification.d.ts +3 -3
- package/dist/packages/stats/patternClassification.js +1 -1
- package/dist/packages/stats/regions.d.ts +7 -0
- package/dist/packages/stats/regions.js +1 -1
- package/dist/packages/stats/renderSummaryReport.js +18 -18
- package/dist/packages/stats/scatter.js +1 -1
- package/dist/packages/stats/sweep.js +1 -1
- package/dist/packages/stats/testPassRate.js +1 -1
- package/dist/packages/stats/trend.js +1 -1
- package/dist/packages/stats/types.d.ts +5 -0
- package/dist/packages/worker/index.js +1 -1
- package/dist/packages/worker/wafermap.worker.d.ts +3 -0
- package/dist/packages/worker/wafermap.worker.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getUniqueTestNumbers as Mo,resolveTestNumber as Do,findTestDef as ko,collectMetadataValues as Eo}from"../renderer/buildView.js";import{metadataCategoricalValue as Bo}from"../core/metadata.js";import{resolveBinColorsForMaps as Oo,mergeBinDefs as Ye,binColorWarning as To,mixedPassBinsWarning as Lo,binColorsEqual as Ro}from"../renderer/binColors.js";import{itemPassBins as Io,INPUT_DEFAULT_PASS_BINS as Wo}from"../core/passBins.js";import{NO_DATA_FILL as $o}from"../renderer/colorMap.js";import{metadataValueColor as Ao}from"../renderer/colorMap.js";import{resolveCanvasTheme as Po}from"./canvasTheme.js";import{ICONS as We}from"./icons.js";import{SHADOW as $e,LEADING as Ze,TRACKING as Fo,controlStyle as Ho,wireControlHover as xt,SPACE as w,EDGE_GUTTER as oe,MAP_CHROME_INSET as jo,RADIUS as z,FONT as L,CLR as h,sevColor as gn,MODE_LABELS as Vo,BIN_LEGEND_MODES as hn,STACKED_MODES as be,Z_ABOVE as bn,applyOverlayZ as No,getTooltip as zo,hideTooltip as yn,createToolbarHelpers as _o,buildModeMenuEl as Go,openDetachWindow as Ko,openFloatingWindow as qo,openModal as Uo,openReportModal as Xo,copyWmapThemeTokens as Yo,syncWmapPopupTheme as Zo,openUserGuideWindow as Qo,makePaletteBtn as Jo,makeLogScaleBtn as ei,makeLegendStyleBtn as ti,makeOverlaysBtn as ni,makeOrientationBtn as oi,menuLayerFor as wn,saveImageBlob as ii,markMenuTrigger as Ae,wireMenuA11y as vn,wireExpandToggle as xn,wireTooltip as Cn,requestedPassFailDisplay as Sn,overlayMenuRows as ai,anyOverlayActive as li,logWmapVersionOnce as si,buildDataModeEntries as ri,metadataKeyHasData as di,metadataModeEntry as ci}from"./toolbar.js";import{waferDisplayLabel as Qe,waferIdentityLabel as Mn}from"../core/waferLabel.js";import{metadataDisplayValue as ui}from"../core/metadata.js";import{withExportContext as fi}from"./exportName.js";import{sortBinsForDisplay as pi}from"../stats/binPareto.js";import{diePassStatus as mi}from"../core/dies.js";import{aggregateValues as gi,aggregateBinCounts as Dn}from"../core/aggregates.js";import{renderWaferMap as hi,renderWaferMapCard as kn,toPublicViewOptions as En}from"./renderWaferMap.js";import{hasDrilldownTargets as bi,waferPopulation as yi}from"./chartPopulation.js";import{classifyChanged as wi,COLOR_KEYS as vi}from"./renderWaferMap.js";import{buildWaferMap as xi,getTestPassStatus as Bn,isParametricTest as Ct,getDieTestValue as Ci}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Je}from"../stats/analyzeWaferMap.js";import{collectWarnings as Si,buildWarningsMenuEl as Mi,severityOf as Di}from"./warnings.js";import{compareNatural as St,arrayEqual as On}from"../core/utils.js";import{createSummaryPanelEl as Mt,buildMetadataStripRow as ki,buildCompactMetadataRows as Tn,metadataEntries as Ln,renderLotSummaryContentSteps as Ei,reportMapsFromItems as Bi}from"./summaryPanel.js";import{renderLotReportHtml as Oi}from"../stats/renderSummaryReport.js";import{prettyKey as Ti}from"../stats/facets.js";import{testLabel as Li,markedTestLabel as Ri,derivedFields as Ii}from"../renderer/testLabel.js";import{mergeTestDefs as Wi}from"../stats/mergeTestDefs.js";import{getDieKey as $i,hasPosition as Ai}from"../core/dies.js";import{runChunked as Pi}from"./chunked.js";function Rn(f){if(typeof f!="number"||!Number.isFinite(f))return;const C=Math.round(f);return C>=1?C:void 0}const Dt=12;function Fi(f,C,p){let A=C;if(C.length>Dt){const k=C.slice(0,Dt-1),I=C.slice(Dt-1),H=I.reduce((X,ie)=>X+ie.count,0);A=[...k,{color:h.label,count:H,label:`Other (${I.length} bins)`}]}const D=f.createElement("div");Object.assign(D.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:z.control,overflow:"hidden",border:`1px solid ${h.menuBorder}`,boxSizing:"border-box",marginTop:w.xs,flexShrink:"0"}),D.setAttribute("role","img"),D.setAttribute("aria-label",`Population split: ${A.map(k=>`${k.label} ${et(k.count/p*100)}`).join(", ")}`);for(const k of A){const I=k.count/p*100,H=f.createElement("div");Object.assign(H.style,{flex:`${I} 1 0`,minWidth:I>0?"2px":"0",background:k.color}),Cn(H,`${k.label} \xB7 ${k.count.toLocaleString()} dies \xB7 ${et(I)}`),D.appendChild(H)}return D}function et(f){return f>0&&f<.1?"<0.1%":`${f.toFixed(1)}%`}function In(f,C,p){const A=new Map;let D=0,k=0;for(const I of f){const H=p?new Set(p(I)):void 0;for(const X of I.dies){if(X.partial||X.edgeExcluded)continue;const ie=C(X);ie!==void 0&&(A.set(ie,(A.get(ie)??0)+1),D++,H&&mi(X,H)&&k++)}}return{counts:A,total:D,pass:k}}function Wn(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 ${h.iconActive}`:`1px solid ${h.menuBorder}`,borderRadius:z.control,boxSizing:"border-box"});const D=f.ownerDocument.createElement("span");if(D.textContent=C.label,Object.assign(D.style,{fontWeight:C.isActive?"700":"400",color:C.isActive?h.iconActive:h.text,whiteSpace:"nowrap"}),p.appendChild(A),p.appendChild(D),C.count!==void 0){const k=f.ownerDocument.createElement("span");if(k.textContent=C.count.toLocaleString(),Object.assign(k.style,{color:C.isActive?h.iconActive:h.text,fontWeight:C.isActive?"700":"400",whiteSpace:"nowrap"}),p.appendChild(k),C.percent!==void 0){const I=f.ownerDocument.createElement("span");I.textContent=et(C.percent),Object.assign(I.style,{color:h.label,whiteSpace:"nowrap"}),p.appendChild(I)}}p.setAttribute("role","button"),p.setAttribute("aria-pressed",C.isActive?"true":"false"),p.tabIndex=0,p.addEventListener("mouseenter",()=>{p.style.background=h.bgHover}),p.addEventListener("mouseleave",()=>{p.style.background="transparent"}),p.addEventListener("focus",()=>{p.style.background=h.bgHover}),p.addEventListener("blur",()=>{p.style.background="transparent"}),p.addEventListener("click",C.onClick),p.addEventListener("keydown",k=>{(k.key==="Enter"||k.key===" ")&&(k.preventDefault(),C.onClick())}),f.appendChild(p)}export function renderWaferGallery(f,C,p={}){si();const A=6;let D=Rn(p.columns);const k=p.showHelpButton??!1,I=p.userGuideExtension,H=p.insights?.enabled??!1,X=p.insights?.sweeps?{sweeps:p.insights.sweeps}:void 0,ie=No(p.zIndex),re=p.summaryPanel,$n=e=>[...Io(e)],kt=()=>v.flatMap(e=>e?[e.ringCount??4]:[]),tt=()=>kt()[0]??4;function An(e){const t=[...new Set(e)].sort((n,o)=>n-o);return t.length<2?null:{code:"ring-count-mixed",severity:"warning",message:`These wafers were built with different ring counts (${t.join(", ")}). Each card and each wafer's findings use their own; the lot's ring yield in the Summary panel, report and Insights uses ${e[0]} rings.`}}let V=p.lotStatsSummary,ye=p.viewOptions?.legendPosition??"default",Pe=p.perCardLegend??!1;function we(){const e=c.plotMode??"hardBin";return hn.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 Et(){const e=Pe||we()!==null;for(const t of S)t&&t.setOptions({showLegend:e})}let c={plotMode:"hardBin",showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...p.viewOptions},S=[],ae=[],de=[],R=[];const Fe=fi(()=>{const e=R.filter(n=>n!=null),t=[...new Set(e.map(n=>ui(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort(St);return{prefix:p.downloadFilename,lots:t,...e.length===1?{wafer:Mn(e[0])}:{waferCount:e.length}}},p.onSaveImage,p.onSaveText);let v=C.map(e=>typeof e=="function"?null:e);function Bt(){return Wi(v)}function ve(){if(v.some(e=>e?.testDefs?.length))return Bt().defs}let xe=0,He=0;const _=new Map;let Pn=0,P=null,Ce=null,Ot=new Set,b=null,Fn={};function Tt(e){return v[e]?.statsSummary??V?.perWafer.find(t=>t.waferIndex===e)?.summary}function nt(){return!!(v.some(e=>e?.statsSummary?.findings.length)||V?.perWafer.some(e=>e.summary.findings.length))}const Hn=zo(),ce=_o(Hn),{makeBtn:Q,setActive:Se,makeSep:G,makeMenuRow:jn,makeMenuSection:Vn,makeDropdown:Lt,closeOpenMenu:je,getOpenMenu:Me,setOpenMenu:De}=ce;f.ownerDocument.addEventListener("click",je,!0);const Rt=()=>yn();window.addEventListener("blur",Rt);let It=p.findingsNotice;function Wt(e){Ot=new Set(e);const t=[...$.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,d)=>{const l=Ot.has(d);o.style.outline=l?`3px solid ${h.findingHighlight}`:"",o.style.outlineOffset=l?"-3px":"",l&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function $t(){Wt([])}function At(){for(const e of S)e&&e.clearSelection()}function ot(e,t){const n=new Set(e),o=t??S.map((d,l)=>l);for(const d of o){const l=R[d],a=S[d];if(!l||!a)continue;const r=l.dies.filter(i=>n.has($i(i)));a.setSelection(r)}}function Nn(){const e=[];for(let t=0;t<v.length;t++){const n=v[t];if(!n)continue;const o=Tt(t)?.findings??[];o.length&&e.push({index:t,item:n,unusualCount:o.filter(d=>d.severity==="unusual").length,notableCount:o.filter(d=>d.severity==="notable").length,totalCount:o.length})}return e}function zn(e){const t=R[e]??v[e];t&&Ie(e,t)}function _n(e){const t=Tt(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 Gn(){Xo(Oi(Bi(v,Wo,tt())),{anchor:f})}function Kn(){if(!b)return;b.innerHTML="";const e=Nn();if(v.length>0){const n=f.ownerDocument.createElement("div"),o=e.length,d=v.filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${d} wafers`:`${o} of ${d} wafer${d===1?"":"s"} with findings`,Object.assign(n.style,{fontSize:L.body,color:h.label,marginBottom:w.md}),b.appendChild(n)}if(e.length>0){const n=f.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...Ho("outlined"),marginBottom:w.lg,display:"block",width:"100%",textAlign:"left"}),xt(n),n.addEventListener("click",Gn),b.appendChild(n)}if(e.length===0){const n=f.ownerDocument.createElement("div");Object.assign(n.style,{color:h.icon,fontSize:L.body,padding:"4px 0"}),n.textContent="No findings on any wafer.",b.appendChild(n)}else for(const{index:n,item:o,unusualCount:d,notableCount:l,totalCount:a}of e){const r=d?"unusual":l?"notable":"info",i=d+l||a,s=f.ownerDocument.createElement("button");s.type="button",Object.assign(s.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:w.xs,border:"none",borderLeft:`3px solid ${gn(r)}`,borderRadius:z.control,background:h.bgHover,cursor:"pointer",fontSize:L.body,textAlign:"left",boxSizing:"border-box"}),s.addEventListener("mouseover",()=>{s.style.background=h.bgActive}),s.addEventListener("mouseout",()=>{s.style.background=h.bgHover});const u=f.ownerDocument.createElement("span");u.textContent=Qe(o,n),Object.assign(u.style,{color:h.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const m=f.ownerDocument.createElement("span");m.textContent=String(i),s.setAttribute("aria-label",`${Qe(o,n)} \u2014 ${i} finding${i===1?"":"s"}${d?`, ${d} unusual`:""} \u2014 view wafer`),Object.assign(m.style,{marginLeft:w.sm,flexShrink:"0",background:gn(r),color:"#fff",borderRadius:z.container,padding:"1px 5px",fontSize:L.body,fontWeight:"600"}),s.appendChild(u),s.appendChild(m),s.addEventListener("click",()=>Ie(n,o)),b.appendChild(s)}const t=f.ownerDocument.createElement("div");t.style.height="12px",b.appendChild(t)}let ue=null,ke=null;function N(){if(b)if(ue?.cancel(),ue=null,V){const e=Ye(v.map(n=>n?.hbinDefs)),t=Ye(v.map(n=>n?.sbinDefs));ue=Pi(Ei(b,{lotSummary:V,items:v,hbinDefs:e.length?e:void 0,sbinDefs:t.length?t:void 0,testDefs:ve(),ringCount:tt(),binColors:c.binColors,plotMode:c.plotMode??"hardBin",fallbackFormat:c.fallbackFormat,activeFindingId:Ce,warnings:p.warnings?.display??!0?J:[],findingsFilter:Fn,findingsNotice:It,onFindingsFilterChange:N,onSaveText:Fe.onSaveText,onFindingClick:(n,o)=>{Ce===n.id?it():Un(n,o),N()},onWaferClick:zn,findingsFor:_n,dieListOptions:p.dieList}),{onDone:()=>{const n=ke;ke=null,n?.()}})}else Kn()}function qn(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}function Pt(e){return[e.variable.kind,e.variable.index??"",e.variable.bin??"",e.comparison.family,e.comparison.left,e.effect.direction].join("|")}let Ve=[];function Ft(){if(Ve.length!==0){for(const e of Ve)S[e]?.setOptions({plotMode:c.plotMode,activeTest:c.activeTest});Ve=[]}}function it(){Ce=null,$t(),At(),Ft(),T({highlightBin:void 0},{fireCallback:!1})}function Un(e,t){if(Ce===e.id){it();return}Ce=e.id,t.style.background=h.bgActive,t.style.fontWeight="600",Ft();const{kind:n,index:o}=e.variable;if(n==="test"){const l=o??0,a=ve();if(a===void 0||a.some(i=>i.testNumber===l))T({plotMode:"value",activeTest:l,highlightBin:void 0},{fireCallback:!1});else{T({highlightBin:void 0},{fireCallback:!1});const s=be.has(c.plotMode??"hardBin")?null:qn(e);if(s){for(const u of s)S[u]?.setOptions({plotMode:"value",activeTest:l});Ve=[...s]}}}else n==="softBin"?T({plotMode:"softBin",highlightBin:void 0},{fireCallback:!1}):T({plotMode:"hardBin",highlightBin:void 0},{fireCallback:!1});$t(),At();const d=e.highlight;if(d.kind==="wafer"){Wt(d.waferIndices);const l=Pt(e);for(const a of d.waferIndices){const s=R[a]?.statsSummary?.findings.find(u=>Pt(u)===l)?.highlight?.dieKeys;s?.length&&ot(s,[a])}}else d.kind==="bin"?d.dieKeys?.length&&ot(d.dieKeys):(d.kind==="region"||d.kind==="dies")&&d.dieKeys?.length&&ot(d.dieKeys)}function le(){if(!P)return;const e=!!b;P.style.display=(V||nt())&&e&&!Te?"flex":"none";const t=b?b.style.display!=="none":!1;(V?.hasNotableFindings||v.some(o=>o?.statsSummary?.hasNotableFindings))&&!t?P.style.color=h.findingIndicator:P.dataset.active||(P.style.color=h.icon)}const W=f.ownerDocument.createElement("div");W.dataset.wmapToolbar="gallery",Object.assign(W.style,{flexShrink:"0",marginLeft:"auto",display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:h.menuBg,border:`1px solid ${h.menuBorder}`,borderRadius:z.control,padding:"0",boxShadow:$e.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const Ht=()=>{const e=Me();e&&(e.remove(),De(null)),Ae(Y,!1)},Y=Q("mode","Plot mode",()=>{if(Me()){Ht();return}const e=v.flatMap(y=>y?.dies??[]),t=ve(),{testEntries:n,binEntries:o,stackedEntries:d}=ri(e,t,{includeStacked:!0}),l=v.filter(Boolean).length,a=y=>{if(y===void 0)return l;let B=0;for(const j of v)j?.dies?.some(U=>Bn(U,y)!==void 0||U.testValues?.[y]!==void 0)&&B++;return B},r=l<2?n:n.map(y=>{const B=a(y.activeTest);return B===l?y:{...y,label:`${y.label} \u2014 ${B} of ${l} wafers`}}),i=c.plotMode??"hardBin",s=c.activeTest??0;function u(y){return y.plotMode!==i?!1:y.plotMode==="value"?s===(y.activeTest??0):y.plotMode==="metadata"?c.activeMetadataKey===y.activeMetadataKey:!0}function m(y,B){y.activeTest!==void 0?T({plotMode:"value",activeTest:y.activeTest,activeMetadataKey:void 0,logScale:y.logScale}):y.activeMetadataKey!==void 0?T({plotMode:y.plotMode,activeTest:void 0,activeMetadataKey:y.activeMetadataKey,passFailDisplay:"off"}):T({plotMode:y.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),B.remove(),De(null),Ae(Y,!1)}const M=new Set,E=v.flatMap(y=>y?.metadataFields??[]).filter(y=>!M.has(y.key)&&M.add(y.key)).filter(y=>di(e,y.key)).map(ci),x=Go(Y.getBoundingClientRect(),r,o,d,u,m,{makeMenuRow:jn,makeMenuSection:Vn},i,Y.ownerDocument.defaultView??window,E);wn(Y).appendChild(x),De(x),Ae(Y,!0),vn(x,Y,Ht)});Ae(Y,!1);const Xn=()=>R.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:Yn,sync:jt}=Jo(ce,()=>({...c,plotMode:c.plotMode??"hardBin"}),Xn,e=>T(e));jt();const Zn=C.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function Ne(){const e=ve(),{testNumber:t}=Do(c.activeTest??0,e);return{testNumber:t,td:ko(e,t)}}function Vt(){if((c.plotMode??"hardBin")!=="value")return!1;const{td:e}=Ne();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function Ee(){if((c.plotMode??"hardBin")!=="value")return!1;const{td:e}=Ne();return e!==void 0&&!Ct(e)}function Qn(){if((c.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=Ne();return v.some(n=>n?.dies?.some(o=>Bn(o,e,t)!==void 0))}function Jn(e,t){if(!t||!Ct(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((Sn(c)==="spec"&&n?"spec":c.colorbarRangeMode??"spec")==="spec"&&n)return;let l=1/0,a=-1/0;for(const r of v)if(r)for(const i of r.dies){const s=Ci(i,e);s!==void 0&&(s<l&&(l=s),s>a&&(a=s))}if(isFinite(l))return l===a?[l,l+1]:[l,a]}function at(e,t,n){const o=c[e];if(o===t||o!=null&&t!=null&&n(o,t))return!1;c={...c,[e]:t};for(const d of S)d&&d.setOptions({[e]:t});return!0}function Nt(){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 Eo(n.dies,e))t.add(o);return{key:e,values:[...t].sort(St)}}function lt(){at("metadataValueOrder",Nt(),(e,t)=>e.key===t.key&&On(e.values,t.values))}function st(){if((c.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=Ne(),n=Jn(e,t);at("valueRange",n?{test:e,range:n}:void 0,(d,l)=>{const a=s=>Array.isArray(s)?{test:void 0,range:s}:{test:s.test,range:s.range},r=a(d),i=a(l);return r.test===i.test&&On(r.range,i.range)})}let rt=!1;function eo(){if(rt)return;rt=!0,(f.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{rt=!1,st(),lt(),_t()})}let dt=!1;function to(){if(dt)return;dt=!0,(f.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{dt=!1,qe()})}let zt=[];function fe(){const{colors:e,mixedHardBins:t}=Oo(v.filter(n=>n!=null),{binColorScheme:c.binColorScheme,useDefinedBinColors:c.useDefinedBinColors});return zt=t,e}function _t(){at("binColors",fe(),Ro),Be()}const no=ni(ce,()=>ai(c,Zn,{functionalActive:Ee(),hasLimits:Vt()&&!Ee(),hasRecorded:Qn()&&!Ee(),binMode:(c.plotMode??"hardBin")==="hardBin"||(c.plotMode??"hardBin")==="softBin"},e=>T(e)),()=>li(c)),{btn:oo,sync:Gt}=ti(ce,()=>({plotMode:c.plotMode,legendPosition:ye}),e=>{ye=e;for(const t of S)t&&t.setOptions({legendPosition:ye})},{get:()=>Pe,set:e=>{Pe=e,Et()},blockedReason:we});Gt();const io=[{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"}],Kt=Lt("aggr","Aggregation method",()=>io,()=>c.aggregationMethod??"mean",e=>T({aggregationMethod:e}));function qt(){const e=c.plotMode==="stackedValues";Kt.style.display=e?"":"none"}qt();const{btn:ao,sync:Ut}=ei(ce,()=>({...c,functionalActive:Ee()}),e=>T(e));Ut();const ze=Q("specRange","Colorbar range: test limits",()=>{const e=c.colorbarRangeMode==="data"?"spec":"data";T({colorbarRangeMode:e})});function Xt(){const e=(c.plotMode??"hardBin")==="value"&&Vt()&&Sn(c)==="off"&&!Ee();ze.style.display=e?"":"none";const t=(c.colorbarRangeMode??"spec")==="spec";Se(ze,t),ze.ariaLabel=t?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"}Xt();const lo=oi(ce,()=>c,e=>T(e)),so=Q("downloadAll","Download gallery PNG",xo),ro=Lt("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"}],()=>D!=null?String(D):"auto",e=>ln(e==="auto"?void 0:Number(e))),O=f.ownerDocument.createElement("div");Object.assign(O.style,{display:"inline-flex",alignItems:"center",gap:"0"}),W.appendChild(O),O.appendChild(Y),O.appendChild(Yn),O.appendChild(Kt),O.appendChild(ao),O.appendChild(ze),O.appendChild(G()),O.appendChild(no),O.appendChild(G()),O.appendChild(oo),O.appendChild(G()),O.appendChild(lo),O.appendChild(G()),O.appendChild(ro),O.appendChild(G()),O.appendChild(so),(V||nt())&&(P=Q("findings","Summary panel",()=>{if(!b)return;const e=b.style.display!=="none";e||N(),b.style.display=e?"none":"flex",Se(P,!e),le()}),W.appendChild(G()),W.appendChild(P));let K=null,_e=null,J=[],Yt=!1;function Be(){const e=Si({lotStatsSummary:V,result:{warnings:[...v.flatMap(n=>n?.warnings??[]),...Bt().warnings]},extra:[c.binColors&&To(c.binColors,c.plotMode),Lo(zt),An(kt())].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||!Yt)&&(Yt=!0,p.warnings?.onWarning?.(e)),co()}function co(){if(!K||!_e)return;const e=J.length,t=e>0;if(K.style.display=t?"flex":"none",_e.style.display=t?"":"none",!t)return;const n=Di(J[0]),o=`${e} data ${e===1?"warning":"warnings"}`;K.style.color=n==="error"?h.errText:h.warnText,K.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(p.warnings?.display??!0)&&(_e=G(),K=Q("warning","Data warnings",()=>{const e=Me();if(je(new MouseEvent("click")),e)return;const t=Mi(K.getBoundingClientRect(),J,K.ownerDocument.defaultView??window);wn(f).appendChild(t),De(t),vn(t,K,()=>je(new MouseEvent("click")))}),Ae(K,!1),W.appendChild(_e),W.appendChild(K)),Be();let se=null;H&&(se=Q("analysis","Insights",()=>{Jt(!Te)}),se.dataset.wmapInsightsBtn="1",W.appendChild(G()),W.appendChild(se));function Zt(){import("./userGuideHtml.js").then(e=>Qo({buildWaferMap:xi,renderWaferMap:hi,renderWaferGallery,analyzeWaferMap:Je},e.USER_GUIDE_HTML,I,f))}k&&(W.appendChild(G()),W.appendChild(Q("help","User guide",()=>Zt())));const pe=f.ownerDocument.createElement("div");pe.dataset.wmapGalleryMeta="1",Object.assign(pe.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${w.sm} ${w.lg}`,fontSize:L.sub,lineHeight:Ze.none,boxSizing:"border-box"});const Ge=f.ownerDocument.createElement("div");Object.assign(Ge.style,{background:h.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:h.menuBg,border:`1px solid ${h.menuBorder}`,borderRadius:z.container,padding:`${w.sm} ${w.lg}`,marginBottom:w.lg,boxShadow:$e.panel,fontSize:L.body,lineHeight:Ze.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 me=null,Oe=null,Qt=null;function uo(){return H?me?Promise.resolve(me):(Qt??=import("./insightsTab.js").then(({createInsightsTab:e})=>(me=e({getItems:()=>v,getLotStats:()=>V,getBinColors:()=>c.binColors??fe(),getRingCount:tt,defaultView:p.insights?.defaultView,sweeps:p.insights?.sweeps,onRemoveSweeps:p.insights?.onRemoveSweeps,onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:Fe.onSaveImage,onSaveText:Fe.onSaveText,ownerDocument:f.ownerDocument,openWafer:(t,n,o)=>{const d=v[t];if(!d)return;let l=null;const a=Uo({title:n,onClose:()=>l?.destroy(),anchor:f});dn(a,n,d.wafer.metadata??void 0),l=ht(a.contentWrap,d,o)}}),Oe=me.el,Oe.style.display="none",f.appendChild(Oe),me)),Qt):Promise.resolve(null)}let Te=!1;function Jt(e){H&&(Te=e,Oe&&(Oe.style.display=e?"flex":"none"),q.style.display=e?"none":"flex",O.style.display=e?"none":"inline-flex",W.style.display="inline-flex",se&&(Se(se,e),se.innerHTML=e?We.wafer:We.analysis,se.ariaLabel=e?"Back to gallery view":"Insights"),le(),qe(),e&&uo().then(t=>{!t||!Te||(t.el.style.display="flex",t.render())}))}H&&p.insights?.defaultOpen&&queueMicrotask(()=>Jt(!0));const fo=4,ct=240,en=480,po=720,mo=1.25;let ge=en;function tn(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 l=o.wafer.radius*2*(fo/d),a=Math.ceil(l+t);(n==null||a>n)&&(n=a)}return n}function go(e){const t=tn(e);return t==null?ct:Math.min(ge,Math.max(ct,t))}function ho(e){const t=tn(e);if(t==null)return!1;const n=Math.min(po,Math.max(en,t));return n<=ge?!1:(ge=n,!0)}function ut(){return D!=null?"none":`${ge}px`}function nn(){const e=ut();for(const t of Array.from($.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let Ke=ct,on=0;function an(e){if(ho(e)&&nn(),D==null){const n=go(e);n>Ke&&(Ke=n)}pt()}function ln(e){D=Rn(e),nn(),pt()}function ft(e){return`repeat(${e}, minmax(0, ${D!=null?"1fr":`${ge}px`}))`}function sn(e){$.style.gridTemplateColumns!==e&&($.style.gridTemplateColumns=e)}function pt(){if(D!=null){sn(ft(D));return}const e=Math.max(1,on),t=12,n=$.clientWidth||0,o=l=>(n-t*(l-1))/l;let d=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const l=Math.min(ge,Ke*mo),a=r=>{let i=0;for(;i<e&&o(i+1)>=r;)i++;return i};d=a(l)||a(Ke)||1}sn(ft(d))}const $=f.ownerDocument.createElement("div");if(Object.assign($.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:ft(1),gap:w.xl,paddingLeft:oe,paddingRight:oe,justifyContent:"start",alignContent:"start",isolation:"isolate"}),re?.placement){const e=re.placement;b=Mt(e,oe,f.ownerDocument),b.style.maxHeight="calc(100vh - 80px)",b.style.position="sticky",b.style.top="8px",b.style.display="flex",b.style.flexDirection="column"}else if(V||nt()){const e=!!re?.defaultOpen;b=Mt("right",oe,f.ownerDocument),b.style.maxHeight="calc(100vh - 80px)",b.style.position="sticky",b.style.top="8px",b.style.flexDirection="column",b.style.display=e?"flex":"none",N()}le(),b?.style.display!=="none"&&P&&Se(P,!0),(re?.placement??"right")==="left"?(b&&q.appendChild(b),q.appendChild($)):(q.appendChild($),b&&q.appendChild(b));const Le=f.ownerDocument.createElement("div");Object.assign(Le.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:oe,paddingRight:oe,paddingTop:oe,zIndex:"1",background:h.menuBg}),Ge.appendChild(pe),Ge.appendChild(W),Le.appendChild(Ge),Le.appendChild(ee),f.appendChild(Le),f.appendChild(q);function qe(){ee.innerHTML="";const e=c.plotMode??"hardBin",t=!Te&&hn.has(e),n=R.filter(g=>g!=null),o=n.find(g=>g.isLotStack),d=ki(n.map(g=>({metadata:g.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0),l=e==="metadata",a=c.activeMetadataKey,r=t&&!l?In(n,g=>(e==="softBin"?g.sbin:g.hbin)??void 0,$n):{counts:new Map,total:0,pass:0},i=t&&!l?c.binColors??fe():void 0,s=i?e==="softBin"?i.pass.soft:i.pass.hard:new Set,u=pi(r.counts.entries(),s).map(([g])=>g),m=t&&l&&a?In(n,g=>Bo(g.metadata?.[a])):{counts:new Map,total:0,pass:0},M=l?Nt()?.values:void 0,E=t&&l?(M??[...m.counts.keys()].sort(St)).filter(g=>m.counts.has(g)):[];if(pe.innerHTML="",d&&pe.appendChild(d),pe.style.display=d?"flex":"none",!u.length&&!E.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 y=c.highlightBin,B=R.flatMap(g=>g?.metadataFields??[]).find(g=>g.key===a),j=l?B?.label??(a?Ti(a):"Metadata"):Vo[e],U=f.ownerDocument.createElement("span");if(U.textContent=j,Object.assign(U.style,{fontSize:L.body,fontWeight:"700",letterSpacing:Fo,textTransform:"uppercase",color:h.label,flexShrink:"0"}),x.appendChild(U),!l&&r.total>0){const g=r.pass,F=g/r.total*100,te=f.ownerDocument.createElement("span");te.textContent=`Yield ${et(F)}`,Object.assign(te.style,{fontSize:L.body,fontWeight:"700",color:h.value,whiteSpace:"nowrap",flexShrink:"0"});const ne=f.ownerDocument.createElement("span");ne.textContent=`${g.toLocaleString()} / ${r.total.toLocaleString()} dies`,Object.assign(ne.style,{fontSize:L.body,color:h.label,whiteSpace:"nowrap",flexShrink:"0"}),x.appendChild(te),x.appendChild(ne)}if(l){const g=c.highlightMetadataValue;E.forEach((F,te)=>{const ne=g===F,Xe=B?.values?.find(vt=>vt.value===F),So=Xe?.color??Ao(te),mn=m.counts.get(F)??0;Wn(x,{color:So,isActive:ne,label:Xe?.label??F,count:mn,percent:m.total>0?mn/m.total*100:void 0,onClick:()=>{const vt=c.highlightMetadataValue===F?void 0:F;T({highlightMetadataValue:vt})}})});return}const bt=e==="softBin"?R.flatMap(g=>g?.sbinDefs??[]):R.flatMap(g=>g?.hbinDefs??[]),un=new Set,yt=[];for(const g of bt)un.has(g.bin)||(un.add(g.bin),yt.push(g));const wt=yt.length>0?new Map(yt.map(g=>[g.bin,g])):null,fn=i??c.binColors??fe(),Co=e==="softBin"?fn.soft:fn.hard,pn=g=>Co.get(g)??$o;for(const g of u){const F=y===g,te=wt?.get(g),ne=r.counts.get(g)??0;Wn(x,{color:pn(g),isActive:F,label:te?.name?`${g} \xB7 ${te.name}`:`Bin ${g}`,count:ne,percent:r.total>0?ne/r.total*100:void 0,onClick:()=>{const Xe=c.highlightBin===g?void 0:g;T({highlightBin:Xe})}})}r.total>0&&u.length>1&&ee.appendChild(Fi(f.ownerDocument,[...r.counts.entries()].sort(([,g],[,F])=>F-g).map(([g,F])=>({color:pn(g),count:F,label:wt?.get(g)?.name?`${g} \xB7 ${wt.get(g).name}`:`Bin ${g}`})),r.total))}function Re(e){const t=v.filter(r=>r!==null);if(!t.length)return[];const n=t.map(r=>r.dies.filter(Ai)),o=t[0].wafer,d=t.length,l=o.metadata?{...o,metadata:(({wafer:r,waferId:i,...s})=>s)(o.metadata)}:o;function a(r,i){return{...r,stats:{...r.stats,isLotStack:!0,aggregationMethod:i,lotSize:d}}}if(e==="stackedValues"){const r=ve();let i=r?.filter(Ct);if(r!==void 0&&i?.length===0)return[];if(r?.length||(i=Mo(t.flatMap(m=>m.dies)).map(m=>({testNumber:m,name:Li(void 0,m)}))),!i?.length)return[];const s=c.aggregationMethod??"mean";return i.map(u=>{const m=gi(n,s,u.testNumber),M={testNumber:0,name:u.name,unit:u.unit,...Ii(u)};return{wafer:l,dies:m,testDefs:[M],label:`${Ri(u,u.testNumber)} \xB7 ${s}`,isLotStack:!0,aggrMethod:s,lotSize:d,statsSummary:a(Je({wafer:l,dies:m,testDefs:[M]},{testNumbers:[0]}),s)}})}if(e==="stackedBins"){let r=Ye(t.map(i=>i?.hbinDefs));return(!r||r.length===0)&&(r=[...new Set(t.flatMap(s=>s.dies.map(u=>u.hbin).filter(u=>u!=null)))].sort((s,u)=>s-u).map(s=>({bin:s,name:`Bin ${s}`}))),r.map(i=>{const s=Dn(n,i.bin,"hard"),u=[{bin:i.bin,name:i.name}];return{wafer:l,dies:s,hbinDefs:u,label:`${i.bin} \xB7 ${i.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:d,statsSummary:a(Je({wafer:l,dies:s,hbinDefs:u}),"countBin")}})}if(e==="stackedSoftBins"){let r=Ye(t.map(i=>i?.sbinDefs));return(!r||r.length===0)&&(r=[...new Set(t.flatMap(s=>s.dies.map(u=>u.sbin).filter(u=>u!=null)))].sort((s,u)=>s-u).map(s=>({bin:s,name:`Bin ${s}`}))),r.map(i=>{const s=Dn(n,i.bin,"soft"),u=[{bin:i.bin,name:i.name}];return{wafer:l,dies:s,sbinDefs:u,label:`${i.bin} \xB7 ${i.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:d,statsSummary:a(Je({wafer:l,dies:s,sbinDefs:u}),"countBin")}})}return t}function mt(e){const t=v.length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:c.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}function T(e,{fireCallback:t=!0}={}){const n=Object.keys(e),o=c.plotMode,d=we()!==null;c={...c,...e};const l=c.plotMode,a=be.has(l),r=o!==void 0&&be.has(o),i=He>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const u=fe();c={...c,binColors:u},e={...e,binColors:u}}if(e.plotMode!==void 0)if(a){const u=mt(l);if(c={...c,...u},i)for(const m of S)m&&m.setOptions(e);else Z(Re(l))}else if(r){const{valueRange:u,lotSize:m,aggregationMethod:M,...E}=c;if(c=E,i)for(const x of S)x&&x.setOptions(e);else Z(v.filter(x=>x!==null))}else for(const u of S)u&&u.setOptions(e);else if(e.aggregationMethod!==void 0&&l==="stackedValues")if(i)for(const u of S)u&&u.setOptions(e);else Z(Re("stackedValues"));else for(const u of S)u&&u.setOptions(e);we()!==null!==d&&Et(),qe(),qt(),Gt(),jt();const s=e.plotMode!==void 0&&e.plotMode!==o;(vi.some(u=>u in e)||s)&&N(),Be(),Ut(),Xt(),st(),lt(),t&&p.onViewOptionsChange?.(En(c),n,wi(n))}function rn(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:w.xs,flex:"1",minWidth:"0"});const d=e.createElement("span");d.textContent=t,Object.assign(d.style,{fontWeight:"700",fontSize:L.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(d);const l=Ln(n??{});let a=null;if(l.length>0){const r=e.createElement("span");Object.assign(r.style,{fontSize:L.body,lineHeight:Ze.none,color:h.label,flexShrink:"0"}),r.textContent="\u25BE",o.appendChild(r),Object.assign(o.style,{cursor:"pointer",borderRadius:z.control}),o.addEventListener("mouseenter",()=>{o.style.background=h.bgHover}),o.addEventListener("mouseleave",()=>{o.style.background="none"}),a=e.createElement("div"),a.dataset.wmapCardMetaPanel="1",Object.assign(a.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:bn,background:h.menuBg,borderBottom:`1px solid ${h.menuBorder}`,boxShadow:$e.menu,padding:`${w.md} ${w.lg}`,fontSize:L.body,display:"none"});const i=Tn(n??{});i&&a.appendChild(i),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`Wafer info for ${t||"this card"}. Click to expand.`),xn(o,s=>{r.textContent=s?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(s)),a&&(a.style.display=s?"block":"none")})}return{wrap:o,metaPanel:a}}function dn(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]"),d=Ln(n??{});if(!o||d.length===0)return;const l=o.parentElement,a=f.ownerDocument.createElement("div");Object.assign(a.style,{display:"flex",alignItems:"center",gap:w.xs,flex:"1",minWidth:"0",cursor:"pointer"}),xt(a,"bare"),l?.insertBefore(a,o),a.appendChild(o);const r=f.ownerDocument.createElement("span");Object.assign(r.style,{fontSize:L.body,lineHeight:Ze.none,color:h.label,flexShrink:"0"}),r.textContent="\u25BE",a.appendChild(r);const i=f.ownerDocument.createElement("div");i.dataset.wmapCardMetaPanel="1",Object.assign(i.style,{position:"absolute",top:"0",left:"0",right:"0",zIndex:bn,background:h.menuBg,borderBottom:`1px solid ${h.menuBorder}`,boxShadow:$e.menu,padding:`${w.md} ${w.lg}`,fontSize:L.body,display:"none"});const s=Tn(n??{});s&&i.appendChild(s),e.contentWrap.style.position="relative",e.contentWrap.appendChild(i),a.setAttribute("aria-expanded","false"),a.setAttribute("aria-label",`Wafer info for ${t}. Click to expand.`),xn(a,u=>{r.textContent=u?"\u25B4":"\u25BE",a.setAttribute("aria-expanded",String(u)),i.style.display=u?"block":"none"})}function gt(e,t,n){const o=f.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:h.menuBg,border:`1px solid ${h.menuBorder}`,borderRadius:z.container,boxShadow:$e.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:ut(),maxHeight:ut()});const d=f.ownerDocument.createElement("div");Object.assign(d.style,{display:"flex",alignItems:"center",padding:`${w.md} ${w.lg} ${w.sm}`,borderBottom:`1px solid ${h.menuBorder}`,flexShrink:"0",gap:w.sm});const{wrap:l,metaPanel:a}=rn(document,Qe(e,t),e.wafer.metadata??void 0);d.appendChild(l);const r=f.ownerDocument.createElement("button");r.dataset.wmapExpandBtn="1",r.setAttribute("aria-label","Open full view"),Cn(r),r.innerHTML=We.expand,Object.assign(r.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${h.menuBorder}`,borderRadius:z.control,background:h.panelBg,color:h.label,padding:w.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),xt(r),d.appendChild(r),o.appendChild(d);const i=f.ownerDocument.createElement("div");Object.assign(i.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(i),a&&i.appendChild(a),$.appendChild(o),o.addEventListener("contextmenu",M=>{if(M.defaultPrevented)return;const E=p.insights?.sweeps;if(!bi(e.testDefs,E))return;M.preventDefault();const x=e.viewOptions?{...c,...e.viewOptions}:c,y=yi(e.dies,{waferLabel:Mn(e),testDefs:e.testDefs,isLotStack:e.isLotStack,activeTest:x.plotMode==="value"?x.activeTest:void 0,waferIndex:t}),B={x:M.clientX,y:M.clientY};import("./drilldown.js").then(({openDrilldownMenu:j})=>{o.isConnected&&j(B,o,y,{sweeps:E,onSaveImage:m.getSaveImageHook()})})});const s=Pe||we()!==null,u=e.viewOptions?{...c,...e.viewOptions}:c,m=kn(i,e,{viewOptions:{...u,showLegend:s,legendPosition:ye},showTooltip:!0,padding:A,statsSummary:e.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,downloadFilename:p.downloadFilename,onClick:e.onClick,onSelect:e.onSelect,insights:X,onExpand:()=>Ie(t,e),showIdentity:!1,chromeInset:jo});return m.setViewControlsVisible(!1),m.setSummaryVisible(!1),r.onclick=()=>Ie(t,e),{card:o,ctrl:m,canvasWrapper:i,expandBtn:r}}function bo(e){const t=de[e];if(!t)return;const n=[..._.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=We.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>wo(n.id)):(t.innerHTML=We.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>Ie(e,R[e]))}function Z(e){vo(),Me()?.remove(),De(null),it(),R=[];for(const i of S)i&&i.destroy();S=[],ae=[],de=[],He=0,$.innerHTML="",on=e.length,an(e.map(i=>typeof i=="function"?null:i));const t=[];for(let i=0;i<e.length;i++){const s=e[i];if(typeof s=="function"){const u=f.ownerDocument.createElement("div");u.className="wmap-gallery-card",Object.assign(u.style,{background:h.menuBg,border:`1px solid ${h.menuBorder}`,borderRadius:z.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const m=f.ownerDocument.createElement("span");m.textContent="\u2026",Object.assign(m.style,{color:h.label,fontSize:"18px"}),u.appendChild(m),$.appendChild(u),R.push(null),S.push(null),ae.push(null),de.push(null),t.push({index:i,factory:s,placeholder:u}),He++}else{const{ctrl:u,canvasWrapper:m,expandBtn:M}=gt(s,i,e.length);R.push(s),S.push(u),ae.push(m),de.push(M)}}_t(),qe(),st(),lt();const n=++xe,o=()=>{setTimeout(()=>{n===xe&&p.onItemsResolved?.()},0)},d=i=>{setTimeout(()=>{n===xe&&p.onItemResolved?.(i,e.length)},0)};let l=e.length-t.length;l>0&&d(l);let a=0;function r(){if(n!==xe)return;if(a>=t.length){if(be.has(c.plotMode)){const B=c.plotMode;Z(Re(B));return}ke=o,N(),ue||(ke=null,o());return}const{index:i,factory:s,placeholder:u}=t[a++],m=s();R[i]=m,v[i]=m,an([m]);const{card:M,ctrl:E,canvasWrapper:x,expandBtn:y}=gt(m,i,e.length);S[i]=E,ae[i]=x,de[i]=y,He--,u.replaceWith(M),d(++l),to(),eo(),!b&&!re?.placement&&m.statsSummary?.findings.length&&(b=Mt("right",oe,f.ownerDocument),b.style.maxHeight="calc(100vh - 80px)",b.style.position="sticky",b.style.top="8px",b.style.flexDirection="column",b.style.display="none",(re?.placement??"right")==="left"?q.insertBefore(b,$):q.appendChild(b),N(),P||(P=Q("findings","Summary panel",()=>{if(!b)return;const j=b.style.display!=="none";j||N(),b.style.display=j?"none":"flex",Se(P,!j),le()}),W.appendChild(G()),W.appendChild(P)),le()),le(),setTimeout(r,0)}t.length>0?setTimeout(r,0):o()}if(be.has(c.plotMode)&&v.length>0){const e=mt(c.plotMode);c={...c,...e},Z(Re(c.plotMode))}else Z(C);Be();let he=0;const cn=new(f.ownerDocument.defaultView??window).ResizeObserver(()=>{if(he)return;he=(f.ownerDocument.defaultView??window).requestAnimationFrame(()=>{he=0,D==null&&pt()})});cn.observe($),b&&N();function yo(e,t){const n=ae[e];if(!n)return;n.innerHTML="",Object.assign(n.style,{alignItems:"center",justifyContent:"center"});const o=f.ownerDocument.createElement("span");o.textContent=t?"Opened in its own window":"Opened in the wafer viewer",Object.assign(o.style,{color:h.label,fontSize:L.body,textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function Ie(e,t){for(const a of _.values())if(a.cardIndex===e)return;const n=Qe(t,e),o=Pn++,d=S[e]?.getOptions(),l=Ko(n);if(l){const a=l.document;a.title=n,Object.assign(a.documentElement.style,{height:"100%"}),Object.assign(a.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:L.family}),Yo(f,a.documentElement);const r=Zo(f,a.documentElement,()=>x.setOptions({})),i=a.createElement("div");i.dataset.wmapWindowBanner="1",i.textContent=n,Object.assign(i.style,{display:"none",padding:`${w.sm} ${w.xl}`,fontSize:L.body,fontWeight:"700",background:h.warnBg,color:h.warnText,borderBottom:`1px solid ${h.warnBorder}`,flexShrink:"0"}),a.body.appendChild(i);const s=a.createElement("div");Object.assign(s.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),a.body.appendChild(s);const{wrap:u,metaPanel:m}=rn(a,n,t.wafer.metadata??void 0),M=a.createElement("div");Object.assign(M.style,{display:"flex",alignItems:"center",padding:`${w.md} ${w.lg} ${w.sm}`,borderBottom:`1px solid ${h.menuBorder}`,flexShrink:"0",gap:w.sm}),M.appendChild(u),s.appendChild(M);const E=a.createElement("div");Object.assign(E.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),m&&E.appendChild(m),s.appendChild(E);const x=ht(E,t,void 0,d),y=setInterval(()=>{l.closed&&Ue(o)},400);l.addEventListener("pagehide",()=>Ue(o)),_.set(o,{id:o,ctrl:x,cardIndex:e,label:n,closePollId:y,stopThemeSync:r,close:()=>{l.closed||l.close()},setTitle:B=>{a.title=B,i.textContent=B,i.style.display="block"}})}else{const a=qo({title:n,onClose:()=>Ue(o),anchor:f});a.contentWrap.style.flexDirection="column",dn(a,n,t.wafer.metadata??void 0);const r=ht(a.contentWrap,t,void 0,d);_.set(o,{id:o,ctrl:r,cardIndex:e,label:n,closePollId:null,close:()=>a.close(),setTitle:i=>{const s=a.box.querySelector("[data-wmap-window-title]");s&&(s.textContent=i,s.title=i)}})}S[e]?.destroy(),S[e]=null,yo(e,l!==null),bo(e)}function ht(e,t,n,o){const d=t.viewOptions?{...c,...t.viewOptions}:c,l=o?{...d,...o}:d,r={...n!==void 0?{...l,plotMode:"value",activeTest:n}:l,showLegend:!0,legendPosition:ye},i=kn(e,t,{viewOptions:r,showTooltip:!0,padding:A,statsSummary:t.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,downloadFilename:p.downloadFilename,onClick:t.onClick,onSelect:t.onSelect,insights:X,showExpandButton:!1,showIdentity:!1});return i.setViewControlsVisible(!0),i.setSummaryVisible(!0),i.setExpandVisible(!1),i}function Ue(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=R[n];if(!o)return;const{card:d,ctrl:l,canvasWrapper:a,expandBtn:r}=gt(o,n,R.length);ae[n]?.parentElement?.replaceWith(d),S[n]=l,ae[n]=a,de[n]=r}function wo(e){const t=_.get(e);t&&(t.close(),Ue(e))}function vo(){for(const e of _.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function xo(){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,l=e[0].height,a=8,r=(f.ownerDocument.defaultView??window).devicePixelRatio||1,i=Math.round(26*r),s=Math.round(12*r),u=f.ownerDocument.createElement("canvas");u.width=n*d+(n-1)*a,u.height=o*(l+i)+(o-1)*a;const m=u.getContext("2d"),M=Po($);m.fillStyle=M.background,m.fillRect(0,0,u.width,u.height),e.forEach((E,x)=>{const y=x%n,B=Math.floor(x/n),j=y*(d+a),U=B*(l+i+a),bt=E.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";m.fillStyle=M.surface,m.fillRect(j,U,d,i),m.fillStyle=M.text,m.font=`700 ${s}px system-ui, sans-serif`,m.textAlign="left",m.textBaseline="middle",m.fillText(bt,j+Math.round(10*r),U+i/2,d-Math.round(20*r)),m.drawImage(E,j,U+i)}),u.toBlob(E=>{if(!E)return;const x=S.find(y=>y!=null)?.getExportTitle();ii(E,["gallery",x].filter(Boolean).join(" "),Fe.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=mt(t);c={...c,...o},Z(Re(t))}else Z(e)},setOptions(e){T(e,{fireCallback:!1})},getOptions(){return En(c)},setFindingsNotice(e){It=e,N()},setColumns(e){ln(e)},getBinColors(){return c.binColors??fe()},setLotStatsSummary(e){V=e,Be(),b&&N(),le()},openUserGuide:Zt,destroy(){xe++,ue?.cancel(),ue=null,ke=null;for(const e of[..._.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();_.clear();for(const e of S)e&&e.destroy();S=[],Me()?.remove(),cn.disconnect(),he&&((f.ownerDocument.defaultView??window).cancelAnimationFrame(he),he=0),f.ownerDocument.removeEventListener("click",je,!0),window.removeEventListener("blur",Rt),ie(),yn(),Le.remove(),q.remove(),b?.remove(),me?.destroy()}}}
|
|
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()}}}
|
|
@@ -2,7 +2,7 @@ import type { PlotMode } from '../renderer/buildView.js';
|
|
|
2
2
|
import type { Die } from '../core/dies.js';
|
|
3
3
|
import { type ToCanvasOptions } from './toCanvas.js';
|
|
4
4
|
import type { WaferMapResult } from '../renderer/buildWaferMap.js';
|
|
5
|
-
import type { StatsSummary } from '../stats/types.js';
|
|
5
|
+
import type { StatsFinding, StatsSummary } from '../stats/types.js';
|
|
6
6
|
import { type SaveImageHandler, type SaveTextHandler, type UserGuideExtension } from './toolbar.js';
|
|
7
7
|
import type { SummaryPanelOptions, FindingsNotice } from './summaryPanel.js';
|
|
8
8
|
import { type WarningsOptions } from './warnings.js';
|
|
@@ -116,9 +116,9 @@ export interface WaferDisplayState {
|
|
|
116
116
|
* when the result has `metadataFields`.
|
|
117
117
|
*/
|
|
118
118
|
activeMetadataKey?: string;
|
|
119
|
-
highlightBin?: number;
|
|
120
|
-
/** Dim every die except
|
|
121
|
-
highlightMetadataValue?: string;
|
|
119
|
+
highlightBin?: number | number[];
|
|
120
|
+
/** Dim every die except these metadata values in `'metadata'` mode — the analogue of `highlightBin`. */
|
|
121
|
+
highlightMetadataValue?: string | string[];
|
|
122
122
|
/**
|
|
123
123
|
* Explicit value colour normalization range.
|
|
124
124
|
*
|
|
@@ -431,6 +431,14 @@ export interface CardRenderOptions extends Omit<RenderOptions, 'viewOptions'> {
|
|
|
431
431
|
chromeInset?: string;
|
|
432
432
|
/** Replaces the expand action for both the expand button and the E key. */
|
|
433
433
|
onExpand?: () => void;
|
|
434
|
+
/**
|
|
435
|
+
* Draw the canvas only while it is on screen (or near it). An off-screen card
|
|
436
|
+
* keeps its view up to date and is drawn when it scrolls into view, or by
|
|
437
|
+
* `drawPendingNow()` — which anything capturing the canvas (the gallery PNG,
|
|
438
|
+
* printing) must call first. For gallery grid cards: a large lot's gallery
|
|
439
|
+
* spent most of a mode switch drawing cards nobody could see.
|
|
440
|
+
*/
|
|
441
|
+
drawWhenVisible?: boolean;
|
|
434
442
|
}
|
|
435
443
|
/** @internal */
|
|
436
444
|
export interface CardController extends WaferMapController {
|
|
@@ -446,8 +454,13 @@ export interface CardController extends WaferMapController {
|
|
|
446
454
|
getExportTitle(): string;
|
|
447
455
|
/** This map's save hook, naming files for its own wafer — for a save the gallery starts on a card's behalf. */
|
|
448
456
|
getSaveImageHook(): SaveImageHandler;
|
|
457
|
+
/** Draw now if a `drawWhenVisible` card skipped drawing while off screen. */
|
|
458
|
+
drawPendingNow(): void;
|
|
449
459
|
}
|
|
450
460
|
/** @internal The public view of a card's options: everything but the gallery's shared state. */
|
|
461
|
+
/** The bin a finding is about — what the legend filter shows while the finding
|
|
462
|
+
* is active — or `undefined` for a yield, test or functional finding. */
|
|
463
|
+
export declare function findingBin(finding: StatsFinding): number | undefined;
|
|
451
464
|
export declare function toPublicViewOptions(opts: CardViewOptions): WaferViewOptions;
|
|
452
465
|
export type RenderableWaferMap = Pick<WaferMapResult, 'wafer' | 'dies'> & Partial<Omit<WaferMapResult, 'wafer' | 'dies'>>;
|
|
453
466
|
export declare function renderWaferMap(container: HTMLElement, result: RenderableWaferMap, options?: RenderOptions): WaferMapController;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{buildView as Pi,buildHoverText as Oi,findTestDef as ht,resolveTestNumber as _t,buildMapTitle as Ri}from"../renderer/buildView.js";import{drawMapCanvas as Ii,BIN_LEGEND_W as $n,BIN_LEGEND_W_COMPACT as Wi,BIN_LEGEND_ADAPT_COMPACT as Fi,BIN_LEGEND_ADAPT_FLOATING as Ai}from"./toCanvas.js";import{buildWaferMap as Hi,getTestPassStatus as zi,isParametricTest as $t}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Vi}from"../stats/analyzeWaferMap.js";import{SHADOW as Yi,LEADING as Gn,wireControlHover as Un,SPACE as A,EDGE_GUTTER as Xi,RADIUS as Zn,FONT as mt,CLR as x,applyOverlayZ as Ni,getTooltip as Qn,hideTooltip as yt,positionTooltip as qn,createToolbarHelpers as ji,buildModeMenuEl as Ki,openReparentedModal as _i,openUserGuideWindow as $i,makePaletteBtn as Gi,makeLogScaleBtn as Ui,makeLegendStyleBtn as Zi,makeOverlaysBtn as Qi,makeOrientationBtn as qi,menuLayerFor as Jn,saveImageBlob as Ji,markMenuTrigger as Qe,wireMenuA11y as ei,wireExpandToggle as eo,nextFrame as Gt,requestedPassFailDisplay as to,overlayMenuRows as no,anyOverlayActive as io,logWmapVersionOnce as oo,buildDataModeEntries as so,metadataKeyHasData as lo,metadataModeEntry as ao}from"./toolbar.js";import{waferIdentityLabel as ro}from"../core/waferLabel.js";import{metadataDisplayValue as co}from"../core/metadata.js";import{withExportContext as fo}from"./exportName.js";import{createSummaryPanelEl as Ut,wrapWithSummaryPanel as Zt,renderWaferSummaryContentSteps as po}from"./summaryPanel.js";import{runChunked as uo}from"./chunked.js";import{collectWarnings as go,buildWarningsMenuEl as ho,severityOf as mo}from"./warnings.js";import{ICONS as ti}from"./icons.js";import{hasDrilldownTargets as yo,selectionPopulation as bo,waferPopulation as vo}from"./chartPopulation.js";import{createIdentityHeader as xo,collapsedLabel as Qt}from"./identityHeader.js";import{getDieKey as fe,hasPosition as ni,isPositionedDie as wo}from"../core/dies.js";import{buildDieListSection as Co}from"./dieList.js";import{buildMaplessSummary as So}from"./maplessSummary.js";import{resolveBinColors as Mo,binColorWarning as Eo}from"../renderer/binColors.js";import{INPUT_DEFAULT_PASS_BINS as Do}from"../core/passBins.js";const ii=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(P){const m=P.some(p=>ii.has(p)),M=P.some(p=>!ii.has(p));return m&&M?"mixed":m?"preference":"state"}export function toPublicViewOptions(P){const{metadataValueOrder:m,binColors:M,lotSize:p,...k}=P;return k}export function renderWaferMap(P,m,M={}){return renderWaferMapCard(P,m,M)}export function renderWaferMapCard(P,m,M={}){oo();const p=P.ownerDocument,k=p.defaultView??window,qt=()=>q.label,Jt=()=>ro({label:qt(),wafer:V}),pe=fo(()=>{const e=co(V.metadata?.lot);return{prefix:M.downloadFilename,lots:e!==void 0?[e]:[],...q.isLotStack?{stackedWafers:h?.lotSize??!0}:{wafer:Jt()}}},M.onSaveImage,M.onSaveText);function en(){const e=h.plotMode==="softBin"||h.plotMode==="stackedSoftBins"?G:$,{primary:t,secondary:n}=Ri(h,c.fallbackFormat,e);return[t,q.isLotStack?"":n].filter(Boolean).join(" ")||"wafer-map"}k.getComputedStyle(P).position==="static"&&(P.style.position="relative");const oi=P.clientHeight;M.height!=null&&(P.style.height=typeof M.height=="number"?`${M.height}px`:M.height);const bt=m.dataCoverage?m.dataCoverage.unpositionedDies:m.dies.filter(e=>!ni(e)).length,Oe=(m.dataCoverage?m.dataCoverage.totalDies:m.dies.length-bt)===0&&bt>0,Re=p.createElement("div");Object.assign(Re.style,{display:"flex",flexDirection:"column",width:"100%",height:"100%"}),P.appendChild(Re);const Ce=p.createElement("div");Object.assign(Ce.style,{position:"relative",width:"100%",flex:"1 1 auto",minHeight:"0"});const ue=M.chromeInset??Xi,_=p.createElement("div");Object.assign(_.style,{display:"flex",alignItems:"stretch",gap:A.sm,background:x.canvasBg,paddingBottom:A.lg,paddingTop:ue,paddingLeft:ue,paddingRight:ue,flexShrink:"0",minWidth:"0"}),Re.appendChild(_),Re.appendChild(Ce);function Ie(){const e=[..._.children].some(t=>t.style.display!=="none");_.style.display=e?"flex":"none"}const S=p.createElement("div");Object.assign(S.style,{position:"relative",width:"100%",height:"100%"});const s=p.createElement("canvas");Object.assign(s.style,{width:"100%",height:"100%",display:"block"}),S.appendChild(s),Ce.appendChild(S);let qe=null;if(bt>0){let n=function(){if(t){const d=Co(e,m.testDefs,{...M.dieList,onSaveText:pe.onSaveText,waferMetadata:V.metadata,metadataFields:me,ownerDocument:p});if(d)return d}const o=ht(m.testDefs,c.activeTest??0),a=$t(o)?c.logScale??o?.logScale??!1:!1;return So(e,m.testDefs,{plotMode:c.plotMode??"hardBin",activeTest:c.activeTest,hbinDefs:$,sbinDefs:G,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",Un(a),Object.assign(a.style,{fontSize:mt.body,padding:`${A.xxs} ${A.sm}`,borderRadius:Zn.control,flexShrink:"0",border:`1px solid ${x.menuBorder}`,background:x.menuBg,color:x.text,cursor:"pointer"}),a.textContent=t?"View chart":"View die list",a.addEventListener("click",d=>{d.stopPropagation(),t=!t,a.textContent=t?"View chart":"View die list",o()}),a};const e=m.dies.filter(o=>!ni(o));let t=!1;if(Oe){const o=p.createElement("div");Object.assign(o.style,{position:"absolute",inset:"0",background:x.panelBg,padding:A.xl,boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",gap:A.md,zIndex:"1"});const a=p.createElement("div");Object.assign(a.style,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:A.md});const d=p.createElement("span");Object.assign(d.style,{fontSize:mt.body,color:x.label,lineHeight:Gn.base}),d.textContent="No die position data for this wafer.",a.appendChild(d);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),S.appendChild(o),qe=()=>{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:x.panelBg,borderTop:`1px solid ${x.menuBorder}`,fontSize:mt.body,color:x.text,cursor:"pointer",padding:`${A.xs} ${A.md}`,display:"flex",alignItems:"center",justifyContent:"space-between",gap:A.md}),Un(o,"bare");const a=p.createElement("span");a.textContent=`+${e.length} ${e.length===1?"die":"dies"} without position data`,o.appendChild(a);const d=p.createElement("span");d.textContent="\u25BE",Object.assign(d.style,{fontSize:mt.body,lineHeight:Gn.none,color:x.label,flexShrink:"0"}),o.appendChild(d),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`${e.length} dies without position data. Click to view.`);let l=null,r=null;eo(o,f=>{if(d.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:x.panelBg,borderTop:`1px solid ${x.menuBorder}`,padding:A.md,boxSizing:"border-box",display:"flex",flexDirection:"column",gap:A.md}),l.addEventListener("click",se=>se.stopPropagation());const y=p.createElement("div");Object.assign(y.style,{display:"flex",justifyContent:"flex-end"}),y.appendChild(i(()=>{r&&r.replaceChildren(n())})),l.appendChild(y),r=p.createElement("div"),Object.assign(r.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),r.appendChild(n()),l.appendChild(r),S.appendChild(l)}else l&&(l.remove(),l=null,r=null)}),S.appendChild(o),qe=()=>{r&&!t&&r.replaceChildren(n())}}}const{onHover:Je,onClick:si,onSelect:le,onViewOptionsChange:li,showTooltip:ai=!0,showToolbar:We=!0,showIdentity:tn=!0,summaryPanel:Fe,showHelpButton:nn=!1,userGuideExtension:ri,onExpand:on,showExpandButton:sn=!0,zIndex:di,insights:ge,warnings:ln,viewOptions:ci={},...Se}=M,Ae=ge?.enabled??!1,fi=.4,pi=20,et=[...m.passBins??Do],an=ln?.display??!0,ui=Ni(di);let ae=M.statsSummary,re=[],rn=!1,tt=null,dn=!1;function vt(){const e=go({result:m,statsSummary:ae,extra:tt?[tt]:[]}),t=e.length!==re.length||e.some((n,i)=>n.code!==re[i]?.code||n.message!==re[i]?.message);re=e,(t||!rn)&&(rn=!0,ln?.onWarning?.(e))}vt();let q=m,V=m.wafer,he=m.dies,w=new Set;const gi={sweeps:ge?.sweeps,onSaveImage:pe.onSaveImage},xt=()=>!Oe&&yo(U,ge?.sweeps);let cn=null,nt=null,it=!1,fn=!1,$=m.hbinDefs,G=m.sbinDefs,U=m.testDefs,me=m.metadataFields,pn=m.reticles?.length?m.reticles:void 0,un=m.reticleConfig,gn=m.view?.dataAxisFlip,wt=m.isLotStack??!1,Ct=m.aggrMethod,St=m.lotSize;const hi=We&&Ae;let Y=null,J=null,ee=null;tn&&(Y=xo(Qt(V.metadata??{},He())??"",V.metadata,{lotStack:He(),ownerDocument:p}),S.appendChild(Y.metaPanel),Y.metaPanel.style.visibility="visible",Y.isEmpty()||(J=hn(Y.wrap),_.insertBefore(J,_.firstChild),Ie()));function hn(e){const t=p.createElement("div");return Object.assign(t.style,{display:"flex",alignItems:"center",padding:`${A.sm} ${A.lg}`,flex:"1 1 auto",minWidth:"0",overflow:"hidden",gap:A.sm}),Object.assign(e.style,{flex:"1",minWidth:"0"}),t.appendChild(e),t}function He(){return wt?{lotSize:St??1,aggrMethod:Ct}:void 0}function mi(){if(!Y)return;Y.update(Qt(V.metadata??{},He())??"",V.metadata,He());const e=J?.isConnected??!1,t=!Y.isEmpty();!t&&e?(J.remove(),J=null):t&&!e&&(J=hn(Y.wrap),J.style.display="",_.insertBefore(J,_.firstChild),Ie())}const yi=[...$??[],...G??[]].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",...ci},X=null,te=!1,mn=null;function bi(){return Ae?X?Promise.resolve(X):(mn??=import("./insightsTab.js").then(({createInsightsTab:e})=>(X=e({getItems:()=>[{wafer:V,dies:he,hbinDefs:$,sbinDefs:G,testDefs:U,label:qt(),passBins:et,statsSummary:ae}],getBinColors:()=>h.binColors,getRingCount:()=>q.ringCount??4,onSaveImage:pe.onSaveImage,onSaveText:pe.onSaveText,defaultView:ge?.defaultView,sweeps:ge?.sweeps,onRemoveSweeps:ge?.onRemoveSweeps,showMetadataStrip:!1,contentInset:ue,backTab:hi?void 0:{label:"Map",onBack:()=>ze(!1)},onOpenGuide:nn&&!We?()=>Xt():void 0,focusTest:t=>{D({plotMode:"value",activeTest:t,highlightBin:void 0}),ze(!1)},ownerDocument:p}),Object.assign(X.el.style,{position:"absolute",inset:"0",background:x.canvasBg,overflowY:"auto",paddingTop:"0"}),X.el.style.display="none",Ce.appendChild(X.el),X)),mn):Promise.resolve(null)}let yn=0;const Mt=["wheel","touchstart","pointerdown","keydown"];function vi(e,t){if(t<=0)return;let n=!1;const i=[],o=()=>{n=!0;for(const d of i)k.clearTimeout(d);i.length=0;for(const d of Mt)e.removeEventListener(d,o)},a=()=>n||!te?!0:(e.scrollTop=t,e.scrollTop>=t);if(!a()){for(const d of Mt)e.addEventListener(d,o,{passive:!0,once:!0});for(const d of[0,50,150,300,600])i.push(k.setTimeout(()=>{a()},d));i.push(k.setTimeout(()=>{for(const d of Mt)e.removeEventListener(d,o)},700))}}function ze(e){if(!Ae)return;const t=te;te=e,X&&!e&&t&&(yn=X.el.scrollTop),X&&(X.el.style.display=e?"flex":"none"),S.style.visibility=e?"hidden":"",F&&(F.style.display=e||Oe?"none":"flex"),T&&(T.style.display=e?"none":"flex"),ee&&(ee.style.display=xe?"none":"flex"),ie&&(ie.style.display="flex"),J&&(J.style.display=""),Ie(),Y&&e&&Y.collapse(),rt(),H&&(H.innerHTML=e?ti.wafer:ti.analysis,H.ariaLabel=e?"Back to wafer view":"Insights"),e&&bi().then(n=>{!n||!te||(n.el.style.display="flex",n.render(),vi(n.el,yn))})}Ae&&ge?.defaultOpen&&queueMicrotask(()=>ze(!0));let h,bn,N=null,B=null,Et=[],Dt;function vn(e){Dt!==e&&(Dt=e,v())}let ye=null,kt=Se.legendOffset??{x:0,y:0},Ve=!1,Me=!1,Ye={x:0,y:0},Bt={x:0,y:0},be=!1,Ee=!1,j="pan",De={x:0,y:0},ot={x:0,y:0},O={x:0,y:0},R={x:0,y:0},Xe=!1,ke=!1;function Lt(){const e=c;h=Pi(V,he.filter(wo),{plotMode:e.plotMode,binColorScheme:e.binColorScheme,valueColorScheme:e.valueColorScheme,reverseValueScheme:e.reverseValueScheme,useDefinedBinColors:e.useDefinedBinColors,binColors:e.binColors??Mo(he,{passBins:et,binColorScheme:e.binColorScheme,hbinDefs:$,sbinDefs:G,useDefinedBinColors:e.useDefinedBinColors}),passBins:et,showDieLabels:e.showDieLabels,showRingBoundaries:e.showRingBoundaries,showQuadrantBoundaries:e.showQuadrantBoundaries,showReticle:e.showReticle,showXYIndicator:e.showXYIndicator,reticles:pn,ringCount:q.ringCount??4,highlightBin:e.highlightBin,highlightMetadataValue:e.highlightMetadataValue,activeTest:e.activeTest,activeMetadataKey:e.activeMetadataKey,testDefs:U,valueRange:e.valueRange,metadataValueOrder:e.metadataValueOrder,logScale:e.logScale,isLotStack:wt,aggregationMethod:Ct??e.aggregationMethod,lotSize:St??e.lotSize,dataAxisFlip:gn,colorbarRangeMode:e.colorbarRangeMode,passFailDisplay:e.passFailDisplay,fallbackFormat:e.fallbackFormat,interactiveTransform:{rotation:e.rotation??0,flipX:e.flipX??!1,flipY:e.flipY??!1}},{hbinDefs:$,sbinDefs:G,metadataFields:me}),bn=new Map(h.dies.map((n,i)=>[fe(n),i]));const t=e.binColors?null:Eo(h.binColors,h.plotMode);t?.message!==tt?.message&&(tt=t,vt(),dn&&Tt())}Lt();let Z=null,Be=null,st=null,xn=M.findingsNotice,xi={},I=null,de=null;function wi(e){const{kind:t,index:n}=e.variable;D(t==="test"?{plotMode:"value",activeTest:n??0,highlightBin:void 0}:t==="softBin"?{plotMode:"softBin",highlightBin:void 0}:{plotMode:"hardBin",highlightBin:void 0});const i=e.highlight;i.kind==="bin"?(Ft(i.dieKeys),D({highlightBin:i.bin})):(i.kind==="region"||i.kind==="dies")&&Ft(i.dieKeys)}const Ne=new Map;function wn(e){Ne.get(e)?.cancel(),Ne.delete(e);const t=uo(po(e,{wafer:V,dies:he,yieldSummary:q.yield,dataCoverage:q.dataCoverage,hbinDefs:$,sbinDefs:G,testDefs:U,statsSummary:ae,warnings:an?re:[],passBins:et,ringCount:q.ringCount??4,binColors:h.binColors,plotMode:c.plotMode??"hardBin",metadataShownElsewhere:tn,fallbackFormat:c.fallbackFormat,activeFindingId:st,findingsFilter:xi,findingsNotice:xn,onFindingsFilterChange:ve,onSaveText:pe.onSaveText,metadataFields:me,dieListOptions:M.dieList,onFindingClick:(n,i)=>{st===n.id?(st=null,Ft([]),D({highlightBin:void 0})):(st=n.id,wi(n)),ve()}}));t.done||Ne.set(e,t)}function ve(){Z&&wn(Z)}function je(){I&&wn(I)}if(Fe?.placement){const e=Fe.placement;Z=Ut(e,ue,p);const t=S.parentElement,n=S.nextSibling;Be=Zt(S,Z,e),t?.insertBefore(Be,n),ve()}else if(ae){const e=Fe?.defaultOpen??!We;I=Ut("right",ue,p),I.style.display=e?"block":"none";const t=S.parentElement,n=S.nextSibling;de=Zt(S,I,"right"),t?.insertBefore(de,n),je()}const W=ai?Qn(p):null;let ie=null,L=null,F=null,T=null,lt=null,K=null,Cn=null,H=null,oe=null,at=null;dn=!0;function Tt(){if(!oe||!at)return;const e=re.length,t=e>0;if(oe.style.display=t?"flex":"none",at.style.display=t?"":"none",!t)return;const n=mo(re[0]),i=`${e} data ${e===1?"warning":"warnings"}`;oe.style.color=n==="error"?x.errText:x.warnText,oe.ariaLabel=n==="error"?`${i} \u2014 the map may be positionally wrong`:i}let Pt=null,Sn=null,Ot=null,Rt=null,It=null,Wt=null;function Ft(e){w=new Set(e??[]),le&&le(Ke()),v()}function rt(){if(!K)return;const e=!!(Z??I);K.style.display=ae&&e&&!te?"flex":"none";const t=Z??I,n=t?t.style.display!=="none":!1;ae?.hasNotableFindings&&!n?K.style.color=x.findingIndicator:K.dataset.active||(K.style.color=x.icon)}let Mn=null;function En(e){const t=Z??I;t&&(t.style.display=e?"block":"none",K&&Mn?.(K,e),rt())}if(We){let g=function(b){j=b,i(se,b==="zoom"),i(E,b==="pan"),lt&&i(lt,b==="select"),s.style.cursor=b==="pan"?"grab":"crosshair"};ie=p.createElement("div"),ie.dataset.wmapToolbar="single",Object.assign(ie.style,{marginLeft:"auto",flexShrink:"0",display:"flex",flexDirection:"row",alignItems:"center",flexWrap:"wrap-reverse",justifyContent:"flex-end",maxWidth:"100%",background:x.menuBg,border:`1px solid ${x.menuBorder}`,borderRadius:Zn.control,boxShadow:Yi.panel,pointerEvents:"auto"});const e=Qn(p),t=ji(e),{makeBtn:n,setActive:i,makeSep:o,makeMenuRow:a,makeMenuSection:d,closeOpenMenu:l,getOpenMenu:r,setOpenMenu:f}=t;Mn=i,Pt=l,Sn=r,p.addEventListener("click",l,!0),F=p.createElement("div"),Object.assign(F.style,{display:Oe?"none":"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),ie.appendChild(F);const y=n("download","Download PNG",Mi);F.appendChild(y),F.appendChild(o());const se=n("zoomMode","Zoom (drag to zoom region)",()=>g("zoom")),Te=n("zoomIn","Zoom in",()=>Le(s.clientWidth/2,s.clientHeight/2,1.2)),ne=n("zoomOut","Zoom out",()=>Le(s.clientWidth/2,s.clientHeight/2,1/1.2)),ce=n("reset","Reset zoom (double-click)",()=>ct());F.appendChild(se),F.appendChild(Te),F.appendChild(ne),F.appendChild(ce),F.appendChild(o());const E=n("pan","Pan (drag to move)",()=>g("pan"));F.appendChild(E),lt=n("boxSelect","Select (drag to select dies)",()=>g("select")),F.appendChild(lt);{const b=n("drilldown","Chart this wafer",()=>{const Pe=b.getBoundingClientRect();In({x:Pe.left,y:Pe.bottom+4},b)});b.setAttribute("aria-haspopup","menu"),nt=b,Rn(),F.appendChild(b)}i(E,!0);{let b=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},Pe=function(u,C){u.activeTest!==void 0?D({plotMode:u.plotMode,activeTest:u.activeTest,activeMetadataKey:void 0,logScale:u.logScale}):u.activeMetadataKey!==void 0?D({plotMode:u.plotMode,activeTest:void 0,activeMetadataKey:u.activeMetadataKey,passFailDisplay:"off"}):D({plotMode:u.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),C.remove(),f(null),Qe(Q,!1)};L=p.createElement("div"),Object.assign(L.style,{display:"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),ie.appendChild(L),T=p.createElement("div"),Object.assign(T.style,{display:"flex",alignItems:"center",gap:"0"}),L.appendChild(T),T.appendChild(o());const ft=()=>{const u=r();u&&(u.remove(),f(null)),Qe(Q,!1)},Q=n("mode","Plot mode",()=>{if(r()){ft();return}const u=he,C=h.testDefs,{testEntries:gt,binEntries:we,stackedEntries:Ge}=so(u,C,{includeStacked:h.isLotStack}),Kt=(me??[]).filter(Ze=>lo(u,Ze.key)).map(ao),Ue=Ki(Q.getBoundingClientRect(),gt,we,Ge,b,Pe,{makeMenuRow:a,makeMenuSection:d},c.plotMode??"hardBin",Q.ownerDocument.defaultView??window,Kt);Jn(Q).appendChild(Ue),f(Ue),Qe(Q,!0),ei(Ue,Q,ft)});Qe(Q,!1);const{btn:pt,sync:$e}=Gi(t,()=>({...c,plotMode:c.plotMode??"hardBin"}),()=>yi,D);Rt=$e,Rt();const Nt=Qi(t,()=>{const u=!!h.hasReticle,C=(c.plotMode??"hardBin")==="value",{testNumber:gt}=_t(c.activeTest??0,h.testDefs),we=ht(h.testDefs,gt),Ge=C&&we!==void 0&&!$t(we),Kt=C&&!Ge&&(we?.limitLow!==void 0||we?.limitHigh!==void 0),Ue=C&&!Ge&&h.dies.some(Ze=>zi(Ze,gt,we)!==void 0);return no(c,u,{functionalActive:Ge,hasLimits:Kt,hasRecorded:Ue,binMode:(c.plotMode??"hardBin")==="hardBin"||(c.plotMode??"hardBin")==="softBin"},Ze=>D(Ze))},()=>io(c)),{btn:jt,sync:Di}=Zi(t,()=>c,u=>D({legendPosition:u}));Ot=Di,Ot();const _n=()=>{const{testNumber:u}=_t(c.activeTest??0,U),C=ht(U,u);return C!==void 0&&!$t(C)},{btn:ki,sync:Bi}=Ui(t,()=>({...c,functionalActive:_n()}),u=>D(u));It=Bi,It();const Li=()=>{const{testNumber:u}=_t(c.activeTest??0,U),C=ht(U,u);return C!==void 0&&(C.limitLow!==void 0||C.limitHigh!==void 0)},ut=n("specRange","Colorbar range: test limits",()=>{const u=c.colorbarRangeMode==="data"?"spec":"data";D({colorbarRangeMode:u})});Wt=()=>{const u=c.plotMode==="value"&&Li()&&to(c)==="off"&&!_n();ut.style.display=u?"":"none";const C=(c.colorbarRangeMode??"spec")==="spec";i(ut,C),ut.ariaLabel=C?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"},Wt();const Ti=qi(t,()=>c,u=>D(u));T.appendChild(Q),T.appendChild(pt),T.appendChild(ki),T.appendChild(ut),Oe||(T.appendChild(o()),T.appendChild(Nt),T.appendChild(o()),T.appendChild(jt),T.appendChild(o()),T.appendChild(Ti)),ae&&(K=n("findings","Summary panel",()=>{const u=Z??I;u&&En(u.style.display==="none")}),L.appendChild(o()),L.appendChild(K),I?.style.display!=="none"&&i(K,!0),rt()),an&&(at=o(),oe=n("warning","Data warnings",()=>{const u=r();if(l(new MouseEvent("click")),u)return;const C=ho(oe.getBoundingClientRect(),re,k);Jn(Ce).appendChild(C),f(C),ei(C,oe,()=>l(new MouseEvent("click")))}),Qe(oe,!1),L.appendChild(at),L.appendChild(oe),Tt()),Ae&&(L.appendChild(o()),H=n("analysis","Insights",()=>{ze(!te),i(H,te)}),H.dataset.wmapInsightsBtn="1",L.appendChild(H)),sn&&(L.appendChild(o()),ee=n("expand","Expand (E)",on??Dn),L.appendChild(ee)),nn&&(L.appendChild(o()),Cn=n("help","User guide",()=>Xt()),L.appendChild(Cn))}_.appendChild(ie),Ie()}let xe=null;function Dn(){xe&&(xe.close(),xe=null);const e=Ce;e.style.flex="1",e.style.minWidth="0",e.style.minHeight="0";const t=Qt(V.metadata??{},He()),n=_.childElementCount>0?[_,e]:[e],i=_i(n,{ownerDocument:p,boxSize:te?{width:"min(96vw, 1600px)",height:"min(92vh, 1000px)"}:void 0,onClosed:()=>{xe=null,ee&&(ee.style.display="flex"),te||s.focus({preventScroll:!0})}});i&&(i.box.setAttribute("aria-label",t??"Expanded wafer map"),n.length>1&&(i.contentWrap.style.flexDirection="column"),xe=i,ee&&(ee.style.display="none"))}function kn(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")||Lt(),Ot?.(),Rt?.(),It?.(),Wt?.(),v();const i=e.plotMode!==void 0&&e.plotMode!==t,o=COLOR_KEYS.some(a=>a in e);(o||i)&&(ve(),je()),(o||i||e.activeTest!==void 0||e.logScale!==void 0||e.colorbarRangeMode!==void 0)&&qe?.()}function D(e){kn(e);const t=Object.keys(e);li?.(c,t,classifyChanged(t))}let At=!1;function Ht(){At||(At=!0,Gt(()=>{At=!1,v()},k))}function v(){const e=B??void 0,t=h.dies[0],n=t?{x:t.width,y:t.height}:Se.diePitchMm,i=Math.floor(s.clientWidth||s.width),o=!!($?.length||G?.length||h.dies.some(y=>y.hbin!=null||y.sbin!=null)),a=c.legendPosition??"default",d=c.showLegend??!0,l=a==="default"||a==="compact",r=(Se.colorbarWidth??16)+28,f=o&&l?a!=="default"?Math.max($n,r):i<Ai?0:i<Fi?Math.max(Wi,r):Math.max($n,r):void 0,g=Ii(s,h,{...Se,minRightReserve:d?f:0,showColorbar:d&&(Se.showColorbar??!0),markFailingDies:c.markFailingDies??!1,legendPosition:a,legendOffset:kt,diePitchMm:n,fallbackFormat:c.fallbackFormat,showAxes:Se.showAxes??B!==null,viewport:e,activeBin:c.plotMode==="metadata"?c.highlightMetadataValue:c.highlightBin,hoverBin:Dt,hbinDefs:$,sbinDefs:G,metadataFields:me});Et=g.binLegendRows,ye=g.legendBox??null,B===null&&(N=g.viewport),w.size>0&&Ci(),Ee&&Si(),Rn()}function Ci(){const e=z();if(!e)return;const t=s.getContext("2d"),n=h.hoverPoints,i=h.rectangles[0],o=i?i.width/2*e.ppm:e.ppm*.5,a=i?i.height/2*e.ppm:e.ppm*.5,d=Math.max(1,Math.min(3,o*.08)),l=o-d,r=a-d,f=[];for(const g of w){const y=bn.get(g);y!==void 0&&f.push({sx:e.originX+n[y].x*e.ppm,sy:e.originY-n[y].y*e.ppm})}if(f.length){t.save(),t.setLineDash([]),t.fillStyle="rgba(0,0,0,0.12)",t.beginPath();for(const{sx:g,sy:y}of f)t.rect(g-l,y-r,l*2,r*2);t.fill(),t.strokeStyle="rgba(255,255,255,0.9)",t.lineWidth=3,t.beginPath();for(const{sx:g,sy:y}of f)t.rect(g-l,y-r,l*2,r*2);t.stroke(),t.strokeStyle="rgba(0,0,0,0.9)",t.lineWidth=1.5,t.beginPath();for(const{sx:g,sy:y}of f)t.rect(g-l,y-r,l*2,r*2);t.stroke(),t.restore()}}function Si(){const e=s.getContext("2d"),t=Math.min(O.x,R.x),n=Math.min(O.y,R.y),i=Math.abs(R.x-O.x),o=Math.abs(R.y-O.y);e.save(),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(t,n,i,o),e.setLineDash([5,3]),e.strokeStyle="rgba(255,255,255,0.9)",e.lineWidth=3,e.strokeRect(t,n,i,o),e.strokeStyle="rgba(0,0,0,0.9)",e.lineWidth=1.5,e.strokeRect(t,n,i,o),e.restore()}function Mi(){s.toBlob(e=>{e&&Ji(e,en(),pe.onSaveImage)})}function Bn(e){return N?Math.max(N.ppm*fi,Math.min(N.ppm*pi,e)):e}function Le(e,t,n){const i=B??N;if(!i)return;const o=Bn(i.ppm*n),a=o/i.ppm,d=e-(e-i.originX)*a,l=t-(t-i.originY)*a,r=(N?.snapDist??1)/(o/(N?.ppm??o));B={originX:d,originY:l,ppm:o,snapDist:r},v()}function z(){return B??N}function Ln(e){if(e.ctrlKey||e.metaKey){e.preventDefault();const t=s.getBoundingClientRect(),n=e.deltaY<0?1.12:1/1.12;Le(e.clientX-t.left,e.clientY-t.top,n)}else if(B!==null){e.preventDefault();const t=z(),n=B.snapDist;B={originX:t.originX-e.deltaX,originY:t.originY-e.deltaY,ppm:t.ppm,snapDist:n},v()}}function zt(e,t,n){return e>=n.x&&e<n.x+n.w&&t>=n.y&&t<n.y+n.h}function Tn(e){if(it=!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(ye&&c.legendPosition==="floating"&&zt(n,i,ye)){Me=!0,Ye={x:n,y:i},Bt={...kt};return}if(Xe&&j!=="pan"){ke=!0,be=!0,De={x:n,y:i},ot={x:z().originX,y:z().originY},s.style.cursor="grabbing";return}if(j==="zoom"||j==="select"){Ee=!0,O=R={x:n,y:i};return}be=!0,De={x:n,y:i},ot={x:z().originX,y:z().originY},s.style.cursor="grabbing"}function Pn(e){const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top;if(Ee){R={x:n,y:i},Ht();return}if(Me){const g=n-Ye.x,y=i-Ye.y;g*g+y*y>16&&(Me=!1,Ve=!0,s.style.cursor="grabbing")}if(Ve){kt={x:Bt.x+(n-Ye.x),y:Bt.y+(i-Ye.y)},Ht();return}if(be){const g=z(),y=B?.snapDist??N?.snapDist??1;B={originX:ot.x+(n-De.x),originY:ot.y+(i-De.y),ppm:g.ppm,snapDist:y},Ht();return}const o=z();if(!o)return;const a=(n-o.originX)/o.ppm,d=(o.originY-i)/o.ppm,r=Yt(a,d,o.snapDist)?.die??null,f=Et.find(g=>n>=g.x&&n<g.x+g.w&&i>=g.y&&i<g.y+g.h);if(vn(f?f.bin:void 0),f){s.style.cursor="pointer",W&&(W.textContent=f.label??`Bin ${f.bin}`,W.style.display="block",qn(W,s,e.clientX,e.clientY,{followPointer:!0})),Je?.(null,e);return}j==="pan"&&(s.style.cursor=r?"crosshair":"grab"),W&&(r?(W.innerHTML=Oi(r,h.plotMode,{testDefs:U,hbinDefs:$,sbinDefs:G,fallbackFormat:c.fallbackFormat,aggrMethod:h.aggrMethod,lotSize:h.lotSize,metadataFields:me,activeTest:h.activeTest,reticleConfig:un}),W.style.display="block",qn(W,s,e.clientX,e.clientY,{followPointer:!0})):W.style.display="none"),Je?.(r,e)}function On(e){const t=s.getBoundingClientRect(),n=e.clientX-t.left,i=e.clientY-t.top,o=e.ctrlKey||e.metaKey;if(W&&(n<0||i<0||n>t.width||i>t.height)&&(W.style.display="none"),Ee){Ee=!1,R={x:n,y:i};const l=n-O.x,r=i-O.y,f=z();if(j==="zoom"){if(l*l+r*r<25)Le(n,i,2);else if(f){const g=Math.min(O.x,R.x),y=Math.max(O.x,R.x),se=Math.min(O.y,R.y),Te=Math.max(O.y,R.y),ne=y-g,ce=Te-se;if(ne>4&&ce>4){const E=s.clientWidth,b=s.clientHeight,Pe=E/ne,ft=b/ce,Q=Math.min(Pe,ft),pt=Bn(f.ppm*Q),$e=pt/f.ppm,Nt=(g+y)/2,jt=(se+Te)/2;B={originX:E/2-(Nt-f.originX)*$e,originY:b/2-(jt-f.originY)*$e,ppm:pt,snapDist:f.snapDist/$e}}}v(),s.style.cursor="crosshair";return}if(l*l+r*r<25)Vt(n,i,o,e);else if(f){const g=(Math.min(O.x,R.x)-f.originX)/f.ppm,y=(Math.max(O.x,R.x)-f.originX)/f.ppm,se=(f.originY-Math.max(O.y,R.y))/f.ppm,Te=(f.originY-Math.min(O.y,R.y))/f.ppm,ne=h.hoverPoints,ce=[];for(let E=0;E<ne.length;E++)if(ne[E].x>=g&&ne[E].x<=y&&ne[E].y>=se&&ne[E].y<=Te){const b=h.dies[E];b&&ce.push(b)}if(o)for(const E of ce){const b=fe(E);w.has(b)?w.delete(b):w.add(b)}else w=new Set(ce.map(E=>fe(E)));le?.(Ke())}v(),s.style.cursor="crosshair";return}if(Me){Me=!1,Vt(n,i,o,e);return}if(Ve){Ve=!1,s.style.cursor="grab";return}if(!be)return;if(be=!1,ke){ke=!1,s.style.cursor=Xe||j==="pan"?"grab":"crosshair";return}s.style.cursor=j==="pan"?"grab":"crosshair";const a=n-De.x,d=i-De.y;a*a+d*d<25&&Vt(n,i,o,e)}function Vt(e,t,n,i){for(const l of Et)if(e>=l.x&&e<l.x+l.w&&t>=l.y&&t<l.y+l.h){if(typeof l.bin=="number"){const r=c.highlightBin===l.bin?void 0:l.bin;D({highlightBin:r})}else{const r=c.highlightMetadataValue===l.bin?void 0:l.bin;D({highlightMetadataValue:r})}return}if(ye&&zt(e,t,ye))return;const o=z();if(!o)return;const d=Yt((e-o.originX)/o.ppm,(o.originY-t)/o.ppm,o.snapDist)?.die??null;if(d){si?.(d,i);const l=fe(d);n?w.has(l)?w.delete(l):w.add(l):w=new Set([l]),le?.(Ke()),v()}else n||(w=new Set,le?.([]),v())}function Ke(){const e=[],t=h.hoverPoints;for(let n=0;n<t.length;n++){const i=h.dies[n];i&&w.has(fe(i))&&e.push(i)}return e}function Rn(){nt&&(nt.style.display=xt()?"flex":"none",nt.ariaLabel=w.size>0?"Chart the selected dies (or right-click)":"Chart this wafer (or right-click)")}function Ei(){const e={waferLabel:Jt(),testDefs:U,isLotStack:q.isLotStack,activeTest:c.plotMode==="value"?c.activeTest:void 0};return w.size>0?bo(Ke(),e):vo(he,e)}function In(e,t){if(!xt())return;const n=Ei();import("./drilldown.js").then(({openDrilldownMenu:i})=>{fn||(cn=i(e,t,n,gi))})}function Wn(e){e.stopPropagation();const t=it;if(it=!1,!xt()||te)return;const n=s.getBoundingClientRect();if(!t){const o=e.clientX-n.left,a=e.clientY-n.top;if(ye&&zt(o,a,ye))return;const d=z(),l=d?Yt((o-d.originX)/d.ppm,(d.originY-a)/d.ppm,d.snapDist)?.die:void 0;l&&!w.has(fe(l))&&(w=new Set([fe(l)]),le?.(Ke()),v())}e.preventDefault();const i=t?{x:n.left+n.width/2,y:n.top+n.height/2}:{x:e.clientX,y:e.clientY};In(i,s)}function Fn(){vn(void 0),W&&yt(p),Je?.(null,new MouseEvent("mouseleave")),s.style.cursor=j==="pan"?"grab":"crosshair"}function An(){be=!1,ke=!1,Ee=!1,Me=!1,Ve=!1,W&&yt(p),Je?.(null,new MouseEvent("mouseleave")),s.style.cursor=j==="pan"?"grab":"crosshair",v()}function Yt(e,t,n){const i=h.hoverPoints,o=h.rectangles;for(let r=0;r<o.length;r++){const f=o[r];if(Math.abs(e-f.x)<=f.width/2&&Math.abs(t-f.y)<=f.height/2){const g=h.dies[r];return g?{die:g,index:r}:null}}let a=null,d=-1,l=n*n;for(let r=0;r<i.length;r++){const f=i[r].x-e,g=i[r].y-t,y=f*f+g*g;y<l&&(l=y,a=h.dies[r]??null,d=r)}return a?{die:a,index:d}:null}const Hn=new k.ResizeObserver(()=>{N=null,B=null,v()});Hn.observe(s),M.height==null&&oi<=0&&Gt(()=>Gt(()=>{P.clientHeight>0||console.warn("[wafermap] The map container has zero height, so the map cannot render. renderWaferMap fills its container \u2014 give the container a resolved height: an explicit CSS `height` (e.g. 600px), a height-resolved flex/grid parent, or `position:absolute; inset:0`. Alternatively pass `{ height: 600 }` in the render options and the library will size it for you.")}));let _e=k.matchMedia(`(resolution: ${k.devicePixelRatio}dppx)`);const dt=()=>{_e.removeEventListener("change",dt),_e=k.matchMedia(`(resolution: ${k.devicePixelRatio}dppx)`),_e.addEventListener("change",dt),v()};_e.addEventListener("change",dt);const zn=k.matchMedia("(prefers-color-scheme: dark)"),Vn=()=>v();zn.addEventListener("change",Vn);const Yn=()=>{W&&yt(p)};k.addEventListener("blur",Yn);function Xn(e){if((e.key==="ContextMenu"||e.shiftKey&&e.key==="F10")&&(it=!0),e.key==="Escape"&&w.size>0&&(w=new Set,le?.([]),v()),(e.key==="e"||e.key==="E")&&sn&&(e.stopPropagation(),(on??Dn)()),(e.ctrlKey||e.metaKey)&&(e.key==="="||e.key==="+"?(e.preventDefault(),Le(s.clientWidth/2,s.clientHeight/2,1.2)):e.key==="-"?(e.preventDefault(),Le(s.clientWidth/2,s.clientHeight/2,1/1.2)):e.key==="0"&&(e.preventDefault(),ct())),!e.ctrlKey&&!e.metaKey&&!e.shiftKey){const n=z();if(n){const i=B?.snapDist??N?.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)&&(B={originX:n.originX+o,originY:n.originY+a,ppm:n.ppm,snapDist:i},v())}e.key===" "&&!Xe&&(e.preventDefault(),Xe=!0,j!=="pan"&&(s.style.cursor="grab"))}}function Nn(e){e.key===" "&&(Xe=!1,ke&&(be=!1,ke=!1),s.style.cursor=j==="pan"?"grab":"crosshair")}s.style.cursor="grab",s.setAttribute("tabindex","0"),s.addEventListener("wheel",Ln,{passive:!1}),s.addEventListener("pointerdown",Tn),s.addEventListener("pointermove",Pn),s.addEventListener("pointerup",On),s.addEventListener("pointerleave",Fn),s.addEventListener("pointercancel",An);const jn=()=>ct();s.addEventListener("dblclick",jn),s.addEventListener("keydown",Xn),s.addEventListener("keyup",Nn),s.addEventListener("contextmenu",Wn);const Kn=e=>{e.stopPropagation()};s.addEventListener("click",Kn),s.clientWidth,v(),qe?.();function ct(){N=null,B=null,v()}function Xt(){import("./userGuideHtml.js").then(e=>$i({buildWaferMap:Hi,renderWaferMap,renderWaferGallery:void 0,analyzeWaferMap:Vi},e.USER_GUIDE_HTML,ri,P))}return Ie(),{setResult(e){q=e,V=e.wafer,he=e.dies,$=e.hbinDefs,G=e.sbinDefs,U=e.testDefs,me=e.metadataFields,pn=e.reticles?.length?e.reticles:void 0,un=e.reticleConfig,gn=e.view?.dataAxisFlip,wt=e.isLotStack,Ct=e.aggrMethod,St=e.lotSize,mi(),Lt(),v(),Z&&ve()},setOptions(e){kn(e)},getOptions(){return{...c}},resetZoom:ct,setSelection(e){w=new Set(e.map(t=>fe(t))),v()},clearSelection(){w=new Set,le?.([]),v()},setFindingsNotice(e){xn=e,Z?ve():I&&je()},setStatsSummary(e){if(ae=e,vt(),Tt(),Z)ve();else if(I)je();else if(e&&!Fe?.placement){const t=Fe?.defaultOpen??!We;I=Ut("right",ue,p),I.style.display=t?"block":"none";const n=S.parentElement,i=S.nextSibling;de=Zt(S,I,"right"),n?.insertBefore(de,i),je()}rt()},closeSummaryPanel(){En(!1)},getExportTitle(){return en()},getSaveImageHook(){return pe.onSaveImage},getBinColors(){return h.binColors},setSummaryVisible(e){K&&(K.style.display=e?"flex":"none")},setViewControlsVisible(e){L&&(L.style.display=e?"flex":"none")},setExpandVisible(e){ee&&(ee.style.display=e?"flex":"none")},openUserGuide:Xt,setInsightsOpen(e){ze(e),H&&(e?(H.dataset.active="1",H.style.background=x.bgActive,H.style.color=x.iconActive):(delete H.dataset.active,H.style.background="transparent",H.style.color=x.icon))},destroy(){fn=!0;for(const e of Ne.values())e.cancel();Ne.clear(),xe?.close(),Sn?.()?.remove(),Pt&&p.removeEventListener("click",Pt,!0),s.removeEventListener("wheel",Ln),s.removeEventListener("pointerdown",Tn),s.removeEventListener("pointermove",Pn),s.removeEventListener("pointerup",On),s.removeEventListener("pointerleave",Fn),s.removeEventListener("pointercancel",An),s.removeEventListener("dblclick",jn),s.removeEventListener("keydown",Xn),s.removeEventListener("keyup",Nn),s.removeEventListener("contextmenu",Wn),cn?.(),s.removeEventListener("click",Kn),Hn.disconnect(),_e.removeEventListener("change",dt),zn.removeEventListener("change",Vn),k.removeEventListener("blur",Yn),ui(),W&&yt(p),ie?.remove(),Be&&(Be.parentElement?.insertBefore(S,Be),Be.remove()),de&&(de.parentElement?.insertBefore(S,de),de.remove()),S.remove(),s.style.cursor="",X?.destroy(),Y?.destroy(),Re.remove()}}}
|
|
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()}}}
|