@wafertools/wafermap 0.35.1 → 0.36.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +11 -8
- package/CHANGELOG.md +117 -0
- package/README.md +3 -3
- package/dist/packages/canvas-adapter/chartPrefs.d.ts +16 -0
- package/dist/packages/canvas-adapter/chartPrefs.js +1 -0
- package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
- package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
- package/dist/packages/canvas-adapter/dataTab.js +1 -1
- package/dist/packages/canvas-adapter/drilldown.js +1 -1
- package/dist/packages/canvas-adapter/index.d.ts +1 -0
- package/dist/packages/canvas-adapter/index.js +1 -1
- package/dist/packages/canvas-adapter/insightsTab.d.ts +7 -0
- package/dist/packages/canvas-adapter/insightsTab.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +20 -5
- package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
- package/dist/packages/canvas-adapter/renderWaferMap.d.ts +71 -37
- package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
- package/dist/packages/canvas-adapter/summaryPanel.d.ts +7 -4
- package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
- package/dist/packages/canvas-adapter/testValueOffer.d.ts +14 -0
- package/dist/packages/canvas-adapter/testValueOffer.js +1 -0
- package/dist/packages/canvas-adapter/toCanvas.js +1 -1
- package/dist/packages/canvas-adapter/toolbar.d.ts +0 -6
- package/dist/packages/canvas-adapter/toolbar.js +1 -1
- package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
- package/dist/packages/canvas-adapter/userGuideHtml.js +10 -3
- package/dist/packages/canvas-adapter/version.d.ts +2 -2
- package/dist/packages/canvas-adapter/version.js +1 -1
- package/dist/packages/canvas-adapter/warnings.js +1 -1
- package/dist/packages/core/aggregates.d.ts +10 -0
- package/dist/packages/core/aggregates.js +1 -1
- package/dist/packages/core/dieTable.d.ts +5 -0
- package/dist/packages/core/dieTable.js +1 -1
- package/dist/packages/core/wafer.d.ts +10 -1
- package/dist/packages/core/wafer.js +1 -1
- package/dist/packages/renderer/buildView.d.ts +5 -0
- package/dist/packages/renderer/buildView.js +1 -1
- package/dist/packages/renderer/buildWaferMap.d.ts +19 -4
- package/dist/packages/renderer/buildWaferMap.js +1 -1
- package/dist/packages/renderer/derivedTests/parser.js +1 -1
- package/dist/packages/renderer/fmt.d.ts +10 -0
- package/dist/packages/renderer/fmt.js +1 -1
- package/dist/packages/renderer/index.d.ts +1 -0
- package/dist/packages/renderer/index.js +1 -1
- package/dist/packages/renderer/valueFilter.d.ts +1 -1
- package/dist/packages/renderer/valueFilter.js +1 -1
- package/dist/packages/stats/analyzeWaferLot.d.ts +16 -0
- package/dist/packages/stats/analyzeWaferLot.js +1 -1
- package/dist/packages/stats/analyzeWaferMap.d.ts +18 -1
- package/dist/packages/stats/analyzeWaferMap.js +1 -1
- package/dist/packages/stats/clusterDetection.js +1 -1
- package/dist/packages/stats/connectedComponents.js +1 -1
- package/dist/packages/stats/correlation.d.ts +36 -4
- package/dist/packages/stats/correlation.js +1 -1
- package/dist/packages/stats/filterFindings.d.ts +1 -1
- package/dist/packages/stats/filterFindings.js +1 -1
- package/dist/packages/stats/findingText.d.ts +8 -0
- package/dist/packages/stats/findingText.js +2 -2
- package/dist/packages/stats/index.d.ts +2 -1
- package/dist/packages/stats/index.js +1 -1
- package/dist/packages/stats/lotDrift.js +1 -1
- package/dist/packages/stats/mergeTestDefs.js +1 -1
- package/dist/packages/stats/plotData.js +1 -1
- package/dist/packages/stats/renderSummaryReport.js +27 -27
- package/dist/packages/stats/reportHtml.d.ts +5 -12
- package/dist/packages/stats/reportHtml.js +96 -34
- package/dist/packages/stats/synthesis.d.ts +4 -0
- package/dist/packages/stats/synthesis.js +1 -1
- package/dist/packages/stats/testPassRate.js +1 -1
- package/dist/packages/stats/testValueBudget.d.ts +15 -0
- package/dist/packages/stats/testValueBudget.js +1 -0
- package/dist/packages/stats/types.d.ts +77 -22
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ import { type UserGuideExtension } from './guideWindow.js';
|
|
|
4
4
|
import { type Die } from '../core/dies.js';
|
|
5
5
|
import type { WaferViewOptions } from './renderWaferMap.js';
|
|
6
6
|
import type { RenderableWaferMap } from './renderWaferMap.js';
|
|
7
|
-
import type { LotStatsSummary } from '../stats/types.js';
|
|
7
|
+
import type { LotStatsSummary, StatsSummary } from '../stats/types.js';
|
|
8
8
|
import { type WarningsOptions } from './warnings.js';
|
|
9
9
|
import type { SummaryPanelOptions, FindingsNotice } from './summaryPanel.js';
|
|
10
10
|
import { type WaferAttributeDef } from '../stats/facets.js';
|
|
@@ -137,6 +137,16 @@ export interface GalleryOptions {
|
|
|
137
137
|
onSaveText?: SaveTextHandler;
|
|
138
138
|
/** Precomputed lot-level stats summary. Enables the summary panel toggle button in the control bar. */
|
|
139
139
|
lotStatsSummary?: LotStatsSummary;
|
|
140
|
+
/**
|
|
141
|
+
* Called after the gallery re-analyses the lot itself: when the reader asks, from the lot Findings section, for the
|
|
142
|
+
* test-value analysis the summaries record as not run (`stats.testValueAnalysis`). `summaries` holds each item's
|
|
143
|
+
* new summary in item order, `lotStatsSummary` the lot's; the gallery already shows them. Keep them so the host's
|
|
144
|
+
* own copies (reports, logs) match.
|
|
145
|
+
*/
|
|
146
|
+
onStatsSummaryChange?: (change: {
|
|
147
|
+
summaries: StatsSummary[];
|
|
148
|
+
lotStatsSummary: LotStatsSummary;
|
|
149
|
+
}) => void;
|
|
140
150
|
/**
|
|
141
151
|
* Options for the always-available Summary panel alongside the gallery
|
|
142
152
|
* grid — a "Lot" tab with full lot-level stats (metadata, yield, bin
|
|
@@ -151,9 +161,12 @@ export interface GalleryOptions {
|
|
|
151
161
|
/**
|
|
152
162
|
* A row at the top of the Findings section stating that a category of finding
|
|
153
163
|
* is not present, and optionally offering to compute it — see
|
|
154
|
-
* {@link FindingsNotice}.
|
|
155
|
-
*
|
|
156
|
-
*
|
|
164
|
+
* {@link FindingsNotice}. Replaces the built-in offer of the skipped
|
|
165
|
+
* test-value analysis while set.
|
|
166
|
+
*
|
|
167
|
+
* @deprecated The renderers offer the skipped test-value analysis themselves
|
|
168
|
+
* (from `stats.testValueAnalysis`) and report the re-run through
|
|
169
|
+
* `onStatsSummaryChange`. See API_REMOVALS.md.
|
|
157
170
|
*/
|
|
158
171
|
findingsNotice?: FindingsNotice;
|
|
159
172
|
/**
|
|
@@ -228,7 +241,9 @@ export interface GalleryController {
|
|
|
228
241
|
setLotStatsSummary(summary: LotStatsSummary | undefined): void;
|
|
229
242
|
/**
|
|
230
243
|
* Replace the lot Findings-section notice (see `FindingsNotice`). Pass
|
|
231
|
-
* `undefined` to clear it
|
|
244
|
+
* `undefined` to clear it, which brings back the built-in offer.
|
|
245
|
+
*
|
|
246
|
+
* @deprecated With `findingsNotice`. See API_REMOVALS.md.
|
|
232
247
|
*/
|
|
233
248
|
setFindingsNotice(notice: FindingsNotice | undefined): void;
|
|
234
249
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createViewSwitch as Ei}from"./viewSwitch.js";import{createSummaryToggle as Ti}from"./summaryToggle.js";import{getUniqueTestNumbers as Oi,resolveTestNumber as Li,findTestDef as Wi,collectMetadataValues as Ri}from"../renderer/buildView.js";import{metadataCategoricalValue as $i}from"../core/metadata.js";import{resolveBinColorsForMaps as Ai,mergeBinDefs as mt,binColorWarning as Pi,mixedPassBinsWarning as Ii,binColorsEqual as Fi}from"../renderer/binColors.js";import{commonPassBins as uo,itemPassBins as Yt}from"../core/passBins.js";import{requireRingCount as te}from"../core/ringCount.js";import{NO_DATA_FILL as Hi}from"../renderer/colorMap.js";import{metadataValueColor as ji}from"../renderer/colorMap.js";import{resolveCanvasTheme as Vi}from"./canvasTheme.js";import{ICONS as Zt}from"./icons.js";import{defaultPlotMode as zi,SHADOW as Qt,LEADING as fo,TRACKING as Gi,controlStyle as Ki,wireControlHover as Jt,SPACE as k,EDGE_GUTTER as de,MAP_CHROME_INSET as Ni,RADIUS as K,FONT as j,CLR as b,sevColor as po,MODE_LABELS as _i,BIN_LEGEND_MODES as go,STACKED_MODES as he,applyOverlayZ as qi,getTooltip as Xi,hideTooltip as mo,createToolbarHelpers as Ui,buildModeMenuEl as Yi,openDetachWindow as Zi,openFloatingWindow as Qi,openModal as Ji,copyWmapThemeTokens as es,syncWmapPopupTheme as ts,makePaletteBtn as ns,makeLogScaleBtn as os,makeLegendStyleBtn as is,makeOverlaysBtn as ss,makeOrientationBtn as as,menuLayerFor as ho,saveImageBlob as ls,markMenuTrigger as Ze,wireMenuA11y as yo,wireTooltip as en,requestedPassFailDisplay as bo,overlayMenuRows as rs,anyOverlayActive as cs,openCompactDiagnostics as ds,roomForPanel as wo,logWmapVersionOnce as us,buildDataModeEntries as fs,metadataKeyHasData as ps,metadataModeEntry as gs}from"./toolbar.js";import{openReportModal as ms,openUserGuideWindow as hs}from"./guideWindow.js";import{waferDisplayLabel as ht,waferIdentityLabel as ye}from"../core/waferLabel.js";import{metadataDisplayValue as ys}from"../core/metadata.js";import{withExportContext as bs}from"./exportName.js";import{sortBinsForDisplay as ws}from"../stats/binPareto.js";import{diePassStatus as vs}from"../core/dies.js";import{aggregateValues as Ss,aggregateBinCounts as vo}from"../core/aggregates.js";import{renderWaferMap as Cs,renderWaferMapCard as So,toPublicViewOptions as Co}from"./renderWaferMap.js";import{waferPopulation as xs,selectionPopulation as Ms,LOT_STACK_REASON as tn}from"./chartPopulation.js";import{sourceFromBins as xo}from"./plotItems.js";import{plotStoreFor as ks}from"./plotStore.js";import{classifyChanged as Ds,COLOR_KEYS as Bs,findingBin as Es,findingPlotMode as Ts}from"./renderWaferMap.js";import{findingPatternKey as Mo}from"../stats/filterFindings.js";import{buildWaferMap as Os,getTestPassStatus as ko,isParametricTest as nn,getDieTestValue as Ls}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as yt}from"../stats/analyzeWaferMap.js";import{collectWarnings as Ws,buildWarningsMenuEl as Rs,severityOf as $s}from"./warnings.js";import{asList as on,compareNatural as sn,arrayEqual as bt,toggleHighlight as Do}from"../core/utils.js";import{buildCompactMap as As,compactLayoutOffered as Ps}from"../core/compact.js";import{attachExpandableMetadata as Bo}from"./identityHeader.js";import{createSummaryPanelEl as an,buildMetadataStripRow as Is,metadataEntries as Fs,renderLotSummaryContentSteps as Hs,reportMapsFromItems as js}from"./summaryPanel.js";import{prettyKey as Vs}from"../stats/facets.js";import{testLabel as zs,markedTestLabel as Gs,derivedFields as Ks}from"../renderer/testLabel.js";import{mergeTestDefs as Ns}from"../stats/mergeTestDefs.js";import{getDieKey as wt,hasPosition as _s}from"../core/dies.js";import{testValue as qs}from"../core/dieTable.js";import{runChunked as Xs}from"./chunked.js";function Eo(u){if(typeof u!="number"||!Number.isFinite(u))return;const x=Math.round(u);return x>=1?x:void 0}const ln=12;function Us(u,x,p){let H=x;if(x.length>ln){const M=x.slice(0,ln-1),E=x.slice(ln-1),V=E.reduce((R,ne)=>R+ne.count,0);H=[...M,{color:b.label,count:V,label:`Other (${E.length} bins)`}]}const T=u.createElement("div");Object.assign(T.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:K.control,overflow:"hidden",border:`1px solid ${b.menuBorder}`,boxSizing:"border-box",marginTop:k.xs,flexShrink:"0"}),T.setAttribute("role","img"),T.setAttribute("aria-label",`Population split: ${H.map(M=>`${M.label} ${vt(M.count/p*100)}`).join(", ")}`);for(const M of H){const E=M.count/p*100,V=u.createElement("div");Object.assign(V.style,{flex:`${E} 1 0`,minWidth:E>0?"2px":"0",background:M.color}),en(V,`${M.label} \xB7 ${M.count.toLocaleString()} dies \xB7 ${vt(E)}`),T.appendChild(V)}return T}function vt(u){return u>0&&u<.1?"<0.1%":`${u.toFixed(1)}%`}function To(u,x,p){const H=new Map;let T=0,M=0;for(const E of u){const V=p?new Set(p(E)):void 0;for(const R of E.dies){if(R.partial||R.edgeExcluded)continue;const ne=x(R);ne!==void 0&&(H.set(ne,(H.get(ne)??0)+1),T++,V&&vs(R,V)&&M++)}}return{counts:H,total:T,pass:M}}function Oo(u,x){const p=u.ownerDocument.createElement("div");Object.assign(p.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${k.xxs} ${k.xs}`,borderRadius:K.control});const H=u.ownerDocument.createElement("span");Object.assign(H.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:x.color,border:x.isActive?`2px solid ${b.iconActive}`:`1px solid ${b.menuBorder}`,borderRadius:K.control,boxSizing:"border-box"});const T=u.ownerDocument.createElement("span");if(T.textContent=x.label,Object.assign(T.style,{fontWeight:x.isActive?"700":"400",color:x.isActive?b.iconActive:b.text,whiteSpace:"nowrap"}),p.appendChild(H),p.appendChild(T),x.count!==void 0){const M=u.ownerDocument.createElement("span");if(M.textContent=x.count.toLocaleString(),Object.assign(M.style,{color:x.isActive?b.iconActive:b.text,fontWeight:x.isActive?"700":"400",whiteSpace:"nowrap"}),p.appendChild(M),x.percent!==void 0){const E=u.ownerDocument.createElement("span");E.textContent=vt(x.percent),Object.assign(E.style,{color:b.label,whiteSpace:"nowrap"}),p.appendChild(E)}}if(p.setAttribute("role","button"),p.setAttribute("aria-pressed",x.isActive?"true":"false"),p.tabIndex=0,p.addEventListener("mouseenter",()=>{p.style.background=b.bgHover}),p.addEventListener("mouseleave",()=>{p.style.background="transparent"}),p.addEventListener("focus",()=>{p.style.background=b.bgHover}),p.addEventListener("blur",()=>{p.style.background="transparent"}),p.addEventListener("click",M=>x.onClick(M.ctrlKey||M.metaKey)),p.addEventListener("keydown",M=>{if(M.key==="Enter"||M.key===" ")M.preventDefault(),x.onClick(M.ctrlKey||M.metaKey);else if(x.onMenu&&(M.key==="ContextMenu"||M.key==="F10"&&M.shiftKey)){M.preventDefault();const E=p.getBoundingClientRect();x.onMenu({x:E.left+E.width/2,y:E.bottom},p)}}),x.onMenu){const M=x.onMenu;p.addEventListener("contextmenu",E=>{E.preventDefault(),M({x:E.clientX,y:E.clientY},p)}),en(p,"Right-click: charts and tables for these dies")}u.appendChild(p)}export function renderWaferGallery(u,x,p={}){us();const H=6;let T=Eo(p.columns);const M=p.showHelpButton??!1,E=p.userGuideExtension,V=p.insights?.enabled??!0,R=ks(p.insights),ne={enabled:!1,plotStore:R},Lo=qi(p.zIndex),be=p.summaryPanel,ue=e=>[...Yt(e)],rn=()=>B.flatMap(e=>e?[te(e,"renderWaferGallery")]:[]),St=()=>rn()[0];function Wo(e){const t=[...new Set(e)].sort((n,o)=>n-o);return t.length<2?null:{code:"ring-count-mixed",severity:"warning",message:`These wafers were built with different ring counts (${t.join(", ")}). Each card and each wafer's findings use their own; the lot's ring yield in the Summary panel, report and Insights uses ${e[0]} rings.`}}let N=p.lotStatsSummary,Re=p.viewOptions?.legendPosition??"default",Qe=p.perCardLegend??!1;function $e(){const e=l.plotMode??"hardBin";return go.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 cn(){const e=Qe||$e()!==null;for(const t of C)t&&t.setOptions({showLegend:e})}let l={plotMode:zi(x.flatMap(e=>typeof e=="function"?[]:[e.dies??[]])),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...p.viewOptions},C=[],oe=[],we=[],D=[];const A=bs(()=>{const e=D.filter(n=>n!=null),t=[...new Set(e.map(n=>ys(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort(sn);return{prefix:p.downloadFilename,lots:t,...e.length===1?{wafer:ye(e[0])}:{waferCount:e.length}}},p.onSaveImage,p.onSaveText);let B=x.map(e=>typeof e=="function"?null:e);function ve(){return Ns(B)}function Ae(){if(B.some(e=>e?.testDefs?.length))return ve().defs}let Pe=0,Je=0;const q=new Map;let Ro=0,et=null,Z=null,ie=null,Se=null;function dn(){Z===null&&ie===null&&(Se={plotMode:l.plotMode,activeTest:l.activeTest})}function un(){Se&&W({...Se},{fireCallback:!1}),Se=null}let fn=new Set,v=null,$o={};function pn(e){return B[e]?.statsSummary??N?.perWafer.find(t=>t.waferIndex===e)?.summary}function gn(){return!!(B.some(e=>e?.statsSummary?.findings.length)||N?.perWafer.some(e=>e.summary.findings.length))}const Ao=Xi(),Ce=Ui(Ao),{makeBtn:xe,setActive:mn,makeSep:fe,syncSeparators:Ct,syncToolbarVisible:xt,makeMenuRow:Po,makeMenuSection:Io,makeDropdown:hn,closeOpenMenu:tt,getOpenMenu:Ie,setOpenMenu:Fe}=Ce;u.ownerDocument.addEventListener("click",tt,!0);const yn=()=>mo();window.addEventListener("blur",yn);let bn=p.findingsNotice;function wn(e){fn=new Set(e);const t=[...$.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,i)=>{const s=fn.has(i);o.style.outline=s?`3px solid ${b.findingHighlight}`:"",o.style.outlineOffset=s?"-3px":"",s&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function Mt(){wn([])}let nt=!1;function kt(){nt=!0;for(const e of C)e&&e.clearSelection();nt=!1}function vn(e){return t=>{!nt&&(Z!==null||ie!==null)&&(Se=null,ke(),z()),Et.set(e,t.length),Q&&!He&&!nt&&Fo(e,t),e.onSelect?.(t)}}function se(e,t){e!==void 0&&(C.forEach((n,o)=>{n&&o!==e&&n.locateDie(null)}),C[e]?.locateDie(t),$.querySelectorAll(".wmap-gallery-card")[e]?.scrollIntoView?.({block:"center",behavior:"smooth"}))}let Q=!1,He=!1,pe=new Set;function Fo(e,t){He=!0;try{pe=new Set(t.map(n=>wt(n))),D.forEach((n,o)=>{const i=C[o];!i||!n||n===e||i.setSelection(n.dies.filter(s=>pe.has(wt(s))))})}finally{He=!1}rt()}function Sn(){pe=new Set,He=!0;try{for(const e of C)e?.clearSelection()}finally{He=!1}rt()}function Dt(){if(!Q||pe.size===0)return;const e=[];let t=!1;if(D.forEach((i,s)=>{if(!i)return;const a=i.dies.filter(d=>pe.has(wt(d)));a.length!==0&&(i.isLotStack&&(t=!0),e.push({label:ye(i)??i.label??`Wafer ${s+1}`,dies:a,waferIndex:s,wafer:i.wafer,passBins:ue(i),ringCount:te(i,"renderWaferGallery")}))}),e.length===0)return;const n=ve(),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?tn:void 0},ctx:{plots:R,attributes:p.attributes,onSaveImage:A.onSaveImage,onSaveText:A.onSaveText,onLocateDie:(i,s)=>se(s,i)}}}function Cn(){const e=[];let t=!1;if(D.forEach((o,i)=>{const s=o?C[i]?.getSelectedDies()??[]:[];!o||s.length===0||(o.isLotStack&&(t=!0),e.push({label:ye(o)??o.label??`Wafer ${i+1}`,dies:s,waferIndex:i,wafer:o.wafer,passBins:ue(o),ringCount:te(o,"renderWaferGallery")}))}),e.length<2)return;const n=l;return{source:{items:e,population:`selected on ${e.length} wafers`,testDefs:ve().defs,activeTest:n.plotMode==="value"?n.activeTest:void 0,notMeasuredReason:t?tn:void 0},ctx:{plots:R,attributes:p.attributes,onSaveImage:A.onSaveImage,onSaveText:A.onSaveText,onLocateDie:(o,i)=>se(i,o)}}}function Ho(e){const t=Dt()??kn(e);if(t)return t;const n=Cn(),o=n?.source.items.some(i=>i.waferIndex===e);return n&&o?{...n,narrowable:!0}:void 0}function Bt(e,t,n){Z!==e&&t.click();const o=v;if(!o)return;const i=N?.findings.find(a=>a.id===e),s=Dt()??Cn()??Vo()??(i?xn(Dn(i)):void 0);s&&import("./drilldown.js").then(({openDrilldownMenu:a})=>{o.isConnected&&a(n,o,s.source,{plots:R,attributes:p.attributes,...s.ctx})})}function jo(e,t,n,o){const i=on(l.highlightBin),s=i.length>1&&i.includes(t)?[...i]:[t],a=[];let d=!1;D.forEach((m,S)=>{m&&(m.isLotStack&&(d=!0),a.push({label:ye(m)??m.label??`Wafer ${S+1}`,dies:m.dies,waferIndex:S,wafer:m.wafer,passBins:ue(m),ringCount:te(m,"renderWaferGallery")}))});const r=ve().defs,g=xo(a,e,s,r,void 0,d);if(!g)return;const c={plots:R,attributes:p.attributes,onSaveImage:A.onSaveImage,onSaveText:A.onSaveText,onLocateDie:(m,S)=>se(S,m)},f=s.length>1?xo(a,e,[t],r,void 0,d):null,h=f?{...c,narrower:{label:`Only ${e} bin ${t}`,backLabel:"All filtered bins",source:f,ctx:c}}:c;import("./drilldown.js").then(({openDrilldownMenu:m})=>{o.isConnected&&m(n,o,g,h)})}function xn(e,t=""){const n=[];let o=!1;for(const s of[...e??[]].sort((a,d)=>a-d)){const a=D[s];a&&(a.isLotStack&&(o=!0),n.push({label:ye(a)??a.label??`Wafer ${s+1}`,dies:a.dies,waferIndex:s,wafer:a.wafer,passBins:ue(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:ve().defs,activeTest:i.plotMode==="value"?i.activeTest:void 0,notMeasuredReason:o?tn:void 0},ctx:{plots:R,attributes:p.attributes,onSaveImage:A.onSaveImage,onSaveText:A.onSaveText,onLocateDie:(s,a)=>se(a,s)}}}function Vo(){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:D[e];if(e===void 0||!t)return;const n=C[e].getSelectedDies(),o=l;return{source:Ms(n,{waferLabel:ye(t),testDefs:t.testDefs,isLotStack:t.isLotStack,activeTest:o.plotMode==="value"?o.activeTest:void 0,waferIndex:e,wafer:t.wafer,passBins:ue(t),ringCount:te(t,"renderWaferGallery")}),ctx:{onSaveImage:A.onSaveImage,onSaveText:A.onSaveText,onLocateDie:(i,s)=>se(s??e,i)}}}function zo(e){e||Sn(),Q=e,rt()}function ot(e,t){const n=new Set(e),o=t??C.map((i,s)=>s);for(const i of o){const s=D[i],a=C[i];if(!s||!a)continue;const d=s.dies.filter(r=>n.has(wt(r)));a.setSelection(d)}}const _=new Set,Et=new Map;function Mn(){[...$.querySelectorAll(".wmap-gallery-card")].forEach((n,o)=>{n.style.outline=_.has(o)?`2px solid ${b.iconActive}`:"",n.style.outlineOffset=_.has(o)?"-2px":""});const t=_.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 Go(e){e<0||(_.has(e)?_.delete(e):_.add(e),Mn())}function Ko(){_.clear(),Mn()}function kn(e){if(!(_.size===0||!_.has(e))){for(const t of Et.values())if(t>0)return;return xn([..._],"picked ")}}function No(){const e=[];for(let t=0;t<B.length;t++){const n=B[t];if(!n)continue;const o=pn(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 _o(e){const t=D[e]??B[e];t&&Xe(e,t)}function qo(e){const t=pn(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 Xo(){import("../stats/renderSummaryReport.js").then(({renderLotReportHtml:e})=>{ms(e(js(B,St())),{anchor:u})})}function Uo(){if(!v)return;v.innerHTML="";const e=No();if(B.length>0){const n=u.ownerDocument.createElement("div"),o=e.length,i=B.filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${i} wafers`:`${o} of ${i} wafer${i===1?"":"s"} with findings`,Object.assign(n.style,{fontSize:j.body,color:b.label,marginBottom:k.md}),v.appendChild(n)}if(e.length>0){const n=u.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...Ki("outlined"),marginBottom:k.lg,display:"block",width:"100%",textAlign:"left"}),Jt(n),n.addEventListener("click",Xo),v.appendChild(n)}if(e.length===0){const n=u.ownerDocument.createElement("div");Object.assign(n.style,{color:b.icon,fontSize:j.body,padding:"4px 0"}),n.textContent="No findings on any wafer.",v.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,g=u.ownerDocument.createElement("button");g.type="button",Object.assign(g.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:k.xs,border:"none",borderLeft:`3px solid ${po(d)}`,borderRadius:K.control,background:b.bgHover,cursor:"pointer",fontSize:j.body,textAlign:"left",boxSizing:"border-box"}),g.addEventListener("mouseover",()=>{g.style.background=b.bgActive}),g.addEventListener("mouseout",()=>{g.style.background=b.bgHover});const c=u.ownerDocument.createElement("span");c.textContent=ht(o,n),Object.assign(c.style,{color:b.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const f=u.ownerDocument.createElement("span");f.textContent=String(r),g.setAttribute("aria-label",`${ht(o,n)} \u2014 ${r} finding${r===1?"":"s"}${i?`, ${i} unusual`:""} \u2014 view wafer`),Object.assign(f.style,{marginLeft:k.sm,flexShrink:"0",background:po(d),color:"#fff",borderRadius:K.container,padding:"1px 5px",fontSize:j.body,fontWeight:"600"}),g.appendChild(c),g.appendChild(f),g.addEventListener("click",()=>Xe(n,o)),v.appendChild(g)}const t=u.ownerDocument.createElement("div");t.style.height="12px",v.appendChild(t)}let Me=null,je=null;function z(){if(v)if(Me?.cancel(),Me=null,N){const e=mt(B.map(n=>n?.hbinDefs)),t=mt(B.map(n=>n?.sbinDefs));Me=Xs(Hs(v,{lotSummary:N,items:B,hbinDefs:e.length?e:void 0,sbinDefs:t.length?t:void 0,testDefs:Ae(),ringCount:St(),binColors:l.binColors,plotMode:l.plotMode??"hardBin",fallbackFormat:l.fallbackFormat,activeFindingId:Z,warnings:p.warnings?.display??!0?ae:[],findingsFilter:$o,findingsNotice:bn,onFindingsFilterChange:z,onSaveText:A.onSaveText,onFindingClick:(n,o)=>{Z===n.id?(ke(),un()):(dn(),Zo(n,o)),z()},activeTest:ie,onTestClick:n=>{const o=ie===n;o||dn(),ke(),o?un():Yo(n),z()},onWaferClick:_o,findingsFor:qo,dieListOptions:p.dieList,onLocateDie:(n,o)=>se(o,n),onClose:()=>On(!1)}),{onDone:()=>{const n=je;je=null,n?.()}})}else Uo()}function Dn(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}let it=[];function Bn(){if(it.length!==0){for(const e of it)C[e]?.setOptions({plotMode:l.plotMode,activeTest:l.activeTest});it=[]}}function ke(){Z=null,ie=null,Mt(),kt(),Bn(),W({highlightBin:void 0},{fireCallback:!1})}function En(){Z===null&&ie===null||(Se=null,ke(),z())}function Tn(e,t){const n=Ae();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=he.has(l.plotMode??"hardBin")?null:t;if(s){for(const a of s)C[a]?.setOptions({plotMode:"value",activeTest:e});it=[...s]}}}function Yo(e){ie=e;const t=o=>D[o]?.statsSummary?.stats.testFailures?.[e]?.dieKeys,n=D.map((o,i)=>i).filter(o=>t(o)?.length);if(Tn(e,n.length?n:null),Mt(),kt(),!he.has(l.plotMode??"hardBin"))for(const o of n)ot(t(o),[o])}function Zo(e,t){if(Z===e.id){ke();return}Z=e.id,ie=null,t.style.background=b.bgActive,t.style.fontWeight="600",Bn();const{kind:n,index:o}=e.variable;if(n==="test")Tn(o??0,Dn(e));else{const s=D.some(d=>d?.dies?.some(r=>r.hbin!=null)),a=uo(D.map(d=>d?Yt(d):void 0));W({plotMode:Ts(e,l.plotMode,s),highlightBin:Es(e,a,s)},{fireCallback:!1})}Mt(),kt();const i=e.highlight;if(i.kind==="wafer"){wn(i.waferIndices);const s=Mo(e);for(const a of i.waferIndices){const d=i.dieKeysByWafer?void 0:D[a]?.statsSummary?.findings.find(g=>Mo(g)===s),r=i.dieKeysByWafer?.[a]??d?.highlight?.dieKeys;r?.length&&ot(r,[a])}}else i.kind==="bin"?i.dieKeys?.length&&ot(i.dieKeys):(i.kind==="region"||i.kind==="dies")&&i.dieKeys?.length&&ot(i.dieKeys)}function Tt(){return!!v&&v.style.display!=="none"}function On(e){!v||e===Tt()||(e&&z(),v.style.display=e?"flex":"none",ge())}function ge(){et&&(Ct(P),xt(P,"inline-flex"),et.sync({visible:!!(N||gn())&&!!v&&!dt,open:Tt(),notable:!!(N?.hasNotableFindings||B.some(e=>e?.statsSummary?.hasNotableFindings))}))}const P=u.ownerDocument.createElement("div");P.dataset.wmapToolbar="gallery",Object.assign(P.style,{flexShrink:"0",marginLeft:"auto",display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:K.control,padding:"0",boxShadow:Qt.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const Ln=()=>{const e=Ie();e&&(e.remove(),Fe(null)),Ze(J,!1)},J=xe("mode","Plot mode",()=>{if(Ie()){Ln();return}const e=B.flatMap(w=>w?.dies??[]),t=Ae(),{testEntries:n,binEntries:o,stackedEntries:i}=fs(e,t,{includeStacked:!0}),s=B.filter(Boolean).length,a=w=>{if(w===void 0)return s;let L=0;for(const I of B)I?.dies?.some(F=>ko(F,w)!==void 0||qs(F,w)!==void 0)&&L++;return L},d=s<2?n:n.map(w=>{const L=a(w.activeTest);return L===s?w:{...w,label:`${w.label} \u2014 ${L} of ${s} wafers`}}),r=l.plotMode??"hardBin",g=l.activeTest??0;function c(w){return w.plotMode!==r?!1:w.plotMode==="value"?g===(w.activeTest??0):w.plotMode==="metadata"?l.activeMetadataKey===w.activeMetadataKey:!0}function f(w,L){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"}),L.remove(),Fe(null),Ze(J,!1)}const h=new Set,m=B.flatMap(w=>w?.metadataFields??[]).filter(w=>!h.has(w.key)&&h.add(w.key)).filter(w=>ps(e,w.key)).map(gs),S=Yi(J.getBoundingClientRect(),d,o,i,c,f,{makeMenuRow:Po,makeMenuSection:Io},r,J.ownerDocument.defaultView??window,m);ho(J).appendChild(S),Fe(S),Ze(J,!0),yo(S,J,Ln)});Ze(J,!1);const Qo=()=>D.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:Jo,sync:Wn}=ns(Ce,()=>({...l,plotMode:l.plotMode??"hardBin"}),Qo,e=>W(e));Wn();const ei=x.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function st(){const e=Ae(),{testNumber:t}=Li(l.activeTest??0,e);return{testNumber:t,td:Wi(e,t)}}function Rn(){if((l.plotMode??"hardBin")!=="value")return!1;const{td:e}=st();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function Ve(){if((l.plotMode??"hardBin")!=="value")return!1;const{td:e}=st();return e!==void 0&&!nn(e)}function ti(){if((l.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=st();return B.some(n=>n?.dies?.some(o=>ko(o,e,t)!==void 0))}function ni(e,t){if(!t||!nn(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((bo(l)==="spec"&&n?"spec":l.colorbarRangeMode??"spec")==="spec"&&n)return;let s=1/0,a=-1/0;for(const d of B)if(d)for(const r of d.dies){const g=Ls(r,e);g!==void 0&&(g<s&&(s=g),g>a&&(a=g))}if(isFinite(s))return s===a?[s,s+1]:[s,a]}function at(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 C)i&&i.setOptions({[e]:t});return!0}function $n(){if((l.plotMode??"hardBin")!=="metadata")return;const e=l.activeMetadataKey;if(!e)return;const t=new Set;for(const n of B)if(n)for(const o of Ri(n.dies,e))t.add(o);return{key:e,values:[...t].sort(sn)}}function Ot(){at("metadataValueOrder",$n(),(e,t)=>e.key===t.key&&bt(e.values,t.values))}function Lt(){if((l.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=st(),n=ni(e,t);at("valueRange",n?{test:e,range:n}:void 0,(i,s)=>{const a=g=>Array.isArray(g)?{test:void 0,range:g}:{test:g.test,range:g.range},d=a(i),r=a(s);return d.test===r.test&&bt(d.range,r.range)})}let Wt=!1;function oi(){if(Wt)return;Wt=!0,(u.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{Wt=!1,Lt(),Ot(),Fn(),In()})}let Rt=!1;function ii(){if(Rt)return;Rt=!0,(u.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{Rt=!1,pt()})}let An=[];function De(){const{colors:e,mixedHardBins:t}=Ai(B.filter(n=>n!=null),{binColorScheme:l.binColorScheme,useDefinedBinColors:l.useDefinedBinColors});return An=t,e}function $t(){return D.filter(e=>e!=null).flatMap(e=>e.dies)}function Pn(){return l.compact?As($t()):void 0}const si=(e,t)=>bt(e.columns,t.columns)&&bt(e.rows,t.rows);function In(){at("compactMap",Pn(),si)&&Zn()}function ai(){return Ps($t(),D.filter(e=>e!=null).map(e=>e.reticleConfig))}function Fn(){at("binColors",De(),Fi),Ge()}const li=ss(Ce,()=>rs(l,ei,{functionalActive:Ve(),hasLimits:Rn()&&!Ve(),hasRecorded:ti()&&!Ve(),binMode:(l.plotMode??"hardBin")==="hardBin"||(l.plotMode??"hardBin")==="softBin"},e=>W(e),{on:!!l.compact,offered:ai(),onChange:e=>W({compact:e}),onDiagnostics:()=>ds($t(),D.filter(e=>e!=null).map(e=>e.reticleConfig),{anchor:u,onSaveText:A.onSaveText})}),()=>cs(l)),{btn:ri,sync:Hn}=is(Ce,()=>({plotMode:l.plotMode,legendPosition:Re}),e=>{Re=e;for(const t of C)t&&t.setOptions({legendPosition:Re})},{get:()=>Qe,set:e=>{Qe=e,cn()},blockedReason:$e});Hn();const ci=[{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"}],jn=hn("aggr","Aggregation method",()=>ci,()=>l.aggregationMethod??"mean",e=>W({aggregationMethod:e}));function Vn(){const e=l.plotMode==="stackedValues";jn.style.display=e?"":"none"}Vn();const{btn:di,sync:zn}=os(Ce,()=>({...l,functionalActive:Ve()}),e=>W(e));zn();const lt=xe("specRange","Colorbar range: test limits",()=>{const e=l.colorbarRangeMode==="data"?"spec":"data";W({colorbarRangeMode:e})});function Gn(){const e=(l.plotMode??"hardBin")==="value"&&Rn()&&bo(l)==="off"&&!Ve();lt.style.display=e?"":"none";const t=(l.colorbarRangeMode??"spec")==="spec";mn(lt,t),lt.ariaLabel=t?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"}Gn();const ui=as(Ce,()=>l,e=>W(e)),fi=xe("downloadAll","Download gallery PNG",ki),Be=xe("boxSelect","Select the same dies on every wafer",()=>{Q&&pe.size>0?Sn():zo(!Q)});Be.style.position="relative";const ze=u.ownerDocument.createElement("span");ze.dataset.wmapSelectAcrossCount="1",Object.assign(ze.style,{position:"absolute",top:"0",right:"0",minWidth:"14px",height:"14px",boxSizing:"border-box",padding:"0 3px",borderRadius:K.pill,background:b.iconActive,color:b.menuBg,fontSize:"11px",lineHeight:"14px",fontWeight:"700",textAlign:"center",pointerEvents:"none",display:"none"}),Be.appendChild(ze);function rt(){mn(Be,Q);const e=Q?pe.size:0;ze.style.display=e>0?"block":"none",ze.textContent=e>99?"99+":String(e),Be.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)",Be.setAttribute("aria-pressed",String(Q))}const X=u.ownerDocument.createElement("button");X.type="button",X.dataset.wmapPickedWafers="1",Object.assign(X.style,{display:"none",border:"none",background:b.bgActive,color:b.iconActive,borderRadius:K.control,padding:`${k.xs} ${k.md}`,fontSize:j.body,cursor:"pointer",whiteSpace:"nowrap",flexShrink:"0"}),Jt(X,"bare"),X.addEventListener("click",Ko);const pi=hn("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=>eo(e==="auto"?void 0:Number(e))),O=u.ownerDocument.createElement("div");Object.assign(O.style,{display:"inline-flex",alignItems:"center",gap:"0"}),P.appendChild(O),O.appendChild(J),O.appendChild(Jo),O.appendChild(jn),O.appendChild(di),O.appendChild(lt),O.appendChild(fe()),O.appendChild(li),O.appendChild(fe()),O.appendChild(ri),O.appendChild(fe()),O.appendChild(ui),O.appendChild(fe()),O.appendChild(pi),O.appendChild(fe()),O.appendChild(Be),O.appendChild(X),O.appendChild(fi),rt();let U=null,ct=null,ae=[],Kn=!1;function Ge(){const e=Ws({lotStatsSummary:N,result:{warnings:[...B.flatMap(n=>n?.warnings??[]),...ve().warnings]},extra:[l.binColors&&Pi(l.binColors,l.plotMode),Ii(An),Wo(rn())].filter(n=>!!n)}),t=e.length!==ae.length||e.some((n,o)=>n.code!==ae[o]?.code||n.message!==ae[o]?.message);ae=e,(t||!Kn)&&(Kn=!0,p.warnings?.onWarning?.(e)),gi()}function gi(){if(!U||!ct)return;const e=ae.length,t=e>0;if(U.style.display=t?"flex":"none",ct.style.display=t?"":"none",Ct(P),xt(P,"inline-flex"),!t)return;const n=$s(ae[0]),o=`${e} data ${e===1?"warning":"warnings"}`;U.style.color=n==="error"?b.errText:b.warnText,U.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(p.warnings?.display??!0)&&(ct=fe(),U=xe("warning","Data warnings",()=>{const e=Ie();if(tt(new MouseEvent("click")),e)return;const t=Rs(U.getBoundingClientRect(),ae,U.ownerDocument.defaultView??window);ho(u).appendChild(t),Fe(t),yo(t,U,()=>tt(new MouseEvent("click")))}),Ze(U,!1),P.appendChild(ct),P.appendChild(U)),Ge();function Nn(){import("./userGuideHtml.js").then(e=>hs({buildWaferMap:Os,renderWaferMap:Cs,renderWaferGallery,analyzeWaferMap:yt},e.USER_GUIDE_HTML,E,u))}M&&(P.appendChild(fe()),P.appendChild(xe("help","User guide",()=>Nn())));const Ee=u.ownerDocument.createElement("div");Ee.dataset.wmapGalleryMeta="1",Object.assign(Ee.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${k.sm} ${k.lg}`,fontSize:j.sub,lineHeight:fo.none,boxSizing:"border-box"});const Te=u.ownerDocument.createElement("div");Object.assign(Te.style,{background:b.canvasBg,display:"flex",alignItems:"stretch",gap:k.lg,paddingBottom:k.lg,minWidth:"0"});const le=u.ownerDocument.createElement("div");le.dataset.wmapGalleryLegend="1",Object.assign(le.style,{display:"flex",flexDirection:"column",gap:k.sm,background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:K.container,padding:`${k.sm} ${k.lg}`,marginBottom:k.lg,boxShadow:Qt.panel,fontSize:j.body,lineHeight:fo.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const Y=u.ownerDocument.createElement("div");Object.assign(Y.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let Oe=null,Ke=null,_n=null;function mi(){return V?Oe?Promise.resolve(Oe):(_n??=import("./insightsTab.js").then(({createInsightsTab:e})=>(Oe=e({attributes:p.attributes,getItems:()=>B,getLotStats:()=>N,getBinColors:()=>l.binColors??De(),getRingCount:()=>te({ringCount:St()},"the Insights tab"),defaultView:p.insights?.defaultView,plotStore:R,onPickPlotsFile:p.insights?.onPickPlotsFile,onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:A.onSaveImage,onSaveText:A.onSaveText,ownerDocument:u.ownerDocument,locateDie:(t,n)=>{Pt(!1),se(n,t)},openWafer:(t,n,o)=>{const i=B[t];if(!i)return;let s=null;const a=Ji({title:n,onClose:()=>s?.destroy(),anchor:u});oo(a,n,i.wafer.metadata??void 0),s=Nt(a.contentWrap,i,o,void 0,wo(a))}}),Ke=Oe.el,Ke.style.display="none",u.appendChild(Ke),Oe)),_n):Promise.resolve(null)}let dt=!1,At=null;function Pt(e){V&&(dt=e,At?.setInsightsOpen(e),Ke&&(Ke.style.display=e?"flex":"none"),Y.style.display=e?"none":"flex",O.style.display=e?"none":"inline-flex",Ct(P),xt(P,"inline-flex"),P.style.display="inline-flex",ge(),pt(),e&&mi().then(t=>{!t||!dt||(t.el.style.display="flex",t.render())}))}V&&p.insights?.defaultOpen&&queueMicrotask(()=>Pt(!0));const qn=4,ut=240,It=480,hi=720,yi=1.25;let me=It;function Xn(e){const t=H*2+110+2,n=Un();if(n)return Math.ceil(n.across*qn+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*(qn/s),d=Math.ceil(a+t);(o==null||d>o)&&(o=d)}return o}function bi(e){const t=Xn(e);return t==null?ut:Math.min(me,Math.max(ut,t))}function wi(e){const t=Xn(e);if(t==null)return!1;const n=Math.min(hi,Math.max(It,t));return n<=me?!1:(me=n,!0)}function Un(){const e=l.compact?l.compactMap:void 0,t=D.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 Yn(e,t){const n=Un();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 vi(){for(const e of oe)e?.parentElement&&Yn(e.parentElement,e)}function Zn(){me=It,Ne=ut,jt(D.map(e=>e??null)),ft(),vi()}function Ft(){return Qn()?`${me}px`:"none"}function Qn(){return T==null&&!Ht}let Ht=!1;function ft(){const e=Ft();for(const t of Array.from($.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let Ne=ut,Jn=0;function jt(e){if(wi(e)&&ft(),T==null){const n=bi(e);n>Ne&&(Ne=n)}zt()}function eo(e){T=Eo(e),ft(),zt()}function Vt(e){return`repeat(${e}, minmax(0, ${Qn()?`${me}px`:"1fr"}))`}function to(e){$.style.gridTemplateColumns!==e&&($.style.gridTemplateColumns=e)}function zt(){if(T!=null){to(Vt(T));return}const e=Math.max(1,Jn),t=12,n=$.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(me,Ne*yi),d=r=>{let g=0;for(;g<e&&o(g+1)>=r;)g++;return g};i=d(a)||d(Ne)||1}const s=n>0&&i<e;s!==Ht&&(Ht=s,ft()),to(Vt(i))}const $=u.ownerDocument.createElement("div");if(Object.assign($.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:Vt(1),gap:k.xl,paddingLeft:de,paddingRight:de,justifyContent:"start",alignContent:"start",isolation:"isolate"}),be?.placement){const e=be.placement;v=an(e,de,u.ownerDocument,Bt),v.style.maxHeight="calc(100vh - 80px)",v.style.position="sticky",v.style.top="8px",v.style.display="flex",v.style.flexDirection="column"}else if(N||gn()){const e=!!be?.defaultOpen;v=an("right",de,u.ownerDocument,Bt),v.style.maxHeight="calc(100vh - 80px)",v.style.position="sticky",v.style.top="8px",v.style.flexDirection="column",v.style.display=e?"flex":"none",z()}ge(),(be?.placement??"right")==="left"?(v&&Y.appendChild(v),Y.appendChild($)):(Y.appendChild($),v&&Y.appendChild(v));const _e=u.ownerDocument.createElement("div");Object.assign(_e.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:de,paddingRight:de,paddingTop:de,zIndex:"1",background:b.menuBg}),Te.appendChild(Ee),Te.appendChild(P),et=Ti(u.ownerDocument,()=>On(!Tt())),Te.appendChild(et.el),ge(),V&&(At=Ei(u.ownerDocument,"Maps","lot",e=>Pt(e)),Te.appendChild(At.el)),_e.appendChild(Te),_e.appendChild(le),u.appendChild(_e),u.appendChild(Y);function pt(){le.innerHTML="";const e=l.plotMode??"hardBin",t=!dt&&go.has(e),n=D.filter(y=>y!=null),o=n.find(y=>y.isLotStack),i=Is(n.map(y=>({metadata:y.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0,{curation:p.attributes}),s=e==="metadata",a=l.activeMetadataKey,d=t&&!s?To(n,y=>(e==="softBin"?y.sbin:y.hbin)??void 0,ue):{counts:new Map,total:0,pass:0},r=t&&!s?l.binColors??De():void 0,g=r?e==="softBin"?r.pass.soft:r.pass.hard:new Set,c=ws(d.counts.entries(),g).map(([y])=>y),f=t&&s&&a?To(n,y=>$i(y.metadata?.[a])):{counts:new Map,total:0,pass:0},h=s?$n()?.values:void 0,m=t&&s?(h??[...f.counts.keys()].sort(sn)).filter(y=>f.counts.has(y)):[];if(Ee.innerHTML="",i&&Ee.appendChild(i),Ee.style.display=i?"flex":"none",!c.length&&!m.length){le.style.display="none";return}le.style.display="flex";const S=u.ownerDocument.createElement("div");Object.assign(S.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${k.sm} ${k.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),le.appendChild(S);const w=on(l.highlightBin),L=D.flatMap(y=>y?.metadataFields??[]).find(y=>y.key===a),I=s?L?.label??(a?Vs(a):"Metadata"):_i[e],F=u.ownerDocument.createElement("span");if(F.textContent=I,Object.assign(F.style,{fontSize:j.body,fontWeight:"700",letterSpacing:Gi,textTransform:"uppercase",color:b.label,flexShrink:"0"}),S.appendChild(F),!s&&d.total>0){const y=d.pass,G=y/d.total*100,re=u.ownerDocument.createElement("span");re.textContent=`Yield ${vt(G)}`,Object.assign(re.style,{fontSize:j.body,fontWeight:"700",color:b.value,whiteSpace:"nowrap",flexShrink:"0"});const ce=u.ownerDocument.createElement("span");ce.textContent=`${y.toLocaleString()} / ${d.total.toLocaleString()} dies`,Object.assign(ce.style,{fontSize:j.body,color:b.label,whiteSpace:"nowrap",flexShrink:"0"}),S.appendChild(re),S.appendChild(ce)}if(s){const y=on(l.highlightMetadataValue);m.forEach((G,re)=>{const ce=y.includes(G),We=L?.values?.find(Ut=>Ut.value===G),Ye=We?.color??ji(re),co=f.counts.get(G)??0;Oo(S,{color:Ye,isActive:ce,label:We?.label??G,count:co,percent:f.total>0?co/f.total*100:void 0,onClick:Ut=>{const Bi=Do(l.highlightMetadataValue,G,Ut);En(),W({highlightMetadataValue:Bi})}})});return}const Ue=e==="softBin"?D.flatMap(y=>y?.sbinDefs??[]):D.flatMap(y=>y?.hbinDefs??[]),ao=new Set,qt=[];for(const y of Ue)ao.has(y.bin)||(ao.add(y.bin),qt.push(y));const Xt=qt.length>0?new Map(qt.map(y=>[y.bin,y])):null,lo=r??l.binColors??De(),Di=e==="softBin"?lo.soft:lo.hard,ro=y=>Di.get(y)??Hi;for(const y of c){const G=w.includes(y),re=Xt?.get(y),ce=d.counts.get(y)??0;Oo(S,{color:ro(y),isActive:G,label:re?.name?`${y} \xB7 ${re.name}`:`Bin ${y}`,count:ce,percent:d.total>0?ce/d.total*100:void 0,onMenu:(We,Ye)=>jo(e==="softBin"?"soft":"hard",y,We,Ye),onClick:We=>{const Ye=Do(l.highlightBin,y,We);En(),W({highlightBin:Ye})}})}d.total>0&&c.length>1&&le.appendChild(Us(u.ownerDocument,[...d.counts.entries()].sort(([,y],[,G])=>G-y).map(([y,G])=>({color:ro(y),count:G,label:Xt?.get(y)?.name?`${y} \xB7 ${Xt.get(y).name}`:`Bin ${y}`})),d.total))}function qe(e){const t=B.filter(c=>c!==null);if(!t.length)return[];const n=t.map(c=>c.dies.filter(_s)),o=t[0].wafer,i=t.length,s=uo(t.map(c=>Yt(c)));if(!s)return[];const a=new Set(t.map(c=>te(c,"renderWaferGallery")));if(a.size!==1)return[];const d=[...a][0],r=o.metadata?{...o,metadata:(({wafer:c,waferId:f,...h})=>h)(o.metadata)}:o;function g(c,f){return{...c,stats:{...c.stats,isLotStack:!0,aggregationMethod:f,lotSize:i}}}if(e==="stackedValues"){const c=Ae();let f=c?.filter(nn);if(c!==void 0&&f?.length===0)return[];if(c?.length||(f=Oi(t.flatMap(S=>S.dies)).map(S=>({testNumber:S,name:zs(void 0,S)}))),!f?.length)return[];const h=l.aggregationMethod??"mean";return f.map(m=>{const S=Ss(n,h,m.testNumber),w={testNumber:0,name:m.name,unit:m.unit,...Ks(m)};return{wafer:r,dies:S,passBins:[...s],ringCount:d,testDefs:[w],label:`${Gs(m,m.testNumber)} \xB7 ${h}`,isLotStack:!0,aggrMethod:h,lotSize:i,statsSummary:g(yt({wafer:r,dies:S,passBins:[...s],ringCount:d,testDefs:[w]},{testNumbers:[0]}),h)}})}if(e==="stackedBins"){let c=mt(t.map(f=>f?.hbinDefs));return(!c||c.length===0)&&(c=[...new Set(t.flatMap(h=>h.dies.map(m=>m.hbin).filter(m=>m!=null)))].sort((h,m)=>h-m).map(h=>({bin:h,name:`Bin ${h}`}))),c.map(f=>{const h=vo(n,f.bin,"hard"),m=[{bin:f.bin,name:f.name}];return{wafer:r,dies:h,passBins:[...s],ringCount:d,hbinDefs:m,label:`${f.bin} \xB7 ${f.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:g(yt({wafer:r,dies:h,passBins:[...s],ringCount:d,hbinDefs:m}),"countBin")}})}if(e==="stackedSoftBins"){let c=mt(t.map(f=>f?.sbinDefs));return(!c||c.length===0)&&(c=[...new Set(t.flatMap(h=>h.dies.map(m=>m.sbin).filter(m=>m!=null)))].sort((h,m)=>h-m).map(h=>({bin:h,name:`Bin ${h}`}))),c.map(f=>{const h=vo(n,f.bin,"soft"),m=[{bin:f.bin,name:f.name}];return{wafer:r,dies:h,passBins:[...s],ringCount:d,sbinDefs:m,label:`${f.bin} \xB7 ${f.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:g(yt({wafer:r,dies:h,passBins:[...s],ringCount:d,sbinDefs:m}),"countBin")}})}return t}function Gt(e){const t=B.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),o=l.plotMode,i=$e()!==null;l={...l,...e};const s=l.plotMode,a=he.has(s),d=o!==void 0&&he.has(o),r=Je>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const c=De();l={...l,binColors:c},e={...e,binColors:c}}if("compact"in e){const c=Pn();l={...l,compactMap:c},e={...e,compactMap:c}}if(("compact"in e||l.compact&&("rotation"in e||"showXYIndicator"in e))&&Zn(),e.plotMode!==void 0)if(a){const c=Gt(s);if(l={...l,...c},r)for(const f of C)f&&f.setOptions(e);else ee(qe(s))}else if(d){const{valueRange:c,lotSize:f,aggregationMethod:h,...m}=l;if(l=m,r)for(const S of C)S&&S.setOptions(e);else ee(B.filter(S=>S!==null))}else for(const c of C)c&&c.setOptions(e);else if(e.aggregationMethod!==void 0&&s==="stackedValues")if(r)for(const c of C)c&&c.setOptions(e);else ee(qe("stackedValues"));else for(const c of C)c&&c.setOptions(e);$e()!==null!==i&&cn(),pt(),Vn(),Hn(),Wn();const g=e.plotMode!==void 0&&e.plotMode!==o;(Bs.some(c=>c in e)||g)&&z(),Ge(),zn(),Gn(),Lt(),Ot(),t&&p.onViewOptionsChange?.(Co(l),n,Ds(n))}function no(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:k.xs,flex:"1",minWidth:"0"});const i=e.createElement("span");i.textContent=t,Object.assign(i.style,{fontWeight:"700",fontSize:j.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(i);const s=Bo(e,o,t,n,p.attributes);return{wrap:o,metaPanel:s}}function oo(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]");if(!o||Fs(n??{}).length===0)return;const i=o.parentElement,s=u.ownerDocument.createElement("div");Object.assign(s.style,{display:"flex",alignItems:"center",gap:k.xs,flex:"1",minWidth:"0"}),i?.insertBefore(s,o),s.appendChild(o);const a=Bo(u.ownerDocument,s,t,n,p.attributes);a&&(e.contentWrap.style.position="relative",e.contentWrap.appendChild(a))}function Kt(e,t,n){const o=u.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:K.container,boxShadow:Qt.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:Ft(),maxHeight:Ft()});const i=u.ownerDocument.createElement("div");Object.assign(i.style,{display:"flex",alignItems:"center",padding:`${k.md} ${k.lg} ${k.sm}`,borderBottom:`1px solid ${b.menuBorder}`,flexShrink:"0",gap:k.sm});const{wrap:s,metaPanel:a}=no(document,ht(e,t),e.wafer.metadata??void 0);i.appendChild(s);const d=u.ownerDocument.createElement("button");d.dataset.wmapExpandBtn="1",d.setAttribute("aria-label","Open full view"),en(d),d.innerHTML=Zt.expand,Object.assign(d.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${b.menuBorder}`,borderRadius:K.control,background:b.panelBg,color:b.label,padding:k.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),Jt(d),i.appendChild(d),i.addEventListener("click",h=>{(h.ctrlKey||h.metaKey)&&(h.preventDefault(),h.stopPropagation(),Go(D.indexOf(e)))},!0),o.appendChild(i);const r=u.ownerDocument.createElement("div");Object.assign(r.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(r),Yn(o,r),a&&r.appendChild(a),$.appendChild(o),o.addEventListener("contextmenu",h=>{if(h.defaultPrevented)return;h.preventDefault();const m=e.viewOptions?{...l,...e.viewOptions}:l,S=Dt()??kn(t),w=S?.source??xs(e.dies,{waferLabel:ye(e),testDefs:e.testDefs,isLotStack:e.isLotStack,activeTest:m.plotMode==="value"?m.activeTest:void 0,waferIndex:t,wafer:e.wafer,passBins:ue(e),ringCount:te(e,"renderWaferGallery")}),L={x:h.clientX,y:h.clientY};import("./drilldown.js").then(({openDrilldownMenu:I})=>{o.isConnected&&I(L,o,w,S?{plots:R,attributes:p.attributes,...S.ctx}:{plots:R,attributes:p.attributes,onSaveImage:f.getSaveImageHook(),onSaveText:f.getSaveTextHook(),onLocateDie:F=>se(t,F)})})});const g=Qe||$e()!==null,c=e.viewOptions?{...l,...e.viewOptions}:l,f=So(r,e,{viewOptions:{...c,showLegend:g,legendPosition:Re},showTooltip:!0,padding:H,statsSummary:e.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,downloadFilename:p.downloadFilename,onClick:e.onClick,onSelect:vn(e),drilldownSourceOverride:()=>Ho(t),insights:ne,onExpand:()=>Xe(t,e),showIdentity:!1,chromeInset:Ni,drawWhenVisible:!0});return f.setViewControlsVisible(!1),f.setSummaryVisible(!1),d.onclick=()=>Xe(t,e),{card:o,ctrl:f,canvasWrapper:r,expandBtn:d}}function Si(e){const t=we[e];if(!t)return;const n=[...q.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=Zt.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>xi(n.id)):(t.innerHTML=Zt.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>Xe(e,D[e]))}function ee(e){Mi(),Ie()?.remove(),Fe(null),ke(),D=[],_.clear(),Et.clear(),X.style.display="none";for(const r of C)r&&r.destroy();C=[],oe=[],we=[],Je=0,$.innerHTML="",Jn=e.length,jt(e.map(r=>typeof r=="function"?null:r));const t=[];for(let r=0;r<e.length;r++){const g=e[r];if(typeof g=="function"){const c=u.ownerDocument.createElement("div");c.className="wmap-gallery-card",Object.assign(c.style,{background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:K.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const f=u.ownerDocument.createElement("span");f.textContent="\u2026",Object.assign(f.style,{color:b.label,fontSize:"18px"}),c.appendChild(f),$.appendChild(c),D.push(null),C.push(null),oe.push(null),we.push(null),t.push({index:r,factory:g,placeholder:c}),Je++}else{const{ctrl:c,canvasWrapper:f,expandBtn:h}=Kt(g,r,e.length);D.push(g),C.push(c),oe.push(f),we.push(h)}}Fn(),pt(),Lt(),Ot(),In();const n=++Pe,o=()=>{setTimeout(()=>{n===Pe&&p.onItemsResolved?.()},0)},i=r=>{setTimeout(()=>{n===Pe&&p.onItemResolved?.(r,e.length)},0)};let s=e.length-t.length;s>0&&i(s);let a=0;function d(){if(n!==Pe)return;if(a>=t.length){if(he.has(l.plotMode)){const L=l.plotMode;ee(qe(L));return}je=o,z(),Me||(je=null,o());return}const{index:r,factory:g,placeholder:c}=t[a++],f=g();D[r]=f,B[r]=f,jt([f]);const{card:h,ctrl:m,canvasWrapper:S,expandBtn:w}=Kt(f,r,e.length);C[r]=m,oe[r]=S,we[r]=w,Je--,c.replaceWith(h),i(++s),ii(),oi(),!v&&!be?.placement&&f.statsSummary?.findings.length&&(v=an("right",de,u.ownerDocument,Bt),v.style.maxHeight="calc(100vh - 80px)",v.style.position="sticky",v.style.top="8px",v.style.flexDirection="column",v.style.display="none",(be?.placement??"right")==="left"?Y.insertBefore(v,$):Y.appendChild(v),z(),ge()),ge(),setTimeout(d,0)}t.length>0?setTimeout(d,0):o()}if(he.has(l.plotMode)&&B.length>0){const e=Gt(l.plotMode);l={...l,...e},ee(qe(l.plotMode))}else ee(x);Ge();let Le=0;const io=new(u.ownerDocument.defaultView??window).ResizeObserver(()=>{if(Le)return;Le=(u.ownerDocument.defaultView??window).requestAnimationFrame(()=>{Le=0,T==null&&zt()})});io.observe($),v&&z();function Ci(e,t){const n=oe[e];if(!n)return;n.innerHTML="",Object.assign(n.style,{alignItems:"center",justifyContent:"center"});const o=u.ownerDocument.createElement("span");o.textContent=t?"Opened in its own window":"Opened in the wafer viewer",Object.assign(o.style,{color:b.label,fontSize:j.body,textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function Xe(e,t){for(const a of q.values())if(a.cardIndex===e)return;const n=ht(t,e),o=Ro++,i=C[e]?.getOptions(),s=Zi(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:j.family}),es(u,a.documentElement);const d=ts(u,a.documentElement,()=>w.setOptions({})),r=a.createElement("div");r.dataset.wmapWindowBanner="1",r.textContent=n,Object.assign(r.style,{display:"none",padding:`${k.sm} ${k.xl}`,fontSize:j.body,fontWeight:"700",background:b.warnBg,color:b.warnText,borderBottom:`1px solid ${b.warnBorder}`,flexShrink:"0"}),a.body.appendChild(r);const g=a.createElement("div");Object.assign(g.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),a.body.appendChild(g);const{wrap:c,metaPanel:f}=no(a,n,t.wafer.metadata??void 0),h=a.createElement("div");Object.assign(h.style,{display:"flex",alignItems:"center",padding:`${k.md} ${k.lg} ${k.sm}`,borderBottom:`1px solid ${b.menuBorder}`,flexShrink:"0",gap:k.sm}),h.appendChild(c),g.appendChild(h);const m=a.createElement("div");Object.assign(m.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),f&&m.appendChild(f),g.appendChild(m);let S=0;const w=Nt(m,t,void 0,i,(I,F)=>{const Ue=I?F:-S;try{s.resizeBy(Ue,0),S=I?F:0}catch{}}),L=setInterval(()=>{s.closed&>(o)},400);s.addEventListener("pagehide",()=>gt(o)),q.set(o,{id:o,ctrl:w,cardIndex:e,label:n,closePollId:L,stopThemeSync:d,close:()=>{s.closed||s.close()},setTitle:I=>{a.title=I,r.textContent=I,r.style.display="block"}})}else{const a=Qi({title:n,onClose:()=>gt(o),anchor:u});a.contentWrap.style.flexDirection="column",oo(a,n,t.wafer.metadata??void 0);const d=Nt(a.contentWrap,t,void 0,i,wo(a));q.set(o,{id:o,ctrl:d,cardIndex:e,label:n,closePollId:null,close:()=>a.close(),setTitle:r=>{const g=a.box.querySelector("[data-wmap-window-title]");g&&(g.textContent=r,g.title=r)}})}C[e]?.destroy(),C[e]=null,Ci(e,s!==null),Si(e)}function Nt(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:Re},g=So(e,t,{viewOptions:r,showTooltip:!0,padding:H,statsSummary:t.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,downloadFilename:p.downloadFilename,onClick:t.onClick,onSelect:vn(t),insights:ne,showExpandButton:!1,onSummaryPanelChange:i,showIdentity:!1});return g.setViewControlsVisible(!0),g.setSummaryVisible(!0),g.setExpandVisible(!1),g}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=D[n];if(!o)return;const{card:i,ctrl:s,canvasWrapper:a,expandBtn:d}=Kt(o,n,D.length);oe[n]?.parentElement?.replaceWith(i),C[n]=s,oe[n]=a,we[n]=d}function xi(e){const t=q.get(e);t&&(t.close(),gt(e))}function Mi(){for(const e of q.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function _t(){for(const e of C)e?.drawPendingNow()}const so=u.ownerDocument.defaultView??window;so.addEventListener("beforeprint",_t);function ki(){_t();const e=[...$.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=(u.ownerDocument.defaultView??window).devicePixelRatio||1,r=Math.round(26*d),g=Math.round(12*d),c=u.ownerDocument.createElement("canvas");c.width=n*i+(n-1)*a,c.height=o*(s+r)+(o-1)*a;const f=c.getContext("2d"),h=Vi($);f.fillStyle=h.background,f.fillRect(0,0,c.width,c.height),e.forEach((m,S)=>{const w=S%n,L=Math.floor(S/n),I=w*(i+a),F=L*(s+r+a),Ue=m.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";f.fillStyle=h.surface,f.fillRect(I,F,i,r),f.fillStyle=h.text,f.font=`700 ${g}px system-ui, sans-serif`,f.textAlign="left",f.textBaseline="middle",f.fillText(Ue,I+Math.round(10*d),F+r/2,i-Math.round(20*d)),f.drawImage(m,I,F+r)}),c.toBlob(m=>{if(!m)return;const S=C.find(w=>w!=null)?.getExportTitle();ls(m,["gallery",S].filter(Boolean).join(" "),A.onSaveImage)})}return{setItems(e){B=e.map(n=>typeof n=="function"?null:n);const t=l.plotMode;if(he.has(t))if(e.some(o=>typeof o=="function"))ee(e);else{const o=Gt(t);l={...l,...o},ee(qe(t))}else ee(e)},setOptions(e){W(e,{fireCallback:!1})},getOptions(){return Co(l)},setFindingsNotice(e){bn=e,z()},setColumns(e){eo(e)},getBinColors(){return l.binColors??De()},setLotStatsSummary(e){N=e,Ge(),v&&z(),ge()},openUserGuide:Nn,destroy(){R.flush(),Pe++,so.removeEventListener("beforeprint",_t),Me?.cancel(),Me=null,je=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=[],Ie()?.remove(),io.disconnect(),Le&&((u.ownerDocument.defaultView??window).cancelAnimationFrame(Le),Le=0),u.ownerDocument.removeEventListener("click",tt,!0),window.removeEventListener("blur",yn),Lo(),mo(),_e.remove(),Y.remove(),v?.remove(),Oe?.destroy()}}}
|
|
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&>(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()}}}
|
|
@@ -42,10 +42,6 @@ export interface WaferPreferences {
|
|
|
42
42
|
* The toolbar offers the toggle only when some definition carries a colour.
|
|
43
43
|
*/
|
|
44
44
|
useDefinedBinColors?: boolean;
|
|
45
|
-
/** Interactive rotation in degrees (0 | 90 | 180 | 270). */
|
|
46
|
-
rotation?: 0 | 90 | 180 | 270;
|
|
47
|
-
flipX?: boolean;
|
|
48
|
-
flipY?: boolean;
|
|
49
45
|
showDieLabels?: boolean;
|
|
50
46
|
showRingBoundaries?: boolean;
|
|
51
47
|
showQuadrantBoundaries?: boolean;
|
|
@@ -58,16 +54,6 @@ export interface WaferPreferences {
|
|
|
58
54
|
* so the map is a little smaller.
|
|
59
55
|
*/
|
|
60
56
|
showAxes?: boolean;
|
|
61
|
-
/**
|
|
62
|
-
* Draw the dies on a compact grid with the empty rows and columns removed and each group of
|
|
63
|
-
* dies outlined, instead of at their physical positions. Default false. The toolbar offers
|
|
64
|
-
* the toggle when the occupied rows and columns repeat at a regular pitch (a multi-project
|
|
65
|
-
* wafer), or at the supplied `reticleConfig` width and height; setting it here applies it
|
|
66
|
-
* regardless. Only the layout changes: every die is still drawn and counted, and axis labels
|
|
67
|
-
* stay original die coordinates. The wafer outline, rings, quadrants, reticle grid and XY
|
|
68
|
-
* indicator are not drawn in this layout.
|
|
69
|
-
*/
|
|
70
|
-
compact?: boolean;
|
|
71
57
|
/** Legend position for bin modes. Default 'default'. */
|
|
72
58
|
legendPosition?: 'default' | 'compact' | 'bottom' | 'top' | 'left' | 'floating';
|
|
73
59
|
/**
|
|
@@ -79,6 +65,44 @@ export interface WaferPreferences {
|
|
|
79
65
|
* place it is set (it used to have four).
|
|
80
66
|
*/
|
|
81
67
|
fallbackFormat?: 'si' | 'engineering';
|
|
68
|
+
/**
|
|
69
|
+
* Hatch dies whose bin is not a pass bin, giving pass/fail a channel that is
|
|
70
|
+
* not hue. Default false. Bin modes only — in value mode the spec markers
|
|
71
|
+
* already serve this role.
|
|
72
|
+
*/
|
|
73
|
+
markFailingDies?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Controls the default colorbar range when the active testDef has spec limits.
|
|
76
|
+
* `'spec'` (default): colorbar spans [limitLow, limitHigh]; out-of-spec dies show fail colors.
|
|
77
|
+
* `'data'`: colorbar spans actual data min/max; out-of-spec coloring still applies.
|
|
78
|
+
*/
|
|
79
|
+
colorbarRangeMode?: 'spec' | 'data';
|
|
80
|
+
/**
|
|
81
|
+
* Insights charts: widen a value axis to take in the test limits. Unset, each chart decides
|
|
82
|
+
* from its own data; the charts' axis menu sets it, and it then holds across tests.
|
|
83
|
+
*/
|
|
84
|
+
chartAxisIncludesLimits?: boolean;
|
|
85
|
+
/** Insights charts: leave outliers off a value axis so the bulk of the data fills it. Default false. */
|
|
86
|
+
chartClipOutliers?: boolean;
|
|
87
|
+
/** Insights charts: which limit lines to draw — test limits, spec limits, both or none. Default `'both'`. */
|
|
88
|
+
chartLimitLines?: 'test' | 'spec' | 'both' | 'none';
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Display state — describes this view of this data, not worth persisting.
|
|
92
|
+
* Changes as the user navigates tests and modes, or depends on the data shown:
|
|
93
|
+
* carried to another lot, it would describe that lot wrongly.
|
|
94
|
+
*/
|
|
95
|
+
export interface WaferDisplayState {
|
|
96
|
+
plotMode?: PlotMode;
|
|
97
|
+
/**
|
|
98
|
+
* Interactive rotation in degrees (0 | 90 | 180 | 270), on top of the data's own orientation.
|
|
99
|
+
* State, not a preference: it is relative to this data, and the only sign of it is the lit
|
|
100
|
+
* Orientation button, so carried to another lot it would show that lot's defects on the wrong side.
|
|
101
|
+
*/
|
|
102
|
+
rotation?: 0 | 90 | 180 | 270;
|
|
103
|
+
/** Interactive mirroring, with `rotation`. */
|
|
104
|
+
flipX?: boolean;
|
|
105
|
+
flipY?: boolean;
|
|
82
106
|
/**
|
|
83
107
|
* Draw this map's own legend block — the categorical bin legend, the spec/
|
|
84
108
|
* pass-fail legend, or the value colorbar, whichever the plot mode calls for.
|
|
@@ -93,33 +117,27 @@ export interface WaferPreferences {
|
|
|
93
117
|
* targets that toggle `highlightBin` for this map — so only turn it off where
|
|
94
118
|
* an equivalent control is still reachable, and never where the map's scale
|
|
95
119
|
* is its own (a data-ranged colorbar). `renderWaferGallery` owns that rule.
|
|
120
|
+
* State, not a preference: whether it is safe off depends on the view.
|
|
96
121
|
*/
|
|
97
122
|
showLegend?: boolean;
|
|
98
123
|
/**
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
*
|
|
124
|
+
* Draw the dies on a compact grid with the empty rows and columns removed and each group of
|
|
125
|
+
* dies outlined, instead of at their physical positions. Default false. The toolbar offers
|
|
126
|
+
* the toggle when the occupied rows and columns repeat at a regular pitch (a multi-project
|
|
127
|
+
* wafer), or at the supplied `reticleConfig` width and height; setting it here applies it
|
|
128
|
+
* regardless. Only the layout changes: every die is still drawn and counted, and axis labels
|
|
129
|
+
* stay original die coordinates. The wafer outline, rings, quadrants, reticle grid and XY
|
|
130
|
+
* indicator are not drawn in this layout. State, not a preference: it suits a multi-project
|
|
131
|
+
* wafer, and carried to an ordinary one it would drop the outline, rings and quadrants.
|
|
102
132
|
*/
|
|
103
|
-
|
|
133
|
+
compact?: boolean;
|
|
104
134
|
/**
|
|
105
135
|
* When true, apply log₁₀ scale to value normalization and the colorbar.
|
|
106
136
|
* Overrides the per-test TestDef.logScale default.
|
|
107
|
-
* Falls back to linear when vMin ≤ 0.
|
|
137
|
+
* Falls back to linear when vMin ≤ 0. Choosing a test resets it to that test's own default,
|
|
138
|
+
* so it is per test, not a preference.
|
|
108
139
|
*/
|
|
109
140
|
logScale?: boolean;
|
|
110
|
-
/**
|
|
111
|
-
* Controls the default colorbar range when the active testDef has spec limits.
|
|
112
|
-
* `'spec'` (default): colorbar spans [limitLow, limitHigh]; out-of-spec dies show fail colors.
|
|
113
|
-
* `'data'`: colorbar spans actual data min/max; out-of-spec coloring still applies.
|
|
114
|
-
*/
|
|
115
|
-
colorbarRangeMode?: 'spec' | 'data';
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Transient display state — describes the current view session, not worth persisting.
|
|
119
|
-
* Changes frequently as the user navigates tests and modes.
|
|
120
|
-
*/
|
|
121
|
-
export interface WaferDisplayState {
|
|
122
|
-
plotMode?: PlotMode;
|
|
123
141
|
/**
|
|
124
142
|
* Requested pass/fail display for `value` mode — `'spec'` (spec-limit judgement),
|
|
125
143
|
* `'test'` (the tester's recorded verdict from `die.testPass`), or `'off'` (gradient).
|
|
@@ -225,6 +243,12 @@ export interface RenderOptions extends ForwardedDrawOptions {
|
|
|
225
243
|
showIdentity?: boolean;
|
|
226
244
|
/** Optional precomputed wafer-level stats summary. Enables the summary panel toggle button in the toolbar. */
|
|
227
245
|
statsSummary?: StatsSummary;
|
|
246
|
+
/**
|
|
247
|
+
* Called with the new summary after the map re-analyses its wafer itself: when the reader asks, from the Findings
|
|
248
|
+
* section, for the test-value analysis the summary records as not run (`stats.testValueAnalysis`). The map already
|
|
249
|
+
* shows the new summary; keep it so the host's own copies (a report, a lot view, a log) match.
|
|
250
|
+
*/
|
|
251
|
+
onStatsSummaryChange?: (summary: StatsSummary) => void;
|
|
228
252
|
/**
|
|
229
253
|
* A prefix for every file the map saves — PNGs and CSVs alike. The lot,
|
|
230
254
|
* wafer and content follow it (`<prefix>_W05_hard-bin.png`), except any the
|
|
@@ -261,9 +285,12 @@ export interface RenderOptions extends ForwardedDrawOptions {
|
|
|
261
285
|
/**
|
|
262
286
|
* A row at the top of the Findings section stating that a category of finding
|
|
263
287
|
* is not present, and optionally offering to compute it — see
|
|
264
|
-
* {@link FindingsNotice}.
|
|
265
|
-
*
|
|
266
|
-
*
|
|
288
|
+
* {@link FindingsNotice}. Replaces the built-in offer of the skipped
|
|
289
|
+
* test-value analysis while set.
|
|
290
|
+
*
|
|
291
|
+
* @deprecated The renderers offer the skipped test-value analysis themselves
|
|
292
|
+
* (from `stats.testValueAnalysis`) and report the re-run through
|
|
293
|
+
* `onStatsSummaryChange`. See API_REMOVALS.md.
|
|
267
294
|
*/
|
|
268
295
|
findingsNotice?: FindingsNotice;
|
|
269
296
|
/**
|
|
@@ -358,8 +385,9 @@ export interface WaferMapController {
|
|
|
358
385
|
/** Programmatically set the selected dies (renders highlight overlay). */
|
|
359
386
|
/**
|
|
360
387
|
* Replace the Findings-section notice (see `FindingsNotice`). Pass `undefined`
|
|
361
|
-
* to clear it
|
|
362
|
-
*
|
|
388
|
+
* to clear it, which brings back the built-in offer.
|
|
389
|
+
*
|
|
390
|
+
* @deprecated With `findingsNotice`. See API_REMOVALS.md.
|
|
363
391
|
*/
|
|
364
392
|
setFindingsNotice(notice: FindingsNotice | undefined): void;
|
|
365
393
|
setSelection(dies: Die[]): void;
|
|
@@ -396,6 +424,7 @@ export interface WaferMapController {
|
|
|
396
424
|
/** Remove all event listeners and DOM elements. */
|
|
397
425
|
destroy(): void;
|
|
398
426
|
}
|
|
427
|
+
export declare const WAFER_PREFERENCE_KEYS: readonly (keyof WaferPreferences)[];
|
|
399
428
|
/** Options that change die colours without changing what the view contains —
|
|
400
429
|
* any of them means every colour-bearing surface (panels, footer) redraws. */
|
|
401
430
|
export declare const COLOR_KEYS: readonly (keyof CardViewOptions)[];
|
|
@@ -465,6 +494,11 @@ export interface CardRenderOptions extends Omit<RenderOptions, 'viewOptions'> {
|
|
|
465
494
|
chromeInset?: string;
|
|
466
495
|
/** Replaces the expand action for both the expand button and the E key. */
|
|
467
496
|
onExpand?: () => void;
|
|
497
|
+
/**
|
|
498
|
+
* The offer of the test-value analysis, in place of this map's own: the gallery's, which runs it for the whole
|
|
499
|
+
* lot (one decision for every wafer), where the map's own would run this wafer alone.
|
|
500
|
+
*/
|
|
501
|
+
testValueOffer?: () => FindingsNotice | undefined;
|
|
468
502
|
/**
|
|
469
503
|
* A host that owns a wider selection than this map's (the gallery, selecting the same die positions
|
|
470
504
|
* on every wafer) supplies the drilldown population and context here. Returns `undefined` to fall back
|