@wafertools/wafermap 0.35.0 → 0.35.1

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 (60) hide show
  1. package/AGENTS.md +7 -1
  2. package/CHANGELOG.md +129 -0
  3. package/README.md +6 -3
  4. package/dist/packages/canvas-adapter/charts/boxplot.js +1 -1
  5. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  6. package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
  7. package/dist/packages/canvas-adapter/renderWaferGallery.js +1 -1
  8. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +14 -1
  9. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  10. package/dist/packages/canvas-adapter/summaryPanel.d.ts +31 -8
  11. package/dist/packages/canvas-adapter/summaryPanel.js +4 -2
  12. package/dist/packages/canvas-adapter/summaryToggle.d.ts +11 -0
  13. package/dist/packages/canvas-adapter/summaryToggle.js +1 -0
  14. package/dist/packages/canvas-adapter/toolbar.d.ts +8 -0
  15. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  16. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  17. package/dist/packages/canvas-adapter/userGuideHtml.js +37 -21
  18. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  19. package/dist/packages/canvas-adapter/version.js +1 -1
  20. package/dist/packages/canvas-adapter/warnings.js +1 -1
  21. package/dist/packages/core/classify.d.ts +5 -0
  22. package/dist/packages/core/classify.js +1 -1
  23. package/dist/packages/core/dieTable.d.ts +26 -0
  24. package/dist/packages/core/dieTable.js +1 -1
  25. package/dist/packages/core/passBins.d.ts +6 -0
  26. package/dist/packages/core/passBins.js +1 -1
  27. package/dist/packages/renderer/buildView.js +1 -1
  28. package/dist/packages/renderer/buildWaferMap.d.ts +32 -1
  29. package/dist/packages/renderer/buildWaferMap.js +1 -1
  30. package/dist/packages/renderer/spec.d.ts +4 -0
  31. package/dist/packages/renderer/spec.js +1 -1
  32. package/dist/packages/renderer/valueFilter.d.ts +55 -0
  33. package/dist/packages/renderer/valueFilter.js +1 -0
  34. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  35. package/dist/packages/stats/analyzeWaferMap.d.ts +44 -3
  36. package/dist/packages/stats/analyzeWaferMap.js +1 -1
  37. package/dist/packages/stats/capability.d.ts +5 -0
  38. package/dist/packages/stats/capability.js +1 -1
  39. package/dist/packages/stats/clusterDetection.js +1 -1
  40. package/dist/packages/stats/connectedComponents.d.ts +19 -0
  41. package/dist/packages/stats/connectedComponents.js +1 -1
  42. package/dist/packages/stats/lotPattern.js +1 -1
  43. package/dist/packages/stats/math.d.ts +25 -3
  44. package/dist/packages/stats/math.js +1 -1
  45. package/dist/packages/stats/patternClassification.d.ts +44 -18
  46. package/dist/packages/stats/patternClassification.js +1 -1
  47. package/dist/packages/stats/plotData.d.ts +11 -0
  48. package/dist/packages/stats/plotData.js +1 -1
  49. package/dist/packages/stats/regions.d.ts +6 -0
  50. package/dist/packages/stats/regions.js +1 -1
  51. package/dist/packages/stats/renderSummaryReport.js +33 -33
  52. package/dist/packages/stats/reportHtml.d.ts +7 -6
  53. package/dist/packages/stats/reportHtml.js +39 -37
  54. package/dist/packages/stats/synthesis.d.ts +44 -17
  55. package/dist/packages/stats/synthesis.js +1 -1
  56. package/dist/packages/stats/types.d.ts +12 -0
  57. package/llms.txt +2 -2
  58. package/package.json +1 -1
  59. package/dist/packages/canvas-adapter/summaryRail.d.ts +0 -7
  60. package/dist/packages/canvas-adapter/summaryRail.js +0 -1
@@ -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 R}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 k=(e,t)=>`var(--wmap-${e}, ${t})`,Q="var(--wmap-font-size, 12px)",Te="var(--wmap-density, 1)",F=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:F(2),xs:F(4),sm:F(6),md:F(8),lg:F(10),xl:F(12),xxl:F(16),xxxl:F(24)},SHADOW={panel:"0 1px 4px rgba(0,0,0,0.10)",menu:"0 4px 12px rgba(0,0,0,0.15)",modal:"0 20px 60px rgba(0,0,0,0.40)"},MOTION={fast:"0.12s ease",base:"0.2s ease"},LEADING={none:"1",tight:"1.2",base:"1.45"},ALPHA={muted:"0.85",disabled:"0.4"},TRACKING="0.05em",EDGE_GUTTER=SPACE.xl,MAP_CHROME_INSET=SPACE.xs,RADIUS={control:"4px",container:"6px",pill:"999px"},FONT={family:"var(--wmap-font-family, inherit)",meta:`calc(${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:k("icon","#506784"),iconHover:k("icon-hover","#2a3f5f"),iconActive:k("icon-active","#1a65ca"),bgHover:k("bg-hover","#edf0f8"),bgActive:k("bg-active","#dce8f8"),separator:k("separator","rgba(0,0,0,0.12)"),menuBg:k("surface","#fff"),menuBorder:k("border","rgba(0,0,0,0.12)"),controlBorder:k("control-border",k("border","rgba(0,0,0,0.30)")),menuHover:k("menu-hover","#f0f4fc"),menuActive:k("menu-active","#dce8f8"),canvasBg:`var(--wmap-canvas-bg, ${k("surface","#f5f5f5")})`,panelBg:k("panel-bg","#fafbfc"),label:k("text-muted","#647687"),value:k("text-strong","#1f2f43"),text:k("text","#333"),warnBg:k("warn-bg","#fffbe6"),warnBorder:k("warn-border","#f0c040"),warnText:k("warn-text","#7a5800"),errBg:k("err-bg","#fef2f2"),errBorder:k("err-border","#dc8a8a"),errText:k("err-text","#7a1c1c"),infoBg:k("info-bg","#dce8f8"),infoText:k("info-text","#334155"),findingHighlight:k("selected","#e07a20"),findingIndicator:k("finding-indicator","#b7551a"),barFill:k("bar-fill","#2a6fc0")};export function sevColor(e){return e==="unusual"?"#a84112":e==="notable"?"#8a6500":CLR.icon}export const ROTATIONS=[0,90,180,270],INLINE_TEST_LIMIT=6,MENU_SEARCH_THRESHOLD=8,DEFAULT_OVERLAY_Z=6e3,Z_BASE=`var(--wmap-z, ${DEFAULT_OVERLAY_Z})`,Z_ABOVE=`calc(var(--wmap-z, ${DEFAULT_OVERLAY_Z}) + 1)`,Z_MENU=`calc(var(--wmap-z, ${DEFAULT_OVERLAY_Z}) + 2)`,Z_ABOVE2=`calc(var(--wmap-z, ${DEFAULT_OVERLAY_Z}) + 3)`;export function applyOverlayZ(e){if(e==null)return()=>{};const t=document.documentElement,n=t.style.getPropertyValue("--wmap-z");return t.style.setProperty("--wmap-z",String(e)),()=>{n?t.style.setProperty("--wmap-z",n):t.style.removeProperty("--wmap-z")}}export function copyWmapThemeTokens(e,t){const n=getComputedStyle(e);for(const o of WMAP_TOKEN_NAMES){const 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 l=window.matchMedia("(prefers-color-scheme: dark)");return l.addEventListener("change",o),()=>{a.disconnect(),l.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,l=openModal({title:"Layout diagnostics",anchor:n.anchor,ownerDocument:a,onClose:()=>{},boxSize:{width:"min(680px, 94vw)",height:"min(480px, 90vh)"}}),x=l.contentWrap;Object.assign(x.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 f=a.createElement("textarea");f.value=o,f.readOnly=!0,f.setAttribute("aria-label","Layout diagnostics"),Object.assign(f.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=(y,p)=>{const b=a.createElement("button");return b.type="button",b.textContent=y,Object.assign(b.style,controlStyle("outlined"),{padding:"5px 12px",color:CLR.text}),wireControlHover(b,"outlined"),b.addEventListener("click",p),b},r=C("Copy",()=>{const y=a.defaultView,p=()=>{f.focus(),f.select();let b=!1;try{b=a.execCommand("copy")}catch{b=!1}s.textContent=b?"Copied":"Copying is not available here. Select the text, or save it as a file."};y?.navigator.clipboard?y.navigator.clipboard.writeText(o).then(()=>{s.textContent="Copied"},p):p()}),d=C("Save as file",()=>{saveTextFile(o,"wafermap-layout-diagnostics.txt","text/plain",n.onSaveText),s.textContent=n.onSaveText?"":"Saved"});return u.append(r,d,s),x.append(i,f,u),f.focus(),f.select(),l}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 l=e.ownerDocument.activeElement,x=l?a.indexOf(l):-1;switch(o.key){case"ArrowDown":o.preventDefault(),a[x<0||x===a.length-1?0:x+1].focus();break;case"ArrowUp":o.preventDefault(),a[x<=0?a.length-1:x-1].focus();break;case"Home":o.preventDefault(),a[0].focus();break;case"End":o.preventDefault(),a[a.length-1].focus();break;case"Enter":case" ":x>=0&&(o.preventDefault(),a[x].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 l=menuLayerFor(t);e.parentElement!==l&&l.appendChild(e);const x=e.ownerDocument.defaultView??window;e.style.left="0",e.style.top="0";const i=e.offsetWidth,f=e.offsetHeight,u=8,s=x.innerWidth,C=x.innerHeight;let r=n+14,d=o-8;r+i+u>s&&(r=n-i-6);const y=t.getBoundingClientRect();if(!a.followPointer&&y.height>0&&y.height<=C*.4&&d<y.bottom&&d+f>y.top&&r<y.right&&r+i>y.left){const h=y.bottom+u,c=y.top-f-u;h+f+u<=C?d=h:c>=u&&(d=c)}d+f+u>C&&(d=C-f-u),d<u&&(d=u),e.style.left=`${r}px`,e.style.top=`${d}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=x=>{const i=o();if(!i)return;const f=getTooltip(e.ownerDocument);if(f.textContent=i,f.style.display="block",x)positionTooltip(f,e,x.clientX,x.clientY);else{const u=e.getBoundingClientRect();positionTooltip(f,e,u.left+u.width/2,u.top)}},l=()=>hideTooltip(e.ownerDocument);e.addEventListener("mousemove",a),e.addEventListener("mouseleave",l),e.addEventListener("focus",()=>a()),e.addEventListener("blur",l)}export function buildDataModeEntries(e,t,n){const o=e.some(Ee),a=e.some(ke),l=e.some(s=>s.hbin!=null),x=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)})):[],f=[...l?[{plotMode:"hardBin",label:MODE_LABELS.hardBin}]:[],...x?[{plotMode:"softBin",label:MODE_LABELS.softBin}]:[]],u=n.includeStacked?[...a?[{plotMode:"stackedValues",label:MODE_LABELS.stackedValues}]:[],...l?[{plotMode:"stackedBins",label:MODE_LABELS.stackedBins}]:[],...x?[{plotMode:"stackedSoftBins",label:MODE_LABELS.stackedSoftBins}]:[]]:[];return{testEntries:i,binEntries:f,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,l,x,i,f=window,u=[]){const{makeMenuRow:s,makeMenuSection:C}=x,r=document.createElement("div"),d=180,p=e.left+d<=(f.innerWidth??1/0)?e.left:Math.max(4,e.right-d);if(Object.assign(r.style,{position:"fixed",top:`${e.bottom+4}px`,left:`${p}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_BASE,minWidth:`${d}px`,padding:"4px 0",pointerEvents:"auto"}),t.length)if(r.appendChild(C("Test Value")),t.length<=INLINE_TEST_LIMIT)for(const b of t)r.appendChild(s(b.label,a(b),!0,h=>{h.stopPropagation(),l(b,r)}));else{const b=i==="value",h=s(MODE_LABELS.value+" \u25B6",b,!1,g=>{g.stopPropagation(),L(),D(),g.detail===0&&Z()});h.setAttribute("aria-haspopup","menu"),h.style.display="flex",h.style.justifyContent="space-between",h.style.alignItems="center";let c=null,E=null;const L=()=>{E!==null&&(clearTimeout(E),E=null)},H=g=>{const A=g.target;A&&(h.contains(A)||c?.contains(A))||w()},w=()=>{L(),c?.remove(),c=null,f.document.removeEventListener("click",H),h.setAttribute("aria-expanded","false")},Z=()=>{const g=c?.querySelector('input, [role="menuitemradio"]');g&&nextFrame(()=>g.focus(),f)},N=()=>{L(),E=setTimeout(w,300)},D=()=>{if(c)return;const g=h.getBoundingClientRect(),A=160,_=320,$=g.right+2+A<=(f.innerWidth??1/0)?g.right+2:Math.max(4,g.left-2-A),j=Math.min(g.top-4,Math.max(4,(f.innerHeight??1/0)-_-4));if(c=document.createElement("div"),c.setAttribute("data-wmap-submenu",""),c.setAttribute("role","menu"),Object.assign(c.style,{position:"fixed",top:`${j}px`,left:`${$}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_ABOVE,minWidth:`${A}px`,maxHeight:`${_}px`,overflowY:"auto",padding:"4px 0",pointerEvents:"auto"}),t.length>MENU_SEARCH_THRESHOLD){const v=makeMenuSearchBox(Y=>{for(const X of V)X.row.style.display=X.label.includes(Y)?"":"none"},"Filter tests\u2026");Object.assign(v.style,{position:"sticky",top:"0",zIndex:"1",background:CLR.menuBg}),c.appendChild(v)}const V=[],W=t.some(v=>v.derived);for(const v of t){const Y=s(v.label,a(v),!1,X=>{X.stopPropagation(),w(),l(v,r)},W?{derived:v.derived===!0}:void 0);V.push({row:Y,label:v.label.toLowerCase()}),c.appendChild(Y)}if(W){const v=f.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"}),c.appendChild(v)}c.addEventListener("mouseenter",L),c.addEventListener("mouseleave",N),wireListNavigation(c,()=>V.filter(v=>v.row.style.display!=="none").map(v=>v.row),()=>{w(),h.focus()}),(r.parentElement??f.document.body).appendChild(c),f.document.addEventListener("click",H),h.setAttribute("aria-expanded","true")};r.addEventListener("keydown",g=>{g.key==="Escape"&&w()}),h.addEventListener("mouseenter",()=>{L(),D()}),h.addEventListener("mouseleave",N),r.appendChild(h)}if(n.length){r.appendChild(C("Bins"));for(const b of n)r.appendChild(s(b.label,a(b),!1,h=>{h.stopPropagation(),l(b,r)}))}if(u.length){r.appendChild(C("Metadata"));for(const b of u)r.appendChild(s(b.label,a(b),!1,h=>{h.stopPropagation(),l(b,r)}))}if(o.length){r.appendChild(C("Lot Aggregation"));for(const b of o)r.appendChild(s(b.label,a(b),!1,h=>{h.stopPropagation(),l(b,r)}))}return r.setAttribute("role","menu"),r.setAttribute("aria-label","Plot mode"),r}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 l(){a(!1)}function x(){a(!o),o&&n.addEventListener("click",l,{once:!0})}const i=u=>{u.stopPropagation(),x()},f=u=>{u.key==="Enter"||u.key===" "?(u.preventDefault(),x()):u.key==="Escape"&&l()};return e.setAttribute("role","button"),e.tabIndex<0&&(e.tabIndex=0),e.addEventListener("click",i),e.addEventListener("keydown",f),{isOpen:()=>o,close:l,destroy(){e.removeEventListener("click",i),e.removeEventListener("keydown",f),n.removeEventListener("click",l)}}}export function buildCheckMenuEl(e,t,n,o=window){const{makeMenuSection:a}=n,l=o.document,x=l.createElement("div"),i=168,u=e.left+i<=(o.innerWidth??1/0)?e.left:Math.max(4,e.right-i);Object.assign(x.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)x.appendChild(a(s.section));else{const C=s.enabled!==!1;if(!C&&!s.disabledHint)continue;const r=l.createElement("div");s.action?r.setAttribute("role","menuitem"):(r.setAttribute("role","menuitemcheckbox"),r.setAttribute("aria-checked",s.active?"true":"false")),r.tabIndex=-1,C||(r.setAttribute("aria-disabled","true"),wireTooltip(r,s.disabledHint)),Object.assign(r.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 d=l.createElement("span");Object.assign(d.style,{width:"12px",flexShrink:"0",color:CLR.iconActive,visibility:s.active?"visible":"hidden"}),d.textContent=s.action?"":"\u2713",d.setAttribute("aria-hidden","true");const y=l.createElement("span");y.textContent=s.label,r.appendChild(d),r.appendChild(y),C?(r.addEventListener("mouseenter",()=>{s.active||(r.style.background=CLR.menuHover)}),r.addEventListener("mouseleave",()=>{r.style.background=s.active?CLR.menuActive:"transparent"}),r.addEventListener("focus",()=>{s.active||(r.style.background=CLR.menuHover)}),r.addEventListener("blur",()=>{r.style.background=s.active?CLR.menuActive:"transparent"}),r.addEventListener("click",p=>{p.stopPropagation(),s.onClick(p)})):r.addEventListener("click",p=>{p.stopPropagation()}),x.appendChild(r)}return x}export function createToolbarHelpers(e){const t=e.ownerDocument;let n=null;const o=r=>menuLayerFor(r);function a(r,d,y){const p=t.createElement("button");return p.innerHTML=R[r],p.type="button",p.ariaLabel=d,Object.assign(p.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"}),p.addEventListener("mouseenter",b=>{p.dataset.active||(p.style.background=CLR.bgHover,p.style.color=CLR.iconHover),e.textContent=p.ariaLabel??d,e.style.display="block",positionTooltip(e,p,b.clientX,b.clientY)}),p.addEventListener("mousemove",b=>{e.style.display==="block"&&positionTooltip(e,p,b.clientX,b.clientY)}),p.addEventListener("mouseleave",()=>{p.dataset.active||(p.style.background="transparent",p.style.color=CLR.icon),e.style.display="none"}),p.addEventListener("click",()=>{e.style.display="none",y()}),p}function l(r,d){d?(r.dataset.active="1",r.style.background=CLR.bgActive,r.style.color=CLR.iconActive):(delete r.dataset.active,r.style.background="transparent",r.style.color=CLR.icon)}function x(){const r=t.createElement("div");return Object.assign(r.style,{width:"1px",height:"18px",background:CLR.separator,margin:"0 2px",flexShrink:"0"}),r}function i(r,d,y,p,b){const h=t.createElement("div");if(b){const c=t.createElement("span");c.textContent=b.derived?ce:"",c.setAttribute("aria-hidden","true"),Object.assign(c.style,{display:"inline-block",width:"1.1em"}),h.append(c,r),b.derived&&h.setAttribute("aria-label",`${r} \u2014 ${de.toLowerCase()}`)}else h.textContent=r;return h.setAttribute("role","menuitemradio"),h.setAttribute("aria-checked",d?"true":"false"),h.tabIndex=-1,Object.assign(h.style,{padding:`6px 14px 6px ${y?"26px":"14px"}`,fontSize:FONT.body,cursor:"pointer",color:d?CLR.iconActive:CLR.text,fontWeight:d?"700":"400",background:d?CLR.menuActive:"transparent",whiteSpace:"nowrap"}),h.addEventListener("mouseenter",()=>{d||(h.style.background=CLR.menuHover)}),h.addEventListener("mouseleave",()=>{h.style.background=d?CLR.menuActive:"transparent"}),h.addEventListener("focus",()=>{d||(h.style.background=CLR.menuHover)}),h.addEventListener("blur",()=>{h.style.background=d?CLR.menuActive:"transparent"}),h.addEventListener("click",p),h}function f(r){const d=t.createElement("div");return d.textContent=r,d.setAttribute("role","presentation"),Object.assign(d.style,{padding:"5px 14px 2px",fontSize:FONT.body,fontWeight:"600",letterSpacing:TRACKING,color:CLR.label,textTransform:"uppercase",pointerEvents:"none",userSelect:"none"}),d}function u(r,d,y,p,b){const h=()=>{n&&(n.remove(),n=null),c.setAttribute("aria-expanded","false")},c=a(r,d,()=>{if(n){h();return}const E=t.createElement("div"),L=c.getBoundingClientRect(),H=c.ownerDocument.defaultView??window,w=148,N=L.left+w<=(H.innerWidth??1/0)?L.left:Math.max(4,L.right-w);Object.assign(E.style,{position:"fixed",top:`${L.bottom+4}px`,left:`${N}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,boxShadow:SHADOW.menu,zIndex:Z_BASE,minWidth:`${w}px`,padding:"4px 0",pointerEvents:"auto"});for(const D of y()){const g=t.createElement("div");g.textContent=D.label,g.dataset.wmapDropdownValue=D.value;const A=D.value===p();g.setAttribute("role","menuitemradio"),g.setAttribute("aria-checked",A?"true":"false"),g.tabIndex=-1,Object.assign(g.style,{padding:"6px 14px",fontSize:FONT.body,cursor:"pointer",color:A?CLR.iconActive:CLR.text,fontWeight:A?"700":"400",background:A?CLR.menuActive:"transparent",whiteSpace:"nowrap"});const _=()=>{D.value!==p()&&(g.style.background=CLR.menuHover)},G=()=>{g.style.background=D.value===p()?CLR.menuActive:"transparent"};g.addEventListener("mouseenter",_),g.addEventListener("mouseleave",G),g.addEventListener("focus",_),g.addEventListener("blur",G),g.addEventListener("click",$=>{$.stopPropagation(),b(D.value),h()}),E.appendChild(g)}E.setAttribute("role","menu"),E.setAttribute("aria-label",d),o(c).appendChild(E),n=E,c.setAttribute("aria-expanded","true"),te(E,c,h)});return c.setAttribute("aria-haspopup","menu"),c.setAttribute("aria-expanded","false"),c}function s(r,d,y,p){function b(){return buildCheckMenuEl(c.getBoundingClientRect(),y().map(E=>"section"in E?E:{...E,onClick:L=>{E.closeMenu&&h(),E.onClick(L),p(c);const H=n;if(!H)return;const w=b();w.setAttribute("role","menu"),w.setAttribute("aria-label",d),H.replaceWith(w),n=w,te(w,c,h)}}),{makeMenuSection:f},c.ownerDocument.defaultView??window)}const h=()=>{n&&(n.remove(),n=null),c.setAttribute("aria-expanded","false")},c=a(r,d,()=>{if(n){h();return}const E=b();E.setAttribute("role","menu"),E.setAttribute("aria-label",d),o(c).appendChild(E),n=E,c.setAttribute("aria-expanded","true"),te(E,c,h)});return c.setAttribute("aria-haspopup","menu"),c.setAttribute("aria-expanded","false"),p(c),c}function C(r){const d=r.target?.closest?.("[data-wmap-submenu]");if(n&&!n.contains(r.target)&&!d&&(n.remove(),n=null,r.target?.getAttribute?.("aria-haspopup")!=="menu"))for(const p of document.querySelectorAll('[aria-haspopup="menu"][aria-expanded="true"]'))p.setAttribute("aria-expanded","false")}return{makeBtn:a,setActive:l,makeSep:x,makeMenuRow:i,makeMenuSection:f,makeDropdown:u,makeCheckMenuBtn:s,closeOpenMenu:C,getOpenMenu:()=>n,setOpenMenu:r=>{n=r}}}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 l=null;t&&(l=n.createElement("div"),l.id="wmap-modal-backdrop",Object.assign(l.style,{position:"fixed",inset:"0",background:"rgba(0,0,0,0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:Z_ABOVE,backdropFilter:"blur(3px)"}));const x=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 f=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:f,height:u,boxShadow:SHADOW.modal,minWidth:"320px",minHeight:"240px",maxWidth:"100vw",maxHeight:"100vh",zIndex:t?Z_ABOVE2:String(me())}),!t){const m=ze();Object.assign(i.style,{position:"fixed",top:`${Math.round(o.innerHeight*.08)+m}px`,left:`${Math.round(o.innerWidth*.08)+m}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 m=n.createElement("span");m.textContent=e.title,m.title=e.title,m.dataset.wmapWindowTitle="1",Object.assign(m.style,{fontWeight:"700",fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"}),s.appendChild(m)}const r=n.createElement("div");r.style.flex="1",s.appendChild(r);let d=null;t||(d=n.createElement("button"),d.type="button",d.innerHTML=R.collapse,d.setAttribute("aria-label","Collapse"),wireTooltip(d),Object.assign(d.style,C),wireControlHover(d),d.addEventListener("click",()=>g(!w)),s.appendChild(d));let y=null;e.printable&&(y=n.createElement("button"),y.type="button",y.innerHTML=R.print,y.setAttribute("aria-label","Print / Save as PDF"),wireTooltip(y),Object.assign(y.style,C),wireControlHover(y),y.addEventListener("click",()=>{typeof e.printable=="function"?e.printable():o.print()}),s.appendChild(y));const p=n.createElement("button");p.type="button",p.innerHTML=R.maximize,p.setAttribute("aria-label","Maximize (F)"),wireTooltip(p),Object.assign(p.style,C),wireControlHover(p),p.addEventListener("click",()=>H(!c));const b=n.createElement("button");b.type="button",b.innerHTML=R.close,b.setAttribute("aria-label","Close (Esc)"),wireTooltip(b),Object.assign(b.style,C),wireControlHover(b),b.addEventListener("click",j);const h=e.maximizable!==!1;h&&s.appendChild(p),s.appendChild(b);let c=!1,E="",L="";function H(m){c=m,p.innerHTML=c?R.minimize:R.maximize,p.setAttribute("aria-label",c?"Restore (F)":"Maximize (F)"),d&&(d.style.display=c?"none":""),v.style.display=c?"none":"block",c?(i.style.borderRadius="0",i.style.width="100vw",i.style.height="100vh",t||(E=i.style.top,L=i.style.left,i.style.top="0",i.style.left="0")):(i.style.borderRadius="12px",i.style.width=f,i.style.height=u,t||(i.style.top=E,i.style.left=L)),e.onMaximizeChange?.(c,i)}let w=!1,Z="",N="";const D=220;function g(m){w=m,d.innerHTML=w?R.uncollapse:R.collapse,d.setAttribute("aria-label",w?"Show contents":"Collapse"),v.style.display=w?"none":"block",w?(Z=i.style.height,N=i.style.width,i.style.minHeight="0",i.style.height="auto",i.style.minWidth="0",i.style.width=`${D}px`,p.disabled=!0,p.style.opacity="0.4",p.style.cursor="default",W.style.display="none"):(i.style.minHeight="240px",i.style.height=Z||u,i.style.minWidth="320px",i.style.width=N||f,p.disabled=!1,p.style.opacity="1",p.style.cursor="pointer",W.style.display="flex")}function A(){const m=n.body.style.userSelect;return n.body.style.userSelect="none",()=>{n.body.style.userSelect=m}}t||(s.style.cursor="move",s.addEventListener("pointerdown",m=>{if(c||m.target.closest('button, [role="button"]'))return;m.preventDefault();const M=A(),S=m.clientX,B=m.clientY,T=i.offsetTop,O=i.offsetLeft,q=o.innerHeight-s.offsetHeight,z=o.innerWidth-40,I=40-i.offsetWidth;s.setPointerCapture(m.pointerId);const P=K=>{const ie=Math.min(Math.max(T+(K.clientY-B),0),q),ge=Math.min(Math.max(O+(K.clientX-S),I),z);i.style.top=`${ie}px`,i.style.left=`${ge}px`},U=K=>{M(),s.releasePointerCapture(K.pointerId),s.removeEventListener("pointermove",P),s.removeEventListener("pointerup",U)};s.addEventListener("pointermove",P),s.addEventListener("pointerup",U)}));const _='button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"]),[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';function G(m){const M=Array.from(i.querySelectorAll(_)).filter(O=>O.offsetParent!==null||O===n.activeElement);if(M.length===0){m.preventDefault(),i.focus();return}const S=M[0],B=M[M.length-1],T=n.activeElement;m.shiftKey&&(T===S||!i.contains(T))?(m.preventDefault(),B.focus()):!m.shiftKey&&T===B&&(m.preventDefault(),S.focus())}const $=m=>{if(m.key==="Escape"){m.defaultPrevented||j();return}if(t&&(m.key==="e"||m.key==="E")){j();return}if(t&&m.key==="Tab"){G(m);return}h&&(m.key==="f"||m.key==="F")&&!w&&H(!c)};function j(){t?n.removeEventListener("keydown",$):i.removeEventListener("keydown",$),oe.remove(),xe(),hideTooltip(n),reparentTooltip(n.body),l?l.remove():i.remove(),t&&(n.body.style.overflow=a),x?.focus?.(),e.onClose()}function V(){t||(i.style.zIndex=String(me()))}const W=n.createElement("div");Object.assign(W.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 Y=320,X=240,J=20;function ee(m,M){const S=o.innerWidth-i.offsetLeft,B=o.innerHeight-i.offsetTop,T=Math.min(Math.max(i.offsetWidth+m,Y),S),O=Math.min(Math.max(i.offsetHeight+M,X),B);i.style.width=`${T}px`,i.style.height=`${O}px`}v.addEventListener("keydown",m=>{if(!(c||w))switch(m.key){case"ArrowRight":m.preventDefault(),ee(J,0);break;case"ArrowLeft":m.preventDefault(),ee(-J,0);break;case"ArrowDown":m.preventDefault(),ee(0,J);break;case"ArrowUp":m.preventDefault(),ee(0,-J);break}}),v.addEventListener("pointerdown",m=>{if(c||w)return;m.preventDefault();const M=A(),S=m.clientX,B=m.clientY,T=i.offsetWidth,O=i.offsetHeight,q=o.innerWidth-i.offsetLeft,z=o.innerHeight-i.offsetTop;v.setPointerCapture(m.pointerId);const I=U=>{const K=Math.min(Math.max(T+(U.clientX-S),Y),q),ie=Math.min(Math.max(O+(U.clientY-B),X),z);i.style.width=`${K}px`,i.style.height=`${ie}px`},P=U=>{M(),v.releasePointerCapture(U.pointerId),v.removeEventListener("pointermove",I),v.removeEventListener("pointerup",P)};v.addEventListener("pointermove",I),v.addEventListener("pointerup",P)}),i.appendChild(s),i.appendChild(W),i.appendChild(v);const ne=e.anchor?overlayRootFor(e.anchor):n.body;l?(l.appendChild(i),ne.appendChild(l)):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 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{
2
2
  body{overflow:visible!important;height:auto!important}
3
3
  body>*:not(.wmap-overlay-box):not(#wmap-modal-backdrop):not(.wmap-overlay-ancestor){display:none!important}
4
4
  #wmap-modal-backdrop{position:static!important;background:none!important;backdrop-filter:none!important;display:block!important}
@@ -6,4 +6,4 @@ body>*:not(.wmap-overlay-box):not(#wmap-modal-backdrop):not(.wmap-overlay-ancest
6
6
  .wmap-overlay-box>div:first-child{display:none!important}
7
7
  .wmap-overlay-box>div:nth-child(2){display:block!important;overflow:visible!important;height:auto!important;flex:none!important;min-height:0!important;min-width:0!important}
8
8
  .wmap-overlay-box>div:nth-child(3){display:none!important}
9
- }`,n.head.appendChild(oe),reparentTooltip(i),t?(l.addEventListener("click",m=>{m.target===l&&j()}),n.addEventListener("keydown",$)):(i.addEventListener("keydown",$),i.addEventListener("mousedown",V),V()),nextFrame(()=>(e.initialFocus?.()??(b.isConnected?b:i)).focus(),o);function ve(m){u=m,!c&&!w&&(i.style.height=m)}function ye(m){const M=()=>{};if(c||w||!(m>0))return M;const S=i.getBoundingClientRect(),B=Math.min(S.width+m,o.innerWidth*.96);if(!(B>S.width+.5))return M;const T=i.style.width,O=f,q=i.style.left,z=`${Math.round(B)}px`;i.style.width=z,f=z;let I=null;if(!t){const P=S.left+B-o.innerWidth;P>0&&(I=`${Math.max(0,Math.round(S.left-P-8))}px`,i.style.left=I)}return()=>{i.style.width===z&&!c&&!w&&(i.style.width=T),f===z&&(f=O),I!==null&&i.style.left===I&&(i.style.left=q)}}return{backdrop:l,box:i,contentWrap:W,close:j,bringToFront:V,setNaturalHeight:ve,reserveWidth:ye}}export function openModal(e){return be({...e,mode:"modal"})}export function openFloatingWindow(e){return be({...e,mode:"window"})}const le=new WeakSet;export function openReparentedModal(e,t={}){if(e.length===0||e.some(a=>le.has(a)))return null;const n=e.map(a=>({el:a,parent:a.parentElement,next:a.nextSibling})),o=openModal({ownerDocument:t.ownerDocument,title:t.title,boxSize:t.boxSize,anchor:t.anchor??e[0],onClose:()=>{for(const a of n){if(le.delete(a.el),!a.parent)continue;const l=a.next&&a.next.parentNode===a.parent?a.next:null;a.parent.insertBefore(a.el,l)}t.onClosed?.()}});for(const a of n)le.add(a.el),o.contentWrap.appendChild(a.el);return o}export function makePaletteBtn(e,t,n,o){const a=e.makeCheckMenuBtn("palette","Colour scheme",()=>{const x=t(),i=[];if(x.plotMode==="hardBin"||x.plotMode==="softBin"){const f=x.binColorScheme??"default";i.push({section:"Bin colours"});for(const u of Se())i.push({label:u.label,active:f===u.name,onClick:()=>o({binColorScheme:u.name})});if(n()){const u=x.useDefinedBinColors??!0;i.push({section:"Bin definitions"}),i.push({label:"Use colours from bin definitions",active:u,onClick:()=>o({useDefinedBinColors:!u})})}}else{const f=x.valueColorScheme??"default";i.push({section:"Value colours"});for(const s of Be())i.push({label:s.label,active:f===s.name,onClick:()=>o({valueColorScheme:s.name})});const u=x.reverseValueScheme??!1;i.push({section:"Direction"}),i.push({label:"Reverse gradient",active:u,onClick:()=>o({reverseValueScheme:!u})})}return i},()=>{});function l(){a.style.display=t().plotMode==="metadata"?"none":""}return{btn:a,sync:l}}export function requestedPassFailDisplay(e){return e.passFailDisplay??"off"}export function overlayMenuRows(e,t,n,o,a){const l=a?.on?{enabled:!1,disabledHint:"Not drawn in the compact layout"}:void 0;return[...a?[{label:"Compact layout",active:a.on,enabled:a.offered||a.on,disabledHint:"Needs a repeating multi-project layout",onClick:()=>a.onChange(!a.on)},{label:"Layout diagnostics",active:!1,action:!0,closeMenu:!0,onClick:()=>a.onDiagnostics()},{section:""}]:[],{label:"Ring boundaries",active:!!e.showRingBoundaries,...l,onClick:()=>o({showRingBoundaries:!e.showRingBoundaries})},{label:"Quadrant lines",active:!!e.showQuadrantBoundaries,...l,onClick:()=>o({showQuadrantBoundaries:!e.showQuadrantBoundaries})},{label:"Die labels",active:!!e.showDieLabels,onClick:()=>o({showDieLabels:!e.showDieLabels})},{label:"Reticle grid",active:!!e.showReticle,enabled:a?.on?!1:t,...l?{disabledHint:l.disabledHint}:{},onClick:()=>o({showReticle:!e.showReticle})},{label:"XY indicator",active:!!e.showXYIndicator,onClick:()=>o({showXYIndicator:!e.showXYIndicator})},{label:"Axis labels",active:!!e.showAxes,onClick:()=>o({showAxes:!e.showAxes})},...passFailMenuRows({...n,display:requestedPassFailDisplay(e)},x=>o({passFailDisplay:x})),{label:"Mark failing dies",active:!!e.markFailingDies,enabled:n.binMode,disabledHint:n.binMode?void 0:"Available on hard/soft bin maps",onClick:()=>o({markFailingDies:!e.markFailingDies})},{section:""},{label:"Clear overlays",active:!1,action:!0,enabled:anyOverlayActive(e),disabledHint:"No overlays are active",onClick:()=>o({showRingBoundaries:!1,showQuadrantBoundaries:!1,showDieLabels:!1,showReticle:!1,showXYIndicator:!1,showAxes:void 0,passFailDisplay:"off",markFailingDies:!1})}]}export function anyOverlayActive(e){return!!(e.showRingBoundaries||e.showQuadrantBoundaries||e.showDieLabels||e.showReticle||e.showXYIndicator||e.showAxes===!0||e.markFailingDies||requestedPassFailDisplay(e)!=="off")}export function passFailMenuRows(e,t){if(e.functionalActive)return[];const n=[];return e.hasLimits&&n.push({label:"Limit pass/fail",active:e.display==="spec",onClick:()=>t(e.display==="spec"?"off":"spec")}),e.hasRecorded&&n.push({label:"Test pass/fail",active:e.display==="test",onClick:()=>t(e.display==="test"?"off":"test")}),n}export function makeLogScaleBtn(e,t,n){const o=e.makeBtn("logScale","Toggle log scale",()=>{n({logScale:!t().logScale})});function a(){const l=t(),x=l.plotMode,i=x==="value"||x==="stackedValues";o.style.display=i&&requestedPassFailDisplay(l)==="off"&&!l.functionalActive?"":"none",e.setActive(o,!!l.logScale)}return{btn:o,sync:a}}const Fe=[{value:"default",label:"Default (right)"},{value:"compact",label:"Compact (right)"},{value:"left",label:"Left"},{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"floating",label:"Floating"}];export function makeLegendStyleBtn(e,t,n,o){const a=e.makeCheckMenuBtn("legend","Legend style",()=>{const x=t().legendPosition??"default",i=[];let f=!0;if(o){const u=o.blockedReason();f=u?!0:o.get(),i.push({label:"Legend on each map",active:f,enabled:!u,disabledHint:u??void 0,onClick:()=>o.set(!o.get())})}if(he(t().plotMode)){o&&i.push({section:"Position on each map"});for(const u of Fe)i.push({label:u.label,active:f&&x===u.value,enabled:f,disabledHint:f?void 0:'Turn on "Legend on each map" to position it',onClick:()=>n(u.value)})}return i},()=>{});function l(){a.style.display=o||he(t().plotMode)?"":"none"}return{btn:a,sync:l}}function he(e){return e==="hardBin"||e==="softBin"||e==="metadata"}export function makeOverlaysBtn(e,t,n){return e.makeCheckMenuBtn("overlays","Overlays",()=>t(),o=>e.setActive(o,n()))}export function makeOrientationBtn(e,t,n){const o=a=>n({...a,showXYIndicator:!0});return e.makeCheckMenuBtn("orient","Orientation",()=>[{section:"Rotate"},{label:"Rotate 90\xB0 clockwise",active:!1,onClick:()=>{const a=t().rotation??0;o({rotation:ROTATIONS[(ROTATIONS.indexOf(a)+1)%4]})}},{section:"Flip"},{label:"Flip horizontal",active:!!t().flipX,onClick:()=>o({flipX:!t().flipX})},{label:"Flip vertical",active:!!t().flipY,onClick:()=>o({flipY:!t().flipY})},{section:""},{label:"Reset orientation",active:!1,action:!0,enabled:!!(t().rotation||t().flipX||t().flipY),disabledHint:"Already in the original orientation",onClick:()=>n({rotation:0,flipX:!1,flipY:!1})}],a=>{const{rotation:l,flipX:x,flipY:i}=t();e.setActive(a,!!(l||x||i))})}
9
+ }`,n.head.appendChild(oe),reparentTooltip(i),t?(d.addEventListener("click",f=>{f.target===d&&z()}),n.addEventListener("keydown",R)):(i.addEventListener("keydown",R),i.addEventListener("mousedown",P),P()),nextFrame(()=>(e.initialFocus?.()??(r.isConnected?r:i)).focus(),o);function ve(f){u=f,!l&&!x&&(i.style.height=f)}function ye(f){const B=()=>{};if(l||x||!(f>0))return B;const D=i.getBoundingClientRect(),H=Math.min(D.width+f,o.innerWidth*.96);if(!(H>D.width+.5))return B;const $=i.style.width,N=p,q=i.style.left,V=`${Math.round(H)}px`;i.style.width=V,p=V;let _=null;if(!t){const Y=D.left+H-o.innerWidth;Y>0&&(_=`${Math.max(0,Math.round(D.left-Y-8))}px`,i.style.left=_)}return()=>{i.style.width===V&&!l&&!x&&(i.style.width=$),p===V&&(p=N),_!==null&&i.style.left===_&&(i.style.left=q)}}return{backdrop:d,box:i,contentWrap:F,close:z,bringToFront:P,setNaturalHeight:ve,reserveWidth:ye}}export function openModal(e){return be({...e,mode:"modal"})}export function openFloatingWindow(e){return be({...e,mode:"window"})}const le=new WeakSet;export function openReparentedModal(e,t={}){if(e.length===0||e.some(a=>le.has(a)))return null;const n=e.map(a=>({el:a,parent:a.parentElement,next:a.nextSibling})),o=openModal({ownerDocument:t.ownerDocument,title:t.title,boxSize:t.boxSize,anchor:t.anchor??e[0],onClose:()=>{for(const a of n){if(le.delete(a.el),!a.parent)continue;const d=a.next&&a.next.parentNode===a.parent?a.next:null;a.parent.insertBefore(a.el,d)}t.onClosed?.()}});for(const a of n)le.add(a.el),o.contentWrap.appendChild(a.el);return o}export function makePaletteBtn(e,t,n,o){const a=e.makeCheckMenuBtn("palette","Colour scheme",()=>{const b=t(),i=[];if(b.plotMode==="hardBin"||b.plotMode==="softBin"){const p=b.binColorScheme??"default";i.push({section:"Bin colours"});for(const u of Se())i.push({label:u.label,active:p===u.name,onClick:()=>o({binColorScheme:u.name})});if(n()){const u=b.useDefinedBinColors??!0;i.push({section:"Bin definitions"}),i.push({label:"Use colours from bin definitions",active:u,onClick:()=>o({useDefinedBinColors:!u})})}}else{const p=b.valueColorScheme??"default";i.push({section:"Value colours"});for(const s of Be())i.push({label:s.label,active:p===s.name,onClick:()=>o({valueColorScheme:s.name})});const u=b.reverseValueScheme??!1;i.push({section:"Direction"}),i.push({label:"Reverse gradient",active:u,onClick:()=>o({reverseValueScheme:!u})})}return i},()=>{});function d(){a.style.display=t().plotMode==="metadata"?"none":""}return{btn:a,sync:d}}export function requestedPassFailDisplay(e){return e.passFailDisplay??"off"}export function overlayMenuRows(e,t,n,o,a){const d=a?.on?{enabled:!1,disabledHint:"Not drawn in the compact layout"}:void 0;return[...a?[{label:"Compact layout",active:a.on,enabled:a.offered||a.on,disabledHint:"Needs a repeating multi-project layout",onClick:()=>a.onChange(!a.on)},{label:"Layout diagnostics",active:!1,action:!0,closeMenu:!0,onClick:()=>a.onDiagnostics()},{section:""}]:[],{label:"Ring boundaries",active:!!e.showRingBoundaries,...d,onClick:()=>o({showRingBoundaries:!e.showRingBoundaries})},{label:"Quadrant lines",active:!!e.showQuadrantBoundaries,...d,onClick:()=>o({showQuadrantBoundaries:!e.showQuadrantBoundaries})},{label:"Die labels",active:!!e.showDieLabels,onClick:()=>o({showDieLabels:!e.showDieLabels})},{label:"Reticle grid",active:!!e.showReticle,enabled:a?.on?!1:t,...d?{disabledHint:d.disabledHint}:{},onClick:()=>o({showReticle:!e.showReticle})},{label:"XY indicator",active:!!e.showXYIndicator,onClick:()=>o({showXYIndicator:!e.showXYIndicator})},{label:"Axis labels",active:!!e.showAxes,onClick:()=>o({showAxes:!e.showAxes})},...passFailMenuRows({...n,display:requestedPassFailDisplay(e)},b=>o({passFailDisplay:b})),{label:"Mark failing dies",active:!!e.markFailingDies,enabled:n.binMode,disabledHint:n.binMode?void 0:"Available on hard/soft bin maps",onClick:()=>o({markFailingDies:!e.markFailingDies})},{section:""},{label:"Clear overlays",active:!1,action:!0,enabled:anyOverlayActive(e),disabledHint:"No overlays are active",onClick:()=>o({showRingBoundaries:!1,showQuadrantBoundaries:!1,showDieLabels:!1,showReticle:!1,showXYIndicator:!1,showAxes:void 0,passFailDisplay:"off",markFailingDies:!1})}]}export function anyOverlayActive(e){return!!(e.showRingBoundaries||e.showQuadrantBoundaries||e.showDieLabels||e.showReticle||e.showXYIndicator||e.showAxes===!0||e.markFailingDies||requestedPassFailDisplay(e)!=="off")}export function passFailMenuRows(e,t){if(e.functionalActive)return[];const n=[];return e.hasLimits&&n.push({label:"Limit pass/fail",active:e.display==="spec",onClick:()=>t(e.display==="spec"?"off":"spec")}),e.hasRecorded&&n.push({label:"Test pass/fail",active:e.display==="test",onClick:()=>t(e.display==="test"?"off":"test")}),n}export function makeLogScaleBtn(e,t,n){const o=e.makeBtn("logScale","Toggle log scale",()=>{n({logScale:!t().logScale})});function a(){const d=t(),b=d.plotMode,i=b==="value"||b==="stackedValues";o.style.display=i&&requestedPassFailDisplay(d)==="off"&&!d.functionalActive?"":"none",e.setActive(o,!!d.logScale)}return{btn:o,sync:a}}const Fe=[{value:"default",label:"Default (right)"},{value:"compact",label:"Compact (right)"},{value:"left",label:"Left"},{value:"top",label:"Top"},{value:"bottom",label:"Bottom"},{value:"floating",label:"Floating"}];export function makeLegendStyleBtn(e,t,n,o){const a=e.makeCheckMenuBtn("legend","Legend style",()=>{const b=t().legendPosition??"default",i=[];let p=!0;if(o){const u=o.blockedReason();p=u?!0:o.get(),i.push({label:"Legend on each map",active:p,enabled:!u,disabledHint:u??void 0,onClick:()=>o.set(!o.get())})}if(he(t().plotMode)){o&&i.push({section:"Position on each map"});for(const u of Fe)i.push({label:u.label,active:p&&b===u.value,enabled:p,disabledHint:p?void 0:'Turn on "Legend on each map" to position it',onClick:()=>n(u.value)})}return i},()=>{});function d(){a.style.display=o||he(t().plotMode)?"":"none"}return{btn:a,sync:d}}function he(e){return e==="hardBin"||e==="softBin"||e==="metadata"}export function makeOverlaysBtn(e,t,n){return e.makeCheckMenuBtn("overlays","Overlays",()=>t(),o=>e.setActive(o,n()))}export function makeOrientationBtn(e,t,n){const o=a=>n({...a,showXYIndicator:!0});return e.makeCheckMenuBtn("orient","Orientation",()=>[{section:"Rotate"},{label:"Rotate 90\xB0 clockwise",active:!1,onClick:()=>{const a=t().rotation??0;o({rotation:ROTATIONS[(ROTATIONS.indexOf(a)+1)%4]})}},{section:"Flip"},{label:"Flip horizontal",active:!!t().flipX,onClick:()=>o({flipX:!t().flipX})},{label:"Flip vertical",active:!!t().flipY,onClick:()=>o({flipY:!t().flipY})},{section:""},{label:"Reset orientation",active:!1,action:!0,enabled:!!(t().rotation||t().flipX||t().flipY),disabledHint:"Already in the original orientation",onClick:()=>n({rotation:0,flipX:!1,flipY:!1})}],a=>{const{rotation:d,flipX:b,flipY:i}=t();e.setActive(a,!!(d||b||i))})}