@wafertools/wafermap 0.31.0 → 0.33.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 (100) hide show
  1. package/AGENTS.md +13 -13
  2. package/CHANGELOG.md +334 -1
  3. package/README.md +3 -3
  4. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +2 -12
  5. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  6. package/dist/packages/canvas-adapter/dieList.js +7 -7
  7. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  8. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  9. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  10. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +47 -4
  11. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  12. package/dist/packages/canvas-adapter/summaryPanel.d.ts +22 -3
  13. package/dist/packages/canvas-adapter/summaryPanel.js +4 -3
  14. package/dist/packages/canvas-adapter/toCanvas.d.ts +23 -2
  15. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  16. package/dist/packages/canvas-adapter/toolbar.d.ts +54 -1
  17. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  18. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  19. package/dist/packages/canvas-adapter/userGuideHtml.js +100 -27
  20. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  21. package/dist/packages/canvas-adapter/version.js +1 -1
  22. package/dist/packages/core/aggregates.d.ts +6 -0
  23. package/dist/packages/core/aggregates.js +1 -1
  24. package/dist/packages/core/compact.d.ts +205 -0
  25. package/dist/packages/core/compact.js +3 -0
  26. package/dist/packages/core/dieTable.d.ts +137 -0
  27. package/dist/packages/core/dieTable.js +1 -0
  28. package/dist/packages/core/dies.d.ts +22 -0
  29. package/dist/packages/core/dies.js +1 -1
  30. package/dist/packages/core/passBins.d.ts +6 -0
  31. package/dist/packages/core/passBins.js +1 -1
  32. package/dist/packages/core/utils.d.ts +14 -0
  33. package/dist/packages/core/utils.js +1 -1
  34. package/dist/packages/renderer/axisTicks.d.ts +14 -0
  35. package/dist/packages/renderer/axisTicks.js +1 -1
  36. package/dist/packages/renderer/buildView.d.ts +29 -4
  37. package/dist/packages/renderer/buildView.js +1 -1
  38. package/dist/packages/renderer/buildWaferMap.d.ts +29 -11
  39. package/dist/packages/renderer/buildWaferMap.js +1 -1
  40. package/dist/packages/renderer/columnarInput.d.ts +87 -0
  41. package/dist/packages/renderer/columnarInput.js +1 -0
  42. package/dist/packages/renderer/compactView.d.ts +22 -0
  43. package/dist/packages/renderer/compactView.js +1 -0
  44. package/dist/packages/renderer/derivedTests/apply.d.ts +8 -6
  45. package/dist/packages/renderer/derivedTests/apply.js +1 -1
  46. package/dist/packages/renderer/index.d.ts +1 -0
  47. package/dist/packages/renderer/spec.d.ts +3 -7
  48. package/dist/packages/renderer/spec.js +1 -1
  49. package/dist/packages/renderer/xyIndicator.d.ts +27 -0
  50. package/dist/packages/renderer/xyIndicator.js +1 -0
  51. package/dist/packages/stats/analyzeWaferLot.d.ts +28 -0
  52. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  53. package/dist/packages/stats/analyzeWaferMap.d.ts +169 -2
  54. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  55. package/dist/packages/stats/binRows.d.ts +38 -0
  56. package/dist/packages/stats/binRows.js +1 -0
  57. package/dist/packages/stats/boxplot.js +1 -1
  58. package/dist/packages/stats/capability.d.ts +7 -7
  59. package/dist/packages/stats/capability.js +1 -1
  60. package/dist/packages/stats/clusterDetection.js +1 -1
  61. package/dist/packages/stats/connectedComponents.js +1 -1
  62. package/dist/packages/stats/correlation.js +1 -1
  63. package/dist/packages/stats/filterFindings.d.ts +30 -0
  64. package/dist/packages/stats/filterFindings.js +1 -1
  65. package/dist/packages/stats/findingText.d.ts +9 -0
  66. package/dist/packages/stats/findingText.js +2 -0
  67. package/dist/packages/stats/histogram.js +1 -1
  68. package/dist/packages/stats/lotDrift.d.ts +16 -0
  69. package/dist/packages/stats/lotDrift.js +1 -0
  70. package/dist/packages/stats/lotPattern.d.ts +33 -0
  71. package/dist/packages/stats/lotPattern.js +1 -0
  72. package/dist/packages/stats/math.d.ts +73 -6
  73. package/dist/packages/stats/math.js +1 -1
  74. package/dist/packages/stats/normalizeInput.js +1 -1
  75. package/dist/packages/stats/patternClassification.d.ts +34 -3
  76. package/dist/packages/stats/patternClassification.js +1 -1
  77. package/dist/packages/stats/presentation.d.ts +42 -0
  78. package/dist/packages/stats/presentation.js +1 -0
  79. package/dist/packages/stats/regions.d.ts +16 -0
  80. package/dist/packages/stats/regions.js +1 -1
  81. package/dist/packages/stats/renderSummaryReport.d.ts +15 -2
  82. package/dist/packages/stats/renderSummaryReport.js +32 -27
  83. package/dist/packages/stats/reportHtml.d.ts +54 -9
  84. package/dist/packages/stats/reportHtml.js +130 -47
  85. package/dist/packages/stats/scatter.js +1 -1
  86. package/dist/packages/stats/sweep.js +1 -1
  87. package/dist/packages/stats/synthesis.d.ts +66 -0
  88. package/dist/packages/stats/synthesis.js +2 -0
  89. package/dist/packages/stats/testPassRate.js +1 -1
  90. package/dist/packages/stats/trend.js +1 -1
  91. package/dist/packages/stats/types.d.ts +6 -1
  92. package/dist/packages/stats/yieldRows.d.ts +31 -0
  93. package/dist/packages/stats/yieldRows.js +1 -0
  94. package/dist/packages/worker/index.js +1 -1
  95. package/dist/packages/worker/wafermap.worker.d.ts +3 -0
  96. package/dist/packages/worker/wafermap.worker.js +1 -1
  97. package/llms.txt +1 -1
  98. package/package.json +1 -1
  99. package/dist/packages/stats/findingsNarrative.d.ts +0 -3
  100. package/dist/packages/stats/findingsNarrative.js +0 -1
@@ -1 +1 @@
1
- import{fontPx as Wt}from"./toolbar.js";import{findTestDef as We,buildMapTitle as Fe}from"../renderer/buildView.js";import{niceStep as Ft}from"../renderer/axisTicks.js";import{sortBinsForDisplay as lo}from"../stats/binPareto.js";import{affineInvert as io,affineVector as Oe}from"../core/transforms.js";import{compareNatural as ao,maxOf as zt,minOf as Ne}from"../core/utils.js";import{resolveValueColorFn as co}from"../renderer/colorSchemes.js";import{NO_DATA_FILL as ro}from"../renderer/colorMap.js";import{SPEC_PASS_FILL as Ee,SPEC_FAIL_LOW as fo,SPEC_FAIL_HIGH as He,contrastTextColor as Ye}from"../renderer/colorMap.js";import{fmt as Xe,fmtColorbarAxis as Ge}from"../renderer/fmt.js";import{resolveCanvasTheme as ho}from"./canvasTheme.js";import{hitGridDims as go}from"./hitGrid.js";function $e(g,e,X,x,c){g.moveTo(e,X+c*x),g.lineTo(e-x*.9,X-c*x*.6),g.lineTo(e+x*.9,X-c*x*.6),g.closePath()}const mo=new Set(["value","stackedValues","stackedBins","stackedSoftBins"]),uo=new Set(["hardBin","softBin","metadata"]),v=()=>`${Wt(-2)}px system-ui, sans-serif`,we=3,Jt=2,po=6,xo=20,bo=()=>`600 ${Wt()}px system-ui, sans-serif`,Ve=36,ue=()=>`${Wt(-1)}px system-ui, sans-serif`,Mo=()=>`600 ${Wt(-1)}px system-ui, sans-serif`,Zt=128,yo=()=>`${Wt(-2)}px system-ui, sans-serif`,Ke=4,E=17,$=11;export const BIN_LEGEND_W=110,BIN_LEGEND_W_COMPACT=64,BIN_LEGEND_ADAPT_COMPACT=280,BIN_LEGEND_ADAPT_FLOATING=180,BIN_LEGEND_MIN_CANVAS_W=150,BIN_LEGEND_MIN_CANVAS_H=120;const jt=28,ut=5,ht=8,Ue=15,qe=12,ze=6;export function toCanvas(g,e,X={}){return drawMapCanvas(g,e,X)}export function drawMapCanvas(g,e,X={}){const x=ho(g.parentElement??g),{padding:c=16,showColorbar:V=!0,markFailingDies:K=!1,colorbarWidth:D=16,background:pt=x.background,legendPosition:tt="default",legendOffset:xt,showAxes:bt=!1,diePitchMm:q,viewport:Z,activeBin:Y,hoverBin:j,fallbackFormat:Mt,minRightReserve:Ot,hbinDefs:ct,sbinDefs:yt,metadataFields:Tt,showTitle:z=!0}=X,F=Math.floor(g.clientWidth||g.width),G=Math.floor(g.clientHeight||g.height),St=F>=BIN_LEGEND_MIN_CANVAS_W&&G>=BIN_LEGEND_MIN_CANVAS_H,At=V&&St&&mo.has(e.plotMode)&&e.passFailDisplay==="off",Rt=V&&St&&uo.has(e.plotMode),ot=V&&St&&e.plotMode==="value"&&(e.passFailDisplay==="spec"&&e.specCounts!==void 0||e.passFailDisplay==="test"&&e.passFailCounts!==void 0),nt=Rt||ot,Nt=Rt&&e.plotMode!=="metadata"&&e.binCounts?lo(e.binCounts.entries(),e.plotMode==="softBin"?e.binColors.pass.soft:e.binColors.pass.hard):[],Et=Rt&&e.plotMode==="metadata"&&e.metadataCounts?[...e.metadataColorMap?.keys()??[...e.metadataCounts.keys()].sort(ao)].map(o=>[o,e.metadataCounts.get(o)??0]):[],st=[];if(ot&&e.passFailDisplay==="test"){const o=e.passFailCounts;st.push({key:-1,color:Ee,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),st.push({key:-2,color:He,label:"Fail",compactLabel:"Fail",count:o.fail,tooltip:`Fail \xB7 ${o.fail} dies`})}else if(ot){const o=e.specCounts,f=We(e.testDefs,e.activeTest);st.push({key:-1,color:Ee,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),f?.limitHigh!==void 0&&st.push({key:-2,color:He,label:"Fail high",compactLabel:"Fail hi",count:o.failHigh,tooltip:`Fail high \xB7 ${o.failHigh} dies`}),f?.limitLow!==void 0&&st.push({key:-3,color:fo,label:"Fail low",compactLabel:"Fail lo",count:o.failLow,tooltip:`Fail low \xB7 ${o.failLow} dies`})}const Ht=ot?st.length:e.plotMode==="metadata"?Et.length:Nt.length,u=(g.ownerDocument.defaultView??window).devicePixelRatio??1;if(F<=0||G<=0)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const k=tt!=="default"?tt:F<BIN_LEGEND_ADAPT_FLOATING?"floating":F<BIN_LEGEND_ADAPT_COMPACT?"compact":"default",dt=k==="default"||k==="compact",pe=k==="left",Qt=k==="bottom",_t=k==="top",Ct=k==="floating",Yt=k==="compact"||k==="floating"?BIN_LEGEND_W_COMPACT:BIN_LEGEND_W,xe=Math.floor((G-2*c)/E),be=Ht>xe?xe-1:Ht,Me=nt&&Qt?be*E:0,vt=nt&&_t?be*E:0,te=e.plotMode==="stackedBins"||e.plotMode==="stackedSoftBins",ee=We(e.testDefs,e.activeTest),ye=te?"Count":ee?.name??(e.activeTest!=null?`Test ${e.activeTest}`:void 0),Te=te?void 0:ee?.unit,[Bt,Pt]=e.valueRange,oe=o=>String(Math.round(o)),Je=e.logScale||e.allIntegerValues?void 0:Ft(Math.max(0,Pt-Bt)*Ve/Math.max(1,G))||void 0,ne=e.allIntegerValues?oe:Ge(Pt,ye,Te,Mt,Je).edgeFmt;let se=0;if(At){const o=g.getContext("2d");o.font=v();const f=[ne(Bt),ne(Pt)];Bt<0&&f.push(ne(-Math.max(Math.abs(Bt),Math.abs(Pt))));for(const n of f)se=Math.max(se,o.measureText(n).width)}const Se=Math.max(xo,Math.ceil(se)+we+Jt+po-c),le=At?D+Se+8:nt&&dt?Yt:0,ie=nt&&pe?Yt:0,ae=bt?32:0,Xt=bt?36:0,Ze=Ot!=null?Math.max(le,Ot):le,je=F-2*c-Ze-Xt-ie,Le=G-2*c-ae-Me-vt;g.width=Math.round(F*u),g.height=Math.round(G*u);const t=g.getContext("2d");t.scale(u,u),t.fillStyle=pt,t.fillRect(0,0,F,G);const U=e.hoverPoints;if(!U.length)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const Gt=e.rectangles[0],ce=Gt?Gt.width/2:0,re=Gt?Gt.height/2:0,$t=e.dieBounds,ke=($t?.minX??0)-ce,Qe=($t?.maxX??0)+ce,ve=($t?.minY??0)-re,Ae=($t?.maxY??0)+re,Re=Qe-ke,_e=Ae-ve;let lt,it,A;if(Z)({originX:lt,originY:it,ppm:A}=Z);else{const f=e.notchDir,n=f&&f.y>.1?13:0,a=f&&f.y<-.1?13:0,r=f&&f.x<-.1?13:0,h=f&&f.x>.1?13:0,d=je-r-h,s=Le-n-a;A=Math.min(d/Re,s/_e),lt=c+Xt+ie+r+(d-Re*A)/2-ke*A,it=c+vt+n+(s-_e*A)/2+Ae*A}const wt=Z?.snapDist??Math.max(ce,re,1)*1.5,Vt=lt+e.waferCenter.x*A,to=it-e.waferCenter.y*A,fe=e.waferRadius*A,rt=o=>{const f=Math.abs(o-to);return f>=fe?0:Math.sqrt(fe*fe-f*f)},gt=(o,f,n,a,r,h,d=bo(),s=x.text)=>{if(!o)return;t.save(),t.fillStyle=s,t.font=d,t.textAlign=a,t.textBaseline=r;const p=a==="right"?f-h:h-f;let l=o;if(p>8&&t.measureText(l).width>p){for(;l.length>1&&t.measureText(l+"\u2026").width>p;)l=l.slice(0,-1);l=l+"\u2026"}p>8&&t.fillText(l,f,n),t.restore()};t.save(),t.setTransform(A*u,0,0,-A*u,lt*u,it*u);const mt=1/A,eo=1/(A*u);if(e.rectangles.length>0){const o=new Map;for(const n of e.rectangles){const a=String(n.fill);let r=o.get(a);r||(r=[],o.set(a,r)),r.push(n)}for(const[n,a]of o){t.beginPath();for(const r of a)t.rect(r.x-r.width/2,r.y-r.height/2,r.width,r.height);t.fillStyle=n,t.fill()}t.strokeStyle="rgba(0,0,0,0.18)",t.lineWidth=.5*eo,t.beginPath();for(const n of e.rectangles)t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height);if(t.stroke(),K){const n=e.rectangles.filter(a=>a.binFail);if(n.length>0){const a=new Map;for(const r of n){const h=Ye(String(r.fill));let d=a.get(h);d||(d=[],a.set(h,d)),d.push(r)}t.save(),t.lineCap="butt";for(const[r,h]of a){t.strokeStyle=r,t.globalAlpha=.55,t.lineWidth=Math.max(.6*mt,Math.min(h[0].width,h[0].height)*.1);for(const d of h){const s=d.width/2,p=d.height/2,l=Math.max(1.6*mt,Math.min(d.width,d.height)/3);t.save(),t.beginPath(),t.rect(d.x-s,d.y-p,d.width,d.height),t.clip(),t.beginPath();for(let M=-(s+p);M<=s+p;M+=l)t.moveTo(d.x-s+M,d.y-p),t.lineTo(d.x-s+M+d.height,d.y+p);t.stroke(),t.restore()}}t.restore()}}const f=e.rectangles.filter(n=>n.specMark);if(f.length>0){const n=new Map;for(const r of f){const h=Ye(String(r.fill)),d=`${r.specMark}|${h}`;let s=n.get(d);s||(s=[],n.set(d,s)),s.push(r)}const a=2.5*mt;t.lineJoin="round";for(const[r,h]of n){const[d,s]=r.split("|"),p=s==="#000000"?"#ffffff":"#000000",l=d==="failHigh"?1:-1,M=Math.min(h[0].width,h[0].height),H=Math.max(2.5*mt,M*.3);t.beginPath();for(const I of h)$e(t,I.x,I.y,H,l);t.strokeStyle=p,t.lineWidth=a,t.stroke(),t.fillStyle=s,t.fill()}}}for(const o of e.overlays){t.beginPath();for(const f of o.points){for(let n=0;n<f.length;n++)n===0?t.moveTo(f[n].x,f[n].y):t.lineTo(f[n].x,f[n].y);o.closed&&t.closePath()}o.fill&&!o.fill.startsWith("rgba(0,0,0,0)")&&(t.fillStyle=o.fill,t.fill()),o.kind==="ring-boundary"||o.kind==="quadrant-boundary"||o.kind==="reticle"?(t.strokeStyle="rgba(0,0,0,0.45)",t.lineWidth=3*mt,t.stroke(),t.strokeStyle="rgba(255,255,255,0.8)",t.lineWidth=1*mt,t.stroke()):(t.strokeStyle=o.lineColor,t.lineWidth=o.lineWidth*mt,t.stroke())}if(t.restore(),e.notchDir){const o=lt+e.waferCenter.x*A,f=it-e.waferCenter.y*A,n=e.notchDir.x,a=-e.notchDir.y,r=e.waferRadius*A,h=4,d=9,s=5,p=o+n*(r+h),l=f+a*(r+h),M=p+n*d,H=l+a*d,I={x:-a,y:n},L=c+Xt+ie,w=F-c-le,J=c+vt,at=G-c-Me-ae;t.save(),t.beginPath(),t.rect(L,J,w-L,at-J),t.clip(),t.beginPath(),t.moveTo(p,l),t.lineTo(M+I.x*s,H+I.y*s),t.lineTo(M-I.x*s,H-I.y*s),t.closePath(),t.fillStyle=x.text,t.fill(),t.restore()}t.save(),t.textAlign="center",t.textBaseline="middle";let Ce=0;if(e.rectangles.length>0){let o=1;for(const h of e.texts)h.role!=="indicator"&&h.text.length>o&&(o=h.text.length);const f=e.rectangles[0].width*A,n=e.rectangles[0].height*A,a=Math.min(f,n),r=f/o;Ce=Math.max(8,Math.min(64,Math.round(Math.min(a*.55,r*1.8))))}for(const o of e.texts){const f=lt+o.x*A,n=it-o.y*A;t.font=`${o.role==="indicator"?o.fontSize:Ce}px system-ui, sans-serif`,t.fillStyle=o.color,t.fillText(o.text,f,n)}if(t.restore(),bt&&To(t,F,G,lt,it,A,c,ae,Xt,q,e.gridToScreen,e.rotation,x),At){const o=co(e.valueColorScheme,e.reverseValueScheme),f=Se,n=Le,a=Math.round(n*.75),r=c+Math.round((n-a)/2),h=F-c-D-f,d=Bt,s=Pt,p=s-d,l=e.plotMode==="stackedSoftBins"?yt:ct,{primary:M,secondary:H,note:I}=z?Fe(e,Mt,l):{primary:"",secondary:"",note:void 0};if(z){const i=Math.max(r-6,c+11),P=Vt+Math.max(rt(i),rt(i-12))+8;gt(M,F-c,i,"right","bottom",P)}let L=r+a+4;const w=i=>Vt+Math.max(rt(i),rt(i+12))+8,J=e.logScale&&d>0?Math.log10(d):0,at=e.logScale&&s>0?Math.log10(s)-J:1,_=i=>e.logScale?(1-(Math.log10(i)-J)/at)*a:(1-(i-d)/p)*a;for(let i=0;i<Zt;i++){const P=1-i/(Zt-1),W=r+i/Zt*a,m=a/Zt+1;t.fillStyle=o(P),t.fillRect(h,W,D,m)}t.strokeStyle="rgba(0,0,0,0.25)",t.lineWidth=.5,t.strokeRect(h,r,D,a),t.fillStyle=x.text,t.font=v(),t.textAlign="left",t.strokeStyle="rgba(0,0,0,0.35)",t.lineWidth=.5;const C=we,It=Ve,et=14;let O;const B=e.logScale&&at>0?So(d,s,a,It,et,J,at):e.allIntegerValues?(()=>{const i=Math.max(1,Ft(p*It/a)),P=[],W=Math.ceil(d/i)*i;for(let m=W;m<=s+i*1e-6;m+=i){const R=(1-(m-d)/p)*a;R>et&&R<a-et&&P.push(Math.round(m))}return P})():(()=>{const i=p>0?Ft(p*It/a):0,P=[];if(i>0){O=i;const W=Math.ceil(d/i)*i;for(let m=W;m<=s+i*1e-6;m+=i){const R=(1-(m-d)/p)*a;R>et&&R<a-et&&P.push(m)}}return P})(),b=ee,S=te,y=Ge(s,ye,Te,Mt,O),N=e.allIntegerValues?oe:y.tickFmt,T=e.allIntegerValues?oe:y.edgeFmt;t.textBaseline="middle";for(const i of B){const P=r+_(i);t.beginPath(),t.moveTo(h+D,P),t.lineTo(h+D+C,P),t.stroke(),t.fillText(N(i),h+D+C+Jt,P)}if(t.beginPath(),t.moveTo(h+D,r),t.lineTo(h+D+C,r),t.stroke(),t.textBaseline="top",t.fillText(T(s),h+D+C+Jt,r),t.beginPath(),t.moveTo(h+D,r+a),t.lineTo(h+D+C,r+a),t.stroke(),t.textBaseline="bottom",t.fillText(T(d),h+D+C+Jt,r+a),!S&&b&&(b.limitLow!==void 0||b.limitHigh!==void 0)){const i=[],P=e.colorbarRangeMode==="spec";for(const[W,m]of[[b.limitLow,"Lo limit"],[b.limitHigh,"Hi limit"]]){if(W===void 0||e.logScale&&W<=0)continue;const R=_(W);!P&&(R<-et||R>a+et)||i.push({value:W,label:m,py:Math.max(0,Math.min(a,R))})}if(i.length>0){t.save(),t.font=v(),t.textAlign="right",t.textBaseline="middle";for(const{py:W,label:m}of i){const R=r+W;P||(t.strokeStyle="rgba(255,255,255,0.85)",t.lineWidth=3,t.beginPath(),t.moveTo(h,R),t.lineTo(h+D,R),t.stroke(),t.strokeStyle="rgba(0,0,0,0.7)",t.lineWidth=1,t.beginPath(),t.moveTo(h,R),t.lineTo(h+D,R),t.stroke()),t.fillStyle=x.text,t.fillText(m,h-3,R);const Lt=m==="Hi limit"?-1:1,kt=4,qt=h-3-t.measureText(m).width-kt-4;t.beginPath(),$e(t,qt,R,kt,Lt),t.strokeStyle="#fff",t.lineWidth=2,t.lineJoin="round",t.stroke(),t.fillStyle=x.text,t.fill()}t.restore()}}if(!S){const i=e.logScale?"log\u2081\u2080":e.logScaleRequested?"linear \u2014 log n/a":null;i&&(t.save(),t.fillStyle=x.text,t.font=Mo(),t.textAlign="right",t.textBaseline="top",t.fillText(i,F-c,L),t.restore(),L+=15)}z&&H&&(gt(H,F-c,L,"right","top",w(L),ue(),x.text),L+=15),z&&I&&gt(I,F-c,L,"right","top",w(L),ue(),x.text)}const he=[];let Q;if(nt){const o=k==="compact",f=e.plotMode==="softBin"?yt:ct,n=f?new Map(f.map(l=>[l.bin,l])):null,a=e.plotMode==="softBin"?e.binColors.soft:e.binColors.hard,r=l=>a.get(l)??ro,h=(l,M)=>{const H=t.measureText(l).width,I=o?0:t.measureText(String(M)).width,L=$+ut+H+(I?jt:0);return{labelWidth:H,countWidth:I,totalWidth:L}},d=Tt?.find(l=>l.key===e.activeMetadataKey),s=ot?st.map(l=>{const M=o?l.compactLabel:l.label;return{key:l.key,color:l.color,count:l.count,label:M,tooltipLabel:l.tooltip,...h(M,l.count)}}):e.plotMode==="metadata"?Et.map(([l,M])=>{const I=d?.values?.find(J=>J.value===l)?.label??l,L=o?l:I,w=e.metadataColorMap?.get(l)??"#d6d9dd";return{key:l,color:w,count:M,label:L,tooltipLabel:`${I} \xB7 ${M} dies`,...h(L,M)}}):Nt.map(([l,M])=>{const H=n?.get(l),I=H?.name?`${l} \xB7 ${H.name}`:`Bin ${l}`,L=o?String(l):I;return{key:l,color:r(l),count:M,label:L,tooltipLabel:`${I} \xB7 ${M} dies`,...h(L,M)}}),p=F-c*2;if(s.length>0){const l=Ct?ht*2+(z?Ue:0):z&&!_t?qe+ze:0,M=Math.max(1,Math.floor((G-2*c-l)/E));let H=s.length,I=1,L=H*E,w=[],J=0;const at=Qt||_t;if(at){const O=zt(s.map(b=>b.totalWidth)),B=Math.max(1,Math.min(s.length,Math.floor((p+8)/(O+8))));for(let b=B;b>=1;b--){const S=Math.ceil(s.length/b);if(S>M)continue;const y=new Array(b).fill(0);for(let T=0;T<s.length;T++){const i=T%b;y[i]=Math.max(y[i],s[T].totalWidth)}if(y.reduce((T,i)=>T+i,0)+(b-1)*8<=p||b===1){I=b,w=y,H=S,L=S*E;break}}}else H=Math.min(s.length,M),L=H*E,s.length>M&&(J=s.length-(M-1)),w=[Yt];let _,C;if(Ct){const O=zt(s.map(i=>$+ut+t.measureText(i.label).width+jt)),B=Math.ceil(O);w=[B];const b=z?Ue:0,S=B+ht*2,y=L+b+ht*2,N=xt?.x??0,T=xt?.y??0;_=Math.min(Math.max(F-c-S+N,c),F-c-S),C=Math.min(Math.max(G-c-y+T,c),G-c-y),Q={x:_,y:C,w:S,h:y},t.save(),t.globalAlpha=.92,t.fillStyle=x.surface,t.fillRect(_,C,S,y),t.globalAlpha=1,t.strokeStyle=x.axisLine,t.lineWidth=1,t.strokeRect(_,C,S,y),t.restore(),_+=ht,C+=ht+b}else Qt?(_=c,C=G-c-L):_t?(_=c,C=c):pe?(_=c+4,C=Math.max(c+Math.round((G-2*c-L)/2),c+l)):(_=F-c-Yt+4,C=Math.max(c+Math.round((G-2*c-L)/2),c+l));if(z){const O=e.plotMode==="softBin"?yt:ct,{primary:B,secondary:b,note:S}=Fe(e,Mt,O),y=ze,N=[b,S].filter(m=>!!m),T=(m,R,Lt)=>N.forEach((kt,qt)=>gt(kt,m,R+qt*16,"left","top",Lt(R+qt*16),ue(),x.text)),i=m=>Vt-Math.max(rt(m),rt(m-12))-8,P=m=>dt?F-c:i(m),W=Ct?Q.y+Q.h:C+L;if(_t){const m=W+y;gt(B,_,m,"left","top",Vt-Math.max(rt(m),rt(m+12))-8),T(_,m+16,i)}else if(Ct)gt(B,Q.x+ht,Q.y+ht,"left","top",Q.x+Q.w-ht),T(Q.x,W+y,()=>Q.x+Q.w);else{const m=Math.max(C-y,c+qe);gt(B,_,m,"left","bottom",P(m)),T(_,W+y,P)}}t.save(),t.font=v();const It=at?8:0,et=(O,B)=>{if(t.measureText(O).width<=B)return O;let b=0,S=O.length;const y="\u2026",N=t.measureText(y).width;for(;b<S;){const T=b+S+1>>1;t.measureText(O.slice(0,T)).width+N<=B?b=T:S=T-1}return b===0?y:O.slice(0,b)+y};if(at){let O=0;for(let B=0;B<H;B++){let b=_;for(let S=0;S<I;S++){const y=s[O++];if(!y)break;const N=y.key===Y,T=!N&&y.key===j,i=b,P=b+$+ut,W=C+B*E+E/2,m=C+B*E+Math.round((E-$)/2),R=w[S]-$-ut-jt;T&&(t.fillStyle=x.hoverRow,t.fillRect(b,C+B*E,w[S],E)),t.fillStyle=y.color,t.fillRect(i,m,$,$),t.strokeStyle=N?x.accent:"rgba(0,0,0,0.25)",t.lineWidth=N?2:.75,t.strokeRect(i,m,$,$),t.fillStyle=N?x.accent:x.text,t.font=N?`bold ${v()}`:v(),t.textAlign="left",t.textBaseline="middle",t.fillText(et(y.label,R),P,W),t.fillStyle=x.textMuted,t.font=v(),t.textAlign="right",t.fillText(String(y.count),b+w[S]-2,W),he.push({bin:y.key,x:b,y:C+B*E,w:w[S],h:E,label:y.tooltipLabel}),b+=w[S]+It}}}else{const O=w[0],B=k!=="compact",b=O-$-ut-(B?jt:0),S=_+O-2;let y=s;J>0&&(y=s.slice(0,M-1));let N=C;for(const T of y){const i=T.key===Y,P=!i&&T.key===j,W=_,m=_+$+ut,R=N+E/2,Lt=N+Math.round((E-$)/2),kt=T.label;P&&(t.fillStyle=x.hoverRow,t.fillRect(_-3,N,O+3,E)),t.fillStyle=T.color,t.fillRect(W,Lt,$,$),t.strokeStyle=i?x.accent:"rgba(0,0,0,0.25)",t.lineWidth=i?2:.75,t.strokeRect(W,Lt,$,$),t.fillStyle=i?x.accent:x.text,t.font=i?`bold ${v()}`:v(),t.textAlign="left",t.textBaseline="middle",t.fillText(et(kt,b),m,R),(B||Ct)&&(t.fillStyle=x.textMuted,t.font=v(),t.textAlign="right",t.fillText(String(T.count),S,R)),he.push({bin:T.key,x:_,y:N,w:O,h:E,label:T.tooltipLabel}),N+=E}J>0&&(t.fillStyle=x.textMuted,t.font=v(),t.textAlign="left",t.textBaseline="middle",t.fillText(`+ ${J} more`,_+$+ut,N+E/2))}}s.length>0&&t.restore()}const oo={originX:lt,originY:it,ppm:A,snapDist:wt},Be=e.rectangles[0]?.width??1,Pe=e.rectangles[0]?.height??1,ft=e.dieBounds,Kt=ft?ft.minX:U.length?Ne(U.map(o=>o.x)):0,Ut=ft?ft.minY:U.length?Ne(U.map(o=>o.y)):0,no=ft?ft.maxX:U.length?zt(U.map(o=>o.x)):1,so=ft?ft.maxY:U.length?zt(U.map(o=>o.y)):1,{cellW:de,cellH:ge,nCols:Dt,nRows:me}=go(no-Kt,so-Ut,Be*1.5,Pe*1.5,U.length),De=Array.from({length:Dt*me},()=>[]);for(let o=0;o<U.length;o++){const f=Math.floor((U[o].x-Kt)/de),n=Math.floor((U[o].y-Ut)/ge),a=Number.isFinite(f)?Math.max(0,Math.min(Dt-1,f)):0,r=Number.isFinite(n)?Math.max(0,Math.min(me-1,n)):0;De[r*Dt+a].push(o)}function Ie(o,f,n){const a=Math.max(0,Math.floor((o-n-Kt)/de)),r=Math.min(Dt-1,Math.floor((o+n-Kt)/de)),h=Math.max(0,Math.floor((f-n-Ut)/ge)),d=Math.min(me-1,Math.floor((f+n-Ut)/ge)),s=[];for(let p=h;p<=d;p++)for(let l=a;l<=r;l++)for(const M of De[p*Dt+l])s.push(M);return s}return{hitTarget:{getDieAtPoint(o,f){const n=(o-lt)/A,a=(it-f)/A,r=Math.max(Be,Pe);for(const s of Ie(n,a,r)){const p=e.rectangles[s];if(p&&Math.abs(n-p.x)<=p.width/2&&Math.abs(a-p.y)<=p.height/2)return e.dies[s]??null}let h=null,d=wt*wt;for(const s of Ie(n,a,wt)){const p=U[s].x-n,l=U[s].y-a,M=p*p+l*l;M<d&&(d=M,h=e.dies[s]??null)}return h}},viewport:oo,binLegendRows:he,legendBox:Q}}function To(g,e,X,x,c,V,K,D,pt,tt,xt,bt,q){g.save(),g.font=yo(),g.fillStyle=q.text,g.strokeStyle=q.axisLine,g.lineWidth=.5;const Z=X-D+4,Y=K+pt-4,j=io(xt),Mt=Oe(j,1,0),Ot=Oe(j,0,1),ct=1e-9;function yt(u){return tt?Math.abs(u.y)<ct&&Math.abs(u.x)>ct?{pitch:tt.x,sign:Math.sign(u.x)}:Math.abs(u.x)<ct&&Math.abs(u.y)>ct?{pitch:tt.y,sign:Math.sign(u.y)}:null:null}const Tt=yt(Mt),z=yt(Ot);function F(u){return Tt?Math.round(u*Tt.sign/Tt.pitch):u}function G(u){return z?Math.round(u*z.sign/z.pitch):u}function St(u){if(!u)return Ft(50/V);const k=50/(u*V);return Math.max(1,Math.round(k))*u}const At=Tt?.pitch,Rt=z?.pitch,ot=St(At),nt=St(Rt);g.textAlign="center",g.textBaseline="top";const Nt=Math.ceil((K-x)/V/ot)*ot,Et=(e-K-x)/V;for(let u=Nt;u<=Et;u+=ot){const k=x+u*V;if(k<K||k>e-K)continue;g.beginPath(),g.moveTo(k,Z-Ke),g.lineTo(k,Z),g.stroke();const dt=tt?String(F(u)):Xe(u);g.fillText(dt,k,Z+2)}g.textAlign="right",g.textBaseline="middle";const st=Math.ceil((c-(X-K))/V/nt)*nt,Ht=(c-K)/V;for(let u=st;u<=Ht;u+=nt){const k=c-u*V;if(k<K||k>X-K)continue;g.beginPath(),g.moveTo(Y,k),g.lineTo(Y+Ke,k),g.stroke();const dt=tt?String(G(u)):Xe(u);g.fillText(dt,Y-2,k)}g.restore()}function So(g,e,X,x,c,V,K){const D=[],pt=K;if(pt<1){const q=Ft((e-g)*x/X);if(q>0){const Z=Math.ceil(g/q)*q;for(let Y=Z;Y<=e+q*1e-6;Y+=q){if(Y<=g||Y>=e)continue;const j=(1-(Math.log10(Y)-V)/K)*X;j>c&&j<X-c&&D.push(Y)}}return D}const tt=pt<3?[1,2,5]:[1],xt=Math.floor(Math.log10(g)),bt=Math.ceil(Math.log10(e));for(let q=xt;q<=bt;q++)for(const Z of tt){const Y=Z*Math.pow(10,q);if(Y<=g||Y>=e)continue;const j=(1-(Math.log10(Y)-V)/K)*X;j>c&&j<X-c&&D.push(Y)}return D}export{fmt,fmtColorbarAxis}from"../renderer/fmt.js";
1
+ import{fontPx as Nt}from"./toolbar.js";import{findTestDef as Oe,buildMapTitle as Ne}from"../renderer/buildView.js";import{niceStep as Et,compactTickIndices as ro}from"../renderer/axisTicks.js";import{sortBinsForDisplay as fo}from"../stats/binPareto.js";import{affineInvert as ho,affineVector as Ee}from"../core/transforms.js";import{asList as go,compareNatural as mo,maxOf as Qt,minOf as He}from"../core/utils.js";import{resolveValueColorFn as uo}from"../renderer/colorSchemes.js";import{NO_DATA_FILL as po}from"../renderer/colorMap.js";import{SPEC_PASS_FILL as Ye,SPEC_FAIL_LOW as xo,SPEC_FAIL_HIGH as Xe,contrastTextColor as Ge}from"../renderer/colorMap.js";import{fmt as $e,fmtColorbarAxis as we}from"../renderer/fmt.js";import{resolveCanvasTheme as bo}from"./canvasTheme.js";import{hitGridDims as Mo}from"./hitGrid.js";function Ve(h,e,P,u,s){h.moveTo(e,P+s*u),h.lineTo(e-u*.9,P-s*u*.6),h.lineTo(e+u*.9,P-s*u*.6),h.closePath()}const yo=new Set(["value","stackedValues","stackedBins","stackedSoftBins"]),To=new Set(["hardBin","softBin","metadata"]),lt=()=>`${Nt(-2)}px system-ui, sans-serif`,Ke=3,vt=2,So=6,ko=20,Lo=()=>`600 ${Nt()}px system-ui, sans-serif`,qe=36,be=()=>`${Nt(-1)}px system-ui, sans-serif`,Ao=()=>`600 ${Nt(-1)}px system-ui, sans-serif`,te=128,Co=()=>`${Nt(-2)}px system-ui, sans-serif`,ze=4,V=17,Z=11;export const BIN_LEGEND_W=110,BIN_LEGEND_W_COMPACT=64,BIN_LEGEND_ADAPT_COMPACT=280,BIN_LEGEND_ADAPT_FLOATING=180,BIN_LEGEND_MIN_CANVAS_W=150,BIN_LEGEND_MIN_CANVAS_H=120;const ee=28,Lt=5,bt=8,Ue=15,Je=12,je=6;export function toCanvas(h,e,P={}){return drawMapCanvas(h,e,P)}export function drawMapCanvas(h,e,P={}){const u=bo(h.parentElement??h),{padding:s=16,showColorbar:C=!0,markFailingDies:z=!1,colorbarWidth:g=16,background:Y=u.background,legendPosition:D="default",legendOffset:U,showAxes:J=!1,diePitchMm:R,viewport:X,activeBin:N,hoverBin:Q,afterDies:Ht,fallbackFormat:At,minRightReserve:Yt,hbinDefs:mt,sbinDefs:Ct,metadataFields:Xt,showTitle:tt=!0}=P,ut=go(N),G=Math.floor(h.clientWidth||h.width),j=Math.floor(h.clientHeight||h.height),Rt=G>=BIN_LEGEND_MIN_CANVAS_W&&j>=BIN_LEGEND_MIN_CANVAS_H,Pt=C&&Rt&&yo.has(e.plotMode)&&e.passFailDisplay==="off",Dt=C&&Rt&&To.has(e.plotMode),ft=C&&Rt&&e.plotMode==="value"&&(e.passFailDisplay==="spec"&&e.specCounts!==void 0||e.passFailDisplay==="test"&&e.passFailCounts!==void 0),ht=Dt||ft,Gt=Dt&&e.plotMode!=="metadata"&&e.binCounts?fo(e.binCounts.entries(),e.plotMode==="softBin"?e.binColors.pass.soft:e.binColors.pass.hard):[],$t=Dt&&e.plotMode==="metadata"&&e.metadataCounts?[...e.metadataColorMap?.keys()??[...e.metadataCounts.keys()].sort(mo)].map(o=>[o,e.metadataCounts.get(o)??0]):[],dt=[];if(ft&&e.passFailDisplay==="test"){const o=e.passFailCounts;dt.push({key:-1,color:Ye,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),dt.push({key:-2,color:Xe,label:"Fail",compactLabel:"Fail",count:o.fail,tooltip:`Fail \xB7 ${o.fail} dies`})}else if(ft){const o=e.specCounts,a=Oe(e.testDefs,e.activeTest);dt.push({key:-1,color:Ye,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),a?.limitHigh!==void 0&&dt.push({key:-2,color:Xe,label:"Fail high",compactLabel:"Fail hi",count:o.failHigh,tooltip:`Fail high \xB7 ${o.failHigh} dies`}),a?.limitLow!==void 0&&dt.push({key:-3,color:xo,label:"Fail low",compactLabel:"Fail lo",count:o.failLow,tooltip:`Fail low \xB7 ${o.failLow} dies`})}const wt=ft?dt.length:e.plotMode==="metadata"?$t.length:Gt.length,nt=(h.ownerDocument.defaultView??window).devicePixelRatio??1;if(G<=0||j<=0)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const ot=D!=="default"?D:G<BIN_LEGEND_ADAPT_FLOATING?"floating":G<BIN_LEGEND_ADAPT_COMPACT?"compact":"default",b=ot==="default"||ot==="compact",it=ot==="left",K=ot==="bottom",Mt=ot==="top",yt=ot==="floating",Tt=ot==="compact"||ot==="floating"?BIN_LEGEND_W_COMPACT:BIN_LEGEND_W,Me=Math.floor((j-2*s)/V),ye=wt>Me?Me-1:wt,Te=ht&&K?ye*V:0,oe=ht&&Mt?ye*V:0,ne=e.plotMode==="stackedBins"||e.plotMode==="stackedSoftBins",se=Oe(e.testDefs,e.activeTest),Se=ne?"Count":se?.name??(e.activeTest!=null?`Test ${e.activeTest}`:void 0),ke=ne?void 0:se?.unit,[It,Wt]=e.valueRange,le=o=>String(Math.round(o)),ve=e.logScale||e.allIntegerValues?void 0:Et(Math.max(0,Wt-It)*qe/Math.max(1,j))||void 0,ie=e.allIntegerValues?le:we(Wt,Se,ke,At,ve).edgeFmt;let ae=0;if(Pt){const o=h.getContext("2d");o.font=lt();const a=[ie(It),ie(Wt)];It<0&&a.push(ie(-Math.max(Math.abs(It),Math.abs(Wt))));for(const p of a)ae=Math.max(ae,o.measureText(p).width)}const Le=Math.max(ko,Math.ceil(ae)+Ke+vt+So-s),ce=Pt?g+Le+8:ht&&b?Tt:0,re=ht&&it?Tt:0,fe=J?32:0,Vt=J?36:0,to=Yt!=null?Math.max(ce,Yt):ce,eo=G-2*s-to-Vt-re,Ae=j-2*s-fe-Te-oe;h.width=Math.round(G*nt),h.height=Math.round(j*nt);const t=h.getContext("2d");t.scale(nt,nt),t.fillStyle=Y,t.fillRect(0,0,G,j);const v=e.hoverPoints;if(!v.length)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const Kt=e.rectangles[0],he=Kt?Kt.width/2:0,de=Kt?Kt.height/2:0,qt=e.dieBounds,Ce=(qt?.minX??0)-he,oo=(qt?.maxX??0)+he,no=(qt?.minY??0)-de,Re=(qt?.maxY??0)+de,_e=oo-Ce,Be=Re-no;let at,ct,_;if(X)({originX:at,originY:ct,ppm:_}=X);else{const a=e.notchDir,p=a&&a.y>.1?13:0,m=a&&a.y<-.1?13:0,d=a&&a.x<-.1?13:0,c=a&&a.x>.1?13:0,f=eo-d-c,l=Ae-p-m;_=Math.min(f/_e,l/Be),at=s+Vt+re+d+(f-_e*_)/2-Ce*_,ct=s+oe+p+(l-Be*_)/2+Re*_}const zt=X?.snapDist??Math.max(he,de,1)*1.5,Ut=at+e.waferCenter.x*_,so=ct-e.waferCenter.y*_,ge=e.waferRadius*_,pt=o=>{const a=Math.abs(o-so);return a>=ge?0:Math.sqrt(ge*ge-a*a)},St=(o,a,p,m,d,c,f=Lo(),l=u.text)=>{if(!o)return;t.save(),t.fillStyle=l,t.font=f,t.textAlign=m,t.textBaseline=d;const i=m==="right"?a-c:c-a;let n=o;if(i>8&&t.measureText(n).width>i){for(;n.length>1&&t.measureText(n+"\u2026").width>i;)n=n.slice(0,-1);n=n+"\u2026"}i>8&&t.fillText(n,a,p),t.restore()};t.save(),t.setTransform(_*nt,0,0,-_*nt,at*nt,ct*nt);const kt=1/_,lo=1/(_*nt);if(e.rectangles.length>0){const o=new Map;for(const d of e.rectangles){const c=String(d.fill);let f=o.get(c);f||(f=[],o.set(c,f)),f.push(d)}for(const[d,c]of o){t.fillStyle=d;for(let f=0;f<c.length;f+=PATH_SHAPES){t.beginPath();const l=Math.min(c.length,f+PATH_SHAPES);for(let i=f;i<l;i++){const n=c[i];t.rect(n.x-n.width/2,n.y-n.height/2,n.width,n.height)}t.fill()}}t.strokeStyle="rgba(0,0,0,0.18)",t.lineWidth=.5*lo,t.lineCap="square";const a=Qe.get(e.rectangles)??outlineSegments(e.rectangles);Qe.set(e.rectangles,a);const p=PATH_SHAPES*4;for(let d=0;d<a.length;d+=p){t.beginPath();const c=Math.min(a.length,d+p);for(let f=d;f<c;f+=4)t.moveTo(a[f],a[f+1]),t.lineTo(a[f+2],a[f+3]);t.stroke()}if(t.lineCap="butt",z){const d=e.rectangles.filter(c=>c.binFail);if(d.length>0){const c=new Map;for(const f of d){const l=Ge(String(f.fill));let i=c.get(l);i||(i=[],c.set(l,i)),i.push(f)}t.save(),t.lineCap="butt";for(const[f,l]of c){t.strokeStyle=f,t.globalAlpha=.55,t.lineWidth=Math.max(.6*kt,Math.min(l[0].width,l[0].height)*.1);for(const i of l){const n=i.width/2,M=i.height/2,E=Math.max(1.6*kt,Math.min(i.width,i.height)/3);t.save(),t.beginPath(),t.rect(i.x-n,i.y-M,i.width,i.height),t.clip(),t.beginPath();for(let A=-(n+M);A<=n+M;A+=E)t.moveTo(i.x-n+A,i.y-M),t.lineTo(i.x-n+A+i.height,i.y+M);t.stroke(),t.restore()}}t.restore()}}const m=e.rectangles.filter(d=>d.specMark);if(m.length>0){const d=new Map;for(const f of m){const l=Ge(String(f.fill)),i=`${f.specMark}|${l}`;let n=d.get(i);n||(n=[],d.set(i,n)),n.push(f)}const c=2.5*kt;t.lineJoin="round";for(const[f,l]of d){const[i,n]=f.split("|"),M=n==="#000000"?"#ffffff":"#000000",E=i==="failHigh"?1:-1,A=Math.min(l[0].width,l[0].height),k=Math.max(2.5*kt,A*.3);t.beginPath();for(const q of l)Ve(t,q.x,q.y,k,E);t.strokeStyle=M,t.lineWidth=c,t.stroke(),t.fillStyle=n,t.fill()}}}for(const o of e.overlays){t.beginPath();for(const a of o.points){for(let p=0;p<a.length;p++)p===0?t.moveTo(a[p].x,a[p].y):t.lineTo(a[p].x,a[p].y);o.closed&&t.closePath()}o.fill&&!o.fill.startsWith("rgba(0,0,0,0)")&&(t.fillStyle=o.fill,t.fill()),o.kind==="ring-boundary"||o.kind==="quadrant-boundary"||o.kind==="reticle"?(t.strokeStyle="rgba(0,0,0,0.45)",t.lineWidth=3*kt,t.stroke(),t.strokeStyle="rgba(255,255,255,0.8)",t.lineWidth=1*kt,t.stroke()):(t.strokeStyle=o.lineColor,t.lineWidth=o.lineWidth*kt,t.stroke())}if(t.restore(),e.notchDir){const o=at+e.waferCenter.x*_,a=ct-e.waferCenter.y*_,p=e.notchDir.x,m=-e.notchDir.y,d=e.waferRadius*_,c=4,f=9,l=5,i=o+p*(d+c),n=a+m*(d+c),M=i+p*f,E=n+m*f,A={x:-m,y:p},k=s+Vt+re,q=G-s-ce,et=s+oe,gt=j-s-Te-fe;t.save(),t.beginPath(),t.rect(k,et,q-k,gt-et),t.clip(),t.beginPath(),t.moveTo(i,n),t.lineTo(M+A.x*l,E+A.y*l),t.lineTo(M-A.x*l,E-A.y*l),t.closePath(),t.fillStyle=u.text,t.fill(),t.restore()}t.save(),t.textAlign="center",t.textBaseline="middle";let Pe=0;if(e.rectangles.length>0){let o=1;for(const c of e.texts)c.role!=="indicator"&&c.text.length>o&&(o=c.text.length);const a=e.rectangles[0].width*_,p=e.rectangles[0].height*_,m=Math.min(a,p),d=a/o;Pe=Math.max(8,Math.min(64,Math.round(Math.min(m*.55,d*1.8))))}for(const o of e.texts){const a=at+o.x*_,p=ct-o.y*_;t.font=`${o.role==="indicator"?o.fontSize:Pe}px system-ui, sans-serif`,t.fillStyle=o.color,t.fillText(o.text,a,p)}if(t.restore(),Ht?.(t,{originX:at,originY:ct,ppm:_},{background:Y,text:u.text}),J&&Ro(t,G,j,at,ct,_,s,fe,Vt,R,e.gridToScreen,e.rotation,u,e.compact),Pt){const o=uo(e.valueColorScheme,e.reverseValueScheme),a=Le,p=Ae,m=Math.round(p*.75),d=s+Math.round((p-m)/2),c=G-s-g-a,f=It,l=Wt,i=l-f,n=e.plotMode==="stackedSoftBins"?Ct:mt,{primary:M,secondary:E,note:A}=tt?Ne(e,At,n):{primary:"",secondary:"",note:void 0};if(tt){const r=Math.max(d-6,s+11),O=Ut+Math.max(pt(r),pt(r-12))+8;St(M,G-s,r,"right","bottom",O)}let k=d+m+4;const q=r=>Ut+Math.max(pt(r),pt(r+12))+8,et=e.logScale&&f>0?Math.log10(f):0,gt=e.logScale&&l>0?Math.log10(l)-et:1,I=r=>e.logScale?(1-(Math.log10(r)-et)/gt)*m:(1-(r-f)/i)*m;for(let r=0;r<te;r++){const O=1-r/(te-1),H=d+r/te*m,x=m/te+1;t.fillStyle=o(O),t.fillRect(c,H,g,x)}t.strokeStyle="rgba(0,0,0,0.25)",t.lineWidth=.5,t.strokeRect(c,d,g,m),t.fillStyle=u.text,t.font=lt(),t.textAlign="left",t.strokeStyle="rgba(0,0,0,0.35)",t.lineWidth=.5;const W=Ke,Ot=qe,rt=14;let $;const F=e.logScale&&gt>0?_o(f,l,m,Ot,rt,et,gt):e.allIntegerValues?(()=>{const r=Math.max(1,Et(i*Ot/m)),O=[],H=Math.ceil(f/r)*r;for(let x=H;x<=l+r*1e-6;x+=r){const B=(1-(x-f)/i)*m;B>rt&&B<m-rt&&O.push(Math.round(x))}return O})():(()=>{const r=i>0?Et(i*Ot/m):0,O=[];if(r>0){$=r;const H=Math.ceil(f/r)*r;for(let x=H;x<=l+r*1e-6;x+=r){const B=(1-(x-f)/i)*m;B>rt&&B<m-rt&&O.push(x)}}return O})(),y=se,L=ne,T=we(l,Se,ke,At,$),w=e.allIntegerValues?le:T.tickFmt,S=e.allIntegerValues?le:T.edgeFmt;t.textBaseline="middle";for(const r of F){const O=d+I(r);t.beginPath(),t.moveTo(c+g,O),t.lineTo(c+g+W,O),t.stroke(),t.fillText(w(r),c+g+W+vt,O)}if(t.beginPath(),t.moveTo(c+g,d),t.lineTo(c+g+W,d),t.stroke(),t.textBaseline="top",t.fillText(S(l),c+g+W+vt,d),t.beginPath(),t.moveTo(c+g,d+m),t.lineTo(c+g+W,d+m),t.stroke(),t.textBaseline="bottom",t.fillText(S(f),c+g+W+vt,d+m),!L&&y&&(y.limitLow!==void 0||y.limitHigh!==void 0)){const r=[],O=e.colorbarRangeMode==="spec";for(const[H,x]of[[y.limitLow,"Lo limit"],[y.limitHigh,"Hi limit"]]){if(H===void 0||e.logScale&&H<=0)continue;const B=I(H);!O&&(B<-rt||B>m+rt)||r.push({value:H,label:x,py:Math.max(0,Math.min(m,B))})}if(r.length>0){t.save(),t.font=lt(),t.textAlign="right",t.textBaseline="middle";for(const{py:H,label:x}of r){const B=d+H;O||(t.strokeStyle="rgba(255,255,255,0.85)",t.lineWidth=3,t.beginPath(),t.moveTo(c,B),t.lineTo(c+g,B),t.stroke(),t.strokeStyle="rgba(0,0,0,0.7)",t.lineWidth=1,t.beginPath(),t.moveTo(c,B),t.lineTo(c+g,B),t.stroke()),t.fillStyle=u.text,t.fillText(x,c-3,B);const _t=x==="Hi limit"?-1:1,Bt=4,Zt=c-3-t.measureText(x).width-Bt-4;t.beginPath(),Ve(t,Zt,B,Bt,_t),t.strokeStyle="#fff",t.lineWidth=2,t.lineJoin="round",t.stroke(),t.fillStyle=u.text,t.fill()}t.restore()}}if(!L){const r=e.logScale?"log\u2081\u2080":e.logScaleRequested?"linear \u2014 log n/a":null;r&&(t.save(),t.fillStyle=u.text,t.font=Ao(),t.textAlign="right",t.textBaseline="top",t.fillText(r,G-s,k),t.restore(),k+=15)}tt&&E&&(St(E,G-s,k,"right","top",q(k),be(),u.text),k+=15),tt&&A&&St(A,G-s,k,"right","top",q(k),be(),u.text)}const me=[];let st;if(ht){const o=ot==="compact",a=e.plotMode==="softBin"?Ct:mt,p=a?new Map(a.map(n=>[n.bin,n])):null,m=e.plotMode==="softBin"?e.binColors.soft:e.binColors.hard,d=n=>m.get(n)??po,c=(n,M)=>{const E=t.measureText(n).width,A=o?0:t.measureText(String(M)).width,k=Z+Lt+E+(A?ee:0);return{labelWidth:E,countWidth:A,totalWidth:k}},f=Xt?.find(n=>n.key===e.activeMetadataKey),l=ft?dt.map(n=>{const M=o?n.compactLabel:n.label;return{key:n.key,color:n.color,count:n.count,label:M,tooltipLabel:n.tooltip,...c(M,n.count)}}):e.plotMode==="metadata"?$t.map(([n,M])=>{const A=f?.values?.find(et=>et.value===n)?.label??n,k=o?n:A,q=e.metadataColorMap?.get(n)??"#d6d9dd";return{key:n,color:q,count:M,label:k,tooltipLabel:`${A} \xB7 ${M} dies`,...c(k,M)}}):Gt.map(([n,M])=>{const E=p?.get(n),A=E?.name?`${n} \xB7 ${E.name}`:`Bin ${n}`,k=o?String(n):A;return{key:n,color:d(n),count:M,label:k,tooltipLabel:`${A} \xB7 ${M} dies`,...c(k,M)}}),i=G-s*2;if(l.length>0){const n=yt?bt*2+(tt?Ue:0):tt&&!Mt?Je+je:0,M=Math.max(1,Math.floor((j-2*s-n)/V));let E=l.length,A=1,k=E*V,q=[],et=0;const gt=K||Mt;if(gt){const $=Qt(l.map(y=>y.totalWidth)),F=Math.max(1,Math.min(l.length,Math.floor((i+8)/($+8))));for(let y=F;y>=1;y--){const L=Math.ceil(l.length/y);if(L>M)continue;const T=new Array(y).fill(0);for(let S=0;S<l.length;S++){const r=S%y;T[r]=Math.max(T[r],l[S].totalWidth)}if(T.reduce((S,r)=>S+r,0)+(y-1)*8<=i||y===1){A=y,q=T,E=L,k=L*V;break}}}else E=Math.min(l.length,M),k=E*V,l.length>M&&(et=l.length-(M-1)),q=[Tt];let I,W;if(yt){const $=Qt(l.map(r=>Z+Lt+t.measureText(r.label).width+ee)),F=Math.ceil($);q=[F];const y=tt?Ue:0,L=F+bt*2,T=k+y+bt*2,w=U?.x??0,S=U?.y??0;I=Math.min(Math.max(G-s-L+w,s),G-s-L),W=Math.min(Math.max(j-s-T+S,s),j-s-T),st={x:I,y:W,w:L,h:T},t.save(),t.globalAlpha=.92,t.fillStyle=u.surface,t.fillRect(I,W,L,T),t.globalAlpha=1,t.strokeStyle=u.axisLine,t.lineWidth=1,t.strokeRect(I,W,L,T),t.restore(),I+=bt,W+=bt+y}else K?(I=s,W=j-s-k):Mt?(I=s,W=s):it?(I=s+4,W=Math.max(s+Math.round((j-2*s-k)/2),s+n)):(I=G-s-Tt+4,W=Math.max(s+Math.round((j-2*s-k)/2),s+n));if(tt){const $=e.plotMode==="softBin"?Ct:mt,{primary:F,secondary:y,note:L}=Ne(e,At,$),T=je,w=[y,L].filter(x=>!!x),S=(x,B,_t)=>w.forEach((Bt,Zt)=>St(Bt,x,B+Zt*16,"left","top",_t(B+Zt*16),be(),u.text)),r=x=>Ut-Math.max(pt(x),pt(x-12))-8,O=x=>b?G-s:r(x),H=yt?st.y+st.h:W+k;if(Mt){const x=H+T;St(F,I,x,"left","top",Ut-Math.max(pt(x),pt(x+12))-8),S(I,x+16,r)}else if(yt)St(F,st.x+bt,st.y+bt,"left","top",st.x+st.w-bt),S(st.x,H+T,()=>st.x+st.w);else{const x=Math.max(W-T,s+Je);St(F,I,x,"left","bottom",O(x)),S(I,H+T,O)}}t.save(),t.font=lt();const Ot=gt?8:0,rt=($,F)=>{if(t.measureText($).width<=F)return $;let y=0,L=$.length;const T="\u2026",w=t.measureText(T).width;for(;y<L;){const S=y+L+1>>1;t.measureText($.slice(0,S)).width+w<=F?y=S:L=S-1}return y===0?T:$.slice(0,y)+T};if(gt){let $=0;for(let F=0;F<E;F++){let y=I;for(let L=0;L<A;L++){const T=l[$++];if(!T)break;const w=ut.includes(T.key),S=!w&&T.key===Q,r=y,O=y+Z+Lt,H=W+F*V+V/2,x=W+F*V+Math.round((V-Z)/2),B=q[L]-Z-Lt-ee;S&&(t.fillStyle=u.hoverRow,t.fillRect(y,W+F*V,q[L],V)),t.fillStyle=T.color,t.fillRect(r,x,Z,Z),t.strokeStyle=w?u.accent:"rgba(0,0,0,0.25)",t.lineWidth=w?2:.75,t.strokeRect(r,x,Z,Z),t.fillStyle=w?u.accent:u.text,t.font=w?`bold ${lt()}`:lt(),t.textAlign="left",t.textBaseline="middle",t.fillText(rt(T.label,B),O,H),t.fillStyle=u.textMuted,t.font=lt(),t.textAlign="right",t.fillText(String(T.count),y+q[L]-2,H),me.push({bin:T.key,x:y,y:W+F*V,w:q[L],h:V,label:T.tooltipLabel}),y+=q[L]+Ot}}}else{const $=q[0],F=ot!=="compact",y=$-Z-Lt-(F?ee:0),L=I+$-2;let T=l;et>0&&(T=l.slice(0,M-1));let w=W;for(const S of T){const r=ut.includes(S.key),O=!r&&S.key===Q,H=I,x=I+Z+Lt,B=w+V/2,_t=w+Math.round((V-Z)/2),Bt=S.label;O&&(t.fillStyle=u.hoverRow,t.fillRect(I-3,w,$+3,V)),t.fillStyle=S.color,t.fillRect(H,_t,Z,Z),t.strokeStyle=r?u.accent:"rgba(0,0,0,0.25)",t.lineWidth=r?2:.75,t.strokeRect(H,_t,Z,Z),t.fillStyle=r?u.accent:u.text,t.font=r?`bold ${lt()}`:lt(),t.textAlign="left",t.textBaseline="middle",t.fillText(rt(Bt,y),x,B),(F||yt)&&(t.fillStyle=u.textMuted,t.font=lt(),t.textAlign="right",t.fillText(String(S.count),L,B)),me.push({bin:S.key,x:I,y:w,w:$,h:V,label:S.tooltipLabel}),w+=V}et>0&&(t.fillStyle=u.textMuted,t.font=lt(),t.textAlign="left",t.textBaseline="middle",t.fillText(`+ ${et} more`,I+Z+Lt,w+V/2))}}l.length>0&&t.restore()}const io={originX:at,originY:ct,ppm:_,snapDist:zt},De=e.rectangles[0]?.width??1,Ie=e.rectangles[0]?.height??1,xt=e.dieBounds,Jt=xt?xt.minX:v.length?He(v.map(o=>o.x)):0,jt=xt?xt.minY:v.length?He(v.map(o=>o.y)):0,ao=xt?xt.maxX:v.length?Qt(v.map(o=>o.x)):1,co=xt?xt.maxY:v.length?Qt(v.map(o=>o.y)):1,{cellW:ue,cellH:pe,nCols:Ft,nRows:xe}=Mo(ao-Jt,co-jt,De*1.5,Ie*1.5,v.length),We=Array.from({length:Ft*xe},()=>[]);for(let o=0;o<v.length;o++){const a=Math.floor((v[o].x-Jt)/ue),p=Math.floor((v[o].y-jt)/pe),m=Number.isFinite(a)?Math.max(0,Math.min(Ft-1,a)):0,d=Number.isFinite(p)?Math.max(0,Math.min(xe-1,p)):0;We[d*Ft+m].push(o)}function Fe(o,a,p){const m=Math.max(0,Math.floor((o-p-Jt)/ue)),d=Math.min(Ft-1,Math.floor((o+p-Jt)/ue)),c=Math.max(0,Math.floor((a-p-jt)/pe)),f=Math.min(xe-1,Math.floor((a+p-jt)/pe)),l=[];for(let i=c;i<=f;i++)for(let n=m;n<=d;n++)for(const M of We[i*Ft+n])l.push(M);return l}return{hitTarget:{getDieAtPoint(o,a){const p=(o-at)/_,m=(ct-a)/_,d=Math.max(De,Ie);for(const l of Fe(p,m,d)){const i=e.rectangles[l];if(i&&Math.abs(p-i.x)<=i.width/2&&Math.abs(m-i.y)<=i.height/2)return e.dies[l]??null}let c=null,f=zt*zt;for(const l of Fe(p,m,zt)){const i=v[l].x-p,n=v[l].y-m,M=i*i+n*n;M<f&&(f=M,c=e.dies[l]??null)}return c}},viewport:io,binLegendRows:me,legendBox:st}}function Ro(h,e,P,u,s,C,z,g,Y,D,U,J,R,X){h.save(),h.font=Co(),h.fillStyle=R.text,h.strokeStyle=R.axisLine,h.lineWidth=.5;const N=P-g+4,Q=z+Y-4,Ht=ho(U),At=Ee(Ht,1,0),Yt=Ee(Ht,0,1),mt=1e-9;function Ct(b){return D?Math.abs(b.y)<mt&&Math.abs(b.x)>mt?{pitch:D.x,sign:Math.sign(b.x),axis:"x"}:Math.abs(b.x)<mt&&Math.abs(b.y)>mt?{pitch:D.y,sign:Math.sign(b.y),axis:"y"}:null:null}function Xt(b,it){if(!X||!b)return null;const K=b.axis==="x"?X.columns:X.rows,Mt=b.axis==="x"?X.columnBreaks:X.rowBreaks,yt=b.axis==="x"?X.centreColumn:X.centreRow;return ro(K.length,Mt,b.pitch*C,it).map(Tt=>({mm:b.sign*(Tt-yt)*b.pitch,label:String(K[Tt])}))}const tt=Ct(At),ut=Ct(Yt);function G(b){return tt?Math.round(b*tt.sign/tt.pitch):b}function j(b){return ut?Math.round(b*ut.sign/ut.pitch):b}function Rt(b){if(!b)return Et(50/C);const it=50/(b*C);return Math.max(1,Math.round(it))*b}const Pt=tt?.pitch,Dt=ut?.pitch,ft=Rt(Pt),ht=Rt(Dt);h.textAlign="center",h.textBaseline="top";const Gt=Math.ceil((z-u)/C/ft)*ft,$t=(e-z-u)/C,dt=Xt(tt,36)??Ze(Gt,$t,ft,b=>D?String(G(b)):$e(b));for(const{mm:b,label:it}of dt){const K=u+b*C;K<z||K>e-z||(h.beginPath(),h.moveTo(K,N-ze),h.lineTo(K,N),h.stroke(),h.fillText(it,K,N+2))}h.textAlign="right",h.textBaseline="middle";const wt=Math.ceil((s-(P-z))/C/ht)*ht,nt=(s-z)/C,ot=Xt(ut,16)??Ze(wt,nt,ht,b=>D?String(j(b)):$e(b));for(const{mm:b,label:it}of ot){const K=s-b*C;K<z||K>P-z||(h.beginPath(),h.moveTo(Q,K),h.lineTo(Q+ze,K),h.stroke(),h.fillText(it,Q-2,K))}h.restore()}function Ze(h,e,P,u){const s=[];for(let C=h;C<=e;C+=P)s.push({mm:C,label:u(C)});return s}function _o(h,e,P,u,s,C,z){const g=[],Y=z;if(Y<1){const R=Et((e-h)*u/P);if(R>0){const X=Math.ceil(h/R)*R;for(let N=X;N<=e+R*1e-6;N+=R){if(N<=h||N>=e)continue;const Q=(1-(Math.log10(N)-C)/z)*P;Q>s&&Q<P-s&&g.push(N)}}return g}const D=Y<3?[1,2,5]:[1],U=Math.floor(Math.log10(h)),J=Math.ceil(Math.log10(e));for(let R=U;R<=J;R++)for(const X of D){const N=X*Math.pow(10,R);if(N<=h||N>=e)continue;const Q=(1-(Math.log10(N)-C)/z)*P;Q>s&&Q<P-s&&g.push(N)}return g}export{fmt,fmtColorbarAxis}from"../renderer/fmt.js";export const PATH_SHAPES=256;const Qe=new WeakMap;export function outlineSegments(h){const e=g=>Math.round(g*1e6),P=new Map,u=new Map,s=(g,Y,D,U)=>{const J=e(Y);let R=g.get(J);R||g.set(J,R={at:Y,spans:[]}),R.spans.push([D,U])};for(const g of h){const Y=g.x-g.width/2,D=g.x+g.width/2,U=g.y-g.height/2,J=g.y+g.height/2;s(P,U,Y,D),s(P,J,Y,D),s(u,Y,U,J),s(u,D,U,J)}const C=[],z=(g,Y)=>{for(const{at:D,spans:U}of g.values()){U.sort((X,N)=>X[0]-N[0]);let[J,R]=U[0];for(let X=1;X<U.length;X++){const[N,Q]=U[X];e(N)<=e(R)?Q>R&&(R=Q):(Y(D,J,R),J=N,R=Q)}Y(D,J,R)}};return z(P,(g,Y,D)=>C.push(Y,g,D,g)),z(u,(g,Y,D)=>C.push(g,Y,g,D)),Float64Array.from(C)}
@@ -334,6 +334,29 @@ export declare function downloadBlob(blob: Blob, filename: string): void;
334
334
  * `suggestedName` (already includes its extension), and the `mimeType`.
335
335
  */
336
336
  export type SaveTextHandler = (text: string, suggestedName: string, mimeType: string) => void | Promise<void>;
337
+ /**
338
+ * A callback for "a panel just opened or closed beside the map in this box": widens the box by the
339
+ * room the panel took when it opens, and gives it back when it closes. Pass it to whatever
340
+ * renders the map inside `handle`. Only changes of state call it, since the room is measured at
341
+ * the moment the map loses it.
342
+ */
343
+ export declare function roomForPanel(handle: OverlayHandle): (open: boolean, widthPx: number) => void;
344
+ /**
345
+ * Show what the compact-layout detector saw, for a person to read and send back: counts and
346
+ * scores only (see `diagnoseMpwLayout`), in a box they can read first, copy, or save as a
347
+ * file. Saving goes through the host's `onSaveText`, the one route that works in a desktop
348
+ * webview; the clipboard may not, so a failed copy says so and leaves the text selectable.
349
+ */
350
+ export declare function openCompactDiagnostics(dies: readonly {
351
+ x?: number | null;
352
+ y?: number | null;
353
+ }[], reticles: readonly ({
354
+ width: number;
355
+ height: number;
356
+ } | undefined)[], opts: {
357
+ anchor: HTMLElement;
358
+ onSaveText?: SaveTextHandler;
359
+ }): OverlayHandle;
337
360
  /**
338
361
  * Persist a text file (e.g. a CSV export). Routes through the host
339
362
  * `onSaveText` hook when provided; otherwise falls back to a browser
@@ -602,6 +625,12 @@ export type CheckMenuRow = {
602
625
  * missing feature, and the user has no way to learn the condition.
603
626
  */
604
627
  disabledHint?: string;
628
+ /**
629
+ * Close the menu after this row is clicked. For an action that opens something of its own
630
+ * (a dialog), which the menu would otherwise stay open on top of. Toggles keep the menu open
631
+ * so several can be set in one visit.
632
+ */
633
+ closeMenu?: boolean;
605
634
  /**
606
635
  * Marks a row that *does* something rather than holding a state — "Clear
607
636
  * overlays", "Reset orientation". Rendered as a plain `menuitem` with no
@@ -701,6 +730,14 @@ export interface OverlayHandle {
701
730
  /** Replace the box's natural height (see `OverlayOptions.boxSize`) — applied
702
731
  * now unless maximized or minimized, and restored to from either. */
703
732
  setNaturalHeight: (height: string) => void;
733
+ /**
734
+ * Make room for `px` of extra content beside what the box already holds, by widening it, and
735
+ * return the function that takes that room back. Capped so the box stays on screen (a window is
736
+ * moved left if it would run off the edge), so it may give less than asked. Does nothing while
737
+ * maximised or collapsed, and releasing leaves a width the user has dragged the box to since.
738
+ * For a panel that opens beside a map, so the map keeps its size instead of giving it up.
739
+ */
740
+ reserveWidth: (px: number) => () => void;
704
741
  }
705
742
  /** Create and open a resizable, maximizable, exclusive expand modal — dims and
706
743
  * blocks the rest of the page. See `openFloatingWindow` for the non-modal form. */
@@ -797,6 +834,8 @@ export interface OverlayFlags {
797
834
  showDieLabels?: boolean;
798
835
  showReticle?: boolean;
799
836
  showXYIndicator?: boolean;
837
+ /** Unset means "while zoomed", the default; see `WaferViewOptions.showAxes`. */
838
+ showAxes?: boolean;
800
839
  passFailDisplay?: 'off' | 'spec' | 'test';
801
840
  /**
802
841
  * Moved here from the Colour scheme menu, where it had been the one entry
@@ -829,7 +868,14 @@ export declare function overlayMenuRows(flags: OverlayFlags, reticleEnabled: boo
829
868
  hasLimits: boolean;
830
869
  hasRecorded: boolean;
831
870
  binMode: boolean;
832
- }, apply: (patch: OverlayFlags) => void): CheckMenuRow[];
871
+ }, apply: (patch: OverlayFlags) => void,
872
+ /** The compact layout toggle, for a host that offers it (a single map). */
873
+ compact?: {
874
+ on: boolean;
875
+ offered: boolean;
876
+ onChange: (on: boolean) => void;
877
+ onDiagnostics: () => void;
878
+ }): CheckMenuRow[];
833
879
  /** Whether any overlay is on — the Overlays button's "active" state. Shared for
834
880
  * the same reason as the rows: it enumerates the same five flags. */
835
881
  export declare function anyOverlayActive(flags: OverlayFlags): boolean;
@@ -884,6 +930,7 @@ export declare function makeOrientationBtn(helpers: ToolbarHelpers, getOpts: ()
884
930
  rotation?: 0 | 90 | 180 | 270;
885
931
  flipX?: boolean;
886
932
  flipY?: boolean;
933
+ showXYIndicator?: boolean;
887
934
  }) => void): HTMLButtonElement;
888
935
  type GuideApi = {
889
936
  buildWaferMap: unknown;
@@ -971,6 +1018,12 @@ export declare function openWaferMapGuide(extension?: UserGuideExtension, anchor
971
1018
  export declare function openReportModal(html: string, opts?: {
972
1019
  anchor?: Element;
973
1020
  ownerDocument?: Document;
1021
+ /**
1022
+ * A report built with `live` tells this page which finding a click on its row meant. Called with that
1023
+ * finding's id and the modal's handle, so the host can close the modal and show the finding on the map.
1024
+ * Only messages from this report's own frame are heeded.
1025
+ */
1026
+ onFinding?: (findingId: string, handle: OverlayHandle) => void;
974
1027
  }): OverlayHandle;
975
1028
  export {};
976
1029
  //# sourceMappingURL=toolbar.d.ts.map
@@ -1,4 +1,4 @@
1
- import{getUniqueTestNumbers as ke}from"../renderer/buildView.js";import{dieHasTestData as Ee}from"../renderer/buildWaferMap.js";import{testLabel as re,isDerivedTest as Ce,DERIVED_MARK as ce,DERIVED_KEY as de}from"../renderer/testLabel.js";import{prettyKey as Le}from"../core/utils.js";import{listBinColorSchemes as Ae,listValueColorSchemes as Me}from"../renderer/colorSchemes.js";import{ICONS as W}from"./icons.js";import{WMAP_VERSION as Se,WMAP_BUILD_TIME as Be}from"./version.js";import{openHtmlReport as De}from"../stats/renderFindingsReport.js";import{buildWaferMap as Te}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as He}from"../stats/analyzeWaferMap.js";let ue=!1;export function logWmapVersionOnce(){ue||(ue=!0,console.log(`[wmap] v${Se} (built ${Be})`))}export const WMAP_TOKEN_NAMES=["z","icon","icon-hover","icon-active","bg-hover","bg-active","separator","surface","border","control-border","menu-hover","menu-active","font-family","font-size","density","panel-bg","text-muted","text","text-strong","warn-bg","warn-border","warn-text","err-bg","err-border","err-text","info-bg","info-text","selected","finding-indicator","canvas-bg","bar-fill"];const k=(e,t)=>`var(--wmap-${e}, ${t})`,K="var(--wmap-font-size, 12px)",Ie="var(--wmap-density, 1)",F=e=>`calc(${e}px * ${Ie})`;export function wireControlHover(e,t="outlined"){let n=null;const o=()=>{n&&(e.style.background=n.background,e.style.color=n.color)};e.addEventListener("mouseenter",()=>{e.dataset.on==="true"||e.disabled||(n||(n={background:e.style.background,color:e.style.color}),e.style.background=CLR.bgHover,e.style.color=CLR.iconHover)}),e.addEventListener("mouseleave",o),e.addEventListener("blur",o)}export function controlStyle(e,t=!1){const n={fontSize:FONT.body,cursor:"pointer",borderRadius:RADIUS.control};return e==="bare"?{...n,border:"none",background:"none",padding:"0",color:CLR.icon}:{...n,border:`1px solid ${CLR.controlBorder}`,background:e==="toggle"&&t?CLR.menuActive:"none",color:e==="toggle"&&t?CLR.iconActive:CLR.text,padding:`${SPACE.xxs} ${SPACE.lg}`}}export const SPACE={xxs:F(2),xs:F(4),sm:F(6),md:F(8),lg:F(10),xl:F(12),xxl:F(16),xxxl:F(24)},SHADOW={panel:"0 1px 4px rgba(0,0,0,0.10)",menu:"0 4px 12px rgba(0,0,0,0.15)",modal:"0 20px 60px rgba(0,0,0,0.40)"},MOTION={fast:"0.12s ease",base:"0.2s ease"},LEADING={none:"1",tight:"1.2",base:"1.45"},ALPHA={muted:"0.85",disabled:"0.4"},TRACKING="0.05em",EDGE_GUTTER=SPACE.xl,MAP_CHROME_INSET=SPACE.xs,RADIUS={control:"4px",container:"6px",pill:"999px"},FONT={family:"var(--wmap-font-family, inherit)",meta:`calc(${K} - 1px)`,body:K,sub:`calc(${K} + 1px)`,heading:`calc(${K} + 3px)`,stat:`calc(${K} + 8px)`};export function fontPx(e=0,t){const n=t?.ownerDocument??(typeof document<"u"?document:null);if(!n)return 12+e;const o=getComputedStyle(t??n.documentElement).getPropertyValue("--wmap-font-size").trim(),r=o?parseFloat(o):NaN;return(Number.isFinite(r)?r:12)+e}export const CLR={icon:k("icon","#506784"),iconHover:k("icon-hover","#2a3f5f"),iconActive:k("icon-active","#1a65ca"),bgHover:k("bg-hover","#edf0f8"),bgActive:k("bg-active","#dce8f8"),separator:k("separator","rgba(0,0,0,0.12)"),menuBg:k("surface","#fff"),menuBorder:k("border","rgba(0,0,0,0.12)"),controlBorder:k("control-border",k("border","rgba(0,0,0,0.30)")),menuHover:k("menu-hover","#f0f4fc"),menuActive:k("menu-active","#dce8f8"),canvasBg:`var(--wmap-canvas-bg, ${k("surface","#f5f5f5")})`,panelBg:k("panel-bg","#fafbfc"),label:k("text-muted","#647687"),value:k("text-strong","#1f2f43"),text:k("text","#333"),warnBg:k("warn-bg","#fffbe6"),warnBorder:k("warn-border","#f0c040"),warnText:k("warn-text","#7a5800"),errBg:k("err-bg","#fef2f2"),errBorder:k("err-border","#dc8a8a"),errText:k("err-text","#7a1c1c"),infoBg:k("info-bg","#dce8f8"),infoText:k("info-text","#334155"),findingHighlight:k("selected","#e07a20"),findingIndicator:k("finding-indicator","#b7551a"),barFill:k("bar-fill","#2a6fc0")};export function sevColor(e){return e==="unusual"?"#a84112":e==="notable"?"#8a6500":CLR.icon}export const ROTATIONS=[0,90,180,270],INLINE_TEST_LIMIT=6,MENU_SEARCH_THRESHOLD=8,DEFAULT_OVERLAY_Z=6e3,Z_BASE=`var(--wmap-z, ${DEFAULT_OVERLAY_Z})`,Z_ABOVE=`calc(var(--wmap-z, ${DEFAULT_OVERLAY_Z}) + 1)`,Z_MENU=`calc(var(--wmap-z, ${DEFAULT_OVERLAY_Z}) + 2)`,Z_ABOVE2=`calc(var(--wmap-z, ${DEFAULT_OVERLAY_Z}) + 3)`;export function applyOverlayZ(e){if(e==null)return()=>{};const t=document.documentElement,n=t.style.getPropertyValue("--wmap-z");return t.style.setProperty("--wmap-z",String(e)),()=>{n?t.style.setProperty("--wmap-z",n):t.style.removeProperty("--wmap-z")}}export function copyWmapThemeTokens(e,t){const n=getComputedStyle(e);for(const o of WMAP_TOKEN_NAMES){const r=n.getPropertyValue(`--wmap-${o}`).trim();r&&t.style.setProperty(`--wmap-${o}`,r)}}export function syncWmapPopupTheme(e,t,n){const o=()=>{copyWmapThemeTokens(e,t),n?.()},r=new window.MutationObserver(o);r.observe(e,{attributes:!0,attributeFilter:["style","class"]}),r.observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]});const l=window.matchMedia("(prefers-color-scheme: dark)");return l.addEventListener("change",o),()=>{r.disconnect(),l.removeEventListener("change",o)}}let ae=null;export function setDetachWindowOpener(e){ae=e}export function openDetachWindow(e){return ae?ae(e):window.open("","_blank","width=560,height=600")}export const MODE_LABELS={value:"Test Value",hardBin:"Hard Bin",softBin:"Soft Bin",stackedValues:"Stacked Test Values",stackedBins:"Stacked Hard Bins",stackedSoftBins:"Stacked Soft Bins",metadata:"Metadata"},BIN_LEGEND_MODES=new Set(["hardBin","softBin","metadata"]),STACKED_MODES=new Set(["stackedValues","stackedBins","stackedSoftBins"]);export function saveImageBlob(e,t,n){const o=`${t}.png`;if(n){n(e,o);return}downloadBlob(e,o)}export function downloadBlob(e,t){const n=URL.createObjectURL(e),o=document.createElement("a");o.href=n,o.download=t,o.click(),URL.revokeObjectURL(n)}export function saveTextFile(e,t,n,o){if(o){o(e,t,n);return}downloadBlob(new Blob([e],{type:n}),t)}const $e='[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';export function nextFrame(e,t=window){const n=t.requestAnimationFrame;typeof n=="function"?n.call(t,e):setTimeout(e,0)}export function wireListNavigation(e,t,n){e.addEventListener("keydown",o=>{const r=t();if(r.length===0)return;const l=e.ownerDocument.activeElement,p=l?r.indexOf(l):-1;switch(o.key){case"ArrowDown":o.preventDefault(),r[p<0||p===r.length-1?0:p+1].focus();break;case"ArrowUp":o.preventDefault(),r[p<=0?r.length-1:p-1].focus();break;case"Home":o.preventDefault(),r[0].focus();break;case"End":o.preventDefault(),r[r.length-1].focus();break;case"Enter":case" ":p>=0&&(o.preventDefault(),r[p].click());break;case"Escape":case"Tab":o.preventDefault(),n();break}})}function J(e,t,n){const o=()=>Array.from(e.querySelectorAll($e));wireListNavigation(e,o,()=>{n(),t?.focus()});const r=o()[0];r&&nextFrame(()=>r.focus())}export function overlayRootFor(e){let t=e;for(;t;){if(t.classList.contains("wmap-overlay-box")||t.tagName==="DIALOG"&&t.matches(":modal"))return t;t=t.parentElement}return e.ownerDocument.body}const pe=new WeakMap;export function menuLayerFor(e){const t=overlayRootFor(e),n=pe.get(t);if(n&&n.isConnected)return n;const r=e.ownerDocument.createElement("div");return r.dataset.wmapMenuLayer="1",Object.assign(r.style,{position:"fixed",inset:"0",zIndex:Z_MENU,pointerEvents:"none"}),t.appendChild(r),pe.set(t,r),r}const se=new WeakMap;export function getTooltip(e=document){const t=se.get(e);if(t&&t.isConnected)return t;const n=t??e.createElement("div");return t||(Object.assign(n.style,{position:"fixed",pointerEvents:"none",background:"rgba(30, 32, 40, 0.93)",color:"#f0f0f2",border:"1px solid rgba(255,255,255,0.10)",padding:"7px 11px",borderRadius:RADIUS.control,fontSize:FONT.sub,lineHeight:LEADING.base,maxWidth:"280px",maxHeight:"min(60vh, 480px)",overflow:"hidden",whiteSpace:"pre-wrap",zIndex:Z_ABOVE2,display:"none",fontFamily:FONT.family,boxShadow:SHADOW.menu}),se.set(e,n)),e.body.appendChild(n),n}export function hideTooltip(e=document){const t=se.get(e);t&&(t.style.display="none")}export function reparentTooltip(e){const t=e?.ownerDocument??document,n=getTooltip(t);(e??t.body).appendChild(n)}export function positionTooltip(e,t,n,o,r={}){const l=menuLayerFor(t);e.parentElement!==l&&l.appendChild(e);const p=e.ownerDocument.defaultView??window;e.style.left="0",e.style.top="0";const i=e.offsetWidth,b=e.offsetHeight,d=8,a=p.innerWidth,y=p.innerHeight;let s=n+14,f=o-8;s+i+d>a&&(s=n-i-6);const x=t.getBoundingClientRect();if(!r.followPointer&&x.height>0&&x.height<=y*.4&&f<x.bottom&&f+b>x.top&&s<x.right&&s+i>x.left){const u=x.bottom+d,h=x.top-b-d;u+b+d<=y?f=u:h>=d&&(f=h)}f+b+d>y&&(f=y-b-d),f<d&&(f=d),e.style.left=`${s}px`,e.style.top=`${f}px`}export function wireTooltip(e,t,n={}){const o=()=>(typeof t=="function"?t():t)??e.getAttribute("aria-label")??"";n.asDataPoint&&(e.tabIndex=0,e.setAttribute("role","img"),typeof t=="string"&&e.setAttribute("aria-label",t));const r=p=>{const i=o();if(!i)return;const b=getTooltip(e.ownerDocument);if(b.textContent=i,b.style.display="block",p)positionTooltip(b,e,p.clientX,p.clientY);else{const d=e.getBoundingClientRect();positionTooltip(b,e,d.left+d.width/2,d.top)}},l=()=>hideTooltip(e.ownerDocument);e.addEventListener("mousemove",r),e.addEventListener("mouseleave",l),e.addEventListener("focus",()=>r()),e.addEventListener("blur",l)}export function buildDataModeEntries(e,t,n){const o=e.some(Ee),r=e.some(a=>a.testValues!==void 0&&Object.keys(a.testValues).length>0),l=e.some(a=>a.hbin!=null),p=e.some(a=>a.sbin!=null),i=o?t!==void 0?t.map(a=>({plotMode:"value",activeTest:a.testNumber,label:a.unit?`${re(a,a.testNumber)} (${a.unit})`:re(a,a.testNumber),logScale:a.logScale,...Ce(a)?{derived:!0}:{}})):ke(e).map(a=>({plotMode:"value",activeTest:a,label:re(void 0,a)})):[],b=[...l?[{plotMode:"hardBin",label:MODE_LABELS.hardBin}]:[],...p?[{plotMode:"softBin",label:MODE_LABELS.softBin}]:[]],d=n.includeStacked?[...r?[{plotMode:"stackedValues",label:MODE_LABELS.stackedValues}]:[],...l?[{plotMode:"stackedBins",label:MODE_LABELS.stackedBins}]:[],...p?[{plotMode:"stackedSoftBins",label:MODE_LABELS.stackedSoftBins}]:[]]:[];return{testEntries:i,binEntries:b,stackedEntries:d}}export function metadataKeyHasData(e,t){return e.some(n=>n.metadata?.[t]!==void 0&&n.metadata?.[t]!==null)}export function metadataModeEntry(e){return{plotMode:"metadata",activeMetadataKey:e.key,label:e.label??Le(e.key)}}export function makeMenuSearchBox(e,t="Filter\u2026",n=document){const o=n.createElement("input");return o.type="text",o.placeholder=t,o.setAttribute("aria-label",t),Object.assign(o.style,{display:"block",width:"calc(100% - 20px)",margin:"2px 10px 6px",padding:`${SPACE.xs} ${SPACE.md}`,fontSize:FONT.body,boxSizing:"border-box",background:CLR.menuBg,color:CLR.text,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,outline:"none"}),o.addEventListener("click",r=>r.stopPropagation()),o.addEventListener("mousedown",r=>r.stopPropagation()),o.addEventListener("keydown",r=>r.stopPropagation()),o.addEventListener("input",()=>e(o.value.trim().toLowerCase())),o.addEventListener("focus",()=>{o.style.borderColor=CLR.iconActive}),o.addEventListener("blur",()=>{o.style.borderColor=CLR.menuBorder}),queueMicrotask(()=>o.focus()),o}export function buildModeMenuEl(e,t,n,o,r,l,p,i,b=window,d=[]){const{makeMenuRow:a,makeMenuSection:y}=p,s=document.createElement("div"),f=180,c=e.left+f<=(b.innerWidth??1/0)?e.left:Math.max(4,e.right-f);if(Object.assign(s.style,{position:"fixed",top:`${e.bottom+4}px`,left:`${c}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_BASE,minWidth:`${f}px`,padding:"4px 0",pointerEvents:"auto"}),t.length)if(s.appendChild(y("Test Value")),t.length<=INLINE_TEST_LIMIT)for(const m of t)s.appendChild(a(m.label,r(m),!0,u=>{u.stopPropagation(),l(m,s)}));else{const m=i==="value",u=a(MODE_LABELS.value+" \u25B6",m,!1,g=>{g.stopPropagation(),A(),S(),g.detail===0&&T()});u.setAttribute("aria-haspopup","menu"),u.style.display="flex",u.style.justifyContent="space-between",u.style.alignItems="center";let h=null,w=null;const A=()=>{w!==null&&(clearTimeout(w),w=null)},E=g=>{const B=g.target;B&&(u.contains(B)||h?.contains(B))||C()},C=()=>{A(),h?.remove(),h=null,b.document.removeEventListener("click",E),u.setAttribute("aria-expanded","false")},T=()=>{const g=h?.querySelector('input, [role="menuitemradio"]');g&&nextFrame(()=>g.focus(),b)},D=()=>{A(),w=setTimeout(C,300)},S=()=>{if(h)return;const g=u.getBoundingClientRect(),B=160,V=320,I=g.right+2+B<=(b.innerWidth??1/0)?g.right+2:Math.max(4,g.left-2-B),Y=Math.min(g.top-4,Math.max(4,(b.innerHeight??1/0)-V-4));if(h=document.createElement("div"),h.setAttribute("data-wmap-submenu",""),h.setAttribute("role","menu"),Object.assign(h.style,{position:"fixed",top:`${Y}px`,left:`${I}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_ABOVE,minWidth:`${B}px`,maxHeight:`${V}px`,overflowY:"auto",padding:"4px 0",pointerEvents:"auto"}),t.length>MENU_SEARCH_THRESHOLD){const L=makeMenuSearchBox(U=>{for(const O of $)O.row.style.display=O.label.includes(U)?"":"none"},"Filter tests\u2026");Object.assign(L.style,{position:"sticky",top:"0",zIndex:"1",background:CLR.menuBg}),h.appendChild(L)}const $=[],M=t.some(L=>L.derived);for(const L of t){const U=a(L.label,r(L),!1,O=>{O.stopPropagation(),C(),l(L,s)},M?{derived:L.derived===!0}:void 0);$.push({row:U,label:L.label.toLowerCase()}),h.appendChild(U)}if(M){const L=b.document.createElement("div");L.setAttribute("role","presentation"),L.textContent=`${ce} ${de}`,Object.assign(L.style,{padding:"6px 14px",fontSize:FONT.meta,color:CLR.label,borderTop:`1px solid ${CLR.menuBorder}`,marginTop:"4px",whiteSpace:"nowrap"}),h.appendChild(L)}h.addEventListener("mouseenter",A),h.addEventListener("mouseleave",D),wireListNavigation(h,()=>$.filter(L=>L.row.style.display!=="none").map(L=>L.row),()=>{C(),u.focus()}),(s.parentElement??b.document.body).appendChild(h),b.document.addEventListener("click",E),u.setAttribute("aria-expanded","true")};s.addEventListener("keydown",g=>{g.key==="Escape"&&C()}),u.addEventListener("mouseenter",()=>{A(),S()}),u.addEventListener("mouseleave",D),s.appendChild(u)}if(n.length){s.appendChild(y("Bins"));for(const m of n)s.appendChild(a(m.label,r(m),!1,u=>{u.stopPropagation(),l(m,s)}))}if(d.length){s.appendChild(y("Metadata"));for(const m of d)s.appendChild(a(m.label,r(m),!1,u=>{u.stopPropagation(),l(m,s)}))}if(o.length){s.appendChild(y("Lot Aggregation"));for(const m of o)s.appendChild(a(m.label,r(m),!1,u=>{u.stopPropagation(),l(m,s)}))}return s.setAttribute("role","menu"),s.setAttribute("aria-label","Plot mode"),s}export function markMenuTrigger(e,t){e.setAttribute("aria-haspopup","menu"),e.setAttribute("aria-expanded",t?"true":"false")}export function wireMenuA11y(e,t,n){J(e,t,n)}export function wireExpandToggle(e,t){const n=e.ownerDocument;let o=!1;function r(d){o!==d&&(o=d,t(o))}function l(){r(!1)}function p(){r(!o),o&&n.addEventListener("click",l,{once:!0})}const i=d=>{d.stopPropagation(),p()},b=d=>{d.key==="Enter"||d.key===" "?(d.preventDefault(),p()):d.key==="Escape"&&l()};return e.setAttribute("role","button"),e.tabIndex<0&&(e.tabIndex=0),e.addEventListener("click",i),e.addEventListener("keydown",b),{isOpen:()=>o,close:l,destroy(){e.removeEventListener("click",i),e.removeEventListener("keydown",b),n.removeEventListener("click",l)}}}export function buildCheckMenuEl(e,t,n,o=window){const{makeMenuSection:r}=n,l=o.document,p=l.createElement("div"),i=168,d=e.left+i<=(o.innerWidth??1/0)?e.left:Math.max(4,e.right-i);Object.assign(p.style,{position:"fixed",top:`${e.bottom+4}px`,left:`${d}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_BASE,minWidth:`${i}px`,padding:"4px 0",pointerEvents:"auto"});for(const a of t)if("section"in a)p.appendChild(r(a.section));else{const y=a.enabled!==!1;if(!y&&!a.disabledHint)continue;const s=l.createElement("div");a.action?s.setAttribute("role","menuitem"):(s.setAttribute("role","menuitemcheckbox"),s.setAttribute("aria-checked",a.active?"true":"false")),s.tabIndex=-1,y||(s.setAttribute("aria-disabled","true"),wireTooltip(s,a.disabledHint)),Object.assign(s.style,{display:"flex",alignItems:"center",gap:SPACE.sm,padding:"6px 14px",fontSize:FONT.body,cursor:y?"pointer":"default",color:y?a.active?CLR.iconActive:CLR.text:CLR.label,fontWeight:a.active?"700":"400",background:a.active?CLR.menuActive:"transparent",whiteSpace:"nowrap"});const f=l.createElement("span");Object.assign(f.style,{width:"12px",flexShrink:"0",color:CLR.iconActive,visibility:a.active?"visible":"hidden"}),f.textContent=a.action?"":"\u2713",f.setAttribute("aria-hidden","true");const x=l.createElement("span");x.textContent=a.label,s.appendChild(f),s.appendChild(x),y?(s.addEventListener("mouseenter",()=>{a.active||(s.style.background=CLR.menuHover)}),s.addEventListener("mouseleave",()=>{s.style.background=a.active?CLR.menuActive:"transparent"}),s.addEventListener("focus",()=>{a.active||(s.style.background=CLR.menuHover)}),s.addEventListener("blur",()=>{s.style.background=a.active?CLR.menuActive:"transparent"}),s.addEventListener("click",c=>{c.stopPropagation(),a.onClick(c)})):s.addEventListener("click",c=>{c.stopPropagation()}),p.appendChild(s)}return p}export function createToolbarHelpers(e){const t=e.ownerDocument;let n=null;const o=s=>menuLayerFor(s);function r(s,f,x){const c=t.createElement("button");return c.innerHTML=W[s],c.type="button",c.ariaLabel=f,Object.assign(c.style,{display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",padding:"0",border:"none",borderRadius:RADIUS.control,background:"transparent",color:CLR.icon,cursor:"pointer",pointerEvents:"auto",transition:`background ${MOTION.fast}, color ${MOTION.fast}`,flexShrink:"0"}),c.addEventListener("mouseenter",m=>{c.dataset.active||(c.style.background=CLR.bgHover,c.style.color=CLR.iconHover),e.textContent=c.ariaLabel??f,e.style.display="block",positionTooltip(e,c,m.clientX,m.clientY)}),c.addEventListener("mousemove",m=>{e.style.display==="block"&&positionTooltip(e,c,m.clientX,m.clientY)}),c.addEventListener("mouseleave",()=>{c.dataset.active||(c.style.background="transparent",c.style.color=CLR.icon),e.style.display="none"}),c.addEventListener("click",()=>{e.style.display="none",x()}),c}function l(s,f){f?(s.dataset.active="1",s.style.background=CLR.bgActive,s.style.color=CLR.iconActive):(delete s.dataset.active,s.style.background="transparent",s.style.color=CLR.icon)}function p(){const s=t.createElement("div");return Object.assign(s.style,{width:"1px",height:"18px",background:CLR.separator,margin:"0 2px",flexShrink:"0"}),s}function i(s,f,x,c,m){const u=t.createElement("div");if(m){const h=t.createElement("span");h.textContent=m.derived?ce:"",h.setAttribute("aria-hidden","true"),Object.assign(h.style,{display:"inline-block",width:"1.1em"}),u.append(h,s),m.derived&&u.setAttribute("aria-label",`${s} \u2014 ${de.toLowerCase()}`)}else u.textContent=s;return u.setAttribute("role","menuitemradio"),u.setAttribute("aria-checked",f?"true":"false"),u.tabIndex=-1,Object.assign(u.style,{padding:`6px 14px 6px ${x?"26px":"14px"}`,fontSize:FONT.body,cursor:"pointer",color:f?CLR.iconActive:CLR.text,fontWeight:f?"700":"400",background:f?CLR.menuActive:"transparent",whiteSpace:"nowrap"}),u.addEventListener("mouseenter",()=>{f||(u.style.background=CLR.menuHover)}),u.addEventListener("mouseleave",()=>{u.style.background=f?CLR.menuActive:"transparent"}),u.addEventListener("focus",()=>{f||(u.style.background=CLR.menuHover)}),u.addEventListener("blur",()=>{u.style.background=f?CLR.menuActive:"transparent"}),u.addEventListener("click",c),u}function b(s){const f=t.createElement("div");return f.textContent=s,f.setAttribute("role","presentation"),Object.assign(f.style,{padding:"5px 14px 2px",fontSize:FONT.body,fontWeight:"600",letterSpacing:TRACKING,color:CLR.label,textTransform:"uppercase",pointerEvents:"none",userSelect:"none"}),f}function d(s,f,x,c,m){const u=()=>{n&&(n.remove(),n=null),h.setAttribute("aria-expanded","false")},h=r(s,f,()=>{if(n){u();return}const w=t.createElement("div"),A=h.getBoundingClientRect(),E=h.ownerDocument.defaultView??window,C=148,D=A.left+C<=(E.innerWidth??1/0)?A.left:Math.max(4,A.right-C);Object.assign(w.style,{position:"fixed",top:`${A.bottom+4}px`,left:`${D}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_BASE,minWidth:`${C}px`,padding:"4px 0",pointerEvents:"auto"});for(const S of x()){const g=t.createElement("div");g.textContent=S.label,g.dataset.wmapDropdownValue=S.value;const B=S.value===c();g.setAttribute("role","menuitemradio"),g.setAttribute("aria-checked",B?"true":"false"),g.tabIndex=-1,Object.assign(g.style,{padding:"6px 14px",fontSize:FONT.body,cursor:"pointer",color:B?CLR.iconActive:CLR.text,fontWeight:B?"700":"400",background:B?CLR.menuActive:"transparent",whiteSpace:"nowrap"});const V=()=>{S.value!==c()&&(g.style.background=CLR.menuHover)},z=()=>{g.style.background=S.value===c()?CLR.menuActive:"transparent"};g.addEventListener("mouseenter",V),g.addEventListener("mouseleave",z),g.addEventListener("focus",V),g.addEventListener("blur",z),g.addEventListener("click",I=>{I.stopPropagation(),m(S.value),u()}),w.appendChild(g)}w.setAttribute("role","menu"),w.setAttribute("aria-label",f),o(h).appendChild(w),n=w,h.setAttribute("aria-expanded","true"),J(w,h,u)});return h.setAttribute("aria-haspopup","menu"),h.setAttribute("aria-expanded","false"),h}function a(s,f,x,c){function m(){return buildCheckMenuEl(h.getBoundingClientRect(),x().map(w=>"section"in w?w:{...w,onClick:A=>{w.onClick(A),c(h);const E=n;if(!E)return;const C=m();C.setAttribute("role","menu"),C.setAttribute("aria-label",f),E.replaceWith(C),n=C,J(C,h,u)}}),{makeMenuSection:b},h.ownerDocument.defaultView??window)}const u=()=>{n&&(n.remove(),n=null),h.setAttribute("aria-expanded","false")},h=r(s,f,()=>{if(n){u();return}const w=m();w.setAttribute("role","menu"),w.setAttribute("aria-label",f),o(h).appendChild(w),n=w,h.setAttribute("aria-expanded","true"),J(w,h,u)});return h.setAttribute("aria-haspopup","menu"),h.setAttribute("aria-expanded","false"),c(h),h}function y(s){const f=s.target?.closest?.("[data-wmap-submenu]");if(n&&!n.contains(s.target)&&!f&&(n.remove(),n=null,s.target?.getAttribute?.("aria-haspopup")!=="menu"))for(const c of document.querySelectorAll('[aria-haspopup="menu"][aria-expanded="true"]'))c.setAttribute("aria-expanded","false")}return{makeBtn:r,setActive:l,makeSep:p,makeMenuRow:i,makeMenuSection:b,makeDropdown:d,makeCheckMenuBtn:a,closeOpenMenu:y,getOpenMenu:()=>n,setOpenMenu:s=>{n=s}}}const Oe=7e3;let Re=0;function fe(){return Oe+ ++Re}const We=32,ze=6;let _e=0;function Ne(){return _e++%ze*We}function Pe(e,t){if(t===e.body)return()=>{};let n=t;for(;n.parentElement&&n.parentElement!==e.body;)n=n.parentElement;return n===e.body?()=>{}:(n.classList.add("wmap-overlay-ancestor"),()=>n.classList.remove("wmap-overlay-ancestor"))}function me(e){const t=e.mode==="modal",n=e.ownerDocument??document,o=n.defaultView??window,r=n.body.style.overflow;t&&(n.body.style.overflow="hidden");let l=null;t&&(l=n.createElement("div"),l.id="wmap-modal-backdrop",Object.assign(l.style,{position:"fixed",inset:"0",background:"rgba(0,0,0,0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:Z_ABOVE,backdropFilter:"blur(3px)"}));const p=n.activeElement,i=n.createElement("div");i.className=t?"wmap-modal-box wmap-overlay-box":"wmap-window-box wmap-overlay-box",i.setAttribute("role","dialog"),t&&i.setAttribute("aria-modal","true"),i.setAttribute("aria-label",e.title??"Expanded wafer map"),i.tabIndex=-1;const b=e.boxSize?.width??"min(90vw, 700px)";let d=e.boxSize?.height??"min(90vh, 700px)";if(Object.assign(i.style,{position:"relative",background:CLR.menuBg,borderRadius:RADIUS.container,overflow:"hidden",display:"flex",flexDirection:"column",width:b,height:d,boxShadow:SHADOW.modal,minWidth:"320px",minHeight:"240px",maxWidth:"100vw",maxHeight:"100vh",zIndex:t?Z_ABOVE2:String(fe())}),!t){const v=Ne();Object.assign(i.style,{position:"fixed",top:`${Math.round(o.innerHeight*.08)+v}px`,left:`${Math.round(o.innerWidth*.08)+v}px`})}const a=n.createElement("div");Object.assign(a.style,{display:"flex",alignItems:"center",gap:SPACE.sm,padding:"10px 14px",borderBottom:`1px solid ${CLR.menuBorder}`,flexShrink:"0"});const y={border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,background:CLR.panelBg,cursor:"pointer",color:CLR.label,lineHeight:LEADING.none,padding:"0",display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px"};if(e.title){const v=n.createElement("span");v.textContent=e.title,v.title=e.title,v.dataset.wmapWindowTitle="1",Object.assign(v.style,{fontWeight:"700",fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"}),a.appendChild(v)}const s=n.createElement("div");s.style.flex="1",a.appendChild(s);let f=null;t||(f=n.createElement("button"),f.type="button",f.innerHTML=W.collapse,f.setAttribute("aria-label","Collapse"),wireTooltip(f),Object.assign(f.style,y),wireControlHover(f),f.addEventListener("click",()=>S(!E)),a.appendChild(f));let x=null;e.printable&&(x=n.createElement("button"),x.type="button",x.innerHTML=W.print,x.setAttribute("aria-label","Print / Save as PDF"),wireTooltip(x),Object.assign(x.style,y),wireControlHover(x),x.addEventListener("click",()=>{typeof e.printable=="function"?e.printable():o.print()}),a.appendChild(x));const c=n.createElement("button");c.type="button",c.innerHTML=W.maximize,c.setAttribute("aria-label","Maximize (F)"),wireTooltip(c),Object.assign(c.style,y),wireControlHover(c),c.addEventListener("click",()=>A(!u));const m=n.createElement("button");m.type="button",m.innerHTML=W.close,m.setAttribute("aria-label","Close (Esc)"),wireTooltip(m),Object.assign(m.style,y),wireControlHover(m),m.addEventListener("click",I),a.appendChild(c),a.appendChild(m);let u=!1,h="",w="";function A(v){u=v,c.innerHTML=u?W.minimize:W.maximize,c.setAttribute("aria-label",u?"Restore (F)":"Maximize (F)"),f&&(f.style.display=u?"none":""),M.style.display=u?"none":"block",u?(i.style.borderRadius="0",i.style.width="100vw",i.style.height="100vh",t||(h=i.style.top,w=i.style.left,i.style.top="0",i.style.left="0")):(i.style.borderRadius="12px",i.style.width=b,i.style.height=d,t||(i.style.top=h,i.style.left=w)),e.onMaximizeChange?.(u,i)}let E=!1,C="",T="";const D=220;function S(v){E=v,f.innerHTML=E?W.uncollapse:W.collapse,f.setAttribute("aria-label",E?"Show contents":"Collapse"),M.style.display=E?"none":"block",E?(C=i.style.height,T=i.style.width,i.style.minHeight="0",i.style.height="auto",i.style.minWidth="0",i.style.width=`${D}px`,c.disabled=!0,c.style.opacity="0.4",c.style.cursor="default",$.style.display="none"):(i.style.minHeight="240px",i.style.height=C||d,i.style.minWidth="320px",i.style.width=T||b,c.disabled=!1,c.style.opacity="1",c.style.cursor="pointer",$.style.display="flex")}function g(){const v=n.body.style.userSelect;return n.body.style.userSelect="none",()=>{n.body.style.userSelect=v}}t||(a.style.cursor="move",a.addEventListener("pointerdown",v=>{if(u||v.target.closest('button, [role="button"]'))return;v.preventDefault();const H=g(),_=v.clientX,N=v.clientY,R=i.offsetTop,P=i.offsetLeft,ne=o.innerHeight-a.offsetHeight,oe=o.innerWidth-40,Q=40-i.offsetWidth;a.setPointerCapture(v.pointerId);const q=X=>{const ie=Math.min(Math.max(R+(X.clientY-N),0),ne),we=Math.min(Math.max(P+(X.clientX-_),Q),oe);i.style.top=`${ie}px`,i.style.left=`${we}px`},G=X=>{H(),a.releasePointerCapture(X.pointerId),a.removeEventListener("pointermove",q),a.removeEventListener("pointerup",G)};a.addEventListener("pointermove",q),a.addEventListener("pointerup",G)}));const B='button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"]),[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';function V(v){const H=Array.from(i.querySelectorAll(B)).filter(P=>P.offsetParent!==null||P===n.activeElement);if(H.length===0){v.preventDefault(),i.focus();return}const _=H[0],N=H[H.length-1],R=n.activeElement;v.shiftKey&&(R===_||!i.contains(R))?(v.preventDefault(),N.focus()):!v.shiftKey&&R===N&&(v.preventDefault(),_.focus())}const z=v=>{if(v.key==="Escape"){I();return}if(t&&(v.key==="e"||v.key==="E")){I();return}if(t&&v.key==="Tab"){V(v);return}(v.key==="f"||v.key==="F")&&!E&&A(!u)};function I(){t?n.removeEventListener("keydown",z):i.removeEventListener("keydown",z),te.remove(),ge(),hideTooltip(n),reparentTooltip(n.body),l?l.remove():i.remove(),t&&(n.body.style.overflow=r),p?.focus?.(),e.onClose()}function Y(){t||(i.style.zIndex=String(fe()))}const $=n.createElement("div");Object.assign($.style,{flex:"1",minHeight:"0",minWidth:"0",display:"flex",overflow:"hidden"});const M=n.createElement("div");M.tabIndex=0,M.setAttribute("role","separator"),M.setAttribute("aria-label","Resize window (arrow keys, or drag)"),Object.assign(M.style,{position:"absolute",right:"0",bottom:"0",width:"16px",height:"16px",cursor:"nwse-resize",touchAction:"none"}),M.innerHTML='<svg viewBox="0 0 16 16" width="16" height="16" style="display:block"><path d="M15 15 L15 9 M15 15 L9 15 M15 15 L15 3 M15 15 L3 15" stroke="currentColor" stroke-width="1" opacity="0.35" fill="none"/></svg>',M.style.color=CLR.label;const L=320,U=240,O=20;function Z(v,H){const _=o.innerWidth-i.offsetLeft,N=o.innerHeight-i.offsetTop,R=Math.min(Math.max(i.offsetWidth+v,L),_),P=Math.min(Math.max(i.offsetHeight+H,U),N);i.style.width=`${R}px`,i.style.height=`${P}px`}M.addEventListener("keydown",v=>{if(!(u||E))switch(v.key){case"ArrowRight":v.preventDefault(),Z(O,0);break;case"ArrowLeft":v.preventDefault(),Z(-O,0);break;case"ArrowDown":v.preventDefault(),Z(0,O);break;case"ArrowUp":v.preventDefault(),Z(0,-O);break}}),M.addEventListener("pointerdown",v=>{if(u||E)return;v.preventDefault();const H=g(),_=v.clientX,N=v.clientY,R=i.offsetWidth,P=i.offsetHeight,ne=o.innerWidth-i.offsetLeft,oe=o.innerHeight-i.offsetTop;M.setPointerCapture(v.pointerId);const Q=G=>{const X=Math.min(Math.max(R+(G.clientX-_),L),ne),ie=Math.min(Math.max(P+(G.clientY-N),U),oe);i.style.width=`${X}px`,i.style.height=`${ie}px`},q=G=>{H(),M.releasePointerCapture(G.pointerId),M.removeEventListener("pointermove",Q),M.removeEventListener("pointerup",q)};M.addEventListener("pointermove",Q),M.addEventListener("pointerup",q)}),i.appendChild(a),i.appendChild($),i.appendChild(M);const ee=e.anchor?overlayRootFor(e.anchor):n.body;l?(l.appendChild(i),ee.appendChild(l)):ee.appendChild(i);const ge=Pe(n,ee),te=n.createElement("style");te.textContent=`@media print{
1
+ import{getUniqueTestNumbers as Ce}from"../renderer/buildView.js";import{dieHasValues as Le}from"../core/dieTable.js";import{dieHasTestData as Ae}from"../renderer/buildWaferMap.js";import{testLabel as re,isDerivedTest as Me,DERIVED_MARK as ce,DERIVED_KEY as de}from"../renderer/testLabel.js";import{prettyKey as Se}from"../core/utils.js";import{diagnoseMpwLayout as Be,formatMpwDiagnostics as De}from"../core/compact.js";import{listBinColorSchemes as Te,listValueColorSchemes as He}from"../renderer/colorSchemes.js";import{ICONS as F}from"./icons.js";import{WMAP_VERSION as ue,WMAP_BUILD_TIME as Oe}from"./version.js";import{openHtmlReport as Ie}from"../stats/renderFindingsReport.js";import{buildWaferMap as $e}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as Re}from"../stats/analyzeWaferMap.js";let pe=!1;export function logWmapVersionOnce(){pe||(pe=!0,console.log(`[wmap] v${ue} (built ${Oe})`))}export const WMAP_TOKEN_NAMES=["z","icon","icon-hover","icon-active","bg-hover","bg-active","separator","surface","border","control-border","menu-hover","menu-active","font-family","font-size","density","panel-bg","text-muted","text","text-strong","warn-bg","warn-border","warn-text","err-bg","err-border","err-text","info-bg","info-text","selected","finding-indicator","canvas-bg","bar-fill"];const E=(e,t)=>`var(--wmap-${e}, ${t})`,J="var(--wmap-font-size, 12px)",We="var(--wmap-density, 1)",U=e=>`calc(${e}px * ${We})`;export function wireControlHover(e,t="outlined"){let n=null;const o=()=>{n&&(e.style.background=n.background,e.style.color=n.color)};e.addEventListener("mouseenter",()=>{e.dataset.on==="true"||e.disabled||(n||(n={background:e.style.background,color:e.style.color}),e.style.background=CLR.bgHover,e.style.color=CLR.iconHover)}),e.addEventListener("mouseleave",o),e.addEventListener("blur",o)}export function controlStyle(e,t=!1){const n={fontSize:FONT.body,cursor:"pointer",borderRadius:RADIUS.control};return e==="bare"?{...n,border:"none",background:"none",padding:"0",color:CLR.icon}:{...n,border:`1px solid ${CLR.controlBorder}`,background:e==="toggle"&&t?CLR.menuActive:"none",color:e==="toggle"&&t?CLR.iconActive:CLR.text,padding:`${SPACE.xxs} ${SPACE.lg}`}}export const SPACE={xxs:U(2),xs:U(4),sm:U(6),md:U(8),lg:U(10),xl:U(12),xxl:U(16),xxxl:U(24)},SHADOW={panel:"0 1px 4px rgba(0,0,0,0.10)",menu:"0 4px 12px rgba(0,0,0,0.15)",modal:"0 20px 60px rgba(0,0,0,0.40)"},MOTION={fast:"0.12s ease",base:"0.2s ease"},LEADING={none:"1",tight:"1.2",base:"1.45"},ALPHA={muted:"0.85",disabled:"0.4"},TRACKING="0.05em",EDGE_GUTTER=SPACE.xl,MAP_CHROME_INSET=SPACE.xs,RADIUS={control:"4px",container:"6px",pill:"999px"},FONT={family:"var(--wmap-font-family, inherit)",meta:`calc(${J} - 1px)`,body:J,sub:`calc(${J} + 1px)`,heading:`calc(${J} + 3px)`,stat:`calc(${J} + 8px)`};export function fontPx(e=0,t){const n=t?.ownerDocument??(typeof document<"u"?document:null);if(!n)return 12+e;const o=getComputedStyle(t??n.documentElement).getPropertyValue("--wmap-font-size").trim(),r=o?parseFloat(o):NaN;return(Number.isFinite(r)?r:12)+e}export const CLR={icon:E("icon","#506784"),iconHover:E("icon-hover","#2a3f5f"),iconActive:E("icon-active","#1a65ca"),bgHover:E("bg-hover","#edf0f8"),bgActive:E("bg-active","#dce8f8"),separator:E("separator","rgba(0,0,0,0.12)"),menuBg:E("surface","#fff"),menuBorder:E("border","rgba(0,0,0,0.12)"),controlBorder:E("control-border",E("border","rgba(0,0,0,0.30)")),menuHover:E("menu-hover","#f0f4fc"),menuActive:E("menu-active","#dce8f8"),canvasBg:`var(--wmap-canvas-bg, ${E("surface","#f5f5f5")})`,panelBg:E("panel-bg","#fafbfc"),label:E("text-muted","#647687"),value:E("text-strong","#1f2f43"),text:E("text","#333"),warnBg:E("warn-bg","#fffbe6"),warnBorder:E("warn-border","#f0c040"),warnText:E("warn-text","#7a5800"),errBg:E("err-bg","#fef2f2"),errBorder:E("err-border","#dc8a8a"),errText:E("err-text","#7a1c1c"),infoBg:E("info-bg","#dce8f8"),infoText:E("info-text","#334155"),findingHighlight:E("selected","#e07a20"),findingIndicator:E("finding-indicator","#b7551a"),barFill:E("bar-fill","#2a6fc0")};export function sevColor(e){return e==="unusual"?"#a84112":e==="notable"?"#8a6500":CLR.icon}export const ROTATIONS=[0,90,180,270],INLINE_TEST_LIMIT=6,MENU_SEARCH_THRESHOLD=8,DEFAULT_OVERLAY_Z=6e3,Z_BASE=`var(--wmap-z, ${DEFAULT_OVERLAY_Z})`,Z_ABOVE=`calc(var(--wmap-z, ${DEFAULT_OVERLAY_Z}) + 1)`,Z_MENU=`calc(var(--wmap-z, ${DEFAULT_OVERLAY_Z}) + 2)`,Z_ABOVE2=`calc(var(--wmap-z, ${DEFAULT_OVERLAY_Z}) + 3)`;export function applyOverlayZ(e){if(e==null)return()=>{};const t=document.documentElement,n=t.style.getPropertyValue("--wmap-z");return t.style.setProperty("--wmap-z",String(e)),()=>{n?t.style.setProperty("--wmap-z",n):t.style.removeProperty("--wmap-z")}}export function copyWmapThemeTokens(e,t){const n=getComputedStyle(e);for(const o of WMAP_TOKEN_NAMES){const r=n.getPropertyValue(`--wmap-${o}`).trim();r&&t.style.setProperty(`--wmap-${o}`,r)}}export function syncWmapPopupTheme(e,t,n){const o=()=>{copyWmapThemeTokens(e,t),n?.()},r=new window.MutationObserver(o);r.observe(e,{attributes:!0,attributeFilter:["style","class"]}),r.observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]});const s=window.matchMedia("(prefers-color-scheme: dark)");return s.addEventListener("change",o),()=>{r.disconnect(),s.removeEventListener("change",o)}}let ae=null;export function setDetachWindowOpener(e){ae=e}export function openDetachWindow(e){return ae?ae(e):window.open("","_blank","width=560,height=600")}export const MODE_LABELS={value:"Test Value",hardBin:"Hard Bin",softBin:"Soft Bin",stackedValues:"Stacked Test Values",stackedBins:"Stacked Hard Bins",stackedSoftBins:"Stacked Soft Bins",metadata:"Metadata"},BIN_LEGEND_MODES=new Set(["hardBin","softBin","metadata"]),STACKED_MODES=new Set(["stackedValues","stackedBins","stackedSoftBins"]);export function saveImageBlob(e,t,n){const o=`${t}.png`;if(n){n(e,o);return}downloadBlob(e,o)}export function downloadBlob(e,t){const n=URL.createObjectURL(e),o=document.createElement("a");o.href=n,o.download=t,o.click(),URL.revokeObjectURL(n)}export function roomForPanel(e){let t=null;return(n,o)=>{t?.(),t=n?e.reserveWidth(o):null}}export function openCompactDiagnostics(e,t,n){const o=De(Be(e,t),ue),r=n.anchor.ownerDocument,s=openModal({title:"Layout diagnostics",anchor:n.anchor,ownerDocument:r,onClose:()=>{},boxSize:{width:"min(680px, 94vw)",height:"min(480px, 90vh)"}}),m=s.contentWrap;Object.assign(m.style,{flexDirection:"column",padding:"14px 16px",gap:"10px",boxSizing:"border-box"});const i=r.createElement("p");i.textContent="This is everything the compact layout looked at. It holds counts and scores only: no die positions, bins, test values or wafer names. If the layout was not detected the way you expect, send it to whoever supports this software.",Object.assign(i.style,{margin:"0",fontSize:FONT.body,color:CLR.text,lineHeight:"1.4"});const c=r.createElement("textarea");c.value=o,c.readOnly=!0,c.setAttribute("aria-label","Layout diagnostics"),Object.assign(c.style,{flex:"1",minHeight:"0",resize:"none",fontFamily:"ui-monospace, monospace",fontSize:FONT.body,padding:"8px",border:`1px solid ${CLR.separator}`,borderRadius:RADIUS.control,color:CLR.text,background:CLR.menuBg});const d=r.createElement("div");Object.assign(d.style,{display:"flex",gap:"8px",alignItems:"center"});const a=r.createElement("span");a.setAttribute("role","status"),Object.assign(a.style,{fontSize:FONT.body,color:CLR.text});const g=(h,u)=>{const p=r.createElement("button");return p.type="button",p.textContent=h,Object.assign(p.style,controlStyle("outlined"),{padding:"5px 12px",color:CLR.text}),wireControlHover(p,"outlined"),p.addEventListener("click",u),p},l=g("Copy",()=>{const h=r.defaultView,u=()=>{c.focus(),c.select();let p=!1;try{p=r.execCommand("copy")}catch{p=!1}a.textContent=p?"Copied":"Copying is not available here. Select the text, or save it as a file."};h?.navigator.clipboard?h.navigator.clipboard.writeText(o).then(()=>{a.textContent="Copied"},u):u()}),b=g("Save as file",()=>{saveTextFile(o,"wafermap-layout-diagnostics.txt","text/plain",n.onSaveText),a.textContent=n.onSaveText?"":"Saved"});return d.append(l,b,a),m.append(i,c,d),c.focus(),c.select(),s}export function saveTextFile(e,t,n,o){if(o){o(e,t,n);return}downloadBlob(new Blob([e],{type:n}),t)}const ze='[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';export function nextFrame(e,t=window){const n=t.requestAnimationFrame;typeof n=="function"?n.call(t,e):setTimeout(e,0)}export function wireListNavigation(e,t,n){e.addEventListener("keydown",o=>{const r=t();if(r.length===0)return;const s=e.ownerDocument.activeElement,m=s?r.indexOf(s):-1;switch(o.key){case"ArrowDown":o.preventDefault(),r[m<0||m===r.length-1?0:m+1].focus();break;case"ArrowUp":o.preventDefault(),r[m<=0?r.length-1:m-1].focus();break;case"Home":o.preventDefault(),r[0].focus();break;case"End":o.preventDefault(),r[r.length-1].focus();break;case"Enter":case" ":m>=0&&(o.preventDefault(),r[m].click());break;case"Escape":case"Tab":o.preventDefault(),n();break}})}function te(e,t,n){const o=()=>Array.from(e.querySelectorAll(ze));wireListNavigation(e,o,()=>{n(),t?.focus()});const r=o()[0];r&&nextFrame(()=>r.focus())}export function overlayRootFor(e){let t=e;for(;t;){if(t.classList.contains("wmap-overlay-box")||t.tagName==="DIALOG"&&t.matches(":modal"))return t;t=t.parentElement}return e.ownerDocument.body}const fe=new WeakMap;export function menuLayerFor(e){const t=overlayRootFor(e),n=fe.get(t);if(n&&n.isConnected)return n;const r=e.ownerDocument.createElement("div");return r.dataset.wmapMenuLayer="1",Object.assign(r.style,{position:"fixed",inset:"0",zIndex:Z_MENU,pointerEvents:"none"}),t.appendChild(r),fe.set(t,r),r}const se=new WeakMap;export function getTooltip(e=document){const t=se.get(e);if(t&&t.isConnected)return t;const n=t??e.createElement("div");return t||(Object.assign(n.style,{position:"fixed",pointerEvents:"none",background:"rgba(30, 32, 40, 0.93)",color:"#f0f0f2",border:"1px solid rgba(255,255,255,0.10)",padding:"7px 11px",borderRadius:RADIUS.control,fontSize:FONT.sub,lineHeight:LEADING.base,maxWidth:"280px",maxHeight:"min(60vh, 480px)",overflow:"hidden",whiteSpace:"pre-wrap",zIndex:Z_ABOVE2,display:"none",fontFamily:FONT.family,boxShadow:SHADOW.menu}),se.set(e,n)),e.body.appendChild(n),n}export function hideTooltip(e=document){const t=se.get(e);t&&(t.style.display="none")}export function reparentTooltip(e){const t=e?.ownerDocument??document,n=getTooltip(t);(e??t.body).appendChild(n)}export function positionTooltip(e,t,n,o,r={}){const s=menuLayerFor(t);e.parentElement!==s&&s.appendChild(e);const m=e.ownerDocument.defaultView??window;e.style.left="0",e.style.top="0";const i=e.offsetWidth,c=e.offsetHeight,d=8,a=m.innerWidth,g=m.innerHeight;let l=n+14,b=o-8;l+i+d>a&&(l=n-i-6);const h=t.getBoundingClientRect();if(!r.followPointer&&h.height>0&&h.height<=g*.4&&b<h.bottom&&b+c>h.top&&l<h.right&&l+i>h.left){const f=h.bottom+d,x=h.top-c-d;f+c+d<=g?b=f:x>=d&&(b=x)}b+c+d>g&&(b=g-c-d),b<d&&(b=d),e.style.left=`${l}px`,e.style.top=`${b}px`}export function wireTooltip(e,t,n={}){const o=()=>(typeof t=="function"?t():t)??e.getAttribute("aria-label")??"";n.asDataPoint&&(e.tabIndex=0,e.setAttribute("role","img"),typeof t=="string"&&e.setAttribute("aria-label",t));const r=m=>{const i=o();if(!i)return;const c=getTooltip(e.ownerDocument);if(c.textContent=i,c.style.display="block",m)positionTooltip(c,e,m.clientX,m.clientY);else{const d=e.getBoundingClientRect();positionTooltip(c,e,d.left+d.width/2,d.top)}},s=()=>hideTooltip(e.ownerDocument);e.addEventListener("mousemove",r),e.addEventListener("mouseleave",s),e.addEventListener("focus",()=>r()),e.addEventListener("blur",s)}export function buildDataModeEntries(e,t,n){const o=e.some(Ae),r=e.some(Le),s=e.some(a=>a.hbin!=null),m=e.some(a=>a.sbin!=null),i=o?t!==void 0?t.map(a=>({plotMode:"value",activeTest:a.testNumber,label:a.unit?`${re(a,a.testNumber)} (${a.unit})`:re(a,a.testNumber),logScale:a.logScale,...Me(a)?{derived:!0}:{}})):Ce(e).map(a=>({plotMode:"value",activeTest:a,label:re(void 0,a)})):[],c=[...s?[{plotMode:"hardBin",label:MODE_LABELS.hardBin}]:[],...m?[{plotMode:"softBin",label:MODE_LABELS.softBin}]:[]],d=n.includeStacked?[...r?[{plotMode:"stackedValues",label:MODE_LABELS.stackedValues}]:[],...s?[{plotMode:"stackedBins",label:MODE_LABELS.stackedBins}]:[],...m?[{plotMode:"stackedSoftBins",label:MODE_LABELS.stackedSoftBins}]:[]]:[];return{testEntries:i,binEntries:c,stackedEntries:d}}export function metadataKeyHasData(e,t){return e.some(n=>n.metadata?.[t]!==void 0&&n.metadata?.[t]!==null)}export function metadataModeEntry(e){return{plotMode:"metadata",activeMetadataKey:e.key,label:e.label??Se(e.key)}}export function makeMenuSearchBox(e,t="Filter\u2026",n=document){const o=n.createElement("input");return o.type="text",o.placeholder=t,o.setAttribute("aria-label",t),Object.assign(o.style,{display:"block",width:"calc(100% - 20px)",margin:"2px 10px 6px",padding:`${SPACE.xs} ${SPACE.md}`,fontSize:FONT.body,boxSizing:"border-box",background:CLR.menuBg,color:CLR.text,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,outline:"none"}),o.addEventListener("click",r=>r.stopPropagation()),o.addEventListener("mousedown",r=>r.stopPropagation()),o.addEventListener("keydown",r=>r.stopPropagation()),o.addEventListener("input",()=>e(o.value.trim().toLowerCase())),o.addEventListener("focus",()=>{o.style.borderColor=CLR.iconActive}),o.addEventListener("blur",()=>{o.style.borderColor=CLR.menuBorder}),queueMicrotask(()=>o.focus()),o}export function buildModeMenuEl(e,t,n,o,r,s,m,i,c=window,d=[]){const{makeMenuRow:a,makeMenuSection:g}=m,l=document.createElement("div"),b=180,u=e.left+b<=(c.innerWidth??1/0)?e.left:Math.max(4,e.right-b);if(Object.assign(l.style,{position:"fixed",top:`${e.bottom+4}px`,left:`${u}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_BASE,minWidth:`${b}px`,padding:"4px 0",pointerEvents:"auto"}),t.length)if(l.appendChild(g("Test Value")),t.length<=INLINE_TEST_LIMIT)for(const p of t)l.appendChild(a(p.label,r(p),!0,f=>{f.stopPropagation(),s(p,l)}));else{const p=i==="value",f=a(MODE_LABELS.value+" \u25B6",p,!1,y=>{y.stopPropagation(),A(),S(),y.detail===0&&$()});f.setAttribute("aria-haspopup","menu"),f.style.display="flex",f.style.justifyContent="space-between",f.style.alignItems="center";let x=null,w=null;const A=()=>{w!==null&&(clearTimeout(w),w=null)},k=y=>{const B=y.target;B&&(f.contains(B)||x?.contains(B))||C()},C=()=>{A(),x?.remove(),x=null,c.document.removeEventListener("click",k),f.setAttribute("aria-expanded","false")},$=()=>{const y=x?.querySelector('input, [role="menuitemradio"]');y&&nextFrame(()=>y.focus(),c)},D=()=>{A(),w=setTimeout(C,300)},S=()=>{if(x)return;const y=f.getBoundingClientRect(),B=160,X=320,W=y.right+2+B<=(c.innerWidth??1/0)?y.right+2:Math.max(4,y.left-2-B),Z=Math.min(y.top-4,Math.max(4,(c.innerHeight??1/0)-X-4));if(x=document.createElement("div"),x.setAttribute("data-wmap-submenu",""),x.setAttribute("role","menu"),Object.assign(x.style,{position:"fixed",top:`${Z}px`,left:`${W}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_ABOVE,minWidth:`${B}px`,maxHeight:`${X}px`,overflowY:"auto",padding:"4px 0",pointerEvents:"auto"}),t.length>MENU_SEARCH_THRESHOLD){const L=makeMenuSearchBox(Y=>{for(const _ of z)_.row.style.display=_.label.includes(Y)?"":"none"},"Filter tests\u2026");Object.assign(L.style,{position:"sticky",top:"0",zIndex:"1",background:CLR.menuBg}),x.appendChild(L)}const z=[],M=t.some(L=>L.derived);for(const L of t){const Y=a(L.label,r(L),!1,_=>{_.stopPropagation(),C(),s(L,l)},M?{derived:L.derived===!0}:void 0);z.push({row:Y,label:L.label.toLowerCase()}),x.appendChild(Y)}if(M){const L=c.document.createElement("div");L.setAttribute("role","presentation"),L.textContent=`${ce} ${de}`,Object.assign(L.style,{padding:"6px 14px",fontSize:FONT.meta,color:CLR.label,borderTop:`1px solid ${CLR.menuBorder}`,marginTop:"4px",whiteSpace:"nowrap"}),x.appendChild(L)}x.addEventListener("mouseenter",A),x.addEventListener("mouseleave",D),wireListNavigation(x,()=>z.filter(L=>L.row.style.display!=="none").map(L=>L.row),()=>{C(),f.focus()}),(l.parentElement??c.document.body).appendChild(x),c.document.addEventListener("click",k),f.setAttribute("aria-expanded","true")};l.addEventListener("keydown",y=>{y.key==="Escape"&&C()}),f.addEventListener("mouseenter",()=>{A(),S()}),f.addEventListener("mouseleave",D),l.appendChild(f)}if(n.length){l.appendChild(g("Bins"));for(const p of n)l.appendChild(a(p.label,r(p),!1,f=>{f.stopPropagation(),s(p,l)}))}if(d.length){l.appendChild(g("Metadata"));for(const p of d)l.appendChild(a(p.label,r(p),!1,f=>{f.stopPropagation(),s(p,l)}))}if(o.length){l.appendChild(g("Lot Aggregation"));for(const p of o)l.appendChild(a(p.label,r(p),!1,f=>{f.stopPropagation(),s(p,l)}))}return l.setAttribute("role","menu"),l.setAttribute("aria-label","Plot mode"),l}export function markMenuTrigger(e,t){e.setAttribute("aria-haspopup","menu"),e.setAttribute("aria-expanded",t?"true":"false")}export function wireMenuA11y(e,t,n){te(e,t,n)}export function wireExpandToggle(e,t){const n=e.ownerDocument;let o=!1;function r(d){o!==d&&(o=d,t(o))}function s(){r(!1)}function m(){r(!o),o&&n.addEventListener("click",s,{once:!0})}const i=d=>{d.stopPropagation(),m()},c=d=>{d.key==="Enter"||d.key===" "?(d.preventDefault(),m()):d.key==="Escape"&&s()};return e.setAttribute("role","button"),e.tabIndex<0&&(e.tabIndex=0),e.addEventListener("click",i),e.addEventListener("keydown",c),{isOpen:()=>o,close:s,destroy(){e.removeEventListener("click",i),e.removeEventListener("keydown",c),n.removeEventListener("click",s)}}}export function buildCheckMenuEl(e,t,n,o=window){const{makeMenuSection:r}=n,s=o.document,m=s.createElement("div"),i=168,d=e.left+i<=(o.innerWidth??1/0)?e.left:Math.max(4,e.right-i);Object.assign(m.style,{position:"fixed",top:`${e.bottom+4}px`,left:`${d}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_BASE,minWidth:`${i}px`,padding:"4px 0",pointerEvents:"auto"});for(const a of t)if("section"in a)m.appendChild(r(a.section));else{const g=a.enabled!==!1;if(!g&&!a.disabledHint)continue;const l=s.createElement("div");a.action?l.setAttribute("role","menuitem"):(l.setAttribute("role","menuitemcheckbox"),l.setAttribute("aria-checked",a.active?"true":"false")),l.tabIndex=-1,g||(l.setAttribute("aria-disabled","true"),wireTooltip(l,a.disabledHint)),Object.assign(l.style,{display:"flex",alignItems:"center",gap:SPACE.sm,padding:"6px 14px",fontSize:FONT.body,cursor:g?"pointer":"default",color:g?a.active?CLR.iconActive:CLR.text:CLR.label,fontWeight:a.active?"700":"400",background:a.active?CLR.menuActive:"transparent",whiteSpace:"nowrap"});const b=s.createElement("span");Object.assign(b.style,{width:"12px",flexShrink:"0",color:CLR.iconActive,visibility:a.active?"visible":"hidden"}),b.textContent=a.action?"":"\u2713",b.setAttribute("aria-hidden","true");const h=s.createElement("span");h.textContent=a.label,l.appendChild(b),l.appendChild(h),g?(l.addEventListener("mouseenter",()=>{a.active||(l.style.background=CLR.menuHover)}),l.addEventListener("mouseleave",()=>{l.style.background=a.active?CLR.menuActive:"transparent"}),l.addEventListener("focus",()=>{a.active||(l.style.background=CLR.menuHover)}),l.addEventListener("blur",()=>{l.style.background=a.active?CLR.menuActive:"transparent"}),l.addEventListener("click",u=>{u.stopPropagation(),a.onClick(u)})):l.addEventListener("click",u=>{u.stopPropagation()}),m.appendChild(l)}return m}export function createToolbarHelpers(e){const t=e.ownerDocument;let n=null;const o=l=>menuLayerFor(l);function r(l,b,h){const u=t.createElement("button");return u.innerHTML=F[l],u.type="button",u.ariaLabel=b,Object.assign(u.style,{display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",padding:"0",border:"none",borderRadius:RADIUS.control,background:"transparent",color:CLR.icon,cursor:"pointer",pointerEvents:"auto",transition:`background ${MOTION.fast}, color ${MOTION.fast}`,flexShrink:"0"}),u.addEventListener("mouseenter",p=>{u.dataset.active||(u.style.background=CLR.bgHover,u.style.color=CLR.iconHover),e.textContent=u.ariaLabel??b,e.style.display="block",positionTooltip(e,u,p.clientX,p.clientY)}),u.addEventListener("mousemove",p=>{e.style.display==="block"&&positionTooltip(e,u,p.clientX,p.clientY)}),u.addEventListener("mouseleave",()=>{u.dataset.active||(u.style.background="transparent",u.style.color=CLR.icon),e.style.display="none"}),u.addEventListener("click",()=>{e.style.display="none",h()}),u}function s(l,b){b?(l.dataset.active="1",l.style.background=CLR.bgActive,l.style.color=CLR.iconActive):(delete l.dataset.active,l.style.background="transparent",l.style.color=CLR.icon)}function m(){const l=t.createElement("div");return Object.assign(l.style,{width:"1px",height:"18px",background:CLR.separator,margin:"0 2px",flexShrink:"0"}),l}function i(l,b,h,u,p){const f=t.createElement("div");if(p){const x=t.createElement("span");x.textContent=p.derived?ce:"",x.setAttribute("aria-hidden","true"),Object.assign(x.style,{display:"inline-block",width:"1.1em"}),f.append(x,l),p.derived&&f.setAttribute("aria-label",`${l} \u2014 ${de.toLowerCase()}`)}else f.textContent=l;return f.setAttribute("role","menuitemradio"),f.setAttribute("aria-checked",b?"true":"false"),f.tabIndex=-1,Object.assign(f.style,{padding:`6px 14px 6px ${h?"26px":"14px"}`,fontSize:FONT.body,cursor:"pointer",color:b?CLR.iconActive:CLR.text,fontWeight:b?"700":"400",background:b?CLR.menuActive:"transparent",whiteSpace:"nowrap"}),f.addEventListener("mouseenter",()=>{b||(f.style.background=CLR.menuHover)}),f.addEventListener("mouseleave",()=>{f.style.background=b?CLR.menuActive:"transparent"}),f.addEventListener("focus",()=>{b||(f.style.background=CLR.menuHover)}),f.addEventListener("blur",()=>{f.style.background=b?CLR.menuActive:"transparent"}),f.addEventListener("click",u),f}function c(l){const b=t.createElement("div");return b.textContent=l,b.setAttribute("role","presentation"),Object.assign(b.style,{padding:"5px 14px 2px",fontSize:FONT.body,fontWeight:"600",letterSpacing:TRACKING,color:CLR.label,textTransform:"uppercase",pointerEvents:"none",userSelect:"none"}),b}function d(l,b,h,u,p){const f=()=>{n&&(n.remove(),n=null),x.setAttribute("aria-expanded","false")},x=r(l,b,()=>{if(n){f();return}const w=t.createElement("div"),A=x.getBoundingClientRect(),k=x.ownerDocument.defaultView??window,C=148,D=A.left+C<=(k.innerWidth??1/0)?A.left:Math.max(4,A.right-C);Object.assign(w.style,{position:"fixed",top:`${A.bottom+4}px`,left:`${D}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_BASE,minWidth:`${C}px`,padding:"4px 0",pointerEvents:"auto"});for(const S of h()){const y=t.createElement("div");y.textContent=S.label,y.dataset.wmapDropdownValue=S.value;const B=S.value===u();y.setAttribute("role","menuitemradio"),y.setAttribute("aria-checked",B?"true":"false"),y.tabIndex=-1,Object.assign(y.style,{padding:"6px 14px",fontSize:FONT.body,cursor:"pointer",color:B?CLR.iconActive:CLR.text,fontWeight:B?"700":"400",background:B?CLR.menuActive:"transparent",whiteSpace:"nowrap"});const X=()=>{S.value!==u()&&(y.style.background=CLR.menuHover)},P=()=>{y.style.background=S.value===u()?CLR.menuActive:"transparent"};y.addEventListener("mouseenter",X),y.addEventListener("mouseleave",P),y.addEventListener("focus",X),y.addEventListener("blur",P),y.addEventListener("click",W=>{W.stopPropagation(),p(S.value),f()}),w.appendChild(y)}w.setAttribute("role","menu"),w.setAttribute("aria-label",b),o(x).appendChild(w),n=w,x.setAttribute("aria-expanded","true"),te(w,x,f)});return x.setAttribute("aria-haspopup","menu"),x.setAttribute("aria-expanded","false"),x}function a(l,b,h,u){function p(){return buildCheckMenuEl(x.getBoundingClientRect(),h().map(w=>"section"in w?w:{...w,onClick:A=>{w.closeMenu&&f(),w.onClick(A),u(x);const k=n;if(!k)return;const C=p();C.setAttribute("role","menu"),C.setAttribute("aria-label",b),k.replaceWith(C),n=C,te(C,x,f)}}),{makeMenuSection:c},x.ownerDocument.defaultView??window)}const f=()=>{n&&(n.remove(),n=null),x.setAttribute("aria-expanded","false")},x=r(l,b,()=>{if(n){f();return}const w=p();w.setAttribute("role","menu"),w.setAttribute("aria-label",b),o(x).appendChild(w),n=w,x.setAttribute("aria-expanded","true"),te(w,x,f)});return x.setAttribute("aria-haspopup","menu"),x.setAttribute("aria-expanded","false"),u(x),x}function g(l){const b=l.target?.closest?.("[data-wmap-submenu]");if(n&&!n.contains(l.target)&&!b&&(n.remove(),n=null,l.target?.getAttribute?.("aria-haspopup")!=="menu"))for(const u of document.querySelectorAll('[aria-haspopup="menu"][aria-expanded="true"]'))u.setAttribute("aria-expanded","false")}return{makeBtn:r,setActive:s,makeSep:m,makeMenuRow:i,makeMenuSection:c,makeDropdown:d,makeCheckMenuBtn:a,closeOpenMenu:g,getOpenMenu:()=>n,setOpenMenu:l=>{n=l}}}const _e=7e3;let Ne=0;function me(){return _e+ ++Ne}const Fe=32,Pe=6;let je=0;function Ve(){return je++%Pe*Fe}function Ue(e,t){if(t===e.body)return()=>{};let n=t;for(;n.parentElement&&n.parentElement!==e.body;)n=n.parentElement;return n===e.body?()=>{}:(n.classList.add("wmap-overlay-ancestor"),()=>n.classList.remove("wmap-overlay-ancestor"))}function be(e){const t=e.mode==="modal",n=e.ownerDocument??document,o=n.defaultView??window,r=n.body.style.overflow;t&&(n.body.style.overflow="hidden");let s=null;t&&(s=n.createElement("div"),s.id="wmap-modal-backdrop",Object.assign(s.style,{position:"fixed",inset:"0",background:"rgba(0,0,0,0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:Z_ABOVE,backdropFilter:"blur(3px)"}));const m=n.activeElement,i=n.createElement("div");i.className=t?"wmap-modal-box wmap-overlay-box":"wmap-window-box wmap-overlay-box",i.setAttribute("role","dialog"),t&&i.setAttribute("aria-modal","true"),i.setAttribute("aria-label",e.title??"Expanded wafer map"),i.tabIndex=-1;let c=e.boxSize?.width??"min(90vw, 700px)",d=e.boxSize?.height??"min(90vh, 700px)";if(Object.assign(i.style,{position:"relative",background:CLR.menuBg,borderRadius:RADIUS.container,overflow:"hidden",display:"flex",flexDirection:"column",width:c,height:d,boxShadow:SHADOW.modal,minWidth:"320px",minHeight:"240px",maxWidth:"100vw",maxHeight:"100vh",zIndex:t?Z_ABOVE2:String(me())}),!t){const v=Ve();Object.assign(i.style,{position:"fixed",top:`${Math.round(o.innerHeight*.08)+v}px`,left:`${Math.round(o.innerWidth*.08)+v}px`})}const a=n.createElement("div");Object.assign(a.style,{display:"flex",alignItems:"center",gap:SPACE.sm,padding:"10px 14px",borderBottom:`1px solid ${CLR.menuBorder}`,flexShrink:"0"});const g={border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,background:CLR.panelBg,cursor:"pointer",color:CLR.label,lineHeight:LEADING.none,padding:"0",display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px"};if(e.title){const v=n.createElement("span");v.textContent=e.title,v.title=e.title,v.dataset.wmapWindowTitle="1",Object.assign(v.style,{fontWeight:"700",fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"}),a.appendChild(v)}const l=n.createElement("div");l.style.flex="1",a.appendChild(l);let b=null;t||(b=n.createElement("button"),b.type="button",b.innerHTML=F.collapse,b.setAttribute("aria-label","Collapse"),wireTooltip(b),Object.assign(b.style,g),wireControlHover(b),b.addEventListener("click",()=>S(!k)),a.appendChild(b));let h=null;e.printable&&(h=n.createElement("button"),h.type="button",h.innerHTML=F.print,h.setAttribute("aria-label","Print / Save as PDF"),wireTooltip(h),Object.assign(h.style,g),wireControlHover(h),h.addEventListener("click",()=>{typeof e.printable=="function"?e.printable():o.print()}),a.appendChild(h));const u=n.createElement("button");u.type="button",u.innerHTML=F.maximize,u.setAttribute("aria-label","Maximize (F)"),wireTooltip(u),Object.assign(u.style,g),wireControlHover(u),u.addEventListener("click",()=>A(!f));const p=n.createElement("button");p.type="button",p.innerHTML=F.close,p.setAttribute("aria-label","Close (Esc)"),wireTooltip(p),Object.assign(p.style,g),wireControlHover(p),p.addEventListener("click",W),a.appendChild(u),a.appendChild(p);let f=!1,x="",w="";function A(v){f=v,u.innerHTML=f?F.minimize:F.maximize,u.setAttribute("aria-label",f?"Restore (F)":"Maximize (F)"),b&&(b.style.display=f?"none":""),M.style.display=f?"none":"block",f?(i.style.borderRadius="0",i.style.width="100vw",i.style.height="100vh",t||(x=i.style.top,w=i.style.left,i.style.top="0",i.style.left="0")):(i.style.borderRadius="12px",i.style.width=c,i.style.height=d,t||(i.style.top=x,i.style.left=w)),e.onMaximizeChange?.(f,i)}let k=!1,C="",$="";const D=220;function S(v){k=v,b.innerHTML=k?F.uncollapse:F.collapse,b.setAttribute("aria-label",k?"Show contents":"Collapse"),M.style.display=k?"none":"block",k?(C=i.style.height,$=i.style.width,i.style.minHeight="0",i.style.height="auto",i.style.minWidth="0",i.style.width=`${D}px`,u.disabled=!0,u.style.opacity="0.4",u.style.cursor="default",z.style.display="none"):(i.style.minHeight="240px",i.style.height=C||d,i.style.minWidth="320px",i.style.width=$||c,u.disabled=!1,u.style.opacity="1",u.style.cursor="pointer",z.style.display="flex")}function y(){const v=n.body.style.userSelect;return n.body.style.userSelect="none",()=>{n.body.style.userSelect=v}}t||(a.style.cursor="move",a.addEventListener("pointerdown",v=>{if(f||v.target.closest('button, [role="button"]'))return;v.preventDefault();const T=y(),H=v.clientX,O=v.clientY,I=i.offsetTop,R=i.offsetLeft,Q=o.innerHeight-a.offsetHeight,j=o.innerWidth-40,N=40-i.offsetWidth;a.setPointerCapture(v.pointerId);const V=K=>{const ie=Math.min(Math.max(I+(K.clientY-O),0),Q),Ee=Math.min(Math.max(R+(K.clientX-H),N),j);i.style.top=`${ie}px`,i.style.left=`${Ee}px`},q=K=>{T(),a.releasePointerCapture(K.pointerId),a.removeEventListener("pointermove",V),a.removeEventListener("pointerup",q)};a.addEventListener("pointermove",V),a.addEventListener("pointerup",q)}));const B='button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"]),[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';function X(v){const T=Array.from(i.querySelectorAll(B)).filter(R=>R.offsetParent!==null||R===n.activeElement);if(T.length===0){v.preventDefault(),i.focus();return}const H=T[0],O=T[T.length-1],I=n.activeElement;v.shiftKey&&(I===H||!i.contains(I))?(v.preventDefault(),O.focus()):!v.shiftKey&&I===O&&(v.preventDefault(),H.focus())}const P=v=>{if(v.key==="Escape"){W();return}if(t&&(v.key==="e"||v.key==="E")){W();return}if(t&&v.key==="Tab"){X(v);return}(v.key==="f"||v.key==="F")&&!k&&A(!f)};function W(){t?n.removeEventListener("keydown",P):i.removeEventListener("keydown",P),oe.remove(),ye(),hideTooltip(n),reparentTooltip(n.body),s?s.remove():i.remove(),t&&(n.body.style.overflow=r),m?.focus?.(),e.onClose()}function Z(){t||(i.style.zIndex=String(me()))}const z=n.createElement("div");Object.assign(z.style,{flex:"1",minHeight:"0",minWidth:"0",display:"flex",overflow:"hidden"});const M=n.createElement("div");M.tabIndex=0,M.setAttribute("role","separator"),M.setAttribute("aria-label","Resize window (arrow keys, or drag)"),Object.assign(M.style,{position:"absolute",right:"0",bottom:"0",width:"16px",height:"16px",cursor:"nwse-resize",touchAction:"none"}),M.innerHTML='<svg viewBox="0 0 16 16" width="16" height="16" style="display:block"><path d="M15 15 L15 9 M15 15 L9 15 M15 15 L15 3 M15 15 L3 15" stroke="currentColor" stroke-width="1" opacity="0.35" fill="none"/></svg>',M.style.color=CLR.label;const L=320,Y=240,_=20;function ee(v,T){const H=o.innerWidth-i.offsetLeft,O=o.innerHeight-i.offsetTop,I=Math.min(Math.max(i.offsetWidth+v,L),H),R=Math.min(Math.max(i.offsetHeight+T,Y),O);i.style.width=`${I}px`,i.style.height=`${R}px`}M.addEventListener("keydown",v=>{if(!(f||k))switch(v.key){case"ArrowRight":v.preventDefault(),ee(_,0);break;case"ArrowLeft":v.preventDefault(),ee(-_,0);break;case"ArrowDown":v.preventDefault(),ee(0,_);break;case"ArrowUp":v.preventDefault(),ee(0,-_);break}}),M.addEventListener("pointerdown",v=>{if(f||k)return;v.preventDefault();const T=y(),H=v.clientX,O=v.clientY,I=i.offsetWidth,R=i.offsetHeight,Q=o.innerWidth-i.offsetLeft,j=o.innerHeight-i.offsetTop;M.setPointerCapture(v.pointerId);const N=q=>{const K=Math.min(Math.max(I+(q.clientX-H),L),Q),ie=Math.min(Math.max(R+(q.clientY-O),Y),j);i.style.width=`${K}px`,i.style.height=`${ie}px`},V=q=>{T(),M.releasePointerCapture(q.pointerId),M.removeEventListener("pointermove",N),M.removeEventListener("pointerup",V)};M.addEventListener("pointermove",N),M.addEventListener("pointerup",V)}),i.appendChild(a),i.appendChild(z),i.appendChild(M);const ne=e.anchor?overlayRootFor(e.anchor):n.body;s?(s.appendChild(i),ne.appendChild(s)):ne.appendChild(i);const ye=Ue(n,ne),oe=n.createElement("style");oe.textContent=`@media print{
2
2
  body{overflow:visible!important;height:auto!important}
3
3
  body>*:not(.wmap-overlay-box):not(#wmap-modal-backdrop):not(.wmap-overlay-ancestor){display:none!important}
4
4
  #wmap-modal-backdrop{position:static!important;background:none!important;backdrop-filter:none!important;display:block!important}
@@ -6,4 +6,4 @@ body>*:not(.wmap-overlay-box):not(#wmap-modal-backdrop):not(.wmap-overlay-ancest
6
6
  .wmap-overlay-box>div:first-child{display:none!important}
7
7
  .wmap-overlay-box>div:nth-child(2){display:block!important;overflow:visible!important;height:auto!important;flex:none!important;min-height:0!important;min-width:0!important}
8
8
  .wmap-overlay-box>div:nth-child(3){display:none!important}
9
- }`,n.head.appendChild(te),reparentTooltip(i),t?(l.addEventListener("click",v=>{v.target===l&&I()}),n.addEventListener("keydown",z)):(i.addEventListener("keydown",z),i.addEventListener("mousedown",Y),Y()),nextFrame(()=>(m.isConnected?m:i).focus(),o);function ye(v){d=v,!u&&!E&&(i.style.height=v)}return{backdrop:l,box:i,contentWrap:$,close:I,bringToFront:Y,setNaturalHeight:ye}}export function openModal(e){return me({...e,mode:"modal"})}export function openFloatingWindow(e){return me({...e,mode:"window"})}const le=new WeakSet;export function openReparentedModal(e,t={}){if(e.length===0||e.some(r=>le.has(r)))return null;const n=e.map(r=>({el:r,parent:r.parentElement,next:r.nextSibling})),o=openModal({ownerDocument:t.ownerDocument,title:t.title,boxSize:t.boxSize,anchor:t.anchor??e[0],onClose:()=>{for(const r of n){if(le.delete(r.el),!r.parent)continue;const l=r.next&&r.next.parentNode===r.parent?r.next:null;r.parent.insertBefore(r.el,l)}t.onClosed?.()}});for(const r of n)le.add(r.el),o.contentWrap.appendChild(r.el);return o}export function makePaletteBtn(e,t,n,o){const r=e.makeCheckMenuBtn("palette","Colour scheme",()=>{const p=t(),i=[];if(p.plotMode==="hardBin"||p.plotMode==="softBin"){const b=p.binColorScheme??"default";i.push({section:"Bin colours"});for(const d of Ae())i.push({label:d.label,active:b===d.name,onClick:()=>o({binColorScheme:d.name})});if(n()){const d=p.useDefinedBinColors??!0;i.push({section:"Bin definitions"}),i.push({label:"Use colours from bin definitions",active:d,onClick:()=>o({useDefinedBinColors:!d})})}}else{const b=p.valueColorScheme??"default";i.push({section:"Value colours"});for(const a of Me())i.push({label:a.label,active:b===a.name,onClick:()=>o({valueColorScheme:a.name})});const d=p.reverseValueScheme??!1;i.push({section:"Direction"}),i.push({label:"Reverse gradient",active:d,onClick:()=>o({reverseValueScheme:!d})})}return i},()=>{});function l(){r.style.display=t().plotMode==="metadata"?"none":""}return{btn:r,sync:l}}export function requestedPassFailDisplay(e){return e.passFailDisplay??"off"}export function overlayMenuRows(e,t,n,o){return[{label:"Ring boundaries",active:!!e.showRingBoundaries,onClick:()=>o({showRingBoundaries:!e.showRingBoundaries})},{label:"Quadrant lines",active:!!e.showQuadrantBoundaries,onClick:()=>o({showQuadrantBoundaries:!e.showQuadrantBoundaries})},{label:"Die labels",active:!!e.showDieLabels,onClick:()=>o({showDieLabels:!e.showDieLabels})},{label:"Reticle grid",active:!!e.showReticle,enabled:t,onClick:()=>o({showReticle:!e.showReticle})},{label:"XY indicator",active:!!e.showXYIndicator,onClick:()=>o({showXYIndicator:!e.showXYIndicator})},...passFailMenuRows({...n,display:requestedPassFailDisplay(e)},r=>o({passFailDisplay:r})),{label:"Mark failing dies",active:!!e.markFailingDies,enabled:n.binMode,disabledHint:n.binMode?void 0:"Available on hard/soft bin maps",onClick:()=>o({markFailingDies:!e.markFailingDies})},{section:""},{label:"Clear overlays",active:!1,action:!0,enabled:anyOverlayActive(e),disabledHint:"No overlays are active",onClick:()=>o({showRingBoundaries:!1,showQuadrantBoundaries:!1,showDieLabels:!1,showReticle:!1,showXYIndicator:!1,passFailDisplay:"off",markFailingDies:!1})}]}export function anyOverlayActive(e){return!!(e.showRingBoundaries||e.showQuadrantBoundaries||e.showDieLabels||e.showReticle||e.showXYIndicator||e.markFailingDies||requestedPassFailDisplay(e)!=="off")}export function passFailMenuRows(e,t){if(e.functionalActive)return[];const n=[];return e.hasLimits&&n.push({label:"Limit pass/fail",active:e.display==="spec",onClick:()=>t(e.display==="spec"?"off":"spec")}),e.hasRecorded&&n.push({label:"Test pass/fail",active:e.display==="test",onClick:()=>t(e.display==="test"?"off":"test")}),n}export function makeLogScaleBtn(e,t,n){const o=e.makeBtn("logScale","Toggle log scale",()=>{n({logScale:!t().logScale})});function r(){const l=t(),p=l.plotMode,i=p==="value"||p==="stackedValues";o.style.display=i&&requestedPassFailDisplay(l)==="off"&&!l.functionalActive?"":"none",e.setActive(o,!!l.logScale)}return{btn:o,sync:r}}const Fe=[{value:"default",label:"Default (right)"},{value:"compact",label:"Compact (right)"},{value:"left",label:"Left"},{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"floating",label:"Floating"}];export function makeLegendStyleBtn(e,t,n,o){const r=e.makeCheckMenuBtn("legend","Legend style",()=>{const p=t().legendPosition??"default",i=[];let b=!0;if(o){const d=o.blockedReason();b=d?!0:o.get(),i.push({label:"Legend on each map",active:b,enabled:!d,disabledHint:d??void 0,onClick:()=>o.set(!o.get())})}if(be(t().plotMode)){o&&i.push({section:"Position on each map"});for(const d of Fe)i.push({label:d.label,active:b&&p===d.value,enabled:b,disabledHint:b?void 0:'Turn on "Legend on each map" to position it',onClick:()=>n(d.value)})}return i},()=>{});function l(){r.style.display=o||be(t().plotMode)?"":"none"}return{btn:r,sync:l}}function be(e){return e==="hardBin"||e==="softBin"||e==="metadata"}export function makeOverlaysBtn(e,t,n){return e.makeCheckMenuBtn("overlays","Overlays",()=>t(),o=>e.setActive(o,n()))}export function makeOrientationBtn(e,t,n){return e.makeCheckMenuBtn("orient","Orientation",()=>[{section:"Rotate"},{label:"Rotate 90\xB0 clockwise",active:!1,onClick:()=>{const o=t().rotation??0;n({rotation:ROTATIONS[(ROTATIONS.indexOf(o)+1)%4]})}},{section:"Flip"},{label:"Flip horizontal",active:!!t().flipX,onClick:()=>n({flipX:!t().flipX})},{label:"Flip vertical",active:!!t().flipY,onClick:()=>n({flipY:!t().flipY})},{section:""},{label:"Reset orientation",active:!1,action:!0,enabled:!!(t().rotation||t().flipX||t().flipY),disabledHint:"Already in the original orientation",onClick:()=>n({rotation:0,flipX:!1,flipY:!1})}],o=>{const{rotation:r,flipX:l,flipY:p}=t();e.setActive(o,!!(r||l||p))})}let j=null;const he=40,je=he+8;function Ve(e,t){const n=e.createElement("div");n.classList.add("wmap-guide-search"),n.style.cssText="display:flex;align-items:center;gap:2px;margin-left:10px;flex:1;min-width:80px;max-width:260px;";const o=e.createElement("input");o.type="text",o.placeholder="Search guide\u2026",o.setAttribute("aria-label","Search guide"),o.style.cssText=`flex:1;min-width:0;padding:4px 8px;font-size:12px;background:${CLR.menuBg};color:${CLR.text};border:1px solid ${CLR.menuBorder};border-radius:${RADIUS.control};outline:none;`,o.addEventListener("focus",()=>{o.style.borderColor=CLR.iconActive}),o.addEventListener("blur",()=>{o.style.borderColor=CLR.menuBorder});const r=e.createElement("span");r.setAttribute("role","status"),r.setAttribute("aria-live","polite"),r.style.cssText=`font-size:12px;color:${CLR.label};min-width:44px;text-align:center;flex-shrink:0;white-space:nowrap;`;function l(x,c){const m=e.createElement("button");return m.type="button",m.textContent=x,m.setAttribute("aria-label",c),m.disabled=!0,m.style.cssText=`border:none;background:none;cursor:pointer;padding:4px 6px;border-radius:${RADIUS.control};font-size:12px;color:${CLR.label};flex-shrink:0;opacity:0.4;`,m.addEventListener("mouseenter",()=>{m.disabled||(m.style.background=CLR.bgHover)}),m.addEventListener("mouseleave",()=>{m.style.background="none"}),m}const p=l("\u25B2","Previous match"),i=l("\u25BC","Next match");let b=[],d=-1;function a(){const x=b.length===0;p.disabled=x,i.disabled=x,p.style.opacity=x?"0.4":"",i.style.opacity=x?"0.4":""}function y(){for(const x of b)x.parentNode?.replaceChild(e.createTextNode(x.textContent??""),x);t.normalize(),b=[],d=-1}function s(x){if(b.length===0)return;d>=0&&(b[d].style.outline="none"),d=(x%b.length+b.length)%b.length;const c=b[d];c.style.outline=`2px solid ${CLR.iconActive}`,c.style.outlineOffset="1px",c.scrollIntoView({behavior:"smooth",block:"center"}),r.textContent=`${d+1}/${b.length}`}function f(x){y();const c=x.trim();if(!c){r.textContent="",a();return}const m=c.toLowerCase(),u=e.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(A){const E=A.parentElement;return!E||E.closest("script,style,.wmap-guide-toc")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),h=[];let w;for(;w=u.nextNode();)h.push(w);for(const A of h){const E=A.textContent??"",C=E.toLowerCase();if(!C.includes(m))continue;const T=e.createDocumentFragment();let D=0,S=C.indexOf(m);for(;S!==-1;){S>D&&T.appendChild(e.createTextNode(E.slice(D,S)));const g=e.createElement("mark");g.textContent=E.slice(S,S+c.length),T.appendChild(g),b.push(g),D=S+c.length,S=C.indexOf(m,D)}D<E.length&&T.appendChild(e.createTextNode(E.slice(D))),A.parentNode?.replaceChild(T,A)}a(),b.length===0?r.textContent="No matches":s(0)}return o.addEventListener("input",()=>f(o.value)),o.addEventListener("keydown",x=>{x.key==="Enter"?(x.preventDefault(),s(d+(x.shiftKey?-1:1))):x.key==="Escape"&&(o.value?(o.value="",f("")):o.blur())}),p.addEventListener("click",()=>s(d-1)),i.addEventListener("click",()=>s(d+1)),n.append(o,r,p,i),n}function Ue(e,t,n){const o=[...t.querySelectorAll("h2[id]")];if(o.length<2)return;for(const c of t.querySelectorAll("h1[id],h2[id],h3[id],h4[id]"))c.style.scrollMarginTop=`${je}px`;const r=e.createElement("div");r.classList.add("wmap-guide-toc"),r.style.cssText=`position:sticky;top:0;z-index:2;background:${CLR.menuBg};border-bottom:1px solid ${CLR.menuBorder};font-family:system-ui,-apple-system,"Segoe UI",sans-serif;`;const l=e.createElement("div");l.style.cssText=`display:flex;align-items:center;gap:4px;height:${he}px;padding:0 12px;box-sizing:border-box;`;const p=e.createElement("span");p.innerHTML='<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>',p.style.cssText=`display:inline-flex;transition:transform ${MOTION.base};flex-shrink:0;`;const i=e.createElement("button");i.type="button";const b="wmap-guide-toc-panel";i.setAttribute("aria-expanded","false"),i.setAttribute("aria-controls",b),i.style.cssText=`display:flex;align-items:center;gap:6px;border:none;background:none;cursor:pointer;padding:6px 8px;margin:0 -8px 0 -8px;border-radius:${RADIUS.control};font-size:13px;font-weight:600;color:${CLR.text};`;const d=e.createElement("span");d.textContent=`Contents (${o.length})`,i.append(p,d),i.addEventListener("mouseenter",()=>{i.style.background=CLR.bgHover}),i.addEventListener("mouseleave",()=>{i.style.background="none"});const a=e.createElement("button");a.type="button",a.textContent="\u2191 Top",a.style.cssText=`margin-left:auto;border:none;background:none;cursor:pointer;padding:6px 8px;border-radius:${RADIUS.control};font-size:12px;color:${CLR.label};`,a.addEventListener("mouseenter",()=>{a.style.background=CLR.bgHover}),a.addEventListener("mouseleave",()=>{a.style.background="none"}),a.addEventListener("click",()=>{x.close(),t.scrollTo({top:0,behavior:"smooth"})}),n?l.append(i,Ve(e,t),a):l.append(i,a);const y=e.createElement("div");y.id=b,y.hidden=!0,y.style.cssText="padding:2px 12px 12px;max-height:min(60vh,440px);overflow-y:auto;";const s=/^\s*\d+(?:\.\d+)*\.\s+/;for(const c of t.querySelectorAll("h2[id],h3[id],h4[id]")){const m=c.firstChild;m?.nodeType===Node.TEXT_NODE&&(m.textContent=(m.textContent??"").replace(s,""))}const f=e.createElement("ul");f.setAttribute("role","list"),f.style.cssText="list-style:none;margin:0;padding:0;columns:200px;column-gap:24px;";for(const c of o){const m=e.createElement("li");m.style.cssText="break-inside:avoid;";const u=e.createElement("a");u.href=`#${c.id}`,u.textContent=c.textContent??"",u.style.cssText=`display:block;padding:4px 6px;margin:0 -6px;border-radius:${RADIUS.control};font-size:12.5px;color:${CLR.iconActive};text-decoration:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;`,u.addEventListener("mouseenter",()=>{u.style.background=CLR.bgHover}),u.addEventListener("mouseleave",()=>{u.style.background="none"}),u.addEventListener("click",h=>{h.preventDefault(),x.close(),c.scrollIntoView({behavior:"smooth",block:"start"})}),m.appendChild(u),f.appendChild(m)}y.appendChild(f);const x=wireExpandToggle(i,c=>{y.hidden=!c,i.setAttribute("aria-expanded",String(c)),p.style.transform=c?"rotate(180deg)":"none"});r.append(l,y),t.prepend(r)}function xe(e,t,n,o,r){const l=t,p=l.__wmapDemoApi;l.__wmapDemoApi=o;const i=e.createElement("div");return i.classList.add("wmap-guide-content"),i.innerHTML=n,Ue(e,i,r),{content:i,restoreApi:()=>{l.__wmapDemoApi===o&&(l.__wmapDemoApi=p)}}}function ve(e,t){const n=t,o=e.querySelector("script");if(o){const r=e.ownerDocument.createElement("script");r.textContent=o.textContent,e.appendChild(r);const l=e.querySelector(".wmap-guide");return l&&n.__wmapPopulateGuideDemos?.(l),n.__wmapDestroyGuideDemos}}function Ge(e,t,n,o){const r=o?.ownerDocument??document,l=r.defaultView??window,{content:p,restoreApi:i}=xe(r,l,t,n,!0);Object.assign(p.style,{flex:"1",overflow:"auto",minHeight:"0",minWidth:"0"});let b;const d=openFloatingWindow({title:e,anchor:o,ownerDocument:r,printable:!0,onMaximizeChange:a=>{p.style.setProperty("--wmap-guide-reading-width",a?"1000px":"720px")},onClose:()=>{j===d&&(j=null),b?.(),i()}});return d.contentWrap.appendChild(p),b=ve(p,l),d}function Xe(e,t,n,o){const r=e.document;r.title=t,Object.assign(r.documentElement.style,{height:"100%"}),Object.assign(r.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:FONT.family}),copyWmapThemeTokens(document.documentElement,r.documentElement);const l=syncWmapPopupTheme(document.documentElement,r.documentElement),{content:p,restoreApi:i}=xe(r,e,n,o,!1);Object.assign(p.style,{flex:"1",overflow:"auto",minHeight:"0",minWidth:"0"}),r.body.appendChild(p);const b=ve(p,e);let d=!1;const a=()=>{if(!d){d=!0,clearInterval(y),l();try{b?.()}catch{}i(),j===s&&(j=null)}},y=setInterval(()=>{e.closed&&a()},400);e.addEventListener("pagehide",a);const s={close:()=>{e.closed||e.close(),a()}};return s}export function openUserGuideWindow(e,t,n,o){j&&(j.close(),j=null);const r=n?.title??"Wafer Map \u2014 User Guide",l=(n?.html??"")+t,i=(o?.ownerDocument.defaultView??window).open("","_blank","width=800,height=820");j=i?Xe(i,r,l,e):Ge(r,l,e,o)}export function openWaferMapGuide(e,t){Promise.all([import("./userGuideHtml.js"),import("./renderWaferMap.js"),import("./renderWaferGallery.js")]).then(([n,o,r])=>{openUserGuideWindow({buildWaferMap:Te,renderWaferMap:o.renderWaferMap,renderWaferGallery:r.renderWaferGallery,analyzeWaferMap:He},n.USER_GUIDE_HTML,e,t)})}export function openReportModal(e,t){const n=t?.ownerDocument??document,o=n.createElement("iframe");o.srcdoc=e,o.title="Summary report",Object.assign(o.style,{border:"0",width:"100%",flex:"1",minHeight:"0",background:"#fff"});const r=n.createElement("div");Object.assign(r.style,{display:"flex",justifyContent:"flex-end",padding:"6px 14px",borderBottom:`1px solid ${CLR.menuBorder}`,flexShrink:"0"});const l=n.createElement("button");l.type="button",wireControlHover(l,"bare"),l.textContent="Open as full page \u2197",Object.assign(l.style,{border:"none",background:"none",color:CLR.iconActive,cursor:"pointer",fontSize:FONT.body,textDecoration:"underline",padding:"0"}),l.addEventListener("click",()=>De(e)),r.appendChild(l);const p=openModal({title:"Summary report",anchor:t?.anchor,ownerDocument:n,printable:()=>o.contentWindow?.print(),onClose:()=>{}});return p.contentWrap.style.flexDirection="column",p.contentWrap.appendChild(r),p.contentWrap.appendChild(o),p}
9
+ }`,n.head.appendChild(oe),reparentTooltip(i),t?(s.addEventListener("click",v=>{v.target===s&&W()}),n.addEventListener("keydown",P)):(i.addEventListener("keydown",P),i.addEventListener("mousedown",Z),Z()),nextFrame(()=>(p.isConnected?p:i).focus(),o);function we(v){d=v,!f&&!k&&(i.style.height=v)}function ke(v){const T=()=>{};if(f||k||!(v>0))return T;const H=i.getBoundingClientRect(),O=Math.min(H.width+v,o.innerWidth*.96);if(!(O>H.width+.5))return T;const I=i.style.width,R=c,Q=i.style.left,j=`${Math.round(O)}px`;i.style.width=j,c=j;let N=null;if(!t){const V=H.left+O-o.innerWidth;V>0&&(N=`${Math.max(0,Math.round(H.left-V-8))}px`,i.style.left=N)}return()=>{i.style.width===j&&!f&&!k&&(i.style.width=I),c===j&&(c=R),N!==null&&i.style.left===N&&(i.style.left=Q)}}return{backdrop:s,box:i,contentWrap:z,close:W,bringToFront:Z,setNaturalHeight:we,reserveWidth:ke}}export function openModal(e){return be({...e,mode:"modal"})}export function openFloatingWindow(e){return be({...e,mode:"window"})}const le=new WeakSet;export function openReparentedModal(e,t={}){if(e.length===0||e.some(r=>le.has(r)))return null;const n=e.map(r=>({el:r,parent:r.parentElement,next:r.nextSibling})),o=openModal({ownerDocument:t.ownerDocument,title:t.title,boxSize:t.boxSize,anchor:t.anchor??e[0],onClose:()=>{for(const r of n){if(le.delete(r.el),!r.parent)continue;const s=r.next&&r.next.parentNode===r.parent?r.next:null;r.parent.insertBefore(r.el,s)}t.onClosed?.()}});for(const r of n)le.add(r.el),o.contentWrap.appendChild(r.el);return o}export function makePaletteBtn(e,t,n,o){const r=e.makeCheckMenuBtn("palette","Colour scheme",()=>{const m=t(),i=[];if(m.plotMode==="hardBin"||m.plotMode==="softBin"){const c=m.binColorScheme??"default";i.push({section:"Bin colours"});for(const d of Te())i.push({label:d.label,active:c===d.name,onClick:()=>o({binColorScheme:d.name})});if(n()){const d=m.useDefinedBinColors??!0;i.push({section:"Bin definitions"}),i.push({label:"Use colours from bin definitions",active:d,onClick:()=>o({useDefinedBinColors:!d})})}}else{const c=m.valueColorScheme??"default";i.push({section:"Value colours"});for(const a of He())i.push({label:a.label,active:c===a.name,onClick:()=>o({valueColorScheme:a.name})});const d=m.reverseValueScheme??!1;i.push({section:"Direction"}),i.push({label:"Reverse gradient",active:d,onClick:()=>o({reverseValueScheme:!d})})}return i},()=>{});function s(){r.style.display=t().plotMode==="metadata"?"none":""}return{btn:r,sync:s}}export function requestedPassFailDisplay(e){return e.passFailDisplay??"off"}export function overlayMenuRows(e,t,n,o,r){const s=r?.on?{enabled:!1,disabledHint:"Not drawn in the compact layout"}:void 0;return[...r?[{label:"Compact layout",active:r.on,enabled:r.offered||r.on,disabledHint:"Needs a repeating multi-project layout",onClick:()=>r.onChange(!r.on)},{label:"Layout diagnostics",active:!1,action:!0,closeMenu:!0,onClick:()=>r.onDiagnostics()},{section:""}]:[],{label:"Ring boundaries",active:!!e.showRingBoundaries,...s,onClick:()=>o({showRingBoundaries:!e.showRingBoundaries})},{label:"Quadrant lines",active:!!e.showQuadrantBoundaries,...s,onClick:()=>o({showQuadrantBoundaries:!e.showQuadrantBoundaries})},{label:"Die labels",active:!!e.showDieLabels,onClick:()=>o({showDieLabels:!e.showDieLabels})},{label:"Reticle grid",active:!!e.showReticle,enabled:r?.on?!1:t,...s?{disabledHint:s.disabledHint}:{},onClick:()=>o({showReticle:!e.showReticle})},{label:"XY indicator",active:!!e.showXYIndicator,onClick:()=>o({showXYIndicator:!e.showXYIndicator})},{label:"Axis labels",active:!!e.showAxes,onClick:()=>o({showAxes:!e.showAxes})},...passFailMenuRows({...n,display:requestedPassFailDisplay(e)},m=>o({passFailDisplay:m})),{label:"Mark failing dies",active:!!e.markFailingDies,enabled:n.binMode,disabledHint:n.binMode?void 0:"Available on hard/soft bin maps",onClick:()=>o({markFailingDies:!e.markFailingDies})},{section:""},{label:"Clear overlays",active:!1,action:!0,enabled:anyOverlayActive(e),disabledHint:"No overlays are active",onClick:()=>o({showRingBoundaries:!1,showQuadrantBoundaries:!1,showDieLabels:!1,showReticle:!1,showXYIndicator:!1,showAxes:void 0,passFailDisplay:"off",markFailingDies:!1})}]}export function anyOverlayActive(e){return!!(e.showRingBoundaries||e.showQuadrantBoundaries||e.showDieLabels||e.showReticle||e.showXYIndicator||e.showAxes===!0||e.markFailingDies||requestedPassFailDisplay(e)!=="off")}export function passFailMenuRows(e,t){if(e.functionalActive)return[];const n=[];return e.hasLimits&&n.push({label:"Limit pass/fail",active:e.display==="spec",onClick:()=>t(e.display==="spec"?"off":"spec")}),e.hasRecorded&&n.push({label:"Test pass/fail",active:e.display==="test",onClick:()=>t(e.display==="test"?"off":"test")}),n}export function makeLogScaleBtn(e,t,n){const o=e.makeBtn("logScale","Toggle log scale",()=>{n({logScale:!t().logScale})});function r(){const s=t(),m=s.plotMode,i=m==="value"||m==="stackedValues";o.style.display=i&&requestedPassFailDisplay(s)==="off"&&!s.functionalActive?"":"none",e.setActive(o,!!s.logScale)}return{btn:o,sync:r}}const Ge=[{value:"default",label:"Default (right)"},{value:"compact",label:"Compact (right)"},{value:"left",label:"Left"},{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"floating",label:"Floating"}];export function makeLegendStyleBtn(e,t,n,o){const r=e.makeCheckMenuBtn("legend","Legend style",()=>{const m=t().legendPosition??"default",i=[];let c=!0;if(o){const d=o.blockedReason();c=d?!0:o.get(),i.push({label:"Legend on each map",active:c,enabled:!d,disabledHint:d??void 0,onClick:()=>o.set(!o.get())})}if(he(t().plotMode)){o&&i.push({section:"Position on each map"});for(const d of Ge)i.push({label:d.label,active:c&&m===d.value,enabled:c,disabledHint:c?void 0:'Turn on "Legend on each map" to position it',onClick:()=>n(d.value)})}return i},()=>{});function s(){r.style.display=o||he(t().plotMode)?"":"none"}return{btn:r,sync:s}}function he(e){return e==="hardBin"||e==="softBin"||e==="metadata"}export function makeOverlaysBtn(e,t,n){return e.makeCheckMenuBtn("overlays","Overlays",()=>t(),o=>e.setActive(o,n()))}export function makeOrientationBtn(e,t,n){const o=r=>n({...r,showXYIndicator:!0});return e.makeCheckMenuBtn("orient","Orientation",()=>[{section:"Rotate"},{label:"Rotate 90\xB0 clockwise",active:!1,onClick:()=>{const r=t().rotation??0;o({rotation:ROTATIONS[(ROTATIONS.indexOf(r)+1)%4]})}},{section:"Flip"},{label:"Flip horizontal",active:!!t().flipX,onClick:()=>o({flipX:!t().flipX})},{label:"Flip vertical",active:!!t().flipY,onClick:()=>o({flipY:!t().flipY})},{section:""},{label:"Reset orientation",active:!1,action:!0,enabled:!!(t().rotation||t().flipX||t().flipY),disabledHint:"Already in the original orientation",onClick:()=>n({rotation:0,flipX:!1,flipY:!1})}],r=>{const{rotation:s,flipX:m,flipY:i}=t();e.setActive(r,!!(s||m||i))})}let G=null;const xe=40,Xe=xe+8;function Ye(e,t){const n=e.createElement("div");n.classList.add("wmap-guide-search"),n.style.cssText="display:flex;align-items:center;gap:2px;margin-left:10px;flex:1;min-width:80px;max-width:260px;";const o=e.createElement("input");o.type="text",o.placeholder="Search guide\u2026",o.setAttribute("aria-label","Search guide"),o.style.cssText=`flex:1;min-width:0;padding:4px 8px;font-size:12px;background:${CLR.menuBg};color:${CLR.text};border:1px solid ${CLR.menuBorder};border-radius:${RADIUS.control};outline:none;`,o.addEventListener("focus",()=>{o.style.borderColor=CLR.iconActive}),o.addEventListener("blur",()=>{o.style.borderColor=CLR.menuBorder});const r=e.createElement("span");r.setAttribute("role","status"),r.setAttribute("aria-live","polite"),r.style.cssText=`font-size:12px;color:${CLR.label};min-width:44px;text-align:center;flex-shrink:0;white-space:nowrap;`;function s(h,u){const p=e.createElement("button");return p.type="button",p.textContent=h,p.setAttribute("aria-label",u),p.disabled=!0,p.style.cssText=`border:none;background:none;cursor:pointer;padding:4px 6px;border-radius:${RADIUS.control};font-size:12px;color:${CLR.label};flex-shrink:0;opacity:0.4;`,p.addEventListener("mouseenter",()=>{p.disabled||(p.style.background=CLR.bgHover)}),p.addEventListener("mouseleave",()=>{p.style.background="none"}),p}const m=s("\u25B2","Previous match"),i=s("\u25BC","Next match");let c=[],d=-1;function a(){const h=c.length===0;m.disabled=h,i.disabled=h,m.style.opacity=h?"0.4":"",i.style.opacity=h?"0.4":""}function g(){for(const h of c)h.parentNode?.replaceChild(e.createTextNode(h.textContent??""),h);t.normalize(),c=[],d=-1}function l(h){if(c.length===0)return;d>=0&&(c[d].style.outline="none"),d=(h%c.length+c.length)%c.length;const u=c[d];u.style.outline=`2px solid ${CLR.iconActive}`,u.style.outlineOffset="1px",u.scrollIntoView({behavior:"smooth",block:"center"}),r.textContent=`${d+1}/${c.length}`}function b(h){g();const u=h.trim();if(!u){r.textContent="",a();return}const p=u.toLowerCase(),f=e.createTreeWalker(t,NodeFilter.SHOW_TEXT,{acceptNode(A){const k=A.parentElement;return!k||k.closest("script,style,.wmap-guide-toc")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),x=[];let w;for(;w=f.nextNode();)x.push(w);for(const A of x){const k=A.textContent??"",C=k.toLowerCase();if(!C.includes(p))continue;const $=e.createDocumentFragment();let D=0,S=C.indexOf(p);for(;S!==-1;){S>D&&$.appendChild(e.createTextNode(k.slice(D,S)));const y=e.createElement("mark");y.textContent=k.slice(S,S+u.length),$.appendChild(y),c.push(y),D=S+u.length,S=C.indexOf(p,D)}D<k.length&&$.appendChild(e.createTextNode(k.slice(D))),A.parentNode?.replaceChild($,A)}a(),c.length===0?r.textContent="No matches":l(0)}return o.addEventListener("input",()=>b(o.value)),o.addEventListener("keydown",h=>{h.key==="Enter"?(h.preventDefault(),l(d+(h.shiftKey?-1:1))):h.key==="Escape"&&(o.value?(o.value="",b("")):o.blur())}),m.addEventListener("click",()=>l(d-1)),i.addEventListener("click",()=>l(d+1)),n.append(o,r,m,i),n}function qe(e,t,n){const o=[...t.querySelectorAll("h2[id]")];if(o.length<2)return;for(const u of t.querySelectorAll("h1[id],h2[id],h3[id],h4[id]"))u.style.scrollMarginTop=`${Xe}px`;const r=e.createElement("div");r.classList.add("wmap-guide-toc"),r.style.cssText=`position:sticky;top:0;z-index:2;background:${CLR.menuBg};border-bottom:1px solid ${CLR.menuBorder};font-family:system-ui,-apple-system,"Segoe UI",sans-serif;`;const s=e.createElement("div");s.style.cssText=`display:flex;align-items:center;gap:4px;height:${xe}px;padding:0 12px;box-sizing:border-box;`;const m=e.createElement("span");m.innerHTML='<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>',m.style.cssText=`display:inline-flex;transition:transform ${MOTION.base};flex-shrink:0;`;const i=e.createElement("button");i.type="button";const c="wmap-guide-toc-panel";i.setAttribute("aria-expanded","false"),i.setAttribute("aria-controls",c),i.style.cssText=`display:flex;align-items:center;gap:6px;border:none;background:none;cursor:pointer;padding:6px 8px;margin:0 -8px 0 -8px;border-radius:${RADIUS.control};font-size:13px;font-weight:600;color:${CLR.text};`;const d=e.createElement("span");d.textContent=`Contents (${o.length})`,i.append(m,d),i.addEventListener("mouseenter",()=>{i.style.background=CLR.bgHover}),i.addEventListener("mouseleave",()=>{i.style.background="none"});const a=e.createElement("button");a.type="button",a.textContent="\u2191 Top",a.style.cssText=`margin-left:auto;border:none;background:none;cursor:pointer;padding:6px 8px;border-radius:${RADIUS.control};font-size:12px;color:${CLR.label};`,a.addEventListener("mouseenter",()=>{a.style.background=CLR.bgHover}),a.addEventListener("mouseleave",()=>{a.style.background="none"}),a.addEventListener("click",()=>{h.close(),t.scrollTo({top:0,behavior:"smooth"})}),n?s.append(i,Ye(e,t),a):s.append(i,a);const g=e.createElement("div");g.id=c,g.hidden=!0,g.style.cssText="padding:2px 12px 12px;max-height:min(60vh,440px);overflow-y:auto;";const l=/^\s*\d+(?:\.\d+)*\.\s+/;for(const u of t.querySelectorAll("h2[id],h3[id],h4[id]")){const p=u.firstChild;p?.nodeType===Node.TEXT_NODE&&(p.textContent=(p.textContent??"").replace(l,""))}const b=e.createElement("ul");b.setAttribute("role","list"),b.style.cssText="list-style:none;margin:0;padding:0;columns:200px;column-gap:24px;";for(const u of o){const p=e.createElement("li");p.style.cssText="break-inside:avoid;";const f=e.createElement("a");f.href=`#${u.id}`,f.textContent=u.textContent??"",f.style.cssText=`display:block;padding:4px 6px;margin:0 -6px;border-radius:${RADIUS.control};font-size:12.5px;color:${CLR.iconActive};text-decoration:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;`,f.addEventListener("mouseenter",()=>{f.style.background=CLR.bgHover}),f.addEventListener("mouseleave",()=>{f.style.background="none"}),f.addEventListener("click",x=>{x.preventDefault(),h.close(),u.scrollIntoView({behavior:"smooth",block:"start"})}),p.appendChild(f),b.appendChild(p)}g.appendChild(b);const h=wireExpandToggle(i,u=>{g.hidden=!u,i.setAttribute("aria-expanded",String(u)),m.style.transform=u?"rotate(180deg)":"none"});r.append(s,g),t.prepend(r)}function ve(e,t,n,o,r){const s=t,m=s.__wmapDemoApi;s.__wmapDemoApi=o;const i=e.createElement("div");return i.classList.add("wmap-guide-content"),i.innerHTML=n,qe(e,i,r),{content:i,restoreApi:()=>{s.__wmapDemoApi===o&&(s.__wmapDemoApi=m)}}}function ge(e,t){const n=t,o=e.querySelector("script");if(o){const r=e.ownerDocument.createElement("script");r.textContent=o.textContent,e.appendChild(r);const s=e.querySelector(".wmap-guide");return s&&n.__wmapPopulateGuideDemos?.(s),n.__wmapDestroyGuideDemos}}function Ke(e,t,n,o){const r=o?.ownerDocument??document,s=r.defaultView??window,{content:m,restoreApi:i}=ve(r,s,t,n,!0);Object.assign(m.style,{flex:"1",overflow:"auto",minHeight:"0",minWidth:"0"});let c;const d=openFloatingWindow({title:e,anchor:o,ownerDocument:r,printable:!0,onMaximizeChange:a=>{m.style.setProperty("--wmap-guide-reading-width",a?"1000px":"720px")},onClose:()=>{G===d&&(G=null),c?.(),i()}});return d.contentWrap.appendChild(m),c=ge(m,s),d}function Ze(e,t,n,o){const r=e.document;r.title=t,Object.assign(r.documentElement.style,{height:"100%"}),Object.assign(r.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:FONT.family}),copyWmapThemeTokens(document.documentElement,r.documentElement);const s=syncWmapPopupTheme(document.documentElement,r.documentElement),{content:m,restoreApi:i}=ve(r,e,n,o,!1);Object.assign(m.style,{flex:"1",overflow:"auto",minHeight:"0",minWidth:"0"}),r.body.appendChild(m);const c=ge(m,e);let d=!1;const a=()=>{if(!d){d=!0,clearInterval(g),s();try{c?.()}catch{}i(),G===l&&(G=null)}},g=setInterval(()=>{e.closed&&a()},400);e.addEventListener("pagehide",a);const l={close:()=>{e.closed||e.close(),a()}};return l}export function openUserGuideWindow(e,t,n,o){G&&(G.close(),G=null);const r=n?.title??"Wafer Map \u2014 User Guide",s=(n?.html??"")+t,i=(o?.ownerDocument.defaultView??window).open("","_blank","width=800,height=820");G=i?Ze(i,r,s,e):Ke(r,s,e,o)}export function openWaferMapGuide(e,t){Promise.all([import("./userGuideHtml.js"),import("./renderWaferMap.js"),import("./renderWaferGallery.js")]).then(([n,o,r])=>{openUserGuideWindow({buildWaferMap:$e,renderWaferMap:o.renderWaferMap,renderWaferGallery:r.renderWaferGallery,analyzeWaferMap:Re},n.USER_GUIDE_HTML,e,t)})}export function openReportModal(e,t){const n=t?.ownerDocument??document,o=n.createElement("iframe");o.srcdoc=e,o.title="Summary report",Object.assign(o.style,{border:"0",width:"100%",flex:"1",minHeight:"0",background:"#fff"});const r=n.createElement("div");Object.assign(r.style,{display:"flex",justifyContent:"flex-end",padding:"6px 14px",borderBottom:`1px solid ${CLR.menuBorder}`,flexShrink:"0"});const s=n.createElement("button");s.type="button",wireControlHover(s,"bare"),s.textContent="Open as full page \u2197",Object.assign(s.style,{border:"none",background:"none",color:CLR.iconActive,cursor:"pointer",fontSize:FONT.body,textDecoration:"underline",padding:"0"}),s.addEventListener("click",()=>Ie(e)),r.appendChild(s);const m=n.defaultView??window,i=d=>{if(d.source!==o.contentWindow)return;const a=d.data?.wmapFinding;typeof a=="string"&&t?.onFinding?.(a,c)};t?.onFinding&&m.addEventListener("message",i);const c=openModal({title:"Summary report",anchor:t?.anchor,ownerDocument:n,printable:()=>o.contentWindow?.print(),onClose:()=>m.removeEventListener("message",i)});return c.contentWrap.style.flexDirection="column",c.contentWrap.appendChild(r),c.contentWrap.appendChild(o),c}