@wafertools/wafermap 0.37.1 → 0.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/CHANGELOG.md +53 -1
  2. package/README.md +20 -13
  3. package/dist/packages/canvas-adapter/chartPopulation.d.ts +8 -3
  4. package/dist/packages/canvas-adapter/chartPopulation.js +1 -1
  5. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +27 -17
  6. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +0 -7
  8. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  9. package/dist/packages/canvas-adapter/drilldown.d.ts +5 -0
  10. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  11. package/dist/packages/canvas-adapter/index.d.ts +1 -0
  12. package/dist/packages/canvas-adapter/index.js +1 -1
  13. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  14. package/dist/packages/canvas-adapter/pinnedTests.d.ts +10 -0
  15. package/dist/packages/canvas-adapter/pinnedTests.js +1 -0
  16. package/dist/packages/canvas-adapter/plotCard.d.ts +1 -1
  17. package/dist/packages/canvas-adapter/plotCard.js +1 -1
  18. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  19. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  20. package/dist/packages/canvas-adapter/summaryPanel.d.ts +3 -3
  21. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  22. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  23. package/dist/packages/canvas-adapter/userGuideHtml.js +32 -19
  24. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  25. package/dist/packages/canvas-adapter/version.js +1 -1
  26. package/dist/packages/canvas-adapter/viewSwitch.js +1 -1
  27. package/dist/packages/renderer/buildWaferMap.js +1 -1
  28. package/dist/packages/renderer/derivedTests/apply.d.ts +10 -0
  29. package/dist/packages/renderer/derivedTests/apply.js +1 -1
  30. package/dist/packages/renderer/derivedTests/check.d.ts +35 -0
  31. package/dist/packages/renderer/derivedTests/check.js +1 -0
  32. package/dist/packages/renderer/fmt.d.ts +5 -0
  33. package/dist/packages/renderer/fmt.js +1 -1
  34. package/dist/packages/renderer/index.d.ts +2 -0
  35. package/dist/packages/renderer/index.js +1 -1
  36. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  37. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  38. package/dist/packages/stats/chartCatalogue.js +1 -1
  39. package/dist/packages/stats/clusterDetection.js +1 -1
  40. package/dist/packages/stats/plotData.d.ts +7 -0
  41. package/dist/packages/stats/plotData.js +1 -1
  42. package/dist/packages/stats/reportHtml.js +33 -29
  43. package/dist/packages/stats/synthesis.d.ts +1 -1
  44. package/dist/packages/stats/synthesis.js +1 -1
  45. package/package.json +8 -4
@@ -1 +1 @@
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
+ import{createViewSwitch as xs}from"./viewSwitch.js";import{createSummaryToggle as Ms}from"./summaryToggle.js";import{getUniqueTestNumbers as ks,resolveTestNumber as Ds,findTestDef as Bs,collectMetadataValues as Es}from"../renderer/buildView.js";import{metadataCategoricalValue as Os}from"../core/metadata.js";import{resolveBinColorsForMaps as Ts,mergeBinDefs as Vt,binColorWarning as Ls,mixedPassBinsWarning as Ps,binColorsEqual as Ws}from"../renderer/binColors.js";import{commonPassBins as ni,itemPassBins as Ue}from"../core/passBins.js";import{PAT_MODE_FIELD as Rs,PAT_MODE_KEY as As,PAT_MODE_ORDER as Fs,isPatMode as mt,patModeOffered as $s,withPatField as Is,withPatVerdicts as Vs}from"./patMode.js";import{requireRingCount as ne}from"../core/ringCount.js";import{NO_DATA_FILL as Hs}from"../renderer/colorMap.js";import{metadataValueColor as js}from"../renderer/colorMap.js";import{resolveCanvasTheme as zs}from"./canvasTheme.js";import{ICONS as Tn}from"./icons.js";import{SHADOW as Ln,LEADING as oi,TRACKING as Ns,controlStyle as _s,wireControlHover as Pn,SPACE as M,EDGE_GUTTER as oe,MAP_CHROME_INSET as Ks,RADIUS as Y,FONT as N,CLR as w,sevColor as ii,MODE_LABELS as Gs,BIN_LEGEND_MODES as si,STACKED_MODES as ie,applyOverlayZ as qs,getTooltip as Xs,hideTooltip as ai,createToolbarHelpers as Ys,buildModeMenuEl as Us,openDetachWindow as Zs,openFloatingWindow as Qs,openModal as Js,copyWmapThemeTokens as ea,syncWmapPopupTheme as ta,makePaletteBtn as na,makeLogScaleBtn as oa,makeLegendStyleBtn as ia,makeOverlaysBtn as sa,makeOrientationBtn as aa,menuLayerFor as li,saveImageBlob as la,markMenuTrigger as gt,wireMenuA11y as ri,wireTooltip as Wn,requestedPassFailDisplay as ci,overlayMenuRows as ra,anyOverlayActive as ca,openCompactDiagnostics as da,roomForPanel as di,logWmapVersionOnce as ua,buildDataModeEntries as fa,metadataKeyHasData as pa,metadataModeEntry as ui}from"./toolbar.js";import{openReportModal as ma,openUserGuideWindow as ga,registerGuideOpener as ha}from"./guideWindow.js";import{waferDisplayLabel as ht,waferIdentityLabel as ve}from"../core/waferLabel.js";import{bandButton as ya}from"./filterButton.js";import{metadataDisplayValue as ba}from"../core/metadata.js";import{withExportContext as wa}from"./exportName.js";import{sortBinsForDisplay as va}from"../stats/binPareto.js";import{diePassStatus as Sa,isYieldEligibleDie as Ca}from"../core/dies.js";import{aggregateValues as xa,aggregateBinCounts as fi}from"../core/aggregates.js";import{renderWaferMap as Ma,renderWaferMapCard as pi,toPublicViewOptions as Ht}from"./renderWaferMap.js";import{waferPopulation as ka,selectionPopulation as Da,LOT_STACK_REASON as Rn}from"./chartPopulation.js";import{sourceFromBins as mi}from"./plotItems.js";import{plotStoreFor as Ba}from"./plotStore.js";import{classifyChanged as An,COLOR_KEYS as Ea,findingBin as Oa,findingPlotMode as Ta}from"./renderWaferMap.js";import{findingPatternKey as gi}from"../stats/filterFindings.js";import{synthesisSource as La}from"../stats/synthesis.js";import{buildWaferMap as Pa,computeCoverage as Wa,computeYield as Ra,defaultBinMode as Aa,getTestPassStatus as hi,isParametricTest as Fn,getDieTestValue as Fa,isBuiltMap as $a}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as $n}from"../stats/analyzeWaferMap.js";import{lotTestValueStatus as Ia}from"../stats/testValueBudget.js";import{testValueNotice as Va}from"./testValueOffer.js";import{axisPrefsFromOptions as In,optionsFromAxisPrefs as Ha,CHART_PREF_KEYS as Vn}from"./chartPrefs.js";import{collectWarnings as ja,buildWarningsMenuEl as za,severityOf as Na}from"./warnings.js";import{asList as Hn,compareNatural as jn,arrayEqual as jt,toggleHighlight as yi}from"../core/utils.js";import{buildCompactMap as _a,compactLayoutOffered as Ka}from"../core/compact.js";import{attachExpandableMetadata as bi}from"./identityHeader.js";import{createSummaryPanelEl as zn,buildMetadataStripRow as Ga,metadataEntries as qa,renderLotSummaryContentSteps as Xa,reportMapsFromItems as Ya}from"./summaryPanel.js";import{prettyKey as Ua}from"../stats/facets.js";import{testLabel as Za,markedTestLabel as Qa,derivedFields as Ja}from"../renderer/testLabel.js";import{mergeTestDefs as el}from"../stats/mergeTestDefs.js";import{getDieKey as zt,hasPosition as tl}from"../core/dies.js";import{testValue as nl}from"../core/dieTable.js";import{runChunked as ol}from"./chunked.js";function wi(r){if(typeof r!="number"||!Number.isFinite(r))return;const k=Math.round(r);return k>=1?k:void 0}const Nn=12;function il(r,k,f){let z=k;if(k.length>Nn){const D=k.slice(0,Nn-1),O=k.slice(Nn-1),I=O.reduce(($,de)=>$+de.count,0);z=[...D,{color:w.label,count:I,label:`Other (${O.length} bins)`}]}const T=r.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} ${Nt(D.count/f*100)}`).join(", ")}`);for(const D of z){const O=D.count/f*100,I=r.createElement("div");Object.assign(I.style,{flex:`${O} 1 0`,minWidth:O>0?"2px":"0",background:D.color}),Wn(I,`${D.label} \xB7 ${D.count.toLocaleString()} dies \xB7 ${Nt(O)}`),T.appendChild(I)}return T}function Nt(r){return r>0&&r<.1?"<0.1%":`${r.toFixed(1)}%`}function vi(r,k,f){const z=new Map;let T=0,D=0;for(const O of r){const I=f?new Set(f(O)):void 0;for(const $ of O.dies){if(!Ca($))continue;const de=k($);de!==void 0&&(z.set(de,(z.get(de)??0)+1),T++,I&&Sa($,I)&&D++)}}return{counts:z,total:T,pass:D}}function Si(r,k){const f=r.ownerDocument.createElement("div");Object.assign(f.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${M.xxs} ${M.xs}`,borderRadius:Y.control});const z=r.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=r.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"}),f.appendChild(z),f.appendChild(T),k.count!==void 0){const D=r.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"}),f.appendChild(D),k.percent!==void 0){const O=r.ownerDocument.createElement("span");O.textContent=Nt(k.percent),Object.assign(O.style,{color:w.label,whiteSpace:"nowrap"}),f.appendChild(O)}}if(f.setAttribute("role","button"),f.setAttribute("aria-pressed",k.isActive?"true":"false"),f.tabIndex=0,f.addEventListener("mouseenter",()=>{f.style.background=w.bgHover}),f.addEventListener("mouseleave",()=>{f.style.background="transparent"}),f.addEventListener("focus",()=>{f.style.background=w.bgHover}),f.addEventListener("blur",()=>{f.style.background="transparent"}),f.addEventListener("click",D=>k.onClick(D.ctrlKey||D.metaKey)),f.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=f.getBoundingClientRect();k.onMenu({x:O.left+O.width/2,y:O.bottom},f)}}),k.onMenu){const D=k.onMenu;f.addEventListener("contextmenu",O=>{O.preventDefault(),D({x:O.clientX,y:O.clientY},f)}),Wn(f,"Right-click: charts and tables for these dies")}r.appendChild(f)}export function renderWaferGallery(r,k,f={}){ua();const z=6;let T=wi(f.columns);const D=f.showHelpButton??!1,O=f.userGuideExtension,I=f.insights?.enabled??!0,$=Ba(f.insights),de={enabled:!1,plotStore:$},Ci=qs(f.zIndex),Re=f.summaryPanel,Se=e=>[...Ue(e)],_n=()=>W.flatMap(e=>e?[ne(e,"renderWaferGallery")]:[]),yt=()=>_n()[0];function xi(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 _=f.lotStatsSummary,Ae;const se=()=>ae?Ae:_;let Ze=f.viewOptions?.legendPosition??"default",bt=f.perCardLegend??!1;function Qe(){const e=a.plotMode??"hardBin";return si.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 Kn(){const e=bt||Qe()!==null;for(const t of C)t&&t.setOptions({showLegend:e})}let a={plotMode:Aa(k.flatMap(e=>typeof e=="function"?[]:[e.dies??[]])),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...f.viewOptions},C=[],ue=[],Fe=[],x=[];const V=wa(()=>{const e=x.filter(n=>n!=null),t=[...new Set(e.map(n=>ba(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort(jn);return{prefix:f.downloadFilename,lots:t,...e.length===1?{wafer:ve(e[0])}:{waferCount:e.length}}},f.onSaveImage,f.onSaveText);let W=k.map(e=>typeof e=="function"?null:e),q=null,Gn=null,_t=!1,Ce=0,ae=!1,wt=!1;const xe=new WeakSet,qn=new WeakMap,Me=()=>{const e=q?.get();return!!e&&!e.off};function Xn(e,t){return{dies:e.dies,wafer:e.wafer,label:ht(e,t),identity:ve(e),waferIndex:t,passBins:Ue(e),testDefs:e.testDefs,statsSummary:e.statsSummary}}const Kt=new Map;function Je(e,t){if(!q||!Me())return e;const n=qn.get(e);if(n&&n.v===Ce)return n.item;const o=q.mark([Xn(e,t)]);let i=e;if(o.narrowing){const s=o.items[0].dies,l=s.filter(u=>!u.filteredOut);i={...e,dies:s,statsSummary:Kt.get(e),...e.yield?{yield:Ra(s,[...Ue(e)],e.yield.yieldPercentGross!=null?"denominator-only":"exclude")}:{},...e.dataCoverage?{dataCoverage:Wa(l)}:{}},o.hidden.size&&xe.add(i)}return qn.set(e,{v:Ce,item:i}),i}const Yn=new WeakMap;function Gt(e,t){const n=Je(e,t);if(!mt(a))return n;const o=Yn.get(n);if(o)return o;const i={...n,dies:Vs(n.dies,n.testDefs,Ue(n)),metadataFields:Is(n.metadataFields)};return xe.has(n)&&xe.add(i),Yn.set(n,i),i}const Un=new WeakMap;function Mi(e,t){if(!q||!Me())return e;const n=Un.get(e);if(n&&n.v===Ce)return n.item;const o=Je(e,t),i=o===e?e:xe.has(o)?null:{...o,dies:o.dies.filter(s=>!s.filteredOut)};return Un.set(e,{v:Ce,item:i}),i}function B(){return!q||!Me()?W:W.map((e,t)=>e?Mi(e,t):null)}let vt=0,et=!1;function Zn(){const e=++vt;Ae=void 0,Kt.clear();const t=()=>{et=!1,R(),re()};if(!ae){t();return}const n=Jt();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}et=!0;const i=_?.analysisOptions??n.find(s=>s.statsSummary)?.statsSummary?.analysisOptions??{};import("../stats/analyzeWaferLot.js").then(async({analyzeWaferLotAsync:s,remapLotWaferIndices:l})=>{const u=await s(o.map(m=>m.it),i);if(e!==vt||_t)return;const d=o.map(m=>m.i);Ae=l(u,d),u.perWafer.forEach((m,v)=>Kt.set(W[d[v]],m.summary)),Ce++,W.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 $e=e=>q&&Me()||mt(a)?e.map((t,n)=>typeof t=="function"?t:Gt(t,n)):e;function qt(){return Gn??=import("./pageFilter.js").then(({createPageFilter:e})=>{const t=e({doc:r.ownerDocument,initial:f.insights?.filter,onChange:f.insights?.onFilterChange,savedFilters:f.insights?.savedFilters,onSavedFiltersChange:f.insights?.onSavedFiltersChange,pickFiltersFile:f.insights?.onPickFiltersFile,onSaveText:f.onSaveText,attributes:f.attributes,getRingCount:()=>ne({ringCount:yt()},"the page filter")});return _t||(q=t,fe=t.createBand(()=>Yt(),{marginLeft:oe,marginRight:oe,marginBottom:M.lg}),r.insertBefore(fe.el,Z),t.subscribe(Ut),t.get()&&Ut()),t}),Gn}let fe=null,St=null,Xt;const Yt=()=>W.flatMap((e,t)=>e?[Xn(e,t)]:[]);function Qn(){clearTimeout(Xt),Xt=setTimeout(()=>{if(!q||!fe)return;const e=Yt(),t=q.keep(e);fe.refresh(t.result,e),fe.el.style.display=q.get()&&!Ke?"":"none"},0)}function Jn(){if(q){if(ke>0){Me()&&(wt=!0);return}Ce++,ae=Me()&&W.some((e,t)=>e!==null&&Je(e,t)!==e),Ae=void 0,et=ae&&!!_,Zn()}}function Ut(){if(Ce++,ae=!1,ke>0){wt=!0,Qn();return}wt=!1;const e=a.plotMode;ae=Me()&&W.some((t,n)=>t!==null&&Je(t,n)!==t),Ae=void 0,et=ae&&!!_,W.length>0&&(ie.has(e)?(a={...a,...$t(e)},X(qe(e))):X($e(W.filter(t=>t!==null)))),Qn(),Zn()}function Ie(){return el(B())}function tt(){if(B().some(e=>e?.testDefs?.length))return Ie().defs}let nt=0,ke=0;const Q=new Map;let ki=0,Ct=null,J=null,pe=null,Ve=null;function xt(){J===null&&pe===null&&(Ve={plotMode:a.plotMode,activeTest:a.activeTest})}function eo(){Ve&&P({...Ve},{fireCallback:!1}),Ve=null}let to=new Set,S=null,Di={};function no(e){return B()[e]?.statsSummary??se()?.perWafer.find(t=>t.waferIndex===e)?.summary}function oo(){return!!(B().some(e=>e?.statsSummary?.findings.length)||se()?.perWafer.some(e=>e.summary.findings.length))}const Bi=Xs(),He=Ys(Bi),{makeBtn:je,setActive:io,makeSep:De,syncSeparators:Zt,syncToolbarVisible:Qt,makeMenuRow:Ei,makeMenuSection:Oi,makeDropdown:so,closeOpenMenu:Mt,getOpenMenu:ot,setOpenMenu:it}=He;r.ownerDocument.addEventListener("click",Mt,!0);const ao=()=>ai();window.addEventListener("blur",ao);let lo=f.findingsNotice,Be=null;function Jt(){const e=W;return e.length>0&&e.every(t=>t!=null&&$a(t))?e:null}function Ti(){return _?.stats.testValueAnalysis??Ia(B().flatMap(e=>e?.statsSummary?[e.statsSummary]:[]))}const en=()=>lo??(Jt()?Va(Ti(),B().length,Be!==null,Li):void 0);function Li(){const e=Jt();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);W=W.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(),f.onStatsSummaryChange?.({summaries:i,lotStatsSummary:o})}).catch(o=>{if(!t.signal.aborted)throw Be=null,R(),o})}function tn(){Be?.abort(),Be=null}function ro(e){to=new Set(e);const t=[...F.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,i)=>{const s=to.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 nn(){ro([])}let kt=!1;function on(){kt=!0;for(const e of C)e&&e.clearSelection();kt=!1}function co(e){return t=>{!kt&&(J!==null||pe!==null)&&(Ve=null,Oe(),R()),ln.set(e,t.length),le&&!st&&!kt&&Pi(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,st=!1,Ee=new Set;function Pi(e,t){st=!0;try{Ee=new Set(t.map(n=>zt(n))),x.forEach((n,o)=>{const i=C[o];!i||!n||n===e||i.setSelection(n.dies.filter(s=>Ee.has(zt(s))))})}finally{st=!1}Lt()}function uo(){Ee=new Set,st=!0;try{for(const e of C)e?.clearSelection()}finally{st=!1}Lt()}function sn(){if(!le||Ee.size===0)return;const e=[];let t=!1;if(x.forEach((i,s)=>{if(!i)return;const l=i.dies.filter(u=>Ee.has(zt(u)));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?Rn:void 0},ctx:{plots:$,getBinColors:()=>a.binColors??K(),attributes:f.attributes,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(i,s)=>me(s,i)}}}function fo(){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?Rn:void 0},ctx:{plots:$,getBinColors:()=>a.binColors??K(),attributes:f.attributes,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(o,i)=>me(i,o)}}}function Wi(e){const t=sn()??go(e);if(t)return t;const n=fo(),o=n?.source.items.some(i=>i.waferIndex===e);return n&&o?{...n,narrowable:!0}:void 0}function an(e,t,n){J!==e&&t.click();const o=S;if(!o)return;const i=se()?.findings.find(l=>l.id===e),s=sn()??fo()??Ai()??(i?po(ho(i)):void 0);s&&import("./drilldown.js").then(({openDrilldownMenu:l})=>{o.isConnected&&l(n,o,s.source,{plots:$,getBinColors:()=>a.binColors??K(),attributes:f.attributes,...s.ctx})})}function Ri(e,t,n,o){const i=Hn(a.highlightBin),s=i.length>1&&i.includes(t)?[...i]:[t],l=[];let u=!1;x.forEach((g,h)=>{g&&(g.isLotStack&&(u=!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 d=Ie().defs,m=mi(l,e,s,d,void 0,u);if(!m)return;const v={plots:$,getBinColors:()=>a.binColors??K(),attributes:f.attributes,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(g,h)=>me(h,g)},p=s.length>1?mi(l,e,[t],d,void 0,u):null,c=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,c)})}function po(e,t=""){const n=[];let o=!1;for(const s of[...e??[]].sort((l,u)=>l-u)){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?Rn:void 0},ctx:{plots:$,getBinColors:()=>a.binColors??K(),attributes:f.attributes,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(s,l)=>me(l,s)}}}function Ai(){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: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 Fi(e){e||uo(),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 u=s.dies.filter(d=>n.has(zt(d)));l.setSelection(u)}}const U=new Set,ln=new Map;function mo(){[...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 $i(e){e<0||(U.has(e)?U.delete(e):U.add(e),mo())}function Ii(){U.clear(),mo()}function go(e){if(!(U.size===0||!U.has(e))){for(const t of ln.values())if(t>0)return;return po([...U],"picked ")}}function Vi(){const e=[];for(let t=0;t<B().length;t++){const n=B()[t];if(!n)continue;const o=no(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 Hi(e){const t=x[e]??B()[e];t&&ut(e,t)}function ji(e){const t=no(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 zi(){import("../stats/renderSummaryReport.js").then(({renderLotReportHtml:e})=>{ma(e(Ya(B(),yt())),{anchor:r})})}function Ni(){if(!S)return;S.innerHTML="";const e=Vi();if(B().length>0){const n=r.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=r.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"}),Pn(n),n.addEventListener("click",zi),S.appendChild(n)}if(e.length===0){const n=r.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 u=i?"unusual":s?"notable":"info",d=i+s||l,m=r.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 ${ii(u)}`,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=r.ownerDocument.createElement("span");v.textContent=ht(o,n),Object.assign(v.style,{color:w.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const p=r.ownerDocument.createElement("span");p.textContent=String(d),m.setAttribute("aria-label",`${ht(o,n)} \u2014 ${d} finding${d===1?"":"s"}${i?`, ${i} unusual`:""} \u2014 view wafer`),Object.assign(p.style,{marginLeft:M.sm,flexShrink:"0",background:ii(u),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=r.ownerDocument.createElement("div");t.style.height="12px",S.appendChild(t)}let ze=null,at=null;function R(){if(!S||ae&&_&&!Ae&&et)return;ze?.cancel(),ze=null;const e=se();if(e){const t=Vt(B().map(o=>o?.hbinDefs)),n=Vt(B().map(o=>o?.sbinDefs));ze=ol(Xa(S,{lotSummary:e,items:B(),hbinDefs:t.length?t:void 0,sbinDefs:n.length?n:void 0,testDefs:tt(),ringCount:yt(),binColors:a.binColors,plotMode:a.plotMode??"hardBin",fallbackFormat:a.fallbackFormat,activeFindingId:J,warnings:f.warnings?.display??!0?ge:[],findingsFilter:Di,findingsNotice:en(),onFindingsFilterChange:R,onSaveText:V.onSaveText,attributes:f.attributes,onFindingClick:(o,i)=>{J===o.id?(Oe(),eo()):(xt(),So(o,i)),R()},activeTest:pe,onTestClick:o=>{const i=pe===o;i||xt(),Oe(),i?eo():vo(o),R()},onShowChart:I?o=>{Ge(!0),$o().then(i=>i?.showWorthCard(o))}:void 0,onWaferClick:Hi,findingsFor:ji,dieListOptions:f.dieList,onLocateDie:(o,i)=>me(i,o),onClose:()=>cn(!1)}),{onDone:()=>{const o=at;at=null,o?.()}})}else Ni()}function ho(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}let Bt=[];function yo(){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,nn(),on(),yo(),P({highlightBin:void 0},{fireCallback:!1})}function bo(){J===null&&pe===null||(Ve=null,Oe(),R())}function wo(e,t){const n=tt();if(n===void 0||n.some(i=>i.testNumber===e))P({plotMode:"value",activeTest:e,highlightBin:void 0},{fireCallback:!1});else{P({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 vo(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(wo(e,n.length?n:null),nn(),on(),!ie.has(a.plotMode??"hardBin"))for(const o of n)Dt(t(o),[o])}function So(e,t){if(J===e.id){Oe();return}J=e.id,pe=null,t&&(t.style.background=w.bgActive,t.style.fontWeight="600"),yo();const{kind:n,index:o}=e.variable;if(n==="test")wo(o??0,ho(e));else{const s=x.some(u=>u?.dies?.some(d=>d.hbin!=null)),l=ni(x.map(u=>u?Ue(u):void 0));P({plotMode:Ta(e,a.plotMode,s),highlightBin:Oa(e,l,s)},{fireCallback:!1})}nn(),on();const i=e.highlight;if(i.kind==="wafer"){ro(i.waferIndices);const s=gi(e);for(const l of i.waferIndices){const u=i.dieKeysByWafer?void 0:x[l]?.statsSummary?.findings.find(m=>gi(m)===s),d=i.dieKeysByWafer?.[l]??u?.highlight?.dieKeys;d?.length&&Dt(d,[l])}}else i.kind==="bin"?i.dieKeys?.length&&Dt(i.dieKeys):(i.kind==="region"||i.kind==="dies")&&i.dieKeys?.length&&Dt(i.dieKeys)}function rn(){return!!S&&S.style.display!=="none"}function cn(e){!S||e===rn()||(e&&R(),S.style.display=e?"flex":"none",re())}function re(){Ct&&(Zt(H),Qt(H,"inline-flex"),Ct.sync({visible:!!(_||se()||oo())&&!!S&&!Ke,open:rn(),notable:!!(se()?.hasNotableFindings||B().some(e=>e?.statsSummary?.hasNotableFindings))}))}const H=r.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:Ln.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const Co=()=>{const e=ot();e&&(e.remove(),it(null)),gt(ce,!1)},ce=je("mode","Plot mode",()=>{if(ot()){Co();return}const e=B().flatMap(y=>y?.dies??[]),t=tt(),{testEntries:n,binEntries:o,stackedEntries:i}=fa(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=>hi(j,y)!==void 0||nl(j,y)!==void 0)&&E++;return E},u=s<2?n:n.map(y=>{const E=l(y.activeTest);return E===s?y:{...y,label:`${y.label} \u2014 ${E} of ${s} wafers`}}),d=a.plotMode??"hardBin",m=a.activeTest??0;function v(y){return y.plotMode!==d?!1:y.plotMode==="value"?m===(y.activeTest??0):y.plotMode==="metadata"?a.activeMetadataKey===y.activeMetadataKey:!0}function p(y,E){y.activeTest!==void 0?P({plotMode:"value",activeTest:y.activeTest,activeMetadataKey:void 0,logScale:y.logScale}):y.activeMetadataKey!==void 0?P({plotMode:y.plotMode,activeTest:void 0,activeMetadataKey:y.activeMetadataKey,passFailDisplay:"off"}):P({plotMode:y.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),E.remove(),it(null),gt(ce,!1)}const c=new Set,g=B().flatMap(y=>y?.metadataFields??[]).filter(y=>!c.has(y.key)&&c.add(y.key)).filter(y=>pa(e,y.key)).map(ui);ke===0&&$s(B())&&g.push(ui(Rs));const h=Us(ce.getBoundingClientRect(),u,o,i,v,p,{makeMenuRow:Ei,makeMenuSection:Oi},d,ce.ownerDocument.defaultView??window,g);li(ce).appendChild(h),it(h),gt(ce,!0),ri(h,ce,Co)});gt(ce,!1);const _i=()=>x.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:Ki,sync:xo}=na(He,()=>({...a,plotMode:a.plotMode??"hardBin"}),_i,e=>P(e));xo();const Gi=k.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function Et(){const e=tt(),{testNumber:t}=Ds(a.activeTest??0,e);return{testNumber:t,td:Bs(e,t)}}function Mo(){if((a.plotMode??"hardBin")!=="value")return!1;const{td:e}=Et();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function lt(){if((a.plotMode??"hardBin")!=="value")return!1;const{td:e}=Et();return e!==void 0&&!Fn(e)}function qi(){if((a.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=Et();return B().some(n=>n?.dies?.some(o=>hi(o,e,t)!==void 0))}function Xi(e,t){if(!t||!Fn(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((ci(a)==="spec"&&n?"spec":a.colorbarRangeMode??"spec")==="spec"&&n)return;let s=1/0,l=-1/0;for(const u of B())if(u)for(const d of u.dies){const m=Fa(d,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 ko(){if((a.plotMode??"hardBin")!=="metadata")return;const e=a.activeMetadataKey;if(!e)return;if(mt(a))return{key:e,values:[...Fs]};const t=new Set;for(const n of B())if(n)for(const o of Es(n.dies,e))t.add(o);return{key:e,values:[...t].sort(jn)}}function dn(){Ot("metadataValueOrder",ko(),(e,t)=>e.key===t.key&&jt(e.values,t.values))}function un(){if((a.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=Et(),n=Xi(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},u=l(i),d=l(s);return u.test===d.test&&jt(u.range,d.range)})}let fn=!1;function Yi(){if(fn)return;fn=!0,(r.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{fn=!1,un(),dn(),Oo(),Eo()})}let pn=!1;function Ui(){if(pn)return;pn=!0,(r.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{pn=!1,Ft()})}let Do=[];function K(){const{colors:e,mixedHardBins:t}=Ts(B().filter(n=>n!=null),{binColorScheme:a.binColorScheme,useDefinedBinColors:a.useDefinedBinColors});return Do=t,e}function mn(){return x.filter(e=>e!=null).flatMap(e=>e.dies)}function Bo(){return a.compact?_a(mn()):void 0}const Zi=(e,t)=>jt(e.columns,t.columns)&&jt(e.rows,t.rows);function Eo(){Ot("compactMap",Bo(),Zi)&&jo()}function Qi(){return Ka(mn(),x.filter(e=>e!=null).map(e=>e.reticleConfig))}function Oo(){Ot("binColors",K(),Ws),Te()}const Ji=sa(He,()=>ra(a,Gi,{functionalActive:lt(),hasLimits:Mo()&&!lt(),hasRecorded:qi()&&!lt(),binMode:(a.plotMode??"hardBin")==="hardBin"||(a.plotMode??"hardBin")==="softBin"},e=>P(e),{on:!!a.compact,offered:Qi(),onChange:e=>P({compact:e}),onDiagnostics:()=>da(mn(),x.filter(e=>e!=null).map(e=>e.reticleConfig),{anchor:r,onSaveText:V.onSaveText})}),()=>ca(a)),{btn:es,sync:To}=ia(He,()=>({plotMode:a.plotMode,legendPosition:Ze}),e=>{Ze=e;for(const t of C)t&&t.setOptions({legendPosition:Ze})},{get:()=>bt,set:e=>{bt=e,Kn()},blockedReason:Qe});To();const ts=[{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"}],Lo=so("aggr","Aggregation method",()=>ts,()=>a.aggregationMethod??"mean",e=>P({aggregationMethod:e}));function Po(){const e=a.plotMode==="stackedValues";Lo.style.display=e?"":"none"}Po();const{btn:ns,sync:Wo}=oa(He,()=>({...a,functionalActive:lt()}),e=>P(e));Wo();const Tt=je("specRange","Colour bar range: test limits",()=>{const e=a.colorbarRangeMode==="data"?"spec":"data";P({colorbarRangeMode:e})});function Ro(){const e=(a.plotMode??"hardBin")==="value"&&Mo()&&ci(a)==="off"&&!lt();Tt.style.display=e?"":"none";const t=(a.colorbarRangeMode??"spec")==="spec";io(Tt,t),Tt.ariaLabel=t?"Colour bar range: test limits (click for data range)":"Colour bar range: data range (click for test limits)"}Ro();const os=aa(He,()=>a,e=>P(e)),is=je("downloadAll","Download gallery PNG",vs),Ne=je("boxSelect","Select the same dies on every wafer",()=>{le&&Ee.size>0?uo():Fi(!le)});Ne.style.position="relative";const rt=r.ownerDocument.createElement("span");rt.dataset.wmapSelectAcrossCount="1",Object.assign(rt.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"}),Ne.appendChild(rt);function Lt(){io(Ne,le);const e=le?Ee.size:0;rt.style.display=e>0?"block":"none",rt.textContent=e>99?"99+":String(e),Ne.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)",Ne.setAttribute("aria-pressed",String(le))}const ee=r.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"}),Pn(ee,"bare"),ee.addEventListener("click",Ii);const ss=so("columns","Columns",()=>[{value:"auto",label:"Auto (0)"},{value:"1",label:"1 column (1)"},{value:"2",label:"2 columns (2)"},{value:"3",label:"3 columns (3)"},{value:"4",label:"4 columns (4)"},{value:"5",label:"5 columns (5)"}],()=>T!=null?String(T):"auto",e=>Sn(e==="auto"?void 0:Number(e))),L=r.ownerDocument.createElement("div");Object.assign(L.style,{display:"inline-flex",alignItems:"center",gap:"0"}),H.appendChild(L),L.appendChild(ce),L.appendChild(Ki),L.appendChild(Lo),L.appendChild(ns),L.appendChild(Tt),L.appendChild(De()),L.appendChild(Ji),L.appendChild(De()),L.appendChild(es),L.appendChild(De()),L.appendChild(os),L.appendChild(De()),L.appendChild(ss),L.appendChild(De()),L.appendChild(Ne),L.appendChild(ee),L.appendChild(is),Lt();let te=null,Pt=null,ge=[],Ao=!1;function Te(){const e=ja({lotStatsSummary:se(),result:{warnings:[...B().flatMap(n=>n?.warnings??[]),...Ie().warnings]},extra:[a.binColors&&Ls(a.binColors,a.plotMode),Ps(Do),xi(_n())].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||!Ao)&&(Ao=!0,f.warnings?.onWarning?.(e)),as()}function as(){if(!te||!Pt)return;const e=ge.length,t=e>0;if(te.style.display=t?"flex":"none",Pt.style.display=t?"":"none",Zt(H),Qt(H,"inline-flex"),!t)return;const n=Na(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}(f.warnings?.display??!0)&&(Pt=De(),te=je("warning","Data warnings",()=>{const e=ot();if(Mt(new MouseEvent("click")),e)return;const t=za(te.getBoundingClientRect(),ge,te.ownerDocument.defaultView??window);li(r).appendChild(t),it(t),ri(t,te,()=>Mt(new MouseEvent("click")))}),gt(te,!1),H.appendChild(Pt),H.appendChild(te)),Te();function gn(e){import("./userGuideHtml.js").then(t=>ga({buildWaferMap:Pa,renderWaferMap:Ma,renderWaferGallery,analyzeWaferMap:$n},t.USER_GUIDE_HTML,O,r,e))}const ls=ha(e=>gn(e));D&&(H.appendChild(De()),H.appendChild(je("help","User guide",()=>gn())));const _e=r.ownerDocument.createElement("div");_e.dataset.wmapGalleryMeta="1",Object.assign(_e.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${M.sm} ${M.lg}`,fontSize:N.sub,lineHeight:oi.none,boxSizing:"border-box"});const Le=r.ownerDocument.createElement("div");Object.assign(Le.style,{background:w.canvasBg,display:"flex",alignItems:"stretch",gap:M.lg,paddingBottom:M.lg,minWidth:"0"});const he=r.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:Ln.panel,fontSize:N.body,lineHeight:oi.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const Z=r.ownerDocument.createElement("div");Object.assign(Z.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let ye=null,ct=null,Fo=null;function $o(){return I?ye?Promise.resolve(ye):(Fo??=Promise.all([import("./insightsTab.js"),qt()]).then(([{createInsightsTab:e},t])=>(ye=e({pageFilter:t,showFilterButton:!1,initialAxisPrefs:In(a),onAxisPrefsChange:n=>{a={...a,...Ha(n)};const o=[...Vn];f.onViewOptionsChange?.(Ht(a),o,An(o))},attributes:f.attributes,getItems:()=>W,getLotStats:()=>_,getBinColors:()=>a.binColors??K(),getRingCount:()=>ne({ringCount:yt()},"the Insights tab"),defaultView:f.insights?.defaultView,plotStore:$,onPickPlotsFile:f.insights?.onPickPlotsFile,showPatMap:()=>{Ge(!1),P({plotMode:"metadata",activeTest:void 0,activeMetadataKey:As,passFailDisplay:"off"})},showOnMap:n=>{if(Ge(!1),n.kind==="test")xt(),Oe(),vo(n.testNumber);else{const o=se(),i=o?La(o).findings.find(s=>s.id===n.id):void 0;i&&J!==i.id&&(xt(),So(i))}cn(!0),R()},onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,ownerDocument:r.ownerDocument,locateDie:(n,o)=>{Ge(!1),me(o,n)},openWafer:(n,o,i)=>{const s=B()[n];if(!s)return;let l=null;const u=Js({title:o,onClose:()=>l?.destroy(),anchor:r});qo(u,o,s.wafer.metadata??void 0),l=kn(u.contentWrap,s,i,void 0,di(u))}}),ct=ye.el,ct.style.display="none",r.appendChild(ct),ye)),Fo):Promise.resolve(null)}let Ke=!1,hn=null;function Ge(e){I&&(Ke=e,hn?.setInsightsOpen(e),ct&&(ct.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",Zt(H),Qt(H,"inline-flex"),H.style.display="inline-flex",re(),Ft(),e&&$o().then(t=>{!t||!Ke||(t.el.style.display="flex",t.render())}))}I&&f.insights?.defaultOpen&&queueMicrotask(()=>Ge(!0));const rs=6,cs=4,Wt=240,yn=480,ds=720,us=1.25;let Pe=yn;function Io(e){const t=z*2+110+2,n=Vo();if(n)return Math.ceil(n.across*cs+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*(rs/s),u=Math.ceil(l+t);(o==null||u>o)&&(o=u)}return o}function fs(e){const t=Io(e);return t==null?Wt:Math.min(Pe,Math.max(Wt,t))}function ps(e){const t=Io(e);if(t==null)return!1;const n=Math.min(ds,Math.max(yn,t));return n<=Pe?!1:(Pe=n,!0)}function Vo(){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 Ho(e,t){const n=Vo();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 ms(){for(const e of ue)e?.parentElement&&Ho(e.parentElement,e)}function jo(){Pe=yn,dt=Wt,vn(x.map(e=>e??null)),Rt(),ms()}function bn(){return zo()?`${Pe}px`:"none"}function zo(){return T==null&&!wn}let wn=!1;function Rt(){const e=bn();for(const t of Array.from(F.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let dt=Wt,No=0;function vn(e){if(ps(e)&&Rt(),T==null){const n=fs(e);n>dt&&(dt=n)}xn()}function Sn(e){T=wi(e),Rt(),xn()}let At=!1;r.addEventListener("pointerenter",()=>{At=!0}),r.addEventListener("pointermove",()=>{At=!0}),r.addEventListener("pointerleave",()=>{At=!1});const gs=()=>{if(At)return!0;try{return r.matches(":hover")}catch{return!1}},_o=e=>{if(e.ctrlKey||e.metaKey||e.altKey||e.shiftKey||e.defaultPrevented||Ke||!gs()&&!r.contains(e.target)||!/^[0-5]$/.test(e.key)||r.ownerDocument.querySelector('[role="dialog"]'))return;const t=e.target;typeof t?.closest=="function"&&t.closest('input, textarea, select, [contenteditable="true"], [role="menu"], [role="dialog"]')||(e.preventDefault(),Sn(e.key==="0"?void 0:Number(e.key)))};r.ownerDocument.addEventListener("keydown",_o);function Cn(e){return`repeat(${e}, minmax(0, ${zo()?`${Pe}px`:"1fr"}))`}function Ko(e){F.style.gridTemplateColumns!==e&&(F.style.gridTemplateColumns=e)}function xn(){if(T!=null){Ko(Cn(T));return}const e=Math.max(1,No),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(Pe,dt*us),u=d=>{let m=0;for(;m<e&&o(m+1)>=d;)m++;return m};i=u(l)||u(dt)||1}const s=n>0&&i<e;s!==wn&&(wn=s,Rt()),Ko(Cn(i))}const F=r.ownerDocument.createElement("div");if(Object.assign(F.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:Cn(1),gap:M.xl,paddingLeft:oe,paddingRight:oe,justifyContent:"start",alignContent:"start",isolation:"isolate"}),Re?.placement){const e=Re.placement;S=zn(e,oe,r.ownerDocument,an),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()||oo()){const e=!!Re?.defaultOpen;S=zn("right",oe,r.ownerDocument,an),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(),(Re?.placement??"right")==="left"?(S&&Z.appendChild(S),Z.appendChild(F)):(Z.appendChild(F),S&&Z.appendChild(S));const We=r.ownerDocument.createElement("div");Object.assign(We.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:oe,paddingRight:oe,paddingTop:oe,zIndex:"1",background:w.menuBg}),Le.appendChild(_e),Le.appendChild(H),Ct=Ms(r.ownerDocument,()=>cn(!rn())),Le.appendChild(Ct.el),re(),I&&(hn=xs(r.ownerDocument,"Maps","lot",e=>Ge(e)),Le.appendChild(hn.el)),I&&(St=ya(r.ownerDocument,"Filter\u2026","wmapGalleryFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>{qt().then(e=>e.openEditor(St??r,Yt()))}),St.style.order="1",Le.appendChild(St)),We.appendChild(Le),We.appendChild(he),r.appendChild(We),r.appendChild(Z);function Ft(){he.innerHTML="";const e=a.plotMode??"hardBin",t=!Ke&&si.has(e),n=x.filter(b=>b!=null&&!xe.has(b)),o=n.find(b=>b.isLotStack),i=Ga(n.map(b=>({metadata:b.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0,{curation:f.attributes}),s=e==="metadata",l=a.activeMetadataKey,u=t&&!s?vi(n,b=>(e==="softBin"?b.sbin:b.hbin)??void 0,Se):{counts:new Map,total:0,pass:0},d=t&&!s?a.binColors??K():void 0,m=d?e==="softBin"?d.pass.soft:d.pass.hard:new Set,v=va(u.counts.entries(),m).map(([b])=>b),p=t&&s&&l?vi(n,b=>Os(b.metadata?.[l])):{counts:new Map,total:0,pass:0},c=s?ko()?.values:void 0,g=t&&s?(c??[...p.counts.keys()].sort(jn)).filter(b=>p.counts.has(b)):[];if(_e.innerHTML="",i&&_e.appendChild(i),_e.style.display=i?"flex":"none",!v.length&&!g.length){he.style.display="none";return}he.style.display="flex";const h=r.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=Hn(a.highlightBin),E=x.flatMap(b=>b?.metadataFields??[]).find(b=>b.key===l),A=s?E?.label??(l?Ua(l):"Metadata"):Gs[e],j=r.ownerDocument.createElement("span");if(j.textContent=A,Object.assign(j.style,{fontSize:N.body,fontWeight:"700",letterSpacing:Ns,textTransform:"uppercase",color:w.label,flexShrink:"0"}),h.appendChild(j),!s&&u.total>0){const b=u.pass,G=b/u.total*100,be=r.ownerDocument.createElement("span");be.textContent=`Yield ${Nt(G)}`,Object.assign(be.style,{fontSize:N.body,fontWeight:"700",color:w.value,whiteSpace:"nowrap",flexShrink:"0"});const we=r.ownerDocument.createElement("span");we.textContent=`${b.toLocaleString()} / ${u.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=Hn(a.highlightMetadataValue);g.forEach((G,be)=>{const we=b.includes(G),Ye=E?.values?.find(On=>On.value===G),pt=Ye?.color??js(be),ti=p.counts.get(G)??0;Si(h,{color:pt,isActive:we,label:Ye?.label??G,count:ti,percent:p.total>0?ti/p.total*100:void 0,onClick:On=>{const Cs=yi(a.highlightMetadataValue,G,On);bo(),P({highlightMetadataValue:Cs})}})});return}const ft=e==="softBin"?x.flatMap(b=>b?.sbinDefs??[]):x.flatMap(b=>b?.hbinDefs??[]),Qo=new Set,Bn=[];for(const b of ft)Qo.has(b.bin)||(Qo.add(b.bin),Bn.push(b));const En=Bn.length>0?new Map(Bn.map(b=>[b.bin,b])):null,Jo=d??a.binColors??K(),Ss=e==="softBin"?Jo.soft:Jo.hard,ei=b=>Ss.get(b)??Hs;for(const b of v){const G=y.includes(b),be=En?.get(b),we=u.counts.get(b)??0;Si(h,{color:ei(b),isActive:G,label:be?.name?`${b} \xB7 ${be.name}`:`Bin ${b}`,count:we,percent:u.total>0?we/u.total*100:void 0,onMenu:(Ye,pt)=>Ri(e==="softBin"?"soft":"hard",b,Ye,pt),onClick:Ye=>{const pt=yi(a.highlightBin,b,Ye);bo(),P({highlightBin:pt})}})}u.total>0&&v.length>1&&he.appendChild(il(r.ownerDocument,[...u.counts.entries()].sort(([,b],[,G])=>G-b).map(([b,G])=>({color:ei(b),count:G,label:En?.get(b)?.name?`${b} \xB7 ${En.get(b).name}`:`Bin ${b}`})),u.total))}function qe(e){const t=B().filter(p=>p!==null&&!xe.has(p));if(!t.length)return[];const n=t.map(p=>p.dies.filter(tl).filter(c=>!c.filteredOut)),o=t[0].wafer,i=t.length,s=ni(t.map(p=>Ue(p)));if(!s)return[];const l=new Set(t.map(p=>ne(p,"renderWaferGallery")));if(l.size!==1)return[];const u=[...l][0],d=o.metadata?{...o,metadata:(({wafer:p,waferId:c,...g})=>g)(o.metadata)}:o;function m(p,c){return{...p,stats:{...p.stats,isLotStack:!0,aggregationMethod:c,lotSize:i}}}function v(p,c){const g=p.map(h=>({...h,hbin:void 0,sbin:void 0}));return $n({wafer:d,dies:g,passBins:[...s],ringCount:u,testDefs:[{testNumber:0,name:c}]},{testNumbers:[0]})}if(e==="stackedValues"){const p=tt();let c=p?.filter(Fn);if(p!==void 0&&c?.length===0)return[];if(p?.length||(c=ks(t.flatMap(y=>y.dies)).map(y=>({testNumber:y,name:Za(void 0,y)}))),!c?.length)return[];const g=a.aggregationMethod??"mean";return c.map(h=>{const y=xa(n,g,h.testNumber),E={testNumber:0,name:h.name,unit:h.unit,...Ja(h)};return{wafer:d,dies:y,passBins:[...s],ringCount:u,testDefs:[E],label:`${Qa(h,h.testNumber)} \xB7 ${g}`,isLotStack:!0,aggrMethod:g,lotSize:i,statsSummary:m($n({wafer:d,dies:y,passBins:[...s],ringCount:u,testDefs:[E]},{testNumbers:[0]}),g)}})}if(e==="stackedBins"){let p=Vt(t.map(c=>c?.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(c=>{const g=fi(n,c.bin,"hard"),h=[{bin:c.bin,name:c.name}];return{wafer:d,dies:g,passBins:[...s],ringCount:u,hbinDefs:h,label:`${c.bin} \xB7 ${c.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:m(v(g,`Wafers in hard bin ${c.bin}`),"countBin")}})}if(e==="stackedSoftBins"){let p=Vt(t.map(c=>c?.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(c=>{const g=fi(n,c.bin,"soft"),h=[{bin:c.bin,name:c.name}];return{wafer:d,dies:g,passBins:[...s],ringCount:u,sbinDefs:h,label:`${c.bin} \xB7 ${c.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:m(v(g,`Wafers in soft bin ${c.bin}`),"countBin")}})}return t}function $t(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 P(e,{fireCallback:t=!0}={}){const n=Object.keys(e);if(n.length>0&&n.every(c=>Vn.includes(c))){a={...a,...e},ye?.setAxisPrefs(In(a)),t&&f.onViewOptionsChange?.(Ht(a),n,An(n));return}Vn.some(c=>c in e)&&ye?.setAxisPrefs(In({...a,...e}));const o=a.plotMode,i=mt(a),s=Qe()!==null;a={...a,...e};const l=a.plotMode,u=ie.has(l),d=mt(a),m=o!==void 0&&ie.has(o),v=ke>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const c=K();a={...a,binColors:c},e={...e,binColors:c}}if("compact"in e){const c=Bo();a={...a,compactMap:c},e={...e,compactMap:c}}if(("compact"in e||a.compact&&("rotation"in e||"showXYIndicator"in e))&&jo(),e.plotMode!==void 0)if(u){const c=$t(l);if(a={...a,...c},v)for(const g of C)g&&g.setOptions(e);else X(qe(l))}else if(m){const{valueRange:c,lotSize:g,aggregationMethod:h,...y}=a;if(a=y,v)for(const E of C)E&&E.setOptions(e);else X(d?$e(W.filter(E=>E!==null)):B().filter(E=>E!==null))}else if(i!==d&&!v)X($e(W.filter(c=>c!==null)));else for(const c of C)c&&c.setOptions(e);else if(e.aggregationMethod!==void 0&&l==="stackedValues")if(v)for(const c of C)c&&c.setOptions(e);else X(qe("stackedValues"));else for(const c of C)c&&c.setOptions(e);Qe()!==null!==s&&Kn(),Ft(),Po(),To(),xo();const p=e.plotMode!==void 0&&e.plotMode!==o;(Ea.some(c=>c in e)||p)&&R(),Te(),Wo(),Ro(),un(),dn(),t&&f.onViewOptionsChange?.(Ht(a),n,An(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=bi(e,o,t,n,f.attributes);return{wrap:o,metaPanel:s}}function qo(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]");if(!o||qa(n??{}).length===0)return;const i=o.parentElement,s=r.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=bi(r.ownerDocument,s,t,n,f.attributes);l&&(e.contentWrap.style.position="relative",e.contentWrap.appendChild(l))}function Mn(e,t,n){const o=r.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:w.menuBg,border:`1px solid ${w.menuBorder}`,borderRadius:Y.container,boxShadow:Ln.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:bn(),maxHeight:bn()});const i=r.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 u=r.ownerDocument.createElement("button");u.dataset.wmapExpandBtn="1",u.setAttribute("aria-label","Open full view"),Wn(u),u.innerHTML=Tn.expand,Object.assign(u.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"}),Pn(u),i.appendChild(u),i.addEventListener("click",c=>{(c.ctrlKey||c.metaKey)&&(c.preventDefault(),c.stopPropagation(),$i(x.indexOf(e)))},!0),o.appendChild(i);const d=r.ownerDocument.createElement("div");Object.assign(d.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(d),Ho(o,d),l&&d.appendChild(l),F.appendChild(o),o.addEventListener("contextmenu",c=>{if(c.defaultPrevented)return;c.preventDefault();const g=e.viewOptions?{...a,...e.viewOptions}:a,h=sn()??go(t),y=h?.source??ka(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:c.clientX,y:c.clientY};import("./drilldown.js").then(({openDrilldownMenu:A})=>{o.isConnected&&A(E,o,y,h?{plots:$,getBinColors:()=>a.binColors??K(),attributes:f.attributes,...h.ctx}:{plots:$,getBinColors:()=>a.binColors??K(),attributes:f.attributes,onSaveImage:p.getSaveImageHook(),onSaveText:p.getSaveTextHook(),onLocateDie:j=>me(t,j)})})});const m=bt||Qe()!==null,v=e.viewOptions?{...a,...e.viewOptions}:a,p=pi(d,e,{viewOptions:{...v,showLegend:m,legendPosition:Ze},showTooltip:!0,padding:z,statsSummary:e.statsSummary,testValueOffer:en,onSaveImage:f.onSaveImage,onSaveText:f.onSaveText,downloadFilename:f.downloadFilename,onClick:e.onClick,onSelect:co(e),drilldownSourceOverride:()=>Wi(t),insights:de,onExpand:()=>ut(t,e),showIdentity:!1,chromeInset:Ks,drawWhenVisible:!0});return p.setViewControlsVisible(!1),p.setSummaryVisible(!1),u.onclick=()=>ut(t,e),xe.has(e)&&(o.style.display="none"),{card:o,ctrl:p,canvasWrapper:d,expandBtn:u}}function hs(e){const t=Fe[e];if(!t)return;const n=[...Q.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=Tn.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>bs(n.id)):(t.innerHTML=Tn.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>ut(e,x[e]))}function X(e){ws(),ot()?.remove(),it(null),Oe(),x=[],U.clear(),ln.clear(),ee.style.display="none";for(const d of C)d&&d.destroy();C=[],ue=[],Fe=[],ke=0,F.innerHTML="",No=e.length,vn(e.map(d=>typeof d=="function"?null:d));const t=[];for(let d=0;d<e.length;d++){const m=e[d];if(typeof m=="function"){const v=r.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=r.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),Fe.push(null),t.push({index:d,factory:m,placeholder:v}),ke++}else{const{ctrl:v,canvasWrapper:p,expandBtn:c}=Mn(m,d,e.length);x.push(m),C.push(v),ue.push(p),Fe.push(c)}}Oo(),Ft(),un(),dn(),Eo();const n=++nt,o=()=>{setTimeout(()=>{n===nt&&f.onItemsResolved?.()},0)},i=d=>{setTimeout(()=>{n===nt&&f.onItemResolved?.(d,e.length)},0)};let s=e.length-t.length;s>0&&i(s);let l=0;function u(){if(n!==nt)return;if(l>=t.length){if(ie.has(a.plotMode)){const A=a.plotMode;X(qe(A));return}if(wt){Ut();return}at=o,R(),ze||(at=null,o());return}const{index:d,factory:m,placeholder:v}=t[l++],p=m();W[d]=p;const c=Gt(p,d);Je(p,d)!==p&&(ae=!0),x[d]=c,vn([c]);const{card:g,ctrl:h,canvasWrapper:y,expandBtn:E}=Mn(c,d,e.length);C[d]=h,ue[d]=y,Fe[d]=E,ke--,v.replaceWith(g),i(++s),Ui(),Yi(),!S&&!Re?.placement&&c.statsSummary?.findings.length&&(S=zn("right",oe,r.ownerDocument,an),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.flexDirection="column",S.style.display="none",(Re?.placement??"right")==="left"?Z.insertBefore(S,F):Z.appendChild(S),R(),re()),re(),setTimeout(u,0)}t.length>0?setTimeout(u,0):o()}if(ie.has(a.plotMode)&&B().length>0){const e=$t(a.plotMode);a={...a,...e},X(qe(a.plotMode))}else X($e(k));f.insights?.filter!==void 0&&qt(),Te();let Xe=0;const Xo=new(r.ownerDocument.defaultView??window).ResizeObserver(()=>{if(Xe)return;Xe=(r.ownerDocument.defaultView??window).requestAnimationFrame(()=>{Xe=0,T==null&&xn()})});Xo.observe(F);const Yo=()=>{r.style.setProperty("--wmap-sticky-top",`${We.offsetHeight}px`)};Yo();const Uo=new(r.ownerDocument.defaultView??window).ResizeObserver(Yo);Uo.observe(We),S&&R();function ys(e,t){const n=ue[e];if(!n)return;n.innerHTML="",Object.assign(n.style,{alignItems:"center",justifyContent:"center"});const o=r.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=ki++,i=C[e]?.getOptions(),s=Zs(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}),ea(r,l.documentElement);const u=ta(r,l.documentElement,()=>y.setOptions({})),d=l.createElement("div");d.dataset.wmapWindowBanner="1",d.textContent=n,Object.assign(d.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(d);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),c=l.createElement("div");Object.assign(c.style,{display:"flex",alignItems:"center",padding:`${M.md} ${M.lg} ${M.sm}`,borderBottom:`1px solid ${w.menuBorder}`,flexShrink:"0",gap:M.sm}),c.appendChild(v),m.appendChild(c);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=kn(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:u,close:()=>{s.closed||s.close()},setTitle:A=>{l.title=A,d.textContent=A,d.style.display="block"}})}else{const l=Qs({title:n,onClose:()=>It(o),anchor:r});l.contentWrap.style.flexDirection="column",qo(l,n,t.wafer.metadata??void 0);const u=kn(l.contentWrap,t,void 0,i,di(l));Q.set(o,{id:o,ctrl:u,cardIndex:e,label:n,closePollId:null,close:()=>l.close(),setTitle:d=>{const m=l.box.querySelector("[data-wmap-window-title]");m&&(m.textContent=d,m.title=d)}})}C[e]?.destroy(),C[e]=null,ys(e,s!==null),hs(e)}function kn(e,t,n,o,i){const s=t.viewOptions?{...a,...t.viewOptions}:a,l=o?{...s,...o}:s,d={...n!==void 0?{...l,plotMode:"value",activeTest:n}:l,showLegend:!0,legendPosition:Ze},m=pi(e,t,{viewOptions:d,showTooltip:!0,padding:z,statsSummary:t.statsSummary,testValueOffer:en,onSaveImage:f.onSaveImage,onSaveText:f.onSaveText,downloadFilename:f.downloadFilename,onClick:t.onClick,onSelect:co(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:u}=Mn(o,n,x.length);ue[n]?.parentElement?.replaceWith(i),C[n]=s,ue[n]=l,Fe[n]=u}function bs(e){const t=Q.get(e);t&&(t.close(),It(e))}function ws(){for(const e of Q.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function Dn(){for(const e of C)e?.drawPendingNow()}const Zo=r.ownerDocument.defaultView??window;Zo.addEventListener("beforeprint",Dn);function vs(){Dn();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,u=(r.ownerDocument.defaultView??window).devicePixelRatio||1,d=Math.round(26*u),m=Math.round(12*u),v=r.ownerDocument.createElement("canvas");v.width=n*i+(n-1)*l,v.height=o*(s+d)+(o-1)*l;const p=v.getContext("2d"),c=zs(F);p.fillStyle=c.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+d+l),ft=g.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";p.fillStyle=c.surface,p.fillRect(A,j,i,d),p.fillStyle=c.text,p.font=`700 ${m}px system-ui, sans-serif`,p.textAlign="left",p.textBaseline="middle",p.fillText(ft,A+Math.round(10*u),j+d/2,i-Math.round(20*u)),p.drawImage(g,A,j+d)}),v.toBlob(g=>{if(!g)return;const h=C.find(y=>y!=null)?.getExportTitle();la(g,["gallery",h].filter(Boolean).join(" "),V.onSaveImage)})}return{setItems(e){tn(),W=e.map(n=>typeof n=="function"?null:n);const t=a.plotMode;if(ie.has(t))if(e.some(o=>typeof o=="function"))X($e(e));else{const o=$t(t);a={...a,...o},X(qe(t))}else X($e(e));Jn()},setOptions(e){P(e,{fireCallback:!1})},getOptions(){return Ht(a)},setFindingsNotice(e){lo=e,R()},setColumns(e){Sn(e)},getBinColors(){return a.binColors??K()},setLotStatsSummary(e){tn(),_=e,Jn(),Te(),S&&R(),re()},openUserGuide:()=>gn(),destroy(){ls(),$.flush(),tn(),nt++,Zo.removeEventListener("beforeprint",Dn),r.ownerDocument.removeEventListener("keydown",_o),ze?.cancel(),ze=null,at=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=[],ot()?.remove(),Xo.disconnect(),Uo.disconnect(),Xe&&((r.ownerDocument.defaultView??window).cancelAnimationFrame(Xe),Xe=0),r.ownerDocument.removeEventListener("click",Mt,!0),window.removeEventListener("blur",ao),Ci(),ai(),We.remove(),Z.remove(),S?.remove(),_t=!0,vt++,clearTimeout(Xt),fe?.el.remove(),ye?.destroy()}}}
@@ -1 +1 @@
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()}}}
1
+ import{createViewSwitch as Io}from"./viewSwitch.js";import{createSummaryToggle as Vo}from"./summaryToggle.js";import{buildView as zo,buildHoverText as Yo,findTestDef as Zt,resolveTestNumber as Fn,buildMapTitle as Ho}from"../renderer/buildView.js";import{drawMapCanvas as _o,BIN_LEGEND_W as Yi,BIN_LEGEND_W_COMPACT as Xo,BIN_LEGEND_ADAPT_COMPACT as Ko,BIN_LEGEND_ADAPT_FLOATING as No,PATH_SHAPES as jo}from"./toCanvas.js";import{buildWaferMap as $o,computeCoverage as Hi,computeYield as _i,defaultBinMode as Go,getTestPassStatus as Uo,isParametricTest as Rn,isBuiltMap as An}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Wn}from"../stats/analyzeWaferMap.js";import{SHADOW as Zo,LEADING as Xi,wireControlHover as Ki,SPACE as V,EDGE_GUTTER as qo,RADIUS as Ni,FONT as qt,CLR as A,applyOverlayZ as Qo,getTooltip as ji,hideTooltip as Qt,positionTooltip as $i,createToolbarHelpers as Jo,buildModeMenuEl as es,openReparentedModal as ts,makePaletteBtn as ns,makeLogScaleBtn as is,makeLegendStyleBtn as os,makeOverlaysBtn as ss,makeOrientationBtn as ls,menuLayerFor as Gi,saveImageBlob as as,markMenuTrigger as mt,wireMenuA11y as Ui,wireExpandToggle as rs,nextFrame as In,requestedPassFailDisplay as ds,overlayMenuRows as cs,anyOverlayActive as fs,openCompactDiagnostics as us,roomForPanel as ps,logWmapVersionOnce as hs,buildDataModeEntries as gs,metadataKeyHasData as ms,metadataModeEntry as Zi}from"./toolbar.js";import{openUserGuideWindow as ys,registerGuideOpener as bs}from"./guideWindow.js";import{waferIdentityLabel as vs}from"../core/waferLabel.js";import{metadataDisplayValue as ws}from"../core/metadata.js";import{withExportContext as xs}from"./exportName.js";import{testValueNotice as Cs}from"./testValueOffer.js";import{axisPrefsFromOptions as qi,optionsFromAxisPrefs as Ss,CHART_PREF_KEYS as Vn}from"./chartPrefs.js";import{createSummaryPanelEl as zn,wrapWithSummaryPanel as Yn,renderWaferSummaryContentSteps as Ms}from"./summaryPanel.js";import{runChunked as Es}from"./chunked.js";import{collectWarnings as Bs,buildWarningsMenuEl as ks,severityOf as Ds}from"./warnings.js";import{plotStoreFor as Ps}from"./plotStore.js";import{selectionPopulation as Ts,waferPopulation as Ls}from"./chartPopulation.js";import{sourceFromBins as Qi}from"./plotItems.js";import{createIdentityHeader as Os,collapsedLabel as Hn}from"./identityHeader.js";import{getDieKey as de,hasPosition as Ji,isPositionedDie as Fs}from"../core/dies.js";import{bandButton as Rs}from"./filterButton.js";import{buildDieListSection as As}from"./dieList.js";import{buildMaplessSummary as Ws}from"./maplessSummary.js";import{resolveBinColors as Is,binColorWarning as Vs}from"../renderer/binColors.js";import{isPassBin as zs,requirePassBins as Ys}from"../core/passBins.js";import{PAT_MODE_FIELD as Hs,PAT_MODE_KEY as _s,isPatMode as eo,patModeOffered as Xs,withPatField as Ks,withPatVerdicts as Ns}from"./patMode.js";import{requireRingCount as ze}from"../core/ringCount.js";import{asList as js,toggleHighlight as to}from"../core/utils.js";import{buildCompactMap as $s,compactLayoutOffered as Gs}from"../core/compact.js";const Us={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(Us);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&&zs(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={}){hs();const u=P.ownerDocument,B=u.defaultView??window,Je=()=>C.label,yt=()=>vs({label:Je(),wafer:$}),ce=xs(()=>{const e=ws($.metadata?.lot);return{prefix:y.downloadFilename,lots:e!==void 0?[e]:[],...C.isLotStack?{stackedWafers:g?.lotSize??!0}:{wafer:yt()}}},y.onSaveImage,y.onSaveText);function _n(){const e=g.plotMode==="softBin"||g.plotMode==="stackedSoftBins"?oe:ie,{primary:n,secondary:t}=Ho(g,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 Ee=u.createElement("div");Object.assign(Ee.style,{position:"relative",width:"100%",flex:"1 1 auto",minHeight:"0"});const me=y.chromeInset??qo,z=u.createElement("div");Object.assign(z.style,{display:"flex",alignItems:"stretch",gap:V.sm,background:A.canvasBg,paddingBottom:V.lg,paddingTop:me,paddingLeft:me,paddingRight:me,flexShrink:"0",minWidth:"0"}),Ye.appendChild(z),Ye.appendChild(Ee);function He(){const e=[...z.children].some(n=>n.style.display!=="none");z.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),Ee.appendChild(M);let bt=null;if(Jt>0){let t=function(){if(n){const l=As(e,h.testDefs,{...y.dieList,onSaveText:ce.onSaveText,waferMetadata:$.metadata,metadataFields:Ne,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 Ws(e,h.testDefs,{plotMode:d.plotMode??"hardBin",activeTest:d.activeTest,hbinDefs:ie,sbinDefs:oe,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",Ki(s),Object.assign(s.style,{fontSize:qt.body,padding:`${V.xxs} ${V.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:V.xl,boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",gap:V.md,zIndex:"1"});const s=u.createElement("div");Object.assign(s.style,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:V.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:`${V.xs} ${V.md}`,display:"flex",alignItems:"center",justifyContent:"space-between",gap:V.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;rs(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:V.md,boxSizing:"border-box",display:"flex",flexDirection:"column",gap:V.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:fe,onViewOptionsChange:Xn,showTooltip:so=!0,showToolbar:Be=!0,showIdentity:Kn=!0,summaryPanel:tt,showHelpButton:Nn=!1,userGuideExtension:lo,onExpand:jn,showExpandButton:$n=!0,zIndex:ao,insights:J,warnings:Gn,viewOptions:ro={},..._e}=y,ke=J?.enabled??Be;let nt=null,Xe=null;ke&&(nt=Io(u,"Map","wafer",e=>Ce(e)),Be||(nt.el.style.marginLeft="auto"),z.appendChild(nt.el)),ke&&(Xe=Rs(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(Xe??P,[St()]))}),Xe.style.order="1",z.appendChild(Xe));const co=.4,fo=20,ne=[...Ys(h,"renderWaferMap")],Un=Gn?.display??!0,uo=Qo(ao);let ue=y.statsSummary,De=!1,wt;const pe=()=>De?wt:ue;let we=[],Zn=!1,xt=null,qn=!1;function en(){const e=Bs({result:h,statsSummary:pe(),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,$=h.wafer,Ct=h.dies,W=h.dies,xe=null,Qn=null,Pe=null;const St=()=>({dies:Ct,wafer:$,label:Je()??"Wafer",identity:yt(),waferIndex:0,passBins:ne,testDefs:K,statsSummary:ue});function tn(){const e=xe?.get();if(wt=void 0,!xe||!e||e.off)return De=!1,Ct;const n=xe.mark([St()]);De=n.narrowing;const t=n.items[0].dies;if(De&&ue&&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)},ue.analysisOptions)}catch{wt=void 0}}return t}function Jn(){if(!xe||!Pe)return;const e=[St()];Pe.refresh(xe.keep(e).result,e),Pe.el.style.display=xe.get()&&!ge?"":"none"}function ei(){W=tn(),Jn(),at(),x(),gn(ue)}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:()=>ze(C,"renderWaferMap")});return xe=n,Pe=n.createBand(()=>[St()],{marginLeft:me,marginRight:me,marginBottom:V.lg}),Ye.insertBefore(Pe.el,Ee),n.subscribe(()=>{Ke||ei()}),n.get()&&!Ke&&ei(),n}),Qn}let w=new Set,Te=null;const on=J?.plotStore??Ps(J),Mt={plots:on,getBinColors:()=>g.binColors,attributes:y.attributes,onSaveImage:ce.onSaveImage,onSaveText:ce.onSaveText,onLocateDie:e=>Kt(e)},Et=()=>!et;let sn=null,Bt=null,kt=!1,Ke=!1,ie=h.hbinDefs,oe=h.sbinDefs,K=h.testDefs,Ne=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,he=null,Pt=null;function Tt(e){Pt&&(Pt.style.display=e?"flex":"none",Ze?.())}Kn&&(ee=Os(Hn($.metadata??{},it())??"",$.metadata,{lotStack:it(),ownerDocument:u,attributes:y.attributes}),M.appendChild(ee.metaPanel),ee.metaPanel.style.visibility="visible",ee.isEmpty()||(he=ii(ee.wrap),z.insertBefore(he,z.firstChild),He()));function ii(e){const n=u.createElement("div");return Object.assign(n.style,{display:"flex",alignItems:"center",padding:`${V.sm} ${V.lg}`,flex:"1 1 auto",minWidth:"0",overflow:"hidden",gap:V.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($.metadata??{},it())??"",$.metadata,it());const e=he?.isConnected??!1,n=!ee.isEmpty();!n&&e?(he.remove(),he=null):n&&!e&&(he=ii(ee.wrap),he.style.display="",z.insertBefore(he,z.firstChild),He())}const ho=[...ie??[],...oe??[]].some(e=>e.color);let d={plotMode:Go([h.dies]),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,showReticle:!1,showXYIndicator:!1,compact:!1,rotation:0,flipX:!1,flipY:!1,legendPosition:"default",...ro},N=null,ge=!1,oi=null;function si(){return ke?N?Promise.resolve(N):(oi??=Promise.all([import("./insightsTab.js"),nn()]).then(([{createInsightsTab:e},n])=>(N=e({pageFilter:n,showFilterButton:!1,initialAxisPrefs:qi(d),onAxisPrefsChange:t=>{d={...d,...Ss(t)};const i=[...Vn];Xn?.(d,i,classifyChanged(i))},attributes:y.attributes,getItems:()=>[{wafer:$,dies:Ct,hbinDefs:ie,sbinDefs:oe,testDefs:K,label:Je(),passBins:ne,ringCount:ze(C,"renderWaferMap"),statsSummary:ue}],getBinColors:()=>g.binColors,getRingCount:()=>ze(C,"renderWaferMap"),onSaveImage:ce.onSaveImage,onSaveText:ce.onSaveText,defaultView:J?.defaultView,plotStore:on,onPickPlotsFile:J?.onPickPlotsFile,showPatMap:()=>{Ce(!1),L({plotMode:"metadata",activeTest:void 0,activeMetadataKey:_s,passFailDisplay:"off"})},showOnMap:t=>{if(Ce(!1),t.kind==="test")ui(t.testNumber);else{const i=pe()?.findings.find(o=>o.id===t.id);i&&pi(i)}pe()&&Ht(!0)},showMetadataStrip:!1,contentInset:me,onOpenGuide:Nn&&!Be?()=>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(N.el.style,{position:"absolute",inset:"0",background:A.canvasBg,overflowY:"auto",paddingTop:"0"}),N.el.style.setProperty("--wmap-sticky-top","0px"),N.el.style.display="none",Ee.appendChild(N.el),N)),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||!ge?!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=ge?"hidden":"")}function Ce(e){if(!ke)return;const n=ge;ge=e,nt?.setInsightsOpen(e),Pe&&(Pe.el.style.display=xe?.get()&&!e?"":"none"),N&&!e&&n&&(li=N.el.scrollTop),N&&(N.el.style.display=e?"flex":"none"),M.style.visibility=e?"hidden":"",cn(),X&&(X.style.display=e||et?"none":"flex"),I&&(I.style.display=e?"none":"flex"),Tt(!Ae),le&&(le.style.display="flex"),he&&(he.style.display=""),He(),Ze?.(),ee&&e&&ee.collapse(),ct(),e&&si().then(t=>{!t||!ge||(t.el.style.display="flex",t.render(),go(t.el,li))})}ke&&J?.defaultOpen&&queueMicrotask(()=>Ce(!0));let g,Le,G=null,O=null,Lt=[],fn;function ai(e){fn!==e&&(fn=e,x())}let Oe=null,un=_e.legendOffset??{x:0,y:0},ot=!1,je=!1,st={x:0,y:0},pn={x:0,y:0},Fe=!1,$e=!1,U="select",Ge={x:0,y:0},Ot={x:0,y:0},Y={x:0,y:0},H={x:0,y:0},lt=!1,Ue=!1;const hn=()=>eo(d)?Ks(Ne):Ne;function at(){const e=d,i=(eo(e)?Ns(W,K,ne):W).filter(Fs);g=zo($,i,{compact:d.compact?d.compactMap??$s(i):void 0,plotMode:e.plotMode,binColorScheme:e.binColorScheme,valueColorScheme:e.valueColorScheme,reverseValueScheme:e.reverseValueScheme,useDefinedBinColors:e.useDefinedBinColors,binColors:e.binColors??Is(W,{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:ze(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()}),Le=void 0;const o=e.binColors?null:Vs(g.binColors,g.plotMode);o?.message!==xt?.message&&(xt=o,en(),qn&&yn())}at();function ri(){return d.showAxes??_e.showAxes??O!==null}function mo(){return Gs(W,[Dt])}let Z=null,Re=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!==ue;if(ue=e,n&&De&&(W=tn(),at(),x()),en(),yn(),Z)se();else if(F)Wt();else if(e&&!tt?.placement){const t=tt?.defaultOpen??!Be;F=zn("right",me,u,Dn),F.style.display=t?"block":"none";const i=M.parentElement,o=M.nextSibling;be=Yn(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)?Cs(pe()?.stats.testValueAnalysis,1,rt,bo):void 0);function bo(){const e=ue,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||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||ue!==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=W.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")&&Yt(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=Es(Ms(e,{wafer:$,dies:W,yieldSummary:De?_i(W,ne,C.yield?.yieldPercentGross!=null?"denominator-only":"exclude"):C.yield,dataCoverage:De?Hi(W.filter(t=>!t.filteredOut)):C.dataCoverage,hbinDefs:ie,sbinDefs:oe,testDefs:K,statsSummary:pe(),warnings:Un?we:[],passBins:ne,ringCount:ze(C,"renderWaferMap"),binColors:g.binColors,plotMode:d.plotMode??"hardBin",metadataShownElsewhere:Kn,fallbackFormat:d.fallbackFormat,activeFindingId:ye,findingsFilter:vo,findingsNotice:yo(),onFindingsFilterChange:se,onSaveText:ce.onSaveText,metadataFields:Ne,dieListOptions:y.dieList,onLocateDie:t=>Kt(t),attributes:y.attributes,onClose:Be&&pe()?()=>Ht(!1):void 0,activeTest:Se,onTestClick:t=>{Se===t?(Se=null,Yt([]),ci(),se()):ui(t)},onFindingClick:(t,i)=>{ye===t.id?(ye=null,Yt([]),ci(),se()):pi(t)},onShowChart:ke?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}),Yt(pe()?.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=zn(e,me,u,Dn);const n=M.parentElement,t=M.nextSibling;Re=Yn(M,Z,e),n?.insertBefore(Re,t),se()}else if(pe()){const e=tt?.defaultOpen??!Be;F=zn("right",me,u,Dn),F.style.display=e?"block":"none";const n=M.parentElement,t=M.nextSibling;be=Yn(M,F,"right"),n?.insertBefore(be,t),Wt()}cn();const _=so?ji(u):null;let le=null,j=null,Ze=null,X=null,I=null,It=null,Vt=null,hi=!0,gi=null,ve=null,zt=null;qn=!0;function yn(){if(!ve||!zt)return;const e=we.length,n=e>0;if(ve.style.display=n?"flex":"none",zt.style.display=n?"":"none",Ze?.(),!n)return;const t=Ds(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 Me(e="selection"){ye===null&&Se===null||(ye=null,Se=null,Ft=null,e==="selection"?L({highlightBin:void 0}):(w=new Set,fe?.([])),se())}function Yt(e){w=new Set(e??[]),fe&&fe(We()),x()}function ct(){if(!Vt)return;Ze?.();const e=Z??F;Vt.sync({visible:hi&&!!pe()&&!!e&&!ge,open:!!e&&e.style.display!=="none",notable:!!pe()?.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(Be){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:Zo.panel,pointerEvents:"auto"});const e=ji(u),n=Jo(e),{makeBtn:t,setActive:i,makeSep:o,syncSeparators:s,syncToolbarVisible:l,makeMenuRow:r,makeMenuSection:c,closeOpenMenu:f,getOpenMenu:p,setOpenMenu:b}=n;Ze=()=>{j&&s(j),le&&l(le,"flex"),He()},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(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},re=function(m,E){m.activeTest!==void 0?L({plotMode:m.plotMode,activeTest:m.activeTest,activeMetadataKey:void 0,logScale:m.logScale}):m.activeMetadataKey!==void 0?L({plotMode:m.plotMode,activeTest:void 0,activeMetadataKey:m.activeMetadataKey,passFailDisplay:"off"}):L({plotMode:m.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),E.remove(),b(null),mt(Q,!1)};j=u.createElement("div"),Object.assign(j.style,{display:"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),le.appendChild(j),I=u.createElement("div"),Object.assign(I.style,{display:"flex",alignItems:"center",gap:"0"}),j.appendChild(I),I.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=W,E=g.testDefs,{testEntries:Gt,binEntries:Ie,stackedEntries:ht}=gs(m,E,{includeStacked:g.isLotStack}),Ut=(Ne??[]).filter(Ve=>ms(m,Ve.key)).map(Zi);Xs([{dies:m,testDefs:E}])&&Ut.push(Zi(Hs));const gt=es(Q.getBoundingClientRect(),Gt,Ie,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}=ns(n,()=>({...d,plotMode:d.plotMode??"hardBin"}),()=>ho,L);wn=On,wn();const To=ss(n,()=>{const m=!!g.hasReticle,E=(d.plotMode??"hardBin")==="value",{testNumber:Gt}=Fn(d.activeTest??0,g.testDefs),Ie=Zt(g.testDefs,Gt),ht=E&&Ie!==void 0&&!Rn(Ie),Ut=E&&!ht&&(Ie?.limitLow!==void 0||Ie?.limitHigh!==void 0),gt=E&&!ht&&g.dies.some(Ve=>Uo(Ve,Gt,Ie)!==void 0);return cs({...d,showAxes:ri()},m,{functionalActive:ht,hasLimits:Ut,hasRecorded:gt,binMode:(d.plotMode??"hardBin")==="hardBin"||(d.plotMode??"hardBin")==="softBin"},Ve=>L(Ve),{on:!!d.compact,offered:mo(),onChange:Ve=>L({compact:Ve}),onDiagnostics:()=>us(W,[Dt],{anchor:a,onSaveText:ce.onSaveText})})},()=>fs(d)),{btn:Lo,sync:Oo}=os(n,()=>d,m=>L({legendPosition:m}));vn=Oo,vn();const zi=()=>{const{testNumber:m}=Fn(d.activeTest??0,K),E=Zt(K,m);return E!==void 0&&!Rn(E)},{btn:Fo,sync:Ro}=is(n,()=>({...d,functionalActive:zi()}),m=>L(m));xn=Ro,xn();const Ao=()=>{const{testNumber:m}=Fn(d.activeTest??0,K),E=Zt(K,m);return E!==void 0&&(E.limitLow!==void 0||E.limitHigh!==void 0)},$t=t("specRange","Colour bar range: test limits",()=>{const m=d.colorbarRangeMode==="data"?"spec":"data";L({colorbarRangeMode:m})});Cn=()=>{const m=d.plotMode==="value"&&Ao()&&ds(d)==="off"&&!zi();$t.style.display=m?"":"none";const E=(d.colorbarRangeMode??"spec")==="spec";i($t,E),$t.ariaLabel=E?"Colour bar range: test limits (click for data range)":"Colour bar range: data range (click for test limits)"},Cn();const Wo=ls(n,()=>d,m=>L(m));I.appendChild(Q),I.appendChild(Ln),I.appendChild(Fo),I.appendChild($t),et||(I.appendChild(o()),I.appendChild(To),I.appendChild(o()),I.appendChild(Lo),I.appendChild(o()),I.appendChild(Wo)),Vt=Vo(u,()=>{const m=Z??F;m&&Ht(m.style.display==="none")}),z.insertBefore(Vt.el,nt?.el??null),ct(),Un&&(zt=o(),ve=t("warning","Data warnings",()=>{const m=p();if(f(new MouseEvent("click")),m)return;const E=ks(ve.getBoundingClientRect(),we,B);Gi(Ee).appendChild(E),b(E),Ui(E,ve,()=>f(new MouseEvent("click")))}),mt(ve,!1),j.appendChild(zt),j.appendChild(ve),yn()),$n&&(j.appendChild(o()),Pt=t("expand","Expand (E)",jn??yi),j.appendChild(Pt)),Nn&&(j.appendChild(o()),gi=t("help","User guide",()=>jt()),j.appendChild(gi)),Ze?.()}z.appendChild(le),Xe&&z.appendChild(Xe),He()}let Ae=null,_t=null;function yi(){Ae&&(Ae.close(),Ae=null);const e=Ee;e.style.flex="1",e.style.minWidth="0",e.style.minHeight="0";const n=Hn($.metadata??{},it()),t=z.childElementCount>0?[z,e]:[e],i=ts(t,{ownerDocument:u,boxSize:ge?{width:"min(96vw, 1600px)",height:"min(92vh, 1000px)"}:void 0,onClosed:()=>{Ae=null,_t=null,Tt(!0),ge||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=ps(i);const o=Z??F,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&&_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)&&N?.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?.(),x();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=>{qe=e[e.length-1].isIntersecting,qe&&Xt&&x()},{rootMargin:"25%"}):null;let qe=Mn===null,Xt=!1;Mn?.observe(a);function En(){Sn||(Sn=!0,In(()=>{Sn=!1,x()},B))}function x(){if(!qe){Xt=!0;return}Xt=!1;const e=O??void 0,n=g.dies[0],t=n?{x:n.width,y:n.height}:_e.diePitchMm,i=Math.floor(a.clientWidth||a.width),o=!!(ie?.length||oe?.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=(_e.colorbarWidth??16)+28,f=o&&r?s!=="default"?Math.max(Yi,c):i<No?0:i<Ko?Math.max(Xo,c):Math.max(Yi,c):void 0,p=_o(a,g,{..._e,minRightReserve:l?f:0,showColorbar:l&&(_e.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:w.size>0||Te!==null?xo:void 0,hbinDefs:ie,sbinDefs:oe,metadataFields:hn()});Lt=p.binLegendRows,Oe=p.legendBox??null,O===null&&(G=p.viewport),$e&&Eo(),Bi()}function xo(e,n,t){w.size>0&&So(e,n,t),Te!==null&&Co(e,n,t)}function Co(e,n,t){Le??=new Map(g.dies.map((b,R)=>[de(b),R]));const i=Te===null?void 0:Le.get(Te);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(Te=e===null?null:de(e),e!==null&&O!==null){ut();return}x()}function vi(){Te!==null&&(Te=null,x())}function So(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&&(Le??=new Map(g.dies.map((v,k)=>[de(v),k])));for(const v of w){const k=Le.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===jo&&(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=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[Le.get(`${c.x+1},${c.y}`),Le.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(Y.x,H.x),t=Math.min(Y.y,H.y),i=Math.abs(H.x-Y.x),o=Math.abs(H.y-Y.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=qe;qe=!0,x(),qe=e}function Bo(){wi(),a.toBlob(e=>{e&&as(e,_n(),ce.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},x()}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},x()}}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(Oe&&d.legendPosition==="floating"&&Bn(t,i,Oe)){je=!0,st={x:t,y:i},pn={...un};return}if(lt&&U!=="pan"){Ue=!0,Fe=!0,Ge={x:t,y:i},Ot={x:te().originX,y:te().originY},a.style.cursor="grabbing";return}if(U==="zoom"||U==="select"){$e=!0,Y=H={x:t,y:i};return}Fe=!0,Ge={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($e){H={x:t,y:i},En();return}if(je){const p=t-st.x,b=i-st.y;p*p+b*b>16&&(je=!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(Fe){const p=te(),b=O?.snapDist??G?.snapDist??1;O={originX:Ot.x+(t-Ge.x),originY:Ot.y+(i-Ge.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,g.plotMode,{testDefs:K,hbinDefs:ie,sbinDefs:oe,fallbackFormat:d.fallbackFormat,aggrMethod:g.aggrMethod,lotSize:g.lotSize,metadataFields:hn(),activeTest:g.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"),$e){$e=!1,H={x:t,y:i};const r=t-Y.x,c=i-Y.y,f=te();if(U==="zoom"){if(r*r+c*c<25)Qe(t,i,2);else if(f){const p=Math.min(Y.x,H.x),b=Math.max(Y.x,H.x),R=Math.min(Y.y,H.y),ae=Math.max(Y.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}}}x(),a.style.cursor="crosshair";return}if(r*r+c*c<25)kn(t,i,o,e);else if(f){const p=(Math.min(Y.x,H.x)-f.originX)/f.ppm,b=(Math.max(Y.x,H.x)-f.originX)/f.ppm,R=(f.originY-Math.max(Y.y,H.y))/f.ppm,ae=(f.originY-Math.min(Y.y,H.y))/f.ppm,v=g.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=g.dies[S];D&&k.push(D)}if(o)for(const S of k){const D=de(S);w.has(D)?w.delete(D):w.add(D)}else w=new Set(k.map(S=>de(S)));Me(),fe?.(We())}x(),a.style.cursor="crosshair";return}if(je){je=!1,kn(t,i,o,e);return}if(ot){ot=!1,a.style.cursor="grab";return}if(!Fe)return;if(Fe=!1,Ue){Ue=!1,a.style.cursor=lt||U==="pan"?"grab":"crosshair";return}a.style.cursor=U==="pan"?"grab":"crosshair";const s=t-Ge.x,l=i-Ge.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){Me("legend"),typeof r.bin=="number"?L({highlightBin:to(d.highlightBin,r.bin,t)}):L({highlightMetadataValue:to(d.highlightMetadataValue,r.bin,t)});return}if(Oe&&Bn(e,n,Oe))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=de(l);t?w.has(r)?w.delete(r):w.add(r):w.size===1&&w.has(r)?w=new Set:w=new Set([r]),Me(),fe?.(We()),x()}else t||(w=new Set,Me(),fe?.([]),x())}function We(){const e=[],n=g.hoverPoints;for(let t=0;t<n.length;t++){const i=g.dies[t];i&&w.has(de(i))&&e.push(i)}return e}function Bi(){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 ki(){const e={waferLabel:yt(),testDefs:K,isLotStack:C.isLotStack,wafer:C.wafer,passBins:ne,ringCount:ze(C,"renderWaferMap"),activeTest:d.plotMode==="value"?d.activeTest:void 0};return w.size>0?Ts(We(),e,W):Ls(W,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=js(d.highlightBin),o=i.length>1&&i.includes(e)?[...i]:[e],s=[{label:yt()??"this wafer",dies:W,wafer:C.wafer,passBins:ne,ringCount:ze(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})=>{Ke||(sn=p(n,f,l,r))})}function Do(){const e=new Set;for(const n of g.dies){const t=de(n);w.has(t)||e.add(t)}w=e,Me(),fe?.(We()),x()}function Pn(e,n){if(!Et())return;const t=y.drilldownSourceOverride?.(),i=t?.source??ki(),o={...Mt,...t?.ctx};if(!t&&w.size>0&&(o.onInvertSelection=Do),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})=>{Ke||(sn=s(e,n,i,o))})}function Di(e){e.stopPropagation();const n=kt;if(kt=!1,!Et()||ge)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(Oe&&Bn(o,s,Oe))return;const r=te(),c=r?Tn((o-r.originX)/r.ppm,(r.originY-s)/r.ppm,r.snapDist)?.die:void 0;c&&!w.has(de(c))&&(w=new Set([de(c)]),Me(),fe?.(We()),x())}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(){Fe=!1,Ue=!1,$e=!1,je=!1,ot=!1,_&&Qt(u),vt?.(null,new MouseEvent("mouseleave")),a.style.cursor=U==="pan"?"grab":"crosshair",x()}function Tn(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 B.ResizeObserver(()=>{G=null,O=null,x()});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),x()};ft.addEventListener("change",Nt);const Oi=B.matchMedia("(prefers-color-scheme: dark)"),Fi=()=>x();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"&&w.size>0&&(w=new Set,Me(),fe?.([]),x()),(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},x())}e.key===" "&&!lt&&(e.preventDefault(),lt=!0,U!=="pan"&&(a.style.cursor="grab"))}}function Wi(e){e.key===" "&&(lt=!1,Ue&&(Fe=!1,Ue=!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,x(),bt?.();function ut(){G=null,O=null,x()}function jt(e){import("./userGuideHtml.js").then(n=>ys({buildWaferMap:$o,renderWaferMap,renderWaferGallery:void 0,analyzeWaferMap:Wn},n.USER_GUIDE_HTML,lo,P,e))}const Po=bs(e=>jt(e));return He(),ke&&J?.filter!==void 0&&nn(),{setResult(e){C=e,$=e.wafer,Ct=e.dies,W=tn(),ie=e.hbinDefs,oe=e.sbinDefs,K=e.testDefs,Ne=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(),x(),Jn(),Z&&se()},setOptions(e){bi(e)},getOptions(){return{...d}},resetZoom:ut,setSelection(e){w=new Set(e.map(n=>de(n))),x()},getSelectedDies:()=>We(),clearSelection(){w=new Set,Me(),fe?.([]),x()},setFindingsNotice(e){fi=e,Rt()},setStatsSummary(e){gn(e)},closeSummaryPanel(){Ht(!1)},getExportTitle(){return _n()},getSaveImageHook(){return ce.onSaveImage},locateDie:Kt,getSaveTextHook(){return ce.onSaveText},drawPendingNow:wi,getBinColors(){return g.binColors},setSummaryVisible(e){hi=e,ct()},setViewControlsVisible(e){j&&(j.style.display=e?"flex":"none")},setExpandVisible(e){Tt(e)},openUserGuide:()=>jt(),setInsightsOpen(e){Ce(e)},destroy(){Ke=!0,Po(),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(),Re&&(Re.parentElement?.insertBefore(M,Re),Re.remove()),be&&(be.parentElement?.insertBefore(M,be),be.remove()),M.remove(),a.style.cursor="",N?.destroy(),ee?.destroy(),Ye.remove()}}}
@@ -17,7 +17,7 @@ import { type Chunked } from '../core/utils.js';
17
17
  import type { WaferMetadata } from '../core/metadata.js';
18
18
  export interface SummaryPanelOptions {
19
19
  /** Which side of the content area to place the panel. Default 'right'. */
20
- placement?: 'right' | 'left' | 'top' | 'bottom';
20
+ placement?: 'right' | 'left';
21
21
  /** Open the panel immediately on render without requiring the user to click the toolbar button. Default false. */
22
22
  defaultOpen?: boolean;
23
23
  }
@@ -441,7 +441,7 @@ capabilityItems?: CapabilityItem[],
441
441
  panel?: HTMLElement,
442
442
  /** See `buildTestSection`'s `columns`. Defaults to the full set. */
443
443
  columns?: 'compact' | 'full'): Chunked<HTMLDivElement | null>;
444
- export declare function createSummaryPanelEl(placement: 'right' | 'left' | 'top' | 'bottom',
444
+ export declare function createSummaryPanelEl(placement: 'right' | 'left',
445
445
  /**
446
446
  * Inset from the edge this panel docks against — stated by the caller,
447
447
  * because only the caller knows what that edge IS.
@@ -471,7 +471,7 @@ onFindingMenu?: (findingId: string, row: HTMLElement, at: {
471
471
  y: number;
472
472
  }) => void): HTMLDivElement;
473
473
  /** Wrap the canvas + panel in a flex container according to placement. */
474
- export declare function wrapWithSummaryPanel(content: HTMLElement, panel: HTMLDivElement, placement: 'right' | 'left' | 'top' | 'bottom'): HTMLDivElement;
474
+ export declare function wrapWithSummaryPanel(content: HTMLElement, panel: HTMLDivElement, placement: 'right' | 'left'): HTMLDivElement;
475
475
  /**
476
476
  * {@link renderWaferSummaryContentSteps}, run straight through — the entry for a
477
477
  * caller that does not stage its render.