@wafertools/wafermap 0.37.0 → 0.37.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
- package/dist/packages/canvas-adapter/charts/patCard.d.ts +2 -0
- package/dist/packages/canvas-adapter/charts/patCard.js +1 -1
- package/dist/packages/canvas-adapter/insightsTab.d.ts +2 -0
- package/dist/packages/canvas-adapter/insightsTab.js +1 -1
- package/dist/packages/canvas-adapter/patMode.d.ts +27 -0
- package/dist/packages/canvas-adapter/patMode.js +1 -0
- package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
- package/dist/packages/canvas-adapter/toolbar.d.ts +7 -4
- 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 +42 -75
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/renderer/buildWaferMap.js +1 -1
- package/dist/packages/stats/chartCatalogue.js +1 -1
- package/dist/packages/stats/groupCompare.d.ts +1 -1
- package/dist/packages/stats/groupCompare.js +1 -1
- package/dist/packages/stats/pat.js +1 -1
- package/package.json +9 -2
- package/dist/packages/canvas-adapter/patMaps.d.ts +0 -26
- package/dist/packages/canvas-adapter/patMaps.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createViewSwitch as fs}from"./viewSwitch.js";import{createSummaryToggle as ps}from"./summaryToggle.js";import{getUniqueTestNumbers as ms,resolveTestNumber as gs,findTestDef as hs,collectMetadataValues as ys}from"../renderer/buildView.js";import{metadataCategoricalValue as bs}from"../core/metadata.js";import{resolveBinColorsForMaps as ws,mergeBinDefs as Ft,binColorWarning as vs,mixedPassBinsWarning as Ss,binColorsEqual as Cs}from"../renderer/binColors.js";import{commonPassBins as Xo,itemPassBins as ut}from"../core/passBins.js";import{requireRingCount as ne}from"../core/ringCount.js";import{NO_DATA_FILL as xs}from"../renderer/colorMap.js";import{metadataValueColor as Ms}from"../renderer/colorMap.js";import{resolveCanvasTheme as ks}from"./canvasTheme.js";import{ICONS as Dn}from"./icons.js";import{SHADOW as Bn,LEADING as Yo,TRACKING as Ds,controlStyle as Bs,wireControlHover as En,SPACE as M,EDGE_GUTTER as oe,MAP_CHROME_INSET as Es,RADIUS as q,FONT as N,CLR as v,sevColor as Uo,MODE_LABELS as Os,BIN_LEGEND_MODES as Zo,STACKED_MODES as ie,applyOverlayZ as Ts,getTooltip as Ls,hideTooltip as Qo,createToolbarHelpers as Ws,buildModeMenuEl as Rs,openDetachWindow as As,openFloatingWindow as Ps,openModal as Fs,copyWmapThemeTokens as $s,syncWmapPopupTheme as Is,makePaletteBtn as Vs,makeLogScaleBtn as Hs,makeLegendStyleBtn as js,makeOverlaysBtn as zs,makeOrientationBtn as Ns,menuLayerFor as Jo,saveImageBlob as Gs,markMenuTrigger as ft,wireMenuA11y as ei,wireTooltip as On,requestedPassFailDisplay as ti,overlayMenuRows as _s,anyOverlayActive as Ks,openCompactDiagnostics as qs,roomForPanel as ni,logWmapVersionOnce as Xs,buildDataModeEntries as Ys,metadataKeyHasData as Us,metadataModeEntry as Zs}from"./toolbar.js";import{openReportModal as Qs,openUserGuideWindow as Js,registerGuideOpener as ea}from"./guideWindow.js";import{waferDisplayLabel as pt,waferIdentityLabel as we}from"../core/waferLabel.js";import{bandButton as ta}from"./filterButton.js";import{metadataDisplayValue as na}from"../core/metadata.js";import{withExportContext as oa}from"./exportName.js";import{sortBinsForDisplay as ia}from"../stats/binPareto.js";import{diePassStatus as sa,isYieldEligibleDie as aa}from"../core/dies.js";import{aggregateValues as la,aggregateBinCounts as oi}from"../core/aggregates.js";import{renderWaferMap as ra,renderWaferMapCard as ii,toPublicViewOptions as $t}from"./renderWaferMap.js";import{waferPopulation as ca,selectionPopulation as da,LOT_STACK_REASON as Tn}from"./chartPopulation.js";import{sourceFromBins as si}from"./plotItems.js";import{plotStoreFor as ua}from"./plotStore.js";import{classifyChanged as Ln,COLOR_KEYS as fa,findingBin as pa,findingPlotMode as ma}from"./renderWaferMap.js";import{findingPatternKey as ai}from"../stats/filterFindings.js";import{synthesisSource as ga}from"../stats/synthesis.js";import{buildWaferMap as ha,computeCoverage as ya,computeYield as ba,defaultBinMode as wa,getTestPassStatus as li,isParametricTest as Wn,getDieTestValue as va,isBuiltMap as Sa}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Rn}from"../stats/analyzeWaferMap.js";import{lotTestValueStatus as Ca}from"../stats/testValueBudget.js";import{testValueNotice as xa}from"./testValueOffer.js";import{axisPrefsFromOptions as An,optionsFromAxisPrefs as Ma,CHART_PREF_KEYS as Pn}from"./chartPrefs.js";import{collectWarnings as ka,buildWarningsMenuEl as Da,severityOf as Ba}from"./warnings.js";import{asList as Fn,compareNatural as $n,arrayEqual as It,toggleHighlight as ri}from"../core/utils.js";import{buildCompactMap as Ea,compactLayoutOffered as Oa}from"../core/compact.js";import{attachExpandableMetadata as ci}from"./identityHeader.js";import{createSummaryPanelEl as In,buildMetadataStripRow as Ta,metadataEntries as La,renderLotSummaryContentSteps as Wa,reportMapsFromItems as Ra}from"./summaryPanel.js";import{prettyKey as Aa}from"../stats/facets.js";import{testLabel as Pa,markedTestLabel as Fa,derivedFields as $a}from"../renderer/testLabel.js";import{mergeTestDefs as Ia}from"../stats/mergeTestDefs.js";import{getDieKey as Vt,hasPosition as Va}from"../core/dies.js";import{testValue as Ha}from"../core/dieTable.js";import{runChunked as ja}from"./chunked.js";function di(u){if(typeof u!="number"||!Number.isFinite(u))return;const k=Math.round(u);return k>=1?k:void 0}const Vn=12;function za(u,k,d){let z=k;if(k.length>Vn){const D=k.slice(0,Vn-1),E=k.slice(Vn-1),$=E.reduce((F,ce)=>F+ce.count,0);z=[...D,{color:v.label,count:$,label:`Other (${E.length} bins)`}]}const O=u.createElement("div");Object.assign(O.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:q.control,overflow:"hidden",border:`1px solid ${v.menuBorder}`,boxSizing:"border-box",marginTop:M.xs,flexShrink:"0"}),O.setAttribute("role","img"),O.setAttribute("aria-label",`Population split: ${z.map(D=>`${D.label} ${Ht(D.count/d*100)}`).join(", ")}`);for(const D of z){const E=D.count/d*100,$=u.createElement("div");Object.assign($.style,{flex:`${E} 1 0`,minWidth:E>0?"2px":"0",background:D.color}),On($,`${D.label} \xB7 ${D.count.toLocaleString()} dies \xB7 ${Ht(E)}`),O.appendChild($)}return O}function Ht(u){return u>0&&u<.1?"<0.1%":`${u.toFixed(1)}%`}function ui(u,k,d){const z=new Map;let O=0,D=0;for(const E of u){const $=d?new Set(d(E)):void 0;for(const F of E.dies){if(!aa(F))continue;const ce=k(F);ce!==void 0&&(z.set(ce,(z.get(ce)??0)+1),O++,$&&sa(F,$)&&D++)}}return{counts:z,total:O,pass:D}}function fi(u,k){const d=u.ownerDocument.createElement("div");Object.assign(d.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${M.xxs} ${M.xs}`,borderRadius:q.control});const z=u.ownerDocument.createElement("span");Object.assign(z.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:k.color,border:k.isActive?`2px solid ${v.iconActive}`:`1px solid ${v.menuBorder}`,borderRadius:q.control,boxSizing:"border-box"});const O=u.ownerDocument.createElement("span");if(O.textContent=k.label,Object.assign(O.style,{fontWeight:k.isActive?"700":"400",color:k.isActive?v.iconActive:v.text,whiteSpace:"nowrap"}),d.appendChild(z),d.appendChild(O),k.count!==void 0){const D=u.ownerDocument.createElement("span");if(D.textContent=k.count.toLocaleString(),Object.assign(D.style,{color:k.isActive?v.iconActive:v.text,fontWeight:k.isActive?"700":"400",whiteSpace:"nowrap"}),d.appendChild(D),k.percent!==void 0){const E=u.ownerDocument.createElement("span");E.textContent=Ht(k.percent),Object.assign(E.style,{color:v.label,whiteSpace:"nowrap"}),d.appendChild(E)}}if(d.setAttribute("role","button"),d.setAttribute("aria-pressed",k.isActive?"true":"false"),d.tabIndex=0,d.addEventListener("mouseenter",()=>{d.style.background=v.bgHover}),d.addEventListener("mouseleave",()=>{d.style.background="transparent"}),d.addEventListener("focus",()=>{d.style.background=v.bgHover}),d.addEventListener("blur",()=>{d.style.background="transparent"}),d.addEventListener("click",D=>k.onClick(D.ctrlKey||D.metaKey)),d.addEventListener("keydown",D=>{if(D.key==="Enter"||D.key===" ")D.preventDefault(),k.onClick(D.ctrlKey||D.metaKey);else if(k.onMenu&&(D.key==="ContextMenu"||D.key==="F10"&&D.shiftKey)){D.preventDefault();const E=d.getBoundingClientRect();k.onMenu({x:E.left+E.width/2,y:E.bottom},d)}}),k.onMenu){const D=k.onMenu;d.addEventListener("contextmenu",E=>{E.preventDefault(),D({x:E.clientX,y:E.clientY},d)}),On(d,"Right-click: charts and tables for these dies")}u.appendChild(d)}export function renderWaferGallery(u,k,d={}){Xs();const z=6;let O=di(d.columns);const D=d.showHelpButton??!1,E=d.userGuideExtension,$=d.insights?.enabled??!0,F=ua(d.insights),ce={enabled:!1,plotStore:F},pi=Ts(d.zIndex),Oe=d.summaryPanel,ve=e=>[...ut(e)],Hn=()=>V.flatMap(e=>e?[ne(e,"renderWaferGallery")]:[]),mt=()=>Hn()[0];function mi(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 K=d.lotStatsSummary,ze;const se=()=>Se?ze:K;let Ne=d.viewOptions?.legendPosition??"default",gt=d.perCardLegend??!1;function Ge(){const e=a.plotMode??"hardBin";return Zo.has(e)?null:a.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 jn(){const e=gt||Ge()!==null;for(const t of C)t&&t.setOptions({showLegend:e})}let a={plotMode:wa(k.flatMap(e=>typeof e=="function"?[]:[e.dies??[]])),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...d.viewOptions},C=[],de=[],Te=[],x=[];const I=oa(()=>{const e=x.filter(n=>n!=null),t=[...new Set(e.map(n=>na(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort($n);return{prefix:d.downloadFilename,lots:t,...e.length===1?{wafer:we(e[0])}:{waferCount:e.length}}},d.onSaveImage,d.onSaveText);let V=k.map(e=>typeof e=="function"?null:e),X=null,zn=null,jt=!1,Le=0,Se=!1,zt=!1;const _e=new WeakSet,Nn=new WeakMap,Ke=()=>{const e=X?.get();return!!e&&!e.off};function Gn(e,t){return{dies:e.dies,wafer:e.wafer,label:pt(e,t),identity:we(e),waferIndex:t,passBins:ut(e),testDefs:e.testDefs,statsSummary:e.statsSummary}}const Nt=new Map;function qe(e,t){if(!X||!Ke())return e;const n=Nn.get(e);if(n&&n.v===Le)return n.item;const o=X.mark([Gn(e,t)]);let i=e;if(o.narrowing){const s=o.items[0].dies,l=s.filter(c=>!c.filteredOut);i={...e,dies:s,statsSummary:Nt.get(e),...e.yield?{yield:ba(s,[...ut(e)],e.yield.yieldPercentGross!=null?"denominator-only":"exclude")}:{},...e.dataCoverage?{dataCoverage:ya(l)}:{}},o.hidden.size&&_e.add(i)}return Nn.set(e,{v:Le,item:i}),i}const _n=new WeakMap;function gi(e,t){if(!X||!Ke())return e;const n=_n.get(e);if(n&&n.v===Le)return n.item;const o=qe(e,t),i=o===e?e:_e.has(o)?null:{...o,dies:o.dies.filter(s=>!s.filteredOut)};return _n.set(e,{v:Le,item:i}),i}function B(){return!X||!Ke()?V:V.map((e,t)=>e?gi(e,t):null)}let ht=0,yt=!1;function hi(){const e=++ht;ze=void 0,Nt.clear();const t=()=>{yt=!1,W(),le()};if(!Se){t();return}const n=Ut();if(!n||!(K||n.some(s=>s.statsSummary))){t();return}const o=B().flatMap((s,l)=>s?[{it:s,i:l}]:[]);if(o.length===0){t();return}yt=!0;const i=K?.analysisOptions??n.find(s=>s.statsSummary)?.statsSummary?.analysisOptions??{};import("../stats/analyzeWaferLot.js").then(async({analyzeWaferLotAsync:s,remapLotWaferIndices:l})=>{const c=await s(o.map(p=>p.it),i);if(e!==ht||jt)return;const r=o.map(p=>p.i);ze=l(c,r),c.perWafer.forEach((p,m)=>Nt.set(V[r[m]],p.summary)),Le++,V.forEach((p,m)=>{if(!p||ie.has(a.plotMode))return;const f=qe(p,m);x[m]=f,C[m]?.setStatsSummary(f.statsSummary)}),De(),t()}).catch(()=>{e===ht&&t()})}const bt=e=>X&&Ke()?e.map((t,n)=>typeof t=="function"?t:qe(t,n)):e;function Gt(){return zn??=import("./pageFilter.js").then(({createPageFilter:e})=>{const t=e({doc:u.ownerDocument,initial:d.insights?.filter,onChange:d.insights?.onFilterChange,savedFilters:d.insights?.savedFilters,onSavedFiltersChange:d.insights?.onSavedFiltersChange,pickFiltersFile:d.insights?.onPickFiltersFile,onSaveText:d.onSaveText,attributes:d.attributes,getRingCount:()=>ne({ringCount:mt()},"the page filter")});return jt||(X=t,ue=t.createBand(()=>Kt(),{marginLeft:oe,marginRight:oe,marginBottom:M.lg}),u.insertBefore(ue.el,U),t.subscribe(qt),t.get()&&qt()),t}),zn}let ue=null,wt=null,_t;const Kt=()=>V.flatMap((e,t)=>e?[Gn(e,t)]:[]);function Kn(){clearTimeout(_t),_t=setTimeout(()=>{if(!X||!ue)return;const e=Kt(),t=X.keep(e);ue.refresh(t.result,e),ue.el.style.display=X.get()&&!it?"":"none"},0)}function qt(){if(Le++,Se=!1,Ue>0){zt=!0,Kn();return}zt=!1;const e=a.plotMode;Se=Ke()&&V.some((t,n)=>t!==null&&qe(t,n)!==t),ze=void 0,yt=Se&&!!K,V.length>0&&(ie.has(e)?(a={...a,...At(e)},Z(Ve(e))):Z(bt(V.filter(t=>t!==null)))),Kn(),hi()}function We(){return Ia(B())}function Xe(){if(B().some(e=>e?.testDefs?.length))return We().defs}let Ye=0,Ue=0;const Q=new Map;let yi=0,vt=null,J=null,fe=null,Re=null;function St(){J===null&&fe===null&&(Re={plotMode:a.plotMode,activeTest:a.activeTest})}function qn(){Re&&R({...Re},{fireCallback:!1}),Re=null}let Xn=new Set,S=null,bi={};function Yn(e){return B()[e]?.statsSummary??se()?.perWafer.find(t=>t.waferIndex===e)?.summary}function Un(){return!!(B().some(e=>e?.statsSummary?.findings.length)||se()?.perWafer.some(e=>e.summary.findings.length))}const wi=Ls(),Ae=Ws(wi),{makeBtn:Pe,setActive:Zn,makeSep:Ce,syncSeparators:Xt,syncToolbarVisible:Yt,makeMenuRow:vi,makeMenuSection:Si,makeDropdown:Qn,closeOpenMenu:Ct,getOpenMenu:Ze,setOpenMenu:Qe}=Ae;u.ownerDocument.addEventListener("click",Ct,!0);const Jn=()=>Qo();window.addEventListener("blur",Jn);let eo=d.findingsNotice,xe=null;function Ut(){const e=V;return e.length>0&&e.every(t=>t!=null&&Sa(t))?e:null}function Ci(){return K?.stats.testValueAnalysis??Ca(B().flatMap(e=>e?.statsSummary?[e.statsSummary]:[]))}const Zt=()=>eo??(Ut()?xa(Ci(),B().length,xe!==null,xi):void 0);function xi(){const e=Ut();if(xe||!e)return;const t=new AbortController;xe=t,W();const n=K?.analysisOptions??e[0].statsSummary?.analysisOptions??{};import("../stats/analyzeWaferLot.js").then(({analyzeWaferLotAsync:o})=>o(e,{...n,enableTestValueAnalysis:!0,signal:t.signal})).then(o=>{if(t.signal.aborted)return;xe=null;const i=o.perWafer.map(s=>s.summary);V=V.map((s,l)=>s&&{...s,statsSummary:i[l]}),ie.has(a.plotMode)||(x=x.map((s,l)=>s&&{...s,statsSummary:i[l]}),C.forEach((s,l)=>s?.setStatsSummary(i[l]))),K=o,De(),W(),le(),d.onStatsSummaryChange?.({summaries:i,lotStatsSummary:o})}).catch(o=>{if(!t.signal.aborted)throw xe=null,W(),o})}function Qt(){xe?.abort(),xe=null}function to(e){Xn=new Set(e);const t=[...P.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,i)=>{const s=Xn.has(i);o.style.outline=s?`3px solid ${v.findingHighlight}`:"",o.style.outlineOffset=s?"-3px":"",s&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function Jt(){to([])}let xt=!1;function en(){xt=!0;for(const e of C)e&&e.clearSelection();xt=!1}function no(e){return t=>{!xt&&(J!==null||fe!==null)&&(Re=null,ke(),W()),on.set(e,t.length),ae&&!Je&&!xt&&Mi(e,t),e.onSelect?.(t)}}function pe(e,t){e!==void 0&&(C.forEach((n,o)=>{n&&o!==e&&n.locateDie(null)}),C[e]?.locateDie(t),P.querySelectorAll(".wmap-gallery-card")[e]?.scrollIntoView?.({block:"center",behavior:"smooth"}))}let ae=!1,Je=!1,Me=new Set;function Mi(e,t){Je=!0;try{Me=new Set(t.map(n=>Vt(n))),x.forEach((n,o)=>{const i=C[o];!i||!n||n===e||i.setSelection(n.dies.filter(s=>Me.has(Vt(s))))})}finally{Je=!1}Ot()}function oo(){Me=new Set,Je=!0;try{for(const e of C)e?.clearSelection()}finally{Je=!1}Ot()}function tn(){if(!ae||Me.size===0)return;const e=[];let t=!1;if(x.forEach((i,s)=>{if(!i)return;const l=i.dies.filter(c=>Me.has(Vt(c)));l.length!==0&&(i.isLotStack&&(t=!0),e.push({label:we(i)??i.label??`Wafer ${s+1}`,dies:l,waferIndex:s,wafer:i.wafer,passBins:ve(i),ringCount:ne(i,"renderWaferGallery")}))}),e.length===0)return;const n=We(),o=a;return{source:{items:e,population:e.length===1?`selected on ${e[0].label}`:`selected at the same die positions on ${e.length} wafers`,testDefs:n.defs,activeTest:o.plotMode==="value"?o.activeTest:void 0,notMeasuredReason:t?Tn:void 0},ctx:{plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,onSaveImage:I.onSaveImage,onSaveText:I.onSaveText,onLocateDie:(i,s)=>pe(s,i)}}}function io(){const e=[];let t=!1;if(x.forEach((o,i)=>{const s=o?C[i]?.getSelectedDies()??[]:[];!o||s.length===0||(o.isLotStack&&(t=!0),e.push({label:we(o)??o.label??`Wafer ${i+1}`,dies:s,waferIndex:i,wafer:o.wafer,passBins:ve(o),ringCount:ne(o,"renderWaferGallery")}))}),e.length<2)return;const n=a;return{source:{items:e,population:`selected on ${e.length} wafers`,testDefs:We().defs,activeTest:n.plotMode==="value"?n.activeTest:void 0,notMeasuredReason:t?Tn:void 0},ctx:{plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,onSaveImage:I.onSaveImage,onSaveText:I.onSaveText,onLocateDie:(o,i)=>pe(i,o)}}}function ki(e){const t=tn()??lo(e);if(t)return t;const n=io(),o=n?.source.items.some(i=>i.waferIndex===e);return n&&o?{...n,narrowable:!0}:void 0}function nn(e,t,n){J!==e&&t.click();const o=S;if(!o)return;const i=se()?.findings.find(l=>l.id===e),s=tn()??io()??Bi()??(i?so(ro(i)):void 0);s&&import("./drilldown.js").then(({openDrilldownMenu:l})=>{o.isConnected&&l(n,o,s.source,{plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,...s.ctx})})}function Di(e,t,n,o){const i=Fn(a.highlightBin),s=i.length>1&&i.includes(t)?[...i]:[t],l=[];let c=!1;x.forEach((h,y)=>{h&&(h.isLotStack&&(c=!0),l.push({label:we(h)??h.label??`Wafer ${y+1}`,dies:h.dies,waferIndex:y,wafer:h.wafer,passBins:ve(h),ringCount:ne(h,"renderWaferGallery")}))});const r=We().defs,p=si(l,e,s,r,void 0,c);if(!p)return;const m={plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,onSaveImage:I.onSaveImage,onSaveText:I.onSaveText,onLocateDie:(h,y)=>pe(y,h)},f=s.length>1?si(l,e,[t],r,void 0,c):null,g=f?{...m,narrower:{label:`Only ${e} bin ${t}`,backLabel:"All filtered bins",source:f,ctx:m}}:m;import("./drilldown.js").then(({openDrilldownMenu:h})=>{o.isConnected&&h(n,o,p,g)})}function so(e,t=""){const n=[];let o=!1;for(const s of[...e??[]].sort((l,c)=>l-c)){const l=x[s];l&&(l.isLotStack&&(o=!0),n.push({label:we(l)??l.label??`Wafer ${s+1}`,dies:l.dies,waferIndex:s,wafer:l.wafer,passBins:ve(l),ringCount:ne(l,"renderWaferGallery")}))}if(n.length===0)return;const i=a;return{source:{items:n,population:n.length===1?`on ${n[0].label}`:`on ${n.length} ${t}wafers`,testDefs:We().defs,activeTest:i.plotMode==="value"?i.activeTest:void 0,notMeasuredReason:o?Tn:void 0},ctx:{plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,onSaveImage:I.onSaveImage,onSaveText:I.onSaveText,onLocateDie:(s,l)=>pe(l,s)}}}function Bi(){let e;for(let i=0;i<C.length;i++)if((C[i]?.getSelectedDies().length??0)!==0){if(e!==void 0)return;e=i}const t=e===void 0?void 0:x[e];if(e===void 0||!t)return;const n=C[e].getSelectedDies(),o=a;return{source:da(n,{waferLabel:we(t),testDefs:t.testDefs,isLotStack:t.isLotStack,activeTest:o.plotMode==="value"?o.activeTest:void 0,waferIndex:e,wafer:t.wafer,passBins:ve(t),ringCount:ne(t,"renderWaferGallery")}),ctx:{onSaveImage:I.onSaveImage,onSaveText:I.onSaveText,onLocateDie:(i,s)=>pe(s??e,i)}}}function Ei(e){e||oo(),ae=e,Ot()}function Mt(e,t){const n=new Set(e),o=t??C.map((i,s)=>s);for(const i of o){const s=x[i],l=C[i];if(!s||!l)continue;const c=s.dies.filter(r=>n.has(Vt(r)));l.setSelection(c)}}const Y=new Set,on=new Map;function ao(){[...P.querySelectorAll(".wmap-gallery-card")].forEach((n,o)=>{n.style.outline=Y.has(o)?`2px solid ${v.iconActive}`:"",n.style.outlineOffset=Y.has(o)?"-2px":""});const t=Y.size;ee.style.display=t>0?"":"none",ee.textContent=`${t} wafer${t===1?"":"s"} picked \u2715`,ee.ariaLabel=`${t} wafer${t===1?"":"s"} picked. Click to clear.`}function Oi(e){e<0||(Y.has(e)?Y.delete(e):Y.add(e),ao())}function Ti(){Y.clear(),ao()}function lo(e){if(!(Y.size===0||!Y.has(e))){for(const t of on.values())if(t>0)return;return so([...Y],"picked ")}}function Li(){const e=[];for(let t=0;t<B().length;t++){const n=B()[t];if(!n)continue;const o=Yn(t)?.findings??[];o.length&&e.push({index:t,item:n,unusualCount:o.filter(i=>i.severity==="unusual").length,notableCount:o.filter(i=>i.severity==="notable").length,totalCount:o.length})}return e}function Wi(e){const t=x[e]??B()[e];t&&rt(e,t)}function Ri(e){const t=Yn(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 Ai(){import("../stats/renderSummaryReport.js").then(({renderLotReportHtml:e})=>{Qs(e(Ra(B(),mt())),{anchor:u})})}function Pi(){if(!S)return;S.innerHTML="";const e=Li();if(B().length>0){const n=u.ownerDocument.createElement("div"),o=e.length,i=B().filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${i} wafers`:`${o} of ${i} wafer${i===1?"":"s"} with findings`,Object.assign(n.style,{fontSize:N.body,color:v.label,marginBottom:M.md}),S.appendChild(n)}if(e.length>0){const n=u.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...Bs("outlined"),marginBottom:M.lg,display:"block",width:"100%",textAlign:"left"}),En(n),n.addEventListener("click",Ai),S.appendChild(n)}if(e.length===0){const n=u.ownerDocument.createElement("div");Object.assign(n.style,{color:v.icon,fontSize:N.body,padding:"4px 0"}),n.textContent="No findings on any wafer.",S.appendChild(n)}else for(const{index:n,item:o,unusualCount:i,notableCount:s,totalCount:l}of e){const c=i?"unusual":s?"notable":"info",r=i+s||l,p=u.ownerDocument.createElement("button");p.type="button",Object.assign(p.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:M.xs,border:"none",borderLeft:`3px solid ${Uo(c)}`,borderRadius:q.control,background:v.bgHover,cursor:"pointer",fontSize:N.body,textAlign:"left",boxSizing:"border-box"}),p.addEventListener("mouseover",()=>{p.style.background=v.bgActive}),p.addEventListener("mouseout",()=>{p.style.background=v.bgHover});const m=u.ownerDocument.createElement("span");m.textContent=pt(o,n),Object.assign(m.style,{color:v.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const f=u.ownerDocument.createElement("span");f.textContent=String(r),p.setAttribute("aria-label",`${pt(o,n)} \u2014 ${r} finding${r===1?"":"s"}${i?`, ${i} unusual`:""} \u2014 view wafer`),Object.assign(f.style,{marginLeft:M.sm,flexShrink:"0",background:Uo(c),color:"#fff",borderRadius:q.container,padding:"1px 5px",fontSize:N.body,fontWeight:"600"}),p.appendChild(m),p.appendChild(f),p.addEventListener("click",()=>rt(n,o)),S.appendChild(p)}const t=u.ownerDocument.createElement("div");t.style.height="12px",S.appendChild(t)}let Fe=null,et=null;function W(){if(!S||Se&&K&&!ze&&yt)return;Fe?.cancel(),Fe=null;const e=se();if(e){const t=Ft(B().map(o=>o?.hbinDefs)),n=Ft(B().map(o=>o?.sbinDefs));Fe=ja(Wa(S,{lotSummary:e,items:B(),hbinDefs:t.length?t:void 0,sbinDefs:n.length?n:void 0,testDefs:Xe(),ringCount:mt(),binColors:a.binColors,plotMode:a.plotMode??"hardBin",fallbackFormat:a.fallbackFormat,activeFindingId:J,warnings:d.warnings?.display??!0?me:[],findingsFilter:bi,findingsNotice:Zt(),onFindingsFilterChange:W,onSaveText:I.onSaveText,attributes:d.attributes,onFindingClick:(o,i)=>{J===o.id?(ke(),qn()):(St(),mo(o,i)),W()},activeTest:fe,onTestClick:o=>{const i=fe===o;i||St(),ke(),i?qn():po(o),W()},onShowChart:$?o=>{st(!0),To().then(i=>i?.showWorthCard(o))}:void 0,onWaferClick:Wi,findingsFor:Ri,dieListOptions:d.dieList,onLocateDie:(o,i)=>pe(i,o),onClose:()=>an(!1)}),{onDone:()=>{const o=et;et=null,o?.()}})}else Pi()}function ro(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}let kt=[];function co(){if(kt.length!==0){for(const e of kt)C[e]?.setOptions({plotMode:a.plotMode,activeTest:a.activeTest});kt=[]}}function ke(){J=null,fe=null,Jt(),en(),co(),R({highlightBin:void 0},{fireCallback:!1})}function uo(){J===null&&fe===null||(Re=null,ke(),W())}function fo(e,t){const n=Xe();if(n===void 0||n.some(i=>i.testNumber===e))R({plotMode:"value",activeTest:e,highlightBin:void 0},{fireCallback:!1});else{R({highlightBin:void 0},{fireCallback:!1});const s=ie.has(a.plotMode??"hardBin")?null:t;if(s){for(const l of s)C[l]?.setOptions({plotMode:"value",activeTest:e});kt=[...s]}}}function po(e){fe=e;const t=o=>x[o]?.statsSummary?.stats.testFailures?.[e]?.dieKeys,n=x.map((o,i)=>i).filter(o=>t(o)?.length);if(fo(e,n.length?n:null),Jt(),en(),!ie.has(a.plotMode??"hardBin"))for(const o of n)Mt(t(o),[o])}function mo(e,t){if(J===e.id){ke();return}J=e.id,fe=null,t&&(t.style.background=v.bgActive,t.style.fontWeight="600"),co();const{kind:n,index:o}=e.variable;if(n==="test")fo(o??0,ro(e));else{const s=x.some(c=>c?.dies?.some(r=>r.hbin!=null)),l=Xo(x.map(c=>c?ut(c):void 0));R({plotMode:ma(e,a.plotMode,s),highlightBin:pa(e,l,s)},{fireCallback:!1})}Jt(),en();const i=e.highlight;if(i.kind==="wafer"){to(i.waferIndices);const s=ai(e);for(const l of i.waferIndices){const c=i.dieKeysByWafer?void 0:x[l]?.statsSummary?.findings.find(p=>ai(p)===s),r=i.dieKeysByWafer?.[l]??c?.highlight?.dieKeys;r?.length&&Mt(r,[l])}}else i.kind==="bin"?i.dieKeys?.length&&Mt(i.dieKeys):(i.kind==="region"||i.kind==="dies")&&i.dieKeys?.length&&Mt(i.dieKeys)}function sn(){return!!S&&S.style.display!=="none"}function an(e){!S||e===sn()||(e&&W(),S.style.display=e?"flex":"none",le())}function le(){vt&&(Xt(H),Yt(H,"inline-flex"),vt.sync({visible:!!(K||se()||Un())&&!!S&&!it,open:sn(),notable:!!(se()?.hasNotableFindings||B().some(e=>e?.statsSummary?.hasNotableFindings))}))}const H=u.ownerDocument.createElement("div");H.dataset.wmapToolbar="gallery",Object.assign(H.style,{flexShrink:"0",marginLeft:"auto",display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:q.control,padding:"0",boxShadow:Bn.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const go=()=>{const e=Ze();e&&(e.remove(),Qe(null)),ft(re,!1)},re=Pe("mode","Plot mode",()=>{if(Ze()){go();return}const e=B().flatMap(w=>w?.dies??[]),t=Xe(),{testEntries:n,binEntries:o,stackedEntries:i}=Ys(e,t,{includeStacked:!0}),s=B().filter(Boolean).length,l=w=>{if(w===void 0)return s;let T=0;for(const A of B())A?.dies?.some(j=>li(j,w)!==void 0||Ha(j,w)!==void 0)&&T++;return T},c=s<2?n:n.map(w=>{const T=l(w.activeTest);return T===s?w:{...w,label:`${w.label} \u2014 ${T} of ${s} wafers`}}),r=a.plotMode??"hardBin",p=a.activeTest??0;function m(w){return w.plotMode!==r?!1:w.plotMode==="value"?p===(w.activeTest??0):w.plotMode==="metadata"?a.activeMetadataKey===w.activeMetadataKey:!0}function f(w,T){w.activeTest!==void 0?R({plotMode:"value",activeTest:w.activeTest,activeMetadataKey:void 0,logScale:w.logScale}):w.activeMetadataKey!==void 0?R({plotMode:w.plotMode,activeTest:void 0,activeMetadataKey:w.activeMetadataKey,passFailDisplay:"off"}):R({plotMode:w.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),T.remove(),Qe(null),ft(re,!1)}const g=new Set,h=B().flatMap(w=>w?.metadataFields??[]).filter(w=>!g.has(w.key)&&g.add(w.key)).filter(w=>Us(e,w.key)).map(Zs),y=Rs(re.getBoundingClientRect(),c,o,i,m,f,{makeMenuRow:vi,makeMenuSection:Si},r,re.ownerDocument.defaultView??window,h);Jo(re).appendChild(y),Qe(y),ft(re,!0),ei(y,re,go)});ft(re,!1);const Fi=()=>x.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:$i,sync:ho}=Vs(Ae,()=>({...a,plotMode:a.plotMode??"hardBin"}),Fi,e=>R(e));ho();const Ii=k.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function Dt(){const e=Xe(),{testNumber:t}=gs(a.activeTest??0,e);return{testNumber:t,td:hs(e,t)}}function yo(){if((a.plotMode??"hardBin")!=="value")return!1;const{td:e}=Dt();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function tt(){if((a.plotMode??"hardBin")!=="value")return!1;const{td:e}=Dt();return e!==void 0&&!Wn(e)}function Vi(){if((a.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=Dt();return B().some(n=>n?.dies?.some(o=>li(o,e,t)!==void 0))}function Hi(e,t){if(!t||!Wn(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((ti(a)==="spec"&&n?"spec":a.colorbarRangeMode??"spec")==="spec"&&n)return;let s=1/0,l=-1/0;for(const c of B())if(c)for(const r of c.dies){const p=va(r,e);p!==void 0&&(p<s&&(s=p),p>l&&(l=p))}if(isFinite(s))return s===l?[s,s+1]:[s,l]}function Bt(e,t,n){const o=a[e];if(o===t||o!=null&&t!=null&&n(o,t))return!1;a={...a,[e]:t};for(const i of C)i&&i.setOptions({[e]:t});return!0}function bo(){if((a.plotMode??"hardBin")!=="metadata")return;const e=a.activeMetadataKey;if(!e)return;const t=new Set;for(const n of B())if(n)for(const o of ys(n.dies,e))t.add(o);return{key:e,values:[...t].sort($n)}}function ln(){Bt("metadataValueOrder",bo(),(e,t)=>e.key===t.key&&It(e.values,t.values))}function rn(){if((a.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=Dt(),n=Hi(e,t);Bt("valueRange",n?{test:e,range:n}:void 0,(i,s)=>{const l=p=>Array.isArray(p)?{test:void 0,range:p}:{test:p.test,range:p.range},c=l(i),r=l(s);return c.test===r.test&&It(c.range,r.range)})}let cn=!1;function ji(){if(cn)return;cn=!0,(u.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{cn=!1,rn(),ln(),Co(),So()})}let dn=!1;function zi(){if(dn)return;dn=!0,(u.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{dn=!1,Rt()})}let wo=[];function G(){const{colors:e,mixedHardBins:t}=ws(B().filter(n=>n!=null),{binColorScheme:a.binColorScheme,useDefinedBinColors:a.useDefinedBinColors});return wo=t,e}function un(){return x.filter(e=>e!=null).flatMap(e=>e.dies)}function vo(){return a.compact?Ea(un()):void 0}const Ni=(e,t)=>It(e.columns,t.columns)&&It(e.rows,t.rows);function So(){Bt("compactMap",vo(),Ni)&&Po()}function Gi(){return Oa(un(),x.filter(e=>e!=null).map(e=>e.reticleConfig))}function Co(){Bt("binColors",G(),Cs),De()}const _i=zs(Ae,()=>_s(a,Ii,{functionalActive:tt(),hasLimits:yo()&&!tt(),hasRecorded:Vi()&&!tt(),binMode:(a.plotMode??"hardBin")==="hardBin"||(a.plotMode??"hardBin")==="softBin"},e=>R(e),{on:!!a.compact,offered:Gi(),onChange:e=>R({compact:e}),onDiagnostics:()=>qs(un(),x.filter(e=>e!=null).map(e=>e.reticleConfig),{anchor:u,onSaveText:I.onSaveText})}),()=>Ks(a)),{btn:Ki,sync:xo}=js(Ae,()=>({plotMode:a.plotMode,legendPosition:Ne}),e=>{Ne=e;for(const t of C)t&&t.setOptions({legendPosition:Ne})},{get:()=>gt,set:e=>{gt=e,jn()},blockedReason:Ge});xo();const qi=[{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"}],Mo=Qn("aggr","Aggregation method",()=>qi,()=>a.aggregationMethod??"mean",e=>R({aggregationMethod:e}));function ko(){const e=a.plotMode==="stackedValues";Mo.style.display=e?"":"none"}ko();const{btn:Xi,sync:Do}=Hs(Ae,()=>({...a,functionalActive:tt()}),e=>R(e));Do();const Et=Pe("specRange","Colorbar range: test limits",()=>{const e=a.colorbarRangeMode==="data"?"spec":"data";R({colorbarRangeMode:e})});function Bo(){const e=(a.plotMode??"hardBin")==="value"&&yo()&&ti(a)==="off"&&!tt();Et.style.display=e?"":"none";const t=(a.colorbarRangeMode??"spec")==="spec";Zn(Et,t),Et.ariaLabel=t?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"}Bo();const Yi=Ns(Ae,()=>a,e=>R(e)),Ui=Pe("downloadAll","Download gallery PNG",cs),$e=Pe("boxSelect","Select the same dies on every wafer",()=>{ae&&Me.size>0?oo():Ei(!ae)});$e.style.position="relative";const nt=u.ownerDocument.createElement("span");nt.dataset.wmapSelectAcrossCount="1",Object.assign(nt.style,{position:"absolute",top:"0",right:"0",minWidth:"14px",height:"14px",boxSizing:"border-box",padding:"0 3px",borderRadius:q.pill,background:v.iconActive,color:v.menuBg,fontSize:"11px",lineHeight:"14px",fontWeight:"700",textAlign:"center",pointerEvents:"none",display:"none"}),$e.appendChild(nt);function Ot(){Zn($e,ae);const e=ae?Me.size:0;nt.style.display=e>0?"block":"none",nt.textContent=e>99?"99+":String(e),$e.ariaLabel=ae?e>0?`Select the same dies on every wafer: on, ${e.toLocaleString()} die position${e===1?"":"s"} selected (click to clear the selection)`:"Select the same dies on every wafer: on (click to turn off)":"Select the same dies on every wafer: off (click to turn on)",$e.setAttribute("aria-pressed",String(ae))}const ee=u.ownerDocument.createElement("button");ee.type="button",ee.dataset.wmapPickedWafers="1",Object.assign(ee.style,{display:"none",border:"none",background:v.bgActive,color:v.iconActive,borderRadius:q.control,padding:`${M.xs} ${M.md}`,fontSize:N.body,cursor:"pointer",whiteSpace:"nowrap",flexShrink:"0"}),En(ee,"bare"),ee.addEventListener("click",Ti);const Zi=Qn("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"}],()=>O!=null?String(O):"auto",e=>Io(e==="auto"?void 0:Number(e))),L=u.ownerDocument.createElement("div");Object.assign(L.style,{display:"inline-flex",alignItems:"center",gap:"0"}),H.appendChild(L),L.appendChild(re),L.appendChild($i),L.appendChild(Mo),L.appendChild(Xi),L.appendChild(Et),L.appendChild(Ce()),L.appendChild(_i),L.appendChild(Ce()),L.appendChild(Ki),L.appendChild(Ce()),L.appendChild(Yi),L.appendChild(Ce()),L.appendChild(Zi),L.appendChild(Ce()),L.appendChild($e),L.appendChild(ee),L.appendChild(Ui),Ot();let te=null,Tt=null,me=[],Eo=!1;function De(){const e=ka({lotStatsSummary:se(),result:{warnings:[...B().flatMap(n=>n?.warnings??[]),...We().warnings]},extra:[a.binColors&&vs(a.binColors,a.plotMode),Ss(wo),mi(Hn())].filter(n=>!!n)}),t=e.length!==me.length||e.some((n,o)=>n.code!==me[o]?.code||n.message!==me[o]?.message);me=e,(t||!Eo)&&(Eo=!0,d.warnings?.onWarning?.(e)),Qi()}function Qi(){if(!te||!Tt)return;const e=me.length,t=e>0;if(te.style.display=t?"flex":"none",Tt.style.display=t?"":"none",Xt(H),Yt(H,"inline-flex"),!t)return;const n=Ba(me[0]),o=`${e} data ${e===1?"warning":"warnings"}`;te.style.color=n==="error"?v.errText:v.warnText,te.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(d.warnings?.display??!0)&&(Tt=Ce(),te=Pe("warning","Data warnings",()=>{const e=Ze();if(Ct(new MouseEvent("click")),e)return;const t=Da(te.getBoundingClientRect(),me,te.ownerDocument.defaultView??window);Jo(u).appendChild(t),Qe(t),ei(t,te,()=>Ct(new MouseEvent("click")))}),ft(te,!1),H.appendChild(Tt),H.appendChild(te)),De();function fn(e){import("./userGuideHtml.js").then(t=>Js({buildWaferMap:ha,renderWaferMap:ra,renderWaferGallery,analyzeWaferMap:Rn},t.USER_GUIDE_HTML,E,u,e))}const Ji=ea(e=>fn(e));D&&(H.appendChild(Ce()),H.appendChild(Pe("help","User guide",()=>fn())));const Ie=u.ownerDocument.createElement("div");Ie.dataset.wmapGalleryMeta="1",Object.assign(Ie.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${M.sm} ${M.lg}`,fontSize:N.sub,lineHeight:Yo.none,boxSizing:"border-box"});const Be=u.ownerDocument.createElement("div");Object.assign(Be.style,{background:v.canvasBg,display:"flex",alignItems:"stretch",gap:M.lg,paddingBottom:M.lg,minWidth:"0"});const ge=u.ownerDocument.createElement("div");ge.dataset.wmapGalleryLegend="1",Object.assign(ge.style,{display:"flex",flexDirection:"column",gap:M.sm,background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:q.container,padding:`${M.sm} ${M.lg}`,marginBottom:M.lg,boxShadow:Bn.panel,fontSize:N.body,lineHeight:Yo.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const U=u.ownerDocument.createElement("div");Object.assign(U.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let he=null,ot=null,Oo=null;function To(){return $?he?Promise.resolve(he):(Oo??=Promise.all([import("./insightsTab.js"),Gt()]).then(([{createInsightsTab:e},t])=>(he=e({pageFilter:t,showFilterButton:!1,initialAxisPrefs:An(a),onAxisPrefsChange:n=>{a={...a,...Ma(n)};const o=[...Pn];d.onViewOptionsChange?.($t(a),o,Ln(o))},attributes:d.attributes,getItems:()=>V,getLotStats:()=>K,getBinColors:()=>a.binColors??G(),getRingCount:()=>ne({ringCount:mt()},"the Insights tab"),defaultView:d.insights?.defaultView,plotStore:F,onPickPlotsFile:d.insights?.onPickPlotsFile,showOnMap:n=>{if(st(!1),n.kind==="test")St(),ke(),po(n.testNumber);else{const o=se(),i=o?ga(o).findings.find(s=>s.id===n.id):void 0;i&&J!==i.id&&(St(),mo(i))}an(!0),W()},onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:I.onSaveImage,onSaveText:I.onSaveText,ownerDocument:u.ownerDocument,locateDie:(n,o)=>{st(!1),pe(o,n)},openWafer:(n,o,i)=>{const s=B()[n];if(!s)return;let l=null;const c=Fs({title:o,onClose:()=>l?.destroy(),anchor:u});jo(c,o,s.wafer.metadata??void 0),l=Sn(c.contentWrap,s,i,void 0,ni(c))}}),ot=he.el,ot.style.display="none",u.appendChild(ot),he)),Oo):Promise.resolve(null)}let it=!1,pn=null;function st(e){$&&(it=e,pn?.setInsightsOpen(e),ot&&(ot.style.display=e?"flex":"none"),U.style.display=e?"none":"flex",ue&&(ue.el.style.display=X?.get()&&!e?"":"none"),L.style.display=e?"none":"inline-flex",Xt(H),Yt(H,"inline-flex"),H.style.display="inline-flex",le(),Rt(),e&&To().then(t=>{!t||!it||(t.el.style.display="flex",t.render())}))}$&&d.insights?.defaultOpen&&queueMicrotask(()=>st(!0));const Lo=4,Lt=240,mn=480,es=720,ts=1.25;let Ee=mn;function Wo(e){const t=z*2+110+2,n=Ro();if(n)return Math.ceil(n.across*Lo+t);let o=null;for(const i of e){if(i==null||!i.dies?.length)continue;const s=i.dies[0].width;if(!(s>0))continue;const l=i.wafer.radius*2*(Lo/s),c=Math.ceil(l+t);(o==null||c>o)&&(o=c)}return o}function ns(e){const t=Wo(e);return t==null?Lt:Math.min(Ee,Math.max(Lt,t))}function os(e){const t=Wo(e);if(t==null)return!1;const n=Math.min(es,Math.max(mn,t));return n<=Ee?!1:(Ee=n,!0)}function Ro(){const e=a.compact?a.compactMap:void 0,t=x.find(i=>i?.dies?.length)?.dies[0];if(!e||!t||e.columns.length===0||e.rows.length===0||!(t.width>0)||!(t.height>0))return;const n=(a.rotation??0)%180!==0,o=a.showXYIndicator?2.5:0;return{across:(n?e.rows.length:e.columns.length)+o,down:(n?e.columns.length:e.rows.length)+o,cellAspect:n?t.height/t.width:t.width/t.height}}function Ao(e,t){const n=Ro();if(!n){e.style.aspectRatio="1",t.style.flex="1",t.style.width="",t.style.aspectRatio="";return}e.style.aspectRatio="auto",t.style.flex="none",t.style.width="100%",t.style.aspectRatio=String(n.across*n.cellAspect/n.down)}function is(){for(const e of de)e?.parentElement&&Ao(e.parentElement,e)}function Po(){Ee=mn,at=Lt,yn(x.map(e=>e??null)),Wt(),is()}function gn(){return Fo()?`${Ee}px`:"none"}function Fo(){return O==null&&!hn}let hn=!1;function Wt(){const e=gn();for(const t of Array.from(P.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let at=Lt,$o=0;function yn(e){if(os(e)&&Wt(),O==null){const n=ns(e);n>at&&(at=n)}wn()}function Io(e){O=di(e),Wt(),wn()}function bn(e){return`repeat(${e}, minmax(0, ${Fo()?`${Ee}px`:"1fr"}))`}function Vo(e){P.style.gridTemplateColumns!==e&&(P.style.gridTemplateColumns=e)}function wn(){if(O!=null){Vo(bn(O));return}const e=Math.max(1,$o),t=12,n=P.clientWidth||0,o=l=>(n-t*(l-1))/l;let i=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const l=Math.min(Ee,at*ts),c=r=>{let p=0;for(;p<e&&o(p+1)>=r;)p++;return p};i=c(l)||c(at)||1}const s=n>0&&i<e;s!==hn&&(hn=s,Wt()),Vo(bn(i))}const P=u.ownerDocument.createElement("div");if(Object.assign(P.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:bn(1),gap:M.xl,paddingLeft:oe,paddingRight:oe,justifyContent:"start",alignContent:"start",isolation:"isolate"}),Oe?.placement){const e=Oe.placement;S=In(e,oe,u.ownerDocument,nn),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.display="flex",S.style.flexDirection="column"}else if(K||se()||Un()){const e=!!Oe?.defaultOpen;S=In("right",oe,u.ownerDocument,nn),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.flexDirection="column",S.style.display=e?"flex":"none",W()}le(),(Oe?.placement??"right")==="left"?(S&&U.appendChild(S),U.appendChild(P)):(U.appendChild(P),S&&U.appendChild(S));const lt=u.ownerDocument.createElement("div");Object.assign(lt.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:oe,paddingRight:oe,paddingTop:oe,zIndex:"1",background:v.menuBg}),Be.appendChild(Ie),Be.appendChild(H),vt=ps(u.ownerDocument,()=>an(!sn())),Be.appendChild(vt.el),le(),$&&(pn=fs(u.ownerDocument,"Maps","lot",e=>st(e)),Be.appendChild(pn.el)),$&&(wt=ta(u.ownerDocument,"Filter\u2026","wmapGalleryFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>{Gt().then(e=>e.openEditor(wt??u,Kt()))}),wt.style.order="1",Be.appendChild(wt)),lt.appendChild(Be),lt.appendChild(ge),u.appendChild(lt),u.appendChild(U);function Rt(){ge.innerHTML="";const e=a.plotMode??"hardBin",t=!it&&Zo.has(e),n=x.filter(b=>b!=null&&!_e.has(b)),o=n.find(b=>b.isLotStack),i=Ta(n.map(b=>({metadata:b.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0,{curation:d.attributes}),s=e==="metadata",l=a.activeMetadataKey,c=t&&!s?ui(n,b=>(e==="softBin"?b.sbin:b.hbin)??void 0,ve):{counts:new Map,total:0,pass:0},r=t&&!s?a.binColors??G():void 0,p=r?e==="softBin"?r.pass.soft:r.pass.hard:new Set,m=ia(c.counts.entries(),p).map(([b])=>b),f=t&&s&&l?ui(n,b=>bs(b.metadata?.[l])):{counts:new Map,total:0,pass:0},g=s?bo()?.values:void 0,h=t&&s?(g??[...f.counts.keys()].sort($n)).filter(b=>f.counts.has(b)):[];if(Ie.innerHTML="",i&&Ie.appendChild(i),Ie.style.display=i?"flex":"none",!m.length&&!h.length){ge.style.display="none";return}ge.style.display="flex";const y=u.ownerDocument.createElement("div");Object.assign(y.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${M.sm} ${M.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),ge.appendChild(y);const w=Fn(a.highlightBin),T=x.flatMap(b=>b?.metadataFields??[]).find(b=>b.key===l),A=s?T?.label??(l?Aa(l):"Metadata"):Os[e],j=u.ownerDocument.createElement("span");if(j.textContent=A,Object.assign(j.style,{fontSize:N.body,fontWeight:"700",letterSpacing:Ds,textTransform:"uppercase",color:v.label,flexShrink:"0"}),y.appendChild(j),!s&&c.total>0){const b=c.pass,_=b/c.total*100,ye=u.ownerDocument.createElement("span");ye.textContent=`Yield ${Ht(_)}`,Object.assign(ye.style,{fontSize:N.body,fontWeight:"700",color:v.value,whiteSpace:"nowrap",flexShrink:"0"});const be=u.ownerDocument.createElement("span");be.textContent=`${b.toLocaleString()} / ${c.total.toLocaleString()} dies`,Object.assign(be.style,{fontSize:N.body,color:v.label,whiteSpace:"nowrap",flexShrink:"0"}),y.appendChild(ye),y.appendChild(be)}if(s){const b=Fn(a.highlightMetadataValue);h.forEach((_,ye)=>{const be=b.includes(_),je=T?.values?.find(kn=>kn.value===_),dt=je?.color??Ms(ye),qo=f.counts.get(_)??0;fi(y,{color:dt,isActive:be,label:je?.label??_,count:qo,percent:f.total>0?qo/f.total*100:void 0,onClick:kn=>{const us=ri(a.highlightMetadataValue,_,kn);uo(),R({highlightMetadataValue:us})}})});return}const ct=e==="softBin"?x.flatMap(b=>b?.sbinDefs??[]):x.flatMap(b=>b?.hbinDefs??[]),Go=new Set,xn=[];for(const b of ct)Go.has(b.bin)||(Go.add(b.bin),xn.push(b));const Mn=xn.length>0?new Map(xn.map(b=>[b.bin,b])):null,_o=r??a.binColors??G(),ds=e==="softBin"?_o.soft:_o.hard,Ko=b=>ds.get(b)??xs;for(const b of m){const _=w.includes(b),ye=Mn?.get(b),be=c.counts.get(b)??0;fi(y,{color:Ko(b),isActive:_,label:ye?.name?`${b} \xB7 ${ye.name}`:`Bin ${b}`,count:be,percent:c.total>0?be/c.total*100:void 0,onMenu:(je,dt)=>Di(e==="softBin"?"soft":"hard",b,je,dt),onClick:je=>{const dt=ri(a.highlightBin,b,je);uo(),R({highlightBin:dt})}})}c.total>0&&m.length>1&&ge.appendChild(za(u.ownerDocument,[...c.counts.entries()].sort(([,b],[,_])=>_-b).map(([b,_])=>({color:Ko(b),count:_,label:Mn?.get(b)?.name?`${b} \xB7 ${Mn.get(b).name}`:`Bin ${b}`})),c.total))}function Ve(e){const t=B().filter(f=>f!==null&&!_e.has(f));if(!t.length)return[];const n=t.map(f=>f.dies.filter(Va).filter(g=>!g.filteredOut)),o=t[0].wafer,i=t.length,s=Xo(t.map(f=>ut(f)));if(!s)return[];const l=new Set(t.map(f=>ne(f,"renderWaferGallery")));if(l.size!==1)return[];const c=[...l][0],r=o.metadata?{...o,metadata:(({wafer:f,waferId:g,...h})=>h)(o.metadata)}:o;function p(f,g){return{...f,stats:{...f.stats,isLotStack:!0,aggregationMethod:g,lotSize:i}}}function m(f,g){const h=f.map(y=>({...y,hbin:void 0,sbin:void 0}));return Rn({wafer:r,dies:h,passBins:[...s],ringCount:c,testDefs:[{testNumber:0,name:g}]},{testNumbers:[0]})}if(e==="stackedValues"){const f=Xe();let g=f?.filter(Wn);if(f!==void 0&&g?.length===0)return[];if(f?.length||(g=ms(t.flatMap(w=>w.dies)).map(w=>({testNumber:w,name:Pa(void 0,w)}))),!g?.length)return[];const h=a.aggregationMethod??"mean";return g.map(y=>{const w=la(n,h,y.testNumber),T={testNumber:0,name:y.name,unit:y.unit,...$a(y)};return{wafer:r,dies:w,passBins:[...s],ringCount:c,testDefs:[T],label:`${Fa(y,y.testNumber)} \xB7 ${h}`,isLotStack:!0,aggrMethod:h,lotSize:i,statsSummary:p(Rn({wafer:r,dies:w,passBins:[...s],ringCount:c,testDefs:[T]},{testNumbers:[0]}),h)}})}if(e==="stackedBins"){let f=Ft(t.map(g=>g?.hbinDefs));return(!f||f.length===0)&&(f=[...new Set(t.flatMap(h=>h.dies.map(y=>y.hbin).filter(y=>y!=null)))].sort((h,y)=>h-y).map(h=>({bin:h,name:`Bin ${h}`}))),f.map(g=>{const h=oi(n,g.bin,"hard"),y=[{bin:g.bin,name:g.name}];return{wafer:r,dies:h,passBins:[...s],ringCount:c,hbinDefs:y,label:`${g.bin} \xB7 ${g.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:p(m(h,`Wafers in hard bin ${g.bin}`),"countBin")}})}if(e==="stackedSoftBins"){let f=Ft(t.map(g=>g?.sbinDefs));return(!f||f.length===0)&&(f=[...new Set(t.flatMap(h=>h.dies.map(y=>y.sbin).filter(y=>y!=null)))].sort((h,y)=>h-y).map(h=>({bin:h,name:`Bin ${h}`}))),f.map(g=>{const h=oi(n,g.bin,"soft"),y=[{bin:g.bin,name:g.name}];return{wafer:r,dies:h,passBins:[...s],ringCount:c,sbinDefs:y,label:`${g.bin} \xB7 ${g.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:p(m(h,`Wafers in soft bin ${g.bin}`),"countBin")}})}return t}function At(e){const t=B().length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:a.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}function R(e,{fireCallback:t=!0}={}){const n=Object.keys(e);if(n.length>0&&n.every(m=>Pn.includes(m))){a={...a,...e},he?.setAxisPrefs(An(a)),t&&d.onViewOptionsChange?.($t(a),n,Ln(n));return}Pn.some(m=>m in e)&&he?.setAxisPrefs(An({...a,...e}));const o=a.plotMode,i=Ge()!==null;a={...a,...e};const s=a.plotMode,l=ie.has(s),c=o!==void 0&&ie.has(o),r=Ue>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const m=G();a={...a,binColors:m},e={...e,binColors:m}}if("compact"in e){const m=vo();a={...a,compactMap:m},e={...e,compactMap:m}}if(("compact"in e||a.compact&&("rotation"in e||"showXYIndicator"in e))&&Po(),e.plotMode!==void 0)if(l){const m=At(s);if(a={...a,...m},r)for(const f of C)f&&f.setOptions(e);else Z(Ve(s))}else if(c){const{valueRange:m,lotSize:f,aggregationMethod:g,...h}=a;if(a=h,r)for(const y of C)y&&y.setOptions(e);else Z(B().filter(y=>y!==null))}else for(const m of C)m&&m.setOptions(e);else if(e.aggregationMethod!==void 0&&s==="stackedValues")if(r)for(const m of C)m&&m.setOptions(e);else Z(Ve("stackedValues"));else for(const m of C)m&&m.setOptions(e);Ge()!==null!==i&&jn(),Rt(),ko(),xo(),ho();const p=e.plotMode!==void 0&&e.plotMode!==o;(fa.some(m=>m in e)||p)&&W(),De(),Do(),Bo(),rn(),ln(),t&&d.onViewOptionsChange?.($t(a),n,Ln(n))}function Ho(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:M.xs,flex:"1",minWidth:"0"});const i=e.createElement("span");i.textContent=t,Object.assign(i.style,{fontWeight:"700",fontSize:N.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(i);const s=ci(e,o,t,n,d.attributes);return{wrap:o,metaPanel:s}}function jo(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]");if(!o||La(n??{}).length===0)return;const i=o.parentElement,s=u.ownerDocument.createElement("div");Object.assign(s.style,{display:"flex",alignItems:"center",gap:M.xs,flex:"1",minWidth:"0"}),i?.insertBefore(s,o),s.appendChild(o);const l=ci(u.ownerDocument,s,t,n,d.attributes);l&&(e.contentWrap.style.position="relative",e.contentWrap.appendChild(l))}function vn(e,t,n){const o=u.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:q.container,boxShadow:Bn.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:gn(),maxHeight:gn()});const i=u.ownerDocument.createElement("div");Object.assign(i.style,{display:"flex",alignItems:"center",padding:`${M.md} ${M.lg} ${M.sm}`,borderBottom:`1px solid ${v.menuBorder}`,flexShrink:"0",gap:M.sm});const{wrap:s,metaPanel:l}=Ho(document,pt(e,t),e.wafer.metadata??void 0);i.appendChild(s);const c=u.ownerDocument.createElement("button");c.dataset.wmapExpandBtn="1",c.setAttribute("aria-label","Open full view"),On(c),c.innerHTML=Dn.expand,Object.assign(c.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${v.menuBorder}`,borderRadius:q.control,background:v.panelBg,color:v.label,padding:M.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),En(c),i.appendChild(c),i.addEventListener("click",g=>{(g.ctrlKey||g.metaKey)&&(g.preventDefault(),g.stopPropagation(),Oi(x.indexOf(e)))},!0),o.appendChild(i);const r=u.ownerDocument.createElement("div");Object.assign(r.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(r),Ao(o,r),l&&r.appendChild(l),P.appendChild(o),o.addEventListener("contextmenu",g=>{if(g.defaultPrevented)return;g.preventDefault();const h=e.viewOptions?{...a,...e.viewOptions}:a,y=tn()??lo(t),w=y?.source??ca(e.dies,{waferLabel:we(e),testDefs:e.testDefs,isLotStack:e.isLotStack,activeTest:h.plotMode==="value"?h.activeTest:void 0,waferIndex:t,wafer:e.wafer,passBins:ve(e),ringCount:ne(e,"renderWaferGallery")}),T={x:g.clientX,y:g.clientY};import("./drilldown.js").then(({openDrilldownMenu:A})=>{o.isConnected&&A(T,o,w,y?{plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,...y.ctx}:{plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,onSaveImage:f.getSaveImageHook(),onSaveText:f.getSaveTextHook(),onLocateDie:j=>pe(t,j)})})});const p=gt||Ge()!==null,m=e.viewOptions?{...a,...e.viewOptions}:a,f=ii(r,e,{viewOptions:{...m,showLegend:p,legendPosition:Ne},showTooltip:!0,padding:z,statsSummary:e.statsSummary,testValueOffer:Zt,onSaveImage:d.onSaveImage,onSaveText:d.onSaveText,downloadFilename:d.downloadFilename,onClick:e.onClick,onSelect:no(e),drilldownSourceOverride:()=>ki(t),insights:ce,onExpand:()=>rt(t,e),showIdentity:!1,chromeInset:Es,drawWhenVisible:!0});return f.setViewControlsVisible(!1),f.setSummaryVisible(!1),c.onclick=()=>rt(t,e),_e.has(e)&&(o.style.display="none"),{card:o,ctrl:f,canvasWrapper:r,expandBtn:c}}function ss(e){const t=Te[e];if(!t)return;const n=[...Q.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=Dn.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>ls(n.id)):(t.innerHTML=Dn.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>rt(e,x[e]))}function Z(e){rs(),Ze()?.remove(),Qe(null),ke(),x=[],Y.clear(),on.clear(),ee.style.display="none";for(const r of C)r&&r.destroy();C=[],de=[],Te=[],Ue=0,P.innerHTML="",$o=e.length,yn(e.map(r=>typeof r=="function"?null:r));const t=[];for(let r=0;r<e.length;r++){const p=e[r];if(typeof p=="function"){const m=u.ownerDocument.createElement("div");m.className="wmap-gallery-card",Object.assign(m.style,{background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:q.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const f=u.ownerDocument.createElement("span");f.textContent="\u2026",Object.assign(f.style,{color:v.label,fontSize:"18px"}),m.appendChild(f),P.appendChild(m),x.push(null),C.push(null),de.push(null),Te.push(null),t.push({index:r,factory:p,placeholder:m}),Ue++}else{const{ctrl:m,canvasWrapper:f,expandBtn:g}=vn(p,r,e.length);x.push(p),C.push(m),de.push(f),Te.push(g)}}Co(),Rt(),rn(),ln(),So();const n=++Ye,o=()=>{setTimeout(()=>{n===Ye&&d.onItemsResolved?.()},0)},i=r=>{setTimeout(()=>{n===Ye&&d.onItemResolved?.(r,e.length)},0)};let s=e.length-t.length;s>0&&i(s);let l=0;function c(){if(n!==Ye)return;if(l>=t.length){if(ie.has(a.plotMode)){const A=a.plotMode;Z(Ve(A));return}if(zt){qt();return}et=o,W(),Fe||(et=null,o());return}const{index:r,factory:p,placeholder:m}=t[l++],f=p();V[r]=f;const g=qe(f,r);g!==f&&(Se=!0),x[r]=g,yn([g]);const{card:h,ctrl:y,canvasWrapper:w,expandBtn:T}=vn(g,r,e.length);C[r]=y,de[r]=w,Te[r]=T,Ue--,m.replaceWith(h),i(++s),zi(),ji(),!S&&!Oe?.placement&&g.statsSummary?.findings.length&&(S=In("right",oe,u.ownerDocument,nn),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.flexDirection="column",S.style.display="none",(Oe?.placement??"right")==="left"?U.insertBefore(S,P):U.appendChild(S),W(),le()),le(),setTimeout(c,0)}t.length>0?setTimeout(c,0):o()}if(ie.has(a.plotMode)&&B().length>0){const e=At(a.plotMode);a={...a,...e},Z(Ve(a.plotMode))}else Z(bt(k));d.insights?.filter!==void 0&&Gt(),De();let He=0;const zo=new(u.ownerDocument.defaultView??window).ResizeObserver(()=>{if(He)return;He=(u.ownerDocument.defaultView??window).requestAnimationFrame(()=>{He=0,O==null&&wn()})});zo.observe(P),S&&W();function as(e,t){const n=de[e];if(!n)return;n.innerHTML="",Object.assign(n.style,{alignItems:"center",justifyContent:"center"});const o=u.ownerDocument.createElement("span");o.textContent=t?"Opened in its own window":"Opened in the wafer viewer",Object.assign(o.style,{color:v.label,fontSize:N.body,textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function rt(e,t){for(const l of Q.values())if(l.cardIndex===e)return;const n=pt(t,e),o=yi++,i=C[e]?.getOptions(),s=As(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:N.family}),$s(u,l.documentElement);const c=Is(u,l.documentElement,()=>w.setOptions({})),r=l.createElement("div");r.dataset.wmapWindowBanner="1",r.textContent=n,Object.assign(r.style,{display:"none",padding:`${M.sm} ${M.xl}`,fontSize:N.body,fontWeight:"700",background:v.warnBg,color:v.warnText,borderBottom:`1px solid ${v.warnBorder}`,flexShrink:"0"}),l.body.appendChild(r);const p=l.createElement("div");Object.assign(p.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),l.body.appendChild(p);const{wrap:m,metaPanel:f}=Ho(l,n,t.wafer.metadata??void 0),g=l.createElement("div");Object.assign(g.style,{display:"flex",alignItems:"center",padding:`${M.md} ${M.lg} ${M.sm}`,borderBottom:`1px solid ${v.menuBorder}`,flexShrink:"0",gap:M.sm}),g.appendChild(m),p.appendChild(g);const h=l.createElement("div");Object.assign(h.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),f&&h.appendChild(f),p.appendChild(h);let y=0;const w=Sn(h,t,void 0,i,(A,j)=>{const ct=A?j:-y;try{s.resizeBy(ct,0),y=A?j:0}catch{}}),T=setInterval(()=>{s.closed&&Pt(o)},400);s.addEventListener("pagehide",()=>Pt(o)),Q.set(o,{id:o,ctrl:w,cardIndex:e,label:n,closePollId:T,stopThemeSync:c,close:()=>{s.closed||s.close()},setTitle:A=>{l.title=A,r.textContent=A,r.style.display="block"}})}else{const l=Ps({title:n,onClose:()=>Pt(o),anchor:u});l.contentWrap.style.flexDirection="column",jo(l,n,t.wafer.metadata??void 0);const c=Sn(l.contentWrap,t,void 0,i,ni(l));Q.set(o,{id:o,ctrl:c,cardIndex:e,label:n,closePollId:null,close:()=>l.close(),setTitle:r=>{const p=l.box.querySelector("[data-wmap-window-title]");p&&(p.textContent=r,p.title=r)}})}C[e]?.destroy(),C[e]=null,as(e,s!==null),ss(e)}function Sn(e,t,n,o,i){const s=t.viewOptions?{...a,...t.viewOptions}:a,l=o?{...s,...o}:s,r={...n!==void 0?{...l,plotMode:"value",activeTest:n}:l,showLegend:!0,legendPosition:Ne},p=ii(e,t,{viewOptions:r,showTooltip:!0,padding:z,statsSummary:t.statsSummary,testValueOffer:Zt,onSaveImage:d.onSaveImage,onSaveText:d.onSaveText,downloadFilename:d.downloadFilename,onClick:t.onClick,onSelect:no(t),insights:ce,showExpandButton:!1,onSummaryPanelChange:i,showIdentity:!1});return p.setViewControlsVisible(!0),p.setSummaryVisible(!0),p.setExpandVisible(!1),p}function Pt(e){const t=Q.get(e);if(!t||(Q.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.(),t.ctrl.destroy(),t.cardIndex===null))return;const n=t.cardIndex,o=x[n];if(!o)return;const{card:i,ctrl:s,canvasWrapper:l,expandBtn:c}=vn(o,n,x.length);de[n]?.parentElement?.replaceWith(i),C[n]=s,de[n]=l,Te[n]=c}function ls(e){const t=Q.get(e);t&&(t.close(),Pt(e))}function rs(){for(const e of Q.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function Cn(){for(const e of C)e?.drawPendingNow()}const No=u.ownerDocument.defaultView??window;No.addEventListener("beforeprint",Cn);function cs(){Cn();const e=[...P.querySelectorAll("canvas")];if(!e.length)return;const t=e.length,n=Math.ceil(Math.sqrt(t)),o=Math.ceil(t/n),i=e[0].width,s=e[0].height,l=8,c=(u.ownerDocument.defaultView??window).devicePixelRatio||1,r=Math.round(26*c),p=Math.round(12*c),m=u.ownerDocument.createElement("canvas");m.width=n*i+(n-1)*l,m.height=o*(s+r)+(o-1)*l;const f=m.getContext("2d"),g=ks(P);f.fillStyle=g.background,f.fillRect(0,0,m.width,m.height),e.forEach((h,y)=>{const w=y%n,T=Math.floor(y/n),A=w*(i+l),j=T*(s+r+l),ct=h.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";f.fillStyle=g.surface,f.fillRect(A,j,i,r),f.fillStyle=g.text,f.font=`700 ${p}px system-ui, sans-serif`,f.textAlign="left",f.textBaseline="middle",f.fillText(ct,A+Math.round(10*c),j+r/2,i-Math.round(20*c)),f.drawImage(h,A,j+r)}),m.toBlob(h=>{if(!h)return;const y=C.find(w=>w!=null)?.getExportTitle();Gs(h,["gallery",y].filter(Boolean).join(" "),I.onSaveImage)})}return{setItems(e){Qt(),V=e.map(n=>typeof n=="function"?null:n);const t=a.plotMode;if(ie.has(t))if(e.some(o=>typeof o=="function"))Z(bt(e));else{const o=At(t);a={...a,...o},Z(Ve(t))}else Z(bt(e))},setOptions(e){R(e,{fireCallback:!1})},getOptions(){return $t(a)},setFindingsNotice(e){eo=e,W()},setColumns(e){Io(e)},getBinColors(){return a.binColors??G()},setLotStatsSummary(e){Qt(),K=e,De(),S&&W(),le()},openUserGuide:()=>fn(),destroy(){Ji(),F.flush(),Qt(),Ye++,No.removeEventListener("beforeprint",Cn),Fe?.cancel(),Fe=null,et=null;for(const e of[...Q.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();Q.clear();for(const e of C)e&&e.destroy();C=[],Ze()?.remove(),zo.disconnect(),He&&((u.ownerDocument.defaultView??window).cancelAnimationFrame(He),He=0),u.ownerDocument.removeEventListener("click",Ct,!0),window.removeEventListener("blur",Jn),pi(),Qo(),lt.remove(),U.remove(),S?.remove(),jt=!0,ht++,clearTimeout(_t),ue?.el.remove(),he?.destroy()}}}
|
|
1
|
+
import{createViewSwitch as ys}from"./viewSwitch.js";import{createSummaryToggle as bs}from"./summaryToggle.js";import{getUniqueTestNumbers as ws,resolveTestNumber as vs,findTestDef as Ss,collectMetadataValues as Cs}from"../renderer/buildView.js";import{metadataCategoricalValue as xs}from"../core/metadata.js";import{resolveBinColorsForMaps as Ms,mergeBinDefs as $t,binColorWarning as ks,mixedPassBinsWarning as Ds,binColorsEqual as Bs}from"../renderer/binColors.js";import{commonPassBins as Jo,itemPassBins as Xe}from"../core/passBins.js";import{PAT_MODE_FIELD as Es,PAT_MODE_KEY as Os,PAT_MODE_ORDER as Ts,isPatMode as mt,patModeOffered as Ls,withPatField as Ws,withPatVerdicts as Ps}from"./patMode.js";import{requireRingCount as ne}from"../core/ringCount.js";import{NO_DATA_FILL as Rs}from"../renderer/colorMap.js";import{metadataValueColor as As}from"../renderer/colorMap.js";import{resolveCanvasTheme as Fs}from"./canvasTheme.js";import{ICONS as En}from"./icons.js";import{SHADOW as On,LEADING as ei,TRACKING as Is,controlStyle as $s,wireControlHover as Tn,SPACE as M,EDGE_GUTTER as oe,MAP_CHROME_INSET as Vs,RADIUS as Y,FONT as N,CLR as w,sevColor as ti,MODE_LABELS as Hs,BIN_LEGEND_MODES as ni,STACKED_MODES as ie,applyOverlayZ as js,getTooltip as zs,hideTooltip as oi,createToolbarHelpers as Ns,buildModeMenuEl as _s,openDetachWindow as Gs,openFloatingWindow as Ks,openModal as qs,copyWmapThemeTokens as Xs,syncWmapPopupTheme as Ys,makePaletteBtn as Us,makeLogScaleBtn as Zs,makeLegendStyleBtn as Qs,makeOverlaysBtn as Js,makeOrientationBtn as ea,menuLayerFor as ii,saveImageBlob as ta,markMenuTrigger as gt,wireMenuA11y as si,wireTooltip as Ln,requestedPassFailDisplay as ai,overlayMenuRows as na,anyOverlayActive as oa,openCompactDiagnostics as ia,roomForPanel as li,logWmapVersionOnce as sa,buildDataModeEntries as aa,metadataKeyHasData as la,metadataModeEntry as ri}from"./toolbar.js";import{openReportModal as ra,openUserGuideWindow as ca,registerGuideOpener as da}from"./guideWindow.js";import{waferDisplayLabel as ht,waferIdentityLabel as ve}from"../core/waferLabel.js";import{bandButton as ua}from"./filterButton.js";import{metadataDisplayValue as fa}from"../core/metadata.js";import{withExportContext as pa}from"./exportName.js";import{sortBinsForDisplay as ma}from"../stats/binPareto.js";import{diePassStatus as ga,isYieldEligibleDie as ha}from"../core/dies.js";import{aggregateValues as ya,aggregateBinCounts as ci}from"../core/aggregates.js";import{renderWaferMap as ba,renderWaferMapCard as di,toPublicViewOptions as Vt}from"./renderWaferMap.js";import{waferPopulation as wa,selectionPopulation as va,LOT_STACK_REASON as Wn}from"./chartPopulation.js";import{sourceFromBins as ui}from"./plotItems.js";import{plotStoreFor as Sa}from"./plotStore.js";import{classifyChanged as Pn,COLOR_KEYS as Ca,findingBin as xa,findingPlotMode as Ma}from"./renderWaferMap.js";import{findingPatternKey as fi}from"../stats/filterFindings.js";import{synthesisSource as ka}from"../stats/synthesis.js";import{buildWaferMap as Da,computeCoverage as Ba,computeYield as Ea,defaultBinMode as Oa,getTestPassStatus as pi,isParametricTest as Rn,getDieTestValue as Ta,isBuiltMap as La}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as An}from"../stats/analyzeWaferMap.js";import{lotTestValueStatus as Wa}from"../stats/testValueBudget.js";import{testValueNotice as Pa}from"./testValueOffer.js";import{axisPrefsFromOptions as Fn,optionsFromAxisPrefs as Ra,CHART_PREF_KEYS as In}from"./chartPrefs.js";import{collectWarnings as Aa,buildWarningsMenuEl as Fa,severityOf as Ia}from"./warnings.js";import{asList as $n,compareNatural as Vn,arrayEqual as Ht,toggleHighlight as mi}from"../core/utils.js";import{buildCompactMap as $a,compactLayoutOffered as Va}from"../core/compact.js";import{attachExpandableMetadata as gi}from"./identityHeader.js";import{createSummaryPanelEl as Hn,buildMetadataStripRow as Ha,metadataEntries as ja,renderLotSummaryContentSteps as za,reportMapsFromItems as Na}from"./summaryPanel.js";import{prettyKey as _a}from"../stats/facets.js";import{testLabel as Ga,markedTestLabel as Ka,derivedFields as qa}from"../renderer/testLabel.js";import{mergeTestDefs as Xa}from"../stats/mergeTestDefs.js";import{getDieKey as jt,hasPosition as Ya}from"../core/dies.js";import{testValue as Ua}from"../core/dieTable.js";import{runChunked as Za}from"./chunked.js";function hi(f){if(typeof f!="number"||!Number.isFinite(f))return;const k=Math.round(f);return k>=1?k:void 0}const jn=12;function Qa(f,k,u){let z=k;if(k.length>jn){const D=k.slice(0,jn-1),O=k.slice(jn-1),$=O.reduce((I,de)=>I+de.count,0);z=[...D,{color:w.label,count:$,label:`Other (${O.length} bins)`}]}const T=f.createElement("div");Object.assign(T.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:Y.control,overflow:"hidden",border:`1px solid ${w.menuBorder}`,boxSizing:"border-box",marginTop:M.xs,flexShrink:"0"}),T.setAttribute("role","img"),T.setAttribute("aria-label",`Population split: ${z.map(D=>`${D.label} ${zt(D.count/u*100)}`).join(", ")}`);for(const D of z){const O=D.count/u*100,$=f.createElement("div");Object.assign($.style,{flex:`${O} 1 0`,minWidth:O>0?"2px":"0",background:D.color}),Ln($,`${D.label} \xB7 ${D.count.toLocaleString()} dies \xB7 ${zt(O)}`),T.appendChild($)}return T}function zt(f){return f>0&&f<.1?"<0.1%":`${f.toFixed(1)}%`}function yi(f,k,u){const z=new Map;let T=0,D=0;for(const O of f){const $=u?new Set(u(O)):void 0;for(const I of O.dies){if(!ha(I))continue;const de=k(I);de!==void 0&&(z.set(de,(z.get(de)??0)+1),T++,$&&ga(I,$)&&D++)}}return{counts:z,total:T,pass:D}}function bi(f,k){const u=f.ownerDocument.createElement("div");Object.assign(u.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${M.xxs} ${M.xs}`,borderRadius:Y.control});const z=f.ownerDocument.createElement("span");Object.assign(z.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:k.color,border:k.isActive?`2px solid ${w.iconActive}`:`1px solid ${w.menuBorder}`,borderRadius:Y.control,boxSizing:"border-box"});const T=f.ownerDocument.createElement("span");if(T.textContent=k.label,Object.assign(T.style,{fontWeight:k.isActive?"700":"400",color:k.isActive?w.iconActive:w.text,whiteSpace:"nowrap"}),u.appendChild(z),u.appendChild(T),k.count!==void 0){const D=f.ownerDocument.createElement("span");if(D.textContent=k.count.toLocaleString(),Object.assign(D.style,{color:k.isActive?w.iconActive:w.text,fontWeight:k.isActive?"700":"400",whiteSpace:"nowrap"}),u.appendChild(D),k.percent!==void 0){const O=f.ownerDocument.createElement("span");O.textContent=zt(k.percent),Object.assign(O.style,{color:w.label,whiteSpace:"nowrap"}),u.appendChild(O)}}if(u.setAttribute("role","button"),u.setAttribute("aria-pressed",k.isActive?"true":"false"),u.tabIndex=0,u.addEventListener("mouseenter",()=>{u.style.background=w.bgHover}),u.addEventListener("mouseleave",()=>{u.style.background="transparent"}),u.addEventListener("focus",()=>{u.style.background=w.bgHover}),u.addEventListener("blur",()=>{u.style.background="transparent"}),u.addEventListener("click",D=>k.onClick(D.ctrlKey||D.metaKey)),u.addEventListener("keydown",D=>{if(D.key==="Enter"||D.key===" ")D.preventDefault(),k.onClick(D.ctrlKey||D.metaKey);else if(k.onMenu&&(D.key==="ContextMenu"||D.key==="F10"&&D.shiftKey)){D.preventDefault();const O=u.getBoundingClientRect();k.onMenu({x:O.left+O.width/2,y:O.bottom},u)}}),k.onMenu){const D=k.onMenu;u.addEventListener("contextmenu",O=>{O.preventDefault(),D({x:O.clientX,y:O.clientY},u)}),Ln(u,"Right-click: charts and tables for these dies")}f.appendChild(u)}export function renderWaferGallery(f,k,u={}){sa();const z=6;let T=hi(u.columns);const D=u.showHelpButton??!1,O=u.userGuideExtension,$=u.insights?.enabled??!0,I=Sa(u.insights),de={enabled:!1,plotStore:I},wi=js(u.zIndex),Pe=u.summaryPanel,Se=e=>[...Xe(e)],zn=()=>P.flatMap(e=>e?[ne(e,"renderWaferGallery")]:[]),yt=()=>zn()[0];function vi(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 _=u.lotStatsSummary,Re;const se=()=>ae?Re:_;let Ye=u.viewOptions?.legendPosition??"default",bt=u.perCardLegend??!1;function Ue(){const e=a.plotMode??"hardBin";return ni.has(e)?null:a.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 Nn(){const e=bt||Ue()!==null;for(const t of C)t&&t.setOptions({showLegend:e})}let a={plotMode:Oa(k.flatMap(e=>typeof e=="function"?[]:[e.dies??[]])),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...u.viewOptions},C=[],ue=[],Ae=[],x=[];const V=pa(()=>{const e=x.filter(n=>n!=null),t=[...new Set(e.map(n=>fa(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort(Vn);return{prefix:u.downloadFilename,lots:t,...e.length===1?{wafer:ve(e[0])}:{waferCount:e.length}}},u.onSaveImage,u.onSaveText);let P=k.map(e=>typeof e=="function"?null:e),q=null,_n=null,Nt=!1,Ce=0,ae=!1,wt=!1;const xe=new WeakSet,Gn=new WeakMap,Me=()=>{const e=q?.get();return!!e&&!e.off};function Kn(e,t){return{dies:e.dies,wafer:e.wafer,label:ht(e,t),identity:ve(e),waferIndex:t,passBins:Xe(e),testDefs:e.testDefs,statsSummary:e.statsSummary}}const _t=new Map;function Ze(e,t){if(!q||!Me())return e;const n=Gn.get(e);if(n&&n.v===Ce)return n.item;const o=q.mark([Kn(e,t)]);let i=e;if(o.narrowing){const s=o.items[0].dies,l=s.filter(d=>!d.filteredOut);i={...e,dies:s,statsSummary:_t.get(e),...e.yield?{yield:Ea(s,[...Xe(e)],e.yield.yieldPercentGross!=null?"denominator-only":"exclude")}:{},...e.dataCoverage?{dataCoverage:Ba(l)}:{}},o.hidden.size&&xe.add(i)}return Gn.set(e,{v:Ce,item:i}),i}const qn=new WeakMap;function Gt(e,t){const n=Ze(e,t);if(!mt(a))return n;const o=qn.get(n);if(o)return o;const i={...n,dies:Ps(n.dies,n.testDefs,Xe(n)),metadataFields:Ws(n.metadataFields)};return xe.has(n)&&xe.add(i),qn.set(n,i),i}const Xn=new WeakMap;function Si(e,t){if(!q||!Me())return e;const n=Xn.get(e);if(n&&n.v===Ce)return n.item;const o=Ze(e,t),i=o===e?e:xe.has(o)?null:{...o,dies:o.dies.filter(s=>!s.filteredOut)};return Xn.set(e,{v:Ce,item:i}),i}function B(){return!q||!Me()?P:P.map((e,t)=>e?Si(e,t):null)}let vt=0,Qe=!1;function Yn(){const e=++vt;Re=void 0,_t.clear();const t=()=>{Qe=!1,R(),re()};if(!ae){t();return}const n=Qt();if(!n||!(_||n.some(s=>s.statsSummary))){t();return}const o=B().flatMap((s,l)=>s?[{it:s,i:l}]:[]);if(o.length===0){t();return}Qe=!0;const i=_?.analysisOptions??n.find(s=>s.statsSummary)?.statsSummary?.analysisOptions??{};import("../stats/analyzeWaferLot.js").then(async({analyzeWaferLotAsync:s,remapLotWaferIndices:l})=>{const d=await s(o.map(m=>m.it),i);if(e!==vt||Nt)return;const c=o.map(m=>m.i);Re=l(d,c),d.perWafer.forEach((m,v)=>_t.set(P[c[v]],m.summary)),Ce++,P.forEach((m,v)=>{if(!m||ie.has(a.plotMode))return;const p=Gt(m,v);x[v]=p,C[v]?.setStatsSummary(p.statsSummary)}),Te(),t()}).catch(()=>{e===vt&&t()})}const Fe=e=>q&&Me()||mt(a)?e.map((t,n)=>typeof t=="function"?t:Gt(t,n)):e;function Kt(){return _n??=import("./pageFilter.js").then(({createPageFilter:e})=>{const t=e({doc:f.ownerDocument,initial:u.insights?.filter,onChange:u.insights?.onFilterChange,savedFilters:u.insights?.savedFilters,onSavedFiltersChange:u.insights?.onSavedFiltersChange,pickFiltersFile:u.insights?.onPickFiltersFile,onSaveText:u.onSaveText,attributes:u.attributes,getRingCount:()=>ne({ringCount:yt()},"the page filter")});return Nt||(q=t,fe=t.createBand(()=>Xt(),{marginLeft:oe,marginRight:oe,marginBottom:M.lg}),f.insertBefore(fe.el,Z),t.subscribe(Yt),t.get()&&Yt()),t}),_n}let fe=null,St=null,qt;const Xt=()=>P.flatMap((e,t)=>e?[Kn(e,t)]:[]);function Un(){clearTimeout(qt),qt=setTimeout(()=>{if(!q||!fe)return;const e=Xt(),t=q.keep(e);fe.refresh(t.result,e),fe.el.style.display=q.get()&&!rt?"":"none"},0)}function Zn(){if(q){if(ke>0){Me()&&(wt=!0);return}Ce++,ae=Me()&&P.some((e,t)=>e!==null&&Ze(e,t)!==e),Re=void 0,Qe=ae&&!!_,Yn()}}function Yt(){if(Ce++,ae=!1,ke>0){wt=!0,Un();return}wt=!1;const e=a.plotMode;ae=Me()&&P.some((t,n)=>t!==null&&Ze(t,n)!==t),Re=void 0,Qe=ae&&!!_,P.length>0&&(ie.has(e)?(a={...a,...Ft(e)},X(Ge(e))):X(Fe(P.filter(t=>t!==null)))),Un(),Yn()}function Ie(){return Xa(B())}function Je(){if(B().some(e=>e?.testDefs?.length))return Ie().defs}let et=0,ke=0;const Q=new Map;let Ci=0,Ct=null,J=null,pe=null,$e=null;function xt(){J===null&&pe===null&&($e={plotMode:a.plotMode,activeTest:a.activeTest})}function Qn(){$e&&W({...$e},{fireCallback:!1}),$e=null}let Jn=new Set,S=null,xi={};function eo(e){return B()[e]?.statsSummary??se()?.perWafer.find(t=>t.waferIndex===e)?.summary}function to(){return!!(B().some(e=>e?.statsSummary?.findings.length)||se()?.perWafer.some(e=>e.summary.findings.length))}const Mi=zs(),Ve=Ns(Mi),{makeBtn:He,setActive:no,makeSep:De,syncSeparators:Ut,syncToolbarVisible:Zt,makeMenuRow:ki,makeMenuSection:Di,makeDropdown:oo,closeOpenMenu:Mt,getOpenMenu:tt,setOpenMenu:nt}=Ve;f.ownerDocument.addEventListener("click",Mt,!0);const io=()=>oi();window.addEventListener("blur",io);let so=u.findingsNotice,Be=null;function Qt(){const e=P;return e.length>0&&e.every(t=>t!=null&&La(t))?e:null}function Bi(){return _?.stats.testValueAnalysis??Wa(B().flatMap(e=>e?.statsSummary?[e.statsSummary]:[]))}const Jt=()=>so??(Qt()?Pa(Bi(),B().length,Be!==null,Ei):void 0);function Ei(){const e=Qt();if(Be||!e)return;const t=new AbortController;Be=t,R();const n=_?.analysisOptions??e[0].statsSummary?.analysisOptions??{};import("../stats/analyzeWaferLot.js").then(({analyzeWaferLotAsync:o})=>o(e,{...n,enableTestValueAnalysis:!0,signal:t.signal})).then(o=>{if(t.signal.aborted)return;Be=null;const i=o.perWafer.map(s=>s.summary);P=P.map((s,l)=>s&&{...s,statsSummary:i[l]}),ie.has(a.plotMode)||(x=x.map((s,l)=>s&&{...s,statsSummary:i[l]}),C.forEach((s,l)=>s?.setStatsSummary(i[l]))),_=o,Te(),R(),re(),u.onStatsSummaryChange?.({summaries:i,lotStatsSummary:o})}).catch(o=>{if(!t.signal.aborted)throw Be=null,R(),o})}function en(){Be?.abort(),Be=null}function ao(e){Jn=new Set(e);const t=[...F.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,i)=>{const s=Jn.has(i);o.style.outline=s?`3px solid ${w.findingHighlight}`:"",o.style.outlineOffset=s?"-3px":"",s&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function tn(){ao([])}let kt=!1;function nn(){kt=!0;for(const e of C)e&&e.clearSelection();kt=!1}function lo(e){return t=>{!kt&&(J!==null||pe!==null)&&($e=null,Oe(),R()),an.set(e,t.length),le&&!ot&&!kt&&Oi(e,t),e.onSelect?.(t)}}function me(e,t){e!==void 0&&(C.forEach((n,o)=>{n&&o!==e&&n.locateDie(null)}),C[e]?.locateDie(t),F.querySelectorAll(".wmap-gallery-card")[e]?.scrollIntoView?.({block:"center",behavior:"smooth"}))}let le=!1,ot=!1,Ee=new Set;function Oi(e,t){ot=!0;try{Ee=new Set(t.map(n=>jt(n))),x.forEach((n,o)=>{const i=C[o];!i||!n||n===e||i.setSelection(n.dies.filter(s=>Ee.has(jt(s))))})}finally{ot=!1}Lt()}function ro(){Ee=new Set,ot=!0;try{for(const e of C)e?.clearSelection()}finally{ot=!1}Lt()}function on(){if(!le||Ee.size===0)return;const e=[];let t=!1;if(x.forEach((i,s)=>{if(!i)return;const l=i.dies.filter(d=>Ee.has(jt(d)));l.length!==0&&(i.isLotStack&&(t=!0),e.push({label:ve(i)??i.label??`Wafer ${s+1}`,dies:l,waferIndex:s,wafer:i.wafer,passBins:Se(i),ringCount:ne(i,"renderWaferGallery")}))}),e.length===0)return;const n=Ie(),o=a;return{source:{items:e,population:e.length===1?`selected on ${e[0].label}`:`selected at the same die positions on ${e.length} wafers`,testDefs:n.defs,activeTest:o.plotMode==="value"?o.activeTest:void 0,notMeasuredReason:t?Wn:void 0},ctx:{plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(i,s)=>me(s,i)}}}function co(){const e=[];let t=!1;if(x.forEach((o,i)=>{const s=o?C[i]?.getSelectedDies()??[]:[];!o||s.length===0||(o.isLotStack&&(t=!0),e.push({label:ve(o)??o.label??`Wafer ${i+1}`,dies:s,waferIndex:i,wafer:o.wafer,passBins:Se(o),ringCount:ne(o,"renderWaferGallery")}))}),e.length<2)return;const n=a;return{source:{items:e,population:`selected on ${e.length} wafers`,testDefs:Ie().defs,activeTest:n.plotMode==="value"?n.activeTest:void 0,notMeasuredReason:t?Wn:void 0},ctx:{plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(o,i)=>me(i,o)}}}function Ti(e){const t=on()??po(e);if(t)return t;const n=co(),o=n?.source.items.some(i=>i.waferIndex===e);return n&&o?{...n,narrowable:!0}:void 0}function sn(e,t,n){J!==e&&t.click();const o=S;if(!o)return;const i=se()?.findings.find(l=>l.id===e),s=on()??co()??Wi()??(i?uo(mo(i)):void 0);s&&import("./drilldown.js").then(({openDrilldownMenu:l})=>{o.isConnected&&l(n,o,s.source,{plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,...s.ctx})})}function Li(e,t,n,o){const i=$n(a.highlightBin),s=i.length>1&&i.includes(t)?[...i]:[t],l=[];let d=!1;x.forEach((g,h)=>{g&&(g.isLotStack&&(d=!0),l.push({label:ve(g)??g.label??`Wafer ${h+1}`,dies:g.dies,waferIndex:h,wafer:g.wafer,passBins:Se(g),ringCount:ne(g,"renderWaferGallery")}))});const c=Ie().defs,m=ui(l,e,s,c,void 0,d);if(!m)return;const v={plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(g,h)=>me(h,g)},p=s.length>1?ui(l,e,[t],c,void 0,d):null,r=p?{...v,narrower:{label:`Only ${e} bin ${t}`,backLabel:"All filtered bins",source:p,ctx:v}}:v;import("./drilldown.js").then(({openDrilldownMenu:g})=>{o.isConnected&&g(n,o,m,r)})}function uo(e,t=""){const n=[];let o=!1;for(const s of[...e??[]].sort((l,d)=>l-d)){const l=x[s];l&&(l.isLotStack&&(o=!0),n.push({label:ve(l)??l.label??`Wafer ${s+1}`,dies:l.dies,waferIndex:s,wafer:l.wafer,passBins:Se(l),ringCount:ne(l,"renderWaferGallery")}))}if(n.length===0)return;const i=a;return{source:{items:n,population:n.length===1?`on ${n[0].label}`:`on ${n.length} ${t}wafers`,testDefs:Ie().defs,activeTest:i.plotMode==="value"?i.activeTest:void 0,notMeasuredReason:o?Wn:void 0},ctx:{plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(s,l)=>me(l,s)}}}function Wi(){let e;for(let i=0;i<C.length;i++)if((C[i]?.getSelectedDies().length??0)!==0){if(e!==void 0)return;e=i}const t=e===void 0?void 0:x[e];if(e===void 0||!t)return;const n=C[e].getSelectedDies(),o=a;return{source:va(n,{waferLabel:ve(t),testDefs:t.testDefs,isLotStack:t.isLotStack,activeTest:o.plotMode==="value"?o.activeTest:void 0,waferIndex:e,wafer:t.wafer,passBins:Se(t),ringCount:ne(t,"renderWaferGallery")}),ctx:{onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(i,s)=>me(s??e,i)}}}function Pi(e){e||ro(),le=e,Lt()}function Dt(e,t){const n=new Set(e),o=t??C.map((i,s)=>s);for(const i of o){const s=x[i],l=C[i];if(!s||!l)continue;const d=s.dies.filter(c=>n.has(jt(c)));l.setSelection(d)}}const U=new Set,an=new Map;function fo(){[...F.querySelectorAll(".wmap-gallery-card")].forEach((n,o)=>{n.style.outline=U.has(o)?`2px solid ${w.iconActive}`:"",n.style.outlineOffset=U.has(o)?"-2px":""});const t=U.size;ee.style.display=t>0?"":"none",ee.textContent=`${t} wafer${t===1?"":"s"} picked \u2715`,ee.ariaLabel=`${t} wafer${t===1?"":"s"} picked. Click to clear.`}function Ri(e){e<0||(U.has(e)?U.delete(e):U.add(e),fo())}function Ai(){U.clear(),fo()}function po(e){if(!(U.size===0||!U.has(e))){for(const t of an.values())if(t>0)return;return uo([...U],"picked ")}}function Fi(){const e=[];for(let t=0;t<B().length;t++){const n=B()[t];if(!n)continue;const o=eo(t)?.findings??[];o.length&&e.push({index:t,item:n,unusualCount:o.filter(i=>i.severity==="unusual").length,notableCount:o.filter(i=>i.severity==="notable").length,totalCount:o.length})}return e}function Ii(e){const t=x[e]??B()[e];t&&ut(e,t)}function $i(e){const t=eo(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 Vi(){import("../stats/renderSummaryReport.js").then(({renderLotReportHtml:e})=>{ra(e(Na(B(),yt())),{anchor:f})})}function Hi(){if(!S)return;S.innerHTML="";const e=Fi();if(B().length>0){const n=f.ownerDocument.createElement("div"),o=e.length,i=B().filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${i} wafers`:`${o} of ${i} wafer${i===1?"":"s"} with findings`,Object.assign(n.style,{fontSize:N.body,color:w.label,marginBottom:M.md}),S.appendChild(n)}if(e.length>0){const n=f.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...$s("outlined"),marginBottom:M.lg,display:"block",width:"100%",textAlign:"left"}),Tn(n),n.addEventListener("click",Vi),S.appendChild(n)}if(e.length===0){const n=f.ownerDocument.createElement("div");Object.assign(n.style,{color:w.icon,fontSize:N.body,padding:"4px 0"}),n.textContent="No findings on any wafer.",S.appendChild(n)}else for(const{index:n,item:o,unusualCount:i,notableCount:s,totalCount:l}of e){const d=i?"unusual":s?"notable":"info",c=i+s||l,m=f.ownerDocument.createElement("button");m.type="button",Object.assign(m.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:M.xs,border:"none",borderLeft:`3px solid ${ti(d)}`,borderRadius:Y.control,background:w.bgHover,cursor:"pointer",fontSize:N.body,textAlign:"left",boxSizing:"border-box"}),m.addEventListener("mouseover",()=>{m.style.background=w.bgActive}),m.addEventListener("mouseout",()=>{m.style.background=w.bgHover});const v=f.ownerDocument.createElement("span");v.textContent=ht(o,n),Object.assign(v.style,{color:w.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const p=f.ownerDocument.createElement("span");p.textContent=String(c),m.setAttribute("aria-label",`${ht(o,n)} \u2014 ${c} finding${c===1?"":"s"}${i?`, ${i} unusual`:""} \u2014 view wafer`),Object.assign(p.style,{marginLeft:M.sm,flexShrink:"0",background:ti(d),color:"#fff",borderRadius:Y.container,padding:"1px 5px",fontSize:N.body,fontWeight:"600"}),m.appendChild(v),m.appendChild(p),m.addEventListener("click",()=>ut(n,o)),S.appendChild(m)}const t=f.ownerDocument.createElement("div");t.style.height="12px",S.appendChild(t)}let je=null,it=null;function R(){if(!S||ae&&_&&!Re&&Qe)return;je?.cancel(),je=null;const e=se();if(e){const t=$t(B().map(o=>o?.hbinDefs)),n=$t(B().map(o=>o?.sbinDefs));je=Za(za(S,{lotSummary:e,items:B(),hbinDefs:t.length?t:void 0,sbinDefs:n.length?n:void 0,testDefs:Je(),ringCount:yt(),binColors:a.binColors,plotMode:a.plotMode??"hardBin",fallbackFormat:a.fallbackFormat,activeFindingId:J,warnings:u.warnings?.display??!0?ge:[],findingsFilter:xi,findingsNotice:Jt(),onFindingsFilterChange:R,onSaveText:V.onSaveText,attributes:u.attributes,onFindingClick:(o,i)=>{J===o.id?(Oe(),Qn()):(xt(),wo(o,i)),R()},activeTest:pe,onTestClick:o=>{const i=pe===o;i||xt(),Oe(),i?Qn():bo(o),R()},onShowChart:$?o=>{_e(!0),Ao().then(i=>i?.showWorthCard(o))}:void 0,onWaferClick:Ii,findingsFor:$i,dieListOptions:u.dieList,onLocateDie:(o,i)=>me(i,o),onClose:()=>rn(!1)}),{onDone:()=>{const o=it;it=null,o?.()}})}else Hi()}function mo(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}let Bt=[];function go(){if(Bt.length!==0){for(const e of Bt)C[e]?.setOptions({plotMode:a.plotMode,activeTest:a.activeTest});Bt=[]}}function Oe(){J=null,pe=null,tn(),nn(),go(),W({highlightBin:void 0},{fireCallback:!1})}function ho(){J===null&&pe===null||($e=null,Oe(),R())}function yo(e,t){const n=Je();if(n===void 0||n.some(i=>i.testNumber===e))W({plotMode:"value",activeTest:e,highlightBin:void 0},{fireCallback:!1});else{W({highlightBin:void 0},{fireCallback:!1});const s=ie.has(a.plotMode??"hardBin")?null:t;if(s){for(const l of s)C[l]?.setOptions({plotMode:"value",activeTest:e});Bt=[...s]}}}function bo(e){pe=e;const t=o=>x[o]?.statsSummary?.stats.testFailures?.[e]?.dieKeys,n=x.map((o,i)=>i).filter(o=>t(o)?.length);if(yo(e,n.length?n:null),tn(),nn(),!ie.has(a.plotMode??"hardBin"))for(const o of n)Dt(t(o),[o])}function wo(e,t){if(J===e.id){Oe();return}J=e.id,pe=null,t&&(t.style.background=w.bgActive,t.style.fontWeight="600"),go();const{kind:n,index:o}=e.variable;if(n==="test")yo(o??0,mo(e));else{const s=x.some(d=>d?.dies?.some(c=>c.hbin!=null)),l=Jo(x.map(d=>d?Xe(d):void 0));W({plotMode:Ma(e,a.plotMode,s),highlightBin:xa(e,l,s)},{fireCallback:!1})}tn(),nn();const i=e.highlight;if(i.kind==="wafer"){ao(i.waferIndices);const s=fi(e);for(const l of i.waferIndices){const d=i.dieKeysByWafer?void 0:x[l]?.statsSummary?.findings.find(m=>fi(m)===s),c=i.dieKeysByWafer?.[l]??d?.highlight?.dieKeys;c?.length&&Dt(c,[l])}}else i.kind==="bin"?i.dieKeys?.length&&Dt(i.dieKeys):(i.kind==="region"||i.kind==="dies")&&i.dieKeys?.length&&Dt(i.dieKeys)}function ln(){return!!S&&S.style.display!=="none"}function rn(e){!S||e===ln()||(e&&R(),S.style.display=e?"flex":"none",re())}function re(){Ct&&(Ut(H),Zt(H,"inline-flex"),Ct.sync({visible:!!(_||se()||to())&&!!S&&!rt,open:ln(),notable:!!(se()?.hasNotableFindings||B().some(e=>e?.statsSummary?.hasNotableFindings))}))}const H=f.ownerDocument.createElement("div");H.dataset.wmapToolbar="gallery",Object.assign(H.style,{flexShrink:"0",marginLeft:"auto",display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:w.menuBg,border:`1px solid ${w.menuBorder}`,borderRadius:Y.control,padding:"0",boxShadow:On.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const vo=()=>{const e=tt();e&&(e.remove(),nt(null)),gt(ce,!1)},ce=He("mode","Plot mode",()=>{if(tt()){vo();return}const e=B().flatMap(y=>y?.dies??[]),t=Je(),{testEntries:n,binEntries:o,stackedEntries:i}=aa(e,t,{includeStacked:!0}),s=B().filter(Boolean).length,l=y=>{if(y===void 0)return s;let E=0;for(const A of B())A?.dies?.some(j=>pi(j,y)!==void 0||Ua(j,y)!==void 0)&&E++;return E},d=s<2?n:n.map(y=>{const E=l(y.activeTest);return E===s?y:{...y,label:`${y.label} \u2014 ${E} of ${s} wafers`}}),c=a.plotMode??"hardBin",m=a.activeTest??0;function v(y){return y.plotMode!==c?!1:y.plotMode==="value"?m===(y.activeTest??0):y.plotMode==="metadata"?a.activeMetadataKey===y.activeMetadataKey:!0}function p(y,E){y.activeTest!==void 0?W({plotMode:"value",activeTest:y.activeTest,activeMetadataKey:void 0,logScale:y.logScale}):y.activeMetadataKey!==void 0?W({plotMode:y.plotMode,activeTest:void 0,activeMetadataKey:y.activeMetadataKey,passFailDisplay:"off"}):W({plotMode:y.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),E.remove(),nt(null),gt(ce,!1)}const r=new Set,g=B().flatMap(y=>y?.metadataFields??[]).filter(y=>!r.has(y.key)&&r.add(y.key)).filter(y=>la(e,y.key)).map(ri);ke===0&&Ls(B())&&g.push(ri(Es));const h=_s(ce.getBoundingClientRect(),d,o,i,v,p,{makeMenuRow:ki,makeMenuSection:Di},c,ce.ownerDocument.defaultView??window,g);ii(ce).appendChild(h),nt(h),gt(ce,!0),si(h,ce,vo)});gt(ce,!1);const ji=()=>x.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:zi,sync:So}=Us(Ve,()=>({...a,plotMode:a.plotMode??"hardBin"}),ji,e=>W(e));So();const Ni=k.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function Et(){const e=Je(),{testNumber:t}=vs(a.activeTest??0,e);return{testNumber:t,td:Ss(e,t)}}function Co(){if((a.plotMode??"hardBin")!=="value")return!1;const{td:e}=Et();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function st(){if((a.plotMode??"hardBin")!=="value")return!1;const{td:e}=Et();return e!==void 0&&!Rn(e)}function _i(){if((a.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=Et();return B().some(n=>n?.dies?.some(o=>pi(o,e,t)!==void 0))}function Gi(e,t){if(!t||!Rn(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((ai(a)==="spec"&&n?"spec":a.colorbarRangeMode??"spec")==="spec"&&n)return;let s=1/0,l=-1/0;for(const d of B())if(d)for(const c of d.dies){const m=Ta(c,e);m!==void 0&&(m<s&&(s=m),m>l&&(l=m))}if(isFinite(s))return s===l?[s,s+1]:[s,l]}function Ot(e,t,n){const o=a[e];if(o===t||o!=null&&t!=null&&n(o,t))return!1;a={...a,[e]:t};for(const i of C)i&&i.setOptions({[e]:t});return!0}function xo(){if((a.plotMode??"hardBin")!=="metadata")return;const e=a.activeMetadataKey;if(!e)return;if(mt(a))return{key:e,values:[...Ts]};const t=new Set;for(const n of B())if(n)for(const o of Cs(n.dies,e))t.add(o);return{key:e,values:[...t].sort(Vn)}}function cn(){Ot("metadataValueOrder",xo(),(e,t)=>e.key===t.key&&Ht(e.values,t.values))}function dn(){if((a.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=Et(),n=Gi(e,t);Ot("valueRange",n?{test:e,range:n}:void 0,(i,s)=>{const l=m=>Array.isArray(m)?{test:void 0,range:m}:{test:m.test,range:m.range},d=l(i),c=l(s);return d.test===c.test&&Ht(d.range,c.range)})}let un=!1;function Ki(){if(un)return;un=!0,(f.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{un=!1,dn(),cn(),Bo(),Do()})}let fn=!1;function qi(){if(fn)return;fn=!0,(f.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{fn=!1,At()})}let Mo=[];function G(){const{colors:e,mixedHardBins:t}=Ms(B().filter(n=>n!=null),{binColorScheme:a.binColorScheme,useDefinedBinColors:a.useDefinedBinColors});return Mo=t,e}function pn(){return x.filter(e=>e!=null).flatMap(e=>e.dies)}function ko(){return a.compact?$a(pn()):void 0}const Xi=(e,t)=>Ht(e.columns,t.columns)&&Ht(e.rows,t.rows);function Do(){Ot("compactMap",ko(),Xi)&&Ho()}function Yi(){return Va(pn(),x.filter(e=>e!=null).map(e=>e.reticleConfig))}function Bo(){Ot("binColors",G(),Bs),Te()}const Ui=Js(Ve,()=>na(a,Ni,{functionalActive:st(),hasLimits:Co()&&!st(),hasRecorded:_i()&&!st(),binMode:(a.plotMode??"hardBin")==="hardBin"||(a.plotMode??"hardBin")==="softBin"},e=>W(e),{on:!!a.compact,offered:Yi(),onChange:e=>W({compact:e}),onDiagnostics:()=>ia(pn(),x.filter(e=>e!=null).map(e=>e.reticleConfig),{anchor:f,onSaveText:V.onSaveText})}),()=>oa(a)),{btn:Zi,sync:Eo}=Qs(Ve,()=>({plotMode:a.plotMode,legendPosition:Ye}),e=>{Ye=e;for(const t of C)t&&t.setOptions({legendPosition:Ye})},{get:()=>bt,set:e=>{bt=e,Nn()},blockedReason:Ue});Eo();const Qi=[{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"}],Oo=oo("aggr","Aggregation method",()=>Qi,()=>a.aggregationMethod??"mean",e=>W({aggregationMethod:e}));function To(){const e=a.plotMode==="stackedValues";Oo.style.display=e?"":"none"}To();const{btn:Ji,sync:Lo}=Zs(Ve,()=>({...a,functionalActive:st()}),e=>W(e));Lo();const Tt=He("specRange","Colorbar range: test limits",()=>{const e=a.colorbarRangeMode==="data"?"spec":"data";W({colorbarRangeMode:e})});function Wo(){const e=(a.plotMode??"hardBin")==="value"&&Co()&&ai(a)==="off"&&!st();Tt.style.display=e?"":"none";const t=(a.colorbarRangeMode??"spec")==="spec";no(Tt,t),Tt.ariaLabel=t?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"}Wo();const es=ea(Ve,()=>a,e=>W(e)),ts=He("downloadAll","Download gallery PNG",ms),ze=He("boxSelect","Select the same dies on every wafer",()=>{le&&Ee.size>0?ro():Pi(!le)});ze.style.position="relative";const at=f.ownerDocument.createElement("span");at.dataset.wmapSelectAcrossCount="1",Object.assign(at.style,{position:"absolute",top:"0",right:"0",minWidth:"14px",height:"14px",boxSizing:"border-box",padding:"0 3px",borderRadius:Y.pill,background:w.iconActive,color:w.menuBg,fontSize:"11px",lineHeight:"14px",fontWeight:"700",textAlign:"center",pointerEvents:"none",display:"none"}),ze.appendChild(at);function Lt(){no(ze,le);const e=le?Ee.size:0;at.style.display=e>0?"block":"none",at.textContent=e>99?"99+":String(e),ze.ariaLabel=le?e>0?`Select the same dies on every wafer: on, ${e.toLocaleString()} die position${e===1?"":"s"} selected (click to clear the selection)`:"Select the same dies on every wafer: on (click to turn off)":"Select the same dies on every wafer: off (click to turn on)",ze.setAttribute("aria-pressed",String(le))}const ee=f.ownerDocument.createElement("button");ee.type="button",ee.dataset.wmapPickedWafers="1",Object.assign(ee.style,{display:"none",border:"none",background:w.bgActive,color:w.iconActive,borderRadius:Y.control,padding:`${M.xs} ${M.md}`,fontSize:N.body,cursor:"pointer",whiteSpace:"nowrap",flexShrink:"0"}),Tn(ee,"bare"),ee.addEventListener("click",Ai);const ns=oo("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"}],()=>T!=null?String(T):"auto",e=>No(e==="auto"?void 0:Number(e))),L=f.ownerDocument.createElement("div");Object.assign(L.style,{display:"inline-flex",alignItems:"center",gap:"0"}),H.appendChild(L),L.appendChild(ce),L.appendChild(zi),L.appendChild(Oo),L.appendChild(Ji),L.appendChild(Tt),L.appendChild(De()),L.appendChild(Ui),L.appendChild(De()),L.appendChild(Zi),L.appendChild(De()),L.appendChild(es),L.appendChild(De()),L.appendChild(ns),L.appendChild(De()),L.appendChild(ze),L.appendChild(ee),L.appendChild(ts),Lt();let te=null,Wt=null,ge=[],Po=!1;function Te(){const e=Aa({lotStatsSummary:se(),result:{warnings:[...B().flatMap(n=>n?.warnings??[]),...Ie().warnings]},extra:[a.binColors&&ks(a.binColors,a.plotMode),Ds(Mo),vi(zn())].filter(n=>!!n)}),t=e.length!==ge.length||e.some((n,o)=>n.code!==ge[o]?.code||n.message!==ge[o]?.message);ge=e,(t||!Po)&&(Po=!0,u.warnings?.onWarning?.(e)),os()}function os(){if(!te||!Wt)return;const e=ge.length,t=e>0;if(te.style.display=t?"flex":"none",Wt.style.display=t?"":"none",Ut(H),Zt(H,"inline-flex"),!t)return;const n=Ia(ge[0]),o=`${e} data ${e===1?"warning":"warnings"}`;te.style.color=n==="error"?w.errText:w.warnText,te.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(u.warnings?.display??!0)&&(Wt=De(),te=He("warning","Data warnings",()=>{const e=tt();if(Mt(new MouseEvent("click")),e)return;const t=Fa(te.getBoundingClientRect(),ge,te.ownerDocument.defaultView??window);ii(f).appendChild(t),nt(t),si(t,te,()=>Mt(new MouseEvent("click")))}),gt(te,!1),H.appendChild(Wt),H.appendChild(te)),Te();function mn(e){import("./userGuideHtml.js").then(t=>ca({buildWaferMap:Da,renderWaferMap:ba,renderWaferGallery,analyzeWaferMap:An},t.USER_GUIDE_HTML,O,f,e))}const is=da(e=>mn(e));D&&(H.appendChild(De()),H.appendChild(He("help","User guide",()=>mn())));const Ne=f.ownerDocument.createElement("div");Ne.dataset.wmapGalleryMeta="1",Object.assign(Ne.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${M.sm} ${M.lg}`,fontSize:N.sub,lineHeight:ei.none,boxSizing:"border-box"});const Le=f.ownerDocument.createElement("div");Object.assign(Le.style,{background:w.canvasBg,display:"flex",alignItems:"stretch",gap:M.lg,paddingBottom:M.lg,minWidth:"0"});const he=f.ownerDocument.createElement("div");he.dataset.wmapGalleryLegend="1",Object.assign(he.style,{display:"flex",flexDirection:"column",gap:M.sm,background:w.menuBg,border:`1px solid ${w.menuBorder}`,borderRadius:Y.container,padding:`${M.sm} ${M.lg}`,marginBottom:M.lg,boxShadow:On.panel,fontSize:N.body,lineHeight:ei.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const Z=f.ownerDocument.createElement("div");Object.assign(Z.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let ye=null,lt=null,Ro=null;function Ao(){return $?ye?Promise.resolve(ye):(Ro??=Promise.all([import("./insightsTab.js"),Kt()]).then(([{createInsightsTab:e},t])=>(ye=e({pageFilter:t,showFilterButton:!1,initialAxisPrefs:Fn(a),onAxisPrefsChange:n=>{a={...a,...Ra(n)};const o=[...In];u.onViewOptionsChange?.(Vt(a),o,Pn(o))},attributes:u.attributes,getItems:()=>P,getLotStats:()=>_,getBinColors:()=>a.binColors??G(),getRingCount:()=>ne({ringCount:yt()},"the Insights tab"),defaultView:u.insights?.defaultView,plotStore:I,onPickPlotsFile:u.insights?.onPickPlotsFile,showPatMap:()=>{_e(!1),W({plotMode:"metadata",activeTest:void 0,activeMetadataKey:Os,passFailDisplay:"off"})},showOnMap:n=>{if(_e(!1),n.kind==="test")xt(),Oe(),bo(n.testNumber);else{const o=se(),i=o?ka(o).findings.find(s=>s.id===n.id):void 0;i&&J!==i.id&&(xt(),wo(i))}rn(!0),R()},onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,ownerDocument:f.ownerDocument,locateDie:(n,o)=>{_e(!1),me(o,n)},openWafer:(n,o,i)=>{const s=B()[n];if(!s)return;let l=null;const d=qs({title:o,onClose:()=>l?.destroy(),anchor:f});Ko(d,o,s.wafer.metadata??void 0),l=xn(d.contentWrap,s,i,void 0,li(d))}}),lt=ye.el,lt.style.display="none",f.appendChild(lt),ye)),Ro):Promise.resolve(null)}let rt=!1,gn=null;function _e(e){$&&(rt=e,gn?.setInsightsOpen(e),lt&&(lt.style.display=e?"flex":"none"),Z.style.display=e?"none":"flex",fe&&(fe.el.style.display=q?.get()&&!e?"":"none"),L.style.display=e?"none":"inline-flex",Ut(H),Zt(H,"inline-flex"),H.style.display="inline-flex",re(),At(),e&&Ao().then(t=>{!t||!rt||(t.el.style.display="flex",t.render())}))}$&&u.insights?.defaultOpen&&queueMicrotask(()=>_e(!0));const Fo=4,Pt=240,hn=480,ss=720,as=1.25;let We=hn;function Io(e){const t=z*2+110+2,n=$o();if(n)return Math.ceil(n.across*Fo+t);let o=null;for(const i of e){if(i==null||!i.dies?.length)continue;const s=i.dies[0].width;if(!(s>0))continue;const l=i.wafer.radius*2*(Fo/s),d=Math.ceil(l+t);(o==null||d>o)&&(o=d)}return o}function ls(e){const t=Io(e);return t==null?Pt:Math.min(We,Math.max(Pt,t))}function rs(e){const t=Io(e);if(t==null)return!1;const n=Math.min(ss,Math.max(hn,t));return n<=We?!1:(We=n,!0)}function $o(){const e=a.compact?a.compactMap:void 0,t=x.find(i=>i?.dies?.length)?.dies[0];if(!e||!t||e.columns.length===0||e.rows.length===0||!(t.width>0)||!(t.height>0))return;const n=(a.rotation??0)%180!==0,o=a.showXYIndicator?2.5:0;return{across:(n?e.rows.length:e.columns.length)+o,down:(n?e.columns.length:e.rows.length)+o,cellAspect:n?t.height/t.width:t.width/t.height}}function Vo(e,t){const n=$o();if(!n){e.style.aspectRatio="1",t.style.flex="1",t.style.width="",t.style.aspectRatio="";return}e.style.aspectRatio="auto",t.style.flex="none",t.style.width="100%",t.style.aspectRatio=String(n.across*n.cellAspect/n.down)}function cs(){for(const e of ue)e?.parentElement&&Vo(e.parentElement,e)}function Ho(){We=hn,ct=Pt,wn(x.map(e=>e??null)),Rt(),cs()}function yn(){return jo()?`${We}px`:"none"}function jo(){return T==null&&!bn}let bn=!1;function Rt(){const e=yn();for(const t of Array.from(F.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let ct=Pt,zo=0;function wn(e){if(rs(e)&&Rt(),T==null){const n=ls(e);n>ct&&(ct=n)}Sn()}function No(e){T=hi(e),Rt(),Sn()}function vn(e){return`repeat(${e}, minmax(0, ${jo()?`${We}px`:"1fr"}))`}function _o(e){F.style.gridTemplateColumns!==e&&(F.style.gridTemplateColumns=e)}function Sn(){if(T!=null){_o(vn(T));return}const e=Math.max(1,zo),t=12,n=F.clientWidth||0,o=l=>(n-t*(l-1))/l;let i=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const l=Math.min(We,ct*as),d=c=>{let m=0;for(;m<e&&o(m+1)>=c;)m++;return m};i=d(l)||d(ct)||1}const s=n>0&&i<e;s!==bn&&(bn=s,Rt()),_o(vn(i))}const F=f.ownerDocument.createElement("div");if(Object.assign(F.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:vn(1),gap:M.xl,paddingLeft:oe,paddingRight:oe,justifyContent:"start",alignContent:"start",isolation:"isolate"}),Pe?.placement){const e=Pe.placement;S=Hn(e,oe,f.ownerDocument,sn),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.display="flex",S.style.flexDirection="column"}else if(_||se()||to()){const e=!!Pe?.defaultOpen;S=Hn("right",oe,f.ownerDocument,sn),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.flexDirection="column",S.style.display=e?"flex":"none",R()}re(),(Pe?.placement??"right")==="left"?(S&&Z.appendChild(S),Z.appendChild(F)):(Z.appendChild(F),S&&Z.appendChild(S));const dt=f.ownerDocument.createElement("div");Object.assign(dt.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:oe,paddingRight:oe,paddingTop:oe,zIndex:"1",background:w.menuBg}),Le.appendChild(Ne),Le.appendChild(H),Ct=bs(f.ownerDocument,()=>rn(!ln())),Le.appendChild(Ct.el),re(),$&&(gn=ys(f.ownerDocument,"Maps","lot",e=>_e(e)),Le.appendChild(gn.el)),$&&(St=ua(f.ownerDocument,"Filter\u2026","wmapGalleryFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>{Kt().then(e=>e.openEditor(St??f,Xt()))}),St.style.order="1",Le.appendChild(St)),dt.appendChild(Le),dt.appendChild(he),f.appendChild(dt),f.appendChild(Z);function At(){he.innerHTML="";const e=a.plotMode??"hardBin",t=!rt&&ni.has(e),n=x.filter(b=>b!=null&&!xe.has(b)),o=n.find(b=>b.isLotStack),i=Ha(n.map(b=>({metadata:b.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0,{curation:u.attributes}),s=e==="metadata",l=a.activeMetadataKey,d=t&&!s?yi(n,b=>(e==="softBin"?b.sbin:b.hbin)??void 0,Se):{counts:new Map,total:0,pass:0},c=t&&!s?a.binColors??G():void 0,m=c?e==="softBin"?c.pass.soft:c.pass.hard:new Set,v=ma(d.counts.entries(),m).map(([b])=>b),p=t&&s&&l?yi(n,b=>xs(b.metadata?.[l])):{counts:new Map,total:0,pass:0},r=s?xo()?.values:void 0,g=t&&s?(r??[...p.counts.keys()].sort(Vn)).filter(b=>p.counts.has(b)):[];if(Ne.innerHTML="",i&&Ne.appendChild(i),Ne.style.display=i?"flex":"none",!v.length&&!g.length){he.style.display="none";return}he.style.display="flex";const h=f.ownerDocument.createElement("div");Object.assign(h.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${M.sm} ${M.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),he.appendChild(h);const y=$n(a.highlightBin),E=x.flatMap(b=>b?.metadataFields??[]).find(b=>b.key===l),A=s?E?.label??(l?_a(l):"Metadata"):Hs[e],j=f.ownerDocument.createElement("span");if(j.textContent=A,Object.assign(j.style,{fontSize:N.body,fontWeight:"700",letterSpacing:Is,textTransform:"uppercase",color:w.label,flexShrink:"0"}),h.appendChild(j),!s&&d.total>0){const b=d.pass,K=b/d.total*100,be=f.ownerDocument.createElement("span");be.textContent=`Yield ${zt(K)}`,Object.assign(be.style,{fontSize:N.body,fontWeight:"700",color:w.value,whiteSpace:"nowrap",flexShrink:"0"});const we=f.ownerDocument.createElement("span");we.textContent=`${b.toLocaleString()} / ${d.total.toLocaleString()} dies`,Object.assign(we.style,{fontSize:N.body,color:w.label,whiteSpace:"nowrap",flexShrink:"0"}),h.appendChild(be),h.appendChild(we)}if(s){const b=$n(a.highlightMetadataValue);g.forEach((K,be)=>{const we=b.includes(K),qe=E?.values?.find(Bn=>Bn.value===K),pt=qe?.color??As(be),Qo=p.counts.get(K)??0;bi(h,{color:pt,isActive:we,label:qe?.label??K,count:Qo,percent:p.total>0?Qo/p.total*100:void 0,onClick:Bn=>{const hs=mi(a.highlightMetadataValue,K,Bn);ho(),W({highlightMetadataValue:hs})}})});return}const ft=e==="softBin"?x.flatMap(b=>b?.sbinDefs??[]):x.flatMap(b=>b?.hbinDefs??[]),Yo=new Set,kn=[];for(const b of ft)Yo.has(b.bin)||(Yo.add(b.bin),kn.push(b));const Dn=kn.length>0?new Map(kn.map(b=>[b.bin,b])):null,Uo=c??a.binColors??G(),gs=e==="softBin"?Uo.soft:Uo.hard,Zo=b=>gs.get(b)??Rs;for(const b of v){const K=y.includes(b),be=Dn?.get(b),we=d.counts.get(b)??0;bi(h,{color:Zo(b),isActive:K,label:be?.name?`${b} \xB7 ${be.name}`:`Bin ${b}`,count:we,percent:d.total>0?we/d.total*100:void 0,onMenu:(qe,pt)=>Li(e==="softBin"?"soft":"hard",b,qe,pt),onClick:qe=>{const pt=mi(a.highlightBin,b,qe);ho(),W({highlightBin:pt})}})}d.total>0&&v.length>1&&he.appendChild(Qa(f.ownerDocument,[...d.counts.entries()].sort(([,b],[,K])=>K-b).map(([b,K])=>({color:Zo(b),count:K,label:Dn?.get(b)?.name?`${b} \xB7 ${Dn.get(b).name}`:`Bin ${b}`})),d.total))}function Ge(e){const t=B().filter(p=>p!==null&&!xe.has(p));if(!t.length)return[];const n=t.map(p=>p.dies.filter(Ya).filter(r=>!r.filteredOut)),o=t[0].wafer,i=t.length,s=Jo(t.map(p=>Xe(p)));if(!s)return[];const l=new Set(t.map(p=>ne(p,"renderWaferGallery")));if(l.size!==1)return[];const d=[...l][0],c=o.metadata?{...o,metadata:(({wafer:p,waferId:r,...g})=>g)(o.metadata)}:o;function m(p,r){return{...p,stats:{...p.stats,isLotStack:!0,aggregationMethod:r,lotSize:i}}}function v(p,r){const g=p.map(h=>({...h,hbin:void 0,sbin:void 0}));return An({wafer:c,dies:g,passBins:[...s],ringCount:d,testDefs:[{testNumber:0,name:r}]},{testNumbers:[0]})}if(e==="stackedValues"){const p=Je();let r=p?.filter(Rn);if(p!==void 0&&r?.length===0)return[];if(p?.length||(r=ws(t.flatMap(y=>y.dies)).map(y=>({testNumber:y,name:Ga(void 0,y)}))),!r?.length)return[];const g=a.aggregationMethod??"mean";return r.map(h=>{const y=ya(n,g,h.testNumber),E={testNumber:0,name:h.name,unit:h.unit,...qa(h)};return{wafer:c,dies:y,passBins:[...s],ringCount:d,testDefs:[E],label:`${Ka(h,h.testNumber)} \xB7 ${g}`,isLotStack:!0,aggrMethod:g,lotSize:i,statsSummary:m(An({wafer:c,dies:y,passBins:[...s],ringCount:d,testDefs:[E]},{testNumbers:[0]}),g)}})}if(e==="stackedBins"){let p=$t(t.map(r=>r?.hbinDefs));return(!p||p.length===0)&&(p=[...new Set(t.flatMap(g=>g.dies.map(h=>h.hbin).filter(h=>h!=null)))].sort((g,h)=>g-h).map(g=>({bin:g,name:`Bin ${g}`}))),p.map(r=>{const g=ci(n,r.bin,"hard"),h=[{bin:r.bin,name:r.name}];return{wafer:c,dies:g,passBins:[...s],ringCount:d,hbinDefs:h,label:`${r.bin} \xB7 ${r.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:m(v(g,`Wafers in hard bin ${r.bin}`),"countBin")}})}if(e==="stackedSoftBins"){let p=$t(t.map(r=>r?.sbinDefs));return(!p||p.length===0)&&(p=[...new Set(t.flatMap(g=>g.dies.map(h=>h.sbin).filter(h=>h!=null)))].sort((g,h)=>g-h).map(g=>({bin:g,name:`Bin ${g}`}))),p.map(r=>{const g=ci(n,r.bin,"soft"),h=[{bin:r.bin,name:r.name}];return{wafer:c,dies:g,passBins:[...s],ringCount:d,sbinDefs:h,label:`${r.bin} \xB7 ${r.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:m(v(g,`Wafers in soft bin ${r.bin}`),"countBin")}})}return t}function Ft(e){const t=B().length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:a.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}function W(e,{fireCallback:t=!0}={}){const n=Object.keys(e);if(n.length>0&&n.every(r=>In.includes(r))){a={...a,...e},ye?.setAxisPrefs(Fn(a)),t&&u.onViewOptionsChange?.(Vt(a),n,Pn(n));return}In.some(r=>r in e)&&ye?.setAxisPrefs(Fn({...a,...e}));const o=a.plotMode,i=mt(a),s=Ue()!==null;a={...a,...e};const l=a.plotMode,d=ie.has(l),c=mt(a),m=o!==void 0&&ie.has(o),v=ke>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const r=G();a={...a,binColors:r},e={...e,binColors:r}}if("compact"in e){const r=ko();a={...a,compactMap:r},e={...e,compactMap:r}}if(("compact"in e||a.compact&&("rotation"in e||"showXYIndicator"in e))&&Ho(),e.plotMode!==void 0)if(d){const r=Ft(l);if(a={...a,...r},v)for(const g of C)g&&g.setOptions(e);else X(Ge(l))}else if(m){const{valueRange:r,lotSize:g,aggregationMethod:h,...y}=a;if(a=y,v)for(const E of C)E&&E.setOptions(e);else X(c?Fe(P.filter(E=>E!==null)):B().filter(E=>E!==null))}else if(i!==c&&!v)X(Fe(P.filter(r=>r!==null)));else for(const r of C)r&&r.setOptions(e);else if(e.aggregationMethod!==void 0&&l==="stackedValues")if(v)for(const r of C)r&&r.setOptions(e);else X(Ge("stackedValues"));else for(const r of C)r&&r.setOptions(e);Ue()!==null!==s&&Nn(),At(),To(),Eo(),So();const p=e.plotMode!==void 0&&e.plotMode!==o;(Ca.some(r=>r in e)||p)&&R(),Te(),Lo(),Wo(),dn(),cn(),t&&u.onViewOptionsChange?.(Vt(a),n,Pn(n))}function Go(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:M.xs,flex:"1",minWidth:"0"});const i=e.createElement("span");i.textContent=t,Object.assign(i.style,{fontWeight:"700",fontSize:N.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(i);const s=gi(e,o,t,n,u.attributes);return{wrap:o,metaPanel:s}}function Ko(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]");if(!o||ja(n??{}).length===0)return;const i=o.parentElement,s=f.ownerDocument.createElement("div");Object.assign(s.style,{display:"flex",alignItems:"center",gap:M.xs,flex:"1",minWidth:"0"}),i?.insertBefore(s,o),s.appendChild(o);const l=gi(f.ownerDocument,s,t,n,u.attributes);l&&(e.contentWrap.style.position="relative",e.contentWrap.appendChild(l))}function Cn(e,t,n){const o=f.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:w.menuBg,border:`1px solid ${w.menuBorder}`,borderRadius:Y.container,boxShadow:On.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:yn(),maxHeight:yn()});const i=f.ownerDocument.createElement("div");Object.assign(i.style,{display:"flex",alignItems:"center",padding:`${M.md} ${M.lg} ${M.sm}`,borderBottom:`1px solid ${w.menuBorder}`,flexShrink:"0",gap:M.sm});const{wrap:s,metaPanel:l}=Go(document,ht(e,t),e.wafer.metadata??void 0);i.appendChild(s);const d=f.ownerDocument.createElement("button");d.dataset.wmapExpandBtn="1",d.setAttribute("aria-label","Open full view"),Ln(d),d.innerHTML=En.expand,Object.assign(d.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${w.menuBorder}`,borderRadius:Y.control,background:w.panelBg,color:w.label,padding:M.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),Tn(d),i.appendChild(d),i.addEventListener("click",r=>{(r.ctrlKey||r.metaKey)&&(r.preventDefault(),r.stopPropagation(),Ri(x.indexOf(e)))},!0),o.appendChild(i);const c=f.ownerDocument.createElement("div");Object.assign(c.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(c),Vo(o,c),l&&c.appendChild(l),F.appendChild(o),o.addEventListener("contextmenu",r=>{if(r.defaultPrevented)return;r.preventDefault();const g=e.viewOptions?{...a,...e.viewOptions}:a,h=on()??po(t),y=h?.source??wa(e.dies,{waferLabel:ve(e),testDefs:e.testDefs,isLotStack:e.isLotStack,activeTest:g.plotMode==="value"?g.activeTest:void 0,waferIndex:t,wafer:e.wafer,passBins:Se(e),ringCount:ne(e,"renderWaferGallery")}),E={x:r.clientX,y:r.clientY};import("./drilldown.js").then(({openDrilldownMenu:A})=>{o.isConnected&&A(E,o,y,h?{plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,...h.ctx}:{plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,onSaveImage:p.getSaveImageHook(),onSaveText:p.getSaveTextHook(),onLocateDie:j=>me(t,j)})})});const m=bt||Ue()!==null,v=e.viewOptions?{...a,...e.viewOptions}:a,p=di(c,e,{viewOptions:{...v,showLegend:m,legendPosition:Ye},showTooltip:!0,padding:z,statsSummary:e.statsSummary,testValueOffer:Jt,onSaveImage:u.onSaveImage,onSaveText:u.onSaveText,downloadFilename:u.downloadFilename,onClick:e.onClick,onSelect:lo(e),drilldownSourceOverride:()=>Ti(t),insights:de,onExpand:()=>ut(t,e),showIdentity:!1,chromeInset:Vs,drawWhenVisible:!0});return p.setViewControlsVisible(!1),p.setSummaryVisible(!1),d.onclick=()=>ut(t,e),xe.has(e)&&(o.style.display="none"),{card:o,ctrl:p,canvasWrapper:c,expandBtn:d}}function ds(e){const t=Ae[e];if(!t)return;const n=[...Q.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=En.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>fs(n.id)):(t.innerHTML=En.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>ut(e,x[e]))}function X(e){ps(),tt()?.remove(),nt(null),Oe(),x=[],U.clear(),an.clear(),ee.style.display="none";for(const c of C)c&&c.destroy();C=[],ue=[],Ae=[],ke=0,F.innerHTML="",zo=e.length,wn(e.map(c=>typeof c=="function"?null:c));const t=[];for(let c=0;c<e.length;c++){const m=e[c];if(typeof m=="function"){const v=f.ownerDocument.createElement("div");v.className="wmap-gallery-card",Object.assign(v.style,{background:w.menuBg,border:`1px solid ${w.menuBorder}`,borderRadius:Y.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const p=f.ownerDocument.createElement("span");p.textContent="\u2026",Object.assign(p.style,{color:w.label,fontSize:"18px"}),v.appendChild(p),F.appendChild(v),x.push(null),C.push(null),ue.push(null),Ae.push(null),t.push({index:c,factory:m,placeholder:v}),ke++}else{const{ctrl:v,canvasWrapper:p,expandBtn:r}=Cn(m,c,e.length);x.push(m),C.push(v),ue.push(p),Ae.push(r)}}Bo(),At(),dn(),cn(),Do();const n=++et,o=()=>{setTimeout(()=>{n===et&&u.onItemsResolved?.()},0)},i=c=>{setTimeout(()=>{n===et&&u.onItemResolved?.(c,e.length)},0)};let s=e.length-t.length;s>0&&i(s);let l=0;function d(){if(n!==et)return;if(l>=t.length){if(ie.has(a.plotMode)){const A=a.plotMode;X(Ge(A));return}if(wt){Yt();return}it=o,R(),je||(it=null,o());return}const{index:c,factory:m,placeholder:v}=t[l++],p=m();P[c]=p;const r=Gt(p,c);Ze(p,c)!==p&&(ae=!0),x[c]=r,wn([r]);const{card:g,ctrl:h,canvasWrapper:y,expandBtn:E}=Cn(r,c,e.length);C[c]=h,ue[c]=y,Ae[c]=E,ke--,v.replaceWith(g),i(++s),qi(),Ki(),!S&&!Pe?.placement&&r.statsSummary?.findings.length&&(S=Hn("right",oe,f.ownerDocument,sn),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.flexDirection="column",S.style.display="none",(Pe?.placement??"right")==="left"?Z.insertBefore(S,F):Z.appendChild(S),R(),re()),re(),setTimeout(d,0)}t.length>0?setTimeout(d,0):o()}if(ie.has(a.plotMode)&&B().length>0){const e=Ft(a.plotMode);a={...a,...e},X(Ge(a.plotMode))}else X(Fe(k));u.insights?.filter!==void 0&&Kt(),Te();let Ke=0;const qo=new(f.ownerDocument.defaultView??window).ResizeObserver(()=>{if(Ke)return;Ke=(f.ownerDocument.defaultView??window).requestAnimationFrame(()=>{Ke=0,T==null&&Sn()})});qo.observe(F),S&&R();function us(e,t){const n=ue[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:w.label,fontSize:N.body,textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function ut(e,t){for(const l of Q.values())if(l.cardIndex===e)return;const n=ht(t,e),o=Ci++,i=C[e]?.getOptions(),s=Gs(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:N.family}),Xs(f,l.documentElement);const d=Ys(f,l.documentElement,()=>y.setOptions({})),c=l.createElement("div");c.dataset.wmapWindowBanner="1",c.textContent=n,Object.assign(c.style,{display:"none",padding:`${M.sm} ${M.xl}`,fontSize:N.body,fontWeight:"700",background:w.warnBg,color:w.warnText,borderBottom:`1px solid ${w.warnBorder}`,flexShrink:"0"}),l.body.appendChild(c);const m=l.createElement("div");Object.assign(m.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),l.body.appendChild(m);const{wrap:v,metaPanel:p}=Go(l,n,t.wafer.metadata??void 0),r=l.createElement("div");Object.assign(r.style,{display:"flex",alignItems:"center",padding:`${M.md} ${M.lg} ${M.sm}`,borderBottom:`1px solid ${w.menuBorder}`,flexShrink:"0",gap:M.sm}),r.appendChild(v),m.appendChild(r);const g=l.createElement("div");Object.assign(g.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),p&&g.appendChild(p),m.appendChild(g);let h=0;const y=xn(g,t,void 0,i,(A,j)=>{const ft=A?j:-h;try{s.resizeBy(ft,0),h=A?j:0}catch{}}),E=setInterval(()=>{s.closed&&It(o)},400);s.addEventListener("pagehide",()=>It(o)),Q.set(o,{id:o,ctrl:y,cardIndex:e,label:n,closePollId:E,stopThemeSync:d,close:()=>{s.closed||s.close()},setTitle:A=>{l.title=A,c.textContent=A,c.style.display="block"}})}else{const l=Ks({title:n,onClose:()=>It(o),anchor:f});l.contentWrap.style.flexDirection="column",Ko(l,n,t.wafer.metadata??void 0);const d=xn(l.contentWrap,t,void 0,i,li(l));Q.set(o,{id:o,ctrl:d,cardIndex:e,label:n,closePollId:null,close:()=>l.close(),setTitle:c=>{const m=l.box.querySelector("[data-wmap-window-title]");m&&(m.textContent=c,m.title=c)}})}C[e]?.destroy(),C[e]=null,us(e,s!==null),ds(e)}function xn(e,t,n,o,i){const s=t.viewOptions?{...a,...t.viewOptions}:a,l=o?{...s,...o}:s,c={...n!==void 0?{...l,plotMode:"value",activeTest:n}:l,showLegend:!0,legendPosition:Ye},m=di(e,t,{viewOptions:c,showTooltip:!0,padding:z,statsSummary:t.statsSummary,testValueOffer:Jt,onSaveImage:u.onSaveImage,onSaveText:u.onSaveText,downloadFilename:u.downloadFilename,onClick:t.onClick,onSelect:lo(t),insights:de,showExpandButton:!1,onSummaryPanelChange:i,showIdentity:!1});return m.setViewControlsVisible(!0),m.setSummaryVisible(!0),m.setExpandVisible(!1),m}function It(e){const t=Q.get(e);if(!t||(Q.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.(),t.ctrl.destroy(),t.cardIndex===null))return;const n=t.cardIndex,o=x[n];if(!o)return;const{card:i,ctrl:s,canvasWrapper:l,expandBtn:d}=Cn(o,n,x.length);ue[n]?.parentElement?.replaceWith(i),C[n]=s,ue[n]=l,Ae[n]=d}function fs(e){const t=Q.get(e);t&&(t.close(),It(e))}function ps(){for(const e of Q.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function Mn(){for(const e of C)e?.drawPendingNow()}const Xo=f.ownerDocument.defaultView??window;Xo.addEventListener("beforeprint",Mn);function ms(){Mn();const e=[...F.querySelectorAll("canvas")];if(!e.length)return;const t=e.length,n=Math.ceil(Math.sqrt(t)),o=Math.ceil(t/n),i=e[0].width,s=e[0].height,l=8,d=(f.ownerDocument.defaultView??window).devicePixelRatio||1,c=Math.round(26*d),m=Math.round(12*d),v=f.ownerDocument.createElement("canvas");v.width=n*i+(n-1)*l,v.height=o*(s+c)+(o-1)*l;const p=v.getContext("2d"),r=Fs(F);p.fillStyle=r.background,p.fillRect(0,0,v.width,v.height),e.forEach((g,h)=>{const y=h%n,E=Math.floor(h/n),A=y*(i+l),j=E*(s+c+l),ft=g.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";p.fillStyle=r.surface,p.fillRect(A,j,i,c),p.fillStyle=r.text,p.font=`700 ${m}px system-ui, sans-serif`,p.textAlign="left",p.textBaseline="middle",p.fillText(ft,A+Math.round(10*d),j+c/2,i-Math.round(20*d)),p.drawImage(g,A,j+c)}),v.toBlob(g=>{if(!g)return;const h=C.find(y=>y!=null)?.getExportTitle();ta(g,["gallery",h].filter(Boolean).join(" "),V.onSaveImage)})}return{setItems(e){en(),P=e.map(n=>typeof n=="function"?null:n);const t=a.plotMode;if(ie.has(t))if(e.some(o=>typeof o=="function"))X(Fe(e));else{const o=Ft(t);a={...a,...o},X(Ge(t))}else X(Fe(e));Zn()},setOptions(e){W(e,{fireCallback:!1})},getOptions(){return Vt(a)},setFindingsNotice(e){so=e,R()},setColumns(e){No(e)},getBinColors(){return a.binColors??G()},setLotStatsSummary(e){en(),_=e,Zn(),Te(),S&&R(),re()},openUserGuide:()=>mn(),destroy(){is(),I.flush(),en(),et++,Xo.removeEventListener("beforeprint",Mn),je?.cancel(),je=null,it=null;for(const e of[...Q.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();Q.clear();for(const e of C)e&&e.destroy();C=[],tt()?.remove(),qo.disconnect(),Ke&&((f.ownerDocument.defaultView??window).cancelAnimationFrame(Ke),Ke=0),f.ownerDocument.removeEventListener("click",Mt,!0),window.removeEventListener("blur",io),wi(),oi(),dt.remove(),Z.remove(),S?.remove(),Nt=!0,vt++,clearTimeout(qt),fe?.el.remove(),ye?.destroy()}}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createViewSwitch as Fo}from"./viewSwitch.js";import{createSummaryToggle as Ro}from"./summaryToggle.js";import{buildView as Wo,buildHoverText as Ao,findTestDef as Ut,resolveTestNumber as On,buildMapTitle as Io}from"../renderer/buildView.js";import{drawMapCanvas as Vo,BIN_LEGEND_W as zi,BIN_LEGEND_W_COMPACT as zo,BIN_LEGEND_ADAPT_COMPACT as Ho,BIN_LEGEND_ADAPT_FLOATING as Yo,PATH_SHAPES as Xo}from"./toCanvas.js";import{buildWaferMap as No,computeCoverage as Hi,computeYield as Yi,defaultBinMode as Ko,getTestPassStatus as _o,isParametricTest as Fn,isBuiltMap as Rn}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Wn}from"../stats/analyzeWaferMap.js";import{SHADOW as jo,LEADING as Xi,wireControlHover as Ni,SPACE as I,EDGE_GUTTER as $o,RADIUS as Ki,FONT as Zt,CLR as W,applyOverlayZ as Go,getTooltip as _i,hideTooltip as qt,positionTooltip as ji,createToolbarHelpers as Uo,buildModeMenuEl as Zo,openReparentedModal as qo,makePaletteBtn as Qo,makeLogScaleBtn as Jo,makeLegendStyleBtn as es,makeOverlaysBtn as ts,makeOrientationBtn as ns,menuLayerFor as $i,saveImageBlob as is,markMenuTrigger as mt,wireMenuA11y as Gi,wireExpandToggle as os,nextFrame as An,requestedPassFailDisplay as ss,overlayMenuRows as ls,anyOverlayActive as as,openCompactDiagnostics as rs,roomForPanel as ds,logWmapVersionOnce as cs,buildDataModeEntries as fs,metadataKeyHasData as us,metadataModeEntry as ps}from"./toolbar.js";import{openUserGuideWindow as hs,registerGuideOpener as gs}from"./guideWindow.js";import{waferIdentityLabel as ms}from"../core/waferLabel.js";import{metadataDisplayValue as ys}from"../core/metadata.js";import{withExportContext as bs}from"./exportName.js";import{testValueNotice as vs}from"./testValueOffer.js";import{axisPrefsFromOptions as Ui,optionsFromAxisPrefs as xs,CHART_PREF_KEYS as In}from"./chartPrefs.js";import{createSummaryPanelEl as Vn,wrapWithSummaryPanel as zn,renderWaferSummaryContentSteps as ws}from"./summaryPanel.js";import{runChunked as Cs}from"./chunked.js";import{collectWarnings as Ss,buildWarningsMenuEl as Ms,severityOf as Es}from"./warnings.js";import{plotStoreFor as Bs}from"./plotStore.js";import{selectionPopulation as ks,waferPopulation as Ds}from"./chartPopulation.js";import{sourceFromBins as Zi}from"./plotItems.js";import{createIdentityHeader as Ps,collapsedLabel as Hn}from"./identityHeader.js";import{getDieKey as he,hasPosition as qi,isPositionedDie as Ls}from"../core/dies.js";import{bandButton as Ts}from"./filterButton.js";import{buildDieListSection as Os}from"./dieList.js";import{buildMaplessSummary as Fs}from"./maplessSummary.js";import{resolveBinColors as Rs,binColorWarning as Ws}from"../renderer/binColors.js";import{isPassBin as As,requirePassBins as Is}from"../core/passBins.js";import{requireRingCount as ze}from"../core/ringCount.js";import{asList as Vs,toggleHighlight as Qi}from"../core/utils.js";import{buildCompactMap as zs,compactLayoutOffered as Hs}from"../core/compact.js";const Ys={binColorScheme:!0,valueColorScheme:!0,reverseValueScheme:!0,useDefinedBinColors:!0,showDieLabels:!0,showRingBoundaries:!0,showQuadrantBoundaries:!0,showReticle:!0,showXYIndicator:!0,showAxes:!0,legendPosition:!0,colorbarRangeMode:!0,markFailingDies:!0,fallbackFormat:!0,chartAxisIncludesLimits:!0,chartClipOutliers:!0,chartLimitLines:!0};export const WAFER_PREFERENCE_KEYS=Object.keys(Ys);const Ji=new Set(WAFER_PREFERENCE_KEYS);export const COLOR_KEYS=["binColorScheme","valueColorScheme","reverseValueScheme","useDefinedBinColors","binColors"];export function classifyChanged(P){const h=P.some(u=>Ji.has(u)),y=P.some(u=>!Ji.has(u));return h&&y?"mixed":h?"preference":"state"}export function findingBin(P,h,y){const{kind:u,bin:E}=P.variable;if(!(u!=="hardBin"&&u!=="softBin"||E===void 0))return h&&As(u,E,h,y)?void 0:E}export function findingPlotMode(P,h,y){const{kind:u}=P.variable;return u==="hardBin"||u==="softBin"?u:h==="hardBin"||h==="softBin"?h:y?"hardBin":"softBin"}export function toPublicViewOptions(P){const{metadataValueOrder:h,binColors:y,lotSize:u,compactMap:E,...Je}=P;return Je}export function renderWaferMap(P,h,y={}){return renderWaferMapCard(P,h,y)}export function renderWaferMapCard(P,h,y={}){cs();const u=P.ownerDocument,E=u.defaultView??window,Je=()=>C.label,yt=()=>ms({label:Je(),wafer:_}),re=bs(()=>{const e=ys(_.metadata?.lot);return{prefix:y.downloadFilename,lots:e!==void 0?[e]:[],...C.isLotStack?{stackedWafers:g?.lotSize??!0}:{wafer:yt()}}},y.onSaveImage,y.onSaveText);function Yn(){const e=g.plotMode==="softBin"||g.plotMode==="stackedSoftBins"?ie:ne,{primary:n,secondary:t}=Io(g,d.fallbackFormat,e);return[n,C.isLotStack?"":t].filter(Boolean).join(" ")||"wafer-map"}E.getComputedStyle(P).position==="static"&&(P.style.position="relative");const eo=P.clientHeight;y.height!=null&&(P.style.height=typeof y.height=="number"?`${y.height}px`:y.height);const Qt=h.dataCoverage?h.dataCoverage.unpositionedDies:h.dies.filter(e=>!qi(e)).length,et=(h.dataCoverage?h.dataCoverage.totalDies:h.dies.length-Qt)===0&&Qt>0,He=u.createElement("div");Object.assign(He.style,{display:"flex",flexDirection:"column",width:"100%",height:"100%"}),P.appendChild(He);const Se=u.createElement("div");Object.assign(Se.style,{position:"relative",width:"100%",flex:"1 1 auto",minHeight:"0"});const ge=y.chromeInset??$o,V=u.createElement("div");Object.assign(V.style,{display:"flex",alignItems:"stretch",gap:I.sm,background:W.canvasBg,paddingBottom:I.lg,paddingTop:ge,paddingLeft:ge,paddingRight:ge,flexShrink:"0",minWidth:"0"}),He.appendChild(V),He.appendChild(Se);function Ye(){const e=[...V.children].some(n=>n.style.display!=="none");V.style.display=e?"flex":"none"}const M=u.createElement("div");Object.assign(M.style,{position:"relative",width:"100%",height:"100%"});const a=u.createElement("canvas");Object.assign(a.style,{width:"100%",height:"100%",display:"block"}),M.appendChild(a),Se.appendChild(M);let bt=null;if(Qt>0){let t=function(){if(n){const l=Os(e,h.testDefs,{...y.dieList,onSaveText:re.onSaveText,waferMetadata:_.metadata,metadataFields:Pe,attributes:y.attributes,ownerDocument:u});if(l)return l}const o=Ut(h.testDefs,d.activeTest??0),s=Fn(o)?d.logScale??o?.logScale??!1:!1;return Fs(e,h.testDefs,{plotMode:d.plotMode??"hardBin",activeTest:d.activeTest,hbinDefs:ne,sbinDefs:ie,binColors:g.binColors,valueColorScheme:d.valueColorScheme,reverseValueScheme:d.reverseValueScheme,logScale:s,colorbarRangeMode:d.colorbarRangeMode,valueRangeDies:h.dies})},i=function(o){const s=u.createElement("button");return s.type="button",Ni(s),Object.assign(s.style,{fontSize:Zt.body,padding:`${I.xxs} ${I.sm}`,borderRadius:Ki.control,flexShrink:"0",border:`1px solid ${W.menuBorder}`,background:W.menuBg,color:W.text,cursor:"pointer"}),s.textContent=n?"View chart":"View die list",s.addEventListener("click",l=>{l.stopPropagation(),n=!n,s.textContent=n?"View chart":"View die list",o()}),s};const e=h.dies.filter(o=>!qi(o));let n=!1;if(et){const o=u.createElement("div");Object.assign(o.style,{position:"absolute",inset:"0",background:W.panelBg,padding:I.xl,boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",gap:I.md,zIndex:"1"});const s=u.createElement("div");Object.assign(s.style,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:I.md});const l=u.createElement("span");Object.assign(l.style,{fontSize:Zt.body,color:W.label,lineHeight:Xi.base}),l.textContent="No die position data for this wafer.",s.appendChild(l);const r=u.createElement("div");Object.assign(r.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),s.appendChild(i(()=>r.replaceChildren(t()))),o.appendChild(s),o.appendChild(r),M.appendChild(o),bt=()=>{n||r.replaceChildren(t())}}else{const o=u.createElement("div");Object.assign(o.style,{position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"3",background:W.panelBg,borderTop:`1px solid ${W.menuBorder}`,fontSize:Zt.body,color:W.text,cursor:"pointer",padding:`${I.xs} ${I.md}`,display:"flex",alignItems:"center",justifyContent:"space-between",gap:I.md}),Ni(o,"bare");const s=u.createElement("span");s.textContent=`+${e.length} ${e.length===1?"die":"dies"} without position data`,o.appendChild(s);const l=u.createElement("span");l.textContent="\u25BE",Object.assign(l.style,{fontSize:Zt.body,lineHeight:Xi.none,color:W.label,flexShrink:"0"}),o.appendChild(l),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`${e.length} dies without position data. Click to view.`);let r=null,c=null;os(o,f=>{if(l.textContent=f?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(f)),f){r=u.createElement("div");const p=o.getBoundingClientRect().height||28;Object.assign(r.style,{position:"absolute",left:"0",right:"0",bottom:`${p}px`,top:"20%",zIndex:"2",background:W.panelBg,borderTop:`1px solid ${W.menuBorder}`,padding:I.md,boxSizing:"border-box",display:"flex",flexDirection:"column",gap:I.md}),r.addEventListener("click",R=>R.stopPropagation());const b=u.createElement("div");Object.assign(b.style,{display:"flex",justifyContent:"flex-end"}),b.appendChild(i(()=>{c&&c.replaceChildren(t())})),r.appendChild(b),c=u.createElement("div"),Object.assign(c.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),c.appendChild(t()),r.appendChild(c),M.appendChild(r)}else r&&(r.remove(),r=null,c=null)}),M.appendChild(o),bt=()=>{c&&!n&&c.replaceChildren(t())}}}const{onHover:vt,onClick:to,onSelect:me,onViewOptionsChange:Xn,showTooltip:no=!0,showToolbar:Me=!0,showIdentity:Nn=!0,summaryPanel:tt,showHelpButton:Kn=!1,userGuideExtension:io,onExpand:_n,showExpandButton:jn=!0,zIndex:oo,insights:J,warnings:$n,viewOptions:so={},...Xe}=y,Ee=J?.enabled??Me;let nt=null,Ne=null;Ee&&(nt=Fo(u,"Map","wafer",e=>Le(e)),Me||(nt.el.style.marginLeft="auto"),V.appendChild(nt.el)),Ee&&(Ne=Ts(u,"Filter\u2026","wmapMapFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>{tn().then(e=>e.openEditor(Ne??P,[St()]))}),Ne.style.order="1",V.appendChild(Ne));const lo=.4,ao=20,de=[...Is(h,"renderWaferMap")],Gn=$n?.display??!0,ro=Go(oo);let ce=y.statsSummary,Be=!1,xt;const fe=()=>Be?xt:ce;let xe=[],Un=!1,wt=null,Zn=!1;function Jt(){const e=Ss({result:h,statsSummary:fe(),extra:wt?[wt]:[]}),n=e.length!==xe.length||e.some((t,i)=>t.code!==xe[i]?.code||t.message!==xe[i]?.message);xe=e,(n||!Un)&&(Un=!0,$n?.onWarning?.(e))}Jt();let C=h,_=h.wafer,Ct=h.dies,N=h.dies,we=null,qn=null,ke=null;const St=()=>({dies:Ct,wafer:_,label:Je()??"Wafer",identity:yt(),waferIndex:0,passBins:de,testDefs:j,statsSummary:ce});function en(){const e=we?.get();if(xt=void 0,!we||!e||e.off)return Be=!1,Ct;const n=we.mark([St()]);Be=n.narrowing;const t=n.items[0].dies;if(Be&&ce&&Rn(C)){const i=t.filter(o=>!o.filteredOut);try{xt=i.length===0?void 0:Wn({...C,dies:i,yield:Yi(t,de,C.yield?.yieldPercentGross!=null?"denominator-only":"exclude"),dataCoverage:Hi(i)},ce.analysisOptions)}catch{xt=void 0}}return t}function Qn(){if(!we||!ke)return;const e=[St()];ke.refresh(we.keep(e).result,e),ke.el.style.display=we.get()&&!pe?"":"none"}function Jn(){N=en(),Qn(),at(),x(),pn(ce)}function tn(){return qn??=import("./pageFilter.js").then(({createPageFilter:e})=>{const n=e({doc:u,initial:J?.filter,onChange:J?.onFilterChange,savedFilters:J?.savedFilters,onSavedFiltersChange:J?.onSavedFiltersChange,pickFiltersFile:J?.onPickFiltersFile,onSaveText:y.onSaveText,attributes:y.attributes,getRingCount:()=>ze(C,"renderWaferMap")});return we=n,ke=n.createBand(()=>[St()],{marginLeft:ge,marginRight:ge,marginBottom:I.lg}),He.insertBefore(ke.el,Se),n.subscribe(()=>{Ke||Jn()}),n.get()&&!Ke&&Jn(),n}),qn}let w=new Set,De=null;const nn=J?.plotStore??Bs(J),Mt={plots:nn,getBinColors:()=>g.binColors,attributes:y.attributes,onSaveImage:re.onSaveImage,onSaveText:re.onSaveText,onLocateDie:e=>Kt(e)},Et=()=>!et;let on=null,Bt=null,kt=!1,Ke=!1,ne=h.hbinDefs,ie=h.sbinDefs,j=h.testDefs,Pe=h.metadataFields,ei=h.reticles?.length?h.reticles:void 0,Dt=h.reticleConfig,ti=h.dataAxisFlip,sn=h.isLotStack??!1,ln=h.aggrMethod,an=h.lotSize,ee=null,ue=null,Pt=null;function Lt(e){Pt&&(Pt.style.display=e?"flex":"none",Ue?.())}Nn&&(ee=Ps(Hn(_.metadata??{},it())??"",_.metadata,{lotStack:it(),ownerDocument:u,attributes:y.attributes}),M.appendChild(ee.metaPanel),ee.metaPanel.style.visibility="visible",ee.isEmpty()||(ue=ni(ee.wrap),V.insertBefore(ue,V.firstChild),Ye()));function ni(e){const n=u.createElement("div");return Object.assign(n.style,{display:"flex",alignItems:"center",padding:`${I.sm} ${I.lg}`,flex:"1 1 auto",minWidth:"0",overflow:"hidden",gap:I.sm}),Object.assign(e.style,{flex:"1",minWidth:"0"}),n.appendChild(e),n}function it(){return sn?{lotSize:an??1,aggrMethod:ln}:void 0}function co(){if(!ee)return;ee.update(Hn(_.metadata??{},it())??"",_.metadata,it());const e=ue?.isConnected??!1,n=!ee.isEmpty();!n&&e?(ue.remove(),ue=null):n&&!e&&(ue=ni(ee.wrap),ue.style.display="",V.insertBefore(ue,V.firstChild),Ye())}const fo=[...ne??[],...ie??[]].some(e=>e.color);let d={plotMode:Ko([h.dies]),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,showReticle:!1,showXYIndicator:!1,compact:!1,rotation:0,flipX:!1,flipY:!1,legendPosition:"default",...so},$=null,pe=!1,ii=null;function oi(){return Ee?$?Promise.resolve($):(ii??=Promise.all([import("./insightsTab.js"),tn()]).then(([{createInsightsTab:e},n])=>($=e({pageFilter:n,showFilterButton:!1,initialAxisPrefs:Ui(d),onAxisPrefsChange:t=>{d={...d,...xs(t)};const i=[...In];Xn?.(d,i,classifyChanged(i))},attributes:y.attributes,getItems:()=>[{wafer:_,dies:Ct,hbinDefs:ne,sbinDefs:ie,testDefs:j,label:Je(),passBins:de,ringCount:ze(C,"renderWaferMap"),statsSummary:ce}],getBinColors:()=>g.binColors,getRingCount:()=>ze(C,"renderWaferMap"),onSaveImage:re.onSaveImage,onSaveText:re.onSaveText,defaultView:J?.defaultView,plotStore:nn,onPickPlotsFile:J?.onPickPlotsFile,showOnMap:t=>{if(Le(!1),t.kind==="test")fi(t.testNumber);else{const i=fe()?.findings.find(o=>o.id===t.id);i&&ui(i)}fe()&&Yt(!0)},showMetadataStrip:!1,contentInset:ge,onOpenGuide:Kn&&!Me?()=>jt():void 0,focusTest:t=>{F({plotMode:"value",activeTest:t,highlightBin:void 0}),Le(!1)},locateDie:t=>{Le(!1),Kt(t)},ownerDocument:u}),Object.assign($.el.style,{position:"absolute",inset:"0",background:W.canvasBg,overflowY:"auto",paddingTop:"0"}),$.el.style.display="none",Se.appendChild($.el),$)),ii):Promise.resolve(null)}let si=0;const rn=["wheel","touchstart","pointerdown","keydown"];function uo(e,n){if(n<=0)return;let t=!1;const i=[],o=()=>{t=!0;for(const l of i)E.clearTimeout(l);i.length=0;for(const l of rn)e.removeEventListener(l,o)},s=()=>t||!pe?!0:(e.scrollTop=n,e.scrollTop>=n);if(!s()){for(const l of rn)e.addEventListener(l,o,{passive:!0,once:!0});for(const l of[0,50,150,300,600])i.push(E.setTimeout(()=>{s()},l));i.push(E.setTimeout(()=>{for(const l of rn)e.removeEventListener(l,o)},700))}}function dn(){for(const e of[Z,O])e&&(e.style.visibility=pe?"hidden":"")}function Le(e){if(!Ee)return;const n=pe;pe=e,nt?.setInsightsOpen(e),ke&&(ke.el.style.display=we?.get()&&!e?"":"none"),$&&!e&&n&&(si=$.el.scrollTop),$&&($.el.style.display=e?"flex":"none"),M.style.visibility=e?"hidden":"",dn(),X&&(X.style.display=e||et?"none":"flex"),A&&(A.style.display=e?"none":"flex"),Lt(!Ae),se&&(se.style.display="flex"),ue&&(ue.style.display=""),Ye(),Ue?.(),ee&&e&&ee.collapse(),ct(),e&&oi().then(t=>{!t||!pe||(t.el.style.display="flex",t.render(),uo(t.el,si))})}Ee&&J?.defaultOpen&&queueMicrotask(()=>Le(!0));let g,Te,G=null,T=null,Tt=[],cn;function li(e){cn!==e&&(cn=e,x())}let Oe=null,fn=Xe.legendOffset??{x:0,y:0},ot=!1,_e=!1,st={x:0,y:0},un={x:0,y:0},Fe=!1,je=!1,U="select",$e={x:0,y:0},Ot={x:0,y:0},z={x:0,y:0},H={x:0,y:0},lt=!1,Ge=!1;function at(){const e=d,n=N.filter(Ls);g=Wo(_,n,{compact:d.compact?d.compactMap??zs(n):void 0,plotMode:e.plotMode,binColorScheme:e.binColorScheme,valueColorScheme:e.valueColorScheme,reverseValueScheme:e.reverseValueScheme,useDefinedBinColors:e.useDefinedBinColors,binColors:e.binColors??Rs(N,{passBins:de,binColorScheme:e.binColorScheme,hbinDefs:ne,sbinDefs:ie,useDefinedBinColors:e.useDefinedBinColors}),passBins:de,showDieLabels:e.showDieLabels,showRingBoundaries:e.showRingBoundaries,showQuadrantBoundaries:e.showQuadrantBoundaries,showReticle:e.showReticle,showXYIndicator:e.showXYIndicator,reticles:ei,ringCount:ze(C,"renderWaferMap"),highlightBin:e.highlightBin,highlightMetadataValue:e.highlightMetadataValue,activeTest:e.activeTest,activeMetadataKey:e.activeMetadataKey,testDefs:j,valueRange:e.valueRange,metadataValueOrder:e.metadataValueOrder,logScale:e.logScale,isLotStack:sn,aggregationMethod:ln??e.aggregationMethod,lotSize:an??e.lotSize,dataAxisFlip:ti,colorbarRangeMode:e.colorbarRangeMode,passFailDisplay:e.passFailDisplay,fallbackFormat:e.fallbackFormat,interactiveTransform:{rotation:e.rotation??0,flipX:e.flipX??!1,flipY:e.flipY??!1}},{hbinDefs:ne,sbinDefs:ie,metadataFields:Pe}),Te=void 0;const t=e.binColors?null:Ws(g.binColors,g.plotMode);t?.message!==wt?.message&&(wt=t,Jt(),Zn&&gn())}at();function ai(){return d.showAxes??Xe.showAxes??T!==null}function po(){return Hs(N,[Dt])}let Z=null,Re=null,ye=null,Ce=null,Ft=null;function ri(){ye===null&&Ce===null&&(Ft={plotMode:d.plotMode,activeTest:d.activeTest})}function di(){F({...Ft??{},highlightBin:void 0}),Ft=null}function pn(e){const n=e!==ce;if(ce=e,n&&Be&&(N=en(),at(),x()),Jt(),gn(),Z)oe();else if(O)At();else if(e&&!tt?.placement){const t=tt?.defaultOpen??!Me;O=Vn("right",ge,u,Bn),O.style.display=t?"block":"none";const i=M.parentElement,o=M.nextSibling;be=zn(M,O,"right"),i?.insertBefore(be,o),At(),dn()}ct()}function Rt(){Z?oe():O&&At()}let ci=y.findingsNotice,rt=!1;const ho=()=>ci??(y.testValueOffer?y.testValueOffer():void 0)??(!y.testValueOffer&&Rn(C)?vs(fe()?.stats.testValueAnalysis,1,rt,go):void 0);function go(){const e=ce,n=C;if(rt||!e||!Rn(n))return;rt=!0,Rt();const t=u.defaultView?.requestAnimationFrame?.bind(u.defaultView)??(s=>setTimeout(s,16));let i=!1;const o=()=>{if(i||Ke)return;i=!0;let s;try{s=Wn(n,{...e.analysisOptions,enableTestValueAnalysis:!0})}catch(l){throw rt=!1,Rt(),l}if(rt=!1,C!==n||ce!==e){Rt();return}pn(s),y.onStatsSummaryChange?.(s)};t(()=>t(o)),setTimeout(o,120)}let mo={},O=null,be=null;function yo(e){const{kind:n,index:t}=e.variable;if(n==="test")F({plotMode:"value",activeTest:t??0,highlightBin:void 0});else{const o=N.some(s=>s.hbin!=null);F({plotMode:findingPlotMode(e,d.plotMode,o),highlightBin:findingBin(e,de,o)})}const i=e.highlight;(i.kind==="bin"||i.kind==="region"||i.kind==="dies")&&Ht(i.dieKeys)}const dt=new Map,hn=new WeakSet;function Wt(e){if(dt.get(e)?.cancel(),dt.delete(e),e.style.display==="none"){hn.add(e);return}hn.delete(e);const n=Cs(ws(e,{wafer:_,dies:N,yieldSummary:Be?Yi(N,de,C.yield?.yieldPercentGross!=null?"denominator-only":"exclude"):C.yield,dataCoverage:Be?Hi(N.filter(t=>!t.filteredOut)):C.dataCoverage,hbinDefs:ne,sbinDefs:ie,testDefs:j,statsSummary:fe(),warnings:Gn?xe:[],passBins:de,ringCount:ze(C,"renderWaferMap"),binColors:g.binColors,plotMode:d.plotMode??"hardBin",metadataShownElsewhere:Nn,fallbackFormat:d.fallbackFormat,activeFindingId:ye,findingsFilter:mo,findingsNotice:ho(),onFindingsFilterChange:oe,onSaveText:re.onSaveText,metadataFields:Pe,dieListOptions:y.dieList,onLocateDie:t=>Kt(t),attributes:y.attributes,onClose:Me&&fe()?()=>Yt(!1):void 0,activeTest:Ce,onTestClick:t=>{Ce===t?(Ce=null,Ht([]),di(),oe()):fi(t)},onFindingClick:(t,i)=>{ye===t.id?(ye=null,Ht([]),di(),oe()):ui(t)},onShowChart:Ee?t=>{Le(!0),oi().then(i=>i?.showWorthCard(t))}:void 0}));n.done||dt.set(e,n)}function fi(e){ri(),ye=null,Ce=e,F({plotMode:"value",activeTest:e,highlightBin:void 0}),Ht(fe()?.stats.testFailures?.[e]?.dieKeys),oe()}function ui(e){ri(),Ce=null,ye=e.id,yo(e),oe()}function oe(){Z?Wt(Z):O&&Wt(O)}function At(){O&&Wt(O)}if(tt?.placement){const e=tt.placement;Z=Vn(e,ge,u,Bn);const n=M.parentElement,t=M.nextSibling;Re=zn(M,Z,e),n?.insertBefore(Re,t),oe()}else if(fe()){const e=tt?.defaultOpen??!Me;O=Vn("right",ge,u,Bn),O.style.display=e?"block":"none";const n=M.parentElement,t=M.nextSibling;be=zn(M,O,"right"),n?.insertBefore(be,t),At()}dn();const Y=no?_i(u):null;let se=null,K=null,Ue=null,X=null,A=null,It=null,Vt=null,pi=!0,hi=null,ve=null,zt=null;Zn=!0;function gn(){if(!ve||!zt)return;const e=xe.length,n=e>0;if(ve.style.display=n?"flex":"none",zt.style.display=n?"":"none",Ue?.(),!n)return;const t=Es(xe[0]),i=`${e} data ${e===1?"warning":"warnings"}`;ve.style.color=t==="error"?W.errText:W.warnText,ve.ariaLabel=t==="error"?`${i} \u2014 the map may be positionally wrong`:i}let mn=null,gi=null,yn=null,bn=null,vn=null,xn=null;function We(e="selection"){ye===null&&Ce===null||(ye=null,Ce=null,Ft=null,e==="selection"?F({highlightBin:void 0}):(w=new Set,me?.([])),oe())}function Ht(e){w=new Set(e??[]),me&&me(Qe()),x()}function ct(){if(!Vt)return;Ue?.();const e=Z??O;Vt.sync({visible:pi&&!!fe()&&!!e&&!pe,open:!!e&&e.style.display!=="none",notable:!!fe()?.hasNotableFindings})}function Yt(e){const n=Z??O;if(!n)return;const t=n.style.display!=="none",i=M.getBoundingClientRect().width;if(n.style.display=e?"block":"none",e!==t){const o=i-M.getBoundingClientRect().width;(y.onSummaryPanelChange??Xt)?.(e,e?o:0)}e&&hn.has(n)&&Wt(n),ct()}if(Me){let R=function(L){U=L,i(v,L==="zoom"),i(q,L==="pan"),It&&i(It,L==="select"),a.style.cursor=L==="pan"?"grab":"crosshair"};se=u.createElement("div"),se.dataset.wmapToolbar="single",Object.assign(se.style,{marginLeft:"auto",flexShrink:"0",display:"flex",flexDirection:"row",alignItems:"center",flexWrap:"wrap-reverse",justifyContent:"flex-end",maxWidth:"100%",background:W.menuBg,border:`1px solid ${W.menuBorder}`,borderRadius:Ki.control,boxShadow:jo.panel,pointerEvents:"auto"});const e=_i(u),n=Uo(e),{makeBtn:t,setActive:i,makeSep:o,syncSeparators:s,syncToolbarVisible:l,makeMenuRow:r,makeMenuSection:c,closeOpenMenu:f,getOpenMenu:p,setOpenMenu:b}=n;Ue=()=>{K&&s(K),se&&l(se,"flex"),Ye()},mn=f,gi=p,u.addEventListener("click",f,!0),X=u.createElement("div"),Object.assign(X.style,{display:et?"none":"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),se.appendChild(X);const le=t("download","Download PNG",So);X.appendChild(le),X.appendChild(o());const v=t("zoomMode","Zoom (drag to zoom region)",()=>R("zoom")),B=t("zoomIn","Zoom in",()=>qe(a.clientWidth/2,a.clientHeight/2,1.2)),S=t("zoomOut","Zoom out",()=>qe(a.clientWidth/2,a.clientHeight/2,1/1.2)),k=t("reset","Reset zoom (double-click)",()=>ut());X.appendChild(v),X.appendChild(B),X.appendChild(S),X.appendChild(k),X.appendChild(o());const q=t("pan","Pan (drag to move)",()=>R("pan"));X.appendChild(q),It=t("boxSelect","Select (drag to select dies)",()=>R("select")),X.appendChild(It);{const L=t("drilldown","Chart this wafer",()=>{const ae=L.getBoundingClientRect();kn({x:ae.left,y:ae.bottom+4},L)});L.setAttribute("aria-haspopup","menu"),Bt=L,Ei(),X.appendChild(L)}R(U);{let L=function(m){return m.plotMode!==(d.plotMode??"hardBin")?!1:m.plotMode==="value"?(d.activeTest??0)===(m.activeTest??0):m.plotMode==="metadata"?d.activeMetadataKey===m.activeMetadataKey:!0},ae=function(m,D){m.activeTest!==void 0?F({plotMode:m.plotMode,activeTest:m.activeTest,activeMetadataKey:void 0,logScale:m.logScale}):m.activeMetadataKey!==void 0?F({plotMode:m.plotMode,activeTest:void 0,activeMetadataKey:m.activeMetadataKey,passFailDisplay:"off"}):F({plotMode:m.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),D.remove(),b(null),mt(Q,!1)};K=u.createElement("div"),Object.assign(K.style,{display:"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),se.appendChild(K),A=u.createElement("div"),Object.assign(A.style,{display:"flex",alignItems:"center",gap:"0"}),K.appendChild(A),A.appendChild(o());const pt=()=>{const m=p();m&&(m.remove(),b(null)),mt(Q,!1)},Q=t("mode","Plot mode",()=>{if(p()){pt();return}const m=N,D=g.testDefs,{testEntries:Gt,binEntries:Ie,stackedEntries:ht}=fs(m,D,{includeStacked:g.isLotStack}),Tn=(Pe??[]).filter(Ve=>us(m,Ve.key)).map(ps),gt=Zo(Q.getBoundingClientRect(),Gt,Ie,ht,L,ae,{makeMenuRow:r,makeMenuSection:c},d.plotMode??"hardBin",Q.ownerDocument.defaultView??window,Tn);$i(Q).appendChild(gt),b(gt),mt(Q,!0),Gi(gt,Q,pt)});mt(Q,!1);const{btn:Pn,sync:Ln}=Qo(n,()=>({...d,plotMode:d.plotMode??"hardBin"}),()=>fo,F);bn=Ln,bn();const Bo=ts(n,()=>{const m=!!g.hasReticle,D=(d.plotMode??"hardBin")==="value",{testNumber:Gt}=On(d.activeTest??0,g.testDefs),Ie=Ut(g.testDefs,Gt),ht=D&&Ie!==void 0&&!Fn(Ie),Tn=D&&!ht&&(Ie?.limitLow!==void 0||Ie?.limitHigh!==void 0),gt=D&&!ht&&g.dies.some(Ve=>_o(Ve,Gt,Ie)!==void 0);return ls({...d,showAxes:ai()},m,{functionalActive:ht,hasLimits:Tn,hasRecorded:gt,binMode:(d.plotMode??"hardBin")==="hardBin"||(d.plotMode??"hardBin")==="softBin"},Ve=>F(Ve),{on:!!d.compact,offered:po(),onChange:Ve=>F({compact:Ve}),onDiagnostics:()=>rs(N,[Dt],{anchor:a,onSaveText:re.onSaveText})})},()=>as(d)),{btn:ko,sync:Do}=es(n,()=>d,m=>F({legendPosition:m}));yn=Do,yn();const Vi=()=>{const{testNumber:m}=On(d.activeTest??0,j),D=Ut(j,m);return D!==void 0&&!Fn(D)},{btn:Po,sync:Lo}=Jo(n,()=>({...d,functionalActive:Vi()}),m=>F(m));vn=Lo,vn();const To=()=>{const{testNumber:m}=On(d.activeTest??0,j),D=Ut(j,m);return D!==void 0&&(D.limitLow!==void 0||D.limitHigh!==void 0)},$t=t("specRange","Colorbar range: test limits",()=>{const m=d.colorbarRangeMode==="data"?"spec":"data";F({colorbarRangeMode:m})});xn=()=>{const m=d.plotMode==="value"&&To()&&ss(d)==="off"&&!Vi();$t.style.display=m?"":"none";const D=(d.colorbarRangeMode??"spec")==="spec";i($t,D),$t.ariaLabel=D?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"},xn();const Oo=ns(n,()=>d,m=>F(m));A.appendChild(Q),A.appendChild(Pn),A.appendChild(Po),A.appendChild($t),et||(A.appendChild(o()),A.appendChild(Bo),A.appendChild(o()),A.appendChild(ko),A.appendChild(o()),A.appendChild(Oo)),Vt=Ro(u,()=>{const m=Z??O;m&&Yt(m.style.display==="none")}),V.insertBefore(Vt.el,nt?.el??null),ct(),Gn&&(zt=o(),ve=t("warning","Data warnings",()=>{const m=p();if(f(new MouseEvent("click")),m)return;const D=Ms(ve.getBoundingClientRect(),xe,E);$i(Se).appendChild(D),b(D),Gi(D,ve,()=>f(new MouseEvent("click")))}),mt(ve,!1),K.appendChild(zt),K.appendChild(ve),gn()),jn&&(K.appendChild(o()),Pt=t("expand","Expand (E)",_n??mi),K.appendChild(Pt)),Kn&&(K.appendChild(o()),hi=t("help","User guide",()=>jt()),K.appendChild(hi)),Ue?.()}V.appendChild(se),Ne&&V.appendChild(Ne),Ye()}let Ae=null,Xt=null;function mi(){Ae&&(Ae.close(),Ae=null);const e=Se;e.style.flex="1",e.style.minWidth="0",e.style.minHeight="0";const n=Hn(_.metadata??{},it()),t=V.childElementCount>0?[V,e]:[e],i=qo(t,{ownerDocument:u,boxSize:pe?{width:"min(96vw, 1600px)",height:"min(92vh, 1000px)"}:void 0,onClosed:()=>{Ae=null,Xt=null,Lt(!0),pe||a.focus({preventScroll:!0})}});if(!i)return;i.box.setAttribute("aria-label",n??"Expanded wafer map"),t.length>1&&(i.contentWrap.style.flexDirection="column"),Ae=i,Xt=ds(i);const o=Z??O,s=Re??be;if(o&&s&&o.style.display!=="none"){const l=parseFloat(u.defaultView?.getComputedStyle(s).columnGap??"")||0,r=o.getBoundingClientRect().width+l;r>0&&Xt(!0,r)}Lt(!1)}function yi(e){("binColorScheme"in e||"useDefinedBinColors"in e)&&!("binColors"in e)&&d.binColors!==void 0&&(e={...e,binColors:void 0});const n=d.plotMode;d={...d,...e},In.some(l=>l in e)&&$?.setAxisPrefs(Ui(d));const t=Object.keys(e);if(t.length>0&&t.every(l=>In.includes(l)))return;("compact"in e||"compactMap"in e)&&(G=null,T=null),e.plotMode!==void 0&&e.plotMode,Object.keys(e).every(l=>l==="legendPosition"||l==="showLegend"||l==="markFailingDies"||l==="showAxes")||at(),yn?.(),bn?.(),vn?.(),xn?.(),x();const o=e.plotMode!==void 0&&e.plotMode!==n,s=COLOR_KEYS.some(l=>l in e);(s||o)&&oe(),(s||o||e.activeTest!==void 0||e.logScale!==void 0||e.colorbarRangeMode!==void 0)&&bt?.()}function F(e){yi(e);const n=Object.keys(e);Xn?.(d,n,classifyChanged(n))}let wn=!1;const Cn=y.drawWhenVisible&&E.IntersectionObserver?new E.IntersectionObserver(e=>{Ze=e[e.length-1].isIntersecting,Ze&&Nt&&x()},{rootMargin:"25%"}):null;let Ze=Cn===null,Nt=!1;Cn?.observe(a);function Sn(){wn||(wn=!0,An(()=>{wn=!1,x()},E))}function x(){if(!Ze){Nt=!0;return}Nt=!1;const e=T??void 0,n=g.dies[0],t=n?{x:n.width,y:n.height}:Xe.diePitchMm,i=Math.floor(a.clientWidth||a.width),o=!!(ne?.length||ie?.length||g.dies.some(b=>b.hbin!=null||b.sbin!=null)),s=d.legendPosition??"default",l=d.showLegend??!0,r=s==="default"||s==="compact",c=(Xe.colorbarWidth??16)+28,f=o&&r?s!=="default"?Math.max(zi,c):i<Yo?0:i<Ho?Math.max(zo,c):Math.max(zi,c):void 0,p=Vo(a,g,{...Xe,minRightReserve:l?f:0,showColorbar:l&&(Xe.showColorbar??!0),markFailingDies:d.markFailingDies??!1,legendPosition:s,legendOffset:fn,diePitchMm:t,fallbackFormat:d.fallbackFormat,showAxes:ai(),viewport:e,activeBin:d.plotMode==="metadata"?d.highlightMetadataValue:d.highlightBin,hoverBin:cn,afterDies:w.size>0||De!==null?bo:void 0,hbinDefs:ne,sbinDefs:ie,metadataFields:Pe});Tt=p.binLegendRows,Oe=p.legendBox??null,T===null&&(G=p.viewport),je&&Co(),Ei()}function bo(e,n,t){w.size>0&&xo(e,n,t),De!==null&&vo(e,n,t)}function vo(e,n,t){Te??=new Map(g.dies.map((b,R)=>[he(b),R]));const i=De===null?void 0:Te.get(De);if(i===void 0)return;const o=g.hoverPoints[i],s=g.rectangles[0],l=s?s.width/2*n.ppm:n.ppm*.5,r=s?s.height/2*n.ppm:n.ppm*.5,c=n.originX+o.x*n.ppm,f=n.originY-o.y*n.ppm,p=Math.max(l,r)*1.25+5;e.save(),e.setLineDash([]),e.beginPath(),e.arc(c,f,p,0,Math.PI*2),e.strokeStyle=t.background,e.lineWidth=6,e.stroke(),e.strokeStyle=t.text,e.lineWidth=3,e.stroke(),e.restore()}function Kt(e){if(De=e===null?null:he(e),e!==null&&T!==null){ut();return}x()}function bi(){De!==null&&(De=null,x())}function xo(e,n,t){const i=g.hoverPoints,o=g.rectangles[0],s=o?o.width/2*n.ppm:n.ppm*.5,l=o?o.height/2*n.ppm:n.ppm*.5,r=new Set;w.size>0&&(Te??=new Map(g.dies.map((v,B)=>[he(v),B])));for(const v of w){const B=Te.get(v);B!==void 0&&r.add(B)}if(!r.size)return;e.save(),e.setLineDash([]),e.fillStyle=t.background,e.globalAlpha=.7;let c=0;e.beginPath();for(let v=0;v<i.length;v++)r.has(v)||(e.rect(n.originX+i[v].x*n.ppm-s,n.originY-i[v].y*n.ppm-l,s*2,l*2),++c===Xo&&(e.fill(),e.beginPath(),c=0));c&&e.fill(),e.globalAlpha=1;const{cw:f,ch:p}=wo(n,s,l),b=new Map,R=v=>Math.round(v*100),le=(v,B,S,k)=>{const q=`${R(v)},${R(B)},${R(S)},${R(k)}`;b.has(q)?b.delete(q):b.set(q,[v,B,S,k])};for(const v of r){const B=n.originX+i[v].x*n.ppm,S=n.originY-i[v].y*n.ppm,k=B-f,q=B+f,L=S-p,ae=S+p;le(k,L,q,L),le(k,ae,q,ae),le(k,L,k,ae),le(q,L,q,ae)}e.strokeStyle=t.text,e.lineWidth=2,e.lineCap="square",e.beginPath();for(const[v,B,S,k]of b.values())e.moveTo(v,B),e.lineTo(S,k);e.stroke(),e.restore()}function wo(e,n,t){const i=g.hoverPoints,o=g.dies;let s=0,l=0;for(let r=0;r<o.length&&(!s||!l);r++){const c=o[r];if(!(c.x==null||c.y==null))for(const f of[Te.get(`${c.x+1},${c.y}`),Te.get(`${c.x},${c.y+1}`)]){if(f===void 0)continue;const p=Math.abs(i[f].x-i[r].x)*e.ppm,b=Math.abs(i[f].y-i[r].y)*e.ppm;p>b?s||=p/2:l||=b/2}}return{cw:s||n,ch:l||t}}function Co(){const e=a.getContext("2d"),n=Math.min(z.x,H.x),t=Math.min(z.y,H.y),i=Math.abs(H.x-z.x),o=Math.abs(H.y-z.y);e.save(),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(n,t,i,o),e.setLineDash([5,3]),e.strokeStyle="rgba(255,255,255,0.9)",e.lineWidth=3,e.strokeRect(n,t,i,o),e.strokeStyle="rgba(0,0,0,0.9)",e.lineWidth=1.5,e.strokeRect(n,t,i,o),e.restore()}function vi(){if(!Nt)return;const e=Ze;Ze=!0,x(),Ze=e}function So(){vi(),a.toBlob(e=>{e&&is(e,Yn(),re.onSaveImage)})}function xi(e){return G?Math.max(G.ppm*lo,Math.min(G.ppm*ao,e)):e}function qe(e,n,t){const i=T??G;if(!i)return;const o=xi(i.ppm*t),s=o/i.ppm,l=e-(e-i.originX)*s,r=n-(n-i.originY)*s,c=(G?.snapDist??1)/(o/(G?.ppm??o));T={originX:l,originY:r,ppm:o,snapDist:c},x()}function te(){return T??G}function wi(e){if(e.ctrlKey||e.metaKey){e.preventDefault();const n=a.getBoundingClientRect(),t=e.deltaY<0?1.12:1/1.12;qe(e.clientX-n.left,e.clientY-n.top,t)}else if(T!==null){e.preventDefault();const n=te(),t=T.snapDist;T={originX:n.originX-e.deltaX,originY:n.originY-e.deltaY,ppm:n.ppm,snapDist:t},x()}}function Mn(e,n,t){return e>=t.x&&e<t.x+t.w&&n>=t.y&&n<t.y+t.h}function Ci(e){if(kt=!1,e.button!==0||(bi(),!te()))return;a.focus({preventScroll:!0}),a.setPointerCapture(e.pointerId);const n=a.getBoundingClientRect(),t=e.clientX-n.left,i=e.clientY-n.top;if(Oe&&d.legendPosition==="floating"&&Mn(t,i,Oe)){_e=!0,st={x:t,y:i},un={...fn};return}if(lt&&U!=="pan"){Ge=!0,Fe=!0,$e={x:t,y:i},Ot={x:te().originX,y:te().originY},a.style.cursor="grabbing";return}if(U==="zoom"||U==="select"){je=!0,z=H={x:t,y:i};return}Fe=!0,$e={x:t,y:i},Ot={x:te().originX,y:te().originY},a.style.cursor="grabbing"}function Si(e){const n=a.getBoundingClientRect(),t=e.clientX-n.left,i=e.clientY-n.top;if(je){H={x:t,y:i},Sn();return}if(_e){const p=t-st.x,b=i-st.y;p*p+b*b>16&&(_e=!1,ot=!0,a.style.cursor="grabbing")}if(ot){fn={x:un.x+(t-st.x),y:un.y+(i-st.y)},Sn();return}if(Fe){const p=te(),b=T?.snapDist??G?.snapDist??1;T={originX:Ot.x+(t-$e.x),originY:Ot.y+(i-$e.y),ppm:p.ppm,snapDist:b},Sn();return}const o=te();if(!o)return;const s=(t-o.originX)/o.ppm,l=(o.originY-i)/o.ppm,c=Dn(s,l,o.snapDist)?.die??null,f=Tt.find(p=>t>=p.x&&t<p.x+p.w&&i>=p.y&&i<p.y+p.h);if(li(f?f.bin:void 0),f){a.style.cursor="pointer",Y&&(Y.textContent=f.label??`Bin ${f.bin}`,Y.style.display="block",ji(Y,a,e.clientX,e.clientY,{followPointer:!0})),vt?.(null,e);return}U==="pan"&&(a.style.cursor=c?"crosshair":"grab"),Y&&(c?(Y.innerHTML=Ao(c,g.plotMode,{testDefs:j,hbinDefs:ne,sbinDefs:ie,fallbackFormat:d.fallbackFormat,aggrMethod:g.aggrMethod,lotSize:g.lotSize,metadataFields:Pe,activeTest:g.activeTest,reticleConfig:Dt}),Y.style.display="block",ji(Y,a,e.clientX,e.clientY,{followPointer:!0})):Y.style.display="none"),vt?.(c,e)}function Mi(e){const n=a.getBoundingClientRect(),t=e.clientX-n.left,i=e.clientY-n.top,o=e.ctrlKey||e.metaKey;if(Y&&(t<0||i<0||t>n.width||i>n.height)&&(Y.style.display="none"),je){je=!1,H={x:t,y:i};const r=t-z.x,c=i-z.y,f=te();if(U==="zoom"){if(r*r+c*c<25)qe(t,i,2);else if(f){const p=Math.min(z.x,H.x),b=Math.max(z.x,H.x),R=Math.min(z.y,H.y),le=Math.max(z.y,H.y),v=b-p,B=le-R;if(v>4&&B>4){const S=a.clientWidth,k=a.clientHeight,q=S/v,L=k/B,ae=Math.min(q,L),pt=xi(f.ppm*ae),Q=pt/f.ppm,Pn=(p+b)/2,Ln=(R+le)/2;T={originX:S/2-(Pn-f.originX)*Q,originY:k/2-(Ln-f.originY)*Q,ppm:pt,snapDist:f.snapDist/Q}}}x(),a.style.cursor="crosshair";return}if(r*r+c*c<25)En(t,i,o,e);else if(f){const p=(Math.min(z.x,H.x)-f.originX)/f.ppm,b=(Math.max(z.x,H.x)-f.originX)/f.ppm,R=(f.originY-Math.max(z.y,H.y))/f.ppm,le=(f.originY-Math.min(z.y,H.y))/f.ppm,v=g.hoverPoints,B=[];for(let S=0;S<v.length;S++)if(v[S].x>=p&&v[S].x<=b&&v[S].y>=R&&v[S].y<=le){const k=g.dies[S];k&&B.push(k)}if(o)for(const S of B){const k=he(S);w.has(k)?w.delete(k):w.add(k)}else w=new Set(B.map(S=>he(S)));We(),me?.(Qe())}x(),a.style.cursor="crosshair";return}if(_e){_e=!1,En(t,i,o,e);return}if(ot){ot=!1,a.style.cursor="grab";return}if(!Fe)return;if(Fe=!1,Ge){Ge=!1,a.style.cursor=lt||U==="pan"?"grab":"crosshair";return}a.style.cursor=U==="pan"?"grab":"crosshair";const s=t-$e.x,l=i-$e.y;s*s+l*l<25&&En(t,i,o,e)}function En(e,n,t,i){for(const r of Tt)if(e>=r.x&&e<r.x+r.w&&n>=r.y&&n<r.y+r.h){We("legend"),typeof r.bin=="number"?F({highlightBin:Qi(d.highlightBin,r.bin,t)}):F({highlightMetadataValue:Qi(d.highlightMetadataValue,r.bin,t)});return}if(Oe&&Mn(e,n,Oe))return;const o=te();if(!o)return;const l=Dn((e-o.originX)/o.ppm,(o.originY-n)/o.ppm,o.snapDist)?.die??null;if(l){to?.(l,i);const r=he(l);t?w.has(r)?w.delete(r):w.add(r):w.size===1&&w.has(r)?w=new Set:w=new Set([r]),We(),me?.(Qe()),x()}else t||(w=new Set,We(),me?.([]),x())}function Qe(){const e=[],n=g.hoverPoints;for(let t=0;t<n.length;t++){const i=g.dies[t];i&&w.has(he(i))&&e.push(i)}return e}function Ei(){Bt&&(Bt.style.display=Et()?"flex":"none",Bt.ariaLabel=w.size>0?"Charts and tables for the selected dies (or right-click)":"Charts and tables for this wafer (or right-click)")}function Bi(){const e={waferLabel:yt(),testDefs:j,isLotStack:C.isLotStack,wafer:C.wafer,passBins:de,ringCount:ze(C,"renderWaferMap"),activeTest:d.plotMode==="value"?d.activeTest:void 0};return w.size>0?ks(Qe(),e):Ds(N,e)}function Bn(e,n,t){ye!==e&&n.click(),kn(t,Z??O??a)}function Mo(e,n){if(!Et())return;const t=d.plotMode==="softBin"?"soft":"hard",i=Vs(d.highlightBin),o=i.length>1&&i.includes(e)?[...i]:[e],s=[{label:yt()??"this wafer",dies:N,wafer:C.wafer,passBins:de,ringCount:ze(C,"renderWaferMap")}],l=Zi(s,t,o,j);if(!l)return;const r={...Mt},c=o.length>1?Zi(s,t,[e],j):null;c&&(r.narrower={label:`Only ${t} bin ${e}`,backLabel:"All filtered bins",source:c,ctx:Mt});const f=a;import("./drilldown.js").then(({openDrilldownMenu:p})=>{Ke||(on=p(n,f,l,r))})}function kn(e,n){if(!Et())return;const t=y.drilldownSourceOverride?.(),i=t?.source??Bi(),o={...Mt,...t?.ctx};if(t?.narrowable){const s=Bi(),l=s.items.reduce((r,c)=>r+c.dies.length,0);o.narrower={label:`Only this wafer \u2014 ${l.toLocaleString()} die${l===1?"":"s"}`,source:s,ctx:Mt}}import("./drilldown.js").then(({openDrilldownMenu:s})=>{Ke||(on=s(e,n,i,o))})}function ki(e){e.stopPropagation();const n=kt;if(kt=!1,!Et()||pe)return;const t=a.getBoundingClientRect();if(!n){const o=e.clientX-t.left,s=e.clientY-t.top,l=Tt.find(f=>o>=f.x&&o<f.x+f.w&&s>=f.y&&s<f.y+f.h);if(l&&typeof l.bin=="number"&&!C.isLotStack&&(d.plotMode===void 0||d.plotMode==="hardBin"||d.plotMode==="softBin")){e.preventDefault(),Mo(l.bin,{x:e.clientX,y:e.clientY});return}if(Oe&&Mn(o,s,Oe))return;const r=te(),c=r?Dn((o-r.originX)/r.ppm,(r.originY-s)/r.ppm,r.snapDist)?.die:void 0;c&&!w.has(he(c))&&(w=new Set([he(c)]),We(),me?.(Qe()),x())}e.preventDefault();const i=n?{x:t.left+t.width/2,y:t.top+t.height/2}:{x:e.clientX,y:e.clientY};kn(i,a)}function Di(){li(void 0),Y&&qt(u),vt?.(null,new MouseEvent("mouseleave")),a.style.cursor=U==="pan"?"grab":"crosshair"}function Pi(){Fe=!1,Ge=!1,je=!1,_e=!1,ot=!1,Y&&qt(u),vt?.(null,new MouseEvent("mouseleave")),a.style.cursor=U==="pan"?"grab":"crosshair",x()}function Dn(e,n,t){const i=g.hoverPoints,o=g.rectangles;for(let c=0;c<o.length;c++){const f=o[c];if(Math.abs(e-f.x)<=f.width/2&&Math.abs(n-f.y)<=f.height/2){const p=g.dies[c];return p?{die:p,index:c}:null}}let s=null,l=-1,r=t*t;for(let c=0;c<i.length;c++){const f=i[c].x-e,p=i[c].y-n,b=f*f+p*p;b<r&&(r=b,s=g.dies[c]??null,l=c)}return s?{die:s,index:l}:null}const Li=new E.ResizeObserver(()=>{G=null,T=null,x()});Li.observe(a),y.height==null&&eo<=0&&An(()=>An(()=>{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 ft=E.matchMedia(`(resolution: ${E.devicePixelRatio}dppx)`);const _t=()=>{ft.removeEventListener("change",_t),ft=E.matchMedia(`(resolution: ${E.devicePixelRatio}dppx)`),ft.addEventListener("change",_t),x()};ft.addEventListener("change",_t);const Ti=E.matchMedia("(prefers-color-scheme: dark)"),Oi=()=>x();Ti.addEventListener("change",Oi);const Fi=()=>{Y&&qt(u)};E.addEventListener("blur",Fi);function Ri(e){if((e.key==="ContextMenu"||e.shiftKey&&e.key==="F10")&&(kt=!0),e.key==="Escape"&&bi(),e.key==="Escape"&&w.size>0&&(w=new Set,We(),me?.([]),x()),(e.key==="e"||e.key==="E")&&jn&&(e.stopPropagation(),(_n??mi)()),(e.ctrlKey||e.metaKey)&&(e.key==="="||e.key==="+"?(e.preventDefault(),qe(a.clientWidth/2,a.clientHeight/2,1.2)):e.key==="-"?(e.preventDefault(),qe(a.clientWidth/2,a.clientHeight/2,1/1.2)):e.key==="0"&&(e.preventDefault(),ut())),!e.ctrlKey&&!e.metaKey&&!e.shiftKey){const t=te();if(t){const i=T?.snapDist??G?.snapDist??1;let o=0,s=0;e.key==="ArrowLeft"&&(o=20,e.preventDefault()),e.key==="ArrowRight"&&(o=-20,e.preventDefault()),e.key==="ArrowUp"&&(s=20,e.preventDefault()),e.key==="ArrowDown"&&(s=-20,e.preventDefault()),(o||s)&&(T={originX:t.originX+o,originY:t.originY+s,ppm:t.ppm,snapDist:i},x())}e.key===" "&&!lt&&(e.preventDefault(),lt=!0,U!=="pan"&&(a.style.cursor="grab"))}}function Wi(e){e.key===" "&&(lt=!1,Ge&&(Fe=!1,Ge=!1),a.style.cursor=U==="pan"?"grab":"crosshair")}a.style.cursor="crosshair",a.setAttribute("tabindex","0"),a.addEventListener("wheel",wi,{passive:!1}),a.addEventListener("pointerdown",Ci),a.addEventListener("pointermove",Si),a.addEventListener("pointerup",Mi),a.addEventListener("pointerleave",Di),a.addEventListener("pointercancel",Pi);const Ai=()=>ut();a.addEventListener("dblclick",Ai),a.addEventListener("keydown",Ri),a.addEventListener("keyup",Wi),a.addEventListener("contextmenu",ki);const Ii=e=>{e.stopPropagation()};a.addEventListener("click",Ii),a.clientWidth,x(),bt?.();function ut(){G=null,T=null,x()}function jt(e){import("./userGuideHtml.js").then(n=>hs({buildWaferMap:No,renderWaferMap,renderWaferGallery:void 0,analyzeWaferMap:Wn},n.USER_GUIDE_HTML,io,P,e))}const Eo=gs(e=>jt(e));return Ye(),Ee&&J?.filter!==void 0&&tn(),{setResult(e){C=e,_=e.wafer,Ct=e.dies,N=en(),ne=e.hbinDefs,ie=e.sbinDefs,j=e.testDefs,Pe=e.metadataFields,ei=e.reticles?.length?e.reticles:void 0,Dt=e.reticleConfig,ti=e.dataAxisFlip,sn=e.isLotStack,ln=e.aggrMethod,an=e.lotSize,co(),at(),x(),Qn(),Z&&oe()},setOptions(e){yi(e)},getOptions(){return{...d}},resetZoom:ut,setSelection(e){w=new Set(e.map(n=>he(n))),x()},getSelectedDies:()=>Qe(),clearSelection(){w=new Set,We(),me?.([]),x()},setFindingsNotice(e){ci=e,Rt()},setStatsSummary(e){pn(e)},closeSummaryPanel(){Yt(!1)},getExportTitle(){return Yn()},getSaveImageHook(){return re.onSaveImage},locateDie:Kt,getSaveTextHook(){return re.onSaveText},drawPendingNow:vi,getBinColors(){return g.binColors},setSummaryVisible(e){pi=e,ct()},setViewControlsVisible(e){K&&(K.style.display=e?"flex":"none")},setExpandVisible(e){Lt(e)},openUserGuide:()=>jt(),setInsightsOpen(e){Le(e)},destroy(){Ke=!0,Eo(),nn.flush();for(const e of dt.values())e.cancel();dt.clear(),Ae?.close(),gi?.()?.remove(),mn&&u.removeEventListener("click",mn,!0),a.removeEventListener("wheel",wi),a.removeEventListener("pointerdown",Ci),a.removeEventListener("pointermove",Si),a.removeEventListener("pointerup",Mi),a.removeEventListener("pointerleave",Di),a.removeEventListener("pointercancel",Pi),a.removeEventListener("dblclick",Ai),a.removeEventListener("keydown",Ri),a.removeEventListener("keyup",Wi),a.removeEventListener("contextmenu",ki),on?.(),a.removeEventListener("click",Ii),Li.disconnect(),Cn?.disconnect(),ft.removeEventListener("change",_t),Ti.removeEventListener("change",Oi),E.removeEventListener("blur",Fi),ro(),Y&&qt(u),se?.remove(),Re&&(Re.parentElement?.insertBefore(M,Re),Re.remove()),be&&(be.parentElement?.insertBefore(M,be),be.remove()),M.remove(),a.style.cursor="",$?.destroy(),ee?.destroy(),He.remove()}}}
|
|
1
|
+
import{createViewSwitch as Wo}from"./viewSwitch.js";import{createSummaryToggle as Io}from"./summaryToggle.js";import{buildView as Vo,buildHoverText as Yo,findTestDef as Zt,resolveTestNumber as Fn,buildMapTitle as zo}from"../renderer/buildView.js";import{drawMapCanvas as Ho,BIN_LEGEND_W as zi,BIN_LEGEND_W_COMPACT as _o,BIN_LEGEND_ADAPT_COMPACT as Xo,BIN_LEGEND_ADAPT_FLOATING as Ko,PATH_SHAPES as No}from"./toCanvas.js";import{buildWaferMap as jo,computeCoverage as Hi,computeYield as _i,defaultBinMode as $o,getTestPassStatus as Go,isParametricTest as Rn,isBuiltMap as An}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Wn}from"../stats/analyzeWaferMap.js";import{SHADOW as Uo,LEADING as Xi,wireControlHover as Ki,SPACE as I,EDGE_GUTTER as Zo,RADIUS as Ni,FONT as qt,CLR as A,applyOverlayZ as qo,getTooltip as ji,hideTooltip as Qt,positionTooltip as $i,createToolbarHelpers as Qo,buildModeMenuEl as Jo,openReparentedModal as es,makePaletteBtn as ts,makeLogScaleBtn as ns,makeLegendStyleBtn as is,makeOverlaysBtn as os,makeOrientationBtn as ss,menuLayerFor as Gi,saveImageBlob as ls,markMenuTrigger as mt,wireMenuA11y as Ui,wireExpandToggle as as,nextFrame as In,requestedPassFailDisplay as rs,overlayMenuRows as ds,anyOverlayActive as cs,openCompactDiagnostics as fs,roomForPanel as us,logWmapVersionOnce as ps,buildDataModeEntries as hs,metadataKeyHasData as gs,metadataModeEntry as Zi}from"./toolbar.js";import{openUserGuideWindow as ms,registerGuideOpener as ys}from"./guideWindow.js";import{waferIdentityLabel as bs}from"../core/waferLabel.js";import{metadataDisplayValue as vs}from"../core/metadata.js";import{withExportContext as ws}from"./exportName.js";import{testValueNotice as xs}from"./testValueOffer.js";import{axisPrefsFromOptions as qi,optionsFromAxisPrefs as Cs,CHART_PREF_KEYS as Vn}from"./chartPrefs.js";import{createSummaryPanelEl as Yn,wrapWithSummaryPanel as zn,renderWaferSummaryContentSteps as Ss}from"./summaryPanel.js";import{runChunked as Ms}from"./chunked.js";import{collectWarnings as Es,buildWarningsMenuEl as Bs,severityOf as ks}from"./warnings.js";import{plotStoreFor as Ds}from"./plotStore.js";import{selectionPopulation as Ps,waferPopulation as Ts}from"./chartPopulation.js";import{sourceFromBins as Qi}from"./plotItems.js";import{createIdentityHeader as Ls,collapsedLabel as Hn}from"./identityHeader.js";import{getDieKey as he,hasPosition as Ji,isPositionedDie as Os}from"../core/dies.js";import{bandButton as Fs}from"./filterButton.js";import{buildDieListSection as Rs}from"./dieList.js";import{buildMaplessSummary as As}from"./maplessSummary.js";import{resolveBinColors as Ws,binColorWarning as Is}from"../renderer/binColors.js";import{isPassBin as Vs,requirePassBins as Ys}from"../core/passBins.js";import{PAT_MODE_FIELD as zs,PAT_MODE_KEY as Hs,isPatMode as eo,patModeOffered as _s,withPatField as Xs,withPatVerdicts as Ks}from"./patMode.js";import{requireRingCount as Ve}from"../core/ringCount.js";import{asList as Ns,toggleHighlight as to}from"../core/utils.js";import{buildCompactMap as js,compactLayoutOffered as $s}from"../core/compact.js";const Gs={binColorScheme:!0,valueColorScheme:!0,reverseValueScheme:!0,useDefinedBinColors:!0,showDieLabels:!0,showRingBoundaries:!0,showQuadrantBoundaries:!0,showReticle:!0,showXYIndicator:!0,showAxes:!0,legendPosition:!0,colorbarRangeMode:!0,markFailingDies:!0,fallbackFormat:!0,chartAxisIncludesLimits:!0,chartClipOutliers:!0,chartLimitLines:!0};export const WAFER_PREFERENCE_KEYS=Object.keys(Gs);const no=new Set(WAFER_PREFERENCE_KEYS);export const COLOR_KEYS=["binColorScheme","valueColorScheme","reverseValueScheme","useDefinedBinColors","binColors"];export function classifyChanged(P){const h=P.some(u=>no.has(u)),y=P.some(u=>!no.has(u));return h&&y?"mixed":h?"preference":"state"}export function findingBin(P,h,y){const{kind:u,bin:B}=P.variable;if(!(u!=="hardBin"&&u!=="softBin"||B===void 0))return h&&Vs(u,B,h,y)?void 0:B}export function findingPlotMode(P,h,y){const{kind:u}=P.variable;return u==="hardBin"||u==="softBin"?u:h==="hardBin"||h==="softBin"?h:y?"hardBin":"softBin"}export function toPublicViewOptions(P){const{metadataValueOrder:h,binColors:y,lotSize:u,compactMap:B,...Je}=P;return Je}export function renderWaferMap(P,h,y={}){return renderWaferMapCard(P,h,y)}export function renderWaferMapCard(P,h,y={}){ps();const u=P.ownerDocument,B=u.defaultView??window,Je=()=>C.label,yt=()=>bs({label:Je(),wafer:j}),de=ws(()=>{const e=vs(j.metadata?.lot);return{prefix:y.downloadFilename,lots:e!==void 0?[e]:[],...C.isLotStack?{stackedWafers:m?.lotSize??!0}:{wafer:yt()}}},y.onSaveImage,y.onSaveText);function _n(){const e=m.plotMode==="softBin"||m.plotMode==="stackedSoftBins"?oe:ie,{primary:n,secondary:t}=zo(m,d.fallbackFormat,e);return[n,C.isLotStack?"":t].filter(Boolean).join(" ")||"wafer-map"}B.getComputedStyle(P).position==="static"&&(P.style.position="relative");const io=P.clientHeight;y.height!=null&&(P.style.height=typeof y.height=="number"?`${y.height}px`:y.height);const Jt=h.dataCoverage?h.dataCoverage.unpositionedDies:h.dies.filter(e=>!Ji(e)).length,et=(h.dataCoverage?h.dataCoverage.totalDies:h.dies.length-Jt)===0&&Jt>0,Ye=u.createElement("div");Object.assign(Ye.style,{display:"flex",flexDirection:"column",width:"100%",height:"100%"}),P.appendChild(Ye);const Me=u.createElement("div");Object.assign(Me.style,{position:"relative",width:"100%",flex:"1 1 auto",minHeight:"0"});const ge=y.chromeInset??Zo,V=u.createElement("div");Object.assign(V.style,{display:"flex",alignItems:"stretch",gap:I.sm,background:A.canvasBg,paddingBottom:I.lg,paddingTop:ge,paddingLeft:ge,paddingRight:ge,flexShrink:"0",minWidth:"0"}),Ye.appendChild(V),Ye.appendChild(Me);function ze(){const e=[...V.children].some(n=>n.style.display!=="none");V.style.display=e?"flex":"none"}const M=u.createElement("div");Object.assign(M.style,{position:"relative",width:"100%",height:"100%"});const a=u.createElement("canvas");Object.assign(a.style,{width:"100%",height:"100%",display:"block"}),M.appendChild(a),Me.appendChild(M);let bt=null;if(Jt>0){let t=function(){if(n){const l=Rs(e,h.testDefs,{...y.dieList,onSaveText:de.onSaveText,waferMetadata:j.metadata,metadataFields:Ke,attributes:y.attributes,ownerDocument:u});if(l)return l}const o=Zt(h.testDefs,d.activeTest??0),s=Rn(o)?d.logScale??o?.logScale??!1:!1;return As(e,h.testDefs,{plotMode:d.plotMode??"hardBin",activeTest:d.activeTest,hbinDefs:ie,sbinDefs:oe,binColors:m.binColors,valueColorScheme:d.valueColorScheme,reverseValueScheme:d.reverseValueScheme,logScale:s,colorbarRangeMode:d.colorbarRangeMode,valueRangeDies:h.dies})},i=function(o){const s=u.createElement("button");return s.type="button",Ki(s),Object.assign(s.style,{fontSize:qt.body,padding:`${I.xxs} ${I.sm}`,borderRadius:Ni.control,flexShrink:"0",border:`1px solid ${A.menuBorder}`,background:A.menuBg,color:A.text,cursor:"pointer"}),s.textContent=n?"View chart":"View die list",s.addEventListener("click",l=>{l.stopPropagation(),n=!n,s.textContent=n?"View chart":"View die list",o()}),s};const e=h.dies.filter(o=>!Ji(o));let n=!1;if(et){const o=u.createElement("div");Object.assign(o.style,{position:"absolute",inset:"0",background:A.panelBg,padding:I.xl,boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",gap:I.md,zIndex:"1"});const s=u.createElement("div");Object.assign(s.style,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:I.md});const l=u.createElement("span");Object.assign(l.style,{fontSize:qt.body,color:A.label,lineHeight:Xi.base}),l.textContent="No die position data for this wafer.",s.appendChild(l);const r=u.createElement("div");Object.assign(r.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),s.appendChild(i(()=>r.replaceChildren(t()))),o.appendChild(s),o.appendChild(r),M.appendChild(o),bt=()=>{n||r.replaceChildren(t())}}else{const o=u.createElement("div");Object.assign(o.style,{position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"3",background:A.panelBg,borderTop:`1px solid ${A.menuBorder}`,fontSize:qt.body,color:A.text,cursor:"pointer",padding:`${I.xs} ${I.md}`,display:"flex",alignItems:"center",justifyContent:"space-between",gap:I.md}),Ki(o,"bare");const s=u.createElement("span");s.textContent=`+${e.length} ${e.length===1?"die":"dies"} without position data`,o.appendChild(s);const l=u.createElement("span");l.textContent="\u25BE",Object.assign(l.style,{fontSize:qt.body,lineHeight:Xi.none,color:A.label,flexShrink:"0"}),o.appendChild(l),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`${e.length} dies without position data. Click to view.`);let r=null,c=null;as(o,f=>{if(l.textContent=f?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(f)),f){r=u.createElement("div");const p=o.getBoundingClientRect().height||28;Object.assign(r.style,{position:"absolute",left:"0",right:"0",bottom:`${p}px`,top:"20%",zIndex:"2",background:A.panelBg,borderTop:`1px solid ${A.menuBorder}`,padding:I.md,boxSizing:"border-box",display:"flex",flexDirection:"column",gap:I.md}),r.addEventListener("click",R=>R.stopPropagation());const b=u.createElement("div");Object.assign(b.style,{display:"flex",justifyContent:"flex-end"}),b.appendChild(i(()=>{c&&c.replaceChildren(t())})),r.appendChild(b),c=u.createElement("div"),Object.assign(c.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),c.appendChild(t()),r.appendChild(c),M.appendChild(r)}else r&&(r.remove(),r=null,c=null)}),M.appendChild(o),bt=()=>{c&&!n&&c.replaceChildren(t())}}}const{onHover:vt,onClick:oo,onSelect:me,onViewOptionsChange:Xn,showTooltip:so=!0,showToolbar:Ee=!0,showIdentity:Kn=!0,summaryPanel:tt,showHelpButton:Nn=!1,userGuideExtension:lo,onExpand:jn,showExpandButton:$n=!0,zIndex:ao,insights:J,warnings:Gn,viewOptions:ro={},...He}=y,Be=J?.enabled??Ee;let nt=null,_e=null;Be&&(nt=Wo(u,"Map","wafer",e=>Ce(e)),Ee||(nt.el.style.marginLeft="auto"),V.appendChild(nt.el)),Be&&(_e=Fs(u,"Filter\u2026","wmapMapFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>{nn().then(e=>e.openEditor(_e??P,[St()]))}),_e.style.order="1",V.appendChild(_e));const co=.4,fo=20,ne=[...Ys(h,"renderWaferMap")],Un=Gn?.display??!0,uo=qo(ao);let ce=y.statsSummary,ke=!1,wt;const fe=()=>ke?wt:ce;let we=[],Zn=!1,xt=null,qn=!1;function en(){const e=Es({result:h,statsSummary:fe(),extra:xt?[xt]:[]}),n=e.length!==we.length||e.some((t,i)=>t.code!==we[i]?.code||t.message!==we[i]?.message);we=e,(n||!Zn)&&(Zn=!0,Gn?.onWarning?.(e))}en();let C=h,j=h.wafer,Ct=h.dies,Y=h.dies,xe=null,Qn=null,De=null;const St=()=>({dies:Ct,wafer:j,label:Je()??"Wafer",identity:yt(),waferIndex:0,passBins:ne,testDefs:K,statsSummary:ce});function tn(){const e=xe?.get();if(wt=void 0,!xe||!e||e.off)return ke=!1,Ct;const n=xe.mark([St()]);ke=n.narrowing;const t=n.items[0].dies;if(ke&&ce&&An(C)){const i=t.filter(o=>!o.filteredOut);try{wt=i.length===0?void 0:Wn({...C,dies:i,yield:_i(t,ne,C.yield?.yieldPercentGross!=null?"denominator-only":"exclude"),dataCoverage:Hi(i)},ce.analysisOptions)}catch{wt=void 0}}return t}function Jn(){if(!xe||!De)return;const e=[St()];De.refresh(xe.keep(e).result,e),De.el.style.display=xe.get()&&!pe?"":"none"}function ei(){Y=tn(),Jn(),at(),w(),gn(ce)}function nn(){return Qn??=import("./pageFilter.js").then(({createPageFilter:e})=>{const n=e({doc:u,initial:J?.filter,onChange:J?.onFilterChange,savedFilters:J?.savedFilters,onSavedFiltersChange:J?.onSavedFiltersChange,pickFiltersFile:J?.onPickFiltersFile,onSaveText:y.onSaveText,attributes:y.attributes,getRingCount:()=>Ve(C,"renderWaferMap")});return xe=n,De=n.createBand(()=>[St()],{marginLeft:ge,marginRight:ge,marginBottom:I.lg}),Ye.insertBefore(De.el,Me),n.subscribe(()=>{Xe||ei()}),n.get()&&!Xe&&ei(),n}),Qn}let x=new Set,Pe=null;const on=J?.plotStore??Ds(J),Mt={plots:on,getBinColors:()=>m.binColors,attributes:y.attributes,onSaveImage:de.onSaveImage,onSaveText:de.onSaveText,onLocateDie:e=>Kt(e)},Et=()=>!et;let sn=null,Bt=null,kt=!1,Xe=!1,ie=h.hbinDefs,oe=h.sbinDefs,K=h.testDefs,Ke=h.metadataFields,ti=h.reticles?.length?h.reticles:void 0,Dt=h.reticleConfig,ni=h.dataAxisFlip,ln=h.isLotStack??!1,an=h.aggrMethod,rn=h.lotSize,ee=null,ue=null,Pt=null;function Tt(e){Pt&&(Pt.style.display=e?"flex":"none",Ue?.())}Kn&&(ee=Ls(Hn(j.metadata??{},it())??"",j.metadata,{lotStack:it(),ownerDocument:u,attributes:y.attributes}),M.appendChild(ee.metaPanel),ee.metaPanel.style.visibility="visible",ee.isEmpty()||(ue=ii(ee.wrap),V.insertBefore(ue,V.firstChild),ze()));function ii(e){const n=u.createElement("div");return Object.assign(n.style,{display:"flex",alignItems:"center",padding:`${I.sm} ${I.lg}`,flex:"1 1 auto",minWidth:"0",overflow:"hidden",gap:I.sm}),Object.assign(e.style,{flex:"1",minWidth:"0"}),n.appendChild(e),n}function it(){return ln?{lotSize:rn??1,aggrMethod:an}:void 0}function po(){if(!ee)return;ee.update(Hn(j.metadata??{},it())??"",j.metadata,it());const e=ue?.isConnected??!1,n=!ee.isEmpty();!n&&e?(ue.remove(),ue=null):n&&!e&&(ue=ii(ee.wrap),ue.style.display="",V.insertBefore(ue,V.firstChild),ze())}const ho=[...ie??[],...oe??[]].some(e=>e.color);let d={plotMode:$o([h.dies]),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,showReticle:!1,showXYIndicator:!1,compact:!1,rotation:0,flipX:!1,flipY:!1,legendPosition:"default",...ro},$=null,pe=!1,oi=null;function si(){return Be?$?Promise.resolve($):(oi??=Promise.all([import("./insightsTab.js"),nn()]).then(([{createInsightsTab:e},n])=>($=e({pageFilter:n,showFilterButton:!1,initialAxisPrefs:qi(d),onAxisPrefsChange:t=>{d={...d,...Cs(t)};const i=[...Vn];Xn?.(d,i,classifyChanged(i))},attributes:y.attributes,getItems:()=>[{wafer:j,dies:Ct,hbinDefs:ie,sbinDefs:oe,testDefs:K,label:Je(),passBins:ne,ringCount:Ve(C,"renderWaferMap"),statsSummary:ce}],getBinColors:()=>m.binColors,getRingCount:()=>Ve(C,"renderWaferMap"),onSaveImage:de.onSaveImage,onSaveText:de.onSaveText,defaultView:J?.defaultView,plotStore:on,onPickPlotsFile:J?.onPickPlotsFile,showPatMap:()=>{Ce(!1),L({plotMode:"metadata",activeTest:void 0,activeMetadataKey:Hs,passFailDisplay:"off"})},showOnMap:t=>{if(Ce(!1),t.kind==="test")ui(t.testNumber);else{const i=fe()?.findings.find(o=>o.id===t.id);i&&pi(i)}fe()&&Ht(!0)},showMetadataStrip:!1,contentInset:ge,onOpenGuide:Nn&&!Ee?()=>jt():void 0,focusTest:t=>{L({plotMode:"value",activeTest:t,highlightBin:void 0}),Ce(!1)},locateDie:t=>{Ce(!1),Kt(t)},ownerDocument:u}),Object.assign($.el.style,{position:"absolute",inset:"0",background:A.canvasBg,overflowY:"auto",paddingTop:"0"}),$.el.style.display="none",Me.appendChild($.el),$)),oi):Promise.resolve(null)}let li=0;const dn=["wheel","touchstart","pointerdown","keydown"];function go(e,n){if(n<=0)return;let t=!1;const i=[],o=()=>{t=!0;for(const l of i)B.clearTimeout(l);i.length=0;for(const l of dn)e.removeEventListener(l,o)},s=()=>t||!pe?!0:(e.scrollTop=n,e.scrollTop>=n);if(!s()){for(const l of dn)e.addEventListener(l,o,{passive:!0,once:!0});for(const l of[0,50,150,300,600])i.push(B.setTimeout(()=>{s()},l));i.push(B.setTimeout(()=>{for(const l of dn)e.removeEventListener(l,o)},700))}}function cn(){for(const e of[Z,F])e&&(e.style.visibility=pe?"hidden":"")}function Ce(e){if(!Be)return;const n=pe;pe=e,nt?.setInsightsOpen(e),De&&(De.el.style.display=xe?.get()&&!e?"":"none"),$&&!e&&n&&(li=$.el.scrollTop),$&&($.el.style.display=e?"flex":"none"),M.style.visibility=e?"hidden":"",cn(),X&&(X.style.display=e||et?"none":"flex"),W&&(W.style.display=e?"none":"flex"),Tt(!Ae),le&&(le.style.display="flex"),ue&&(ue.style.display=""),ze(),Ue?.(),ee&&e&&ee.collapse(),ct(),e&&si().then(t=>{!t||!pe||(t.el.style.display="flex",t.render(),go(t.el,li))})}Be&&J?.defaultOpen&&queueMicrotask(()=>Ce(!0));let m,Te,G=null,O=null,Lt=[],fn;function ai(e){fn!==e&&(fn=e,w())}let Le=null,un=He.legendOffset??{x:0,y:0},ot=!1,Ne=!1,st={x:0,y:0},pn={x:0,y:0},Oe=!1,je=!1,U="select",$e={x:0,y:0},Ot={x:0,y:0},z={x:0,y:0},H={x:0,y:0},lt=!1,Ge=!1;const hn=()=>eo(d)?Xs(Ke):Ke;function at(){const e=d,i=(eo(e)?Ks(Y,K,ne):Y).filter(Os);m=Vo(j,i,{compact:d.compact?d.compactMap??js(i):void 0,plotMode:e.plotMode,binColorScheme:e.binColorScheme,valueColorScheme:e.valueColorScheme,reverseValueScheme:e.reverseValueScheme,useDefinedBinColors:e.useDefinedBinColors,binColors:e.binColors??Ws(Y,{passBins:ne,binColorScheme:e.binColorScheme,hbinDefs:ie,sbinDefs:oe,useDefinedBinColors:e.useDefinedBinColors}),passBins:ne,showDieLabels:e.showDieLabels,showRingBoundaries:e.showRingBoundaries,showQuadrantBoundaries:e.showQuadrantBoundaries,showReticle:e.showReticle,showXYIndicator:e.showXYIndicator,reticles:ti,ringCount:Ve(C,"renderWaferMap"),highlightBin:e.highlightBin,highlightMetadataValue:e.highlightMetadataValue,activeTest:e.activeTest,activeMetadataKey:e.activeMetadataKey,testDefs:K,valueRange:e.valueRange,metadataValueOrder:e.metadataValueOrder,logScale:e.logScale,isLotStack:ln,aggregationMethod:an??e.aggregationMethod,lotSize:rn??e.lotSize,dataAxisFlip:ni,colorbarRangeMode:e.colorbarRangeMode,passFailDisplay:e.passFailDisplay,fallbackFormat:e.fallbackFormat,interactiveTransform:{rotation:e.rotation??0,flipX:e.flipX??!1,flipY:e.flipY??!1}},{hbinDefs:ie,sbinDefs:oe,metadataFields:hn()}),Te=void 0;const o=e.binColors?null:Is(m.binColors,m.plotMode);o?.message!==xt?.message&&(xt=o,en(),qn&&yn())}at();function ri(){return d.showAxes??He.showAxes??O!==null}function mo(){return $s(Y,[Dt])}let Z=null,Fe=null,ye=null,Se=null,Ft=null;function di(){ye===null&&Se===null&&(Ft={plotMode:d.plotMode,activeTest:d.activeTest})}function ci(){L({...Ft??{},highlightBin:void 0}),Ft=null}function gn(e){const n=e!==ce;if(ce=e,n&&ke&&(Y=tn(),at(),w()),en(),yn(),Z)se();else if(F)Wt();else if(e&&!tt?.placement){const t=tt?.defaultOpen??!Ee;F=Yn("right",ge,u,Dn),F.style.display=t?"block":"none";const i=M.parentElement,o=M.nextSibling;be=zn(M,F,"right"),i?.insertBefore(be,o),Wt(),cn()}ct()}function Rt(){Z?se():F&&Wt()}let fi=y.findingsNotice,rt=!1;const yo=()=>fi??(y.testValueOffer?y.testValueOffer():void 0)??(!y.testValueOffer&&An(C)?xs(fe()?.stats.testValueAnalysis,1,rt,bo):void 0);function bo(){const e=ce,n=C;if(rt||!e||!An(n))return;rt=!0,Rt();const t=u.defaultView?.requestAnimationFrame?.bind(u.defaultView)??(s=>setTimeout(s,16));let i=!1;const o=()=>{if(i||Xe)return;i=!0;let s;try{s=Wn(n,{...e.analysisOptions,enableTestValueAnalysis:!0})}catch(l){throw rt=!1,Rt(),l}if(rt=!1,C!==n||ce!==e){Rt();return}gn(s),y.onStatsSummaryChange?.(s)};t(()=>t(o)),setTimeout(o,120)}let vo={},F=null,be=null;function wo(e){const{kind:n,index:t}=e.variable;if(n==="test")L({plotMode:"value",activeTest:t??0,highlightBin:void 0});else{const o=Y.some(s=>s.hbin!=null);L({plotMode:findingPlotMode(e,d.plotMode,o),highlightBin:findingBin(e,ne,o)})}const i=e.highlight;(i.kind==="bin"||i.kind==="region"||i.kind==="dies")&&zt(i.dieKeys)}const dt=new Map,mn=new WeakSet;function At(e){if(dt.get(e)?.cancel(),dt.delete(e),e.style.display==="none"){mn.add(e);return}mn.delete(e);const n=Ms(Ss(e,{wafer:j,dies:Y,yieldSummary:ke?_i(Y,ne,C.yield?.yieldPercentGross!=null?"denominator-only":"exclude"):C.yield,dataCoverage:ke?Hi(Y.filter(t=>!t.filteredOut)):C.dataCoverage,hbinDefs:ie,sbinDefs:oe,testDefs:K,statsSummary:fe(),warnings:Un?we:[],passBins:ne,ringCount:Ve(C,"renderWaferMap"),binColors:m.binColors,plotMode:d.plotMode??"hardBin",metadataShownElsewhere:Kn,fallbackFormat:d.fallbackFormat,activeFindingId:ye,findingsFilter:vo,findingsNotice:yo(),onFindingsFilterChange:se,onSaveText:de.onSaveText,metadataFields:Ke,dieListOptions:y.dieList,onLocateDie:t=>Kt(t),attributes:y.attributes,onClose:Ee&&fe()?()=>Ht(!1):void 0,activeTest:Se,onTestClick:t=>{Se===t?(Se=null,zt([]),ci(),se()):ui(t)},onFindingClick:(t,i)=>{ye===t.id?(ye=null,zt([]),ci(),se()):pi(t)},onShowChart:Be?t=>{Ce(!0),si().then(i=>i?.showWorthCard(t))}:void 0}));n.done||dt.set(e,n)}function ui(e){di(),ye=null,Se=e,L({plotMode:"value",activeTest:e,highlightBin:void 0}),zt(fe()?.stats.testFailures?.[e]?.dieKeys),se()}function pi(e){di(),Se=null,ye=e.id,wo(e),se()}function se(){Z?At(Z):F&&At(F)}function Wt(){F&&At(F)}if(tt?.placement){const e=tt.placement;Z=Yn(e,ge,u,Dn);const n=M.parentElement,t=M.nextSibling;Fe=zn(M,Z,e),n?.insertBefore(Fe,t),se()}else if(fe()){const e=tt?.defaultOpen??!Ee;F=Yn("right",ge,u,Dn),F.style.display=e?"block":"none";const n=M.parentElement,t=M.nextSibling;be=zn(M,F,"right"),n?.insertBefore(be,t),Wt()}cn();const _=so?ji(u):null;let le=null,N=null,Ue=null,X=null,W=null,It=null,Vt=null,hi=!0,gi=null,ve=null,Yt=null;qn=!0;function yn(){if(!ve||!Yt)return;const e=we.length,n=e>0;if(ve.style.display=n?"flex":"none",Yt.style.display=n?"":"none",Ue?.(),!n)return;const t=ks(we[0]),i=`${e} data ${e===1?"warning":"warnings"}`;ve.style.color=t==="error"?A.errText:A.warnText,ve.ariaLabel=t==="error"?`${i} \u2014 the map may be positionally wrong`:i}let bn=null,mi=null,vn=null,wn=null,xn=null,Cn=null;function Re(e="selection"){ye===null&&Se===null||(ye=null,Se=null,Ft=null,e==="selection"?L({highlightBin:void 0}):(x=new Set,me?.([])),se())}function zt(e){x=new Set(e??[]),me&&me(Qe()),w()}function ct(){if(!Vt)return;Ue?.();const e=Z??F;Vt.sync({visible:hi&&!!fe()&&!!e&&!pe,open:!!e&&e.style.display!=="none",notable:!!fe()?.hasNotableFindings})}function Ht(e){const n=Z??F;if(!n)return;const t=n.style.display!=="none",i=M.getBoundingClientRect().width;if(n.style.display=e?"block":"none",e!==t){const o=i-M.getBoundingClientRect().width;(y.onSummaryPanelChange??_t)?.(e,e?o:0)}e&&mn.has(n)&&At(n),ct()}if(Ee){let R=function(T){U=T,i(v,T==="zoom"),i(q,T==="pan"),It&&i(It,T==="select"),a.style.cursor=T==="pan"?"grab":"crosshair"};le=u.createElement("div"),le.dataset.wmapToolbar="single",Object.assign(le.style,{marginLeft:"auto",flexShrink:"0",display:"flex",flexDirection:"row",alignItems:"center",flexWrap:"wrap-reverse",justifyContent:"flex-end",maxWidth:"100%",background:A.menuBg,border:`1px solid ${A.menuBorder}`,borderRadius:Ni.control,boxShadow:Uo.panel,pointerEvents:"auto"});const e=ji(u),n=Qo(e),{makeBtn:t,setActive:i,makeSep:o,syncSeparators:s,syncToolbarVisible:l,makeMenuRow:r,makeMenuSection:c,closeOpenMenu:f,getOpenMenu:p,setOpenMenu:b}=n;Ue=()=>{N&&s(N),le&&l(le,"flex"),ze()},bn=f,mi=p,u.addEventListener("click",f,!0),X=u.createElement("div"),Object.assign(X.style,{display:et?"none":"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),le.appendChild(X);const ae=t("download","Download PNG",Bo);X.appendChild(ae),X.appendChild(o());const v=t("zoomMode","Zoom (drag to zoom region)",()=>R("zoom")),k=t("zoomIn","Zoom in",()=>qe(a.clientWidth/2,a.clientHeight/2,1.2)),S=t("zoomOut","Zoom out",()=>qe(a.clientWidth/2,a.clientHeight/2,1/1.2)),D=t("reset","Reset zoom (double-click)",()=>ut());X.appendChild(v),X.appendChild(k),X.appendChild(S),X.appendChild(D),X.appendChild(o());const q=t("pan","Pan (drag to move)",()=>R("pan"));X.appendChild(q),It=t("boxSelect","Select (drag to select dies)",()=>R("select")),X.appendChild(It);{const T=t("drilldown","Chart this wafer",()=>{const re=T.getBoundingClientRect();Pn({x:re.left,y:re.bottom+4},T)});T.setAttribute("aria-haspopup","menu"),Bt=T,Bi(),X.appendChild(T)}R(U);{let T=function(g){return g.plotMode!==(d.plotMode??"hardBin")?!1:g.plotMode==="value"?(d.activeTest??0)===(g.activeTest??0):g.plotMode==="metadata"?d.activeMetadataKey===g.activeMetadataKey:!0},re=function(g,E){g.activeTest!==void 0?L({plotMode:g.plotMode,activeTest:g.activeTest,activeMetadataKey:void 0,logScale:g.logScale}):g.activeMetadataKey!==void 0?L({plotMode:g.plotMode,activeTest:void 0,activeMetadataKey:g.activeMetadataKey,passFailDisplay:"off"}):L({plotMode:g.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),E.remove(),b(null),mt(Q,!1)};N=u.createElement("div"),Object.assign(N.style,{display:"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),le.appendChild(N),W=u.createElement("div"),Object.assign(W.style,{display:"flex",alignItems:"center",gap:"0"}),N.appendChild(W),W.appendChild(o());const pt=()=>{const g=p();g&&(g.remove(),b(null)),mt(Q,!1)},Q=t("mode","Plot mode",()=>{if(p()){pt();return}const g=Y,E=m.testDefs,{testEntries:Gt,binEntries:We,stackedEntries:ht}=hs(g,E,{includeStacked:m.isLotStack}),Ut=(Ke??[]).filter(Ie=>gs(g,Ie.key)).map(Zi);_s([{dies:g,testDefs:E}])&&Ut.push(Zi(zs));const gt=Jo(Q.getBoundingClientRect(),Gt,We,ht,T,re,{makeMenuRow:r,makeMenuSection:c},d.plotMode??"hardBin",Q.ownerDocument.defaultView??window,Ut);Gi(Q).appendChild(gt),b(gt),mt(Q,!0),Ui(gt,Q,pt)});mt(Q,!1);const{btn:Ln,sync:On}=ts(n,()=>({...d,plotMode:d.plotMode??"hardBin"}),()=>ho,L);wn=On,wn();const Po=os(n,()=>{const g=!!m.hasReticle,E=(d.plotMode??"hardBin")==="value",{testNumber:Gt}=Fn(d.activeTest??0,m.testDefs),We=Zt(m.testDefs,Gt),ht=E&&We!==void 0&&!Rn(We),Ut=E&&!ht&&(We?.limitLow!==void 0||We?.limitHigh!==void 0),gt=E&&!ht&&m.dies.some(Ie=>Go(Ie,Gt,We)!==void 0);return ds({...d,showAxes:ri()},g,{functionalActive:ht,hasLimits:Ut,hasRecorded:gt,binMode:(d.plotMode??"hardBin")==="hardBin"||(d.plotMode??"hardBin")==="softBin"},Ie=>L(Ie),{on:!!d.compact,offered:mo(),onChange:Ie=>L({compact:Ie}),onDiagnostics:()=>fs(Y,[Dt],{anchor:a,onSaveText:de.onSaveText})})},()=>cs(d)),{btn:To,sync:Lo}=is(n,()=>d,g=>L({legendPosition:g}));vn=Lo,vn();const Yi=()=>{const{testNumber:g}=Fn(d.activeTest??0,K),E=Zt(K,g);return E!==void 0&&!Rn(E)},{btn:Oo,sync:Fo}=ns(n,()=>({...d,functionalActive:Yi()}),g=>L(g));xn=Fo,xn();const Ro=()=>{const{testNumber:g}=Fn(d.activeTest??0,K),E=Zt(K,g);return E!==void 0&&(E.limitLow!==void 0||E.limitHigh!==void 0)},$t=t("specRange","Colorbar range: test limits",()=>{const g=d.colorbarRangeMode==="data"?"spec":"data";L({colorbarRangeMode:g})});Cn=()=>{const g=d.plotMode==="value"&&Ro()&&rs(d)==="off"&&!Yi();$t.style.display=g?"":"none";const E=(d.colorbarRangeMode??"spec")==="spec";i($t,E),$t.ariaLabel=E?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"},Cn();const Ao=ss(n,()=>d,g=>L(g));W.appendChild(Q),W.appendChild(Ln),W.appendChild(Oo),W.appendChild($t),et||(W.appendChild(o()),W.appendChild(Po),W.appendChild(o()),W.appendChild(To),W.appendChild(o()),W.appendChild(Ao)),Vt=Io(u,()=>{const g=Z??F;g&&Ht(g.style.display==="none")}),V.insertBefore(Vt.el,nt?.el??null),ct(),Un&&(Yt=o(),ve=t("warning","Data warnings",()=>{const g=p();if(f(new MouseEvent("click")),g)return;const E=Bs(ve.getBoundingClientRect(),we,B);Gi(Me).appendChild(E),b(E),Ui(E,ve,()=>f(new MouseEvent("click")))}),mt(ve,!1),N.appendChild(Yt),N.appendChild(ve),yn()),$n&&(N.appendChild(o()),Pt=t("expand","Expand (E)",jn??yi),N.appendChild(Pt)),Nn&&(N.appendChild(o()),gi=t("help","User guide",()=>jt()),N.appendChild(gi)),Ue?.()}V.appendChild(le),_e&&V.appendChild(_e),ze()}let Ae=null,_t=null;function yi(){Ae&&(Ae.close(),Ae=null);const e=Me;e.style.flex="1",e.style.minWidth="0",e.style.minHeight="0";const n=Hn(j.metadata??{},it()),t=V.childElementCount>0?[V,e]:[e],i=es(t,{ownerDocument:u,boxSize:pe?{width:"min(96vw, 1600px)",height:"min(92vh, 1000px)"}:void 0,onClosed:()=>{Ae=null,_t=null,Tt(!0),pe||a.focus({preventScroll:!0})}});if(!i)return;i.box.setAttribute("aria-label",n??"Expanded wafer map"),t.length>1&&(i.contentWrap.style.flexDirection="column"),Ae=i,_t=us(i);const o=Z??F,s=Fe??be;if(o&&s&&o.style.display!=="none"){const l=parseFloat(u.defaultView?.getComputedStyle(s).columnGap??"")||0,r=o.getBoundingClientRect().width+l;r>0&&_t(!0,r)}Tt(!1)}function bi(e){("binColorScheme"in e||"useDefinedBinColors"in e)&&!("binColors"in e)&&d.binColors!==void 0&&(e={...e,binColors:void 0});const n=d.plotMode;d={...d,...e},Vn.some(l=>l in e)&&$?.setAxisPrefs(qi(d));const t=Object.keys(e);if(t.length>0&&t.every(l=>Vn.includes(l)))return;("compact"in e||"compactMap"in e)&&(G=null,O=null),e.plotMode!==void 0&&e.plotMode,Object.keys(e).every(l=>l==="legendPosition"||l==="showLegend"||l==="markFailingDies"||l==="showAxes")||at(),vn?.(),wn?.(),xn?.(),Cn?.(),w();const o=e.plotMode!==void 0&&e.plotMode!==n,s=COLOR_KEYS.some(l=>l in e);(s||o)&&se(),(s||o||e.activeTest!==void 0||e.logScale!==void 0||e.colorbarRangeMode!==void 0)&&bt?.()}function L(e){bi(e);const n=Object.keys(e);Xn?.(d,n,classifyChanged(n))}let Sn=!1;const Mn=y.drawWhenVisible&&B.IntersectionObserver?new B.IntersectionObserver(e=>{Ze=e[e.length-1].isIntersecting,Ze&&Xt&&w()},{rootMargin:"25%"}):null;let Ze=Mn===null,Xt=!1;Mn?.observe(a);function En(){Sn||(Sn=!0,In(()=>{Sn=!1,w()},B))}function w(){if(!Ze){Xt=!0;return}Xt=!1;const e=O??void 0,n=m.dies[0],t=n?{x:n.width,y:n.height}:He.diePitchMm,i=Math.floor(a.clientWidth||a.width),o=!!(ie?.length||oe?.length||m.dies.some(b=>b.hbin!=null||b.sbin!=null)),s=d.legendPosition??"default",l=d.showLegend??!0,r=s==="default"||s==="compact",c=(He.colorbarWidth??16)+28,f=o&&r?s!=="default"?Math.max(zi,c):i<Ko?0:i<Xo?Math.max(_o,c):Math.max(zi,c):void 0,p=Ho(a,m,{...He,minRightReserve:l?f:0,showColorbar:l&&(He.showColorbar??!0),markFailingDies:d.markFailingDies??!1,legendPosition:s,legendOffset:un,diePitchMm:t,fallbackFormat:d.fallbackFormat,showAxes:ri(),viewport:e,activeBin:d.plotMode==="metadata"?d.highlightMetadataValue:d.highlightBin,hoverBin:fn,afterDies:x.size>0||Pe!==null?xo:void 0,hbinDefs:ie,sbinDefs:oe,metadataFields:hn()});Lt=p.binLegendRows,Le=p.legendBox??null,O===null&&(G=p.viewport),je&&Eo(),Bi()}function xo(e,n,t){x.size>0&&So(e,n,t),Pe!==null&&Co(e,n,t)}function Co(e,n,t){Te??=new Map(m.dies.map((b,R)=>[he(b),R]));const i=Pe===null?void 0:Te.get(Pe);if(i===void 0)return;const o=m.hoverPoints[i],s=m.rectangles[0],l=s?s.width/2*n.ppm:n.ppm*.5,r=s?s.height/2*n.ppm:n.ppm*.5,c=n.originX+o.x*n.ppm,f=n.originY-o.y*n.ppm,p=Math.max(l,r)*1.25+5;e.save(),e.setLineDash([]),e.beginPath(),e.arc(c,f,p,0,Math.PI*2),e.strokeStyle=t.background,e.lineWidth=6,e.stroke(),e.strokeStyle=t.text,e.lineWidth=3,e.stroke(),e.restore()}function Kt(e){if(Pe=e===null?null:he(e),e!==null&&O!==null){ut();return}w()}function vi(){Pe!==null&&(Pe=null,w())}function So(e,n,t){const i=m.hoverPoints,o=m.rectangles[0],s=o?o.width/2*n.ppm:n.ppm*.5,l=o?o.height/2*n.ppm:n.ppm*.5,r=new Set;x.size>0&&(Te??=new Map(m.dies.map((v,k)=>[he(v),k])));for(const v of x){const k=Te.get(v);k!==void 0&&r.add(k)}if(!r.size)return;e.save(),e.setLineDash([]),e.fillStyle=t.background,e.globalAlpha=.7;let c=0;e.beginPath();for(let v=0;v<i.length;v++)r.has(v)||(e.rect(n.originX+i[v].x*n.ppm-s,n.originY-i[v].y*n.ppm-l,s*2,l*2),++c===No&&(e.fill(),e.beginPath(),c=0));c&&e.fill(),e.globalAlpha=1;const{cw:f,ch:p}=Mo(n,s,l),b=new Map,R=v=>Math.round(v*100),ae=(v,k,S,D)=>{const q=`${R(v)},${R(k)},${R(S)},${R(D)}`;b.has(q)?b.delete(q):b.set(q,[v,k,S,D])};for(const v of r){const k=n.originX+i[v].x*n.ppm,S=n.originY-i[v].y*n.ppm,D=k-f,q=k+f,T=S-p,re=S+p;ae(D,T,q,T),ae(D,re,q,re),ae(D,T,D,re),ae(q,T,q,re)}e.strokeStyle=t.text,e.lineWidth=2,e.lineCap="square",e.beginPath();for(const[v,k,S,D]of b.values())e.moveTo(v,k),e.lineTo(S,D);e.stroke(),e.restore()}function Mo(e,n,t){const i=m.hoverPoints,o=m.dies;let s=0,l=0;for(let r=0;r<o.length&&(!s||!l);r++){const c=o[r];if(!(c.x==null||c.y==null))for(const f of[Te.get(`${c.x+1},${c.y}`),Te.get(`${c.x},${c.y+1}`)]){if(f===void 0)continue;const p=Math.abs(i[f].x-i[r].x)*e.ppm,b=Math.abs(i[f].y-i[r].y)*e.ppm;p>b?s||=p/2:l||=b/2}}return{cw:s||n,ch:l||t}}function Eo(){const e=a.getContext("2d"),n=Math.min(z.x,H.x),t=Math.min(z.y,H.y),i=Math.abs(H.x-z.x),o=Math.abs(H.y-z.y);e.save(),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(n,t,i,o),e.setLineDash([5,3]),e.strokeStyle="rgba(255,255,255,0.9)",e.lineWidth=3,e.strokeRect(n,t,i,o),e.strokeStyle="rgba(0,0,0,0.9)",e.lineWidth=1.5,e.strokeRect(n,t,i,o),e.restore()}function wi(){if(!Xt)return;const e=Ze;Ze=!0,w(),Ze=e}function Bo(){wi(),a.toBlob(e=>{e&&ls(e,_n(),de.onSaveImage)})}function xi(e){return G?Math.max(G.ppm*co,Math.min(G.ppm*fo,e)):e}function qe(e,n,t){const i=O??G;if(!i)return;const o=xi(i.ppm*t),s=o/i.ppm,l=e-(e-i.originX)*s,r=n-(n-i.originY)*s,c=(G?.snapDist??1)/(o/(G?.ppm??o));O={originX:l,originY:r,ppm:o,snapDist:c},w()}function te(){return O??G}function Ci(e){if(e.ctrlKey||e.metaKey){e.preventDefault();const n=a.getBoundingClientRect(),t=e.deltaY<0?1.12:1/1.12;qe(e.clientX-n.left,e.clientY-n.top,t)}else if(O!==null){e.preventDefault();const n=te(),t=O.snapDist;O={originX:n.originX-e.deltaX,originY:n.originY-e.deltaY,ppm:n.ppm,snapDist:t},w()}}function Bn(e,n,t){return e>=t.x&&e<t.x+t.w&&n>=t.y&&n<t.y+t.h}function Si(e){if(kt=!1,e.button!==0||(vi(),!te()))return;a.focus({preventScroll:!0}),a.setPointerCapture(e.pointerId);const n=a.getBoundingClientRect(),t=e.clientX-n.left,i=e.clientY-n.top;if(Le&&d.legendPosition==="floating"&&Bn(t,i,Le)){Ne=!0,st={x:t,y:i},pn={...un};return}if(lt&&U!=="pan"){Ge=!0,Oe=!0,$e={x:t,y:i},Ot={x:te().originX,y:te().originY},a.style.cursor="grabbing";return}if(U==="zoom"||U==="select"){je=!0,z=H={x:t,y:i};return}Oe=!0,$e={x:t,y:i},Ot={x:te().originX,y:te().originY},a.style.cursor="grabbing"}function Mi(e){const n=a.getBoundingClientRect(),t=e.clientX-n.left,i=e.clientY-n.top;if(je){H={x:t,y:i},En();return}if(Ne){const p=t-st.x,b=i-st.y;p*p+b*b>16&&(Ne=!1,ot=!0,a.style.cursor="grabbing")}if(ot){un={x:pn.x+(t-st.x),y:pn.y+(i-st.y)},En();return}if(Oe){const p=te(),b=O?.snapDist??G?.snapDist??1;O={originX:Ot.x+(t-$e.x),originY:Ot.y+(i-$e.y),ppm:p.ppm,snapDist:b},En();return}const o=te();if(!o)return;const s=(t-o.originX)/o.ppm,l=(o.originY-i)/o.ppm,c=Tn(s,l,o.snapDist)?.die??null,f=Lt.find(p=>t>=p.x&&t<p.x+p.w&&i>=p.y&&i<p.y+p.h);if(ai(f?f.bin:void 0),f){a.style.cursor="pointer",_&&(_.textContent=f.label??`Bin ${f.bin}`,_.style.display="block",$i(_,a,e.clientX,e.clientY,{followPointer:!0})),vt?.(null,e);return}U==="pan"&&(a.style.cursor=c?"crosshair":"grab"),_&&(c?(_.innerHTML=Yo(c,m.plotMode,{testDefs:K,hbinDefs:ie,sbinDefs:oe,fallbackFormat:d.fallbackFormat,aggrMethod:m.aggrMethod,lotSize:m.lotSize,metadataFields:hn(),activeTest:m.activeTest,reticleConfig:Dt}),_.style.display="block",$i(_,a,e.clientX,e.clientY,{followPointer:!0})):_.style.display="none"),vt?.(c,e)}function Ei(e){const n=a.getBoundingClientRect(),t=e.clientX-n.left,i=e.clientY-n.top,o=e.ctrlKey||e.metaKey;if(_&&(t<0||i<0||t>n.width||i>n.height)&&(_.style.display="none"),je){je=!1,H={x:t,y:i};const r=t-z.x,c=i-z.y,f=te();if(U==="zoom"){if(r*r+c*c<25)qe(t,i,2);else if(f){const p=Math.min(z.x,H.x),b=Math.max(z.x,H.x),R=Math.min(z.y,H.y),ae=Math.max(z.y,H.y),v=b-p,k=ae-R;if(v>4&&k>4){const S=a.clientWidth,D=a.clientHeight,q=S/v,T=D/k,re=Math.min(q,T),pt=xi(f.ppm*re),Q=pt/f.ppm,Ln=(p+b)/2,On=(R+ae)/2;O={originX:S/2-(Ln-f.originX)*Q,originY:D/2-(On-f.originY)*Q,ppm:pt,snapDist:f.snapDist/Q}}}w(),a.style.cursor="crosshair";return}if(r*r+c*c<25)kn(t,i,o,e);else if(f){const p=(Math.min(z.x,H.x)-f.originX)/f.ppm,b=(Math.max(z.x,H.x)-f.originX)/f.ppm,R=(f.originY-Math.max(z.y,H.y))/f.ppm,ae=(f.originY-Math.min(z.y,H.y))/f.ppm,v=m.hoverPoints,k=[];for(let S=0;S<v.length;S++)if(v[S].x>=p&&v[S].x<=b&&v[S].y>=R&&v[S].y<=ae){const D=m.dies[S];D&&k.push(D)}if(o)for(const S of k){const D=he(S);x.has(D)?x.delete(D):x.add(D)}else x=new Set(k.map(S=>he(S)));Re(),me?.(Qe())}w(),a.style.cursor="crosshair";return}if(Ne){Ne=!1,kn(t,i,o,e);return}if(ot){ot=!1,a.style.cursor="grab";return}if(!Oe)return;if(Oe=!1,Ge){Ge=!1,a.style.cursor=lt||U==="pan"?"grab":"crosshair";return}a.style.cursor=U==="pan"?"grab":"crosshair";const s=t-$e.x,l=i-$e.y;s*s+l*l<25&&kn(t,i,o,e)}function kn(e,n,t,i){for(const r of Lt)if(e>=r.x&&e<r.x+r.w&&n>=r.y&&n<r.y+r.h){Re("legend"),typeof r.bin=="number"?L({highlightBin:to(d.highlightBin,r.bin,t)}):L({highlightMetadataValue:to(d.highlightMetadataValue,r.bin,t)});return}if(Le&&Bn(e,n,Le))return;const o=te();if(!o)return;const l=Tn((e-o.originX)/o.ppm,(o.originY-n)/o.ppm,o.snapDist)?.die??null;if(l){oo?.(l,i);const r=he(l);t?x.has(r)?x.delete(r):x.add(r):x.size===1&&x.has(r)?x=new Set:x=new Set([r]),Re(),me?.(Qe()),w()}else t||(x=new Set,Re(),me?.([]),w())}function Qe(){const e=[],n=m.hoverPoints;for(let t=0;t<n.length;t++){const i=m.dies[t];i&&x.has(he(i))&&e.push(i)}return e}function Bi(){Bt&&(Bt.style.display=Et()?"flex":"none",Bt.ariaLabel=x.size>0?"Charts and tables for the selected dies (or right-click)":"Charts and tables for this wafer (or right-click)")}function ki(){const e={waferLabel:yt(),testDefs:K,isLotStack:C.isLotStack,wafer:C.wafer,passBins:ne,ringCount:Ve(C,"renderWaferMap"),activeTest:d.plotMode==="value"?d.activeTest:void 0};return x.size>0?Ps(Qe(),e):Ts(Y,e)}function Dn(e,n,t){ye!==e&&n.click(),Pn(t,Z??F??a)}function ko(e,n){if(!Et())return;const t=d.plotMode==="softBin"?"soft":"hard",i=Ns(d.highlightBin),o=i.length>1&&i.includes(e)?[...i]:[e],s=[{label:yt()??"this wafer",dies:Y,wafer:C.wafer,passBins:ne,ringCount:Ve(C,"renderWaferMap")}],l=Qi(s,t,o,K);if(!l)return;const r={...Mt},c=o.length>1?Qi(s,t,[e],K):null;c&&(r.narrower={label:`Only ${t} bin ${e}`,backLabel:"All filtered bins",source:c,ctx:Mt});const f=a;import("./drilldown.js").then(({openDrilldownMenu:p})=>{Xe||(sn=p(n,f,l,r))})}function Pn(e,n){if(!Et())return;const t=y.drilldownSourceOverride?.(),i=t?.source??ki(),o={...Mt,...t?.ctx};if(t?.narrowable){const s=ki(),l=s.items.reduce((r,c)=>r+c.dies.length,0);o.narrower={label:`Only this wafer \u2014 ${l.toLocaleString()} die${l===1?"":"s"}`,source:s,ctx:Mt}}import("./drilldown.js").then(({openDrilldownMenu:s})=>{Xe||(sn=s(e,n,i,o))})}function Di(e){e.stopPropagation();const n=kt;if(kt=!1,!Et()||pe)return;const t=a.getBoundingClientRect();if(!n){const o=e.clientX-t.left,s=e.clientY-t.top,l=Lt.find(f=>o>=f.x&&o<f.x+f.w&&s>=f.y&&s<f.y+f.h);if(l&&typeof l.bin=="number"&&!C.isLotStack&&(d.plotMode===void 0||d.plotMode==="hardBin"||d.plotMode==="softBin")){e.preventDefault(),ko(l.bin,{x:e.clientX,y:e.clientY});return}if(Le&&Bn(o,s,Le))return;const r=te(),c=r?Tn((o-r.originX)/r.ppm,(r.originY-s)/r.ppm,r.snapDist)?.die:void 0;c&&!x.has(he(c))&&(x=new Set([he(c)]),Re(),me?.(Qe()),w())}e.preventDefault();const i=n?{x:t.left+t.width/2,y:t.top+t.height/2}:{x:e.clientX,y:e.clientY};Pn(i,a)}function Pi(){ai(void 0),_&&Qt(u),vt?.(null,new MouseEvent("mouseleave")),a.style.cursor=U==="pan"?"grab":"crosshair"}function Ti(){Oe=!1,Ge=!1,je=!1,Ne=!1,ot=!1,_&&Qt(u),vt?.(null,new MouseEvent("mouseleave")),a.style.cursor=U==="pan"?"grab":"crosshair",w()}function Tn(e,n,t){const i=m.hoverPoints,o=m.rectangles;for(let c=0;c<o.length;c++){const f=o[c];if(Math.abs(e-f.x)<=f.width/2&&Math.abs(n-f.y)<=f.height/2){const p=m.dies[c];return p?{die:p,index:c}:null}}let s=null,l=-1,r=t*t;for(let c=0;c<i.length;c++){const f=i[c].x-e,p=i[c].y-n,b=f*f+p*p;b<r&&(r=b,s=m.dies[c]??null,l=c)}return s?{die:s,index:l}:null}const Li=new B.ResizeObserver(()=>{G=null,O=null,w()});Li.observe(a),y.height==null&&io<=0&&In(()=>In(()=>{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 ft=B.matchMedia(`(resolution: ${B.devicePixelRatio}dppx)`);const Nt=()=>{ft.removeEventListener("change",Nt),ft=B.matchMedia(`(resolution: ${B.devicePixelRatio}dppx)`),ft.addEventListener("change",Nt),w()};ft.addEventListener("change",Nt);const Oi=B.matchMedia("(prefers-color-scheme: dark)"),Fi=()=>w();Oi.addEventListener("change",Fi);const Ri=()=>{_&&Qt(u)};B.addEventListener("blur",Ri);function Ai(e){if((e.key==="ContextMenu"||e.shiftKey&&e.key==="F10")&&(kt=!0),e.key==="Escape"&&vi(),e.key==="Escape"&&x.size>0&&(x=new Set,Re(),me?.([]),w()),(e.key==="e"||e.key==="E")&&$n&&(e.stopPropagation(),(jn??yi)()),(e.ctrlKey||e.metaKey)&&(e.key==="="||e.key==="+"?(e.preventDefault(),qe(a.clientWidth/2,a.clientHeight/2,1.2)):e.key==="-"?(e.preventDefault(),qe(a.clientWidth/2,a.clientHeight/2,1/1.2)):e.key==="0"&&(e.preventDefault(),ut())),!e.ctrlKey&&!e.metaKey&&!e.shiftKey){const t=te();if(t){const i=O?.snapDist??G?.snapDist??1;let o=0,s=0;e.key==="ArrowLeft"&&(o=20,e.preventDefault()),e.key==="ArrowRight"&&(o=-20,e.preventDefault()),e.key==="ArrowUp"&&(s=20,e.preventDefault()),e.key==="ArrowDown"&&(s=-20,e.preventDefault()),(o||s)&&(O={originX:t.originX+o,originY:t.originY+s,ppm:t.ppm,snapDist:i},w())}e.key===" "&&!lt&&(e.preventDefault(),lt=!0,U!=="pan"&&(a.style.cursor="grab"))}}function Wi(e){e.key===" "&&(lt=!1,Ge&&(Oe=!1,Ge=!1),a.style.cursor=U==="pan"?"grab":"crosshair")}a.style.cursor="crosshair",a.setAttribute("tabindex","0"),a.addEventListener("wheel",Ci,{passive:!1}),a.addEventListener("pointerdown",Si),a.addEventListener("pointermove",Mi),a.addEventListener("pointerup",Ei),a.addEventListener("pointerleave",Pi),a.addEventListener("pointercancel",Ti);const Ii=()=>ut();a.addEventListener("dblclick",Ii),a.addEventListener("keydown",Ai),a.addEventListener("keyup",Wi),a.addEventListener("contextmenu",Di);const Vi=e=>{e.stopPropagation()};a.addEventListener("click",Vi),a.clientWidth,w(),bt?.();function ut(){G=null,O=null,w()}function jt(e){import("./userGuideHtml.js").then(n=>ms({buildWaferMap:jo,renderWaferMap,renderWaferGallery:void 0,analyzeWaferMap:Wn},n.USER_GUIDE_HTML,lo,P,e))}const Do=ys(e=>jt(e));return ze(),Be&&J?.filter!==void 0&&nn(),{setResult(e){C=e,j=e.wafer,Ct=e.dies,Y=tn(),ie=e.hbinDefs,oe=e.sbinDefs,K=e.testDefs,Ke=e.metadataFields,ti=e.reticles?.length?e.reticles:void 0,Dt=e.reticleConfig,ni=e.dataAxisFlip,ln=e.isLotStack,an=e.aggrMethod,rn=e.lotSize,po(),at(),w(),Jn(),Z&&se()},setOptions(e){bi(e)},getOptions(){return{...d}},resetZoom:ut,setSelection(e){x=new Set(e.map(n=>he(n))),w()},getSelectedDies:()=>Qe(),clearSelection(){x=new Set,Re(),me?.([]),w()},setFindingsNotice(e){fi=e,Rt()},setStatsSummary(e){gn(e)},closeSummaryPanel(){Ht(!1)},getExportTitle(){return _n()},getSaveImageHook(){return de.onSaveImage},locateDie:Kt,getSaveTextHook(){return de.onSaveText},drawPendingNow:wi,getBinColors(){return m.binColors},setSummaryVisible(e){hi=e,ct()},setViewControlsVisible(e){N&&(N.style.display=e?"flex":"none")},setExpandVisible(e){Tt(e)},openUserGuide:()=>jt(),setInsightsOpen(e){Ce(e)},destroy(){Xe=!0,Do(),on.flush();for(const e of dt.values())e.cancel();dt.clear(),Ae?.close(),mi?.()?.remove(),bn&&u.removeEventListener("click",bn,!0),a.removeEventListener("wheel",Ci),a.removeEventListener("pointerdown",Si),a.removeEventListener("pointermove",Mi),a.removeEventListener("pointerup",Ei),a.removeEventListener("pointerleave",Pi),a.removeEventListener("pointercancel",Ti),a.removeEventListener("dblclick",Ii),a.removeEventListener("keydown",Ai),a.removeEventListener("keyup",Wi),a.removeEventListener("contextmenu",Di),sn?.(),a.removeEventListener("click",Vi),Li.disconnect(),Mn?.disconnect(),ft.removeEventListener("change",Nt),Oi.removeEventListener("change",Fi),B.removeEventListener("blur",Ri),uo(),_&&Qt(u),le?.remove(),Fe&&(Fe.parentElement?.insertBefore(M,Fe),Fe.remove()),be&&(be.parentElement?.insertBefore(M,be),be.remove()),M.remove(),a.style.cursor="",$?.destroy(),ee?.destroy(),Ye.remove()}}}
|
|
@@ -582,11 +582,13 @@ export declare function metadataModeEntry(field: MetadataFieldDef): ModeEntry;
|
|
|
582
582
|
* get the same filter-as-you-type box instead of building it twice.
|
|
583
583
|
*
|
|
584
584
|
* `onFilter` receives the lowercased query on every keystroke; the caller
|
|
585
|
-
* owns showing/hiding its own rows. Autofocuses on mount. Click/keydown are
|
|
585
|
+
* owns showing/hiding its own rows. Enter picks the only row left showing, when `visibleRows` is given. Autofocuses on mount. Click/keydown are
|
|
586
586
|
* stopped from bubbling so typing (including Space/arrow keys) lands in the
|
|
587
587
|
* input rather than triggering the host menu's own keyboard navigation.
|
|
588
588
|
*/
|
|
589
|
-
export declare function makeMenuSearchBox(onFilter: (query: string) => void, placeholder?: string, ownerDocument?: Document
|
|
589
|
+
export declare function makeMenuSearchBox(onFilter: (query: string) => void, placeholder?: string, ownerDocument?: Document,
|
|
590
|
+
/** The rows still showing: when Enter is pressed with exactly one, it is picked. */
|
|
591
|
+
visibleRows?: () => HTMLElement[]): HTMLInputElement;
|
|
590
592
|
/**
|
|
591
593
|
* Build the plot-mode dropdown menu element.
|
|
592
594
|
* Shared between renderWaferMap and renderWaferGallery.
|
|
@@ -607,8 +609,9 @@ export declare function wireMenuA11y(menu: HTMLElement, trigger: HTMLElement | n
|
|
|
607
609
|
/**
|
|
608
610
|
* Open a command menu (`role="menu"`, rows that act and are done) under `at`: a card's ⋯ menu, the drilldown menu at
|
|
609
611
|
* a click. `anchor` is an on-page element of the triggering render; it resolves the menu layer and gets focus back on
|
|
610
|
-
* Escape. A `trigger` button has its `aria-expanded` kept in step. The menu
|
|
611
|
-
* outside press, Escape, Tab, the window losing focus, or another command menu
|
|
612
|
+
* Escape. A `trigger` button has its `aria-expanded` kept in step. The menu scrolls when taller than the window, flips
|
|
613
|
+
* to stay on screen, and closes on an outside press, Escape, Tab, the window losing focus, or another command menu
|
|
614
|
+
* opening. Returns its close function.
|
|
612
615
|
*/
|
|
613
616
|
export declare function openCommandMenu(at: DOMRect, anchor: HTMLElement, rows: CheckMenuRow[], label: string, opts?: {
|
|
614
617
|
trigger?: HTMLElement;
|