@wafertools/wafermap 0.35.0 → 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.
Files changed (97) hide show
  1. package/AGENTS.md +18 -9
  2. package/CHANGELOG.md +246 -0
  3. package/README.md +7 -4
  4. package/dist/packages/canvas-adapter/chartPrefs.d.ts +16 -0
  5. package/dist/packages/canvas-adapter/chartPrefs.js +1 -0
  6. package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  8. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  9. package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
  10. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  11. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  12. package/dist/packages/canvas-adapter/index.d.ts +1 -0
  13. package/dist/packages/canvas-adapter/index.js +1 -1
  14. package/dist/packages/canvas-adapter/insightsTab.d.ts +7 -0
  15. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  16. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +20 -5
  17. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  18. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +85 -38
  19. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  20. package/dist/packages/canvas-adapter/summaryPanel.d.ts +38 -12
  21. package/dist/packages/canvas-adapter/summaryPanel.js +4 -2
  22. package/dist/packages/canvas-adapter/summaryToggle.d.ts +11 -0
  23. package/dist/packages/canvas-adapter/summaryToggle.js +1 -0
  24. package/dist/packages/canvas-adapter/testValueOffer.d.ts +14 -0
  25. package/dist/packages/canvas-adapter/testValueOffer.js +1 -0
  26. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  27. package/dist/packages/canvas-adapter/toolbar.d.ts +2 -0
  28. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  29. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  30. package/dist/packages/canvas-adapter/userGuideHtml.js +46 -23
  31. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  32. package/dist/packages/canvas-adapter/version.js +1 -1
  33. package/dist/packages/canvas-adapter/warnings.js +1 -1
  34. package/dist/packages/core/aggregates.d.ts +10 -0
  35. package/dist/packages/core/aggregates.js +1 -1
  36. package/dist/packages/core/classify.d.ts +5 -0
  37. package/dist/packages/core/classify.js +1 -1
  38. package/dist/packages/core/dieTable.d.ts +31 -0
  39. package/dist/packages/core/dieTable.js +1 -1
  40. package/dist/packages/core/passBins.d.ts +6 -0
  41. package/dist/packages/core/passBins.js +1 -1
  42. package/dist/packages/core/wafer.d.ts +10 -1
  43. package/dist/packages/core/wafer.js +1 -1
  44. package/dist/packages/renderer/buildView.d.ts +5 -0
  45. package/dist/packages/renderer/buildView.js +1 -1
  46. package/dist/packages/renderer/buildWaferMap.d.ts +50 -4
  47. package/dist/packages/renderer/buildWaferMap.js +1 -1
  48. package/dist/packages/renderer/derivedTests/parser.js +1 -1
  49. package/dist/packages/renderer/fmt.d.ts +10 -0
  50. package/dist/packages/renderer/fmt.js +1 -1
  51. package/dist/packages/renderer/index.d.ts +1 -0
  52. package/dist/packages/renderer/index.js +1 -1
  53. package/dist/packages/renderer/spec.d.ts +4 -0
  54. package/dist/packages/renderer/spec.js +1 -1
  55. package/dist/packages/renderer/valueFilter.d.ts +55 -0
  56. package/dist/packages/renderer/valueFilter.js +1 -0
  57. package/dist/packages/stats/analyzeWaferLot.d.ts +16 -0
  58. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  59. package/dist/packages/stats/analyzeWaferMap.d.ts +62 -4
  60. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  61. package/dist/packages/stats/capability.d.ts +5 -0
  62. package/dist/packages/stats/capability.js +1 -1
  63. package/dist/packages/stats/clusterDetection.js +1 -1
  64. package/dist/packages/stats/connectedComponents.d.ts +19 -0
  65. package/dist/packages/stats/connectedComponents.js +1 -1
  66. package/dist/packages/stats/correlation.d.ts +36 -4
  67. package/dist/packages/stats/correlation.js +1 -1
  68. package/dist/packages/stats/filterFindings.d.ts +1 -1
  69. package/dist/packages/stats/filterFindings.js +1 -1
  70. package/dist/packages/stats/findingText.d.ts +8 -0
  71. package/dist/packages/stats/findingText.js +2 -2
  72. package/dist/packages/stats/index.d.ts +2 -1
  73. package/dist/packages/stats/index.js +1 -1
  74. package/dist/packages/stats/lotDrift.js +1 -1
  75. package/dist/packages/stats/lotPattern.js +1 -1
  76. package/dist/packages/stats/math.d.ts +25 -3
  77. package/dist/packages/stats/math.js +1 -1
  78. package/dist/packages/stats/mergeTestDefs.js +1 -1
  79. package/dist/packages/stats/patternClassification.d.ts +44 -18
  80. package/dist/packages/stats/patternClassification.js +1 -1
  81. package/dist/packages/stats/plotData.d.ts +11 -0
  82. package/dist/packages/stats/plotData.js +1 -1
  83. package/dist/packages/stats/regions.d.ts +6 -0
  84. package/dist/packages/stats/regions.js +1 -1
  85. package/dist/packages/stats/renderSummaryReport.js +33 -33
  86. package/dist/packages/stats/reportHtml.d.ts +12 -18
  87. package/dist/packages/stats/reportHtml.js +112 -48
  88. package/dist/packages/stats/synthesis.d.ts +48 -17
  89. package/dist/packages/stats/synthesis.js +1 -1
  90. package/dist/packages/stats/testPassRate.js +1 -1
  91. package/dist/packages/stats/testValueBudget.d.ts +15 -0
  92. package/dist/packages/stats/testValueBudget.js +1 -0
  93. package/dist/packages/stats/types.d.ts +89 -22
  94. package/llms.txt +2 -2
  95. package/package.json +1 -1
  96. package/dist/packages/canvas-adapter/summaryRail.d.ts +0 -7
  97. package/dist/packages/canvas-adapter/summaryRail.js +0 -1
@@ -1 +1 @@
1
- import{createViewSwitch as bi}from"./viewSwitch.js";import{createSummaryRail as wi}from"./summaryRail.js";import{getUniqueTestNumbers as vi,resolveTestNumber as Si,findTestDef as Ci,collectMetadataValues as xi}from"../renderer/buildView.js";import{metadataCategoricalValue as Mi}from"../core/metadata.js";import{resolveBinColorsForMaps as ki,mergeBinDefs as mt,binColorWarning as Di,mixedPassBinsWarning as Bi,binColorsEqual as Ei}from"../renderer/binColors.js";import{commonPassBins as Oi,itemPassBins as to}from"../core/passBins.js";import{requireRingCount as ne}from"../core/ringCount.js";import{NO_DATA_FILL as Ti}from"../renderer/colorMap.js";import{metadataValueColor as Li}from"../renderer/colorMap.js";import{resolveCanvasTheme as Wi}from"./canvasTheme.js";import{ICONS as _t}from"./icons.js";import{SHADOW as qt,LEADING as no,TRACKING as Ri,controlStyle as $i,wireControlHover as Xt,SPACE as k,EDGE_GUTTER as fe,MAP_CHROME_INSET as Ai,RADIUS as _,FONT as j,CLR as b,sevColor as oo,MODE_LABELS as Ii,BIN_LEGEND_MODES as io,STACKED_MODES as Oe,applyOverlayZ as Pi,getTooltip as Fi,hideTooltip as so,createToolbarHelpers as Hi,buildModeMenuEl as ji,openDetachWindow as Vi,openFloatingWindow as zi,openModal as Ni,copyWmapThemeTokens as Gi,syncWmapPopupTheme as Ki,makePaletteBtn as _i,makeLogScaleBtn as qi,makeLegendStyleBtn as Xi,makeOverlaysBtn as Ui,makeOrientationBtn as Yi,menuLayerFor as ao,saveImageBlob as Zi,markMenuTrigger as Ze,wireMenuA11y as lo,wireTooltip as Ut,requestedPassFailDisplay as ro,overlayMenuRows as Qi,anyOverlayActive as Ji,openCompactDiagnostics as es,roomForPanel as co,logWmapVersionOnce as ts,buildDataModeEntries as ns,metadataKeyHasData as os,metadataModeEntry as is}from"./toolbar.js";import{openReportModal as ss,openUserGuideWindow as as}from"./guideWindow.js";import{waferDisplayLabel as gt,waferIdentityLabel as ye}from"../core/waferLabel.js";import{metadataDisplayValue as ls}from"../core/metadata.js";import{withExportContext as rs}from"./exportName.js";import{sortBinsForDisplay as cs}from"../stats/binPareto.js";import{diePassStatus as ds}from"../core/dies.js";import{aggregateValues as us,aggregateBinCounts as uo}from"../core/aggregates.js";import{renderWaferMap as fs,renderWaferMapCard as fo,toPublicViewOptions as po}from"./renderWaferMap.js";import{waferPopulation as ps,selectionPopulation as ms,LOT_STACK_REASON as Yt}from"./chartPopulation.js";import{sourceFromBins as mo}from"./plotItems.js";import{plotStoreFor as gs}from"./plotStore.js";import{classifyChanged as hs,COLOR_KEYS as ys,findingBin as bs}from"./renderWaferMap.js";import{findingPatternKey as go}from"../stats/filterFindings.js";import{buildWaferMap as ws,getTestPassStatus as ho,isParametricTest as Zt,getDieTestValue as vs}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as ht}from"../stats/analyzeWaferMap.js";import{collectWarnings as Ss,buildWarningsMenuEl as Cs,severityOf as xs}from"./warnings.js";import{asList as Qt,compareNatural as Jt,arrayEqual as yt,toggleHighlight as yo}from"../core/utils.js";import{buildCompactMap as Ms,compactLayoutOffered as ks}from"../core/compact.js";import{attachExpandableMetadata as bo}from"./identityHeader.js";import{createSummaryPanelEl as en,buildMetadataStripRow as Ds,metadataEntries as Bs,renderLotSummaryContentSteps as Es,reportMapsFromItems as Os}from"./summaryPanel.js";import{prettyKey as Ts}from"../stats/facets.js";import{testLabel as Ls,markedTestLabel as Ws,derivedFields as Rs}from"../renderer/testLabel.js";import{mergeTestDefs as $s}from"../stats/mergeTestDefs.js";import{getDieKey as bt,hasPosition as As}from"../core/dies.js";import{testValue as Is}from"../core/dieTable.js";import{runChunked as Ps}from"./chunked.js";function wo(d){if(typeof d!="number"||!Number.isFinite(d))return;const D=Math.round(d);return D>=1?D:void 0}const tn=12;function Fs(d,D,p){let H=D;if(D.length>tn){const x=D.slice(0,tn-1),E=D.slice(tn-1),V=E.reduce((R,oe)=>R+oe.count,0);H=[...x,{color:b.label,count:V,label:`Other (${E.length} bins)`}]}const O=d.createElement("div");Object.assign(O.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:_.control,overflow:"hidden",border:`1px solid ${b.menuBorder}`,boxSizing:"border-box",marginTop:k.xs,flexShrink:"0"}),O.setAttribute("role","img"),O.setAttribute("aria-label",`Population split: ${H.map(x=>`${x.label} ${wt(x.count/p*100)}`).join(", ")}`);for(const x of H){const E=x.count/p*100,V=d.createElement("div");Object.assign(V.style,{flex:`${E} 1 0`,minWidth:E>0?"2px":"0",background:x.color}),Ut(V,`${x.label} \xB7 ${x.count.toLocaleString()} dies \xB7 ${wt(E)}`),O.appendChild(V)}return O}function wt(d){return d>0&&d<.1?"<0.1%":`${d.toFixed(1)}%`}function vo(d,D,p){const H=new Map;let O=0,x=0;for(const E of d){const V=p?new Set(p(E)):void 0;for(const R of E.dies){if(R.partial||R.edgeExcluded)continue;const oe=D(R);oe!==void 0&&(H.set(oe,(H.get(oe)??0)+1),O++,V&&ds(R,V)&&x++)}}return{counts:H,total:O,pass:x}}function So(d,D){const p=d.ownerDocument.createElement("div");Object.assign(p.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${k.xxs} ${k.xs}`,borderRadius:_.control});const H=d.ownerDocument.createElement("span");Object.assign(H.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:D.color,border:D.isActive?`2px solid ${b.iconActive}`:`1px solid ${b.menuBorder}`,borderRadius:_.control,boxSizing:"border-box"});const O=d.ownerDocument.createElement("span");if(O.textContent=D.label,Object.assign(O.style,{fontWeight:D.isActive?"700":"400",color:D.isActive?b.iconActive:b.text,whiteSpace:"nowrap"}),p.appendChild(H),p.appendChild(O),D.count!==void 0){const x=d.ownerDocument.createElement("span");if(x.textContent=D.count.toLocaleString(),Object.assign(x.style,{color:D.isActive?b.iconActive:b.text,fontWeight:D.isActive?"700":"400",whiteSpace:"nowrap"}),p.appendChild(x),D.percent!==void 0){const E=d.ownerDocument.createElement("span");E.textContent=wt(D.percent),Object.assign(E.style,{color:b.label,whiteSpace:"nowrap"}),p.appendChild(E)}}if(p.setAttribute("role","button"),p.setAttribute("aria-pressed",D.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",x=>D.onClick(x.ctrlKey||x.metaKey)),p.addEventListener("keydown",x=>{if(x.key==="Enter"||x.key===" ")x.preventDefault(),D.onClick(x.ctrlKey||x.metaKey);else if(D.onMenu&&(x.key==="ContextMenu"||x.key==="F10"&&x.shiftKey)){x.preventDefault();const E=p.getBoundingClientRect();D.onMenu({x:E.left+E.width/2,y:E.bottom},p)}}),D.onMenu){const x=D.onMenu;p.addEventListener("contextmenu",E=>{E.preventDefault(),x({x:E.clientX,y:E.clientY},p)}),Ut(p,"Right-click: charts and tables for these dies")}d.appendChild(p)}export function renderWaferGallery(d,D,p={}){ts();const H=6;let O=wo(p.columns);const x=p.showHelpButton??!1,E=p.userGuideExtension,V=p.insights?.enabled??!0,R=gs(p.insights),oe={enabled:!1,plotStore:R},Co=Pi(p.zIndex),be=p.summaryPanel,pe=e=>[...to(e)],nn=()=>M.flatMap(e=>e?[ne(e,"renderWaferGallery")]:[]),vt=()=>nn()[0];function xo(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 z=p.lotStatsSummary,Te=p.viewOptions?.legendPosition??"default",Qe=p.perCardLegend??!1;function Le(){const e=l.plotMode??"hardBin";return io.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 on(){const e=Qe||Le()!==null;for(const t of C)t&&t.setOptions({showLegend:e})}let l={plotMode:"hardBin",showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...p.viewOptions},C=[],ie=[],we=[],B=[];const P=rs(()=>{const e=B.filter(n=>n!=null),t=[...new Set(e.map(n=>ls(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort(Jt);return{prefix:p.downloadFilename,lots:t,...e.length===1?{wafer:ye(e[0])}:{waferCount:e.length}}},p.onSaveImage,p.onSaveText);let M=D.map(e=>typeof e=="function"?null:e);function ve(){return $s(M)}function We(){if(M.some(e=>e?.testDefs?.length))return ve().defs}let Re=0,Je=0;const U=new Map;let Mo=0,$=null,se=null,sn=new Set,w=null,ko={};function an(e){return M[e]?.statsSummary??z?.perWafer.find(t=>t.waferIndex===e)?.summary}function St(){return!!(M.some(e=>e?.statsSummary?.findings.length)||z?.perWafer.some(e=>e.summary.findings.length))}const Do=Fi(),Se=Hi(Do),{makeBtn:ae,setActive:$e,makeSep:Q,makeMenuRow:Bo,makeMenuSection:Eo,makeDropdown:ln,closeOpenMenu:et,getOpenMenu:Ae,setOpenMenu:Ie}=Se;d.ownerDocument.addEventListener("click",et,!0);const rn=()=>so();window.addEventListener("blur",rn);let cn=p.findingsNotice;function dn(e){sn=new Set(e);const t=[...A.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,i)=>{const s=sn.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 un(){dn([])}let tt=!1;function fn(){tt=!0;for(const e of C)e&&e.clearSelection();tt=!1}function pn(e){return t=>{!tt&&se!==null&&(He(),N()),kt.set(e,t.length),J&&!Pe&&!tt&&Oo(e,t),e.onSelect?.(t)}}function le(e,t){e!==void 0&&(C.forEach((n,o)=>{n&&o!==e&&n.locateDie(null)}),C[e]?.locateDie(t),A.querySelectorAll(".wmap-gallery-card")[e]?.scrollIntoView?.({block:"center",behavior:"smooth"}))}let J=!1,Pe=!1,me=new Set;function Oo(e,t){Pe=!0;try{me=new Set(t.map(n=>bt(n))),B.forEach((n,o)=>{const i=C[o];!i||!n||n===e||i.setSelection(n.dies.filter(s=>me.has(bt(s))))})}finally{Pe=!1}lt()}function mn(){me=new Set,Pe=!0;try{for(const e of C)e?.clearSelection()}finally{Pe=!1}lt()}function Ct(){if(!J||me.size===0)return;const e=[];let t=!1;if(B.forEach((i,s)=>{if(!i)return;const a=i.dies.filter(f=>me.has(bt(f)));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:pe(i),ringCount:ne(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?Yt:void 0},ctx:{plots:R,attributes:p.attributes,onSaveImage:P.onSaveImage,onSaveText:P.onSaveText,onLocateDie:(i,s)=>le(s,i)}}}function gn(){const e=[];let t=!1;if(B.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:pe(o),ringCount:ne(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?Yt:void 0},ctx:{plots:R,attributes:p.attributes,onSaveImage:P.onSaveImage,onSaveText:P.onSaveText,onLocateDie:(o,i)=>le(i,o)}}}function To(e){const t=Ct()??bn(e);if(t)return t;const n=gn(),o=n?.source.items.some(i=>i.waferIndex===e);return n&&o?{...n,narrowable:!0}:void 0}function xt(e,t,n){se!==e&&t.click();const o=w;if(!o)return;const i=z?.findings.find(a=>a.id===e),s=Ct()??gn()??Wo()??(i?hn(wn(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 Lo(e,t,n,o){const i=Qt(l.highlightBin),s=i.length>1&&i.includes(t)?[...i]:[t],a=[];let f=!1;B.forEach((g,S)=>{g&&(g.isLotStack&&(f=!0),a.push({label:ye(g)??g.label??`Wafer ${S+1}`,dies:g.dies,waferIndex:S,wafer:g.wafer,passBins:pe(g),ringCount:ne(g,"renderWaferGallery")}))});const r=ve().defs,m=mo(a,e,s,r,void 0,f);if(!m)return;const c={plots:R,attributes:p.attributes,onSaveImage:P.onSaveImage,onSaveText:P.onSaveText,onLocateDie:(g,S)=>le(S,g)},u=s.length>1?mo(a,e,[t],r,void 0,f):null,h=u?{...c,narrower:{label:`Only ${e} bin ${t}`,backLabel:"All filtered bins",source:u,ctx:c}}:c;import("./drilldown.js").then(({openDrilldownMenu:g})=>{o.isConnected&&g(n,o,m,h)})}function hn(e,t=""){const n=[];let o=!1;for(const s of[...e??[]].sort((a,f)=>a-f)){const a=B[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:pe(a),ringCount:ne(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?Yt:void 0},ctx:{plots:R,attributes:p.attributes,onSaveImage:P.onSaveImage,onSaveText:P.onSaveText,onLocateDie:(s,a)=>le(a,s)}}}function Wo(){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:B[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:pe(t),ringCount:ne(t,"renderWaferGallery")}),ctx:{onSaveImage:P.onSaveImage,onSaveText:P.onSaveText,onLocateDie:(i,s)=>le(s??e,i)}}}function Ro(e){e||mn(),J=e,lt()}function Mt(e,t){const n=new Set(e),o=t??C.map((i,s)=>s);for(const i of o){const s=B[i],a=C[i];if(!s||!a)continue;const f=s.dies.filter(r=>n.has(bt(r)));a.setSelection(f)}}const q=new Set,kt=new Map;function yn(){[...A.querySelectorAll(".wmap-gallery-card")].forEach((n,o)=>{n.style.outline=q.has(o)?`2px solid ${b.iconActive}`:"",n.style.outlineOffset=q.has(o)?"-2px":""});const t=q.size;Y.style.display=t>0?"":"none",Y.textContent=`${t} wafer${t===1?"":"s"} picked \u2715`,Y.ariaLabel=`${t} wafer${t===1?"":"s"} picked. Click to clear.`}function $o(e){e<0||(q.has(e)?q.delete(e):q.add(e),yn())}function Ao(){q.clear(),yn()}function bn(e){if(!(q.size===0||!q.has(e))){for(const t of kt.values())if(t>0)return;return hn([...q],"picked ")}}function Io(){const e=[];for(let t=0;t<M.length;t++){const n=M[t];if(!n)continue;const o=an(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 Po(e){const t=B[e]??M[e];t&&Xe(e,t)}function Fo(e){const t=an(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 Ho(){import("../stats/renderSummaryReport.js").then(({renderLotReportHtml:e})=>{ss(e(Os(M,vt())),{anchor:d})})}function jo(){if(!w)return;w.innerHTML="";const e=Io();if(M.length>0){const n=d.ownerDocument.createElement("div"),o=e.length,i=M.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}),w.appendChild(n)}if(e.length>0){const n=d.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...$i("outlined"),marginBottom:k.lg,display:"block",width:"100%",textAlign:"left"}),Xt(n),n.addEventListener("click",Ho),w.appendChild(n)}if(e.length===0){const n=d.ownerDocument.createElement("div");Object.assign(n.style,{color:b.icon,fontSize:j.body,padding:"4px 0"}),n.textContent="No findings on any wafer.",w.appendChild(n)}else for(const{index:n,item:o,unusualCount:i,notableCount:s,totalCount:a}of e){const f=i?"unusual":s?"notable":"info",r=i+s||a,m=d.ownerDocument.createElement("button");m.type="button",Object.assign(m.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:k.xs,border:"none",borderLeft:`3px solid ${oo(f)}`,borderRadius:_.control,background:b.bgHover,cursor:"pointer",fontSize:j.body,textAlign:"left",boxSizing:"border-box"}),m.addEventListener("mouseover",()=>{m.style.background=b.bgActive}),m.addEventListener("mouseout",()=>{m.style.background=b.bgHover});const c=d.ownerDocument.createElement("span");c.textContent=gt(o,n),Object.assign(c.style,{color:b.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const u=d.ownerDocument.createElement("span");u.textContent=String(r),m.setAttribute("aria-label",`${gt(o,n)} \u2014 ${r} finding${r===1?"":"s"}${i?`, ${i} unusual`:""} \u2014 view wafer`),Object.assign(u.style,{marginLeft:k.sm,flexShrink:"0",background:oo(f),color:"#fff",borderRadius:_.container,padding:"1px 5px",fontSize:j.body,fontWeight:"600"}),m.appendChild(c),m.appendChild(u),m.addEventListener("click",()=>Xe(n,o)),w.appendChild(m)}const t=d.ownerDocument.createElement("div");t.style.height="12px",w.appendChild(t)}let Ce=null,Fe=null;function N(){if(w)if(Ce?.cancel(),Ce=null,z){const e=mt(M.map(n=>n?.hbinDefs)),t=mt(M.map(n=>n?.sbinDefs));Ce=Ps(Es(w,{lotSummary:z,items:M,hbinDefs:e.length?e:void 0,sbinDefs:t.length?t:void 0,testDefs:We(),ringCount:vt(),binColors:l.binColors,plotMode:l.plotMode??"hardBin",fallbackFormat:l.fallbackFormat,activeFindingId:se,warnings:p.warnings?.display??!0?re:[],findingsFilter:ko,findingsNotice:cn,onFindingsFilterChange:N,onSaveText:P.onSaveText,onFindingClick:(n,o)=>{se===n.id?He():Vo(n,o),N()},onWaferClick:Po,findingsFor:Fo,dieListOptions:p.dieList,onLocateDie:(n,o)=>le(o,n)}),{onDone:()=>{const n=Fe;Fe=null,n?.()}})}else jo()}function wn(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}let nt=[];function vn(){if(nt.length!==0){for(const e of nt)C[e]?.setOptions({plotMode:l.plotMode,activeTest:l.activeTest});nt=[]}}function He(){se=null,un(),fn(),vn(),I({highlightBin:void 0},{fireCallback:!1})}function Sn(){se!==null&&(He(),N())}function Vo(e,t){if(se===e.id){He();return}se=e.id,t.style.background=b.bgActive,t.style.fontWeight="600",vn();const{kind:n,index:o}=e.variable;if(n==="test"){const s=o??0,a=We();if(a===void 0||a.some(r=>r.testNumber===s))I({plotMode:"value",activeTest:s,highlightBin:void 0},{fireCallback:!1});else{I({highlightBin:void 0},{fireCallback:!1});const m=Oe.has(l.plotMode??"hardBin")?null:wn(e);if(m){for(const c of m)C[c]?.setOptions({plotMode:"value",activeTest:s});nt=[...m]}}}else I({plotMode:n==="softBin"?"softBin":"hardBin",highlightBin:bs(e)},{fireCallback:!1});un(),fn();const i=e.highlight;if(i.kind==="wafer"){dn(i.waferIndices);const s=go(e);for(const a of i.waferIndices){const f=i.dieKeysByWafer?void 0:B[a]?.statsSummary?.findings.find(m=>go(m)===s),r=i.dieKeysByWafer?.[a]??f?.highlight?.dieKeys;r?.length&&Mt(r,[a])}}else i.kind==="bin"?i.dieKeys?.length&&Mt(i.dieKeys):(i.kind==="region"||i.kind==="dies")&&i.dieKeys?.length&&Mt(i.dieKeys)}let ot=null;function Cn(){if(!ot)return;const e=w?w.style.display!=="none":!0,t=!!$&&$.style.display!=="none",n=!!(z?.hasNotableFindings||M.some(o=>o?.statsSummary?.hasNotableFindings));ot.sync(t&&!e,n)}function ge(){if(!$)return;const e=!!w;$.style.display=(z||St())&&e&&!ct?"flex":"none";const t=w?w.style.display!=="none":!1;(z?.hasNotableFindings||M.some(o=>o?.statsSummary?.hasNotableFindings))&&!t?$.style.color=b.findingIndicator:$.dataset.active||($.style.color=b.icon),Cn()}const G=d.ownerDocument.createElement("div");G.dataset.wmapToolbar="gallery",Object.assign(G.style,{flexShrink:"0",marginLeft:"auto",display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:_.control,padding:"0",boxShadow:qt.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const xn=()=>{const e=Ae();e&&(e.remove(),Ie(null)),Ze(ee,!1)},ee=ae("mode","Plot mode",()=>{if(Ae()){xn();return}const e=M.flatMap(v=>v?.dies??[]),t=We(),{testEntries:n,binEntries:o,stackedEntries:i}=ns(e,t,{includeStacked:!0}),s=M.filter(Boolean).length,a=v=>{if(v===void 0)return s;let L=0;for(const W of M)W?.dies?.some(F=>ho(F,v)!==void 0||Is(F,v)!==void 0)&&L++;return L},f=s<2?n:n.map(v=>{const L=a(v.activeTest);return L===s?v:{...v,label:`${v.label} \u2014 ${L} of ${s} wafers`}}),r=l.plotMode??"hardBin",m=l.activeTest??0;function c(v){return v.plotMode!==r?!1:v.plotMode==="value"?m===(v.activeTest??0):v.plotMode==="metadata"?l.activeMetadataKey===v.activeMetadataKey:!0}function u(v,L){v.activeTest!==void 0?I({plotMode:"value",activeTest:v.activeTest,activeMetadataKey:void 0,logScale:v.logScale}):v.activeMetadataKey!==void 0?I({plotMode:v.plotMode,activeTest:void 0,activeMetadataKey:v.activeMetadataKey,passFailDisplay:"off"}):I({plotMode:v.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),L.remove(),Ie(null),Ze(ee,!1)}const h=new Set,g=M.flatMap(v=>v?.metadataFields??[]).filter(v=>!h.has(v.key)&&h.add(v.key)).filter(v=>os(e,v.key)).map(is),S=ji(ee.getBoundingClientRect(),f,o,i,c,u,{makeMenuRow:Bo,makeMenuSection:Eo},r,ee.ownerDocument.defaultView??window,g);ao(ee).appendChild(S),Ie(S),Ze(ee,!0),lo(S,ee,xn)});Ze(ee,!1);const zo=()=>B.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:No,sync:Mn}=_i(Se,()=>({...l,plotMode:l.plotMode??"hardBin"}),zo,e=>I(e));Mn();const Go=D.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function it(){const e=We(),{testNumber:t}=Si(l.activeTest??0,e);return{testNumber:t,td:Ci(e,t)}}function kn(){if((l.plotMode??"hardBin")!=="value")return!1;const{td:e}=it();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function je(){if((l.plotMode??"hardBin")!=="value")return!1;const{td:e}=it();return e!==void 0&&!Zt(e)}function Ko(){if((l.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=it();return M.some(n=>n?.dies?.some(o=>ho(o,e,t)!==void 0))}function _o(e,t){if(!t||!Zt(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((ro(l)==="spec"&&n?"spec":l.colorbarRangeMode??"spec")==="spec"&&n)return;let s=1/0,a=-1/0;for(const f of M)if(f)for(const r of f.dies){const m=vs(r,e);m!==void 0&&(m<s&&(s=m),m>a&&(a=m))}if(isFinite(s))return s===a?[s,s+1]:[s,a]}function st(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 Dn(){if((l.plotMode??"hardBin")!=="metadata")return;const e=l.activeMetadataKey;if(!e)return;const t=new Set;for(const n of M)if(n)for(const o of xi(n.dies,e))t.add(o);return{key:e,values:[...t].sort(Jt)}}function Dt(){st("metadataValueOrder",Dn(),(e,t)=>e.key===t.key&&yt(e.values,t.values))}function Bt(){if((l.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=it(),n=_o(e,t);st("valueRange",n?{test:e,range:n}:void 0,(i,s)=>{const a=m=>Array.isArray(m)?{test:void 0,range:m}:{test:m.test,range:m.range},f=a(i),r=a(s);return f.test===r.test&&yt(f.range,r.range)})}let Et=!1;function qo(){if(Et)return;Et=!0,(d.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{Et=!1,Bt(),Dt(),Tn(),On()})}let Ot=!1;function Xo(){if(Ot)return;Ot=!0,(d.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{Ot=!1,ft()})}let Bn=[];function xe(){const{colors:e,mixedHardBins:t}=ki(M.filter(n=>n!=null),{binColorScheme:l.binColorScheme,useDefinedBinColors:l.useDefinedBinColors});return Bn=t,e}function Tt(){return B.filter(e=>e!=null).flatMap(e=>e.dies)}function En(){return l.compact?Ms(Tt()):void 0}const Uo=(e,t)=>yt(e.columns,t.columns)&&yt(e.rows,t.rows);function On(){st("compactMap",En(),Uo)&&Nn()}function Yo(){return ks(Tt(),B.filter(e=>e!=null).map(e=>e.reticleConfig))}function Tn(){st("binColors",xe(),Ei),ze()}const Zo=Ui(Se,()=>Qi(l,Go,{functionalActive:je(),hasLimits:kn()&&!je(),hasRecorded:Ko()&&!je(),binMode:(l.plotMode??"hardBin")==="hardBin"||(l.plotMode??"hardBin")==="softBin"},e=>I(e),{on:!!l.compact,offered:Yo(),onChange:e=>I({compact:e}),onDiagnostics:()=>es(Tt(),B.filter(e=>e!=null).map(e=>e.reticleConfig),{anchor:d,onSaveText:P.onSaveText})}),()=>Ji(l)),{btn:Qo,sync:Ln}=Xi(Se,()=>({plotMode:l.plotMode,legendPosition:Te}),e=>{Te=e;for(const t of C)t&&t.setOptions({legendPosition:Te})},{get:()=>Qe,set:e=>{Qe=e,on()},blockedReason:Le});Ln();const Jo=[{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"}],Wn=ln("aggr","Aggregation method",()=>Jo,()=>l.aggregationMethod??"mean",e=>I({aggregationMethod:e}));function Rn(){const e=l.plotMode==="stackedValues";Wn.style.display=e?"":"none"}Rn();const{btn:ei,sync:$n}=qi(Se,()=>({...l,functionalActive:je()}),e=>I(e));$n();const at=ae("specRange","Colorbar range: test limits",()=>{const e=l.colorbarRangeMode==="data"?"spec":"data";I({colorbarRangeMode:e})});function An(){const e=(l.plotMode??"hardBin")==="value"&&kn()&&ro(l)==="off"&&!je();at.style.display=e?"":"none";const t=(l.colorbarRangeMode??"spec")==="spec";$e(at,t),at.ariaLabel=t?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"}An();const ti=Yi(Se,()=>l,e=>I(e)),ni=ae("downloadAll","Download gallery PNG",gi),Me=ae("boxSelect","Select the same dies on every wafer",()=>{J&&me.size>0?mn():Ro(!J)});Me.style.position="relative";const Ve=d.ownerDocument.createElement("span");Ve.dataset.wmapSelectAcrossCount="1",Object.assign(Ve.style,{position:"absolute",top:"0",right:"0",minWidth:"14px",height:"14px",boxSizing:"border-box",padding:"0 3px",borderRadius:_.pill,background:b.iconActive,color:b.menuBg,fontSize:"11px",lineHeight:"14px",fontWeight:"700",textAlign:"center",pointerEvents:"none",display:"none"}),Me.appendChild(Ve);function lt(){$e(Me,J);const e=J?me.size:0;Ve.style.display=e>0?"block":"none",Ve.textContent=e>99?"99+":String(e),Me.ariaLabel=J?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)",Me.setAttribute("aria-pressed",String(J))}const Y=d.ownerDocument.createElement("button");Y.type="button",Y.dataset.wmapPickedWafers="1",Object.assign(Y.style,{display:"none",border:"none",background:b.bgActive,color:b.iconActive,borderRadius:_.control,padding:`${k.xs} ${k.md}`,fontSize:j.body,cursor:"pointer",whiteSpace:"nowrap",flexShrink:"0"}),Xt(Y,"bare"),Y.addEventListener("click",Ao);const oi=ln("columns","Columns",()=>[{value:"auto",label:"Auto"},{value:"1",label:"1 column"},{value:"2",label:"2 columns"},{value:"3",label:"3 columns"},{value:"4",label:"4 columns"},{value:"5",label:"5 columns"}],()=>O!=null?String(O):"auto",e=>Kn(e==="auto"?void 0:Number(e))),T=d.ownerDocument.createElement("div");Object.assign(T.style,{display:"inline-flex",alignItems:"center",gap:"0"}),G.appendChild(T),T.appendChild(ee),T.appendChild(No),T.appendChild(Wn),T.appendChild(ei),T.appendChild(at),T.appendChild(Q()),T.appendChild(Zo),T.appendChild(Q()),T.appendChild(Qo),T.appendChild(Q()),T.appendChild(ti),T.appendChild(Q()),T.appendChild(oi),T.appendChild(Q()),T.appendChild(Me),T.appendChild(Y),T.appendChild(ni),lt(),(z||St())&&($=ae("findings","Summary panel",()=>{if(!w)return;const e=w.style.display!=="none";e||N(),w.style.display=e?"none":"flex",$e($,!e),ge()}),G.appendChild(Q()),G.appendChild($));let Z=null,rt=null,re=[],In=!1;function ze(){const e=Ss({lotStatsSummary:z,result:{warnings:[...M.flatMap(n=>n?.warnings??[]),...ve().warnings]},extra:[l.binColors&&Di(l.binColors,l.plotMode),Bi(Bn),xo(nn())].filter(n=>!!n)}),t=e.length!==re.length||e.some((n,o)=>n.code!==re[o]?.code||n.message!==re[o]?.message);re=e,(t||!In)&&(In=!0,p.warnings?.onWarning?.(e)),ii()}function ii(){if(!Z||!rt)return;const e=re.length,t=e>0;if(Z.style.display=t?"flex":"none",rt.style.display=t?"":"none",!t)return;const n=xs(re[0]),o=`${e} data ${e===1?"warning":"warnings"}`;Z.style.color=n==="error"?b.errText:b.warnText,Z.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(p.warnings?.display??!0)&&(rt=Q(),Z=ae("warning","Data warnings",()=>{const e=Ae();if(et(new MouseEvent("click")),e)return;const t=Cs(Z.getBoundingClientRect(),re,Z.ownerDocument.defaultView??window);ao(d).appendChild(t),Ie(t),lo(t,Z,()=>et(new MouseEvent("click")))}),Ze(Z,!1),G.appendChild(rt),G.appendChild(Z)),ze();function Pn(){import("./userGuideHtml.js").then(e=>as({buildWaferMap:ws,renderWaferMap:fs,renderWaferGallery,analyzeWaferMap:ht},e.USER_GUIDE_HTML,E,d))}x&&(G.appendChild(Q()),G.appendChild(ae("help","User guide",()=>Pn())));const ke=d.ownerDocument.createElement("div");ke.dataset.wmapGalleryMeta="1",Object.assign(ke.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${k.sm} ${k.lg}`,fontSize:j.sub,lineHeight:no.none,boxSizing:"border-box"});const Ne=d.ownerDocument.createElement("div");Object.assign(Ne.style,{background:b.canvasBg,display:"flex",alignItems:"stretch",gap:k.lg,paddingBottom:k.lg,minWidth:"0"});const ce=d.ownerDocument.createElement("div");ce.dataset.wmapGalleryLegend="1",Object.assign(ce.style,{display:"flex",flexDirection:"column",gap:k.sm,background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:_.container,padding:`${k.sm} ${k.lg}`,marginBottom:k.lg,boxShadow:qt.panel,fontSize:j.body,lineHeight:no.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const X=d.ownerDocument.createElement("div");Object.assign(X.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let De=null,Ge=null,Fn=null;function si(){return V?De?Promise.resolve(De):(Fn??=import("./insightsTab.js").then(({createInsightsTab:e})=>(De=e({attributes:p.attributes,getItems:()=>M,getLotStats:()=>z,getBinColors:()=>l.binColors??xe(),getRingCount:()=>ne({ringCount:vt()},"the Insights tab"),defaultView:p.insights?.defaultView,plotStore:R,onPickPlotsFile:p.insights?.onPickPlotsFile,onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:P.onSaveImage,onSaveText:P.onSaveText,ownerDocument:d.ownerDocument,locateDie:(t,n)=>{Wt(!1),le(n,t)},openWafer:(t,n,o)=>{const i=M[t];if(!i)return;let s=null;const a=Ni({title:n,onClose:()=>s?.destroy(),anchor:d});Xn(a,n,i.wafer.metadata??void 0),s=Vt(a.contentWrap,i,o,void 0,co(a))}}),Ge=De.el,Ge.style.display="none",d.appendChild(Ge),De)),Fn):Promise.resolve(null)}let ct=!1,Lt=null;function Wt(e){V&&(ct=e,Lt?.setInsightsOpen(e),Ge&&(Ge.style.display=e?"flex":"none"),X.style.display=e?"none":"flex",T.style.display=e?"none":"inline-flex",G.style.display="inline-flex",ge(),ft(),e&&si().then(t=>{!t||!ct||(t.el.style.display="flex",t.render())}))}V&&p.insights?.defaultOpen&&queueMicrotask(()=>Wt(!0));const Hn=4,dt=240,Rt=480,ai=720,li=1.25;let he=Rt;function jn(e){const t=H*2+110+2,n=Vn();if(n)return Math.ceil(n.across*Hn+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*(Hn/s),f=Math.ceil(a+t);(o==null||f>o)&&(o=f)}return o}function ri(e){const t=jn(e);return t==null?dt:Math.min(he,Math.max(dt,t))}function ci(e){const t=jn(e);if(t==null)return!1;const n=Math.min(ai,Math.max(Rt,t));return n<=he?!1:(he=n,!0)}function Vn(){const e=l.compact?l.compactMap:void 0,t=B.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 zn(e,t){const n=Vn();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 di(){for(const e of ie)e?.parentElement&&zn(e.parentElement,e)}function Nn(){he=Rt,Ke=dt,It(B.map(e=>e??null)),At(),di()}function $t(){return O!=null?"none":`${he}px`}function At(){const e=$t();for(const t of Array.from(A.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let Ke=dt,Gn=0;function It(e){if(ci(e)&&At(),O==null){const n=ri(e);n>Ke&&(Ke=n)}Ft()}function Kn(e){O=wo(e),At(),Ft()}function Pt(e){return`repeat(${e}, minmax(0, ${O!=null?"1fr":`${he}px`}))`}function _n(e){A.style.gridTemplateColumns!==e&&(A.style.gridTemplateColumns=e)}function Ft(){if(O!=null){_n(Pt(O));return}const e=Math.max(1,Gn),t=12,n=A.clientWidth||0,o=s=>(n-t*(s-1))/s;let i=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const s=Math.min(he,Ke*li),a=f=>{let r=0;for(;r<e&&o(r+1)>=f;)r++;return r};i=a(s)||a(Ke)||1}_n(Pt(i))}const A=d.ownerDocument.createElement("div");if(Object.assign(A.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:Pt(1),gap:k.xl,paddingLeft:fe,paddingRight:fe,justifyContent:"start",alignContent:"start",isolation:"isolate"}),be?.placement){const e=be.placement;w=en(e,fe,d.ownerDocument,xt),w.style.maxHeight="calc(100vh - 80px)",w.style.position="sticky",w.style.top="8px",w.style.display="flex",w.style.flexDirection="column"}else if(z||St()){const e=!!be?.defaultOpen;w=en("right",fe,d.ownerDocument,xt),w.style.maxHeight="calc(100vh - 80px)",w.style.position="sticky",w.style.top="8px",w.style.flexDirection="column",w.style.display=e?"flex":"none",N()}ge(),w?.style.display!=="none"&&$&&$e($,!0);const ut=be?.placement??"right";ut==="left"?(w&&X.appendChild(w),X.appendChild(A)):(X.appendChild(A),w&&X.appendChild(w)),(ut==="left"||ut==="right")&&(ot=wi(d.ownerDocument,ut,()=>$?.click()),X.appendChild(ot.el),Cn());const _e=d.ownerDocument.createElement("div");Object.assign(_e.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:fe,paddingRight:fe,paddingTop:fe,zIndex:"1",background:b.menuBg}),Ne.appendChild(ke),Ne.appendChild(G),V&&(Lt=bi(d.ownerDocument,"Maps","lot",e=>Wt(e)),Ne.appendChild(Lt.el)),_e.appendChild(Ne),_e.appendChild(ce),d.appendChild(_e),d.appendChild(X);function ft(){ce.innerHTML="";const e=l.plotMode??"hardBin",t=!ct&&io.has(e),n=B.filter(y=>y!=null),o=n.find(y=>y.isLotStack),i=Ds(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,f=t&&!s?vo(n,y=>(e==="softBin"?y.sbin:y.hbin)??void 0,pe):{counts:new Map,total:0,pass:0},r=t&&!s?l.binColors??xe():void 0,m=r?e==="softBin"?r.pass.soft:r.pass.hard:new Set,c=cs(f.counts.entries(),m).map(([y])=>y),u=t&&s&&a?vo(n,y=>Mi(y.metadata?.[a])):{counts:new Map,total:0,pass:0},h=s?Dn()?.values:void 0,g=t&&s?(h??[...u.counts.keys()].sort(Jt)).filter(y=>u.counts.has(y)):[];if(ke.innerHTML="",i&&ke.appendChild(i),ke.style.display=i?"flex":"none",!c.length&&!g.length){ce.style.display="none";return}ce.style.display="flex";const S=d.ownerDocument.createElement("div");Object.assign(S.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${k.sm} ${k.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),ce.appendChild(S);const v=Qt(l.highlightBin),L=B.flatMap(y=>y?.metadataFields??[]).find(y=>y.key===a),W=s?L?.label??(a?Ts(a):"Metadata"):Ii[e],F=d.ownerDocument.createElement("span");if(F.textContent=W,Object.assign(F.style,{fontSize:j.body,fontWeight:"700",letterSpacing:Ri,textTransform:"uppercase",color:b.label,flexShrink:"0"}),S.appendChild(F),!s&&f.total>0){const y=f.pass,K=y/f.total*100,de=d.ownerDocument.createElement("span");de.textContent=`Yield ${wt(K)}`,Object.assign(de.style,{fontSize:j.body,fontWeight:"700",color:b.value,whiteSpace:"nowrap",flexShrink:"0"});const ue=d.ownerDocument.createElement("span");ue.textContent=`${y.toLocaleString()} / ${f.total.toLocaleString()} dies`,Object.assign(ue.style,{fontSize:j.body,color:b.label,whiteSpace:"nowrap",flexShrink:"0"}),S.appendChild(de),S.appendChild(ue)}if(s){const y=Qt(l.highlightMetadataValue);g.forEach((K,de)=>{const ue=y.includes(K),Ee=L?.values?.find(Kt=>Kt.value===K),Ye=Ee?.color??Li(de),eo=u.counts.get(K)??0;So(S,{color:Ye,isActive:ue,label:Ee?.label??K,count:eo,percent:u.total>0?eo/u.total*100:void 0,onClick:Kt=>{const yi=yo(l.highlightMetadataValue,K,Kt);Sn(),I({highlightMetadataValue:yi})}})});return}const Ue=e==="softBin"?B.flatMap(y=>y?.sbinDefs??[]):B.flatMap(y=>y?.hbinDefs??[]),Zn=new Set,Nt=[];for(const y of Ue)Zn.has(y.bin)||(Zn.add(y.bin),Nt.push(y));const Gt=Nt.length>0?new Map(Nt.map(y=>[y.bin,y])):null,Qn=r??l.binColors??xe(),hi=e==="softBin"?Qn.soft:Qn.hard,Jn=y=>hi.get(y)??Ti;for(const y of c){const K=v.includes(y),de=Gt?.get(y),ue=f.counts.get(y)??0;So(S,{color:Jn(y),isActive:K,label:de?.name?`${y} \xB7 ${de.name}`:`Bin ${y}`,count:ue,percent:f.total>0?ue/f.total*100:void 0,onMenu:(Ee,Ye)=>Lo(e==="softBin"?"soft":"hard",y,Ee,Ye),onClick:Ee=>{const Ye=yo(l.highlightBin,y,Ee);Sn(),I({highlightBin:Ye})}})}f.total>0&&c.length>1&&ce.appendChild(Fs(d.ownerDocument,[...f.counts.entries()].sort(([,y],[,K])=>K-y).map(([y,K])=>({color:Jn(y),count:K,label:Gt?.get(y)?.name?`${y} \xB7 ${Gt.get(y).name}`:`Bin ${y}`})),f.total))}function qe(e){const t=M.filter(c=>c!==null);if(!t.length)return[];const n=t.map(c=>c.dies.filter(As)),o=t[0].wafer,i=t.length,s=Oi(t.map(c=>to(c)));if(!s)return[];const a=new Set(t.map(c=>ne(c,"renderWaferGallery")));if(a.size!==1)return[];const f=[...a][0],r=o.metadata?{...o,metadata:(({wafer:c,waferId:u,...h})=>h)(o.metadata)}:o;function m(c,u){return{...c,stats:{...c.stats,isLotStack:!0,aggregationMethod:u,lotSize:i}}}if(e==="stackedValues"){const c=We();let u=c?.filter(Zt);if(c!==void 0&&u?.length===0)return[];if(c?.length||(u=vi(t.flatMap(S=>S.dies)).map(S=>({testNumber:S,name:Ls(void 0,S)}))),!u?.length)return[];const h=l.aggregationMethod??"mean";return u.map(g=>{const S=us(n,h,g.testNumber),v={testNumber:0,name:g.name,unit:g.unit,...Rs(g)};return{wafer:r,dies:S,passBins:[...s],ringCount:f,testDefs:[v],label:`${Ws(g,g.testNumber)} \xB7 ${h}`,isLotStack:!0,aggrMethod:h,lotSize:i,statsSummary:m(ht({wafer:r,dies:S,passBins:[...s],ringCount:f,testDefs:[v]},{testNumbers:[0]}),h)}})}if(e==="stackedBins"){let c=mt(t.map(u=>u?.hbinDefs));return(!c||c.length===0)&&(c=[...new Set(t.flatMap(h=>h.dies.map(g=>g.hbin).filter(g=>g!=null)))].sort((h,g)=>h-g).map(h=>({bin:h,name:`Bin ${h}`}))),c.map(u=>{const h=uo(n,u.bin,"hard"),g=[{bin:u.bin,name:u.name}];return{wafer:r,dies:h,passBins:[...s],ringCount:f,hbinDefs:g,label:`${u.bin} \xB7 ${u.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:m(ht({wafer:r,dies:h,passBins:[...s],ringCount:f,hbinDefs:g}),"countBin")}})}if(e==="stackedSoftBins"){let c=mt(t.map(u=>u?.sbinDefs));return(!c||c.length===0)&&(c=[...new Set(t.flatMap(h=>h.dies.map(g=>g.sbin).filter(g=>g!=null)))].sort((h,g)=>h-g).map(h=>({bin:h,name:`Bin ${h}`}))),c.map(u=>{const h=uo(n,u.bin,"soft"),g=[{bin:u.bin,name:u.name}];return{wafer:r,dies:h,passBins:[...s],ringCount:f,sbinDefs:g,label:`${u.bin} \xB7 ${u.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:m(ht({wafer:r,dies:h,passBins:[...s],ringCount:f,sbinDefs:g}),"countBin")}})}return t}function Ht(e){const t=M.length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:l.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}function I(e,{fireCallback:t=!0}={}){const n=Object.keys(e),o=l.plotMode,i=Le()!==null;l={...l,...e};const s=l.plotMode,a=Oe.has(s),f=o!==void 0&&Oe.has(o),r=Je>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const c=xe();l={...l,binColors:c},e={...e,binColors:c}}if("compact"in e){const c=En();l={...l,compactMap:c},e={...e,compactMap:c}}if(("compact"in e||l.compact&&("rotation"in e||"showXYIndicator"in e))&&Nn(),e.plotMode!==void 0)if(a){const c=Ht(s);if(l={...l,...c},r)for(const u of C)u&&u.setOptions(e);else te(qe(s))}else if(f){const{valueRange:c,lotSize:u,aggregationMethod:h,...g}=l;if(l=g,r)for(const S of C)S&&S.setOptions(e);else te(M.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 te(qe("stackedValues"));else for(const c of C)c&&c.setOptions(e);Le()!==null!==i&&on(),ft(),Rn(),Ln(),Mn();const m=e.plotMode!==void 0&&e.plotMode!==o;(ys.some(c=>c in e)||m)&&N(),ze(),$n(),An(),Bt(),Dt(),t&&p.onViewOptionsChange?.(po(l),n,hs(n))}function qn(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 Xn(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]");if(!o||Bs(n??{}).length===0)return;const i=o.parentElement,s=d.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(d.ownerDocument,s,t,n,p.attributes);a&&(e.contentWrap.style.position="relative",e.contentWrap.appendChild(a))}function jt(e,t,n){const o=d.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:_.container,boxShadow:qt.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:$t(),maxHeight:$t()});const i=d.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}=qn(document,gt(e,t),e.wafer.metadata??void 0);i.appendChild(s);const f=d.ownerDocument.createElement("button");f.dataset.wmapExpandBtn="1",f.setAttribute("aria-label","Open full view"),Ut(f),f.innerHTML=_t.expand,Object.assign(f.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${b.menuBorder}`,borderRadius:_.control,background:b.panelBg,color:b.label,padding:k.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),Xt(f),i.appendChild(f),i.addEventListener("click",h=>{(h.ctrlKey||h.metaKey)&&(h.preventDefault(),h.stopPropagation(),$o(B.indexOf(e)))},!0),o.appendChild(i);const r=d.ownerDocument.createElement("div");Object.assign(r.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(r),zn(o,r),a&&r.appendChild(a),A.appendChild(o),o.addEventListener("contextmenu",h=>{if(h.defaultPrevented)return;h.preventDefault();const g=e.viewOptions?{...l,...e.viewOptions}:l,S=Ct()??bn(t),v=S?.source??ps(e.dies,{waferLabel:ye(e),testDefs:e.testDefs,isLotStack:e.isLotStack,activeTest:g.plotMode==="value"?g.activeTest:void 0,waferIndex:t,wafer:e.wafer,passBins:pe(e),ringCount:ne(e,"renderWaferGallery")}),L={x:h.clientX,y:h.clientY};import("./drilldown.js").then(({openDrilldownMenu:W})=>{o.isConnected&&W(L,o,v,S?{plots:R,attributes:p.attributes,...S.ctx}:{plots:R,attributes:p.attributes,onSaveImage:u.getSaveImageHook(),onSaveText:u.getSaveTextHook(),onLocateDie:F=>le(t,F)})})});const m=Qe||Le()!==null,c=e.viewOptions?{...l,...e.viewOptions}:l,u=fo(r,e,{viewOptions:{...c,showLegend:m,legendPosition:Te},showTooltip:!0,padding:H,statsSummary:e.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,downloadFilename:p.downloadFilename,onClick:e.onClick,onSelect:pn(e),drilldownSourceOverride:()=>To(t),insights:oe,onExpand:()=>Xe(t,e),showIdentity:!1,chromeInset:Ai,drawWhenVisible:!0});return u.setViewControlsVisible(!1),u.setSummaryVisible(!1),f.onclick=()=>Xe(t,e),{card:o,ctrl:u,canvasWrapper:r,expandBtn:f}}function ui(e){const t=we[e];if(!t)return;const n=[...U.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=_t.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>pi(n.id)):(t.innerHTML=_t.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>Xe(e,B[e]))}function te(e){mi(),Ae()?.remove(),Ie(null),He(),B=[],q.clear(),kt.clear(),Y.style.display="none";for(const r of C)r&&r.destroy();C=[],ie=[],we=[],Je=0,A.innerHTML="",Gn=e.length,It(e.map(r=>typeof r=="function"?null:r));const t=[];for(let r=0;r<e.length;r++){const m=e[r];if(typeof m=="function"){const c=d.ownerDocument.createElement("div");c.className="wmap-gallery-card",Object.assign(c.style,{background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:_.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const u=d.ownerDocument.createElement("span");u.textContent="\u2026",Object.assign(u.style,{color:b.label,fontSize:"18px"}),c.appendChild(u),A.appendChild(c),B.push(null),C.push(null),ie.push(null),we.push(null),t.push({index:r,factory:m,placeholder:c}),Je++}else{const{ctrl:c,canvasWrapper:u,expandBtn:h}=jt(m,r,e.length);B.push(m),C.push(c),ie.push(u),we.push(h)}}Tn(),ft(),Bt(),Dt(),On();const n=++Re,o=()=>{setTimeout(()=>{n===Re&&p.onItemsResolved?.()},0)},i=r=>{setTimeout(()=>{n===Re&&p.onItemResolved?.(r,e.length)},0)};let s=e.length-t.length;s>0&&i(s);let a=0;function f(){if(n!==Re)return;if(a>=t.length){if(Oe.has(l.plotMode)){const L=l.plotMode;te(qe(L));return}Fe=o,N(),Ce||(Fe=null,o());return}const{index:r,factory:m,placeholder:c}=t[a++],u=m();B[r]=u,M[r]=u,It([u]);const{card:h,ctrl:g,canvasWrapper:S,expandBtn:v}=jt(u,r,e.length);C[r]=g,ie[r]=S,we[r]=v,Je--,c.replaceWith(h),i(++s),Xo(),qo(),!w&&!be?.placement&&u.statsSummary?.findings.length&&(w=en("right",fe,d.ownerDocument,xt),w.style.maxHeight="calc(100vh - 80px)",w.style.position="sticky",w.style.top="8px",w.style.flexDirection="column",w.style.display="none",(be?.placement??"right")==="left"?X.insertBefore(w,A):X.appendChild(w),N(),$||($=ae("findings","Summary panel",()=>{if(!w)return;const W=w.style.display!=="none";W||N(),w.style.display=W?"none":"flex",$e($,!W),ge()}),G.appendChild(Q()),G.appendChild($)),ge()),ge(),setTimeout(f,0)}t.length>0?setTimeout(f,0):o()}if(Oe.has(l.plotMode)&&M.length>0){const e=Ht(l.plotMode);l={...l,...e},te(qe(l.plotMode))}else te(D);ze();let Be=0;const Un=new(d.ownerDocument.defaultView??window).ResizeObserver(()=>{if(Be)return;Be=(d.ownerDocument.defaultView??window).requestAnimationFrame(()=>{Be=0,O==null&&Ft()})});Un.observe(A),w&&N();function fi(e,t){const n=ie[e];if(!n)return;n.innerHTML="",Object.assign(n.style,{alignItems:"center",justifyContent:"center"});const o=d.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 U.values())if(a.cardIndex===e)return;const n=gt(t,e),o=Mo++,i=C[e]?.getOptions(),s=Vi(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}),Gi(d,a.documentElement);const f=Ki(d,a.documentElement,()=>v.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 m=a.createElement("div");Object.assign(m.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),a.body.appendChild(m);const{wrap:c,metaPanel:u}=qn(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),m.appendChild(h);const g=a.createElement("div");Object.assign(g.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),u&&g.appendChild(u),m.appendChild(g);let S=0;const v=Vt(g,t,void 0,i,(W,F)=>{const Ue=W?F:-S;try{s.resizeBy(Ue,0),S=W?F:0}catch{}}),L=setInterval(()=>{s.closed&&pt(o)},400);s.addEventListener("pagehide",()=>pt(o)),U.set(o,{id:o,ctrl:v,cardIndex:e,label:n,closePollId:L,stopThemeSync:f,close:()=>{s.closed||s.close()},setTitle:W=>{a.title=W,r.textContent=W,r.style.display="block"}})}else{const a=zi({title:n,onClose:()=>pt(o),anchor:d});a.contentWrap.style.flexDirection="column",Xn(a,n,t.wafer.metadata??void 0);const f=Vt(a.contentWrap,t,void 0,i,co(a));U.set(o,{id:o,ctrl:f,cardIndex:e,label:n,closePollId:null,close:()=>a.close(),setTitle:r=>{const m=a.box.querySelector("[data-wmap-window-title]");m&&(m.textContent=r,m.title=r)}})}C[e]?.destroy(),C[e]=null,fi(e,s!==null),ui(e)}function Vt(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:Te},m=fo(e,t,{viewOptions:r,showTooltip:!0,padding:H,statsSummary:t.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,downloadFilename:p.downloadFilename,onClick:t.onClick,onSelect:pn(t),insights:oe,showExpandButton:!1,onSummaryPanelChange:i,showIdentity:!1});return m.setViewControlsVisible(!0),m.setSummaryVisible(!0),m.setExpandVisible(!1),m}function pt(e){const t=U.get(e);if(!t||(U.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.(),t.ctrl.destroy(),t.cardIndex===null))return;const n=t.cardIndex,o=B[n];if(!o)return;const{card:i,ctrl:s,canvasWrapper:a,expandBtn:f}=jt(o,n,B.length);ie[n]?.parentElement?.replaceWith(i),C[n]=s,ie[n]=a,we[n]=f}function pi(e){const t=U.get(e);t&&(t.close(),pt(e))}function mi(){for(const e of U.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function zt(){for(const e of C)e?.drawPendingNow()}const Yn=d.ownerDocument.defaultView??window;Yn.addEventListener("beforeprint",zt);function gi(){zt();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,f=(d.ownerDocument.defaultView??window).devicePixelRatio||1,r=Math.round(26*f),m=Math.round(12*f),c=d.ownerDocument.createElement("canvas");c.width=n*i+(n-1)*a,c.height=o*(s+r)+(o-1)*a;const u=c.getContext("2d"),h=Wi(A);u.fillStyle=h.background,u.fillRect(0,0,c.width,c.height),e.forEach((g,S)=>{const v=S%n,L=Math.floor(S/n),W=v*(i+a),F=L*(s+r+a),Ue=g.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";u.fillStyle=h.surface,u.fillRect(W,F,i,r),u.fillStyle=h.text,u.font=`700 ${m}px system-ui, sans-serif`,u.textAlign="left",u.textBaseline="middle",u.fillText(Ue,W+Math.round(10*f),F+r/2,i-Math.round(20*f)),u.drawImage(g,W,F+r)}),c.toBlob(g=>{if(!g)return;const S=C.find(v=>v!=null)?.getExportTitle();Zi(g,["gallery",S].filter(Boolean).join(" "),P.onSaveImage)})}return{setItems(e){M=e.map(n=>typeof n=="function"?null:n);const t=l.plotMode;if(Oe.has(t))if(e.some(o=>typeof o=="function"))te(e);else{const o=Ht(t);l={...l,...o},te(qe(t))}else te(e)},setOptions(e){I(e,{fireCallback:!1})},getOptions(){return po(l)},setFindingsNotice(e){cn=e,N()},setColumns(e){Kn(e)},getBinColors(){return l.binColors??xe()},setLotStatsSummary(e){z=e,ze(),w&&N(),ge()},openUserGuide:Pn,destroy(){R.flush(),Re++,Yn.removeEventListener("beforeprint",zt),Ce?.cancel(),Ce=null,Fe=null;for(const e of[...U.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();U.clear();for(const e of C)e&&e.destroy();C=[],Ae()?.remove(),Un.disconnect(),Be&&((d.ownerDocument.defaultView??window).cancelAnimationFrame(Be),Be=0),d.ownerDocument.removeEventListener("click",et,!0),window.removeEventListener("blur",rn),Co(),so(),_e.remove(),X.remove(),w?.remove(),De?.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&&gt(o)},400);s.addEventListener("pagehide",()=>gt(o)),q.set(o,{id:o,ctrl:w,cardIndex:e,label:n,closePollId:O,stopThemeSync:d,close:()=>{s.closed||s.close()},setTitle:F=>{a.title=F,r.textContent=F,r.style.display="block"}})}else{const a=ss({title:n,onClose:()=>gt(o),anchor:c});a.contentWrap.style.flexDirection="column",uo(a,n,t.wafer.metadata??void 0);const d=qt(a.contentWrap,t,void 0,i,Do(a));q.set(o,{id:o,ctrl:d,cardIndex:e,label:n,closePollId:null,close:()=>a.close(),setTitle:r=>{const p=a.box.querySelector("[data-wmap-window-title]");p&&(p.textContent=r,p.title=r)}})}x[e]?.destroy(),x[e]=null,Ti(e,s!==null),Oi(e)}function qt(e,t,n,o,i){const s=t.viewOptions?{...l,...t.viewOptions}:l,a=o?{...s,...o}:s,r={...n!==void 0?{...a,plotMode:"value",activeTest:n}:a,showLegend:!0,legendPosition:$e},p=Eo(e,t,{viewOptions:r,showTooltip:!0,padding:V,statsSummary:t.statsSummary,testValueOffer:kt,onSaveImage:f.onSaveImage,onSaveText:f.onSaveText,downloadFilename:f.downloadFilename,onClick:t.onClick,onSelect:Bn(t),insights:ne,showExpandButton:!1,onSummaryPanelChange:i,showIdentity:!1});return p.setViewControlsVisible(!0),p.setSummaryVisible(!0),p.setExpandVisible(!1),p}function gt(e){const t=q.get(e);if(!t||(q.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.(),t.ctrl.destroy(),t.cardIndex===null))return;const n=t.cardIndex,o=M[n];if(!o)return;const{card:i,ctrl:s,canvasWrapper:a,expandBtn:d}=Kt(o,n,M.length);oe[n]?.parentElement?.replaceWith(i),x[n]=s,oe[n]=a,ve[n]=d}function Li(e){const t=q.get(e);t&&(t.close(),gt(e))}function Wi(){for(const e of q.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function Xt(){for(const e of x)e?.drawPendingNow()}const po=c.ownerDocument.defaultView??window;po.addEventListener("beforeprint",Xt);function Ri(){Xt();const e=[...A.querySelectorAll("canvas")];if(!e.length)return;const t=e.length,n=Math.ceil(Math.sqrt(t)),o=Math.ceil(t/n),i=e[0].width,s=e[0].height,a=8,d=(c.ownerDocument.defaultView??window).devicePixelRatio||1,r=Math.round(26*d),p=Math.round(12*d),g=c.ownerDocument.createElement("canvas");g.width=n*i+(n-1)*a,g.height=o*(s+r)+(o-1)*a;const u=g.getContext("2d"),y=Yi(A);u.fillStyle=y.background,u.fillRect(0,0,g.width,g.height),e.forEach((m,h)=>{const w=h%n,O=Math.floor(h/n),F=w*(i+a),H=O*(s+r+a),Ue=m.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";u.fillStyle=y.surface,u.fillRect(F,H,i,r),u.fillStyle=y.text,u.font=`700 ${p}px system-ui, sans-serif`,u.textAlign="left",u.textBaseline="middle",u.fillText(Ue,F+Math.round(10*d),H+r/2,i-Math.round(20*d)),u.drawImage(m,F,H+r)}),g.toBlob(m=>{if(!m)return;const h=x.find(w=>w!=null)?.getExportTitle();ms(m,["gallery",h].filter(Boolean).join(" "),P.onSaveImage)})}return{setItems(e){C=e.map(n=>typeof n=="function"?null:n);const t=l.plotMode;if(pe.has(t))if(e.some(o=>typeof o=="function"))ee(e);else{const o=Gt(t);l={...l,...o},ee(Xe(t))}else ee(e)},setOptions(e){W(e,{fireCallback:!1})},getOptions(){return bt(l)},setFindingsNotice(e){Mn=e,$()},setColumns(e){lo(e)},getBinColors(){return l.binColors??Ee()},setLotStatsSummary(e){j=e,Te(),S&&$(),ae()},openUserGuide:Qn,destroy(){R.flush(),ke?.abort(),Fe++,po.removeEventListener("beforeprint",Xt),De?.cancel(),De=null,ze=null;for(const e of[...q.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();q.clear();for(const e of x)e&&e.destroy();x=[],He()?.remove(),fo.disconnect(),Re&&((c.ownerDocument.defaultView??window).cancelAnimationFrame(Re),Re=0),c.ownerDocument.removeEventListener("click",nt,!0),window.removeEventListener("blur",xn),Io(),Co(),qe.remove(),U.remove(),S?.remove(),ce?.destroy()}}}
@@ -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
- * Hatch dies whose bin is not a pass bin, giving pass/fail a channel that is
100
- * not hue. Default false. Bin modes only — in value mode the spec markers
101
- * already serve this role.
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
- markFailingDies?: boolean;
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}. wmap never raises this itself: only the host knows
265
- * what analysis it chose to skip and what running it would cost. Replaceable
266
- * afterwards via the controller's `setFindingsNotice`.
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 — which is what a host does once it has run the analysis the
362
- * notice was offering.
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
@@ -517,7 +551,20 @@ export interface CardController extends WaferMapController {
517
551
  /** @internal The public view of a card's options: everything but the gallery's shared state. */
518
552
  /** The bin a finding is about — what the legend filter shows while the finding
519
553
  * is active — or `undefined` for a yield, test or functional finding. */
520
- export declare function findingBin(finding: StatsFinding): number | undefined;
554
+ /**
555
+ * The bin a finding highlights on the map, or `undefined` for none. A pass bin that fell in a region is that
556
+ * region's pass rate, so it is shown as a yield finding is, as the region's dies: highlighting the passing
557
+ * dies would point at the dies the finding is not about. `passBins` are the population's own; without one set
558
+ * for it (wafers judged differently) no bin is taken for a pass bin.
559
+ */
560
+ export declare function findingBin(finding: StatsFinding, passBins: readonly number[] | undefined, hasHardBins: boolean): number | undefined;
561
+ /**
562
+ * The bin mode a finding is shown in. A bin finding takes its own bin type. Any other (a yield region,
563
+ * a spatial pattern) is about which dies, not which bin, so the map keeps the bin mode it is in, and
564
+ * from another mode takes a bin type the dies carry: a soft-bin-only lot switched to hard bins draws
565
+ * every die as no data. One rule for the single map and the gallery.
566
+ */
567
+ export declare function findingPlotMode(finding: StatsFinding, current: PlotMode | undefined, hasHardBins: boolean): PlotMode;
521
568
  export declare function toPublicViewOptions(opts: CardViewOptions): WaferViewOptions;
522
569
  export type RenderableWaferMap = Pick<WaferMapResult, 'wafer' | 'dies'> & Partial<Omit<WaferMapResult, 'wafer' | 'dies'>>;
523
570
  export declare function renderWaferMap(container: HTMLElement, result: RenderableWaferMap, options?: RenderOptions): WaferMapController;