@wafertools/wafermap 0.35.1 → 0.37.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 (188) hide show
  1. package/AGENTS.md +13 -10
  2. package/CHANGELOG.md +474 -0
  3. package/README.md +7 -7
  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/capability.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/cardAbout.d.ts +21 -0
  8. package/dist/packages/canvas-adapter/charts/cardAbout.js +1 -0
  9. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +65 -12
  10. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  11. package/dist/packages/canvas-adapter/charts/commonality.d.ts +18 -0
  12. package/dist/packages/canvas-adapter/charts/commonality.js +1 -0
  13. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  14. package/dist/packages/canvas-adapter/charts/groupComparison.d.ts +31 -0
  15. package/dist/packages/canvas-adapter/charts/groupComparison.js +1 -0
  16. package/dist/packages/canvas-adapter/charts/index.d.ts +0 -10
  17. package/dist/packages/canvas-adapter/charts/index.js +1 -1
  18. package/dist/packages/canvas-adapter/charts/patCard.d.ts +21 -0
  19. package/dist/packages/canvas-adapter/charts/patCard.js +1 -0
  20. package/dist/packages/canvas-adapter/charts/plotChart.d.ts +56 -2
  21. package/dist/packages/canvas-adapter/charts/plotChart.js +1 -1
  22. package/dist/packages/canvas-adapter/charts/pointInteractions.d.ts +2 -0
  23. package/dist/packages/canvas-adapter/charts/pointInteractions.js +1 -1
  24. package/dist/packages/canvas-adapter/charts/regionYieldDiagram.js +1 -1
  25. package/dist/packages/canvas-adapter/charts/sweep.js +1 -1
  26. package/dist/packages/canvas-adapter/dataTab.d.ts +3 -0
  27. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  28. package/dist/packages/canvas-adapter/dieList.d.ts +12 -0
  29. package/dist/packages/canvas-adapter/dieList.js +2 -2
  30. package/dist/packages/canvas-adapter/differenceMapPanel.d.ts +26 -0
  31. package/dist/packages/canvas-adapter/differenceMapPanel.js +1 -0
  32. package/dist/packages/canvas-adapter/drilldown.d.ts +3 -0
  33. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  34. package/dist/packages/canvas-adapter/filterButton.d.ts +3 -0
  35. package/dist/packages/canvas-adapter/filterButton.js +1 -0
  36. package/dist/packages/canvas-adapter/filterEditor.d.ts +53 -0
  37. package/dist/packages/canvas-adapter/filterEditor.js +1 -0
  38. package/dist/packages/canvas-adapter/guideWindow.d.ts +9 -1
  39. package/dist/packages/canvas-adapter/guideWindow.js +1 -1
  40. package/dist/packages/canvas-adapter/icons.js +1 -1
  41. package/dist/packages/canvas-adapter/index.d.ts +1 -0
  42. package/dist/packages/canvas-adapter/index.js +1 -1
  43. package/dist/packages/canvas-adapter/insightsTab.d.ts +57 -2
  44. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  45. package/dist/packages/canvas-adapter/pageFilter.d.ts +84 -0
  46. package/dist/packages/canvas-adapter/pageFilter.js +2 -0
  47. package/dist/packages/canvas-adapter/patMaps.d.ts +26 -0
  48. package/dist/packages/canvas-adapter/patMaps.js +1 -0
  49. package/dist/packages/canvas-adapter/plotCard.d.ts +67 -0
  50. package/dist/packages/canvas-adapter/plotCard.js +1 -0
  51. package/dist/packages/canvas-adapter/plotEditor.d.ts +13 -2
  52. package/dist/packages/canvas-adapter/plotEditor.js +1 -1
  53. package/dist/packages/canvas-adapter/plotModal.js +1 -1
  54. package/dist/packages/canvas-adapter/plotStore.js +1 -1
  55. package/dist/packages/canvas-adapter/plotTab.d.ts +6 -0
  56. package/dist/packages/canvas-adapter/plotTab.js +1 -1
  57. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +20 -5
  58. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  59. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +71 -37
  60. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  61. package/dist/packages/canvas-adapter/summaryPanel.d.ts +22 -9
  62. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  63. package/dist/packages/canvas-adapter/testValueOffer.d.ts +14 -0
  64. package/dist/packages/canvas-adapter/testValueOffer.js +1 -0
  65. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  66. package/dist/packages/canvas-adapter/toolbar.d.ts +12 -6
  67. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  68. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  69. package/dist/packages/canvas-adapter/userGuideHtml.js +607 -117
  70. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  71. package/dist/packages/canvas-adapter/version.js +1 -1
  72. package/dist/packages/canvas-adapter/warnings.js +1 -1
  73. package/dist/packages/core/aggregates.d.ts +10 -0
  74. package/dist/packages/core/aggregates.js +1 -1
  75. package/dist/packages/core/classify.d.ts +11 -0
  76. package/dist/packages/core/classify.js +1 -1
  77. package/dist/packages/core/dieTable.d.ts +5 -0
  78. package/dist/packages/core/dieTable.js +1 -1
  79. package/dist/packages/core/dies.d.ts +2 -0
  80. package/dist/packages/core/dies.js +1 -1
  81. package/dist/packages/core/wafer.d.ts +10 -1
  82. package/dist/packages/core/wafer.js +1 -1
  83. package/dist/packages/renderer/buildView.d.ts +5 -0
  84. package/dist/packages/renderer/buildView.js +1 -1
  85. package/dist/packages/renderer/buildWaferMap.d.ts +21 -4
  86. package/dist/packages/renderer/buildWaferMap.js +1 -1
  87. package/dist/packages/renderer/deprecate.d.ts +2 -8
  88. package/dist/packages/renderer/deprecate.js +1 -1
  89. package/dist/packages/renderer/derivedTests/parser.js +1 -1
  90. package/dist/packages/renderer/fmt.d.ts +10 -0
  91. package/dist/packages/renderer/fmt.js +1 -1
  92. package/dist/packages/renderer/index.d.ts +1 -0
  93. package/dist/packages/renderer/index.js +1 -1
  94. package/dist/packages/renderer/testLabel.d.ts +0 -11
  95. package/dist/packages/renderer/testLabel.js +1 -1
  96. package/dist/packages/renderer/valueFilter.d.ts +1 -1
  97. package/dist/packages/renderer/valueFilter.js +1 -1
  98. package/dist/packages/stats/analyzeWaferLot.d.ts +22 -0
  99. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  100. package/dist/packages/stats/analyzeWaferMap.d.ts +26 -1
  101. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  102. package/dist/packages/stats/binPareto.d.ts +2 -54
  103. package/dist/packages/stats/binPareto.js +1 -1
  104. package/dist/packages/stats/binRows.js +1 -1
  105. package/dist/packages/stats/capability.d.ts +10 -0
  106. package/dist/packages/stats/capability.js +1 -1
  107. package/dist/packages/stats/cardSpec.d.ts +53 -0
  108. package/dist/packages/stats/cardSpec.js +1 -0
  109. package/dist/packages/stats/chartCatalogue.d.ts +37 -0
  110. package/dist/packages/stats/chartCatalogue.js +1 -0
  111. package/dist/packages/stats/clusterDetection.d.ts +9 -0
  112. package/dist/packages/stats/clusterDetection.js +1 -1
  113. package/dist/packages/stats/commonality.d.ts +62 -0
  114. package/dist/packages/stats/commonality.js +1 -0
  115. package/dist/packages/stats/connectedComponents.js +1 -1
  116. package/dist/packages/stats/control.d.ts +21 -0
  117. package/dist/packages/stats/control.js +1 -0
  118. package/dist/packages/stats/correlation.d.ts +42 -4
  119. package/dist/packages/stats/correlation.js +1 -1
  120. package/dist/packages/stats/dieRegions.d.ts +4 -1
  121. package/dist/packages/stats/dieRegions.js +1 -1
  122. package/dist/packages/stats/differenceMap.d.ts +22 -0
  123. package/dist/packages/stats/differenceMap.js +1 -0
  124. package/dist/packages/stats/examplePicks.d.ts +22 -0
  125. package/dist/packages/stats/examplePicks.js +1 -0
  126. package/dist/packages/stats/filterFile.d.ts +41 -0
  127. package/dist/packages/stats/filterFile.js +2 -0
  128. package/dist/packages/stats/filterFindings.d.ts +21 -6
  129. package/dist/packages/stats/filterFindings.js +1 -1
  130. package/dist/packages/stats/findingText.d.ts +8 -0
  131. package/dist/packages/stats/findingText.js +2 -2
  132. package/dist/packages/stats/groupCompare.d.ts +87 -0
  133. package/dist/packages/stats/groupCompare.js +1 -0
  134. package/dist/packages/stats/guideSections.d.ts +55 -0
  135. package/dist/packages/stats/guideSections.js +1 -0
  136. package/dist/packages/stats/index.d.ts +5 -2
  137. package/dist/packages/stats/index.js +1 -1
  138. package/dist/packages/stats/lotDrift.js +1 -1
  139. package/dist/packages/stats/math.d.ts +29 -4
  140. package/dist/packages/stats/math.js +1 -1
  141. package/dist/packages/stats/mergeTestDefs.js +1 -1
  142. package/dist/packages/stats/metadataColumns.d.ts +3 -0
  143. package/dist/packages/stats/metadataColumns.js +1 -1
  144. package/dist/packages/stats/pat.d.ts +58 -0
  145. package/dist/packages/stats/pat.js +1 -0
  146. package/dist/packages/stats/patSummary.d.ts +45 -0
  147. package/dist/packages/stats/patSummary.js +1 -0
  148. package/dist/packages/stats/patternClassification.d.ts +3 -3
  149. package/dist/packages/stats/patternClassification.js +1 -1
  150. package/dist/packages/stats/plotData.d.ts +294 -17
  151. package/dist/packages/stats/plotData.js +1 -1
  152. package/dist/packages/stats/plotId.d.ts +2 -0
  153. package/dist/packages/stats/plotId.js +1 -1
  154. package/dist/packages/stats/plotReferences.d.ts +17 -0
  155. package/dist/packages/stats/plotReferences.js +1 -0
  156. package/dist/packages/stats/plotSpec.d.ts +239 -3
  157. package/dist/packages/stats/plotSpec.js +4 -4
  158. package/dist/packages/stats/regions.js +1 -1
  159. package/dist/packages/stats/renderSummaryReport.js +33 -33
  160. package/dist/packages/stats/reportHtml.d.ts +5 -12
  161. package/dist/packages/stats/reportHtml.js +98 -40
  162. package/dist/packages/stats/synthesis.d.ts +48 -16
  163. package/dist/packages/stats/synthesis.js +1 -1
  164. package/dist/packages/stats/testPassRate.d.ts +7 -0
  165. package/dist/packages/stats/testPassRate.js +1 -1
  166. package/dist/packages/stats/testValueBudget.d.ts +15 -0
  167. package/dist/packages/stats/testValueBudget.js +1 -0
  168. package/dist/packages/stats/types.d.ts +90 -30
  169. package/dist/packages/stats/yield.d.ts +3 -11
  170. package/dist/packages/stats/yield.js +1 -1
  171. package/llms.txt +1 -1
  172. package/package.json +2 -1
  173. package/dist/packages/canvas-adapter/charts/barPanel.d.ts +0 -83
  174. package/dist/packages/canvas-adapter/charts/barPanel.js +0 -1
  175. package/dist/packages/canvas-adapter/charts/binCluster.d.ts +0 -27
  176. package/dist/packages/canvas-adapter/charts/binCluster.js +0 -1
  177. package/dist/packages/canvas-adapter/charts/boxplot.d.ts +0 -72
  178. package/dist/packages/canvas-adapter/charts/boxplot.js +0 -1
  179. package/dist/packages/canvas-adapter/charts/groupedBarPlot.d.ts +0 -53
  180. package/dist/packages/canvas-adapter/charts/groupedBarPlot.js +0 -1
  181. package/dist/packages/canvas-adapter/charts/histogram.d.ts +0 -61
  182. package/dist/packages/canvas-adapter/charts/histogram.js +0 -1
  183. package/dist/packages/canvas-adapter/charts/scatter.d.ts +0 -80
  184. package/dist/packages/canvas-adapter/charts/scatter.js +0 -1
  185. package/dist/packages/canvas-adapter/charts/testPassRate.d.ts +0 -27
  186. package/dist/packages/canvas-adapter/charts/testPassRate.js +0 -1
  187. package/dist/packages/canvas-adapter/charts/trend.d.ts +0 -50
  188. package/dist/packages/canvas-adapter/charts/trend.js +0 -1
@@ -1 +1 @@
1
- import{defaultPlot as Z,defaultSweep as ee,describeTitleDrift as te,examplePlots as oe,fieldCatalogue as ne,resolvePlot as se,titleDrift as re}from"../stats/plotData.js";import{addPlots as le,newPlotId as T,readPlotsFile as ae,writePlotsFile as ie}from"../stats/plotSpec.js";import{isYieldEligibleDie as ce}from"../core/dies.js";import{testValue as pe}from"../core/dieTable.js";import{sweepAppliesTo as de}from"../stats/sweep.js";import{plotToSweep as L}from"../stats/plotSpec.js";import{renderPlotChart as fe}from"./charts/plotChart.js";import{renderSweepPanel as ue}from"./charts/sweep.js";import{makeChartGridWrap as me}from"./charts/chartShell.js";import{confirmDialog as he}from"./confirmDialog.js";import{openDrilldownMenu as O}from"./drilldown.js";import{openPlotEditor as ge}from"./plotModal.js";import{sourceFromDies as ye,sourceFromPoints as we,toPlotItems as be}from"./plotItems.js";import{CLR as g,FONT as S,RADIUS as F,SPACE as u,controlStyle as xe,markNoPrint as E,saveTextFile as Pe,wireControlHover as ve,wireTooltip as De}from"./toolbar.js";const R=1e4;export function createPlotSection(r){const{doc:i,store:l}=r,c=be(r.items.map(e=>({label:e.identity??e.label,dies:e.dies,waferIndex:e.waferIndex,wafer:e.wafer,passBins:e.passBins,ringCount:r.ringCount}))),C={testDefs:r.testDefs,groupBy:r.groupBy,curation:r.attributes},U=e=>se(e,c,C),b=ne(c,C),m=i.createElement("div");m.dataset.wmapPlotTab="1",Object.assign(m.style,{display:"flex",flexDirection:"column",gap:u.lg,width:"100%"});const x=i.createElement("div");Object.assign(x.style,{display:"flex",flexWrap:"wrap",gap:u.md,alignItems:"center"});const d=(e,t,n,o)=>{const s=i.createElement("button");return s.type="button",s.textContent=e,s.dataset[t]="1",Object.assign(s.style,{...xe("outlined"),fontSize:S.body}),ve(s),De(s,n),s.addEventListener("click",o),s},P=d("Delete all plots\u2026","wmapPlotDeleteAll","Remove every plot and sweep. You are asked first, and Undo brings them back for ten seconds",()=>{V()});x.append(d("+ New plot","wmapPlotNew","Start a chart of your own: choose its type, what goes on each axis and how it is coloured",()=>z()),d("+ New sweep","wmapPlotNewSweep","Read an ordered run of tests as a response curve, and measure where two curves cross",()=>M()),d("Add examples","wmapPlotExamples","Draw one example of each chart type this lot can show, to edit or delete",()=>Y()),d("Import plots\u2026","wmapPlotImport","Add the plots from a file written by Export plots\u2026",()=>{Q()}),d("Export plots\u2026","wmapPlotExport","Save all your plots to a file, to share or to keep a copy",()=>X()),P),E(x),m.appendChild(x);const p=i.createElement("div");p.setAttribute("role","status"),Object.assign(p.style,{display:"none",flexWrap:"wrap",gap:u.md,alignItems:"center",padding:`${u.sm} ${u.md}`,background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:F.container,color:g.text,fontSize:S.body}),E(p),m.appendChild(p);let h;function y(e,t,n=[]){h!==void 0&&clearTimeout(h),p.replaceChildren();const o=i.createElement("span");if(o.textContent=e,p.appendChild(o),t){const s=d(t.label,"wmapPlotNoticeAction",t.label==="Undo"?"Put back what was just removed":t.label,()=>{t.run(),I()});p.appendChild(s)}for(const s of n){const a=i.createElement("div");a.textContent=s,Object.assign(a.style,{flexBasis:"100%",color:g.label}),p.appendChild(a)}p.style.display="flex",h=setTimeout(I,t?R:R*2)}function I(){h!==void 0&&(clearTimeout(h),h=void 0),p.style.display="none",p.replaceChildren()}const v=i.createElement("div");v.textContent="No plots yet. A plot is any measured value against another, or a distribution, that you choose: New plot starts one, and it is kept for the next lot. Add examples draws one of each chart type from this lot to start from.",Object.assign(v.style,{color:g.label,fontSize:S.body,padding:`${u.lg} 0`});const D=me(i);m.append(v,D);const w=new Map,A=()=>({onSaveImage:r.onSaveImage,onOpenWafer:r.openWafer?(e,t)=>r.openWafer(c[e].waferIndex??e,c[e].label,t):r.focusTest&&c.length===1?(e,t)=>{t!==void 0&&r.focusTest(t)}:void 0,openActionLabel:!r.openWafer&&r.focusTest&&c.length===1?"show this test on the map":void 0,onSelectPoints:(e,t,n)=>W(e,t,n)}),$=()=>({plots:l,onSaveImage:r.onSaveImage,onSaveText:r.onSaveText,onLocateDie:r.locateDie});function W(e,t,n){const o=we(e,c,r.testDefs);o&&O(t,n,o,$())}function k(e,t=!1){ge({doc:i,anchor:m,store:l,plot:e,draft:t,items:c,ctx:C,groupLabel:r.groupLabel,chart:A(),onSelectLevel:j})}function M(){const e=ee(r.testDefs,T());l.upsert(e),k(e)}function j(e,t){const n=s=>e.testNumbers.some(a=>{const f=pe(s,a);return f!==void 0&&Number.isFinite(f)}),o=ye(c,`measured at ${e.label}`,s=>ce(s)&&n(s),r.testDefs,e.testNumbers[0]);o&&O({x:t.clientX,y:t.clientY},t.target,o,$())}function z(){const e=Z(b,T());l.upsert(e),k(e)}function Y(){const e=o=>JSON.stringify([o.chart,o.fields,o.aggregate??null,o.sweep??null]),t=new Set(l.get().map(e)),n=oe(b,c.length,T).filter(o=>!t.has(e(o)));if(n.length===0){y(b.some(o=>o.group==="Tests")?"The examples for this lot are already in your plots.":"There are no measured values in this lot to draw examples from.");return}for(const o of n)l.upsert(o);y(`Added ${n.length} example plot${n.length===1?"":"s"}: ${n.map(o=>o.chart).join(", ")}. Edit one to make it yours, or Delete what you do not need.`)}function N(e,t){const n=(o,s,a,f)=>e.appendChild(d(o,s,a,f));n("Edit","wmapPlotEdit","Change this plot\u2019s type, fields, titles, limits and axes",()=>{const o=l.get().find(s=>s.id===t.id);o&&k(o)}),n("Duplicate","wmapPlotDuplicate","Make a copy of this plot to vary",()=>{l.duplicate(t.id)}),n("Delete","wmapPlotDelete","Remove this plot. Undo brings it back for ten seconds",()=>{const o=l.remove(t.id);o&&y(`Deleted \u201C${o.plot.title??"plot"}\u201D.`,{label:"Undo",run:()=>l.insertAt(o.index,o.plot)})})}function _(e){return e.chart==="sweep"?J(e):H(e)}function H(e){const t=fe({ownerDocument:i,waferLabel:s=>c[s]?.label??"",...A()});t.card.dataset.wmapPlotId=e.id,E(t.actions),N(t.actions,e);const n=i.createElement("div");n.dataset.wmapPlotTitleDrift="1",Object.assign(n.style,{display:"none",flexWrap:"wrap",gap:u.md,alignItems:"center",flexBasis:"100%",padding:`${u.xs} ${u.md}`,background:g.warnBg,border:`1px solid ${g.warnBorder}`,borderRadius:F.control,color:g.warnText,fontSize:S.body}),t.actions.appendChild(n);const o={card:t.card,actions:t.actions,json:"",driftNote:n,destroy:()=>t.destroy(),update:s=>{const a=U(s);t.setPlot(a),t.card.style.opacity=a.issues.length?"0.7":"1",G(n,s)}};return w.set(e.id,o),o}function J(e){const t=L(e),n=c.flatMap(a=>a.dies),o=ue({spec:t,dies:n,testDefs:r.testDefs,onSaveImage:r.onSaveImage,ownerDocument:i,onSelectPoint:j});o.card.dataset.wmapPlotId=e.id,o.card.dataset.wmapSweepPlot="1",E(o.actions),N(o.actions,e);const s={card:o.card,actions:o.actions,json:"",destroy:()=>o.destroy(),update:a=>{const f=L(a);o.setSpec(f),o.card.style.opacity=de(f,r.testDefs)?"1":"0.7"}};return w.set(e.id,s),s}function G(e,t){const n=te(re(t,b));if(e.replaceChildren(),e.style.display=n?"flex":"none",!n)return;const o=i.createElement("span");o.textContent=n,e.append(o,d("Use the automatic title","wmapPlotAutoTitle","Replace the title you typed with the one written from the plot\u2019s settings",()=>{const s=l.get().find(f=>f.id===t.id);if(!s)return;const a={...s};delete a.title,l.upsert(a)}))}function B(){const e=l.get();for(const[t,n]of w)e.some(o=>o.id===t)||(n.destroy(),n.card.remove(),w.delete(t));e.forEach((t,n)=>{const o=w.get(t.id)??_(t),s=JSON.stringify(t);o.json!==s&&(o.json=s,o.update(t)),D.children[n]!==o.card&&D.insertBefore(o.card,D.children[n]??null)}),v.style.display=e.length===0?"":"none",P.disabled=e.length===0,P.style.opacity=e.length===0?"0.5":"1",P.style.cursor=e.length===0?"default":"pointer"}const K=l.subscribe(B);B();async function V(){const e=l.get().slice();if(e.length===0)return;const t=e.length;if(!await he({doc:i,anchor:m,title:"Delete all plots",message:t===1?"Delete your 1 saved plot? It is kept on this computer for the next lot, so it will not be there for the next file either. Export plots\u2026 first to keep a copy.":`Delete all ${t} saved plots, sweeps included? They are kept on this computer for the next lot, so they will not be there for the next file either. Export plots\u2026 first to keep a copy.`,confirmLabel:t===1?"Delete 1 plot":`Delete ${t} plots`}))return;const o=l.get().slice();o.length!==0&&(l.replaceAll([]),y(`Deleted ${o.length===1?"1 plot":`all ${o.length} plots`}.`,{label:"Undo",run:()=>l.replaceAll(o)}))}function X(){const e=l.get();if(e.length===0){y("There are no plots to export yet.");return}Pe(ie(e),"wafermap-plots.json","application/json",r.onSaveText)}async function q(){return r.pickPlotsFile?r.pickPlotsFile():new Promise(e=>{const t=i.createElement("input");t.type="file",t.accept=".json,application/json",t.addEventListener("change",()=>{const n=t.files?.[0];if(!n){e(null);return}n.text().then(e,()=>e(null))}),t.addEventListener("cancel",()=>e(null)),t.click()})}async function Q(){const e=await q();if(e===null)return;const t=ae(e);if(t.error){y(`Could not import: ${t.error}`);return}const{plots:n,copies:o}=le(l.get(),t.plots);l.replaceAll(n);const s=[...t.warnings,...o.length?[`Kept as copies, since a plot with the same id already existed: ${o.join(", ")}`]:[]];y(`Imported ${t.plots.length} plot${t.plots.length===1?"":"s"}.`,void 0,s)}return{card:m,destroy:()=>{K(),h!==void 0&&clearTimeout(h);for(const e of w.values())e.destroy();w.clear(),l.flush()}}}
1
+ import{defaultPlot as te,defaultSweep as oe,describeTitleDrift as ne,examplePlots as se,fieldCatalogue as re,resolvePlot as le,titleDrift as ae}from"../stats/plotData.js";import{addPlots as ie,newPlotId as T,readPlotsFile as ce,writePlotsFile as pe}from"../stats/plotSpec.js";import{buildFilterStrip as de}from"./filterEditor.js";import{isYieldEligibleDie as fe}from"../core/dies.js";import{testValue as ue}from"../core/dieTable.js";import{sweepAppliesTo as me}from"../stats/sweep.js";import{plotToSweep as F}from"../stats/plotSpec.js";import{renderPlotChart as he}from"./charts/plotChart.js";import{renderSweepPanel as ge}from"./charts/sweep.js";import{makeChartGridWrap as we}from"./charts/chartShell.js";import{confirmDialog as ye}from"./confirmDialog.js";import{openDrilldownMenu as L}from"./drilldown.js";import{openPlotEditor as be}from"./plotModal.js";import{sourceFromDies as xe,sourceFromPoints as ve,toPlotItems as Pe}from"./plotItems.js";import{CLR as g,FONT as C,RADIUS as O,SPACE as u,controlStyle as De,markNoPrint as E,saveTextFile as Se,wireControlHover as Ce,wireTooltip as Ee}from"./toolbar.js";const W=1e4;export function createPlotSection(r){const{doc:i,store:l}=r,p=Pe(r.items.map(e=>({label:e.identity??e.label,dies:e.dies,waferIndex:e.waferIndex,wafer:e.wafer,passBins:e.passBins,ringCount:r.ringCount}))),b={testDefs:r.testDefs,groupBy:r.groupBy,curation:r.attributes},M=e=>le(e,p,b),x=re(p,b),m=i.createElement("div");m.dataset.wmapPlotTab="1",Object.assign(m.style,{display:"flex",flexDirection:"column",gap:u.lg,width:"100%"});const v=i.createElement("div");Object.assign(v.style,{display:"flex",flexWrap:"wrap",gap:u.md,alignItems:"center"});const f=(e,t,n,o)=>{const s=i.createElement("button");return s.type="button",s.textContent=e,s.dataset[t]="1",Object.assign(s.style,{...De("outlined"),fontSize:C.body}),Ce(s),Ee(s,n),s.addEventListener("click",o),s},P=f("Delete all plots\u2026","wmapPlotDeleteAll","Remove every plot and sweep. You are asked first, and Undo brings them back for ten seconds",()=>{X()});v.append(f("+ New plot","wmapPlotNew","Start a chart of your own: choose its type, what goes on each axis and how it is coloured",()=>z()),f("+ New sweep","wmapPlotNewSweep","Read an ordered run of tests as a response curve, and measure where two curves cross",()=>U()),f("Add examples","wmapPlotExamples","Draw one example of each chart type this lot can show, to edit or delete",()=>Y()),f("Import plots\u2026","wmapPlotImport","Add the plots from a file written by Export plots\u2026",()=>{Z()}),f("Export plots\u2026","wmapPlotExport","Save all your plots to a file, to share or to keep a copy",()=>q()),P),E(v),m.appendChild(v);const d=i.createElement("div");d.setAttribute("role","status"),Object.assign(d.style,{display:"none",flexWrap:"wrap",gap:u.md,alignItems:"center",padding:`${u.sm} ${u.md}`,background:g.menuBg,border:`1px solid ${g.menuBorder}`,borderRadius:O.container,color:g.text,fontSize:C.body}),E(d),m.appendChild(d);let h;function w(e,t,n=[]){h!==void 0&&clearTimeout(h),d.replaceChildren();const o=i.createElement("span");if(o.textContent=e,d.appendChild(o),t){const s=f(t.label,"wmapPlotNoticeAction",t.label==="Undo"?"Put back what was just removed":t.label,()=>{t.run(),I()});d.appendChild(s)}for(const s of n){const a=i.createElement("div");a.textContent=s,Object.assign(a.style,{flexBasis:"100%",color:g.label}),d.appendChild(a)}d.style.display="flex",h=setTimeout(I,t?W:W*2)}function I(){h!==void 0&&(clearTimeout(h),h=void 0),d.style.display="none",d.replaceChildren()}const D=i.createElement("div");D.textContent="No plots yet. A plot is any measured value against another, or a distribution, that you choose: New plot starts one, and it is kept for the next lot. Add examples draws one of each chart type from this lot to start from.",Object.assign(D.style,{color:g.label,fontSize:C.body,padding:`${u.lg} 0`});const S=we(i);m.append(D,S);const y=new Map,A=()=>({onSaveImage:r.onSaveImage,binColors:r.getBinColors?.(),onWaferMenu:r.waferMenu?(e,t,n)=>r.waferMenu(p[e].waferIndex??e,t,n):void 0,onOpenWafer:r.openWafer?(e,t)=>r.openWafer(p[e].waferIndex??e,p[e].label,t):r.focusTest&&p.length===1?(e,t)=>{t!==void 0&&r.focusTest(t)}:void 0,openActionLabel:!r.openWafer&&r.focusTest&&p.length===1?"show this test on the map":void 0,onSelectPoints:(e,t,n)=>R(e,t,n)}),$=()=>({plots:l,getBinColors:r.getBinColors,onSaveImage:r.onSaveImage,onSaveText:r.onSaveText,onLocateDie:r.locateDie});function R(e,t,n){const o=ve(e,p,r.testDefs);o&&L(t,n,o,$())}function k(e,t=!1){be({doc:i,anchor:m,store:l,plot:e,draft:t,items:p,ctx:b,groupLabel:r.groupLabel,chart:A(),onSelectLevel:j})}function U(){const e=oe(r.testDefs,T());l.upsert(e),k(e)}function j(e,t){const n=s=>e.testNumbers.some(a=>{const c=ue(s,a);return c!==void 0&&Number.isFinite(c)}),o=xe(p,`measured at ${e.label}`,s=>fe(s)&&n(s),r.testDefs,e.testNumbers[0]);o&&L({x:t.clientX,y:t.clientY},t.target,o,$())}function z(){const e=te(x,T());l.upsert(e),k(e)}function Y(){const e=o=>JSON.stringify([o.chart,o.fields,o.aggregate??null,o.sweep??null,o.fit??null,o.normalCurve??null,o.spread??null,o.normalize??null,o.sort??null,o.cumulative??null,o.stack??null]),t=new Set(l.get().map(e)),n=se(x,p.length,T,{items:p,ctx:b}).filter(o=>!t.has(e(o)));if(n.length===0){w(x.some(o=>o.group==="Tests")?"The examples for this lot are already in your plots.":"There are no measured values in this lot to draw examples from.");return}for(const o of n)l.upsert(o);w(`Added ${n.length} example plot${n.length===1?"":"s"}: ${[...new Set(n.map(o=>o.chart))].join(", ")}. Edit one to make it yours, or Delete what you do not need.`)}function B(e,t){const n=(o,s,a,c)=>e.appendChild(f(o,s,a,c));n("Edit","wmapPlotEdit","Change this plot\u2019s type, fields, titles, limits and axes",()=>{const o=l.get().find(s=>s.id===t.id);o&&k(o)}),n("Duplicate","wmapPlotDuplicate","Make a copy of this plot to vary",()=>{l.duplicate(t.id)}),n("Delete","wmapPlotDelete","Remove this plot. Undo brings it back for ten seconds",()=>{const o=l.remove(t.id);o&&w(`Deleted \u201C${o.plot.title??"plot"}\u201D.`,{label:"Undo",run:()=>l.insertAt(o.index,o.plot)})})}function _(e){return e.chart==="sweep"?J(e):H(e)}function H(e){const t=he({ownerDocument:i,waferLabel:a=>p[a]?.label??"",...A()});t.card.dataset.wmapPlotId=e.id,E(t.actions),B(t.actions,e);const n=i.createElement("div");n.dataset.wmapPlotTitleDrift="1",Object.assign(n.style,{display:"none",flexWrap:"wrap",gap:u.md,alignItems:"center",flexBasis:"100%",padding:`${u.xs} ${u.md}`,background:g.warnBg,border:`1px solid ${g.warnBorder}`,borderRadius:O.control,color:g.warnText,fontSize:C.body});const o=i.createElement("div");o.style.flexBasis="100%",t.actions.append(o,n);const s={card:t.card,actions:t.actions,json:"",driftNote:n,destroy:()=>t.destroy(),update:a=>{const c=M(a);t.setPlot(c),G(o,a),t.card.style.opacity=c.issues.length?"0.7":"1",K(n,a)}};return y.set(e.id,s),s}function J(e){const t=F(e),n=p.flatMap(a=>a.dies),o=ge({spec:t,dies:n,testDefs:r.testDefs,onSaveImage:r.onSaveImage,ownerDocument:i,onSelectPoint:j});o.card.dataset.wmapPlotId=e.id,o.card.dataset.wmapSweepPlot="1",E(o.actions),B(o.actions,e);const s={card:o.card,actions:o.actions,json:"",destroy:()=>o.destroy(),update:a=>{const c=F(a);o.setSpec(c),o.card.style.opacity=me(c,r.testDefs)?"1":"0.7"}};return y.set(e.id,s),s}function G(e,t){const n=t.where;e.replaceChildren(),n&&e.appendChild(de({doc:i,filter:n,testDefs:r.testDefs,attributes:r.attributes,label:"Filter",onToggle:o=>{const s=l.get().find(ee=>ee.id===t.id),a=s?.where;if(!s||!a)return;const c={...a};o?delete c.off:c.off=!0,l.upsert({...s,where:c})}}))}function K(e,t){const n=ne(ae(t,x));if(e.replaceChildren(),e.style.display=n?"flex":"none",!n)return;const o=i.createElement("span");o.textContent=n,e.append(o,f("Use the automatic title","wmapPlotAutoTitle","Replace the title you typed with the one written from the plot\u2019s settings",()=>{const s=l.get().find(c=>c.id===t.id);if(!s)return;const a={...s};delete a.title,l.upsert(a)}))}function N(){const e=l.get();for(const[t,n]of y)e.some(o=>o.id===t)||(n.destroy(),n.card.remove(),y.delete(t));e.forEach((t,n)=>{const o=y.get(t.id)??_(t),s=JSON.stringify(t);o.json!==s&&(o.json=s,o.update(t)),S.children[n]!==o.card&&S.insertBefore(o.card,S.children[n]??null)}),D.style.display=e.length===0?"":"none",P.disabled=e.length===0,P.style.opacity=e.length===0?"0.5":"1",P.style.cursor=e.length===0?"default":"pointer"}const V=l.subscribe(N);N();async function X(){const e=l.get().slice();if(e.length===0)return;const t=e.length;if(!await ye({doc:i,anchor:m,title:"Delete all plots",message:t===1?"Delete your 1 saved plot? It is kept on this computer for the next lot, so it will not be there for the next file either. Export plots\u2026 first to keep a copy.":`Delete all ${t} saved plots, sweeps included? They are kept on this computer for the next lot, so they will not be there for the next file either. Export plots\u2026 first to keep a copy.`,confirmLabel:t===1?"Delete 1 plot":`Delete ${t} plots`}))return;const o=l.get().slice();o.length!==0&&(l.replaceAll([]),w(`Deleted ${o.length===1?"1 plot":`all ${o.length} plots`}.`,{label:"Undo",run:()=>l.replaceAll(o)}))}function q(){const e=l.get();if(e.length===0){w("There are no plots to export yet.");return}Se(pe(e),"wafermap-plots.json","application/json",r.onSaveText)}async function Q(){return r.pickPlotsFile?r.pickPlotsFile():new Promise(e=>{const t=i.createElement("input");t.type="file",t.accept=".json,application/json",t.addEventListener("change",()=>{const n=t.files?.[0];if(!n){e(null);return}n.text().then(e,()=>e(null))}),t.addEventListener("cancel",()=>e(null)),t.click()})}async function Z(){const e=await Q();if(e===null)return;const t=ce(e);if(t.error){w(`Could not import: ${t.error}`);return}const{plots:n,copies:o}=ie(l.get(),t.plots);l.replaceAll(n);const s=[...t.warnings,...o.length?[`Kept as copies, since a plot with the same id already existed: ${o.join(", ")}`]:[]];w(`Imported ${t.plots.length} plot${t.plots.length===1?"":"s"}.`,void 0,s)}return{card:m,destroy:()=>{V(),h!==void 0&&clearTimeout(h);for(const e of y.values())e.destroy();y.clear(),l.flush()}}}
@@ -4,7 +4,7 @@ import { type UserGuideExtension } from './guideWindow.js';
4
4
  import { type Die } from '../core/dies.js';
5
5
  import type { WaferViewOptions } from './renderWaferMap.js';
6
6
  import type { RenderableWaferMap } from './renderWaferMap.js';
7
- import type { LotStatsSummary } from '../stats/types.js';
7
+ import type { LotStatsSummary, StatsSummary } from '../stats/types.js';
8
8
  import { type WarningsOptions } from './warnings.js';
9
9
  import type { SummaryPanelOptions, FindingsNotice } from './summaryPanel.js';
10
10
  import { type WaferAttributeDef } from '../stats/facets.js';
@@ -137,6 +137,16 @@ export interface GalleryOptions {
137
137
  onSaveText?: SaveTextHandler;
138
138
  /** Precomputed lot-level stats summary. Enables the summary panel toggle button in the control bar. */
139
139
  lotStatsSummary?: LotStatsSummary;
140
+ /**
141
+ * Called after the gallery re-analyses the lot itself: when the reader asks, from the lot Findings section, for the
142
+ * test-value analysis the summaries record as not run (`stats.testValueAnalysis`). `summaries` holds each item's
143
+ * new summary in item order, `lotStatsSummary` the lot's; the gallery already shows them. Keep them so the host's
144
+ * own copies (reports, logs) match.
145
+ */
146
+ onStatsSummaryChange?: (change: {
147
+ summaries: StatsSummary[];
148
+ lotStatsSummary: LotStatsSummary;
149
+ }) => void;
140
150
  /**
141
151
  * Options for the always-available Summary panel alongside the gallery
142
152
  * grid — a "Lot" tab with full lot-level stats (metadata, yield, bin
@@ -151,9 +161,12 @@ export interface GalleryOptions {
151
161
  /**
152
162
  * A row at the top of the Findings section stating that a category of finding
153
163
  * is not present, and optionally offering to compute it — see
154
- * {@link FindingsNotice}. wmap never raises this itself: only the host knows
155
- * what analysis it chose to skip and what running it would cost. Replaceable
156
- * afterwards via the controller's `setFindingsNotice`.
164
+ * {@link FindingsNotice}. Replaces the built-in offer of the skipped
165
+ * test-value analysis while set.
166
+ *
167
+ * @deprecated The renderers offer the skipped test-value analysis themselves
168
+ * (from `stats.testValueAnalysis`) and report the re-run through
169
+ * `onStatsSummaryChange`. See API_REMOVALS.md.
157
170
  */
158
171
  findingsNotice?: FindingsNotice;
159
172
  /**
@@ -228,7 +241,9 @@ export interface GalleryController {
228
241
  setLotStatsSummary(summary: LotStatsSummary | undefined): void;
229
242
  /**
230
243
  * Replace the lot Findings-section notice (see `FindingsNotice`). Pass
231
- * `undefined` to clear it once the offered analysis has been run.
244
+ * `undefined` to clear it, which brings back the built-in offer.
245
+ *
246
+ * @deprecated With `findingsNotice`. See API_REMOVALS.md.
232
247
  */
233
248
  setFindingsNotice(notice: FindingsNotice | undefined): void;
234
249
  /**
@@ -1 +1 @@
1
- import{createViewSwitch as Ei}from"./viewSwitch.js";import{createSummaryToggle as Ti}from"./summaryToggle.js";import{getUniqueTestNumbers as Oi,resolveTestNumber as Li,findTestDef as Wi,collectMetadataValues as Ri}from"../renderer/buildView.js";import{metadataCategoricalValue as $i}from"../core/metadata.js";import{resolveBinColorsForMaps as Ai,mergeBinDefs as mt,binColorWarning as Pi,mixedPassBinsWarning as Ii,binColorsEqual as Fi}from"../renderer/binColors.js";import{commonPassBins as uo,itemPassBins as Yt}from"../core/passBins.js";import{requireRingCount as te}from"../core/ringCount.js";import{NO_DATA_FILL as Hi}from"../renderer/colorMap.js";import{metadataValueColor as ji}from"../renderer/colorMap.js";import{resolveCanvasTheme as Vi}from"./canvasTheme.js";import{ICONS as Zt}from"./icons.js";import{defaultPlotMode as zi,SHADOW as Qt,LEADING as fo,TRACKING as Gi,controlStyle as Ki,wireControlHover as Jt,SPACE as k,EDGE_GUTTER as de,MAP_CHROME_INSET as Ni,RADIUS as K,FONT as j,CLR as b,sevColor as po,MODE_LABELS as _i,BIN_LEGEND_MODES as go,STACKED_MODES as he,applyOverlayZ as qi,getTooltip as Xi,hideTooltip as mo,createToolbarHelpers as Ui,buildModeMenuEl as Yi,openDetachWindow as Zi,openFloatingWindow as Qi,openModal as Ji,copyWmapThemeTokens as es,syncWmapPopupTheme as ts,makePaletteBtn as ns,makeLogScaleBtn as os,makeLegendStyleBtn as is,makeOverlaysBtn as ss,makeOrientationBtn as as,menuLayerFor as ho,saveImageBlob as ls,markMenuTrigger as Ze,wireMenuA11y as yo,wireTooltip as en,requestedPassFailDisplay as bo,overlayMenuRows as rs,anyOverlayActive as cs,openCompactDiagnostics as ds,roomForPanel as wo,logWmapVersionOnce as us,buildDataModeEntries as fs,metadataKeyHasData as ps,metadataModeEntry as gs}from"./toolbar.js";import{openReportModal as ms,openUserGuideWindow as hs}from"./guideWindow.js";import{waferDisplayLabel as ht,waferIdentityLabel as ye}from"../core/waferLabel.js";import{metadataDisplayValue as ys}from"../core/metadata.js";import{withExportContext as bs}from"./exportName.js";import{sortBinsForDisplay as ws}from"../stats/binPareto.js";import{diePassStatus as vs}from"../core/dies.js";import{aggregateValues as Ss,aggregateBinCounts as vo}from"../core/aggregates.js";import{renderWaferMap as Cs,renderWaferMapCard as So,toPublicViewOptions as Co}from"./renderWaferMap.js";import{waferPopulation as xs,selectionPopulation as Ms,LOT_STACK_REASON as tn}from"./chartPopulation.js";import{sourceFromBins as xo}from"./plotItems.js";import{plotStoreFor as ks}from"./plotStore.js";import{classifyChanged as Ds,COLOR_KEYS as Bs,findingBin as Es,findingPlotMode as Ts}from"./renderWaferMap.js";import{findingPatternKey as Mo}from"../stats/filterFindings.js";import{buildWaferMap as Os,getTestPassStatus as ko,isParametricTest as nn,getDieTestValue as Ls}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as yt}from"../stats/analyzeWaferMap.js";import{collectWarnings as Ws,buildWarningsMenuEl as Rs,severityOf as $s}from"./warnings.js";import{asList as on,compareNatural as sn,arrayEqual as bt,toggleHighlight as Do}from"../core/utils.js";import{buildCompactMap as As,compactLayoutOffered as Ps}from"../core/compact.js";import{attachExpandableMetadata as Bo}from"./identityHeader.js";import{createSummaryPanelEl as an,buildMetadataStripRow as Is,metadataEntries as Fs,renderLotSummaryContentSteps as Hs,reportMapsFromItems as js}from"./summaryPanel.js";import{prettyKey as Vs}from"../stats/facets.js";import{testLabel as zs,markedTestLabel as Gs,derivedFields as Ks}from"../renderer/testLabel.js";import{mergeTestDefs as Ns}from"../stats/mergeTestDefs.js";import{getDieKey as wt,hasPosition as _s}from"../core/dies.js";import{testValue as qs}from"../core/dieTable.js";import{runChunked as Xs}from"./chunked.js";function Eo(u){if(typeof u!="number"||!Number.isFinite(u))return;const x=Math.round(u);return x>=1?x:void 0}const ln=12;function Us(u,x,p){let H=x;if(x.length>ln){const M=x.slice(0,ln-1),E=x.slice(ln-1),V=E.reduce((R,ne)=>R+ne.count,0);H=[...M,{color:b.label,count:V,label:`Other (${E.length} bins)`}]}const T=u.createElement("div");Object.assign(T.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:K.control,overflow:"hidden",border:`1px solid ${b.menuBorder}`,boxSizing:"border-box",marginTop:k.xs,flexShrink:"0"}),T.setAttribute("role","img"),T.setAttribute("aria-label",`Population split: ${H.map(M=>`${M.label} ${vt(M.count/p*100)}`).join(", ")}`);for(const M of H){const E=M.count/p*100,V=u.createElement("div");Object.assign(V.style,{flex:`${E} 1 0`,minWidth:E>0?"2px":"0",background:M.color}),en(V,`${M.label} \xB7 ${M.count.toLocaleString()} dies \xB7 ${vt(E)}`),T.appendChild(V)}return T}function vt(u){return u>0&&u<.1?"<0.1%":`${u.toFixed(1)}%`}function To(u,x,p){const H=new Map;let T=0,M=0;for(const E of u){const V=p?new Set(p(E)):void 0;for(const R of E.dies){if(R.partial||R.edgeExcluded)continue;const ne=x(R);ne!==void 0&&(H.set(ne,(H.get(ne)??0)+1),T++,V&&vs(R,V)&&M++)}}return{counts:H,total:T,pass:M}}function Oo(u,x){const p=u.ownerDocument.createElement("div");Object.assign(p.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${k.xxs} ${k.xs}`,borderRadius:K.control});const H=u.ownerDocument.createElement("span");Object.assign(H.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:x.color,border:x.isActive?`2px solid ${b.iconActive}`:`1px solid ${b.menuBorder}`,borderRadius:K.control,boxSizing:"border-box"});const T=u.ownerDocument.createElement("span");if(T.textContent=x.label,Object.assign(T.style,{fontWeight:x.isActive?"700":"400",color:x.isActive?b.iconActive:b.text,whiteSpace:"nowrap"}),p.appendChild(H),p.appendChild(T),x.count!==void 0){const M=u.ownerDocument.createElement("span");if(M.textContent=x.count.toLocaleString(),Object.assign(M.style,{color:x.isActive?b.iconActive:b.text,fontWeight:x.isActive?"700":"400",whiteSpace:"nowrap"}),p.appendChild(M),x.percent!==void 0){const E=u.ownerDocument.createElement("span");E.textContent=vt(x.percent),Object.assign(E.style,{color:b.label,whiteSpace:"nowrap"}),p.appendChild(E)}}if(p.setAttribute("role","button"),p.setAttribute("aria-pressed",x.isActive?"true":"false"),p.tabIndex=0,p.addEventListener("mouseenter",()=>{p.style.background=b.bgHover}),p.addEventListener("mouseleave",()=>{p.style.background="transparent"}),p.addEventListener("focus",()=>{p.style.background=b.bgHover}),p.addEventListener("blur",()=>{p.style.background="transparent"}),p.addEventListener("click",M=>x.onClick(M.ctrlKey||M.metaKey)),p.addEventListener("keydown",M=>{if(M.key==="Enter"||M.key===" ")M.preventDefault(),x.onClick(M.ctrlKey||M.metaKey);else if(x.onMenu&&(M.key==="ContextMenu"||M.key==="F10"&&M.shiftKey)){M.preventDefault();const E=p.getBoundingClientRect();x.onMenu({x:E.left+E.width/2,y:E.bottom},p)}}),x.onMenu){const M=x.onMenu;p.addEventListener("contextmenu",E=>{E.preventDefault(),M({x:E.clientX,y:E.clientY},p)}),en(p,"Right-click: charts and tables for these dies")}u.appendChild(p)}export function renderWaferGallery(u,x,p={}){us();const H=6;let T=Eo(p.columns);const M=p.showHelpButton??!1,E=p.userGuideExtension,V=p.insights?.enabled??!0,R=ks(p.insights),ne={enabled:!1,plotStore:R},Lo=qi(p.zIndex),be=p.summaryPanel,ue=e=>[...Yt(e)],rn=()=>B.flatMap(e=>e?[te(e,"renderWaferGallery")]:[]),St=()=>rn()[0];function Wo(e){const t=[...new Set(e)].sort((n,o)=>n-o);return t.length<2?null:{code:"ring-count-mixed",severity:"warning",message:`These wafers were built with different ring counts (${t.join(", ")}). Each card and each wafer's findings use their own; the lot's ring yield in the Summary panel, report and Insights uses ${e[0]} rings.`}}let N=p.lotStatsSummary,Re=p.viewOptions?.legendPosition??"default",Qe=p.perCardLegend??!1;function $e(){const e=l.plotMode??"hardBin";return go.has(e)?null:l.colorbarRangeMode==="data"?"Each map has its own value range, so it keeps its own colour bar":"These wafers have no shared colour bar for value mode, so each map keeps its own"}function cn(){const e=Qe||$e()!==null;for(const t of C)t&&t.setOptions({showLegend:e})}let l={plotMode:zi(x.flatMap(e=>typeof e=="function"?[]:[e.dies??[]])),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...p.viewOptions},C=[],oe=[],we=[],D=[];const A=bs(()=>{const e=D.filter(n=>n!=null),t=[...new Set(e.map(n=>ys(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort(sn);return{prefix:p.downloadFilename,lots:t,...e.length===1?{wafer:ye(e[0])}:{waferCount:e.length}}},p.onSaveImage,p.onSaveText);let B=x.map(e=>typeof e=="function"?null:e);function ve(){return Ns(B)}function Ae(){if(B.some(e=>e?.testDefs?.length))return ve().defs}let Pe=0,Je=0;const q=new Map;let Ro=0,et=null,Z=null,ie=null,Se=null;function dn(){Z===null&&ie===null&&(Se={plotMode:l.plotMode,activeTest:l.activeTest})}function un(){Se&&W({...Se},{fireCallback:!1}),Se=null}let fn=new Set,v=null,$o={};function pn(e){return B[e]?.statsSummary??N?.perWafer.find(t=>t.waferIndex===e)?.summary}function gn(){return!!(B.some(e=>e?.statsSummary?.findings.length)||N?.perWafer.some(e=>e.summary.findings.length))}const Ao=Xi(),Ce=Ui(Ao),{makeBtn:xe,setActive:mn,makeSep:fe,syncSeparators:Ct,syncToolbarVisible:xt,makeMenuRow:Po,makeMenuSection:Io,makeDropdown:hn,closeOpenMenu:tt,getOpenMenu:Ie,setOpenMenu:Fe}=Ce;u.ownerDocument.addEventListener("click",tt,!0);const yn=()=>mo();window.addEventListener("blur",yn);let bn=p.findingsNotice;function wn(e){fn=new Set(e);const t=[...$.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,i)=>{const s=fn.has(i);o.style.outline=s?`3px solid ${b.findingHighlight}`:"",o.style.outlineOffset=s?"-3px":"",s&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function Mt(){wn([])}let nt=!1;function kt(){nt=!0;for(const e of C)e&&e.clearSelection();nt=!1}function vn(e){return t=>{!nt&&(Z!==null||ie!==null)&&(Se=null,ke(),z()),Et.set(e,t.length),Q&&!He&&!nt&&Fo(e,t),e.onSelect?.(t)}}function se(e,t){e!==void 0&&(C.forEach((n,o)=>{n&&o!==e&&n.locateDie(null)}),C[e]?.locateDie(t),$.querySelectorAll(".wmap-gallery-card")[e]?.scrollIntoView?.({block:"center",behavior:"smooth"}))}let Q=!1,He=!1,pe=new Set;function Fo(e,t){He=!0;try{pe=new Set(t.map(n=>wt(n))),D.forEach((n,o)=>{const i=C[o];!i||!n||n===e||i.setSelection(n.dies.filter(s=>pe.has(wt(s))))})}finally{He=!1}rt()}function Sn(){pe=new Set,He=!0;try{for(const e of C)e?.clearSelection()}finally{He=!1}rt()}function Dt(){if(!Q||pe.size===0)return;const e=[];let t=!1;if(D.forEach((i,s)=>{if(!i)return;const a=i.dies.filter(d=>pe.has(wt(d)));a.length!==0&&(i.isLotStack&&(t=!0),e.push({label:ye(i)??i.label??`Wafer ${s+1}`,dies:a,waferIndex:s,wafer:i.wafer,passBins:ue(i),ringCount:te(i,"renderWaferGallery")}))}),e.length===0)return;const n=ve(),o=l;return{source:{items:e,population:e.length===1?`selected on ${e[0].label}`:`selected at the same die positions on ${e.length} wafers`,testDefs:n.defs,activeTest:o.plotMode==="value"?o.activeTest:void 0,notMeasuredReason:t?tn:void 0},ctx:{plots:R,attributes:p.attributes,onSaveImage:A.onSaveImage,onSaveText:A.onSaveText,onLocateDie:(i,s)=>se(s,i)}}}function Cn(){const e=[];let t=!1;if(D.forEach((o,i)=>{const s=o?C[i]?.getSelectedDies()??[]:[];!o||s.length===0||(o.isLotStack&&(t=!0),e.push({label:ye(o)??o.label??`Wafer ${i+1}`,dies:s,waferIndex:i,wafer:o.wafer,passBins:ue(o),ringCount:te(o,"renderWaferGallery")}))}),e.length<2)return;const n=l;return{source:{items:e,population:`selected on ${e.length} wafers`,testDefs:ve().defs,activeTest:n.plotMode==="value"?n.activeTest:void 0,notMeasuredReason:t?tn:void 0},ctx:{plots:R,attributes:p.attributes,onSaveImage:A.onSaveImage,onSaveText:A.onSaveText,onLocateDie:(o,i)=>se(i,o)}}}function Ho(e){const t=Dt()??kn(e);if(t)return t;const n=Cn(),o=n?.source.items.some(i=>i.waferIndex===e);return n&&o?{...n,narrowable:!0}:void 0}function Bt(e,t,n){Z!==e&&t.click();const o=v;if(!o)return;const i=N?.findings.find(a=>a.id===e),s=Dt()??Cn()??Vo()??(i?xn(Dn(i)):void 0);s&&import("./drilldown.js").then(({openDrilldownMenu:a})=>{o.isConnected&&a(n,o,s.source,{plots:R,attributes:p.attributes,...s.ctx})})}function jo(e,t,n,o){const i=on(l.highlightBin),s=i.length>1&&i.includes(t)?[...i]:[t],a=[];let d=!1;D.forEach((m,S)=>{m&&(m.isLotStack&&(d=!0),a.push({label:ye(m)??m.label??`Wafer ${S+1}`,dies:m.dies,waferIndex:S,wafer:m.wafer,passBins:ue(m),ringCount:te(m,"renderWaferGallery")}))});const r=ve().defs,g=xo(a,e,s,r,void 0,d);if(!g)return;const c={plots:R,attributes:p.attributes,onSaveImage:A.onSaveImage,onSaveText:A.onSaveText,onLocateDie:(m,S)=>se(S,m)},f=s.length>1?xo(a,e,[t],r,void 0,d):null,h=f?{...c,narrower:{label:`Only ${e} bin ${t}`,backLabel:"All filtered bins",source:f,ctx:c}}:c;import("./drilldown.js").then(({openDrilldownMenu:m})=>{o.isConnected&&m(n,o,g,h)})}function xn(e,t=""){const n=[];let o=!1;for(const s of[...e??[]].sort((a,d)=>a-d)){const a=D[s];a&&(a.isLotStack&&(o=!0),n.push({label:ye(a)??a.label??`Wafer ${s+1}`,dies:a.dies,waferIndex:s,wafer:a.wafer,passBins:ue(a),ringCount:te(a,"renderWaferGallery")}))}if(n.length===0)return;const i=l;return{source:{items:n,population:n.length===1?`on ${n[0].label}`:`on ${n.length} ${t}wafers`,testDefs:ve().defs,activeTest:i.plotMode==="value"?i.activeTest:void 0,notMeasuredReason:o?tn:void 0},ctx:{plots:R,attributes:p.attributes,onSaveImage:A.onSaveImage,onSaveText:A.onSaveText,onLocateDie:(s,a)=>se(a,s)}}}function Vo(){let e;for(let i=0;i<C.length;i++)if((C[i]?.getSelectedDies().length??0)!==0){if(e!==void 0)return;e=i}const t=e===void 0?void 0:D[e];if(e===void 0||!t)return;const n=C[e].getSelectedDies(),o=l;return{source:Ms(n,{waferLabel:ye(t),testDefs:t.testDefs,isLotStack:t.isLotStack,activeTest:o.plotMode==="value"?o.activeTest:void 0,waferIndex:e,wafer:t.wafer,passBins:ue(t),ringCount:te(t,"renderWaferGallery")}),ctx:{onSaveImage:A.onSaveImage,onSaveText:A.onSaveText,onLocateDie:(i,s)=>se(s??e,i)}}}function zo(e){e||Sn(),Q=e,rt()}function ot(e,t){const n=new Set(e),o=t??C.map((i,s)=>s);for(const i of o){const s=D[i],a=C[i];if(!s||!a)continue;const d=s.dies.filter(r=>n.has(wt(r)));a.setSelection(d)}}const _=new Set,Et=new Map;function Mn(){[...$.querySelectorAll(".wmap-gallery-card")].forEach((n,o)=>{n.style.outline=_.has(o)?`2px solid ${b.iconActive}`:"",n.style.outlineOffset=_.has(o)?"-2px":""});const t=_.size;X.style.display=t>0?"":"none",X.textContent=`${t} wafer${t===1?"":"s"} picked \u2715`,X.ariaLabel=`${t} wafer${t===1?"":"s"} picked. Click to clear.`}function Go(e){e<0||(_.has(e)?_.delete(e):_.add(e),Mn())}function Ko(){_.clear(),Mn()}function kn(e){if(!(_.size===0||!_.has(e))){for(const t of Et.values())if(t>0)return;return xn([..._],"picked ")}}function No(){const e=[];for(let t=0;t<B.length;t++){const n=B[t];if(!n)continue;const o=pn(t)?.findings??[];o.length&&e.push({index:t,item:n,unusualCount:o.filter(i=>i.severity==="unusual").length,notableCount:o.filter(i=>i.severity==="notable").length,totalCount:o.length})}return e}function _o(e){const t=D[e]??B[e];t&&Xe(e,t)}function qo(e){const t=pn(e)?.findings??[];if(t.length)return{total:t.length,unusual:t.filter(n=>n.severity==="unusual").length,notable:t.filter(n=>n.severity==="notable").length}}function Xo(){import("../stats/renderSummaryReport.js").then(({renderLotReportHtml:e})=>{ms(e(js(B,St())),{anchor:u})})}function Uo(){if(!v)return;v.innerHTML="";const e=No();if(B.length>0){const n=u.ownerDocument.createElement("div"),o=e.length,i=B.filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${i} wafers`:`${o} of ${i} wafer${i===1?"":"s"} with findings`,Object.assign(n.style,{fontSize:j.body,color:b.label,marginBottom:k.md}),v.appendChild(n)}if(e.length>0){const n=u.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...Ki("outlined"),marginBottom:k.lg,display:"block",width:"100%",textAlign:"left"}),Jt(n),n.addEventListener("click",Xo),v.appendChild(n)}if(e.length===0){const n=u.ownerDocument.createElement("div");Object.assign(n.style,{color:b.icon,fontSize:j.body,padding:"4px 0"}),n.textContent="No findings on any wafer.",v.appendChild(n)}else for(const{index:n,item:o,unusualCount:i,notableCount:s,totalCount:a}of e){const d=i?"unusual":s?"notable":"info",r=i+s||a,g=u.ownerDocument.createElement("button");g.type="button",Object.assign(g.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:k.xs,border:"none",borderLeft:`3px solid ${po(d)}`,borderRadius:K.control,background:b.bgHover,cursor:"pointer",fontSize:j.body,textAlign:"left",boxSizing:"border-box"}),g.addEventListener("mouseover",()=>{g.style.background=b.bgActive}),g.addEventListener("mouseout",()=>{g.style.background=b.bgHover});const c=u.ownerDocument.createElement("span");c.textContent=ht(o,n),Object.assign(c.style,{color:b.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const f=u.ownerDocument.createElement("span");f.textContent=String(r),g.setAttribute("aria-label",`${ht(o,n)} \u2014 ${r} finding${r===1?"":"s"}${i?`, ${i} unusual`:""} \u2014 view wafer`),Object.assign(f.style,{marginLeft:k.sm,flexShrink:"0",background:po(d),color:"#fff",borderRadius:K.container,padding:"1px 5px",fontSize:j.body,fontWeight:"600"}),g.appendChild(c),g.appendChild(f),g.addEventListener("click",()=>Xe(n,o)),v.appendChild(g)}const t=u.ownerDocument.createElement("div");t.style.height="12px",v.appendChild(t)}let Me=null,je=null;function z(){if(v)if(Me?.cancel(),Me=null,N){const e=mt(B.map(n=>n?.hbinDefs)),t=mt(B.map(n=>n?.sbinDefs));Me=Xs(Hs(v,{lotSummary:N,items:B,hbinDefs:e.length?e:void 0,sbinDefs:t.length?t:void 0,testDefs:Ae(),ringCount:St(),binColors:l.binColors,plotMode:l.plotMode??"hardBin",fallbackFormat:l.fallbackFormat,activeFindingId:Z,warnings:p.warnings?.display??!0?ae:[],findingsFilter:$o,findingsNotice:bn,onFindingsFilterChange:z,onSaveText:A.onSaveText,onFindingClick:(n,o)=>{Z===n.id?(ke(),un()):(dn(),Zo(n,o)),z()},activeTest:ie,onTestClick:n=>{const o=ie===n;o||dn(),ke(),o?un():Yo(n),z()},onWaferClick:_o,findingsFor:qo,dieListOptions:p.dieList,onLocateDie:(n,o)=>se(o,n),onClose:()=>On(!1)}),{onDone:()=>{const n=je;je=null,n?.()}})}else Uo()}function Dn(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}let it=[];function Bn(){if(it.length!==0){for(const e of it)C[e]?.setOptions({plotMode:l.plotMode,activeTest:l.activeTest});it=[]}}function ke(){Z=null,ie=null,Mt(),kt(),Bn(),W({highlightBin:void 0},{fireCallback:!1})}function En(){Z===null&&ie===null||(Se=null,ke(),z())}function Tn(e,t){const n=Ae();if(n===void 0||n.some(i=>i.testNumber===e))W({plotMode:"value",activeTest:e,highlightBin:void 0},{fireCallback:!1});else{W({highlightBin:void 0},{fireCallback:!1});const s=he.has(l.plotMode??"hardBin")?null:t;if(s){for(const a of s)C[a]?.setOptions({plotMode:"value",activeTest:e});it=[...s]}}}function Yo(e){ie=e;const t=o=>D[o]?.statsSummary?.stats.testFailures?.[e]?.dieKeys,n=D.map((o,i)=>i).filter(o=>t(o)?.length);if(Tn(e,n.length?n:null),Mt(),kt(),!he.has(l.plotMode??"hardBin"))for(const o of n)ot(t(o),[o])}function Zo(e,t){if(Z===e.id){ke();return}Z=e.id,ie=null,t.style.background=b.bgActive,t.style.fontWeight="600",Bn();const{kind:n,index:o}=e.variable;if(n==="test")Tn(o??0,Dn(e));else{const s=D.some(d=>d?.dies?.some(r=>r.hbin!=null)),a=uo(D.map(d=>d?Yt(d):void 0));W({plotMode:Ts(e,l.plotMode,s),highlightBin:Es(e,a,s)},{fireCallback:!1})}Mt(),kt();const i=e.highlight;if(i.kind==="wafer"){wn(i.waferIndices);const s=Mo(e);for(const a of i.waferIndices){const d=i.dieKeysByWafer?void 0:D[a]?.statsSummary?.findings.find(g=>Mo(g)===s),r=i.dieKeysByWafer?.[a]??d?.highlight?.dieKeys;r?.length&&ot(r,[a])}}else i.kind==="bin"?i.dieKeys?.length&&ot(i.dieKeys):(i.kind==="region"||i.kind==="dies")&&i.dieKeys?.length&&ot(i.dieKeys)}function Tt(){return!!v&&v.style.display!=="none"}function On(e){!v||e===Tt()||(e&&z(),v.style.display=e?"flex":"none",ge())}function ge(){et&&(Ct(P),xt(P,"inline-flex"),et.sync({visible:!!(N||gn())&&!!v&&!dt,open:Tt(),notable:!!(N?.hasNotableFindings||B.some(e=>e?.statsSummary?.hasNotableFindings))}))}const P=u.ownerDocument.createElement("div");P.dataset.wmapToolbar="gallery",Object.assign(P.style,{flexShrink:"0",marginLeft:"auto",display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:K.control,padding:"0",boxShadow:Qt.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const Ln=()=>{const e=Ie();e&&(e.remove(),Fe(null)),Ze(J,!1)},J=xe("mode","Plot mode",()=>{if(Ie()){Ln();return}const e=B.flatMap(w=>w?.dies??[]),t=Ae(),{testEntries:n,binEntries:o,stackedEntries:i}=fs(e,t,{includeStacked:!0}),s=B.filter(Boolean).length,a=w=>{if(w===void 0)return s;let L=0;for(const I of B)I?.dies?.some(F=>ko(F,w)!==void 0||qs(F,w)!==void 0)&&L++;return L},d=s<2?n:n.map(w=>{const L=a(w.activeTest);return L===s?w:{...w,label:`${w.label} \u2014 ${L} of ${s} wafers`}}),r=l.plotMode??"hardBin",g=l.activeTest??0;function c(w){return w.plotMode!==r?!1:w.plotMode==="value"?g===(w.activeTest??0):w.plotMode==="metadata"?l.activeMetadataKey===w.activeMetadataKey:!0}function f(w,L){w.activeTest!==void 0?W({plotMode:"value",activeTest:w.activeTest,activeMetadataKey:void 0,logScale:w.logScale}):w.activeMetadataKey!==void 0?W({plotMode:w.plotMode,activeTest:void 0,activeMetadataKey:w.activeMetadataKey,passFailDisplay:"off"}):W({plotMode:w.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),L.remove(),Fe(null),Ze(J,!1)}const h=new Set,m=B.flatMap(w=>w?.metadataFields??[]).filter(w=>!h.has(w.key)&&h.add(w.key)).filter(w=>ps(e,w.key)).map(gs),S=Yi(J.getBoundingClientRect(),d,o,i,c,f,{makeMenuRow:Po,makeMenuSection:Io},r,J.ownerDocument.defaultView??window,m);ho(J).appendChild(S),Fe(S),Ze(J,!0),yo(S,J,Ln)});Ze(J,!1);const Qo=()=>D.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:Jo,sync:Wn}=ns(Ce,()=>({...l,plotMode:l.plotMode??"hardBin"}),Qo,e=>W(e));Wn();const ei=x.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function st(){const e=Ae(),{testNumber:t}=Li(l.activeTest??0,e);return{testNumber:t,td:Wi(e,t)}}function Rn(){if((l.plotMode??"hardBin")!=="value")return!1;const{td:e}=st();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function Ve(){if((l.plotMode??"hardBin")!=="value")return!1;const{td:e}=st();return e!==void 0&&!nn(e)}function ti(){if((l.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=st();return B.some(n=>n?.dies?.some(o=>ko(o,e,t)!==void 0))}function ni(e,t){if(!t||!nn(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((bo(l)==="spec"&&n?"spec":l.colorbarRangeMode??"spec")==="spec"&&n)return;let s=1/0,a=-1/0;for(const d of B)if(d)for(const r of d.dies){const g=Ls(r,e);g!==void 0&&(g<s&&(s=g),g>a&&(a=g))}if(isFinite(s))return s===a?[s,s+1]:[s,a]}function at(e,t,n){const o=l[e];if(o===t||o!=null&&t!=null&&n(o,t))return!1;l={...l,[e]:t};for(const i of C)i&&i.setOptions({[e]:t});return!0}function $n(){if((l.plotMode??"hardBin")!=="metadata")return;const e=l.activeMetadataKey;if(!e)return;const t=new Set;for(const n of B)if(n)for(const o of Ri(n.dies,e))t.add(o);return{key:e,values:[...t].sort(sn)}}function Ot(){at("metadataValueOrder",$n(),(e,t)=>e.key===t.key&&bt(e.values,t.values))}function Lt(){if((l.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=st(),n=ni(e,t);at("valueRange",n?{test:e,range:n}:void 0,(i,s)=>{const a=g=>Array.isArray(g)?{test:void 0,range:g}:{test:g.test,range:g.range},d=a(i),r=a(s);return d.test===r.test&&bt(d.range,r.range)})}let Wt=!1;function oi(){if(Wt)return;Wt=!0,(u.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{Wt=!1,Lt(),Ot(),Fn(),In()})}let Rt=!1;function ii(){if(Rt)return;Rt=!0,(u.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{Rt=!1,pt()})}let An=[];function De(){const{colors:e,mixedHardBins:t}=Ai(B.filter(n=>n!=null),{binColorScheme:l.binColorScheme,useDefinedBinColors:l.useDefinedBinColors});return An=t,e}function $t(){return D.filter(e=>e!=null).flatMap(e=>e.dies)}function Pn(){return l.compact?As($t()):void 0}const si=(e,t)=>bt(e.columns,t.columns)&&bt(e.rows,t.rows);function In(){at("compactMap",Pn(),si)&&Zn()}function ai(){return Ps($t(),D.filter(e=>e!=null).map(e=>e.reticleConfig))}function Fn(){at("binColors",De(),Fi),Ge()}const li=ss(Ce,()=>rs(l,ei,{functionalActive:Ve(),hasLimits:Rn()&&!Ve(),hasRecorded:ti()&&!Ve(),binMode:(l.plotMode??"hardBin")==="hardBin"||(l.plotMode??"hardBin")==="softBin"},e=>W(e),{on:!!l.compact,offered:ai(),onChange:e=>W({compact:e}),onDiagnostics:()=>ds($t(),D.filter(e=>e!=null).map(e=>e.reticleConfig),{anchor:u,onSaveText:A.onSaveText})}),()=>cs(l)),{btn:ri,sync:Hn}=is(Ce,()=>({plotMode:l.plotMode,legendPosition:Re}),e=>{Re=e;for(const t of C)t&&t.setOptions({legendPosition:Re})},{get:()=>Qe,set:e=>{Qe=e,cn()},blockedReason:$e});Hn();const ci=[{value:"mean",label:"Mean"},{value:"median",label:"Median"},{value:"stddev",label:"Std Dev"},{value:"min",label:"Min"},{value:"max",label:"Max"},{value:"count",label:"Count"}],jn=hn("aggr","Aggregation method",()=>ci,()=>l.aggregationMethod??"mean",e=>W({aggregationMethod:e}));function Vn(){const e=l.plotMode==="stackedValues";jn.style.display=e?"":"none"}Vn();const{btn:di,sync:zn}=os(Ce,()=>({...l,functionalActive:Ve()}),e=>W(e));zn();const lt=xe("specRange","Colorbar range: test limits",()=>{const e=l.colorbarRangeMode==="data"?"spec":"data";W({colorbarRangeMode:e})});function Gn(){const e=(l.plotMode??"hardBin")==="value"&&Rn()&&bo(l)==="off"&&!Ve();lt.style.display=e?"":"none";const t=(l.colorbarRangeMode??"spec")==="spec";mn(lt,t),lt.ariaLabel=t?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"}Gn();const ui=as(Ce,()=>l,e=>W(e)),fi=xe("downloadAll","Download gallery PNG",ki),Be=xe("boxSelect","Select the same dies on every wafer",()=>{Q&&pe.size>0?Sn():zo(!Q)});Be.style.position="relative";const ze=u.ownerDocument.createElement("span");ze.dataset.wmapSelectAcrossCount="1",Object.assign(ze.style,{position:"absolute",top:"0",right:"0",minWidth:"14px",height:"14px",boxSizing:"border-box",padding:"0 3px",borderRadius:K.pill,background:b.iconActive,color:b.menuBg,fontSize:"11px",lineHeight:"14px",fontWeight:"700",textAlign:"center",pointerEvents:"none",display:"none"}),Be.appendChild(ze);function rt(){mn(Be,Q);const e=Q?pe.size:0;ze.style.display=e>0?"block":"none",ze.textContent=e>99?"99+":String(e),Be.ariaLabel=Q?e>0?`Select the same dies on every wafer: on, ${e.toLocaleString()} die position${e===1?"":"s"} selected (click to clear the selection)`:"Select the same dies on every wafer: on (click to turn off)":"Select the same dies on every wafer: off (click to turn on)",Be.setAttribute("aria-pressed",String(Q))}const X=u.ownerDocument.createElement("button");X.type="button",X.dataset.wmapPickedWafers="1",Object.assign(X.style,{display:"none",border:"none",background:b.bgActive,color:b.iconActive,borderRadius:K.control,padding:`${k.xs} ${k.md}`,fontSize:j.body,cursor:"pointer",whiteSpace:"nowrap",flexShrink:"0"}),Jt(X,"bare"),X.addEventListener("click",Ko);const pi=hn("columns","Columns",()=>[{value:"auto",label:"Auto"},{value:"1",label:"1 column"},{value:"2",label:"2 columns"},{value:"3",label:"3 columns"},{value:"4",label:"4 columns"},{value:"5",label:"5 columns"}],()=>T!=null?String(T):"auto",e=>eo(e==="auto"?void 0:Number(e))),O=u.ownerDocument.createElement("div");Object.assign(O.style,{display:"inline-flex",alignItems:"center",gap:"0"}),P.appendChild(O),O.appendChild(J),O.appendChild(Jo),O.appendChild(jn),O.appendChild(di),O.appendChild(lt),O.appendChild(fe()),O.appendChild(li),O.appendChild(fe()),O.appendChild(ri),O.appendChild(fe()),O.appendChild(ui),O.appendChild(fe()),O.appendChild(pi),O.appendChild(fe()),O.appendChild(Be),O.appendChild(X),O.appendChild(fi),rt();let U=null,ct=null,ae=[],Kn=!1;function Ge(){const e=Ws({lotStatsSummary:N,result:{warnings:[...B.flatMap(n=>n?.warnings??[]),...ve().warnings]},extra:[l.binColors&&Pi(l.binColors,l.plotMode),Ii(An),Wo(rn())].filter(n=>!!n)}),t=e.length!==ae.length||e.some((n,o)=>n.code!==ae[o]?.code||n.message!==ae[o]?.message);ae=e,(t||!Kn)&&(Kn=!0,p.warnings?.onWarning?.(e)),gi()}function gi(){if(!U||!ct)return;const e=ae.length,t=e>0;if(U.style.display=t?"flex":"none",ct.style.display=t?"":"none",Ct(P),xt(P,"inline-flex"),!t)return;const n=$s(ae[0]),o=`${e} data ${e===1?"warning":"warnings"}`;U.style.color=n==="error"?b.errText:b.warnText,U.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(p.warnings?.display??!0)&&(ct=fe(),U=xe("warning","Data warnings",()=>{const e=Ie();if(tt(new MouseEvent("click")),e)return;const t=Rs(U.getBoundingClientRect(),ae,U.ownerDocument.defaultView??window);ho(u).appendChild(t),Fe(t),yo(t,U,()=>tt(new MouseEvent("click")))}),Ze(U,!1),P.appendChild(ct),P.appendChild(U)),Ge();function Nn(){import("./userGuideHtml.js").then(e=>hs({buildWaferMap:Os,renderWaferMap:Cs,renderWaferGallery,analyzeWaferMap:yt},e.USER_GUIDE_HTML,E,u))}M&&(P.appendChild(fe()),P.appendChild(xe("help","User guide",()=>Nn())));const Ee=u.ownerDocument.createElement("div");Ee.dataset.wmapGalleryMeta="1",Object.assign(Ee.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${k.sm} ${k.lg}`,fontSize:j.sub,lineHeight:fo.none,boxSizing:"border-box"});const Te=u.ownerDocument.createElement("div");Object.assign(Te.style,{background:b.canvasBg,display:"flex",alignItems:"stretch",gap:k.lg,paddingBottom:k.lg,minWidth:"0"});const le=u.ownerDocument.createElement("div");le.dataset.wmapGalleryLegend="1",Object.assign(le.style,{display:"flex",flexDirection:"column",gap:k.sm,background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:K.container,padding:`${k.sm} ${k.lg}`,marginBottom:k.lg,boxShadow:Qt.panel,fontSize:j.body,lineHeight:fo.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const Y=u.ownerDocument.createElement("div");Object.assign(Y.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let Oe=null,Ke=null,_n=null;function mi(){return V?Oe?Promise.resolve(Oe):(_n??=import("./insightsTab.js").then(({createInsightsTab:e})=>(Oe=e({attributes:p.attributes,getItems:()=>B,getLotStats:()=>N,getBinColors:()=>l.binColors??De(),getRingCount:()=>te({ringCount:St()},"the Insights tab"),defaultView:p.insights?.defaultView,plotStore:R,onPickPlotsFile:p.insights?.onPickPlotsFile,onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:A.onSaveImage,onSaveText:A.onSaveText,ownerDocument:u.ownerDocument,locateDie:(t,n)=>{Pt(!1),se(n,t)},openWafer:(t,n,o)=>{const i=B[t];if(!i)return;let s=null;const a=Ji({title:n,onClose:()=>s?.destroy(),anchor:u});oo(a,n,i.wafer.metadata??void 0),s=Nt(a.contentWrap,i,o,void 0,wo(a))}}),Ke=Oe.el,Ke.style.display="none",u.appendChild(Ke),Oe)),_n):Promise.resolve(null)}let dt=!1,At=null;function Pt(e){V&&(dt=e,At?.setInsightsOpen(e),Ke&&(Ke.style.display=e?"flex":"none"),Y.style.display=e?"none":"flex",O.style.display=e?"none":"inline-flex",Ct(P),xt(P,"inline-flex"),P.style.display="inline-flex",ge(),pt(),e&&mi().then(t=>{!t||!dt||(t.el.style.display="flex",t.render())}))}V&&p.insights?.defaultOpen&&queueMicrotask(()=>Pt(!0));const qn=4,ut=240,It=480,hi=720,yi=1.25;let me=It;function Xn(e){const t=H*2+110+2,n=Un();if(n)return Math.ceil(n.across*qn+t);let o=null;for(const i of e){if(i==null||!i.dies?.length)continue;const s=i.dies[0].width;if(!(s>0))continue;const a=i.wafer.radius*2*(qn/s),d=Math.ceil(a+t);(o==null||d>o)&&(o=d)}return o}function bi(e){const t=Xn(e);return t==null?ut:Math.min(me,Math.max(ut,t))}function wi(e){const t=Xn(e);if(t==null)return!1;const n=Math.min(hi,Math.max(It,t));return n<=me?!1:(me=n,!0)}function Un(){const e=l.compact?l.compactMap:void 0,t=D.find(i=>i?.dies?.length)?.dies[0];if(!e||!t||e.columns.length===0||e.rows.length===0||!(t.width>0)||!(t.height>0))return;const n=(l.rotation??0)%180!==0,o=l.showXYIndicator?2.5:0;return{across:(n?e.rows.length:e.columns.length)+o,down:(n?e.columns.length:e.rows.length)+o,cellAspect:n?t.height/t.width:t.width/t.height}}function Yn(e,t){const n=Un();if(!n){e.style.aspectRatio="1",t.style.flex="1",t.style.width="",t.style.aspectRatio="";return}e.style.aspectRatio="auto",t.style.flex="none",t.style.width="100%",t.style.aspectRatio=String(n.across*n.cellAspect/n.down)}function vi(){for(const e of oe)e?.parentElement&&Yn(e.parentElement,e)}function Zn(){me=It,Ne=ut,jt(D.map(e=>e??null)),ft(),vi()}function Ft(){return Qn()?`${me}px`:"none"}function Qn(){return T==null&&!Ht}let Ht=!1;function ft(){const e=Ft();for(const t of Array.from($.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let Ne=ut,Jn=0;function jt(e){if(wi(e)&&ft(),T==null){const n=bi(e);n>Ne&&(Ne=n)}zt()}function eo(e){T=Eo(e),ft(),zt()}function Vt(e){return`repeat(${e}, minmax(0, ${Qn()?`${me}px`:"1fr"}))`}function to(e){$.style.gridTemplateColumns!==e&&($.style.gridTemplateColumns=e)}function zt(){if(T!=null){to(Vt(T));return}const e=Math.max(1,Jn),t=12,n=$.clientWidth||0,o=a=>(n-t*(a-1))/a;let i=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const a=Math.min(me,Ne*yi),d=r=>{let g=0;for(;g<e&&o(g+1)>=r;)g++;return g};i=d(a)||d(Ne)||1}const s=n>0&&i<e;s!==Ht&&(Ht=s,ft()),to(Vt(i))}const $=u.ownerDocument.createElement("div");if(Object.assign($.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:Vt(1),gap:k.xl,paddingLeft:de,paddingRight:de,justifyContent:"start",alignContent:"start",isolation:"isolate"}),be?.placement){const e=be.placement;v=an(e,de,u.ownerDocument,Bt),v.style.maxHeight="calc(100vh - 80px)",v.style.position="sticky",v.style.top="8px",v.style.display="flex",v.style.flexDirection="column"}else if(N||gn()){const e=!!be?.defaultOpen;v=an("right",de,u.ownerDocument,Bt),v.style.maxHeight="calc(100vh - 80px)",v.style.position="sticky",v.style.top="8px",v.style.flexDirection="column",v.style.display=e?"flex":"none",z()}ge(),(be?.placement??"right")==="left"?(v&&Y.appendChild(v),Y.appendChild($)):(Y.appendChild($),v&&Y.appendChild(v));const _e=u.ownerDocument.createElement("div");Object.assign(_e.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:de,paddingRight:de,paddingTop:de,zIndex:"1",background:b.menuBg}),Te.appendChild(Ee),Te.appendChild(P),et=Ti(u.ownerDocument,()=>On(!Tt())),Te.appendChild(et.el),ge(),V&&(At=Ei(u.ownerDocument,"Maps","lot",e=>Pt(e)),Te.appendChild(At.el)),_e.appendChild(Te),_e.appendChild(le),u.appendChild(_e),u.appendChild(Y);function pt(){le.innerHTML="";const e=l.plotMode??"hardBin",t=!dt&&go.has(e),n=D.filter(y=>y!=null),o=n.find(y=>y.isLotStack),i=Is(n.map(y=>({metadata:y.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0,{curation:p.attributes}),s=e==="metadata",a=l.activeMetadataKey,d=t&&!s?To(n,y=>(e==="softBin"?y.sbin:y.hbin)??void 0,ue):{counts:new Map,total:0,pass:0},r=t&&!s?l.binColors??De():void 0,g=r?e==="softBin"?r.pass.soft:r.pass.hard:new Set,c=ws(d.counts.entries(),g).map(([y])=>y),f=t&&s&&a?To(n,y=>$i(y.metadata?.[a])):{counts:new Map,total:0,pass:0},h=s?$n()?.values:void 0,m=t&&s?(h??[...f.counts.keys()].sort(sn)).filter(y=>f.counts.has(y)):[];if(Ee.innerHTML="",i&&Ee.appendChild(i),Ee.style.display=i?"flex":"none",!c.length&&!m.length){le.style.display="none";return}le.style.display="flex";const S=u.ownerDocument.createElement("div");Object.assign(S.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${k.sm} ${k.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),le.appendChild(S);const w=on(l.highlightBin),L=D.flatMap(y=>y?.metadataFields??[]).find(y=>y.key===a),I=s?L?.label??(a?Vs(a):"Metadata"):_i[e],F=u.ownerDocument.createElement("span");if(F.textContent=I,Object.assign(F.style,{fontSize:j.body,fontWeight:"700",letterSpacing:Gi,textTransform:"uppercase",color:b.label,flexShrink:"0"}),S.appendChild(F),!s&&d.total>0){const y=d.pass,G=y/d.total*100,re=u.ownerDocument.createElement("span");re.textContent=`Yield ${vt(G)}`,Object.assign(re.style,{fontSize:j.body,fontWeight:"700",color:b.value,whiteSpace:"nowrap",flexShrink:"0"});const ce=u.ownerDocument.createElement("span");ce.textContent=`${y.toLocaleString()} / ${d.total.toLocaleString()} dies`,Object.assign(ce.style,{fontSize:j.body,color:b.label,whiteSpace:"nowrap",flexShrink:"0"}),S.appendChild(re),S.appendChild(ce)}if(s){const y=on(l.highlightMetadataValue);m.forEach((G,re)=>{const ce=y.includes(G),We=L?.values?.find(Ut=>Ut.value===G),Ye=We?.color??ji(re),co=f.counts.get(G)??0;Oo(S,{color:Ye,isActive:ce,label:We?.label??G,count:co,percent:f.total>0?co/f.total*100:void 0,onClick:Ut=>{const Bi=Do(l.highlightMetadataValue,G,Ut);En(),W({highlightMetadataValue:Bi})}})});return}const Ue=e==="softBin"?D.flatMap(y=>y?.sbinDefs??[]):D.flatMap(y=>y?.hbinDefs??[]),ao=new Set,qt=[];for(const y of Ue)ao.has(y.bin)||(ao.add(y.bin),qt.push(y));const Xt=qt.length>0?new Map(qt.map(y=>[y.bin,y])):null,lo=r??l.binColors??De(),Di=e==="softBin"?lo.soft:lo.hard,ro=y=>Di.get(y)??Hi;for(const y of c){const G=w.includes(y),re=Xt?.get(y),ce=d.counts.get(y)??0;Oo(S,{color:ro(y),isActive:G,label:re?.name?`${y} \xB7 ${re.name}`:`Bin ${y}`,count:ce,percent:d.total>0?ce/d.total*100:void 0,onMenu:(We,Ye)=>jo(e==="softBin"?"soft":"hard",y,We,Ye),onClick:We=>{const Ye=Do(l.highlightBin,y,We);En(),W({highlightBin:Ye})}})}d.total>0&&c.length>1&&le.appendChild(Us(u.ownerDocument,[...d.counts.entries()].sort(([,y],[,G])=>G-y).map(([y,G])=>({color:ro(y),count:G,label:Xt?.get(y)?.name?`${y} \xB7 ${Xt.get(y).name}`:`Bin ${y}`})),d.total))}function qe(e){const t=B.filter(c=>c!==null);if(!t.length)return[];const n=t.map(c=>c.dies.filter(_s)),o=t[0].wafer,i=t.length,s=uo(t.map(c=>Yt(c)));if(!s)return[];const a=new Set(t.map(c=>te(c,"renderWaferGallery")));if(a.size!==1)return[];const d=[...a][0],r=o.metadata?{...o,metadata:(({wafer:c,waferId:f,...h})=>h)(o.metadata)}:o;function g(c,f){return{...c,stats:{...c.stats,isLotStack:!0,aggregationMethod:f,lotSize:i}}}if(e==="stackedValues"){const c=Ae();let f=c?.filter(nn);if(c!==void 0&&f?.length===0)return[];if(c?.length||(f=Oi(t.flatMap(S=>S.dies)).map(S=>({testNumber:S,name:zs(void 0,S)}))),!f?.length)return[];const h=l.aggregationMethod??"mean";return f.map(m=>{const S=Ss(n,h,m.testNumber),w={testNumber:0,name:m.name,unit:m.unit,...Ks(m)};return{wafer:r,dies:S,passBins:[...s],ringCount:d,testDefs:[w],label:`${Gs(m,m.testNumber)} \xB7 ${h}`,isLotStack:!0,aggrMethod:h,lotSize:i,statsSummary:g(yt({wafer:r,dies:S,passBins:[...s],ringCount:d,testDefs:[w]},{testNumbers:[0]}),h)}})}if(e==="stackedBins"){let c=mt(t.map(f=>f?.hbinDefs));return(!c||c.length===0)&&(c=[...new Set(t.flatMap(h=>h.dies.map(m=>m.hbin).filter(m=>m!=null)))].sort((h,m)=>h-m).map(h=>({bin:h,name:`Bin ${h}`}))),c.map(f=>{const h=vo(n,f.bin,"hard"),m=[{bin:f.bin,name:f.name}];return{wafer:r,dies:h,passBins:[...s],ringCount:d,hbinDefs:m,label:`${f.bin} \xB7 ${f.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:g(yt({wafer:r,dies:h,passBins:[...s],ringCount:d,hbinDefs:m}),"countBin")}})}if(e==="stackedSoftBins"){let c=mt(t.map(f=>f?.sbinDefs));return(!c||c.length===0)&&(c=[...new Set(t.flatMap(h=>h.dies.map(m=>m.sbin).filter(m=>m!=null)))].sort((h,m)=>h-m).map(h=>({bin:h,name:`Bin ${h}`}))),c.map(f=>{const h=vo(n,f.bin,"soft"),m=[{bin:f.bin,name:f.name}];return{wafer:r,dies:h,passBins:[...s],ringCount:d,sbinDefs:m,label:`${f.bin} \xB7 ${f.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:g(yt({wafer:r,dies:h,passBins:[...s],ringCount:d,sbinDefs:m}),"countBin")}})}return t}function Gt(e){const t=B.length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:l.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}function W(e,{fireCallback:t=!0}={}){const n=Object.keys(e),o=l.plotMode,i=$e()!==null;l={...l,...e};const s=l.plotMode,a=he.has(s),d=o!==void 0&&he.has(o),r=Je>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const c=De();l={...l,binColors:c},e={...e,binColors:c}}if("compact"in e){const c=Pn();l={...l,compactMap:c},e={...e,compactMap:c}}if(("compact"in e||l.compact&&("rotation"in e||"showXYIndicator"in e))&&Zn(),e.plotMode!==void 0)if(a){const c=Gt(s);if(l={...l,...c},r)for(const f of C)f&&f.setOptions(e);else ee(qe(s))}else if(d){const{valueRange:c,lotSize:f,aggregationMethod:h,...m}=l;if(l=m,r)for(const S of C)S&&S.setOptions(e);else ee(B.filter(S=>S!==null))}else for(const c of C)c&&c.setOptions(e);else if(e.aggregationMethod!==void 0&&s==="stackedValues")if(r)for(const c of C)c&&c.setOptions(e);else ee(qe("stackedValues"));else for(const c of C)c&&c.setOptions(e);$e()!==null!==i&&cn(),pt(),Vn(),Hn(),Wn();const g=e.plotMode!==void 0&&e.plotMode!==o;(Bs.some(c=>c in e)||g)&&z(),Ge(),zn(),Gn(),Lt(),Ot(),t&&p.onViewOptionsChange?.(Co(l),n,Ds(n))}function no(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:k.xs,flex:"1",minWidth:"0"});const i=e.createElement("span");i.textContent=t,Object.assign(i.style,{fontWeight:"700",fontSize:j.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(i);const s=Bo(e,o,t,n,p.attributes);return{wrap:o,metaPanel:s}}function oo(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]");if(!o||Fs(n??{}).length===0)return;const i=o.parentElement,s=u.ownerDocument.createElement("div");Object.assign(s.style,{display:"flex",alignItems:"center",gap:k.xs,flex:"1",minWidth:"0"}),i?.insertBefore(s,o),s.appendChild(o);const a=Bo(u.ownerDocument,s,t,n,p.attributes);a&&(e.contentWrap.style.position="relative",e.contentWrap.appendChild(a))}function Kt(e,t,n){const o=u.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:K.container,boxShadow:Qt.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:Ft(),maxHeight:Ft()});const i=u.ownerDocument.createElement("div");Object.assign(i.style,{display:"flex",alignItems:"center",padding:`${k.md} ${k.lg} ${k.sm}`,borderBottom:`1px solid ${b.menuBorder}`,flexShrink:"0",gap:k.sm});const{wrap:s,metaPanel:a}=no(document,ht(e,t),e.wafer.metadata??void 0);i.appendChild(s);const d=u.ownerDocument.createElement("button");d.dataset.wmapExpandBtn="1",d.setAttribute("aria-label","Open full view"),en(d),d.innerHTML=Zt.expand,Object.assign(d.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${b.menuBorder}`,borderRadius:K.control,background:b.panelBg,color:b.label,padding:k.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),Jt(d),i.appendChild(d),i.addEventListener("click",h=>{(h.ctrlKey||h.metaKey)&&(h.preventDefault(),h.stopPropagation(),Go(D.indexOf(e)))},!0),o.appendChild(i);const r=u.ownerDocument.createElement("div");Object.assign(r.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(r),Yn(o,r),a&&r.appendChild(a),$.appendChild(o),o.addEventListener("contextmenu",h=>{if(h.defaultPrevented)return;h.preventDefault();const m=e.viewOptions?{...l,...e.viewOptions}:l,S=Dt()??kn(t),w=S?.source??xs(e.dies,{waferLabel:ye(e),testDefs:e.testDefs,isLotStack:e.isLotStack,activeTest:m.plotMode==="value"?m.activeTest:void 0,waferIndex:t,wafer:e.wafer,passBins:ue(e),ringCount:te(e,"renderWaferGallery")}),L={x:h.clientX,y:h.clientY};import("./drilldown.js").then(({openDrilldownMenu:I})=>{o.isConnected&&I(L,o,w,S?{plots:R,attributes:p.attributes,...S.ctx}:{plots:R,attributes:p.attributes,onSaveImage:f.getSaveImageHook(),onSaveText:f.getSaveTextHook(),onLocateDie:F=>se(t,F)})})});const g=Qe||$e()!==null,c=e.viewOptions?{...l,...e.viewOptions}:l,f=So(r,e,{viewOptions:{...c,showLegend:g,legendPosition:Re},showTooltip:!0,padding:H,statsSummary:e.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,downloadFilename:p.downloadFilename,onClick:e.onClick,onSelect:vn(e),drilldownSourceOverride:()=>Ho(t),insights:ne,onExpand:()=>Xe(t,e),showIdentity:!1,chromeInset:Ni,drawWhenVisible:!0});return f.setViewControlsVisible(!1),f.setSummaryVisible(!1),d.onclick=()=>Xe(t,e),{card:o,ctrl:f,canvasWrapper:r,expandBtn:d}}function Si(e){const t=we[e];if(!t)return;const n=[...q.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=Zt.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>xi(n.id)):(t.innerHTML=Zt.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>Xe(e,D[e]))}function ee(e){Mi(),Ie()?.remove(),Fe(null),ke(),D=[],_.clear(),Et.clear(),X.style.display="none";for(const r of C)r&&r.destroy();C=[],oe=[],we=[],Je=0,$.innerHTML="",Jn=e.length,jt(e.map(r=>typeof r=="function"?null:r));const t=[];for(let r=0;r<e.length;r++){const g=e[r];if(typeof g=="function"){const c=u.ownerDocument.createElement("div");c.className="wmap-gallery-card",Object.assign(c.style,{background:b.menuBg,border:`1px solid ${b.menuBorder}`,borderRadius:K.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const f=u.ownerDocument.createElement("span");f.textContent="\u2026",Object.assign(f.style,{color:b.label,fontSize:"18px"}),c.appendChild(f),$.appendChild(c),D.push(null),C.push(null),oe.push(null),we.push(null),t.push({index:r,factory:g,placeholder:c}),Je++}else{const{ctrl:c,canvasWrapper:f,expandBtn:h}=Kt(g,r,e.length);D.push(g),C.push(c),oe.push(f),we.push(h)}}Fn(),pt(),Lt(),Ot(),In();const n=++Pe,o=()=>{setTimeout(()=>{n===Pe&&p.onItemsResolved?.()},0)},i=r=>{setTimeout(()=>{n===Pe&&p.onItemResolved?.(r,e.length)},0)};let s=e.length-t.length;s>0&&i(s);let a=0;function d(){if(n!==Pe)return;if(a>=t.length){if(he.has(l.plotMode)){const L=l.plotMode;ee(qe(L));return}je=o,z(),Me||(je=null,o());return}const{index:r,factory:g,placeholder:c}=t[a++],f=g();D[r]=f,B[r]=f,jt([f]);const{card:h,ctrl:m,canvasWrapper:S,expandBtn:w}=Kt(f,r,e.length);C[r]=m,oe[r]=S,we[r]=w,Je--,c.replaceWith(h),i(++s),ii(),oi(),!v&&!be?.placement&&f.statsSummary?.findings.length&&(v=an("right",de,u.ownerDocument,Bt),v.style.maxHeight="calc(100vh - 80px)",v.style.position="sticky",v.style.top="8px",v.style.flexDirection="column",v.style.display="none",(be?.placement??"right")==="left"?Y.insertBefore(v,$):Y.appendChild(v),z(),ge()),ge(),setTimeout(d,0)}t.length>0?setTimeout(d,0):o()}if(he.has(l.plotMode)&&B.length>0){const e=Gt(l.plotMode);l={...l,...e},ee(qe(l.plotMode))}else ee(x);Ge();let Le=0;const io=new(u.ownerDocument.defaultView??window).ResizeObserver(()=>{if(Le)return;Le=(u.ownerDocument.defaultView??window).requestAnimationFrame(()=>{Le=0,T==null&&zt()})});io.observe($),v&&z();function Ci(e,t){const n=oe[e];if(!n)return;n.innerHTML="",Object.assign(n.style,{alignItems:"center",justifyContent:"center"});const o=u.ownerDocument.createElement("span");o.textContent=t?"Opened in its own window":"Opened in the wafer viewer",Object.assign(o.style,{color:b.label,fontSize:j.body,textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function Xe(e,t){for(const a of q.values())if(a.cardIndex===e)return;const n=ht(t,e),o=Ro++,i=C[e]?.getOptions(),s=Zi(n);if(s){const a=s.document;a.title=n,Object.assign(a.documentElement.style,{height:"100%"}),Object.assign(a.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:j.family}),es(u,a.documentElement);const d=ts(u,a.documentElement,()=>w.setOptions({})),r=a.createElement("div");r.dataset.wmapWindowBanner="1",r.textContent=n,Object.assign(r.style,{display:"none",padding:`${k.sm} ${k.xl}`,fontSize:j.body,fontWeight:"700",background:b.warnBg,color:b.warnText,borderBottom:`1px solid ${b.warnBorder}`,flexShrink:"0"}),a.body.appendChild(r);const g=a.createElement("div");Object.assign(g.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),a.body.appendChild(g);const{wrap:c,metaPanel:f}=no(a,n,t.wafer.metadata??void 0),h=a.createElement("div");Object.assign(h.style,{display:"flex",alignItems:"center",padding:`${k.md} ${k.lg} ${k.sm}`,borderBottom:`1px solid ${b.menuBorder}`,flexShrink:"0",gap:k.sm}),h.appendChild(c),g.appendChild(h);const m=a.createElement("div");Object.assign(m.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),f&&m.appendChild(f),g.appendChild(m);let S=0;const w=Nt(m,t,void 0,i,(I,F)=>{const Ue=I?F:-S;try{s.resizeBy(Ue,0),S=I?F:0}catch{}}),L=setInterval(()=>{s.closed&&gt(o)},400);s.addEventListener("pagehide",()=>gt(o)),q.set(o,{id:o,ctrl:w,cardIndex:e,label:n,closePollId:L,stopThemeSync:d,close:()=>{s.closed||s.close()},setTitle:I=>{a.title=I,r.textContent=I,r.style.display="block"}})}else{const a=Qi({title:n,onClose:()=>gt(o),anchor:u});a.contentWrap.style.flexDirection="column",oo(a,n,t.wafer.metadata??void 0);const d=Nt(a.contentWrap,t,void 0,i,wo(a));q.set(o,{id:o,ctrl:d,cardIndex:e,label:n,closePollId:null,close:()=>a.close(),setTitle:r=>{const g=a.box.querySelector("[data-wmap-window-title]");g&&(g.textContent=r,g.title=r)}})}C[e]?.destroy(),C[e]=null,Ci(e,s!==null),Si(e)}function Nt(e,t,n,o,i){const s=t.viewOptions?{...l,...t.viewOptions}:l,a=o?{...s,...o}:s,r={...n!==void 0?{...a,plotMode:"value",activeTest:n}:a,showLegend:!0,legendPosition:Re},g=So(e,t,{viewOptions:r,showTooltip:!0,padding:H,statsSummary:t.statsSummary,onSaveImage:p.onSaveImage,onSaveText:p.onSaveText,downloadFilename:p.downloadFilename,onClick:t.onClick,onSelect:vn(t),insights:ne,showExpandButton:!1,onSummaryPanelChange:i,showIdentity:!1});return g.setViewControlsVisible(!0),g.setSummaryVisible(!0),g.setExpandVisible(!1),g}function gt(e){const t=q.get(e);if(!t||(q.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.(),t.ctrl.destroy(),t.cardIndex===null))return;const n=t.cardIndex,o=D[n];if(!o)return;const{card:i,ctrl:s,canvasWrapper:a,expandBtn:d}=Kt(o,n,D.length);oe[n]?.parentElement?.replaceWith(i),C[n]=s,oe[n]=a,we[n]=d}function xi(e){const t=q.get(e);t&&(t.close(),gt(e))}function Mi(){for(const e of q.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function _t(){for(const e of C)e?.drawPendingNow()}const so=u.ownerDocument.defaultView??window;so.addEventListener("beforeprint",_t);function ki(){_t();const e=[...$.querySelectorAll("canvas")];if(!e.length)return;const t=e.length,n=Math.ceil(Math.sqrt(t)),o=Math.ceil(t/n),i=e[0].width,s=e[0].height,a=8,d=(u.ownerDocument.defaultView??window).devicePixelRatio||1,r=Math.round(26*d),g=Math.round(12*d),c=u.ownerDocument.createElement("canvas");c.width=n*i+(n-1)*a,c.height=o*(s+r)+(o-1)*a;const f=c.getContext("2d"),h=Vi($);f.fillStyle=h.background,f.fillRect(0,0,c.width,c.height),e.forEach((m,S)=>{const w=S%n,L=Math.floor(S/n),I=w*(i+a),F=L*(s+r+a),Ue=m.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";f.fillStyle=h.surface,f.fillRect(I,F,i,r),f.fillStyle=h.text,f.font=`700 ${g}px system-ui, sans-serif`,f.textAlign="left",f.textBaseline="middle",f.fillText(Ue,I+Math.round(10*d),F+r/2,i-Math.round(20*d)),f.drawImage(m,I,F+r)}),c.toBlob(m=>{if(!m)return;const S=C.find(w=>w!=null)?.getExportTitle();ls(m,["gallery",S].filter(Boolean).join(" "),A.onSaveImage)})}return{setItems(e){B=e.map(n=>typeof n=="function"?null:n);const t=l.plotMode;if(he.has(t))if(e.some(o=>typeof o=="function"))ee(e);else{const o=Gt(t);l={...l,...o},ee(qe(t))}else ee(e)},setOptions(e){W(e,{fireCallback:!1})},getOptions(){return Co(l)},setFindingsNotice(e){bn=e,z()},setColumns(e){eo(e)},getBinColors(){return l.binColors??De()},setLotStatsSummary(e){N=e,Ge(),v&&z(),ge()},openUserGuide:Nn,destroy(){R.flush(),Pe++,so.removeEventListener("beforeprint",_t),Me?.cancel(),Me=null,je=null;for(const e of[...q.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();q.clear();for(const e of C)e&&e.destroy();C=[],Ie()?.remove(),io.disconnect(),Le&&((u.ownerDocument.defaultView??window).cancelAnimationFrame(Le),Le=0),u.ownerDocument.removeEventListener("click",tt,!0),window.removeEventListener("blur",yn),Lo(),mo(),_e.remove(),Y.remove(),v?.remove(),Oe?.destroy()}}}
1
+ import{createViewSwitch as fs}from"./viewSwitch.js";import{createSummaryToggle as ps}from"./summaryToggle.js";import{getUniqueTestNumbers as ms,resolveTestNumber as gs,findTestDef as hs,collectMetadataValues as ys}from"../renderer/buildView.js";import{metadataCategoricalValue as bs}from"../core/metadata.js";import{resolveBinColorsForMaps as ws,mergeBinDefs as Ft,binColorWarning as vs,mixedPassBinsWarning as Ss,binColorsEqual as Cs}from"../renderer/binColors.js";import{commonPassBins as Xo,itemPassBins as ut}from"../core/passBins.js";import{requireRingCount as ne}from"../core/ringCount.js";import{NO_DATA_FILL as xs}from"../renderer/colorMap.js";import{metadataValueColor as Ms}from"../renderer/colorMap.js";import{resolveCanvasTheme as ks}from"./canvasTheme.js";import{ICONS as Dn}from"./icons.js";import{SHADOW as Bn,LEADING as Yo,TRACKING as Ds,controlStyle as Bs,wireControlHover as En,SPACE as M,EDGE_GUTTER as oe,MAP_CHROME_INSET as Es,RADIUS as q,FONT as N,CLR as v,sevColor as Uo,MODE_LABELS as Os,BIN_LEGEND_MODES as Zo,STACKED_MODES as ie,applyOverlayZ as Ts,getTooltip as Ls,hideTooltip as Qo,createToolbarHelpers as Ws,buildModeMenuEl as Rs,openDetachWindow as As,openFloatingWindow as Ps,openModal as Fs,copyWmapThemeTokens as $s,syncWmapPopupTheme as Is,makePaletteBtn as Vs,makeLogScaleBtn as Hs,makeLegendStyleBtn as js,makeOverlaysBtn as zs,makeOrientationBtn as Ns,menuLayerFor as Jo,saveImageBlob as Gs,markMenuTrigger as ft,wireMenuA11y as ei,wireTooltip as On,requestedPassFailDisplay as ti,overlayMenuRows as _s,anyOverlayActive as Ks,openCompactDiagnostics as qs,roomForPanel as ni,logWmapVersionOnce as Xs,buildDataModeEntries as Ys,metadataKeyHasData as Us,metadataModeEntry as Zs}from"./toolbar.js";import{openReportModal as Qs,openUserGuideWindow as Js,registerGuideOpener as ea}from"./guideWindow.js";import{waferDisplayLabel as pt,waferIdentityLabel as we}from"../core/waferLabel.js";import{bandButton as ta}from"./filterButton.js";import{metadataDisplayValue as na}from"../core/metadata.js";import{withExportContext as oa}from"./exportName.js";import{sortBinsForDisplay as ia}from"../stats/binPareto.js";import{diePassStatus as sa,isYieldEligibleDie as aa}from"../core/dies.js";import{aggregateValues as la,aggregateBinCounts as oi}from"../core/aggregates.js";import{renderWaferMap as ra,renderWaferMapCard as ii,toPublicViewOptions as $t}from"./renderWaferMap.js";import{waferPopulation as ca,selectionPopulation as da,LOT_STACK_REASON as Tn}from"./chartPopulation.js";import{sourceFromBins as si}from"./plotItems.js";import{plotStoreFor as ua}from"./plotStore.js";import{classifyChanged as Ln,COLOR_KEYS as fa,findingBin as pa,findingPlotMode as ma}from"./renderWaferMap.js";import{findingPatternKey as ai}from"../stats/filterFindings.js";import{synthesisSource as ga}from"../stats/synthesis.js";import{buildWaferMap as ha,computeCoverage as ya,computeYield as ba,defaultBinMode as wa,getTestPassStatus as li,isParametricTest as Wn,getDieTestValue as va,isBuiltMap as Sa}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Rn}from"../stats/analyzeWaferMap.js";import{lotTestValueStatus as Ca}from"../stats/testValueBudget.js";import{testValueNotice as xa}from"./testValueOffer.js";import{axisPrefsFromOptions as An,optionsFromAxisPrefs as Ma,CHART_PREF_KEYS as Pn}from"./chartPrefs.js";import{collectWarnings as ka,buildWarningsMenuEl as Da,severityOf as Ba}from"./warnings.js";import{asList as Fn,compareNatural as $n,arrayEqual as It,toggleHighlight as ri}from"../core/utils.js";import{buildCompactMap as Ea,compactLayoutOffered as Oa}from"../core/compact.js";import{attachExpandableMetadata as ci}from"./identityHeader.js";import{createSummaryPanelEl as In,buildMetadataStripRow as Ta,metadataEntries as La,renderLotSummaryContentSteps as Wa,reportMapsFromItems as Ra}from"./summaryPanel.js";import{prettyKey as Aa}from"../stats/facets.js";import{testLabel as Pa,markedTestLabel as Fa,derivedFields as $a}from"../renderer/testLabel.js";import{mergeTestDefs as Ia}from"../stats/mergeTestDefs.js";import{getDieKey as Vt,hasPosition as Va}from"../core/dies.js";import{testValue as Ha}from"../core/dieTable.js";import{runChunked as ja}from"./chunked.js";function di(u){if(typeof u!="number"||!Number.isFinite(u))return;const k=Math.round(u);return k>=1?k:void 0}const Vn=12;function za(u,k,d){let z=k;if(k.length>Vn){const D=k.slice(0,Vn-1),E=k.slice(Vn-1),$=E.reduce((F,ce)=>F+ce.count,0);z=[...D,{color:v.label,count:$,label:`Other (${E.length} bins)`}]}const O=u.createElement("div");Object.assign(O.style,{display:"flex",columnGap:"1px",width:"100%",height:"8px",borderRadius:q.control,overflow:"hidden",border:`1px solid ${v.menuBorder}`,boxSizing:"border-box",marginTop:M.xs,flexShrink:"0"}),O.setAttribute("role","img"),O.setAttribute("aria-label",`Population split: ${z.map(D=>`${D.label} ${Ht(D.count/d*100)}`).join(", ")}`);for(const D of z){const E=D.count/d*100,$=u.createElement("div");Object.assign($.style,{flex:`${E} 1 0`,minWidth:E>0?"2px":"0",background:D.color}),On($,`${D.label} \xB7 ${D.count.toLocaleString()} dies \xB7 ${Ht(E)}`),O.appendChild($)}return O}function Ht(u){return u>0&&u<.1?"<0.1%":`${u.toFixed(1)}%`}function ui(u,k,d){const z=new Map;let O=0,D=0;for(const E of u){const $=d?new Set(d(E)):void 0;for(const F of E.dies){if(!aa(F))continue;const ce=k(F);ce!==void 0&&(z.set(ce,(z.get(ce)??0)+1),O++,$&&sa(F,$)&&D++)}}return{counts:z,total:O,pass:D}}function fi(u,k){const d=u.ownerDocument.createElement("div");Object.assign(d.style,{display:"flex",alignItems:"center",gap:"5px",cursor:"pointer",userSelect:"none",padding:`${M.xxs} ${M.xs}`,borderRadius:q.control});const z=u.ownerDocument.createElement("span");Object.assign(z.style,{display:"inline-block",width:"13px",height:"13px",flexShrink:"0",background:k.color,border:k.isActive?`2px solid ${v.iconActive}`:`1px solid ${v.menuBorder}`,borderRadius:q.control,boxSizing:"border-box"});const O=u.ownerDocument.createElement("span");if(O.textContent=k.label,Object.assign(O.style,{fontWeight:k.isActive?"700":"400",color:k.isActive?v.iconActive:v.text,whiteSpace:"nowrap"}),d.appendChild(z),d.appendChild(O),k.count!==void 0){const D=u.ownerDocument.createElement("span");if(D.textContent=k.count.toLocaleString(),Object.assign(D.style,{color:k.isActive?v.iconActive:v.text,fontWeight:k.isActive?"700":"400",whiteSpace:"nowrap"}),d.appendChild(D),k.percent!==void 0){const E=u.ownerDocument.createElement("span");E.textContent=Ht(k.percent),Object.assign(E.style,{color:v.label,whiteSpace:"nowrap"}),d.appendChild(E)}}if(d.setAttribute("role","button"),d.setAttribute("aria-pressed",k.isActive?"true":"false"),d.tabIndex=0,d.addEventListener("mouseenter",()=>{d.style.background=v.bgHover}),d.addEventListener("mouseleave",()=>{d.style.background="transparent"}),d.addEventListener("focus",()=>{d.style.background=v.bgHover}),d.addEventListener("blur",()=>{d.style.background="transparent"}),d.addEventListener("click",D=>k.onClick(D.ctrlKey||D.metaKey)),d.addEventListener("keydown",D=>{if(D.key==="Enter"||D.key===" ")D.preventDefault(),k.onClick(D.ctrlKey||D.metaKey);else if(k.onMenu&&(D.key==="ContextMenu"||D.key==="F10"&&D.shiftKey)){D.preventDefault();const E=d.getBoundingClientRect();k.onMenu({x:E.left+E.width/2,y:E.bottom},d)}}),k.onMenu){const D=k.onMenu;d.addEventListener("contextmenu",E=>{E.preventDefault(),D({x:E.clientX,y:E.clientY},d)}),On(d,"Right-click: charts and tables for these dies")}u.appendChild(d)}export function renderWaferGallery(u,k,d={}){Xs();const z=6;let O=di(d.columns);const D=d.showHelpButton??!1,E=d.userGuideExtension,$=d.insights?.enabled??!0,F=ua(d.insights),ce={enabled:!1,plotStore:F},pi=Ts(d.zIndex),Oe=d.summaryPanel,ve=e=>[...ut(e)],Hn=()=>V.flatMap(e=>e?[ne(e,"renderWaferGallery")]:[]),mt=()=>Hn()[0];function mi(e){const t=[...new Set(e)].sort((n,o)=>n-o);return t.length<2?null:{code:"ring-count-mixed",severity:"warning",message:`These wafers were built with different ring counts (${t.join(", ")}). Each card and each wafer's findings use their own; the lot's ring yield in the Summary panel, report and Insights uses ${e[0]} rings.`}}let K=d.lotStatsSummary,ze;const se=()=>Se?ze:K;let Ne=d.viewOptions?.legendPosition??"default",gt=d.perCardLegend??!1;function Ge(){const e=a.plotMode??"hardBin";return Zo.has(e)?null:a.colorbarRangeMode==="data"?"Each map has its own value range, so it keeps its own colour bar":"These wafers have no shared colour bar for value mode, so each map keeps its own"}function jn(){const e=gt||Ge()!==null;for(const t of C)t&&t.setOptions({showLegend:e})}let a={plotMode:wa(k.flatMap(e=>typeof e=="function"?[]:[e.dies??[]])),showDieLabels:!1,showRingBoundaries:!1,showQuadrantBoundaries:!1,rotation:0,flipX:!1,flipY:!1,...d.viewOptions},C=[],de=[],Te=[],x=[];const I=oa(()=>{const e=x.filter(n=>n!=null),t=[...new Set(e.map(n=>na(n.wafer.metadata?.lot)).filter(n=>n!==void 0))].sort($n);return{prefix:d.downloadFilename,lots:t,...e.length===1?{wafer:we(e[0])}:{waferCount:e.length}}},d.onSaveImage,d.onSaveText);let V=k.map(e=>typeof e=="function"?null:e),X=null,zn=null,jt=!1,Le=0,Se=!1,zt=!1;const _e=new WeakSet,Nn=new WeakMap,Ke=()=>{const e=X?.get();return!!e&&!e.off};function Gn(e,t){return{dies:e.dies,wafer:e.wafer,label:pt(e,t),identity:we(e),waferIndex:t,passBins:ut(e),testDefs:e.testDefs,statsSummary:e.statsSummary}}const Nt=new Map;function qe(e,t){if(!X||!Ke())return e;const n=Nn.get(e);if(n&&n.v===Le)return n.item;const o=X.mark([Gn(e,t)]);let i=e;if(o.narrowing){const s=o.items[0].dies,l=s.filter(c=>!c.filteredOut);i={...e,dies:s,statsSummary:Nt.get(e),...e.yield?{yield:ba(s,[...ut(e)],e.yield.yieldPercentGross!=null?"denominator-only":"exclude")}:{},...e.dataCoverage?{dataCoverage:ya(l)}:{}},o.hidden.size&&_e.add(i)}return Nn.set(e,{v:Le,item:i}),i}const _n=new WeakMap;function gi(e,t){if(!X||!Ke())return e;const n=_n.get(e);if(n&&n.v===Le)return n.item;const o=qe(e,t),i=o===e?e:_e.has(o)?null:{...o,dies:o.dies.filter(s=>!s.filteredOut)};return _n.set(e,{v:Le,item:i}),i}function B(){return!X||!Ke()?V:V.map((e,t)=>e?gi(e,t):null)}let ht=0,yt=!1;function hi(){const e=++ht;ze=void 0,Nt.clear();const t=()=>{yt=!1,W(),le()};if(!Se){t();return}const n=Ut();if(!n||!(K||n.some(s=>s.statsSummary))){t();return}const o=B().flatMap((s,l)=>s?[{it:s,i:l}]:[]);if(o.length===0){t();return}yt=!0;const i=K?.analysisOptions??n.find(s=>s.statsSummary)?.statsSummary?.analysisOptions??{};import("../stats/analyzeWaferLot.js").then(async({analyzeWaferLotAsync:s,remapLotWaferIndices:l})=>{const c=await s(o.map(p=>p.it),i);if(e!==ht||jt)return;const r=o.map(p=>p.i);ze=l(c,r),c.perWafer.forEach((p,m)=>Nt.set(V[r[m]],p.summary)),Le++,V.forEach((p,m)=>{if(!p||ie.has(a.plotMode))return;const f=qe(p,m);x[m]=f,C[m]?.setStatsSummary(f.statsSummary)}),De(),t()}).catch(()=>{e===ht&&t()})}const bt=e=>X&&Ke()?e.map((t,n)=>typeof t=="function"?t:qe(t,n)):e;function Gt(){return zn??=import("./pageFilter.js").then(({createPageFilter:e})=>{const t=e({doc:u.ownerDocument,initial:d.insights?.filter,onChange:d.insights?.onFilterChange,savedFilters:d.insights?.savedFilters,onSavedFiltersChange:d.insights?.onSavedFiltersChange,pickFiltersFile:d.insights?.onPickFiltersFile,onSaveText:d.onSaveText,attributes:d.attributes,getRingCount:()=>ne({ringCount:mt()},"the page filter")});return jt||(X=t,ue=t.createBand(()=>Kt(),{marginLeft:oe,marginRight:oe,marginBottom:M.lg}),u.insertBefore(ue.el,U),t.subscribe(qt),t.get()&&qt()),t}),zn}let ue=null,wt=null,_t;const Kt=()=>V.flatMap((e,t)=>e?[Gn(e,t)]:[]);function Kn(){clearTimeout(_t),_t=setTimeout(()=>{if(!X||!ue)return;const e=Kt(),t=X.keep(e);ue.refresh(t.result,e),ue.el.style.display=X.get()&&!it?"":"none"},0)}function qt(){if(Le++,Se=!1,Ue>0){zt=!0,Kn();return}zt=!1;const e=a.plotMode;Se=Ke()&&V.some((t,n)=>t!==null&&qe(t,n)!==t),ze=void 0,yt=Se&&!!K,V.length>0&&(ie.has(e)?(a={...a,...At(e)},Z(Ve(e))):Z(bt(V.filter(t=>t!==null)))),Kn(),hi()}function We(){return Ia(B())}function Xe(){if(B().some(e=>e?.testDefs?.length))return We().defs}let Ye=0,Ue=0;const Q=new Map;let yi=0,vt=null,J=null,fe=null,Re=null;function St(){J===null&&fe===null&&(Re={plotMode:a.plotMode,activeTest:a.activeTest})}function qn(){Re&&R({...Re},{fireCallback:!1}),Re=null}let Xn=new Set,S=null,bi={};function Yn(e){return B()[e]?.statsSummary??se()?.perWafer.find(t=>t.waferIndex===e)?.summary}function Un(){return!!(B().some(e=>e?.statsSummary?.findings.length)||se()?.perWafer.some(e=>e.summary.findings.length))}const wi=Ls(),Ae=Ws(wi),{makeBtn:Pe,setActive:Zn,makeSep:Ce,syncSeparators:Xt,syncToolbarVisible:Yt,makeMenuRow:vi,makeMenuSection:Si,makeDropdown:Qn,closeOpenMenu:Ct,getOpenMenu:Ze,setOpenMenu:Qe}=Ae;u.ownerDocument.addEventListener("click",Ct,!0);const Jn=()=>Qo();window.addEventListener("blur",Jn);let eo=d.findingsNotice,xe=null;function Ut(){const e=V;return e.length>0&&e.every(t=>t!=null&&Sa(t))?e:null}function Ci(){return K?.stats.testValueAnalysis??Ca(B().flatMap(e=>e?.statsSummary?[e.statsSummary]:[]))}const Zt=()=>eo??(Ut()?xa(Ci(),B().length,xe!==null,xi):void 0);function xi(){const e=Ut();if(xe||!e)return;const t=new AbortController;xe=t,W();const n=K?.analysisOptions??e[0].statsSummary?.analysisOptions??{};import("../stats/analyzeWaferLot.js").then(({analyzeWaferLotAsync:o})=>o(e,{...n,enableTestValueAnalysis:!0,signal:t.signal})).then(o=>{if(t.signal.aborted)return;xe=null;const i=o.perWafer.map(s=>s.summary);V=V.map((s,l)=>s&&{...s,statsSummary:i[l]}),ie.has(a.plotMode)||(x=x.map((s,l)=>s&&{...s,statsSummary:i[l]}),C.forEach((s,l)=>s?.setStatsSummary(i[l]))),K=o,De(),W(),le(),d.onStatsSummaryChange?.({summaries:i,lotStatsSummary:o})}).catch(o=>{if(!t.signal.aborted)throw xe=null,W(),o})}function Qt(){xe?.abort(),xe=null}function to(e){Xn=new Set(e);const t=[...P.querySelectorAll(".wmap-gallery-card")];let n;t.forEach((o,i)=>{const s=Xn.has(i);o.style.outline=s?`3px solid ${v.findingHighlight}`:"",o.style.outlineOffset=s?"-3px":"",s&&n===void 0&&(n=o)}),n?.scrollIntoView?.({behavior:"smooth",block:"nearest"})}function Jt(){to([])}let xt=!1;function en(){xt=!0;for(const e of C)e&&e.clearSelection();xt=!1}function no(e){return t=>{!xt&&(J!==null||fe!==null)&&(Re=null,ke(),W()),on.set(e,t.length),ae&&!Je&&!xt&&Mi(e,t),e.onSelect?.(t)}}function pe(e,t){e!==void 0&&(C.forEach((n,o)=>{n&&o!==e&&n.locateDie(null)}),C[e]?.locateDie(t),P.querySelectorAll(".wmap-gallery-card")[e]?.scrollIntoView?.({block:"center",behavior:"smooth"}))}let ae=!1,Je=!1,Me=new Set;function Mi(e,t){Je=!0;try{Me=new Set(t.map(n=>Vt(n))),x.forEach((n,o)=>{const i=C[o];!i||!n||n===e||i.setSelection(n.dies.filter(s=>Me.has(Vt(s))))})}finally{Je=!1}Ot()}function oo(){Me=new Set,Je=!0;try{for(const e of C)e?.clearSelection()}finally{Je=!1}Ot()}function tn(){if(!ae||Me.size===0)return;const e=[];let t=!1;if(x.forEach((i,s)=>{if(!i)return;const l=i.dies.filter(c=>Me.has(Vt(c)));l.length!==0&&(i.isLotStack&&(t=!0),e.push({label:we(i)??i.label??`Wafer ${s+1}`,dies:l,waferIndex:s,wafer:i.wafer,passBins:ve(i),ringCount:ne(i,"renderWaferGallery")}))}),e.length===0)return;const n=We(),o=a;return{source:{items:e,population:e.length===1?`selected on ${e[0].label}`:`selected at the same die positions on ${e.length} wafers`,testDefs:n.defs,activeTest:o.plotMode==="value"?o.activeTest:void 0,notMeasuredReason:t?Tn:void 0},ctx:{plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,onSaveImage:I.onSaveImage,onSaveText:I.onSaveText,onLocateDie:(i,s)=>pe(s,i)}}}function io(){const e=[];let t=!1;if(x.forEach((o,i)=>{const s=o?C[i]?.getSelectedDies()??[]:[];!o||s.length===0||(o.isLotStack&&(t=!0),e.push({label:we(o)??o.label??`Wafer ${i+1}`,dies:s,waferIndex:i,wafer:o.wafer,passBins:ve(o),ringCount:ne(o,"renderWaferGallery")}))}),e.length<2)return;const n=a;return{source:{items:e,population:`selected on ${e.length} wafers`,testDefs:We().defs,activeTest:n.plotMode==="value"?n.activeTest:void 0,notMeasuredReason:t?Tn:void 0},ctx:{plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,onSaveImage:I.onSaveImage,onSaveText:I.onSaveText,onLocateDie:(o,i)=>pe(i,o)}}}function ki(e){const t=tn()??lo(e);if(t)return t;const n=io(),o=n?.source.items.some(i=>i.waferIndex===e);return n&&o?{...n,narrowable:!0}:void 0}function nn(e,t,n){J!==e&&t.click();const o=S;if(!o)return;const i=se()?.findings.find(l=>l.id===e),s=tn()??io()??Bi()??(i?so(ro(i)):void 0);s&&import("./drilldown.js").then(({openDrilldownMenu:l})=>{o.isConnected&&l(n,o,s.source,{plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,...s.ctx})})}function Di(e,t,n,o){const i=Fn(a.highlightBin),s=i.length>1&&i.includes(t)?[...i]:[t],l=[];let c=!1;x.forEach((h,y)=>{h&&(h.isLotStack&&(c=!0),l.push({label:we(h)??h.label??`Wafer ${y+1}`,dies:h.dies,waferIndex:y,wafer:h.wafer,passBins:ve(h),ringCount:ne(h,"renderWaferGallery")}))});const r=We().defs,p=si(l,e,s,r,void 0,c);if(!p)return;const m={plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,onSaveImage:I.onSaveImage,onSaveText:I.onSaveText,onLocateDie:(h,y)=>pe(y,h)},f=s.length>1?si(l,e,[t],r,void 0,c):null,g=f?{...m,narrower:{label:`Only ${e} bin ${t}`,backLabel:"All filtered bins",source:f,ctx:m}}:m;import("./drilldown.js").then(({openDrilldownMenu:h})=>{o.isConnected&&h(n,o,p,g)})}function so(e,t=""){const n=[];let o=!1;for(const s of[...e??[]].sort((l,c)=>l-c)){const l=x[s];l&&(l.isLotStack&&(o=!0),n.push({label:we(l)??l.label??`Wafer ${s+1}`,dies:l.dies,waferIndex:s,wafer:l.wafer,passBins:ve(l),ringCount:ne(l,"renderWaferGallery")}))}if(n.length===0)return;const i=a;return{source:{items:n,population:n.length===1?`on ${n[0].label}`:`on ${n.length} ${t}wafers`,testDefs:We().defs,activeTest:i.plotMode==="value"?i.activeTest:void 0,notMeasuredReason:o?Tn:void 0},ctx:{plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,onSaveImage:I.onSaveImage,onSaveText:I.onSaveText,onLocateDie:(s,l)=>pe(l,s)}}}function Bi(){let e;for(let i=0;i<C.length;i++)if((C[i]?.getSelectedDies().length??0)!==0){if(e!==void 0)return;e=i}const t=e===void 0?void 0:x[e];if(e===void 0||!t)return;const n=C[e].getSelectedDies(),o=a;return{source:da(n,{waferLabel:we(t),testDefs:t.testDefs,isLotStack:t.isLotStack,activeTest:o.plotMode==="value"?o.activeTest:void 0,waferIndex:e,wafer:t.wafer,passBins:ve(t),ringCount:ne(t,"renderWaferGallery")}),ctx:{onSaveImage:I.onSaveImage,onSaveText:I.onSaveText,onLocateDie:(i,s)=>pe(s??e,i)}}}function Ei(e){e||oo(),ae=e,Ot()}function Mt(e,t){const n=new Set(e),o=t??C.map((i,s)=>s);for(const i of o){const s=x[i],l=C[i];if(!s||!l)continue;const c=s.dies.filter(r=>n.has(Vt(r)));l.setSelection(c)}}const Y=new Set,on=new Map;function ao(){[...P.querySelectorAll(".wmap-gallery-card")].forEach((n,o)=>{n.style.outline=Y.has(o)?`2px solid ${v.iconActive}`:"",n.style.outlineOffset=Y.has(o)?"-2px":""});const t=Y.size;ee.style.display=t>0?"":"none",ee.textContent=`${t} wafer${t===1?"":"s"} picked \u2715`,ee.ariaLabel=`${t} wafer${t===1?"":"s"} picked. Click to clear.`}function Oi(e){e<0||(Y.has(e)?Y.delete(e):Y.add(e),ao())}function Ti(){Y.clear(),ao()}function lo(e){if(!(Y.size===0||!Y.has(e))){for(const t of on.values())if(t>0)return;return so([...Y],"picked ")}}function Li(){const e=[];for(let t=0;t<B().length;t++){const n=B()[t];if(!n)continue;const o=Yn(t)?.findings??[];o.length&&e.push({index:t,item:n,unusualCount:o.filter(i=>i.severity==="unusual").length,notableCount:o.filter(i=>i.severity==="notable").length,totalCount:o.length})}return e}function Wi(e){const t=x[e]??B()[e];t&&rt(e,t)}function Ri(e){const t=Yn(e)?.findings??[];if(t.length)return{total:t.length,unusual:t.filter(n=>n.severity==="unusual").length,notable:t.filter(n=>n.severity==="notable").length}}function Ai(){import("../stats/renderSummaryReport.js").then(({renderLotReportHtml:e})=>{Qs(e(Ra(B(),mt())),{anchor:u})})}function Pi(){if(!S)return;S.innerHTML="";const e=Li();if(B().length>0){const n=u.ownerDocument.createElement("div"),o=e.length,i=B().filter(Boolean).length;n.textContent=o===0?`No findings on any of the ${i} wafers`:`${o} of ${i} wafer${i===1?"":"s"} with findings`,Object.assign(n.style,{fontSize:N.body,color:v.label,marginBottom:M.md}),S.appendChild(n)}if(e.length>0){const n=u.ownerDocument.createElement("button");n.type="button",n.textContent="Summary report",Object.assign(n.style,{...Bs("outlined"),marginBottom:M.lg,display:"block",width:"100%",textAlign:"left"}),En(n),n.addEventListener("click",Ai),S.appendChild(n)}if(e.length===0){const n=u.ownerDocument.createElement("div");Object.assign(n.style,{color:v.icon,fontSize:N.body,padding:"4px 0"}),n.textContent="No findings on any wafer.",S.appendChild(n)}else for(const{index:n,item:o,unusualCount:i,notableCount:s,totalCount:l}of e){const c=i?"unusual":s?"notable":"info",r=i+s||l,p=u.ownerDocument.createElement("button");p.type="button",Object.assign(p.style,{display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",padding:"5px 8px",marginBottom:M.xs,border:"none",borderLeft:`3px solid ${Uo(c)}`,borderRadius:q.control,background:v.bgHover,cursor:"pointer",fontSize:N.body,textAlign:"left",boxSizing:"border-box"}),p.addEventListener("mouseover",()=>{p.style.background=v.bgActive}),p.addEventListener("mouseout",()=>{p.style.background=v.bgHover});const m=u.ownerDocument.createElement("span");m.textContent=pt(o,n),Object.assign(m.style,{color:v.iconHover,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"});const f=u.ownerDocument.createElement("span");f.textContent=String(r),p.setAttribute("aria-label",`${pt(o,n)} \u2014 ${r} finding${r===1?"":"s"}${i?`, ${i} unusual`:""} \u2014 view wafer`),Object.assign(f.style,{marginLeft:M.sm,flexShrink:"0",background:Uo(c),color:"#fff",borderRadius:q.container,padding:"1px 5px",fontSize:N.body,fontWeight:"600"}),p.appendChild(m),p.appendChild(f),p.addEventListener("click",()=>rt(n,o)),S.appendChild(p)}const t=u.ownerDocument.createElement("div");t.style.height="12px",S.appendChild(t)}let Fe=null,et=null;function W(){if(!S||Se&&K&&!ze&&yt)return;Fe?.cancel(),Fe=null;const e=se();if(e){const t=Ft(B().map(o=>o?.hbinDefs)),n=Ft(B().map(o=>o?.sbinDefs));Fe=ja(Wa(S,{lotSummary:e,items:B(),hbinDefs:t.length?t:void 0,sbinDefs:n.length?n:void 0,testDefs:Xe(),ringCount:mt(),binColors:a.binColors,plotMode:a.plotMode??"hardBin",fallbackFormat:a.fallbackFormat,activeFindingId:J,warnings:d.warnings?.display??!0?me:[],findingsFilter:bi,findingsNotice:Zt(),onFindingsFilterChange:W,onSaveText:I.onSaveText,attributes:d.attributes,onFindingClick:(o,i)=>{J===o.id?(ke(),qn()):(St(),mo(o,i)),W()},activeTest:fe,onTestClick:o=>{const i=fe===o;i||St(),ke(),i?qn():po(o),W()},onShowChart:$?o=>{st(!0),To().then(i=>i?.showWorthCard(o))}:void 0,onWaferClick:Wi,findingsFor:Ri,dieListOptions:d.dieList,onLocateDie:(o,i)=>pe(i,o),onClose:()=>an(!1)}),{onDone:()=>{const o=et;et=null,o?.()}})}else Pi()}function ro(e){const t=e.highlight;return t?.kind==="wafer"&&t.waferIndices?.length?t.waferIndices:null}let kt=[];function co(){if(kt.length!==0){for(const e of kt)C[e]?.setOptions({plotMode:a.plotMode,activeTest:a.activeTest});kt=[]}}function ke(){J=null,fe=null,Jt(),en(),co(),R({highlightBin:void 0},{fireCallback:!1})}function uo(){J===null&&fe===null||(Re=null,ke(),W())}function fo(e,t){const n=Xe();if(n===void 0||n.some(i=>i.testNumber===e))R({plotMode:"value",activeTest:e,highlightBin:void 0},{fireCallback:!1});else{R({highlightBin:void 0},{fireCallback:!1});const s=ie.has(a.plotMode??"hardBin")?null:t;if(s){for(const l of s)C[l]?.setOptions({plotMode:"value",activeTest:e});kt=[...s]}}}function po(e){fe=e;const t=o=>x[o]?.statsSummary?.stats.testFailures?.[e]?.dieKeys,n=x.map((o,i)=>i).filter(o=>t(o)?.length);if(fo(e,n.length?n:null),Jt(),en(),!ie.has(a.plotMode??"hardBin"))for(const o of n)Mt(t(o),[o])}function mo(e,t){if(J===e.id){ke();return}J=e.id,fe=null,t&&(t.style.background=v.bgActive,t.style.fontWeight="600"),co();const{kind:n,index:o}=e.variable;if(n==="test")fo(o??0,ro(e));else{const s=x.some(c=>c?.dies?.some(r=>r.hbin!=null)),l=Xo(x.map(c=>c?ut(c):void 0));R({plotMode:ma(e,a.plotMode,s),highlightBin:pa(e,l,s)},{fireCallback:!1})}Jt(),en();const i=e.highlight;if(i.kind==="wafer"){to(i.waferIndices);const s=ai(e);for(const l of i.waferIndices){const c=i.dieKeysByWafer?void 0:x[l]?.statsSummary?.findings.find(p=>ai(p)===s),r=i.dieKeysByWafer?.[l]??c?.highlight?.dieKeys;r?.length&&Mt(r,[l])}}else i.kind==="bin"?i.dieKeys?.length&&Mt(i.dieKeys):(i.kind==="region"||i.kind==="dies")&&i.dieKeys?.length&&Mt(i.dieKeys)}function sn(){return!!S&&S.style.display!=="none"}function an(e){!S||e===sn()||(e&&W(),S.style.display=e?"flex":"none",le())}function le(){vt&&(Xt(H),Yt(H,"inline-flex"),vt.sync({visible:!!(K||se()||Un())&&!!S&&!it,open:sn(),notable:!!(se()?.hasNotableFindings||B().some(e=>e?.statsSummary?.hasNotableFindings))}))}const H=u.ownerDocument.createElement("div");H.dataset.wmapToolbar="gallery",Object.assign(H.style,{flexShrink:"0",marginLeft:"auto",display:"inline-flex",flexDirection:"row",alignItems:"center",gap:"0",background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:q.control,padding:"0",boxShadow:Bn.panel,flexWrap:"wrap",minWidth:"0",overflowX:"auto"});const go=()=>{const e=Ze();e&&(e.remove(),Qe(null)),ft(re,!1)},re=Pe("mode","Plot mode",()=>{if(Ze()){go();return}const e=B().flatMap(w=>w?.dies??[]),t=Xe(),{testEntries:n,binEntries:o,stackedEntries:i}=Ys(e,t,{includeStacked:!0}),s=B().filter(Boolean).length,l=w=>{if(w===void 0)return s;let T=0;for(const A of B())A?.dies?.some(j=>li(j,w)!==void 0||Ha(j,w)!==void 0)&&T++;return T},c=s<2?n:n.map(w=>{const T=l(w.activeTest);return T===s?w:{...w,label:`${w.label} \u2014 ${T} of ${s} wafers`}}),r=a.plotMode??"hardBin",p=a.activeTest??0;function m(w){return w.plotMode!==r?!1:w.plotMode==="value"?p===(w.activeTest??0):w.plotMode==="metadata"?a.activeMetadataKey===w.activeMetadataKey:!0}function f(w,T){w.activeTest!==void 0?R({plotMode:"value",activeTest:w.activeTest,activeMetadataKey:void 0,logScale:w.logScale}):w.activeMetadataKey!==void 0?R({plotMode:w.plotMode,activeTest:void 0,activeMetadataKey:w.activeMetadataKey,passFailDisplay:"off"}):R({plotMode:w.plotMode,activeTest:void 0,activeMetadataKey:void 0,passFailDisplay:"off"}),T.remove(),Qe(null),ft(re,!1)}const g=new Set,h=B().flatMap(w=>w?.metadataFields??[]).filter(w=>!g.has(w.key)&&g.add(w.key)).filter(w=>Us(e,w.key)).map(Zs),y=Rs(re.getBoundingClientRect(),c,o,i,m,f,{makeMenuRow:vi,makeMenuSection:Si},r,re.ownerDocument.defaultView??window,h);Jo(re).appendChild(y),Qe(y),ft(re,!0),ei(y,re,go)});ft(re,!1);const Fi=()=>x.flatMap(e=>e?[...e.hbinDefs??[],...e.sbinDefs??[]]:[]).some(e=>e.color),{btn:$i,sync:ho}=Vs(Ae,()=>({...a,plotMode:a.plotMode??"hardBin"}),Fi,e=>R(e));ho();const Ii=k.some(e=>typeof e!="function"&&(e.reticles?.length??0)>0);function Dt(){const e=Xe(),{testNumber:t}=gs(a.activeTest??0,e);return{testNumber:t,td:hs(e,t)}}function yo(){if((a.plotMode??"hardBin")!=="value")return!1;const{td:e}=Dt();return e!==void 0&&(e.limitLow!==void 0||e.limitHigh!==void 0)}function tt(){if((a.plotMode??"hardBin")!=="value")return!1;const{td:e}=Dt();return e!==void 0&&!Wn(e)}function Vi(){if((a.plotMode??"hardBin")!=="value")return!1;const{testNumber:e,td:t}=Dt();return B().some(n=>n?.dies?.some(o=>li(o,e,t)!==void 0))}function Hi(e,t){if(!t||!Wn(t))return;const n=t.limitLow!==void 0||t.limitHigh!==void 0;if((ti(a)==="spec"&&n?"spec":a.colorbarRangeMode??"spec")==="spec"&&n)return;let s=1/0,l=-1/0;for(const c of B())if(c)for(const r of c.dies){const p=va(r,e);p!==void 0&&(p<s&&(s=p),p>l&&(l=p))}if(isFinite(s))return s===l?[s,s+1]:[s,l]}function Bt(e,t,n){const o=a[e];if(o===t||o!=null&&t!=null&&n(o,t))return!1;a={...a,[e]:t};for(const i of C)i&&i.setOptions({[e]:t});return!0}function bo(){if((a.plotMode??"hardBin")!=="metadata")return;const e=a.activeMetadataKey;if(!e)return;const t=new Set;for(const n of B())if(n)for(const o of ys(n.dies,e))t.add(o);return{key:e,values:[...t].sort($n)}}function ln(){Bt("metadataValueOrder",bo(),(e,t)=>e.key===t.key&&It(e.values,t.values))}function rn(){if((a.plotMode??"hardBin")!=="value")return;const{testNumber:e,td:t}=Dt(),n=Hi(e,t);Bt("valueRange",n?{test:e,range:n}:void 0,(i,s)=>{const l=p=>Array.isArray(p)?{test:void 0,range:p}:{test:p.test,range:p.range},c=l(i),r=l(s);return c.test===r.test&&It(c.range,r.range)})}let cn=!1;function ji(){if(cn)return;cn=!0,(u.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{cn=!1,rn(),ln(),Co(),So()})}let dn=!1;function zi(){if(dn)return;dn=!0,(u.ownerDocument.defaultView?.requestAnimationFrame??(t=>setTimeout(()=>t(0),0)))(()=>{dn=!1,Rt()})}let wo=[];function G(){const{colors:e,mixedHardBins:t}=ws(B().filter(n=>n!=null),{binColorScheme:a.binColorScheme,useDefinedBinColors:a.useDefinedBinColors});return wo=t,e}function un(){return x.filter(e=>e!=null).flatMap(e=>e.dies)}function vo(){return a.compact?Ea(un()):void 0}const Ni=(e,t)=>It(e.columns,t.columns)&&It(e.rows,t.rows);function So(){Bt("compactMap",vo(),Ni)&&Po()}function Gi(){return Oa(un(),x.filter(e=>e!=null).map(e=>e.reticleConfig))}function Co(){Bt("binColors",G(),Cs),De()}const _i=zs(Ae,()=>_s(a,Ii,{functionalActive:tt(),hasLimits:yo()&&!tt(),hasRecorded:Vi()&&!tt(),binMode:(a.plotMode??"hardBin")==="hardBin"||(a.plotMode??"hardBin")==="softBin"},e=>R(e),{on:!!a.compact,offered:Gi(),onChange:e=>R({compact:e}),onDiagnostics:()=>qs(un(),x.filter(e=>e!=null).map(e=>e.reticleConfig),{anchor:u,onSaveText:I.onSaveText})}),()=>Ks(a)),{btn:Ki,sync:xo}=js(Ae,()=>({plotMode:a.plotMode,legendPosition:Ne}),e=>{Ne=e;for(const t of C)t&&t.setOptions({legendPosition:Ne})},{get:()=>gt,set:e=>{gt=e,jn()},blockedReason:Ge});xo();const qi=[{value:"mean",label:"Mean"},{value:"median",label:"Median"},{value:"stddev",label:"Std Dev"},{value:"min",label:"Min"},{value:"max",label:"Max"},{value:"count",label:"Count"}],Mo=Qn("aggr","Aggregation method",()=>qi,()=>a.aggregationMethod??"mean",e=>R({aggregationMethod:e}));function ko(){const e=a.plotMode==="stackedValues";Mo.style.display=e?"":"none"}ko();const{btn:Xi,sync:Do}=Hs(Ae,()=>({...a,functionalActive:tt()}),e=>R(e));Do();const Et=Pe("specRange","Colorbar range: test limits",()=>{const e=a.colorbarRangeMode==="data"?"spec":"data";R({colorbarRangeMode:e})});function Bo(){const e=(a.plotMode??"hardBin")==="value"&&yo()&&ti(a)==="off"&&!tt();Et.style.display=e?"":"none";const t=(a.colorbarRangeMode??"spec")==="spec";Zn(Et,t),Et.ariaLabel=t?"Colorbar range: test limits (click for data range)":"Colorbar range: data range (click for test limits)"}Bo();const Yi=Ns(Ae,()=>a,e=>R(e)),Ui=Pe("downloadAll","Download gallery PNG",cs),$e=Pe("boxSelect","Select the same dies on every wafer",()=>{ae&&Me.size>0?oo():Ei(!ae)});$e.style.position="relative";const nt=u.ownerDocument.createElement("span");nt.dataset.wmapSelectAcrossCount="1",Object.assign(nt.style,{position:"absolute",top:"0",right:"0",minWidth:"14px",height:"14px",boxSizing:"border-box",padding:"0 3px",borderRadius:q.pill,background:v.iconActive,color:v.menuBg,fontSize:"11px",lineHeight:"14px",fontWeight:"700",textAlign:"center",pointerEvents:"none",display:"none"}),$e.appendChild(nt);function Ot(){Zn($e,ae);const e=ae?Me.size:0;nt.style.display=e>0?"block":"none",nt.textContent=e>99?"99+":String(e),$e.ariaLabel=ae?e>0?`Select the same dies on every wafer: on, ${e.toLocaleString()} die position${e===1?"":"s"} selected (click to clear the selection)`:"Select the same dies on every wafer: on (click to turn off)":"Select the same dies on every wafer: off (click to turn on)",$e.setAttribute("aria-pressed",String(ae))}const ee=u.ownerDocument.createElement("button");ee.type="button",ee.dataset.wmapPickedWafers="1",Object.assign(ee.style,{display:"none",border:"none",background:v.bgActive,color:v.iconActive,borderRadius:q.control,padding:`${M.xs} ${M.md}`,fontSize:N.body,cursor:"pointer",whiteSpace:"nowrap",flexShrink:"0"}),En(ee,"bare"),ee.addEventListener("click",Ti);const Zi=Qn("columns","Columns",()=>[{value:"auto",label:"Auto"},{value:"1",label:"1 column"},{value:"2",label:"2 columns"},{value:"3",label:"3 columns"},{value:"4",label:"4 columns"},{value:"5",label:"5 columns"}],()=>O!=null?String(O):"auto",e=>Io(e==="auto"?void 0:Number(e))),L=u.ownerDocument.createElement("div");Object.assign(L.style,{display:"inline-flex",alignItems:"center",gap:"0"}),H.appendChild(L),L.appendChild(re),L.appendChild($i),L.appendChild(Mo),L.appendChild(Xi),L.appendChild(Et),L.appendChild(Ce()),L.appendChild(_i),L.appendChild(Ce()),L.appendChild(Ki),L.appendChild(Ce()),L.appendChild(Yi),L.appendChild(Ce()),L.appendChild(Zi),L.appendChild(Ce()),L.appendChild($e),L.appendChild(ee),L.appendChild(Ui),Ot();let te=null,Tt=null,me=[],Eo=!1;function De(){const e=ka({lotStatsSummary:se(),result:{warnings:[...B().flatMap(n=>n?.warnings??[]),...We().warnings]},extra:[a.binColors&&vs(a.binColors,a.plotMode),Ss(wo),mi(Hn())].filter(n=>!!n)}),t=e.length!==me.length||e.some((n,o)=>n.code!==me[o]?.code||n.message!==me[o]?.message);me=e,(t||!Eo)&&(Eo=!0,d.warnings?.onWarning?.(e)),Qi()}function Qi(){if(!te||!Tt)return;const e=me.length,t=e>0;if(te.style.display=t?"flex":"none",Tt.style.display=t?"":"none",Xt(H),Yt(H,"inline-flex"),!t)return;const n=Ba(me[0]),o=`${e} data ${e===1?"warning":"warnings"}`;te.style.color=n==="error"?v.errText:v.warnText,te.ariaLabel=n==="error"?`${o} \u2014 some wafers may be positionally wrong`:o}(d.warnings?.display??!0)&&(Tt=Ce(),te=Pe("warning","Data warnings",()=>{const e=Ze();if(Ct(new MouseEvent("click")),e)return;const t=Da(te.getBoundingClientRect(),me,te.ownerDocument.defaultView??window);Jo(u).appendChild(t),Qe(t),ei(t,te,()=>Ct(new MouseEvent("click")))}),ft(te,!1),H.appendChild(Tt),H.appendChild(te)),De();function fn(e){import("./userGuideHtml.js").then(t=>Js({buildWaferMap:ha,renderWaferMap:ra,renderWaferGallery,analyzeWaferMap:Rn},t.USER_GUIDE_HTML,E,u,e))}const Ji=ea(e=>fn(e));D&&(H.appendChild(Ce()),H.appendChild(Pe("help","User guide",()=>fn())));const Ie=u.ownerDocument.createElement("div");Ie.dataset.wmapGalleryMeta="1",Object.assign(Ie.style,{flex:"1",minWidth:"0",overflow:"hidden",display:"flex",alignItems:"center",padding:`${M.sm} ${M.lg}`,fontSize:N.sub,lineHeight:Yo.none,boxSizing:"border-box"});const Be=u.ownerDocument.createElement("div");Object.assign(Be.style,{background:v.canvasBg,display:"flex",alignItems:"stretch",gap:M.lg,paddingBottom:M.lg,minWidth:"0"});const ge=u.ownerDocument.createElement("div");ge.dataset.wmapGalleryLegend="1",Object.assign(ge.style,{display:"flex",flexDirection:"column",gap:M.sm,background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:q.container,padding:`${M.sm} ${M.lg}`,marginBottom:M.lg,boxShadow:Bn.panel,fontSize:N.body,lineHeight:Yo.none,boxSizing:"border-box",width:"100%",minWidth:"0"});const U=u.ownerDocument.createElement("div");Object.assign(U.style,{display:"flex",flexDirection:"row",alignItems:"flex-start"});let he=null,ot=null,Oo=null;function To(){return $?he?Promise.resolve(he):(Oo??=Promise.all([import("./insightsTab.js"),Gt()]).then(([{createInsightsTab:e},t])=>(he=e({pageFilter:t,showFilterButton:!1,initialAxisPrefs:An(a),onAxisPrefsChange:n=>{a={...a,...Ma(n)};const o=[...Pn];d.onViewOptionsChange?.($t(a),o,Ln(o))},attributes:d.attributes,getItems:()=>V,getLotStats:()=>K,getBinColors:()=>a.binColors??G(),getRingCount:()=>ne({ringCount:mt()},"the Insights tab"),defaultView:d.insights?.defaultView,plotStore:F,onPickPlotsFile:d.insights?.onPickPlotsFile,showOnMap:n=>{if(st(!1),n.kind==="test")St(),ke(),po(n.testNumber);else{const o=se(),i=o?ga(o).findings.find(s=>s.id===n.id):void 0;i&&J!==i.id&&(St(),mo(i))}an(!0),W()},onOpenGuide:void 0,showMetadataStrip:!1,onSaveImage:I.onSaveImage,onSaveText:I.onSaveText,ownerDocument:u.ownerDocument,locateDie:(n,o)=>{st(!1),pe(o,n)},openWafer:(n,o,i)=>{const s=B()[n];if(!s)return;let l=null;const c=Fs({title:o,onClose:()=>l?.destroy(),anchor:u});jo(c,o,s.wafer.metadata??void 0),l=Sn(c.contentWrap,s,i,void 0,ni(c))}}),ot=he.el,ot.style.display="none",u.appendChild(ot),he)),Oo):Promise.resolve(null)}let it=!1,pn=null;function st(e){$&&(it=e,pn?.setInsightsOpen(e),ot&&(ot.style.display=e?"flex":"none"),U.style.display=e?"none":"flex",ue&&(ue.el.style.display=X?.get()&&!e?"":"none"),L.style.display=e?"none":"inline-flex",Xt(H),Yt(H,"inline-flex"),H.style.display="inline-flex",le(),Rt(),e&&To().then(t=>{!t||!it||(t.el.style.display="flex",t.render())}))}$&&d.insights?.defaultOpen&&queueMicrotask(()=>st(!0));const Lo=4,Lt=240,mn=480,es=720,ts=1.25;let Ee=mn;function Wo(e){const t=z*2+110+2,n=Ro();if(n)return Math.ceil(n.across*Lo+t);let o=null;for(const i of e){if(i==null||!i.dies?.length)continue;const s=i.dies[0].width;if(!(s>0))continue;const l=i.wafer.radius*2*(Lo/s),c=Math.ceil(l+t);(o==null||c>o)&&(o=c)}return o}function ns(e){const t=Wo(e);return t==null?Lt:Math.min(Ee,Math.max(Lt,t))}function os(e){const t=Wo(e);if(t==null)return!1;const n=Math.min(es,Math.max(mn,t));return n<=Ee?!1:(Ee=n,!0)}function Ro(){const e=a.compact?a.compactMap:void 0,t=x.find(i=>i?.dies?.length)?.dies[0];if(!e||!t||e.columns.length===0||e.rows.length===0||!(t.width>0)||!(t.height>0))return;const n=(a.rotation??0)%180!==0,o=a.showXYIndicator?2.5:0;return{across:(n?e.rows.length:e.columns.length)+o,down:(n?e.columns.length:e.rows.length)+o,cellAspect:n?t.height/t.width:t.width/t.height}}function Ao(e,t){const n=Ro();if(!n){e.style.aspectRatio="1",t.style.flex="1",t.style.width="",t.style.aspectRatio="";return}e.style.aspectRatio="auto",t.style.flex="none",t.style.width="100%",t.style.aspectRatio=String(n.across*n.cellAspect/n.down)}function is(){for(const e of de)e?.parentElement&&Ao(e.parentElement,e)}function Po(){Ee=mn,at=Lt,yn(x.map(e=>e??null)),Wt(),is()}function gn(){return Fo()?`${Ee}px`:"none"}function Fo(){return O==null&&!hn}let hn=!1;function Wt(){const e=gn();for(const t of Array.from(P.children))t.classList.contains("wmap-gallery-card")&&(t.style.maxWidth=e,t.style.maxHeight=e)}let at=Lt,$o=0;function yn(e){if(os(e)&&Wt(),O==null){const n=ns(e);n>at&&(at=n)}wn()}function Io(e){O=di(e),Wt(),wn()}function bn(e){return`repeat(${e}, minmax(0, ${Fo()?`${Ee}px`:"1fr"}))`}function Vo(e){P.style.gridTemplateColumns!==e&&(P.style.gridTemplateColumns=e)}function wn(){if(O!=null){Vo(bn(O));return}const e=Math.max(1,$o),t=12,n=P.clientWidth||0,o=l=>(n-t*(l-1))/l;let i=Math.max(1,Math.ceil(Math.sqrt(e)));if(n>0){const l=Math.min(Ee,at*ts),c=r=>{let p=0;for(;p<e&&o(p+1)>=r;)p++;return p};i=c(l)||c(at)||1}const s=n>0&&i<e;s!==hn&&(hn=s,Wt()),Vo(bn(i))}const P=u.ownerDocument.createElement("div");if(Object.assign(P.style,{flex:"1 1 0",minWidth:"0",display:"grid",gridTemplateColumns:bn(1),gap:M.xl,paddingLeft:oe,paddingRight:oe,justifyContent:"start",alignContent:"start",isolation:"isolate"}),Oe?.placement){const e=Oe.placement;S=In(e,oe,u.ownerDocument,nn),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.display="flex",S.style.flexDirection="column"}else if(K||se()||Un()){const e=!!Oe?.defaultOpen;S=In("right",oe,u.ownerDocument,nn),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.flexDirection="column",S.style.display=e?"flex":"none",W()}le(),(Oe?.placement??"right")==="left"?(S&&U.appendChild(S),U.appendChild(P)):(U.appendChild(P),S&&U.appendChild(S));const lt=u.ownerDocument.createElement("div");Object.assign(lt.style,{position:"sticky",top:"0",display:"flex",flexDirection:"column",paddingLeft:oe,paddingRight:oe,paddingTop:oe,zIndex:"1",background:v.menuBg}),Be.appendChild(Ie),Be.appendChild(H),vt=ps(u.ownerDocument,()=>an(!sn())),Be.appendChild(vt.el),le(),$&&(pn=fs(u.ownerDocument,"Maps","lot",e=>st(e)),Be.appendChild(pn.el)),$&&(wt=ta(u.ownerDocument,"Filter\u2026","wmapGalleryFilterOpen","Show only the wafers and dies that meet conditions you set, on the maps, the gallery and every Insights tab",()=>{Gt().then(e=>e.openEditor(wt??u,Kt()))}),wt.style.order="1",Be.appendChild(wt)),lt.appendChild(Be),lt.appendChild(ge),u.appendChild(lt),u.appendChild(U);function Rt(){ge.innerHTML="";const e=a.plotMode??"hardBin",t=!it&&Zo.has(e),n=x.filter(b=>b!=null&&!_e.has(b)),o=n.find(b=>b.isLotStack),i=Ta(n.map(b=>({metadata:b.wafer.metadata??void 0})),o?{lotSize:o.lotSize??n.length,aggrMethod:o.aggrMethod}:void 0,{curation:d.attributes}),s=e==="metadata",l=a.activeMetadataKey,c=t&&!s?ui(n,b=>(e==="softBin"?b.sbin:b.hbin)??void 0,ve):{counts:new Map,total:0,pass:0},r=t&&!s?a.binColors??G():void 0,p=r?e==="softBin"?r.pass.soft:r.pass.hard:new Set,m=ia(c.counts.entries(),p).map(([b])=>b),f=t&&s&&l?ui(n,b=>bs(b.metadata?.[l])):{counts:new Map,total:0,pass:0},g=s?bo()?.values:void 0,h=t&&s?(g??[...f.counts.keys()].sort($n)).filter(b=>f.counts.has(b)):[];if(Ie.innerHTML="",i&&Ie.appendChild(i),Ie.style.display=i?"flex":"none",!m.length&&!h.length){ge.style.display="none";return}ge.style.display="flex";const y=u.ownerDocument.createElement("div");Object.assign(y.style,{display:"flex",flexWrap:"wrap",alignItems:"center",gap:`${M.sm} ${M.xl}`,maxHeight:"86px",overflowY:"auto",overflowX:"hidden"}),ge.appendChild(y);const w=Fn(a.highlightBin),T=x.flatMap(b=>b?.metadataFields??[]).find(b=>b.key===l),A=s?T?.label??(l?Aa(l):"Metadata"):Os[e],j=u.ownerDocument.createElement("span");if(j.textContent=A,Object.assign(j.style,{fontSize:N.body,fontWeight:"700",letterSpacing:Ds,textTransform:"uppercase",color:v.label,flexShrink:"0"}),y.appendChild(j),!s&&c.total>0){const b=c.pass,_=b/c.total*100,ye=u.ownerDocument.createElement("span");ye.textContent=`Yield ${Ht(_)}`,Object.assign(ye.style,{fontSize:N.body,fontWeight:"700",color:v.value,whiteSpace:"nowrap",flexShrink:"0"});const be=u.ownerDocument.createElement("span");be.textContent=`${b.toLocaleString()} / ${c.total.toLocaleString()} dies`,Object.assign(be.style,{fontSize:N.body,color:v.label,whiteSpace:"nowrap",flexShrink:"0"}),y.appendChild(ye),y.appendChild(be)}if(s){const b=Fn(a.highlightMetadataValue);h.forEach((_,ye)=>{const be=b.includes(_),je=T?.values?.find(kn=>kn.value===_),dt=je?.color??Ms(ye),qo=f.counts.get(_)??0;fi(y,{color:dt,isActive:be,label:je?.label??_,count:qo,percent:f.total>0?qo/f.total*100:void 0,onClick:kn=>{const us=ri(a.highlightMetadataValue,_,kn);uo(),R({highlightMetadataValue:us})}})});return}const ct=e==="softBin"?x.flatMap(b=>b?.sbinDefs??[]):x.flatMap(b=>b?.hbinDefs??[]),Go=new Set,xn=[];for(const b of ct)Go.has(b.bin)||(Go.add(b.bin),xn.push(b));const Mn=xn.length>0?new Map(xn.map(b=>[b.bin,b])):null,_o=r??a.binColors??G(),ds=e==="softBin"?_o.soft:_o.hard,Ko=b=>ds.get(b)??xs;for(const b of m){const _=w.includes(b),ye=Mn?.get(b),be=c.counts.get(b)??0;fi(y,{color:Ko(b),isActive:_,label:ye?.name?`${b} \xB7 ${ye.name}`:`Bin ${b}`,count:be,percent:c.total>0?be/c.total*100:void 0,onMenu:(je,dt)=>Di(e==="softBin"?"soft":"hard",b,je,dt),onClick:je=>{const dt=ri(a.highlightBin,b,je);uo(),R({highlightBin:dt})}})}c.total>0&&m.length>1&&ge.appendChild(za(u.ownerDocument,[...c.counts.entries()].sort(([,b],[,_])=>_-b).map(([b,_])=>({color:Ko(b),count:_,label:Mn?.get(b)?.name?`${b} \xB7 ${Mn.get(b).name}`:`Bin ${b}`})),c.total))}function Ve(e){const t=B().filter(f=>f!==null&&!_e.has(f));if(!t.length)return[];const n=t.map(f=>f.dies.filter(Va).filter(g=>!g.filteredOut)),o=t[0].wafer,i=t.length,s=Xo(t.map(f=>ut(f)));if(!s)return[];const l=new Set(t.map(f=>ne(f,"renderWaferGallery")));if(l.size!==1)return[];const c=[...l][0],r=o.metadata?{...o,metadata:(({wafer:f,waferId:g,...h})=>h)(o.metadata)}:o;function p(f,g){return{...f,stats:{...f.stats,isLotStack:!0,aggregationMethod:g,lotSize:i}}}function m(f,g){const h=f.map(y=>({...y,hbin:void 0,sbin:void 0}));return Rn({wafer:r,dies:h,passBins:[...s],ringCount:c,testDefs:[{testNumber:0,name:g}]},{testNumbers:[0]})}if(e==="stackedValues"){const f=Xe();let g=f?.filter(Wn);if(f!==void 0&&g?.length===0)return[];if(f?.length||(g=ms(t.flatMap(w=>w.dies)).map(w=>({testNumber:w,name:Pa(void 0,w)}))),!g?.length)return[];const h=a.aggregationMethod??"mean";return g.map(y=>{const w=la(n,h,y.testNumber),T={testNumber:0,name:y.name,unit:y.unit,...$a(y)};return{wafer:r,dies:w,passBins:[...s],ringCount:c,testDefs:[T],label:`${Fa(y,y.testNumber)} \xB7 ${h}`,isLotStack:!0,aggrMethod:h,lotSize:i,statsSummary:p(Rn({wafer:r,dies:w,passBins:[...s],ringCount:c,testDefs:[T]},{testNumbers:[0]}),h)}})}if(e==="stackedBins"){let f=Ft(t.map(g=>g?.hbinDefs));return(!f||f.length===0)&&(f=[...new Set(t.flatMap(h=>h.dies.map(y=>y.hbin).filter(y=>y!=null)))].sort((h,y)=>h-y).map(h=>({bin:h,name:`Bin ${h}`}))),f.map(g=>{const h=oi(n,g.bin,"hard"),y=[{bin:g.bin,name:g.name}];return{wafer:r,dies:h,passBins:[...s],ringCount:c,hbinDefs:y,label:`${g.bin} \xB7 ${g.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:p(m(h,`Wafers in hard bin ${g.bin}`),"countBin")}})}if(e==="stackedSoftBins"){let f=Ft(t.map(g=>g?.sbinDefs));return(!f||f.length===0)&&(f=[...new Set(t.flatMap(h=>h.dies.map(y=>y.sbin).filter(y=>y!=null)))].sort((h,y)=>h-y).map(h=>({bin:h,name:`Bin ${h}`}))),f.map(g=>{const h=oi(n,g.bin,"soft"),y=[{bin:g.bin,name:g.name}];return{wafer:r,dies:h,passBins:[...s],ringCount:c,sbinDefs:y,label:`${g.bin} \xB7 ${g.name}`,isLotStack:!0,aggrMethod:"countBin",lotSize:i,statsSummary:p(m(h,`Wafers in soft bin ${g.bin}`),"countBin")}})}return t}function At(e){const t=B().length;return e==="stackedBins"||e==="stackedSoftBins"?{valueRange:[0,t],lotSize:t}:e==="stackedValues"?{aggregationMethod:a.aggregationMethod??"mean",valueRange:void 0,lotSize:void 0}:{}}function R(e,{fireCallback:t=!0}={}){const n=Object.keys(e);if(n.length>0&&n.every(m=>Pn.includes(m))){a={...a,...e},he?.setAxisPrefs(An(a)),t&&d.onViewOptionsChange?.($t(a),n,Ln(n));return}Pn.some(m=>m in e)&&he?.setAxisPrefs(An({...a,...e}));const o=a.plotMode,i=Ge()!==null;a={...a,...e};const s=a.plotMode,l=ie.has(s),c=o!==void 0&&ie.has(o),r=Ue>0;if("binColorScheme"in e||"useDefinedBinColors"in e){const m=G();a={...a,binColors:m},e={...e,binColors:m}}if("compact"in e){const m=vo();a={...a,compactMap:m},e={...e,compactMap:m}}if(("compact"in e||a.compact&&("rotation"in e||"showXYIndicator"in e))&&Po(),e.plotMode!==void 0)if(l){const m=At(s);if(a={...a,...m},r)for(const f of C)f&&f.setOptions(e);else Z(Ve(s))}else if(c){const{valueRange:m,lotSize:f,aggregationMethod:g,...h}=a;if(a=h,r)for(const y of C)y&&y.setOptions(e);else Z(B().filter(y=>y!==null))}else for(const m of C)m&&m.setOptions(e);else if(e.aggregationMethod!==void 0&&s==="stackedValues")if(r)for(const m of C)m&&m.setOptions(e);else Z(Ve("stackedValues"));else for(const m of C)m&&m.setOptions(e);Ge()!==null!==i&&jn(),Rt(),ko(),xo(),ho();const p=e.plotMode!==void 0&&e.plotMode!==o;(fa.some(m=>m in e)||p)&&W(),De(),Do(),Bo(),rn(),ln(),t&&d.onViewOptionsChange?.($t(a),n,Ln(n))}function Ho(e,t,n){const o=e.createElement("div");Object.assign(o.style,{display:"flex",alignItems:"center",gap:M.xs,flex:"1",minWidth:"0"});const i=e.createElement("span");i.textContent=t,Object.assign(i.style,{fontWeight:"700",fontSize:N.sub,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}),o.appendChild(i);const s=ci(e,o,t,n,d.attributes);return{wrap:o,metaPanel:s}}function jo(e,t,n){const o=e.box.querySelector("[data-wmap-window-title]");if(!o||La(n??{}).length===0)return;const i=o.parentElement,s=u.ownerDocument.createElement("div");Object.assign(s.style,{display:"flex",alignItems:"center",gap:M.xs,flex:"1",minWidth:"0"}),i?.insertBefore(s,o),s.appendChild(o);const l=ci(u.ownerDocument,s,t,n,d.attributes);l&&(e.contentWrap.style.position="relative",e.contentWrap.appendChild(l))}function vn(e,t,n){const o=u.ownerDocument.createElement("div");o.className="wmap-gallery-card",Object.assign(o.style,{background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:q.container,boxShadow:Bn.panel,overflow:"hidden",display:"flex",flexDirection:"column",position:"relative",aspectRatio:"1",maxWidth:gn(),maxHeight:gn()});const i=u.ownerDocument.createElement("div");Object.assign(i.style,{display:"flex",alignItems:"center",padding:`${M.md} ${M.lg} ${M.sm}`,borderBottom:`1px solid ${v.menuBorder}`,flexShrink:"0",gap:M.sm});const{wrap:s,metaPanel:l}=Ho(document,pt(e,t),e.wafer.metadata??void 0);i.appendChild(s);const c=u.ownerDocument.createElement("button");c.dataset.wmapExpandBtn="1",c.setAttribute("aria-label","Open full view"),On(c),c.innerHTML=Dn.expand,Object.assign(c.style,{display:"flex",alignItems:"center",justifyContent:"center",border:`1px solid ${v.menuBorder}`,borderRadius:q.control,background:v.panelBg,color:v.label,padding:M.xxs,cursor:"pointer",flexShrink:"0",width:"22px",height:"22px"}),En(c),i.appendChild(c),i.addEventListener("click",g=>{(g.ctrlKey||g.metaKey)&&(g.preventDefault(),g.stopPropagation(),Oi(x.indexOf(e)))},!0),o.appendChild(i);const r=u.ownerDocument.createElement("div");Object.assign(r.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),o.appendChild(r),Ao(o,r),l&&r.appendChild(l),P.appendChild(o),o.addEventListener("contextmenu",g=>{if(g.defaultPrevented)return;g.preventDefault();const h=e.viewOptions?{...a,...e.viewOptions}:a,y=tn()??lo(t),w=y?.source??ca(e.dies,{waferLabel:we(e),testDefs:e.testDefs,isLotStack:e.isLotStack,activeTest:h.plotMode==="value"?h.activeTest:void 0,waferIndex:t,wafer:e.wafer,passBins:ve(e),ringCount:ne(e,"renderWaferGallery")}),T={x:g.clientX,y:g.clientY};import("./drilldown.js").then(({openDrilldownMenu:A})=>{o.isConnected&&A(T,o,w,y?{plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,...y.ctx}:{plots:F,getBinColors:()=>a.binColors??G(),attributes:d.attributes,onSaveImage:f.getSaveImageHook(),onSaveText:f.getSaveTextHook(),onLocateDie:j=>pe(t,j)})})});const p=gt||Ge()!==null,m=e.viewOptions?{...a,...e.viewOptions}:a,f=ii(r,e,{viewOptions:{...m,showLegend:p,legendPosition:Ne},showTooltip:!0,padding:z,statsSummary:e.statsSummary,testValueOffer:Zt,onSaveImage:d.onSaveImage,onSaveText:d.onSaveText,downloadFilename:d.downloadFilename,onClick:e.onClick,onSelect:no(e),drilldownSourceOverride:()=>ki(t),insights:ce,onExpand:()=>rt(t,e),showIdentity:!1,chromeInset:Es,drawWhenVisible:!0});return f.setViewControlsVisible(!1),f.setSummaryVisible(!1),c.onclick=()=>rt(t,e),_e.has(e)&&(o.style.display="none"),{card:o,ctrl:f,canvasWrapper:r,expandBtn:c}}function ss(e){const t=Te[e];if(!t)return;const n=[...Q.values()].find(o=>o.cardIndex===e);n?(t.innerHTML=Dn.minimize,t.setAttribute("aria-label","Reattach to gallery"),t.onclick=()=>ls(n.id)):(t.innerHTML=Dn.expand,t.setAttribute("aria-label","Open full view"),t.onclick=()=>rt(e,x[e]))}function Z(e){rs(),Ze()?.remove(),Qe(null),ke(),x=[],Y.clear(),on.clear(),ee.style.display="none";for(const r of C)r&&r.destroy();C=[],de=[],Te=[],Ue=0,P.innerHTML="",$o=e.length,yn(e.map(r=>typeof r=="function"?null:r));const t=[];for(let r=0;r<e.length;r++){const p=e[r];if(typeof p=="function"){const m=u.ownerDocument.createElement("div");m.className="wmap-gallery-card",Object.assign(m.style,{background:v.menuBg,border:`1px solid ${v.menuBorder}`,borderRadius:q.container,aspectRatio:"1",display:"flex",alignItems:"center",justifyContent:"center"});const f=u.ownerDocument.createElement("span");f.textContent="\u2026",Object.assign(f.style,{color:v.label,fontSize:"18px"}),m.appendChild(f),P.appendChild(m),x.push(null),C.push(null),de.push(null),Te.push(null),t.push({index:r,factory:p,placeholder:m}),Ue++}else{const{ctrl:m,canvasWrapper:f,expandBtn:g}=vn(p,r,e.length);x.push(p),C.push(m),de.push(f),Te.push(g)}}Co(),Rt(),rn(),ln(),So();const n=++Ye,o=()=>{setTimeout(()=>{n===Ye&&d.onItemsResolved?.()},0)},i=r=>{setTimeout(()=>{n===Ye&&d.onItemResolved?.(r,e.length)},0)};let s=e.length-t.length;s>0&&i(s);let l=0;function c(){if(n!==Ye)return;if(l>=t.length){if(ie.has(a.plotMode)){const A=a.plotMode;Z(Ve(A));return}if(zt){qt();return}et=o,W(),Fe||(et=null,o());return}const{index:r,factory:p,placeholder:m}=t[l++],f=p();V[r]=f;const g=qe(f,r);g!==f&&(Se=!0),x[r]=g,yn([g]);const{card:h,ctrl:y,canvasWrapper:w,expandBtn:T}=vn(g,r,e.length);C[r]=y,de[r]=w,Te[r]=T,Ue--,m.replaceWith(h),i(++s),zi(),ji(),!S&&!Oe?.placement&&g.statsSummary?.findings.length&&(S=In("right",oe,u.ownerDocument,nn),S.style.maxHeight="calc(100vh - 80px)",S.style.position="sticky",S.style.top="8px",S.style.flexDirection="column",S.style.display="none",(Oe?.placement??"right")==="left"?U.insertBefore(S,P):U.appendChild(S),W(),le()),le(),setTimeout(c,0)}t.length>0?setTimeout(c,0):o()}if(ie.has(a.plotMode)&&B().length>0){const e=At(a.plotMode);a={...a,...e},Z(Ve(a.plotMode))}else Z(bt(k));d.insights?.filter!==void 0&&Gt(),De();let He=0;const zo=new(u.ownerDocument.defaultView??window).ResizeObserver(()=>{if(He)return;He=(u.ownerDocument.defaultView??window).requestAnimationFrame(()=>{He=0,O==null&&wn()})});zo.observe(P),S&&W();function as(e,t){const n=de[e];if(!n)return;n.innerHTML="",Object.assign(n.style,{alignItems:"center",justifyContent:"center"});const o=u.ownerDocument.createElement("span");o.textContent=t?"Opened in its own window":"Opened in the wafer viewer",Object.assign(o.style,{color:v.label,fontSize:N.body,textAlign:"center",padding:"0 12px"}),n.appendChild(o)}function rt(e,t){for(const l of Q.values())if(l.cardIndex===e)return;const n=pt(t,e),o=yi++,i=C[e]?.getOptions(),s=As(n);if(s){const l=s.document;l.title=n,Object.assign(l.documentElement.style,{height:"100%"}),Object.assign(l.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:N.family}),$s(u,l.documentElement);const c=Is(u,l.documentElement,()=>w.setOptions({})),r=l.createElement("div");r.dataset.wmapWindowBanner="1",r.textContent=n,Object.assign(r.style,{display:"none",padding:`${M.sm} ${M.xl}`,fontSize:N.body,fontWeight:"700",background:v.warnBg,color:v.warnText,borderBottom:`1px solid ${v.warnBorder}`,flexShrink:"0"}),l.body.appendChild(r);const p=l.createElement("div");Object.assign(p.style,{flex:"1",minHeight:"0",display:"flex",flexDirection:"column"}),l.body.appendChild(p);const{wrap:m,metaPanel:f}=Ho(l,n,t.wafer.metadata??void 0),g=l.createElement("div");Object.assign(g.style,{display:"flex",alignItems:"center",padding:`${M.md} ${M.lg} ${M.sm}`,borderBottom:`1px solid ${v.menuBorder}`,flexShrink:"0",gap:M.sm}),g.appendChild(m),p.appendChild(g);const h=l.createElement("div");Object.assign(h.style,{position:"relative",flex:"1",minHeight:"0",overflow:"hidden",display:"flex",flexDirection:"column"}),f&&h.appendChild(f),p.appendChild(h);let y=0;const w=Sn(h,t,void 0,i,(A,j)=>{const ct=A?j:-y;try{s.resizeBy(ct,0),y=A?j:0}catch{}}),T=setInterval(()=>{s.closed&&Pt(o)},400);s.addEventListener("pagehide",()=>Pt(o)),Q.set(o,{id:o,ctrl:w,cardIndex:e,label:n,closePollId:T,stopThemeSync:c,close:()=>{s.closed||s.close()},setTitle:A=>{l.title=A,r.textContent=A,r.style.display="block"}})}else{const l=Ps({title:n,onClose:()=>Pt(o),anchor:u});l.contentWrap.style.flexDirection="column",jo(l,n,t.wafer.metadata??void 0);const c=Sn(l.contentWrap,t,void 0,i,ni(l));Q.set(o,{id:o,ctrl:c,cardIndex:e,label:n,closePollId:null,close:()=>l.close(),setTitle:r=>{const p=l.box.querySelector("[data-wmap-window-title]");p&&(p.textContent=r,p.title=r)}})}C[e]?.destroy(),C[e]=null,as(e,s!==null),ss(e)}function Sn(e,t,n,o,i){const s=t.viewOptions?{...a,...t.viewOptions}:a,l=o?{...s,...o}:s,r={...n!==void 0?{...l,plotMode:"value",activeTest:n}:l,showLegend:!0,legendPosition:Ne},p=ii(e,t,{viewOptions:r,showTooltip:!0,padding:z,statsSummary:t.statsSummary,testValueOffer:Zt,onSaveImage:d.onSaveImage,onSaveText:d.onSaveText,downloadFilename:d.downloadFilename,onClick:t.onClick,onSelect:no(t),insights:ce,showExpandButton:!1,onSummaryPanelChange:i,showIdentity:!1});return p.setViewControlsVisible(!0),p.setSummaryVisible(!0),p.setExpandVisible(!1),p}function Pt(e){const t=Q.get(e);if(!t||(Q.delete(e),t.closePollId!=null&&clearInterval(t.closePollId),t.stopThemeSync?.(),t.ctrl.destroy(),t.cardIndex===null))return;const n=t.cardIndex,o=x[n];if(!o)return;const{card:i,ctrl:s,canvasWrapper:l,expandBtn:c}=vn(o,n,x.length);de[n]?.parentElement?.replaceWith(i),C[n]=s,de[n]=l,Te[n]=c}function ls(e){const t=Q.get(e);t&&(t.close(),Pt(e))}function rs(){for(const e of Q.values())e.cardIndex!==null&&(e.cardIndex=null,e.setTitle(`${e.label} \u2014 unlinked from gallery`))}function Cn(){for(const e of C)e?.drawPendingNow()}const No=u.ownerDocument.defaultView??window;No.addEventListener("beforeprint",Cn);function cs(){Cn();const e=[...P.querySelectorAll("canvas")];if(!e.length)return;const t=e.length,n=Math.ceil(Math.sqrt(t)),o=Math.ceil(t/n),i=e[0].width,s=e[0].height,l=8,c=(u.ownerDocument.defaultView??window).devicePixelRatio||1,r=Math.round(26*c),p=Math.round(12*c),m=u.ownerDocument.createElement("canvas");m.width=n*i+(n-1)*l,m.height=o*(s+r)+(o-1)*l;const f=m.getContext("2d"),g=ks(P);f.fillStyle=g.background,f.fillRect(0,0,m.width,m.height),e.forEach((h,y)=>{const w=y%n,T=Math.floor(y/n),A=w*(i+l),j=T*(s+r+l),ct=h.closest(".wmap-gallery-card")?.querySelector("span")?.textContent??"";f.fillStyle=g.surface,f.fillRect(A,j,i,r),f.fillStyle=g.text,f.font=`700 ${p}px system-ui, sans-serif`,f.textAlign="left",f.textBaseline="middle",f.fillText(ct,A+Math.round(10*c),j+r/2,i-Math.round(20*c)),f.drawImage(h,A,j+r)}),m.toBlob(h=>{if(!h)return;const y=C.find(w=>w!=null)?.getExportTitle();Gs(h,["gallery",y].filter(Boolean).join(" "),I.onSaveImage)})}return{setItems(e){Qt(),V=e.map(n=>typeof n=="function"?null:n);const t=a.plotMode;if(ie.has(t))if(e.some(o=>typeof o=="function"))Z(bt(e));else{const o=At(t);a={...a,...o},Z(Ve(t))}else Z(bt(e))},setOptions(e){R(e,{fireCallback:!1})},getOptions(){return $t(a)},setFindingsNotice(e){eo=e,W()},setColumns(e){Io(e)},getBinColors(){return a.binColors??G()},setLotStatsSummary(e){Qt(),K=e,De(),S&&W(),le()},openUserGuide:()=>fn(),destroy(){Ji(),F.flush(),Qt(),Ye++,No.removeEventListener("beforeprint",Cn),Fe?.cancel(),Fe=null,et=null;for(const e of[...Q.values()])e.closePollId!=null&&clearInterval(e.closePollId),e.close(),e.ctrl.destroy();Q.clear();for(const e of C)e&&e.destroy();C=[],Ze()?.remove(),zo.disconnect(),He&&((u.ownerDocument.defaultView??window).cancelAnimationFrame(He),He=0),u.ownerDocument.removeEventListener("click",Ct,!0),window.removeEventListener("blur",Jn),pi(),Qo(),lt.remove(),U.remove(),S?.remove(),jt=!0,ht++,clearTimeout(_t),ue?.el.remove(),he?.destroy()}}}
@@ -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