@wafertools/wafermap 0.24.3 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +59 -0
  2. package/dist/packages/canvas-adapter/charts/capability.js +1 -1
  3. package/dist/packages/canvas-adapter/charts/chartShell.d.ts +16 -0
  4. package/dist/packages/canvas-adapter/charts/chartShell.js +1 -1
  5. package/dist/packages/canvas-adapter/charts/correlation.js +1 -1
  6. package/dist/packages/canvas-adapter/charts/histogram.js +1 -1
  7. package/dist/packages/canvas-adapter/charts/scatter.js +1 -1
  8. package/dist/packages/canvas-adapter/dieList.d.ts +17 -0
  9. package/dist/packages/canvas-adapter/dieList.js +7 -7
  10. package/dist/packages/canvas-adapter/icons.js +1 -1
  11. package/dist/packages/canvas-adapter/index.d.ts +4 -0
  12. package/dist/packages/canvas-adapter/index.js +1 -1
  13. package/dist/packages/canvas-adapter/renderWaferGallery.d.ts +14 -1
  14. package/dist/packages/canvas-adapter/renderWaferGallery.js +6 -6
  15. package/dist/packages/canvas-adapter/renderWaferMap.d.ts +22 -0
  16. package/dist/packages/canvas-adapter/renderWaferMap.js +1 -1
  17. package/dist/packages/canvas-adapter/summaryPanel.js +3 -3
  18. package/dist/packages/canvas-adapter/toCanvas.d.ts +11 -0
  19. package/dist/packages/canvas-adapter/toCanvas.js +1 -1
  20. package/dist/packages/canvas-adapter/toolbar.d.ts +108 -6
  21. package/dist/packages/canvas-adapter/toolbar.js +2 -2
  22. package/dist/packages/canvas-adapter/userGuideHtml.d.ts +1 -1
  23. package/dist/packages/canvas-adapter/userGuideHtml.js +42 -4
  24. package/dist/packages/canvas-adapter/version.d.ts +2 -2
  25. package/dist/packages/canvas-adapter/version.js +1 -1
  26. package/dist/packages/renderer/buildView.d.ts +22 -0
  27. package/dist/packages/renderer/buildView.js +1 -1
  28. package/dist/packages/renderer/buildWaferMap.d.ts +5 -1
  29. package/dist/packages/renderer/buildWaferMap.js +1 -1
  30. package/dist/packages/stats/analyzeWaferLot.js +1 -1
  31. package/dist/packages/stats/renderSummaryReport.js +1 -1
  32. package/dist/packages/stats/reportHtml.d.ts +6 -4
  33. package/dist/packages/stats/types.d.ts +14 -1
  34. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- import{getUniqueTestNumbers as ue}from"../renderer/buildView.js";import{dieHasTestData as pe}from"../renderer/buildWaferMap.js";import{prettyKey as fe}from"../core/utils.js";import{listColorSchemes as oe}from"../renderer/colorSchemes.js";import{ICONS as $}from"./icons.js";import{WMAP_VERSION as me,WMAP_BUILD_TIME as be}from"./version.js";let ie=!1;export function logWmapVersionOnce(){ie||(ie=!0,console.log(`[wmap] v${me} (built ${be})`))}export const WMAP_TOKEN_NAMES=["z","icon","icon-hover","icon-active","bg-hover","bg-active","separator","surface","border","menu-hover","menu-active","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","bar-fill-muted"];const w=(e,n)=>`var(--wmap-${e}, ${n})`;export const CLR={icon:w("icon","#506784"),iconHover:w("icon-hover","#2a3f5f"),iconActive:w("icon-active","#1a65ca"),bgHover:w("bg-hover","#edf0f8"),bgActive:w("bg-active","#dce8f8"),separator:w("separator","rgba(0,0,0,0.12)"),menuBg:w("surface","#fff"),menuBorder:w("border","rgba(0,0,0,0.12)"),menuHover:w("menu-hover","#f0f4fc"),menuActive:w("menu-active","#dce8f8"),panelBg:w("panel-bg","#fafbfc"),label:w("text-muted","#647687"),value:w("text-strong","#1f2f43"),text:w("text","#333"),warnBg:w("warn-bg","#fffbe6"),warnBorder:w("warn-border","#f0c040"),warnText:w("warn-text","#7a5800"),errBg:w("err-bg","#fef2f2"),errBorder:w("err-border","#dc8a8a"),errText:w("err-text","#7a1c1c"),infoBg:w("info-bg","#dce8f8"),infoText:w("info-text","#334155"),findingHighlight:w("selected","#e07a20"),findingIndicator:w("finding-indicator","#b7551a"),barFill:w("bar-fill","#2a6fc0"),barFillMuted:w("bar-fill-muted","#94a3b8")};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_ABOVE2=`calc(var(--wmap-z, ${DEFAULT_OVERLAY_Z}) + 2)`;export function applyOverlayZ(e){if(e==null)return()=>{};const n=document.documentElement,t=n.style.getPropertyValue("--wmap-z");return n.style.setProperty("--wmap-z",String(e)),()=>{t?n.style.setProperty("--wmap-z",t):n.style.removeProperty("--wmap-z")}}export function copyWmapThemeTokens(e,n){const t=getComputedStyle(e);for(const o of WMAP_TOKEN_NAMES){const a=t.getPropertyValue(`--wmap-${o}`).trim();a&&n.style.setProperty(`--wmap-${o}`,a)}}export function syncWmapPopupTheme(e,n,t){const o=()=>{copyWmapThemeTokens(e,n),t?.()},a=new window.MutationObserver(o);a.observe(e,{attributes:!0,attributeFilter:["style","class"]}),a.observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]});const r=window.matchMedia("(prefers-color-scheme: dark)");return r.addEventListener("change",o),()=>{a.disconnect(),r.removeEventListener("change",o)}}let ee=null;export function setDetachWindowOpener(e){ee=e}export function openDetachWindow(e){return ee?ee(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,n,t){const o=`${n}.png`;if(t){t(e,o);return}const a=URL.createObjectURL(e),r=document.createElement("a");r.href=a,r.download=o,r.click(),URL.revokeObjectURL(a)}export function saveTextFile(e,n,t,o){if(o){o(e,n,t);return}const a=new Blob([e],{type:t}),r=URL.createObjectURL(a),c=document.createElement("a");c.href=r,c.download=n,c.click(),URL.revokeObjectURL(r)}const he='[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';export function nextFrame(e,n=window){const t=n.requestAnimationFrame;typeof t=="function"?t.call(n,e):setTimeout(e,0)}function Oe(e,n,t){e.setAttribute("role","menu"),e.setAttribute("aria-label",n);for(const o of Array.from(e.children)){const a=t(o);a&&(o.setAttribute("role",a),o.tabIndex=-1)}}function G(e,n,t){const o=()=>Array.from(e.querySelectorAll(he));e.addEventListener("keydown",r=>{const c=o();if(c.length===0)return;const i=e.ownerDocument.activeElement,d=i?c.indexOf(i):-1;switch(r.key){case"ArrowDown":r.preventDefault(),c[d<0||d===c.length-1?0:d+1].focus();break;case"ArrowUp":r.preventDefault(),c[d<=0?c.length-1:d-1].focus();break;case"Home":r.preventDefault(),c[0].focus();break;case"End":r.preventDefault(),c[c.length-1].focus();break;case"Enter":case" ":d>=0&&(r.preventDefault(),c[d].click());break;case"Escape":case"Tab":r.preventDefault(),t(),n?.focus();break}});const a=o()[0];a&&nextFrame(()=>a.focus())}export function overlayRootFor(e){let n=e;for(;n;){if(n.classList.contains("wmap-overlay-box")||n.tagName==="DIALOG"&&n.matches(":modal"))return n;n=n.parentElement}return e.ownerDocument.body}const te=new WeakMap;export function getTooltip(e=document){const n=te.get(e);if(n&&n.isConnected)return n;const t=n??e.createElement("div");return n||(Object.assign(t.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:"5px",fontSize:"13px",lineHeight:"1.55",maxWidth:"280px",maxHeight:"min(60vh, 480px)",overflow:"hidden",whiteSpace:"pre-wrap",zIndex:Z_ABOVE,display:"none",fontFamily:"system-ui, sans-serif",boxShadow:"0 3px 10px rgba(0,0,0,0.45)"}),te.set(e,t)),e.body.appendChild(t),t}export function hideTooltip(e=document){const n=te.get(e);n&&(n.style.display="none")}export function reparentTooltip(e){const n=e?.ownerDocument??document,t=getTooltip(n);(e??n.body).appendChild(t)}export function positionTooltip(e,n,t,o){const a=overlayRootFor(n);e.parentElement!==a&&a.appendChild(e);const r=e.ownerDocument.defaultView??window;e.style.left="0",e.style.top="0";const c=e.offsetWidth,i=e.offsetHeight,d=8;let b=t+14,m=o-8;b+c+d>r.innerWidth&&(b=t-c-6),m+i+d>r.innerHeight&&(m=r.innerHeight-i-d),m<d&&(m=d),e.style.left=`${b}px`,e.style.top=`${m}px`}export function buildDataModeEntries(e,n,t){const o=e.some(pe),a=e.some(m=>m.testValues!==void 0&&Object.keys(m.testValues).length>0),r=e.some(m=>m.hbin!=null),c=e.some(m=>m.sbin!=null),i=o?n?.length?n.map(m=>({plotMode:"value",activeTest:m.testNumber,label:m.unit?`${m.name} (${m.unit})`:m.name,logScale:m.logScale})):ue(e).map(m=>({plotMode:"value",activeTest:m,label:`Test ${m}`})):[],d=[...r?[{plotMode:"hardBin",label:MODE_LABELS.hardBin}]:[],...c?[{plotMode:"softBin",label:MODE_LABELS.softBin}]:[]],b=t.includeStacked?[...a?[{plotMode:"stackedValues",label:MODE_LABELS.stackedValues}]:[],...r?[{plotMode:"stackedBins",label:MODE_LABELS.stackedBins}]:[],...c?[{plotMode:"stackedSoftBins",label:MODE_LABELS.stackedSoftBins}]:[]]:[];return{testEntries:i,binEntries:d,stackedEntries:b}}export function metadataKeyHasData(e,n){return e.some(t=>t.metadata?.[n]!==void 0&&t.metadata?.[n]!==null)}export function metadataModeEntry(e){return{plotMode:"metadata",activeMetadataKey:e.key,label:e.label??fe(e.key)}}export function makeMenuSearchBox(e,n="Filter\u2026",t=document){const o=t.createElement("input");return o.type="text",o.placeholder=n,o.setAttribute("aria-label",n),Object.assign(o.style,{display:"block",width:"calc(100% - 20px)",margin:"2px 10px 6px",padding:"4px 8px",fontSize:"12px",boxSizing:"border-box",background:CLR.menuBg,color:CLR.text,border:`1px solid ${CLR.menuBorder}`,borderRadius:"4px",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,n,t,o,a,r,c,i,d=window,b=[]){const{makeMenuRow:m,makeMenuSection:h}=c,s=document.createElement("div"),l=180,x=e.left+l<=(d.innerWidth??1/0)?e.left:Math.max(4,e.right-l);if(Object.assign(s.style,{position:"fixed",top:`${e.bottom+4}px`,left:`${x}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",zIndex:Z_BASE,minWidth:`${l}px`,padding:"4px 0",pointerEvents:"auto"}),n.length)if(s.appendChild(h("Test Value")),n.length<=INLINE_TEST_LIMIT)for(const u of n)s.appendChild(m(u.label,a(u),!0,g=>{g.stopPropagation(),r(u,s)}));else{const u=i==="value",g=m(MODE_LABELS.value+" \u25B6",u,!1,()=>{});g.style.display="flex",g.style.justifyContent="space-between",g.style.alignItems="center";let f=null,y=null;const M=()=>{y!==null&&(clearTimeout(y),y=null)},S=()=>{M(),f?.remove(),f=null},L=()=>{M(),y=setTimeout(S,300)},U=()=>{if(f)return;const W=g.getBoundingClientRect(),A=160,k=320,I=W.right+2+A<=(d.innerWidth??1/0)?W.right+2:Math.max(4,W.left-2-A),B=Math.min(W.top-4,Math.max(4,(d.innerHeight??1/0)-k-4));if(f=document.createElement("div"),Object.assign(f.style,{position:"fixed",top:`${B}px`,left:`${I}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",zIndex:Z_ABOVE,minWidth:`${A}px`,maxHeight:`${k}px`,overflowY:"auto",padding:"4px 0",pointerEvents:"auto"}),n.length>MENU_SEARCH_THRESHOLD){const D=makeMenuSearchBox(F=>{for(const O of E)O.row.style.display=O.label.includes(F)?"":"none"},"Filter tests\u2026");Object.assign(D.style,{position:"sticky",top:"0",zIndex:"1",background:CLR.menuBg}),f.appendChild(D)}const E=[];for(const D of n){const F=m(D.label,a(D),!1,O=>{O.stopPropagation(),S(),r(D,s)});E.push({row:F,label:D.label.toLowerCase()}),f.appendChild(F)}f.addEventListener("mouseenter",M),f.addEventListener("mouseleave",L),(s.parentElement??d.document.body).appendChild(f),d.document.addEventListener("click",S,{once:!0})};g.addEventListener("mouseenter",()=>{M(),U()}),g.addEventListener("mouseleave",L),s.appendChild(g)}if(t.length){s.appendChild(h("Bins"));for(const u of t)s.appendChild(m(u.label,a(u),!1,g=>{g.stopPropagation(),r(u,s)}))}if(b.length){s.appendChild(h("Metadata"));for(const u of b)s.appendChild(m(u.label,a(u),!1,g=>{g.stopPropagation(),r(u,s)}))}if(o.length){s.appendChild(h("Lot Aggregation"));for(const u of o)s.appendChild(m(u.label,a(u),!1,g=>{g.stopPropagation(),r(u,s)}))}return s.setAttribute("role","menu"),s.setAttribute("aria-label","Plot mode"),s}export function markMenuTrigger(e,n){e.setAttribute("aria-haspopup","menu"),e.setAttribute("aria-expanded",n?"true":"false")}export function wireMenuA11y(e,n,t){G(e,n,t)}export function wireExpandToggle(e,n){const t=e.ownerDocument;let o=!1;function a(b){o!==b&&(o=b,n(o))}function r(){a(!1)}function c(){a(!o),o&&t.addEventListener("click",r,{once:!0})}const i=b=>{b.stopPropagation(),c()},d=b=>{b.key==="Enter"||b.key===" "?(b.preventDefault(),c()):b.key==="Escape"&&r()};return e.setAttribute("role","button"),e.tabIndex<0&&(e.tabIndex=0),e.addEventListener("click",i),e.addEventListener("keydown",d),{isOpen:()=>o,close:r,destroy(){e.removeEventListener("click",i),e.removeEventListener("keydown",d),t.removeEventListener("click",r)}}}export function buildCheckMenuEl(e,n,t,o=window){const{makeMenuRow:a,makeMenuSection:r}=t,c=o.document,i=c.createElement("div"),d=168,m=e.left+d<=(o.innerWidth??1/0)?e.left:Math.max(4,e.right-d);Object.assign(i.style,{position:"fixed",top:`${e.bottom+4}px`,left:`${m}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",zIndex:Z_BASE,minWidth:`${d}px`,padding:"4px 0",pointerEvents:"auto"});for(const h of n)if("section"in h)i.appendChild(r(h.section));else{if(!(h.enabled!==!1))continue;const l=c.createElement("div");l.setAttribute("role","menuitemcheckbox"),l.setAttribute("aria-checked",h.active?"true":"false"),l.tabIndex=-1,Object.assign(l.style,{display:"flex",alignItems:"center",gap:"6px",padding:"6px 14px",fontSize:"12px",cursor:"pointer",color:h.active?CLR.iconActive:CLR.text,fontWeight:h.active?"700":"400",background:h.active?CLR.menuActive:"transparent",whiteSpace:"nowrap",outline:"none"});const v=c.createElement("span");Object.assign(v.style,{width:"12px",flexShrink:"0",color:CLR.iconActive,visibility:h.active?"visible":"hidden"}),v.textContent="\u2713",v.setAttribute("aria-hidden","true");const x=c.createElement("span");x.textContent=h.label,l.appendChild(v),l.appendChild(x),l.addEventListener("mouseenter",()=>{h.active||(l.style.background=CLR.menuHover)}),l.addEventListener("mouseleave",()=>{l.style.background=h.active?CLR.menuActive:"transparent"}),l.addEventListener("focus",()=>{h.active||(l.style.background=CLR.menuHover)}),l.addEventListener("blur",()=>{l.style.background=h.active?CLR.menuActive:"transparent"}),l.addEventListener("click",u=>{u.stopPropagation(),h.onClick(u)}),i.appendChild(l)}return i}export function createToolbarHelpers(e){const n=e.ownerDocument;let t=null;const o=s=>overlayRootFor(s);function a(s,l,v){const x=n.createElement("button");return x.innerHTML=$[s],x.type="button",x.ariaLabel=l,Object.assign(x.style,{display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",padding:"0",border:"none",borderRadius:"3px",background:"transparent",color:CLR.icon,cursor:"pointer",pointerEvents:"auto",transition:"background 0.12s, color 0.12s",flexShrink:"0"}),x.addEventListener("mouseenter",u=>{x.dataset.active||(x.style.background=CLR.bgHover,x.style.color=CLR.iconHover),e.innerHTML=x.ariaLabel??l,e.style.display="block",positionTooltip(e,x,u.clientX,u.clientY)}),x.addEventListener("mousemove",u=>{e.style.display==="block"&&positionTooltip(e,x,u.clientX,u.clientY)}),x.addEventListener("mouseleave",()=>{x.dataset.active||(x.style.background="transparent",x.style.color=CLR.icon),e.style.display="none"}),x.addEventListener("click",()=>{e.style.display="none",v()}),x}function r(s,l){l?(s.dataset.active="1",s.style.background=CLR.bgActive,s.style.color=CLR.iconActive):(delete s.dataset.active,s.style.background="transparent",s.style.color=CLR.icon)}function c(){const s=n.createElement("div");return Object.assign(s.style,{width:"1px",height:"18px",background:CLR.separator,margin:"0 2px",flexShrink:"0"}),s}function i(s,l,v,x){const u=n.createElement("div");return u.textContent=s,u.setAttribute("role","menuitemradio"),u.setAttribute("aria-checked",l?"true":"false"),u.tabIndex=-1,Object.assign(u.style,{padding:`6px 14px 6px ${v?"26px":"14px"}`,fontSize:"12px",cursor:"pointer",color:l?CLR.iconActive:CLR.text,fontWeight:l?"700":"400",background:l?CLR.menuActive:"transparent",whiteSpace:"nowrap",outline:"none"}),u.addEventListener("mouseenter",()=>{l||(u.style.background=CLR.menuHover)}),u.addEventListener("mouseleave",()=>{u.style.background=l?CLR.menuActive:"transparent"}),u.addEventListener("focus",()=>{l||(u.style.background=CLR.menuHover)}),u.addEventListener("blur",()=>{u.style.background=l?CLR.menuActive:"transparent"}),u.addEventListener("click",x),u}function d(s){const l=n.createElement("div");return l.textContent=s,l.setAttribute("role","presentation"),Object.assign(l.style,{padding:"5px 14px 2px",fontSize:"10px",fontWeight:"600",letterSpacing:"0.05em",color:CLR.label,textTransform:"uppercase",pointerEvents:"none",userSelect:"none"}),l}function b(s,l,v,x,u){const g=()=>{t&&(t.remove(),t=null),f.setAttribute("aria-expanded","false")},f=a(s,l,()=>{if(t){g();return}const y=n.createElement("div"),M=f.getBoundingClientRect(),S=f.ownerDocument.defaultView??window,L=148,W=M.left+L<=(S.innerWidth??1/0)?M.left:Math.max(4,M.right-L);Object.assign(y.style,{position:"fixed",top:`${M.bottom+4}px`,left:`${W}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",zIndex:Z_BASE,minWidth:`${L}px`,padding:"4px 0",pointerEvents:"auto"});for(const A of v()){const k=n.createElement("div");k.textContent=A.label,k.dataset.wmapDropdownValue=A.value;const C=A.value===x();k.setAttribute("role","menuitemradio"),k.setAttribute("aria-checked",C?"true":"false"),k.tabIndex=-1,Object.assign(k.style,{padding:"6px 14px",fontSize:"12px",cursor:"pointer",color:C?CLR.iconActive:CLR.text,fontWeight:C?"700":"400",background:C?CLR.menuActive:"transparent",whiteSpace:"nowrap",outline:"none"});const I=()=>{A.value!==x()&&(k.style.background=CLR.menuHover)},B=()=>{k.style.background=A.value===x()?CLR.menuActive:"transparent"};k.addEventListener("mouseenter",I),k.addEventListener("mouseleave",B),k.addEventListener("focus",I),k.addEventListener("blur",B),k.addEventListener("click",E=>{E.stopPropagation(),u(A.value),g()}),y.appendChild(k)}y.setAttribute("role","menu"),y.setAttribute("aria-label",l),o(f).appendChild(y),t=y,f.setAttribute("aria-expanded","true"),G(y,f,g)});return f.setAttribute("aria-haspopup","menu"),f.setAttribute("aria-expanded","false"),f}function m(s,l,v,x){function u(){return buildCheckMenuEl(f.getBoundingClientRect(),v().map(y=>"section"in y?y:{...y,onClick:M=>{y.onClick(M),x(f);const S=t;if(!S)return;const L=u();L.setAttribute("role","menu"),L.setAttribute("aria-label",l),S.replaceWith(L),t=L,G(L,f,g)}}),{makeMenuRow:i,makeMenuSection:d},f.ownerDocument.defaultView??window)}const g=()=>{t&&(t.remove(),t=null),f.setAttribute("aria-expanded","false")},f=a(s,l,()=>{if(t){g();return}const y=u();y.setAttribute("role","menu"),y.setAttribute("aria-label",l),o(f).appendChild(y),t=y,f.setAttribute("aria-expanded","true"),G(y,f,g)});return f.setAttribute("aria-haspopup","menu"),f.setAttribute("aria-expanded","false"),x(f),f}function h(s){if(t&&!t.contains(s.target)&&(t.remove(),t=null,s.target?.getAttribute?.("aria-haspopup")!=="menu"))for(const v of document.querySelectorAll('[aria-haspopup="menu"][aria-expanded="true"]'))v.setAttribute("aria-expanded","false")}return{makeBtn:a,setActive:r,makeSep:c,makeMenuRow:i,makeMenuSection:d,makeDropdown:b,makeCheckMenuBtn:m,closeOpenMenu:h,getOpenMenu:()=>t,setOpenMenu:s=>{t=s}}}const xe=7e3;let ve=0;function ae(){return xe+ ++ve}const ge=32,ye=6;let we=0;function ke(){return we++%ye*ge}function Ee(e,n){if(n===e.body)return()=>{};let t=n;for(;t.parentElement&&t.parentElement!==e.body;)t=t.parentElement;return t===e.body?()=>{}:(t.classList.add("wmap-overlay-ancestor"),()=>t.classList.remove("wmap-overlay-ancestor"))}function re(e){const n=e.mode==="modal",t=e.ownerDocument??document,o=t.defaultView??window,a=t.body.style.overflow;n&&(t.body.style.overflow="hidden");let r=null;n&&(r=t.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 c=t.activeElement,i=t.createElement("div");if(i.className=n?"wmap-modal-box wmap-overlay-box":"wmap-window-box wmap-overlay-box",i.setAttribute("role","dialog"),n&&i.setAttribute("aria-modal","true"),i.setAttribute("aria-label",e.title??"Expanded wafer map"),i.tabIndex=-1,Object.assign(i.style,{position:"relative",background:CLR.menuBg,borderRadius:"12px",overflow:"hidden",display:"flex",flexDirection:"column",width:"min(90vw, 700px)",height:"min(90vh, 700px)",boxShadow:"0 20px 60px rgba(0,0,0,0.4)",minWidth:"320px",minHeight:"240px",maxWidth:"100vw",maxHeight:"100vh",zIndex:n?Z_ABOVE2:String(ae())}),!n){const p=ke();Object.assign(i.style,{position:"fixed",top:`${Math.round(o.innerHeight*.08)+p}px`,left:`${Math.round(o.innerWidth*.08)+p}px`})}const d=t.createElement("div");Object.assign(d.style,{display:"flex",alignItems:"center",gap:"6px",padding:"10px 14px",borderBottom:`1px solid ${CLR.menuBorder}`,flexShrink:"0"});const b={border:`1px solid ${CLR.menuBorder}`,borderRadius:"4px",background:CLR.panelBg,cursor:"pointer",color:CLR.label,lineHeight:"1",padding:"0",display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px"};if(e.title){const p=t.createElement("span");p.textContent=e.title,p.title=e.title,p.dataset.wmapWindowTitle="1",Object.assign(p.style,{fontWeight:"700",fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"}),d.appendChild(p)}const m=t.createElement("div");m.style.flex="1",d.appendChild(m);let h=null;n||(h=t.createElement("button"),h.type="button",h.innerHTML=$.windowMinimize,h.title="Minimize",h.setAttribute("aria-label","Minimize"),Object.assign(h.style,b),h.addEventListener("click",()=>L(!f)),d.appendChild(h));const s=t.createElement("button");s.type="button",s.innerHTML=$.maximize,s.title="Maximize (F)",s.setAttribute("aria-label","Maximize"),Object.assign(s.style,b),s.addEventListener("click",()=>g(!v));const l=t.createElement("button");l.type="button",l.innerHTML=$.close,l.title="Close (Esc)",l.setAttribute("aria-label","Close"),Object.assign(l.style,b),l.addEventListener("click",C),d.appendChild(s),d.appendChild(l);let v=!1,x="",u="";function g(p){v=p,s.innerHTML=v?$.minimize:$.maximize,s.title=v?"Restore (F)":"Maximize (F)",s.setAttribute("aria-label",v?"Restore":"Maximize"),E.style.display=v?"none":"block",v?(i.style.borderRadius="0",i.style.width="100vw",i.style.height="100vh",n||(x=i.style.top,u=i.style.left,i.style.top="0",i.style.left="0")):(i.style.borderRadius="12px",i.style.width="min(90vw, 700px)",i.style.height="min(90vh, 700px)",n||(i.style.top=x,i.style.left=u)),e.onMaximizeChange?.(v,i)}let f=!1,y="",M="";const S=220;function L(p){f=p,h.innerHTML=f?$.windowRestore:$.windowMinimize,h.title=f?"Restore":"Minimize",h.setAttribute("aria-label",f?"Restore":"Minimize"),E.style.display=f?"none":"block",f?(y=i.style.height,M=i.style.width,i.style.minHeight="0",i.style.height="auto",i.style.minWidth="0",i.style.width=`${S}px`,s.disabled=!0,s.style.opacity="0.4",s.style.cursor="default",B.style.display="none"):(i.style.minHeight="240px",i.style.height=y||"min(90vh, 700px)",i.style.minWidth="320px",i.style.width=M||"min(90vw, 700px)",s.disabled=!1,s.style.opacity="1",s.style.cursor="pointer",B.style.display="flex")}function U(){const p=t.body.style.userSelect;return t.body.style.userSelect="none",()=>{t.body.style.userSelect=p}}n||(d.style.cursor="move",d.addEventListener("pointerdown",p=>{if(v||p.target.closest('button, [role="button"]'))return;p.preventDefault();const T=U(),z=p.clientX,R=p.clientY,H=i.offsetTop,_=i.offsetLeft,Z=o.innerHeight-d.offsetHeight,Q=o.innerWidth-40,X=40-i.offsetWidth;d.setPointerCapture(p.pointerId);const N=V=>{const J=Math.min(Math.max(H+(V.clientY-R),0),Z),de=Math.min(Math.max(_+(V.clientX-z),X),Q);i.style.top=`${J}px`,i.style.left=`${de}px`},P=V=>{T(),d.releasePointerCapture(V.pointerId),d.removeEventListener("pointermove",N),d.removeEventListener("pointerup",P)};d.addEventListener("pointermove",N),d.addEventListener("pointerup",P)}));const W='button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"]),[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';function A(p){const T=Array.from(i.querySelectorAll(W)).filter(_=>_.offsetParent!==null||_===t.activeElement);if(T.length===0){p.preventDefault(),i.focus();return}const z=T[0],R=T[T.length-1],H=t.activeElement;p.shiftKey&&(H===z||!i.contains(H))?(p.preventDefault(),R.focus()):!p.shiftKey&&H===R&&(p.preventDefault(),z.focus())}const k=p=>{if(p.key==="Escape"){C();return}if(n&&(p.key==="e"||p.key==="E")){C();return}if(n&&p.key==="Tab"){A(p);return}(p.key==="f"||p.key==="F")&&!f&&g(!v)};function C(){n?t.removeEventListener("keydown",k):i.removeEventListener("keydown",k),q.remove(),ce(),hideTooltip(t),reparentTooltip(t.body),r?r.remove():i.remove(),n&&(t.body.style.overflow=a),c?.focus?.(),e.onClose()}function I(){n||(i.style.zIndex=String(ae()))}const B=t.createElement("div");Object.assign(B.style,{flex:"1",minHeight:"0",minWidth:"0",display:"flex",overflow:"hidden"});const E=t.createElement("div");E.tabIndex=0,E.setAttribute("role","separator"),E.setAttribute("aria-label","Resize window (arrow keys, or drag)"),Object.assign(E.style,{position:"absolute",right:"0",bottom:"0",width:"16px",height:"16px",cursor:"nwse-resize",touchAction:"none"}),E.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>',E.style.color=CLR.label;const D=320,F=240,O=20;function Y(p,T){const z=o.innerWidth-i.offsetLeft,R=o.innerHeight-i.offsetTop,H=Math.min(Math.max(i.offsetWidth+p,D),z),_=Math.min(Math.max(i.offsetHeight+T,F),R);i.style.width=`${H}px`,i.style.height=`${_}px`}E.addEventListener("keydown",p=>{if(!(v||f))switch(p.key){case"ArrowRight":p.preventDefault(),Y(O,0);break;case"ArrowLeft":p.preventDefault(),Y(-O,0);break;case"ArrowDown":p.preventDefault(),Y(0,O);break;case"ArrowUp":p.preventDefault(),Y(0,-O);break}}),E.addEventListener("pointerdown",p=>{if(v||f)return;p.preventDefault();const T=U(),z=p.clientX,R=p.clientY,H=i.offsetWidth,_=i.offsetHeight,Z=o.innerWidth-i.offsetLeft,Q=o.innerHeight-i.offsetTop;E.setPointerCapture(p.pointerId);const X=P=>{const V=Math.min(Math.max(H+(P.clientX-z),D),Z),J=Math.min(Math.max(_+(P.clientY-R),F),Q);i.style.width=`${V}px`,i.style.height=`${J}px`},N=P=>{T(),E.releasePointerCapture(P.pointerId),E.removeEventListener("pointermove",X),E.removeEventListener("pointerup",N)};E.addEventListener("pointermove",X),E.addEventListener("pointerup",N)}),i.appendChild(d),i.appendChild(B),i.appendChild(E);const K=e.anchor?overlayRootFor(e.anchor):t.body;r?(r.appendChild(i),K.appendChild(r)):K.appendChild(i);const ce=Ee(t,K),q=t.createElement("style");return q.textContent=`@media print{
1
+ import{getUniqueTestNumbers as be}from"../renderer/buildView.js";import{dieHasTestData as xe}from"../renderer/buildWaferMap.js";import{prettyKey as he}from"../core/utils.js";import{listColorSchemes as ie}from"../renderer/colorSchemes.js";import{ICONS as I}from"./icons.js";import{WMAP_VERSION as ge,WMAP_BUILD_TIME as ve}from"./version.js";import{openHtmlReport as ye}from"../stats/renderFindingsReport.js";import{buildWaferMap as we}from"../renderer/buildWaferMap.js";import{analyzeWaferMap as ke}from"../stats/analyzeWaferMap.js";let re=!1;export function logWmapVersionOnce(){re||(re=!0,console.log(`[wmap] v${ge} (built ${ve})`))}export const WMAP_TOKEN_NAMES=["z","icon","icon-hover","icon-active","bg-hover","bg-active","separator","surface","border","menu-hover","menu-active","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","bar-fill-muted"];const w=(e,n)=>`var(--wmap-${e}, ${n})`;export const CLR={icon:w("icon","#506784"),iconHover:w("icon-hover","#2a3f5f"),iconActive:w("icon-active","#1a65ca"),bgHover:w("bg-hover","#edf0f8"),bgActive:w("bg-active","#dce8f8"),separator:w("separator","rgba(0,0,0,0.12)"),menuBg:w("surface","#fff"),menuBorder:w("border","rgba(0,0,0,0.12)"),menuHover:w("menu-hover","#f0f4fc"),menuActive:w("menu-active","#dce8f8"),panelBg:w("panel-bg","#fafbfc"),label:w("text-muted","#647687"),value:w("text-strong","#1f2f43"),text:w("text","#333"),warnBg:w("warn-bg","#fffbe6"),warnBorder:w("warn-border","#f0c040"),warnText:w("warn-text","#7a5800"),errBg:w("err-bg","#fef2f2"),errBorder:w("err-border","#dc8a8a"),errText:w("err-text","#7a1c1c"),infoBg:w("info-bg","#dce8f8"),infoText:w("info-text","#334155"),findingHighlight:w("selected","#e07a20"),findingIndicator:w("finding-indicator","#b7551a"),barFill:w("bar-fill","#2a6fc0"),barFillMuted:w("bar-fill-muted","#94a3b8")};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 n=document.documentElement,t=n.style.getPropertyValue("--wmap-z");return n.style.setProperty("--wmap-z",String(e)),()=>{t?n.style.setProperty("--wmap-z",t):n.style.removeProperty("--wmap-z")}}export function copyWmapThemeTokens(e,n){const t=getComputedStyle(e);for(const o of WMAP_TOKEN_NAMES){const r=t.getPropertyValue(`--wmap-${o}`).trim();r&&n.style.setProperty(`--wmap-${o}`,r)}}export function syncWmapPopupTheme(e,n,t){const o=()=>{copyWmapThemeTokens(e,n),t?.()},r=new window.MutationObserver(o);r.observe(e,{attributes:!0,attributeFilter:["style","class"]}),r.observe(document.documentElement,{attributes:!0,attributeFilter:["style","class"]});const a=window.matchMedia("(prefers-color-scheme: dark)");return a.addEventListener("change",o),()=>{r.disconnect(),a.removeEventListener("change",o)}}let te=null;export function setDetachWindowOpener(e){te=e}export function openDetachWindow(e){return te?te(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,n,t){const o=`${n}.png`;if(t){t(e,o);return}const r=URL.createObjectURL(e),a=document.createElement("a");a.href=r,a.download=o,a.click(),URL.revokeObjectURL(r)}export function saveTextFile(e,n,t,o){if(o){o(e,n,t);return}const r=new Blob([e],{type:t}),a=URL.createObjectURL(r),p=document.createElement("a");p.href=a,p.download=n,p.click(),URL.revokeObjectURL(a)}const Ee='[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';export function nextFrame(e,n=window){const t=n.requestAnimationFrame;typeof t=="function"?t.call(n,e):setTimeout(e,0)}function Ge(e,n,t){e.setAttribute("role","menu"),e.setAttribute("aria-label",n);for(const o of Array.from(e.children)){const r=t(o);r&&(o.setAttribute("role",r),o.tabIndex=-1)}}function q(e,n,t){const o=()=>Array.from(e.querySelectorAll(Ee));e.addEventListener("keydown",a=>{const p=o();if(p.length===0)return;const i=e.ownerDocument.activeElement,l=i?p.indexOf(i):-1;switch(a.key){case"ArrowDown":a.preventDefault(),p[l<0||l===p.length-1?0:l+1].focus();break;case"ArrowUp":a.preventDefault(),p[l<=0?p.length-1:l-1].focus();break;case"Home":a.preventDefault(),p[0].focus();break;case"End":a.preventDefault(),p[p.length-1].focus();break;case"Enter":case" ":l>=0&&(a.preventDefault(),p[l].click());break;case"Escape":case"Tab":a.preventDefault(),t(),n?.focus();break}});const r=o()[0];r&&nextFrame(()=>r.focus())}export function overlayRootFor(e){let n=e;for(;n;){if(n.classList.contains("wmap-overlay-box")||n.tagName==="DIALOG"&&n.matches(":modal"))return n;n=n.parentElement}return e.ownerDocument.body}const ae=new WeakMap;export function menuLayerFor(e){const n=overlayRootFor(e),t=ae.get(n);if(t&&t.isConnected)return t;const r=e.ownerDocument.createElement("div");return r.dataset.wmapMenuLayer="1",Object.assign(r.style,{position:"fixed",inset:"0",zIndex:Z_MENU,pointerEvents:"none"}),n.appendChild(r),ae.set(n,r),r}const ne=new WeakMap;export function getTooltip(e=document){const n=ne.get(e);if(n&&n.isConnected)return n;const t=n??e.createElement("div");return n||(Object.assign(t.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:"5px",fontSize:"13px",lineHeight:"1.55",maxWidth:"280px",maxHeight:"min(60vh, 480px)",overflow:"hidden",whiteSpace:"pre-wrap",zIndex:Z_ABOVE,display:"none",fontFamily:"system-ui, sans-serif",boxShadow:"0 3px 10px rgba(0,0,0,0.45)"}),ne.set(e,t)),e.body.appendChild(t),t}export function hideTooltip(e=document){const n=ne.get(e);n&&(n.style.display="none")}export function reparentTooltip(e){const n=e?.ownerDocument??document,t=getTooltip(n);(e??n.body).appendChild(t)}export function positionTooltip(e,n,t,o){const r=overlayRootFor(n);e.parentElement!==r&&r.appendChild(e);const a=e.ownerDocument.defaultView??window;e.style.left="0",e.style.top="0";const p=e.offsetWidth,i=e.offsetHeight,l=8;let h=t+14,f=o-8;h+p+l>a.innerWidth&&(h=t-p-6),f+i+l>a.innerHeight&&(f=a.innerHeight-i-l),f<l&&(f=l),e.style.left=`${h}px`,e.style.top=`${f}px`}export function buildDataModeEntries(e,n,t){const o=e.some(xe),r=e.some(f=>f.testValues!==void 0&&Object.keys(f.testValues).length>0),a=e.some(f=>f.hbin!=null),p=e.some(f=>f.sbin!=null),i=o?n?.length?n.map(f=>({plotMode:"value",activeTest:f.testNumber,label:f.unit?`${f.name} (${f.unit})`:f.name,logScale:f.logScale})):be(e).map(f=>({plotMode:"value",activeTest:f,label:`Test ${f}`})):[],l=[...a?[{plotMode:"hardBin",label:MODE_LABELS.hardBin}]:[],...p?[{plotMode:"softBin",label:MODE_LABELS.softBin}]:[]],h=t.includeStacked?[...r?[{plotMode:"stackedValues",label:MODE_LABELS.stackedValues}]:[],...a?[{plotMode:"stackedBins",label:MODE_LABELS.stackedBins}]:[],...p?[{plotMode:"stackedSoftBins",label:MODE_LABELS.stackedSoftBins}]:[]]:[];return{testEntries:i,binEntries:l,stackedEntries:h}}export function metadataKeyHasData(e,n){return e.some(t=>t.metadata?.[n]!==void 0&&t.metadata?.[n]!==null)}export function metadataModeEntry(e){return{plotMode:"metadata",activeMetadataKey:e.key,label:e.label??he(e.key)}}export function makeMenuSearchBox(e,n="Filter\u2026",t=document){const o=t.createElement("input");return o.type="text",o.placeholder=n,o.setAttribute("aria-label",n),Object.assign(o.style,{display:"block",width:"calc(100% - 20px)",margin:"2px 10px 6px",padding:"4px 8px",fontSize:"12px",boxSizing:"border-box",background:CLR.menuBg,color:CLR.text,border:`1px solid ${CLR.menuBorder}`,borderRadius:"4px",outline:"none"}),o.addEventListener("click",r=>r.stopPropagation()),o.addEventListener("mousedown",r=>r.stopPropagation()),o.addEventListener("keydown",r=>r.stopPropagation()),o.addEventListener("input",()=>e(o.value.trim().toLowerCase())),o.addEventListener("focus",()=>{o.style.borderColor=CLR.iconActive}),o.addEventListener("blur",()=>{o.style.borderColor=CLR.menuBorder}),queueMicrotask(()=>o.focus()),o}export function buildModeMenuEl(e,n,t,o,r,a,p,i,l=window,h=[]){const{makeMenuRow:f,makeMenuSection:b}=p,s=document.createElement("div"),d=180,u=e.left+d<=(l.innerWidth??1/0)?e.left:Math.max(4,e.right-d);if(Object.assign(s.style,{position:"fixed",top:`${e.bottom+4}px`,left:`${u}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",zIndex:Z_BASE,minWidth:`${d}px`,padding:"4px 0",pointerEvents:"auto"}),n.length)if(s.appendChild(b("Test Value")),n.length<=INLINE_TEST_LIMIT)for(const c of n)s.appendChild(f(c.label,r(c),!0,y=>{y.stopPropagation(),a(c,s)}));else{const c=i==="value",y=f(MODE_LABELS.value+" \u25B6",c,!1,()=>{});y.style.display="flex",y.style.justifyContent="space-between",y.style.alignItems="center";let g=null,v=null;const L=()=>{v!==null&&(clearTimeout(v),v=null)},C=()=>{L(),g?.remove(),g=null},A=()=>{L(),v=setTimeout(C,300)},O=()=>{if(g)return;const S=y.getBoundingClientRect(),M=160,E=320,T=S.right+2+M<=(l.innerWidth??1/0)?S.right+2:Math.max(4,S.left-2-M),z=Math.min(S.top-4,Math.max(4,(l.innerHeight??1/0)-E-4));if(g=document.createElement("div"),Object.assign(g.style,{position:"fixed",top:`${z}px`,left:`${T}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",zIndex:Z_ABOVE,minWidth:`${M}px`,maxHeight:`${E}px`,overflowY:"auto",padding:"4px 0",pointerEvents:"auto"}),n.length>MENU_SEARCH_THRESHOLD){const k=makeMenuSearchBox(j=>{for(const F of D)F.row.style.display=F.label.includes(j)?"":"none"},"Filter tests\u2026");Object.assign(k.style,{position:"sticky",top:"0",zIndex:"1",background:CLR.menuBg}),g.appendChild(k)}const D=[];for(const k of n){const j=f(k.label,r(k),!1,F=>{F.stopPropagation(),C(),a(k,s)});D.push({row:j,label:k.label.toLowerCase()}),g.appendChild(j)}g.addEventListener("mouseenter",L),g.addEventListener("mouseleave",A),(s.parentElement??l.document.body).appendChild(g),l.document.addEventListener("click",C,{once:!0})};y.addEventListener("mouseenter",()=>{L(),O()}),y.addEventListener("mouseleave",A),s.appendChild(y)}if(t.length){s.appendChild(b("Bins"));for(const c of t)s.appendChild(f(c.label,r(c),!1,y=>{y.stopPropagation(),a(c,s)}))}if(h.length){s.appendChild(b("Metadata"));for(const c of h)s.appendChild(f(c.label,r(c),!1,y=>{y.stopPropagation(),a(c,s)}))}if(o.length){s.appendChild(b("Lot Aggregation"));for(const c of o)s.appendChild(f(c.label,r(c),!1,y=>{y.stopPropagation(),a(c,s)}))}return s.setAttribute("role","menu"),s.setAttribute("aria-label","Plot mode"),s}export function markMenuTrigger(e,n){e.setAttribute("aria-haspopup","menu"),e.setAttribute("aria-expanded",n?"true":"false")}export function wireMenuA11y(e,n,t){q(e,n,t)}export function wireExpandToggle(e,n){const t=e.ownerDocument;let o=!1;function r(h){o!==h&&(o=h,n(o))}function a(){r(!1)}function p(){r(!o),o&&t.addEventListener("click",a,{once:!0})}const i=h=>{h.stopPropagation(),p()},l=h=>{h.key==="Enter"||h.key===" "?(h.preventDefault(),p()):h.key==="Escape"&&a()};return e.setAttribute("role","button"),e.tabIndex<0&&(e.tabIndex=0),e.addEventListener("click",i),e.addEventListener("keydown",l),{isOpen:()=>o,close:a,destroy(){e.removeEventListener("click",i),e.removeEventListener("keydown",l),t.removeEventListener("click",a)}}}export function buildCheckMenuEl(e,n,t,o=window){const{makeMenuRow:r,makeMenuSection:a}=t,p=o.document,i=p.createElement("div"),l=168,f=e.left+l<=(o.innerWidth??1/0)?e.left:Math.max(4,e.right-l);Object.assign(i.style,{position:"fixed",top:`${e.bottom+4}px`,left:`${f}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",zIndex:Z_BASE,minWidth:`${l}px`,padding:"4px 0",pointerEvents:"auto"});for(const b of n)if("section"in b)i.appendChild(a(b.section));else{const s=b.enabled!==!1;if(!s&&!b.disabledHint)continue;const d=p.createElement("div");d.setAttribute("role","menuitemcheckbox"),d.setAttribute("aria-checked",b.active?"true":"false"),d.tabIndex=-1,s||(d.setAttribute("aria-disabled","true"),d.title=b.disabledHint),Object.assign(d.style,{display:"flex",alignItems:"center",gap:"6px",padding:"6px 14px",fontSize:"12px",cursor:s?"pointer":"default",color:s?b.active?CLR.iconActive:CLR.text:CLR.label,fontWeight:b.active?"700":"400",background:b.active?CLR.menuActive:"transparent",whiteSpace:"nowrap",outline:"none"});const m=p.createElement("span");Object.assign(m.style,{width:"12px",flexShrink:"0",color:CLR.iconActive,visibility:b.active?"visible":"hidden"}),m.textContent="\u2713",m.setAttribute("aria-hidden","true");const u=p.createElement("span");u.textContent=b.label,d.appendChild(m),d.appendChild(u),s?(d.addEventListener("mouseenter",()=>{b.active||(d.style.background=CLR.menuHover)}),d.addEventListener("mouseleave",()=>{d.style.background=b.active?CLR.menuActive:"transparent"}),d.addEventListener("focus",()=>{b.active||(d.style.background=CLR.menuHover)}),d.addEventListener("blur",()=>{d.style.background=b.active?CLR.menuActive:"transparent"}),d.addEventListener("click",c=>{c.stopPropagation(),b.onClick(c)})):d.addEventListener("click",c=>{c.stopPropagation()}),i.appendChild(d)}return i}export function createToolbarHelpers(e){const n=e.ownerDocument;let t=null;const o=s=>menuLayerFor(s);function r(s,d,m){const u=n.createElement("button");return u.innerHTML=I[s],u.type="button",u.ariaLabel=d,Object.assign(u.style,{display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px",padding:"0",border:"none",borderRadius:"3px",background:"transparent",color:CLR.icon,cursor:"pointer",pointerEvents:"auto",transition:"background 0.12s, color 0.12s",flexShrink:"0"}),u.addEventListener("mouseenter",c=>{u.dataset.active||(u.style.background=CLR.bgHover,u.style.color=CLR.iconHover),e.innerHTML=u.ariaLabel??d,e.style.display="block",positionTooltip(e,u,c.clientX,c.clientY)}),u.addEventListener("mousemove",c=>{e.style.display==="block"&&positionTooltip(e,u,c.clientX,c.clientY)}),u.addEventListener("mouseleave",()=>{u.dataset.active||(u.style.background="transparent",u.style.color=CLR.icon),e.style.display="none"}),u.addEventListener("click",()=>{e.style.display="none",m()}),u}function a(s,d){d?(s.dataset.active="1",s.style.background=CLR.bgActive,s.style.color=CLR.iconActive):(delete s.dataset.active,s.style.background="transparent",s.style.color=CLR.icon)}function p(){const s=n.createElement("div");return Object.assign(s.style,{width:"1px",height:"18px",background:CLR.separator,margin:"0 2px",flexShrink:"0"}),s}function i(s,d,m,u){const c=n.createElement("div");return c.textContent=s,c.setAttribute("role","menuitemradio"),c.setAttribute("aria-checked",d?"true":"false"),c.tabIndex=-1,Object.assign(c.style,{padding:`6px 14px 6px ${m?"26px":"14px"}`,fontSize:"12px",cursor:"pointer",color:d?CLR.iconActive:CLR.text,fontWeight:d?"700":"400",background:d?CLR.menuActive:"transparent",whiteSpace:"nowrap",outline:"none"}),c.addEventListener("mouseenter",()=>{d||(c.style.background=CLR.menuHover)}),c.addEventListener("mouseleave",()=>{c.style.background=d?CLR.menuActive:"transparent"}),c.addEventListener("focus",()=>{d||(c.style.background=CLR.menuHover)}),c.addEventListener("blur",()=>{c.style.background=d?CLR.menuActive:"transparent"}),c.addEventListener("click",u),c}function l(s){const d=n.createElement("div");return d.textContent=s,d.setAttribute("role","presentation"),Object.assign(d.style,{padding:"5px 14px 2px",fontSize:"10px",fontWeight:"600",letterSpacing:"0.05em",color:CLR.label,textTransform:"uppercase",pointerEvents:"none",userSelect:"none"}),d}function h(s,d,m,u,c){const y=()=>{t&&(t.remove(),t=null),g.setAttribute("aria-expanded","false")},g=r(s,d,()=>{if(t){y();return}const v=n.createElement("div"),L=g.getBoundingClientRect(),C=g.ownerDocument.defaultView??window,A=148,S=L.left+A<=(C.innerWidth??1/0)?L.left:Math.max(4,L.right-A);Object.assign(v.style,{position:"fixed",top:`${L.bottom+4}px`,left:`${S}px`,background:CLR.menuBg,border:`1px solid ${CLR.menuBorder}`,borderRadius:"4px",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",zIndex:Z_BASE,minWidth:`${A}px`,padding:"4px 0",pointerEvents:"auto"});for(const M of m()){const E=n.createElement("div");E.textContent=M.label,E.dataset.wmapDropdownValue=M.value;const B=M.value===u();E.setAttribute("role","menuitemradio"),E.setAttribute("aria-checked",B?"true":"false"),E.tabIndex=-1,Object.assign(E.style,{padding:"6px 14px",fontSize:"12px",cursor:"pointer",color:B?CLR.iconActive:CLR.text,fontWeight:B?"700":"400",background:B?CLR.menuActive:"transparent",whiteSpace:"nowrap",outline:"none"});const T=()=>{M.value!==u()&&(E.style.background=CLR.menuHover)},z=()=>{E.style.background=M.value===u()?CLR.menuActive:"transparent"};E.addEventListener("mouseenter",T),E.addEventListener("mouseleave",z),E.addEventListener("focus",T),E.addEventListener("blur",z),E.addEventListener("click",D=>{D.stopPropagation(),c(M.value),y()}),v.appendChild(E)}v.setAttribute("role","menu"),v.setAttribute("aria-label",d),o(g).appendChild(v),t=v,g.setAttribute("aria-expanded","true"),q(v,g,y)});return g.setAttribute("aria-haspopup","menu"),g.setAttribute("aria-expanded","false"),g}function f(s,d,m,u){function c(){return buildCheckMenuEl(g.getBoundingClientRect(),m().map(v=>"section"in v?v:{...v,onClick:L=>{v.onClick(L),u(g);const C=t;if(!C)return;const A=c();A.setAttribute("role","menu"),A.setAttribute("aria-label",d),C.replaceWith(A),t=A,q(A,g,y)}}),{makeMenuRow:i,makeMenuSection:l},g.ownerDocument.defaultView??window)}const y=()=>{t&&(t.remove(),t=null),g.setAttribute("aria-expanded","false")},g=r(s,d,()=>{if(t){y();return}const v=c();v.setAttribute("role","menu"),v.setAttribute("aria-label",d),o(g).appendChild(v),t=v,g.setAttribute("aria-expanded","true"),q(v,g,y)});return g.setAttribute("aria-haspopup","menu"),g.setAttribute("aria-expanded","false"),u(g),g}function b(s){if(t&&!t.contains(s.target)&&(t.remove(),t=null,s.target?.getAttribute?.("aria-haspopup")!=="menu"))for(const m of document.querySelectorAll('[aria-haspopup="menu"][aria-expanded="true"]'))m.setAttribute("aria-expanded","false")}return{makeBtn:r,setActive:a,makeSep:p,makeMenuRow:i,makeMenuSection:l,makeDropdown:h,makeCheckMenuBtn:f,closeOpenMenu:b,getOpenMenu:()=>t,setOpenMenu:s=>{t=s}}}const Le=7e3;let Ce=0;function se(){return Le+ ++Ce}const Me=32,Ae=6;let Se=0;function Be(){return Se++%Ae*Me}function Te(e,n){if(n===e.body)return()=>{};let t=n;for(;t.parentElement&&t.parentElement!==e.body;)t=t.parentElement;return t===e.body?()=>{}:(t.classList.add("wmap-overlay-ancestor"),()=>t.classList.remove("wmap-overlay-ancestor"))}function le(e){const n=e.mode==="modal",t=e.ownerDocument??document,o=t.defaultView??window,r=t.body.style.overflow;n&&(t.body.style.overflow="hidden");let a=null;n&&(a=t.createElement("div"),a.id="wmap-modal-backdrop",Object.assign(a.style,{position:"fixed",inset:"0",background:"rgba(0,0,0,0.6)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:Z_ABOVE,backdropFilter:"blur(3px)"}));const p=t.activeElement,i=t.createElement("div");if(i.className=n?"wmap-modal-box wmap-overlay-box":"wmap-window-box wmap-overlay-box",i.setAttribute("role","dialog"),n&&i.setAttribute("aria-modal","true"),i.setAttribute("aria-label",e.title??"Expanded wafer map"),i.tabIndex=-1,Object.assign(i.style,{position:"relative",background:CLR.menuBg,borderRadius:"12px",overflow:"hidden",display:"flex",flexDirection:"column",width:"min(90vw, 700px)",height:"min(90vh, 700px)",boxShadow:"0 20px 60px rgba(0,0,0,0.4)",minWidth:"320px",minHeight:"240px",maxWidth:"100vw",maxHeight:"100vh",zIndex:n?Z_ABOVE2:String(se())}),!n){const x=Be();Object.assign(i.style,{position:"fixed",top:`${Math.round(o.innerHeight*.08)+x}px`,left:`${Math.round(o.innerWidth*.08)+x}px`})}const l=t.createElement("div");Object.assign(l.style,{display:"flex",alignItems:"center",gap:"6px",padding:"10px 14px",borderBottom:`1px solid ${CLR.menuBorder}`,flexShrink:"0"});const h={border:`1px solid ${CLR.menuBorder}`,borderRadius:"4px",background:CLR.panelBg,cursor:"pointer",color:CLR.label,lineHeight:"1",padding:"0",display:"flex",alignItems:"center",justifyContent:"center",width:"28px",height:"28px"};if(e.title){const x=t.createElement("span");x.textContent=e.title,x.title=e.title,x.dataset.wmapWindowTitle="1",Object.assign(x.style,{fontWeight:"700",fontSize:"14px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",minWidth:"0"}),l.appendChild(x)}const f=t.createElement("div");f.style.flex="1",l.appendChild(f);let b=null;n||(b=t.createElement("button"),b.type="button",b.innerHTML=I.windowMinimize,b.title="Minimize",b.setAttribute("aria-label","Minimize"),Object.assign(b.style,h),b.addEventListener("click",()=>O(!v)),l.appendChild(b));let s=null;e.printable&&(s=t.createElement("button"),s.type="button",s.innerHTML=I.print,s.title="Print / Save as PDF",s.setAttribute("aria-label","Print / Save as PDF"),Object.assign(s.style,h),s.addEventListener("click",()=>{typeof e.printable=="function"?e.printable():o.print()}),l.appendChild(s));const d=t.createElement("button");d.type="button",d.innerHTML=I.maximize,d.title="Maximize (F)",d.setAttribute("aria-label","Maximize"),Object.assign(d.style,h),d.addEventListener("click",()=>g(!u));const m=t.createElement("button");m.type="button",m.innerHTML=I.close,m.title="Close (Esc)",m.setAttribute("aria-label","Close"),Object.assign(m.style,h),m.addEventListener("click",T),l.appendChild(d),l.appendChild(m);let u=!1,c="",y="";function g(x){u=x,d.innerHTML=u?I.minimize:I.maximize,d.title=u?"Restore (F)":"Maximize (F)",d.setAttribute("aria-label",u?"Restore":"Maximize"),k.style.display=u?"none":"block",u?(i.style.borderRadius="0",i.style.width="100vw",i.style.height="100vh",n||(c=i.style.top,y=i.style.left,i.style.top="0",i.style.left="0")):(i.style.borderRadius="12px",i.style.width="min(90vw, 700px)",i.style.height="min(90vh, 700px)",n||(i.style.top=c,i.style.left=y)),e.onMaximizeChange?.(u,i)}let v=!1,L="",C="";const A=220;function O(x){v=x,b.innerHTML=v?I.windowRestore:I.windowMinimize,b.title=v?"Restore":"Minimize",b.setAttribute("aria-label",v?"Restore":"Minimize"),k.style.display=v?"none":"block",v?(L=i.style.height,C=i.style.width,i.style.minHeight="0",i.style.height="auto",i.style.minWidth="0",i.style.width=`${A}px`,d.disabled=!0,d.style.opacity="0.4",d.style.cursor="default",D.style.display="none"):(i.style.minHeight="240px",i.style.height=L||"min(90vh, 700px)",i.style.minWidth="320px",i.style.width=C||"min(90vw, 700px)",d.disabled=!1,d.style.opacity="1",d.style.cursor="pointer",D.style.display="flex")}function S(){const x=t.body.style.userSelect;return t.body.style.userSelect="none",()=>{t.body.style.userSelect=x}}n||(l.style.cursor="move",l.addEventListener("pointerdown",x=>{if(u||x.target.closest('button, [role="button"]'))return;x.preventDefault();const H=S(),R=x.clientX,$=x.clientY,W=i.offsetTop,_=i.offsetLeft,J=o.innerHeight-l.offsetHeight,Q=o.innerWidth-40,Y=40-i.offsetWidth;l.setPointerCapture(x.pointerId);const V=U=>{const ee=Math.min(Math.max(W+(U.clientY-$),0),J),me=Math.min(Math.max(_+(U.clientX-R),Y),Q);i.style.top=`${ee}px`,i.style.left=`${me}px`},N=U=>{H(),l.releasePointerCapture(U.pointerId),l.removeEventListener("pointermove",V),l.removeEventListener("pointerup",N)};l.addEventListener("pointermove",V),l.addEventListener("pointerup",N)}));const M='button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"]),[role="menuitem"],[role="menuitemradio"],[role="menuitemcheckbox"]';function E(x){const H=Array.from(i.querySelectorAll(M)).filter(_=>_.offsetParent!==null||_===t.activeElement);if(H.length===0){x.preventDefault(),i.focus();return}const R=H[0],$=H[H.length-1],W=t.activeElement;x.shiftKey&&(W===R||!i.contains(W))?(x.preventDefault(),$.focus()):!x.shiftKey&&W===$&&(x.preventDefault(),R.focus())}const B=x=>{if(x.key==="Escape"){T();return}if(n&&(x.key==="e"||x.key==="E")){T();return}if(n&&x.key==="Tab"){E(x);return}(x.key==="f"||x.key==="F")&&!v&&g(!u)};function T(){n?t.removeEventListener("keydown",B):i.removeEventListener("keydown",B),Z.remove(),fe(),hideTooltip(t),reparentTooltip(t.body),a?a.remove():i.remove(),n&&(t.body.style.overflow=r),p?.focus?.(),e.onClose()}function z(){n||(i.style.zIndex=String(se()))}const D=t.createElement("div");Object.assign(D.style,{flex:"1",minHeight:"0",minWidth:"0",display:"flex",overflow:"hidden"});const k=t.createElement("div");k.tabIndex=0,k.setAttribute("role","separator"),k.setAttribute("aria-label","Resize window (arrow keys, or drag)"),Object.assign(k.style,{position:"absolute",right:"0",bottom:"0",width:"16px",height:"16px",cursor:"nwse-resize",touchAction:"none"}),k.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>',k.style.color=CLR.label;const j=320,F=240,G=20;function X(x,H){const R=o.innerWidth-i.offsetLeft,$=o.innerHeight-i.offsetTop,W=Math.min(Math.max(i.offsetWidth+x,j),R),_=Math.min(Math.max(i.offsetHeight+H,F),$);i.style.width=`${W}px`,i.style.height=`${_}px`}k.addEventListener("keydown",x=>{if(!(u||v))switch(x.key){case"ArrowRight":x.preventDefault(),X(G,0);break;case"ArrowLeft":x.preventDefault(),X(-G,0);break;case"ArrowDown":x.preventDefault(),X(0,G);break;case"ArrowUp":x.preventDefault(),X(0,-G);break}}),k.addEventListener("pointerdown",x=>{if(u||v)return;x.preventDefault();const H=S(),R=x.clientX,$=x.clientY,W=i.offsetWidth,_=i.offsetHeight,J=o.innerWidth-i.offsetLeft,Q=o.innerHeight-i.offsetTop;k.setPointerCapture(x.pointerId);const Y=N=>{const U=Math.min(Math.max(W+(N.clientX-R),j),J),ee=Math.min(Math.max(_+(N.clientY-$),F),Q);i.style.width=`${U}px`,i.style.height=`${ee}px`},V=N=>{H(),k.releasePointerCapture(N.pointerId),k.removeEventListener("pointermove",Y),k.removeEventListener("pointerup",V)};k.addEventListener("pointermove",Y),k.addEventListener("pointerup",V)}),i.appendChild(l),i.appendChild(D),i.appendChild(k);const K=e.anchor?overlayRootFor(e.anchor):t.body;a?(a.appendChild(i),K.appendChild(a)):K.appendChild(i);const fe=Te(t,K),Z=t.createElement("style");return Z.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
- }`,t.head.appendChild(q),reparentTooltip(i),n?(r.addEventListener("click",p=>{p.target===r&&C()}),t.addEventListener("keydown",k)):(i.addEventListener("keydown",k),i.addEventListener("mousedown",I),I()),nextFrame(()=>(l.isConnected?l:i).focus(),o),{backdrop:r,box:i,contentWrap:B,close:C,bringToFront:I}}export function openModal(e){return re({...e,mode:"modal"})}export function openFloatingWindow(e){return re({...e,mode:"window"})}const ne=new WeakSet;export function openReparentedModal(e,n={}){if(e.length===0||e.some(a=>ne.has(a)))return null;const t=e.map(a=>({el:a,parent:a.parentElement,next:a.nextSibling})),o=openModal({ownerDocument:n.ownerDocument,title:n.title,anchor:e[0],onClose:()=>{for(const a of t){if(ne.delete(a.el),!a.parent)continue;const r=a.next&&a.next.parentNode===a.parent?a.next:null;a.parent.insertBefore(a.el,r)}n.onClosed?.()}});for(const a of t)ne.add(a.el),o.contentWrap.appendChild(a.el);return o}export function makePaletteBtn(e,n,t,o,a){const r=e.makeDropdown("palette","Colour scheme",()=>{const d=n()==="hardBin"||n()==="softBin"?oe().filter(b=>b.name==="default"||b.name==="accessible"):oe();return[...o()?[{value:"custom",label:"Custom"}]:[],...d.map(b=>({value:b.name,label:b.label}))]},()=>t(),i=>a(i));function c(){r.style.display=n()==="metadata"?"none":""}return{btn:r,sync:c}}export function requestedPassFailDisplay(e){return e.passFailDisplay??"off"}export function passFailMenuRows(e,n){if(e.functionalActive)return[];const t=[];return e.hasLimits&&t.push({label:"Spec pass/fail",active:e.display==="spec",onClick:()=>n(e.display==="spec"?"off":"spec")}),e.hasRecorded&&t.push({label:"Test pass/fail",active:e.display==="test",onClick:()=>n(e.display==="test"?"off":"test")}),t}export function makeLogScaleBtn(e,n,t){const o=e.makeBtn("logScale","Toggle log scale",()=>{t({logScale:!n().logScale})});function a(){const r=n(),c=r.plotMode,i=c==="value"||c==="stackedValues";o.style.display=i&&requestedPassFailDisplay(r)==="off"&&!r.functionalActive?"":"none",e.setActive(o,!!r.logScale)}return{btn:o,sync:a}}export function makeLegendStyleBtn(e,n,t){const o=e.makeDropdown("legend","Legend style",()=>[{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"}],()=>n().legendPosition??"default",r=>t(r));function a(){const r=n().plotMode;o.style.display=r==="hardBin"||r==="softBin"||r==="metadata"?"":"none"}return{btn:o,sync:a}}export function makeOverlaysBtn(e,n,t){return e.makeCheckMenuBtn("overlays","Overlays",()=>n(),o=>e.setActive(o,t()))}export function makeOrientationBtn(e,n,t){return e.makeCheckMenuBtn("orient","Orientation",()=>[{section:"Rotate"},{label:"Rotate 90\xB0 clockwise",active:!1,onClick:()=>{const o=n().rotation??0;t({rotation:ROTATIONS[(ROTATIONS.indexOf(o)+1)%4]})}},{section:"Flip"},{label:"Flip horizontal",active:!!n().flipX,onClick:()=>t({flipX:!n().flipX})},{label:"Flip vertical",active:!!n().flipY,onClick:()=>t({flipY:!n().flipY})}],o=>{const{rotation:a,flipX:r,flipY:c}=n();e.setActive(o,!!(a||r||c))})}let j=null;function se(e,n,t,o){const a=n,r=a.__wmapDemoApi;a.__wmapDemoApi=o;const c=e.createElement("div");return c.classList.add("wmap-guide-content"),c.innerHTML=t,{content:c,restoreApi:()=>{a.__wmapDemoApi===o&&(a.__wmapDemoApi=r)}}}function le(e,n){const t=n,o=e.querySelector("script");if(o){const a=e.ownerDocument.createElement("script");a.textContent=o.textContent,e.appendChild(a);const r=e.querySelector(".wmap-guide");return r&&t.__wmapPopulateGuideDemos?.(r),t.__wmapDestroyGuideDemos}}function Me(e,n,t,o){const a=o?.ownerDocument??document,r=a.defaultView??window,{content:c,restoreApi:i}=se(a,r,n,t);Object.assign(c.style,{flex:"1",overflow:"auto",minHeight:"0",minWidth:"0"});let d;const b=openFloatingWindow({title:e,anchor:o,ownerDocument:a,onMaximizeChange:m=>{c.querySelector(".wmap-guide")?.classList.toggle("wmap-guide--max",m)},onClose:()=>{j===b&&(j=null),d?.(),i()}});return b.contentWrap.appendChild(c),d=le(c,r),b}function Le(e,n,t,o){const a=e.document;a.title=n,Object.assign(a.documentElement.style,{height:"100%"}),Object.assign(a.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:'system-ui, -apple-system, "Segoe UI", sans-serif'}),copyWmapThemeTokens(document.documentElement,a.documentElement);const r=syncWmapPopupTheme(document.documentElement,a.documentElement),{content:c,restoreApi:i}=se(a,e,t,o);Object.assign(c.style,{flex:"1",overflow:"auto",minHeight:"0",minWidth:"0"}),a.body.appendChild(c);const d=le(c,e);let b=!1;const m=()=>{if(!b){b=!0,clearInterval(h),r();try{d?.()}catch{}i(),j===s&&(j=null)}},h=setInterval(()=>{e.closed&&m()},400);e.addEventListener("pagehide",m);const s={close:()=>{e.closed||e.close(),m()}};return s}export function openUserGuideWindow(e,n,t,o){j&&(j.close(),j=null);const a=t?.title??"Wafer Map \u2014 User Guide",r=(t?.html??"")+n,i=(o?.ownerDocument.defaultView??window).open("","_blank","width=800,height=820");j=i?Le(i,a,r,e):Me(a,r,e,o)}
9
+ }`,t.head.appendChild(Z),reparentTooltip(i),n?(a.addEventListener("click",x=>{x.target===a&&T()}),t.addEventListener("keydown",B)):(i.addEventListener("keydown",B),i.addEventListener("mousedown",z),z()),nextFrame(()=>(m.isConnected?m:i).focus(),o),{backdrop:a,box:i,contentWrap:D,close:T,bringToFront:z}}export function openModal(e){return le({...e,mode:"modal"})}export function openFloatingWindow(e){return le({...e,mode:"window"})}const oe=new WeakSet;export function openReparentedModal(e,n={}){if(e.length===0||e.some(r=>oe.has(r)))return null;const t=e.map(r=>({el:r,parent:r.parentElement,next:r.nextSibling})),o=openModal({ownerDocument:n.ownerDocument,title:n.title,anchor:e[0],onClose:()=>{for(const r of t){if(oe.delete(r.el),!r.parent)continue;const a=r.next&&r.next.parentNode===r.parent?r.next:null;r.parent.insertBefore(r.el,a)}n.onClosed?.()}});for(const r of t)oe.add(r.el),o.contentWrap.appendChild(r.el);return o}export function makePaletteBtn(e,n,t,o,r,a){const p=()=>n()==="hardBin"||n()==="softBin",i=e.makeCheckMenuBtn("palette","Colour scheme",()=>{const h=p()?ie().filter(s=>s.name==="default"||s.name==="accessible"):ie(),f=t(),b=[];a&&b.push({section:"Scheme"}),o()&&b.push({label:"Custom",active:f==="custom",onClick:()=>r("custom")});for(const s of h)b.push({label:s.label,active:f===s.name,onClick:()=>r(s.name)});return a&&(b.push({section:"Encoding"}),b.push({label:"Mark failing dies",active:a.get(),enabled:p(),disabledHint:p()?void 0:"Available on hard/soft bin maps",onClick:()=>a.set(!a.get())})),b},()=>{});function l(){i.style.display=n()==="metadata"?"none":""}return{btn:i,sync:l}}export function requestedPassFailDisplay(e){return e.passFailDisplay??"off"}export function passFailMenuRows(e,n){if(e.functionalActive)return[];const t=[];return e.hasLimits&&t.push({label:"Spec pass/fail",active:e.display==="spec",onClick:()=>n(e.display==="spec"?"off":"spec")}),e.hasRecorded&&t.push({label:"Test pass/fail",active:e.display==="test",onClick:()=>n(e.display==="test"?"off":"test")}),t}export function makeLogScaleBtn(e,n,t){const o=e.makeBtn("logScale","Toggle log scale",()=>{t({logScale:!n().logScale})});function r(){const a=n(),p=a.plotMode,i=p==="value"||p==="stackedValues";o.style.display=i&&requestedPassFailDisplay(a)==="off"&&!a.functionalActive?"":"none",e.setActive(o,!!a.logScale)}return{btn:o,sync:r}}const De=[{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,n,t,o){const r=e.makeCheckMenuBtn("legend","Legend style",()=>{const p=n().legendPosition??"default",i=[];if(ce(n().plotMode)){o&&i.push({section:"Position"});for(const l of De)i.push({label:l.label,active:p===l.value,onClick:()=>t(l.value)})}if(o){const l=o.blockedReason();i.push({section:"Per map"}),i.push({label:"Legend on each map",active:l?!0:o.get(),enabled:!l,disabledHint:l??void 0,onClick:()=>o.set(!o.get())})}return i},()=>{});function a(){r.style.display=o||ce(n().plotMode)?"":"none"}return{btn:r,sync:a}}function ce(e){return e==="hardBin"||e==="softBin"||e==="metadata"}export function makeOverlaysBtn(e,n,t){return e.makeCheckMenuBtn("overlays","Overlays",()=>n(),o=>e.setActive(o,t()))}export function makeOrientationBtn(e,n,t){return e.makeCheckMenuBtn("orient","Orientation",()=>[{section:"Rotate"},{label:"Rotate 90\xB0 clockwise",active:!1,onClick:()=>{const o=n().rotation??0;t({rotation:ROTATIONS[(ROTATIONS.indexOf(o)+1)%4]})}},{section:"Flip"},{label:"Flip horizontal",active:!!n().flipX,onClick:()=>t({flipX:!n().flipX})},{label:"Flip vertical",active:!!n().flipY,onClick:()=>t({flipY:!n().flipY})}],o=>{const{rotation:r,flipX:a,flipY:p}=n();e.setActive(o,!!(r||a||p))})}let P=null;const de=40,He=de+8;function Oe(e,n){const t=e.createElement("div");t.classList.add("wmap-guide-search"),t.style.cssText="display:flex;align-items:center;gap:2px;margin-left:10px;flex:1;min-width:80px;max-width:260px;";const o=e.createElement("input");o.type="text",o.placeholder="Search guide\u2026",o.setAttribute("aria-label","Search guide"),o.style.cssText=`flex:1;min-width:0;padding:4px 8px;font-size:12px;background:${CLR.menuBg};color:${CLR.text};border:1px solid ${CLR.menuBorder};border-radius:4px;outline:none;`,o.addEventListener("focus",()=>{o.style.borderColor=CLR.iconActive}),o.addEventListener("blur",()=>{o.style.borderColor=CLR.menuBorder});const r=e.createElement("span");r.setAttribute("role","status"),r.setAttribute("aria-live","polite"),r.style.cssText=`font-size:11px;color:${CLR.label};min-width:44px;text-align:center;flex-shrink:0;white-space:nowrap;`;function a(m,u){const c=e.createElement("button");return c.type="button",c.textContent=m,c.setAttribute("aria-label",u),c.disabled=!0,c.style.cssText=`border:none;background:none;cursor:pointer;padding:3px 5px;border-radius:3px;font-size:10px;color:${CLR.label};flex-shrink:0;opacity:0.4;`,c.addEventListener("mouseenter",()=>{c.disabled||(c.style.background=CLR.bgHover)}),c.addEventListener("mouseleave",()=>{c.style.background="none"}),c}const p=a("\u25B2","Previous match"),i=a("\u25BC","Next match");let l=[],h=-1;function f(){const m=l.length===0;p.disabled=m,i.disabled=m,p.style.opacity=m?"0.4":"",i.style.opacity=m?"0.4":""}function b(){for(const m of l)m.parentNode?.replaceChild(e.createTextNode(m.textContent??""),m);n.normalize(),l=[],h=-1}function s(m){if(l.length===0)return;h>=0&&(l[h].style.outline="none"),h=(m%l.length+l.length)%l.length;const u=l[h];u.style.outline=`2px solid ${CLR.iconActive}`,u.style.outlineOffset="1px",u.scrollIntoView({behavior:"smooth",block:"center"}),r.textContent=`${h+1}/${l.length}`}function d(m){b();const u=m.trim();if(!u){r.textContent="",f();return}const c=u.toLowerCase(),y=e.createTreeWalker(n,NodeFilter.SHOW_TEXT,{acceptNode(L){const C=L.parentElement;return!C||C.closest("script,style,.wmap-guide-toc")?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}}),g=[];let v;for(;v=y.nextNode();)g.push(v);for(const L of g){const C=L.textContent??"",A=C.toLowerCase();if(!A.includes(c))continue;const O=e.createDocumentFragment();let S=0,M=A.indexOf(c);for(;M!==-1;){M>S&&O.appendChild(e.createTextNode(C.slice(S,M)));const E=e.createElement("mark");E.textContent=C.slice(M,M+u.length),O.appendChild(E),l.push(E),S=M+u.length,M=A.indexOf(c,S)}S<C.length&&O.appendChild(e.createTextNode(C.slice(S))),L.parentNode?.replaceChild(O,L)}f(),l.length===0?r.textContent="No matches":s(0)}return o.addEventListener("input",()=>d(o.value)),o.addEventListener("keydown",m=>{m.key==="Enter"?(m.preventDefault(),s(h+(m.shiftKey?-1:1))):m.key==="Escape"&&(o.value?(o.value="",d("")):o.blur())}),p.addEventListener("click",()=>s(h-1)),i.addEventListener("click",()=>s(h+1)),t.append(o,r,p,i),t}function We(e,n,t){const o=[...n.querySelectorAll("h2[id]")];if(o.length<2)return;for(const m of n.querySelectorAll("h1[id],h2[id],h3[id],h4[id]"))m.style.scrollMarginTop=`${He}px`;const r=e.createElement("div");r.classList.add("wmap-guide-toc"),r.style.cssText=`position:sticky;top:0;z-index:2;background:${CLR.menuBg};border-bottom:1px solid ${CLR.menuBorder};font-family:system-ui,-apple-system,"Segoe UI",sans-serif;`;const a=e.createElement("div");a.style.cssText=`display:flex;align-items:center;gap:4px;height:${de}px;padding:0 14px;box-sizing:border-box;`;const p=e.createElement("span");p.innerHTML='<svg viewBox="0 0 24 24" width="12" height="12" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>',p.style.cssText="display:inline-flex;transition:transform 0.15s ease;flex-shrink:0;";const i=e.createElement("button");i.type="button";const l="wmap-guide-toc-panel";i.setAttribute("aria-expanded","false"),i.setAttribute("aria-controls",l),i.style.cssText=`display:flex;align-items:center;gap:6px;border:none;background:none;cursor:pointer;padding:6px 8px;margin:0 -8px 0 -8px;border-radius:4px;font-size:13px;font-weight:600;color:${CLR.text};`;const h=e.createElement("span");h.textContent=`Contents (${o.length})`,i.append(p,h),i.addEventListener("mouseenter",()=>{i.style.background=CLR.bgHover}),i.addEventListener("mouseleave",()=>{i.style.background="none"});const f=e.createElement("button");f.type="button",f.textContent="\u2191 Top",f.style.cssText=`margin-left:auto;border:none;background:none;cursor:pointer;padding:6px 8px;border-radius:4px;font-size:12px;color:${CLR.label};`,f.addEventListener("mouseenter",()=>{f.style.background=CLR.bgHover}),f.addEventListener("mouseleave",()=>{f.style.background="none"}),f.addEventListener("click",()=>{d.close(),n.scrollTo({top:0,behavior:"smooth"})}),t?a.append(i,Oe(e,n),f):a.append(i,f);const b=e.createElement("div");b.id=l,b.hidden=!0,b.style.cssText="padding:2px 14px 14px;max-height:min(60vh,440px);overflow-y:auto;";const s=e.createElement("ul");s.setAttribute("role","list"),s.style.cssText="list-style:none;margin:0;padding:0;columns:200px;column-gap:20px;";for(const m of o){const u=e.createElement("li");u.style.cssText="break-inside:avoid;";const c=e.createElement("a");c.href=`#${m.id}`,c.textContent=(m.textContent??"").replace(/^\d+\.\s+/,""),c.style.cssText=`display:block;padding:4px 6px;margin:0 -6px;border-radius:3px;font-size:12.5px;color:${CLR.iconActive};text-decoration:none;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;`,c.addEventListener("mouseenter",()=>{c.style.background=CLR.bgHover}),c.addEventListener("mouseleave",()=>{c.style.background="none"}),c.addEventListener("click",y=>{y.preventDefault(),d.close(),m.scrollIntoView({behavior:"smooth",block:"start"})}),u.appendChild(c),s.appendChild(u)}b.appendChild(s);const d=wireExpandToggle(i,m=>{b.hidden=!m,i.setAttribute("aria-expanded",String(m)),p.style.transform=m?"rotate(180deg)":"none"});r.append(a,b),n.prepend(r)}function pe(e,n,t,o,r){const a=n,p=a.__wmapDemoApi;a.__wmapDemoApi=o;const i=e.createElement("div");return i.classList.add("wmap-guide-content"),i.innerHTML=t,We(e,i,r),{content:i,restoreApi:()=>{a.__wmapDemoApi===o&&(a.__wmapDemoApi=p)}}}function ue(e,n){const t=n,o=e.querySelector("script");if(o){const r=e.ownerDocument.createElement("script");r.textContent=o.textContent,e.appendChild(r);const a=e.querySelector(".wmap-guide");return a&&t.__wmapPopulateGuideDemos?.(a),t.__wmapDestroyGuideDemos}}function Ie(e,n,t,o){const r=o?.ownerDocument??document,a=r.defaultView??window,{content:p,restoreApi:i}=pe(r,a,n,t,!0);Object.assign(p.style,{flex:"1",overflow:"auto",minHeight:"0",minWidth:"0"});let l;const h=openFloatingWindow({title:e,anchor:o,ownerDocument:r,printable:!0,onMaximizeChange:f=>{p.style.setProperty("--wmap-guide-reading-width",f?"1000px":"720px")},onClose:()=>{P===h&&(P=null),l?.(),i()}});return h.contentWrap.appendChild(p),l=ue(p,a),h}function ze(e,n,t,o){const r=e.document;r.title=n,Object.assign(r.documentElement.style,{height:"100%"}),Object.assign(r.body.style,{margin:"0",height:"100vh",overflow:"hidden",display:"flex",flexDirection:"column",fontFamily:'system-ui, -apple-system, "Segoe UI", sans-serif'}),copyWmapThemeTokens(document.documentElement,r.documentElement);const a=syncWmapPopupTheme(document.documentElement,r.documentElement),{content:p,restoreApi:i}=pe(r,e,t,o,!1);Object.assign(p.style,{flex:"1",overflow:"auto",minHeight:"0",minWidth:"0"}),r.body.appendChild(p);const l=ue(p,e);let h=!1;const f=()=>{if(!h){h=!0,clearInterval(b),a();try{l?.()}catch{}i(),P===s&&(P=null)}},b=setInterval(()=>{e.closed&&f()},400);e.addEventListener("pagehide",f);const s={close:()=>{e.closed||e.close(),f()}};return s}export function openUserGuideWindow(e,n,t,o){P&&(P.close(),P=null);const r=t?.title??"Wafer Map \u2014 User Guide",a=(t?.html??"")+n,i=(o?.ownerDocument.defaultView??window).open("","_blank","width=800,height=820");P=i?ze(i,r,a,e):Ie(r,a,e,o)}export function openWaferMapGuide(e,n){Promise.all([import("./userGuideHtml.js"),import("./renderWaferMap.js"),import("./renderWaferGallery.js")]).then(([t,o,r])=>{openUserGuideWindow({buildWaferMap:we,renderWaferMap:o.renderWaferMap,renderWaferGallery:r.renderWaferGallery,analyzeWaferMap:ke},t.USER_GUIDE_HTML,e,n)})}export function openReportModal(e,n){const t=n?.ownerDocument??document,o=t.createElement("iframe");o.srcdoc=e,o.title="Summary report",Object.assign(o.style,{border:"0",width:"100%",flex:"1",minHeight:"0",background:"#fff"});const r=t.createElement("div");Object.assign(r.style,{display:"flex",justifyContent:"flex-end",padding:"6px 14px",borderBottom:`1px solid ${CLR.menuBorder}`,flexShrink:"0"});const a=t.createElement("button");a.type="button",a.textContent="Open as full page \u2197",Object.assign(a.style,{border:"none",background:"none",color:CLR.iconActive,cursor:"pointer",fontSize:"12px",textDecoration:"underline",padding:"0"}),a.addEventListener("click",()=>ye(e)),r.appendChild(a);const p=openModal({title:"Summary report",anchor:n?.anchor,ownerDocument:t,printable:()=>o.contentWindow?.print(),onClose:()=>{}});return p.contentWrap.style.flexDirection="column",p.contentWrap.appendChild(r),p.contentWrap.appendChild(o),p}