@wafertools/wafermap 0.35.1 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/AGENTS.md +11 -8
  2. package/CHANGELOG.md +117 -0
  3. package/README.md +3 -3
  4. package/dist/packages/canvas-adapter/chartPrefs.d.ts +16 -0
  5. package/dist/packages/canvas-adapter/chartPrefs.js +1 -0
  6. package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  8. package/dist/packages/canvas-adapter/dataTab.js +1 -1
  9. package/dist/packages/canvas-adapter/drilldown.js +1 -1
  10. package/dist/packages/canvas-adapter/index.d.ts +1 -0
  11. package/dist/packages/canvas-adapter/index.js +1 -1
  12. package/dist/packages/canvas-adapter/insightsTab.d.ts +7 -0
  13. package/dist/packages/canvas-adapter/insightsTab.js +1 -1
  14. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +20 -5
  15. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  16. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +71 -37
  17. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  18. package/dist/packages/canvas-adapter/summaryPanel.d.ts +7 -4
  19. package/dist/packages/canvas-adapter/summaryPanel.js +4 -4
  20. package/dist/packages/canvas-adapter/testValueOffer.d.ts +14 -0
  21. package/dist/packages/canvas-adapter/testValueOffer.js +1 -0
  22. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  23. package/dist/packages/canvas-adapter/toolbar.d.ts +0 -6
  24. package/dist/packages/canvas-adapter/toolbar.js +1 -1
  25. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  26. package/dist/packages/canvas-adapter/userGuideHtml.js +10 -3
  27. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  28. package/dist/packages/canvas-adapter/version.js +1 -1
  29. package/dist/packages/canvas-adapter/warnings.js +1 -1
  30. package/dist/packages/core/aggregates.d.ts +10 -0
  31. package/dist/packages/core/aggregates.js +1 -1
  32. package/dist/packages/core/dieTable.d.ts +5 -0
  33. package/dist/packages/core/dieTable.js +1 -1
  34. package/dist/packages/core/wafer.d.ts +10 -1
  35. package/dist/packages/core/wafer.js +1 -1
  36. package/dist/packages/renderer/buildView.d.ts +5 -0
  37. package/dist/packages/renderer/buildView.js +1 -1
  38. package/dist/packages/renderer/buildWaferMap.d.ts +19 -4
  39. package/dist/packages/renderer/buildWaferMap.js +1 -1
  40. package/dist/packages/renderer/derivedTests/parser.js +1 -1
  41. package/dist/packages/renderer/fmt.d.ts +10 -0
  42. package/dist/packages/renderer/fmt.js +1 -1
  43. package/dist/packages/renderer/index.d.ts +1 -0
  44. package/dist/packages/renderer/index.js +1 -1
  45. package/dist/packages/renderer/valueFilter.d.ts +1 -1
  46. package/dist/packages/renderer/valueFilter.js +1 -1
  47. package/dist/packages/stats/analyzeWaferLot.d.ts +16 -0
  48. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  49. package/dist/packages/stats/analyzeWaferMap.d.ts +18 -1
  50. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  51. package/dist/packages/stats/clusterDetection.js +1 -1
  52. package/dist/packages/stats/connectedComponents.js +1 -1
  53. package/dist/packages/stats/correlation.d.ts +36 -4
  54. package/dist/packages/stats/correlation.js +1 -1
  55. package/dist/packages/stats/filterFindings.d.ts +1 -1
  56. package/dist/packages/stats/filterFindings.js +1 -1
  57. package/dist/packages/stats/findingText.d.ts +8 -0
  58. package/dist/packages/stats/findingText.js +2 -2
  59. package/dist/packages/stats/index.d.ts +2 -1
  60. package/dist/packages/stats/index.js +1 -1
  61. package/dist/packages/stats/lotDrift.js +1 -1
  62. package/dist/packages/stats/mergeTestDefs.js +1 -1
  63. package/dist/packages/stats/plotData.js +1 -1
  64. package/dist/packages/stats/renderSummaryReport.js +27 -27
  65. package/dist/packages/stats/reportHtml.d.ts +5 -12
  66. package/dist/packages/stats/reportHtml.js +96 -34
  67. package/dist/packages/stats/synthesis.d.ts +4 -0
  68. package/dist/packages/stats/synthesis.js +1 -1
  69. package/dist/packages/stats/testPassRate.js +1 -1
  70. package/dist/packages/stats/testValueBudget.d.ts +15 -0
  71. package/dist/packages/stats/testValueBudget.js +1 -0
  72. package/dist/packages/stats/types.d.ts +77 -22
  73. package/package.json +1 -1
@@ -1 +1 @@
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)}
1
+ import{fontPx as Ot}from"./toolbar.js";import{findTestDef as Ee,buildMapTitle as He}from"../renderer/buildView.js";import{niceStep as Et,compactTickIndices as mo}from"../renderer/axisTicks.js";import{sortBinsForDisplay as uo}from"../stats/binPareto.js";import{affineInvert as po,affineVector as Ge}from"../core/transforms.js";import{asList as xo,compareNatural as Mo,maxOf as te,minOf as Xe}from"../core/utils.js";import{resolveValueColorFn as yo}from"../renderer/colorSchemes.js";import{NO_DATA_FILL as bo}from"../renderer/colorMap.js";import{SPEC_PASS_FILL as Ye,SPEC_FAIL_LOW as To,SPEC_FAIL_HIGH as $e,contrastTextColor as we}from"../renderer/colorMap.js";import{fmt as Ve,fmtColorbarAxis as Ke}from"../renderer/fmt.js";import{resolveCanvasTheme as So}from"./canvasTheme.js";import{hitGridDims as ko}from"./hitGrid.js";const Lo=5,ze=4;function qe(f,e,F,g,l){f.moveTo(e,F+l*g),f.lineTo(e-g*.9,F-l*g*.6),f.lineTo(e+g*.9,F-l*g*.6),f.closePath()}const Ao=new Set(["value","stackedValues","stackedBins","stackedSoftBins"]),_o=new Set(["hardBin","softBin","metadata"]),ct=()=>`${Ot(-2)}px system-ui, sans-serif`,Ue=3,ee=2,Co=6,Ro=20,Po=()=>`600 ${Ot()}px system-ui, sans-serif`,Je=36,be=()=>`${Ot(-1)}px system-ui, sans-serif`,je=()=>`600 ${Ot(-1)}px system-ui, sans-serif`,oe=128,Bo=()=>`${Ot(-2)}px system-ui, sans-serif`,Ze=4,K=17,Q=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 ne=28,At=5,yt=8,Qe=15,ve=12,to=6;export function toCanvas(f,e,F={}){return drawMapCanvas(f,e,F)}export function drawMapCanvas(f,e,F={}){const g=So(f.parentElement??f),{padding:l=16,showColorbar:P=!0,markFailingDies:q=!1,colorbarWidth:m=16,background:Y=g.background,legendPosition:N="default",legendOffset:U,showAxes:J=!1,diePitchMm:B,viewport:$,activeBin:H,hoverBin:v,afterDies:Ht,fallbackFormat:_t,minRightReserve:Gt,hbinDefs:mt,sbinDefs:Ct,metadataFields:Xt,showTitle:nt=!0}=F,ut=xo(H),G=Math.floor(f.clientWidth||f.width),j=Math.floor(f.clientHeight||f.height),Rt=G>=BIN_LEGEND_MIN_CANVAS_W&&j>=BIN_LEGEND_MIN_CANVAS_H,It=P&&Rt&&Ao.has(e.plotMode)&&e.passFailDisplay==="off",Dt=P&&Rt&&_o.has(e.plotMode),ht=P&&Rt&&e.plotMode==="value"&&(e.passFailDisplay==="spec"&&e.specCounts!==void 0||e.passFailDisplay==="test"&&e.passFailCounts!==void 0),dt=Dt||ht,Yt=Dt&&e.plotMode!=="metadata"&&e.binCounts?uo(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]):[],gt=[];if(ht&&e.passFailDisplay==="test"){const o=e.passFailCounts;gt.push({key:-1,color:Ye,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),gt.push({key:-2,color:$e,label:"Fail",compactLabel:"Fail",count:o.fail,tooltip:`Fail \xB7 ${o.fail} dies`})}else if(ht){const o=e.specCounts,c=Ee(e.testDefs,e.activeTest);gt.push({key:-1,color:Ye,label:"Pass",compactLabel:"Pass",count:o.pass,tooltip:`Pass \xB7 ${o.pass} dies`}),c?.limitHigh!==void 0&&gt.push({key:-2,color:$e,label:"Fail high",compactLabel:"Fail hi",count:o.failHigh,tooltip:`Fail high \xB7 ${o.failHigh} dies`}),c?.limitLow!==void 0&&gt.push({key:-3,color:To,label:"Fail low",compactLabel:"Fail lo",count:o.failLow,tooltip:`Fail low \xB7 ${o.failLow} dies`})}const wt=ht?gt.length:e.plotMode==="metadata"?$t.length:Yt.length,et=(f.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 st=N!=="default"?N:G<BIN_LEGEND_ADAPT_FLOATING?"floating":G<BIN_LEGEND_ADAPT_COMPACT?"compact":"default",y=st==="default"||st==="compact",rt=st==="left",z=st==="bottom",bt=st==="top",Tt=st==="floating",St=st==="compact"||st==="floating"?BIN_LEGEND_W_COMPACT:BIN_LEGEND_W,Te=Math.floor((j-2*l)/K),Se=wt>Te?Te-1:wt,ke=dt&&z?Se*K:0,se=dt&&bt?Se*K:0,le=e.plotMode==="stackedBins"||e.plotMode==="stackedSoftBins",ie=Ee(e.testDefs,e.activeTest),Le=le?"Count":ie?.name??(e.activeTest!=null?`Test ${e.activeTest}`:void 0),Ae=le?void 0:ie?.unit,[Wt,Ft]=e.valueRange,ae=o=>String(Math.round(o)),no=e.logScale||e.allIntegerValues?void 0:Et(Math.max(0,Ft-Wt)*Je/Math.max(1,j))||void 0,ce=e.allIntegerValues?ae:Ke(Ft,Le,Ae,_t,no).edgeFmt;let re=0;if(It){const o=f.getContext("2d");o.font=ct();const c=[ce(Wt),ce(Ft)];Wt<0&&c.push(ce(-Math.max(Math.abs(Wt),Math.abs(Ft))));for(const x of c)re=Math.max(re,o.measureText(x).width)}const _e=Math.max(Ro,Math.ceil(re)+Ue+ee+Co-l),fe=It?m+_e+8:dt&&y?St:0,he=dt&&rt?St:0,de=J?32:0,Vt=J?36:0,so=Gt!=null?Math.max(fe,Gt):fe,lo=G-2*l-so-Vt-he,Ce=j-2*l-de-ke-se;f.width=Math.round(G*et),f.height=Math.round(j*et);const t=f.getContext("2d");t.scale(et,et),t.fillStyle=Y,t.fillRect(0,0,G,j);const ot=e.hoverPoints;if(!ot.length)return{hitTarget:{getDieAtPoint:()=>null},viewport:{originX:0,originY:0,ppm:1,snapDist:1},binLegendRows:[]};const Kt=e.rectangles[0],ge=Kt?Kt.width/2:0,me=Kt?Kt.height/2:0,zt=e.dieBounds,Re=(zt?.minX??0)-ge,io=(zt?.maxX??0)+ge,ao=(zt?.minY??0)-me,Pe=(zt?.maxY??0)+me,Be=io-Re,Ie=Pe-ao;let lt,it,C;if($)({originX:lt,originY:it,ppm:C}=$);else{const c=e.notchDir,x=c&&c.y>.1?13:0,u=c&&c.y<-.1?13:0,k=c&&c.x<-.1?13:0,p=c&&c.x>.1?13:0,h=lo-k-p,i=Ce-x-u;C=Math.min(h/Be,i/Ie),lt=l+Vt+he+k+(h-Be*C)/2-Re*C,it=l+se+x+(i-Ie*C)/2+Pe*C}const qt=$?.snapDist??Math.max(ge,me,1)*1.5,Ut=lt+e.waferCenter.x*C,co=it-e.waferCenter.y*C,ue=e.waferRadius*C,pt=o=>{const c=Math.abs(o-co);return c>=ue?0:Math.sqrt(ue*ue-c*c)},kt=(o,c,x,u,k,p,h=Po(),i=g.text)=>{if(!o)return;t.save(),t.fillStyle=i,t.font=h,t.textAlign=u,t.textBaseline=k;const a=u==="right"?c-p:p-c;let n=o;if(a>8&&t.measureText(n).width>a){for(;n.length>1&&t.measureText(n+"\u2026").width>a;)n=n.slice(0,-1);n=n+"\u2026"}a>8&&t.fillText(n,c,x),t.restore()};t.save(),t.setTransform(C*et,0,0,-C*et,lt*et,it*et);const xt=1/C;let Jt=!1;const ro=1/(C*et),jt=e.rectangles.length>0&&e.dieGap*C*et<1;if(e.rectangles.length>0){const o=new Map;for(const h of e.rectangles){const i=String(h.fill);let a=o.get(i);a||(a=[],o.set(i,a)),a.push(h)}const c=C*et,x=lt*et,u=it*et,k=e.dieGap/2;jt&&(t.save(),t.setTransform(1,0,0,1,0,0));for(const[h,i]of o){t.fillStyle=h;for(let a=0;a<i.length;a+=PATH_SHAPES){t.beginPath();const n=Math.min(i.length,a+PATH_SHAPES);for(let s=a;s<n;s++){const d=i[s];if(jt){const L=d.width/2+k,b=d.height/2+k,I=2*L*c>=ze?1:0,Z=2*b*c>=ze?1:0,tt=Math.round(x+(d.x-L)*c),D=Math.max(tt+1,Math.round(x+(d.x+L)*c)-I),R=Math.round(u-(d.y+b)*c),Lt=Math.max(R+1,Math.round(u-(d.y-b)*c)-Z);t.rect(tt,R,D-tt,Lt-R)}else t.rect(d.x-d.width/2,d.y-d.height/2,d.width,d.height)}t.fill()}}if(jt&&t.restore(),!jt){t.strokeStyle="rgba(0,0,0,0.18)",t.lineWidth=.5*ro,t.lineCap="square";const h=oo.get(e.rectangles)??outlineSegments(e.rectangles);oo.set(e.rectangles,h);const i=PATH_SHAPES*4;for(let a=0;a<h.length;a+=i){t.beginPath();const n=Math.min(h.length,a+i);for(let s=a;s<n;s+=4)t.moveTo(h[s],h[s+1]),t.lineTo(h[s+2],h[s+3]);t.stroke()}t.lineCap="butt"}if(q){const h=e.rectangles.filter(i=>i.binFail);if(h.length>0){const i=new Map;for(const a of h){const n=we(String(a.fill));let s=i.get(n);s||(s=[],i.set(n,s)),s.push(a)}t.save(),t.lineCap="butt";for(const[a,n]of i){t.strokeStyle=a,t.globalAlpha=.55,t.lineWidth=Math.max(.6*xt,Math.min(n[0].width,n[0].height)*.1);for(const s of n){const d=s.width/2,L=s.height/2,b=Math.max(1.6*xt,Math.min(s.width,s.height)/3);t.save(),t.beginPath(),t.rect(s.x-d,s.y-L,s.width,s.height),t.clip(),t.beginPath();for(let I=-(d+L);I<=d+L;I+=b)t.moveTo(s.x-d+I,s.y-L),t.lineTo(s.x-d+I+s.height,s.y+L);t.stroke(),t.restore()}}t.restore()}}const p=e.rectangles.filter(h=>h.specMark);if(Jt=p.length>0&&Math.min(p[0].width,p[0].height)<Lo*xt,p.length>0&&!Jt){const h=new Map;for(const a of p){const n=we(String(a.fill)),s=`${a.specMark}|${n}`;let d=h.get(s);d||(d=[],h.set(s,d)),d.push(a)}const i=2.5*xt;t.lineJoin="round";for(const[a,n]of h){const[s,d]=a.split("|"),L=d==="#000000"?"#ffffff":"#000000",b=s==="failHigh"?1:-1,I=Math.min(n[0].width,n[0].height),Z=Math.max(2.5*xt,I*.3);t.beginPath();for(const tt of n)qe(t,tt.x,tt.y,Z,b);t.strokeStyle=L,t.lineWidth=i,t.stroke(),t.fillStyle=d,t.fill()}}}for(const o of e.overlays){t.beginPath();for(const c of o.points){for(let x=0;x<c.length;x++)x===0?t.moveTo(c[x].x,c[x].y):t.lineTo(c[x].x,c[x].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*xt,t.stroke(),t.strokeStyle="rgba(255,255,255,0.8)",t.lineWidth=1*xt,t.stroke()):(t.strokeStyle=o.lineColor,t.lineWidth=o.lineWidth*xt,t.stroke())}if(t.restore(),e.notchDir){const o=lt+e.waferCenter.x*C,c=it-e.waferCenter.y*C,x=e.notchDir.x,u=-e.notchDir.y,k=e.waferRadius*C,p=4,h=9,i=5,a=o+x*(k+p),n=c+u*(k+p),s=a+x*h,d=n+u*h,L={x:-u,y:x},b=l+Vt+he,I=G-l-fe,Z=l+se,tt=j-l-ke-de;t.save(),t.beginPath(),t.rect(b,Z,I-b,tt-Z),t.clip(),t.beginPath(),t.moveTo(a,n),t.lineTo(s+L.x*i,d+L.y*i),t.lineTo(s-L.x*i,d-L.y*i),t.closePath(),t.fillStyle=g.text,t.fill(),t.restore()}t.save(),t.textAlign="center",t.textBaseline="middle";let De=0;if(e.rectangles.length>0){let o=1;for(const p of e.texts)p.role!=="indicator"&&p.text.length>o&&(o=p.text.length);const c=e.rectangles[0].width*C,x=e.rectangles[0].height*C,u=Math.min(c,x),k=c/o;De=Math.max(8,Math.min(64,Math.round(Math.min(u*.55,k*1.8))))}for(const o of e.texts){const c=lt+o.x*C,x=it-o.y*C;t.font=`${o.role==="indicator"?o.fontSize:De}px system-ui, sans-serif`,t.fillStyle=o.color,t.fillText(o.text,c,x)}if(t.restore(),Ht?.(t,{originX:lt,originY:it,ppm:C},{background:Y,text:g.text}),J&&Io(t,G,j,lt,it,C,l,de,Vt,B,e.gridToScreen,e.rotation,g,e.compact),It){const o=yo(e.valueColorScheme,e.reverseValueScheme),c=_e,x=Ce,u=Math.round(x*.75),k=l+Math.round((x-u)/2),p=G-l-m-c,h=Wt,i=Ft,a=i-h,n=e.plotMode==="stackedSoftBins"?Ct:mt,{primary:s,secondary:d,note:L}=nt?He(e,_t,n):{primary:"",secondary:"",note:void 0};if(nt){const r=Math.max(k-6,l+11),E=Ut+Math.max(pt(r),pt(r-12))+8;kt(s,G-l,r,"right","bottom",E)}let b=k+u+4;const I=r=>Ut+Math.max(pt(r),pt(r+12))+8,Z=e.logScale&&h>0?Math.log10(h):0,tt=e.logScale&&i>0?Math.log10(i)-Z:1,D=r=>e.logScale?(1-(Math.log10(r)-Z)/tt)*u:(1-(r-h)/a)*u;for(let r=0;r<oe;r++){const E=1-r/(oe-1),X=k+r/oe*u,M=u/oe+1;t.fillStyle=o(E),t.fillRect(p,X,m,M)}t.strokeStyle="rgba(0,0,0,0.25)",t.lineWidth=.5,t.strokeRect(p,k,m,u),t.fillStyle=g.text,t.font=ct(),t.textAlign="left",t.strokeStyle="rgba(0,0,0,0.35)",t.lineWidth=.5;const R=Ue,Lt=Je,ft=14;let w;const O=e.logScale&&tt>0?Do(h,i,u,Lt,ft,Z,tt):e.allIntegerValues?(()=>{const r=Math.max(1,Et(a*Lt/u)),E=[],X=Math.ceil(h/r)*r;for(let M=X;M<=i+r*1e-6;M+=r){const W=(1-(M-h)/a)*u;W>ft&&W<u-ft&&E.push(Math.round(M))}return E})():(()=>{const r=a>0?Et(a*Lt/u):0,E=[];if(r>0){w=r;const X=Math.ceil(h/r)*r;for(let M=X;M<=i+r*1e-6;M+=r){const W=(1-(M-h)/a)*u;W>ft&&W<u-ft&&E.push(M)}}return E})(),T=ie,_=le,S=Ke(i,Le,Ae,_t,w),V=e.allIntegerValues?ae:S.tickFmt,A=e.allIntegerValues?ae:S.edgeFmt;t.textBaseline="middle";for(const r of O){const E=k+D(r);t.beginPath(),t.moveTo(p+m,E),t.lineTo(p+m+R,E),t.stroke(),t.fillText(V(r),p+m+R+ee,E)}if(t.beginPath(),t.moveTo(p+m,k),t.lineTo(p+m+R,k),t.stroke(),t.textBaseline="top",t.fillText(A(i),p+m+R+ee,k),t.beginPath(),t.moveTo(p+m,k+u),t.lineTo(p+m+R,k+u),t.stroke(),t.textBaseline="bottom",t.fillText(A(h),p+m+R+ee,k+u),!_&&T&&(T.limitLow!==void 0||T.limitHigh!==void 0)){const r=[],E=e.colorbarRangeMode==="spec";for(const[X,M]of[[T.limitLow,"Lo limit"],[T.limitHigh,"Hi limit"]]){if(X===void 0||e.logScale&&X<=0)continue;const W=D(X);!E&&(W<-ft||W>u+ft)||r.push({value:X,label:M,py:Math.max(0,Math.min(u,W))})}if(r.length>0){t.save(),t.font=ct(),t.textAlign="right",t.textBaseline="middle";for(const{py:X,label:M}of r){const W=k+X;if(E||(t.strokeStyle="rgba(255,255,255,0.85)",t.lineWidth=3,t.beginPath(),t.moveTo(p,W),t.lineTo(p+m,W),t.stroke(),t.strokeStyle="rgba(0,0,0,0.7)",t.lineWidth=1,t.beginPath(),t.moveTo(p,W),t.lineTo(p+m,W),t.stroke()),t.fillStyle=g.text,t.fillText(M,p-3,W),Jt)continue;const Pt=M==="Hi limit"?-1:1,Bt=4,vt=p-3-t.measureText(M).width-Bt-4;t.beginPath(),qe(t,vt,W,Bt,Pt),t.strokeStyle="#fff",t.lineWidth=2,t.lineJoin="round",t.stroke(),t.fillStyle=g.text,t.fill()}t.restore()}}if(!_){const r=e.logScale?"log\u2081\u2080":e.logScaleRequested?"linear \u2014 log n/a":null;r&&(t.save(),t.fillStyle=g.text,t.font=je(),t.textAlign="right",t.textBaseline="top",t.fillText(r,G-l,b),t.restore(),b+=15)}Jt&&(t.save(),t.fillStyle=g.text,t.font=je(),t.textAlign="right",t.textBaseline="top",t.fillText("\u25BD\u25B3 limit marks: zoom in",G-l,b),t.restore(),b+=15),nt&&d&&(kt(d,G-l,b,"right","top",I(b),be(),g.text),b+=15),nt&&L&&kt(L,G-l,b,"right","top",I(b),be(),g.text)}const pe=[];let at;if(dt){const o=st==="compact",c=e.plotMode==="softBin"?Ct:mt,x=c?new Map(c.map(n=>[n.bin,n])):null,u=e.plotMode==="softBin"?e.binColors.soft:e.binColors.hard,k=n=>u.get(n)??bo,p=(n,s)=>{const d=t.measureText(n).width,L=o?0:t.measureText(String(s)).width,b=Q+At+d+(L?ne:0);return{labelWidth:d,countWidth:L,totalWidth:b}},h=Xt?.find(n=>n.key===e.activeMetadataKey),i=ht?gt.map(n=>{const s=o?n.compactLabel:n.label;return{key:n.key,color:n.color,count:n.count,label:s,tooltipLabel:n.tooltip,...p(s,n.count)}}):e.plotMode==="metadata"?$t.map(([n,s])=>{const L=h?.values?.find(Z=>Z.value===n)?.label??n,b=o?n:L,I=e.metadataColorMap?.get(n)??"#d6d9dd";return{key:n,color:I,count:s,label:b,tooltipLabel:`${L} \xB7 ${s} dies`,...p(b,s)}}):Yt.map(([n,s])=>{const d=x?.get(n),L=d?.name?`${n} \xB7 ${d.name}`:`Bin ${n}`,b=o?String(n):L;return{key:n,color:k(n),count:s,label:b,tooltipLabel:`${L} \xB7 ${s} dies`,...p(b,s)}}),a=G-l*2;if(i.length>0){const n=Tt?yt*2+(nt?Qe:0):nt&&!bt?ve+to:0,s=Math.max(1,Math.floor((j-2*l-n)/K));let d=i.length,L=1,b=d*K,I=[],Z=0;const tt=z||bt;if(tt){const w=te(i.map(T=>T.totalWidth)),O=Math.max(1,Math.min(i.length,Math.floor((a+8)/(w+8))));for(let T=O;T>=1;T--){const _=Math.ceil(i.length/T);if(_>s)continue;const S=new Array(T).fill(0);for(let A=0;A<i.length;A++){const r=A%T;S[r]=Math.max(S[r],i[A].totalWidth)}if(S.reduce((A,r)=>A+r,0)+(T-1)*8<=a||T===1){L=T,I=S,d=_,b=_*K;break}}}else d=Math.min(i.length,s),b=d*K,i.length>s&&(Z=i.length-(s-1)),I=[St];let D,R;if(Tt){const w=te(i.map(r=>Q+At+t.measureText(r.label).width+ne)),O=Math.ceil(w);I=[O];const T=nt?Qe:0,_=O+yt*2,S=b+T+yt*2,V=U?.x??0,A=U?.y??0;D=Math.min(Math.max(G-l-_+V,l),G-l-_),R=Math.min(Math.max(j-l-S+A,l),j-l-S),at={x:D,y:R,w:_,h:S},t.save(),t.globalAlpha=.92,t.fillStyle=g.surface,t.fillRect(D,R,_,S),t.globalAlpha=1,t.strokeStyle=g.axisLine,t.lineWidth=1,t.strokeRect(D,R,_,S),t.restore(),D+=yt,R+=yt+T}else z?(D=l,R=j-l-b):bt?(D=l,R=l):rt?(D=l+4,R=Math.max(l+Math.round((j-2*l-b)/2),l+n)):(D=G-l-St+4,R=Math.max(l+Math.round((j-2*l-b)/2),l+n));if(nt){const w=e.plotMode==="softBin"?Ct:mt,{primary:O,secondary:T,note:_}=He(e,_t,w),S=to,V=[T,_].filter(M=>!!M),A=(M,W,Pt)=>V.forEach((Bt,vt)=>kt(Bt,M,W+vt*16,"left","top",Pt(W+vt*16),be(),g.text)),r=M=>Ut-Math.max(pt(M),pt(M-12))-8,E=M=>y?G-l:r(M),X=Tt?at.y+at.h:R+b;if(bt){const M=X+S;kt(O,D,M,"left","top",Ut-Math.max(pt(M),pt(M+12))-8),A(D,M+16,r)}else if(Tt)kt(O,at.x+yt,at.y+yt,"left","top",at.x+at.w-yt),A(at.x,X+S,()=>at.x+at.w);else{const M=Math.max(R-S,l+ve);kt(O,D,M,"left","bottom",E(M)),A(D,X+S,E)}}t.save(),t.font=ct();const Lt=tt?8:0,ft=(w,O)=>{if(t.measureText(w).width<=O)return w;let T=0,_=w.length;const S="\u2026",V=t.measureText(S).width;for(;T<_;){const A=T+_+1>>1;t.measureText(w.slice(0,A)).width+V<=O?T=A:_=A-1}return T===0?S:w.slice(0,T)+S};if(tt){let w=0;for(let O=0;O<d;O++){let T=D;for(let _=0;_<L;_++){const S=i[w++];if(!S)break;const V=ut.includes(S.key),A=!V&&S.key===v,r=T,E=T+Q+At,X=R+O*K+K/2,M=R+O*K+Math.round((K-Q)/2),W=I[_]-Q-At-ne;A&&(t.fillStyle=g.hoverRow,t.fillRect(T,R+O*K,I[_],K)),t.fillStyle=S.color,t.fillRect(r,M,Q,Q),t.strokeStyle=V?g.accent:"rgba(0,0,0,0.25)",t.lineWidth=V?2:.75,t.strokeRect(r,M,Q,Q),t.fillStyle=V?g.accent:g.text,t.font=V?`bold ${ct()}`:ct(),t.textAlign="left",t.textBaseline="middle",t.fillText(ft(S.label,W),E,X),t.fillStyle=g.textMuted,t.font=ct(),t.textAlign="right",t.fillText(String(S.count),T+I[_]-2,X),pe.push({bin:S.key,x:T,y:R+O*K,w:I[_],h:K,label:S.tooltipLabel}),T+=I[_]+Lt}}}else{const w=I[0],O=st!=="compact",T=w-Q-At-(O?ne:0),_=D+w-2;let S=i;Z>0&&(S=i.slice(0,s-1));let V=R;for(const A of S){const r=ut.includes(A.key),E=!r&&A.key===v,X=D,M=D+Q+At,W=V+K/2,Pt=V+Math.round((K-Q)/2),Bt=A.label;E&&(t.fillStyle=g.hoverRow,t.fillRect(D-3,V,w+3,K)),t.fillStyle=A.color,t.fillRect(X,Pt,Q,Q),t.strokeStyle=r?g.accent:"rgba(0,0,0,0.25)",t.lineWidth=r?2:.75,t.strokeRect(X,Pt,Q,Q),t.fillStyle=r?g.accent:g.text,t.font=r?`bold ${ct()}`:ct(),t.textAlign="left",t.textBaseline="middle",t.fillText(ft(Bt,T),M,W),(O||Tt)&&(t.fillStyle=g.textMuted,t.font=ct(),t.textAlign="right",t.fillText(String(A.count),_,W)),pe.push({bin:A.key,x:D,y:V,w,h:K,label:A.tooltipLabel}),V+=K}Z>0&&(t.fillStyle=g.textMuted,t.font=ct(),t.textAlign="left",t.textBaseline="middle",t.fillText(`+ ${Z} more`,D+Q+At,V+K/2))}}i.length>0&&t.restore()}const fo={originX:lt,originY:it,ppm:C,snapDist:qt},We=e.rectangles[0]?.width??1,Fe=e.rectangles[0]?.height??1,Mt=e.dieBounds,Zt=Mt?Mt.minX:ot.length?Xe(ot.map(o=>o.x)):0,Qt=Mt?Mt.minY:ot.length?Xe(ot.map(o=>o.y)):0,ho=Mt?Mt.maxX:ot.length?te(ot.map(o=>o.x)):1,go=Mt?Mt.maxY:ot.length?te(ot.map(o=>o.y)):1,{cellW:xe,cellH:Me,nCols:Nt,nRows:ye}=ko(ho-Zt,go-Qt,We*1.5,Fe*1.5,ot.length),Ne=Array.from({length:Nt*ye},()=>[]);for(let o=0;o<ot.length;o++){const c=Math.floor((ot[o].x-Zt)/xe),x=Math.floor((ot[o].y-Qt)/Me),u=Number.isFinite(c)?Math.max(0,Math.min(Nt-1,c)):0,k=Number.isFinite(x)?Math.max(0,Math.min(ye-1,x)):0;Ne[k*Nt+u].push(o)}function Oe(o,c,x){const u=Math.max(0,Math.floor((o-x-Zt)/xe)),k=Math.min(Nt-1,Math.floor((o+x-Zt)/xe)),p=Math.max(0,Math.floor((c-x-Qt)/Me)),h=Math.min(ye-1,Math.floor((c+x-Qt)/Me)),i=[];for(let a=p;a<=h;a++)for(let n=u;n<=k;n++)for(const s of Ne[a*Nt+n])i.push(s);return i}return{hitTarget:{getDieAtPoint(o,c){const x=(o-lt)/C,u=(it-c)/C,k=Math.max(We,Fe);for(const i of Oe(x,u,k)){const a=e.rectangles[i];if(a&&Math.abs(x-a.x)<=a.width/2&&Math.abs(u-a.y)<=a.height/2)return e.dies[i]??null}let p=null,h=qt*qt;for(const i of Oe(x,u,qt)){const a=ot[i].x-x,n=ot[i].y-u,s=a*a+n*n;s<h&&(h=s,p=e.dies[i]??null)}return p}},viewport:fo,binLegendRows:pe,legendBox:at}}function Io(f,e,F,g,l,P,q,m,Y,N,U,J,B,$){f.save(),f.font=Bo(),f.fillStyle=B.text,f.strokeStyle=B.axisLine,f.lineWidth=.5;const H=F-m+4,v=q+Y-4,Ht=po(U),_t=Ge(Ht,1,0),Gt=Ge(Ht,0,1),mt=1e-9;function Ct(y){return N?Math.abs(y.y)<mt&&Math.abs(y.x)>mt?{pitch:N.x,sign:Math.sign(y.x),axis:"x"}:Math.abs(y.x)<mt&&Math.abs(y.y)>mt?{pitch:N.y,sign:Math.sign(y.y),axis:"y"}:null:null}function Xt(y,rt){if(!$||!y)return null;const z=y.axis==="x"?$.columns:$.rows,bt=y.axis==="x"?$.columnBreaks:$.rowBreaks,Tt=y.axis==="x"?$.centreColumn:$.centreRow;return mo(z.length,bt,y.pitch*P,rt).map(St=>({mm:y.sign*(St-Tt)*y.pitch,label:String(z[St])}))}const nt=Ct(_t),ut=Ct(Gt);function G(y){return nt?Math.round(y*nt.sign/nt.pitch):y}function j(y){return ut?Math.round(y*ut.sign/ut.pitch):y}function Rt(y){if(!y)return Et(50/P);const rt=50/(y*P);return Math.max(1,Math.round(rt))*y}const It=nt?.pitch,Dt=ut?.pitch,ht=Rt(It),dt=Rt(Dt);f.textAlign="center",f.textBaseline="top";const Yt=Math.ceil((q-g)/P/ht)*ht,$t=(e-q-g)/P,gt=Xt(nt,36)??eo(Yt,$t,ht,y=>N?String(G(y)):Ve(y));for(const{mm:y,label:rt}of gt){const z=g+y*P;z<q||z>e-q||(f.beginPath(),f.moveTo(z,H-Ze),f.lineTo(z,H),f.stroke(),f.fillText(rt,z,H+2))}f.textAlign="right",f.textBaseline="middle";const wt=Math.ceil((l-(F-q))/P/dt)*dt,et=(l-q)/P,st=Xt(ut,16)??eo(wt,et,dt,y=>N?String(j(y)):Ve(y));for(const{mm:y,label:rt}of st){const z=l-y*P;z<q||z>F-q||(f.beginPath(),f.moveTo(v,z),f.lineTo(v+Ze,z),f.stroke(),f.fillText(rt,v-2,z))}f.restore()}function eo(f,e,F,g){const l=[];for(let P=f;P<=e;P+=F)l.push({mm:P,label:g(P)});return l}function Do(f,e,F,g,l,P,q){const m=[],Y=q;if(Y<1){const B=Et((e-f)*g/F);if(B>0){const $=Math.ceil(f/B)*B;for(let H=$;H<=e+B*1e-6;H+=B){if(H<=f||H>=e)continue;const v=(1-(Math.log10(H)-P)/q)*F;v>l&&v<F-l&&m.push(H)}}return m}const N=Y<3?[1,2,5]:[1],U=Math.floor(Math.log10(f)),J=Math.ceil(Math.log10(e));for(let B=U;B<=J;B++)for(const $ of N){const H=$*Math.pow(10,B);if(H<=f||H>=e)continue;const v=(1-(Math.log10(H)-P)/q)*F;v>l&&v<F-l&&m.push(H)}return m}export{fmt,fmtColorbarAxis}from"../renderer/fmt.js";export const PATH_SHAPES=256;const oo=new WeakMap;export function outlineSegments(f){const e=m=>Math.round(m*1e6),F=new Map,g=new Map,l=(m,Y,N,U)=>{const J=e(Y);let B=m.get(J);B||m.set(J,B={at:Y,spans:[]}),B.spans.push([N,U])};for(const m of f){const Y=m.x-m.width/2,N=m.x+m.width/2,U=m.y-m.height/2,J=m.y+m.height/2;l(F,U,Y,N),l(F,J,Y,N),l(g,Y,U,J),l(g,N,U,J)}const P=[],q=(m,Y)=>{for(const{at:N,spans:U}of m.values()){U.sort(($,H)=>$[0]-H[0]);let[J,B]=U[0];for(let $=1;$<U.length;$++){const[H,v]=U[$];e(H)<=e(B)?v>B&&(B=v):(Y(N,J,B),J=H,B=v)}Y(N,J,B)}};return q(F,(m,Y,N)=>P.push(Y,m,N,m)),q(g,(m,Y,N)=>P.push(m,Y,m,N)),Float64Array.from(P)}
@@ -542,12 +542,6 @@ export type ModeEntry = {
542
542
  logScale?: boolean;
543
543
  derived?: true;
544
544
  };
545
- /**
546
- * The bin mode a map opens in when the host names no plot mode: hard bins when any die has one, else
547
- * soft bins when any die has one. Hard bins over soft-bin data draw every die as no data. With no bins
548
- * at all it stays hard bins, as it always has. One rule for the single map and the gallery.
549
- */
550
- export declare function defaultPlotMode(dieLists: readonly (readonly Pick<Die, 'hbin' | 'sbin'>[])[]): PlotMode;
551
545
  /**
552
546
  * Which plot modes the data actually supports — the single derivation shared by
553
547
  * `renderWaferMap` and `renderWaferGallery`.
@@ -1,4 +1,4 @@
1
- import{getUniqueTestNumbers as we}from"../renderer/buildView.js";import{dieHasValues as ke}from"../core/dieTable.js";import{dieHasTestData as Ee}from"../renderer/buildWaferMap.js";import{testLabel as ae,isDerivedTest as Ce,DERIVED_MARK as ce,DERIVED_KEY as de}from"../renderer/testLabel.js";import{prettyKey as Le}from"../core/utils.js";import{diagnoseMpwLayout as Ae,formatMpwDiagnostics as Me}from"../core/compact.js";import{listBinColorSchemes as Se,listValueColorSchemes as Be}from"../renderer/colorSchemes.js";import{ICONS as j}from"./icons.js";import{WMAP_VERSION as ue,WMAP_BUILD_TIME as De}from"./version.js";let pe=!1;export function logWmapVersionOnce(){pe||(pe=!0,console.log(`[wmap] v${ue} (built ${De})`))}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})`,Q="var(--wmap-font-size, 12px)",Te="var(--wmap-density, 1)",X=e=>`calc(${e}px * ${Te})`;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:X(2),xs:X(4),sm:X(6),md:X(8),lg:X(10),xl:X(12),xxl:X(16),xxxl:X(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(${Q} - 1px)`,body:Q,sub:`calc(${Q} + 1px)`,heading:`calc(${Q} + 3px)`,stat:`calc(${Q} + 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(),a=o?parseFloat(o):NaN;return(Number.isFinite(a)?a: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 a=n.getPropertyValue(`--wmap-${o}`).trim();a&&t.style.setProperty(`--wmap-${o}`,a)}}export function syncWmapPopupTheme(e,t,n){const o=()=>{copyWmapThemeTokens(e,t),n?.()},a=new window.MutationObserver(o);a.observe(e,{attributes:!0,attributeFilter:["style","class"]}),a.observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]});const d=window.matchMedia("(prefers-color-scheme: dark)");return d.addEventListener("change",o),()=>{a.disconnect(),d.removeEventListener("change",o)}}let re=null;export function setDetachWindowOpener(e){re=e}export function openDetachWindow(e){return re?re(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 markNoPrint(e){e.setAttribute("data-wmap-noprint","1");const t=e.ownerDocument;if(!t.getElementById("wmap-noprint-style")){const n=t.createElement("style");n.id="wmap-noprint-style",n.textContent="@media print{[data-wmap-noprint]{display:none!important}}",t.head.appendChild(n)}}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=Me(Ae(e,t),ue),a=n.anchor.ownerDocument,d=openModal({title:"Layout diagnostics",anchor:n.anchor,ownerDocument:a,onClose:()=>{},boxSize:{width:"min(680px, 94vw)",height:"min(480px, 90vh)"}}),b=d.contentWrap;Object.assign(b.style,{flexDirection:"column",padding:"14px 16px",gap:"10px",boxSizing:"border-box"});const i=a.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 p=a.createElement("textarea");p.value=o,p.readOnly=!0,p.setAttribute("aria-label","Layout diagnostics"),Object.assign(p.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 u=a.createElement("div");Object.assign(u.style,{display:"flex",gap:"8px",alignItems:"center"});const s=a.createElement("span");s.setAttribute("role","status"),Object.assign(s.style,{fontSize:FONT.body,color:CLR.text});const C=(k,c)=>{const r=a.createElement("button");return r.type="button",r.textContent=k,Object.assign(r.style,controlStyle("outlined"),{padding:"5px 12px",color:CLR.text}),wireControlHover(r,"outlined"),r.addEventListener("click",c),r},m=C("Copy",()=>{const k=a.defaultView,c=()=>{p.focus(),p.select();let r=!1;try{r=a.execCommand("copy")}catch{r=!1}s.textContent=r?"Copied":"Copying is not available here. Select the text, or save it as a file."};k?.navigator.clipboard?k.navigator.clipboard.writeText(o).then(()=>{s.textContent="Copied"},c):c()}),y=C("Save as file",()=>{saveTextFile(o,"wafermap-layout-diagnostics.txt","text/plain",n.onSaveText),s.textContent=n.onSaveText?"":"Saved"});return u.append(m,y,s),b.append(i,p,u),p.focus(),p.select(),d}export function saveTextFile(e,t,n,o){if(o){o(e,t,n);return}downloadBlob(typeof e=="string"?new Blob([e],{type:n}):e,t)}const He='[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 a=t();if(a.length===0)return;const d=e.ownerDocument.activeElement,b=d?a.indexOf(d):-1;switch(o.key){case"ArrowDown":o.preventDefault(),a[b<0||b===a.length-1?0:b+1].focus();break;case"ArrowUp":o.preventDefault(),a[b<=0?a.length-1:b-1].focus();break;case"Home":o.preventDefault(),a[0].focus();break;case"End":o.preventDefault(),a[a.length-1].focus();break;case"Enter":case" ":b>=0&&(o.preventDefault(),a[b].click());break;case"Escape":case"Tab":o.preventDefault(),n();break}})}function te(e,t,n){const o=()=>Array.from(e.querySelectorAll(He));wireListNavigation(e,o,()=>{n(),t?.focus()});const a=o()[0];a&&nextFrame(()=>a.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 a=e.ownerDocument.createElement("div");return a.dataset.wmapMenuLayer="1",Object.assign(a.style,{position:"fixed",inset:"0",zIndex:Z_MENU,pointerEvents:"none"}),t.appendChild(a),fe.set(t,a),a}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,a={}){const d=menuLayerFor(t);e.parentElement!==d&&d.appendChild(e);const b=e.ownerDocument.defaultView??window;e.style.left="0",e.style.top="0";const i=e.offsetWidth,p=e.offsetHeight,u=8,s=b.innerWidth,C=b.innerHeight;let m=n+14,y=o-8;m+i+u>s&&(m=n-i-6);const k=t.getBoundingClientRect();if(!a.followPointer&&k.height>0&&k.height<=C*.4&&y<k.bottom&&y+p>k.top&&m<k.right&&m+i>k.left){const h=k.bottom+u,l=k.top-p-u;h+p+u<=C?y=h:l>=u&&(y=l)}y+p+u>C&&(y=C-p-u),y<u&&(y=u),e.style.left=`${m}px`,e.style.top=`${y}px`}export function wireTooltip(e,t,n={}){const o=()=>(typeof t=="function"?t():t)??e.getAttribute("aria-label")??"";typeof t=="string"&&(e.dataset.wmapTip=t),n.asDataPoint&&(e.tabIndex=0,e.setAttribute("role","img"),typeof t=="string"&&e.setAttribute("aria-label",t));const a=b=>{const i=o();if(!i)return;const p=getTooltip(e.ownerDocument);if(p.textContent=i,p.style.display="block",b)positionTooltip(p,e,b.clientX,b.clientY);else{const u=e.getBoundingClientRect();positionTooltip(p,e,u.left+u.width/2,u.top)}},d=()=>hideTooltip(e.ownerDocument);e.addEventListener("mousemove",a),e.addEventListener("mouseleave",d),e.addEventListener("focus",()=>a()),e.addEventListener("blur",d)}export function defaultPlotMode(e){const t=n=>e.some(o=>o.some(a=>n(a)!=null));return t(n=>n.hbin)?"hardBin":t(n=>n.sbin)?"softBin":"hardBin"}export function buildDataModeEntries(e,t,n){const o=e.some(Ee),a=e.some(ke),d=e.some(s=>s.hbin!=null),b=e.some(s=>s.sbin!=null),i=o?t!==void 0?t.map(s=>({plotMode:"value",activeTest:s.testNumber,label:s.unit?`${ae(s,s.testNumber)} (${s.unit})`:ae(s,s.testNumber),logScale:s.logScale,...Ce(s)?{derived:!0}:{}})):we(e).map(s=>({plotMode:"value",activeTest:s,label:ae(void 0,s)})):[],p=[...d?[{plotMode:"hardBin",label:MODE_LABELS.hardBin}]:[],...b?[{plotMode:"softBin",label:MODE_LABELS.softBin}]:[]],u=n.includeStacked?[...a?[{plotMode:"stackedValues",label:MODE_LABELS.stackedValues}]:[],...d?[{plotMode:"stackedBins",label:MODE_LABELS.stackedBins}]:[],...b?[{plotMode:"stackedSoftBins",label:MODE_LABELS.stackedSoftBins}]:[]]:[];return{testEntries:i,binEntries:p,stackedEntries:u}}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",a=>a.stopPropagation()),o.addEventListener("mousedown",a=>a.stopPropagation()),o.addEventListener("keydown",a=>a.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,a,d,b,i,p=window,u=[]){const{makeMenuRow:s,makeMenuSection:C}=b,m=document.createElement("div"),y=180,c=e.left+y<=(p.innerWidth??1/0)?e.left:Math.max(4,e.right-y);if(Object.assign(m.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:`${y}px`,padding:"4px 0",pointerEvents:"auto"}),t.length)if(m.appendChild(C("Test Value")),t.length<=INLINE_TEST_LIMIT)for(const r of t)m.appendChild(s(r.label,a(r),!0,h=>{h.stopPropagation(),d(r,m)}));else{const r=i==="value",h=s(MODE_LABELS.value+" \u25B6",r,!1,A=>{A.stopPropagation(),g(),S(),A.detail===0&&O()});h.setAttribute("aria-haspopup","menu"),h.style.display="flex",h.style.justifyContent="space-between",h.style.alignItems="center";let l=null,L=null;const g=()=>{L!==null&&(clearTimeout(L),L=null)},w=A=>{const T=A.target;T&&(h.contains(T)||l?.contains(T))||x()},x=()=>{g(),l?.remove(),l=null,p.document.removeEventListener("click",w),h.setAttribute("aria-expanded","false")},O=()=>{const A=l?.querySelector('input, [role="menuitemradio"]');A&&nextFrame(()=>A.focus(),p)},W=()=>{g(),L=setTimeout(x,300)},S=()=>{if(l)return;const A=h.getBoundingClientRect(),T=160,I=320,R=A.right+2+T<=(p.innerWidth??1/0)?A.right+2:Math.max(4,A.left-2-T),z=Math.min(A.top-4,Math.max(4,(p.innerHeight??1/0)-I-4));if(l=document.createElement("div"),l.setAttribute("data-wmap-submenu",""),l.setAttribute("role","menu"),Object.assign(l.style,{position:"fixed",top:`${z}px`,left:`${R}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_ABOVE,minWidth:`${T}px`,maxHeight:`${I}px`,overflowY:"auto",padding:"4px 0",pointerEvents:"auto"}),t.length>MENU_SEARCH_THRESHOLD){const v=makeMenuSearchBox(U=>{for(const K of P)K.row.style.display=K.label.includes(U)?"":"none"},"Filter tests\u2026");Object.assign(v.style,{position:"sticky",top:"0",zIndex:"1",background:CLR.menuBg}),l.appendChild(v)}const P=[],F=t.some(v=>v.derived);for(const v of t){const U=s(v.label,a(v),!1,K=>{K.stopPropagation(),x(),d(v,m)},F?{derived:v.derived===!0}:void 0);P.push({row:U,label:v.label.toLowerCase()}),l.appendChild(U)}if(F){const v=p.document.createElement("div");v.setAttribute("role","presentation"),v.textContent=`${ce} ${de}`,Object.assign(v.style,{padding:"6px 14px",fontSize:FONT.meta,color:CLR.label,borderTop:`1px solid ${CLR.menuBorder}`,marginTop:"4px",whiteSpace:"nowrap"}),l.appendChild(v)}l.addEventListener("mouseenter",g),l.addEventListener("mouseleave",W),wireListNavigation(l,()=>P.filter(v=>v.row.style.display!=="none").map(v=>v.row),()=>{x(),h.focus()}),(m.parentElement??p.document.body).appendChild(l),p.document.addEventListener("click",w),h.setAttribute("aria-expanded","true")};m.addEventListener("keydown",A=>{A.key==="Escape"&&x()}),h.addEventListener("mouseenter",()=>{g(),S()}),h.addEventListener("mouseleave",W),m.appendChild(h)}if(n.length){m.appendChild(C("Bins"));for(const r of n)m.appendChild(s(r.label,a(r),!1,h=>{h.stopPropagation(),d(r,m)}))}if(u.length){m.appendChild(C("Metadata"));for(const r of u)m.appendChild(s(r.label,a(r),!1,h=>{h.stopPropagation(),d(r,m)}))}if(o.length){m.appendChild(C("Lot Aggregation"));for(const r of o)m.appendChild(s(r.label,a(r),!1,h=>{h.stopPropagation(),d(r,m)}))}return m.setAttribute("role","menu"),m.setAttribute("aria-label","Plot mode"),m}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 a(u){o!==u&&(o=u,t(o))}function d(){a(!1)}function b(){a(!o),o&&n.addEventListener("click",d,{once:!0})}const i=u=>{u.stopPropagation(),b()},p=u=>{u.key==="Enter"||u.key===" "?(u.preventDefault(),b()):u.key==="Escape"&&d()};return e.setAttribute("role","button"),e.tabIndex<0&&(e.tabIndex=0),e.addEventListener("click",i),e.addEventListener("keydown",p),{isOpen:()=>o,close:d,destroy(){e.removeEventListener("click",i),e.removeEventListener("keydown",p),n.removeEventListener("click",d)}}}export function buildCheckMenuEl(e,t,n,o=window){const{makeMenuSection:a}=n,d=o.document,b=d.createElement("div"),i=168,u=e.left+i<=(o.innerWidth??1/0)?e.left:Math.max(4,e.right-i);Object.assign(b.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:`${i}px`,padding:"4px 0",pointerEvents:"auto"});for(const s of t)if("section"in s)b.appendChild(a(s.section));else{const C=s.enabled!==!1;if(!C&&!s.disabledHint)continue;const m=d.createElement("div");s.action?m.setAttribute("role","menuitem"):(m.setAttribute("role","menuitemcheckbox"),m.setAttribute("aria-checked",s.active?"true":"false")),m.tabIndex=-1,C||(m.setAttribute("aria-disabled","true"),wireTooltip(m,s.disabledHint)),Object.assign(m.style,{display:"flex",alignItems:"center",gap:SPACE.sm,padding:"6px 14px",fontSize:FONT.body,cursor:C?"pointer":"default",color:C?s.active?CLR.iconActive:CLR.text:CLR.label,fontWeight:s.active?"700":"400",background:s.active?CLR.menuActive:"transparent",whiteSpace:"nowrap"});const y=d.createElement("span");Object.assign(y.style,{width:"12px",flexShrink:"0",color:CLR.iconActive,visibility:s.active?"visible":"hidden"}),y.textContent=s.action?"":"\u2713",y.setAttribute("aria-hidden","true");const k=d.createElement("span");k.textContent=s.label,m.appendChild(y),m.appendChild(k),C?(m.addEventListener("mouseenter",()=>{s.active||(m.style.background=CLR.menuHover)}),m.addEventListener("mouseleave",()=>{m.style.background=s.active?CLR.menuActive:"transparent"}),m.addEventListener("focus",()=>{s.active||(m.style.background=CLR.menuHover)}),m.addEventListener("blur",()=>{m.style.background=s.active?CLR.menuActive:"transparent"}),m.addEventListener("click",c=>{c.stopPropagation(),s.onClick(c)})):m.addEventListener("click",c=>{c.stopPropagation()}),b.appendChild(m)}return b}export function createToolbarHelpers(e){const t=e.ownerDocument;let n=null;const o=c=>menuLayerFor(c);function a(c,r,h){const l=t.createElement("button");return l.innerHTML=j[c],l.type="button",l.ariaLabel=r,Object.assign(l.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"}),l.addEventListener("mouseenter",L=>{l.dataset.active||(l.style.background=CLR.bgHover,l.style.color=CLR.iconHover),e.textContent=l.ariaLabel??r,e.style.display="block",positionTooltip(e,l,L.clientX,L.clientY)}),l.addEventListener("mousemove",L=>{e.style.display==="block"&&positionTooltip(e,l,L.clientX,L.clientY)}),l.addEventListener("mouseleave",()=>{l.dataset.active||(l.style.background="transparent",l.style.color=CLR.icon),e.style.display="none"}),l.addEventListener("click",()=>{e.style.display="none",h()}),l}function d(c,r){r?(c.dataset.active="1",c.style.background=CLR.bgActive,c.style.color=CLR.iconActive):(delete c.dataset.active,c.style.background="transparent",c.style.color=CLR.icon)}function b(){const c=t.createElement("div");return Object.assign(c.style,{width:"1px",height:"18px",background:CLR.separator,margin:"0 2px",flexShrink:"0"}),c.dataset.wmapSep="1",c}function i(c){let r=!1,h=null;for(const l of Array.from(c.children))l.dataset.wmapSep?r&&!h?h=l:l.style.display="none":l.style.display!=="none"&&(h&&(h.style.display="",h=null),r=!0);h&&(h.style.display="none")}function p(c){for(const r of Array.from(c.children))if(!(r.dataset.wmapSep||r.style.display==="none"))if(r.tagName==="DIV"&&!r.getAttribute("role")&&r.children.length){if(p(r))return!0}else return!0;return!1}function u(c,r){c.style.display=p(c)?r:"none"}function s(c,r,h,l,L){const g=t.createElement("div");if(L){const w=t.createElement("span");w.textContent=L.derived?ce:"",w.setAttribute("aria-hidden","true"),Object.assign(w.style,{display:"inline-block",width:"1.1em"}),g.append(w,c),L.derived&&g.setAttribute("aria-label",`${c} \u2014 ${de.toLowerCase()}`)}else g.textContent=c;return g.setAttribute("role","menuitemradio"),g.setAttribute("aria-checked",r?"true":"false"),g.tabIndex=-1,Object.assign(g.style,{padding:`6px 14px 6px ${h?"26px":"14px"}`,fontSize:FONT.body,cursor:"pointer",color:r?CLR.iconActive:CLR.text,fontWeight:r?"700":"400",background:r?CLR.menuActive:"transparent",whiteSpace:"nowrap"}),g.addEventListener("mouseenter",()=>{r||(g.style.background=CLR.menuHover)}),g.addEventListener("mouseleave",()=>{g.style.background=r?CLR.menuActive:"transparent"}),g.addEventListener("focus",()=>{r||(g.style.background=CLR.menuHover)}),g.addEventListener("blur",()=>{g.style.background=r?CLR.menuActive:"transparent"}),g.addEventListener("click",l),g}function C(c){const r=t.createElement("div");return r.textContent=c,r.setAttribute("role","presentation"),Object.assign(r.style,{padding:"5px 14px 2px",fontSize:FONT.body,fontWeight:"600",letterSpacing:TRACKING,color:CLR.label,textTransform:"uppercase",pointerEvents:"none",userSelect:"none"}),r}function m(c,r,h,l,L){const g=()=>{n&&(n.remove(),n=null),w.setAttribute("aria-expanded","false")},w=a(c,r,()=>{if(n){g();return}const x=t.createElement("div"),O=w.getBoundingClientRect(),W=w.ownerDocument.defaultView??window,S=148,T=O.left+S<=(W.innerWidth??1/0)?O.left:Math.max(4,O.right-S);Object.assign(x.style,{position:"fixed",top:`${O.bottom+4}px`,left:`${T}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_BASE,minWidth:`${S}px`,padding:"4px 0",pointerEvents:"auto"});for(const I of h()){const M=t.createElement("div");M.textContent=I.label,M.dataset.wmapDropdownValue=I.value;const R=I.value===l();M.setAttribute("role","menuitemradio"),M.setAttribute("aria-checked",R?"true":"false"),M.tabIndex=-1,Object.assign(M.style,{padding:"6px 14px",fontSize:FONT.body,cursor:"pointer",color:R?CLR.iconActive:CLR.text,fontWeight:R?"700":"400",background:R?CLR.menuActive:"transparent",whiteSpace:"nowrap"});const z=()=>{I.value!==l()&&(M.style.background=CLR.menuHover)},P=()=>{M.style.background=I.value===l()?CLR.menuActive:"transparent"};M.addEventListener("mouseenter",z),M.addEventListener("mouseleave",P),M.addEventListener("focus",z),M.addEventListener("blur",P),M.addEventListener("click",F=>{F.stopPropagation(),L(I.value),g()}),x.appendChild(M)}x.setAttribute("role","menu"),x.setAttribute("aria-label",r),o(w).appendChild(x),n=x,w.setAttribute("aria-expanded","true"),te(x,w,g)});return w.setAttribute("aria-haspopup","menu"),w.setAttribute("aria-expanded","false"),w}function y(c,r,h,l){function L(){return buildCheckMenuEl(w.getBoundingClientRect(),h().map(x=>"section"in x?x:{...x,onClick:O=>{x.closeMenu&&g(),x.onClick(O),l(w);const W=n;if(!W)return;const S=L();S.setAttribute("role","menu"),S.setAttribute("aria-label",r),W.replaceWith(S),n=S,te(S,w,g)}}),{makeMenuSection:C},w.ownerDocument.defaultView??window)}const g=()=>{n&&(n.remove(),n=null),w.setAttribute("aria-expanded","false")},w=a(c,r,()=>{if(n){g();return}const x=L();x.setAttribute("role","menu"),x.setAttribute("aria-label",r),o(w).appendChild(x),n=x,w.setAttribute("aria-expanded","true"),te(x,w,g)});return w.setAttribute("aria-haspopup","menu"),w.setAttribute("aria-expanded","false"),l(w),w}function k(c){const r=c.target?.closest?.("[data-wmap-submenu]");if(n&&!n.contains(c.target)&&!r&&(n.remove(),n=null,c.target?.getAttribute?.("aria-haspopup")!=="menu"))for(const l of document.querySelectorAll('[aria-haspopup="menu"][aria-expanded="true"]'))l.setAttribute("aria-expanded","false")}return{makeBtn:a,setActive:d,makeSep:b,syncSeparators:i,syncToolbarVisible:u,makeMenuRow:s,makeMenuSection:C,makeDropdown:m,makeCheckMenuBtn:y,closeOpenMenu:k,getOpenMenu:()=>n,setOpenMenu:c=>{n=c}}}const Oe=7e3;let Ie=0;function me(){return Oe+ ++Ie}const Re=32,$e=6;let We=0;function ze(){return We++%$e*Re}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 be(e){const t=e.mode==="modal",n=e.ownerDocument??document,o=n.defaultView??window,a=n.body.style.overflow;t&&(n.body.style.overflow="hidden");let d=null;t&&(d=n.createElement("div"),d.id="wmap-modal-backdrop",Object.assign(d.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 b=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 p=e.boxSize?.width??"min(90vw, 700px)",u=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:p,height:u,boxShadow:SHADOW.modal,minWidth:"320px",minHeight:"240px",maxWidth:"100vw",maxHeight:"100vh",zIndex:t?Z_ABOVE2:String(me())}),!t){const f=ze();Object.assign(i.style,{position:"fixed",top:`${Math.round(o.innerHeight*.08)+f}px`,left:`${Math.round(o.innerWidth*.08)+f}px`})}const s=n.createElement("div");Object.assign(s.style,{display:"flex",alignItems:"center",gap:SPACE.sm,padding:"10px 14px",borderBottom:`1px solid ${CLR.menuBorder}`,flexShrink:"0"});const C={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 f=n.createElement("span");f.textContent=e.title,f.title=e.title,f.dataset.wmapWindowTitle="1",Object.assign(f.style,{fontWeight:"700",fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"}),s.appendChild(f)}const m=n.createElement("div");m.style.flex="1",s.appendChild(m);let y=null;t||(y=n.createElement("button"),y.type="button",y.innerHTML=j.collapse,y.setAttribute("aria-label","Collapse"),wireTooltip(y),Object.assign(y.style,C),wireControlHover(y),y.addEventListener("click",()=>A(!x)),s.appendChild(y));let k=null;e.printable&&(k=n.createElement("button"),k.type="button",k.innerHTML=j.print,k.setAttribute("aria-label","Print / Save as PDF"),wireTooltip(k),Object.assign(k.style,C),wireControlHover(k),k.addEventListener("click",()=>{typeof e.printable=="function"?e.printable():o.print()}),s.appendChild(k));const c=n.createElement("button");c.type="button",c.innerHTML=j.maximize,c.setAttribute("aria-label","Maximize (F)"),wireTooltip(c),Object.assign(c.style,C),wireControlHover(c),c.addEventListener("click",()=>w(!l));const r=n.createElement("button");r.type="button",r.innerHTML=j.close,r.setAttribute("aria-label","Close (Esc)"),wireTooltip(r),Object.assign(r.style,C),wireControlHover(r),r.addEventListener("click",z);const h=e.maximizable!==!1;h&&s.appendChild(c),s.appendChild(r);let l=!1,L="",g="";function w(f){l=f,c.innerHTML=l?j.minimize:j.maximize,c.setAttribute("aria-label",l?"Restore (F)":"Maximize (F)"),y&&(y.style.display=l?"none":""),v.style.display=l?"none":"block",l?(i.style.borderRadius="0",i.style.width="100vw",i.style.height="100vh",t||(L=i.style.top,g=i.style.left,i.style.top="0",i.style.left="0")):(i.style.borderRadius="12px",i.style.width=p,i.style.height=u,t||(i.style.top=L,i.style.left=g)),e.onMaximizeChange?.(l,i)}let x=!1,O="",W="";const S=220;function A(f){x=f,y.innerHTML=x?j.uncollapse:j.collapse,y.setAttribute("aria-label",x?"Show contents":"Collapse"),v.style.display=x?"none":"block",x?(O=i.style.height,W=i.style.width,i.style.minHeight="0",i.style.height="auto",i.style.minWidth="0",i.style.width=`${S}px`,c.disabled=!0,c.style.opacity="0.4",c.style.cursor="default",F.style.display="none"):(i.style.minHeight="240px",i.style.height=O||u,i.style.minWidth="320px",i.style.width=W||p,c.disabled=!1,c.style.opacity="1",c.style.cursor="pointer",F.style.display="flex")}function T(){const f=n.body.style.userSelect;return n.body.style.userSelect="none",()=>{n.body.style.userSelect=f}}t||(s.style.cursor="move",s.addEventListener("pointerdown",f=>{if(l||f.target.closest('button, [role="button"]'))return;f.preventDefault();const B=T(),D=f.clientX,H=f.clientY,$=i.offsetTop,N=i.offsetLeft,q=o.innerHeight-s.offsetHeight,V=o.innerWidth-40,_=40-i.offsetWidth;s.setPointerCapture(f.pointerId);const Y=G=>{const ie=Math.min(Math.max($+(G.clientY-H),0),q),ge=Math.min(Math.max(N+(G.clientX-D),_),V);i.style.top=`${ie}px`,i.style.left=`${ge}px`},Z=G=>{B(),s.releasePointerCapture(G.pointerId),s.removeEventListener("pointermove",Y),s.removeEventListener("pointerup",Z)};s.addEventListener("pointermove",Y),s.addEventListener("pointerup",Z)}));const I='button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"]),[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';function M(f){const B=Array.from(i.querySelectorAll(I)).filter(N=>N.offsetParent!==null||N===n.activeElement);if(B.length===0){f.preventDefault(),i.focus();return}const D=B[0],H=B[B.length-1],$=n.activeElement;f.shiftKey&&($===D||!i.contains($))?(f.preventDefault(),H.focus()):!f.shiftKey&&$===H&&(f.preventDefault(),D.focus())}const R=f=>{if(f.key==="Escape"){f.defaultPrevented||z();return}if(t&&(f.key==="e"||f.key==="E")){z();return}if(t&&f.key==="Tab"){M(f);return}h&&(f.key==="f"||f.key==="F")&&!x&&w(!l)};function z(){t?n.removeEventListener("keydown",R):i.removeEventListener("keydown",R),oe.remove(),xe(),hideTooltip(n),reparentTooltip(n.body),d?d.remove():i.remove(),t&&(n.body.style.overflow=a),b?.focus?.(),e.onClose()}function P(){t||(i.style.zIndex=String(me()))}const F=n.createElement("div");Object.assign(F.style,{flex:"1",minHeight:"0",minWidth:"0",display:"flex",overflow:"hidden"});const v=n.createElement("div");v.tabIndex=0,v.setAttribute("role","separator"),v.setAttribute("aria-label","Resize window (arrow keys, or drag)"),Object.assign(v.style,{position:"absolute",right:"0",bottom:"0",width:"16px",height:"16px",cursor:"nwse-resize",touchAction:"none"}),v.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>',v.style.color=CLR.label;const U=320,K=240,J=20;function ee(f,B){const D=o.innerWidth-i.offsetLeft,H=o.innerHeight-i.offsetTop,$=Math.min(Math.max(i.offsetWidth+f,U),D),N=Math.min(Math.max(i.offsetHeight+B,K),H);i.style.width=`${$}px`,i.style.height=`${N}px`}v.addEventListener("keydown",f=>{if(!(l||x))switch(f.key){case"ArrowRight":f.preventDefault(),ee(J,0);break;case"ArrowLeft":f.preventDefault(),ee(-J,0);break;case"ArrowDown":f.preventDefault(),ee(0,J);break;case"ArrowUp":f.preventDefault(),ee(0,-J);break}}),v.addEventListener("pointerdown",f=>{if(l||x)return;f.preventDefault();const B=T(),D=f.clientX,H=f.clientY,$=i.offsetWidth,N=i.offsetHeight,q=o.innerWidth-i.offsetLeft,V=o.innerHeight-i.offsetTop;v.setPointerCapture(f.pointerId);const _=Z=>{const G=Math.min(Math.max($+(Z.clientX-D),U),q),ie=Math.min(Math.max(N+(Z.clientY-H),K),V);i.style.width=`${G}px`,i.style.height=`${ie}px`},Y=Z=>{B(),v.releasePointerCapture(Z.pointerId),v.removeEventListener("pointermove",_),v.removeEventListener("pointerup",Y)};v.addEventListener("pointermove",_),v.addEventListener("pointerup",Y)}),i.appendChild(s),i.appendChild(F),i.appendChild(v);const ne=e.anchor?overlayRootFor(e.anchor):n.body;d?(d.appendChild(i),ne.appendChild(d)):ne.appendChild(i);const xe=Pe(n,ne),oe=n.createElement("style");oe.textContent=`@media print{
1
+ import{getUniqueTestNumbers as we}from"../renderer/buildView.js";import{dieHasValues as ke}from"../core/dieTable.js";import{dieHasTestData as Ee}from"../renderer/buildWaferMap.js";import{testLabel as ae,isDerivedTest as Ce,DERIVED_MARK as ce,DERIVED_KEY as de}from"../renderer/testLabel.js";import{prettyKey as Le}from"../core/utils.js";import{diagnoseMpwLayout as Ae,formatMpwDiagnostics as Me}from"../core/compact.js";import{listBinColorSchemes as Se,listValueColorSchemes as Be}from"../renderer/colorSchemes.js";import{ICONS as j}from"./icons.js";import{WMAP_VERSION as ue,WMAP_BUILD_TIME as De}from"./version.js";let pe=!1;export function logWmapVersionOnce(){pe||(pe=!0,console.log(`[wmap] v${ue} (built ${De})`))}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})`,Q="var(--wmap-font-size, 12px)",Te="var(--wmap-density, 1)",X=e=>`calc(${e}px * ${Te})`;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:X(2),xs:X(4),sm:X(6),md:X(8),lg:X(10),xl:X(12),xxl:X(16),xxxl:X(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(${Q} - 1px)`,body:Q,sub:`calc(${Q} + 1px)`,heading:`calc(${Q} + 3px)`,stat:`calc(${Q} + 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(),a=o?parseFloat(o):NaN;return(Number.isFinite(a)?a: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 a=n.getPropertyValue(`--wmap-${o}`).trim();a&&t.style.setProperty(`--wmap-${o}`,a)}}export function syncWmapPopupTheme(e,t,n){const o=()=>{copyWmapThemeTokens(e,t),n?.()},a=new window.MutationObserver(o);a.observe(e,{attributes:!0,attributeFilter:["style","class"]}),a.observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]});const d=window.matchMedia("(prefers-color-scheme: dark)");return d.addEventListener("change",o),()=>{a.disconnect(),d.removeEventListener("change",o)}}let re=null;export function setDetachWindowOpener(e){re=e}export function openDetachWindow(e){return re?re(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 markNoPrint(e){e.setAttribute("data-wmap-noprint","1");const t=e.ownerDocument;if(!t.getElementById("wmap-noprint-style")){const n=t.createElement("style");n.id="wmap-noprint-style",n.textContent="@media print{[data-wmap-noprint]{display:none!important}}",t.head.appendChild(n)}}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=Me(Ae(e,t),ue),a=n.anchor.ownerDocument,d=openModal({title:"Layout diagnostics",anchor:n.anchor,ownerDocument:a,onClose:()=>{},boxSize:{width:"min(680px, 94vw)",height:"min(480px, 90vh)"}}),b=d.contentWrap;Object.assign(b.style,{flexDirection:"column",padding:"14px 16px",gap:"10px",boxSizing:"border-box"});const i=a.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 p=a.createElement("textarea");p.value=o,p.readOnly=!0,p.setAttribute("aria-label","Layout diagnostics"),Object.assign(p.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 u=a.createElement("div");Object.assign(u.style,{display:"flex",gap:"8px",alignItems:"center"});const s=a.createElement("span");s.setAttribute("role","status"),Object.assign(s.style,{fontSize:FONT.body,color:CLR.text});const C=(k,c)=>{const r=a.createElement("button");return r.type="button",r.textContent=k,Object.assign(r.style,controlStyle("outlined"),{padding:"5px 12px",color:CLR.text}),wireControlHover(r,"outlined"),r.addEventListener("click",c),r},m=C("Copy",()=>{const k=a.defaultView,c=()=>{p.focus(),p.select();let r=!1;try{r=a.execCommand("copy")}catch{r=!1}s.textContent=r?"Copied":"Copying is not available here. Select the text, or save it as a file."};k?.navigator.clipboard?k.navigator.clipboard.writeText(o).then(()=>{s.textContent="Copied"},c):c()}),y=C("Save as file",()=>{saveTextFile(o,"wafermap-layout-diagnostics.txt","text/plain",n.onSaveText),s.textContent=n.onSaveText?"":"Saved"});return u.append(m,y,s),b.append(i,p,u),p.focus(),p.select(),d}export function saveTextFile(e,t,n,o){if(o){o(e,t,n);return}downloadBlob(typeof e=="string"?new Blob([e],{type:n}):e,t)}const He='[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 a=t();if(a.length===0)return;const d=e.ownerDocument.activeElement,b=d?a.indexOf(d):-1;switch(o.key){case"ArrowDown":o.preventDefault(),a[b<0||b===a.length-1?0:b+1].focus();break;case"ArrowUp":o.preventDefault(),a[b<=0?a.length-1:b-1].focus();break;case"Home":o.preventDefault(),a[0].focus();break;case"End":o.preventDefault(),a[a.length-1].focus();break;case"Enter":case" ":b>=0&&(o.preventDefault(),a[b].click());break;case"Escape":case"Tab":o.preventDefault(),n();break}})}function te(e,t,n){const o=()=>Array.from(e.querySelectorAll(He));wireListNavigation(e,o,()=>{n(),t?.focus()});const a=o()[0];a&&nextFrame(()=>a.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 a=e.ownerDocument.createElement("div");return a.dataset.wmapMenuLayer="1",Object.assign(a.style,{position:"fixed",inset:"0",zIndex:Z_MENU,pointerEvents:"none"}),t.appendChild(a),fe.set(t,a),a}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,a={}){const d=menuLayerFor(t);e.parentElement!==d&&d.appendChild(e);const b=e.ownerDocument.defaultView??window;e.style.left="0",e.style.top="0";const i=e.offsetWidth,p=e.offsetHeight,u=8,s=b.innerWidth,C=b.innerHeight;let m=n+14,y=o-8;m+i+u>s&&(m=n-i-6);const k=t.getBoundingClientRect();if(!a.followPointer&&k.height>0&&k.height<=C*.4&&y<k.bottom&&y+p>k.top&&m<k.right&&m+i>k.left){const h=k.bottom+u,l=k.top-p-u;h+p+u<=C?y=h:l>=u&&(y=l)}y+p+u>C&&(y=C-p-u),y<u&&(y=u),e.style.left=`${m}px`,e.style.top=`${y}px`}export function wireTooltip(e,t,n={}){const o=()=>(typeof t=="function"?t():t)??e.getAttribute("aria-label")??"";typeof t=="string"&&(e.dataset.wmapTip=t),n.asDataPoint&&(e.tabIndex=0,e.setAttribute("role","img"),typeof t=="string"&&e.setAttribute("aria-label",t));const a=b=>{const i=o();if(!i)return;const p=getTooltip(e.ownerDocument);if(p.textContent=i,p.style.display="block",b)positionTooltip(p,e,b.clientX,b.clientY);else{const u=e.getBoundingClientRect();positionTooltip(p,e,u.left+u.width/2,u.top)}},d=()=>hideTooltip(e.ownerDocument);e.addEventListener("mousemove",a),e.addEventListener("mouseleave",d),e.addEventListener("focus",()=>a()),e.addEventListener("blur",d)}export function buildDataModeEntries(e,t,n){const o=e.some(Ee),a=e.some(ke),d=e.some(s=>s.hbin!=null),b=e.some(s=>s.sbin!=null),i=o?t!==void 0?t.map(s=>({plotMode:"value",activeTest:s.testNumber,label:s.unit?`${ae(s,s.testNumber)} (${s.unit})`:ae(s,s.testNumber),logScale:s.logScale,...Ce(s)?{derived:!0}:{}})):we(e).map(s=>({plotMode:"value",activeTest:s,label:ae(void 0,s)})):[],p=[...d?[{plotMode:"hardBin",label:MODE_LABELS.hardBin}]:[],...b?[{plotMode:"softBin",label:MODE_LABELS.softBin}]:[]],u=n.includeStacked?[...a?[{plotMode:"stackedValues",label:MODE_LABELS.stackedValues}]:[],...d?[{plotMode:"stackedBins",label:MODE_LABELS.stackedBins}]:[],...b?[{plotMode:"stackedSoftBins",label:MODE_LABELS.stackedSoftBins}]:[]]:[];return{testEntries:i,binEntries:p,stackedEntries:u}}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",a=>a.stopPropagation()),o.addEventListener("mousedown",a=>a.stopPropagation()),o.addEventListener("keydown",a=>a.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,a,d,b,i,p=window,u=[]){const{makeMenuRow:s,makeMenuSection:C}=b,m=document.createElement("div"),y=180,c=e.left+y<=(p.innerWidth??1/0)?e.left:Math.max(4,e.right-y);if(Object.assign(m.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:`${y}px`,padding:"4px 0",pointerEvents:"auto"}),t.length)if(m.appendChild(C("Test Value")),t.length<=INLINE_TEST_LIMIT)for(const r of t)m.appendChild(s(r.label,a(r),!0,h=>{h.stopPropagation(),d(r,m)}));else{const r=i==="value",h=s(MODE_LABELS.value+" \u25B6",r,!1,A=>{A.stopPropagation(),g(),S(),A.detail===0&&O()});h.setAttribute("aria-haspopup","menu"),h.style.display="flex",h.style.justifyContent="space-between",h.style.alignItems="center";let l=null,L=null;const g=()=>{L!==null&&(clearTimeout(L),L=null)},w=A=>{const T=A.target;T&&(h.contains(T)||l?.contains(T))||x()},x=()=>{g(),l?.remove(),l=null,p.document.removeEventListener("click",w),h.setAttribute("aria-expanded","false")},O=()=>{const A=l?.querySelector('input, [role="menuitemradio"]');A&&nextFrame(()=>A.focus(),p)},W=()=>{g(),L=setTimeout(x,300)},S=()=>{if(l)return;const A=h.getBoundingClientRect(),T=160,I=320,R=A.right+2+T<=(p.innerWidth??1/0)?A.right+2:Math.max(4,A.left-2-T),z=Math.min(A.top-4,Math.max(4,(p.innerHeight??1/0)-I-4));if(l=document.createElement("div"),l.setAttribute("data-wmap-submenu",""),l.setAttribute("role","menu"),Object.assign(l.style,{position:"fixed",top:`${z}px`,left:`${R}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_ABOVE,minWidth:`${T}px`,maxHeight:`${I}px`,overflowY:"auto",padding:"4px 0",pointerEvents:"auto"}),t.length>MENU_SEARCH_THRESHOLD){const v=makeMenuSearchBox(U=>{for(const K of P)K.row.style.display=K.label.includes(U)?"":"none"},"Filter tests\u2026");Object.assign(v.style,{position:"sticky",top:"0",zIndex:"1",background:CLR.menuBg}),l.appendChild(v)}const P=[],F=t.some(v=>v.derived);for(const v of t){const U=s(v.label,a(v),!1,K=>{K.stopPropagation(),x(),d(v,m)},F?{derived:v.derived===!0}:void 0);P.push({row:U,label:v.label.toLowerCase()}),l.appendChild(U)}if(F){const v=p.document.createElement("div");v.setAttribute("role","presentation"),v.textContent=`${ce} ${de}`,Object.assign(v.style,{padding:"6px 14px",fontSize:FONT.meta,color:CLR.label,borderTop:`1px solid ${CLR.menuBorder}`,marginTop:"4px",whiteSpace:"nowrap"}),l.appendChild(v)}l.addEventListener("mouseenter",g),l.addEventListener("mouseleave",W),wireListNavigation(l,()=>P.filter(v=>v.row.style.display!=="none").map(v=>v.row),()=>{x(),h.focus()}),(m.parentElement??p.document.body).appendChild(l),p.document.addEventListener("click",w),h.setAttribute("aria-expanded","true")};m.addEventListener("keydown",A=>{A.key==="Escape"&&x()}),h.addEventListener("mouseenter",()=>{g(),S()}),h.addEventListener("mouseleave",W),m.appendChild(h)}if(n.length){m.appendChild(C("Bins"));for(const r of n)m.appendChild(s(r.label,a(r),!1,h=>{h.stopPropagation(),d(r,m)}))}if(u.length){m.appendChild(C("Metadata"));for(const r of u)m.appendChild(s(r.label,a(r),!1,h=>{h.stopPropagation(),d(r,m)}))}if(o.length){m.appendChild(C("Lot Aggregation"));for(const r of o)m.appendChild(s(r.label,a(r),!1,h=>{h.stopPropagation(),d(r,m)}))}return m.setAttribute("role","menu"),m.setAttribute("aria-label","Plot mode"),m}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 a(u){o!==u&&(o=u,t(o))}function d(){a(!1)}function b(){a(!o),o&&n.addEventListener("click",d,{once:!0})}const i=u=>{u.stopPropagation(),b()},p=u=>{u.key==="Enter"||u.key===" "?(u.preventDefault(),b()):u.key==="Escape"&&d()};return e.setAttribute("role","button"),e.tabIndex<0&&(e.tabIndex=0),e.addEventListener("click",i),e.addEventListener("keydown",p),{isOpen:()=>o,close:d,destroy(){e.removeEventListener("click",i),e.removeEventListener("keydown",p),n.removeEventListener("click",d)}}}export function buildCheckMenuEl(e,t,n,o=window){const{makeMenuSection:a}=n,d=o.document,b=d.createElement("div"),i=168,u=e.left+i<=(o.innerWidth??1/0)?e.left:Math.max(4,e.right-i);Object.assign(b.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:`${i}px`,padding:"4px 0",pointerEvents:"auto"});for(const s of t)if("section"in s)b.appendChild(a(s.section));else{const C=s.enabled!==!1;if(!C&&!s.disabledHint)continue;const m=d.createElement("div");s.action?m.setAttribute("role","menuitem"):(m.setAttribute("role","menuitemcheckbox"),m.setAttribute("aria-checked",s.active?"true":"false")),m.tabIndex=-1,C||(m.setAttribute("aria-disabled","true"),wireTooltip(m,s.disabledHint)),Object.assign(m.style,{display:"flex",alignItems:"center",gap:SPACE.sm,padding:"6px 14px",fontSize:FONT.body,cursor:C?"pointer":"default",color:C?s.active?CLR.iconActive:CLR.text:CLR.label,fontWeight:s.active?"700":"400",background:s.active?CLR.menuActive:"transparent",whiteSpace:"nowrap"});const y=d.createElement("span");Object.assign(y.style,{width:"12px",flexShrink:"0",color:CLR.iconActive,visibility:s.active?"visible":"hidden"}),y.textContent=s.action?"":"\u2713",y.setAttribute("aria-hidden","true");const k=d.createElement("span");k.textContent=s.label,m.appendChild(y),m.appendChild(k),C?(m.addEventListener("mouseenter",()=>{s.active||(m.style.background=CLR.menuHover)}),m.addEventListener("mouseleave",()=>{m.style.background=s.active?CLR.menuActive:"transparent"}),m.addEventListener("focus",()=>{s.active||(m.style.background=CLR.menuHover)}),m.addEventListener("blur",()=>{m.style.background=s.active?CLR.menuActive:"transparent"}),m.addEventListener("click",c=>{c.stopPropagation(),s.onClick(c)})):m.addEventListener("click",c=>{c.stopPropagation()}),b.appendChild(m)}return b}export function createToolbarHelpers(e){const t=e.ownerDocument;let n=null;const o=c=>menuLayerFor(c);function a(c,r,h){const l=t.createElement("button");return l.innerHTML=j[c],l.type="button",l.ariaLabel=r,Object.assign(l.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"}),l.addEventListener("mouseenter",L=>{l.dataset.active||(l.style.background=CLR.bgHover,l.style.color=CLR.iconHover),e.textContent=l.ariaLabel??r,e.style.display="block",positionTooltip(e,l,L.clientX,L.clientY)}),l.addEventListener("mousemove",L=>{e.style.display==="block"&&positionTooltip(e,l,L.clientX,L.clientY)}),l.addEventListener("mouseleave",()=>{l.dataset.active||(l.style.background="transparent",l.style.color=CLR.icon),e.style.display="none"}),l.addEventListener("click",()=>{e.style.display="none",h()}),l}function d(c,r){r?(c.dataset.active="1",c.style.background=CLR.bgActive,c.style.color=CLR.iconActive):(delete c.dataset.active,c.style.background="transparent",c.style.color=CLR.icon)}function b(){const c=t.createElement("div");return Object.assign(c.style,{width:"1px",height:"18px",background:CLR.separator,margin:"0 2px",flexShrink:"0"}),c.dataset.wmapSep="1",c}function i(c){let r=!1,h=null;for(const l of Array.from(c.children))l.dataset.wmapSep?r&&!h?h=l:l.style.display="none":l.style.display!=="none"&&(h&&(h.style.display="",h=null),r=!0);h&&(h.style.display="none")}function p(c){for(const r of Array.from(c.children))if(!(r.dataset.wmapSep||r.style.display==="none"))if(r.tagName==="DIV"&&!r.getAttribute("role")&&r.children.length){if(p(r))return!0}else return!0;return!1}function u(c,r){c.style.display=p(c)?r:"none"}function s(c,r,h,l,L){const g=t.createElement("div");if(L){const w=t.createElement("span");w.textContent=L.derived?ce:"",w.setAttribute("aria-hidden","true"),Object.assign(w.style,{display:"inline-block",width:"1.1em"}),g.append(w,c),L.derived&&g.setAttribute("aria-label",`${c} \u2014 ${de.toLowerCase()}`)}else g.textContent=c;return g.setAttribute("role","menuitemradio"),g.setAttribute("aria-checked",r?"true":"false"),g.tabIndex=-1,Object.assign(g.style,{padding:`6px 14px 6px ${h?"26px":"14px"}`,fontSize:FONT.body,cursor:"pointer",color:r?CLR.iconActive:CLR.text,fontWeight:r?"700":"400",background:r?CLR.menuActive:"transparent",whiteSpace:"nowrap"}),g.addEventListener("mouseenter",()=>{r||(g.style.background=CLR.menuHover)}),g.addEventListener("mouseleave",()=>{g.style.background=r?CLR.menuActive:"transparent"}),g.addEventListener("focus",()=>{r||(g.style.background=CLR.menuHover)}),g.addEventListener("blur",()=>{g.style.background=r?CLR.menuActive:"transparent"}),g.addEventListener("click",l),g}function C(c){const r=t.createElement("div");return r.textContent=c,r.setAttribute("role","presentation"),Object.assign(r.style,{padding:"5px 14px 2px",fontSize:FONT.body,fontWeight:"600",letterSpacing:TRACKING,color:CLR.label,textTransform:"uppercase",pointerEvents:"none",userSelect:"none"}),r}function m(c,r,h,l,L){const g=()=>{n&&(n.remove(),n=null),w.setAttribute("aria-expanded","false")},w=a(c,r,()=>{if(n){g();return}const x=t.createElement("div"),O=w.getBoundingClientRect(),W=w.ownerDocument.defaultView??window,S=148,T=O.left+S<=(W.innerWidth??1/0)?O.left:Math.max(4,O.right-S);Object.assign(x.style,{position:"fixed",top:`${O.bottom+4}px`,left:`${T}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_BASE,minWidth:`${S}px`,padding:"4px 0",pointerEvents:"auto"});for(const I of h()){const M=t.createElement("div");M.textContent=I.label,M.dataset.wmapDropdownValue=I.value;const R=I.value===l();M.setAttribute("role","menuitemradio"),M.setAttribute("aria-checked",R?"true":"false"),M.tabIndex=-1,Object.assign(M.style,{padding:"6px 14px",fontSize:FONT.body,cursor:"pointer",color:R?CLR.iconActive:CLR.text,fontWeight:R?"700":"400",background:R?CLR.menuActive:"transparent",whiteSpace:"nowrap"});const z=()=>{I.value!==l()&&(M.style.background=CLR.menuHover)},P=()=>{M.style.background=I.value===l()?CLR.menuActive:"transparent"};M.addEventListener("mouseenter",z),M.addEventListener("mouseleave",P),M.addEventListener("focus",z),M.addEventListener("blur",P),M.addEventListener("click",F=>{F.stopPropagation(),L(I.value),g()}),x.appendChild(M)}x.setAttribute("role","menu"),x.setAttribute("aria-label",r),o(w).appendChild(x),n=x,w.setAttribute("aria-expanded","true"),te(x,w,g)});return w.setAttribute("aria-haspopup","menu"),w.setAttribute("aria-expanded","false"),w}function y(c,r,h,l){function L(){return buildCheckMenuEl(w.getBoundingClientRect(),h().map(x=>"section"in x?x:{...x,onClick:O=>{x.closeMenu&&g(),x.onClick(O),l(w);const W=n;if(!W)return;const S=L();S.setAttribute("role","menu"),S.setAttribute("aria-label",r),W.replaceWith(S),n=S,te(S,w,g)}}),{makeMenuSection:C},w.ownerDocument.defaultView??window)}const g=()=>{n&&(n.remove(),n=null),w.setAttribute("aria-expanded","false")},w=a(c,r,()=>{if(n){g();return}const x=L();x.setAttribute("role","menu"),x.setAttribute("aria-label",r),o(w).appendChild(x),n=x,w.setAttribute("aria-expanded","true"),te(x,w,g)});return w.setAttribute("aria-haspopup","menu"),w.setAttribute("aria-expanded","false"),l(w),w}function k(c){const r=c.target?.closest?.("[data-wmap-submenu]");if(n&&!n.contains(c.target)&&!r&&(n.remove(),n=null,c.target?.getAttribute?.("aria-haspopup")!=="menu"))for(const l of document.querySelectorAll('[aria-haspopup="menu"][aria-expanded="true"]'))l.setAttribute("aria-expanded","false")}return{makeBtn:a,setActive:d,makeSep:b,syncSeparators:i,syncToolbarVisible:u,makeMenuRow:s,makeMenuSection:C,makeDropdown:m,makeCheckMenuBtn:y,closeOpenMenu:k,getOpenMenu:()=>n,setOpenMenu:c=>{n=c}}}const Oe=7e3;let Ie=0;function me(){return Oe+ ++Ie}const Re=32,$e=6;let We=0;function ze(){return We++%$e*Re}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 be(e){const t=e.mode==="modal",n=e.ownerDocument??document,o=n.defaultView??window,a=n.body.style.overflow;t&&(n.body.style.overflow="hidden");let d=null;t&&(d=n.createElement("div"),d.id="wmap-modal-backdrop",Object.assign(d.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 b=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 p=e.boxSize?.width??"min(90vw, 700px)",u=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:p,height:u,boxShadow:SHADOW.modal,minWidth:"320px",minHeight:"240px",maxWidth:"100vw",maxHeight:"100vh",zIndex:t?Z_ABOVE2:String(me())}),!t){const f=ze();Object.assign(i.style,{position:"fixed",top:`${Math.round(o.innerHeight*.08)+f}px`,left:`${Math.round(o.innerWidth*.08)+f}px`})}const s=n.createElement("div");Object.assign(s.style,{display:"flex",alignItems:"center",gap:SPACE.sm,padding:"10px 14px",borderBottom:`1px solid ${CLR.menuBorder}`,flexShrink:"0"});const C={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 f=n.createElement("span");f.textContent=e.title,f.title=e.title,f.dataset.wmapWindowTitle="1",Object.assign(f.style,{fontWeight:"700",fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"}),s.appendChild(f)}const m=n.createElement("div");m.style.flex="1",s.appendChild(m);let y=null;t||(y=n.createElement("button"),y.type="button",y.innerHTML=j.collapse,y.setAttribute("aria-label","Collapse"),wireTooltip(y),Object.assign(y.style,C),wireControlHover(y),y.addEventListener("click",()=>A(!x)),s.appendChild(y));let k=null;e.printable&&(k=n.createElement("button"),k.type="button",k.innerHTML=j.print,k.setAttribute("aria-label","Print / Save as PDF"),wireTooltip(k),Object.assign(k.style,C),wireControlHover(k),k.addEventListener("click",()=>{typeof e.printable=="function"?e.printable():o.print()}),s.appendChild(k));const c=n.createElement("button");c.type="button",c.innerHTML=j.maximize,c.setAttribute("aria-label","Maximize (F)"),wireTooltip(c),Object.assign(c.style,C),wireControlHover(c),c.addEventListener("click",()=>w(!l));const r=n.createElement("button");r.type="button",r.innerHTML=j.close,r.setAttribute("aria-label","Close (Esc)"),wireTooltip(r),Object.assign(r.style,C),wireControlHover(r),r.addEventListener("click",z);const h=e.maximizable!==!1;h&&s.appendChild(c),s.appendChild(r);let l=!1,L="",g="";function w(f){l=f,c.innerHTML=l?j.minimize:j.maximize,c.setAttribute("aria-label",l?"Restore (F)":"Maximize (F)"),y&&(y.style.display=l?"none":""),v.style.display=l?"none":"block",l?(i.style.borderRadius="0",i.style.width="100vw",i.style.height="100vh",t||(L=i.style.top,g=i.style.left,i.style.top="0",i.style.left="0")):(i.style.borderRadius="12px",i.style.width=p,i.style.height=u,t||(i.style.top=L,i.style.left=g)),e.onMaximizeChange?.(l,i)}let x=!1,O="",W="";const S=220;function A(f){x=f,y.innerHTML=x?j.uncollapse:j.collapse,y.setAttribute("aria-label",x?"Show contents":"Collapse"),v.style.display=x?"none":"block",x?(O=i.style.height,W=i.style.width,i.style.minHeight="0",i.style.height="auto",i.style.minWidth="0",i.style.width=`${S}px`,c.disabled=!0,c.style.opacity="0.4",c.style.cursor="default",F.style.display="none"):(i.style.minHeight="240px",i.style.height=O||u,i.style.minWidth="320px",i.style.width=W||p,c.disabled=!1,c.style.opacity="1",c.style.cursor="pointer",F.style.display="flex")}function T(){const f=n.body.style.userSelect;return n.body.style.userSelect="none",()=>{n.body.style.userSelect=f}}t||(s.style.cursor="move",s.addEventListener("pointerdown",f=>{if(l||f.target.closest('button, [role="button"]'))return;f.preventDefault();const B=T(),D=f.clientX,H=f.clientY,$=i.offsetTop,N=i.offsetLeft,q=o.innerHeight-s.offsetHeight,V=o.innerWidth-40,_=40-i.offsetWidth;s.setPointerCapture(f.pointerId);const Y=G=>{const ie=Math.min(Math.max($+(G.clientY-H),0),q),ge=Math.min(Math.max(N+(G.clientX-D),_),V);i.style.top=`${ie}px`,i.style.left=`${ge}px`},Z=G=>{B(),s.releasePointerCapture(G.pointerId),s.removeEventListener("pointermove",Y),s.removeEventListener("pointerup",Z)};s.addEventListener("pointermove",Y),s.addEventListener("pointerup",Z)}));const I='button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"]),[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';function M(f){const B=Array.from(i.querySelectorAll(I)).filter(N=>N.offsetParent!==null||N===n.activeElement);if(B.length===0){f.preventDefault(),i.focus();return}const D=B[0],H=B[B.length-1],$=n.activeElement;f.shiftKey&&($===D||!i.contains($))?(f.preventDefault(),H.focus()):!f.shiftKey&&$===H&&(f.preventDefault(),D.focus())}const R=f=>{if(f.key==="Escape"){f.defaultPrevented||z();return}if(t&&(f.key==="e"||f.key==="E")){z();return}if(t&&f.key==="Tab"){M(f);return}h&&(f.key==="f"||f.key==="F")&&!x&&w(!l)};function z(){t?n.removeEventListener("keydown",R):i.removeEventListener("keydown",R),oe.remove(),xe(),hideTooltip(n),reparentTooltip(n.body),d?d.remove():i.remove(),t&&(n.body.style.overflow=a),b?.focus?.(),e.onClose()}function P(){t||(i.style.zIndex=String(me()))}const F=n.createElement("div");Object.assign(F.style,{flex:"1",minHeight:"0",minWidth:"0",display:"flex",overflow:"hidden"});const v=n.createElement("div");v.tabIndex=0,v.setAttribute("role","separator"),v.setAttribute("aria-label","Resize window (arrow keys, or drag)"),Object.assign(v.style,{position:"absolute",right:"0",bottom:"0",width:"16px",height:"16px",cursor:"nwse-resize",touchAction:"none"}),v.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>',v.style.color=CLR.label;const U=320,K=240,J=20;function ee(f,B){const D=o.innerWidth-i.offsetLeft,H=o.innerHeight-i.offsetTop,$=Math.min(Math.max(i.offsetWidth+f,U),D),N=Math.min(Math.max(i.offsetHeight+B,K),H);i.style.width=`${$}px`,i.style.height=`${N}px`}v.addEventListener("keydown",f=>{if(!(l||x))switch(f.key){case"ArrowRight":f.preventDefault(),ee(J,0);break;case"ArrowLeft":f.preventDefault(),ee(-J,0);break;case"ArrowDown":f.preventDefault(),ee(0,J);break;case"ArrowUp":f.preventDefault(),ee(0,-J);break}}),v.addEventListener("pointerdown",f=>{if(l||x)return;f.preventDefault();const B=T(),D=f.clientX,H=f.clientY,$=i.offsetWidth,N=i.offsetHeight,q=o.innerWidth-i.offsetLeft,V=o.innerHeight-i.offsetTop;v.setPointerCapture(f.pointerId);const _=Z=>{const G=Math.min(Math.max($+(Z.clientX-D),U),q),ie=Math.min(Math.max(N+(Z.clientY-H),K),V);i.style.width=`${G}px`,i.style.height=`${ie}px`},Y=Z=>{B(),v.releasePointerCapture(Z.pointerId),v.removeEventListener("pointermove",_),v.removeEventListener("pointerup",Y)};v.addEventListener("pointermove",_),v.addEventListener("pointerup",Y)}),i.appendChild(s),i.appendChild(F),i.appendChild(v);const ne=e.anchor?overlayRootFor(e.anchor):n.body;d?(d.appendChild(i),ne.appendChild(d)):ne.appendChild(i);const xe=Pe(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}