@wafertools/wafermap 0.37.0 → 0.37.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.
@@ -1,4 +1,4 @@
1
- import{getUniqueTestNumbers as ke}from"../renderer/buildView.js";import{dieHasValues as Ee}from"../core/dieTable.js";import{dieHasTestData as Ce}from"../renderer/buildWaferMap.js";import{testLabel as re,isDerivedTest as Le,DERIVED_MARK as de,DERIVED_KEY as ue}from"../renderer/testLabel.js";import{prettyKey as Ae}from"../core/utils.js";import{diagnoseMpwLayout as Me,formatMpwDiagnostics as Se}from"../core/compact.js";import{listBinColorSchemes as Be,listValueColorSchemes as De}from"../renderer/colorSchemes.js";import{ICONS as j}from"./icons.js";import{WMAP_VERSION as pe,WMAP_BUILD_TIME as Te}from"./version.js";let fe=!1;export function logWmapVersionOnce(){fe||(fe=!0,console.log(`[wmap] v${pe} (built ${Te})`))}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 C=(e,t)=>`var(--wmap-${e}, ${t})`,Q="var(--wmap-font-size, 12px)",He="var(--wmap-density, 1)",X=e=>`calc(${e}px * ${He})`;export function wireControlHover(e,t="outlined"){let n=null;const o=()=>{!n||e.dataset.on==="true"||(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(),i=o?parseFloat(o):NaN;return(Number.isFinite(i)?i:12)+e}export const CLR={icon:C("icon","#506784"),iconHover:C("icon-hover","#2a3f5f"),iconActive:C("icon-active","#1a65ca"),bgHover:C("bg-hover","#edf0f8"),bgActive:C("bg-active","#dce8f8"),separator:C("separator","rgba(0,0,0,0.12)"),menuBg:C("surface","#fff"),menuBorder:C("border","rgba(0,0,0,0.12)"),controlBorder:C("control-border",C("border","rgba(0,0,0,0.30)")),menuHover:C("menu-hover","#f0f4fc"),menuActive:C("menu-active","#dce8f8"),canvasBg:`var(--wmap-canvas-bg, ${C("surface","#f5f5f5")})`,panelBg:C("panel-bg","#fafbfc"),label:C("text-muted","#647687"),value:C("text-strong","#1f2f43"),text:C("text","#333"),warnBg:C("warn-bg","#fffbe6"),warnBorder:C("warn-border","#f0c040"),warnText:C("warn-text","#7a5800"),errBg:C("err-bg","#fef2f2"),errBorder:C("err-border","#dc8a8a"),errText:C("err-text","#7a1c1c"),infoBg:C("info-bg","#dce8f8"),infoText:C("info-text","#334155"),findingHighlight:C("selected","#e07a20"),findingIndicator:C("finding-indicator","#b7551a"),barFill:C("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 i=n.getPropertyValue(`--wmap-${o}`).trim();i&&t.style.setProperty(`--wmap-${o}`,i)}}export function syncWmapPopupTheme(e,t,n){const o=()=>{copyWmapThemeTokens(e,t),n?.()},i=new window.MutationObserver(o);i.observe(e,{attributes:!0,attributeFilter:["style","class"]}),i.observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]});const l=window.matchMedia("(prefers-color-scheme: dark)");return l.addEventListener("change",o),()=>{i.disconnect(),l.removeEventListener("change",o)}}let se=null;export function setDetachWindowOpener(e){se=e}export function openDetachWindow(e){return se?se(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=Se(Me(e,t),pe),i=n.anchor.ownerDocument,l=openModal({title:"Layout diagnostics",anchor:n.anchor,ownerDocument:i,onClose:()=>{},boxSize:{width:"min(680px, 94vw)",height:"min(480px, 90vh)"}}),f=l.contentWrap;Object.assign(f.style,{flexDirection:"column",padding:"14px 16px",gap:"10px",boxSizing:"border-box"});const a=i.createElement("p");a.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(a.style,{margin:"0",fontSize:FONT.body,color:CLR.text,lineHeight:"1.4"});const d=i.createElement("textarea");d.value=o,d.readOnly=!0,d.setAttribute("aria-label","Layout diagnostics"),Object.assign(d.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 p=i.createElement("div");Object.assign(p.style,{display:"flex",gap:"8px",alignItems:"center"});const s=i.createElement("span");s.setAttribute("role","status"),Object.assign(s.style,{fontSize:FONT.body,color:CLR.text});const w=(E,u)=>{const r=i.createElement("button");return r.type="button",r.textContent=E,Object.assign(r.style,controlStyle("outlined"),{padding:"5px 12px",color:CLR.text}),wireControlHover(r,"outlined"),r.addEventListener("click",u),r},m=w("Copy",()=>{const E=i.defaultView,u=()=>{d.focus(),d.select();let r=!1;try{r=i.execCommand("copy")}catch{r=!1}s.textContent=r?"Copied":"Copying is not available here. Select the text, or save it as a file."};E?.navigator.clipboard?E.navigator.clipboard.writeText(o).then(()=>{s.textContent="Copied"},u):u()}),x=w("Save as file",()=>{saveTextFile(o,"wafermap-layout-diagnostics.txt","text/plain",n.onSaveText),s.textContent=n.onSaveText?"":"Saved"});return p.append(m,x,s),f.append(a,d,p),d.focus(),d.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 Oe='[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 i=t();if(i.length===0)return;const l=e.ownerDocument.activeElement,f=l?i.indexOf(l):-1;switch(o.key){case"ArrowDown":o.preventDefault(),i[f<0||f===i.length-1?0:f+1].focus();break;case"ArrowUp":o.preventDefault(),i[f<=0?i.length-1:f-1].focus();break;case"Home":o.preventDefault(),i[0].focus();break;case"End":o.preventDefault(),i[i.length-1].focus();break;case"Enter":case" ":f>=0&&(o.preventDefault(),i[f].click());break;case"Escape":case"Tab":o.preventDefault(),n();break}})}function te(e,t,n){const o=()=>Array.from(e.querySelectorAll(Oe));wireListNavigation(e,o,()=>{n(),t?.focus()});const i=o()[0];i&&nextFrame(()=>i.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 me=new WeakMap;export function menuLayerFor(e){const t=overlayRootFor(e),n=me.get(t);if(n&&n.isConnected)return n;const i=e.ownerDocument.createElement("div");return i.dataset.wmapMenuLayer="1",Object.assign(i.style,{position:"fixed",inset:"0",zIndex:Z_MENU,pointerEvents:"none"}),t.appendChild(i),me.set(t,i),i}const le=new WeakMap;export function getTooltip(e=document){const t=le.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}),le.set(e,n)),e.body.appendChild(n),n}export function hideTooltip(e=document){const t=le.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,i={}){const l=menuLayerFor(t);e.parentElement!==l&&l.appendChild(e);const f=e.ownerDocument.defaultView??window;e.style.left="0",e.style.top="0";const a=e.offsetWidth,d=e.offsetHeight,p=8,s=f.innerWidth,w=f.innerHeight;let m=n+14,x=o-8;m+a+p>s&&(m=n-a-6);const E=t.getBoundingClientRect();if(!i.followPointer&&E.height>0&&E.height<=w*.4&&x<E.bottom&&x+d>E.top&&m<E.right&&m+a>E.left){const h=E.bottom+p,c=E.top-d-p;h+d+p<=w?x=h:c>=p&&(x=c)}x+d+p>w&&(x=w-d-p),x<p&&(x=p),e.style.left=`${m}px`,e.style.top=`${x}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 i=f=>{const a=o();if(!a)return;const d=getTooltip(e.ownerDocument);if(d.textContent=a,d.style.display="block",f)positionTooltip(d,e,f.clientX,f.clientY);else{const p=e.getBoundingClientRect();positionTooltip(d,e,p.left+p.width/2,p.top)}},l=()=>hideTooltip(e.ownerDocument);e.addEventListener("mousemove",i),e.addEventListener("mouseleave",l),e.addEventListener("focus",()=>i()),e.addEventListener("blur",l)}export function buildDataModeEntries(e,t,n){const o=e.some(Ce),i=e.some(Ee),l=e.some(s=>s.hbin!=null),f=e.some(s=>s.sbin!=null),a=o?t!==void 0?t.map(s=>({plotMode:"value",activeTest:s.testNumber,label:s.unit?`${re(s,s.testNumber)} (${s.unit})`:re(s,s.testNumber),logScale:s.logScale,...Le(s)?{derived:!0}:{}})):ke(e).map(s=>({plotMode:"value",activeTest:s,label:re(void 0,s)})):[],d=[...l?[{plotMode:"hardBin",label:MODE_LABELS.hardBin}]:[],...f?[{plotMode:"softBin",label:MODE_LABELS.softBin}]:[]],p=n.includeStacked?[...i?[{plotMode:"stackedValues",label:MODE_LABELS.stackedValues}]:[],...l?[{plotMode:"stackedBins",label:MODE_LABELS.stackedBins}]:[],...f?[{plotMode:"stackedSoftBins",label:MODE_LABELS.stackedSoftBins}]:[]]:[];return{testEntries:a,binEntries:d,stackedEntries:p}}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??Ae(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",i=>i.stopPropagation()),o.addEventListener("mousedown",i=>i.stopPropagation()),o.addEventListener("keydown",i=>i.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,i,l,f,a,d=window,p=[]){const{makeMenuRow:s,makeMenuSection:w}=f,m=document.createElement("div"),x=180,u=e.left+x<=(d.innerWidth??1/0)?e.left:Math.max(4,e.right-x);if(Object.assign(m.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:`${x}px`,padding:"4px 0",pointerEvents:"auto"}),t.length)if(m.appendChild(w("Test Value")),t.length<=INLINE_TEST_LIMIT)for(const r of t)m.appendChild(s(r.label,i(r),!0,h=>{h.stopPropagation(),l(r,m)}));else{const r=a==="value",h=s(MODE_LABELS.value+" \u25B6",r,!1,A=>{A.stopPropagation(),g(),B(),A.detail===0&&O()});h.setAttribute("aria-haspopup","menu"),h.style.display="flex",h.style.justifyContent="space-between",h.style.alignItems="center";let c=null,L=null;const g=()=>{L!==null&&(clearTimeout(L),L=null)},k=A=>{const T=A.target;T&&(h.contains(T)||c?.contains(T))||v()},v=()=>{g(),c?.remove(),c=null,d.document.removeEventListener("click",k),h.setAttribute("aria-expanded","false")},O=()=>{const A=c?.querySelector('input, [role="menuitemradio"]');A&&nextFrame(()=>A.focus(),d)},W=()=>{g(),L=setTimeout(v,300)},B=()=>{if(c)return;const A=h.getBoundingClientRect(),T=160,I=320,R=A.right+2+T<=(d.innerWidth??1/0)?A.right+2:Math.max(4,A.left-2-T),z=Math.min(A.top-4,Math.max(4,(d.innerHeight??1/0)-I-4));if(c=document.createElement("div"),c.setAttribute("data-wmap-submenu",""),c.setAttribute("role","menu"),Object.assign(c.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 y=makeMenuSearchBox(U=>{for(const K of P)K.row.style.display=K.label.includes(U)?"":"none"},"Filter tests\u2026");Object.assign(y.style,{position:"sticky",top:"0",zIndex:"1",background:CLR.menuBg}),c.appendChild(y)}const P=[],N=t.some(y=>y.derived);for(const y of t){const U=s(y.label,i(y),!1,K=>{K.stopPropagation(),v(),l(y,m)},N?{derived:y.derived===!0}:void 0);P.push({row:U,label:y.label.toLowerCase()}),c.appendChild(U)}if(N){const y=d.document.createElement("div");y.setAttribute("role","presentation"),y.textContent=`${de} ${ue}`,Object.assign(y.style,{padding:"6px 14px",fontSize:FONT.meta,color:CLR.label,borderTop:`1px solid ${CLR.menuBorder}`,marginTop:"4px",whiteSpace:"nowrap"}),c.appendChild(y)}c.addEventListener("mouseenter",g),c.addEventListener("mouseleave",W),wireListNavigation(c,()=>P.filter(y=>y.row.style.display!=="none").map(y=>y.row),()=>{v(),h.focus()}),(m.parentElement??d.document.body).appendChild(c),d.document.addEventListener("click",k),h.setAttribute("aria-expanded","true")};m.addEventListener("keydown",A=>{A.key==="Escape"&&v()}),h.addEventListener("mouseenter",()=>{g(),B()}),h.addEventListener("mouseleave",W),m.appendChild(h)}if(n.length){m.appendChild(w("Bins"));for(const r of n)m.appendChild(s(r.label,i(r),!1,h=>{h.stopPropagation(),l(r,m)}))}if(p.length){m.appendChild(w("Metadata"));for(const r of p)m.appendChild(s(r.label,i(r),!1,h=>{h.stopPropagation(),l(r,m)}))}if(o.length){m.appendChild(w("Lot Aggregation"));for(const r of o)m.appendChild(s(r.label,i(r),!1,h=>{h.stopPropagation(),l(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)}const ne=new WeakMap;export function openCommandMenu(e,t,n,o,i={}){const l=t.ownerDocument,f=l.defaultView??window;ne.get(l)?.();const{makeMenuSection:a}=createToolbarHelpers(getTooltip(l)),d=buildCheckMenuEl(e,n,{makeMenuSection:a},f);d.setAttribute("role","menu"),d.setAttribute("aria-label",o),i.hook&&(d.dataset[i.hook]="1"),menuLayerFor(t).appendChild(d);const p=d.getBoundingClientRect();p.bottom>f.innerHeight-4&&(d.style.top=`${Math.max(4,e.top-p.height)}px`),p.right>f.innerWidth-4&&(d.style.left=`${Math.max(4,f.innerWidth-p.width-4)}px`);let s=!1;function w(){s||(s=!0,d.remove(),i.trigger&&markMenuTrigger(i.trigger,!1),l.removeEventListener("pointerdown",m,!0),f.removeEventListener("blur",w),ne.get(l)===w&&ne.delete(l))}function m(x){!d.contains(x.target)&&!i.trigger?.contains(x.target)&&w()}return l.addEventListener("pointerdown",m,!0),f.addEventListener("blur",w),wireMenuA11y(d,i.trigger??t,w),i.trigger&&markMenuTrigger(i.trigger,!0),ne.set(l,w),w}export function wireExpandToggle(e,t){const n=e.ownerDocument;let o=!1;function i(p){o!==p&&(o=p,t(o))}function l(){i(!1)}function f(){i(!o),o&&n.addEventListener("click",l,{once:!0})}const a=p=>{p.stopPropagation(),f()},d=p=>{p.key==="Enter"||p.key===" "?(p.preventDefault(),f()):p.key==="Escape"&&l()};return e.setAttribute("role","button"),e.tabIndex<0&&(e.tabIndex=0),e.addEventListener("click",a),e.addEventListener("keydown",d),{isOpen:()=>o,close:l,destroy(){e.removeEventListener("click",a),e.removeEventListener("keydown",d),n.removeEventListener("click",l)}}}export function buildCheckMenuEl(e,t,n,o=window){const{makeMenuSection:i}=n,l=o.document,f=l.createElement("div"),a=168,p=e.left+a<=(o.innerWidth??1/0)?e.left:Math.max(4,e.right-a);Object.assign(f.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:`${a}px`,padding:"4px 0",pointerEvents:"auto"});for(const s of t)if("section"in s)f.appendChild(i(s.section));else{const w=s.enabled!==!1;if(!w&&!s.disabledHint)continue;const m=l.createElement("div");s.action?m.setAttribute("role","menuitem"):(m.setAttribute("role","menuitemcheckbox"),m.setAttribute("aria-checked",s.active?"true":"false")),m.tabIndex=-1,w||(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:w?"pointer":"default",color:w?s.active?CLR.iconActive:CLR.text:CLR.label,fontWeight:s.active?"700":"400",background:s.active?CLR.menuActive:"transparent",whiteSpace:"nowrap"});const x=l.createElement("span");Object.assign(x.style,{width:"12px",flexShrink:"0",color:CLR.iconActive,visibility:s.active?"visible":"hidden"}),x.textContent=s.action?"":"\u2713",x.setAttribute("aria-hidden","true");const E=l.createElement("span");E.textContent=s.label,m.appendChild(x),m.appendChild(E),w?(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",u=>{u.stopPropagation(),s.onClick(u)})):m.addEventListener("click",u=>{u.stopPropagation()}),f.appendChild(m)}return f}export function createToolbarHelpers(e){const t=e.ownerDocument;let n=null;const o=u=>menuLayerFor(u);function i(u,r,h){const c=t.createElement("button");return c.innerHTML=j[u],c.type="button",c.ariaLabel=r,Object.assign(c.style,{display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",padding:"0",border:"none",borderRadius:RADIUS.control,background:"transparent",color:CLR.icon,cursor:"pointer",pointerEvents:"auto",transition:`background ${MOTION.fast}, color ${MOTION.fast}`,flexShrink:"0"}),c.addEventListener("mouseenter",L=>{c.dataset.active||(c.style.background=CLR.bgHover,c.style.color=CLR.iconHover),e.textContent=c.ariaLabel??r,e.style.display="block",positionTooltip(e,c,L.clientX,L.clientY)}),c.addEventListener("mousemove",L=>{e.style.display==="block"&&positionTooltip(e,c,L.clientX,L.clientY)}),c.addEventListener("mouseleave",()=>{c.dataset.active||(c.style.background="transparent",c.style.color=CLR.icon),e.style.display="none"}),c.addEventListener("click",()=>{e.style.display="none",h()}),c}function l(u,r){r?(u.dataset.active="1",u.style.background=CLR.bgActive,u.style.color=CLR.iconActive):(delete u.dataset.active,u.style.background="transparent",u.style.color=CLR.icon)}function f(){const u=t.createElement("div");return Object.assign(u.style,{width:"1px",height:"18px",background:CLR.separator,margin:"0 2px",flexShrink:"0"}),u.dataset.wmapSep="1",u}function a(u){let r=!1,h=null;for(const c of Array.from(u.children))c.dataset.wmapSep?r&&!h?h=c:c.style.display="none":c.style.display!=="none"&&(h&&(h.style.display="",h=null),r=!0);h&&(h.style.display="none")}function d(u){for(const r of Array.from(u.children))if(!(r.dataset.wmapSep||r.style.display==="none"))if(r.tagName==="DIV"&&!r.getAttribute("role")&&r.children.length){if(d(r))return!0}else return!0;return!1}function p(u,r){u.style.display=d(u)?r:"none"}function s(u,r,h,c,L){const g=t.createElement("div");if(L){const k=t.createElement("span");k.textContent=L.derived?de:"",k.setAttribute("aria-hidden","true"),Object.assign(k.style,{display:"inline-block",width:"1.1em"}),g.append(k,u),L.derived&&g.setAttribute("aria-label",`${u} \u2014 ${ue.toLowerCase()}`)}else g.textContent=u;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",c),g}function w(u){const r=t.createElement("div");return r.textContent=u,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(u,r,h,c,L){const g=()=>{n&&(n.remove(),n=null),k.setAttribute("aria-expanded","false")},k=i(u,r,()=>{if(n){g();return}const v=t.createElement("div"),O=k.getBoundingClientRect(),W=k.ownerDocument.defaultView??window,B=148,T=O.left+B<=(W.innerWidth??1/0)?O.left:Math.max(4,O.right-B);Object.assign(v.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:`${B}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===c();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!==c()&&(M.style.background=CLR.menuHover)},P=()=>{M.style.background=I.value===c()?CLR.menuActive:"transparent"};M.addEventListener("mouseenter",z),M.addEventListener("mouseleave",P),M.addEventListener("focus",z),M.addEventListener("blur",P),M.addEventListener("click",N=>{N.stopPropagation(),L(I.value),g()}),v.appendChild(M)}v.setAttribute("role","menu"),v.setAttribute("aria-label",r),o(k).appendChild(v),n=v,k.setAttribute("aria-expanded","true"),te(v,k,g)});return k.setAttribute("aria-haspopup","menu"),k.setAttribute("aria-expanded","false"),k}function x(u,r,h,c){function L(){return buildCheckMenuEl(k.getBoundingClientRect(),h().map(v=>"section"in v?v:{...v,onClick:O=>{v.closeMenu&&g(),v.onClick(O),c(k);const W=n;if(!W)return;const B=L();B.setAttribute("role","menu"),B.setAttribute("aria-label",r),W.replaceWith(B),n=B,te(B,k,g)}}),{makeMenuSection:w},k.ownerDocument.defaultView??window)}const g=()=>{n&&(n.remove(),n=null),k.setAttribute("aria-expanded","false")},k=i(u,r,()=>{if(n){g();return}const v=L();v.setAttribute("role","menu"),v.setAttribute("aria-label",r),o(k).appendChild(v),n=v,k.setAttribute("aria-expanded","true"),te(v,k,g)});return k.setAttribute("aria-haspopup","menu"),k.setAttribute("aria-expanded","false"),c(k),k}function E(u){const r=u.target?.closest?.("[data-wmap-submenu]");if(n&&!n.contains(u.target)&&!r&&(n.remove(),n=null,u.target?.getAttribute?.("aria-haspopup")!=="menu"))for(const c of document.querySelectorAll('[aria-haspopup="menu"][aria-expanded="true"]'))c.setAttribute("aria-expanded","false")}return{makeBtn:i,setActive:l,makeSep:f,syncSeparators:a,syncToolbarVisible:p,makeMenuRow:s,makeMenuSection:w,makeDropdown:m,makeCheckMenuBtn:x,closeOpenMenu:E,getOpenMenu:()=>n,setOpenMenu:u=>{n=u}}}const Ie=7e3;let Re=0;function be(){return Ie+ ++Re}const $e=32,We=6;let ze=0;function Pe(){return ze++%We*$e}function Ne(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 he(e){const t=e.mode==="modal",n=e.ownerDocument??document,o=n.defaultView??window,i=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 f=n.activeElement,a=n.createElement("div");a.className=t?"wmap-modal-box wmap-overlay-box":"wmap-window-box wmap-overlay-box",a.setAttribute("role","dialog"),t&&a.setAttribute("aria-modal","true"),a.setAttribute("aria-label",e.title??"Expanded wafer map"),a.tabIndex=-1;let d=e.boxSize?.width??"min(90vw, 700px)",p=e.boxSize?.height??"min(90vh, 700px)";if(Object.assign(a.style,{position:"relative",background:CLR.menuBg,borderRadius:RADIUS.container,overflow:"hidden",display:"flex",flexDirection:"column",width:d,height:p,boxShadow:SHADOW.modal,minWidth:"320px",minHeight:"240px",maxWidth:"100vw",maxHeight:"100vh",zIndex:t?Z_ABOVE2:String(be())}),!t){const b=Pe();Object.assign(a.style,{position:"fixed",top:`${Math.round(o.innerHeight*.08)+b}px`,left:`${Math.round(o.innerWidth*.08)+b}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 w={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 b=n.createElement("span");b.textContent=e.title,b.title=e.title,b.dataset.wmapWindowTitle="1",Object.assign(b.style,{fontWeight:"700",fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"}),s.appendChild(b)}const m=n.createElement("div");m.style.flex="1",s.appendChild(m);let x=null;t||(x=n.createElement("button"),x.type="button",x.innerHTML=j.collapse,x.setAttribute("aria-label","Collapse"),wireTooltip(x),Object.assign(x.style,w),wireControlHover(x),x.addEventListener("click",()=>A(!v)),s.appendChild(x));let E=null;e.printable&&(E=n.createElement("button"),E.type="button",E.innerHTML=j.print,E.setAttribute("aria-label","Print / Save as PDF"),wireTooltip(E),Object.assign(E.style,w),wireControlHover(E),E.addEventListener("click",()=>{typeof e.printable=="function"?e.printable():o.print()}),s.appendChild(E));const u=n.createElement("button");u.type="button",u.innerHTML=j.maximize,u.setAttribute("aria-label","Maximize (F)"),wireTooltip(u),Object.assign(u.style,w),wireControlHover(u),u.addEventListener("click",()=>k(!c));const r=n.createElement("button");r.type="button",r.innerHTML=j.close,r.setAttribute("aria-label","Close (Esc)"),wireTooltip(r),Object.assign(r.style,w),wireControlHover(r),r.addEventListener("click",z);const h=e.maximizable!==!1;h&&s.appendChild(u),s.appendChild(r);let c=!1,L="",g="";function k(b){c=b,u.innerHTML=c?j.minimize:j.maximize,u.setAttribute("aria-label",c?"Restore (F)":"Maximize (F)"),x&&(x.style.display=c?"none":""),y.style.display=c?"none":"block",c?(a.style.borderRadius="0",a.style.width="100vw",a.style.height="100vh",t||(L=a.style.top,g=a.style.left,a.style.top="0",a.style.left="0")):(a.style.borderRadius="12px",a.style.width=d,a.style.height=p,t||(a.style.top=L,a.style.left=g)),e.onMaximizeChange?.(c,a)}let v=!1,O="",W="";const B=220;function A(b){v=b,x.innerHTML=v?j.uncollapse:j.collapse,x.setAttribute("aria-label",v?"Show contents":"Collapse"),y.style.display=v?"none":"block",v?(O=a.style.height,W=a.style.width,a.style.minHeight="0",a.style.height="auto",a.style.minWidth="0",a.style.width=`${B}px`,u.disabled=!0,u.style.opacity="0.4",u.style.cursor="default",N.style.display="none"):(a.style.minHeight="240px",a.style.height=O||p,a.style.minWidth="320px",a.style.width=W||d,u.disabled=!1,u.style.opacity="1",u.style.cursor="pointer",N.style.display="flex")}function T(){const b=n.body.style.userSelect;return n.body.style.userSelect="none",()=>{n.body.style.userSelect=b}}t||(s.style.cursor="move",s.addEventListener("pointerdown",b=>{if(c||b.target.closest('button, [role="button"]'))return;b.preventDefault();const S=T(),D=b.clientX,H=b.clientY,$=a.offsetTop,F=a.offsetLeft,q=o.innerHeight-s.offsetHeight,V=o.innerWidth-40,_=40-a.offsetWidth;s.setPointerCapture(b.pointerId);const Y=G=>{const ae=Math.min(Math.max($+(G.clientY-H),0),q),we=Math.min(Math.max(F+(G.clientX-D),_),V);a.style.top=`${ae}px`,a.style.left=`${we}px`},Z=G=>{S(),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(b){const S=Array.from(a.querySelectorAll(I)).filter(F=>F.offsetParent!==null||F===n.activeElement);if(S.length===0){b.preventDefault(),a.focus();return}const D=S[0],H=S[S.length-1],$=n.activeElement;b.shiftKey&&($===D||!a.contains($))?(b.preventDefault(),H.focus()):!b.shiftKey&&$===H&&(b.preventDefault(),D.focus())}const R=b=>{if(b.key==="Escape"){b.defaultPrevented||z();return}const S=isTextEntry(b.target);if(t&&!S&&(b.key==="e"||b.key==="E")){z();return}if(t&&b.key==="Tab"){M(b);return}h&&!S&&(b.key==="f"||b.key==="F")&&!v&&k(!c)};function z(){t?n.removeEventListener("keydown",R):a.removeEventListener("keydown",R),ie.remove(),ve(),hideTooltip(n),reparentTooltip(n.body),l?l.remove():a.remove(),t&&(n.body.style.overflow=i),f?.focus?.(),e.onClose()}function P(){t||(a.style.zIndex=String(be()))}const N=n.createElement("div");Object.assign(N.style,{flex:"1",minHeight:"0",minWidth:"0",display:"flex",overflow:"hidden"});const y=n.createElement("div");y.tabIndex=0,y.setAttribute("role","separator"),y.setAttribute("aria-label","Resize window (arrow keys, or drag)"),Object.assign(y.style,{position:"absolute",right:"0",bottom:"0",width:"16px",height:"16px",cursor:"nwse-resize",touchAction:"none"}),y.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>',y.style.color=CLR.label;const U=320,K=240,J=20;function ee(b,S){const D=o.innerWidth-a.offsetLeft,H=o.innerHeight-a.offsetTop,$=Math.min(Math.max(a.offsetWidth+b,U),D),F=Math.min(Math.max(a.offsetHeight+S,K),H);a.style.width=`${$}px`,a.style.height=`${F}px`}y.addEventListener("keydown",b=>{if(!(c||v))switch(b.key){case"ArrowRight":b.preventDefault(),ee(J,0);break;case"ArrowLeft":b.preventDefault(),ee(-J,0);break;case"ArrowDown":b.preventDefault(),ee(0,J);break;case"ArrowUp":b.preventDefault(),ee(0,-J);break}}),y.addEventListener("pointerdown",b=>{if(c||v)return;b.preventDefault();const S=T(),D=b.clientX,H=b.clientY,$=a.offsetWidth,F=a.offsetHeight,q=o.innerWidth-a.offsetLeft,V=o.innerHeight-a.offsetTop;y.setPointerCapture(b.pointerId);const _=Z=>{const G=Math.min(Math.max($+(Z.clientX-D),U),q),ae=Math.min(Math.max(F+(Z.clientY-H),K),V);a.style.width=`${G}px`,a.style.height=`${ae}px`},Y=Z=>{S(),y.releasePointerCapture(Z.pointerId),y.removeEventListener("pointermove",_),y.removeEventListener("pointerup",Y)};y.addEventListener("pointermove",_),y.addEventListener("pointerup",Y)}),a.appendChild(s),a.appendChild(N),a.appendChild(y);const oe=e.anchor?overlayRootFor(e.anchor):n.body;l?(l.appendChild(a),oe.appendChild(l)):oe.appendChild(a);const ve=Ne(n,oe),ie=n.createElement("style");ie.textContent=`@media print{
1
+ import{getUniqueTestNumbers as ke}from"../renderer/buildView.js";import{dieHasValues as Ee}from"../core/dieTable.js";import{dieHasTestData as Ce}from"../renderer/buildWaferMap.js";import{testLabel as re,isDerivedTest as Le,DERIVED_MARK as de,DERIVED_KEY as ue}from"../renderer/testLabel.js";import{prettyKey as Ae}from"../core/utils.js";import{diagnoseMpwLayout as Me,formatMpwDiagnostics as Se}from"../core/compact.js";import{listBinColorSchemes as Be,listValueColorSchemes as De}from"../renderer/colorSchemes.js";import{ICONS as V}from"./icons.js";import{WMAP_VERSION as pe,WMAP_BUILD_TIME as Te}from"./version.js";let fe=!1;export function logWmapVersionOnce(){fe||(fe=!0,console.log(`[wmap] v${pe} (built ${Te})`))}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 C=(e,t)=>`var(--wmap-${e}, ${t})`,Q="var(--wmap-font-size, 12px)",He="var(--wmap-density, 1)",U=e=>`calc(${e}px * ${He})`;export function wireControlHover(e,t="outlined"){let n=null;const a=()=>{!n||e.dataset.on==="true"||(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",a),e.addEventListener("blur",a)}export function controlStyle(e,t=!1){const n={fontSize:FONT.body,cursor:"pointer",borderRadius:RADIUS.control};return e==="bare"?{...n,border:"none",background:"none",padding:"0",color:CLR.icon}:{...n,border:`1px solid ${CLR.controlBorder}`,background:e==="toggle"&&t?CLR.menuActive:"none",color:e==="toggle"&&t?CLR.iconActive:CLR.text,padding:`${SPACE.xxs} ${SPACE.lg}`}}export const SPACE={xxs:U(2),xs:U(4),sm:U(6),md:U(8),lg:U(10),xl:U(12),xxl:U(16),xxxl:U(24)},SHADOW={panel:"0 1px 4px rgba(0,0,0,0.10)",menu:"0 4px 12px rgba(0,0,0,0.15)",modal:"0 20px 60px rgba(0,0,0,0.40)"},MOTION={fast:"0.12s ease",base:"0.2s ease"},LEADING={none:"1",tight:"1.2",base:"1.45"},ALPHA={muted:"0.85",disabled:"0.4"},TRACKING="0.05em",EDGE_GUTTER=SPACE.xl,MAP_CHROME_INSET=SPACE.xs,RADIUS={control:"4px",container:"6px",pill:"999px"},FONT={family:"var(--wmap-font-family, inherit)",meta:`calc(${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 a=getComputedStyle(t??n.documentElement).getPropertyValue("--wmap-font-size").trim(),o=a?parseFloat(a):NaN;return(Number.isFinite(o)?o:12)+e}export const CLR={icon:C("icon","#506784"),iconHover:C("icon-hover","#2a3f5f"),iconActive:C("icon-active","#1a65ca"),bgHover:C("bg-hover","#edf0f8"),bgActive:C("bg-active","#dce8f8"),separator:C("separator","rgba(0,0,0,0.12)"),menuBg:C("surface","#fff"),menuBorder:C("border","rgba(0,0,0,0.12)"),controlBorder:C("control-border",C("border","rgba(0,0,0,0.30)")),menuHover:C("menu-hover","#f0f4fc"),menuActive:C("menu-active","#dce8f8"),canvasBg:`var(--wmap-canvas-bg, ${C("surface","#f5f5f5")})`,panelBg:C("panel-bg","#fafbfc"),label:C("text-muted","#647687"),value:C("text-strong","#1f2f43"),text:C("text","#333"),warnBg:C("warn-bg","#fffbe6"),warnBorder:C("warn-border","#f0c040"),warnText:C("warn-text","#7a5800"),errBg:C("err-bg","#fef2f2"),errBorder:C("err-border","#dc8a8a"),errText:C("err-text","#7a1c1c"),infoBg:C("info-bg","#dce8f8"),infoText:C("info-text","#334155"),findingHighlight:C("selected","#e07a20"),findingIndicator:C("finding-indicator","#b7551a"),barFill:C("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 a of WMAP_TOKEN_NAMES){const o=n.getPropertyValue(`--wmap-${a}`).trim();o&&t.style.setProperty(`--wmap-${a}`,o)}}export function syncWmapPopupTheme(e,t,n){const a=()=>{copyWmapThemeTokens(e,t),n?.()},o=new window.MutationObserver(a);o.observe(e,{attributes:!0,attributeFilter:["style","class"]}),o.observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]});const r=window.matchMedia("(prefers-color-scheme: dark)");return r.addEventListener("change",a),()=>{o.disconnect(),r.removeEventListener("change",a)}}let se=null;export function setDetachWindowOpener(e){se=e}export function openDetachWindow(e){return se?se(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 a=`${t}.png`;if(n){n(e,a);return}downloadBlob(e,a)}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),a=document.createElement("a");a.href=n,a.download=t,a.click(),URL.revokeObjectURL(n)}export function roomForPanel(e){let t=null;return(n,a)=>{t?.(),t=n?e.reserveWidth(a):null}}export function openCompactDiagnostics(e,t,n){const a=Se(Me(e,t),pe),o=n.anchor.ownerDocument,r=openModal({title:"Layout diagnostics",anchor:n.anchor,ownerDocument:o,onClose:()=>{},boxSize:{width:"min(680px, 94vw)",height:"min(480px, 90vh)"}}),m=r.contentWrap;Object.assign(m.style,{flexDirection:"column",padding:"14px 16px",gap:"10px",boxSizing:"border-box"});const i=o.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 d=o.createElement("textarea");d.value=a,d.readOnly=!0,d.setAttribute("aria-label","Layout diagnostics"),Object.assign(d.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 p=o.createElement("div");Object.assign(p.style,{display:"flex",gap:"8px",alignItems:"center"});const s=o.createElement("span");s.setAttribute("role","status"),Object.assign(s.style,{fontSize:FONT.body,color:CLR.text});const E=(k,u)=>{const l=o.createElement("button");return l.type="button",l.textContent=k,Object.assign(l.style,controlStyle("outlined"),{padding:"5px 12px",color:CLR.text}),wireControlHover(l,"outlined"),l.addEventListener("click",u),l},f=E("Copy",()=>{const k=o.defaultView,u=()=>{d.focus(),d.select();let l=!1;try{l=o.execCommand("copy")}catch{l=!1}s.textContent=l?"Copied":"Copying is not available here. Select the text, or save it as a file."};k?.navigator.clipboard?k.navigator.clipboard.writeText(a).then(()=>{s.textContent="Copied"},u):u()}),x=E("Save as file",()=>{saveTextFile(a,"wafermap-layout-diagnostics.txt","text/plain",n.onSaveText),s.textContent=n.onSaveText?"":"Saved"});return p.append(f,x,s),m.append(i,d,p),d.focus(),d.select(),r}export function saveTextFile(e,t,n,a){if(a){a(e,t,n);return}downloadBlob(typeof e=="string"?new Blob([e],{type:n}):e,t)}const Oe='[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",a=>{const o=t();if(o.length===0)return;const r=e.ownerDocument.activeElement,m=r?o.indexOf(r):-1;switch(a.key){case"ArrowDown":a.preventDefault(),o[m<0||m===o.length-1?0:m+1].focus();break;case"ArrowUp":a.preventDefault(),o[m<=0?o.length-1:m-1].focus();break;case"Home":a.preventDefault(),o[0].focus();break;case"End":a.preventDefault(),o[o.length-1].focus();break;case"Enter":case" ":m>=0&&(a.preventDefault(),o[m].click());break;case"Escape":case"Tab":a.preventDefault(),n();break}})}function te(e,t,n){const a=()=>Array.from(e.querySelectorAll(Oe));wireListNavigation(e,a,()=>{n(),t?.focus()});const o=a()[0];o&&nextFrame(()=>o.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 me=new WeakMap;export function menuLayerFor(e){const t=overlayRootFor(e),n=me.get(t);if(n&&n.isConnected)return n;const o=e.ownerDocument.createElement("div");return o.dataset.wmapMenuLayer="1",Object.assign(o.style,{position:"fixed",inset:"0",zIndex:Z_MENU,pointerEvents:"none"}),t.appendChild(o),me.set(t,o),o}const le=new WeakMap;export function getTooltip(e=document){const t=le.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}),le.set(e,n)),e.body.appendChild(n),n}export function hideTooltip(e=document){const t=le.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,a,o={}){const r=menuLayerFor(t);e.parentElement!==r&&r.appendChild(e);const m=e.ownerDocument.defaultView??window;e.style.left="0",e.style.top="0";const i=e.offsetWidth,d=e.offsetHeight,p=8,s=m.innerWidth,E=m.innerHeight;let f=n+14,x=a-8;f+i+p>s&&(f=n-i-6);const k=t.getBoundingClientRect();if(!o.followPointer&&k.height>0&&k.height<=E*.4&&x<k.bottom&&x+d>k.top&&f<k.right&&f+i>k.left){const h=k.bottom+p,c=k.top-d-p;h+d+p<=E?x=h:c>=p&&(x=c)}x+d+p>E&&(x=E-d-p),x<p&&(x=p),e.style.left=`${f}px`,e.style.top=`${x}px`}export function wireTooltip(e,t,n={}){const a=()=>(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 o=m=>{const i=a();if(!i)return;const d=getTooltip(e.ownerDocument);if(d.textContent=i,d.style.display="block",m)positionTooltip(d,e,m.clientX,m.clientY);else{const p=e.getBoundingClientRect();positionTooltip(d,e,p.left+p.width/2,p.top)}},r=()=>hideTooltip(e.ownerDocument);e.addEventListener("mousemove",o),e.addEventListener("mouseleave",r),e.addEventListener("focus",()=>o()),e.addEventListener("blur",r)}export function buildDataModeEntries(e,t,n){const a=e.some(Ce),o=e.some(Ee),r=e.some(s=>s.hbin!=null),m=e.some(s=>s.sbin!=null),i=a?t!==void 0?t.map(s=>({plotMode:"value",activeTest:s.testNumber,label:s.unit?`${re(s,s.testNumber)} (${s.unit})`:re(s,s.testNumber),logScale:s.logScale,...Le(s)?{derived:!0}:{}})):ke(e).map(s=>({plotMode:"value",activeTest:s,label:re(void 0,s)})):[],d=[...r?[{plotMode:"hardBin",label:MODE_LABELS.hardBin}]:[],...m?[{plotMode:"softBin",label:MODE_LABELS.softBin}]:[]],p=n.includeStacked?[...o?[{plotMode:"stackedValues",label:MODE_LABELS.stackedValues}]:[],...r?[{plotMode:"stackedBins",label:MODE_LABELS.stackedBins}]:[],...m?[{plotMode:"stackedSoftBins",label:MODE_LABELS.stackedSoftBins}]:[]]:[];return{testEntries:i,binEntries:d,stackedEntries:p}}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??Ae(e.key)}}export function makeMenuSearchBox(e,t="Filter\u2026",n=document,a){const o=n.createElement("input");return o.type="text",o.placeholder=t,o.setAttribute("aria-label",t),Object.assign(o.style,{display:"block",width:"calc(100% - 20px)",margin:"2px 10px 6px",padding:`${SPACE.xs} ${SPACE.md}`,fontSize:FONT.body,boxSizing:"border-box",background:CLR.menuBg,color:CLR.text,border:`1px solid ${CLR.menuBorder}`,borderRadius:RADIUS.control,outline:"none"}),o.addEventListener("click",r=>r.stopPropagation()),o.addEventListener("mousedown",r=>r.stopPropagation()),o.addEventListener("keydown",r=>{if(r.stopPropagation(),r.key!=="Enter"||!a)return;const m=a();m.length===1&&(r.preventDefault(),m[0].click())}),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,a,o,r,m,i,d=window,p=[]){const{makeMenuRow:s,makeMenuSection:E}=m,f=document.createElement("div"),x=180,u=e.left+x<=(d.innerWidth??1/0)?e.left:Math.max(4,e.right-x);if(Object.assign(f.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:`${x}px`,padding:"4px 0",pointerEvents:"auto"}),t.length)if(f.appendChild(E("Test Value")),t.length<=INLINE_TEST_LIMIT)for(const l of t)f.appendChild(s(l.label,o(l),!0,h=>{h.stopPropagation(),r(l,f)}));else{const l=i==="value",h=s(MODE_LABELS.value+" \u25B6",l,!1,A=>{A.stopPropagation(),g(),B(),A.detail===0&&O()});h.setAttribute("aria-haspopup","menu"),h.style.display="flex",h.style.justifyContent="space-between",h.style.alignItems="center";let c=null,L=null;const g=()=>{L!==null&&(clearTimeout(L),L=null)},w=A=>{const T=A.target;T&&(h.contains(T)||c?.contains(T))||v()},v=()=>{g(),c?.remove(),c=null,d.document.removeEventListener("click",w),h.setAttribute("aria-expanded","false")},O=()=>{const A=c?.querySelector('input, [role="menuitemradio"]');A&&nextFrame(()=>A.focus(),d)},P=()=>{g(),L=setTimeout(v,300)},B=()=>{if(c)return;const A=h.getBoundingClientRect(),T=160,I=320,R=A.right+2+T<=(d.innerWidth??1/0)?A.right+2:Math.max(4,A.left-2-T),N=Math.min(A.top-4,Math.max(4,(d.innerHeight??1/0)-I-4));if(c=document.createElement("div"),c.setAttribute("data-wmap-submenu",""),c.setAttribute("role","menu"),Object.assign(c.style,{position:"fixed",top:`${N}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 y=makeMenuSearchBox(W=>{for(const K of $)K.row.style.display=K.label.includes(W)?"":"none"},"Filter tests\u2026",void 0,()=>$.filter(W=>W.row.style.display!=="none").map(W=>W.row));Object.assign(y.style,{position:"sticky",top:"0",zIndex:"1",background:CLR.menuBg}),c.appendChild(y)}const $=[],F=t.some(y=>y.derived);for(const y of t){const W=s(y.label,o(y),!1,K=>{K.stopPropagation(),v(),r(y,f)},F?{derived:y.derived===!0}:void 0);$.push({row:W,label:y.label.toLowerCase()}),c.appendChild(W)}if(F){const y=d.document.createElement("div");y.setAttribute("role","presentation"),y.textContent=`${de} ${ue}`,Object.assign(y.style,{padding:"6px 14px",fontSize:FONT.meta,color:CLR.label,borderTop:`1px solid ${CLR.menuBorder}`,marginTop:"4px",whiteSpace:"nowrap"}),c.appendChild(y)}c.addEventListener("mouseenter",g),c.addEventListener("mouseleave",P),wireListNavigation(c,()=>$.filter(y=>y.row.style.display!=="none").map(y=>y.row),()=>{v(),h.focus()}),(f.parentElement??d.document.body).appendChild(c),d.document.addEventListener("click",w),h.setAttribute("aria-expanded","true")};f.addEventListener("keydown",A=>{A.key==="Escape"&&v()}),h.addEventListener("mouseenter",()=>{g(),B()}),h.addEventListener("mouseleave",P),f.appendChild(h)}if(n.length){f.appendChild(E("Bins"));for(const l of n)f.appendChild(s(l.label,o(l),!1,h=>{h.stopPropagation(),r(l,f)}))}if(p.length){f.appendChild(E("Metadata"));for(const l of p)f.appendChild(s(l.label,o(l),!1,h=>{h.stopPropagation(),r(l,f)}))}if(a.length){f.appendChild(E("Lot Aggregation"));for(const l of a)f.appendChild(s(l.label,o(l),!1,h=>{h.stopPropagation(),r(l,f)}))}return f.setAttribute("role","menu"),f.setAttribute("aria-label","Plot mode"),f}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)}const ne=new WeakMap;export function openCommandMenu(e,t,n,a,o={}){const r=t.ownerDocument,m=r.defaultView??window;ne.get(r)?.();const{makeMenuSection:i}=createToolbarHelpers(getTooltip(r)),d=buildCheckMenuEl(e,n,{makeMenuSection:i},m);d.setAttribute("role","menu"),d.setAttribute("aria-label",a),o.hook&&(d.dataset[o.hook]="1"),menuLayerFor(t).appendChild(d);const p=m.innerHeight-8;d.getBoundingClientRect().height>p&&Object.assign(d.style,{maxHeight:`${p}px`,overflowY:"auto"});const s=d.getBoundingClientRect();s.bottom>m.innerHeight-4&&(d.style.top=`${Math.max(4,e.top-s.height)}px`),s.right>m.innerWidth-4&&(d.style.left=`${Math.max(4,m.innerWidth-s.width-4)}px`);let E=!1;function f(){E||(E=!0,d.remove(),o.trigger&&markMenuTrigger(o.trigger,!1),r.removeEventListener("pointerdown",x,!0),m.removeEventListener("blur",f),ne.get(r)===f&&ne.delete(r))}function x(k){!d.contains(k.target)&&!o.trigger?.contains(k.target)&&f()}return r.addEventListener("pointerdown",x,!0),m.addEventListener("blur",f),wireMenuA11y(d,o.trigger??t,f),o.trigger&&markMenuTrigger(o.trigger,!0),ne.set(r,f),f}export function wireExpandToggle(e,t){const n=e.ownerDocument;let a=!1;function o(p){a!==p&&(a=p,t(a))}function r(){o(!1)}function m(){o(!a),a&&n.addEventListener("click",r,{once:!0})}const i=p=>{p.stopPropagation(),m()},d=p=>{p.key==="Enter"||p.key===" "?(p.preventDefault(),m()):p.key==="Escape"&&r()};return e.setAttribute("role","button"),e.tabIndex<0&&(e.tabIndex=0),e.addEventListener("click",i),e.addEventListener("keydown",d),{isOpen:()=>a,close:r,destroy(){e.removeEventListener("click",i),e.removeEventListener("keydown",d),n.removeEventListener("click",r)}}}export function buildCheckMenuEl(e,t,n,a=window){const{makeMenuSection:o}=n,r=a.document,m=r.createElement("div"),i=168,p=e.left+i<=(a.innerWidth??1/0)?e.left:Math.max(4,e.right-i);Object.assign(m.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:`${i}px`,padding:"4px 0",pointerEvents:"auto"});for(const s of t)if("section"in s)m.appendChild(o(s.section));else{const E=s.enabled!==!1;if(!E&&!s.disabledHint)continue;const f=r.createElement("div");s.action?f.setAttribute("role","menuitem"):(f.setAttribute("role","menuitemcheckbox"),f.setAttribute("aria-checked",s.active?"true":"false")),f.tabIndex=-1,E||(f.setAttribute("aria-disabled","true"),wireTooltip(f,s.disabledHint)),Object.assign(f.style,{display:"flex",alignItems:"center",gap:SPACE.sm,padding:"6px 14px",fontSize:FONT.body,cursor:E?"pointer":"default",color:E?s.active?CLR.iconActive:CLR.text:CLR.label,fontWeight:s.active?"700":"400",background:s.active?CLR.menuActive:"transparent",whiteSpace:"nowrap"});const x=r.createElement("span");Object.assign(x.style,{width:"12px",flexShrink:"0",color:CLR.iconActive,visibility:s.active?"visible":"hidden"}),x.textContent=s.action?"":"\u2713",x.setAttribute("aria-hidden","true");const k=r.createElement("span");k.textContent=s.label,f.appendChild(x),f.appendChild(k),E?(f.addEventListener("mouseenter",()=>{s.active||(f.style.background=CLR.menuHover)}),f.addEventListener("mouseleave",()=>{f.style.background=s.active?CLR.menuActive:"transparent"}),f.addEventListener("focus",()=>{s.active||(f.style.background=CLR.menuHover)}),f.addEventListener("blur",()=>{f.style.background=s.active?CLR.menuActive:"transparent"}),f.addEventListener("click",u=>{u.stopPropagation(),s.onClick(u)})):f.addEventListener("click",u=>{u.stopPropagation()}),m.appendChild(f)}return m}export function createToolbarHelpers(e){const t=e.ownerDocument;let n=null;const a=u=>menuLayerFor(u);function o(u,l,h){const c=t.createElement("button");return c.innerHTML=V[u],c.type="button",c.ariaLabel=l,Object.assign(c.style,{display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",padding:"0",border:"none",borderRadius:RADIUS.control,background:"transparent",color:CLR.icon,cursor:"pointer",pointerEvents:"auto",transition:`background ${MOTION.fast}, color ${MOTION.fast}`,flexShrink:"0"}),c.addEventListener("mouseenter",L=>{c.dataset.active||(c.style.background=CLR.bgHover,c.style.color=CLR.iconHover),e.textContent=c.ariaLabel??l,e.style.display="block",positionTooltip(e,c,L.clientX,L.clientY)}),c.addEventListener("mousemove",L=>{e.style.display==="block"&&positionTooltip(e,c,L.clientX,L.clientY)}),c.addEventListener("mouseleave",()=>{c.dataset.active||(c.style.background="transparent",c.style.color=CLR.icon),e.style.display="none"}),c.addEventListener("click",()=>{e.style.display="none",h()}),c}function r(u,l){l?(u.dataset.active="1",u.style.background=CLR.bgActive,u.style.color=CLR.iconActive):(delete u.dataset.active,u.style.background="transparent",u.style.color=CLR.icon)}function m(){const u=t.createElement("div");return Object.assign(u.style,{width:"1px",height:"18px",background:CLR.separator,margin:"0 2px",flexShrink:"0"}),u.dataset.wmapSep="1",u}function i(u){let l=!1,h=null;for(const c of Array.from(u.children))c.dataset.wmapSep?l&&!h?h=c:c.style.display="none":c.style.display!=="none"&&(h&&(h.style.display="",h=null),l=!0);h&&(h.style.display="none")}function d(u){for(const l of Array.from(u.children))if(!(l.dataset.wmapSep||l.style.display==="none"))if(l.tagName==="DIV"&&!l.getAttribute("role")&&l.children.length){if(d(l))return!0}else return!0;return!1}function p(u,l){u.style.display=d(u)?l:"none"}function s(u,l,h,c,L){const g=t.createElement("div");if(L){const w=t.createElement("span");w.textContent=L.derived?de:"",w.setAttribute("aria-hidden","true"),Object.assign(w.style,{display:"inline-block",width:"1.1em"}),g.append(w,u),L.derived&&g.setAttribute("aria-label",`${u} \u2014 ${ue.toLowerCase()}`)}else g.textContent=u;return g.setAttribute("role","menuitemradio"),g.setAttribute("aria-checked",l?"true":"false"),g.tabIndex=-1,Object.assign(g.style,{padding:`6px 14px 6px ${h?"26px":"14px"}`,fontSize:FONT.body,cursor:"pointer",color:l?CLR.iconActive:CLR.text,fontWeight:l?"700":"400",background:l?CLR.menuActive:"transparent",whiteSpace:"nowrap"}),g.addEventListener("mouseenter",()=>{l||(g.style.background=CLR.menuHover)}),g.addEventListener("mouseleave",()=>{g.style.background=l?CLR.menuActive:"transparent"}),g.addEventListener("focus",()=>{l||(g.style.background=CLR.menuHover)}),g.addEventListener("blur",()=>{g.style.background=l?CLR.menuActive:"transparent"}),g.addEventListener("click",c),g}function E(u){const l=t.createElement("div");return l.textContent=u,l.setAttribute("role","presentation"),Object.assign(l.style,{padding:"5px 14px 2px",fontSize:FONT.body,fontWeight:"600",letterSpacing:TRACKING,color:CLR.label,textTransform:"uppercase",pointerEvents:"none",userSelect:"none"}),l}function f(u,l,h,c,L){const g=()=>{n&&(n.remove(),n=null),w.setAttribute("aria-expanded","false")},w=o(u,l,()=>{if(n){g();return}const v=t.createElement("div"),O=w.getBoundingClientRect(),P=w.ownerDocument.defaultView??window,B=148,T=O.left+B<=(P.innerWidth??1/0)?O.left:Math.max(4,O.right-B);Object.assign(v.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:`${B}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===c();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 N=()=>{I.value!==c()&&(M.style.background=CLR.menuHover)},$=()=>{M.style.background=I.value===c()?CLR.menuActive:"transparent"};M.addEventListener("mouseenter",N),M.addEventListener("mouseleave",$),M.addEventListener("focus",N),M.addEventListener("blur",$),M.addEventListener("click",F=>{F.stopPropagation(),L(I.value),g()}),v.appendChild(M)}v.setAttribute("role","menu"),v.setAttribute("aria-label",l),a(w).appendChild(v),n=v,w.setAttribute("aria-expanded","true"),te(v,w,g)});return w.setAttribute("aria-haspopup","menu"),w.setAttribute("aria-expanded","false"),w}function x(u,l,h,c){function L(){return buildCheckMenuEl(w.getBoundingClientRect(),h().map(v=>"section"in v?v:{...v,onClick:O=>{v.closeMenu&&g(),v.onClick(O),c(w);const P=n;if(!P)return;const B=L();B.setAttribute("role","menu"),B.setAttribute("aria-label",l),P.replaceWith(B),n=B,te(B,w,g)}}),{makeMenuSection:E},w.ownerDocument.defaultView??window)}const g=()=>{n&&(n.remove(),n=null),w.setAttribute("aria-expanded","false")},w=o(u,l,()=>{if(n){g();return}const v=L();v.setAttribute("role","menu"),v.setAttribute("aria-label",l),a(w).appendChild(v),n=v,w.setAttribute("aria-expanded","true"),te(v,w,g)});return w.setAttribute("aria-haspopup","menu"),w.setAttribute("aria-expanded","false"),c(w),w}function k(u){const l=u.target?.closest?.("[data-wmap-submenu]");if(n&&!n.contains(u.target)&&!l&&(n.remove(),n=null,u.target?.getAttribute?.("aria-haspopup")!=="menu"))for(const c of document.querySelectorAll('[aria-haspopup="menu"][aria-expanded="true"]'))c.setAttribute("aria-expanded","false")}return{makeBtn:o,setActive:r,makeSep:m,syncSeparators:i,syncToolbarVisible:p,makeMenuRow:s,makeMenuSection:E,makeDropdown:f,makeCheckMenuBtn:x,closeOpenMenu:k,getOpenMenu:()=>n,setOpenMenu:u=>{n=u}}}const Ie=7e3;let Re=0;function be(){return Ie+ ++Re}const $e=32,We=6;let ze=0;function Pe(){return ze++%We*$e}function Ne(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 he(e){const t=e.mode==="modal",n=e.ownerDocument??document,a=n.defaultView??window,o=n.body.style.overflow;t&&(n.body.style.overflow="hidden");let r=null;t&&(r=n.createElement("div"),r.id="wmap-modal-backdrop",Object.assign(r.style,{position:"fixed",inset:"0",background:"rgba(0,0,0,0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:Z_ABOVE,backdropFilter:"blur(3px)"}));const m=n.activeElement,i=n.createElement("div");i.className=t?"wmap-modal-box wmap-overlay-box":"wmap-window-box wmap-overlay-box",i.setAttribute("role","dialog"),t&&i.setAttribute("aria-modal","true"),i.setAttribute("aria-label",e.title??"Expanded wafer map"),i.tabIndex=-1;let d=e.boxSize?.width??"min(90vw, 700px)",p=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:d,height:p,boxShadow:SHADOW.modal,minWidth:"320px",minHeight:"240px",maxWidth:"100vw",maxHeight:"100vh",zIndex:t?Z_ABOVE2:String(be())}),!t){const b=Pe();Object.assign(i.style,{position:"fixed",top:`${Math.round(a.innerHeight*.08)+b}px`,left:`${Math.round(a.innerWidth*.08)+b}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 E={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 b=n.createElement("span");b.textContent=e.title,b.title=e.title,b.dataset.wmapWindowTitle="1",Object.assign(b.style,{fontWeight:"700",fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"}),s.appendChild(b)}const f=n.createElement("div");f.style.flex="1",s.appendChild(f);let x=null;t||(x=n.createElement("button"),x.type="button",x.innerHTML=V.collapse,x.setAttribute("aria-label","Collapse"),wireTooltip(x),Object.assign(x.style,E),wireControlHover(x),x.addEventListener("click",()=>A(!v)),s.appendChild(x));let k=null;e.printable&&(k=n.createElement("button"),k.type="button",k.innerHTML=V.print,k.setAttribute("aria-label","Print / Save as PDF"),wireTooltip(k),Object.assign(k.style,E),wireControlHover(k),k.addEventListener("click",()=>{typeof e.printable=="function"?e.printable():a.print()}),s.appendChild(k));const u=n.createElement("button");u.type="button",u.innerHTML=V.maximize,u.setAttribute("aria-label","Maximize (F)"),wireTooltip(u),Object.assign(u.style,E),wireControlHover(u),u.addEventListener("click",()=>w(!c));const l=n.createElement("button");l.type="button",l.innerHTML=V.close,l.setAttribute("aria-label","Close (Esc)"),wireTooltip(l),Object.assign(l.style,E),wireControlHover(l),l.addEventListener("click",N);const h=e.maximizable!==!1;h&&s.appendChild(u),s.appendChild(l);let c=!1,L="",g="";function w(b){c=b,u.innerHTML=c?V.minimize:V.maximize,u.setAttribute("aria-label",c?"Restore (F)":"Maximize (F)"),x&&(x.style.display=c?"none":""),y.style.display=c?"none":"block",c?(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=d,i.style.height=p,t||(i.style.top=L,i.style.left=g)),e.onMaximizeChange?.(c,i)}let v=!1,O="",P="";const B=220;function A(b){v=b,x.innerHTML=v?V.uncollapse:V.collapse,x.setAttribute("aria-label",v?"Show contents":"Collapse"),y.style.display=v?"none":"block",v?(O=i.style.height,P=i.style.width,i.style.minHeight="0",i.style.height="auto",i.style.minWidth="0",i.style.width=`${B}px`,u.disabled=!0,u.style.opacity="0.4",u.style.cursor="default",F.style.display="none"):(i.style.minHeight="240px",i.style.height=O||p,i.style.minWidth="320px",i.style.width=P||d,u.disabled=!1,u.style.opacity="1",u.style.cursor="pointer",F.style.display="flex")}function T(){const b=n.body.style.userSelect;return n.body.style.userSelect="none",()=>{n.body.style.userSelect=b}}t||(s.style.cursor="move",s.addEventListener("pointerdown",b=>{if(c||b.target.closest('button, [role="button"]'))return;b.preventDefault();const S=T(),D=b.clientX,H=b.clientY,z=i.offsetTop,j=i.offsetLeft,q=a.innerHeight-s.offsetHeight,Y=a.innerWidth-40,_=40-i.offsetWidth;s.setPointerCapture(b.pointerId);const X=G=>{const ae=Math.min(Math.max(z+(G.clientY-H),0),q),we=Math.min(Math.max(j+(G.clientX-D),_),Y);i.style.top=`${ae}px`,i.style.left=`${we}px`},Z=G=>{S(),s.releasePointerCapture(G.pointerId),s.removeEventListener("pointermove",X),s.removeEventListener("pointerup",Z)};s.addEventListener("pointermove",X),s.addEventListener("pointerup",Z)}));const I='button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"]),[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';function M(b){const S=Array.from(i.querySelectorAll(I)).filter(j=>j.offsetParent!==null||j===n.activeElement);if(S.length===0){b.preventDefault(),i.focus();return}const D=S[0],H=S[S.length-1],z=n.activeElement;b.shiftKey&&(z===D||!i.contains(z))?(b.preventDefault(),H.focus()):!b.shiftKey&&z===H&&(b.preventDefault(),D.focus())}const R=b=>{if(b.key==="Escape"){b.defaultPrevented||N();return}const S=isTextEntry(b.target);if(t&&!S&&(b.key==="e"||b.key==="E")){N();return}if(t&&b.key==="Tab"){M(b);return}h&&!S&&(b.key==="f"||b.key==="F")&&!v&&w(!c)};function N(){t?n.removeEventListener("keydown",R):i.removeEventListener("keydown",R),ie.remove(),ve(),hideTooltip(n),reparentTooltip(n.body),r?r.remove():i.remove(),t&&(n.body.style.overflow=o),m?.focus?.(),e.onClose()}function $(){t||(i.style.zIndex=String(be()))}const F=n.createElement("div");Object.assign(F.style,{flex:"1",minHeight:"0",minWidth:"0",display:"flex",overflow:"hidden"});const y=n.createElement("div");y.tabIndex=0,y.setAttribute("role","separator"),y.setAttribute("aria-label","Resize window (arrow keys, or drag)"),Object.assign(y.style,{position:"absolute",right:"0",bottom:"0",width:"16px",height:"16px",cursor:"nwse-resize",touchAction:"none"}),y.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>',y.style.color=CLR.label;const W=320,K=240,J=20;function ee(b,S){const D=a.innerWidth-i.offsetLeft,H=a.innerHeight-i.offsetTop,z=Math.min(Math.max(i.offsetWidth+b,W),D),j=Math.min(Math.max(i.offsetHeight+S,K),H);i.style.width=`${z}px`,i.style.height=`${j}px`}y.addEventListener("keydown",b=>{if(!(c||v))switch(b.key){case"ArrowRight":b.preventDefault(),ee(J,0);break;case"ArrowLeft":b.preventDefault(),ee(-J,0);break;case"ArrowDown":b.preventDefault(),ee(0,J);break;case"ArrowUp":b.preventDefault(),ee(0,-J);break}}),y.addEventListener("pointerdown",b=>{if(c||v)return;b.preventDefault();const S=T(),D=b.clientX,H=b.clientY,z=i.offsetWidth,j=i.offsetHeight,q=a.innerWidth-i.offsetLeft,Y=a.innerHeight-i.offsetTop;y.setPointerCapture(b.pointerId);const _=Z=>{const G=Math.min(Math.max(z+(Z.clientX-D),W),q),ae=Math.min(Math.max(j+(Z.clientY-H),K),Y);i.style.width=`${G}px`,i.style.height=`${ae}px`},X=Z=>{S(),y.releasePointerCapture(Z.pointerId),y.removeEventListener("pointermove",_),y.removeEventListener("pointerup",X)};y.addEventListener("pointermove",_),y.addEventListener("pointerup",X)}),i.appendChild(s),i.appendChild(F),i.appendChild(y);const oe=e.anchor?overlayRootFor(e.anchor):n.body;r?(r.appendChild(i),oe.appendChild(r)):oe.appendChild(i);const ve=Ne(n,oe),ie=n.createElement("style");ie.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(ie),reparentTooltip(a),t?(l.addEventListener("click",b=>{b.target===l&&z()}),n.addEventListener("keydown",R)):(a.addEventListener("keydown",R),a.addEventListener("mousedown",P),P()),nextFrame(()=>(e.initialFocus?.()??(r.isConnected?r:a)).focus(),o);function ye(b){p=b,!c&&!v&&(a.style.height=b)}function ge(b){const S=()=>{};if(c||v||!(b>0))return S;const D=a.getBoundingClientRect(),H=Math.min(D.width+b,o.innerWidth*.96);if(!(H>D.width+.5))return S;const $=a.style.width,F=d,q=a.style.left,V=`${Math.round(H)}px`;a.style.width=V,d=V;let _=null;if(!t){const Y=D.left+H-o.innerWidth;Y>0&&(_=`${Math.max(0,Math.round(D.left-Y-8))}px`,a.style.left=_)}return()=>{a.style.width===V&&!c&&!v&&(a.style.width=$),d===V&&(d=F),_!==null&&a.style.left===_&&(a.style.left=q)}}return{backdrop:l,box:a,contentWrap:N,close:z,bringToFront:P,setNaturalHeight:ye,reserveWidth:ge}}export function isTextEntry(e){const t=e;if(!t||typeof t.tagName!="string")return!1;const n=t.tagName;return n==="TEXTAREA"||n==="SELECT"?!0:n==="INPUT"?!["checkbox","radio","button","submit","reset","range","color","file","image"].includes(t.type):t.isContentEditable===!0}export function openModal(e){return he({...e,mode:"modal"})}export function openFloatingWindow(e){return he({...e,mode:"window"})}const ce=new WeakSet;export function openReparentedModal(e,t={}){if(e.length===0||e.some(i=>ce.has(i)))return null;const n=e.map(i=>({el:i,parent:i.parentElement,next:i.nextSibling})),o=openModal({ownerDocument:t.ownerDocument,title:t.title,boxSize:t.boxSize,anchor:t.anchor??e[0],onClose:()=>{for(const i of n){if(ce.delete(i.el),!i.parent)continue;const l=i.next&&i.next.parentNode===i.parent?i.next:null;i.parent.insertBefore(i.el,l)}t.onClosed?.()}});for(const i of n)ce.add(i.el),o.contentWrap.appendChild(i.el);return o}export function makePaletteBtn(e,t,n,o){const i=e.makeCheckMenuBtn("palette","Colour scheme",()=>{const f=t(),a=[];if(f.plotMode==="hardBin"||f.plotMode==="softBin"){const d=f.binColorScheme??"default";a.push({section:"Bin colours"});for(const p of Be())a.push({label:p.label,active:d===p.name,onClick:()=>o({binColorScheme:p.name})});if(n()){const p=f.useDefinedBinColors??!0;a.push({section:"Bin definitions"}),a.push({label:"Use colours from bin definitions",active:p,onClick:()=>o({useDefinedBinColors:!p})})}}else{const d=f.valueColorScheme??"default";a.push({section:"Value colours"});for(const s of De())a.push({label:s.label,active:d===s.name,onClick:()=>o({valueColorScheme:s.name})});const p=f.reverseValueScheme??!1;a.push({section:"Direction"}),a.push({label:"Reverse gradient",active:p,onClick:()=>o({reverseValueScheme:!p})})}return a},()=>{});function l(){i.style.display=t().plotMode==="metadata"?"none":""}return{btn:i,sync:l}}export function requestedPassFailDisplay(e){return e.passFailDisplay??"off"}export function overlayMenuRows(e,t,n,o,i){const l=i?.on?{enabled:!1,disabledHint:"Not drawn in the compact layout"}:void 0;return[...i?[{label:"Compact layout",active:i.on,enabled:i.offered||i.on,disabledHint:"Needs a repeating multi-project layout",onClick:()=>i.onChange(!i.on)},{label:"Layout diagnostics",active:!1,action:!0,closeMenu:!0,onClick:()=>i.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:i?.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)},f=>o({passFailDisplay:f})),{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 i(){const l=t(),f=l.plotMode,a=f==="value"||f==="stackedValues";o.style.display=a&&requestedPassFailDisplay(l)==="off"&&!l.functionalActive?"":"none",e.setActive(o,!!l.logScale)}return{btn:o,sync:i}}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 i=e.makeCheckMenuBtn("legend","Legend style",()=>{const f=t().legendPosition??"default",a=[];let d=!0;if(o){const p=o.blockedReason();d=p?!0:o.get(),a.push({label:"Legend on each map",active:d,enabled:!p,disabledHint:p??void 0,onClick:()=>o.set(!o.get())})}if(xe(t().plotMode)){o&&a.push({section:"Position on each map"});for(const p of Fe)a.push({label:p.label,active:d&&f===p.value,enabled:d,disabledHint:d?void 0:'Turn on "Legend on each map" to position it',onClick:()=>n(p.value)})}return a},()=>{});function l(){i.style.display=o||xe(t().plotMode)?"":"none"}return{btn:i,sync:l}}function xe(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=i=>n({...i,showXYIndicator:!0});return e.makeCheckMenuBtn("orient","Orientation",()=>[{section:"Rotate"},{label:"Rotate 90\xB0 clockwise",active:!1,onClick:()=>{const i=t().rotation??0;o({rotation:ROTATIONS[(ROTATIONS.indexOf(i)+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})}],i=>{const{rotation:l,flipX:f,flipY:a}=t();e.setActive(i,!!(l||f||a))})}
9
+ }`,n.head.appendChild(ie),reparentTooltip(i),t?(r.addEventListener("click",b=>{b.target===r&&N()}),n.addEventListener("keydown",R)):(i.addEventListener("keydown",R),i.addEventListener("mousedown",$),$()),nextFrame(()=>(e.initialFocus?.()??(l.isConnected?l:i)).focus(),a);function ye(b){p=b,!c&&!v&&(i.style.height=b)}function ge(b){const S=()=>{};if(c||v||!(b>0))return S;const D=i.getBoundingClientRect(),H=Math.min(D.width+b,a.innerWidth*.96);if(!(H>D.width+.5))return S;const z=i.style.width,j=d,q=i.style.left,Y=`${Math.round(H)}px`;i.style.width=Y,d=Y;let _=null;if(!t){const X=D.left+H-a.innerWidth;X>0&&(_=`${Math.max(0,Math.round(D.left-X-8))}px`,i.style.left=_)}return()=>{i.style.width===Y&&!c&&!v&&(i.style.width=z),d===Y&&(d=j),_!==null&&i.style.left===_&&(i.style.left=q)}}return{backdrop:r,box:i,contentWrap:F,close:N,bringToFront:$,setNaturalHeight:ye,reserveWidth:ge}}export function isTextEntry(e){const t=e;if(!t||typeof t.tagName!="string")return!1;const n=t.tagName;return n==="TEXTAREA"||n==="SELECT"?!0:n==="INPUT"?!["checkbox","radio","button","submit","reset","range","color","file","image"].includes(t.type):t.isContentEditable===!0}export function openModal(e){return he({...e,mode:"modal"})}export function openFloatingWindow(e){return he({...e,mode:"window"})}const ce=new WeakSet;export function openReparentedModal(e,t={}){if(e.length===0||e.some(o=>ce.has(o)))return null;const n=e.map(o=>({el:o,parent:o.parentElement,next:o.nextSibling})),a=openModal({ownerDocument:t.ownerDocument,title:t.title,boxSize:t.boxSize,anchor:t.anchor??e[0],onClose:()=>{for(const o of n){if(ce.delete(o.el),!o.parent)continue;const r=o.next&&o.next.parentNode===o.parent?o.next:null;o.parent.insertBefore(o.el,r)}t.onClosed?.()}});for(const o of n)ce.add(o.el),a.contentWrap.appendChild(o.el);return a}export function makePaletteBtn(e,t,n,a){const o=e.makeCheckMenuBtn("palette","Colour scheme",()=>{const m=t(),i=[];if(m.plotMode==="hardBin"||m.plotMode==="softBin"){const d=m.binColorScheme??"default";i.push({section:"Bin colours"});for(const p of Be())i.push({label:p.label,active:d===p.name,onClick:()=>a({binColorScheme:p.name})});if(n()){const p=m.useDefinedBinColors??!0;i.push({section:"Bin definitions"}),i.push({label:"Use colours from bin definitions",active:p,onClick:()=>a({useDefinedBinColors:!p})})}}else{const d=m.valueColorScheme??"default";i.push({section:"Value colours"});for(const s of De())i.push({label:s.label,active:d===s.name,onClick:()=>a({valueColorScheme:s.name})});const p=m.reverseValueScheme??!1;i.push({section:"Direction"}),i.push({label:"Reverse gradient",active:p,onClick:()=>a({reverseValueScheme:!p})})}return i},()=>{});function r(){o.style.display=t().plotMode==="metadata"?"none":""}return{btn:o,sync:r}}export function requestedPassFailDisplay(e){return e.passFailDisplay??"off"}export function overlayMenuRows(e,t,n,a,o){const r=o?.on?{enabled:!1,disabledHint:"Not drawn in the compact layout"}:void 0;return[...o?[{label:"Compact layout",active:o.on,enabled:o.offered||o.on,disabledHint:"Needs a repeating multi-project layout",onClick:()=>o.onChange(!o.on)},{label:"Layout diagnostics",active:!1,action:!0,closeMenu:!0,onClick:()=>o.onDiagnostics()},{section:""}]:[],{label:"Ring boundaries",active:!!e.showRingBoundaries,...r,onClick:()=>a({showRingBoundaries:!e.showRingBoundaries})},{label:"Quadrant lines",active:!!e.showQuadrantBoundaries,...r,onClick:()=>a({showQuadrantBoundaries:!e.showQuadrantBoundaries})},{label:"Die labels",active:!!e.showDieLabels,onClick:()=>a({showDieLabels:!e.showDieLabels})},{label:"Reticle grid",active:!!e.showReticle,enabled:o?.on?!1:t,...r?{disabledHint:r.disabledHint}:{},onClick:()=>a({showReticle:!e.showReticle})},{label:"XY indicator",active:!!e.showXYIndicator,onClick:()=>a({showXYIndicator:!e.showXYIndicator})},{label:"Axis labels",active:!!e.showAxes,onClick:()=>a({showAxes:!e.showAxes})},...passFailMenuRows({...n,display:requestedPassFailDisplay(e)},m=>a({passFailDisplay:m})),{label:"Mark failing dies",active:!!e.markFailingDies,enabled:n.binMode,disabledHint:n.binMode?void 0:"Available on hard/soft bin maps",onClick:()=>a({markFailingDies:!e.markFailingDies})},{section:""},{label:"Clear overlays",active:!1,action:!0,enabled:anyOverlayActive(e),disabledHint:"No overlays are active",onClick:()=>a({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 a=e.makeBtn("logScale","Toggle log scale",()=>{n({logScale:!t().logScale})});function o(){const r=t(),m=r.plotMode,i=m==="value"||m==="stackedValues";a.style.display=i&&requestedPassFailDisplay(r)==="off"&&!r.functionalActive?"":"none",e.setActive(a,!!r.logScale)}return{btn:a,sync:o}}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,a){const o=e.makeCheckMenuBtn("legend","Legend style",()=>{const m=t().legendPosition??"default",i=[];let d=!0;if(a){const p=a.blockedReason();d=p?!0:a.get(),i.push({label:"Legend on each map",active:d,enabled:!p,disabledHint:p??void 0,onClick:()=>a.set(!a.get())})}if(xe(t().plotMode)){a&&i.push({section:"Position on each map"});for(const p of Fe)i.push({label:p.label,active:d&&m===p.value,enabled:d,disabledHint:d?void 0:'Turn on "Legend on each map" to position it',onClick:()=>n(p.value)})}return i},()=>{});function r(){o.style.display=a||xe(t().plotMode)?"":"none"}return{btn:o,sync:r}}function xe(e){return e==="hardBin"||e==="softBin"||e==="metadata"}export function makeOverlaysBtn(e,t,n){return e.makeCheckMenuBtn("overlays","Overlays",()=>t(),a=>e.setActive(a,n()))}export function makeOrientationBtn(e,t,n){const a=o=>n({...o,showXYIndicator:!0});return e.makeCheckMenuBtn("orient","Orientation",()=>[{section:"Rotate"},{label:"Rotate 90\xB0 clockwise",active:!1,onClick:()=>{const o=t().rotation??0;a({rotation:ROTATIONS[(ROTATIONS.indexOf(o)+1)%4]})}},{section:"Flip"},{label:"Flip horizontal",active:!!t().flipX,onClick:()=>a({flipX:!t().flipX})},{label:"Flip vertical",active:!!t().flipY,onClick:()=>a({flipY:!t().flipY})},{section:""},{label:"Reset orientation",active:!1,action:!0,enabled:!!(t().rotation||t().flipX||t().flipY),disabledHint:"Already in the original orientation",onClick:()=>n({rotation:0,flipX:!1,flipY:!1})}],o=>{const{rotation:r,flipX:m,flipY:i}=t();e.setActive(o,!!(r||m||i))})}