@wafertools/wafermap 0.36.0 → 0.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/AGENTS.md +2 -2
  2. package/CHANGELOG.md +385 -0
  3. package/README.md +7 -7
  4. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  5. package/dist/packages/canvas-adapter/charts/cardAbout.d.ts +21 -0
  6. package/dist/packages/canvas-adapter/charts/cardAbout.js +1 -0
  7. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +65 -12
  8. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  9. package/dist/packages/canvas-adapter/charts/commonality.d.ts +18 -0
  10. package/dist/packages/canvas-adapter/charts/commonality.js +1 -0
  11. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  12. package/dist/packages/canvas-adapter/charts/groupComparison.d.ts +31 -0
  13. package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -0
  14. package/dist/packages/canvas-adapter/charts/index.d.ts +0 -10
  15. package/dist/packages/canvas-adapter/charts/index.js +1 -1
  16. package/dist/packages/canvas-adapter/charts/patCard.d.ts +23 -0
  17. package/dist/packages/canvas-adapter/charts/patCard.js +1 -0
  18. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +56 -2
  19. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  20. package/dist/packages/canvas-adapter/charts/pointInteractions.d.ts +2 -0
  21. package/dist/packages/canvas-adapter/charts/pointInteractions.js +1 -1
  22. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  23. package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
  24. package/dist/packages/canvas-adapter/dataTab.d.ts +3 -0
  25. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  26. package/dist/packages/canvas-adapter/dieList.d.ts +12 -0
  27. package/dist/packages/canvas-adapter/dieList.js +2 -2
  28. package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +26 -0
  29. package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -0
  30. package/dist/packages/canvas-adapter/drilldown.d.ts +3 -0
  31. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  32. package/dist/packages/canvas-adapter/filterButton.d.ts +3 -0
  33. package/dist/packages/canvas-adapter/filterButton.js +1 -0
  34. package/dist/packages/canvas-adapter/filterEditor.d.ts +53 -0
  35. package/dist/packages/canvas-adapter/filterEditor.js +1 -0
  36. package/dist/packages/canvas-adapter/guideWindow.d.ts +9 -1
  37. package/dist/packages/canvas-adapter/guideWindow.js +1 -1
  38. package/dist/packages/canvas-adapter/icons.js +1 -1
  39. package/dist/packages/canvas-adapter/insightsTab.d.ts +52 -2
  40. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  41. package/dist/packages/canvas-adapter/pageFilter.d.ts +84 -0
  42. package/dist/packages/canvas-adapter/pageFilter.js +2 -0
  43. package/dist/packages/canvas-adapter/patMode.d.ts +27 -0
  44. package/dist/packages/canvas-adapter/patMode.js +1 -0
  45. package/dist/packages/canvas-adapter/plotCard.d.ts +67 -0
  46. package/dist/packages/canvas-adapter/plotCard.js +1 -0
  47. package/dist/packages/canvas-adapter/plotEditor.d.ts +13 -2
  48. package/dist/packages/canvas-adapter/plotEditor.js +1 -1
  49. package/dist/packages/canvas-adapter/plotModal.js +1 -1
  50. package/dist/packages/canvas-adapter/plotStore.js +1 -1
  51. package/dist/packages/canvas-adapter/plotTab.d.ts +6 -0
  52. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  53. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  54. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  55. package/dist/packages/canvas-adapter/summaryPanel.d.ts +15 -5
  56. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  57. package/dist/packages/canvas-adapter/toolbar.d.ts +17 -2
  58. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  59. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  60. package/dist/packages/canvas-adapter/userGuideHtml.js +590 -140
  61. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  62. package/dist/packages/canvas-adapter/version.js +1 -1
  63. package/dist/packages/core/classify.d.ts +11 -0
  64. package/dist/packages/core/classify.js +1 -1
  65. package/dist/packages/core/dies.d.ts +2 -0
  66. package/dist/packages/core/dies.js +1 -1
  67. package/dist/packages/core/wafer.d.ts +2 -2
  68. package/dist/packages/renderer/buildView.js +1 -1
  69. package/dist/packages/renderer/buildWaferMap.d.ts +2 -0
  70. package/dist/packages/renderer/buildWaferMap.js +1 -1
  71. package/dist/packages/renderer/deprecate.d.ts +2 -8
  72. package/dist/packages/renderer/deprecate.js +1 -1
  73. package/dist/packages/renderer/fmt.js +1 -1
  74. package/dist/packages/renderer/testLabel.d.ts +0 -11
  75. package/dist/packages/renderer/testLabel.js +1 -1
  76. package/dist/packages/stats/analyzeWaferLot.d.ts +6 -0
  77. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  78. package/dist/packages/stats/analyzeWaferMap.d.ts +8 -0
  79. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  80. package/dist/packages/stats/binPareto.d.ts +2 -54
  81. package/dist/packages/stats/binPareto.js +1 -1
  82. package/dist/packages/stats/binRows.js +1 -1
  83. package/dist/packages/stats/capability.d.ts +10 -0
  84. package/dist/packages/stats/capability.js +1 -1
  85. package/dist/packages/stats/cardSpec.d.ts +53 -0
  86. package/dist/packages/stats/cardSpec.js +1 -0
  87. package/dist/packages/stats/chartCatalogue.d.ts +37 -0
  88. package/dist/packages/stats/chartCatalogue.js +1 -0
  89. package/dist/packages/stats/clusterDetection.d.ts +9 -0
  90. package/dist/packages/stats/clusterDetection.js +1 -1
  91. package/dist/packages/stats/commonality.d.ts +62 -0
  92. package/dist/packages/stats/commonality.js +1 -0
  93. package/dist/packages/stats/control.d.ts +21 -0
  94. package/dist/packages/stats/control.js +1 -0
  95. package/dist/packages/stats/correlation.d.ts +9 -3
  96. package/dist/packages/stats/correlation.js +1 -1
  97. package/dist/packages/stats/dieRegions.d.ts +4 -1
  98. package/dist/packages/stats/dieRegions.js +1 -1
  99. package/dist/packages/stats/differenceMap.d.ts +22 -0
  100. package/dist/packages/stats/differenceMap.js +1 -0
  101. package/dist/packages/stats/examplePicks.d.ts +22 -0
  102. package/dist/packages/stats/examplePicks.js +1 -0
  103. package/dist/packages/stats/filterFile.d.ts +41 -0
  104. package/dist/packages/stats/filterFile.js +2 -0
  105. package/dist/packages/stats/filterFindings.d.ts +20 -5
  106. package/dist/packages/stats/filterFindings.js +1 -1
  107. package/dist/packages/stats/groupCompare.d.ts +87 -0
  108. package/dist/packages/stats/groupCompare.js +1 -0
  109. package/dist/packages/stats/guideSections.d.ts +55 -0
  110. package/dist/packages/stats/guideSections.js +1 -0
  111. package/dist/packages/stats/index.d.ts +3 -1
  112. package/dist/packages/stats/index.js +1 -1
  113. package/dist/packages/stats/math.d.ts +29 -4
  114. package/dist/packages/stats/math.js +1 -1
  115. package/dist/packages/stats/metadataColumns.d.ts +3 -0
  116. package/dist/packages/stats/metadataColumns.js +1 -1
  117. package/dist/packages/stats/pat.d.ts +58 -0
  118. package/dist/packages/stats/pat.js +1 -0
  119. package/dist/packages/stats/patSummary.d.ts +45 -0
  120. package/dist/packages/stats/patSummary.js +1 -0
  121. package/dist/packages/stats/patternClassification.d.ts +3 -3
  122. package/dist/packages/stats/patternClassification.js +1 -1
  123. package/dist/packages/stats/plotData.d.ts +294 -17
  124. package/dist/packages/stats/plotData.js +1 -1
  125. package/dist/packages/stats/plotId.d.ts +2 -0
  126. package/dist/packages/stats/plotId.js +1 -1
  127. package/dist/packages/stats/plotReferences.d.ts +17 -0
  128. package/dist/packages/stats/plotReferences.js +1 -0
  129. package/dist/packages/stats/plotSpec.d.ts +239 -3
  130. package/dist/packages/stats/plotSpec.js +4 -4
  131. package/dist/packages/stats/regions.js +1 -1
  132. package/dist/packages/stats/renderSummaryReport.js +31 -31
  133. package/dist/packages/stats/reportHtml.js +9 -13
  134. package/dist/packages/stats/synthesis.d.ts +44 -16
  135. package/dist/packages/stats/synthesis.js +1 -1
  136. package/dist/packages/stats/testPassRate.d.ts +7 -0
  137. package/dist/packages/stats/testPassRate.js +1 -1
  138. package/dist/packages/stats/types.d.ts +13 -8
  139. package/dist/packages/stats/yield.d.ts +3 -11
  140. package/dist/packages/stats/yield.js +1 -1
  141. package/llms.txt +1 -1
  142. package/package.json +10 -2
  143. package/dist/packages/canvas-adapter/charts/barPanel.d.ts +0 -83
  144. package/dist/packages/canvas-adapter/charts/barPanel.js +0 -1
  145. package/dist/packages/canvas-adapter/charts/binCluster.d.ts +0 -27
  146. package/dist/packages/canvas-adapter/charts/binCluster.js +0 -1
  147. package/dist/packages/canvas-adapter/charts/boxplot.d.ts +0 -72
  148. package/dist/packages/canvas-adapter/charts/boxplot.js +0 -1
  149. package/dist/packages/canvas-adapter/charts/groupedBarPlot.d.ts +0 -53
  150. package/dist/packages/canvas-adapter/charts/groupedBarPlot.js +0 -1
  151. package/dist/packages/canvas-adapter/charts/histogram.d.ts +0 -61
  152. package/dist/packages/canvas-adapter/charts/histogram.js +0 -1
  153. package/dist/packages/canvas-adapter/charts/scatter.d.ts +0 -80
  154. package/dist/packages/canvas-adapter/charts/scatter.js +0 -1
  155. package/dist/packages/canvas-adapter/charts/testPassRate.d.ts +0 -27
  156. package/dist/packages/canvas-adapter/charts/testPassRate.js +0 -1
  157. package/dist/packages/canvas-adapter/charts/trend.d.ts +0 -50
  158. package/dist/packages/canvas-adapter/charts/trend.js +0 -1
@@ -1 +1 @@
1
- import{createViewSwitch as Pi}from"./viewSwitch.js";import{createSummaryToggle as Ii}from"./summaryToggle.js";import{getUniqueTestNumbers as Fi,resolveTestNumber as Hi,findTestDef as Vi,collectMetadataValues as ji}from"../renderer/buildView.js";import{metadataCategoricalValue as zi}from"../core/metadata.js";import{resolveBinColorsForMaps as Ni,mergeBinDefs as ht,binColorWarning as _i,mixedPassBinsWarning as Gi,binColorsEqual as Ki}from"../renderer/binColors.js";import{commonPassBins as bo,itemPassBins as Qt}from"../core/passBins.js";import{requireRingCount as te}from"../core/ringCount.js";import{NO_DATA_FILL as qi}from"../renderer/colorMap.js";import{metadataValueColor as Xi}from"../renderer/colorMap.js";import{resolveCanvasTheme as Yi}from"./canvasTheme.js";import{ICONS as Jt}from"./icons.js";import{SHADOW as en,LEADING as wo,TRACKING as Ui,controlStyle as Zi,wireControlHover as tn,SPACE as B,EDGE_GUTTER as fe,MAP_CHROME_INSET as Qi,RADIUS as G,FONT as z,CLR as v,sevColor as vo,MODE_LABELS as Ji,BIN_LEGEND_MODES as So,STACKED_MODES as pe,applyOverlayZ as es,getTooltip as ts,hideTooltip as Co,createToolbarHelpers as ns,buildModeMenuEl as os,openDetachWindow as is,openFloatingWindow as ss,openModal as as,copyWmapThemeTokens as ls,syncWmapPopupTheme as rs,makePaletteBtn as cs,makeLogScaleBtn as ds,makeLegendStyleBtn as us,makeOverlaysBtn as fs,makeOrientationBtn as ps,menuLayerFor as xo,saveImageBlob as ms,markMenuTrigger as Qe,wireMenuA11y as Mo,wireTooltip as nn,requestedPassFailDisplay as ko,overlayMenuRows as gs,anyOverlayActive as hs,openCompactDiagnostics as ys,roomForPanel as Do,logWmapVersionOnce as bs,buildDataModeEntries as ws,metadataKeyHasData as vs,metadataModeEntry as Ss}from"./toolbar.js";import{openReportModal as Cs,openUserGuideWindow as xs}from"./guideWindow.js";import{waferDisplayLabel as yt,waferIdentityLabel as be}from"../core/waferLabel.js";import{metadataDisplayValue as Ms}from"../core/metadata.js";import{withExportContext as ks}from"./exportName.js";import{sortBinsForDisplay as Ds}from"../stats/binPareto.js";import{diePassStatus as Bs}from"../core/dies.js";import{aggregateValues as Es,aggregateBinCounts as Bo}from"../core/aggregates.js";import{renderWaferMap as Os,renderWaferMapCard as Eo,toPublicViewOptions as bt}from"./renderWaferMap.js";import{waferPopulation as Ts,selectionPopulation as Ls,LOT_STACK_REASON as on}from"./chartPopulation.js";import{sourceFromBins as Oo}from"./plotItems.js";import{plotStoreFor as Ws}from"./plotStore.js";import{classifyChanged as sn,COLOR_KEYS as Rs,findingBin as As,findingPlotMode as $s}from"./renderWaferMap.js";import{findingPatternKey as To}from"../stats/filterFindings.js";import{buildWaferMap as Ps,defaultBinMode as Is,getTestPassStatus as Lo,isParametricTest as an,getDieTestValue as Fs,isBuiltMap as Hs}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as ln}from"../stats/analyzeWaferMap.js";import{lotTestValueStatus as Vs}from"../stats/testValueBudget.js";import{testValueNotice as js}from"./testValueOffer.js";import{axisPrefsFromOptions as rn,optionsFromAxisPrefs as zs,CHART_PREF_KEYS as cn}from"./chartPrefs.js";import{collectWarnings as Ns,buildWarningsMenuEl as _s,severityOf as Gs}from"./warnings.js";import{asList as dn,compareNatural as un,arrayEqual as wt,toggleHighlight as Wo}from"../core/utils.js";import{buildCompactMap as Ks,compactLayoutOffered as qs}from"../core/compact.js";import{attachExpandableMetadata as Ro}from"./identityHeader.js";import{createSummaryPanelEl as fn,buildMetadataStripRow as Xs,metadataEntries as Ys,renderLotSummaryContentSteps as Us,reportMapsFromItems as Zs}from"./summaryPanel.js";import{prettyKey as Qs}from"../stats/facets.js";import{testLabel as Js,markedTestLabel as ea,derivedFields as ta}from"../renderer/testLabel.js";import{mergeTestDefs as na}from"../stats/mergeTestDefs.js";import{getDieKey as vt,hasPosition as oa}from"../core/dies.js";import{testValue as ia}from"../core/dieTable.js";import{runChunked as sa}from"./chunked.js";function Ao(c){if(typeof c!="number"||!Number.isFinite(c))return;const k=Math.round(c);return k>=1?k:void 0}const pn=12;function aa(c,k,f){let V=k;if(k.length>pn){const D=k.slice(0,pn-1),E=k.slice(pn-1),N=E.reduce((R,ne)=>R+ne.count,0);V=[...D,{color:v.label,count:N,label:`Other (${E.length} bins)`}]}const T=c.createElement("div");Object.assign(T.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:G.control,overflow:"hidden",border:`1px solid ${v.menuBorder}`,boxSizing:"border-box",marginTop:B.xs,flexShrink:"0"}),T.setAttribute("role","img"),T.setAttribute("aria-label",`Population split: ${V.map(D=>`${D.label} ${St(D.count/f*100)}`).join(", ")}`);for(const D of V){const E=D.count/f*100,N=c.createElement("div");Object.assign(N.style,{flex:`${E} 1 0`,minWidth:E>0?"2px":"0",background:D.color}),nn(N,`${D.label} \xB7 ${D.count.toLocaleString()} dies \xB7 ${St(E)}`),T.appendChild(N)}return T}function St(c){return c>0&&c<.1?"<0.1%":`${c.toFixed(1)}%`}function $o(c,k,f){const V=new Map;let T=0,D=0;for(const E of c){const N=f?new Set(f(E)):void 0;for(const R of E.dies){if(R.partial||R.edgeExcluded)continue;const ne=k(R);ne!==void 0&&(V.set(ne,(V.get(ne)??0)+1),T++,N&&Bs(R,N)&&D++)}}return{counts:V,total:T,pass:D}}function Po(c,k){const f=c.ownerDocument.createElement("div");Object.assign(f.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${B.xxs} ${B.xs}`,borderRadius:G.control});const V=c.ownerDocument.createElement("span");Object.assign(V.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:k.color,border:k.isActive?`2px solid ${v.iconActive}`:`1px solid ${v.menuBorder}`,borderRadius:G.control,boxSizing:"border-box"});const T=c.ownerDocument.createElement("span");if(T.textContent=k.label,Object.assign(T.style,{fontWeight:k.isActive?"700":"400",color:k.isActive?v.iconActive:v.text,whiteSpace:"nowrap"}),f.appendChild(V),f.appendChild(T),k.count!==void 0){const D=c.ownerDocument.createElement("span");if(D.textContent=k.count.toLocaleString(),Object.assign(D.style,{color:k.isActive?v.iconActive:v.text,fontWeight:k.isActive?"700":"400",whiteSpace:"nowrap"}),f.appendChild(D),k.percent!==void 0){const E=c.ownerDocument.createElement("span");E.textContent=St(k.percent),Object.assign(E.style,{color:v.label,whiteSpace:"nowrap"}),f.appendChild(E)}}if(f.setAttribute("role","button"),f.setAttribute("aria-pressed",k.isActive?"true":"false"),f.tabIndex=0,f.addEventListener("mouseenter",()=>{f.style.background=v.bgHover}),f.addEventListener("mouseleave",()=>{f.style.background="transparent"}),f.addEventListener("focus",()=>{f.style.background=v.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 E=f.getBoundingClientRect();k.onMenu({x:E.left+E.width/2,y:E.bottom},f)}}),k.onMenu){const D=k.onMenu;f.addEventListener("contextmenu",E=>{E.preventDefault(),D({x:E.clientX,y:E.clientY},f)}),nn(f,"Right-click: charts and tables for these dies")}c.appendChild(f)}export function renderWaferGallery(c,k,f={}){bs();const V=6;let T=Ao(f.columns);const D=f.showHelpButton??!1,E=f.userGuideExtension,N=f.insights?.enabled??!0,R=Ws(f.insights),ne={enabled:!1,plotStore:R},Io=es(f.zIndex),we=f.summaryPanel,me=e=>[...Qt(e)],mn=()=>C.flatMap(e=>e?[te(e,"renderWaferGallery")]:[]),Ct=()=>mn()[0];function Fo(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 j=f.lotStatsSummary,$e=f.viewOptions?.legendPosition??"default",Je=f.perCardLegend??!1;function Pe(){const e=l.plotMode??"hardBin";return So.has(e)?null:l.colorbarRangeMode==="data"?"Each map has its own value range, so it keeps its own colour bar":"These wafers have no shared colour bar for value mode, so each map keeps its own"}function gn(){const e=Je||Pe()!==null;for(const t of x)t&&t.setOptions({showLegend:e})}let l={plotMode:Is(k.flatMap(e=>typeof e=="function"?[]:[e.dies??[]])),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...f.viewOptions},x=[],oe=[],ve=[],M=[];const P=ks(()=>{const e=M.filter(n=>n!=null),t=[...new Set(e.map(n=>Ms(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort(un);return{prefix:f.downloadFilename,lots:t,...e.length===1?{wafer:be(e[0])}:{waferCount:e.length}}},f.onSaveImage,f.onSaveText);let C=k.map(e=>typeof e=="function"?null:e);function Se(){return na(C)}function Ie(){if(C.some(e=>e?.testDefs?.length))return Se().defs}let Fe=0,et=0;const q=new Map;let Ho=0,tt=null,Z=null,ie=null,Ce=null;function hn(){Z===null&&ie===null&&(Ce={plotMode:l.plotMode,activeTest:l.activeTest})}function yn(){Ce&&W({...Ce},{fireCallback:!1}),Ce=null}let bn=new Set,S=null,Vo={};function wn(e){return C[e]?.statsSummary??j?.perWafer.find(t=>t.waferIndex===e)?.summary}function vn(){return!!(C.some(e=>e?.statsSummary?.findings.length)||j?.perWafer.some(e=>e.summary.findings.length))}const jo=ts(),xe=ns(jo),{makeBtn:Me,setActive:Sn,makeSep:ge,syncSeparators:xt,syncToolbarVisible:Mt,makeMenuRow:zo,makeMenuSection:No,makeDropdown:Cn,closeOpenMenu:nt,getOpenMenu:He,setOpenMenu:Ve}=xe;c.ownerDocument.addEventListener("click",nt,!0);const xn=()=>Co();window.addEventListener("blur",xn);let Mn=f.findingsNotice,ke=null;function kn(){const e=C;return e.length>0&&e.every(t=>t!=null&&Hs(t))?e:null}function _o(){return j?.stats.testValueAnalysis??Vs(C.flatMap(e=>e?.statsSummary?[e.statsSummary]:[]))}const kt=()=>Mn??(kn()?js(_o(),C.length,ke!==null,Go):void 0);function Go(){const e=kn();if(ke||!e)return;const t=new AbortController;ke=t,$();const n=j?.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;ke=null;const i=o.perWafer.map(s=>s.summary);C=C.map((s,a)=>s&&{...s,statsSummary:i[a]}),pe.has(l.plotMode)||(M=M.map((s,a)=>s&&{...s,statsSummary:i[a]}),x.forEach((s,a)=>s?.setStatsSummary(i[a]))),j=o,Te(),$(),ae(),f.onStatsSummaryChange?.({summaries:i,lotStatsSummary:o})}).catch(o=>{if(!t.signal.aborted)throw ke=null,$(),o})}function Dn(e){bn=new Set(e);const t=[...A.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,i)=>{const s=bn.has(i);o.style.outline=s?`3px solid ${v.findingHighlight}`:"",o.style.outlineOffset=s?"-3px":"",s&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function Dt(){Dn([])}let ot=!1;function Bt(){ot=!0;for(const e of x)e&&e.clearSelection();ot=!1}function Bn(e){return t=>{!ot&&(Z!==null||ie!==null)&&(Ce=null,Be(),$()),Tt.set(e,t.length),Q&&!je&&!ot&&Ko(e,t),e.onSelect?.(t)}}function se(e,t){e!==void 0&&(x.forEach((n,o)=>{n&&o!==e&&n.locateDie(null)}),x[e]?.locateDie(t),A.querySelectorAll(".wmap-gallery-card")[e]?.scrollIntoView?.({block:"center",behavior:"smooth"}))}let Q=!1,je=!1,he=new Set;function Ko(e,t){je=!0;try{he=new Set(t.map(n=>vt(n))),M.forEach((n,o)=>{const i=x[o];!i||!n||n===e||i.setSelection(n.dies.filter(s=>he.has(vt(s))))})}finally{je=!1}ct()}function En(){he=new Set,je=!0;try{for(const e of x)e?.clearSelection()}finally{je=!1}ct()}function Et(){if(!Q||he.size===0)return;const e=[];let t=!1;if(M.forEach((i,s)=>{if(!i)return;const a=i.dies.filter(d=>he.has(vt(d)));a.length!==0&&(i.isLotStack&&(t=!0),e.push({label:be(i)??i.label??`Wafer ${s+1}`,dies:a,waferIndex:s,wafer:i.wafer,passBins:me(i),ringCount:te(i,"renderWaferGallery")}))}),e.length===0)return;const n=Se(),o=l;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?on:void 0},ctx:{plots:R,attributes:f.attributes,onSaveImage:P.onSaveImage,onSaveText:P.onSaveText,onLocateDie:(i,s)=>se(s,i)}}}function On(){const e=[];let t=!1;if(M.forEach((o,i)=>{const s=o?x[i]?.getSelectedDies()??[]:[];!o||s.length===0||(o.isLotStack&&(t=!0),e.push({label:be(o)??o.label??`Wafer ${i+1}`,dies:s,waferIndex:i,wafer:o.wafer,passBins:me(o),ringCount:te(o,"renderWaferGallery")}))}),e.length<2)return;const n=l;return{source:{items:e,population:`selected on ${e.length} wafers`,testDefs:Se().defs,activeTest:n.plotMode==="value"?n.activeTest:void 0,notMeasuredReason:t?on:void 0},ctx:{plots:R,attributes:f.attributes,onSaveImage:P.onSaveImage,onSaveText:P.onSaveText,onLocateDie:(o,i)=>se(i,o)}}}function qo(e){const t=Et()??Wn(e);if(t)return t;const n=On(),o=n?.source.items.some(i=>i.waferIndex===e);return n&&o?{...n,narrowable:!0}:void 0}function Ot(e,t,n){Z!==e&&t.click();const o=S;if(!o)return;const i=j?.findings.find(a=>a.id===e),s=Et()??On()??Yo()??(i?Tn(Rn(i)):void 0);s&&import("./drilldown.js").then(({openDrilldownMenu:a})=>{o.isConnected&&a(n,o,s.source,{plots:R,attributes:f.attributes,...s.ctx})})}function Xo(e,t,n,o){const i=dn(l.highlightBin),s=i.length>1&&i.includes(t)?[...i]:[t],a=[];let d=!1;M.forEach((m,h)=>{m&&(m.isLotStack&&(d=!0),a.push({label:be(m)??m.label??`Wafer ${h+1}`,dies:m.dies,waferIndex:h,wafer:m.wafer,passBins:me(m),ringCount:te(m,"renderWaferGallery")}))});const r=Se().defs,p=Oo(a,e,s,r,void 0,d);if(!p)return;const g={plots:R,attributes:f.attributes,onSaveImage:P.onSaveImage,onSaveText:P.onSaveText,onLocateDie:(m,h)=>se(h,m)},u=s.length>1?Oo(a,e,[t],r,void 0,d):null,y=u?{...g,narrower:{label:`Only ${e} bin ${t}`,backLabel:"All filtered bins",source:u,ctx:g}}:g;import("./drilldown.js").then(({openDrilldownMenu:m})=>{o.isConnected&&m(n,o,p,y)})}function Tn(e,t=""){const n=[];let o=!1;for(const s of[...e??[]].sort((a,d)=>a-d)){const a=M[s];a&&(a.isLotStack&&(o=!0),n.push({label:be(a)??a.label??`Wafer ${s+1}`,dies:a.dies,waferIndex:s,wafer:a.wafer,passBins:me(a),ringCount:te(a,"renderWaferGallery")}))}if(n.length===0)return;const i=l;return{source:{items:n,population:n.length===1?`on ${n[0].label}`:`on ${n.length} ${t}wafers`,testDefs:Se().defs,activeTest:i.plotMode==="value"?i.activeTest:void 0,notMeasuredReason:o?on:void 0},ctx:{plots:R,attributes:f.attributes,onSaveImage:P.onSaveImage,onSaveText:P.onSaveText,onLocateDie:(s,a)=>se(a,s)}}}function Yo(){let e;for(let i=0;i<x.length;i++)if((x[i]?.getSelectedDies().length??0)!==0){if(e!==void 0)return;e=i}const t=e===void 0?void 0:M[e];if(e===void 0||!t)return;const n=x[e].getSelectedDies(),o=l;return{source:Ls(n,{waferLabel:be(t),testDefs:t.testDefs,isLotStack:t.isLotStack,activeTest:o.plotMode==="value"?o.activeTest:void 0,waferIndex:e,wafer:t.wafer,passBins:me(t),ringCount:te(t,"renderWaferGallery")}),ctx:{onSaveImage:P.onSaveImage,onSaveText:P.onSaveText,onLocateDie:(i,s)=>se(s??e,i)}}}function Uo(e){e||En(),Q=e,ct()}function it(e,t){const n=new Set(e),o=t??x.map((i,s)=>s);for(const i of o){const s=M[i],a=x[i];if(!s||!a)continue;const d=s.dies.filter(r=>n.has(vt(r)));a.setSelection(d)}}const K=new Set,Tt=new Map;function Ln(){[...A.querySelectorAll(".wmap-gallery-card")].forEach((n,o)=>{n.style.outline=K.has(o)?`2px solid ${v.iconActive}`:"",n.style.outlineOffset=K.has(o)?"-2px":""});const t=K.size;X.style.display=t>0?"":"none",X.textContent=`${t} wafer${t===1?"":"s"} picked \u2715`,X.ariaLabel=`${t} wafer${t===1?"":"s"} picked. Click to clear.`}function Zo(e){e<0||(K.has(e)?K.delete(e):K.add(e),Ln())}function Qo(){K.clear(),Ln()}function Wn(e){if(!(K.size===0||!K.has(e))){for(const t of Tt.values())if(t>0)return;return Tn([...K],"picked ")}}function Jo(){const e=[];for(let t=0;t<C.length;t++){const n=C[t];if(!n)continue;const o=wn(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 ei(e){const t=M[e]??C[e];t&&Ye(e,t)}function ti(e){const t=wn(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 ni(){import("../stats/renderSummaryReport.js").then(({renderLotReportHtml:e})=>{Cs(e(Zs(C,Ct())),{anchor:c})})}function oi(){if(!S)return;S.innerHTML="";const e=Jo();if(C.length>0){const n=c.ownerDocument.createElement("div"),o=e.length,i=C.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:z.body,color:v.label,marginBottom:B.md}),S.appendChild(n)}if(e.length>0){const n=c.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...Zi("outlined"),marginBottom:B.lg,display:"block",width:"100%",textAlign:"left"}),tn(n),n.addEventListener("click",ni),S.appendChild(n)}if(e.length===0){const n=c.ownerDocument.createElement("div");Object.assign(n.style,{color:v.icon,fontSize:z.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:a}of e){const d=i?"unusual":s?"notable":"info",r=i+s||a,p=c.ownerDocument.createElement("button");p.type="button",Object.assign(p.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:B.xs,border:"none",borderLeft:`3px solid ${vo(d)}`,borderRadius:G.control,background:v.bgHover,cursor:"pointer",fontSize:z.body,textAlign:"left",boxSizing:"border-box"}),p.addEventListener("mouseover",()=>{p.style.background=v.bgActive}),p.addEventListener("mouseout",()=>{p.style.background=v.bgHover});const g=c.ownerDocument.createElement("span");g.textContent=yt(o,n),Object.assign(g.style,{color:v.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const u=c.ownerDocument.createElement("span");u.textContent=String(r),p.setAttribute("aria-label",`${yt(o,n)} \u2014 ${r} finding${r===1?"":"s"}${i?`, ${i} unusual`:""} \u2014 view wafer`),Object.assign(u.style,{marginLeft:B.sm,flexShrink:"0",background:vo(d),color:"#fff",borderRadius:G.container,padding:"1px 5px",fontSize:z.body,fontWeight:"600"}),p.appendChild(g),p.appendChild(u),p.addEventListener("click",()=>Ye(n,o)),S.appendChild(p)}const t=c.ownerDocument.createElement("div");t.style.height="12px",S.appendChild(t)}let De=null,ze=null;function $(){if(S)if(De?.cancel(),De=null,j){const e=ht(C.map(n=>n?.hbinDefs)),t=ht(C.map(n=>n?.sbinDefs));De=sa(Us(S,{lotSummary:j,items:C,hbinDefs:e.length?e:void 0,sbinDefs:t.length?t:void 0,testDefs:Ie(),ringCount:Ct(),binColors:l.binColors,plotMode:l.plotMode??"hardBin",fallbackFormat:l.fallbackFormat,activeFindingId:Z,warnings:f.warnings?.display??!0?le:[],findingsFilter:Vo,findingsNotice:kt(),onFindingsFilterChange:$,onSaveText:P.onSaveText,onFindingClick:(n,o)=>{Z===n.id?(Be(),yn()):(hn(),si(n,o)),$()},activeTest:ie,onTestClick:n=>{const o=ie===n;o||hn(),Be(),o?yn():ii(n),$()},onWaferClick:ei,findingsFor:ti,dieListOptions:f.dieList,onLocateDie:(n,o)=>se(o,n),onClose:()=>In(!1)}),{onDone:()=>{const n=ze;ze=null,n?.()}})}else oi()}function Rn(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}let st=[];function An(){if(st.length!==0){for(const e of st)x[e]?.setOptions({plotMode:l.plotMode,activeTest:l.activeTest});st=[]}}function Be(){Z=null,ie=null,Dt(),Bt(),An(),W({highlightBin:void 0},{fireCallback:!1})}function $n(){Z===null&&ie===null||(Ce=null,Be(),$())}function Pn(e,t){const n=Ie();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=pe.has(l.plotMode??"hardBin")?null:t;if(s){for(const a of s)x[a]?.setOptions({plotMode:"value",activeTest:e});st=[...s]}}}function ii(e){ie=e;const t=o=>M[o]?.statsSummary?.stats.testFailures?.[e]?.dieKeys,n=M.map((o,i)=>i).filter(o=>t(o)?.length);if(Pn(e,n.length?n:null),Dt(),Bt(),!pe.has(l.plotMode??"hardBin"))for(const o of n)it(t(o),[o])}function si(e,t){if(Z===e.id){Be();return}Z=e.id,ie=null,t.style.background=v.bgActive,t.style.fontWeight="600",An();const{kind:n,index:o}=e.variable;if(n==="test")Pn(o??0,Rn(e));else{const s=M.some(d=>d?.dies?.some(r=>r.hbin!=null)),a=bo(M.map(d=>d?Qt(d):void 0));W({plotMode:$s(e,l.plotMode,s),highlightBin:As(e,a,s)},{fireCallback:!1})}Dt(),Bt();const i=e.highlight;if(i.kind==="wafer"){Dn(i.waferIndices);const s=To(e);for(const a of i.waferIndices){const d=i.dieKeysByWafer?void 0:M[a]?.statsSummary?.findings.find(p=>To(p)===s),r=i.dieKeysByWafer?.[a]??d?.highlight?.dieKeys;r?.length&&it(r,[a])}}else i.kind==="bin"?i.dieKeys?.length&&it(i.dieKeys):(i.kind==="region"||i.kind==="dies")&&i.dieKeys?.length&&it(i.dieKeys)}function Lt(){return!!S&&S.style.display!=="none"}function In(e){!S||e===Lt()||(e&&$(),S.style.display=e?"flex":"none",ae())}function ae(){tt&&(xt(I),Mt(I,"inline-flex"),tt.sync({visible:!!(j||vn())&&!!S&&!ut,open:Lt(),notable:!!(j?.hasNotableFindings||C.some(e=>e?.statsSummary?.hasNotableFindings))}))}const I=c.ownerDocument.createElement("div");I.dataset.wmapToolbar="gallery",Object.assign(I.style,{flexShrink:"0",marginLeft:"auto",display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:G.control,padding:"0",boxShadow:en.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const Fn=()=>{const e=He();e&&(e.remove(),Ve(null)),Qe(J,!1)},J=Me("mode","Plot mode",()=>{if(He()){Fn();return}const e=C.flatMap(w=>w?.dies??[]),t=Ie(),{testEntries:n,binEntries:o,stackedEntries:i}=ws(e,t,{includeStacked:!0}),s=C.filter(Boolean).length,a=w=>{if(w===void 0)return s;let O=0;for(const F of C)F?.dies?.some(H=>Lo(H,w)!==void 0||ia(H,w)!==void 0)&&O++;return O},d=s<2?n:n.map(w=>{const O=a(w.activeTest);return O===s?w:{...w,label:`${w.label} \u2014 ${O} of ${s} wafers`}}),r=l.plotMode??"hardBin",p=l.activeTest??0;function g(w){return w.plotMode!==r?!1:w.plotMode==="value"?p===(w.activeTest??0):w.plotMode==="metadata"?l.activeMetadataKey===w.activeMetadataKey:!0}function u(w,O){w.activeTest!==void 0?W({plotMode:"value",activeTest:w.activeTest,activeMetadataKey:void 0,logScale:w.logScale}):w.activeMetadataKey!==void 0?W({plotMode:w.plotMode,activeTest:void 0,activeMetadataKey:w.activeMetadataKey,passFailDisplay:"off"}):W({plotMode:w.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),O.remove(),Ve(null),Qe(J,!1)}const y=new Set,m=C.flatMap(w=>w?.metadataFields??[]).filter(w=>!y.has(w.key)&&y.add(w.key)).filter(w=>vs(e,w.key)).map(Ss),h=os(J.getBoundingClientRect(),d,o,i,g,u,{makeMenuRow:zo,makeMenuSection:No},r,J.ownerDocument.defaultView??window,m);xo(J).appendChild(h),Ve(h),Qe(J,!0),Mo(h,J,Fn)});Qe(J,!1);const ai=()=>M.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:li,sync:Hn}=cs(xe,()=>({...l,plotMode:l.plotMode??"hardBin"}),ai,e=>W(e));Hn();const ri=k.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function at(){const e=Ie(),{testNumber:t}=Hi(l.activeTest??0,e);return{testNumber:t,td:Vi(e,t)}}function Vn(){if((l.plotMode??"hardBin")!=="value")return!1;const{td:e}=at();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function Ne(){if((l.plotMode??"hardBin")!=="value")return!1;const{td:e}=at();return e!==void 0&&!an(e)}function ci(){if((l.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=at();return C.some(n=>n?.dies?.some(o=>Lo(o,e,t)!==void 0))}function di(e,t){if(!t||!an(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((ko(l)==="spec"&&n?"spec":l.colorbarRangeMode??"spec")==="spec"&&n)return;let s=1/0,a=-1/0;for(const d of C)if(d)for(const r of d.dies){const p=Fs(r,e);p!==void 0&&(p<s&&(s=p),p>a&&(a=p))}if(isFinite(s))return s===a?[s,s+1]:[s,a]}function lt(e,t,n){const o=l[e];if(o===t||o!=null&&t!=null&&n(o,t))return!1;l={...l,[e]:t};for(const i of x)i&&i.setOptions({[e]:t});return!0}function jn(){if((l.plotMode??"hardBin")!=="metadata")return;const e=l.activeMetadataKey;if(!e)return;const t=new Set;for(const n of C)if(n)for(const o of ji(n.dies,e))t.add(o);return{key:e,values:[...t].sort(un)}}function Wt(){lt("metadataValueOrder",jn(),(e,t)=>e.key===t.key&&wt(e.values,t.values))}function Rt(){if((l.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=at(),n=di(e,t);lt("valueRange",n?{test:e,range:n}:void 0,(i,s)=>{const a=p=>Array.isArray(p)?{test:void 0,range:p}:{test:p.test,range:p.range},d=a(i),r=a(s);return d.test===r.test&&wt(d.range,r.range)})}let At=!1;function ui(){if(At)return;At=!0,(c.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{At=!1,Rt(),Wt(),Gn(),_n()})}let $t=!1;function fi(){if($t)return;$t=!0,(c.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{$t=!1,mt()})}let zn=[];function Ee(){const{colors:e,mixedHardBins:t}=Ni(C.filter(n=>n!=null),{binColorScheme:l.binColorScheme,useDefinedBinColors:l.useDefinedBinColors});return zn=t,e}function Pt(){return M.filter(e=>e!=null).flatMap(e=>e.dies)}function Nn(){return l.compact?Ks(Pt()):void 0}const pi=(e,t)=>wt(e.columns,t.columns)&&wt(e.rows,t.rows);function _n(){lt("compactMap",Nn(),pi)&&io()}function mi(){return qs(Pt(),M.filter(e=>e!=null).map(e=>e.reticleConfig))}function Gn(){lt("binColors",Ee(),Ki),Te()}const gi=fs(xe,()=>gs(l,ri,{functionalActive:Ne(),hasLimits:Vn()&&!Ne(),hasRecorded:ci()&&!Ne(),binMode:(l.plotMode??"hardBin")==="hardBin"||(l.plotMode??"hardBin")==="softBin"},e=>W(e),{on:!!l.compact,offered:mi(),onChange:e=>W({compact:e}),onDiagnostics:()=>ys(Pt(),M.filter(e=>e!=null).map(e=>e.reticleConfig),{anchor:c,onSaveText:P.onSaveText})}),()=>hs(l)),{btn:hi,sync:Kn}=us(xe,()=>({plotMode:l.plotMode,legendPosition:$e}),e=>{$e=e;for(const t of x)t&&t.setOptions({legendPosition:$e})},{get:()=>Je,set:e=>{Je=e,gn()},blockedReason:Pe});Kn();const yi=[{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"}],qn=Cn("aggr","Aggregation method",()=>yi,()=>l.aggregationMethod??"mean",e=>W({aggregationMethod:e}));function Xn(){const e=l.plotMode==="stackedValues";qn.style.display=e?"":"none"}Xn();const{btn:bi,sync:Yn}=ds(xe,()=>({...l,functionalActive:Ne()}),e=>W(e));Yn();const rt=Me("specRange","Colorbar range: test limits",()=>{const e=l.colorbarRangeMode==="data"?"spec":"data";W({colorbarRangeMode:e})});function Un(){const e=(l.plotMode??"hardBin")==="value"&&Vn()&&ko(l)==="off"&&!Ne();rt.style.display=e?"":"none";const t=(l.colorbarRangeMode??"spec")==="spec";Sn(rt,t),rt.ariaLabel=t?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"}Un();const wi=ps(xe,()=>l,e=>W(e)),vi=Me("downloadAll","Download gallery PNG",Ri),Oe=Me("boxSelect","Select the same dies on every wafer",()=>{Q&&he.size>0?En():Uo(!Q)});Oe.style.position="relative";const _e=c.ownerDocument.createElement("span");_e.dataset.wmapSelectAcrossCount="1",Object.assign(_e.style,{position:"absolute",top:"0",right:"0",minWidth:"14px",height:"14px",boxSizing:"border-box",padding:"0 3px",borderRadius:G.pill,background:v.iconActive,color:v.menuBg,fontSize:"11px",lineHeight:"14px",fontWeight:"700",textAlign:"center",pointerEvents:"none",display:"none"}),Oe.appendChild(_e);function ct(){Sn(Oe,Q);const e=Q?he.size:0;_e.style.display=e>0?"block":"none",_e.textContent=e>99?"99+":String(e),Oe.ariaLabel=Q?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)",Oe.setAttribute("aria-pressed",String(Q))}const X=c.ownerDocument.createElement("button");X.type="button",X.dataset.wmapPickedWafers="1",Object.assign(X.style,{display:"none",border:"none",background:v.bgActive,color:v.iconActive,borderRadius:G.control,padding:`${B.xs} ${B.md}`,fontSize:z.body,cursor:"pointer",whiteSpace:"nowrap",flexShrink:"0"}),tn(X,"bare"),X.addEventListener("click",Qo);const Si=Cn("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=>lo(e==="auto"?void 0:Number(e))),L=c.ownerDocument.createElement("div");Object.assign(L.style,{display:"inline-flex",alignItems:"center",gap:"0"}),I.appendChild(L),L.appendChild(J),L.appendChild(li),L.appendChild(qn),L.appendChild(bi),L.appendChild(rt),L.appendChild(ge()),L.appendChild(gi),L.appendChild(ge()),L.appendChild(hi),L.appendChild(ge()),L.appendChild(wi),L.appendChild(ge()),L.appendChild(Si),L.appendChild(ge()),L.appendChild(Oe),L.appendChild(X),L.appendChild(vi),ct();let Y=null,dt=null,le=[],Zn=!1;function Te(){const e=Ns({lotStatsSummary:j,result:{warnings:[...C.flatMap(n=>n?.warnings??[]),...Se().warnings]},extra:[l.binColors&&_i(l.binColors,l.plotMode),Gi(zn),Fo(mn())].filter(n=>!!n)}),t=e.length!==le.length||e.some((n,o)=>n.code!==le[o]?.code||n.message!==le[o]?.message);le=e,(t||!Zn)&&(Zn=!0,f.warnings?.onWarning?.(e)),Ci()}function Ci(){if(!Y||!dt)return;const e=le.length,t=e>0;if(Y.style.display=t?"flex":"none",dt.style.display=t?"":"none",xt(I),Mt(I,"inline-flex"),!t)return;const n=Gs(le[0]),o=`${e} data ${e===1?"warning":"warnings"}`;Y.style.color=n==="error"?v.errText:v.warnText,Y.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(f.warnings?.display??!0)&&(dt=ge(),Y=Me("warning","Data warnings",()=>{const e=He();if(nt(new MouseEvent("click")),e)return;const t=_s(Y.getBoundingClientRect(),le,Y.ownerDocument.defaultView??window);xo(c).appendChild(t),Ve(t),Mo(t,Y,()=>nt(new MouseEvent("click")))}),Qe(Y,!1),I.appendChild(dt),I.appendChild(Y)),Te();function Qn(){import("./userGuideHtml.js").then(e=>xs({buildWaferMap:Ps,renderWaferMap:Os,renderWaferGallery,analyzeWaferMap:ln},e.USER_GUIDE_HTML,E,c))}D&&(I.appendChild(ge()),I.appendChild(Me("help","User guide",()=>Qn())));const Le=c.ownerDocument.createElement("div");Le.dataset.wmapGalleryMeta="1",Object.assign(Le.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${B.sm} ${B.lg}`,fontSize:z.sub,lineHeight:wo.none,boxSizing:"border-box"});const We=c.ownerDocument.createElement("div");Object.assign(We.style,{background:v.canvasBg,display:"flex",alignItems:"stretch",gap:B.lg,paddingBottom:B.lg,minWidth:"0"});const re=c.ownerDocument.createElement("div");re.dataset.wmapGalleryLegend="1",Object.assign(re.style,{display:"flex",flexDirection:"column",gap:B.sm,background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:G.container,padding:`${B.sm} ${B.lg}`,marginBottom:B.lg,boxShadow:en.panel,fontSize:z.body,lineHeight:wo.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const U=c.ownerDocument.createElement("div");Object.assign(U.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let ce=null,Ge=null,Jn=null;function xi(){return N?ce?Promise.resolve(ce):(Jn??=import("./insightsTab.js").then(({createInsightsTab:e})=>(ce=e({initialAxisPrefs:rn(l),onAxisPrefsChange:t=>{l={...l,...zs(t)};const n=[...cn];f.onViewOptionsChange?.(bt(l),n,sn(n))},attributes:f.attributes,getItems:()=>C,getLotStats:()=>j,getBinColors:()=>l.binColors??Ee(),getRingCount:()=>te({ringCount:Ct()},"the Insights tab"),defaultView:f.insights?.defaultView,plotStore:R,onPickPlotsFile:f.insights?.onPickPlotsFile,onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:P.onSaveImage,onSaveText:P.onSaveText,ownerDocument:c.ownerDocument,locateDie:(t,n)=>{Ft(!1),se(n,t)},openWafer:(t,n,o)=>{const i=C[t];if(!i)return;let s=null;const a=as({title:n,onClose:()=>s?.destroy(),anchor:c});uo(a,n,i.wafer.metadata??void 0),s=qt(a.contentWrap,i,o,void 0,Do(a))}}),Ge=ce.el,Ge.style.display="none",c.appendChild(Ge),ce)),Jn):Promise.resolve(null)}let ut=!1,It=null;function Ft(e){N&&(ut=e,It?.setInsightsOpen(e),Ge&&(Ge.style.display=e?"flex":"none"),U.style.display=e?"none":"flex",L.style.display=e?"none":"inline-flex",xt(I),Mt(I,"inline-flex"),I.style.display="inline-flex",ae(),mt(),e&&xi().then(t=>{!t||!ut||(t.el.style.display="flex",t.render())}))}N&&f.insights?.defaultOpen&&queueMicrotask(()=>Ft(!0));const eo=4,ft=240,Ht=480,Mi=720,ki=1.25;let ye=Ht;function to(e){const t=V*2+110+2,n=no();if(n)return Math.ceil(n.across*eo+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 a=i.wafer.radius*2*(eo/s),d=Math.ceil(a+t);(o==null||d>o)&&(o=d)}return o}function Di(e){const t=to(e);return t==null?ft:Math.min(ye,Math.max(ft,t))}function Bi(e){const t=to(e);if(t==null)return!1;const n=Math.min(Mi,Math.max(Ht,t));return n<=ye?!1:(ye=n,!0)}function no(){const e=l.compact?l.compactMap:void 0,t=M.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=(l.rotation??0)%180!==0,o=l.showXYIndicator?2.5:0;return{across:(n?e.rows.length:e.columns.length)+o,down:(n?e.columns.length:e.rows.length)+o,cellAspect:n?t.height/t.width:t.width/t.height}}function oo(e,t){const n=no();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 Ei(){for(const e of oe)e?.parentElement&&oo(e.parentElement,e)}function io(){ye=Ht,Ke=ft,zt(M.map(e=>e??null)),pt(),Ei()}function Vt(){return so()?`${ye}px`:"none"}function so(){return T==null&&!jt}let jt=!1;function pt(){const e=Vt();for(const t of Array.from(A.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let Ke=ft,ao=0;function zt(e){if(Bi(e)&&pt(),T==null){const n=Di(e);n>Ke&&(Ke=n)}_t()}function lo(e){T=Ao(e),pt(),_t()}function Nt(e){return`repeat(${e}, minmax(0, ${so()?`${ye}px`:"1fr"}))`}function ro(e){A.style.gridTemplateColumns!==e&&(A.style.gridTemplateColumns=e)}function _t(){if(T!=null){ro(Nt(T));return}const e=Math.max(1,ao),t=12,n=A.clientWidth||0,o=a=>(n-t*(a-1))/a;let i=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const a=Math.min(ye,Ke*ki),d=r=>{let p=0;for(;p<e&&o(p+1)>=r;)p++;return p};i=d(a)||d(Ke)||1}const s=n>0&&i<e;s!==jt&&(jt=s,pt()),ro(Nt(i))}const A=c.ownerDocument.createElement("div");if(Object.assign(A.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:Nt(1),gap:B.xl,paddingLeft:fe,paddingRight:fe,justifyContent:"start",alignContent:"start",isolation:"isolate"}),we?.placement){const e=we.placement;S=fn(e,fe,c.ownerDocument,Ot),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.display="flex",S.style.flexDirection="column"}else if(j||vn()){const e=!!we?.defaultOpen;S=fn("right",fe,c.ownerDocument,Ot),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.flexDirection="column",S.style.display=e?"flex":"none",$()}ae(),(we?.placement??"right")==="left"?(S&&U.appendChild(S),U.appendChild(A)):(U.appendChild(A),S&&U.appendChild(S));const qe=c.ownerDocument.createElement("div");Object.assign(qe.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:fe,paddingRight:fe,paddingTop:fe,zIndex:"1",background:v.menuBg}),We.appendChild(Le),We.appendChild(I),tt=Ii(c.ownerDocument,()=>In(!Lt())),We.appendChild(tt.el),ae(),N&&(It=Pi(c.ownerDocument,"Maps","lot",e=>Ft(e)),We.appendChild(It.el)),qe.appendChild(We),qe.appendChild(re),c.appendChild(qe),c.appendChild(U);function mt(){re.innerHTML="";const e=l.plotMode??"hardBin",t=!ut&&So.has(e),n=M.filter(b=>b!=null),o=n.find(b=>b.isLotStack),i=Xs(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",a=l.activeMetadataKey,d=t&&!s?$o(n,b=>(e==="softBin"?b.sbin:b.hbin)??void 0,me):{counts:new Map,total:0,pass:0},r=t&&!s?l.binColors??Ee():void 0,p=r?e==="softBin"?r.pass.soft:r.pass.hard:new Set,g=Ds(d.counts.entries(),p).map(([b])=>b),u=t&&s&&a?$o(n,b=>zi(b.metadata?.[a])):{counts:new Map,total:0,pass:0},y=s?jn()?.values:void 0,m=t&&s?(y??[...u.counts.keys()].sort(un)).filter(b=>u.counts.has(b)):[];if(Le.innerHTML="",i&&Le.appendChild(i),Le.style.display=i?"flex":"none",!g.length&&!m.length){re.style.display="none";return}re.style.display="flex";const h=c.ownerDocument.createElement("div");Object.assign(h.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${B.sm} ${B.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),re.appendChild(h);const w=dn(l.highlightBin),O=M.flatMap(b=>b?.metadataFields??[]).find(b=>b.key===a),F=s?O?.label??(a?Qs(a):"Metadata"):Ji[e],H=c.ownerDocument.createElement("span");if(H.textContent=F,Object.assign(H.style,{fontSize:z.body,fontWeight:"700",letterSpacing:Ui,textTransform:"uppercase",color:v.label,flexShrink:"0"}),h.appendChild(H),!s&&d.total>0){const b=d.pass,_=b/d.total*100,de=c.ownerDocument.createElement("span");de.textContent=`Yield ${St(_)}`,Object.assign(de.style,{fontSize:z.body,fontWeight:"700",color:v.value,whiteSpace:"nowrap",flexShrink:"0"});const ue=c.ownerDocument.createElement("span");ue.textContent=`${b.toLocaleString()} / ${d.total.toLocaleString()} dies`,Object.assign(ue.style,{fontSize:z.body,color:v.label,whiteSpace:"nowrap",flexShrink:"0"}),h.appendChild(de),h.appendChild(ue)}if(s){const b=dn(l.highlightMetadataValue);m.forEach((_,de)=>{const ue=b.includes(_),Ae=O?.values?.find(Zt=>Zt.value===_),Ze=Ae?.color??Xi(de),yo=u.counts.get(_)??0;Po(h,{color:Ze,isActive:ue,label:Ae?.label??_,count:yo,percent:u.total>0?yo/u.total*100:void 0,onClick:Zt=>{const $i=Wo(l.highlightMetadataValue,_,Zt);$n(),W({highlightMetadataValue:$i})}})});return}const Ue=e==="softBin"?M.flatMap(b=>b?.sbinDefs??[]):M.flatMap(b=>b?.hbinDefs??[]),mo=new Set,Yt=[];for(const b of Ue)mo.has(b.bin)||(mo.add(b.bin),Yt.push(b));const Ut=Yt.length>0?new Map(Yt.map(b=>[b.bin,b])):null,go=r??l.binColors??Ee(),Ai=e==="softBin"?go.soft:go.hard,ho=b=>Ai.get(b)??qi;for(const b of g){const _=w.includes(b),de=Ut?.get(b),ue=d.counts.get(b)??0;Po(h,{color:ho(b),isActive:_,label:de?.name?`${b} \xB7 ${de.name}`:`Bin ${b}`,count:ue,percent:d.total>0?ue/d.total*100:void 0,onMenu:(Ae,Ze)=>Xo(e==="softBin"?"soft":"hard",b,Ae,Ze),onClick:Ae=>{const Ze=Wo(l.highlightBin,b,Ae);$n(),W({highlightBin:Ze})}})}d.total>0&&g.length>1&&re.appendChild(aa(c.ownerDocument,[...d.counts.entries()].sort(([,b],[,_])=>_-b).map(([b,_])=>({color:ho(b),count:_,label:Ut?.get(b)?.name?`${b} \xB7 ${Ut.get(b).name}`:`Bin ${b}`})),d.total))}function Xe(e){const t=C.filter(u=>u!==null);if(!t.length)return[];const n=t.map(u=>u.dies.filter(oa)),o=t[0].wafer,i=t.length,s=bo(t.map(u=>Qt(u)));if(!s)return[];const a=new Set(t.map(u=>te(u,"renderWaferGallery")));if(a.size!==1)return[];const d=[...a][0],r=o.metadata?{...o,metadata:(({wafer:u,waferId:y,...m})=>m)(o.metadata)}:o;function p(u,y){return{...u,stats:{...u.stats,isLotStack:!0,aggregationMethod:y,lotSize:i}}}function g(u,y){const m=u.map(h=>({...h,hbin:void 0,sbin:void 0}));return ln({wafer:r,dies:m,passBins:[...s],ringCount:d,testDefs:[{testNumber:0,name:y}]},{testNumbers:[0]})}if(e==="stackedValues"){const u=Ie();let y=u?.filter(an);if(u!==void 0&&y?.length===0)return[];if(u?.length||(y=Fi(t.flatMap(w=>w.dies)).map(w=>({testNumber:w,name:Js(void 0,w)}))),!y?.length)return[];const m=l.aggregationMethod??"mean";return y.map(h=>{const w=Es(n,m,h.testNumber),O={testNumber:0,name:h.name,unit:h.unit,...ta(h)};return{wafer:r,dies:w,passBins:[...s],ringCount:d,testDefs:[O],label:`${ea(h,h.testNumber)} \xB7 ${m}`,isLotStack:!0,aggrMethod:m,lotSize:i,statsSummary:p(ln({wafer:r,dies:w,passBins:[...s],ringCount:d,testDefs:[O]},{testNumbers:[0]}),m)}})}if(e==="stackedBins"){let u=ht(t.map(y=>y?.hbinDefs));return(!u||u.length===0)&&(u=[...new Set(t.flatMap(m=>m.dies.map(h=>h.hbin).filter(h=>h!=null)))].sort((m,h)=>m-h).map(m=>({bin:m,name:`Bin ${m}`}))),u.map(y=>{const m=Bo(n,y.bin,"hard"),h=[{bin:y.bin,name:y.name}];return{wafer:r,dies:m,passBins:[...s],ringCount:d,hbinDefs:h,label:`${y.bin} \xB7 ${y.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:p(g(m,`Wafers in hard bin ${y.bin}`),"countBin")}})}if(e==="stackedSoftBins"){let u=ht(t.map(y=>y?.sbinDefs));return(!u||u.length===0)&&(u=[...new Set(t.flatMap(m=>m.dies.map(h=>h.sbin).filter(h=>h!=null)))].sort((m,h)=>m-h).map(m=>({bin:m,name:`Bin ${m}`}))),u.map(y=>{const m=Bo(n,y.bin,"soft"),h=[{bin:y.bin,name:y.name}];return{wafer:r,dies:m,passBins:[...s],ringCount:d,sbinDefs:h,label:`${y.bin} \xB7 ${y.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:p(g(m,`Wafers in soft bin ${y.bin}`),"countBin")}})}return t}function Gt(e){const t=C.length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:l.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(g=>cn.includes(g))){l={...l,...e},ce?.setAxisPrefs(rn(l)),t&&f.onViewOptionsChange?.(bt(l),n,sn(n));return}cn.some(g=>g in e)&&ce?.setAxisPrefs(rn({...l,...e}));const o=l.plotMode,i=Pe()!==null;l={...l,...e};const s=l.plotMode,a=pe.has(s),d=o!==void 0&&pe.has(o),r=et>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const g=Ee();l={...l,binColors:g},e={...e,binColors:g}}if("compact"in e){const g=Nn();l={...l,compactMap:g},e={...e,compactMap:g}}if(("compact"in e||l.compact&&("rotation"in e||"showXYIndicator"in e))&&io(),e.plotMode!==void 0)if(a){const g=Gt(s);if(l={...l,...g},r)for(const u of x)u&&u.setOptions(e);else ee(Xe(s))}else if(d){const{valueRange:g,lotSize:u,aggregationMethod:y,...m}=l;if(l=m,r)for(const h of x)h&&h.setOptions(e);else ee(C.filter(h=>h!==null))}else for(const g of x)g&&g.setOptions(e);else if(e.aggregationMethod!==void 0&&s==="stackedValues")if(r)for(const g of x)g&&g.setOptions(e);else ee(Xe("stackedValues"));else for(const g of x)g&&g.setOptions(e);Pe()!==null!==i&&gn(),mt(),Xn(),Kn(),Hn();const p=e.plotMode!==void 0&&e.plotMode!==o;(Rs.some(g=>g in e)||p)&&$(),Te(),Yn(),Un(),Rt(),Wt(),t&&f.onViewOptionsChange?.(bt(l),n,sn(n))}function co(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:B.xs,flex:"1",minWidth:"0"});const i=e.createElement("span");i.textContent=t,Object.assign(i.style,{fontWeight:"700",fontSize:z.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(i);const s=Ro(e,o,t,n,f.attributes);return{wrap:o,metaPanel:s}}function uo(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]");if(!o||Ys(n??{}).length===0)return;const i=o.parentElement,s=c.ownerDocument.createElement("div");Object.assign(s.style,{display:"flex",alignItems:"center",gap:B.xs,flex:"1",minWidth:"0"}),i?.insertBefore(s,o),s.appendChild(o);const a=Ro(c.ownerDocument,s,t,n,f.attributes);a&&(e.contentWrap.style.position="relative",e.contentWrap.appendChild(a))}function Kt(e,t,n){const o=c.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:G.container,boxShadow:en.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:Vt(),maxHeight:Vt()});const i=c.ownerDocument.createElement("div");Object.assign(i.style,{display:"flex",alignItems:"center",padding:`${B.md} ${B.lg} ${B.sm}`,borderBottom:`1px solid ${v.menuBorder}`,flexShrink:"0",gap:B.sm});const{wrap:s,metaPanel:a}=co(document,yt(e,t),e.wafer.metadata??void 0);i.appendChild(s);const d=c.ownerDocument.createElement("button");d.dataset.wmapExpandBtn="1",d.setAttribute("aria-label","Open full view"),nn(d),d.innerHTML=Jt.expand,Object.assign(d.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${v.menuBorder}`,borderRadius:G.control,background:v.panelBg,color:v.label,padding:B.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),tn(d),i.appendChild(d),i.addEventListener("click",y=>{(y.ctrlKey||y.metaKey)&&(y.preventDefault(),y.stopPropagation(),Zo(M.indexOf(e)))},!0),o.appendChild(i);const r=c.ownerDocument.createElement("div");Object.assign(r.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(r),oo(o,r),a&&r.appendChild(a),A.appendChild(o),o.addEventListener("contextmenu",y=>{if(y.defaultPrevented)return;y.preventDefault();const m=e.viewOptions?{...l,...e.viewOptions}:l,h=Et()??Wn(t),w=h?.source??Ts(e.dies,{waferLabel:be(e),testDefs:e.testDefs,isLotStack:e.isLotStack,activeTest:m.plotMode==="value"?m.activeTest:void 0,waferIndex:t,wafer:e.wafer,passBins:me(e),ringCount:te(e,"renderWaferGallery")}),O={x:y.clientX,y:y.clientY};import("./drilldown.js").then(({openDrilldownMenu:F})=>{o.isConnected&&F(O,o,w,h?{plots:R,attributes:f.attributes,...h.ctx}:{plots:R,attributes:f.attributes,onSaveImage:u.getSaveImageHook(),onSaveText:u.getSaveTextHook(),onLocateDie:H=>se(t,H)})})});const p=Je||Pe()!==null,g=e.viewOptions?{...l,...e.viewOptions}:l,u=Eo(r,e,{viewOptions:{...g,showLegend:p,legendPosition:$e},showTooltip:!0,padding:V,statsSummary:e.statsSummary,testValueOffer:kt,onSaveImage:f.onSaveImage,onSaveText:f.onSaveText,downloadFilename:f.downloadFilename,onClick:e.onClick,onSelect:Bn(e),drilldownSourceOverride:()=>qo(t),insights:ne,onExpand:()=>Ye(t,e),showIdentity:!1,chromeInset:Qi,drawWhenVisible:!0});return u.setViewControlsVisible(!1),u.setSummaryVisible(!1),d.onclick=()=>Ye(t,e),{card:o,ctrl:u,canvasWrapper:r,expandBtn:d}}function Oi(e){const t=ve[e];if(!t)return;const n=[...q.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=Jt.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>Li(n.id)):(t.innerHTML=Jt.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>Ye(e,M[e]))}function ee(e){Wi(),He()?.remove(),Ve(null),Be(),M=[],K.clear(),Tt.clear(),X.style.display="none";for(const r of x)r&&r.destroy();x=[],oe=[],ve=[],et=0,A.innerHTML="",ao=e.length,zt(e.map(r=>typeof r=="function"?null:r));const t=[];for(let r=0;r<e.length;r++){const p=e[r];if(typeof p=="function"){const g=c.ownerDocument.createElement("div");g.className="wmap-gallery-card",Object.assign(g.style,{background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:G.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const u=c.ownerDocument.createElement("span");u.textContent="\u2026",Object.assign(u.style,{color:v.label,fontSize:"18px"}),g.appendChild(u),A.appendChild(g),M.push(null),x.push(null),oe.push(null),ve.push(null),t.push({index:r,factory:p,placeholder:g}),et++}else{const{ctrl:g,canvasWrapper:u,expandBtn:y}=Kt(p,r,e.length);M.push(p),x.push(g),oe.push(u),ve.push(y)}}Gn(),mt(),Rt(),Wt(),_n();const n=++Fe,o=()=>{setTimeout(()=>{n===Fe&&f.onItemsResolved?.()},0)},i=r=>{setTimeout(()=>{n===Fe&&f.onItemResolved?.(r,e.length)},0)};let s=e.length-t.length;s>0&&i(s);let a=0;function d(){if(n!==Fe)return;if(a>=t.length){if(pe.has(l.plotMode)){const O=l.plotMode;ee(Xe(O));return}ze=o,$(),De||(ze=null,o());return}const{index:r,factory:p,placeholder:g}=t[a++],u=p();M[r]=u,C[r]=u,zt([u]);const{card:y,ctrl:m,canvasWrapper:h,expandBtn:w}=Kt(u,r,e.length);x[r]=m,oe[r]=h,ve[r]=w,et--,g.replaceWith(y),i(++s),fi(),ui(),!S&&!we?.placement&&u.statsSummary?.findings.length&&(S=fn("right",fe,c.ownerDocument,Ot),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.flexDirection="column",S.style.display="none",(we?.placement??"right")==="left"?U.insertBefore(S,A):U.appendChild(S),$(),ae()),ae(),setTimeout(d,0)}t.length>0?setTimeout(d,0):o()}if(pe.has(l.plotMode)&&C.length>0){const e=Gt(l.plotMode);l={...l,...e},ee(Xe(l.plotMode))}else ee(k);Te();let Re=0;const fo=new(c.ownerDocument.defaultView??window).ResizeObserver(()=>{if(Re)return;Re=(c.ownerDocument.defaultView??window).requestAnimationFrame(()=>{Re=0,T==null&&_t()})});fo.observe(A),S&&$();function Ti(e,t){const n=oe[e];if(!n)return;n.innerHTML="",Object.assign(n.style,{alignItems:"center",justifyContent:"center"});const o=c.ownerDocument.createElement("span");o.textContent=t?"Opened in its own window":"Opened in the wafer viewer",Object.assign(o.style,{color:v.label,fontSize:z.body,textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function Ye(e,t){for(const a of q.values())if(a.cardIndex===e)return;const n=yt(t,e),o=Ho++,i=x[e]?.getOptions(),s=is(n);if(s){const a=s.document;a.title=n,Object.assign(a.documentElement.style,{height:"100%"}),Object.assign(a.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:z.family}),ls(c,a.documentElement);const d=rs(c,a.documentElement,()=>w.setOptions({})),r=a.createElement("div");r.dataset.wmapWindowBanner="1",r.textContent=n,Object.assign(r.style,{display:"none",padding:`${B.sm} ${B.xl}`,fontSize:z.body,fontWeight:"700",background:v.warnBg,color:v.warnText,borderBottom:`1px solid ${v.warnBorder}`,flexShrink:"0"}),a.body.appendChild(r);const p=a.createElement("div");Object.assign(p.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),a.body.appendChild(p);const{wrap:g,metaPanel:u}=co(a,n,t.wafer.metadata??void 0),y=a.createElement("div");Object.assign(y.style,{display:"flex",alignItems:"center",padding:`${B.md} ${B.lg} ${B.sm}`,borderBottom:`1px solid ${v.menuBorder}`,flexShrink:"0",gap:B.sm}),y.appendChild(g),p.appendChild(y);const m=a.createElement("div");Object.assign(m.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),u&&m.appendChild(u),p.appendChild(m);let h=0;const w=qt(m,t,void 0,i,(F,H)=>{const Ue=F?H:-h;try{s.resizeBy(Ue,0),h=F?H:0}catch{}}),O=setInterval(()=>{s.closed&&gt(o)},400);s.addEventListener("pagehide",()=>gt(o)),q.set(o,{id:o,ctrl:w,cardIndex:e,label:n,closePollId:O,stopThemeSync:d,close:()=>{s.closed||s.close()},setTitle:F=>{a.title=F,r.textContent=F,r.style.display="block"}})}else{const a=ss({title:n,onClose:()=>gt(o),anchor:c});a.contentWrap.style.flexDirection="column",uo(a,n,t.wafer.metadata??void 0);const d=qt(a.contentWrap,t,void 0,i,Do(a));q.set(o,{id:o,ctrl:d,cardIndex:e,label:n,closePollId:null,close:()=>a.close(),setTitle:r=>{const p=a.box.querySelector("[data-wmap-window-title]");p&&(p.textContent=r,p.title=r)}})}x[e]?.destroy(),x[e]=null,Ti(e,s!==null),Oi(e)}function qt(e,t,n,o,i){const s=t.viewOptions?{...l,...t.viewOptions}:l,a=o?{...s,...o}:s,r={...n!==void 0?{...a,plotMode:"value",activeTest:n}:a,showLegend:!0,legendPosition:$e},p=Eo(e,t,{viewOptions:r,showTooltip:!0,padding:V,statsSummary:t.statsSummary,testValueOffer:kt,onSaveImage:f.onSaveImage,onSaveText:f.onSaveText,downloadFilename:f.downloadFilename,onClick:t.onClick,onSelect:Bn(t),insights:ne,showExpandButton:!1,onSummaryPanelChange:i,showIdentity:!1});return p.setViewControlsVisible(!0),p.setSummaryVisible(!0),p.setExpandVisible(!1),p}function gt(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=M[n];if(!o)return;const{card:i,ctrl:s,canvasWrapper:a,expandBtn:d}=Kt(o,n,M.length);oe[n]?.parentElement?.replaceWith(i),x[n]=s,oe[n]=a,ve[n]=d}function Li(e){const t=q.get(e);t&&(t.close(),gt(e))}function Wi(){for(const e of q.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function Xt(){for(const e of x)e?.drawPendingNow()}const po=c.ownerDocument.defaultView??window;po.addEventListener("beforeprint",Xt);function Ri(){Xt();const e=[...A.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,a=8,d=(c.ownerDocument.defaultView??window).devicePixelRatio||1,r=Math.round(26*d),p=Math.round(12*d),g=c.ownerDocument.createElement("canvas");g.width=n*i+(n-1)*a,g.height=o*(s+r)+(o-1)*a;const u=g.getContext("2d"),y=Yi(A);u.fillStyle=y.background,u.fillRect(0,0,g.width,g.height),e.forEach((m,h)=>{const w=h%n,O=Math.floor(h/n),F=w*(i+a),H=O*(s+r+a),Ue=m.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";u.fillStyle=y.surface,u.fillRect(F,H,i,r),u.fillStyle=y.text,u.font=`700 ${p}px system-ui, sans-serif`,u.textAlign="left",u.textBaseline="middle",u.fillText(Ue,F+Math.round(10*d),H+r/2,i-Math.round(20*d)),u.drawImage(m,F,H+r)}),g.toBlob(m=>{if(!m)return;const h=x.find(w=>w!=null)?.getExportTitle();ms(m,["gallery",h].filter(Boolean).join(" "),P.onSaveImage)})}return{setItems(e){C=e.map(n=>typeof n=="function"?null:n);const t=l.plotMode;if(pe.has(t))if(e.some(o=>typeof o=="function"))ee(e);else{const o=Gt(t);l={...l,...o},ee(Xe(t))}else ee(e)},setOptions(e){W(e,{fireCallback:!1})},getOptions(){return bt(l)},setFindingsNotice(e){Mn=e,$()},setColumns(e){lo(e)},getBinColors(){return l.binColors??Ee()},setLotStatsSummary(e){j=e,Te(),S&&$(),ae()},openUserGuide:Qn,destroy(){R.flush(),ke?.abort(),Fe++,po.removeEventListener("beforeprint",Xt),De?.cancel(),De=null,ze=null;for(const e of[...q.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();q.clear();for(const e of x)e&&e.destroy();x=[],He()?.remove(),fo.disconnect(),Re&&((c.ownerDocument.defaultView??window).cancelAnimationFrame(Re),Re=0),c.ownerDocument.removeEventListener("click",nt,!0),window.removeEventListener("blur",xn),Io(),Co(),qe.remove(),U.remove(),S?.remove(),ce?.destroy()}}}
1
+ import{createViewSwitch as ys}from"./viewSwitch.js";import{createSummaryToggle as bs}from"./summaryToggle.js";import{getUniqueTestNumbers as ws,resolveTestNumber as vs,findTestDef as Ss,collectMetadataValues as Cs}from"../renderer/buildView.js";import{metadataCategoricalValue as xs}from"../core/metadata.js";import{resolveBinColorsForMaps as Ms,mergeBinDefs as $t,binColorWarning as ks,mixedPassBinsWarning as Ds,binColorsEqual as Bs}from"../renderer/binColors.js";import{commonPassBins as Jo,itemPassBins as Xe}from"../core/passBins.js";import{PAT_MODE_FIELD as Es,PAT_MODE_KEY as Os,PAT_MODE_ORDER as Ts,isPatMode as mt,patModeOffered as Ls,withPatField as Ws,withPatVerdicts as Ps}from"./patMode.js";import{requireRingCount as ne}from"../core/ringCount.js";import{NO_DATA_FILL as Rs}from"../renderer/colorMap.js";import{metadataValueColor as As}from"../renderer/colorMap.js";import{resolveCanvasTheme as Fs}from"./canvasTheme.js";import{ICONS as En}from"./icons.js";import{SHADOW as On,LEADING as ei,TRACKING as Is,controlStyle as $s,wireControlHover as Tn,SPACE as M,EDGE_GUTTER as oe,MAP_CHROME_INSET as Vs,RADIUS as Y,FONT as N,CLR as w,sevColor as ti,MODE_LABELS as Hs,BIN_LEGEND_MODES as ni,STACKED_MODES as ie,applyOverlayZ as js,getTooltip as zs,hideTooltip as oi,createToolbarHelpers as Ns,buildModeMenuEl as _s,openDetachWindow as Gs,openFloatingWindow as Ks,openModal as qs,copyWmapThemeTokens as Xs,syncWmapPopupTheme as Ys,makePaletteBtn as Us,makeLogScaleBtn as Zs,makeLegendStyleBtn as Qs,makeOverlaysBtn as Js,makeOrientationBtn as ea,menuLayerFor as ii,saveImageBlob as ta,markMenuTrigger as gt,wireMenuA11y as si,wireTooltip as Ln,requestedPassFailDisplay as ai,overlayMenuRows as na,anyOverlayActive as oa,openCompactDiagnostics as ia,roomForPanel as li,logWmapVersionOnce as sa,buildDataModeEntries as aa,metadataKeyHasData as la,metadataModeEntry as ri}from"./toolbar.js";import{openReportModal as ra,openUserGuideWindow as ca,registerGuideOpener as da}from"./guideWindow.js";import{waferDisplayLabel as ht,waferIdentityLabel as ve}from"../core/waferLabel.js";import{bandButton as ua}from"./filterButton.js";import{metadataDisplayValue as fa}from"../core/metadata.js";import{withExportContext as pa}from"./exportName.js";import{sortBinsForDisplay as ma}from"../stats/binPareto.js";import{diePassStatus as ga,isYieldEligibleDie as ha}from"../core/dies.js";import{aggregateValues as ya,aggregateBinCounts as ci}from"../core/aggregates.js";import{renderWaferMap as ba,renderWaferMapCard as di,toPublicViewOptions as Vt}from"./renderWaferMap.js";import{waferPopulation as wa,selectionPopulation as va,LOT_STACK_REASON as Wn}from"./chartPopulation.js";import{sourceFromBins as ui}from"./plotItems.js";import{plotStoreFor as Sa}from"./plotStore.js";import{classifyChanged as Pn,COLOR_KEYS as Ca,findingBin as xa,findingPlotMode as Ma}from"./renderWaferMap.js";import{findingPatternKey as fi}from"../stats/filterFindings.js";import{synthesisSource as ka}from"../stats/synthesis.js";import{buildWaferMap as Da,computeCoverage as Ba,computeYield as Ea,defaultBinMode as Oa,getTestPassStatus as pi,isParametricTest as Rn,getDieTestValue as Ta,isBuiltMap as La}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as An}from"../stats/analyzeWaferMap.js";import{lotTestValueStatus as Wa}from"../stats/testValueBudget.js";import{testValueNotice as Pa}from"./testValueOffer.js";import{axisPrefsFromOptions as Fn,optionsFromAxisPrefs as Ra,CHART_PREF_KEYS as In}from"./chartPrefs.js";import{collectWarnings as Aa,buildWarningsMenuEl as Fa,severityOf as Ia}from"./warnings.js";import{asList as $n,compareNatural as Vn,arrayEqual as Ht,toggleHighlight as mi}from"../core/utils.js";import{buildCompactMap as $a,compactLayoutOffered as Va}from"../core/compact.js";import{attachExpandableMetadata as gi}from"./identityHeader.js";import{createSummaryPanelEl as Hn,buildMetadataStripRow as Ha,metadataEntries as ja,renderLotSummaryContentSteps as za,reportMapsFromItems as Na}from"./summaryPanel.js";import{prettyKey as _a}from"../stats/facets.js";import{testLabel as Ga,markedTestLabel as Ka,derivedFields as qa}from"../renderer/testLabel.js";import{mergeTestDefs as Xa}from"../stats/mergeTestDefs.js";import{getDieKey as jt,hasPosition as Ya}from"../core/dies.js";import{testValue as Ua}from"../core/dieTable.js";import{runChunked as Za}from"./chunked.js";function hi(f){if(typeof f!="number"||!Number.isFinite(f))return;const k=Math.round(f);return k>=1?k:void 0}const jn=12;function Qa(f,k,u){let z=k;if(k.length>jn){const D=k.slice(0,jn-1),O=k.slice(jn-1),$=O.reduce((I,de)=>I+de.count,0);z=[...D,{color:w.label,count:$,label:`Other (${O.length} bins)`}]}const T=f.createElement("div");Object.assign(T.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:Y.control,overflow:"hidden",border:`1px solid ${w.menuBorder}`,boxSizing:"border-box",marginTop:M.xs,flexShrink:"0"}),T.setAttribute("role","img"),T.setAttribute("aria-label",`Population split: ${z.map(D=>`${D.label} ${zt(D.count/u*100)}`).join(", ")}`);for(const D of z){const O=D.count/u*100,$=f.createElement("div");Object.assign($.style,{flex:`${O} 1 0`,minWidth:O>0?"2px":"0",background:D.color}),Ln($,`${D.label} \xB7 ${D.count.toLocaleString()} dies \xB7 ${zt(O)}`),T.appendChild($)}return T}function zt(f){return f>0&&f<.1?"<0.1%":`${f.toFixed(1)}%`}function yi(f,k,u){const z=new Map;let T=0,D=0;for(const O of f){const $=u?new Set(u(O)):void 0;for(const I of O.dies){if(!ha(I))continue;const de=k(I);de!==void 0&&(z.set(de,(z.get(de)??0)+1),T++,$&&ga(I,$)&&D++)}}return{counts:z,total:T,pass:D}}function bi(f,k){const u=f.ownerDocument.createElement("div");Object.assign(u.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${M.xxs} ${M.xs}`,borderRadius:Y.control});const z=f.ownerDocument.createElement("span");Object.assign(z.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:k.color,border:k.isActive?`2px solid ${w.iconActive}`:`1px solid ${w.menuBorder}`,borderRadius:Y.control,boxSizing:"border-box"});const T=f.ownerDocument.createElement("span");if(T.textContent=k.label,Object.assign(T.style,{fontWeight:k.isActive?"700":"400",color:k.isActive?w.iconActive:w.text,whiteSpace:"nowrap"}),u.appendChild(z),u.appendChild(T),k.count!==void 0){const D=f.ownerDocument.createElement("span");if(D.textContent=k.count.toLocaleString(),Object.assign(D.style,{color:k.isActive?w.iconActive:w.text,fontWeight:k.isActive?"700":"400",whiteSpace:"nowrap"}),u.appendChild(D),k.percent!==void 0){const O=f.ownerDocument.createElement("span");O.textContent=zt(k.percent),Object.assign(O.style,{color:w.label,whiteSpace:"nowrap"}),u.appendChild(O)}}if(u.setAttribute("role","button"),u.setAttribute("aria-pressed",k.isActive?"true":"false"),u.tabIndex=0,u.addEventListener("mouseenter",()=>{u.style.background=w.bgHover}),u.addEventListener("mouseleave",()=>{u.style.background="transparent"}),u.addEventListener("focus",()=>{u.style.background=w.bgHover}),u.addEventListener("blur",()=>{u.style.background="transparent"}),u.addEventListener("click",D=>k.onClick(D.ctrlKey||D.metaKey)),u.addEventListener("keydown",D=>{if(D.key==="Enter"||D.key===" ")D.preventDefault(),k.onClick(D.ctrlKey||D.metaKey);else if(k.onMenu&&(D.key==="ContextMenu"||D.key==="F10"&&D.shiftKey)){D.preventDefault();const O=u.getBoundingClientRect();k.onMenu({x:O.left+O.width/2,y:O.bottom},u)}}),k.onMenu){const D=k.onMenu;u.addEventListener("contextmenu",O=>{O.preventDefault(),D({x:O.clientX,y:O.clientY},u)}),Ln(u,"Right-click: charts and tables for these dies")}f.appendChild(u)}export function renderWaferGallery(f,k,u={}){sa();const z=6;let T=hi(u.columns);const D=u.showHelpButton??!1,O=u.userGuideExtension,$=u.insights?.enabled??!0,I=Sa(u.insights),de={enabled:!1,plotStore:I},wi=js(u.zIndex),Pe=u.summaryPanel,Se=e=>[...Xe(e)],zn=()=>P.flatMap(e=>e?[ne(e,"renderWaferGallery")]:[]),yt=()=>zn()[0];function vi(e){const t=[...new Set(e)].sort((n,o)=>n-o);return t.length<2?null:{code:"ring-count-mixed",severity:"warning",message:`These wafers were built with different ring counts (${t.join(", ")}). Each card and each wafer's findings use their own; the lot's ring yield in the Summary panel, report and Insights uses ${e[0]} rings.`}}let _=u.lotStatsSummary,Re;const se=()=>ae?Re:_;let Ye=u.viewOptions?.legendPosition??"default",bt=u.perCardLegend??!1;function Ue(){const e=a.plotMode??"hardBin";return ni.has(e)?null:a.colorbarRangeMode==="data"?"Each map has its own value range, so it keeps its own colour bar":"These wafers have no shared colour bar for value mode, so each map keeps its own"}function Nn(){const e=bt||Ue()!==null;for(const t of C)t&&t.setOptions({showLegend:e})}let a={plotMode:Oa(k.flatMap(e=>typeof e=="function"?[]:[e.dies??[]])),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...u.viewOptions},C=[],ue=[],Ae=[],x=[];const V=pa(()=>{const e=x.filter(n=>n!=null),t=[...new Set(e.map(n=>fa(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort(Vn);return{prefix:u.downloadFilename,lots:t,...e.length===1?{wafer:ve(e[0])}:{waferCount:e.length}}},u.onSaveImage,u.onSaveText);let P=k.map(e=>typeof e=="function"?null:e),q=null,_n=null,Nt=!1,Ce=0,ae=!1,wt=!1;const xe=new WeakSet,Gn=new WeakMap,Me=()=>{const e=q?.get();return!!e&&!e.off};function Kn(e,t){return{dies:e.dies,wafer:e.wafer,label:ht(e,t),identity:ve(e),waferIndex:t,passBins:Xe(e),testDefs:e.testDefs,statsSummary:e.statsSummary}}const _t=new Map;function Ze(e,t){if(!q||!Me())return e;const n=Gn.get(e);if(n&&n.v===Ce)return n.item;const o=q.mark([Kn(e,t)]);let i=e;if(o.narrowing){const s=o.items[0].dies,l=s.filter(d=>!d.filteredOut);i={...e,dies:s,statsSummary:_t.get(e),...e.yield?{yield:Ea(s,[...Xe(e)],e.yield.yieldPercentGross!=null?"denominator-only":"exclude")}:{},...e.dataCoverage?{dataCoverage:Ba(l)}:{}},o.hidden.size&&xe.add(i)}return Gn.set(e,{v:Ce,item:i}),i}const qn=new WeakMap;function Gt(e,t){const n=Ze(e,t);if(!mt(a))return n;const o=qn.get(n);if(o)return o;const i={...n,dies:Ps(n.dies,n.testDefs,Xe(n)),metadataFields:Ws(n.metadataFields)};return xe.has(n)&&xe.add(i),qn.set(n,i),i}const Xn=new WeakMap;function Si(e,t){if(!q||!Me())return e;const n=Xn.get(e);if(n&&n.v===Ce)return n.item;const o=Ze(e,t),i=o===e?e:xe.has(o)?null:{...o,dies:o.dies.filter(s=>!s.filteredOut)};return Xn.set(e,{v:Ce,item:i}),i}function B(){return!q||!Me()?P:P.map((e,t)=>e?Si(e,t):null)}let vt=0,Qe=!1;function Yn(){const e=++vt;Re=void 0,_t.clear();const t=()=>{Qe=!1,R(),re()};if(!ae){t();return}const n=Qt();if(!n||!(_||n.some(s=>s.statsSummary))){t();return}const o=B().flatMap((s,l)=>s?[{it:s,i:l}]:[]);if(o.length===0){t();return}Qe=!0;const i=_?.analysisOptions??n.find(s=>s.statsSummary)?.statsSummary?.analysisOptions??{};import("../stats/analyzeWaferLot.js").then(async({analyzeWaferLotAsync:s,remapLotWaferIndices:l})=>{const d=await s(o.map(m=>m.it),i);if(e!==vt||Nt)return;const c=o.map(m=>m.i);Re=l(d,c),d.perWafer.forEach((m,v)=>_t.set(P[c[v]],m.summary)),Ce++,P.forEach((m,v)=>{if(!m||ie.has(a.plotMode))return;const p=Gt(m,v);x[v]=p,C[v]?.setStatsSummary(p.statsSummary)}),Te(),t()}).catch(()=>{e===vt&&t()})}const Fe=e=>q&&Me()||mt(a)?e.map((t,n)=>typeof t=="function"?t:Gt(t,n)):e;function Kt(){return _n??=import("./pageFilter.js").then(({createPageFilter:e})=>{const t=e({doc:f.ownerDocument,initial:u.insights?.filter,onChange:u.insights?.onFilterChange,savedFilters:u.insights?.savedFilters,onSavedFiltersChange:u.insights?.onSavedFiltersChange,pickFiltersFile:u.insights?.onPickFiltersFile,onSaveText:u.onSaveText,attributes:u.attributes,getRingCount:()=>ne({ringCount:yt()},"the page filter")});return Nt||(q=t,fe=t.createBand(()=>Xt(),{marginLeft:oe,marginRight:oe,marginBottom:M.lg}),f.insertBefore(fe.el,Z),t.subscribe(Yt),t.get()&&Yt()),t}),_n}let fe=null,St=null,qt;const Xt=()=>P.flatMap((e,t)=>e?[Kn(e,t)]:[]);function Un(){clearTimeout(qt),qt=setTimeout(()=>{if(!q||!fe)return;const e=Xt(),t=q.keep(e);fe.refresh(t.result,e),fe.el.style.display=q.get()&&!rt?"":"none"},0)}function Zn(){if(q){if(ke>0){Me()&&(wt=!0);return}Ce++,ae=Me()&&P.some((e,t)=>e!==null&&Ze(e,t)!==e),Re=void 0,Qe=ae&&!!_,Yn()}}function Yt(){if(Ce++,ae=!1,ke>0){wt=!0,Un();return}wt=!1;const e=a.plotMode;ae=Me()&&P.some((t,n)=>t!==null&&Ze(t,n)!==t),Re=void 0,Qe=ae&&!!_,P.length>0&&(ie.has(e)?(a={...a,...Ft(e)},X(Ge(e))):X(Fe(P.filter(t=>t!==null)))),Un(),Yn()}function Ie(){return Xa(B())}function Je(){if(B().some(e=>e?.testDefs?.length))return Ie().defs}let et=0,ke=0;const Q=new Map;let Ci=0,Ct=null,J=null,pe=null,$e=null;function xt(){J===null&&pe===null&&($e={plotMode:a.plotMode,activeTest:a.activeTest})}function Qn(){$e&&W({...$e},{fireCallback:!1}),$e=null}let Jn=new Set,S=null,xi={};function eo(e){return B()[e]?.statsSummary??se()?.perWafer.find(t=>t.waferIndex===e)?.summary}function to(){return!!(B().some(e=>e?.statsSummary?.findings.length)||se()?.perWafer.some(e=>e.summary.findings.length))}const Mi=zs(),Ve=Ns(Mi),{makeBtn:He,setActive:no,makeSep:De,syncSeparators:Ut,syncToolbarVisible:Zt,makeMenuRow:ki,makeMenuSection:Di,makeDropdown:oo,closeOpenMenu:Mt,getOpenMenu:tt,setOpenMenu:nt}=Ve;f.ownerDocument.addEventListener("click",Mt,!0);const io=()=>oi();window.addEventListener("blur",io);let so=u.findingsNotice,Be=null;function Qt(){const e=P;return e.length>0&&e.every(t=>t!=null&&La(t))?e:null}function Bi(){return _?.stats.testValueAnalysis??Wa(B().flatMap(e=>e?.statsSummary?[e.statsSummary]:[]))}const Jt=()=>so??(Qt()?Pa(Bi(),B().length,Be!==null,Ei):void 0);function Ei(){const e=Qt();if(Be||!e)return;const t=new AbortController;Be=t,R();const n=_?.analysisOptions??e[0].statsSummary?.analysisOptions??{};import("../stats/analyzeWaferLot.js").then(({analyzeWaferLotAsync:o})=>o(e,{...n,enableTestValueAnalysis:!0,signal:t.signal})).then(o=>{if(t.signal.aborted)return;Be=null;const i=o.perWafer.map(s=>s.summary);P=P.map((s,l)=>s&&{...s,statsSummary:i[l]}),ie.has(a.plotMode)||(x=x.map((s,l)=>s&&{...s,statsSummary:i[l]}),C.forEach((s,l)=>s?.setStatsSummary(i[l]))),_=o,Te(),R(),re(),u.onStatsSummaryChange?.({summaries:i,lotStatsSummary:o})}).catch(o=>{if(!t.signal.aborted)throw Be=null,R(),o})}function en(){Be?.abort(),Be=null}function ao(e){Jn=new Set(e);const t=[...F.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,i)=>{const s=Jn.has(i);o.style.outline=s?`3px solid ${w.findingHighlight}`:"",o.style.outlineOffset=s?"-3px":"",s&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function tn(){ao([])}let kt=!1;function nn(){kt=!0;for(const e of C)e&&e.clearSelection();kt=!1}function lo(e){return t=>{!kt&&(J!==null||pe!==null)&&($e=null,Oe(),R()),an.set(e,t.length),le&&!ot&&!kt&&Oi(e,t),e.onSelect?.(t)}}function me(e,t){e!==void 0&&(C.forEach((n,o)=>{n&&o!==e&&n.locateDie(null)}),C[e]?.locateDie(t),F.querySelectorAll(".wmap-gallery-card")[e]?.scrollIntoView?.({block:"center",behavior:"smooth"}))}let le=!1,ot=!1,Ee=new Set;function Oi(e,t){ot=!0;try{Ee=new Set(t.map(n=>jt(n))),x.forEach((n,o)=>{const i=C[o];!i||!n||n===e||i.setSelection(n.dies.filter(s=>Ee.has(jt(s))))})}finally{ot=!1}Lt()}function ro(){Ee=new Set,ot=!0;try{for(const e of C)e?.clearSelection()}finally{ot=!1}Lt()}function on(){if(!le||Ee.size===0)return;const e=[];let t=!1;if(x.forEach((i,s)=>{if(!i)return;const l=i.dies.filter(d=>Ee.has(jt(d)));l.length!==0&&(i.isLotStack&&(t=!0),e.push({label:ve(i)??i.label??`Wafer ${s+1}`,dies:l,waferIndex:s,wafer:i.wafer,passBins:Se(i),ringCount:ne(i,"renderWaferGallery")}))}),e.length===0)return;const n=Ie(),o=a;return{source:{items:e,population:e.length===1?`selected on ${e[0].label}`:`selected at the same die positions on ${e.length} wafers`,testDefs:n.defs,activeTest:o.plotMode==="value"?o.activeTest:void 0,notMeasuredReason:t?Wn:void 0},ctx:{plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(i,s)=>me(s,i)}}}function co(){const e=[];let t=!1;if(x.forEach((o,i)=>{const s=o?C[i]?.getSelectedDies()??[]:[];!o||s.length===0||(o.isLotStack&&(t=!0),e.push({label:ve(o)??o.label??`Wafer ${i+1}`,dies:s,waferIndex:i,wafer:o.wafer,passBins:Se(o),ringCount:ne(o,"renderWaferGallery")}))}),e.length<2)return;const n=a;return{source:{items:e,population:`selected on ${e.length} wafers`,testDefs:Ie().defs,activeTest:n.plotMode==="value"?n.activeTest:void 0,notMeasuredReason:t?Wn:void 0},ctx:{plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(o,i)=>me(i,o)}}}function Ti(e){const t=on()??po(e);if(t)return t;const n=co(),o=n?.source.items.some(i=>i.waferIndex===e);return n&&o?{...n,narrowable:!0}:void 0}function sn(e,t,n){J!==e&&t.click();const o=S;if(!o)return;const i=se()?.findings.find(l=>l.id===e),s=on()??co()??Wi()??(i?uo(mo(i)):void 0);s&&import("./drilldown.js").then(({openDrilldownMenu:l})=>{o.isConnected&&l(n,o,s.source,{plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,...s.ctx})})}function Li(e,t,n,o){const i=$n(a.highlightBin),s=i.length>1&&i.includes(t)?[...i]:[t],l=[];let d=!1;x.forEach((g,h)=>{g&&(g.isLotStack&&(d=!0),l.push({label:ve(g)??g.label??`Wafer ${h+1}`,dies:g.dies,waferIndex:h,wafer:g.wafer,passBins:Se(g),ringCount:ne(g,"renderWaferGallery")}))});const c=Ie().defs,m=ui(l,e,s,c,void 0,d);if(!m)return;const v={plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(g,h)=>me(h,g)},p=s.length>1?ui(l,e,[t],c,void 0,d):null,r=p?{...v,narrower:{label:`Only ${e} bin ${t}`,backLabel:"All filtered bins",source:p,ctx:v}}:v;import("./drilldown.js").then(({openDrilldownMenu:g})=>{o.isConnected&&g(n,o,m,r)})}function uo(e,t=""){const n=[];let o=!1;for(const s of[...e??[]].sort((l,d)=>l-d)){const l=x[s];l&&(l.isLotStack&&(o=!0),n.push({label:ve(l)??l.label??`Wafer ${s+1}`,dies:l.dies,waferIndex:s,wafer:l.wafer,passBins:Se(l),ringCount:ne(l,"renderWaferGallery")}))}if(n.length===0)return;const i=a;return{source:{items:n,population:n.length===1?`on ${n[0].label}`:`on ${n.length} ${t}wafers`,testDefs:Ie().defs,activeTest:i.plotMode==="value"?i.activeTest:void 0,notMeasuredReason:o?Wn:void 0},ctx:{plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(s,l)=>me(l,s)}}}function Wi(){let e;for(let i=0;i<C.length;i++)if((C[i]?.getSelectedDies().length??0)!==0){if(e!==void 0)return;e=i}const t=e===void 0?void 0:x[e];if(e===void 0||!t)return;const n=C[e].getSelectedDies(),o=a;return{source:va(n,{waferLabel:ve(t),testDefs:t.testDefs,isLotStack:t.isLotStack,activeTest:o.plotMode==="value"?o.activeTest:void 0,waferIndex:e,wafer:t.wafer,passBins:Se(t),ringCount:ne(t,"renderWaferGallery")}),ctx:{onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,onLocateDie:(i,s)=>me(s??e,i)}}}function Pi(e){e||ro(),le=e,Lt()}function Dt(e,t){const n=new Set(e),o=t??C.map((i,s)=>s);for(const i of o){const s=x[i],l=C[i];if(!s||!l)continue;const d=s.dies.filter(c=>n.has(jt(c)));l.setSelection(d)}}const U=new Set,an=new Map;function fo(){[...F.querySelectorAll(".wmap-gallery-card")].forEach((n,o)=>{n.style.outline=U.has(o)?`2px solid ${w.iconActive}`:"",n.style.outlineOffset=U.has(o)?"-2px":""});const t=U.size;ee.style.display=t>0?"":"none",ee.textContent=`${t} wafer${t===1?"":"s"} picked \u2715`,ee.ariaLabel=`${t} wafer${t===1?"":"s"} picked. Click to clear.`}function Ri(e){e<0||(U.has(e)?U.delete(e):U.add(e),fo())}function Ai(){U.clear(),fo()}function po(e){if(!(U.size===0||!U.has(e))){for(const t of an.values())if(t>0)return;return uo([...U],"picked ")}}function Fi(){const e=[];for(let t=0;t<B().length;t++){const n=B()[t];if(!n)continue;const o=eo(t)?.findings??[];o.length&&e.push({index:t,item:n,unusualCount:o.filter(i=>i.severity==="unusual").length,notableCount:o.filter(i=>i.severity==="notable").length,totalCount:o.length})}return e}function Ii(e){const t=x[e]??B()[e];t&&ut(e,t)}function $i(e){const t=eo(e)?.findings??[];if(t.length)return{total:t.length,unusual:t.filter(n=>n.severity==="unusual").length,notable:t.filter(n=>n.severity==="notable").length}}function Vi(){import("../stats/renderSummaryReport.js").then(({renderLotReportHtml:e})=>{ra(e(Na(B(),yt())),{anchor:f})})}function Hi(){if(!S)return;S.innerHTML="";const e=Fi();if(B().length>0){const n=f.ownerDocument.createElement("div"),o=e.length,i=B().filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${i} wafers`:`${o} of ${i} wafer${i===1?"":"s"} with findings`,Object.assign(n.style,{fontSize:N.body,color:w.label,marginBottom:M.md}),S.appendChild(n)}if(e.length>0){const n=f.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...$s("outlined"),marginBottom:M.lg,display:"block",width:"100%",textAlign:"left"}),Tn(n),n.addEventListener("click",Vi),S.appendChild(n)}if(e.length===0){const n=f.ownerDocument.createElement("div");Object.assign(n.style,{color:w.icon,fontSize:N.body,padding:"4px 0"}),n.textContent="No findings on any wafer.",S.appendChild(n)}else for(const{index:n,item:o,unusualCount:i,notableCount:s,totalCount:l}of e){const d=i?"unusual":s?"notable":"info",c=i+s||l,m=f.ownerDocument.createElement("button");m.type="button",Object.assign(m.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:M.xs,border:"none",borderLeft:`3px solid ${ti(d)}`,borderRadius:Y.control,background:w.bgHover,cursor:"pointer",fontSize:N.body,textAlign:"left",boxSizing:"border-box"}),m.addEventListener("mouseover",()=>{m.style.background=w.bgActive}),m.addEventListener("mouseout",()=>{m.style.background=w.bgHover});const v=f.ownerDocument.createElement("span");v.textContent=ht(o,n),Object.assign(v.style,{color:w.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const p=f.ownerDocument.createElement("span");p.textContent=String(c),m.setAttribute("aria-label",`${ht(o,n)} \u2014 ${c} finding${c===1?"":"s"}${i?`, ${i} unusual`:""} \u2014 view wafer`),Object.assign(p.style,{marginLeft:M.sm,flexShrink:"0",background:ti(d),color:"#fff",borderRadius:Y.container,padding:"1px 5px",fontSize:N.body,fontWeight:"600"}),m.appendChild(v),m.appendChild(p),m.addEventListener("click",()=>ut(n,o)),S.appendChild(m)}const t=f.ownerDocument.createElement("div");t.style.height="12px",S.appendChild(t)}let je=null,it=null;function R(){if(!S||ae&&_&&!Re&&Qe)return;je?.cancel(),je=null;const e=se();if(e){const t=$t(B().map(o=>o?.hbinDefs)),n=$t(B().map(o=>o?.sbinDefs));je=Za(za(S,{lotSummary:e,items:B(),hbinDefs:t.length?t:void 0,sbinDefs:n.length?n:void 0,testDefs:Je(),ringCount:yt(),binColors:a.binColors,plotMode:a.plotMode??"hardBin",fallbackFormat:a.fallbackFormat,activeFindingId:J,warnings:u.warnings?.display??!0?ge:[],findingsFilter:xi,findingsNotice:Jt(),onFindingsFilterChange:R,onSaveText:V.onSaveText,attributes:u.attributes,onFindingClick:(o,i)=>{J===o.id?(Oe(),Qn()):(xt(),wo(o,i)),R()},activeTest:pe,onTestClick:o=>{const i=pe===o;i||xt(),Oe(),i?Qn():bo(o),R()},onShowChart:$?o=>{_e(!0),Ao().then(i=>i?.showWorthCard(o))}:void 0,onWaferClick:Ii,findingsFor:$i,dieListOptions:u.dieList,onLocateDie:(o,i)=>me(i,o),onClose:()=>rn(!1)}),{onDone:()=>{const o=it;it=null,o?.()}})}else Hi()}function mo(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}let Bt=[];function go(){if(Bt.length!==0){for(const e of Bt)C[e]?.setOptions({plotMode:a.plotMode,activeTest:a.activeTest});Bt=[]}}function Oe(){J=null,pe=null,tn(),nn(),go(),W({highlightBin:void 0},{fireCallback:!1})}function ho(){J===null&&pe===null||($e=null,Oe(),R())}function yo(e,t){const n=Je();if(n===void 0||n.some(i=>i.testNumber===e))W({plotMode:"value",activeTest:e,highlightBin:void 0},{fireCallback:!1});else{W({highlightBin:void 0},{fireCallback:!1});const s=ie.has(a.plotMode??"hardBin")?null:t;if(s){for(const l of s)C[l]?.setOptions({plotMode:"value",activeTest:e});Bt=[...s]}}}function bo(e){pe=e;const t=o=>x[o]?.statsSummary?.stats.testFailures?.[e]?.dieKeys,n=x.map((o,i)=>i).filter(o=>t(o)?.length);if(yo(e,n.length?n:null),tn(),nn(),!ie.has(a.plotMode??"hardBin"))for(const o of n)Dt(t(o),[o])}function wo(e,t){if(J===e.id){Oe();return}J=e.id,pe=null,t&&(t.style.background=w.bgActive,t.style.fontWeight="600"),go();const{kind:n,index:o}=e.variable;if(n==="test")yo(o??0,mo(e));else{const s=x.some(d=>d?.dies?.some(c=>c.hbin!=null)),l=Jo(x.map(d=>d?Xe(d):void 0));W({plotMode:Ma(e,a.plotMode,s),highlightBin:xa(e,l,s)},{fireCallback:!1})}tn(),nn();const i=e.highlight;if(i.kind==="wafer"){ao(i.waferIndices);const s=fi(e);for(const l of i.waferIndices){const d=i.dieKeysByWafer?void 0:x[l]?.statsSummary?.findings.find(m=>fi(m)===s),c=i.dieKeysByWafer?.[l]??d?.highlight?.dieKeys;c?.length&&Dt(c,[l])}}else i.kind==="bin"?i.dieKeys?.length&&Dt(i.dieKeys):(i.kind==="region"||i.kind==="dies")&&i.dieKeys?.length&&Dt(i.dieKeys)}function ln(){return!!S&&S.style.display!=="none"}function rn(e){!S||e===ln()||(e&&R(),S.style.display=e?"flex":"none",re())}function re(){Ct&&(Ut(H),Zt(H,"inline-flex"),Ct.sync({visible:!!(_||se()||to())&&!!S&&!rt,open:ln(),notable:!!(se()?.hasNotableFindings||B().some(e=>e?.statsSummary?.hasNotableFindings))}))}const H=f.ownerDocument.createElement("div");H.dataset.wmapToolbar="gallery",Object.assign(H.style,{flexShrink:"0",marginLeft:"auto",display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:w.menuBg,border:`1px solid ${w.menuBorder}`,borderRadius:Y.control,padding:"0",boxShadow:On.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const vo=()=>{const e=tt();e&&(e.remove(),nt(null)),gt(ce,!1)},ce=He("mode","Plot mode",()=>{if(tt()){vo();return}const e=B().flatMap(y=>y?.dies??[]),t=Je(),{testEntries:n,binEntries:o,stackedEntries:i}=aa(e,t,{includeStacked:!0}),s=B().filter(Boolean).length,l=y=>{if(y===void 0)return s;let E=0;for(const A of B())A?.dies?.some(j=>pi(j,y)!==void 0||Ua(j,y)!==void 0)&&E++;return E},d=s<2?n:n.map(y=>{const E=l(y.activeTest);return E===s?y:{...y,label:`${y.label} \u2014 ${E} of ${s} wafers`}}),c=a.plotMode??"hardBin",m=a.activeTest??0;function v(y){return y.plotMode!==c?!1:y.plotMode==="value"?m===(y.activeTest??0):y.plotMode==="metadata"?a.activeMetadataKey===y.activeMetadataKey:!0}function p(y,E){y.activeTest!==void 0?W({plotMode:"value",activeTest:y.activeTest,activeMetadataKey:void 0,logScale:y.logScale}):y.activeMetadataKey!==void 0?W({plotMode:y.plotMode,activeTest:void 0,activeMetadataKey:y.activeMetadataKey,passFailDisplay:"off"}):W({plotMode:y.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),E.remove(),nt(null),gt(ce,!1)}const r=new Set,g=B().flatMap(y=>y?.metadataFields??[]).filter(y=>!r.has(y.key)&&r.add(y.key)).filter(y=>la(e,y.key)).map(ri);ke===0&&Ls(B())&&g.push(ri(Es));const h=_s(ce.getBoundingClientRect(),d,o,i,v,p,{makeMenuRow:ki,makeMenuSection:Di},c,ce.ownerDocument.defaultView??window,g);ii(ce).appendChild(h),nt(h),gt(ce,!0),si(h,ce,vo)});gt(ce,!1);const ji=()=>x.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:zi,sync:So}=Us(Ve,()=>({...a,plotMode:a.plotMode??"hardBin"}),ji,e=>W(e));So();const Ni=k.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function Et(){const e=Je(),{testNumber:t}=vs(a.activeTest??0,e);return{testNumber:t,td:Ss(e,t)}}function Co(){if((a.plotMode??"hardBin")!=="value")return!1;const{td:e}=Et();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function st(){if((a.plotMode??"hardBin")!=="value")return!1;const{td:e}=Et();return e!==void 0&&!Rn(e)}function _i(){if((a.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=Et();return B().some(n=>n?.dies?.some(o=>pi(o,e,t)!==void 0))}function Gi(e,t){if(!t||!Rn(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((ai(a)==="spec"&&n?"spec":a.colorbarRangeMode??"spec")==="spec"&&n)return;let s=1/0,l=-1/0;for(const d of B())if(d)for(const c of d.dies){const m=Ta(c,e);m!==void 0&&(m<s&&(s=m),m>l&&(l=m))}if(isFinite(s))return s===l?[s,s+1]:[s,l]}function Ot(e,t,n){const o=a[e];if(o===t||o!=null&&t!=null&&n(o,t))return!1;a={...a,[e]:t};for(const i of C)i&&i.setOptions({[e]:t});return!0}function xo(){if((a.plotMode??"hardBin")!=="metadata")return;const e=a.activeMetadataKey;if(!e)return;if(mt(a))return{key:e,values:[...Ts]};const t=new Set;for(const n of B())if(n)for(const o of Cs(n.dies,e))t.add(o);return{key:e,values:[...t].sort(Vn)}}function cn(){Ot("metadataValueOrder",xo(),(e,t)=>e.key===t.key&&Ht(e.values,t.values))}function dn(){if((a.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=Et(),n=Gi(e,t);Ot("valueRange",n?{test:e,range:n}:void 0,(i,s)=>{const l=m=>Array.isArray(m)?{test:void 0,range:m}:{test:m.test,range:m.range},d=l(i),c=l(s);return d.test===c.test&&Ht(d.range,c.range)})}let un=!1;function Ki(){if(un)return;un=!0,(f.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{un=!1,dn(),cn(),Bo(),Do()})}let fn=!1;function qi(){if(fn)return;fn=!0,(f.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{fn=!1,At()})}let Mo=[];function G(){const{colors:e,mixedHardBins:t}=Ms(B().filter(n=>n!=null),{binColorScheme:a.binColorScheme,useDefinedBinColors:a.useDefinedBinColors});return Mo=t,e}function pn(){return x.filter(e=>e!=null).flatMap(e=>e.dies)}function ko(){return a.compact?$a(pn()):void 0}const Xi=(e,t)=>Ht(e.columns,t.columns)&&Ht(e.rows,t.rows);function Do(){Ot("compactMap",ko(),Xi)&&Ho()}function Yi(){return Va(pn(),x.filter(e=>e!=null).map(e=>e.reticleConfig))}function Bo(){Ot("binColors",G(),Bs),Te()}const Ui=Js(Ve,()=>na(a,Ni,{functionalActive:st(),hasLimits:Co()&&!st(),hasRecorded:_i()&&!st(),binMode:(a.plotMode??"hardBin")==="hardBin"||(a.plotMode??"hardBin")==="softBin"},e=>W(e),{on:!!a.compact,offered:Yi(),onChange:e=>W({compact:e}),onDiagnostics:()=>ia(pn(),x.filter(e=>e!=null).map(e=>e.reticleConfig),{anchor:f,onSaveText:V.onSaveText})}),()=>oa(a)),{btn:Zi,sync:Eo}=Qs(Ve,()=>({plotMode:a.plotMode,legendPosition:Ye}),e=>{Ye=e;for(const t of C)t&&t.setOptions({legendPosition:Ye})},{get:()=>bt,set:e=>{bt=e,Nn()},blockedReason:Ue});Eo();const Qi=[{value:"mean",label:"Mean"},{value:"median",label:"Median"},{value:"stddev",label:"Std Dev"},{value:"min",label:"Min"},{value:"max",label:"Max"},{value:"count",label:"Count"}],Oo=oo("aggr","Aggregation method",()=>Qi,()=>a.aggregationMethod??"mean",e=>W({aggregationMethod:e}));function To(){const e=a.plotMode==="stackedValues";Oo.style.display=e?"":"none"}To();const{btn:Ji,sync:Lo}=Zs(Ve,()=>({...a,functionalActive:st()}),e=>W(e));Lo();const Tt=He("specRange","Colorbar range: test limits",()=>{const e=a.colorbarRangeMode==="data"?"spec":"data";W({colorbarRangeMode:e})});function Wo(){const e=(a.plotMode??"hardBin")==="value"&&Co()&&ai(a)==="off"&&!st();Tt.style.display=e?"":"none";const t=(a.colorbarRangeMode??"spec")==="spec";no(Tt,t),Tt.ariaLabel=t?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"}Wo();const es=ea(Ve,()=>a,e=>W(e)),ts=He("downloadAll","Download gallery PNG",ms),ze=He("boxSelect","Select the same dies on every wafer",()=>{le&&Ee.size>0?ro():Pi(!le)});ze.style.position="relative";const at=f.ownerDocument.createElement("span");at.dataset.wmapSelectAcrossCount="1",Object.assign(at.style,{position:"absolute",top:"0",right:"0",minWidth:"14px",height:"14px",boxSizing:"border-box",padding:"0 3px",borderRadius:Y.pill,background:w.iconActive,color:w.menuBg,fontSize:"11px",lineHeight:"14px",fontWeight:"700",textAlign:"center",pointerEvents:"none",display:"none"}),ze.appendChild(at);function Lt(){no(ze,le);const e=le?Ee.size:0;at.style.display=e>0?"block":"none",at.textContent=e>99?"99+":String(e),ze.ariaLabel=le?e>0?`Select the same dies on every wafer: on, ${e.toLocaleString()} die position${e===1?"":"s"} selected (click to clear the selection)`:"Select the same dies on every wafer: on (click to turn off)":"Select the same dies on every wafer: off (click to turn on)",ze.setAttribute("aria-pressed",String(le))}const ee=f.ownerDocument.createElement("button");ee.type="button",ee.dataset.wmapPickedWafers="1",Object.assign(ee.style,{display:"none",border:"none",background:w.bgActive,color:w.iconActive,borderRadius:Y.control,padding:`${M.xs} ${M.md}`,fontSize:N.body,cursor:"pointer",whiteSpace:"nowrap",flexShrink:"0"}),Tn(ee,"bare"),ee.addEventListener("click",Ai);const ns=oo("columns","Columns",()=>[{value:"auto",label:"Auto"},{value:"1",label:"1 column"},{value:"2",label:"2 columns"},{value:"3",label:"3 columns"},{value:"4",label:"4 columns"},{value:"5",label:"5 columns"}],()=>T!=null?String(T):"auto",e=>No(e==="auto"?void 0:Number(e))),L=f.ownerDocument.createElement("div");Object.assign(L.style,{display:"inline-flex",alignItems:"center",gap:"0"}),H.appendChild(L),L.appendChild(ce),L.appendChild(zi),L.appendChild(Oo),L.appendChild(Ji),L.appendChild(Tt),L.appendChild(De()),L.appendChild(Ui),L.appendChild(De()),L.appendChild(Zi),L.appendChild(De()),L.appendChild(es),L.appendChild(De()),L.appendChild(ns),L.appendChild(De()),L.appendChild(ze),L.appendChild(ee),L.appendChild(ts),Lt();let te=null,Wt=null,ge=[],Po=!1;function Te(){const e=Aa({lotStatsSummary:se(),result:{warnings:[...B().flatMap(n=>n?.warnings??[]),...Ie().warnings]},extra:[a.binColors&&ks(a.binColors,a.plotMode),Ds(Mo),vi(zn())].filter(n=>!!n)}),t=e.length!==ge.length||e.some((n,o)=>n.code!==ge[o]?.code||n.message!==ge[o]?.message);ge=e,(t||!Po)&&(Po=!0,u.warnings?.onWarning?.(e)),os()}function os(){if(!te||!Wt)return;const e=ge.length,t=e>0;if(te.style.display=t?"flex":"none",Wt.style.display=t?"":"none",Ut(H),Zt(H,"inline-flex"),!t)return;const n=Ia(ge[0]),o=`${e} data ${e===1?"warning":"warnings"}`;te.style.color=n==="error"?w.errText:w.warnText,te.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(u.warnings?.display??!0)&&(Wt=De(),te=He("warning","Data warnings",()=>{const e=tt();if(Mt(new MouseEvent("click")),e)return;const t=Fa(te.getBoundingClientRect(),ge,te.ownerDocument.defaultView??window);ii(f).appendChild(t),nt(t),si(t,te,()=>Mt(new MouseEvent("click")))}),gt(te,!1),H.appendChild(Wt),H.appendChild(te)),Te();function mn(e){import("./userGuideHtml.js").then(t=>ca({buildWaferMap:Da,renderWaferMap:ba,renderWaferGallery,analyzeWaferMap:An},t.USER_GUIDE_HTML,O,f,e))}const is=da(e=>mn(e));D&&(H.appendChild(De()),H.appendChild(He("help","User guide",()=>mn())));const Ne=f.ownerDocument.createElement("div");Ne.dataset.wmapGalleryMeta="1",Object.assign(Ne.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${M.sm} ${M.lg}`,fontSize:N.sub,lineHeight:ei.none,boxSizing:"border-box"});const Le=f.ownerDocument.createElement("div");Object.assign(Le.style,{background:w.canvasBg,display:"flex",alignItems:"stretch",gap:M.lg,paddingBottom:M.lg,minWidth:"0"});const he=f.ownerDocument.createElement("div");he.dataset.wmapGalleryLegend="1",Object.assign(he.style,{display:"flex",flexDirection:"column",gap:M.sm,background:w.menuBg,border:`1px solid ${w.menuBorder}`,borderRadius:Y.container,padding:`${M.sm} ${M.lg}`,marginBottom:M.lg,boxShadow:On.panel,fontSize:N.body,lineHeight:ei.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const Z=f.ownerDocument.createElement("div");Object.assign(Z.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let ye=null,lt=null,Ro=null;function Ao(){return $?ye?Promise.resolve(ye):(Ro??=Promise.all([import("./insightsTab.js"),Kt()]).then(([{createInsightsTab:e},t])=>(ye=e({pageFilter:t,showFilterButton:!1,initialAxisPrefs:Fn(a),onAxisPrefsChange:n=>{a={...a,...Ra(n)};const o=[...In];u.onViewOptionsChange?.(Vt(a),o,Pn(o))},attributes:u.attributes,getItems:()=>P,getLotStats:()=>_,getBinColors:()=>a.binColors??G(),getRingCount:()=>ne({ringCount:yt()},"the Insights tab"),defaultView:u.insights?.defaultView,plotStore:I,onPickPlotsFile:u.insights?.onPickPlotsFile,showPatMap:()=>{_e(!1),W({plotMode:"metadata",activeTest:void 0,activeMetadataKey:Os,passFailDisplay:"off"})},showOnMap:n=>{if(_e(!1),n.kind==="test")xt(),Oe(),bo(n.testNumber);else{const o=se(),i=o?ka(o).findings.find(s=>s.id===n.id):void 0;i&&J!==i.id&&(xt(),wo(i))}rn(!0),R()},onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:V.onSaveImage,onSaveText:V.onSaveText,ownerDocument:f.ownerDocument,locateDie:(n,o)=>{_e(!1),me(o,n)},openWafer:(n,o,i)=>{const s=B()[n];if(!s)return;let l=null;const d=qs({title:o,onClose:()=>l?.destroy(),anchor:f});Ko(d,o,s.wafer.metadata??void 0),l=xn(d.contentWrap,s,i,void 0,li(d))}}),lt=ye.el,lt.style.display="none",f.appendChild(lt),ye)),Ro):Promise.resolve(null)}let rt=!1,gn=null;function _e(e){$&&(rt=e,gn?.setInsightsOpen(e),lt&&(lt.style.display=e?"flex":"none"),Z.style.display=e?"none":"flex",fe&&(fe.el.style.display=q?.get()&&!e?"":"none"),L.style.display=e?"none":"inline-flex",Ut(H),Zt(H,"inline-flex"),H.style.display="inline-flex",re(),At(),e&&Ao().then(t=>{!t||!rt||(t.el.style.display="flex",t.render())}))}$&&u.insights?.defaultOpen&&queueMicrotask(()=>_e(!0));const Fo=4,Pt=240,hn=480,ss=720,as=1.25;let We=hn;function Io(e){const t=z*2+110+2,n=$o();if(n)return Math.ceil(n.across*Fo+t);let o=null;for(const i of e){if(i==null||!i.dies?.length)continue;const s=i.dies[0].width;if(!(s>0))continue;const l=i.wafer.radius*2*(Fo/s),d=Math.ceil(l+t);(o==null||d>o)&&(o=d)}return o}function ls(e){const t=Io(e);return t==null?Pt:Math.min(We,Math.max(Pt,t))}function rs(e){const t=Io(e);if(t==null)return!1;const n=Math.min(ss,Math.max(hn,t));return n<=We?!1:(We=n,!0)}function $o(){const e=a.compact?a.compactMap:void 0,t=x.find(i=>i?.dies?.length)?.dies[0];if(!e||!t||e.columns.length===0||e.rows.length===0||!(t.width>0)||!(t.height>0))return;const n=(a.rotation??0)%180!==0,o=a.showXYIndicator?2.5:0;return{across:(n?e.rows.length:e.columns.length)+o,down:(n?e.columns.length:e.rows.length)+o,cellAspect:n?t.height/t.width:t.width/t.height}}function Vo(e,t){const n=$o();if(!n){e.style.aspectRatio="1",t.style.flex="1",t.style.width="",t.style.aspectRatio="";return}e.style.aspectRatio="auto",t.style.flex="none",t.style.width="100%",t.style.aspectRatio=String(n.across*n.cellAspect/n.down)}function cs(){for(const e of ue)e?.parentElement&&Vo(e.parentElement,e)}function Ho(){We=hn,ct=Pt,wn(x.map(e=>e??null)),Rt(),cs()}function yn(){return jo()?`${We}px`:"none"}function jo(){return T==null&&!bn}let bn=!1;function Rt(){const e=yn();for(const t of Array.from(F.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let ct=Pt,zo=0;function wn(e){if(rs(e)&&Rt(),T==null){const n=ls(e);n>ct&&(ct=n)}Sn()}function No(e){T=hi(e),Rt(),Sn()}function vn(e){return`repeat(${e}, minmax(0, ${jo()?`${We}px`:"1fr"}))`}function _o(e){F.style.gridTemplateColumns!==e&&(F.style.gridTemplateColumns=e)}function Sn(){if(T!=null){_o(vn(T));return}const e=Math.max(1,zo),t=12,n=F.clientWidth||0,o=l=>(n-t*(l-1))/l;let i=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const l=Math.min(We,ct*as),d=c=>{let m=0;for(;m<e&&o(m+1)>=c;)m++;return m};i=d(l)||d(ct)||1}const s=n>0&&i<e;s!==bn&&(bn=s,Rt()),_o(vn(i))}const F=f.ownerDocument.createElement("div");if(Object.assign(F.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:vn(1),gap:M.xl,paddingLeft:oe,paddingRight:oe,justifyContent:"start",alignContent:"start",isolation:"isolate"}),Pe?.placement){const e=Pe.placement;S=Hn(e,oe,f.ownerDocument,sn),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.display="flex",S.style.flexDirection="column"}else if(_||se()||to()){const e=!!Pe?.defaultOpen;S=Hn("right",oe,f.ownerDocument,sn),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.flexDirection="column",S.style.display=e?"flex":"none",R()}re(),(Pe?.placement??"right")==="left"?(S&&Z.appendChild(S),Z.appendChild(F)):(Z.appendChild(F),S&&Z.appendChild(S));const dt=f.ownerDocument.createElement("div");Object.assign(dt.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:oe,paddingRight:oe,paddingTop:oe,zIndex:"1",background:w.menuBg}),Le.appendChild(Ne),Le.appendChild(H),Ct=bs(f.ownerDocument,()=>rn(!ln())),Le.appendChild(Ct.el),re(),$&&(gn=ys(f.ownerDocument,"Maps","lot",e=>_e(e)),Le.appendChild(gn.el)),$&&(St=ua(f.ownerDocument,"Filter\u2026","wmapGalleryFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>{Kt().then(e=>e.openEditor(St??f,Xt()))}),St.style.order="1",Le.appendChild(St)),dt.appendChild(Le),dt.appendChild(he),f.appendChild(dt),f.appendChild(Z);function At(){he.innerHTML="";const e=a.plotMode??"hardBin",t=!rt&&ni.has(e),n=x.filter(b=>b!=null&&!xe.has(b)),o=n.find(b=>b.isLotStack),i=Ha(n.map(b=>({metadata:b.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0,{curation:u.attributes}),s=e==="metadata",l=a.activeMetadataKey,d=t&&!s?yi(n,b=>(e==="softBin"?b.sbin:b.hbin)??void 0,Se):{counts:new Map,total:0,pass:0},c=t&&!s?a.binColors??G():void 0,m=c?e==="softBin"?c.pass.soft:c.pass.hard:new Set,v=ma(d.counts.entries(),m).map(([b])=>b),p=t&&s&&l?yi(n,b=>xs(b.metadata?.[l])):{counts:new Map,total:0,pass:0},r=s?xo()?.values:void 0,g=t&&s?(r??[...p.counts.keys()].sort(Vn)).filter(b=>p.counts.has(b)):[];if(Ne.innerHTML="",i&&Ne.appendChild(i),Ne.style.display=i?"flex":"none",!v.length&&!g.length){he.style.display="none";return}he.style.display="flex";const h=f.ownerDocument.createElement("div");Object.assign(h.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${M.sm} ${M.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),he.appendChild(h);const y=$n(a.highlightBin),E=x.flatMap(b=>b?.metadataFields??[]).find(b=>b.key===l),A=s?E?.label??(l?_a(l):"Metadata"):Hs[e],j=f.ownerDocument.createElement("span");if(j.textContent=A,Object.assign(j.style,{fontSize:N.body,fontWeight:"700",letterSpacing:Is,textTransform:"uppercase",color:w.label,flexShrink:"0"}),h.appendChild(j),!s&&d.total>0){const b=d.pass,K=b/d.total*100,be=f.ownerDocument.createElement("span");be.textContent=`Yield ${zt(K)}`,Object.assign(be.style,{fontSize:N.body,fontWeight:"700",color:w.value,whiteSpace:"nowrap",flexShrink:"0"});const we=f.ownerDocument.createElement("span");we.textContent=`${b.toLocaleString()} / ${d.total.toLocaleString()} dies`,Object.assign(we.style,{fontSize:N.body,color:w.label,whiteSpace:"nowrap",flexShrink:"0"}),h.appendChild(be),h.appendChild(we)}if(s){const b=$n(a.highlightMetadataValue);g.forEach((K,be)=>{const we=b.includes(K),qe=E?.values?.find(Bn=>Bn.value===K),pt=qe?.color??As(be),Qo=p.counts.get(K)??0;bi(h,{color:pt,isActive:we,label:qe?.label??K,count:Qo,percent:p.total>0?Qo/p.total*100:void 0,onClick:Bn=>{const hs=mi(a.highlightMetadataValue,K,Bn);ho(),W({highlightMetadataValue:hs})}})});return}const ft=e==="softBin"?x.flatMap(b=>b?.sbinDefs??[]):x.flatMap(b=>b?.hbinDefs??[]),Yo=new Set,kn=[];for(const b of ft)Yo.has(b.bin)||(Yo.add(b.bin),kn.push(b));const Dn=kn.length>0?new Map(kn.map(b=>[b.bin,b])):null,Uo=c??a.binColors??G(),gs=e==="softBin"?Uo.soft:Uo.hard,Zo=b=>gs.get(b)??Rs;for(const b of v){const K=y.includes(b),be=Dn?.get(b),we=d.counts.get(b)??0;bi(h,{color:Zo(b),isActive:K,label:be?.name?`${b} \xB7 ${be.name}`:`Bin ${b}`,count:we,percent:d.total>0?we/d.total*100:void 0,onMenu:(qe,pt)=>Li(e==="softBin"?"soft":"hard",b,qe,pt),onClick:qe=>{const pt=mi(a.highlightBin,b,qe);ho(),W({highlightBin:pt})}})}d.total>0&&v.length>1&&he.appendChild(Qa(f.ownerDocument,[...d.counts.entries()].sort(([,b],[,K])=>K-b).map(([b,K])=>({color:Zo(b),count:K,label:Dn?.get(b)?.name?`${b} \xB7 ${Dn.get(b).name}`:`Bin ${b}`})),d.total))}function Ge(e){const t=B().filter(p=>p!==null&&!xe.has(p));if(!t.length)return[];const n=t.map(p=>p.dies.filter(Ya).filter(r=>!r.filteredOut)),o=t[0].wafer,i=t.length,s=Jo(t.map(p=>Xe(p)));if(!s)return[];const l=new Set(t.map(p=>ne(p,"renderWaferGallery")));if(l.size!==1)return[];const d=[...l][0],c=o.metadata?{...o,metadata:(({wafer:p,waferId:r,...g})=>g)(o.metadata)}:o;function m(p,r){return{...p,stats:{...p.stats,isLotStack:!0,aggregationMethod:r,lotSize:i}}}function v(p,r){const g=p.map(h=>({...h,hbin:void 0,sbin:void 0}));return An({wafer:c,dies:g,passBins:[...s],ringCount:d,testDefs:[{testNumber:0,name:r}]},{testNumbers:[0]})}if(e==="stackedValues"){const p=Je();let r=p?.filter(Rn);if(p!==void 0&&r?.length===0)return[];if(p?.length||(r=ws(t.flatMap(y=>y.dies)).map(y=>({testNumber:y,name:Ga(void 0,y)}))),!r?.length)return[];const g=a.aggregationMethod??"mean";return r.map(h=>{const y=ya(n,g,h.testNumber),E={testNumber:0,name:h.name,unit:h.unit,...qa(h)};return{wafer:c,dies:y,passBins:[...s],ringCount:d,testDefs:[E],label:`${Ka(h,h.testNumber)} \xB7 ${g}`,isLotStack:!0,aggrMethod:g,lotSize:i,statsSummary:m(An({wafer:c,dies:y,passBins:[...s],ringCount:d,testDefs:[E]},{testNumbers:[0]}),g)}})}if(e==="stackedBins"){let p=$t(t.map(r=>r?.hbinDefs));return(!p||p.length===0)&&(p=[...new Set(t.flatMap(g=>g.dies.map(h=>h.hbin).filter(h=>h!=null)))].sort((g,h)=>g-h).map(g=>({bin:g,name:`Bin ${g}`}))),p.map(r=>{const g=ci(n,r.bin,"hard"),h=[{bin:r.bin,name:r.name}];return{wafer:c,dies:g,passBins:[...s],ringCount:d,hbinDefs:h,label:`${r.bin} \xB7 ${r.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:m(v(g,`Wafers in hard bin ${r.bin}`),"countBin")}})}if(e==="stackedSoftBins"){let p=$t(t.map(r=>r?.sbinDefs));return(!p||p.length===0)&&(p=[...new Set(t.flatMap(g=>g.dies.map(h=>h.sbin).filter(h=>h!=null)))].sort((g,h)=>g-h).map(g=>({bin:g,name:`Bin ${g}`}))),p.map(r=>{const g=ci(n,r.bin,"soft"),h=[{bin:r.bin,name:r.name}];return{wafer:c,dies:g,passBins:[...s],ringCount:d,sbinDefs:h,label:`${r.bin} \xB7 ${r.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:m(v(g,`Wafers in soft bin ${r.bin}`),"countBin")}})}return t}function Ft(e){const t=B().length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:a.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}function W(e,{fireCallback:t=!0}={}){const n=Object.keys(e);if(n.length>0&&n.every(r=>In.includes(r))){a={...a,...e},ye?.setAxisPrefs(Fn(a)),t&&u.onViewOptionsChange?.(Vt(a),n,Pn(n));return}In.some(r=>r in e)&&ye?.setAxisPrefs(Fn({...a,...e}));const o=a.plotMode,i=mt(a),s=Ue()!==null;a={...a,...e};const l=a.plotMode,d=ie.has(l),c=mt(a),m=o!==void 0&&ie.has(o),v=ke>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const r=G();a={...a,binColors:r},e={...e,binColors:r}}if("compact"in e){const r=ko();a={...a,compactMap:r},e={...e,compactMap:r}}if(("compact"in e||a.compact&&("rotation"in e||"showXYIndicator"in e))&&Ho(),e.plotMode!==void 0)if(d){const r=Ft(l);if(a={...a,...r},v)for(const g of C)g&&g.setOptions(e);else X(Ge(l))}else if(m){const{valueRange:r,lotSize:g,aggregationMethod:h,...y}=a;if(a=y,v)for(const E of C)E&&E.setOptions(e);else X(c?Fe(P.filter(E=>E!==null)):B().filter(E=>E!==null))}else if(i!==c&&!v)X(Fe(P.filter(r=>r!==null)));else for(const r of C)r&&r.setOptions(e);else if(e.aggregationMethod!==void 0&&l==="stackedValues")if(v)for(const r of C)r&&r.setOptions(e);else X(Ge("stackedValues"));else for(const r of C)r&&r.setOptions(e);Ue()!==null!==s&&Nn(),At(),To(),Eo(),So();const p=e.plotMode!==void 0&&e.plotMode!==o;(Ca.some(r=>r in e)||p)&&R(),Te(),Lo(),Wo(),dn(),cn(),t&&u.onViewOptionsChange?.(Vt(a),n,Pn(n))}function Go(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:M.xs,flex:"1",minWidth:"0"});const i=e.createElement("span");i.textContent=t,Object.assign(i.style,{fontWeight:"700",fontSize:N.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(i);const s=gi(e,o,t,n,u.attributes);return{wrap:o,metaPanel:s}}function Ko(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]");if(!o||ja(n??{}).length===0)return;const i=o.parentElement,s=f.ownerDocument.createElement("div");Object.assign(s.style,{display:"flex",alignItems:"center",gap:M.xs,flex:"1",minWidth:"0"}),i?.insertBefore(s,o),s.appendChild(o);const l=gi(f.ownerDocument,s,t,n,u.attributes);l&&(e.contentWrap.style.position="relative",e.contentWrap.appendChild(l))}function Cn(e,t,n){const o=f.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:w.menuBg,border:`1px solid ${w.menuBorder}`,borderRadius:Y.container,boxShadow:On.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:yn(),maxHeight:yn()});const i=f.ownerDocument.createElement("div");Object.assign(i.style,{display:"flex",alignItems:"center",padding:`${M.md} ${M.lg} ${M.sm}`,borderBottom:`1px solid ${w.menuBorder}`,flexShrink:"0",gap:M.sm});const{wrap:s,metaPanel:l}=Go(document,ht(e,t),e.wafer.metadata??void 0);i.appendChild(s);const d=f.ownerDocument.createElement("button");d.dataset.wmapExpandBtn="1",d.setAttribute("aria-label","Open full view"),Ln(d),d.innerHTML=En.expand,Object.assign(d.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${w.menuBorder}`,borderRadius:Y.control,background:w.panelBg,color:w.label,padding:M.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),Tn(d),i.appendChild(d),i.addEventListener("click",r=>{(r.ctrlKey||r.metaKey)&&(r.preventDefault(),r.stopPropagation(),Ri(x.indexOf(e)))},!0),o.appendChild(i);const c=f.ownerDocument.createElement("div");Object.assign(c.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(c),Vo(o,c),l&&c.appendChild(l),F.appendChild(o),o.addEventListener("contextmenu",r=>{if(r.defaultPrevented)return;r.preventDefault();const g=e.viewOptions?{...a,...e.viewOptions}:a,h=on()??po(t),y=h?.source??wa(e.dies,{waferLabel:ve(e),testDefs:e.testDefs,isLotStack:e.isLotStack,activeTest:g.plotMode==="value"?g.activeTest:void 0,waferIndex:t,wafer:e.wafer,passBins:Se(e),ringCount:ne(e,"renderWaferGallery")}),E={x:r.clientX,y:r.clientY};import("./drilldown.js").then(({openDrilldownMenu:A})=>{o.isConnected&&A(E,o,y,h?{plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,...h.ctx}:{plots:I,getBinColors:()=>a.binColors??G(),attributes:u.attributes,onSaveImage:p.getSaveImageHook(),onSaveText:p.getSaveTextHook(),onLocateDie:j=>me(t,j)})})});const m=bt||Ue()!==null,v=e.viewOptions?{...a,...e.viewOptions}:a,p=di(c,e,{viewOptions:{...v,showLegend:m,legendPosition:Ye},showTooltip:!0,padding:z,statsSummary:e.statsSummary,testValueOffer:Jt,onSaveImage:u.onSaveImage,onSaveText:u.onSaveText,downloadFilename:u.downloadFilename,onClick:e.onClick,onSelect:lo(e),drilldownSourceOverride:()=>Ti(t),insights:de,onExpand:()=>ut(t,e),showIdentity:!1,chromeInset:Vs,drawWhenVisible:!0});return p.setViewControlsVisible(!1),p.setSummaryVisible(!1),d.onclick=()=>ut(t,e),xe.has(e)&&(o.style.display="none"),{card:o,ctrl:p,canvasWrapper:c,expandBtn:d}}function ds(e){const t=Ae[e];if(!t)return;const n=[...Q.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=En.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>fs(n.id)):(t.innerHTML=En.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>ut(e,x[e]))}function X(e){ps(),tt()?.remove(),nt(null),Oe(),x=[],U.clear(),an.clear(),ee.style.display="none";for(const c of C)c&&c.destroy();C=[],ue=[],Ae=[],ke=0,F.innerHTML="",zo=e.length,wn(e.map(c=>typeof c=="function"?null:c));const t=[];for(let c=0;c<e.length;c++){const m=e[c];if(typeof m=="function"){const v=f.ownerDocument.createElement("div");v.className="wmap-gallery-card",Object.assign(v.style,{background:w.menuBg,border:`1px solid ${w.menuBorder}`,borderRadius:Y.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const p=f.ownerDocument.createElement("span");p.textContent="\u2026",Object.assign(p.style,{color:w.label,fontSize:"18px"}),v.appendChild(p),F.appendChild(v),x.push(null),C.push(null),ue.push(null),Ae.push(null),t.push({index:c,factory:m,placeholder:v}),ke++}else{const{ctrl:v,canvasWrapper:p,expandBtn:r}=Cn(m,c,e.length);x.push(m),C.push(v),ue.push(p),Ae.push(r)}}Bo(),At(),dn(),cn(),Do();const n=++et,o=()=>{setTimeout(()=>{n===et&&u.onItemsResolved?.()},0)},i=c=>{setTimeout(()=>{n===et&&u.onItemResolved?.(c,e.length)},0)};let s=e.length-t.length;s>0&&i(s);let l=0;function d(){if(n!==et)return;if(l>=t.length){if(ie.has(a.plotMode)){const A=a.plotMode;X(Ge(A));return}if(wt){Yt();return}it=o,R(),je||(it=null,o());return}const{index:c,factory:m,placeholder:v}=t[l++],p=m();P[c]=p;const r=Gt(p,c);Ze(p,c)!==p&&(ae=!0),x[c]=r,wn([r]);const{card:g,ctrl:h,canvasWrapper:y,expandBtn:E}=Cn(r,c,e.length);C[c]=h,ue[c]=y,Ae[c]=E,ke--,v.replaceWith(g),i(++s),qi(),Ki(),!S&&!Pe?.placement&&r.statsSummary?.findings.length&&(S=Hn("right",oe,f.ownerDocument,sn),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.flexDirection="column",S.style.display="none",(Pe?.placement??"right")==="left"?Z.insertBefore(S,F):Z.appendChild(S),R(),re()),re(),setTimeout(d,0)}t.length>0?setTimeout(d,0):o()}if(ie.has(a.plotMode)&&B().length>0){const e=Ft(a.plotMode);a={...a,...e},X(Ge(a.plotMode))}else X(Fe(k));u.insights?.filter!==void 0&&Kt(),Te();let Ke=0;const qo=new(f.ownerDocument.defaultView??window).ResizeObserver(()=>{if(Ke)return;Ke=(f.ownerDocument.defaultView??window).requestAnimationFrame(()=>{Ke=0,T==null&&Sn()})});qo.observe(F),S&&R();function us(e,t){const n=ue[e];if(!n)return;n.innerHTML="",Object.assign(n.style,{alignItems:"center",justifyContent:"center"});const o=f.ownerDocument.createElement("span");o.textContent=t?"Opened in its own window":"Opened in the wafer viewer",Object.assign(o.style,{color:w.label,fontSize:N.body,textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function ut(e,t){for(const l of Q.values())if(l.cardIndex===e)return;const n=ht(t,e),o=Ci++,i=C[e]?.getOptions(),s=Gs(n);if(s){const l=s.document;l.title=n,Object.assign(l.documentElement.style,{height:"100%"}),Object.assign(l.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:N.family}),Xs(f,l.documentElement);const d=Ys(f,l.documentElement,()=>y.setOptions({})),c=l.createElement("div");c.dataset.wmapWindowBanner="1",c.textContent=n,Object.assign(c.style,{display:"none",padding:`${M.sm} ${M.xl}`,fontSize:N.body,fontWeight:"700",background:w.warnBg,color:w.warnText,borderBottom:`1px solid ${w.warnBorder}`,flexShrink:"0"}),l.body.appendChild(c);const m=l.createElement("div");Object.assign(m.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),l.body.appendChild(m);const{wrap:v,metaPanel:p}=Go(l,n,t.wafer.metadata??void 0),r=l.createElement("div");Object.assign(r.style,{display:"flex",alignItems:"center",padding:`${M.md} ${M.lg} ${M.sm}`,borderBottom:`1px solid ${w.menuBorder}`,flexShrink:"0",gap:M.sm}),r.appendChild(v),m.appendChild(r);const g=l.createElement("div");Object.assign(g.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),p&&g.appendChild(p),m.appendChild(g);let h=0;const y=xn(g,t,void 0,i,(A,j)=>{const ft=A?j:-h;try{s.resizeBy(ft,0),h=A?j:0}catch{}}),E=setInterval(()=>{s.closed&&It(o)},400);s.addEventListener("pagehide",()=>It(o)),Q.set(o,{id:o,ctrl:y,cardIndex:e,label:n,closePollId:E,stopThemeSync:d,close:()=>{s.closed||s.close()},setTitle:A=>{l.title=A,c.textContent=A,c.style.display="block"}})}else{const l=Ks({title:n,onClose:()=>It(o),anchor:f});l.contentWrap.style.flexDirection="column",Ko(l,n,t.wafer.metadata??void 0);const d=xn(l.contentWrap,t,void 0,i,li(l));Q.set(o,{id:o,ctrl:d,cardIndex:e,label:n,closePollId:null,close:()=>l.close(),setTitle:c=>{const m=l.box.querySelector("[data-wmap-window-title]");m&&(m.textContent=c,m.title=c)}})}C[e]?.destroy(),C[e]=null,us(e,s!==null),ds(e)}function xn(e,t,n,o,i){const s=t.viewOptions?{...a,...t.viewOptions}:a,l=o?{...s,...o}:s,c={...n!==void 0?{...l,plotMode:"value",activeTest:n}:l,showLegend:!0,legendPosition:Ye},m=di(e,t,{viewOptions:c,showTooltip:!0,padding:z,statsSummary:t.statsSummary,testValueOffer:Jt,onSaveImage:u.onSaveImage,onSaveText:u.onSaveText,downloadFilename:u.downloadFilename,onClick:t.onClick,onSelect:lo(t),insights:de,showExpandButton:!1,onSummaryPanelChange:i,showIdentity:!1});return m.setViewControlsVisible(!0),m.setSummaryVisible(!0),m.setExpandVisible(!1),m}function It(e){const t=Q.get(e);if(!t||(Q.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.(),t.ctrl.destroy(),t.cardIndex===null))return;const n=t.cardIndex,o=x[n];if(!o)return;const{card:i,ctrl:s,canvasWrapper:l,expandBtn:d}=Cn(o,n,x.length);ue[n]?.parentElement?.replaceWith(i),C[n]=s,ue[n]=l,Ae[n]=d}function fs(e){const t=Q.get(e);t&&(t.close(),It(e))}function ps(){for(const e of Q.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function Mn(){for(const e of C)e?.drawPendingNow()}const Xo=f.ownerDocument.defaultView??window;Xo.addEventListener("beforeprint",Mn);function ms(){Mn();const e=[...F.querySelectorAll("canvas")];if(!e.length)return;const t=e.length,n=Math.ceil(Math.sqrt(t)),o=Math.ceil(t/n),i=e[0].width,s=e[0].height,l=8,d=(f.ownerDocument.defaultView??window).devicePixelRatio||1,c=Math.round(26*d),m=Math.round(12*d),v=f.ownerDocument.createElement("canvas");v.width=n*i+(n-1)*l,v.height=o*(s+c)+(o-1)*l;const p=v.getContext("2d"),r=Fs(F);p.fillStyle=r.background,p.fillRect(0,0,v.width,v.height),e.forEach((g,h)=>{const y=h%n,E=Math.floor(h/n),A=y*(i+l),j=E*(s+c+l),ft=g.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";p.fillStyle=r.surface,p.fillRect(A,j,i,c),p.fillStyle=r.text,p.font=`700 ${m}px system-ui, sans-serif`,p.textAlign="left",p.textBaseline="middle",p.fillText(ft,A+Math.round(10*d),j+c/2,i-Math.round(20*d)),p.drawImage(g,A,j+c)}),v.toBlob(g=>{if(!g)return;const h=C.find(y=>y!=null)?.getExportTitle();ta(g,["gallery",h].filter(Boolean).join(" "),V.onSaveImage)})}return{setItems(e){en(),P=e.map(n=>typeof n=="function"?null:n);const t=a.plotMode;if(ie.has(t))if(e.some(o=>typeof o=="function"))X(Fe(e));else{const o=Ft(t);a={...a,...o},X(Ge(t))}else X(Fe(e));Zn()},setOptions(e){W(e,{fireCallback:!1})},getOptions(){return Vt(a)},setFindingsNotice(e){so=e,R()},setColumns(e){No(e)},getBinColors(){return a.binColors??G()},setLotStatsSummary(e){en(),_=e,Zn(),Te(),S&&R(),re()},openUserGuide:()=>mn(),destroy(){is(),I.flush(),en(),et++,Xo.removeEventListener("beforeprint",Mn),je?.cancel(),je=null,it=null;for(const e of[...Q.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();Q.clear();for(const e of C)e&&e.destroy();C=[],tt()?.remove(),qo.disconnect(),Ke&&((f.ownerDocument.defaultView??window).cancelAnimationFrame(Ke),Ke=0),f.ownerDocument.removeEventListener("click",Mt,!0),window.removeEventListener("blur",io),wi(),oi(),dt.remove(),Z.remove(),S?.remove(),Nt=!0,vt++,clearTimeout(qt),fe?.el.remove(),ye?.destroy()}}}
@@ -1 +1 @@
1
- import{createViewSwitch as go}from"./viewSwitch.js";import{createSummaryToggle as mo}from"./summaryToggle.js";import{buildView as yo,buildHoverText as bo,findTestDef as Wt,resolveTestNumber as xn,buildMapTitle as vo}from"../renderer/buildView.js";import{drawMapCanvas as xo,BIN_LEGEND_W as wi,BIN_LEGEND_W_COMPACT as wo,BIN_LEGEND_ADAPT_COMPACT as Co,BIN_LEGEND_ADAPT_FLOATING as So,PATH_SHAPES as Mo}from"./toCanvas.js";import{buildWaferMap as Eo,defaultBinMode as Bo,getTestPassStatus as ko,isParametricTest as wn,isBuiltMap as Ci}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Si}from"../stats/analyzeWaferMap.js";import{SHADOW as Do,LEADING as Mi,wireControlHover as Ei,SPACE as Y,EDGE_GUTTER as Lo,RADIUS as Bi,FONT as It,CLR as A,applyOverlayZ as Po,getTooltip as ki,hideTooltip as Vt,positionTooltip as Di,createToolbarHelpers as To,buildModeMenuEl as Oo,openReparentedModal as Ro,makePaletteBtn as Fo,makeLogScaleBtn as Ao,makeLegendStyleBtn as Wo,makeOverlaysBtn as Io,makeOrientationBtn as Vo,menuLayerFor as Li,saveImageBlob as zo,markMenuTrigger as st,wireMenuA11y as Pi,wireExpandToggle as Ho,nextFrame as Cn,requestedPassFailDisplay as Yo,overlayMenuRows as Xo,anyOverlayActive as Ko,openCompactDiagnostics as _o,roomForPanel as jo,logWmapVersionOnce as No,buildDataModeEntries as $o,metadataKeyHasData as Go,metadataModeEntry as Uo}from"./toolbar.js";import{openUserGuideWindow as Zo}from"./guideWindow.js";import{waferIdentityLabel as qo}from"../core/waferLabel.js";import{metadataDisplayValue as Qo}from"../core/metadata.js";import{withExportContext as Jo}from"./exportName.js";import{testValueNotice as es}from"./testValueOffer.js";import{axisPrefsFromOptions as Ti,optionsFromAxisPrefs as ts,CHART_PREF_KEYS as Sn}from"./chartPrefs.js";import{createSummaryPanelEl as Mn,wrapWithSummaryPanel as En,renderWaferSummaryContentSteps as ns}from"./summaryPanel.js";import{runChunked as is}from"./chunked.js";import{collectWarnings as os,buildWarningsMenuEl as ss,severityOf as ls}from"./warnings.js";import{plotStoreFor as as}from"./plotStore.js";import{selectionPopulation as rs,waferPopulation as ds}from"./chartPopulation.js";import{sourceFromBins as Oi}from"./plotItems.js";import{createIdentityHeader as cs,collapsedLabel as Bn}from"./identityHeader.js";import{getDieKey as de,hasPosition as Ri,isPositionedDie as fs}from"../core/dies.js";import{buildDieListSection as us}from"./dieList.js";import{buildMaplessSummary as ps}from"./maplessSummary.js";import{resolveBinColors as hs,binColorWarning as gs}from"../renderer/binColors.js";import{isPassBin as ms,requirePassBins as ys}from"../core/passBins.js";import{requireRingCount as lt}from"../core/ringCount.js";import{asList as bs,toggleHighlight as Fi}from"../core/utils.js";import{buildCompactMap as vs,compactLayoutOffered as xs}from"../core/compact.js";const ws={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(ws);const Ai=new Set(WAFER_PREFERENCE_KEYS);export const COLOR_KEYS=["binColorScheme","valueColorScheme","reverseValueScheme","useDefinedBinColors","binColors"];export function classifyChanged(L){const h=L.some(u=>Ai.has(u)),b=L.some(u=>!Ai.has(u));return h&&b?"mixed":h?"preference":"state"}export function findingBin(L,h,b){const{kind:u,bin:M}=L.variable;if(!(u!=="hardBin"&&u!=="softBin"||M===void 0))return h&&ms(u,M,h,b)?void 0:M}export function findingPlotMode(L,h,b){const{kind:u}=L.variable;return u==="hardBin"||u==="softBin"?u:h==="hardBin"||h==="softBin"?h:b?"hardBin":"softBin"}export function toPublicViewOptions(L){const{metadataValueOrder:h,binColors:b,lotSize:u,compactMap:M,...at}=L;return at}export function renderWaferMap(L,h,b={}){return renderWaferMapCard(L,h,b)}export function renderWaferMapCard(L,h,b={}){No();const u=L.ownerDocument,M=u.defaultView??window,at=()=>F.label,zt=()=>qo({label:at(),wafer:Z}),ae=Jo(()=>{const e=Qo(Z.metadata?.lot);return{prefix:b.downloadFilename,lots:e!==void 0?[e]:[],...F.isLotStack?{stackedWafers:m?.lotSize??!0}:{wafer:zt()}}},b.onSaveImage,b.onSaveText);function kn(){const e=m.plotMode==="softBin"||m.plotMode==="stackedSoftBins"?ie:ne,{primary:n,secondary:t}=vo(m,d.fallbackFormat,e);return[n,F.isLotStack?"":t].filter(Boolean).join(" ")||"wafer-map"}M.getComputedStyle(L).position==="static"&&(L.style.position="relative");const Wi=L.clientHeight;b.height!=null&&(L.style.height=typeof b.height=="number"?`${b.height}px`:b.height);const Ht=h.dataCoverage?h.dataCoverage.unpositionedDies:h.dies.filter(e=>!Ri(e)).length,Ke=(h.dataCoverage?h.dataCoverage.totalDies:h.dies.length-Ht)===0&&Ht>0,_e=u.createElement("div");Object.assign(_e.style,{display:"flex",flexDirection:"column",width:"100%",height:"100%"}),L.appendChild(_e);const Te=u.createElement("div");Object.assign(Te.style,{position:"relative",width:"100%",flex:"1 1 auto",minHeight:"0"});const be=b.chromeInset??Lo,K=u.createElement("div");Object.assign(K.style,{display:"flex",alignItems:"stretch",gap:Y.sm,background:A.canvasBg,paddingBottom:Y.lg,paddingTop:be,paddingLeft:be,paddingRight:be,flexShrink:"0",minWidth:"0"}),_e.appendChild(K),_e.appendChild(Te);function Oe(){const e=[...K.children].some(n=>n.style.display!=="none");K.style.display=e?"flex":"none"}const S=u.createElement("div");Object.assign(S.style,{position:"relative",width:"100%",height:"100%"});const a=u.createElement("canvas");Object.assign(a.style,{width:"100%",height:"100%",display:"block"}),S.appendChild(a),Te.appendChild(S);let rt=null;if(Ht>0){let t=function(){if(n){const l=us(e,h.testDefs,{...b.dieList,onSaveText:ae.onSaveText,waferMetadata:Z.metadata,metadataFields:Ce,ownerDocument:u});if(l)return l}const i=Wt(h.testDefs,d.activeTest??0),s=wn(i)?d.logScale??i?.logScale??!1:!1;return ps(e,h.testDefs,{plotMode:d.plotMode??"hardBin",activeTest:d.activeTest,hbinDefs:ne,sbinDefs:ie,binColors:m.binColors,valueColorScheme:d.valueColorScheme,reverseValueScheme:d.reverseValueScheme,logScale:s,colorbarRangeMode:d.colorbarRangeMode,valueRangeDies:h.dies})},o=function(i){const s=u.createElement("button");return s.type="button",Ei(s),Object.assign(s.style,{fontSize:It.body,padding:`${Y.xxs} ${Y.sm}`,borderRadius:Bi.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",i()}),s};const e=h.dies.filter(i=>!Ri(i));let n=!1;if(Ke){const i=u.createElement("div");Object.assign(i.style,{position:"absolute",inset:"0",background:A.panelBg,padding:Y.xl,boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",gap:Y.md,zIndex:"1"});const s=u.createElement("div");Object.assign(s.style,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:Y.md});const l=u.createElement("span");Object.assign(l.style,{fontSize:It.body,color:A.label,lineHeight:Mi.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(o(()=>r.replaceChildren(t()))),i.appendChild(s),i.appendChild(r),S.appendChild(i),rt=()=>{n||r.replaceChildren(t())}}else{const i=u.createElement("div");Object.assign(i.style,{position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"3",background:A.panelBg,borderTop:`1px solid ${A.menuBorder}`,fontSize:It.body,color:A.text,cursor:"pointer",padding:`${Y.xs} ${Y.md}`,display:"flex",alignItems:"center",justifyContent:"space-between",gap:Y.md}),Ei(i,"bare");const s=u.createElement("span");s.textContent=`+${e.length} ${e.length===1?"die":"dies"} without position data`,i.appendChild(s);const l=u.createElement("span");l.textContent="\u25BE",Object.assign(l.style,{fontSize:It.body,lineHeight:Mi.none,color:A.label,flexShrink:"0"}),i.appendChild(l),i.setAttribute("aria-expanded","false"),i.setAttribute("aria-label",`${e.length} dies without position data. Click to view.`);let r=null,c=null;Ho(i,f=>{if(l.textContent=f?"\u25B4":"\u25BE",i.setAttribute("aria-expanded",String(f)),f){r=u.createElement("div");const p=i.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:Y.md,boxSizing:"border-box",display:"flex",flexDirection:"column",gap:Y.md}),r.addEventListener("click",R=>R.stopPropagation());const y=u.createElement("div");Object.assign(y.style,{display:"flex",justifyContent:"flex-end"}),y.appendChild(o(()=>{c&&c.replaceChildren(t())})),r.appendChild(y),c=u.createElement("div"),Object.assign(c.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),c.appendChild(t()),r.appendChild(c),S.appendChild(r)}else r&&(r.remove(),r=null,c=null)}),S.appendChild(i),rt=()=>{c&&!n&&c.replaceChildren(t())}}}const{onHover:dt,onClick:Ii,onSelect:ce,onViewOptionsChange:Dn,showTooltip:Vi=!0,showToolbar:ve=!0,showIdentity:Ln=!0,summaryPanel:je,showHelpButton:Pn=!1,userGuideExtension:zi,onExpand:Tn,showExpandButton:On=!0,zIndex:Hi,insights:Re,warnings:Rn,viewOptions:Yi={},...Fe}=b,ct=Re?.enabled??ve;let Ne=null;ct&&(Ne=go(u,"Map","wafer",e=>Ge(e)),ve||(Ne.el.style.marginLeft="auto"),K.appendChild(Ne.el));const Xi=.4,Ki=20,xe=[...ys(h,"renderWaferMap")],Fn=Rn?.display??!0,_i=Po(Hi);let ee=b.statsSummary,me=[],An=!1,ft=null,Wn=!1;function Yt(){const e=os({result:h,statsSummary:ee,extra:ft?[ft]:[]}),n=e.length!==me.length||e.some((t,o)=>t.code!==me[o]?.code||t.message!==me[o]?.message);me=e,(n||!An)&&(An=!0,Rn?.onWarning?.(e))}Yt();let F=h,Z=h.wafer,te=h.dies,x=new Set,we=null;const Xt=Re?.plotStore??as(Re),ut={plots:Xt,attributes:b.attributes,onSaveImage:ae.onSaveImage,onSaveText:ae.onSaveText,onLocateDie:e=>Ot(e)},pt=()=>!Ke;let Kt=null,ht=null,gt=!1,mt=!1,ne=h.hbinDefs,ie=h.sbinDefs,q=h.testDefs,Ce=h.metadataFields,In=h.reticles?.length?h.reticles:void 0,yt=h.reticleConfig,Vn=h.dataAxisFlip,_t=h.isLotStack??!1,jt=h.aggrMethod,Nt=h.lotSize,Q=null,re=null,bt=null;function vt(e){bt&&(bt.style.display=e?"flex":"none",ze?.())}Ln&&(Q=cs(Bn(Z.metadata??{},$e())??"",Z.metadata,{lotStack:$e(),ownerDocument:u,attributes:b.attributes}),S.appendChild(Q.metaPanel),Q.metaPanel.style.visibility="visible",Q.isEmpty()||(re=zn(Q.wrap),K.insertBefore(re,K.firstChild),Oe()));function zn(e){const n=u.createElement("div");return Object.assign(n.style,{display:"flex",alignItems:"center",padding:`${Y.sm} ${Y.lg}`,flex:"1 1 auto",minWidth:"0",overflow:"hidden",gap:Y.sm}),Object.assign(e.style,{flex:"1",minWidth:"0"}),n.appendChild(e),n}function $e(){return _t?{lotSize:Nt??1,aggrMethod:jt}:void 0}function ji(){if(!Q)return;Q.update(Bn(Z.metadata??{},$e())??"",Z.metadata,$e());const e=re?.isConnected??!1,n=!Q.isEmpty();!n&&e?(re.remove(),re=null):n&&!e&&(re=zn(Q.wrap),re.style.display="",K.insertBefore(re,K.firstChild),Oe())}const Ni=[...ne??[],...ie??[]].some(e=>e.color);let d={plotMode:Bo([h.dies]),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,showReticle:!1,showXYIndicator:!1,compact:!1,rotation:0,flipX:!1,flipY:!1,legendPosition:"default",...Yi},_=null,fe=!1,Hn=null;function $i(){return ct?_?Promise.resolve(_):(Hn??=import("./insightsTab.js").then(({createInsightsTab:e})=>(_=e({initialAxisPrefs:Ti(d),onAxisPrefsChange:n=>{d={...d,...ts(n)};const t=[...Sn];Dn?.(d,t,classifyChanged(t))},attributes:b.attributes,getItems:()=>[{wafer:Z,dies:te,hbinDefs:ne,sbinDefs:ie,testDefs:q,label:at(),passBins:xe,statsSummary:ee}],getBinColors:()=>m.binColors,getRingCount:()=>lt(F,"renderWaferMap"),onSaveImage:ae.onSaveImage,onSaveText:ae.onSaveText,defaultView:Re?.defaultView,plotStore:Xt,onPickPlotsFile:Re?.onPickPlotsFile,showMetadataStrip:!1,contentInset:be,onOpenGuide:Pn&&!ve?()=>mn():void 0,focusTest:n=>{O({plotMode:"value",activeTest:n,highlightBin:void 0}),Ge(!1)},locateDie:n=>{Ge(!1),Ot(n)},ownerDocument:u}),Object.assign(_.el.style,{position:"absolute",inset:"0",background:A.canvasBg,overflowY:"auto",paddingTop:"0"}),_.el.style.display="none",Te.appendChild(_.el),_)),Hn):Promise.resolve(null)}let Yn=0;const $t=["wheel","touchstart","pointerdown","keydown"];function Gi(e,n){if(n<=0)return;let t=!1;const o=[],i=()=>{t=!0;for(const l of o)M.clearTimeout(l);o.length=0;for(const l of $t)e.removeEventListener(l,i)},s=()=>t||!fe?!0:(e.scrollTop=n,e.scrollTop>=n);if(!s()){for(const l of $t)e.addEventListener(l,i,{passive:!0,once:!0});for(const l of[0,50,150,300,600])o.push(M.setTimeout(()=>{s()},l));o.push(M.setTimeout(()=>{for(const l of $t)e.removeEventListener(l,i)},700))}}function Gt(){for(const e of[$,T])e&&(e.style.visibility=fe?"hidden":"")}function Ge(e){if(!ct)return;const n=fe;fe=e,Ne?.setInsightsOpen(e),_&&!e&&n&&(Yn=_.el.scrollTop),_&&(_.el.style.display=e?"flex":"none"),S.style.visibility=e?"hidden":"",Gt(),H&&(H.style.display=e||Ke?"none":"flex"),W&&(W.style.display=e?"none":"flex"),vt(!De),oe&&(oe.style.display="flex"),re&&(re.style.display=""),Oe(),ze?.(),Q&&e&&Q.collapse(),Je(),e&&$i().then(t=>{!t||!fe||(t.el.style.display="flex",t.render(),Gi(t.el,Yn))})}ct&&Re?.defaultOpen&&queueMicrotask(()=>Ge(!0));let m,Se,j=null,P=null,xt=[],Ut;function Xn(e){Ut!==e&&(Ut=e,w())}let Me=null,Zt=Fe.legendOffset??{x:0,y:0},Ue=!1,Ae=!1,Ze={x:0,y:0},qt={x:0,y:0},Ee=!1,We=!1,N="select",Ie={x:0,y:0},wt={x:0,y:0},I={x:0,y:0},V={x:0,y:0},qe=!1,Ve=!1;function Qt(){const e=d,n=te.filter(fs);m=yo(Z,n,{compact:d.compact?d.compactMap??vs(n):void 0,plotMode:e.plotMode,binColorScheme:e.binColorScheme,valueColorScheme:e.valueColorScheme,reverseValueScheme:e.reverseValueScheme,useDefinedBinColors:e.useDefinedBinColors,binColors:e.binColors??hs(te,{passBins:xe,binColorScheme:e.binColorScheme,hbinDefs:ne,sbinDefs:ie,useDefinedBinColors:e.useDefinedBinColors}),passBins:xe,showDieLabels:e.showDieLabels,showRingBoundaries:e.showRingBoundaries,showQuadrantBoundaries:e.showQuadrantBoundaries,showReticle:e.showReticle,showXYIndicator:e.showXYIndicator,reticles:In,ringCount:lt(F,"renderWaferMap"),highlightBin:e.highlightBin,highlightMetadataValue:e.highlightMetadataValue,activeTest:e.activeTest,activeMetadataKey:e.activeMetadataKey,testDefs:q,valueRange:e.valueRange,metadataValueOrder:e.metadataValueOrder,logScale:e.logScale,isLotStack:_t,aggregationMethod:jt??e.aggregationMethod,lotSize:Nt??e.lotSize,dataAxisFlip:Vn,colorbarRangeMode:e.colorbarRangeMode,passFailDisplay:e.passFailDisplay,fallbackFormat:e.fallbackFormat,interactiveTransform:{rotation:e.rotation??0,flipX:e.flipX??!1,flipY:e.flipY??!1}},{hbinDefs:ne,sbinDefs:ie,metadataFields:Ce}),Se=void 0;const t=e.binColors?null:gs(m.binColors,m.plotMode);t?.message!==ft?.message&&(ft=t,Yt(),Wn&&en())}Qt();function Kn(){return d.showAxes??Fe.showAxes??P!==null}function Ui(){return xs(te,[yt])}let $=null,Be=null,ue=null,ye=null,Ct=null;function _n(){ue===null&&ye===null&&(Ct={plotMode:d.plotMode,activeTest:d.activeTest})}function jn(){O({...Ct??{},highlightBin:void 0}),Ct=null}function Nn(e){if(ee=e,Yt(),en(),$)he();else if(T)Et();else if(e&&!je?.placement){const n=je?.defaultOpen??!ve;T=Mn("right",be,u,pn),T.style.display=n?"block":"none";const t=S.parentElement,o=S.nextSibling;pe=En(S,T,"right"),t?.insertBefore(pe,o),Et(),Gt()}Je()}function $n(){$?he():T&&Et()}let Gn=b.findingsNotice,St=!1;const Zi=()=>Gn??(b.testValueOffer?b.testValueOffer():void 0)??(!b.testValueOffer&&Ci(F)?es(ee?.stats.testValueAnalysis,1,St,qi):void 0);function qi(){const e=ee,n=F;if(St||!e||!Ci(n))return;St=!0,$n();const t=u.defaultView?.requestAnimationFrame?.bind(u.defaultView)??(s=>setTimeout(s,16));let o=!1;const i=()=>{if(o||mt)return;o=!0;const s=Si(n,{...e.analysisOptions,enableTestValueAnalysis:!0});St=!1,Nn(s),b.onStatsSummaryChange?.(s)};t(()=>t(i)),setTimeout(i,120)}let Qi={},T=null,pe=null;function Ji(e){const{kind:n,index:t}=e.variable;if(n==="test")O({plotMode:"value",activeTest:t??0,highlightBin:void 0});else{const i=te.some(s=>s.hbin!=null);O({plotMode:findingPlotMode(e,d.plotMode,i),highlightBin:findingBin(e,xe,i)})}const o=e.highlight;(o.kind==="bin"||o.kind==="region"||o.kind==="dies")&&Lt(o.dieKeys)}const Qe=new Map,Jt=new WeakSet;function Mt(e){if(Qe.get(e)?.cancel(),Qe.delete(e),e.style.display==="none"){Jt.add(e);return}Jt.delete(e);const n=is(ns(e,{wafer:Z,dies:te,yieldSummary:F.yield,dataCoverage:F.dataCoverage,hbinDefs:ne,sbinDefs:ie,testDefs:q,statsSummary:ee,warnings:Fn?me:[],passBins:xe,ringCount:lt(F,"renderWaferMap"),binColors:m.binColors,plotMode:d.plotMode??"hardBin",metadataShownElsewhere:Ln,fallbackFormat:d.fallbackFormat,activeFindingId:ue,findingsFilter:Qi,findingsNotice:Zi(),onFindingsFilterChange:he,onSaveText:ae.onSaveText,metadataFields:Ce,dieListOptions:b.dieList,onLocateDie:t=>Ot(t),onClose:ve&&ee?()=>an(!1):void 0,activeTest:ye,onTestClick:t=>{ye===t?(ye=null,Lt([]),jn()):(_n(),ue=null,ye=t,O({plotMode:"value",activeTest:t,highlightBin:void 0}),Lt(ee?.stats.testFailures?.[t]?.dieKeys)),he()},onFindingClick:(t,o)=>{ue===t.id?(ue=null,Lt([]),jn()):(_n(),ye=null,ue=t.id,Ji(t)),he()}}));n.done||Qe.set(e,n)}function he(){$?Mt($):T&&Mt(T)}function Et(){T&&Mt(T)}if(je?.placement){const e=je.placement;$=Mn(e,be,u,pn);const n=S.parentElement,t=S.nextSibling;Be=En(S,$,e),n?.insertBefore(Be,t),he()}else if(ee){const e=je?.defaultOpen??!ve;T=Mn("right",be,u,pn),T.style.display=e?"block":"none";const n=S.parentElement,t=S.nextSibling;pe=En(S,T,"right"),n?.insertBefore(pe,t),Et()}Gt();const z=Vi?ki(u):null;let oe=null,X=null,ze=null,H=null,W=null,Bt=null,kt=null,Un=!0,Zn=null,ge=null,Dt=null;Wn=!0;function en(){if(!ge||!Dt)return;const e=me.length,n=e>0;if(ge.style.display=n?"flex":"none",Dt.style.display=n?"":"none",ze?.(),!n)return;const t=ls(me[0]),o=`${e} data ${e===1?"warning":"warnings"}`;ge.style.color=t==="error"?A.errText:A.warnText,ge.ariaLabel=t==="error"?`${o} \u2014 the map may be positionally wrong`:o}let tn=null,qn=null,nn=null,on=null,sn=null,ln=null;function ke(e="selection"){ue===null&&ye===null||(ue=null,ye=null,Ct=null,e==="selection"?O({highlightBin:void 0}):(x=new Set,ce?.([])),he())}function Lt(e){x=new Set(e??[]),ce&&ce(Xe()),w()}function Je(){if(!kt)return;ze?.();const e=$??T;kt.sync({visible:Un&&!!ee&&!!e&&!fe,open:!!e&&e.style.display!=="none",notable:!!ee?.hasNotableFindings})}function an(e){const n=$??T;if(!n)return;const t=n.style.display!=="none",o=S.getBoundingClientRect().width;if(n.style.display=e?"block":"none",e!==t){const i=o-S.getBoundingClientRect().width;(b.onSummaryPanelChange??Pt)?.(e,e?i:0)}e&&Jt.has(n)&&Mt(n),Je()}if(ve){let R=function(D){N=D,o(v,D==="zoom"),o(G,D==="pan"),Bt&&o(Bt,D==="select"),a.style.cursor=D==="pan"?"grab":"crosshair"};oe=u.createElement("div"),oe.dataset.wmapToolbar="single",Object.assign(oe.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:Bi.control,boxShadow:Do.panel,pointerEvents:"auto"});const e=ki(u),n=To(e),{makeBtn:t,setActive:o,makeSep:i,syncSeparators:s,syncToolbarVisible:l,makeMenuRow:r,makeMenuSection:c,closeOpenMenu:f,getOpenMenu:p,setOpenMenu:y}=n;ze=()=>{X&&s(X),oe&&l(oe,"flex"),Oe()},tn=f,qn=p,u.addEventListener("click",f,!0),H=u.createElement("div"),Object.assign(H.style,{display:Ke?"none":"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),oe.appendChild(H);const se=t("download","Download PNG",so);H.appendChild(se),H.appendChild(i());const v=t("zoomMode","Zoom (drag to zoom region)",()=>R("zoom")),E=t("zoomIn","Zoom in",()=>Ye(a.clientWidth/2,a.clientHeight/2,1.2)),C=t("zoomOut","Zoom out",()=>Ye(a.clientWidth/2,a.clientHeight/2,1/1.2)),B=t("reset","Reset zoom (double-click)",()=>tt());H.appendChild(v),H.appendChild(E),H.appendChild(C),H.appendChild(B),H.appendChild(i());const G=t("pan","Pan (drag to move)",()=>R("pan"));H.appendChild(G),Bt=t("boxSelect","Select (drag to select dies)",()=>R("select")),H.appendChild(Bt);{const D=t("drilldown","Chart this wafer",()=>{const le=D.getBoundingClientRect();hn({x:le.left,y:le.bottom+4},D)});D.setAttribute("aria-haspopup","menu"),ht=D,ai(),H.appendChild(D)}R(N);{let D=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},le=function(g,k){g.activeTest!==void 0?O({plotMode:g.plotMode,activeTest:g.activeTest,activeMetadataKey:void 0,logScale:g.logScale}):g.activeMetadataKey!==void 0?O({plotMode:g.plotMode,activeTest:void 0,activeMetadataKey:g.activeMetadataKey,passFailDisplay:"off"}):O({plotMode:g.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),k.remove(),y(null),st(U,!1)};X=u.createElement("div"),Object.assign(X.style,{display:"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),oe.appendChild(X),W=u.createElement("div"),Object.assign(W.style,{display:"flex",alignItems:"center",gap:"0"}),X.appendChild(W),W.appendChild(i());const nt=()=>{const g=p();g&&(g.remove(),y(null)),st(U,!1)},U=t("mode","Plot mode",()=>{if(p()){nt();return}const g=te,k=m.testDefs,{testEntries:At,binEntries:Le,stackedEntries:it}=$o(g,k,{includeStacked:m.isLotStack}),vn=(Ce??[]).filter(Pe=>Go(g,Pe.key)).map(Uo),ot=Oo(U.getBoundingClientRect(),At,Le,it,D,le,{makeMenuRow:r,makeMenuSection:c},d.plotMode??"hardBin",U.ownerDocument.defaultView??window,vn);Li(U).appendChild(ot),y(ot),st(U,!0),Pi(ot,U,nt)});st(U,!1);const{btn:yn,sync:bn}=Fo(n,()=>({...d,plotMode:d.plotMode??"hardBin"}),()=>Ni,O);on=bn,on();const ao=Io(n,()=>{const g=!!m.hasReticle,k=(d.plotMode??"hardBin")==="value",{testNumber:At}=xn(d.activeTest??0,m.testDefs),Le=Wt(m.testDefs,At),it=k&&Le!==void 0&&!wn(Le),vn=k&&!it&&(Le?.limitLow!==void 0||Le?.limitHigh!==void 0),ot=k&&!it&&m.dies.some(Pe=>ko(Pe,At,Le)!==void 0);return Xo({...d,showAxes:Kn()},g,{functionalActive:it,hasLimits:vn,hasRecorded:ot,binMode:(d.plotMode??"hardBin")==="hardBin"||(d.plotMode??"hardBin")==="softBin"},Pe=>O(Pe),{on:!!d.compact,offered:Ui(),onChange:Pe=>O({compact:Pe}),onDiagnostics:()=>_o(te,[yt],{anchor:a,onSaveText:ae.onSaveText})})},()=>Ko(d)),{btn:ro,sync:co}=Wo(n,()=>d,g=>O({legendPosition:g}));nn=co,nn();const xi=()=>{const{testNumber:g}=xn(d.activeTest??0,q),k=Wt(q,g);return k!==void 0&&!wn(k)},{btn:fo,sync:uo}=Ao(n,()=>({...d,functionalActive:xi()}),g=>O(g));sn=uo,sn();const po=()=>{const{testNumber:g}=xn(d.activeTest??0,q),k=Wt(q,g);return k!==void 0&&(k.limitLow!==void 0||k.limitHigh!==void 0)},Ft=t("specRange","Colorbar range: test limits",()=>{const g=d.colorbarRangeMode==="data"?"spec":"data";O({colorbarRangeMode:g})});ln=()=>{const g=d.plotMode==="value"&&po()&&Yo(d)==="off"&&!xi();Ft.style.display=g?"":"none";const k=(d.colorbarRangeMode??"spec")==="spec";o(Ft,k),Ft.ariaLabel=k?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"},ln();const ho=Vo(n,()=>d,g=>O(g));W.appendChild(U),W.appendChild(yn),W.appendChild(fo),W.appendChild(Ft),Ke||(W.appendChild(i()),W.appendChild(ao),W.appendChild(i()),W.appendChild(ro),W.appendChild(i()),W.appendChild(ho)),kt=mo(u,()=>{const g=$??T;g&&an(g.style.display==="none")}),K.insertBefore(kt.el,Ne?.el??null),Je(),Fn&&(Dt=i(),ge=t("warning","Data warnings",()=>{const g=p();if(f(new MouseEvent("click")),g)return;const k=ss(ge.getBoundingClientRect(),me,M);Li(Te).appendChild(k),y(k),Pi(k,ge,()=>f(new MouseEvent("click")))}),st(ge,!1),X.appendChild(Dt),X.appendChild(ge),en()),On&&(X.appendChild(i()),bt=t("expand","Expand (E)",Tn??Qn),X.appendChild(bt)),Pn&&(X.appendChild(i()),Zn=t("help","User guide",()=>mn()),X.appendChild(Zn)),ze?.()}K.appendChild(oe),Oe()}let De=null,Pt=null;function Qn(){De&&(De.close(),De=null);const e=Te;e.style.flex="1",e.style.minWidth="0",e.style.minHeight="0";const n=Bn(Z.metadata??{},$e()),t=K.childElementCount>0?[K,e]:[e],o=Ro(t,{ownerDocument:u,boxSize:fe?{width:"min(96vw, 1600px)",height:"min(92vh, 1000px)"}:void 0,onClosed:()=>{De=null,Pt=null,vt(!0),fe||a.focus({preventScroll:!0})}});if(!o)return;o.box.setAttribute("aria-label",n??"Expanded wafer map"),t.length>1&&(o.contentWrap.style.flexDirection="column"),De=o,Pt=jo(o);const i=$??T,s=Be??pe;if(i&&s&&i.style.display!=="none"){const l=parseFloat(u.defaultView?.getComputedStyle(s).columnGap??"")||0,r=i.getBoundingClientRect().width+l;r>0&&Pt(!0,r)}vt(!1)}function Jn(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},Sn.some(l=>l in e)&&_?.setAxisPrefs(Ti(d));const t=Object.keys(e);if(t.length>0&&t.every(l=>Sn.includes(l)))return;("compact"in e||"compactMap"in e)&&(j=null,P=null),e.plotMode!==void 0&&e.plotMode,Object.keys(e).every(l=>l==="legendPosition"||l==="showLegend"||l==="markFailingDies"||l==="showAxes")||Qt(),nn?.(),on?.(),sn?.(),ln?.(),w();const i=e.plotMode!==void 0&&e.plotMode!==n,s=COLOR_KEYS.some(l=>l in e);(s||i)&&he(),(s||i||e.activeTest!==void 0||e.logScale!==void 0||e.colorbarRangeMode!==void 0)&&rt?.()}function O(e){Jn(e);const n=Object.keys(e);Dn?.(d,n,classifyChanged(n))}let rn=!1;const dn=b.drawWhenVisible&&M.IntersectionObserver?new M.IntersectionObserver(e=>{He=e[e.length-1].isIntersecting,He&&Tt&&w()},{rootMargin:"25%"}):null;let He=dn===null,Tt=!1;dn?.observe(a);function cn(){rn||(rn=!0,Cn(()=>{rn=!1,w()},M))}function w(){if(!He){Tt=!0;return}Tt=!1;const e=P??void 0,n=m.dies[0],t=n?{x:n.width,y:n.height}:Fe.diePitchMm,o=Math.floor(a.clientWidth||a.width),i=!!(ne?.length||ie?.length||m.dies.some(y=>y.hbin!=null||y.sbin!=null)),s=d.legendPosition??"default",l=d.showLegend??!0,r=s==="default"||s==="compact",c=(Fe.colorbarWidth??16)+28,f=i&&r?s!=="default"?Math.max(wi,c):o<So?0:o<Co?Math.max(wo,c):Math.max(wi,c):void 0,p=xo(a,m,{...Fe,minRightReserve:l?f:0,showColorbar:l&&(Fe.showColorbar??!0),markFailingDies:d.markFailingDies??!1,legendPosition:s,legendOffset:Zt,diePitchMm:t,fallbackFormat:d.fallbackFormat,showAxes:Kn(),viewport:e,activeBin:d.plotMode==="metadata"?d.highlightMetadataValue:d.highlightBin,hoverBin:Ut,afterDies:x.size>0||we!==null?eo:void 0,hbinDefs:ne,sbinDefs:ie,metadataFields:Ce});xt=p.binLegendRows,Me=p.legendBox??null,P===null&&(j=p.viewport),We&&oo(),ai()}function eo(e,n,t){x.size>0&&no(e,n,t),we!==null&&to(e,n,t)}function to(e,n,t){Se??=new Map(m.dies.map((y,R)=>[de(y),R]));const o=we===null?void 0:Se.get(we);if(o===void 0)return;const i=m.hoverPoints[o],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+i.x*n.ppm,f=n.originY-i.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 Ot(e){if(we=e===null?null:de(e),e!==null&&P!==null){tt();return}w()}function ei(){we!==null&&(we=null,w())}function no(e,n,t){const o=m.hoverPoints,i=m.rectangles[0],s=i?i.width/2*n.ppm:n.ppm*.5,l=i?i.height/2*n.ppm:n.ppm*.5,r=new Set;x.size>0&&(Se??=new Map(m.dies.map((v,E)=>[de(v),E])));for(const v of x){const E=Se.get(v);E!==void 0&&r.add(E)}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<o.length;v++)r.has(v)||(e.rect(n.originX+o[v].x*n.ppm-s,n.originY-o[v].y*n.ppm-l,s*2,l*2),++c===Mo&&(e.fill(),e.beginPath(),c=0));c&&e.fill(),e.globalAlpha=1;const{cw:f,ch:p}=io(n,s,l),y=new Map,R=v=>Math.round(v*100),se=(v,E,C,B)=>{const G=`${R(v)},${R(E)},${R(C)},${R(B)}`;y.has(G)?y.delete(G):y.set(G,[v,E,C,B])};for(const v of r){const E=n.originX+o[v].x*n.ppm,C=n.originY-o[v].y*n.ppm,B=E-f,G=E+f,D=C-p,le=C+p;se(B,D,G,D),se(B,le,G,le),se(B,D,B,le),se(G,D,G,le)}e.strokeStyle=t.text,e.lineWidth=2,e.lineCap="square",e.beginPath();for(const[v,E,C,B]of y.values())e.moveTo(v,E),e.lineTo(C,B);e.stroke(),e.restore()}function io(e,n,t){const o=m.hoverPoints,i=m.dies;let s=0,l=0;for(let r=0;r<i.length&&(!s||!l);r++){const c=i[r];if(!(c.x==null||c.y==null))for(const f of[Se.get(`${c.x+1},${c.y}`),Se.get(`${c.x},${c.y+1}`)]){if(f===void 0)continue;const p=Math.abs(o[f].x-o[r].x)*e.ppm,y=Math.abs(o[f].y-o[r].y)*e.ppm;p>y?s||=p/2:l||=y/2}}return{cw:s||n,ch:l||t}}function oo(){const e=a.getContext("2d"),n=Math.min(I.x,V.x),t=Math.min(I.y,V.y),o=Math.abs(V.x-I.x),i=Math.abs(V.y-I.y);e.save(),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(n,t,o,i),e.setLineDash([5,3]),e.strokeStyle="rgba(255,255,255,0.9)",e.lineWidth=3,e.strokeRect(n,t,o,i),e.strokeStyle="rgba(0,0,0,0.9)",e.lineWidth=1.5,e.strokeRect(n,t,o,i),e.restore()}function ti(){if(!Tt)return;const e=He;He=!0,w(),He=e}function so(){ti(),a.toBlob(e=>{e&&zo(e,kn(),ae.onSaveImage)})}function ni(e){return j?Math.max(j.ppm*Xi,Math.min(j.ppm*Ki,e)):e}function Ye(e,n,t){const o=P??j;if(!o)return;const i=ni(o.ppm*t),s=i/o.ppm,l=e-(e-o.originX)*s,r=n-(n-o.originY)*s,c=(j?.snapDist??1)/(i/(j?.ppm??i));P={originX:l,originY:r,ppm:i,snapDist:c},w()}function J(){return P??j}function ii(e){if(e.ctrlKey||e.metaKey){e.preventDefault();const n=a.getBoundingClientRect(),t=e.deltaY<0?1.12:1/1.12;Ye(e.clientX-n.left,e.clientY-n.top,t)}else if(P!==null){e.preventDefault();const n=J(),t=P.snapDist;P={originX:n.originX-e.deltaX,originY:n.originY-e.deltaY,ppm:n.ppm,snapDist:t},w()}}function fn(e,n,t){return e>=t.x&&e<t.x+t.w&&n>=t.y&&n<t.y+t.h}function oi(e){if(gt=!1,e.button!==0||(ei(),!J()))return;a.focus({preventScroll:!0}),a.setPointerCapture(e.pointerId);const n=a.getBoundingClientRect(),t=e.clientX-n.left,o=e.clientY-n.top;if(Me&&d.legendPosition==="floating"&&fn(t,o,Me)){Ae=!0,Ze={x:t,y:o},qt={...Zt};return}if(qe&&N!=="pan"){Ve=!0,Ee=!0,Ie={x:t,y:o},wt={x:J().originX,y:J().originY},a.style.cursor="grabbing";return}if(N==="zoom"||N==="select"){We=!0,I=V={x:t,y:o};return}Ee=!0,Ie={x:t,y:o},wt={x:J().originX,y:J().originY},a.style.cursor="grabbing"}function si(e){const n=a.getBoundingClientRect(),t=e.clientX-n.left,o=e.clientY-n.top;if(We){V={x:t,y:o},cn();return}if(Ae){const p=t-Ze.x,y=o-Ze.y;p*p+y*y>16&&(Ae=!1,Ue=!0,a.style.cursor="grabbing")}if(Ue){Zt={x:qt.x+(t-Ze.x),y:qt.y+(o-Ze.y)},cn();return}if(Ee){const p=J(),y=P?.snapDist??j?.snapDist??1;P={originX:wt.x+(t-Ie.x),originY:wt.y+(o-Ie.y),ppm:p.ppm,snapDist:y},cn();return}const i=J();if(!i)return;const s=(t-i.originX)/i.ppm,l=(i.originY-o)/i.ppm,c=gn(s,l,i.snapDist)?.die??null,f=xt.find(p=>t>=p.x&&t<p.x+p.w&&o>=p.y&&o<p.y+p.h);if(Xn(f?f.bin:void 0),f){a.style.cursor="pointer",z&&(z.textContent=f.label??`Bin ${f.bin}`,z.style.display="block",Di(z,a,e.clientX,e.clientY,{followPointer:!0})),dt?.(null,e);return}N==="pan"&&(a.style.cursor=c?"crosshair":"grab"),z&&(c?(z.innerHTML=bo(c,m.plotMode,{testDefs:q,hbinDefs:ne,sbinDefs:ie,fallbackFormat:d.fallbackFormat,aggrMethod:m.aggrMethod,lotSize:m.lotSize,metadataFields:Ce,activeTest:m.activeTest,reticleConfig:yt}),z.style.display="block",Di(z,a,e.clientX,e.clientY,{followPointer:!0})):z.style.display="none"),dt?.(c,e)}function li(e){const n=a.getBoundingClientRect(),t=e.clientX-n.left,o=e.clientY-n.top,i=e.ctrlKey||e.metaKey;if(z&&(t<0||o<0||t>n.width||o>n.height)&&(z.style.display="none"),We){We=!1,V={x:t,y:o};const r=t-I.x,c=o-I.y,f=J();if(N==="zoom"){if(r*r+c*c<25)Ye(t,o,2);else if(f){const p=Math.min(I.x,V.x),y=Math.max(I.x,V.x),R=Math.min(I.y,V.y),se=Math.max(I.y,V.y),v=y-p,E=se-R;if(v>4&&E>4){const C=a.clientWidth,B=a.clientHeight,G=C/v,D=B/E,le=Math.min(G,D),nt=ni(f.ppm*le),U=nt/f.ppm,yn=(p+y)/2,bn=(R+se)/2;P={originX:C/2-(yn-f.originX)*U,originY:B/2-(bn-f.originY)*U,ppm:nt,snapDist:f.snapDist/U}}}w(),a.style.cursor="crosshair";return}if(r*r+c*c<25)un(t,o,i,e);else if(f){const p=(Math.min(I.x,V.x)-f.originX)/f.ppm,y=(Math.max(I.x,V.x)-f.originX)/f.ppm,R=(f.originY-Math.max(I.y,V.y))/f.ppm,se=(f.originY-Math.min(I.y,V.y))/f.ppm,v=m.hoverPoints,E=[];for(let C=0;C<v.length;C++)if(v[C].x>=p&&v[C].x<=y&&v[C].y>=R&&v[C].y<=se){const B=m.dies[C];B&&E.push(B)}if(i)for(const C of E){const B=de(C);x.has(B)?x.delete(B):x.add(B)}else x=new Set(E.map(C=>de(C)));ke(),ce?.(Xe())}w(),a.style.cursor="crosshair";return}if(Ae){Ae=!1,un(t,o,i,e);return}if(Ue){Ue=!1,a.style.cursor="grab";return}if(!Ee)return;if(Ee=!1,Ve){Ve=!1,a.style.cursor=qe||N==="pan"?"grab":"crosshair";return}a.style.cursor=N==="pan"?"grab":"crosshair";const s=t-Ie.x,l=o-Ie.y;s*s+l*l<25&&un(t,o,i,e)}function un(e,n,t,o){for(const r of xt)if(e>=r.x&&e<r.x+r.w&&n>=r.y&&n<r.y+r.h){ke("legend"),typeof r.bin=="number"?O({highlightBin:Fi(d.highlightBin,r.bin,t)}):O({highlightMetadataValue:Fi(d.highlightMetadataValue,r.bin,t)});return}if(Me&&fn(e,n,Me))return;const i=J();if(!i)return;const l=gn((e-i.originX)/i.ppm,(i.originY-n)/i.ppm,i.snapDist)?.die??null;if(l){Ii?.(l,o);const r=de(l);t?x.has(r)?x.delete(r):x.add(r):x.size===1&&x.has(r)?x=new Set:x=new Set([r]),ke(),ce?.(Xe()),w()}else t||(x=new Set,ke(),ce?.([]),w())}function Xe(){const e=[],n=m.hoverPoints;for(let t=0;t<n.length;t++){const o=m.dies[t];o&&x.has(de(o))&&e.push(o)}return e}function ai(){ht&&(ht.style.display=pt()?"flex":"none",ht.ariaLabel=x.size>0?"Charts and tables for the selected dies (or right-click)":"Charts and tables for this wafer (or right-click)")}function ri(){const e={waferLabel:zt(),testDefs:q,isLotStack:F.isLotStack,wafer:F.wafer,passBins:xe,ringCount:lt(F,"renderWaferMap"),activeTest:d.plotMode==="value"?d.activeTest:void 0};return x.size>0?rs(Xe(),e):ds(te,e)}function pn(e,n,t){ue!==e&&n.click(),hn(t,$??T??a)}function lo(e,n){if(!pt())return;const t=d.plotMode==="softBin"?"soft":"hard",o=bs(d.highlightBin),i=o.length>1&&o.includes(e)?[...o]:[e],s=[{label:zt()??"this wafer",dies:te,wafer:F.wafer,passBins:xe,ringCount:lt(F,"renderWaferMap")}],l=Oi(s,t,i,q);if(!l)return;const r={...ut},c=i.length>1?Oi(s,t,[e],q):null;c&&(r.narrower={label:`Only ${t} bin ${e}`,backLabel:"All filtered bins",source:c,ctx:ut});const f=a;import("./drilldown.js").then(({openDrilldownMenu:p})=>{mt||(Kt=p(n,f,l,r))})}function hn(e,n){if(!pt())return;const t=b.drilldownSourceOverride?.(),o=t?.source??ri(),i={...ut,...t?.ctx};if(t?.narrowable){const s=ri(),l=s.items.reduce((r,c)=>r+c.dies.length,0);i.narrower={label:`Only this wafer \u2014 ${l.toLocaleString()} die${l===1?"":"s"}`,source:s,ctx:ut}}import("./drilldown.js").then(({openDrilldownMenu:s})=>{mt||(Kt=s(e,n,o,i))})}function di(e){e.stopPropagation();const n=gt;if(gt=!1,!pt()||fe)return;const t=a.getBoundingClientRect();if(!n){const i=e.clientX-t.left,s=e.clientY-t.top,l=xt.find(f=>i>=f.x&&i<f.x+f.w&&s>=f.y&&s<f.y+f.h);if(l&&typeof l.bin=="number"&&!F.isLotStack&&(d.plotMode===void 0||d.plotMode==="hardBin"||d.plotMode==="softBin")){e.preventDefault(),lo(l.bin,{x:e.clientX,y:e.clientY});return}if(Me&&fn(i,s,Me))return;const r=J(),c=r?gn((i-r.originX)/r.ppm,(r.originY-s)/r.ppm,r.snapDist)?.die:void 0;c&&!x.has(de(c))&&(x=new Set([de(c)]),ke(),ce?.(Xe()),w())}e.preventDefault();const o=n?{x:t.left+t.width/2,y:t.top+t.height/2}:{x:e.clientX,y:e.clientY};hn(o,a)}function ci(){Xn(void 0),z&&Vt(u),dt?.(null,new MouseEvent("mouseleave")),a.style.cursor=N==="pan"?"grab":"crosshair"}function fi(){Ee=!1,Ve=!1,We=!1,Ae=!1,Ue=!1,z&&Vt(u),dt?.(null,new MouseEvent("mouseleave")),a.style.cursor=N==="pan"?"grab":"crosshair",w()}function gn(e,n,t){const o=m.hoverPoints,i=m.rectangles;for(let c=0;c<i.length;c++){const f=i[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<o.length;c++){const f=o[c].x-e,p=o[c].y-n,y=f*f+p*p;y<r&&(r=y,s=m.dies[c]??null,l=c)}return s?{die:s,index:l}:null}const ui=new M.ResizeObserver(()=>{j=null,P=null,w()});ui.observe(a),b.height==null&&Wi<=0&&Cn(()=>Cn(()=>{L.clientHeight>0||console.warn("[wafermap] The map container has zero height, so the map cannot render. renderWaferMap fills its container \u2014 give the container a resolved height: an explicit CSS `height` (e.g. 600px), a height-resolved flex/grid parent, or `position:absolute; inset:0`. Alternatively pass `{ height: 600 }` in the render options and the library will size it for you.")}));let et=M.matchMedia(`(resolution: ${M.devicePixelRatio}dppx)`);const Rt=()=>{et.removeEventListener("change",Rt),et=M.matchMedia(`(resolution: ${M.devicePixelRatio}dppx)`),et.addEventListener("change",Rt),w()};et.addEventListener("change",Rt);const pi=M.matchMedia("(prefers-color-scheme: dark)"),hi=()=>w();pi.addEventListener("change",hi);const gi=()=>{z&&Vt(u)};M.addEventListener("blur",gi);function mi(e){if((e.key==="ContextMenu"||e.shiftKey&&e.key==="F10")&&(gt=!0),e.key==="Escape"&&ei(),e.key==="Escape"&&x.size>0&&(x=new Set,ke(),ce?.([]),w()),(e.key==="e"||e.key==="E")&&On&&(e.stopPropagation(),(Tn??Qn)()),(e.ctrlKey||e.metaKey)&&(e.key==="="||e.key==="+"?(e.preventDefault(),Ye(a.clientWidth/2,a.clientHeight/2,1.2)):e.key==="-"?(e.preventDefault(),Ye(a.clientWidth/2,a.clientHeight/2,1/1.2)):e.key==="0"&&(e.preventDefault(),tt())),!e.ctrlKey&&!e.metaKey&&!e.shiftKey){const t=J();if(t){const o=P?.snapDist??j?.snapDist??1;let i=0,s=0;e.key==="ArrowLeft"&&(i=20,e.preventDefault()),e.key==="ArrowRight"&&(i=-20,e.preventDefault()),e.key==="ArrowUp"&&(s=20,e.preventDefault()),e.key==="ArrowDown"&&(s=-20,e.preventDefault()),(i||s)&&(P={originX:t.originX+i,originY:t.originY+s,ppm:t.ppm,snapDist:o},w())}e.key===" "&&!qe&&(e.preventDefault(),qe=!0,N!=="pan"&&(a.style.cursor="grab"))}}function yi(e){e.key===" "&&(qe=!1,Ve&&(Ee=!1,Ve=!1),a.style.cursor=N==="pan"?"grab":"crosshair")}a.style.cursor="crosshair",a.setAttribute("tabindex","0"),a.addEventListener("wheel",ii,{passive:!1}),a.addEventListener("pointerdown",oi),a.addEventListener("pointermove",si),a.addEventListener("pointerup",li),a.addEventListener("pointerleave",ci),a.addEventListener("pointercancel",fi);const bi=()=>tt();a.addEventListener("dblclick",bi),a.addEventListener("keydown",mi),a.addEventListener("keyup",yi),a.addEventListener("contextmenu",di);const vi=e=>{e.stopPropagation()};a.addEventListener("click",vi),a.clientWidth,w(),rt?.();function tt(){j=null,P=null,w()}function mn(){import("./userGuideHtml.js").then(e=>Zo({buildWaferMap:Eo,renderWaferMap,renderWaferGallery:void 0,analyzeWaferMap:Si},e.USER_GUIDE_HTML,zi,L))}return Oe(),{setResult(e){F=e,Z=e.wafer,te=e.dies,ne=e.hbinDefs,ie=e.sbinDefs,q=e.testDefs,Ce=e.metadataFields,In=e.reticles?.length?e.reticles:void 0,yt=e.reticleConfig,Vn=e.dataAxisFlip,_t=e.isLotStack,jt=e.aggrMethod,Nt=e.lotSize,ji(),Qt(),w(),$&&he()},setOptions(e){Jn(e)},getOptions(){return{...d}},resetZoom:tt,setSelection(e){x=new Set(e.map(n=>de(n))),w()},getSelectedDies:()=>Xe(),clearSelection(){x=new Set,ke(),ce?.([]),w()},setFindingsNotice(e){Gn=e,$n()},setStatsSummary(e){Nn(e)},closeSummaryPanel(){an(!1)},getExportTitle(){return kn()},getSaveImageHook(){return ae.onSaveImage},locateDie:Ot,getSaveTextHook(){return ae.onSaveText},drawPendingNow:ti,getBinColors(){return m.binColors},setSummaryVisible(e){Un=e,Je()},setViewControlsVisible(e){X&&(X.style.display=e?"flex":"none")},setExpandVisible(e){vt(e)},openUserGuide:mn,setInsightsOpen(e){Ge(e)},destroy(){mt=!0,Xt.flush();for(const e of Qe.values())e.cancel();Qe.clear(),De?.close(),qn?.()?.remove(),tn&&u.removeEventListener("click",tn,!0),a.removeEventListener("wheel",ii),a.removeEventListener("pointerdown",oi),a.removeEventListener("pointermove",si),a.removeEventListener("pointerup",li),a.removeEventListener("pointerleave",ci),a.removeEventListener("pointercancel",fi),a.removeEventListener("dblclick",bi),a.removeEventListener("keydown",mi),a.removeEventListener("keyup",yi),a.removeEventListener("contextmenu",di),Kt?.(),a.removeEventListener("click",vi),ui.disconnect(),dn?.disconnect(),et.removeEventListener("change",Rt),pi.removeEventListener("change",hi),M.removeEventListener("blur",gi),_i(),z&&Vt(u),oe?.remove(),Be&&(Be.parentElement?.insertBefore(S,Be),Be.remove()),pe&&(pe.parentElement?.insertBefore(S,pe),pe.remove()),S.remove(),a.style.cursor="",_?.destroy(),Q?.destroy(),_e.remove()}}}
1
+ import{createViewSwitch as Wo}from"./viewSwitch.js";import{createSummaryToggle as Io}from"./summaryToggle.js";import{buildView as Vo,buildHoverText as Yo,findTestDef as Zt,resolveTestNumber as Fn,buildMapTitle as zo}from"../renderer/buildView.js";import{drawMapCanvas as Ho,BIN_LEGEND_W as zi,BIN_LEGEND_W_COMPACT as _o,BIN_LEGEND_ADAPT_COMPACT as Xo,BIN_LEGEND_ADAPT_FLOATING as Ko,PATH_SHAPES as No}from"./toCanvas.js";import{buildWaferMap as jo,computeCoverage as Hi,computeYield as _i,defaultBinMode as $o,getTestPassStatus as Go,isParametricTest as Rn,isBuiltMap as An}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Wn}from"../stats/analyzeWaferMap.js";import{SHADOW as Uo,LEADING as Xi,wireControlHover as Ki,SPACE as I,EDGE_GUTTER as Zo,RADIUS as Ni,FONT as qt,CLR as A,applyOverlayZ as qo,getTooltip as ji,hideTooltip as Qt,positionTooltip as $i,createToolbarHelpers as Qo,buildModeMenuEl as Jo,openReparentedModal as es,makePaletteBtn as ts,makeLogScaleBtn as ns,makeLegendStyleBtn as is,makeOverlaysBtn as os,makeOrientationBtn as ss,menuLayerFor as Gi,saveImageBlob as ls,markMenuTrigger as mt,wireMenuA11y as Ui,wireExpandToggle as as,nextFrame as In,requestedPassFailDisplay as rs,overlayMenuRows as ds,anyOverlayActive as cs,openCompactDiagnostics as fs,roomForPanel as us,logWmapVersionOnce as ps,buildDataModeEntries as hs,metadataKeyHasData as gs,metadataModeEntry as Zi}from"./toolbar.js";import{openUserGuideWindow as ms,registerGuideOpener as ys}from"./guideWindow.js";import{waferIdentityLabel as bs}from"../core/waferLabel.js";import{metadataDisplayValue as vs}from"../core/metadata.js";import{withExportContext as ws}from"./exportName.js";import{testValueNotice as xs}from"./testValueOffer.js";import{axisPrefsFromOptions as qi,optionsFromAxisPrefs as Cs,CHART_PREF_KEYS as Vn}from"./chartPrefs.js";import{createSummaryPanelEl as Yn,wrapWithSummaryPanel as zn,renderWaferSummaryContentSteps as Ss}from"./summaryPanel.js";import{runChunked as Ms}from"./chunked.js";import{collectWarnings as Es,buildWarningsMenuEl as Bs,severityOf as ks}from"./warnings.js";import{plotStoreFor as Ds}from"./plotStore.js";import{selectionPopulation as Ps,waferPopulation as Ts}from"./chartPopulation.js";import{sourceFromBins as Qi}from"./plotItems.js";import{createIdentityHeader as Ls,collapsedLabel as Hn}from"./identityHeader.js";import{getDieKey as he,hasPosition as Ji,isPositionedDie as Os}from"../core/dies.js";import{bandButton as Fs}from"./filterButton.js";import{buildDieListSection as Rs}from"./dieList.js";import{buildMaplessSummary as As}from"./maplessSummary.js";import{resolveBinColors as Ws,binColorWarning as Is}from"../renderer/binColors.js";import{isPassBin as Vs,requirePassBins as Ys}from"../core/passBins.js";import{PAT_MODE_FIELD as zs,PAT_MODE_KEY as Hs,isPatMode as eo,patModeOffered as _s,withPatField as Xs,withPatVerdicts as Ks}from"./patMode.js";import{requireRingCount as Ve}from"../core/ringCount.js";import{asList as Ns,toggleHighlight as to}from"../core/utils.js";import{buildCompactMap as js,compactLayoutOffered as $s}from"../core/compact.js";const Gs={binColorScheme:!0,valueColorScheme:!0,reverseValueScheme:!0,useDefinedBinColors:!0,showDieLabels:!0,showRingBoundaries:!0,showQuadrantBoundaries:!0,showReticle:!0,showXYIndicator:!0,showAxes:!0,legendPosition:!0,colorbarRangeMode:!0,markFailingDies:!0,fallbackFormat:!0,chartAxisIncludesLimits:!0,chartClipOutliers:!0,chartLimitLines:!0};export const WAFER_PREFERENCE_KEYS=Object.keys(Gs);const no=new Set(WAFER_PREFERENCE_KEYS);export const COLOR_KEYS=["binColorScheme","valueColorScheme","reverseValueScheme","useDefinedBinColors","binColors"];export function classifyChanged(P){const h=P.some(u=>no.has(u)),y=P.some(u=>!no.has(u));return h&&y?"mixed":h?"preference":"state"}export function findingBin(P,h,y){const{kind:u,bin:B}=P.variable;if(!(u!=="hardBin"&&u!=="softBin"||B===void 0))return h&&Vs(u,B,h,y)?void 0:B}export function findingPlotMode(P,h,y){const{kind:u}=P.variable;return u==="hardBin"||u==="softBin"?u:h==="hardBin"||h==="softBin"?h:y?"hardBin":"softBin"}export function toPublicViewOptions(P){const{metadataValueOrder:h,binColors:y,lotSize:u,compactMap:B,...Je}=P;return Je}export function renderWaferMap(P,h,y={}){return renderWaferMapCard(P,h,y)}export function renderWaferMapCard(P,h,y={}){ps();const u=P.ownerDocument,B=u.defaultView??window,Je=()=>C.label,yt=()=>bs({label:Je(),wafer:j}),de=ws(()=>{const e=vs(j.metadata?.lot);return{prefix:y.downloadFilename,lots:e!==void 0?[e]:[],...C.isLotStack?{stackedWafers:m?.lotSize??!0}:{wafer:yt()}}},y.onSaveImage,y.onSaveText);function _n(){const e=m.plotMode==="softBin"||m.plotMode==="stackedSoftBins"?oe:ie,{primary:n,secondary:t}=zo(m,d.fallbackFormat,e);return[n,C.isLotStack?"":t].filter(Boolean).join(" ")||"wafer-map"}B.getComputedStyle(P).position==="static"&&(P.style.position="relative");const io=P.clientHeight;y.height!=null&&(P.style.height=typeof y.height=="number"?`${y.height}px`:y.height);const Jt=h.dataCoverage?h.dataCoverage.unpositionedDies:h.dies.filter(e=>!Ji(e)).length,et=(h.dataCoverage?h.dataCoverage.totalDies:h.dies.length-Jt)===0&&Jt>0,Ye=u.createElement("div");Object.assign(Ye.style,{display:"flex",flexDirection:"column",width:"100%",height:"100%"}),P.appendChild(Ye);const Me=u.createElement("div");Object.assign(Me.style,{position:"relative",width:"100%",flex:"1 1 auto",minHeight:"0"});const ge=y.chromeInset??Zo,V=u.createElement("div");Object.assign(V.style,{display:"flex",alignItems:"stretch",gap:I.sm,background:A.canvasBg,paddingBottom:I.lg,paddingTop:ge,paddingLeft:ge,paddingRight:ge,flexShrink:"0",minWidth:"0"}),Ye.appendChild(V),Ye.appendChild(Me);function ze(){const e=[...V.children].some(n=>n.style.display!=="none");V.style.display=e?"flex":"none"}const M=u.createElement("div");Object.assign(M.style,{position:"relative",width:"100%",height:"100%"});const a=u.createElement("canvas");Object.assign(a.style,{width:"100%",height:"100%",display:"block"}),M.appendChild(a),Me.appendChild(M);let bt=null;if(Jt>0){let t=function(){if(n){const l=Rs(e,h.testDefs,{...y.dieList,onSaveText:de.onSaveText,waferMetadata:j.metadata,metadataFields:Ke,attributes:y.attributes,ownerDocument:u});if(l)return l}const o=Zt(h.testDefs,d.activeTest??0),s=Rn(o)?d.logScale??o?.logScale??!1:!1;return As(e,h.testDefs,{plotMode:d.plotMode??"hardBin",activeTest:d.activeTest,hbinDefs:ie,sbinDefs:oe,binColors:m.binColors,valueColorScheme:d.valueColorScheme,reverseValueScheme:d.reverseValueScheme,logScale:s,colorbarRangeMode:d.colorbarRangeMode,valueRangeDies:h.dies})},i=function(o){const s=u.createElement("button");return s.type="button",Ki(s),Object.assign(s.style,{fontSize:qt.body,padding:`${I.xxs} ${I.sm}`,borderRadius:Ni.control,flexShrink:"0",border:`1px solid ${A.menuBorder}`,background:A.menuBg,color:A.text,cursor:"pointer"}),s.textContent=n?"View chart":"View die list",s.addEventListener("click",l=>{l.stopPropagation(),n=!n,s.textContent=n?"View chart":"View die list",o()}),s};const e=h.dies.filter(o=>!Ji(o));let n=!1;if(et){const o=u.createElement("div");Object.assign(o.style,{position:"absolute",inset:"0",background:A.panelBg,padding:I.xl,boxSizing:"border-box",overflow:"hidden",display:"flex",flexDirection:"column",gap:I.md,zIndex:"1"});const s=u.createElement("div");Object.assign(s.style,{display:"flex",justifyContent:"space-between",alignItems:"flex-start",gap:I.md});const l=u.createElement("span");Object.assign(l.style,{fontSize:qt.body,color:A.label,lineHeight:Xi.base}),l.textContent="No die position data for this wafer.",s.appendChild(l);const r=u.createElement("div");Object.assign(r.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),s.appendChild(i(()=>r.replaceChildren(t()))),o.appendChild(s),o.appendChild(r),M.appendChild(o),bt=()=>{n||r.replaceChildren(t())}}else{const o=u.createElement("div");Object.assign(o.style,{position:"absolute",left:"0",right:"0",bottom:"0",zIndex:"3",background:A.panelBg,borderTop:`1px solid ${A.menuBorder}`,fontSize:qt.body,color:A.text,cursor:"pointer",padding:`${I.xs} ${I.md}`,display:"flex",alignItems:"center",justifyContent:"space-between",gap:I.md}),Ki(o,"bare");const s=u.createElement("span");s.textContent=`+${e.length} ${e.length===1?"die":"dies"} without position data`,o.appendChild(s);const l=u.createElement("span");l.textContent="\u25BE",Object.assign(l.style,{fontSize:qt.body,lineHeight:Xi.none,color:A.label,flexShrink:"0"}),o.appendChild(l),o.setAttribute("aria-expanded","false"),o.setAttribute("aria-label",`${e.length} dies without position data. Click to view.`);let r=null,c=null;as(o,f=>{if(l.textContent=f?"\u25B4":"\u25BE",o.setAttribute("aria-expanded",String(f)),f){r=u.createElement("div");const p=o.getBoundingClientRect().height||28;Object.assign(r.style,{position:"absolute",left:"0",right:"0",bottom:`${p}px`,top:"20%",zIndex:"2",background:A.panelBg,borderTop:`1px solid ${A.menuBorder}`,padding:I.md,boxSizing:"border-box",display:"flex",flexDirection:"column",gap:I.md}),r.addEventListener("click",R=>R.stopPropagation());const b=u.createElement("div");Object.assign(b.style,{display:"flex",justifyContent:"flex-end"}),b.appendChild(i(()=>{c&&c.replaceChildren(t())})),r.appendChild(b),c=u.createElement("div"),Object.assign(c.style,{flex:"1",minHeight:"0",overflow:"auto",display:"flex",flexDirection:"column"}),c.appendChild(t()),r.appendChild(c),M.appendChild(r)}else r&&(r.remove(),r=null,c=null)}),M.appendChild(o),bt=()=>{c&&!n&&c.replaceChildren(t())}}}const{onHover:vt,onClick:oo,onSelect:me,onViewOptionsChange:Xn,showTooltip:so=!0,showToolbar:Ee=!0,showIdentity:Kn=!0,summaryPanel:tt,showHelpButton:Nn=!1,userGuideExtension:lo,onExpand:jn,showExpandButton:$n=!0,zIndex:ao,insights:J,warnings:Gn,viewOptions:ro={},...He}=y,Be=J?.enabled??Ee;let nt=null,_e=null;Be&&(nt=Wo(u,"Map","wafer",e=>Ce(e)),Ee||(nt.el.style.marginLeft="auto"),V.appendChild(nt.el)),Be&&(_e=Fs(u,"Filter\u2026","wmapMapFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>{nn().then(e=>e.openEditor(_e??P,[St()]))}),_e.style.order="1",V.appendChild(_e));const co=.4,fo=20,ne=[...Ys(h,"renderWaferMap")],Un=Gn?.display??!0,uo=qo(ao);let ce=y.statsSummary,ke=!1,wt;const fe=()=>ke?wt:ce;let we=[],Zn=!1,xt=null,qn=!1;function en(){const e=Es({result:h,statsSummary:fe(),extra:xt?[xt]:[]}),n=e.length!==we.length||e.some((t,i)=>t.code!==we[i]?.code||t.message!==we[i]?.message);we=e,(n||!Zn)&&(Zn=!0,Gn?.onWarning?.(e))}en();let C=h,j=h.wafer,Ct=h.dies,Y=h.dies,xe=null,Qn=null,De=null;const St=()=>({dies:Ct,wafer:j,label:Je()??"Wafer",identity:yt(),waferIndex:0,passBins:ne,testDefs:K,statsSummary:ce});function tn(){const e=xe?.get();if(wt=void 0,!xe||!e||e.off)return ke=!1,Ct;const n=xe.mark([St()]);ke=n.narrowing;const t=n.items[0].dies;if(ke&&ce&&An(C)){const i=t.filter(o=>!o.filteredOut);try{wt=i.length===0?void 0:Wn({...C,dies:i,yield:_i(t,ne,C.yield?.yieldPercentGross!=null?"denominator-only":"exclude"),dataCoverage:Hi(i)},ce.analysisOptions)}catch{wt=void 0}}return t}function Jn(){if(!xe||!De)return;const e=[St()];De.refresh(xe.keep(e).result,e),De.el.style.display=xe.get()&&!pe?"":"none"}function ei(){Y=tn(),Jn(),at(),w(),gn(ce)}function nn(){return Qn??=import("./pageFilter.js").then(({createPageFilter:e})=>{const n=e({doc:u,initial:J?.filter,onChange:J?.onFilterChange,savedFilters:J?.savedFilters,onSavedFiltersChange:J?.onSavedFiltersChange,pickFiltersFile:J?.onPickFiltersFile,onSaveText:y.onSaveText,attributes:y.attributes,getRingCount:()=>Ve(C,"renderWaferMap")});return xe=n,De=n.createBand(()=>[St()],{marginLeft:ge,marginRight:ge,marginBottom:I.lg}),Ye.insertBefore(De.el,Me),n.subscribe(()=>{Xe||ei()}),n.get()&&!Xe&&ei(),n}),Qn}let x=new Set,Pe=null;const on=J?.plotStore??Ds(J),Mt={plots:on,getBinColors:()=>m.binColors,attributes:y.attributes,onSaveImage:de.onSaveImage,onSaveText:de.onSaveText,onLocateDie:e=>Kt(e)},Et=()=>!et;let sn=null,Bt=null,kt=!1,Xe=!1,ie=h.hbinDefs,oe=h.sbinDefs,K=h.testDefs,Ke=h.metadataFields,ti=h.reticles?.length?h.reticles:void 0,Dt=h.reticleConfig,ni=h.dataAxisFlip,ln=h.isLotStack??!1,an=h.aggrMethod,rn=h.lotSize,ee=null,ue=null,Pt=null;function Tt(e){Pt&&(Pt.style.display=e?"flex":"none",Ue?.())}Kn&&(ee=Ls(Hn(j.metadata??{},it())??"",j.metadata,{lotStack:it(),ownerDocument:u,attributes:y.attributes}),M.appendChild(ee.metaPanel),ee.metaPanel.style.visibility="visible",ee.isEmpty()||(ue=ii(ee.wrap),V.insertBefore(ue,V.firstChild),ze()));function ii(e){const n=u.createElement("div");return Object.assign(n.style,{display:"flex",alignItems:"center",padding:`${I.sm} ${I.lg}`,flex:"1 1 auto",minWidth:"0",overflow:"hidden",gap:I.sm}),Object.assign(e.style,{flex:"1",minWidth:"0"}),n.appendChild(e),n}function it(){return ln?{lotSize:rn??1,aggrMethod:an}:void 0}function po(){if(!ee)return;ee.update(Hn(j.metadata??{},it())??"",j.metadata,it());const e=ue?.isConnected??!1,n=!ee.isEmpty();!n&&e?(ue.remove(),ue=null):n&&!e&&(ue=ii(ee.wrap),ue.style.display="",V.insertBefore(ue,V.firstChild),ze())}const ho=[...ie??[],...oe??[]].some(e=>e.color);let d={plotMode:$o([h.dies]),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,showReticle:!1,showXYIndicator:!1,compact:!1,rotation:0,flipX:!1,flipY:!1,legendPosition:"default",...ro},$=null,pe=!1,oi=null;function si(){return Be?$?Promise.resolve($):(oi??=Promise.all([import("./insightsTab.js"),nn()]).then(([{createInsightsTab:e},n])=>($=e({pageFilter:n,showFilterButton:!1,initialAxisPrefs:qi(d),onAxisPrefsChange:t=>{d={...d,...Cs(t)};const i=[...Vn];Xn?.(d,i,classifyChanged(i))},attributes:y.attributes,getItems:()=>[{wafer:j,dies:Ct,hbinDefs:ie,sbinDefs:oe,testDefs:K,label:Je(),passBins:ne,ringCount:Ve(C,"renderWaferMap"),statsSummary:ce}],getBinColors:()=>m.binColors,getRingCount:()=>Ve(C,"renderWaferMap"),onSaveImage:de.onSaveImage,onSaveText:de.onSaveText,defaultView:J?.defaultView,plotStore:on,onPickPlotsFile:J?.onPickPlotsFile,showPatMap:()=>{Ce(!1),L({plotMode:"metadata",activeTest:void 0,activeMetadataKey:Hs,passFailDisplay:"off"})},showOnMap:t=>{if(Ce(!1),t.kind==="test")ui(t.testNumber);else{const i=fe()?.findings.find(o=>o.id===t.id);i&&pi(i)}fe()&&Ht(!0)},showMetadataStrip:!1,contentInset:ge,onOpenGuide:Nn&&!Ee?()=>jt():void 0,focusTest:t=>{L({plotMode:"value",activeTest:t,highlightBin:void 0}),Ce(!1)},locateDie:t=>{Ce(!1),Kt(t)},ownerDocument:u}),Object.assign($.el.style,{position:"absolute",inset:"0",background:A.canvasBg,overflowY:"auto",paddingTop:"0"}),$.el.style.display="none",Me.appendChild($.el),$)),oi):Promise.resolve(null)}let li=0;const dn=["wheel","touchstart","pointerdown","keydown"];function go(e,n){if(n<=0)return;let t=!1;const i=[],o=()=>{t=!0;for(const l of i)B.clearTimeout(l);i.length=0;for(const l of dn)e.removeEventListener(l,o)},s=()=>t||!pe?!0:(e.scrollTop=n,e.scrollTop>=n);if(!s()){for(const l of dn)e.addEventListener(l,o,{passive:!0,once:!0});for(const l of[0,50,150,300,600])i.push(B.setTimeout(()=>{s()},l));i.push(B.setTimeout(()=>{for(const l of dn)e.removeEventListener(l,o)},700))}}function cn(){for(const e of[Z,F])e&&(e.style.visibility=pe?"hidden":"")}function Ce(e){if(!Be)return;const n=pe;pe=e,nt?.setInsightsOpen(e),De&&(De.el.style.display=xe?.get()&&!e?"":"none"),$&&!e&&n&&(li=$.el.scrollTop),$&&($.el.style.display=e?"flex":"none"),M.style.visibility=e?"hidden":"",cn(),X&&(X.style.display=e||et?"none":"flex"),W&&(W.style.display=e?"none":"flex"),Tt(!Ae),le&&(le.style.display="flex"),ue&&(ue.style.display=""),ze(),Ue?.(),ee&&e&&ee.collapse(),ct(),e&&si().then(t=>{!t||!pe||(t.el.style.display="flex",t.render(),go(t.el,li))})}Be&&J?.defaultOpen&&queueMicrotask(()=>Ce(!0));let m,Te,G=null,O=null,Lt=[],fn;function ai(e){fn!==e&&(fn=e,w())}let Le=null,un=He.legendOffset??{x:0,y:0},ot=!1,Ne=!1,st={x:0,y:0},pn={x:0,y:0},Oe=!1,je=!1,U="select",$e={x:0,y:0},Ot={x:0,y:0},z={x:0,y:0},H={x:0,y:0},lt=!1,Ge=!1;const hn=()=>eo(d)?Xs(Ke):Ke;function at(){const e=d,i=(eo(e)?Ks(Y,K,ne):Y).filter(Os);m=Vo(j,i,{compact:d.compact?d.compactMap??js(i):void 0,plotMode:e.plotMode,binColorScheme:e.binColorScheme,valueColorScheme:e.valueColorScheme,reverseValueScheme:e.reverseValueScheme,useDefinedBinColors:e.useDefinedBinColors,binColors:e.binColors??Ws(Y,{passBins:ne,binColorScheme:e.binColorScheme,hbinDefs:ie,sbinDefs:oe,useDefinedBinColors:e.useDefinedBinColors}),passBins:ne,showDieLabels:e.showDieLabels,showRingBoundaries:e.showRingBoundaries,showQuadrantBoundaries:e.showQuadrantBoundaries,showReticle:e.showReticle,showXYIndicator:e.showXYIndicator,reticles:ti,ringCount:Ve(C,"renderWaferMap"),highlightBin:e.highlightBin,highlightMetadataValue:e.highlightMetadataValue,activeTest:e.activeTest,activeMetadataKey:e.activeMetadataKey,testDefs:K,valueRange:e.valueRange,metadataValueOrder:e.metadataValueOrder,logScale:e.logScale,isLotStack:ln,aggregationMethod:an??e.aggregationMethod,lotSize:rn??e.lotSize,dataAxisFlip:ni,colorbarRangeMode:e.colorbarRangeMode,passFailDisplay:e.passFailDisplay,fallbackFormat:e.fallbackFormat,interactiveTransform:{rotation:e.rotation??0,flipX:e.flipX??!1,flipY:e.flipY??!1}},{hbinDefs:ie,sbinDefs:oe,metadataFields:hn()}),Te=void 0;const o=e.binColors?null:Is(m.binColors,m.plotMode);o?.message!==xt?.message&&(xt=o,en(),qn&&yn())}at();function ri(){return d.showAxes??He.showAxes??O!==null}function mo(){return $s(Y,[Dt])}let Z=null,Fe=null,ye=null,Se=null,Ft=null;function di(){ye===null&&Se===null&&(Ft={plotMode:d.plotMode,activeTest:d.activeTest})}function ci(){L({...Ft??{},highlightBin:void 0}),Ft=null}function gn(e){const n=e!==ce;if(ce=e,n&&ke&&(Y=tn(),at(),w()),en(),yn(),Z)se();else if(F)Wt();else if(e&&!tt?.placement){const t=tt?.defaultOpen??!Ee;F=Yn("right",ge,u,Dn),F.style.display=t?"block":"none";const i=M.parentElement,o=M.nextSibling;be=zn(M,F,"right"),i?.insertBefore(be,o),Wt(),cn()}ct()}function Rt(){Z?se():F&&Wt()}let fi=y.findingsNotice,rt=!1;const yo=()=>fi??(y.testValueOffer?y.testValueOffer():void 0)??(!y.testValueOffer&&An(C)?xs(fe()?.stats.testValueAnalysis,1,rt,bo):void 0);function bo(){const e=ce,n=C;if(rt||!e||!An(n))return;rt=!0,Rt();const t=u.defaultView?.requestAnimationFrame?.bind(u.defaultView)??(s=>setTimeout(s,16));let i=!1;const o=()=>{if(i||Xe)return;i=!0;let s;try{s=Wn(n,{...e.analysisOptions,enableTestValueAnalysis:!0})}catch(l){throw rt=!1,Rt(),l}if(rt=!1,C!==n||ce!==e){Rt();return}gn(s),y.onStatsSummaryChange?.(s)};t(()=>t(o)),setTimeout(o,120)}let vo={},F=null,be=null;function wo(e){const{kind:n,index:t}=e.variable;if(n==="test")L({plotMode:"value",activeTest:t??0,highlightBin:void 0});else{const o=Y.some(s=>s.hbin!=null);L({plotMode:findingPlotMode(e,d.plotMode,o),highlightBin:findingBin(e,ne,o)})}const i=e.highlight;(i.kind==="bin"||i.kind==="region"||i.kind==="dies")&&zt(i.dieKeys)}const dt=new Map,mn=new WeakSet;function At(e){if(dt.get(e)?.cancel(),dt.delete(e),e.style.display==="none"){mn.add(e);return}mn.delete(e);const n=Ms(Ss(e,{wafer:j,dies:Y,yieldSummary:ke?_i(Y,ne,C.yield?.yieldPercentGross!=null?"denominator-only":"exclude"):C.yield,dataCoverage:ke?Hi(Y.filter(t=>!t.filteredOut)):C.dataCoverage,hbinDefs:ie,sbinDefs:oe,testDefs:K,statsSummary:fe(),warnings:Un?we:[],passBins:ne,ringCount:Ve(C,"renderWaferMap"),binColors:m.binColors,plotMode:d.plotMode??"hardBin",metadataShownElsewhere:Kn,fallbackFormat:d.fallbackFormat,activeFindingId:ye,findingsFilter:vo,findingsNotice:yo(),onFindingsFilterChange:se,onSaveText:de.onSaveText,metadataFields:Ke,dieListOptions:y.dieList,onLocateDie:t=>Kt(t),attributes:y.attributes,onClose:Ee&&fe()?()=>Ht(!1):void 0,activeTest:Se,onTestClick:t=>{Se===t?(Se=null,zt([]),ci(),se()):ui(t)},onFindingClick:(t,i)=>{ye===t.id?(ye=null,zt([]),ci(),se()):pi(t)},onShowChart:Be?t=>{Ce(!0),si().then(i=>i?.showWorthCard(t))}:void 0}));n.done||dt.set(e,n)}function ui(e){di(),ye=null,Se=e,L({plotMode:"value",activeTest:e,highlightBin:void 0}),zt(fe()?.stats.testFailures?.[e]?.dieKeys),se()}function pi(e){di(),Se=null,ye=e.id,wo(e),se()}function se(){Z?At(Z):F&&At(F)}function Wt(){F&&At(F)}if(tt?.placement){const e=tt.placement;Z=Yn(e,ge,u,Dn);const n=M.parentElement,t=M.nextSibling;Fe=zn(M,Z,e),n?.insertBefore(Fe,t),se()}else if(fe()){const e=tt?.defaultOpen??!Ee;F=Yn("right",ge,u,Dn),F.style.display=e?"block":"none";const n=M.parentElement,t=M.nextSibling;be=zn(M,F,"right"),n?.insertBefore(be,t),Wt()}cn();const _=so?ji(u):null;let le=null,N=null,Ue=null,X=null,W=null,It=null,Vt=null,hi=!0,gi=null,ve=null,Yt=null;qn=!0;function yn(){if(!ve||!Yt)return;const e=we.length,n=e>0;if(ve.style.display=n?"flex":"none",Yt.style.display=n?"":"none",Ue?.(),!n)return;const t=ks(we[0]),i=`${e} data ${e===1?"warning":"warnings"}`;ve.style.color=t==="error"?A.errText:A.warnText,ve.ariaLabel=t==="error"?`${i} \u2014 the map may be positionally wrong`:i}let bn=null,mi=null,vn=null,wn=null,xn=null,Cn=null;function Re(e="selection"){ye===null&&Se===null||(ye=null,Se=null,Ft=null,e==="selection"?L({highlightBin:void 0}):(x=new Set,me?.([])),se())}function zt(e){x=new Set(e??[]),me&&me(Qe()),w()}function ct(){if(!Vt)return;Ue?.();const e=Z??F;Vt.sync({visible:hi&&!!fe()&&!!e&&!pe,open:!!e&&e.style.display!=="none",notable:!!fe()?.hasNotableFindings})}function Ht(e){const n=Z??F;if(!n)return;const t=n.style.display!=="none",i=M.getBoundingClientRect().width;if(n.style.display=e?"block":"none",e!==t){const o=i-M.getBoundingClientRect().width;(y.onSummaryPanelChange??_t)?.(e,e?o:0)}e&&mn.has(n)&&At(n),ct()}if(Ee){let R=function(T){U=T,i(v,T==="zoom"),i(q,T==="pan"),It&&i(It,T==="select"),a.style.cursor=T==="pan"?"grab":"crosshair"};le=u.createElement("div"),le.dataset.wmapToolbar="single",Object.assign(le.style,{marginLeft:"auto",flexShrink:"0",display:"flex",flexDirection:"row",alignItems:"center",flexWrap:"wrap-reverse",justifyContent:"flex-end",maxWidth:"100%",background:A.menuBg,border:`1px solid ${A.menuBorder}`,borderRadius:Ni.control,boxShadow:Uo.panel,pointerEvents:"auto"});const e=ji(u),n=Qo(e),{makeBtn:t,setActive:i,makeSep:o,syncSeparators:s,syncToolbarVisible:l,makeMenuRow:r,makeMenuSection:c,closeOpenMenu:f,getOpenMenu:p,setOpenMenu:b}=n;Ue=()=>{N&&s(N),le&&l(le,"flex"),ze()},bn=f,mi=p,u.addEventListener("click",f,!0),X=u.createElement("div"),Object.assign(X.style,{display:et?"none":"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),le.appendChild(X);const ae=t("download","Download PNG",Bo);X.appendChild(ae),X.appendChild(o());const v=t("zoomMode","Zoom (drag to zoom region)",()=>R("zoom")),k=t("zoomIn","Zoom in",()=>qe(a.clientWidth/2,a.clientHeight/2,1.2)),S=t("zoomOut","Zoom out",()=>qe(a.clientWidth/2,a.clientHeight/2,1/1.2)),D=t("reset","Reset zoom (double-click)",()=>ut());X.appendChild(v),X.appendChild(k),X.appendChild(S),X.appendChild(D),X.appendChild(o());const q=t("pan","Pan (drag to move)",()=>R("pan"));X.appendChild(q),It=t("boxSelect","Select (drag to select dies)",()=>R("select")),X.appendChild(It);{const T=t("drilldown","Chart this wafer",()=>{const re=T.getBoundingClientRect();Pn({x:re.left,y:re.bottom+4},T)});T.setAttribute("aria-haspopup","menu"),Bt=T,Bi(),X.appendChild(T)}R(U);{let T=function(g){return g.plotMode!==(d.plotMode??"hardBin")?!1:g.plotMode==="value"?(d.activeTest??0)===(g.activeTest??0):g.plotMode==="metadata"?d.activeMetadataKey===g.activeMetadataKey:!0},re=function(g,E){g.activeTest!==void 0?L({plotMode:g.plotMode,activeTest:g.activeTest,activeMetadataKey:void 0,logScale:g.logScale}):g.activeMetadataKey!==void 0?L({plotMode:g.plotMode,activeTest:void 0,activeMetadataKey:g.activeMetadataKey,passFailDisplay:"off"}):L({plotMode:g.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),E.remove(),b(null),mt(Q,!1)};N=u.createElement("div"),Object.assign(N.style,{display:"flex",alignItems:"center",gap:"0",flexWrap:"wrap",justifyContent:"flex-end"}),le.appendChild(N),W=u.createElement("div"),Object.assign(W.style,{display:"flex",alignItems:"center",gap:"0"}),N.appendChild(W),W.appendChild(o());const pt=()=>{const g=p();g&&(g.remove(),b(null)),mt(Q,!1)},Q=t("mode","Plot mode",()=>{if(p()){pt();return}const g=Y,E=m.testDefs,{testEntries:Gt,binEntries:We,stackedEntries:ht}=hs(g,E,{includeStacked:m.isLotStack}),Ut=(Ke??[]).filter(Ie=>gs(g,Ie.key)).map(Zi);_s([{dies:g,testDefs:E}])&&Ut.push(Zi(zs));const gt=Jo(Q.getBoundingClientRect(),Gt,We,ht,T,re,{makeMenuRow:r,makeMenuSection:c},d.plotMode??"hardBin",Q.ownerDocument.defaultView??window,Ut);Gi(Q).appendChild(gt),b(gt),mt(Q,!0),Ui(gt,Q,pt)});mt(Q,!1);const{btn:Ln,sync:On}=ts(n,()=>({...d,plotMode:d.plotMode??"hardBin"}),()=>ho,L);wn=On,wn();const Po=os(n,()=>{const g=!!m.hasReticle,E=(d.plotMode??"hardBin")==="value",{testNumber:Gt}=Fn(d.activeTest??0,m.testDefs),We=Zt(m.testDefs,Gt),ht=E&&We!==void 0&&!Rn(We),Ut=E&&!ht&&(We?.limitLow!==void 0||We?.limitHigh!==void 0),gt=E&&!ht&&m.dies.some(Ie=>Go(Ie,Gt,We)!==void 0);return ds({...d,showAxes:ri()},g,{functionalActive:ht,hasLimits:Ut,hasRecorded:gt,binMode:(d.plotMode??"hardBin")==="hardBin"||(d.plotMode??"hardBin")==="softBin"},Ie=>L(Ie),{on:!!d.compact,offered:mo(),onChange:Ie=>L({compact:Ie}),onDiagnostics:()=>fs(Y,[Dt],{anchor:a,onSaveText:de.onSaveText})})},()=>cs(d)),{btn:To,sync:Lo}=is(n,()=>d,g=>L({legendPosition:g}));vn=Lo,vn();const Yi=()=>{const{testNumber:g}=Fn(d.activeTest??0,K),E=Zt(K,g);return E!==void 0&&!Rn(E)},{btn:Oo,sync:Fo}=ns(n,()=>({...d,functionalActive:Yi()}),g=>L(g));xn=Fo,xn();const Ro=()=>{const{testNumber:g}=Fn(d.activeTest??0,K),E=Zt(K,g);return E!==void 0&&(E.limitLow!==void 0||E.limitHigh!==void 0)},$t=t("specRange","Colorbar range: test limits",()=>{const g=d.colorbarRangeMode==="data"?"spec":"data";L({colorbarRangeMode:g})});Cn=()=>{const g=d.plotMode==="value"&&Ro()&&rs(d)==="off"&&!Yi();$t.style.display=g?"":"none";const E=(d.colorbarRangeMode??"spec")==="spec";i($t,E),$t.ariaLabel=E?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"},Cn();const Ao=ss(n,()=>d,g=>L(g));W.appendChild(Q),W.appendChild(Ln),W.appendChild(Oo),W.appendChild($t),et||(W.appendChild(o()),W.appendChild(Po),W.appendChild(o()),W.appendChild(To),W.appendChild(o()),W.appendChild(Ao)),Vt=Io(u,()=>{const g=Z??F;g&&Ht(g.style.display==="none")}),V.insertBefore(Vt.el,nt?.el??null),ct(),Un&&(Yt=o(),ve=t("warning","Data warnings",()=>{const g=p();if(f(new MouseEvent("click")),g)return;const E=Bs(ve.getBoundingClientRect(),we,B);Gi(Me).appendChild(E),b(E),Ui(E,ve,()=>f(new MouseEvent("click")))}),mt(ve,!1),N.appendChild(Yt),N.appendChild(ve),yn()),$n&&(N.appendChild(o()),Pt=t("expand","Expand (E)",jn??yi),N.appendChild(Pt)),Nn&&(N.appendChild(o()),gi=t("help","User guide",()=>jt()),N.appendChild(gi)),Ue?.()}V.appendChild(le),_e&&V.appendChild(_e),ze()}let Ae=null,_t=null;function yi(){Ae&&(Ae.close(),Ae=null);const e=Me;e.style.flex="1",e.style.minWidth="0",e.style.minHeight="0";const n=Hn(j.metadata??{},it()),t=V.childElementCount>0?[V,e]:[e],i=es(t,{ownerDocument:u,boxSize:pe?{width:"min(96vw, 1600px)",height:"min(92vh, 1000px)"}:void 0,onClosed:()=>{Ae=null,_t=null,Tt(!0),pe||a.focus({preventScroll:!0})}});if(!i)return;i.box.setAttribute("aria-label",n??"Expanded wafer map"),t.length>1&&(i.contentWrap.style.flexDirection="column"),Ae=i,_t=us(i);const o=Z??F,s=Fe??be;if(o&&s&&o.style.display!=="none"){const l=parseFloat(u.defaultView?.getComputedStyle(s).columnGap??"")||0,r=o.getBoundingClientRect().width+l;r>0&&_t(!0,r)}Tt(!1)}function bi(e){("binColorScheme"in e||"useDefinedBinColors"in e)&&!("binColors"in e)&&d.binColors!==void 0&&(e={...e,binColors:void 0});const n=d.plotMode;d={...d,...e},Vn.some(l=>l in e)&&$?.setAxisPrefs(qi(d));const t=Object.keys(e);if(t.length>0&&t.every(l=>Vn.includes(l)))return;("compact"in e||"compactMap"in e)&&(G=null,O=null),e.plotMode!==void 0&&e.plotMode,Object.keys(e).every(l=>l==="legendPosition"||l==="showLegend"||l==="markFailingDies"||l==="showAxes")||at(),vn?.(),wn?.(),xn?.(),Cn?.(),w();const o=e.plotMode!==void 0&&e.plotMode!==n,s=COLOR_KEYS.some(l=>l in e);(s||o)&&se(),(s||o||e.activeTest!==void 0||e.logScale!==void 0||e.colorbarRangeMode!==void 0)&&bt?.()}function L(e){bi(e);const n=Object.keys(e);Xn?.(d,n,classifyChanged(n))}let Sn=!1;const Mn=y.drawWhenVisible&&B.IntersectionObserver?new B.IntersectionObserver(e=>{Ze=e[e.length-1].isIntersecting,Ze&&Xt&&w()},{rootMargin:"25%"}):null;let Ze=Mn===null,Xt=!1;Mn?.observe(a);function En(){Sn||(Sn=!0,In(()=>{Sn=!1,w()},B))}function w(){if(!Ze){Xt=!0;return}Xt=!1;const e=O??void 0,n=m.dies[0],t=n?{x:n.width,y:n.height}:He.diePitchMm,i=Math.floor(a.clientWidth||a.width),o=!!(ie?.length||oe?.length||m.dies.some(b=>b.hbin!=null||b.sbin!=null)),s=d.legendPosition??"default",l=d.showLegend??!0,r=s==="default"||s==="compact",c=(He.colorbarWidth??16)+28,f=o&&r?s!=="default"?Math.max(zi,c):i<Ko?0:i<Xo?Math.max(_o,c):Math.max(zi,c):void 0,p=Ho(a,m,{...He,minRightReserve:l?f:0,showColorbar:l&&(He.showColorbar??!0),markFailingDies:d.markFailingDies??!1,legendPosition:s,legendOffset:un,diePitchMm:t,fallbackFormat:d.fallbackFormat,showAxes:ri(),viewport:e,activeBin:d.plotMode==="metadata"?d.highlightMetadataValue:d.highlightBin,hoverBin:fn,afterDies:x.size>0||Pe!==null?xo:void 0,hbinDefs:ie,sbinDefs:oe,metadataFields:hn()});Lt=p.binLegendRows,Le=p.legendBox??null,O===null&&(G=p.viewport),je&&Eo(),Bi()}function xo(e,n,t){x.size>0&&So(e,n,t),Pe!==null&&Co(e,n,t)}function Co(e,n,t){Te??=new Map(m.dies.map((b,R)=>[he(b),R]));const i=Pe===null?void 0:Te.get(Pe);if(i===void 0)return;const o=m.hoverPoints[i],s=m.rectangles[0],l=s?s.width/2*n.ppm:n.ppm*.5,r=s?s.height/2*n.ppm:n.ppm*.5,c=n.originX+o.x*n.ppm,f=n.originY-o.y*n.ppm,p=Math.max(l,r)*1.25+5;e.save(),e.setLineDash([]),e.beginPath(),e.arc(c,f,p,0,Math.PI*2),e.strokeStyle=t.background,e.lineWidth=6,e.stroke(),e.strokeStyle=t.text,e.lineWidth=3,e.stroke(),e.restore()}function Kt(e){if(Pe=e===null?null:he(e),e!==null&&O!==null){ut();return}w()}function vi(){Pe!==null&&(Pe=null,w())}function So(e,n,t){const i=m.hoverPoints,o=m.rectangles[0],s=o?o.width/2*n.ppm:n.ppm*.5,l=o?o.height/2*n.ppm:n.ppm*.5,r=new Set;x.size>0&&(Te??=new Map(m.dies.map((v,k)=>[he(v),k])));for(const v of x){const k=Te.get(v);k!==void 0&&r.add(k)}if(!r.size)return;e.save(),e.setLineDash([]),e.fillStyle=t.background,e.globalAlpha=.7;let c=0;e.beginPath();for(let v=0;v<i.length;v++)r.has(v)||(e.rect(n.originX+i[v].x*n.ppm-s,n.originY-i[v].y*n.ppm-l,s*2,l*2),++c===No&&(e.fill(),e.beginPath(),c=0));c&&e.fill(),e.globalAlpha=1;const{cw:f,ch:p}=Mo(n,s,l),b=new Map,R=v=>Math.round(v*100),ae=(v,k,S,D)=>{const q=`${R(v)},${R(k)},${R(S)},${R(D)}`;b.has(q)?b.delete(q):b.set(q,[v,k,S,D])};for(const v of r){const k=n.originX+i[v].x*n.ppm,S=n.originY-i[v].y*n.ppm,D=k-f,q=k+f,T=S-p,re=S+p;ae(D,T,q,T),ae(D,re,q,re),ae(D,T,D,re),ae(q,T,q,re)}e.strokeStyle=t.text,e.lineWidth=2,e.lineCap="square",e.beginPath();for(const[v,k,S,D]of b.values())e.moveTo(v,k),e.lineTo(S,D);e.stroke(),e.restore()}function Mo(e,n,t){const i=m.hoverPoints,o=m.dies;let s=0,l=0;for(let r=0;r<o.length&&(!s||!l);r++){const c=o[r];if(!(c.x==null||c.y==null))for(const f of[Te.get(`${c.x+1},${c.y}`),Te.get(`${c.x},${c.y+1}`)]){if(f===void 0)continue;const p=Math.abs(i[f].x-i[r].x)*e.ppm,b=Math.abs(i[f].y-i[r].y)*e.ppm;p>b?s||=p/2:l||=b/2}}return{cw:s||n,ch:l||t}}function Eo(){const e=a.getContext("2d"),n=Math.min(z.x,H.x),t=Math.min(z.y,H.y),i=Math.abs(H.x-z.x),o=Math.abs(H.y-z.y);e.save(),e.fillStyle="rgba(0,0,0,0.08)",e.fillRect(n,t,i,o),e.setLineDash([5,3]),e.strokeStyle="rgba(255,255,255,0.9)",e.lineWidth=3,e.strokeRect(n,t,i,o),e.strokeStyle="rgba(0,0,0,0.9)",e.lineWidth=1.5,e.strokeRect(n,t,i,o),e.restore()}function wi(){if(!Xt)return;const e=Ze;Ze=!0,w(),Ze=e}function Bo(){wi(),a.toBlob(e=>{e&&ls(e,_n(),de.onSaveImage)})}function xi(e){return G?Math.max(G.ppm*co,Math.min(G.ppm*fo,e)):e}function qe(e,n,t){const i=O??G;if(!i)return;const o=xi(i.ppm*t),s=o/i.ppm,l=e-(e-i.originX)*s,r=n-(n-i.originY)*s,c=(G?.snapDist??1)/(o/(G?.ppm??o));O={originX:l,originY:r,ppm:o,snapDist:c},w()}function te(){return O??G}function Ci(e){if(e.ctrlKey||e.metaKey){e.preventDefault();const n=a.getBoundingClientRect(),t=e.deltaY<0?1.12:1/1.12;qe(e.clientX-n.left,e.clientY-n.top,t)}else if(O!==null){e.preventDefault();const n=te(),t=O.snapDist;O={originX:n.originX-e.deltaX,originY:n.originY-e.deltaY,ppm:n.ppm,snapDist:t},w()}}function Bn(e,n,t){return e>=t.x&&e<t.x+t.w&&n>=t.y&&n<t.y+t.h}function Si(e){if(kt=!1,e.button!==0||(vi(),!te()))return;a.focus({preventScroll:!0}),a.setPointerCapture(e.pointerId);const n=a.getBoundingClientRect(),t=e.clientX-n.left,i=e.clientY-n.top;if(Le&&d.legendPosition==="floating"&&Bn(t,i,Le)){Ne=!0,st={x:t,y:i},pn={...un};return}if(lt&&U!=="pan"){Ge=!0,Oe=!0,$e={x:t,y:i},Ot={x:te().originX,y:te().originY},a.style.cursor="grabbing";return}if(U==="zoom"||U==="select"){je=!0,z=H={x:t,y:i};return}Oe=!0,$e={x:t,y:i},Ot={x:te().originX,y:te().originY},a.style.cursor="grabbing"}function Mi(e){const n=a.getBoundingClientRect(),t=e.clientX-n.left,i=e.clientY-n.top;if(je){H={x:t,y:i},En();return}if(Ne){const p=t-st.x,b=i-st.y;p*p+b*b>16&&(Ne=!1,ot=!0,a.style.cursor="grabbing")}if(ot){un={x:pn.x+(t-st.x),y:pn.y+(i-st.y)},En();return}if(Oe){const p=te(),b=O?.snapDist??G?.snapDist??1;O={originX:Ot.x+(t-$e.x),originY:Ot.y+(i-$e.y),ppm:p.ppm,snapDist:b},En();return}const o=te();if(!o)return;const s=(t-o.originX)/o.ppm,l=(o.originY-i)/o.ppm,c=Tn(s,l,o.snapDist)?.die??null,f=Lt.find(p=>t>=p.x&&t<p.x+p.w&&i>=p.y&&i<p.y+p.h);if(ai(f?f.bin:void 0),f){a.style.cursor="pointer",_&&(_.textContent=f.label??`Bin ${f.bin}`,_.style.display="block",$i(_,a,e.clientX,e.clientY,{followPointer:!0})),vt?.(null,e);return}U==="pan"&&(a.style.cursor=c?"crosshair":"grab"),_&&(c?(_.innerHTML=Yo(c,m.plotMode,{testDefs:K,hbinDefs:ie,sbinDefs:oe,fallbackFormat:d.fallbackFormat,aggrMethod:m.aggrMethod,lotSize:m.lotSize,metadataFields:hn(),activeTest:m.activeTest,reticleConfig:Dt}),_.style.display="block",$i(_,a,e.clientX,e.clientY,{followPointer:!0})):_.style.display="none"),vt?.(c,e)}function Ei(e){const n=a.getBoundingClientRect(),t=e.clientX-n.left,i=e.clientY-n.top,o=e.ctrlKey||e.metaKey;if(_&&(t<0||i<0||t>n.width||i>n.height)&&(_.style.display="none"),je){je=!1,H={x:t,y:i};const r=t-z.x,c=i-z.y,f=te();if(U==="zoom"){if(r*r+c*c<25)qe(t,i,2);else if(f){const p=Math.min(z.x,H.x),b=Math.max(z.x,H.x),R=Math.min(z.y,H.y),ae=Math.max(z.y,H.y),v=b-p,k=ae-R;if(v>4&&k>4){const S=a.clientWidth,D=a.clientHeight,q=S/v,T=D/k,re=Math.min(q,T),pt=xi(f.ppm*re),Q=pt/f.ppm,Ln=(p+b)/2,On=(R+ae)/2;O={originX:S/2-(Ln-f.originX)*Q,originY:D/2-(On-f.originY)*Q,ppm:pt,snapDist:f.snapDist/Q}}}w(),a.style.cursor="crosshair";return}if(r*r+c*c<25)kn(t,i,o,e);else if(f){const p=(Math.min(z.x,H.x)-f.originX)/f.ppm,b=(Math.max(z.x,H.x)-f.originX)/f.ppm,R=(f.originY-Math.max(z.y,H.y))/f.ppm,ae=(f.originY-Math.min(z.y,H.y))/f.ppm,v=m.hoverPoints,k=[];for(let S=0;S<v.length;S++)if(v[S].x>=p&&v[S].x<=b&&v[S].y>=R&&v[S].y<=ae){const D=m.dies[S];D&&k.push(D)}if(o)for(const S of k){const D=he(S);x.has(D)?x.delete(D):x.add(D)}else x=new Set(k.map(S=>he(S)));Re(),me?.(Qe())}w(),a.style.cursor="crosshair";return}if(Ne){Ne=!1,kn(t,i,o,e);return}if(ot){ot=!1,a.style.cursor="grab";return}if(!Oe)return;if(Oe=!1,Ge){Ge=!1,a.style.cursor=lt||U==="pan"?"grab":"crosshair";return}a.style.cursor=U==="pan"?"grab":"crosshair";const s=t-$e.x,l=i-$e.y;s*s+l*l<25&&kn(t,i,o,e)}function kn(e,n,t,i){for(const r of Lt)if(e>=r.x&&e<r.x+r.w&&n>=r.y&&n<r.y+r.h){Re("legend"),typeof r.bin=="number"?L({highlightBin:to(d.highlightBin,r.bin,t)}):L({highlightMetadataValue:to(d.highlightMetadataValue,r.bin,t)});return}if(Le&&Bn(e,n,Le))return;const o=te();if(!o)return;const l=Tn((e-o.originX)/o.ppm,(o.originY-n)/o.ppm,o.snapDist)?.die??null;if(l){oo?.(l,i);const r=he(l);t?x.has(r)?x.delete(r):x.add(r):x.size===1&&x.has(r)?x=new Set:x=new Set([r]),Re(),me?.(Qe()),w()}else t||(x=new Set,Re(),me?.([]),w())}function Qe(){const e=[],n=m.hoverPoints;for(let t=0;t<n.length;t++){const i=m.dies[t];i&&x.has(he(i))&&e.push(i)}return e}function Bi(){Bt&&(Bt.style.display=Et()?"flex":"none",Bt.ariaLabel=x.size>0?"Charts and tables for the selected dies (or right-click)":"Charts and tables for this wafer (or right-click)")}function ki(){const e={waferLabel:yt(),testDefs:K,isLotStack:C.isLotStack,wafer:C.wafer,passBins:ne,ringCount:Ve(C,"renderWaferMap"),activeTest:d.plotMode==="value"?d.activeTest:void 0};return x.size>0?Ps(Qe(),e):Ts(Y,e)}function Dn(e,n,t){ye!==e&&n.click(),Pn(t,Z??F??a)}function ko(e,n){if(!Et())return;const t=d.plotMode==="softBin"?"soft":"hard",i=Ns(d.highlightBin),o=i.length>1&&i.includes(e)?[...i]:[e],s=[{label:yt()??"this wafer",dies:Y,wafer:C.wafer,passBins:ne,ringCount:Ve(C,"renderWaferMap")}],l=Qi(s,t,o,K);if(!l)return;const r={...Mt},c=o.length>1?Qi(s,t,[e],K):null;c&&(r.narrower={label:`Only ${t} bin ${e}`,backLabel:"All filtered bins",source:c,ctx:Mt});const f=a;import("./drilldown.js").then(({openDrilldownMenu:p})=>{Xe||(sn=p(n,f,l,r))})}function Pn(e,n){if(!Et())return;const t=y.drilldownSourceOverride?.(),i=t?.source??ki(),o={...Mt,...t?.ctx};if(t?.narrowable){const s=ki(),l=s.items.reduce((r,c)=>r+c.dies.length,0);o.narrower={label:`Only this wafer \u2014 ${l.toLocaleString()} die${l===1?"":"s"}`,source:s,ctx:Mt}}import("./drilldown.js").then(({openDrilldownMenu:s})=>{Xe||(sn=s(e,n,i,o))})}function Di(e){e.stopPropagation();const n=kt;if(kt=!1,!Et()||pe)return;const t=a.getBoundingClientRect();if(!n){const o=e.clientX-t.left,s=e.clientY-t.top,l=Lt.find(f=>o>=f.x&&o<f.x+f.w&&s>=f.y&&s<f.y+f.h);if(l&&typeof l.bin=="number"&&!C.isLotStack&&(d.plotMode===void 0||d.plotMode==="hardBin"||d.plotMode==="softBin")){e.preventDefault(),ko(l.bin,{x:e.clientX,y:e.clientY});return}if(Le&&Bn(o,s,Le))return;const r=te(),c=r?Tn((o-r.originX)/r.ppm,(r.originY-s)/r.ppm,r.snapDist)?.die:void 0;c&&!x.has(he(c))&&(x=new Set([he(c)]),Re(),me?.(Qe()),w())}e.preventDefault();const i=n?{x:t.left+t.width/2,y:t.top+t.height/2}:{x:e.clientX,y:e.clientY};Pn(i,a)}function Pi(){ai(void 0),_&&Qt(u),vt?.(null,new MouseEvent("mouseleave")),a.style.cursor=U==="pan"?"grab":"crosshair"}function Ti(){Oe=!1,Ge=!1,je=!1,Ne=!1,ot=!1,_&&Qt(u),vt?.(null,new MouseEvent("mouseleave")),a.style.cursor=U==="pan"?"grab":"crosshair",w()}function Tn(e,n,t){const i=m.hoverPoints,o=m.rectangles;for(let c=0;c<o.length;c++){const f=o[c];if(Math.abs(e-f.x)<=f.width/2&&Math.abs(n-f.y)<=f.height/2){const p=m.dies[c];return p?{die:p,index:c}:null}}let s=null,l=-1,r=t*t;for(let c=0;c<i.length;c++){const f=i[c].x-e,p=i[c].y-n,b=f*f+p*p;b<r&&(r=b,s=m.dies[c]??null,l=c)}return s?{die:s,index:l}:null}const Li=new B.ResizeObserver(()=>{G=null,O=null,w()});Li.observe(a),y.height==null&&io<=0&&In(()=>In(()=>{P.clientHeight>0||console.warn("[wafermap] The map container has zero height, so the map cannot render. renderWaferMap fills its container \u2014 give the container a resolved height: an explicit CSS `height` (e.g. 600px), a height-resolved flex/grid parent, or `position:absolute; inset:0`. Alternatively pass `{ height: 600 }` in the render options and the library will size it for you.")}));let ft=B.matchMedia(`(resolution: ${B.devicePixelRatio}dppx)`);const Nt=()=>{ft.removeEventListener("change",Nt),ft=B.matchMedia(`(resolution: ${B.devicePixelRatio}dppx)`),ft.addEventListener("change",Nt),w()};ft.addEventListener("change",Nt);const Oi=B.matchMedia("(prefers-color-scheme: dark)"),Fi=()=>w();Oi.addEventListener("change",Fi);const Ri=()=>{_&&Qt(u)};B.addEventListener("blur",Ri);function Ai(e){if((e.key==="ContextMenu"||e.shiftKey&&e.key==="F10")&&(kt=!0),e.key==="Escape"&&vi(),e.key==="Escape"&&x.size>0&&(x=new Set,Re(),me?.([]),w()),(e.key==="e"||e.key==="E")&&$n&&(e.stopPropagation(),(jn??yi)()),(e.ctrlKey||e.metaKey)&&(e.key==="="||e.key==="+"?(e.preventDefault(),qe(a.clientWidth/2,a.clientHeight/2,1.2)):e.key==="-"?(e.preventDefault(),qe(a.clientWidth/2,a.clientHeight/2,1/1.2)):e.key==="0"&&(e.preventDefault(),ut())),!e.ctrlKey&&!e.metaKey&&!e.shiftKey){const t=te();if(t){const i=O?.snapDist??G?.snapDist??1;let o=0,s=0;e.key==="ArrowLeft"&&(o=20,e.preventDefault()),e.key==="ArrowRight"&&(o=-20,e.preventDefault()),e.key==="ArrowUp"&&(s=20,e.preventDefault()),e.key==="ArrowDown"&&(s=-20,e.preventDefault()),(o||s)&&(O={originX:t.originX+o,originY:t.originY+s,ppm:t.ppm,snapDist:i},w())}e.key===" "&&!lt&&(e.preventDefault(),lt=!0,U!=="pan"&&(a.style.cursor="grab"))}}function Wi(e){e.key===" "&&(lt=!1,Ge&&(Oe=!1,Ge=!1),a.style.cursor=U==="pan"?"grab":"crosshair")}a.style.cursor="crosshair",a.setAttribute("tabindex","0"),a.addEventListener("wheel",Ci,{passive:!1}),a.addEventListener("pointerdown",Si),a.addEventListener("pointermove",Mi),a.addEventListener("pointerup",Ei),a.addEventListener("pointerleave",Pi),a.addEventListener("pointercancel",Ti);const Ii=()=>ut();a.addEventListener("dblclick",Ii),a.addEventListener("keydown",Ai),a.addEventListener("keyup",Wi),a.addEventListener("contextmenu",Di);const Vi=e=>{e.stopPropagation()};a.addEventListener("click",Vi),a.clientWidth,w(),bt?.();function ut(){G=null,O=null,w()}function jt(e){import("./userGuideHtml.js").then(n=>ms({buildWaferMap:jo,renderWaferMap,renderWaferGallery:void 0,analyzeWaferMap:Wn},n.USER_GUIDE_HTML,lo,P,e))}const Do=ys(e=>jt(e));return ze(),Be&&J?.filter!==void 0&&nn(),{setResult(e){C=e,j=e.wafer,Ct=e.dies,Y=tn(),ie=e.hbinDefs,oe=e.sbinDefs,K=e.testDefs,Ke=e.metadataFields,ti=e.reticles?.length?e.reticles:void 0,Dt=e.reticleConfig,ni=e.dataAxisFlip,ln=e.isLotStack,an=e.aggrMethod,rn=e.lotSize,po(),at(),w(),Jn(),Z&&se()},setOptions(e){bi(e)},getOptions(){return{...d}},resetZoom:ut,setSelection(e){x=new Set(e.map(n=>he(n))),w()},getSelectedDies:()=>Qe(),clearSelection(){x=new Set,Re(),me?.([]),w()},setFindingsNotice(e){fi=e,Rt()},setStatsSummary(e){gn(e)},closeSummaryPanel(){Ht(!1)},getExportTitle(){return _n()},getSaveImageHook(){return de.onSaveImage},locateDie:Kt,getSaveTextHook(){return de.onSaveText},drawPendingNow:wi,getBinColors(){return m.binColors},setSummaryVisible(e){hi=e,ct()},setViewControlsVisible(e){N&&(N.style.display=e?"flex":"none")},setExpandVisible(e){Tt(e)},openUserGuide:()=>jt(),setInsightsOpen(e){Ce(e)},destroy(){Xe=!0,Do(),on.flush();for(const e of dt.values())e.cancel();dt.clear(),Ae?.close(),mi?.()?.remove(),bn&&u.removeEventListener("click",bn,!0),a.removeEventListener("wheel",Ci),a.removeEventListener("pointerdown",Si),a.removeEventListener("pointermove",Mi),a.removeEventListener("pointerup",Ei),a.removeEventListener("pointerleave",Pi),a.removeEventListener("pointercancel",Ti),a.removeEventListener("dblclick",Ii),a.removeEventListener("keydown",Ai),a.removeEventListener("keyup",Wi),a.removeEventListener("contextmenu",Di),sn?.(),a.removeEventListener("click",Vi),Li.disconnect(),Mn?.disconnect(),ft.removeEventListener("change",Nt),Oi.removeEventListener("change",Fi),B.removeEventListener("blur",Ri),uo(),_&&Qt(u),le?.remove(),Fe&&(Fe.parentElement?.insertBefore(M,Fe),Fe.remove()),be&&(be.parentElement?.insertBefore(M,be),be.remove()),M.remove(),a.style.cursor="",$?.destroy(),ee?.destroy(),Ye.remove()}}}
@@ -140,11 +140,6 @@ export declare function buildBinBreakdownSection(params: {
140
140
  passBins?: number[];
141
141
  panel?: HTMLElement;
142
142
  }): HTMLDivElement | null;
143
- /** Aggregate bin counts across all wafers in the lot — no lot-pooled
144
- * precomputed bin counts exist (`hardBinCounts`/`softBinCounts` are
145
- * per-wafer only), so this scans the pooled `Die[]` directly, same as
146
- * `buildBinSection` does when it has no `precomputedCounts`. */
147
- export declare function buildLotBinSection(allDies: Die[], binDefs: BinDef[] | undefined, mode: 'hard' | 'soft', binColors?: BinColors): HTMLDivElement | null;
148
143
  /**
149
144
  * Region yield as ONE section with a Ring/Quadrant selector, replacing the two
150
145
  * always-on stacked sections (`Ring Yield` + `Quadrant Yield`) this used to render.
@@ -356,6 +351,13 @@ export interface SynthesisSectionActions {
356
351
  activeTest?: number | null;
357
352
  /** The map's bin colours, so a bin chip carries the swatch the legend shows. */
358
353
  binColors?: BinColors;
354
+ /**
355
+ * Opens an item's Worth a look card in Insights (by `synthesisKey`): the one way from a row to its chart. Offered on the
356
+ * items that have a card (the top ones), never on the "also" list. Omitted ⇒ no Chart links (no Insights).
357
+ */
358
+ onShowChart?: (key: string) => void;
359
+ /** The host's wafer attributes: which fields groups are compared in, and what they are called. */
360
+ attributes?: Record<string, FacetCuration>;
359
361
  }
360
362
  /**
361
363
  * The first section of both panels: what the wafer or lot did and what stands out, from the same
@@ -526,6 +528,8 @@ export declare function renderWaferSummaryContentSteps(panel: HTMLDivElement, pa
526
528
  onTestClick?: (testNumber: number) => void;
527
529
  /** The test `onTestClick` last showed, while it is still shown. */
528
530
  activeTest?: number | null;
531
+ /** Opens a "What stands out" item's Worth a look card in Insights (`synthesisKey`). Omitted ⇒ no Chart links. */
532
+ onShowChart?: (key: string) => void;
529
533
  findingsFilter?: FindingsFilter;
530
534
  onFindingsFilterChange?: () => void;
531
535
  /** See {@link FindingsNotice} — a host row at the top of the Findings section. */
@@ -537,6 +541,8 @@ export declare function renderWaferSummaryContentSteps(panel: HTMLDivElement, pa
537
541
  dieListOptions?: DieListDisplayOptions;
538
542
  /** A die row clicked in the Data tables: show that die on its map. */
539
543
  onLocateDie?: (die: Die, waferIndex: number | undefined) => void;
544
+ /** The host's wafer attributes (`attributes` on the render options): what the Data tables call each field. */
545
+ attributes?: Record<string, FacetCuration>;
540
546
  /**
541
547
  * Suppress the "Wafer Info" metadata section because the caller already
542
548
  * renders this metadata elsewhere — `renderWaferMap` passes true whenever its
@@ -611,6 +617,8 @@ export declare function renderLotSummaryContentSteps(panel: HTMLDivElement, para
611
617
  onTestClick?: (testNumber: number) => void;
612
618
  /** The test `onTestClick` last showed, while it is still shown. */
613
619
  activeTest?: number | null;
620
+ /** Opens a "What stands out" item's Worth a look card in Insights (`synthesisKey`). Omitted ⇒ no Chart links. */
621
+ onShowChart?: (key: string) => void;
614
622
  onWaferClick?: (waferIndex: number) => void;
615
623
  findingsFilter?: FindingsFilter;
616
624
  onFindingsFilterChange?: () => void;
@@ -623,6 +631,8 @@ export declare function renderLotSummaryContentSteps(panel: HTMLDivElement, para
623
631
  dieListOptions?: DieListDisplayOptions;
624
632
  /** A die row clicked in the Data tables: show that die on its map. */
625
633
  onLocateDie?: (die: Die, waferIndex: number | undefined) => void;
634
+ /** The host's wafer attributes (`attributes` on the render options): what the Data tables call each field. */
635
+ attributes?: Record<string, FacetCuration>;
626
636
  /** Per-wafer findings tally badged onto the Wafer Yield rows — see
627
637
  * `buildPerWaferYieldSection`. */
628
638
  findingsFor?: (waferIndex: number) => {