| @@ -1,65 +1,76 @@ | ||
| 1 | -(function(){"use strict";function w(s,...e){return{__wpdHtml:!0,strings:s,values:e}}function at(s){return!!s&&s.__wpdHtml===!0}const dt="$$wpd$$",y=/\$\$wpd\$\$(\d+)\$\$/g;function lt(s){let e=s[0];for(let t=1;t<s.length;t++)e+=`${dt}${t-1}$$`+s[t];return e}const Ae=new WeakMap;function Ee(s){const e=Ae.get(s);if(e)return e;const t=document.createElement("template");t.innerHTML=lt(s);const n=[],r=(a,d)=>{if(a.nodeType===Node.ELEMENT_NODE){const c=a;for(const f of Array.from(c.attributes)){const h=f.name,u=f.value,m=h[0];if(y.test(u))if(y.lastIndex=0,m==="@"){const g=y.exec(u);y.lastIndex=0,n.push({path:d,kind:"event",name:h.slice(1),valueIndex:g?Number(g[1]):0}),c.removeAttribute(h)}else if(m==="."){const g=y.exec(u);y.lastIndex=0,n.push({path:d,kind:"prop",name:h.slice(1),valueIndex:g?Number(g[1]):0}),c.removeAttribute(h)}else if(m==="?"){const g=y.exec(u);y.lastIndex=0,n.push({path:d,kind:"bool",name:h.slice(1),valueIndex:g?Number(g[1]):0}),c.removeAttribute(h)}else{const g=[],k=[];let _=0,x;for(y.lastIndex=0;(x=y.exec(u))!==null;)g.push(u.slice(_,x.index)),k.push(Number(x[1])),_=x.index+x[0].length;g.push(u.slice(_)),n.push({path:d,kind:"attr",name:h,template:g,valueIndices:k}),c.setAttribute(h,"")}}}const l=Array.from(a.childNodes);let p=0;for(let c=0;c<l.length;c++){const f=l[c],h=c+p;if(f.nodeType===Node.TEXT_NODE){const u=f.textContent||"";if(!y.test(u)){y.lastIndex=0;continue}y.lastIndex=0;const m=f.parentNode;let g=0,k;const _=[],x=[];for(y.lastIndex=0;(k=y.exec(u))!==null;){k.index>g&&_.push(document.createTextNode(u.slice(g,k.index)));const I=document.createTextNode("");_.push(I),x.push({path:[...d,h+_.length-1],kind:"node",valueIndex:Number(k[1])}),g=k.index+k[0].length}g<u.length&&_.push(document.createTextNode(u.slice(g)));for(const I of _)m.insertBefore(I,f);m.removeChild(f),p+=_.length-1,n.push(...x)}else r(f,[...d,h])}};r(t.content,[]);const o={template:t,buildParts:a=>{const d=[];for(const l of n){let p=a;for(const c of l.path)p=p.childNodes[c];l.kind==="node"?d.push({kind:"node",valueIndex:l.valueIndex,child:{anchor:p,state:null}}):l.kind==="attr"?d.push({kind:"attr",element:p,name:l.name,template:l.template,valueIndices:l.valueIndices}):l.kind==="event"?d.push({kind:"event",valueIndex:l.valueIndex,element:p,name:l.name}):l.kind==="prop"?d.push({kind:"prop",valueIndex:l.valueIndex,element:p,name:l.name}):l.kind==="bool"&&d.push({kind:"bool",valueIndex:l.valueIndex,element:p,name:l.name})}return d}};return Ae.set(s,o),o}const $e=new WeakMap;function ct(s,e){for(const t of s.nodes)if(t.parentNode!==e)return!1;return!0}function K(s,e){const t=$e.get(e);if(t&&t.strings===s.strings&&ct(t,e)){X(t.parts,s.values);return}const n=Ee(s.strings),r=n.template.content.cloneNode(!0),i=n.buildParts(r),o=Array.from(r.childNodes);for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(r),X(i,s.values),$e.set(e,{strings:s.strings,parts:i,nodes:o})}function X(s,e){for(const t of s)if(t.kind==="node")oe(t.child,e[t.valueIndex]);else if(t.kind==="attr"){let n=t.template[0];for(let r=0;r<t.valueIndices.length;r++)n+=Re(e[t.valueIndices[r]]),n+=t.template[r+1];n!==t.last&&(t.last=n,n===""?t.element.removeAttribute(t.name):t.element.setAttribute(t.name,n))}else if(t.kind==="event"){const n=e[t.valueIndex];n!==t.current&&(t.current&&t.element.removeEventListener(t.name,t.current),n&&t.element.addEventListener(t.name,n),t.current=n)}else if(t.kind==="prop"){const n=e[t.valueIndex];n!==t.last&&(t.last=n,t.element[t.name]=n)}else if(t.kind==="bool"){const n=!!e[t.valueIndex];n!==t.last&&(t.last=n,n?t.element.setAttribute(t.name,""):t.element.removeAttribute(t.name))}}function oe(s,e){if(e==null||e===!1){s.state&&(N(s.state),s.state=null);return}if(Array.isArray(e)){ft(s,e);return}if(at(e)){pt(s,e);return}if(e instanceof Node){ut(s,e);return}ht(s,Re(e))}function ut(s,e){const t=s.state;t?.shape==="node"&&t.node===e||(t&&N(t),Y(s,[e]),s.state={shape:"node",node:e})}function ht(s,e){const t=s.state;if(t?.shape==="text"){t.text!==e&&(t.node.textContent=e,t.text=e);return}t&&N(t);const n=document.createTextNode(e);Y(s,[n]),s.state={shape:"text",node:n,text:e}}function pt(s,e){const t=s.state;if(t?.shape==="template"&&t.strings===e.strings){X(t.parts,e.values);return}t&&N(t);const n=Ee(e.strings),r=n.template.content.cloneNode(!0),i=n.buildParts(r),o=Array.from(r.childNodes);Y(s,[r]),X(i,e.values),s.state={shape:"template",strings:e.strings,parts:i,nodes:o}}function ft(s,e){const t=s.state;if(t?.shape==="array"&&t.entries.length===e.length){for(let r=0;r<e.length;r++)oe(t.entries[r],e[r]);return}t&&N(t);const n=[];for(const r of e){const i=document.createTextNode("");Y(s,[i]);const o={anchor:i,state:null};oe(o,r),n.push(o)}s.state={shape:"array",entries:n}}function Y(s,e){const t=s.anchor.parentNode;if(t)for(const n of e)t.insertBefore(n,s.anchor)}function N(s){if(s.shape==="text"){s.node.remove();return}if(s.shape==="template"){for(const e of s.parts)e.kind==="node"&&e.child.state&&(N(e.child.state),e.child.state=null);for(const e of s.nodes)e.parentNode&&e.parentNode.removeChild(e);return}if(s.shape==="node"){s.node.parentNode&&s.node.parentNode.removeChild(s.node);return}for(const e of s.entries)e.state&&N(e.state),e.anchor.remove()}function Re(s){return s==null||s===!1?"":String(s)}const R=class R extends HTMLElement{constructor(){super(),this._renderScheduled=!1,this._propValues={},this.constructor.shadow?(this.attachShadow({mode:"open"}),this._renderRoot=this.shadowRoot):this._renderRoot=this,this._installPropAccessors()}static get observedAttributes(){return this.props.map(Ne)}connectedCallback(){this._adoptStyles(),this.requestUpdate()}attributeChangedCallback(e,t,n){if(t===n)return;const r=mt(e);this._propValues[r]=n,this.requestUpdate()}get classNames(){return Array.from(this.classList)}set classNames(e){if(e==null){this.removeAttribute("class");return}const n=(Array.isArray(e)?e:String(e).split(/\s+/)).map(r=>String(r).trim()).filter(r=>r!=="");this.className=n.join(" ")}requestUpdate(){this._scheduleRender()}emit(e,t){return this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_installPropAccessors(){const e=this.constructor;for(const t of e.props){if(Object.getOwnPropertyDescriptor(this,t))continue;const n=Ne(t);Object.defineProperty(this,t,{get:()=>t in this._propValues?this._propValues[t]:this.getAttribute(n),set:r=>{let i;r==null||r===!1?i=null:r===!0?i="":i=String(r),this._propValues[t]=i,i===null?this.removeAttribute(n):this.setAttribute(n,i),this.requestUpdate()},enumerable:!0,configurable:!0})}}_scheduleRender(){this._renderScheduled||!this.isConnected||(this._renderScheduled=!0,queueMicrotask(()=>{this._renderScheduled=!1,this.isConnected&&K(this.render(),this._renderRoot)}))}_adoptStyles(){const e=this.constructor;if(e.styles.length!==0)if(e.shadow&&this.shadowRoot){const t=e.styles.map(n=>n.sheet).filter(n=>n!==null);if(this.shadowRoot.adoptedStyleSheets=t,t.length!==e.styles.length){for(const n of e.styles)if(!n.sheet){const r=document.createElement("style");r.textContent=n.cssText,this.shadowRoot.appendChild(r)}}}else this._adoptLightStyles(e)}_adoptLightStyles(e){if(!R._lightStylesAdopted.has(e)){R._lightStylesAdopted.add(e);for(const t of e.styles){const n=document.createElement("style");n.dataset.wpdUi=this.tagName.toLowerCase(),n.textContent=t.cssText,document.head.appendChild(n)}}}};R.props=[],R.styles=[],R.shadow=!0,R._lightStylesAdopted=new WeakSet;let S=R;function E(s,e){customElements.get(s)||customElements.define(s,e)}function Ne(s){return s.replace(/[A-Z]/g,e=>"-"+e.toLowerCase())}function mt(s){return s.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}const bt=(()=>{try{return typeof new CSSStyleSheet().replaceSync=="function"}catch{return!1}})();function $(s,...e){let t=s[0];for(let n=1;n<s.length;n++){const r=e[n-1];if(typeof r=="string"||typeof r=="number")t+=String(r);else if(r&&r.__wpdCss)t+=r.cssText;else throw new TypeError("[wpd-ui] css`` interpolations must be strings, numbers, or other css`` results. Got: "+typeof r);t+=s[n]}if(bt){const n=new CSSStyleSheet;return n.replaceSync(t),{__wpdCss:!0,sheet:n,cssText:t}}return{__wpdCss:!0,sheet:null,cssText:t}}const gt=$`:host{display:inline-flex}:host( [ fill-cell ] ){display:flex;width:100%}button{appearance:none;display:inline-flex;align-items:center;justify-content:center;gap:6px;padding:var( --wpd-button-padding,6px 12px );border-radius:var( --wpd-button-border-radius,6px );font:inherit;font-weight:500;cursor:pointer;transition:background-color 0.12s ease,color 0.12s ease,border-color 0.12s ease;background:var( --wpd-button-bg,transparent );background-image:var( --wpd-button-bg-image,none );background-repeat:var( --wpd-button-bg-image-repeat,repeat );background-size:var( --wpd-button-bg-image-size,auto );background-position:var( --wpd-button-bg-image-position,center );color:var( --wpd-button-fg,var( --wpd-fg,#1d2327 ) );border:var( --wpd-button-border,1px solid var( --wpd-border,#c3c4c7 ) )}:host( [ fill-cell ] ) button{width:100%;min-height:var( --wpd-button-min-height,44px )}button:disabled{opacity:0.5;cursor:not-allowed}button:hover:not(:disabled ){background-color:var( --wpd-button-bg-hover,var( --wpd-hover,rgba( 0,0,0,0.04 ) ) )}:host( [ variant='primary' ] ) button{background-color:var( --wpd-button-bg,var( --wp-admin-theme-color,#2271b1 ) );color:var( --wpd-button-fg,var( --wpd-fg-on-accent,#fff ) );border:var( --wpd-button-border,1px solid transparent )}:host( [ variant='primary' ] ) button:hover:not(:disabled ){filter:brightness( 1.06 );background-color:var( --wpd-button-bg,var( --wp-admin-theme-color,#2271b1 ) )}:host( [ variant='secondary' ] ) button{background-color:var( --wpd-button-bg,var( --wpd-hover,rgba( 0,0,0,0.06 ) ) );color:var( --wpd-button-fg,var( --wpd-fg,#1d2327 ) );border:var( --wpd-button-border,1px solid transparent )}:host( [ variant='secondary' ] ) button:hover:not(:disabled ){background-color:var( --wpd-button-bg-hover,var( --wpd-hover,rgba( 0,0,0,0.1 ) ) )}:host( [ variant='danger' ] ) button{background-color:var( --wpd-button-bg,transparent );color:var( --wpd-button-fg,var( --wpd-danger,#d63638 ) );border:var( --wpd-button-border,1px solid currentColor )}:host( [ variant='danger' ] ) button:hover:not(:disabled ){background-color:var( --wpd-danger,#d63638 );color:var( --wpd-fg-on-accent,#fff )}:host( [ variant='link' ] ) button{background-color:transparent;background-image:none;color:var( --wpd-button-fg,var( --wp-admin-theme-color,#2271b1 ) );border:0;padding:0;text-decoration:underline}:host( [ busy ] ) button{pointer-events:none;opacity:0.75}.wpd-button__spinner{box-sizing:border-box;display:inline-block;width:12px;height:12px;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;animation:wpd-button-spin 0.6s linear infinite;flex-shrink:0}@keyframes wpd-button-spin{to{transform:rotate( 360deg )}}`,F=class F extends S{render(){const e=this.disabled!==null,t=this.busy!==null,n=this.type||"button";return w` | |
| 1 | +(function(){"use strict";function v(o,...e){return{__wpdHtml:!0,strings:o,values:e}}function xt(o){return!!o&&o.__wpdHtml===!0}const wt="$$wpd$$",x=/\$\$wpd\$\$(\d+)\$\$/g,Ct="$$wpd-node$$",St=/^\$\$wpd-node\$\$(\d+)\$\$$/,Et=new Set(["style","script","textarea","title"]);function At(o){let e="",t=!1,s=null,n=!1,i=null,r="",a=!1;for(let l=0;l<o.length;l++){const d=o[l];e+=d;for(let u=0;u<d.length;u++){const c=d[u];if(n){d.startsWith("-->",u)&&(n=!1,u+=2);continue}if(i!==null){c==="<"&&d[u+1]==="/"&&d.slice(u+2,u+2+i.length).toLowerCase()===i&&(u+=1+i.length,i=null,t=!0,a=!1,r="");continue}if(s!==null){c===s&&(s=null);continue}if(t){c==='"'||c==="'"?(s=c,a=!1):c===">"?(t=!1,a=!1,Et.has(r)&&(i=r),r=""):a&&(/[a-zA-Z0-9-]/.test(c)?r+=c.toLowerCase():a=!1);continue}if(d.startsWith("<!--",u)){n=!0,u+=3;continue}const f=d[u+1]??"";c==="<"&&/[a-zA-Z/!]/.test(f)&&(t=!0,r="",a=/[a-zA-Z]/.test(f))}l<o.length-1&&(e+=t||n||i!==null?`${wt}${l}$$`:`<!--${Ct}${l}$$-->`)}return e}const ze=new WeakMap;function Ie(o){const e=ze.get(o);if(e)return e;const t=document.createElement("template");t.innerHTML=At(o);const s=[],n=(a,l)=>{if(a.nodeType===Node.ELEMENT_NODE){const c=a;for(const f of Array.from(c.attributes)){const p=f.name,h=f.value,m=p[0];if(x.test(h))if(x.lastIndex=0,m==="@"){const b=x.exec(h);x.lastIndex=0,s.push({path:l,kind:"event",name:p.slice(1),valueIndex:b?Number(b[1]):0}),c.removeAttribute(p)}else if(m==="."){const b=x.exec(h);x.lastIndex=0,s.push({path:l,kind:"prop",name:p.slice(1),valueIndex:b?Number(b[1]):0}),c.removeAttribute(p)}else if(m==="?"){const b=x.exec(h);x.lastIndex=0,s.push({path:l,kind:"bool",name:p.slice(1),valueIndex:b?Number(b[1]):0}),c.removeAttribute(p)}else{const b=[],w=[];let y=0,C;for(x.lastIndex=0;(C=x.exec(h))!==null;)b.push(h.slice(y,C.index)),w.push(Number(C[1])),y=C.index+C[0].length;b.push(h.slice(y)),s.push({path:l,kind:"attr",name:p,template:b,valueIndices:w}),c.setAttribute(p,"")}}}const d=Array.from(a.childNodes);let u=0;for(let c=0;c<d.length;c++){const f=d[c],p=c+u;if(f.nodeType===Node.COMMENT_NODE){const h=St.exec(f.data);if(h){const m=document.createTextNode("");f.parentNode.replaceChild(m,f),s.push({path:[...l,p],kind:"node",valueIndex:Number(h[1])})}continue}if(f.nodeType===Node.TEXT_NODE){const h=f.textContent||"";if(!x.test(h)){x.lastIndex=0;continue}x.lastIndex=0;const m=f.parentNode;let b=0,w;const y=[],C=[];for(x.lastIndex=0;(w=x.exec(h))!==null;){w.index>b&&y.push(document.createTextNode(h.slice(b,w.index)));const M=document.createTextNode("");y.push(M),C.push({path:[...l,p+y.length-1],kind:"node",valueIndex:Number(w[1])}),b=w.index+w[0].length}b<h.length&&y.push(document.createTextNode(h.slice(b)));for(const M of y)m.insertBefore(M,f);m.removeChild(f),u+=y.length-1,s.push(...C)}else n(f,[...l,p])}};n(t.content,[]);const r={template:t,buildParts:a=>{const l=[];for(const d of s){let u=a;for(const c of d.path)u=u.childNodes[c];d.kind==="node"?l.push({kind:"node",valueIndex:d.valueIndex,child:{anchor:u,state:null}}):d.kind==="attr"?l.push({kind:"attr",element:u,name:d.name,template:d.template,valueIndices:d.valueIndices}):d.kind==="event"?l.push({kind:"event",valueIndex:d.valueIndex,element:u,name:d.name}):d.kind==="prop"?l.push({kind:"prop",valueIndex:d.valueIndex,element:u,name:d.name}):d.kind==="bool"&&l.push({kind:"bool",valueIndex:d.valueIndex,element:u,name:d.name})}return l}};return ze.set(o,r),r}const Me=new WeakMap;function $t(o,e){for(const t of o.nodes)if(t.parentNode!==e)return!1;return!0}function Y(o,e){const t=Me.get(e);if(t&&t.strings===o.strings&&$t(t,e)){Z(t.parts,o.values);return}const s=Ie(o.strings),n=s.template.content.cloneNode(!0),i=s.buildParts(n),r=Array.from(n.childNodes);for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(n),Z(i,o.values),Me.set(e,{strings:o.strings,parts:i,nodes:r})}function Z(o,e){for(const t of o)if(t.kind==="node")J(t.child,e[t.valueIndex]);else if(t.kind==="attr"){let s=t.template[0];for(let n=0;n<t.valueIndices.length;n++)s+=Pe(e[t.valueIndices[n]]),s+=t.template[n+1];s!==t.last&&(t.last=s,s===""?t.element.removeAttribute(t.name):t.element.setAttribute(t.name,s))}else if(t.kind==="event"){const s=e[t.valueIndex];s!==t.current&&(t.current&&t.element.removeEventListener(t.name,t.current),s&&t.element.addEventListener(t.name,s),t.current=s)}else if(t.kind==="prop"){const s=e[t.valueIndex];s!==t.last&&(t.last=s,t.element[t.name]=s)}else if(t.kind==="bool"){const s=!!e[t.valueIndex];s!==t.last&&(t.last=s,s?t.element.setAttribute(t.name,""):t.element.removeAttribute(t.name))}}function J(o,e){if(e==null||e===!1){o.state&&($(o.state),o.state=null);return}if(Array.isArray(e)){Lt(o,e);return}if(xt(e)){Tt(o,e);return}if(e instanceof Node){Rt(o,e);return}Nt(o,Pe(e))}function Rt(o,e){const t=o.state;t?.shape==="node"&&t.node===e||(t&&$(t),H(o,[e]),o.state={shape:"node",node:e})}function Nt(o,e){const t=o.state;if(t?.shape==="text"){t.text!==e&&(t.node.textContent=e,t.text=e);return}t&&$(t);const s=document.createTextNode(e);H(o,[s]),o.state={shape:"text",node:s,text:e}}function Tt(o,e){const t=o.state;if(t?.shape==="template"&&t.strings===e.strings){Z(t.parts,e.values);return}t&&$(t);const s=Ie(e.strings),n=s.template.content.cloneNode(!0),i=s.buildParts(n),r=Array.from(n.childNodes);H(o,[n]),Z(i,e.values),o.state={shape:"template",strings:e.strings,parts:i,nodes:r}}function Lt(o,e){const t=o.state;if(t?.shape==="array"){const n=Math.min(t.entries.length,e.length);for(let i=0;i<n;i++)J(t.entries[i],e[i]);if(e.length<t.entries.length){for(let i=e.length;i<t.entries.length;i++){const r=t.entries[i];r.state&&$(r.state),r.anchor.remove()}t.entries.length=e.length}else for(let i=t.entries.length;i<e.length;i++){const r=document.createTextNode("");H(o,[r]);const a={anchor:r,state:null};J(a,e[i]),t.entries.push(a)}return}t&&$(t);const s=[];for(const n of e){const i=document.createTextNode("");H(o,[i]);const r={anchor:i,state:null};J(r,n),s.push(r)}o.state={shape:"array",entries:s}}function H(o,e){const t=o.anchor.parentNode;if(t)for(const s of e)t.insertBefore(s,o.anchor)}function $(o){if(o.shape==="text"){o.node.remove();return}if(o.shape==="template"){for(const e of o.parts)e.kind==="node"&&e.child.state&&($(e.child.state),e.child.state=null);for(const e of o.nodes)e.parentNode&&e.parentNode.removeChild(e);return}if(o.shape==="node"){o.node.parentNode&&o.node.parentNode.removeChild(o.node);return}for(const e of o.entries)e.state&&$(e.state),e.anchor.remove()}function Pe(o){return o==null||o===!1?"":String(o)}const N=class N extends HTMLElement{constructor(){super(),this._renderScheduled=!1,this._propValues={},this.constructor.shadow?(this.attachShadow({mode:"open"}),this._renderRoot=this.shadowRoot):this._renderRoot=this,this._installPropAccessors()}static get observedAttributes(){return this.props.map(He)}connectedCallback(){this._adoptStyles(),this.requestUpdate()}attributeChangedCallback(e,t,s){if(t===s)return;const n=zt(e);this._propValues[n]=s,this.requestUpdate()}get classNames(){return Array.from(this.classList)}set classNames(e){if(e==null){this.removeAttribute("class");return}const s=(Array.isArray(e)?e:String(e).split(/\s+/)).map(n=>String(n).trim()).filter(n=>n!=="");this.className=s.join(" ")}requestUpdate(){this._scheduleRender()}emit(e,t){return this.dispatchEvent(new CustomEvent(e,{detail:t,bubbles:!0,composed:!0}))}_installPropAccessors(){const e=this.constructor;for(const t of e.props){if(Object.getOwnPropertyDescriptor(this,t))continue;const s=He(t);Object.defineProperty(this,t,{get:()=>t in this._propValues?this._propValues[t]:this.getAttribute(s),set:n=>{let i;n==null||n===!1?i=null:n===!0?i="":i=String(n),this._propValues[t]=i,i===null?this.removeAttribute(s):this.setAttribute(s,i),this.requestUpdate()},enumerable:!0,configurable:!0})}}_scheduleRender(){this._renderScheduled||!this.isConnected||(this._renderScheduled=!0,queueMicrotask(()=>{this._renderScheduled=!1,this.isConnected&&Y(this.render(),this._renderRoot)}))}_adoptStyles(){const e=this.constructor;if(e.styles.length!==0)if(e.shadow&&this.shadowRoot){const t=e.styles.map(s=>s.sheet).filter(s=>s!==null);if(this.shadowRoot.adoptedStyleSheets=t,t.length!==e.styles.length){for(const s of e.styles)if(!s.sheet){const n=document.createElement("style");n.textContent=s.cssText,this.shadowRoot.appendChild(n)}}}else this._adoptLightStyles(e)}_adoptLightStyles(e){if(!N._lightStylesAdopted.has(e)){N._lightStylesAdopted.add(e);for(const t of e.styles){const s=document.createElement("style");s.dataset.osUi=this.tagName.toLowerCase(),s.textContent=t.cssText,document.head.appendChild(s)}}}};N.props=[],N.styles=[],N.shadow=!0,N._lightStylesAdopted=new WeakSet;let E=N;function R(o,e){customElements.get(o)||customElements.define(o,e)}function He(o){return o.replace(/[A-Z]/g,e=>"-"+e.toLowerCase())}function zt(o){return o.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}const It=(()=>{try{return typeof new CSSStyleSheet().replaceSync=="function"}catch{return!1}})();function _(o,...e){let t=o[0];for(let s=1;s<o.length;s++){const n=e[s-1];if(typeof n=="string"||typeof n=="number")t+=String(n);else if(n&&n.__wpdCss)t+=n.cssText;else throw new TypeError("[os-ui] css`` interpolations must be strings, numbers, or other css`` results. Got: "+typeof n);t+=o[s]}if(It){const s=new CSSStyleSheet;return s.replaceSync(t),{__wpdCss:!0,sheet:s,cssText:t}}return{__wpdCss:!0,sheet:null,cssText:t}}const Q=_`:host{--_holo-fill:var( --os-ui-holo-fill,${"linear-gradient( 124deg, #afa2e8 0%, #f5a8ea 46%, #8ee9f7 100% )"} );--_holo-ink:var( --os-ui-holo-ink,#0c0b0f );--_holo-sheen:var( --os-ui-holo-sheen,linear-gradient( 124deg,rgba( 159,214,255,0.1 ) 0%,rgba( 236,155,255,0.12 ) 34%,rgba( 242,82,252,0.1 ) 58%,rgba( 147,240,198,0.09 ) 100% ) );--_holo-edge:var( --os-ui-holo-edge,linear-gradient( 124deg,rgba( 154,242,255,0.7 ) 0%,rgba( 236,155,255,0.85 ) 38%,rgba( 242,82,252,0.7 ) 62%,rgba( 159,152,255,0.6 ) 100% ) );--_holo-edge-quiet:var( --os-ui-holo-edge-quiet,linear-gradient( 124deg,rgba( 154,242,255,0.22 ) 0%,rgba( 236,155,255,0.28 ) 38%,rgba( 242,82,252,0.22 ) 62%,rgba( 159,152,255,0.2 ) 100% ) );--_holo-glow:var( --os-ui-holo-glow,0 0 0 1px rgba( 242,82,252,0.28 ),0 2px 10px rgba( 242,82,252,0.22 ) );--_holo-glow-strong:var( --os-ui-holo-glow-strong,0 0 0 1px rgba( 242,82,252,0.42 ),0 4px 18px rgba( 242,82,252,0.38 ),0 1px 3px rgba( 12,11,15,0.6 ) );--_holo-track:var( --os-ui-holo-track,rgba( 255,251,255,0.16 ) );--_holo-track-edge:var( --os-ui-holo-track-edge,#8c8f94 );--_holo-ring-color:var( --os-ui-accent-dim,#2271b1 );--_holo-focus:var( --os-ui-focus-ring,0 0 0 2px rgba( 12,11,15,0.9 ),0 0 0 4px #f252fc,0 0 12px 2px rgba( 242,82,252,0.45 ) );--_holo-focus-field:var( --os-ui-focus-ring-field,0 0 0 1px #f252fc,0 0 0 4px rgba( 242,82,252,0.18 ) );--_holo-t:var( --os-ui-holo-transition,220ms );--_holo-t-fast:var( --os-ui-motion-fast,140ms );--_holo-t-slow:var( --os-ui-motion-slow,340ms );--_holo-t-ambient:var( --os-ui-motion-ambient,12s );--_holo-spring:var( --os-ui-ease-spring,cubic-bezier( 0.32,1.5,0.55,1 ) );--_holo-ease:var( --os-ui-ease-out,cubic-bezier( 0.22,0.9,0.28,1 ) );--_holo-loop:var( --os-ui-ease-loop,cubic-bezier( 0.45,0,0.55,1 ) )}`,Mt=_` .os-holo-fill{background-color:transparent;background-image:var( --_holo-fill );background-size:220% 220%;background-position:22% 28%;background-repeat:no-repeat;color:var( --_holo-ink );transition:background-position var( --_holo-t ) ease,box-shadow var( --_holo-t ) ease,filter var( --_holo-t ) ease}.os-holo-fill:hover{background-position:74% 66%}.os-holo-fill:active{background-position:88% 82%;filter:brightness( 0.94 )}@media ( prefers-reduced-motion:reduce ){.os-holo-fill{transition-duration:1ms}.os-holo-fill:hover,.os-holo-fill:active{background-position:22% 28%}}`,Fe=_` .os-holo-sheen{position:relative;isolation:isolate}.os-holo-sheen::before{content:'';position:absolute;inset:0;z-index:-1;border-radius:inherit;background-image:var( --_holo-sheen );background-size:200% 200%;background-position:20% 30%;opacity:0;pointer-events:none;transition:opacity var( --_holo-t ) ease,background-position var( --_holo-t ) ease}.os-holo-sheen:hover::before,.os-holo-sheen:focus-visible::before{opacity:1;background-position:76% 68%}@media ( prefers-reduced-motion:reduce ){.os-holo-sheen::before{transition-duration:1ms}.os-holo-sheen:hover::before,.os-holo-sheen:focus-visible::before{background-position:20% 30%}}`,qe=_` .os-holo-edge{position:relative}.os-holo-edge::after{content:'';position:absolute;inset:0;border-radius:inherit;padding:1px;background-image:var( --_holo-edge-quiet );opacity:0;pointer-events:none;-webkit-mask:linear-gradient( #000 0 0 ) content-box,linear-gradient( #000 0 0 );-webkit-mask-composite:xor;mask:linear-gradient( #000 0 0 ) content-box,linear-gradient( #000 0 0 );mask-composite:exclude;transition:opacity var( --_holo-t ) ease}.os-holo-edge:hover::after,.os-holo-edge:focus-visible::after{background-image:var( --_holo-edge );opacity:1}.os-holo-edge.is-lit::after{background-image:var( --_holo-edge );opacity:1}@media ( prefers-reduced-motion:reduce ){.os-holo-edge::after{transition-duration:1ms}}`,De=_` .os-holo-glint{position:absolute;inset:0;border-radius:inherit;overflow:hidden;pointer-events:none}.os-holo-glint::before{content:'';position:absolute;top:-60%;bottom:-60%;width:45%;inset-inline-start:-60%;background:linear-gradient( 90deg,transparent 0%,rgba( 255,251,255,0.14 ) 45%,rgba( 255,251,255,0.22 ) 50%,rgba( 255,251,255,0.14 ) 55%,transparent 100% );transform:rotate( 18deg ) translateX( 0 );opacity:0}:hover>.os-holo-glint::before,:focus-visible>.os-holo-glint::before,:host(:hover )>.os-holo-glint::before,:host(:focus-visible )>.os-holo-glint::before{animation:os-holo-glint var( --_holo-t-slow ) var( --_holo-ease )}@keyframes os-holo-glint{0%{opacity:0;transform:rotate( 18deg ) translateX( 0 )}15%{opacity:1}85%{opacity:1}100%{opacity:0;transform:rotate( 18deg ) translateX( 240vw )}}@media ( prefers-reduced-motion:reduce ){:hover>.os-holo-glint::before,:focus-visible>.os-holo-glint::before,:host(:hover )>.os-holo-glint::before,:host(:focus-visible )>.os-holo-glint::before{animation:none}}`,Oe=_` .os-holo-ring{position:absolute;inset:0;border-radius:inherit;box-shadow:0 0 0 0 var( --_holo-ring-color );opacity:0;pointer-events:none}:active:not(:disabled )>.os-holo-ring,:host(:active:not( [ disabled ] ) )>.os-holo-ring{animation:os-holo-ring var( --_holo-t-slow ) var( --_holo-ease )}@keyframes os-holo-ring{0%{opacity:0.45;box-shadow:0 0 0 0 var( --_holo-ring-color )}100%{opacity:0;box-shadow:0 0 0 10px transparent}}@media ( prefers-reduced-motion:reduce ){:active:not(:disabled )>.os-holo-ring,:host(:active:not( [ disabled ] ) )>.os-holo-ring{animation:none}}`,Pt=_` .os-holo-shimmer{background-image:var( --_holo-fill );background-size:300% 300%;background-repeat:no-repeat;animation:os-holo-shimmer 2.4s var( --_holo-loop ) infinite}@keyframes os-holo-shimmer{0%{background-position:0% 50%}100%{background-position:100% 50%}}@media ( prefers-reduced-motion:reduce ){.os-holo-shimmer{animation:none;background-position:30% 50%}}`,Ht=_` .os-holo-enter{animation:os-holo-enter var( --_holo-t ) var( --_holo-spring )}@keyframes os-holo-enter{from{opacity:0;transform:scale( 0.96 )}}@media ( prefers-reduced-motion:reduce ){.os-holo-enter{animation:none}}`,Ft=_` input:where(:not( [ type='checkbox' ] ):not( [ type='radio' ] ) ),select,textarea{transition:background-color var( --_holo-t ) ease,border-color var( --_holo-t ) ease,box-shadow var( --_holo-t ) ease}input:where(:not( [ type='checkbox' ] ):not( [ type='radio' ] ) ):hover:not(:disabled ),select:hover:not(:disabled ),textarea:hover:not(:disabled ){border-color:var( --os-ui-border-strong,#8c8f94 )}input:where(:not( [ type='checkbox' ] ):not( [ type='radio' ] ) ):focus,input:where(:not( [ type='checkbox' ] ):not( [ type='radio' ] ) ):focus-visible,select:focus,select:focus-visible,textarea:focus,textarea:focus-visible{outline:none;border-color:var( --os-ui-accent,#2271b1 );box-shadow:var( --_holo-focus-field )}input::placeholder,textarea::placeholder{color:var( --os-ui-fg-faint,#8c8f94 );opacity:1}input::selection,textarea::selection{background:var( --os-ui-selection-bg,rgba( 159,152,255,0.6 ) );color:var( --os-ui-selection-fg,#fffbff )}@media ( prefers-reduced-motion:reduce ){input:where(:not( [ type='checkbox' ] ):not( [ type='radio' ] ) ),select,textarea{transition-duration:1ms}}`,Ue=_` input[ type='checkbox' ],input[ type='radio' ]{appearance:none;-webkit-appearance:none;position:relative;flex:0 0 auto;box-sizing:border-box;width:16px;height:16px;margin:0;padding:0;border:1px solid var( --_holo-track-edge );border-radius:4px;background-color:var( --_holo-track );background-image:none;background-repeat:no-repeat;cursor:inherit;transition:background-color var( --_holo-t ) ease,border-color var( --_holo-t ) ease,box-shadow var( --_holo-t ) ease}input[ type='radio' ]{border-radius:50%}input[ type='checkbox' ]:hover:not(:disabled ),input[ type='radio' ]:hover:not(:disabled ){border-color:var( --os-ui-accent,#2271b1 )}input[ type='checkbox' ]:focus-visible,input[ type='radio' ]:focus-visible{outline:none;box-shadow:var( --_holo-focus )}input[ type='checkbox' ]:checked,input[ type='checkbox' ]:indeterminate,input[ type='radio' ]:checked{border-color:transparent;background-color:var( --os-ui-accent,#2271b1 )}input[ type='checkbox' ]:checked:focus-visible,input[ type='radio' ]:checked:focus-visible{box-shadow:var( --_holo-focus )}input[ type='checkbox' ]:checked::after{content:'';position:absolute;inset-inline-start:50%;top:46%;width:3.5px;height:7.5px;border:solid var( --os-ui-accent-ink,var( --os-ui-fg-on-accent,#fff ) );border-width:0 2px 2px 0;transform:translate( -50%,-50% ) rotate( 45deg );animation:os-holo-tick 180ms cubic-bezier( 0.3,1.4,0.6,1 )}input[ type='checkbox' ]:indeterminate::after{content:'';position:absolute;inset-inline-start:50%;top:50%;width:8px;height:2px;border:0;border-radius:1px;background:var( --os-ui-accent-ink,var( --os-ui-fg-on-accent,#fff ) );transform:translate( -50%,-50% )}input[ type='radio' ]:checked::after{content:'';position:absolute;inset-inline-start:50%;top:50%;width:6px;height:6px;border-radius:50%;background:var( --os-ui-accent-ink,var( --os-ui-fg-on-accent,#fff ) );transform:translate( -50%,-50% );animation:os-holo-tick 180ms cubic-bezier( 0.3,1.4,0.6,1 )}input[ type='checkbox' ]:disabled,input[ type='radio' ]:disabled{cursor:not-allowed}@keyframes os-holo-tick{from{opacity:0;transform:translate( -50%,-50% ) rotate( 45deg ) scale( 0.4 )}}@media ( prefers-reduced-motion:reduce ){input[ type='checkbox' ]:checked::after,input[ type='radio' ]:checked::after{animation:none}}`,We=_` @keyframes os-holo-drift{0%{background-position:16% 26%}50%{background-position:84% 74%}100%{background-position:16% 26%}}.os-holo-alive{animation:os-holo-drift var( --_holo-t-ambient ) var( --_holo-loop ) infinite}@media ( prefers-reduced-motion:reduce ){.os-holo-alive{animation:none}}`;_` ${Q} ${Mt} ${Fe} ${qe} ${De} ${Oe} ${Pt} ${Ht} ${Ft} ${Ue} ${We} `;const qt=_` ${Q} ${Fe} ${qe} ${De} ${Oe} ${We}:host{display:inline-flex}:host( [ fill-cell ] ){display:flex;width:100%}button{appearance:none;display:inline-flex;align-items:center;justify-content:center;gap:6px;padding:var( --os-ui-button-padding,6px 12px );border-radius:var( --os-ui-button-border-radius,6px );font:inherit;font-weight:500;cursor:pointer;transition:background-color var( --_holo-t ) ease,color var( --_holo-t ) ease,border-color var( --_holo-t ) ease,box-shadow var( --_holo-t ) ease,transform 80ms ease;background:var( --os-ui-button-bg,transparent );background-image:var( --os-ui-button-bg-image,none );background-repeat:var( --os-ui-button-bg-image-repeat,repeat );background-size:var( --os-ui-button-bg-image-size,auto );background-position:var( --os-ui-button-bg-image-position,center );color:var( --os-ui-button-fg,var( --os-ui-fg,#1d2327 ) );border:var( --os-ui-button-border,1px solid var( --os-ui-border,#c3c4c7 ) )}:host( [ fill-cell ] ) button{width:100%;min-height:var( --os-ui-button-min-height,44px )}button:disabled{opacity:0.5;cursor:not-allowed}button:active:not(:disabled ){transform:translateY( 1px )}button:hover:not(:disabled ){background-color:var( --os-ui-button-bg-hover,var( --os-ui-hover,rgba( 0,0,0,0.04 ) ) )}button:focus-visible{outline:none;box-shadow:var( --_holo-focus )}button:disabled::before,button:disabled::after,button:disabled .os-holo-glint{opacity:0 !important}:host( [ variant='primary' ] ) button{background-color:var( --os-ui-button-bg,var( --wp-admin-theme-color,#2271b1 ) );color:var( --os-ui-button-fg,var( --os-ui-accent-ink,var( --os-ui-fg-on-accent,#fff ) ) );border:var( --os-ui-button-border,1px solid transparent )}:host( [ variant='primary' ] ) button:hover:not(:disabled ){filter:brightness( 1.06 );background-color:var( --os-ui-button-bg,var( --wp-admin-theme-color,#2271b1 ) );box-shadow:var( --_holo-glow )}:host( [ variant='holo' ] ) button{background-color:transparent;background-image:var( --_holo-fill );background-size:220% 220%;background-position:22% 28%;background-repeat:no-repeat;color:var( --os-ui-button-fg,var( --_holo-ink ) );border:var( --os-ui-button-border,1px solid transparent );box-shadow:var( --_holo-glow );font-weight:600;transition:background-position var( --_holo-t ) ease,box-shadow var( --_holo-t ) ease,filter var( --_holo-t ) ease,transform 80ms ease}:host( [ variant='holo' ] ) button:hover:not(:disabled ){background-color:transparent;background-position:74% 66%;box-shadow:var( --_holo-glow-strong )}:host( [ variant='holo' ] ) button:active:not(:disabled ){background-position:88% 82%;filter:brightness( 0.94 )}:host( [ variant='holo' ] ) button::before{display:none}@media ( prefers-reduced-motion:reduce ){:host( [ variant='holo' ] ) button:hover:not(:disabled ),:host( [ variant='holo' ] ) button:active:not(:disabled ){background-position:22% 28%}}:host( [ variant='secondary' ] ) button{background-color:var( --os-ui-button-bg,var( --os-ui-hover,rgba( 0,0,0,0.06 ) ) );color:var( --os-ui-button-fg,var( --os-ui-fg,#1d2327 ) );border:var( --os-ui-button-border,1px solid transparent )}:host( [ variant='secondary' ] ) button:hover:not(:disabled ){background-color:var( --os-ui-button-bg-hover,var( --os-ui-hover,rgba( 0,0,0,0.1 ) ) )}:host( [ variant='danger' ] ) button{background-color:var( --os-ui-button-bg,transparent );color:var( --os-ui-button-fg,var( --os-ui-danger,#d63638 ) );border:var( --os-ui-button-border,1px solid currentColor )}:host( [ variant='danger' ] ) button:hover:not(:disabled ){background-color:var( --os-ui-danger,#d63638 );color:var( --os-ui-fg-on-accent,#fff )}:host( [ variant='danger' ] ) button::after{display:none}:host( [ variant='link' ] ) button{background-color:transparent;background-image:none;color:var( --os-ui-button-fg,var( --wp-admin-theme-color,#2271b1 ) );border:0;padding:0;text-decoration:underline}:host( [ variant='link' ] ) button::before,:host( [ variant='link' ] ) button::after,:host( [ variant='link' ] ) .os-holo-glint,:host( [ variant='link' ] ) .os-holo-ring{display:none}:host( [ variant='link' ] ) button:active:not(:disabled ){transform:none}:host( [ busy ] ) button{pointer-events:none;opacity:0.75}:host( [ variant='holo' ][ busy ] ) button{animation:os-holo-drift 12s ease-in-out infinite}@media ( prefers-reduced-motion:reduce ){:host( [ variant='holo' ][ busy ] ) button{animation:none}}.os-button__spinner{box-sizing:border-box;display:inline-block;width:12px;height:12px;border:2px solid currentColor;border-right-color:transparent;border-radius:50%;animation:os-button-spin 0.6s linear infinite;flex-shrink:0}@keyframes os-button-spin{to{transform:rotate( 360deg )}}`,U=class U extends E{static get observedAttributes(){return[...super.observedAttributes,"aria-label"]}render(){const e=this.disabled!==null,t=this.busy!==null,s=this.type||"button",n=this.getAttribute("aria-label")||"";return v` | |
| 2 | 2 | <button |
| 3 | 3 | part="button" |
| 4 | - type=${n} | |
| 4 | + class="os-holo-edge os-holo-sheen" | |
| 5 | + type=${s} | |
| 5 | 6 | ?disabled=${e||t} |
| 6 | 7 | aria-busy=${t?"true":"false"} |
| 8 | + aria-label=${n} | |
| 7 | 9 | > |
| 8 | - ${t?w`<span class="wpd-button__spinner" aria-hidden="true"></span>`:""} | |
| 10 | + ${t?v`<span class="os-button__spinner" aria-hidden="true"></span>`:""} | |
| 9 | 11 | <slot></slot> |
| 12 | + <!-- | |
| 13 | + The two motion layers. Elements rather than | |
| 14 | + pseudo-elements because the sheen and the hairline | |
| 15 | + have already taken this button's ::before and | |
| 16 | + ::after — see the pseudo-element budget note in | |
| 17 | + src/ui/holo.ts. Both are inert and aria-hidden. | |
| 18 | + --> | |
| 19 | + <span class="os-holo-glint" aria-hidden="true"></span> | |
| 20 | + <span class="os-holo-ring" aria-hidden="true"></span> | |
| 10 | 21 | </button> |
| 11 | - `}};F.props=["variant","disabled","type","busy","fill-cell"],F.styles=[gt],F.help=void 0;let ae=F;E("wpd-button",ae);const wt=$`:host{display:inline-flex;align-items:center;justify-content:center;width:var( --wpd-icon-size,16px );height:var( --wpd-icon-size,16px );color:inherit;line-height:1}:host( [ hidden ] ){display:none}.wpd-icon__glyph{font-size:var( --wpd-icon-size,16px );width:var( --wpd-icon-size,16px );height:var( --wpd-icon-size,16px );line-height:1;color:inherit;display:inline-flex;align-items:center;justify-content:center}.wpd-icon__glyph--char{font-family:dashicons;font-style:normal;font-weight:normal;font-variant:normal;text-transform:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;speak:none}.wpd-icon__glyph.dashicons{font-family:dashicons}`;let Z=null;function _t(s){let e=s.trim();if(e==="")return null;(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1));const t=e.match(/^\\([0-9a-f]{1,6})\s?$/i);return t?String.fromCodePoint(parseInt(t[1],16)):e||null}function Te(){const s=new Map;if(typeof document>"u")return s;const e=Array.from(document.styleSheets??[]);for(const t of e){let n=null;try{n=t.cssRules}catch{continue}if(n)for(const r of Array.from(n)){const i=r;if(!i||!i.selectorText)continue;const o=i.selectorText.match(/\.dashicons-([a-z0-9-]+)::?before/i);if(!o)continue;const a=i.style?.content;if(!a)continue;const d=_t(a);d&&s.set(o[1],d)}}return s}function vt(s){Z||(Z=Te());const e=s.startsWith("dashicons-")?s.slice(10):s;return Z.get(e)??null}function yt(){Z=Te()}let Le=!1;function kt(){if(Le||typeof window>"u")return;Le=!0;const s=()=>{yt()};document.readyState==="loading"&&document.addEventListener("DOMContentLoaded",s,{once:!0}),window.addEventListener("load",s,{once:!0})}kt();const D=class D extends S{render(){const e=this.name||"",t=e.startsWith("dashicons-")?e.slice(10):e,n=this.size;n&&/^\d+$/.test(n)&&this.style.setProperty("--wpd-icon-size",`${n}px`);const r=vt(t);return r?w`<span | |
| 12 | - class="wpd-icon__glyph wpd-icon__glyph--char dashicons dashicons-${t}" | |
| 22 | + `}};U.props=["variant","disabled","type","busy","fill-cell"],U.styles=[qt],U.help=void 0;let he=U;R("os-button",he);const Dt=_`:host{display:inline-flex;align-items:center;justify-content:center;width:var( --os-ui-icon-size,16px );height:var( --os-ui-icon-size,16px );color:inherit;line-height:1}:host( [ hidden ] ){display:none}.os-icon__glyph{font-size:var( --os-ui-icon-size,16px );width:var( --os-ui-icon-size,16px );height:var( --os-ui-icon-size,16px );line-height:1;color:inherit;display:inline-flex;align-items:center;justify-content:center}.os-icon__glyph--char{font-family:dashicons;font-style:normal;font-weight:normal;font-variant:normal;text-transform:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;speak:none}.os-icon__glyph.dashicons{font-family:dashicons}`;let ee=null;function Ot(o){let e=o.trim();if(e==="")return null;(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))&&(e=e.slice(1,-1));const t=e.match(/^\\([0-9a-f]{1,6})\s?$/i);return t?String.fromCodePoint(parseInt(t[1],16)):e||null}function je(){const o=new Map;if(typeof document>"u")return o;const e=Array.from(document.styleSheets??[]);for(const t of e){let s=null;try{s=t.cssRules}catch{continue}if(s)for(const n of Array.from(s)){const i=n;if(!i||!i.selectorText)continue;const r=i.selectorText.match(/\.dashicons-([a-z0-9-]+)::?before/i);if(!r)continue;const a=i.style?.content;if(!a)continue;const l=Ot(a);l&&o.set(r[1],l)}}return o}function Ut(o){ee||(ee=je());const e=o.startsWith("dashicons-")?o.slice(10):o;return ee.get(e)??null}function Wt(){ee=je()}let Ge=!1;function jt(){if(Ge||typeof window>"u")return;Ge=!0;const o=()=>{Wt()};document.readyState==="loading"&&document.addEventListener("DOMContentLoaded",o,{once:!0}),window.addEventListener("load",o,{once:!0})}jt();const W=class W extends E{render(){const e=this.name||"",t=e.startsWith("dashicons-")?e.slice(10):e,s=this.size;s&&/^\d+$/.test(s)&&this.style.setProperty("--os-ui-icon-size",`${s}px`);const n=Ut(t);return n?v`<span | |
| 23 | + class="os-icon__glyph os-icon__glyph--char dashicons dashicons-${t}" | |
| 13 | 24 | aria-hidden="true" |
| 14 | - >${r}</span>`:w`<span | |
| 15 | - class="wpd-icon__glyph dashicons dashicons-${t}" | |
| 25 | + >${n}</span>`:v`<span | |
| 26 | + class="os-icon__glyph dashicons dashicons-${t}" | |
| 16 | 27 | aria-hidden="true" |
| 17 | - ></span>`}};D.props=["name","size"],D.styles=[wt],D.help=void 0;let de=D;E("wpd-icon",de);const xt=$`:host{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;padding:32px 24px;text-align:center;color:var( --wpd-empty-state-fg,var( --wpd-fg-muted,#646970 ) )}:host( [ hidden ] ){display:none}.wpd-empty-state__icon{margin-bottom:4px;color:var( --wpd-empty-state-icon-color,currentColor );opacity:0.75}.wpd-empty-state__heading{margin:0;font-size:14px;font-weight:600;color:var( --wpd-fg,#1d2327 )}.wpd-empty-state__description{margin:0;font-size:12px;line-height:1.4;max-width:48ch}.wpd-empty-state__description:empty{display:none}.wpd-empty-state__cta{margin-top:8px}.wpd-empty-state__cta:empty{display:none}`,U=class U extends S{render(){const e=this.icon||"",t=this.heading||"",n=this.description||"";return w` | |
| 18 | - ${e?w`<wpd-icon | |
| 19 | - class="wpd-empty-state__icon" | |
| 28 | + ></span>`}};W.props=["name","size"],W.styles=[Dt],W.help=void 0;let pe=W;R("os-icon",pe);const Gt=_`:host{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:6px;padding:32px 24px;text-align:center;color:var( --os-ui-empty-state-fg,var( --os-ui-fg-muted,#646970 ) )}:host( [ hidden ] ){display:none}.os-empty-state__icon{margin-bottom:4px;color:var( --os-ui-empty-state-icon-color,currentColor );opacity:0.75}.os-empty-state__heading{margin:0;font-size:14px;font-weight:600;color:var( --os-ui-fg,#1d2327 )}.os-empty-state__description{margin:0;font-size:12px;line-height:1.4;max-width:48ch}.os-empty-state__description:empty{display:none}.os-empty-state__cta{margin-top:8px}.os-empty-state__cta:empty{display:none}`,j=class j extends E{render(){const e=this.icon||"",t=this.heading||"",s=this.description||"";return v` | |
| 29 | + ${e?v`<os-icon | |
| 30 | + class="os-empty-state__icon" | |
| 20 | 31 | name=${e} |
| 21 | 32 | size="28" |
| 22 | - ></wpd-icon>`:null} | |
| 23 | - <h3 class="wpd-empty-state__heading">${t}</h3> | |
| 24 | - <p class="wpd-empty-state__description">${n}</p> | |
| 25 | - <div class="wpd-empty-state__cta"> | |
| 33 | + ></os-icon>`:null} | |
| 34 | + <h3 class="os-empty-state__heading">${t}</h3> | |
| 35 | + <p class="os-empty-state__description">${s}</p> | |
| 36 | + <div class="os-empty-state__cta"> | |
| 26 | 37 | <slot name="cta"></slot> |
| 27 | 38 | </div> |
| 28 | 39 | <slot></slot> |
| 29 | - `}};U.props=["icon","heading","description"],U.styles=[xt],U.help=void 0;let le=U;E("wpd-empty-state",le);const Ct="desktop-mode";function Ie(){return window.wp?.i18n}function b(s,e=Ct){return Ie()?.__(s,e)??s}function v(s,...e){const t=Ie()?.sprintf;if(t)return t(s,...e);let n=0;return s.replace(/%(?:(\d+)\$)?[sd]/g,(r,i)=>{const o=i?Number.parseInt(i,10)-1:n++;return String(e[o]??"")})}function J(){const s=window.wp?.hooks;if(!s)throw new Error("[desktop-mode] `window.wp.hooks` is not available. The plugin declares `wp-hooks` as a script dependency; if you are seeing this error, verify the enqueue order.");return s}function St(s,e,t,n){J().addAction(s,e,t,n)}function At(s,e){return J().removeAction(s,e)}function Pe(s,e,...t){return J().applyFilters(s,e,...t)}function Et(s,...e){J().doAction(s,...e)}const $t={GAMES:"desktop-mode.games"},Rt="desktop-mode.activity.";function ce(s){return`${Rt}${String(s)}`}let Nt=0;const ze={publish(s,e){Et(ce(s),e)},subscribe(s,e){const t=`desktop-mode/activity-sub/${++Nt}`,n=ce(s);St(n,t,i=>e(i));let r=!1;return()=>{r||(r=!0,At(n,t))}},filter(s,e,...t){return Pe(ce(s),e,...t)}},Tt="wpd-confirm-dialog";let ue=null;function Q(){return typeof window.customElements<"u"&&!!window.customElements.get(Tt)}function Lt(s){return new Promise((e,t)=>{const n=document.querySelector('script[data-desktop-mode-shell-overlays="1"]'),r=()=>{if(Q()){e();return}t(new Error("[desktop-mode] shell-overlays bundle loaded but did not register the overlay components."))};if(n){Q()?r():(n.addEventListener("load",r),n.addEventListener("error",()=>t(new Error("failed to load shell-overlays bundle"))));return}const i=document.createElement("script");i.src=s,i.async=!0,i.dataset.desktopModeShellOverlays="1",i.addEventListener("load",r),i.addEventListener("error",()=>t(new Error("failed to load shell-overlays bundle"))),document.head.appendChild(i)})}function It(s){return Q()||!s?Promise.resolve():(ue||(ue=Lt(s)),ue)}function Pt(){return window.desktopModeConfig?.shellOverlaysBundleUrl??""}function zt(s,e){const t=Pt();if(Q()||!t){e();return}It(t).then(()=>{s()&&e()}).catch(n=>{typeof console<"u"&&console.warn("[desktop-mode] shell-overlays failed to load; menu/dialog suppressed:",n)})}const Mt=4e3,Ot=200;function z(s){const e=ze.filter("desktop-mode/toast-requested",{...s});if(!e||e.cancel===!0)return()=>{};let t=!1,n=null;return zt(()=>!t,()=>{n=Ht(e)}),()=>{t=!0,n&&n()}}function Ht(s){const e=qt(),t=document.createElement("wpd-toast");t.textContent=s.message,s.action&&(t.setAttribute("action",s.action.label),t.addEventListener("wpd-toast-action",()=>{s.action?.onClick(),i()})),s.dismissible&&(t.setAttribute("dismissible",""),t.addEventListener("wpd-toast-dismiss",()=>{s.onDismiss?.(),i()})),e.appendChild(t);let n=!1,r=null;const i=()=>{n||(n=!0,r!==null&&(window.clearTimeout(r),r=null),t.setAttribute("state","out"),window.setTimeout(()=>{t.remove()},Ot))};return requestAnimationFrame(()=>{t.setAttribute("state","in")}),s.persistent||(r=window.setTimeout(i,s.duration??Mt)),ze.publish("desktop-mode/toast-shown",{...s}),i}function qt(){const s=document.querySelector("wpd-toast-container");if(s)return s;const e=document.createElement("wpd-toast-container");return document.body.appendChild(e),e}function Me(s,e){if(!s||typeof s!="object")return["def (not an object)"];const t=s,n=[];for(const r of e)r.valid(t)||n.push(`${r.field} (${r.message})`);return n}class Ft extends Error{constructor(e,t,n){super(`[desktop-mode] ${e} registration rejected — fields: `+t.join(", ")+"."),this.name="RegistrationError",this.kind=e,this.errors=t,this.def=n}}function Dt(s,e,t){if(e.length!==0)throw new Ft(s,e,t)}const Oe="__desktopModeSharedStores";function Ut(){const s=window;let e=s[Oe];return e||(e=new Map,s[Oe]=e),e}function He(s,e){const t=Ut();let n=t.get(s);n||(n={state:e(),listeners:new Set,rebuild:e},t.set(s,n));const r={get state(){return n.state},set state(i){n.state=i},getState(){return n.state},notify(){for(const i of Array.from(n.listeners))try{i(n.state)}catch(o){console.error(`[desktop-mode/shared-store:${s}] subscriber threw:`,o)}},subscribe(i){return n.listeners.add(i),()=>{n.listeners.delete(i)}},setState(i){const o=n.state;if(typeof o!="object"||o===null){console.warn(`[desktop-mode/shared-store:${s}] setState called on a primitive store; use the state setter instead.`);return}Object.assign(o,i),r.notify()},reset(){const i=n.rebuild(),o=n.state;if(typeof o=="object"&&o!==null&&typeof i=="object"&&i!==null){const a=o;for(const d of Object.keys(a))delete a[d];Object.assign(a,i)}else n.state=i;n.listeners.clear()}};return r}const qe=He("desktop-mode/games-registry",()=>({seed:[],listeners:new Set})),ee=qe.state.seed,he=qe.state.listeners;function Gt(s){Dt("Game",Me(s,De),s);const e=ee.findIndex(t=>t.id===s.id);e>=0?ee[e]=s:ee.push(s),Bt()}function jt(s){return he.add(s),()=>{he.delete(s)}}function Bt(){const s=Array.from(he);for(const e of s)try{e()}catch(t){typeof console<"u"&&console.error("[desktop-mode] games registry listener threw:",t)}}function Fe(){const s=ee.slice(),e=Pe($t.GAMES,s);return Array.isArray(e)?e.filter(Wt):(typeof console<"u"&&console.warn("[desktop-mode] `desktop-mode.games` filter returned a non-array; falling back to seed list."),s)}function pe(s){return Fe().find(e=>e.id===s)}const De=[{field:"id",message:"missing or not a non-empty string",valid:s=>typeof s.id=="string"&&s.id!==""},{field:"title",message:"missing or not a non-empty string",valid:s=>typeof s.title=="string"&&s.title!==""},{field:"scoreColumns",message:"must be an array",valid:s=>Array.isArray(s.scoreColumns)},{field:"render/scriptUrl",message:"needs a `render` callback or a `scriptUrl` to lazily load one",valid:s=>typeof s.render=="function"||typeof s.scriptUrl=="string"&&s.scriptUrl!==""}];function Wt(s){return Me(s,De).length===0}const Vt="http://localhost/";function Ue(s,e){const t=typeof window<"u"&&window.location?window.location.href:Vt,n=new URL(s,t),r=e.replace(/^\/+/,""),i=r.indexOf("?"),o=i===-1?r:r.slice(0,i),a=i===-1?"":r.slice(i+1);if(n.searchParams.has("rest_route")){const d=n.searchParams.get("rest_route")??"/",l=d.endsWith("/")?d:d+"/";n.searchParams.set("rest_route",l+o)}else{const d=n.pathname.endsWith("/")?n.pathname:n.pathname+"/";n.pathname=d+o}return a&&new URLSearchParams(a).forEach((l,p)=>{n.searchParams.append(p,l)}),n.toString()}const Ge="X-WP-Nonce";function Kt(s,e){const t=Xt();if(!t)return e;const n=Yt(s);if(!n||!Zt(n))return e;const r=e?.headers??(typeof Request<"u"&&s instanceof Request?s.headers:void 0),i=new Headers(r??{});return i.has(Ge)?e:(i.set(Ge,t),{...e??{},headers:i})}function Xt(){if(typeof window>"u")return;const e=window.desktopModeConfig?.restNonce;return typeof e=="string"&&e.length>0?e:void 0}function Yt(s){try{const e=typeof window<"u"&&window.location?window.location.href:void 0;return typeof s=="string"?new URL(s,e):s instanceof URL?s:typeof Request<"u"&&s instanceof Request?new URL(s.url,e):null}catch{return null}}function Zt(s){return typeof window>"u"||!window.location||s.origin!==window.location.origin?!1:!!(s.pathname.includes("/wp-json/")||s.searchParams.has("rest_route"))}function je(s,e,t={}){const n=window.wp?.desktop?.fetch;if(typeof n=="function")return n(s,e,t);const r=Kt(s,e);return fetch(s,r)}const Jt="desktop-mode/games";function Qt(){const e=window.wp?.desktop?.config;return{restUrl:e?.restUrl||"/wp-json/",restNonce:e?.restNonce||""}}async function A(s,e={},t={}){const{restUrl:n,restNonce:r}=Qt(),i=new Headers(e.headers??{});i.set("X-WP-Nonce",r),e.body&&!i.has("Content-Type")&&i.set("Content-Type","application/json");const o=await je(Ue(n,s),{...e,headers:i,credentials:"same-origin"},{source:Jt,windowId:t.windowId,silent:t.silent}),a=await o.json().catch(()=>null);if(!o.ok){const d=a?.message||`Games request failed (${o.status})`,l=new Error(d);throw l.status=o.status,l}return a}function Be(s,e={}){const t=new URLSearchParams({page:String(e.page??1),per_page:String(e.perPage??25),orderby:e.orderby??"score",order:e.order??"desc"});return e.userId&&t.set("user_id",String(e.userId)),A(`desktop-mode/v1/games/${s}/scores?${t}`)}function en(s,e,t={}){return A(`desktop-mode/v1/games/${s}/scores`,{method:"POST",body:JSON.stringify({score:e.score,meta:e.meta??{}})},t)}function tn(){return A("desktop-mode/v1/games/playtime")}function nn(s,e,t={}){return A(`desktop-mode/v1/games/${s}/playtime`,{method:"POST",body:JSON.stringify({seconds:e})},t)}function sn(s={}){const e=new URLSearchParams({box:s.box??"all"});return s.state&&e.set("state",s.state),A(`desktop-mode/v1/games/challenges?${e}`)}function rn(s){return A("desktop-mode/v1/games/challenges",{method:"POST",body:JSON.stringify({game:s.game,recipient_id:s.recipientId,score:s.score,meta:s.meta??{}})})}function on(s){return A(`desktop-mode/v1/games/challenges/${s}/accept`,{method:"POST"})}function an(s){return A(`desktop-mode/v1/games/challenges/${s}/decline`,{method:"POST"})}function dn(s,e,t={}){return A(`desktop-mode/v1/games/challenges/${s}/complete`,{method:"POST",body:JSON.stringify({score:e.score,meta:e.meta??{}})},t)}const ln=6e4;function cn(s,e={}){let t=Date.now(),n=0,r=!1;const i=()=>{if(t===null)return;const d=Date.now();n+=Math.max(0,d-t),t=d},o=()=>{i();const d=Math.floor(n/1e3);d<1||(n-=d*1e3,nn(s,d,{windowId:e.windowId,silent:!0}).catch(()=>{n+=d*1e3}))},a=setInterval(o,ln);return{pause:()=>{i(),t=null},resume:()=>{r||t!==null||(t=Date.now())},stop:()=>{r||(r=!0,clearInterval(a),i(),t=null,o())}}}function un(s,e,t){const n=new Date(`${e}T00:00:00Z`);if(isNaN(n.getTime())||t<1)return 0;const r=new Date(n.getTime()-(t-1)*864e5).toISOString().slice(0,10);let i=0;for(const[o,a]of Object.entries(s))o>=r&&o<=e&&(i+=Math.max(0,Math.floor(Number(a)||0)));return i}function We(s){const e=Math.max(0,Math.floor(Number(s)||0)),t=Math.floor(e/3600),n=Math.floor(e%3600/60);return t>0?v(b("%1$dh %2$dm"),t,n):n>0?v(b("%dm"),n):v(b("%ds"),e)}function Ve(){return window.wp?.desktop??{}}const hn=760,pn=560,fn=480,mn=380;async function bn(s){if(typeof s.render=="function")return s;const e=Ve().loadVendorScript;if(!s.scriptUrl||typeof e!="function")throw new Error(`[desktop-mode] Game "${s.id}" has no render callback and no loadable script.`);await e(s.scriptUrl,{translations:s.scriptTranslations,l10n:s.scriptL10n,before:s.scriptBefore,after:s.scriptAfter});const n=window.desktopModeGames?.[s.id];if(!n||typeof n.render!="function")throw new Error(`[desktop-mode] No game def on window.desktopModeGames["${s.id}"]. Script loaded but didn't publish a def — check the plugin's global assignment.`);const r={...s,render:n.render,window:n.window??s.window};return Gt(r),r}async function Ke(s,e={}){const t=Ve();let n=pe(s);if(!n)throw new Error(`[desktop-mode] Unknown game "${s}".`);n=await bn(n);const r=n.render;if(typeof r!="function")throw new Error(`[desktop-mode] Game "${s}" did not provide a render callback.`);if(typeof t.registerWindow!="function")throw new Error("[desktop-mode] wp.desktop.registerWindow is missing — the shell must boot before launching games.");const i=`desktop-mode-game-${s}`,o=`game:${i}`,a=t.windowManager,d=a?.getByBaseId?.(i)??a?.getById(i);if(d){const u=d.config?.desktopId;u&&a?.switchDesktop&&u!==a?.getActiveDesktopId?.()&&a.switchDesktop(u),t.registerWindow({id:i,title:n.title,icon:n.icon,render:()=>{}});return}t.wallpaper?.suspend(o);let l=!1;const p=()=>{l||(l=!0,t.wallpaper?.resume(o))};let c=null;const f=()=>{c?.stop(),c=null};t.onWindow?.(i,{closed:()=>{f(),p()},minimized:()=>c?.pause(),restored:()=>c?.resume()});const h=u=>e.challenge?dn(e.challenge.id,u,{windowId:i}).then(()=>{}):en(s,u,{windowId:i}).then(()=>{});try{await t.registerWindow({id:i,title:n.title,icon:n.icon,width:n.window?.width??hn,height:n.window?.height??pn,minWidth:n.window?.minWidth??fn,minHeight:n.window?.minHeight??mn,render:u=>{const m={windowId:i,container:u,config:n.config??{},challenge:e.challenge,submitScore:h,close:()=>{t.windowManager?.getById(i)?.close()}};c=cn(s,{windowId:i});const g=r(m);return()=>{try{g?.()}finally{f(),p()}}}})}catch(u){throw f(),p(),u}}function gn(s){if(!s)return 214;let e=5381;for(let t=0;t<s.length;t++)e=Math.imul(e,33)+s.charCodeAt(t);return(e%360+360)%360}const wn=$`:host{display:inline-flex;position:relative;width:var( --wpd-avatar-size,32px );height:var( --wpd-avatar-size,32px );flex:0 0 auto;vertical-align:middle;line-height:0;perspective:calc( var( --wpd-avatar-size,32px ) * 8 );--wpd-avatar-tilt-x:0deg;--wpd-avatar-tilt-y:0deg;--wpd-avatar-hover:0;--wpd-avatar-glare-x:50%;--wpd-avatar-glare-y:50%}:host( [ hidden ] ){display:none}.wpd-avatar__tile{position:relative;width:100%;height:100%;border-radius:50%;overflow:hidden;background:var( --desktop-mode-window-bg,#f0f0f1 );color:var( --wpd-fg-on-accent,#fff );display:flex;align-items:center;justify-content:center;font-weight:700;font-size:calc( var( --wpd-avatar-size,32px ) * 0.48 );line-height:1;letter-spacing:0;font-feature-settings:'tnum' 1;user-select:none;transform-style:preserve-3d;transform:rotateX( var( --wpd-avatar-tilt-x ) ) rotateY( var( --wpd-avatar-tilt-y ) ) scale( calc( 1 + var( --wpd-avatar-hover ) * 0.07 ) );transition:transform 220ms cubic-bezier( 0.2,0.8,0.2,1 ),box-shadow 220ms cubic-bezier( 0.2,0.8,0.2,1 );box-shadow:inset 0 0 0 1px rgba( 255,255,255,calc( 0.18 + 0.22 * var( --wpd-avatar-hover ) ) ),inset 0 0 0 calc( 1px + var( --wpd-avatar-hover ) * 1px ) rgba( 0,0,0,calc( 0.08 + 0.04 * var( --wpd-avatar-hover ) ) ),0 calc( 1px + var( --wpd-avatar-hover ) * 8px ) calc( 6px + var( --wpd-avatar-hover ) * 18px ) rgba( 0,0,0,calc( 0.08 + 0.18 * var( --wpd-avatar-hover ) ) )}.wpd-avatar__tile::after{content:'';position:absolute;inset:0;border-radius:50%;background:radial-gradient( circle at var( --wpd-avatar-glare-x ) var( --wpd-avatar-glare-y ),var( --wpd-scrim,rgba( 255,255,255,0.55 ) ) 0%,var( --wpd-hover,rgba( 255,255,255,0 ) ) 55% );opacity:var( --wpd-avatar-hover );mix-blend-mode:overlay;pointer-events:none;transition:opacity 220ms cubic-bezier( 0.2,0.8,0.2,1 )}.wpd-avatar__tile::before{content:'';position:absolute;inset:calc( var( --wpd-avatar-hover ) * -3px );border-radius:50%;background:radial-gradient( circle at var( --wpd-avatar-glare-x ) var( --wpd-avatar-glare-y ),rgba( 99,102,241,calc( 0.35 * var( --wpd-avatar-hover ) ) ) 0%,rgba( 99,102,241,0 ) 70% );filter:blur( 4px );pointer-events:none;z-index:-1;transition:inset 220ms cubic-bezier( 0.2,0.8,0.2,1 ),background 220ms}.wpd-avatar__tile img{width:calc( 100% + 2px );height:calc( 100% + 2px );margin:-1px;object-fit:cover;display:block;transform:translateZ( 1px )}.wpd-avatar__dot{position:absolute;bottom:0;inset-inline-end:0;width:calc( var( --wpd-avatar-size,32px ) * 0.32 );height:calc( var( --wpd-avatar-size,32px ) * 0.32 );min-width:8px;min-height:8px;border-radius:50%;box-sizing:border-box;border:2px solid var( --wpd-avatar-dot-ring,var( --desktop-mode-window-bg,#fff ) );background:var( --wpd-avatar-dot-color,transparent );z-index:2}.wpd-avatar__dot--online{background:var( --wpd-success-fg,#00a32a )}.wpd-avatar__dot--inactive{background:var( --wpd-warning-fg,#dba617 )}.wpd-avatar__dot--offline{background:var( --wpd-fg-muted,#8c8f94 )}@media ( prefers-reduced-motion:reduce ){.wpd-avatar__tile{transform:none;transition:box-shadow 200ms}.wpd-avatar__tile::after,.wpd-avatar__tile::before{display:none}}`,Xe={xs:20,sm:24,md:40,lg:64,xl:96},Ye=new Set(["online","inactive","offline"]),G=class G extends S{constructor(){super(...arguments),this._presenceHandler=null,this._imgFailed=!1,this._onPointerMove=null,this._onPointerEnter=null,this._onPointerLeave=null,this._tiltRaf=0,this._pendingTiltX="0deg",this._pendingTiltY="0deg",this._pendingGlareX="50%",this._pendingGlareY="50%"}connectedCallback(){super.connectedCallback(),this._maybeAttachPresenceListener(),this._attachHoverEffect()}disconnectedCallback(){this._presenceHandler&&(document.removeEventListener("desktop-mode-presence-changed",this._presenceHandler),this._presenceHandler=null),this._detachHoverEffect()}attributeChangedCallback(e,t,n){super.attributeChangedCallback(e,t,n),e==="src"&&(this._imgFailed=!1),(e==="user-id"||e==="presence")&&this._maybeAttachPresenceListener()}render(){const e=this._attr("src"),t=this._attr("name")||"",n=this._attr("alt"),r=n!==null?n:t,i=this._attr("size"),o=this._resolveSize(i),a=this._presenceForRender(),d=this._attr("clickable")!==null;this.style.setProperty("--wpd-avatar-size",`${o}px`);const l=e&&!this._imgFailed?"":this._initialsBg(t),p=e&&!this._imgFailed?w`<img | |
| 40 | + `}};j.props=["icon","heading","description"],j.styles=[Gt],j.help=void 0;let fe=j;R("os-empty-state",fe);const Bt="desktop-mode";function Be(){return window.wp?.i18n}function g(o,e=Bt){return Be()?.__(o,e)??o}function k(o,...e){const t=Be()?.sprintf;if(t)return t(o,...e);let s=0;return o.replace(/%(?:(\d+)\$)?[sd]/g,(n,i)=>{const r=i?Number.parseInt(i,10)-1:s++;return String(e[r]??"")})}function te(){const o=window.wp?.hooks;if(!o)throw new Error("[openstation] `window.wp.hooks` is not available. The plugin declares `wp-hooks` as a script dependency; if you are seeing this error, verify the enqueue order.");return o}function Kt(o,e,t,s){te().addAction(o,e,t,s)}function Vt(o,e){return te().removeAction(o,e)}function Ke(o,e,...t){return te().applyFilters(o,e,...t)}function Xt(o,...e){te().doAction(o,...e)}const Yt={GAMES:"os.games"},Zt="os.activity.";function me(o){return Zt+String(o).replace(/[^a-zA-Z0-9_.-]/g,".")}let Jt=0;const be={publish(o,e){Xt(me(o),e)},subscribe(o,e){const t=`os/activity-sub/${++Jt}`,s=me(o);Kt(s,t,i=>e(i));let n=!1;return()=>{n||(n=!0,Vt(s,t))}},filter(o,e,...t){return Ke(me(o),e,...t)}};let ge=null;function oe(){return!!window.openStationShellOverlays}function Qt(o){return new Promise((e,t)=>{const s=document.querySelector('script[data-os-shell-overlays="1"]'),n=()=>{if(oe()){e();return}t(new Error("[openstation] shell-overlays bundle loaded but did not set `window.openStationShellOverlays`."))};if(s){oe()?n():(s.addEventListener("load",n),s.addEventListener("error",()=>t(new Error("failed to load shell-overlays bundle"))));return}const i=document.createElement("script");i.src=o,i.async=!0,i.dataset.osShellOverlays="1",i.addEventListener("load",n),i.addEventListener("error",()=>t(new Error("failed to load shell-overlays bundle"))),document.head.appendChild(i)})}function eo(o){return oe()||!o?Promise.resolve():(ge||(ge=Qt(o)),ge)}function to(){return window.openStationConfig?.shellOverlaysBundleUrl??""}function oo(o,e){const t=to();if(oe()||!t){e();return}eo(t).then(()=>{o()&&e()}).catch(s=>{typeof console<"u"&&console.warn("[openstation] shell-overlays failed to load; menu/dialog suppressed:",s)})}const so=4e3,no=200,io=1200;function F(o){const e=be.filter("os/toast-requested",{...o});if(!e||e.cancel===!0)return()=>{};let t=!1,s=null;return oo(()=>!t,()=>{s=lo(e)}),()=>{t=!0,s&&s()}}const ro={success:"positive",warning:"warning",error:"critical","shell-error":"critical"};function ao(o){return o?window.openStationConfig?.toastTypes?.find(s=>s.id===o)?.tone??ro[o]??null:null}function lo(o){const e=po(),t=document.createElement("os-toast");t.textContent=o.message;const s=ao(o.type);s&&t.setAttribute("tone",s),o.action&&(t.setAttribute("action",o.action.label),t.addEventListener("os-toast-action",()=>{o.action?.onClick(),d()})),o.dismissible&&(t.setAttribute("dismissible",""),t.addEventListener("os-toast-dismiss",()=>{o.onDismiss?.(),d()})),e.appendChild(t);let n=!1,i=null,r=o.duration??so,a=0;const l=()=>{i!==null&&(window.clearTimeout(i),i=null)},d=()=>{n||(n=!0,l(),ho(t),t.setAttribute("state","out"),window.setTimeout(()=>{t.remove(),uo()},no))},u=()=>{n||o.persistent||i!==null||(a=Date.now(),i=window.setTimeout(d,r))},c=()=>{i!==null&&(r=Math.max(0,r-(Date.now()-a)),l())};return requestAnimationFrame(()=>{t.setAttribute("state","in")}),t.addEventListener("os-toast-hold",f=>{if(f.detail?.held){c();return}r=Math.max(r,io),u()}),co(t),u(),be.publish("os/toast-shown",{...o}),d}let se=null,q=0;function Ve(o){const e=o.target;e instanceof HTMLElement&&(e.closest("os-toast-container")||(se=e))}function co(o){q===0&&document.addEventListener("focusin",Ve,!0),q+=1;const e=o.ownerDocument,t=e.activeElement;t instanceof HTMLElement&&t!==e.body&&!t.closest("os-toast-container")&&(se=t)}function uo(){q=Math.max(0,q-1),q===0&&document.removeEventListener("focusin",Ve,!0)}function ho(o){const e=o.ownerDocument.activeElement;e!==o&&!o.contains(e)||se?.isConnected===!0&&se.focus()}function po(){const o=document.querySelector("os-toast-container");if(o)return o;const e=document.createElement("os-toast-container");return document.body.appendChild(e),e}function Xe(o,e){if(!o||typeof o!="object")return["def (not an object)"];const t=o,s=[];for(const n of e)n.valid(t)||s.push(`${n.field} (${n.message})`);return s}class fo extends Error{constructor(e,t,s){super(`[openstation] ${e} registration rejected — fields: `+t.join(", ")+"."),this.name="RegistrationError",this.kind=e,this.errors=t,this.def=s}}function mo(o,e,t){if(e.length!==0)throw new fo(o,e,t)}const Ye="__openStationSharedStores";function bo(){const o=window;let e=o[Ye];return e||(e=new Map,o[Ye]=e),e}function ve(o,e){const t=bo();let s=t.get(o);s||(s={state:e(),listeners:new Set,rebuild:e},t.set(o,s));const n={get state(){return s.state},set state(i){s.state=i},getState(){return s.state},notify(){for(const i of Array.from(s.listeners))try{i(s.state)}catch(r){console.error(`[desktop-mode/shared-store:${o}] subscriber threw:`,r)}},subscribe(i){return s.listeners.add(i),()=>{s.listeners.delete(i)}},setState(i){const r=s.state;if(typeof r!="object"||r===null){console.warn(`[desktop-mode/shared-store:${o}] setState called on a primitive store; use the state setter instead.`);return}Object.assign(r,i),n.notify()},reset(){const i=s.rebuild(),r=s.state;if(typeof r=="object"&&r!==null&&typeof i=="object"&&i!==null){const a=r;for(const l of Object.keys(a))delete a[l];Object.assign(a,i)}else s.state=i;s.listeners.clear()}};return n}const Ze=ve("desktop-mode/games-registry",()=>({seed:[],listeners:new Set})),ne=Ze.state.seed,_e=Ze.state.listeners;function go(o){mo("Game",Xe(o,Qe),o);const e=ne.findIndex(t=>t.id===o.id);e>=0?ne[e]=o:ne.push(o),_o()}function vo(o){return _e.add(o),()=>{_e.delete(o)}}function _o(){const o=Array.from(_e);for(const e of o)try{e()}catch(t){typeof console<"u"&&console.error("[openstation] games registry listener threw:",t)}}function Je(){const o=ne.slice(),e=Ke(Yt.GAMES,o);return Array.isArray(e)?e.filter(yo):(typeof console<"u"&&console.warn("[openstation] `os.games` filter returned a non-array; falling back to seed list."),o)}function ye(o){return Je().find(e=>e.id===o)}const Qe=[{field:"id",message:"missing or not a non-empty string",valid:o=>typeof o.id=="string"&&o.id!==""},{field:"title",message:"missing or not a non-empty string",valid:o=>typeof o.title=="string"&&o.title!==""},{field:"scoreColumns",message:"must be an array",valid:o=>Array.isArray(o.scoreColumns)},{field:"render/scriptUrl",message:"needs a `render` callback or a `scriptUrl` to lazily load one",valid:o=>typeof o.render=="function"||typeof o.scriptUrl=="string"&&o.scriptUrl!==""}];function yo(o){return Xe(o,Qe).length===0}const et=new Set;function ko(o){if(et.has(o))return;const t=window.openStationConfig?.deferredStyles?.[o];if(!t?.url)return;et.add(o);const s=t.url.replace(/\\/g,"\\\\").replace(/"/g,'\\"');if(!document.head.querySelector(`link[rel="stylesheet"][href="${s}"]`)){const i=document.createElement("link");i.rel="stylesheet",i.href=t.url,i.dataset.osStyleHandle=o,document.head.appendChild(i)}for(const i of t.inline??[]){if(typeof i!="string"||i==="")continue;const r=document.createElement("style");r.dataset.osStyleHandle=o,r.textContent=i,document.head.appendChild(r)}}const xo="http://localhost/";function tt(o,e){const t=typeof window<"u"&&window.location?window.location.href:xo,s=new URL(o,t),n=e.replace(/^\/+/,""),i=n.indexOf("?"),r=i===-1?n:n.slice(0,i),a=i===-1?"":n.slice(i+1);if(s.searchParams.has("rest_route")){const l=s.searchParams.get("rest_route")??"/",d=l.endsWith("/")?l:l+"/";s.searchParams.set("rest_route",d+r)}else{const l=s.pathname.endsWith("/")?s.pathname:s.pathname+"/";s.pathname=l+r}return a&&new URLSearchParams(a).forEach((d,u)=>{s.searchParams.append(u,d)}),s.toString()}const ot="X-WP-Nonce";function wo(o,e){const t=Co();if(!t)return e;const s=So(o);if(!s||!Eo(s))return e;const n=e?.headers??(typeof Request<"u"&&o instanceof Request?o.headers:void 0),i=new Headers(n??{});return i.has(ot)?e:(i.set(ot,t),{...e??{},headers:i})}function Co(){if(typeof window>"u")return;const e=window.openStationConfig?.restNonce;return typeof e=="string"&&e.length>0?e:void 0}function So(o){try{const e=typeof window<"u"&&window.location?window.location.href:void 0;return typeof o=="string"?new URL(o,e):o instanceof URL?o:typeof Request<"u"&&o instanceof Request?new URL(o.url,e):null}catch{return null}}function Eo(o){return typeof window>"u"||!window.location||o.origin!==window.location.origin?!1:!!(o.pathname.includes("/wp-json/")||o.searchParams.has("rest_route"))}function st(o,e,t={}){const s=window.wp?.os?.fetch;if(typeof s=="function")return s(o,e,t);const n=wo(o,e);return fetch(o,n)}class Ao extends Error{constructor(e,t){super(e||t.serverMessage||`HTTP ${t.status}`),this.name="RestError",this.status=t.status,this.code=t.code,this.data=t.data,this.serverMessage=t.serverMessage??""}}function $o(o){const e=typeof o=="object"&&o!==null?o:void 0;return{code:typeof e?.code=="string"?e.code:void 0,data:e?.data,serverMessage:typeof e?.message=="string"?e.message:""}}function nt(o,e,t=""){return new Ao(t,{status:o,...$o(e)})}async function Ro(o,e=""){let t=null;try{t=await o.json()}catch{t=null}return nt(o.status,t,e)}const No="desktop-mode/games";function To(){const e=window.wp?.os?.config;return{restUrl:e?.restUrl||"/wp-json/",restNonce:e?.restNonce||""}}async function A(o,e={},t={}){const{restUrl:s,restNonce:n}=To(),i=new Headers(e.headers??{});i.set("X-WP-Nonce",n),e.body&&!i.has("Content-Type")&&i.set("Content-Type","application/json");const r=await st(tt(s,o),{...e,headers:i,credentials:"same-origin"},{source:No,windowId:t.windowId,silent:t.silent}),a=await r.json().catch(()=>null);if(!r.ok)throw nt(r.status,a);return a}function it(o,e={}){const t=new URLSearchParams({page:String(e.page??1),per_page:String(e.perPage??25),orderby:e.orderby??"score",order:e.order??"desc"});return e.userId&&t.set("user_id",String(e.userId)),A(`desktop-mode/v1/games/${o}/scores?${t}`)}function Lo(o,e,t={}){return A(`desktop-mode/v1/games/${o}/scores`,{method:"POST",body:JSON.stringify({score:e.score,meta:e.meta??{}})},t)}function zo(){return A("desktop-mode/v1/games/playtime")}function Io(o,e,t={}){return A(`desktop-mode/v1/games/${o}/playtime`,{method:"POST",body:JSON.stringify({seconds:e})},t)}function Mo(o={}){const e=new URLSearchParams({box:o.box??"all"});return o.state&&e.set("state",o.state),A(`desktop-mode/v1/games/challenges?${e}`)}function Po(o){return A("desktop-mode/v1/games/challenges",{method:"POST",body:JSON.stringify({game:o.game,recipient_id:o.recipientId,score:o.score,meta:o.meta??{}})})}function Ho(o){return A(`desktop-mode/v1/games/challenges/${o}/accept`,{method:"POST"})}function Fo(o){return A(`desktop-mode/v1/games/challenges/${o}/decline`,{method:"POST"})}function qo(o,e,t={}){return A(`desktop-mode/v1/games/challenges/${o}/complete`,{method:"POST",body:JSON.stringify({score:e.score,meta:e.meta??{}})},t)}const Do=6e4;function Oo(o,e={}){let t=Date.now(),s=0,n=!1;const i=()=>{if(t===null)return;const l=Date.now();s+=Math.max(0,l-t),t=l},r=()=>{i();const l=Math.floor(s/1e3);l<1||(s-=l*1e3,Io(o,l,{windowId:e.windowId,silent:!0}).catch(()=>{s+=l*1e3}))},a=setInterval(r,Do);return{pause:()=>{i(),t=null},resume:()=>{n||t!==null||(t=Date.now())},stop:()=>{n||(n=!0,clearInterval(a),i(),t=null,r())}}}function Uo(o,e,t){const s=new Date(`${e}T00:00:00Z`);if(isNaN(s.getTime())||t<1)return 0;const n=new Date(s.getTime()-(t-1)*864e5).toISOString().slice(0,10);let i=0;for(const[r,a]of Object.entries(o))r>=n&&r<=e&&(i+=Math.max(0,Math.floor(Number(a)||0)));return i}function rt(o){const e=Math.max(0,Math.floor(Number(o)||0)),t=Math.floor(e/3600),s=Math.floor(e%3600/60);return t>0?k(g("%1$dh %2$dm"),t,s):s>0?k(g("%dm"),s):k(g("%ds"),e)}const D=ve("desktop-mode/games-challenges",()=>({rows:new Map,version:0,listeners:new Set}));function ie(o){const e=D.state;let t=!1;for(const s of o){if(!s||typeof s.id!="number")continue;const n=e.rows.get(s.id);(!n||n.updatedAtMs!==s.updatedAtMs)&&(e.rows.set(s.id,s),t=!0),s.updatedAtMs>e.version&&(e.version=s.updatedAtMs)}t&&jo()}function Wo(o){return D.state.listeners.add(o),()=>{D.state.listeners.delete(o)}}function jo(){for(const o of Array.from(D.state.listeners))try{o()}catch(e){typeof console<"u"&&console.error("[openstation] challenges store listener threw:",e)}}function Go(){return Array.from(D.state.rows.values()).sort((o,e)=>e.updatedAtMs-o.updatedAtMs)}function at(){return window.wp?.os??{}}const Bo=760,Ko=560,Vo=480,Xo=380;function Yo(){const o=window.openStationConfig?.gameStyleHandles??[];for(const e of o)ko(e)}async function Zo(o){if(typeof o.render=="function")return o;const e=at().loadVendorScript;if(!o.scriptUrl||typeof e!="function")throw new Error(`[openstation] Game "${o.id}" has no render callback and no loadable script.`);await e(o.scriptUrl,{translations:o.scriptTranslations,deps:o.scriptDeps,l10n:o.scriptL10n,before:o.scriptBefore,after:o.scriptAfter});const s=window.openStationGames?.[o.id];if(!s||typeof s.render!="function")throw new Error(`[openstation] No game def on window.openStationGames["${o.id}"]. Script loaded but didn't publish a def — check the plugin's global assignment.`);const n={...o,render:s.render,window:s.window??o.window};return go(n),n}async function lt(o,e={}){const t=at(),s=ye(o);if(!s)throw new Error(`[openstation] Unknown game "${o}".`);if(Yo(),typeof t.registerWindow!="function")throw new Error("[openstation] wp.os.registerWindow is missing — the shell must boot before launching games.");const n=`os-game-${o}`,i=`game:${n}`,r=t.windowManager,a=r?.getByBaseId?.(n)??r?.getById(n);if(a){const h=a.config?.desktopId;h&&r?.switchDesktop&&h!==r?.getActiveDesktopId?.()&&r.switchDesktop(h),t.registerWindow({id:n,title:s.title,icon:s.icon,render:()=>{}});return}t.wallpaper?.suspend(i);let l=!1;const d=()=>{l||(l=!0,t.wallpaper?.resume(i))};let u=null;const c=()=>{u?.stop(),u=null};t.onWindow?.(n,{closed:()=>{c(),d()},minimized:()=>u?.pause(),restored:()=>u?.resume()});const f=(h,m)=>{t.activity?.publish("os/game-score-recorded",{game:o,score:h.score,meta:h.meta??{},windowId:n,challengeId:m})},p=h=>{if(e.challenge){const m=e.challenge.id;return qo(m,h,{windowId:n}).then(({challenge:b})=>{ie([b]),f(h,m)})}return Lo(o,h,{windowId:n}).then(()=>f(h))};try{await t.registerWindow({id:n,title:s.title,icon:s.icon,width:s.window?.width??Bo,height:s.window?.height??Ko,minWidth:s.window?.minWidth??Vo,minHeight:s.window?.minHeight??Xo,render:async h=>{const m=await Zo(s),b=m.render;if(typeof b!="function")throw new Error(`[openstation] Game "${o}" did not provide a render callback.`);const w={windowId:n,container:h,config:m.config??{},challenge:e.challenge,submitScore:p,close:()=>{t.windowManager?.getById(n)?.close()}};u=Oo(o,{windowId:n});const y=b(w);return()=>{try{y?.()}finally{c(),d()}}}})}catch(h){throw c(),d(),h}}function Jo(o){if(!o)return 214;let e=5381;for(let t=0;t<o.length;t++)e=Math.imul(e,33)+o.charCodeAt(t);return(e%360+360)%360}const Qo=_`:host{display:inline-flex;position:relative;width:var( --os-ui-avatar-size,32px );height:var( --os-ui-avatar-size,32px );flex:0 0 auto;vertical-align:middle;line-height:0;perspective:calc( var( --os-ui-avatar-size,32px ) * 8 );--os-ui-avatar-tilt-x:0deg;--os-ui-avatar-tilt-y:0deg;--os-ui-avatar-hover:0;--os-ui-avatar-glare-x:50%;--os-ui-avatar-glare-y:50%}:host( [ hidden ] ){display:none}.os-avatar__tile{position:relative;width:100%;height:100%;border-radius:50%;overflow:hidden;background:var( --os-window-bg,#f0f0f1 );color:var( --os-ui-fg-on-accent,#fff );display:flex;align-items:center;justify-content:center;font-weight:700;font-size:calc( var( --os-ui-avatar-size,32px ) * 0.48 );line-height:1;letter-spacing:0;font-feature-settings:'tnum' 1;user-select:none;transform-style:preserve-3d;transform:rotateX( var( --os-ui-avatar-tilt-x ) ) rotateY( var( --os-ui-avatar-tilt-y ) ) scale( calc( 1 + var( --os-ui-avatar-hover ) * 0.07 ) );transition:transform 220ms cubic-bezier( 0.2,0.8,0.2,1 ),box-shadow 220ms cubic-bezier( 0.2,0.8,0.2,1 );box-shadow:inset 0 0 0 1px rgba( 255,255,255,calc( 0.18 + 0.22 * var( --os-ui-avatar-hover ) ) ),inset 0 0 0 calc( 1px + var( --os-ui-avatar-hover ) * 1px ) rgba( 0,0,0,calc( 0.08 + 0.04 * var( --os-ui-avatar-hover ) ) ),0 calc( 1px + var( --os-ui-avatar-hover ) * 8px ) calc( 6px + var( --os-ui-avatar-hover ) * 18px ) rgba( 0,0,0,calc( 0.08 + 0.18 * var( --os-ui-avatar-hover ) ) )}.os-avatar__tile::after{content:'';position:absolute;inset:0;border-radius:50%;background:radial-gradient( circle at var( --os-ui-avatar-glare-x ) var( --os-ui-avatar-glare-y ),var( --os-ui-scrim,rgba( 255,255,255,0.55 ) ) 0%,var( --os-ui-hover,rgba( 255,255,255,0 ) ) 55% );opacity:var( --os-ui-avatar-hover );mix-blend-mode:overlay;pointer-events:none;transition:opacity 220ms cubic-bezier( 0.2,0.8,0.2,1 )}.os-avatar__tile::before{content:'';position:absolute;inset:calc( var( --os-ui-avatar-hover ) * -3px );border-radius:50%;background:radial-gradient( circle at var( --os-ui-avatar-glare-x ) var( --os-ui-avatar-glare-y ),color-mix( in srgb,var( --os-ui-avatar-halo,rgb( 99,102,241 ) ) calc( 35% * var( --os-ui-avatar-hover ) ),transparent ) 0%,transparent 70% );filter:blur( 4px );pointer-events:none;z-index:-1;transition:inset 220ms cubic-bezier( 0.2,0.8,0.2,1 ),background 220ms}.os-avatar__tile img{width:calc( 100% + 2px );height:calc( 100% + 2px );margin:-1px;object-fit:cover;display:block;transform:translateZ( 1px )}.os-avatar__dot{position:absolute;bottom:0;inset-inline-end:0;width:calc( var( --os-ui-avatar-size,32px ) * 0.32 );height:calc( var( --os-ui-avatar-size,32px ) * 0.32 );min-width:8px;min-height:8px;border-radius:50%;box-sizing:border-box;border:2px solid var( --os-ui-avatar-dot-ring,var( --os-window-bg,#fff ) );background:var( --os-ui-avatar-dot-color,transparent );z-index:2}.os-avatar__dot--online{background:var( --os-ui-success-fg,#00a32a )}.os-avatar__dot--online::after{content:'';position:absolute;inset:-2px;border-radius:50%;border:1px solid var( --os-ui-success-fg,#00a32a );animation:os-avatar-presence 6s var( --os-ui-ease-out,cubic-bezier( 0.22,0.9,0.28,1 ) ) infinite;pointer-events:none}@keyframes os-avatar-presence{0%{opacity:0.6;transform:scale( 1 )}20%{opacity:0;transform:scale( 2.2 )}100%{opacity:0;transform:scale( 2.2 )}}.os-avatar__dot--inactive{background:var( --os-ui-warning-fg,#dba617 )}.os-avatar__dot--offline{background:var( --os-ui-fg-muted,#8c8f94 )}@media ( prefers-reduced-motion:reduce ){.os-avatar__dot--online::after{animation:none;opacity:0.6}.os-avatar__tile{transform:none;transition:box-shadow 200ms}.os-avatar__tile::after,.os-avatar__tile::before{display:none}}`,ct={xs:20,sm:24,md:40,lg:64,xl:96},dt=new Set(["online","inactive","offline"]),G=class G extends E{constructor(){super(...arguments),this._presenceHandler=null,this._imgFailed=!1,this._onPointerMove=null,this._onPointerEnter=null,this._onPointerLeave=null,this._tiltRaf=0,this._pendingTiltX="0deg",this._pendingTiltY="0deg",this._pendingGlareX="50%",this._pendingGlareY="50%"}connectedCallback(){super.connectedCallback(),this._maybeAttachPresenceListener(),this._attachHoverEffect()}disconnectedCallback(){this._presenceHandler&&(document.removeEventListener("os-presence-changed",this._presenceHandler),this._presenceHandler=null),this._detachHoverEffect()}attributeChangedCallback(e,t,s){super.attributeChangedCallback(e,t,s),e==="src"&&(this._imgFailed=!1),(e==="user-id"||e==="presence")&&this._maybeAttachPresenceListener()}render(){const e=this._attr("src"),t=this._attr("name")||"",s=this._attr("alt"),n=s!==null?s:t,i=this._attr("size"),r=this._resolveSize(i),a=this._presenceForRender(),l=this._attr("clickable")!==null;this.style.setProperty("--os-ui-avatar-size",`${r}px`);const d=e&&!this._imgFailed?"":this._initialsBg(t),u=e&&!this._imgFailed?v`<img | |
| 30 | 41 | src=${e} |
| 31 | - alt=${r} | |
| 42 | + alt=${n} | |
| 32 | 43 | @error=${()=>this._onImgError()} |
| 33 | 44 | loading="lazy" |
| 34 | - />`:this._initials(t),c=a?w`<span | |
| 35 | - class=${`wpd-avatar__dot wpd-avatar__dot--${a}`} | |
| 45 | + />`:this._initials(t),c=a?v`<span | |
| 46 | + class=${`os-avatar__dot os-avatar__dot--${a}`} | |
| 36 | 47 | aria-label=${this._presenceLabel(a)} |
| 37 | - ></span>`:w``;return d?w` | |
| 48 | + ></span>`:v``;return l?v` | |
| 38 | 49 | <button |
| 39 | 50 | type="button" |
| 40 | - class="wpd-avatar__tile" | |
| 41 | - aria-label=${r||"User"} | |
| 42 | - style=${l?`background:${l};`:""} | |
| 51 | + class="os-avatar__tile" | |
| 52 | + aria-label=${n||"User"} | |
| 53 | + style=${d?`background:${d};`:""} | |
| 43 | 54 | @click=${f=>this._onClick(f)} |
| 44 | - >${p}</button> | |
| 55 | + >${u}</button> | |
| 45 | 56 | ${c} |
| 46 | - `:w` | |
| 57 | + `:v` | |
| 47 | 58 | <div |
| 48 | - class="wpd-avatar__tile" | |
| 59 | + class="os-avatar__tile" | |
| 49 | 60 | role="img" |
| 50 | - aria-label=${r||"User"} | |
| 51 | - style=${l?`background:${l};`:""} | |
| 52 | - >${p}</div> | |
| 61 | + aria-label=${n||"User"} | |
| 62 | + style=${d?`background:${d};`:""} | |
| 63 | + >${u}</div> | |
| 53 | 64 | ${c} |
| 54 | - `}_attr(e){return this.getAttribute(e)}_resolveSize(e){if(!e)return 32;if(e in Xe)return Xe[e];const t=Number(e);return Number.isFinite(t)&&t>0?t:32}_initials(e){const t=e.trim();return t?Array.from(t)[0]?.toUpperCase()??"?":"?"}_initialsBg(e){const t=gn(e);return`linear-gradient(135deg, hsl(${t} 62% 55%), hsl(${(t+24)%360} 58% 42%))`}_presenceForRender(){const e=this._attr("presence");return e&&Ye.has(e)?e:null}_presenceLabel(e){switch(e){case"online":return"Online";case"inactive":return"Inactive";case"offline":return"Offline"}}_onImgError(){this._imgFailed=!0,this.requestUpdate()}_onClick(e){const t=this._attr("user-id"),n={userId:t!==null&&Number(t)||null,originalEvent:e};this.emit("wpd-avatar-click",n)}_attachHoverEffect(){typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches||(this._onPointerEnter=()=>{this.style.setProperty("--wpd-avatar-hover","1")},this._onPointerLeave=()=>{this.style.setProperty("--wpd-avatar-hover","0"),this._pendingTiltX="0deg",this._pendingTiltY="0deg",this._pendingGlareX="50%",this._pendingGlareY="50%",this._flushTilt()},this._onPointerMove=t=>{const n=this.getBoundingClientRect();if(n.width===0||n.height===0)return;const r=(t.clientX-n.left)/n.width-.5,i=(t.clientY-n.top)/n.height-.5,o=14;this._pendingTiltY=`${(r*o).toFixed(2)}deg`,this._pendingTiltX=`${(-i*o).toFixed(2)}deg`;const a=Math.max(0,Math.min(100,(r+.5)*100)),d=Math.max(0,Math.min(100,(i+.5)*100));this._pendingGlareX=`${a.toFixed(1)}%`,this._pendingGlareY=`${d.toFixed(1)}%`,this._tiltRaf||(this._tiltRaf=requestAnimationFrame(()=>this._flushTilt()))},this.addEventListener("pointerenter",this._onPointerEnter),this.addEventListener("pointerleave",this._onPointerLeave),this.addEventListener("pointermove",this._onPointerMove))}_flushTilt(){this._tiltRaf=0,this.style.setProperty("--wpd-avatar-tilt-x",this._pendingTiltX),this.style.setProperty("--wpd-avatar-tilt-y",this._pendingTiltY),this.style.setProperty("--wpd-avatar-glare-x",this._pendingGlareX),this.style.setProperty("--wpd-avatar-glare-y",this._pendingGlareY)}_detachHoverEffect(){this._onPointerMove&&(this.removeEventListener("pointermove",this._onPointerMove),this._onPointerMove=null),this._onPointerEnter&&(this.removeEventListener("pointerenter",this._onPointerEnter),this._onPointerEnter=null),this._onPointerLeave&&(this.removeEventListener("pointerleave",this._onPointerLeave),this._onPointerLeave=null),this._tiltRaf&&(cancelAnimationFrame(this._tiltRaf),this._tiltRaf=0)}_maybeAttachPresenceListener(){const e=this._attr("user-id"),t=this._attr("presence"),n=!!e&&!t;n&&!this._presenceHandler?(this._presenceHandler=r=>{const i=r.detail;i&&String(i.userId)===String(e)&&i.newStatus&&Ye.has(i.newStatus)&&this.setAttribute("presence",i.newStatus)},document.addEventListener("desktop-mode-presence-changed",this._presenceHandler)):!n&&this._presenceHandler&&(document.removeEventListener("desktop-mode-presence-changed",this._presenceHandler),this._presenceHandler=null)}};G.props=["src","alt","name","size","presence","userId","clickable"],G.styles=[wn],G.help=void 0;let fe=G;E("wpd-avatar",fe);const _n=$`:host{display:none;position:fixed;inset:0;align-items:center;justify-content:center;background:var( --wpd-scrim,rgba( 0,0,0,0.45 ) );background-image:var( --wpd-scrim-image,none );background-repeat:var( --wpd-scrim-image-repeat,repeat );background-size:var( --wpd-scrim-image-size,auto );background-position:var( --wpd-scrim-image-position,center );backdrop-filter:blur( 2px );z-index:10000;--wpd-fg:#f0f0f1;--wpd-fg-muted:#bbc1c7;--wpd-fg-muted:#a7aaad;--wpd-fg-muted:#a7aaad;--wpd-border:rgba( 255,255,255,0.25 );--desktop-mode-window-bg:#2c3338;--wpd-button-bg-hover:rgba( 255,255,255,0.08 )}:host( [ open ] ){display:flex}.dialog{max-width:92vw;max-height:90vh;background-color:var( --wpd-modal-bg,#1d2327 );background-image:var( --wpd-dialog-bg-image,none );background-repeat:var( --wpd-dialog-bg-image-repeat,repeat );background-size:var( --wpd-dialog-bg-image-size,auto );background-position:var( --wpd-dialog-bg-image-position,center );color:var( --wpd-modal-fg,var( --desktop-mode-fg,#fff ) );border:1px solid var( --wpd-border,rgba( 255,255,255,0.08 ) );border-radius:10px;box-shadow:0 20px 50px rgba( 0,0,0,0.6 );display:flex;flex-direction:column;overflow:hidden}:host( [ size='sm' ] ) .dialog{width:min( 360px,92vw )}:host(:not( [ size ] ) ) .dialog,:host( [ size='md' ] ) .dialog{width:min( 540px,92vw )}:host( [ size='lg' ] ) .dialog{width:min( 760px,94vw )}.header{display:flex;align-items:center;gap:10px;padding:16px 20px 12px;border-bottom:1px solid var( --wpd-border,rgba( 255,255,255,0.06 ) )}.title{margin:0;flex:1;font-size:15px;font-weight:600}.header-actions{display:flex;gap:6px}.header-actions::slotted( * ){margin-inline-start:6px}.close{background:transparent;border:0;color:inherit;font-size:18px;line-height:1;padding:4px 8px;border-radius:4px;cursor:pointer;opacity:0.7}.close:hover{opacity:1;background:var( --wpd-hover,rgba( 255,255,255,0.08 ) )}.body{padding:16px 20px;overflow:auto;flex:1 1 auto;font-size:13px;line-height:1.5}.footer{padding:12px 20px 16px;border-top:1px solid var( --wpd-border,rgba( 255,255,255,0.06 ) )}.footer slot{display:flex;justify-content:flex-end;gap:10px;flex-wrap:wrap}:host( [ mandatory ] ) .close{display:none}`,Ze='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',j=class j extends S{constructor(){super(...arguments),this._prevFocus=null,this._onKey=e=>{if(e.key==="Escape"&&!this.hasAttribute("mandatory")){e.preventDefault(),this._cancel();return}if(e.key==="Tab"){const t=this._focusables();if(t.length===0)return;const n=t[0],r=t[t.length-1],i=this.ownerDocument,o=i?i.activeElement:null,a=e.composedPath()[0]||o;e.shiftKey&&a===n?(e.preventDefault(),r.focus()):!e.shiftKey&&a===r&&(e.preventDefault(),n.focus())}},this._onBackdrop=e=>{if(this.hasAttribute("mandatory"))return;const t=e.composedPath();(t.length>0?t[0]:e.target)===this&&this._cancel()}}connectedCallback(){super.connectedCallback(),this.setAttribute("role","dialog"),this.setAttribute("aria-modal","true"),this.addEventListener("keydown",this._onKey),this.addEventListener("click",this._onBackdrop)}disconnectedCallback(){this.removeEventListener("keydown",this._onKey),this.removeEventListener("click",this._onBackdrop)}attributeChangedCallback(e,t,n){if(super.attributeChangedCallback?.(e,t,n),e==="open"){if(n!==null){const r=this.ownerDocument;this._prevFocus=r?r.activeElement:null,queueMicrotask(()=>this._focusFirst())}else if(this._prevFocus){try{this._prevFocus.focus()}catch{}this._prevFocus=null}}}showModal(){this.setAttribute("open","")}hideModal(){this.removeAttribute("open")}_focusables(){const e=this.shadowRoot;if(!e)return[];const t=Array.from(this.querySelectorAll(Ze)),n=Array.from(e.querySelectorAll(Ze));return[...t,...n].filter(r=>r.offsetParent!==null||r.tagName==="BUTTON")}_focusFirst(){const e=this._focusables();e.length>0?e[0].focus():this.shadowRoot?.querySelector(".dialog")?.focus?.()}_cancel(){const e=new CustomEvent("wpd-modal-cancel",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(e)&&this.hideModal()}render(){const e=this.getAttribute("title")??"",t=this.hasAttribute("mandatory");return w` | |
| 55 | - <div class="dialog" tabindex="-1"> | |
| 56 | - ${e?w` | |
| 65 | + `}_attr(e){return this.getAttribute(e)}_resolveSize(e){if(!e)return 32;if(e in ct)return ct[e];const t=Number(e);return Number.isFinite(t)&&t>0?t:32}_initials(e){const t=e.trim();return t?Array.from(t)[0]?.toUpperCase()??"?":"?"}_initialsBg(e){const t=Jo(e);return`linear-gradient(135deg, hsl(${t} 62% 55%), hsl(${(t+24)%360} 58% 42%))`}_presenceForRender(){const e=this._attr("presence");return e&&dt.has(e)?e:null}_presenceLabel(e){switch(e){case"online":return"Online";case"inactive":return"Inactive";case"offline":return"Offline"}}_onImgError(){this._imgFailed=!0,this.requestUpdate()}_onClick(e){const t=this._attr("user-id"),s={userId:t!==null&&Number(t)||null,originalEvent:e};this.emit("os-avatar-click",s)}_attachHoverEffect(){typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches||(this._onPointerEnter=()=>{this.style.setProperty("--os-ui-avatar-hover","1")},this._onPointerLeave=()=>{this.style.setProperty("--os-ui-avatar-hover","0"),this._pendingTiltX="0deg",this._pendingTiltY="0deg",this._pendingGlareX="50%",this._pendingGlareY="50%",this._flushTilt()},this._onPointerMove=t=>{const s=this.getBoundingClientRect();if(s.width===0||s.height===0)return;const n=(t.clientX-s.left)/s.width-.5,i=(t.clientY-s.top)/s.height-.5,r=14;this._pendingTiltY=`${(n*r).toFixed(2)}deg`,this._pendingTiltX=`${(-i*r).toFixed(2)}deg`;const a=Math.max(0,Math.min(100,(n+.5)*100)),l=Math.max(0,Math.min(100,(i+.5)*100));this._pendingGlareX=`${a.toFixed(1)}%`,this._pendingGlareY=`${l.toFixed(1)}%`,this._tiltRaf||(this._tiltRaf=requestAnimationFrame(()=>this._flushTilt()))},this.addEventListener("pointerenter",this._onPointerEnter),this.addEventListener("pointerleave",this._onPointerLeave),this.addEventListener("pointermove",this._onPointerMove))}_flushTilt(){this._tiltRaf=0,this.style.setProperty("--os-ui-avatar-tilt-x",this._pendingTiltX),this.style.setProperty("--os-ui-avatar-tilt-y",this._pendingTiltY),this.style.setProperty("--os-ui-avatar-glare-x",this._pendingGlareX),this.style.setProperty("--os-ui-avatar-glare-y",this._pendingGlareY)}_detachHoverEffect(){this._onPointerMove&&(this.removeEventListener("pointermove",this._onPointerMove),this._onPointerMove=null),this._onPointerEnter&&(this.removeEventListener("pointerenter",this._onPointerEnter),this._onPointerEnter=null),this._onPointerLeave&&(this.removeEventListener("pointerleave",this._onPointerLeave),this._onPointerLeave=null),this._tiltRaf&&(cancelAnimationFrame(this._tiltRaf),this._tiltRaf=0)}_maybeAttachPresenceListener(){const e=this._attr("user-id"),t=this._attr("presence"),s=!!e&&!t;s&&!this._presenceHandler?(this._presenceHandler=n=>{const i=n.detail;i&&String(i.userId)===String(e)&&i.newStatus&&dt.has(i.newStatus)&&this.setAttribute("presence",i.newStatus)},document.addEventListener("os-presence-changed",this._presenceHandler)):!s&&this._presenceHandler&&(document.removeEventListener("os-presence-changed",this._presenceHandler),this._presenceHandler=null)}};G.props=["src","alt","name","size","presence","userId","clickable"],G.styles=[Qo],G.help=void 0;let ke=G;R("os-avatar",ke);const es=_` ${Q}:host{display:none;position:fixed;inset:0;align-items:center;justify-content:center;background:var( --os-ui-scrim,rgba( 0,0,0,0.45 ) );background-image:var( --os-ui-scrim-image,none );background-repeat:var( --os-ui-scrim-image-repeat,repeat );background-size:var( --os-ui-scrim-image-size,auto );background-position:var( --os-ui-scrim-image-position,center );backdrop-filter:blur( 2px );z-index:10000;--os-ui-fg:var( --os-ui-modal-text,#f0f0f1 );--os-ui-fg-muted:var( --os-ui-modal-text-muted,#a7aaad );--os-ui-border:var( --os-ui-modal-border,rgba( 255,255,255,0.25 ) );--os-window-bg:var( --os-ui-modal-field-bg,#2c3338 );--os-ui-button-bg-hover:var( --os-ui-modal-button-bg-hover,rgba( 255,255,255,0.08 ) );--os-ui-surface:var( --os-ui-modal-surface,#2c3338 );--os-ui-surface-elevated:var( --os-ui-modal-surface-elevated,#3c434a );--os-ui-border-strong:var( --os-ui-modal-border-strong,rgba( 255,255,255,0.35 ) );--os-ui-hover:var( --os-ui-modal-hover,rgba( 255,255,255,0.08 ) );--os-ui-notice-color:var( --os-ui-modal-text,#f0f0f1 );--os-ui-card-bg:var( --os-ui-modal-surface,#2c3338 );--os-ui-card-fg:var( --os-ui-modal-text,#f0f0f1 );--os-ui-card-border:var( --os-ui-modal-border,rgba( 255,255,255,0.25 ) );--os-ui-card-border-hover:var( --os-ui-modal-border-strong,rgba( 255,255,255,0.35 ) )}:host( [ open ] ){display:flex;animation:os-modal-scrim var( --_holo-t ) var( --_holo-ease )}:host( [ open ] ) .dialog{animation:os-modal-dialog var( --_holo-t ) var( --_holo-spring )}@keyframes os-modal-scrim{from{opacity:0}}@keyframes os-modal-dialog{from{opacity:0;transform:scale( 0.96 ) translateY( 8px )}}@media ( prefers-reduced-motion:reduce ){:host( [ open ] ),:host( [ open ] ) .dialog{animation:none}}.dialog{max-width:92vw;max-height:90vh;background-color:var( --os-ui-modal-bg,#1d2327 );background-image:var( --os-ui-dialog-bg-image,none );background-repeat:var( --os-ui-dialog-bg-image-repeat,repeat );background-size:var( --os-ui-dialog-bg-image-size,auto );background-position:var( --os-ui-dialog-bg-image-position,center );color:var( --os-ui-modal-fg,var( --os-fg,#fff ) );border:1px solid var( --os-ui-border,rgba( 255,255,255,0.08 ) );border-radius:10px;box-shadow:0 20px 50px rgba( 0,0,0,0.6 );display:flex;flex-direction:column;overflow:hidden}:host( [ size='sm' ] ) .dialog{width:min( 360px,92vw )}:host(:not( [ size ] ) ) .dialog,:host( [ size='md' ] ) .dialog{width:min( 540px,92vw )}:host( [ size='lg' ] ) .dialog{width:min( 760px,94vw )}.header{display:flex;align-items:center;gap:10px;padding:16px 20px 12px;border-bottom:1px solid var( --os-ui-border,rgba( 255,255,255,0.06 ) )}.title{margin:0;flex:1;font-size:15px;font-weight:600}.header-actions{display:flex;gap:6px}.header-actions::slotted( * ){margin-inline-start:6px}.close{background:transparent;border:0;color:inherit;font-size:18px;line-height:1;padding:4px 8px;border-radius:4px;cursor:pointer;opacity:0.7}.close:hover{opacity:1;background:var( --os-ui-hover,rgba( 255,255,255,0.08 ) )}.body{padding:16px 20px;overflow:auto;flex:1 1 auto;font-size:13px;line-height:1.5}.footer{padding:12px 20px 16px;border-top:1px solid var( --os-ui-border,rgba( 255,255,255,0.06 ) )}.footer slot{display:flex;justify-content:flex-end;gap:10px;flex-wrap:wrap}:host( [ mandatory ] ) .close{display:none}`,ut='a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])',B=class B extends E{constructor(){super(...arguments),this._prevFocus=null,this._onKey=e=>{if(e.key==="Escape"&&!this.hasAttribute("mandatory")){e.preventDefault(),this._cancel();return}if(e.key==="Tab"){const t=this._focusables();if(t.length===0)return;const s=t[0],n=t[t.length-1],i=this.ownerDocument,r=i?i.activeElement:null,a=e.composedPath()[0]||r;e.shiftKey&&a===s?(e.preventDefault(),n.focus()):!e.shiftKey&&a===n&&(e.preventDefault(),s.focus())}},this._onBackdrop=e=>{if(this.hasAttribute("mandatory"))return;const t=e.composedPath();(t.length>0?t[0]:e.target)===this&&this._cancel()}}connectedCallback(){super.connectedCallback(),this.setAttribute("role","dialog"),this.setAttribute("aria-modal","true"),this.addEventListener("keydown",this._onKey),this.addEventListener("click",this._onBackdrop)}disconnectedCallback(){this.removeEventListener("keydown",this._onKey),this.removeEventListener("click",this._onBackdrop)}attributeChangedCallback(e,t,s){if(super.attributeChangedCallback?.(e,t,s),e==="open"){if(s!==null){const n=this.ownerDocument;this._prevFocus=n?n.activeElement:null,queueMicrotask(()=>this._focusFirst())}else if(this._prevFocus){try{this._prevFocus.focus()}catch{}this._prevFocus=null}}}showModal(){this.setAttribute("open","")}hideModal(){this.removeAttribute("open")}_focusables(){const e=this.shadowRoot;if(!e)return[];const t=Array.from(this.querySelectorAll(ut)),s=Array.from(e.querySelectorAll(ut));return[...t,...s].filter(n=>n.offsetParent!==null||n.tagName==="BUTTON")}_focusFirst(){const e=this._focusables();e.length>0?e[0].focus():this.shadowRoot?.querySelector(".dialog")?.focus?.()}_cancel(){const e=new CustomEvent("os-modal-cancel",{bubbles:!0,cancelable:!0,composed:!0});this.dispatchEvent(e)&&this.hideModal()}render(){const e=this.getAttribute("title")??"",t=this.hasAttribute("mandatory");return v` | |
| 66 | + <div part="dialog" class="dialog" tabindex="-1"> | |
| 67 | + ${e?v` | |
| 57 | 68 | <div class="header"> |
| 58 | 69 | <h2 class="title">${e}</h2> |
| 59 | 70 | <div class="header-actions"> |
| 60 | 71 | <slot name="header-actions"></slot> |
| 61 | - ${t?w``:w`<button | |
| 72 | + ${t?v``:v`<button | |
| 62 | 73 | type="button" |
| 63 | 74 | class="close" |
| 64 | 75 | aria-label="Close" |
| 65 | 76 | @click=${()=>this._cancel()} |
| @@ -65,9 +76,9 @@ | ||
| 65 | 76 | @click=${()=>this._cancel()} |
| 66 | 77 | >×</button>`} |
| 67 | 78 | </div> |
| 68 | 79 | </div> |
| 69 | - `:w``} | |
| 80 | + `:v``} | |
| 70 | 81 | <div class="body"> |
| 71 | 82 | <slot></slot> |
| 72 | 83 | </div> |
| 73 | 84 | <div class="footer"> |
| @@ -73,9 +84,9 @@ | ||
| 73 | 84 | <div class="footer"> |
| 74 | 85 | <slot name="footer"></slot> |
| 75 | 86 | </div> |
| 76 | 87 | </div> |
| 77 | - `}};j.props=["open","title","size","mandatory"],j.styles=[_n],j.help=void 0;let me=j;E("wpd-modal",me);const vn=$`:host{display:block;position:relative;font-size:13px}.input{width:100%;padding:8px 10px;background:var( --wpd-input-bg,var( --wpd-hover,rgba( 255,255,255,0.06 ) ) );color:inherit;border:1px solid var( --wpd-border,rgba( 255,255,255,0.12 ) );border-radius:6px;font:inherit;box-sizing:border-box}.input:focus{outline:2px solid var( --wp-admin-theme-color,#2271b1 );outline-offset:-1px}.dropdown{background:var( --desktop-mode-bg,#1d2327 );color:var( --desktop-mode-fg,#fff );border:1px solid var( --wpd-border,rgba( 255,255,255,0.18 ) );border-radius:6px;overflow:auto;z-index:11000;box-shadow:0 12px 32px rgba( 0,0,0,0.5 )}.empty.error{color:#ff8080}.item{display:flex;align-items:center;gap:10px;padding:8px 10px;cursor:pointer;border:0;background:transparent;color:inherit;width:100%;text-align:start;font:inherit}.item:hover,.item:focus{background:var( --wpd-hover,rgba( 255,255,255,0.06 ) );outline:none}.avatar{width:24px;height:24px;border-radius:50%;flex:0 0 auto;background:var( --wpd-hover,rgba( 255,255,255,0.1 ) )}.name{font-weight:500}.slug{opacity:0.6;font-size:12px}.empty{padding:12px;color:var( --wpd-fg-muted,rgba( 255,255,255,0.5 ) );font-size:12px}`,B=class B extends S{constructor(){super(...arguments),this._timer=null,this._abort=null,this._results=[],this._query="",this._open=!1,this._phase="idle",this._error="",this._dropdownStyle="",this._onScrollOrResize=()=>{},this._onInput=e=>{const t=e.target.value;this._query=t,this._scheduleSearch(t)},this._onFocus=()=>{if(this._results.length===0&&this._phase==="idle"){this._scheduleSearch(this._query);return}this._open=!0,this._positionDropdown(),this.requestUpdate()},this._onBlur=()=>{setTimeout(()=>{this._open=!1,this.requestUpdate()},150)},this._pick=e=>{this.emit("wpd-user-pick",{user:e}),this._results=[],this._open=!1,this._phase="idle",this._query="";const t=this.shadowRoot?.querySelector(".input");t&&(t.value=""),this.requestUpdate()}}connectedCallback(){super.connectedCallback(),this._onScrollOrResize=()=>{this._open&&(this._positionDropdown(),this.requestUpdate())},window.addEventListener("resize",this._onScrollOrResize),window.addEventListener("scroll",this._onScrollOrResize,!0)}disconnectedCallback(){this._timer&&clearTimeout(this._timer),this._abort&&this._abort.abort(),window.removeEventListener("resize",this._onScrollOrResize),window.removeEventListener("scroll",this._onScrollOrResize,!0)}_endpoint(){const e=this.getAttribute("endpoint");return e||window.desktopModeConfig?.filesUsersSearchUrl||""}_scheduleSearch(e){this._timer&&clearTimeout(this._timer),this._phase="loading",this._open=!0,this._positionDropdown(),this.requestUpdate(),this._timer=setTimeout(()=>this._runSearch(e),200)}async _runSearch(e){const t=this._endpoint();if(!t){this._phase="error",this._error="Search endpoint is not configured.",this._results=[],this._open=!0,this.requestUpdate();return}this._abort&&this._abort.abort();const n=new AbortController;this._abort=n;const r=this.getAttribute("exclude")||"",i=t+"?q="+encodeURIComponent(e)+"&exclude="+encodeURIComponent(r);try{const o={signal:n.signal,credentials:"same-origin"},a=await je(i,o,{source:"desktop-mode/files-user-search",silent:!0});if(!a.ok)throw new Error(`HTTP ${a.status}`);const d=await a.json();this._results=d&&Array.isArray(d.users)?d.users:[],this._phase="ready",this._error="",this._open=!0}catch(o){if(o.name==="AbortError")return;this._results=[],this._phase="error",this._error=o.message||"Search failed.",this._open=!0}this._positionDropdown(),this.requestUpdate()}_positionDropdown(){const e=this.shadowRoot?.querySelector(".input");if(!e)return;const t=e.getBoundingClientRect(),n=t.bottom+4,r=t.left,i=t.width,a=window.innerHeight-t.bottom,d=t.top,l=Math.max(120,Math.min(280,Math.max(a,d)-16));a<200&&d>a?this._dropdownStyle=["position:fixed",`left:${r}px`,`top:${t.top-4-l}px`,`width:${i}px`,`max-height:${l}px`].join(";"):this._dropdownStyle=["position:fixed",`left:${r}px`,`top:${n}px`,`width:${i}px`,`max-height:${l}px`].join(";")}_dropdownContent(){if(this._phase==="loading")return w`<div class="empty">Searching…</div>`;if(this._phase==="error")return w`<div class="empty error">${this._error}</div>`;if(this._results.length===0){const e=this._query?"No matches.":"No users available.";return w`<div class="empty">${e}</div>`}return this._results.map(e=>w` | |
| 88 | + `}};B.props=["open","title","size","mandatory"],B.styles=[es],B.help=void 0;let xe=B;R("os-modal",xe);const ts=_`:host{display:block;position:relative;font-size:13px}.input{width:100%;padding:8px 10px;background:var( --os-ui-input-bg,var( --os-ui-hover,rgba( 255,255,255,0.06 ) ) );color:inherit;border:1px solid var( --os-ui-border,rgba( 255,255,255,0.12 ) );border-radius:6px;font:inherit;box-sizing:border-box}.input:focus{outline:none;border-color:var( --os-ui-accent,#2271b1 );box-shadow:var( --os-ui-focus-ring-field,0 0 0 1px #2271b1,0 0 0 4px rgba( 34,113,177,0.18 ) )}.dropdown{background:var( --os-bg,#1d2327 );color:var( --os-fg,#fff );border:1px solid var( --os-ui-border,rgba( 255,255,255,0.18 ) );border-radius:6px;overflow:auto;z-index:11000;box-shadow:0 12px 32px rgba( 0,0,0,0.5 )}.empty.error{color:var( --os-ui-danger-hover,#ff8080 )}.item{display:flex;align-items:center;gap:10px;padding:8px 10px;cursor:pointer;border:0;background:transparent;color:inherit;width:100%;text-align:start;font:inherit}.item:hover,.item:focus{background:var( --os-ui-hover,rgba( 255,255,255,0.06 ) );outline:none}.avatar{width:24px;height:24px;border-radius:50%;flex:0 0 auto;background:var( --os-ui-hover,rgba( 255,255,255,0.1 ) )}.name{font-weight:500}.slug{opacity:0.6;font-size:12px}.empty{padding:12px;color:var( --os-ui-fg-muted,rgba( 255,255,255,0.5 ) );font-size:12px}`,K=class K extends E{constructor(){super(...arguments),this._timer=null,this._abort=null,this._results=[],this._query="",this._open=!1,this._phase="idle",this._error="",this._dropdownStyle="",this._onScrollOrResize=()=>{},this._onInput=e=>{const t=e.target.value;this._query=t,this._scheduleSearch(t)},this._onFocus=()=>{if(this._results.length===0&&this._phase==="idle"){this._scheduleSearch(this._query);return}this._open=!0,this._positionDropdown(),this.requestUpdate()},this._onBlur=()=>{setTimeout(()=>{this._open=!1,this.requestUpdate()},150)},this._pick=e=>{this.emit("os-user-pick",{user:e}),this._results=[],this._open=!1,this._phase="idle",this._query="";const t=this.shadowRoot?.querySelector(".input");t&&(t.value=""),this.requestUpdate()}}connectedCallback(){super.connectedCallback(),this._onScrollOrResize=()=>{this._open&&(this._positionDropdown(),this.requestUpdate())},window.addEventListener("resize",this._onScrollOrResize),window.addEventListener("scroll",this._onScrollOrResize,!0)}disconnectedCallback(){this._timer&&clearTimeout(this._timer),this._abort&&this._abort.abort(),window.removeEventListener("resize",this._onScrollOrResize),window.removeEventListener("scroll",this._onScrollOrResize,!0)}_endpoint(){const e=this.getAttribute("endpoint");return e||window.openStationConfig?.filesUsersSearchUrl||""}_scheduleSearch(e){this._timer&&clearTimeout(this._timer),this._phase="loading",this._open=!0,this._positionDropdown(),this.requestUpdate(),this._timer=setTimeout(()=>this._runSearch(e),200)}async _runSearch(e){const t=this._endpoint();if(!t){this._phase="error",this._error="Search endpoint is not configured.",this._results=[],this._open=!0,this.requestUpdate();return}this._abort&&this._abort.abort();const s=new AbortController;this._abort=s;const n=this.getAttribute("exclude")||"",i=t+"?q="+encodeURIComponent(e)+"&exclude="+encodeURIComponent(n);try{const r={signal:s.signal,credentials:"same-origin"},a=await st(i,r,{source:"desktop-mode/files-user-search",silent:!0});if(!a.ok)throw await Ro(a);const l=await a.json();this._results=l&&Array.isArray(l.users)?l.users:[],this._phase="ready",this._error="",this._open=!0}catch(r){if(r.name==="AbortError")return;this._results=[],this._phase="error",this._error=r.message||"Search failed.",this._open=!0}this._positionDropdown(),this.requestUpdate()}_positionDropdown(){const e=this.shadowRoot?.querySelector(".input");if(!e)return;const t=e.getBoundingClientRect(),s=t.bottom+4,n=t.left,i=t.width,a=window.innerHeight-t.bottom,l=t.top,d=Math.max(120,Math.min(280,Math.max(a,l)-16));a<200&&l>a?this._dropdownStyle=["position:fixed",`left:${n}px`,`top:${t.top-4-d}px`,`width:${i}px`,`max-height:${d}px`].join(";"):this._dropdownStyle=["position:fixed",`left:${n}px`,`top:${s}px`,`width:${i}px`,`max-height:${d}px`].join(";")}_dropdownContent(){if(this._phase==="loading")return v`<div class="empty">Searching…</div>`;if(this._phase==="error")return v`<div class="empty error">${this._error}</div>`;if(this._results.length===0){const e=this._query?"No matches.":"No users available.";return v`<div class="empty">${e}</div>`}return this._results.map(e=>v` | |
| 78 | 89 | <button |
| 79 | 90 | type="button" |
| 80 | 91 | class="item" |
| 81 | 92 | role="option" |
| @@ -87,9 +98,9 @@ | ||
| 87 | 98 | <div class="name">${e.name}</div> |
| 88 | 99 | <div class="slug">${e.slug}</div> |
| 89 | 100 | </div> |
| 90 | 101 | </button> |
| 91 | - `)}render(){const e=this.getAttribute("placeholder")||"Search users…";return w` | |
| 102 | + `)}render(){const e=this.getAttribute("placeholder")||"Search users…";return v` | |
| 92 | 103 | <input |
| 93 | 104 | class="input" |
| 94 | 105 | type="search" |
| 95 | 106 | placeholder=${e} |
| @@ -98,16 +109,16 @@ | ||
| 98 | 109 | @focus=${this._onFocus} |
| 99 | 110 | @blur=${this._onBlur} |
| 100 | 111 | .value=${this._query} |
| 101 | 112 | /> |
| 102 | - ${this._open?w` | |
| 113 | + ${this._open?v` | |
| 103 | 114 | <div class="dropdown" role="listbox" style=${this._dropdownStyle}> |
| 104 | 115 | ${this._dropdownContent()} |
| 105 | 116 | </div> |
| 106 | - `:w``} | |
| 107 | - `}};B.props=["placeholder","exclude","endpoint"],B.styles=[vn],B.help=void 0;let be=B;E("wpd-user-search",be);function yn(){const e=window.desktopModeGamesConfig?.usersSearchUrl;if(e)return e;const n=window.wp?.desktop?.config?.restUrl||"/wp-json/";return Ue(n,"desktop-mode/v1/games/users/search")}function Je(s){return new Promise(e=>{const t=document.createElement("wpd-modal");t.setAttribute("open",""),t.setAttribute("title",b("Send a challenge")),t.setAttribute("size","sm");const n=document.createElement("div");n.className="desktop-mode-games__challenge-dialog";const r=document.createElement("p");r.className="desktop-mode-games__challenge-summary",r.textContent=v(b("Challenge someone to beat your %1$s score of %2$s."),s.gameTitle,String(s.score)),n.appendChild(r);const i=document.createElement("wpd-user-search");i.setAttribute("placeholder",b("Find a player…")),i.setAttribute("endpoint",yn()),n.appendChild(i);const o=document.createElement("div");o.className="desktop-mode-games__challenge-picked",o.hidden=!0,n.appendChild(o),t.appendChild(n);const a=document.createElement("div");a.setAttribute("slot","footer"),a.className="desktop-mode-games__challenge-footer";const d=document.createElement("wpd-button");d.setAttribute("variant","ghost"),d.textContent=b("Cancel");const l=document.createElement("wpd-button");l.setAttribute("variant","primary"),l.setAttribute("disabled",""),l.textContent=b("Send challenge"),a.append(d,l),t.appendChild(a);let p=null,c=!1;const f=()=>{t.remove(),e()},h=()=>{if(o.innerHTML="",!p){o.hidden=!0,l.setAttribute("disabled","");return}o.hidden=!1;const u=document.createElement("wpd-avatar");u.setAttribute("src",p.avatarUrl),u.setAttribute("name",p.name),u.setAttribute("size","sm"),u.setAttribute("user-id",String(p.id)),o.appendChild(u);const m=document.createElement("span");m.textContent=p.name,o.appendChild(m),l.removeAttribute("disabled")};i.addEventListener("wpd-user-pick",u=>{const m=u.detail?.user;m&&(p=m,h())}),d.addEventListener("click",f),t.addEventListener("wpd-modal-cancel",f),l.addEventListener("click",()=>{!p||c||(c=!0,l.setAttribute("disabled",""),rn({game:s.game,recipientId:p.id,score:s.score,meta:s.meta}).then(()=>{z({message:v(b("Challenge sent to %s."),p.name)}),f()}).catch(u=>{c=!1,l.removeAttribute("disabled"),z({message:u instanceof Error?u.message:b("Could not send the challenge.")})}))}),document.body.appendChild(t)})}const kn=$`:host{display:inline;color:inherit;font:inherit}`,te=new Set;let M=null;const xn=3e4;function Cn(){M===null&&(M=window.setInterval(()=>{for(const s of te)s.tick()},xn))}function Sn(){M!==null&&te.size===0&&(window.clearInterval(M),M=null)}function An(s){if(!s)return null;const e=t=>{const n=new Date(t);return Number.isNaN(n.getTime())?null:n};return En(s)?e(s):e(s.replace(" ","T")+"Z")}function En(s){const e=Math.max(s.indexOf("T"),s.indexOf(" ")),t=e===-1?"":s.slice(e+1);return/(?:[Zz]|[+-]\d{2}:?\d{2})$/.test(t)}let ge=null,we=null;function Qe(){return typeof navigator<"u"&&navigator.language||"en"}function $n(){return ge||(ge=new Intl.RelativeTimeFormat(Qe(),{numeric:"auto"})),ge}function et(){return we||(we=new Intl.RelativeTimeFormat(Qe(),{numeric:"always",style:"narrow"})),we}function Rn(s,e){const t=$n(),n=s.getTime()-e,r=Math.round(n/1e3),i=Math.abs;return i(r)<45?t.format(0,"second"):tt(t,r)}function tt(s,e){const t=Math.abs,n=Math.round(e/60);if(t(n)<45)return s.format(n,"minute");const r=Math.round(n/60);if(t(r)<22)return s.format(r,"hour");const i=Math.round(r/24);if(t(i)<26)return s.format(i,"day");const o=Math.round(i/30);if(t(o)<11)return s.format(o,"month");const a=Math.round(i/365);return s.format(a,"year")}function Nn(s,e){const t=Math.round((s.getTime()-e)/1e3),n=Math.abs;return n(t)<45?et().format(0,"second"):n(t)>7*24*60*60?s.toLocaleDateString(void 0,{month:"short",day:"numeric"}):tt(et(),t)}const W=class W extends S{connectedCallback(){super.connectedCallback(),te.add(this),Cn()}disconnectedCallback(){te.delete(this),Sn()}tick(){this.requestUpdate()}render(){const e=this.datetime,t=An(e);if(!t)return w`<span>${e??""}</span>`;const n=Date.now(),r=this.hasAttribute("compact")?Nn(t,n):Rn(t,n),i=t.toLocaleString();return w`<time datetime=${t.toISOString()} title=${i} | |
| 108 | - >${r}</time | |
| 109 | - >`}};W.props=["datetime","compact"],W.styles=[kn],W.help=void 0;let _e=W;E("wpd-relative-time",_e);const Tn=$`:host{display:block;--wpd-table-bg:var( --wpd-surface,#fff );--wpd-table-border:var( --wpd-border,rgba( 0,0,0,0.08 ) );--wpd-table-column-border:var( --wpd-border-strong,rgba( 0,0,0,0.14 ) );--wpd-table-header-bg:var( --wpd-surface-elevated,#f6f7f7 );--wpd-table-row-hover:rgba( 0,0,0,0.04 );--wpd-table-stripe:rgba( 0,0,0,0.03 );--wpd-table-cell-padding:8px 12px;--wpd-table-font-size:13px;--wpd-table-max-height:none;font-size:var( --wpd-table-font-size );color:inherit}:host( [ hidden ] ){display:none}.scroll{position:relative;overflow:auto;max-height:var( --wpd-table-max-height );border:1px solid var( --wpd-table-border );border-radius:4px;background:var( --wpd-table-bg )}table{width:100%;border-collapse:separate;border-spacing:0;background:var( --wpd-table-bg )}thead th{text-align:start;font-weight:600;background-color:var( --wpd-table-header-bg );background-image:var( --wpd-table-header-bg-image,none );background-repeat:var( --wpd-table-header-bg-image-repeat,repeat );background-size:var( --wpd-table-header-bg-image-size,auto );background-position:var( --wpd-table-header-bg-image-position,center );padding:var( --wpd-table-cell-padding );border-bottom:1px solid var( --wpd-table-border );white-space:nowrap}tbody td{padding:var( --wpd-table-cell-padding );border-bottom:1px solid var( --wpd-table-border );background-color:var( --wpd-table-bg );vertical-align:middle}tbody tr:last-child td{border-bottom:0}:host( [ striped ] ) tbody tr:nth-child( odd ) td{background-image:linear-gradient( var( --wpd-table-stripe ),var( --wpd-table-stripe ) )}:host( [ hover ] ) tbody tr:hover td{background-image:linear-gradient( var( --wpd-table-row-hover ),var( --wpd-table-row-hover ) )}:host( [ hover ] [ striped ] ) tbody tr:nth-child( odd ):hover td{background-image:linear-gradient( var( --wpd-table-row-hover ),var( --wpd-table-row-hover ) ),linear-gradient( var( --wpd-table-stripe ),var( --wpd-table-stripe ) )}:host( [ compact ] ){--wpd-table-cell-padding:4px 8px;--wpd-table-font-size:12px}:host( [ bordered ] ) thead th,:host( [ bordered ] ) tbody td{border-inline-end:1px solid var( --wpd-table-column-border )}:host( [ bordered ] ) thead th:last-child,:host( [ bordered ] ) tbody td:last-child{border-inline-end:0}th.is-sticky,td.is-sticky{position:sticky;z-index:10}tbody td.is-sticky{background-color:var( --wpd-table-bg )}thead th.is-sticky{background-color:var( --wpd-table-header-bg );background-image:var( --wpd-table-header-bg-image,none );background-repeat:var( --wpd-table-header-bg-image-repeat,repeat );background-size:var( --wpd-table-header-bg-image-size,auto );background-position:var( --wpd-table-header-bg-image-position,center );z-index:30}:host( [ sticky-header ] ) thead th{position:sticky;top:0;z-index:20}:host( [ sticky-header ] ) thead tr.filter-row th{top:var( --wpd-table-header-height,33px );z-index:20}:host( [ sticky-header ] ) thead th.is-sticky{z-index:40}:host( [ sticky-header ] ) thead tr.filter-row th.is-sticky{z-index:40}th.is-sticky-edge,td.is-sticky-edge{border-inline-end:var( --wpd-table-sticky-edge,2px solid var( --wpd-table-border ) )}.align-center{text-align:center}.align-end{text-align:end}.filter-row th{padding:4px 8px;background-color:var( --wpd-table-header-bg );background-image:var( --wpd-table-header-bg-image,none );background-repeat:var( --wpd-table-header-bg-image-repeat,repeat );background-size:var( --wpd-table-header-bg-image-size,auto );background-position:var( --wpd-table-header-bg-image-position,center );border-bottom:1px solid var( --wpd-table-border );font-weight:400}.filter-input,.filter-select{width:100%;min-width:60px;box-sizing:border-box;padding:4px 6px;font:inherit;color:inherit;background-color:var( --wpd-table-bg );border:1px solid var( --wpd-table-border );border-radius:3px}.filter-input:focus,.filter-select:focus{outline:2px solid var( --wp-admin-theme-color,#2271b1 );outline-offset:-1px}.expander{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;padding:0;border:0;background:transparent;color:inherit;cursor:pointer;border-radius:3px;font-size:11px;line-height:1}.expander:hover{background:var( --wpd-hover,rgba( 0,0,0,0.06 ) )}td.col-expander,th.col-expander{width:36px;min-width:36px;padding-left:0;padding-right:0;text-align:center}tr.subtable td{padding:0;background-color:var( --wpd-table-bg );background-image:linear-gradient( var( --wpd-table-stripe ),var( --wpd-table-stripe ) );border-bottom:1px solid var( --wpd-table-border )}tr.subtable .subtable-inner{padding:8px 12px 8px 32px}tr.empty td{padding:24px;text-align:center;color:var( --wpd-text-muted,var( --wpd-fg-muted,rgba( 0,0,0,0.55 ) ) );font-style:italic}thead th.is-sortable{cursor:pointer;user-select:none}thead th.is-sortable:hover{background-image:linear-gradient( var( --wpd-table-row-hover ),var( --wpd-table-row-hover ) )}thead th.is-sortable:focus-visible{outline:2px solid var( --wp-admin-theme-color,#2271b1 );outline-offset:-2px}.sort-indicator{font-size:10px;color:var( --wpd-text-muted,var( --wpd-fg-muted,rgba( 0,0,0,0.55 ) ) );margin-inline-start:2px}thead th.sort-asc .sort-indicator,thead th.sort-desc .sort-indicator{color:var( --wp-admin-theme-color,#2271b1 )}td.col-select,th.col-select{width:40px;min-width:40px;padding-left:0;padding-right:0;text-align:center}.select-all-checkbox,.select-row-checkbox{cursor:pointer;margin:0}tbody tr.is-selected td{background-color:color-mix( in srgb,var( --wp-admin-theme-color,#2271b1 ) 10%,var( --wpd-table-bg ) );background-image:none}tbody tr.is-selected:hover td{background-color:color-mix( in srgb,var( --wp-admin-theme-color,#2271b1 ) 16%,var( --wpd-table-bg ) )}tbody tr.skeleton td{padding:var( --wpd-table-cell-padding )}.skeleton-bar{display:block;height:12px;border-radius:3px;background:linear-gradient( 90deg,var( --wpd-table-skeleton-color,var( --wpd-hover,rgba( 0,0,0,0.06 ) ) ) 0%,var( --wpd-table-skeleton-highlight,var( --wpd-hover,rgba( 0,0,0,0.14 ) ) ) 50%,var( --wpd-table-skeleton-color,var( --wpd-hover,rgba( 0,0,0,0.06 ) ) ) 100% );background-size:200% 100%;animation:wpd-table-skeleton-pulse 1.4s ease-in-out infinite}@keyframes wpd-table-skeleton-pulse{0%{background-position:200% 50%}100%{background-position:-200% 50%}}@media ( prefers-reduced-motion:reduce ){.skeleton-bar{animation:none}}`,O="__wpd_expander__",H="__wpd_select__",V=class V extends S{constructor(){super(...arguments),this._data=[],this._columns=[],this._filters={},this._expanded=new Set,this._subTable=null,this._sort=null,this._selection=new Set,this._getRowId=(e,t)=>t,this._filterCache=new Map,this._paintScheduled=!1,this._stickyHeaderWarned=!1,this._stickyRaceWarned=!1,this._resizeObserver=null,this._stickyMicroScheduled=!1,this._stickyRafHandle=null,this._loadingDesyncWarned=!1,this._lastStickyIndex=-1}get data(){return this._data}set data(e){this._data=Array.isArray(e)?e.slice():[],this._expanded.clear(),this._schedulePaint()}get columns(){return this._columns}set columns(e){this._columns=Array.isArray(e)?e.slice():[];const t=new Set(this._columns.map(n=>n.key));for(const n of Object.keys(this._filters))t.has(n)||delete this._filters[n];for(const n of Array.from(this._filterCache.keys()))t.has(n)||this._filterCache.delete(n);this._sort&&!t.has(this._sort.key)&&(this._sort=null),this._schedulePaint()}get filters(){return{...this._filters}}set filters(e){this._filters=e?{...e}:{},this._schedulePaint()}get sort(){return this._sort?{...this._sort}:null}set sort(e){this._sort=e?{...e}:null,this._schedulePaint()}get selection(){return new Set(this._selection)}set selection(e){this._selection=new Set(e??[]),this._schedulePaint()}get selectedRows(){const e=[];return this._data.forEach((t,n)=>{this._selection.has(this._getRowId(t,n))&&e.push(t)}),e}get visibleRows(){return this._filteredRows().map(e=>e.row)}get getRowId(){return this._getRowId}set getRowId(e){this._getRowId=typeof e=="function"?e:(t,n)=>n,this._schedulePaint()}get subTable(){return this._subTable}set subTable(e){this._subTable=typeof e=="function"?e:null,this._expanded.clear(),this._schedulePaint()}get expanded(){return new Set(this._expanded)}set expanded(e){this._expanded=new Set(e??[]),this._schedulePaint()}expand(e){e<0||e>=this._data.length||this._expanded.has(e)||(this._expanded.add(e),this.emit("wpd-table-expand-change",{row:this._data[e],index:e,expanded:!0}),this._schedulePaint())}collapse(e){this._expanded.has(e)&&(this._expanded.delete(e),this.emit("wpd-table-expand-change",{row:this._data[e],index:e,expanded:!1}),this._schedulePaint())}expandAll(){if(!this._subTable)return;let e=!1;for(let t=0;t<this._data.length;t++)this._subTable(this._data[t],t)&&(this._expanded.has(t)||(this._expanded.add(t),e=!0));e&&this._schedulePaint()}collapseAll(){this._expanded.size!==0&&(this._expanded.clear(),this._schedulePaint())}isExpanded(e){return this._expanded.has(e)}clearFilters(){Object.keys(this._filters).length!==0&&(this._filters={},this.emit("wpd-table-filter-change",{filters:{}}),this._schedulePaint())}clearSort(){this._sort!==null&&(this._sort=null,this.emit("wpd-table-sort-change",{sort:null}),this._schedulePaint())}select(e){if(this._selection.has(e))return;const t=this._readSelectable(),n=t==="single"?Array.from(this._selection):[];t==="single"&&this._selection.clear(),this._selection.add(e),this._emitSelectionChange(),this._syncSelectionDom([e,...n])}deselect(e){this._selection.delete(e)&&(this._emitSelectionChange(),this._syncSelectionDom([e]))}selectAll(){if(this._readSelectable()==="multi"){for(const{row:e,index:t}of this._filteredRows())this._selection.add(this._getRowId(e,t));this._emitSelectionChange(),this._syncSelectionDom("all")}}clearSelection(){this._selection.size!==0&&(this._selection.clear(),this._emitSelectionChange(),this._syncSelectionDom("all"))}_syncSelectionDom(e){const t=this.shadowRoot;if(!t)return;const n=t.querySelector("tbody");if(!n)return;let r=null;if(e!=="all"){r=new Set;for(const a of e)r.add(String(a))}const i=n.querySelectorAll("tr[data-row-id]");for(const a of i){const d=a.dataset.rowId;if(d===void 0||r&&!r.has(d))continue;const l=Number(a.dataset.rowIndex);if(!Number.isFinite(l))continue;const p=this._data[l];if(p===void 0)continue;const c=this._getRowId(p,l),f=this._selection.has(c);a.classList.toggle("is-selected",f);const h=a.querySelector("input.select-row-checkbox");h&&h.checked!==f&&(h.checked=f)}const o=t.querySelector("thead .select-all-checkbox");if(o){const{total:a,selected:d}=this._visibleSelectionStats();o.checked=a>0&&d===a,o.indeterminate=d>0&&d<a}}scrollToRow(e){const t=this.shadowRoot;if(!t)return;const r=t.querySelectorAll("tbody tr:not(.subtable):not(.empty):not(.skeleton)")[e];r&&r.scrollIntoView({block:"nearest",inline:"nearest"})}connectedCallback(){super.connectedCallback(),this._schedulePaint()}disconnectedCallback(){this._resizeObserver?.disconnect(),this._resizeObserver=null,this._stickyRafHandle!==null&&typeof cancelAnimationFrame<"u"&&(cancelAnimationFrame(this._stickyRafHandle),this._stickyRafHandle=null)}recomputeLayout(){this._applyStickyOffsets(),this._measureHeaderHeight()}render(){return w` | |
| 117 | + `:v``} | |
| 118 | + `}};K.props=["placeholder","exclude","endpoint"],K.styles=[ts],K.help=void 0;let we=K;R("os-user-search",we);function os(){const e=window.openStationGamesConfig?.usersSearchUrl;if(e)return e;const s=window.wp?.os?.config?.restUrl||"/wp-json/";return tt(s,"desktop-mode/v1/games/users/search")}function ht(o){return new Promise(e=>{const t=document.createElement("os-modal");t.setAttribute("open",""),t.setAttribute("title",g("Send a challenge")),t.setAttribute("size","sm");const s=document.createElement("div");s.className="os-games__challenge-dialog";const n=document.createElement("p");n.className="os-games__challenge-summary",n.textContent=k(g("Challenge someone to beat your %1$s score of %2$s."),o.gameTitle,String(o.score)),s.appendChild(n);const i=document.createElement("os-user-search");i.setAttribute("placeholder",g("Find a player…")),i.setAttribute("endpoint",os()),s.appendChild(i);const r=document.createElement("div");r.className="os-games__challenge-picked",r.hidden=!0,s.appendChild(r),t.appendChild(s);const a=document.createElement("div");a.setAttribute("slot","footer"),a.className="os-games__challenge-footer";const l=document.createElement("os-button");l.setAttribute("variant","ghost"),l.textContent=g("Cancel");const d=document.createElement("os-button");d.setAttribute("variant","primary"),d.setAttribute("disabled",""),d.textContent=g("Send challenge"),a.append(l,d),t.appendChild(a);let u=null,c=!1;const f=()=>{t.remove(),e()},p=()=>{if(r.innerHTML="",!u){r.hidden=!0,d.setAttribute("disabled","");return}r.hidden=!1;const h=document.createElement("os-avatar");h.setAttribute("src",u.avatarUrl),h.setAttribute("name",u.name),h.setAttribute("size","sm"),h.setAttribute("user-id",String(u.id)),r.appendChild(h);const m=document.createElement("span");m.textContent=u.name,r.appendChild(m),d.removeAttribute("disabled")};i.addEventListener("os-user-pick",h=>{const m=h.detail?.user;m&&(u=m,p())}),l.addEventListener("click",f),t.addEventListener("os-modal-cancel",f),d.addEventListener("click",()=>{!u||c||(c=!0,d.setAttribute("disabled",""),Po({game:o.game,recipientId:u.id,score:o.score,meta:o.meta}).then(()=>{F({message:k(g("Challenge sent to %s."),u.name)}),f()}).catch(h=>{c=!1,d.removeAttribute("disabled"),F({message:h instanceof Error?h.message:g("Could not send the challenge.")})}))}),document.body.appendChild(t)})}const ss=_`:host{display:inline;color:inherit;font:inherit}`,re=new Set;let O=null;const ns=3e4;function is(){O===null&&(O=window.setInterval(()=>{for(const o of re)o.tick()},ns))}function rs(){O!==null&&re.size===0&&(window.clearInterval(O),O=null)}function as(o){if(!o)return null;const e=t=>{const s=new Date(t);return Number.isNaN(s.getTime())?null:s};return ls(o)?e(o):e(o.replace(" ","T")+"Z")}function ls(o){const e=Math.max(o.indexOf("T"),o.indexOf(" ")),t=e===-1?"":o.slice(e+1);return/(?:[Zz]|[+-]\d{2}:?\d{2})$/.test(t)}let Ce=null,Se=null;function pt(){return typeof navigator<"u"&&navigator.language||"en"}function cs(){return Ce||(Ce=new Intl.RelativeTimeFormat(pt(),{numeric:"auto"})),Ce}function ft(){return Se||(Se=new Intl.RelativeTimeFormat(pt(),{numeric:"always",style:"narrow"})),Se}function ds(o,e){const t=cs(),s=o.getTime()-e,n=Math.round(s/1e3),i=Math.abs;return i(n)<45?t.format(0,"second"):mt(t,n)}function mt(o,e){const t=Math.abs,s=Math.round(e/60);if(t(s)<45)return o.format(s,"minute");const n=Math.round(s/60);if(t(n)<22)return o.format(n,"hour");const i=Math.round(n/24);if(t(i)<26)return o.format(i,"day");const r=Math.round(i/30);if(t(r)<11)return o.format(r,"month");const a=Math.round(i/365);return o.format(a,"year")}function us(o,e){const t=Math.round((o.getTime()-e)/1e3),s=Math.abs;return s(t)<45?ft().format(0,"second"):s(t)>7*24*60*60?o.toLocaleDateString(void 0,{month:"short",day:"numeric"}):mt(ft(),t)}const V=class V extends E{connectedCallback(){super.connectedCallback(),re.add(this),is()}disconnectedCallback(){re.delete(this),rs()}tick(){this.requestUpdate()}render(){const e=this.datetime,t=as(e);if(!t)return v`<span>${e??""}</span>`;const s=Date.now(),n=this.hasAttribute("compact")?us(t,s):ds(t,s),i=t.toLocaleString();return v`<time datetime=${t.toISOString()} title=${i} | |
| 119 | + >${n}</time | |
| 120 | + >`}};V.props=["datetime","compact"],V.styles=[ss],V.help=void 0;let Ee=V;R("os-relative-time",Ee);const hs=_` ${Q} ${Ue}:host{display:block;--_bg:var( --os-ui-table-bg,var( --os-ui-surface,#fff ) );--_border:var( --os-ui-table-border,var( --os-ui-border,rgba( 0,0,0,0.08 ) ) );--_column-border:var( --os-ui-table-column-border,var( --os-ui-border-strong,rgba( 0,0,0,0.14 ) ) );--_header-bg:var( --os-ui-table-header-bg,var( --os-ui-surface-elevated,#f6f7f7 ) );--_row-hover:var( --os-ui-table-row-hover,var( --os-ui-hover,rgba( 0,0,0,0.04 ) ) );--_stripe:var( --os-ui-table-stripe,var( --os-ui-surface-subtle,rgba( 0,0,0,0.03 ) ) );--_cell-padding:var( --os-ui-table-cell-padding,8px 12px );--_font-size:var( --os-ui-table-font-size,13px );--_max-height:var( --os-ui-table-max-height,none );font-size:var( --_font-size );color:inherit}:host( [ hidden ] ){display:none}.scroll{position:relative;overflow:auto;max-height:var( --_max-height );border:1px solid var( --_border );border-radius:4px;background:var( --_bg )}table{width:100%;border-collapse:separate;border-spacing:0;background:var( --_bg )}thead th{text-align:start;font-weight:600;background-color:var( --_header-bg );background-image:var( --os-ui-table-header-bg-image,none );background-repeat:var( --os-ui-table-header-bg-image-repeat,repeat );background-size:var( --os-ui-table-header-bg-image-size,auto );background-position:var( --os-ui-table-header-bg-image-position,center );padding:var( --_cell-padding );border-bottom:1px solid var( --_border );white-space:nowrap}tbody td{padding:var( --_cell-padding );border-bottom:1px solid var( --_border );background-color:var( --_bg );vertical-align:middle}tbody tr:last-child td{border-bottom:0}:host( [ striped ] ) tbody tr:nth-child( odd ) td{background-image:linear-gradient( var( --_stripe ),var( --_stripe ) )}:host( [ hover ] ) tbody tr:hover td{background-image:linear-gradient( var( --_row-hover ),var( --_row-hover ) )}:host( [ hover ][ striped ] ) tbody tr:nth-child( odd ):hover td{background-image:linear-gradient( var( --_row-hover ),var( --_row-hover ) ),linear-gradient( var( --_stripe ),var( --_stripe ) )}:host( [ compact ] ){--os-ui-table-cell-padding:4px 8px;--os-ui-table-font-size:12px}:host( [ bordered ] ) thead th,:host( [ bordered ] ) tbody td{border-inline-end:1px solid var( --_column-border )}:host( [ bordered ] ) thead th:last-child,:host( [ bordered ] ) tbody td:last-child{border-inline-end:0}th.is-sticky,td.is-sticky{position:sticky;z-index:10}tbody td.is-sticky{background-color:var( --_bg )}thead th.is-sticky{background-color:var( --_header-bg );background-image:var( --os-ui-table-header-bg-image,none );background-repeat:var( --os-ui-table-header-bg-image-repeat,repeat );background-size:var( --os-ui-table-header-bg-image-size,auto );background-position:var( --os-ui-table-header-bg-image-position,center );z-index:30}:host( [ sticky-header ] ) thead th{position:sticky;top:0;z-index:20}:host( [ sticky-header ] ) thead tr.filter-row th{top:var( --os-ui-table-header-height,33px );z-index:20}:host( [ sticky-header ] ) thead th.is-sticky{z-index:40}:host( [ sticky-header ] ) thead tr.filter-row th.is-sticky{z-index:40}th.is-sticky-edge,td.is-sticky-edge{border-inline-end:var( --os-ui-table-sticky-edge,2px solid var( --_border ) )}.align-center{text-align:center}.align-end{text-align:end}.filter-row th{padding:4px 8px;background-color:var( --_header-bg );background-image:var( --os-ui-table-header-bg-image,none );background-repeat:var( --os-ui-table-header-bg-image-repeat,repeat );background-size:var( --os-ui-table-header-bg-image-size,auto );background-position:var( --os-ui-table-header-bg-image-position,center );border-bottom:1px solid var( --_border );font-weight:400}.filter-input,.filter-select{width:100%;min-width:60px;box-sizing:border-box;padding:4px 6px;font:inherit;color:inherit;background-color:var( --_bg );border:1px solid var( --_border );border-radius:3px}.filter-input:focus,.filter-select:focus{outline:none;border-color:var( --os-ui-accent,#2271b1 );box-shadow:var( --_holo-focus-field )}.expander{display:inline-flex;align-items:center;justify-content:center;width:20px;height:20px;padding:0;border:0;background:transparent;color:inherit;cursor:pointer;border-radius:3px;font-size:11px;line-height:1}.expander:hover{background:var( --os-ui-hover,rgba( 0,0,0,0.06 ) )}td.col-expander,th.col-expander{width:36px;min-width:36px;padding-left:0;padding-right:0;text-align:center}tr.subtable td{padding:0;background-color:var( --_bg );background-image:linear-gradient( var( --_stripe ),var( --_stripe ) );border-bottom:1px solid var( --_border )}tr.subtable .subtable-inner{padding:8px 12px 8px 32px}tr.empty td{padding:24px;text-align:center;color:var( --os-ui-text-muted,var( --os-ui-fg-muted,rgba( 0,0,0,0.55 ) ) );font-style:italic}thead th.is-sortable{cursor:pointer;user-select:none}thead th.is-sortable:hover{background-image:linear-gradient( var( --_row-hover ),var( --_row-hover ) )}thead th.is-sortable:focus-visible{outline:none;box-shadow:inset 0 0 0 2px var( --os-ui-accent,#2271b1 )}.sort-indicator{font-size:10px;color:var( --os-ui-text-muted,var( --os-ui-fg-muted,rgba( 0,0,0,0.55 ) ) );margin-inline-start:2px}thead th.sort-asc .sort-indicator,thead th.sort-desc .sort-indicator{color:var( --wp-admin-theme-color,#2271b1 )}td.col-select,th.col-select{width:40px;min-width:40px;padding-left:0;padding-right:0;text-align:center}.select-all-checkbox,.select-row-checkbox{cursor:pointer;margin:0}tbody tr.is-selected td{background-color:color-mix( in srgb,var( --wp-admin-theme-color,#2271b1 ) 10%,var( --_bg ) );background-image:none}tbody tr.is-selected:hover td{background-color:color-mix( in srgb,var( --wp-admin-theme-color,#2271b1 ) 16%,var( --_bg ) )}tbody tr.is-selected td:first-child{box-shadow:inset 3px 0 0 0 var( --os-ui-accent,#2271b1 )}tbody:dir( rtl ) tr.is-selected td:first-child{box-shadow:inset -3px 0 0 0 var( --os-ui-accent,#2271b1 )}:host( [ stacked ] ) .scroll{border:0;border-radius:0}:host( [ stacked ] ) table,:host( [ stacked ] ) tbody{display:block;width:100%}:host( [ stacked ] ) colgroup,:host( [ stacked ] ) thead{display:none}:host( [ stacked ] ) tbody tr{display:flex;align-items:flex-start;gap:12px;padding:12px 14px;border-bottom:1px solid var( --_border );background-color:var( --_bg )}:host( [ stacked ] ) tbody tr:last-child{border-bottom:0}:host( [ stacked ] ) tbody td{display:block;padding:0;border:0;background-color:transparent;background-image:none;box-shadow:none;min-width:0;width:auto;vertical-align:baseline}:host( [ stacked ] ) tbody tr.is-selected td,:host( [ stacked ] ) tbody tr.is-selected:hover td,:host( [ stacked ][ striped ] ) tbody tr:nth-child( odd ) td,:host( [ stacked ][ hover ] ) tbody tr:hover td,:host( [ stacked ][ hover ][ striped ] ) tbody tr:nth-child( odd ):hover td,:host( [ stacked ][ bordered ] ) tbody td{padding:0;border:0;background-color:transparent;background-image:none;box-shadow:none}:host( [ stacked ][ hover ] ) tbody tr:hover{background-image:linear-gradient( var( --_row-hover ),var( --_row-hover ) )}:host( [ stacked ] ) tbody tr.is-selected,:host( [ stacked ] ) tbody tr.is-selected:hover{background-color:color-mix( in srgb,var( --wp-admin-theme-color,#2271b1 ) 10%,var( --_bg ) );background-image:none;box-shadow:inset 3px 0 0 0 var( --os-ui-accent,#2271b1 )}:host( [ stacked ] ) tbody:dir( rtl ) tr.is-selected{box-shadow:inset -3px 0 0 0 var( --os-ui-accent,#2271b1 )}:host( [ stacked ] ) tbody td.col-select,:host( [ stacked ] ) tbody td.col-expander{flex:0 0 auto;display:flex;align-items:center;justify-content:center;min-width:0}:host( [ stacked ] ) tbody td.col-select{width:44px;height:44px;margin:-11px 0 -11px -11px;cursor:pointer}:host( [ stacked ] ) .select-row-checkbox{width:22px;height:22px}:host( [ stacked ] ) tbody td.col-expander{width:28px;height:22px;margin-inline-start:-4px}:host( [ stacked ] ) tbody td.stack-body{flex:1 1 auto;display:flex;flex-direction:column;gap:4px;min-width:0}.stack-cell{display:flex;align-items:baseline;gap:6px;min-width:0;line-height:1.4}.stack-title{font-size:15px;font-weight:600;line-height:1.35}.stack-meta{font-size:13px}.stack-label{flex:0 0 auto;font-size:12px;color:var( --os-ui-text-muted,var( --os-ui-fg-muted,rgba( 0,0,0,0.55 ) ) )}.stack-label::after{content:'·';margin-inline-start:6px}.stack-value{flex:1 1 auto;min-width:0;display:flex;align-items:center;flex-wrap:wrap;gap:6px}.stack-actions{margin-block-start:6px}.stack-actions .stack-value{gap:8px}.stack-actions .stack-value>*{justify-content:flex-start;max-width:100%}:host( [ stacked ] ) tr.subtable,:host( [ stacked ] ) tr.empty{display:block;padding:0}:host( [ stacked ] ) tr.subtable td{background-image:linear-gradient( var( --_stripe ),var( --_stripe ) )}:host( [ stacked ] ) tr.subtable .subtable-inner{padding:8px 14px 12px}:host( [ stacked ] ) tr.empty td{padding:24px}:host( [ stacked ] ) tr.skeleton{display:block;padding:14px;border-bottom:1px solid var( --_border )}:host( [ stacked ] ) tr.skeleton td.stack-body{gap:8px}:host( [ stacked ] ) tr.skeleton .skeleton-bar:first-child{height:15px}tbody tr.skeleton td{padding:var( --_cell-padding )}.skeleton-bar{display:block;height:12px;border-radius:3px;background:linear-gradient( 90deg,var( --os-ui-table-skeleton-color,var( --os-ui-hover,rgba( 0,0,0,0.06 ) ) ) 0%,var( --os-ui-table-skeleton-highlight,var( --os-ui-hover,rgba( 0,0,0,0.14 ) ) ) 50%,var( --os-ui-table-skeleton-color,var( --os-ui-hover,rgba( 0,0,0,0.06 ) ) ) 100% );background-size:200% 100%;animation:os-table-skeleton-pulse 1.4s ease-in-out infinite}@keyframes os-table-skeleton-pulse{0%{background-position:200% 50%}100%{background-position:-200% 50%}}@media ( prefers-reduced-motion:reduce ){.skeleton-bar{animation:none}}`,z="__wpd_expander__",I="__wpd_select__",X=class X extends E{constructor(){super(...arguments),this._data=[],this._columns=[],this._filters={},this._expanded=new Set,this._subTable=null,this._sort=null,this._selection=new Set,this._getRowId=(e,t)=>t,this._filterCache=new Map,this._paintScheduled=!1,this._stacked=!1,this._stickyHeaderWarned=!1,this._stickyRaceWarned=!1,this._resizeObserver=null,this._stickyMicroScheduled=!1,this._stickyRafHandle=null,this._loadingDesyncWarned=!1,this._lastStickyIndex=-1}get data(){return this._data}set data(e){this._data=Array.isArray(e)?e.slice():[],this._expanded.clear(),this._schedulePaint()}get columns(){return this._columns}set columns(e){this._columns=Array.isArray(e)?e.slice():[];const t=new Set(this._columns.map(s=>s.key));for(const s of Object.keys(this._filters))t.has(s)||delete this._filters[s];for(const s of Array.from(this._filterCache.keys()))t.has(s)||this._filterCache.delete(s);this._sort&&!t.has(this._sort.key)&&(this._sort=null),this._schedulePaint()}get filters(){return{...this._filters}}set filters(e){this._filters=e?{...e}:{},this._schedulePaint()}get sort(){return this._sort?{...this._sort}:null}set sort(e){this._sort=e?{...e}:null,this._schedulePaint()}get selection(){return new Set(this._selection)}set selection(e){this._selection=new Set(e??[]),this._schedulePaint()}get selectedRows(){const e=[];return this._data.forEach((t,s)=>{this._selection.has(this._getRowId(t,s))&&e.push(t)}),e}get visibleRows(){return this._filteredRows().map(e=>e.row)}get getRowId(){return this._getRowId}set getRowId(e){this._getRowId=typeof e=="function"?e:(t,s)=>s,this._schedulePaint()}get subTable(){return this._subTable}set subTable(e){this._subTable=typeof e=="function"?e:null,this._expanded.clear(),this._schedulePaint()}get expanded(){return new Set(this._expanded)}set expanded(e){this._expanded=new Set(e??[]),this._schedulePaint()}expand(e){e<0||e>=this._data.length||this._expanded.has(e)||(this._expanded.add(e),this.emit("os-table-expand-change",{row:this._data[e],index:e,expanded:!0}),this._schedulePaint())}collapse(e){this._expanded.has(e)&&(this._expanded.delete(e),this.emit("os-table-expand-change",{row:this._data[e],index:e,expanded:!1}),this._schedulePaint())}expandAll(){if(!this._subTable)return;let e=!1;for(let t=0;t<this._data.length;t++)this._subTable(this._data[t],t)&&(this._expanded.has(t)||(this._expanded.add(t),e=!0));e&&this._schedulePaint()}collapseAll(){this._expanded.size!==0&&(this._expanded.clear(),this._schedulePaint())}isExpanded(e){return this._expanded.has(e)}clearFilters(){Object.keys(this._filters).length!==0&&(this._filters={},this.emit("os-table-filter-change",{filters:{}}),this._schedulePaint())}clearSort(){this._sort!==null&&(this._sort=null,this.emit("os-table-sort-change",{sort:null}),this._schedulePaint())}select(e){if(this._selection.has(e))return;const t=this._readSelectable(),s=t==="single"?Array.from(this._selection):[];t==="single"&&this._selection.clear(),this._selection.add(e),this._emitSelectionChange(),this._syncSelectionDom([e,...s])}deselect(e){this._selection.delete(e)&&(this._emitSelectionChange(),this._syncSelectionDom([e]))}selectAll(){if(this._readSelectable()==="multi"){for(const{row:e,index:t}of this._filteredRows())this._selection.add(this._getRowId(e,t));this._emitSelectionChange(),this._syncSelectionDom("all")}}clearSelection(){this._selection.size!==0&&(this._selection.clear(),this._emitSelectionChange(),this._syncSelectionDom("all"))}_syncSelectionDom(e){const t=this.shadowRoot;if(!t)return;const s=t.querySelector("tbody");if(!s)return;let n=null;if(e!=="all"){n=new Set;for(const a of e)n.add(String(a))}const i=s.querySelectorAll("tr[data-row-id]");for(const a of i){const l=a.dataset.rowId;if(l===void 0||n&&!n.has(l))continue;const d=Number(a.dataset.rowIndex);if(!Number.isFinite(d))continue;const u=this._data[d];if(u===void 0)continue;const c=this._getRowId(u,d),f=this._selection.has(c);a.classList.toggle("is-selected",f);const p=a.querySelector("input.select-row-checkbox");p&&p.checked!==f&&(p.checked=f)}const r=t.querySelector("thead .select-all-checkbox");if(r){const{total:a,selected:l}=this._visibleSelectionStats();r.checked=a>0&&l===a,r.indeterminate=l>0&&l<a}}scrollToRow(e){const t=this.shadowRoot;if(!t)return;const n=t.querySelectorAll("tbody tr:not(.subtable):not(.empty):not(.skeleton)")[e];n&&n.scrollIntoView({block:"nearest",inline:"nearest"})}connectedCallback(){super.connectedCallback(),this._schedulePaint()}disconnectedCallback(){this._resizeObserver?.disconnect(),this._resizeObserver=null,this._stickyRafHandle!==null&&typeof cancelAnimationFrame<"u"&&(cancelAnimationFrame(this._stickyRafHandle),this._stickyRafHandle=null)}recomputeLayout(){this._applyStickyOffsets(),this._measureHeaderHeight()}render(){return v` | |
| 110 | 121 | <div class="scroll" part="scroll"> |
| 111 | 122 | <table part="table"> |
| 112 | 123 | <colgroup></colgroup> |
| 113 | 124 | <thead></thead> |
| @@ -113,5 +124,5 @@ | ||
| 113 | 124 | <thead></thead> |
| 114 | 125 | <tbody></tbody> |
| 115 | 126 | </table> |
| 116 | 127 | </div> |
| 117 | - `}requestUpdate(){super.requestUpdate(),this._schedulePaint()}_schedulePaint(){this._paintScheduled||!this.isConnected||(this._paintScheduled=!0,queueMicrotask(()=>{this._paintScheduled=!1,this.isConnected&&this._paint()}))}_paint(){const e=this.shadowRoot;if(!e)return;e.querySelector("tbody")||K(this.render(),e);const t=e.querySelector("colgroup"),n=e.querySelector("thead"),r=e.querySelector("tbody");if(!t||!n||!r)return;const i=this._effectiveColumns(),o=this._readStickyColumns();this._lastStickyIndex=this._computeLastStickyIndex(i,o),this._paintColgroup(t,i),this._paintHead(n,i,o),this._paintBody(r,i,o),this._applyStickyOffsets(),this._measureHeaderHeight(),this._scheduleStickyOffsets(),this._maybeWarnStickyHeader(),this._maybeWarnLoadingDesync(r),this._ensureResizeObserver()}_maybeWarnLoadingDesync(e){this._loadingDesyncWarned||this.hasAttribute("loading")&&(e.querySelector("tr.skeleton")||(this._loadingDesyncWarned=!0,console.warn("[wpd-table] `loading` attribute is set but no skeleton rows rendered. Either attributeChangedCallback didn't route through requestUpdate (framework regression), or `loading` was set after the most recent paint and no follow-up trigger ran. Toggling `data` will force a paint as a workaround.")))}_scheduleStickyOffsets(){this._stickyMicroScheduled||(this._stickyMicroScheduled=!0,queueMicrotask(()=>{this._stickyMicroScheduled=!1,this.isConnected&&this._applyStickyOffsets()})),this._stickyRafHandle===null&&typeof requestAnimationFrame<"u"&&(this._stickyRafHandle=requestAnimationFrame(()=>{this._stickyRafHandle=null,this.isConnected&&(this._applyStickyOffsets(),this._measureHeaderHeight())}))}_ensureResizeObserver(){if(this._resizeObserver||typeof ResizeObserver>"u")return;const e=this.shadowRoot?.querySelector(".scroll");e&&(this._resizeObserver=new ResizeObserver(()=>{this.isConnected&&(this._applyStickyOffsets(),this._measureHeaderHeight(),this._stickyHeaderWarned=!1,this._maybeWarnStickyHeader())}),this._resizeObserver.observe(e),this._resizeObserver.observe(this))}_paintColgroup(e,t){const n=[];for(const r of t){const i=document.createElement("col");r.width&&(i.style.width=r.width),n.push(i)}e.replaceChildren(...n)}_paintHead(e,t,n){const r=document.createElement("tr");r.setAttribute("part","header-row");for(let d=0;d<t.length;d++)r.appendChild(this._buildHeaderCell(t[d],d,n));const i=e.querySelector(':scope > tr[part="header-row"]');i?e.replaceChild(r,i):e.insertBefore(r,e.firstChild);const o=t.some(d=>d.filter||Array.isArray(d.filterOptions)||typeof d.filterRender=="function");let a=e.querySelector(":scope > tr.filter-row");if(o){const d=[];for(let c=0;c<t.length;c++)d.push(this._buildFilterCell(t[c],c,n));a||(a=document.createElement("tr"),a.classList.add("filter-row"),a.setAttribute("part","filter-row"),e.appendChild(a));const l=Array.from(a.children);let p=l.length===d.length;if(p){for(let c=0;c<d.length;c++)if(l[c]!==d[c]){p=!1;break}}if(!p){const c=new Set(d);for(const f of d)a.appendChild(f);for(const f of Array.from(a.children))c.has(f)||a.removeChild(f)}}else a&&a.remove()}_buildHeaderCell(e,t,n){const r=document.createElement("th");if(r.setAttribute("scope","col"),r.dataset.key=e.key,this._applyCellClasses(r,e,t,n),e.minWidth&&(r.style.minWidth=e.minWidth),e.key===H){if(this._readSelectable()==="multi"){const o=document.createElement("input");o.type="checkbox",o.className="select-all-checkbox",o.setAttribute("data-noclick",""),o.setAttribute("aria-label","Select all rows");const{total:a,selected:d}=this._visibleSelectionStats();o.checked=a>0&&d===a,o.indeterminate=d>0&&d<a,o.addEventListener("change",()=>{o.checked?this.selectAll():this.clearSelection()}),r.appendChild(o)}return r}if(r.textContent=e.label??(e.key===O?"":e.key),e.sortable){r.classList.add("is-sortable");const i=this._sort?.key===e.key,o=document.createElement("span");o.className="sort-indicator";let a="";i&&(a=this._sort.direction==="asc"?" ▲":" ▼"),o.textContent=a,r.appendChild(o),i&&r.classList.add(this._sort.direction==="asc"?"sort-asc":"sort-desc"),r.addEventListener("click",()=>this._cycleSort(e.key))}return r}_buildFilterCell(e,t,n){const r=this._filterCache.get(e.key),i=Array.isArray(e.filterOptions),o=typeof e.filterRender=="function";let a;if(!e.filter&&!i&&!o||e.key===O||e.key===H?a="none":o?a="custom":e.filter==="select"||i?a="select":a="text",r&&r.kind===a){if(r.th.className="",this._applyCellClasses(r.th,e,t,n),a==="select"){const c=r.control,f=this._resolveFilterOptions(e),h=f.map(u=>u.value).join("|");h!==r.optionsKey?(this._populateSelect(c,f,this._filters[e.key]??""),r.optionsKey=h):c.value=this._filters[e.key]??""}else if(a==="text"){const c=r.control,f=this._filters[e.key]??"";c.value!==f&&c.ownerDocument.activeElement!==c&&(c.value=f)}else a==="custom"&&e.filterRender&&e.filterRender(r.th,{value:this._filters[e.key]??"",setValue:c=>this._onFilterChange(e.key,c),col:e});return r.th}const d=document.createElement("th");if(this._applyCellClasses(d,e,t,n),a==="none")return this._filterCache.set(e.key,{th:d,control:null,optionsKey:"",kind:"none"}),d;if(a==="custom"&&e.filterRender)return e.filterRender(d,{value:this._filters[e.key]??"",setValue:c=>this._onFilterChange(e.key,c),col:e}),this._filterCache.set(e.key,{th:d,control:null,optionsKey:"",kind:"custom"}),d;let l,p="";if(a==="select"){const c=document.createElement("select");c.classList.add("filter-select"),c.setAttribute("data-noclick",""),c.setAttribute("aria-label",`Filter ${e.label??e.key}`);const f=this._resolveFilterOptions(e);this._populateSelect(c,f,this._filters[e.key]??""),p=f.map(h=>h.value).join("|"),c.addEventListener("change",()=>{this._onFilterChange(e.key,c.value)}),l=c}else{const c=document.createElement("input");c.type="search",c.classList.add("filter-input"),c.setAttribute("data-noclick",""),c.setAttribute("placeholder","Filter…"),c.setAttribute("aria-label",`Filter ${e.label??e.key}`),c.value=this._filters[e.key]??"",c.addEventListener("input",()=>{this._onFilterChange(e.key,c.value)}),l=c}return d.appendChild(l),this._filterCache.set(e.key,{th:d,control:l,optionsKey:p,kind:a}),d}_populateSelect(e,t,n){e.replaceChildren();const r=document.createElement("option");r.value="",r.textContent="All",e.appendChild(r);for(const i of t){const o=document.createElement("option");o.value=i.value,o.textContent=i.label,i.value===n&&(o.selected=!0),e.appendChild(o)}e.value=n}_resolveFilterOptions(e){return Array.isArray(e.filterOptions)?e.filterOptions:this._uniqueValues(e.key).map(t=>({value:t,label:t}))}_paintBody(e,t,n){if(e.replaceChildren(),this.hasAttribute("loading")){const i=this._readLoadingRows();for(let o=0;o<i;o++)e.appendChild(this._buildSkeletonRow(t,o));return}const r=this._sortedRows(this._filteredRows());if(r.length===0){e.appendChild(this._buildEmptyRow(t.length));return}for(const{row:i,index:o}of r)if(e.appendChild(this._buildBodyRow(i,o,t,n)),this._expanded.has(o)&&this._subTable){const a=this._subTable(i,o);a&&e.appendChild(this._buildSubTableRow(a,t.length))}}_buildEmptyRow(e){const t=document.createElement("tr");t.classList.add("empty");const n=document.createElement("td");n.colSpan=e;const r=document.createElement("slot");return r.name="empty",r.textContent=this.getAttribute("empty")||"No data",n.appendChild(r),t.appendChild(n),t}_buildSkeletonRow(e,t){const n=document.createElement("tr");n.classList.add("skeleton"),n.setAttribute("aria-hidden","true");for(const r of e){const i=document.createElement("td"),o=document.createElement("span");o.className="skeleton-bar";const a=50+(t*7+n.children.length*13)%40;o.style.width=`${a}%`,i.appendChild(o),n.appendChild(i)}return n}_buildBodyRow(e,t,n,r){const i=document.createElement("tr");i.setAttribute("part","row"),i.dataset.rowIndex=String(t);const o=this._getRowId(e,t);i.dataset.rowId=String(o),this._selection.has(o)&&i.classList.add("is-selected"),i.addEventListener("click",a=>{this._onRowClick(e,t,a)});for(let a=0;a<n.length;a++)i.appendChild(this._buildBodyCell(n[a],a,e,t,r));return i}_buildBodyCell(e,t,n,r,i){const o=document.createElement("td");if(this._applyCellClasses(o,e,t,i),e.minWidth&&(o.style.minWidth=e.minWidth),e.key===H){const d=this._getRowId(n,r),l=document.createElement("input");return l.type="checkbox",l.className="select-row-checkbox",l.setAttribute("data-noclick",""),l.setAttribute("aria-label","Select row"),l.checked=this._selection.has(d),l.addEventListener("change",()=>{l.checked?this.select(d):this.deselect(d)}),o.appendChild(l),o}if(e.key===O){if(!(this._subTable?!!this._subTable(n,r):!1))return o;const l=this._expanded.has(r),p=document.createElement("button");return p.type="button",p.className="expander",p.setAttribute("data-noclick",""),p.setAttribute("aria-expanded",l?"true":"false"),p.setAttribute("aria-label",l?"Collapse row":"Expand row"),p.textContent=l?"▾":"▸",p.addEventListener("click",c=>{this._toggleRow(r,n,c)}),o.appendChild(p),o}const a=n[e.key];if(e.render){const d=e.render(a,n,r);this._mountCellContent(o,d)}else a!=null&&(o.textContent=String(a));return o}_buildSubTableRow(e,t){const n=document.createElement("tr");n.classList.add("subtable"),n.setAttribute("part","subtable-row");const r=document.createElement("td");r.colSpan=t;const i=document.createElement("div");if(i.classList.add("subtable-inner"),e instanceof Node)i.appendChild(e);else if(nt(e))K(e,i);else{const o=document.createElement("wpd-table");o.columns=e.columns,o.data=e.data,e.subTable&&(o.subTable=e.subTable),i.appendChild(o)}return r.appendChild(i),n.appendChild(r),n}_mountCellContent(e,t){if(typeof t=="string"){e.textContent=t;return}if(t instanceof Node){e.appendChild(t);return}nt(t)&&K(t,e)}_onFilterChange(e,t){t===""?delete this._filters[e]:this._filters[e]=t,this.emit("wpd-table-filter-change",{filters:{...this._filters}});const r=this.shadowRoot?.querySelector("tbody");if(r){const i=this._effectiveColumns(),o=this._readStickyColumns();this._lastStickyIndex=this._computeLastStickyIndex(i,o),this._paintBody(r,i,o),this._applyStickyOffsets()}}_onRowClick(e,t,n){const r=n.composedPath?.()??[];for(const i of r){if(i instanceof Element&&i.hasAttribute("data-noclick"))return;if(i===this)break}this.emit("wpd-table-row-click",{row:e,index:t,originalEvent:n})}_toggleRow(e,t,n){n.stopPropagation();const r=this._expanded.has(e);r?this._expanded.delete(e):this._expanded.add(e),this.emit("wpd-table-expand-change",{row:t,index:e,expanded:!r}),this._schedulePaint()}_cycleSort(e){!this._sort||this._sort.key!==e?this._sort={key:e,direction:"asc"}:this._sort.direction==="asc"?this._sort={key:e,direction:"desc"}:this._sort=null,this.emit("wpd-table-sort-change",{sort:this._sort?{...this._sort}:null}),this._schedulePaint()}_emitSelectionChange(){this.emit("wpd-table-selection-change",{selection:Array.from(this._selection),rows:this.selectedRows})}_filteredRows(){const e=[],t=Object.keys(this._filters).filter(n=>this._filters[n]!=="");for(let n=0;n<this._data.length;n++){const r=this._data[n];let i=!0;for(const o of t){const a=this._columns.find(c=>c.key===o);if(a&&typeof a.filterRender=="function")continue;const d=this._filters[o]??"",l=r[o],p=l==null?"":String(l);if(a?.filter==="select"){if(p!==d){i=!1;break}}else if(!p.toLowerCase().includes(d.toLowerCase())){i=!1;break}}i&&e.push({row:r,index:n})}return e}_sortedRows(e){if(!this._sort)return e;const t=this._columns.find(i=>i.key===this._sort.key);if(!t)return e;const n=this._sort.direction==="desc"?-1:1,r=e.slice();return r.sort((i,o)=>{const a=t.sortValue?t.sortValue(i.row,i.row[t.key]):i.row[t.key],d=t.sortValue?t.sortValue(o.row,o.row[t.key]):o.row[t.key];return Ln(a,d)*n}),r}_uniqueValues(e){const t=new Set;for(const n of this._data){const r=n[e];r!=null&&t.add(String(r))}return Array.from(t).sort()}_visibleSelectionStats(){let e=0,t=0;for(const{row:n,index:r}of this._filteredRows())e++,this._selection.has(this._getRowId(n,r))&&t++;return{total:e,selected:t}}_readStickyColumns(){const e=parseInt(this.getAttribute("sticky-columns")||"0",10);return Number.isFinite(e)&&e>0?e:0}_readLoadingRows(){const e=parseInt(this.getAttribute("loading-rows")||"5",10);return Number.isFinite(e)&&e>0?Math.min(e,100):5}_readSelectable(){const e=this.getAttribute("selectable");return e==="single"?"single":e==="multi"||e===""?"multi":null}_isStickyIndex(e,t,n){return n.sticky===!1?!1:n.sticky===!0?!0:e<t}_computeLastStickyIndex(e,t){let n=-1;for(let r=0;r<e.length;r++)this._isStickyIndex(r,t,e[r])&&(n=r);return n}_applyCellClasses(e,t,n,r){t.key===O&&e.classList.add("col-expander"),t.key===H&&e.classList.add("col-select"),t.align==="center"&&e.classList.add("align-center"),t.align==="end"&&e.classList.add("align-end"),this._isStickyIndex(n,r,t)&&(e.classList.add("is-sticky"),n===this._lastStickyIndex&&e.classList.add("is-sticky-edge"))}_effectiveColumns(){const e=[];return this._readSelectable()&&e.push({key:H,label:"",width:"40px",align:"center"}),this._subTable&&e.push({key:O,label:"",width:"36px",align:"center"}),e.push(...this._columns),e}_applyStickyOffsets(){const e=this.shadowRoot;if(!e)return;const t=e.querySelector("thead tr");if(!t)return;const n=Array.from(t.children),r=[];let i=0;for(let a=0;a<n.length;a++)r[a]=i,n[a].classList.contains("is-sticky")&&(i+=n[a].offsetWidth);e.querySelectorAll("thead tr, tbody tr:not(.subtable):not(.empty):not(.skeleton)").forEach(a=>{const d=Array.from(a.children);for(let l=0;l<d.length;l++)d[l].classList.contains("is-sticky")&&(d[l].style.insetInlineStart=`${r[l]}px`)}),this._maybeWarnStickyOffsetRace(n,r)}_maybeWarnStickyOffsetRace(e,t){if(this._stickyRaceWarned)return;const n=this._readStickyColumns();if(n<2)return;const r=Math.min(n-1,e.length-1);if(r<=0||t[r]!==0||this.offsetWidth===0)return;this._stickyRaceWarned=!0;const i=e[0]?.offsetWidth??0;console.warn(`[wpd-table] sticky-columns: column ${r} resolved to inset-inline-start: 0px while the host is visible. ths[0].offsetWidth was ${i}px at measurement time. Likely a layout race — call recomputeLayout() after the panel finishes its mount/transition, or wrap the assignment of \`data\` in a requestAnimationFrame.`)}_measureHeaderHeight(){const e=this.shadowRoot;if(!e)return;const t=e.querySelector("thead tr");if(!t)return;const n=t.offsetHeight;n>0&&this.style.setProperty("--wpd-table-header-height",`${n}px`)}_maybeWarnStickyHeader(){if(this._stickyHeaderWarned||!this.hasAttribute("sticky-header")||this.hasAttribute("loading")||this._data.length<8)return;const e=this.shadowRoot?.querySelector(".scroll");e&&e.offsetWidth!==0&&e.scrollHeight<=e.clientHeight+1&&(this._stickyHeaderWarned=!0,console.warn("[wpd-table] sticky-header is set but the table has no scroll container. Set --wpd-table-max-height on the host (or wrap it in a scrolling parent) so the header has something to stick to."))}};V.props=["stickyColumns","stickyHeader","striped","hover","compact","bordered","empty","loading","loadingRows","selectable"],V.styles=[Tn],V.help=void 0;let ve=V;function nt(s){return!!s&&s.__wpdHtml===!0}function Ln(s,e){if(s===e)return 0;if(s==null)return-1;if(e==null)return 1;if(typeof s=="number"&&typeof e=="number")return s-e;if(s instanceof Date&&e instanceof Date)return s.getTime()-e.getTime();const t=Number(s),n=Number(e);return Number.isFinite(t)&&Number.isFinite(n)?t-n:String(s).localeCompare(String(e))}E("wpd-table",ve);const st=25;function In(){const s=window.wp;return Number(s?.desktop?.config?.currentUserId)||0}function Pn(s){const e=Math.max(0,Math.round(Number(s)||0)),t=Math.floor(e/60),n=e%60;return`${t}:${String(n).padStart(2,"0")}`}function zn(s){const e=[{key:"userName",label:b("Player"),render:(t,n)=>{const r=document.createElement("span");r.style.cssText="display:inline-flex;align-items:center;gap:8px;min-width:0;";const i=document.createElement("wpd-avatar");i.setAttribute("src",n.userAvatar),i.setAttribute("name",n.userName),i.setAttribute("size","xs"),i.setAttribute("user-id",String(n.userId)),r.appendChild(i);const o=document.createElement("span");return o.textContent=n.userName,r.appendChild(o),r}}];for(const t of s.scoreColumns)e.push({key:t.key,label:t.label,render:(n,r)=>{const i=t.key==="score"?r.score:r.meta[t.key];return i==null?"—":t.type==="time"?Pn(i):String(i)}});return e.push({key:"createdAtMs",label:b("When"),render:(t,n)=>{const r=document.createElement("wpd-relative-time");return r.setAttribute("datetime",new Date(n.createdAtMs).toISOString()),r}}),e.push({key:"__actions",label:"",render:(t,n)=>{if(n.userId!==In())return"";const r=document.createElement("wpd-button");return r.setAttribute("variant","secondary"),r.setAttribute("size","sm"),r.textContent=b("Challenge…"),r.addEventListener("click",()=>{Je({game:s.id,gameTitle:s.title,score:n.score,meta:n.meta})}),r}}),e}function Mn(s,e){s.innerHTML="";const t=document.createElement("div");t.className="desktop-mode-games__scoreboard-table",s.appendChild(t);const n=document.createElement("div");n.className="desktop-mode-games__pager",s.appendChild(n);let r=1,i=0,o=0,a=!1;const d=document.createElement("wpd-table");d.setAttribute("sticky-header",""),d.setAttribute("hover",""),d.setAttribute("striped","");const l=document.createElement("div");l.setAttribute("slot","empty"),l.className="desktop-mode-games__scoreboard-empty",l.textContent=b("No scores yet — be the first to play!"),d.appendChild(l),t.appendChild(d),d.columns=zn(e),d.data=[];const p=()=>{n.innerHTML="";const f=Math.max(1,Math.ceil(i/st));if(f<=1)return;const h=document.createElement("wpd-button");h.setAttribute("variant","ghost"),h.textContent=b("Previous"),r<=1&&h.setAttribute("disabled",""),h.addEventListener("click",()=>void c(r-1));const u=document.createElement("span");u.className="desktop-mode-games__pager-label",u.textContent=`${r} / ${f}`;const m=document.createElement("wpd-button");m.setAttribute("variant","ghost"),m.textContent=b("Next"),r>=f&&m.setAttribute("disabled",""),m.addEventListener("click",()=>void c(r+1)),n.append(h,u,m)},c=async f=>{const h=++o;d.setAttribute("loading","");try{const u=await Be(e.id,{page:f,perPage:st});if(a||h!==o)return;r=f,i=u.total,d.data=u.scores}catch(u){typeof console<"u"&&console.error("[desktop-mode] scoreboard load failed:",u)}finally{!a&&h===o&&(d.removeAttribute("loading"),p())}};return c(1),()=>{a=!0}}const q=He("desktop-mode/games-challenges",()=>({rows:new Map,version:0,listeners:new Set}));function ye(s){const e=q.state;let t=!1;for(const n of s){if(!n||typeof n.id!="number")continue;const r=e.rows.get(n.id);(!r||r.updatedAtMs!==n.updatedAtMs)&&(e.rows.set(n.id,n),t=!0),n.updatedAtMs>e.version&&(e.version=n.updatedAtMs)}t&&Hn()}function On(s){return q.state.listeners.add(s),()=>{q.state.listeners.delete(s)}}function Hn(){for(const s of Array.from(q.state.listeners))try{s()}catch(e){typeof console<"u"&&console.error("[desktop-mode] challenges store listener threw:",e)}}function qn(){return Array.from(q.state.rows.values()).sort((s,e)=>e.updatedAtMs-s.updatedAtMs)}function Fn(s){return pe(s)?.title||s}async function Dn(s){const{challenge:e}=await on(s.id);ye([e]),await Ke(s.game,{challenge:{id:s.id,scoreToBeat:s.scoreToBeat,scoreMeta:s.scoreMeta,challengerName:s.challengerName}})}function Un(){const s=window.wp;return Number(s?.desktop?.config?.currentUserId)||0}function Gn(s,e){const t=s.recipientId===e,n=t?s.challengerName:s.recipientName,r=Fn(s.game),i=String(s.scoreToBeat);if(s.state==="pending")return v(b(t?"%1$s challenged you to %2$s — beat %3$s.":"Waiting for %1$s to accept your %2$s challenge (%3$s)."),n,r,i);if(s.state==="accepted")return t?v(b("You accepted — play %1$s and beat %2$s!"),r,i):v(b("%1$s accepted your %2$s challenge and is playing."),n,r);if(s.state==="declined")return v(b(t?"You declined %1$s’s %2$s challenge.":"%1$s declined your %2$s challenge."),n,r);const o=s.result==="beaten",a=String(s.resultScore??0);return t?v(b(o?"You beat the %1$s challenge: %2$s vs %3$s.":"You missed the %1$s challenge: %2$s vs %3$s."),r,a,i):v(b(o?"%1$s beat your score: %2$s vs %3$s.":"%1$s did not beat your score: %2$s vs %3$s."),n,a,i)}function jn(s,e){const t=s.recipientId===e,n=document.createElement("li");n.className=`desktop-mode-games__challenge desktop-mode-games__challenge--${s.state}`;const r=document.createElement("wpd-avatar"),i=t?s.challengerId:s.recipientId;r.setAttribute("src",t?s.challengerAvatar:s.recipientAvatar),r.setAttribute("name",t?s.challengerName:s.recipientName),r.setAttribute("size","sm"),r.setAttribute("user-id",String(i)),n.appendChild(r);const o=document.createElement("div");o.className="desktop-mode-games__challenge-main";const a=document.createElement("p");a.textContent=Gn(s,e),o.appendChild(a);const d=document.createElement("wpd-relative-time");if(d.setAttribute("datetime",new Date(s.updatedAtMs).toISOString()),o.appendChild(d),n.appendChild(o),t&&s.state==="pending"){const l=document.createElement("div");l.className="desktop-mode-games__challenge-actions";const p=document.createElement("wpd-button");p.setAttribute("variant","primary"),p.setAttribute("size","sm"),p.textContent=b("Accept & Play"),p.addEventListener("click",()=>{p.setAttribute("disabled",""),Dn(s).catch(f=>{p.removeAttribute("disabled"),z({message:f instanceof Error?f.message:b("Could not accept the challenge.")})})}),l.appendChild(p);const c=document.createElement("wpd-button");c.setAttribute("variant","ghost"),c.setAttribute("size","sm"),c.textContent=b("Decline"),c.addEventListener("click",()=>{c.setAttribute("disabled",""),an(s.id).then(({challenge:f})=>ye([f])).catch(f=>{c.removeAttribute("disabled"),z({message:f instanceof Error?f.message:b("Could not decline the challenge.")})})}),l.appendChild(c),n.appendChild(l)}return n}function Bn(s,e){s.innerHTML="";const t=document.createElement("ul");t.className="desktop-mode-games__challenge-list",s.appendChild(t);const n=Un(),r=()=>{t.innerHTML="";const o=qn().filter(a=>!e||a.game===e);if(o.length===0){const a=document.createElement("wpd-empty-state");a.setAttribute("icon","awards"),a.setAttribute("heading",b("No challenges yet")),a.setAttribute("description",b("Press Challenge to throw down one of your scores, or pick a row from the scoreboard.")),t.appendChild(a);return}for(const a of o)t.appendChild(jn(a,n))},i=On(r);return r(),sn({box:"all"}).then(({challenges:o})=>ye(o)).catch(o=>{typeof console<"u"&&console.error("[desktop-mode] challenges resync failed:",o)}),i}const Wn="[data-desktop-mode-games-root]",Vn="[data-desktop-mode-games-grid]",Kn="[data-desktop-mode-games-detail]";function Xn(){const s=window.wp;return Number(s?.desktop?.config?.currentUserId)||0}function rt(s){if(s.startsWith("data:")||/^https?:\/\//.test(s)){const t=document.createElement("img");return t.src=s,t.alt="",t.className="desktop-mode-games__icon-img",t}const e=document.createElement("span");return e.className=`dashicons ${s||"dashicons-admin-generic"} desktop-mode-games__icon-dashicon`,e.setAttribute("aria-hidden","true"),e}function Yn(s){const e=s.querySelector(Wn),t=s.querySelector(Vn),n=s.querySelector(Kn);if(!e||!t||!n)return;const r=[];let i=[],o=null;const a=()=>{for(const h of i)try{h()}catch{}i=[]},d=async h=>{const u=Xn(),g=(await Be(h.id,{perPage:1,userId:u})).scores[0];if(!g){z({message:v(b("Play %s first — you need a score to challenge with."),h.title)});return}await Je({game:h.id,gameTitle:h.title,score:g.score,meta:g.meta})},l=h=>{a(),n.hidden=!1,n.innerHTML="";const u=document.createElement("div");u.className="desktop-mode-games__hero";const m=document.createElement("div");m.className="desktop-mode-games__hero-visual",m.appendChild(rt(h.icon)),u.appendChild(m);const g=document.createElement("div");g.className="desktop-mode-games__hero-info";const k=document.createElement("h2");if(k.className="desktop-mode-games__hero-title",k.textContent=h.title,g.appendChild(k),h.description){const C=document.createElement("p");C.className="desktop-mode-games__hero-desc",C.textContent=h.description,g.appendChild(C)}const _=document.createElement("div");_.className="desktop-mode-games__hero-playtime",_.hidden=!0,g.appendChild(_);let x=!1;i.push(()=>{x=!0});const I=(C,ie)=>{const L=document.createElement("span");L.className="desktop-mode-games__playtime-stat";const Ce=document.createElement("span");Ce.className="desktop-mode-games__playtime-label",Ce.textContent=C,L.appendChild(Ce);const Se=document.createElement("span");return Se.className="desktop-mode-games__playtime-value",Se.textContent=ie,L.appendChild(Se),L};tn().then(C=>{const ie=Number(C.playtime[h.id])||0;if(x||ie<1)return;const L=un(C.daily?.[h.id]??{},C.today,14);L>0&&_.appendChild(I(b("Play time (last two weeks)"),We(L))),_.appendChild(I(b("Play time (total)"),We(ie))),_.hidden=!1}).catch(()=>{}),u.appendChild(g);const ne=document.createElement("div");ne.className="desktop-mode-games__hero-actions";const T=document.createElement("wpd-button");T.setAttribute("variant","primary"),T.setAttribute("size","lg"),T.textContent=b("Play"),T.addEventListener("click",()=>{T.setAttribute("disabled",""),Ke(h.id).catch(C=>{typeof console<"u"&&console.error("[desktop-mode] game launch failed:",C)}).finally(()=>{T.removeAttribute("disabled")})}),ne.appendChild(T);const P=document.createElement("wpd-button");P.setAttribute("variant","secondary"),P.textContent=b("Challenge…"),P.addEventListener("click",()=>{P.setAttribute("disabled",""),d(h).finally(()=>{P.removeAttribute("disabled")})}),ne.appendChild(P),u.appendChild(ne),n.appendChild(u);const se=document.createElement("section");se.className="desktop-mode-games__section";const ke=document.createElement("h3");ke.className="desktop-mode-games__section-heading",ke.textContent=b("Scoreboard"),se.appendChild(ke);const it=document.createElement("div");se.appendChild(it),n.appendChild(se),i.push(Mn(it,h));const re=document.createElement("section");re.className="desktop-mode-games__section";const xe=document.createElement("h3");xe.className="desktop-mode-games__section-heading",xe.textContent=b("Challenges"),re.appendChild(xe);const ot=document.createElement("div");re.appendChild(ot),n.appendChild(re),i.push(Bn(ot,h.id))},p=h=>{const u=pe(h);if(u){o=h;for(const m of Array.from(t.querySelectorAll("[data-game-id]"))){const g=m.getAttribute("data-game-id")===h;m.classList.toggle("desktop-mode-games__tile--selected",g),m.setAttribute("aria-selected",g?"true":"false")}l(u)}},c=h=>{const u=document.createElement("button");u.type="button",u.className="desktop-mode-games__tile",u.setAttribute("data-game-id",h.id),u.setAttribute("role","option"),u.setAttribute("aria-selected","false");const m=document.createElement("span");m.className="desktop-mode-games__tile-visual",m.appendChild(rt(h.icon)),u.appendChild(m);const g=document.createElement("span");return g.className="desktop-mode-games__tile-title",g.textContent=h.title,u.appendChild(g),u.addEventListener("click",()=>p(h.id)),u},f=()=>{t.innerHTML="";const h=Fe();if(h.length===0){const m=document.createElement("wpd-empty-state");m.setAttribute("icon","games"),m.setAttribute("heading",b("No games installed")),m.setAttribute("description",b("Plugins can add games with desktop_mode_register_game().")),t.appendChild(m),a(),n.hidden=!0,n.innerHTML="",o=null;return}for(const m of h)t.appendChild(c(m));const u=o&&h.some(m=>m.id===o)?o:h[0].id;p(u)};return f(),r.push(jt(f)),()=>{a();for(const h of r)try{h()}catch{}}}const Zn=window.desktopModeNativeWindows??(window.desktopModeNativeWindows={});Zn["desktop-mode-games"]=Yn})(); | |
| 128 | + `}requestUpdate(){super.requestUpdate(),this._schedulePaint()}_schedulePaint(){this._paintScheduled||!this.isConnected||(this._paintScheduled=!0,queueMicrotask(()=>{this._paintScheduled=!1,this.isConnected&&this._paint()}))}_paint(){const e=this.shadowRoot;if(!e)return;e.querySelector("tbody")||Y(this.render(),e);const t=e.querySelector("colgroup"),s=e.querySelector("thead"),n=e.querySelector("tbody");if(!t||!s||!n)return;const i=this._effectiveColumns();this._stacked=this.hasAttribute("stacked");const r=this._readStickyColumns();this._lastStickyIndex=this._computeLastStickyIndex(i,r),this._paintColgroup(t,i),this._paintHead(s,i,r),this._paintBody(n,i,r),this._applyStickyOffsets(),this._measureHeaderHeight(),this._scheduleStickyOffsets(),this._maybeWarnStickyHeader(),this._maybeWarnLoadingDesync(n),this._ensureResizeObserver()}_maybeWarnLoadingDesync(e){this._loadingDesyncWarned||this.hasAttribute("loading")&&(e.querySelector("tr.skeleton")||(this._loadingDesyncWarned=!0,console.warn("[os-table] `loading` attribute is set but no skeleton rows rendered. Either attributeChangedCallback didn't route through requestUpdate (framework regression), or `loading` was set after the most recent paint and no follow-up trigger ran. Toggling `data` will force a paint as a workaround.")))}_scheduleStickyOffsets(){this._stickyMicroScheduled||(this._stickyMicroScheduled=!0,queueMicrotask(()=>{this._stickyMicroScheduled=!1,this.isConnected&&this._applyStickyOffsets()})),this._stickyRafHandle===null&&typeof requestAnimationFrame<"u"&&(this._stickyRafHandle=requestAnimationFrame(()=>{this._stickyRafHandle=null,this.isConnected&&(this._applyStickyOffsets(),this._measureHeaderHeight())}))}_ensureResizeObserver(){if(this._resizeObserver||typeof ResizeObserver>"u")return;const e=this.shadowRoot?.querySelector(".scroll");e&&(this._resizeObserver=new ResizeObserver(()=>{this.isConnected&&(this._applyStickyOffsets(),this._measureHeaderHeight(),this._stickyHeaderWarned=!1,this._maybeWarnStickyHeader())}),this._resizeObserver.observe(e),this._resizeObserver.observe(this))}_paintColgroup(e,t){const s=[];for(const n of t){const i=document.createElement("col");n.width&&(i.style.width=n.width),s.push(i)}e.replaceChildren(...s)}_paintHead(e,t,s){const n=document.createElement("tr");n.setAttribute("part","header-row");for(let l=0;l<t.length;l++)n.appendChild(this._buildHeaderCell(t[l],l,s));const i=e.querySelector(':scope > tr[part="header-row"]');i?e.replaceChild(n,i):e.insertBefore(n,e.firstChild);const r=t.some(l=>l.filter||Array.isArray(l.filterOptions)||typeof l.filterRender=="function");let a=e.querySelector(":scope > tr.filter-row");if(r){const l=[];for(let c=0;c<t.length;c++)l.push(this._buildFilterCell(t[c],c,s));a||(a=document.createElement("tr"),a.classList.add("filter-row"),a.setAttribute("part","filter-row"),e.appendChild(a));const d=Array.from(a.children);let u=d.length===l.length;if(u){for(let c=0;c<l.length;c++)if(d[c]!==l[c]){u=!1;break}}if(!u){const c=new Set(l);for(const f of l)a.appendChild(f);for(const f of Array.from(a.children))c.has(f)||a.removeChild(f)}}else a&&a.remove()}_buildHeaderCell(e,t,s){const n=document.createElement("th");if(n.setAttribute("scope","col"),n.dataset.key=e.key,this._applyCellClasses(n,e,t,s),e.minWidth&&(n.style.minWidth=e.minWidth),e.key===I){if(this._readSelectable()==="multi"){const r=document.createElement("input");r.type="checkbox",r.className="select-all-checkbox",r.setAttribute("data-noclick",""),r.setAttribute("aria-label","Select all rows");const{total:a,selected:l}=this._visibleSelectionStats();r.checked=a>0&&l===a,r.indeterminate=l>0&&l<a,r.addEventListener("change",()=>{r.checked?this.selectAll():this.clearSelection()}),n.appendChild(r)}return n}if(n.textContent=e.label??(e.key===z?"":e.key),e.sortable){n.classList.add("is-sortable");const i=this._sort?.key===e.key,r=document.createElement("span");r.className="sort-indicator";let a="";i&&(a=this._sort.direction==="asc"?" ▲":" ▼"),r.textContent=a,n.appendChild(r),i&&n.classList.add(this._sort.direction==="asc"?"sort-asc":"sort-desc"),n.addEventListener("click",()=>this._cycleSort(e.key))}return n}_buildFilterCell(e,t,s){const n=this._filterCache.get(e.key),i=Array.isArray(e.filterOptions),r=typeof e.filterRender=="function";let a;if(!e.filter&&!i&&!r||e.key===z||e.key===I?a="none":r?a="custom":e.filter==="select"||i?a="select":a="text",n&&n.kind===a){if(n.th.className="",this._applyCellClasses(n.th,e,t,s),a==="select"){const c=n.control,f=this._resolveFilterOptions(e),p=f.map(h=>h.value).join("|");p!==n.optionsKey?(this._populateSelect(c,f,this._filters[e.key]??""),n.optionsKey=p):c.value=this._filters[e.key]??""}else if(a==="text"){const c=n.control,f=this._filters[e.key]??"";c.value!==f&&c.ownerDocument.activeElement!==c&&(c.value=f)}else a==="custom"&&e.filterRender&&e.filterRender(n.th,{value:this._filters[e.key]??"",setValue:c=>this._onFilterChange(e.key,c),col:e});return n.th}const l=document.createElement("th");if(this._applyCellClasses(l,e,t,s),a==="none")return this._filterCache.set(e.key,{th:l,control:null,optionsKey:"",kind:"none"}),l;if(a==="custom"&&e.filterRender)return e.filterRender(l,{value:this._filters[e.key]??"",setValue:c=>this._onFilterChange(e.key,c),col:e}),this._filterCache.set(e.key,{th:l,control:null,optionsKey:"",kind:"custom"}),l;let d,u="";if(a==="select"){const c=document.createElement("select");c.classList.add("filter-select"),c.setAttribute("data-noclick",""),c.setAttribute("aria-label",`Filter ${e.label??e.key}`);const f=this._resolveFilterOptions(e);this._populateSelect(c,f,this._filters[e.key]??""),u=f.map(p=>p.value).join("|"),c.addEventListener("change",()=>{this._onFilterChange(e.key,c.value)}),d=c}else{const c=document.createElement("input");c.type="search",c.classList.add("filter-input"),c.setAttribute("data-noclick",""),c.setAttribute("placeholder","Filter…"),c.setAttribute("aria-label",`Filter ${e.label??e.key}`),c.value=this._filters[e.key]??"",c.addEventListener("input",()=>{this._onFilterChange(e.key,c.value)}),d=c}return l.appendChild(d),this._filterCache.set(e.key,{th:l,control:d,optionsKey:u,kind:a}),l}_populateSelect(e,t,s){e.replaceChildren();const n=document.createElement("option");n.value="",n.textContent="All",e.appendChild(n);for(const i of t){const r=document.createElement("option");r.value=i.value,r.textContent=i.label,i.value===s&&(r.selected=!0),e.appendChild(r)}e.value=s}_resolveFilterOptions(e){return Array.isArray(e.filterOptions)?e.filterOptions:this._uniqueValues(e.key).map(t=>({value:t,label:t}))}_paintBody(e,t,s){if(e.replaceChildren(),this.hasAttribute("loading")){const i=this._readLoadingRows();for(let r=0;r<i;r++)e.appendChild(this._buildSkeletonRow(t,r));return}const n=this._sortedRows(this._filteredRows());if(n.length===0){e.appendChild(this._buildEmptyRow(t.length));return}for(const{row:i,index:r}of n)if(e.appendChild(this._stacked?this._buildStackedRow(i,r,t):this._buildBodyRow(i,r,t,s)),this._expanded.has(r)&&this._subTable){const a=this._subTable(i,r);a&&e.appendChild(this._buildSubTableRow(a,t.length))}}_buildEmptyRow(e){const t=document.createElement("tr");t.classList.add("empty");const s=document.createElement("td");s.colSpan=e;const n=document.createElement("slot");return n.name="empty",n.textContent=this.getAttribute("empty")||"No data",s.appendChild(n),t.appendChild(s),t}_buildSkeletonRow(e,t){const s=document.createElement("tr");if(s.classList.add("skeleton"),s.setAttribute("aria-hidden","true"),this._stacked){s.classList.add("stack-row");const n=document.createElement("td");n.className="stack-body",n.colSpan=Math.max(1,e.length);for(const i of[55+t*7%25,30+t*11%15]){const r=document.createElement("span");r.className="skeleton-bar",r.style.width=`${i}%`,n.appendChild(r)}return s.appendChild(n),s}for(const n of e){const i=document.createElement("td"),r=document.createElement("span");r.className="skeleton-bar";const a=50+(t*7+s.children.length*13)%40;r.style.width=`${a}%`,i.appendChild(r),s.appendChild(i)}return s}_buildBodyRow(e,t,s,n){const i=document.createElement("tr");i.setAttribute("part","row"),i.dataset.rowIndex=String(t);const r=this._getRowId(e,t);i.dataset.rowId=String(r),this._selection.has(r)&&i.classList.add("is-selected"),i.addEventListener("click",a=>{this._onRowClick(e,t,a)});for(let a=0;a<s.length;a++)i.appendChild(this._buildBodyCell(s[a],a,e,t,n));return i}_buildStackedRow(e,t,s){const n=document.createElement("tr");n.setAttribute("part","row"),n.classList.add("stack-row"),n.dataset.rowIndex=String(t);const i=this._getRowId(e,t);n.dataset.rowId=String(i),this._selection.has(i)&&n.classList.add("is-selected"),n.addEventListener("click",d=>{this._onRowClick(e,t,d)});const r=document.createElement("td");r.className="stack-body";let a=0,l=0;for(let d=0;d<s.length;d++){const u=s[d];if(u.key===I||u.key===z){n.appendChild(this._buildBodyCell(u,d,e,t,0));continue}l++;const c=ps(u,a++);if(c==="hidden")continue;const f=document.createElement("div");if(f.className=`stack-cell stack-${c}`,f.dataset.key=u.key,c==="meta"&&u.label){const b=document.createElement("span");b.className="stack-label",b.textContent=u.label,f.appendChild(b)}const p=document.createElement("span");p.className="stack-value";const h=e[u.key],m=ae(h);u.render?this._mountCellContent(p,u.render(h,e,t)):m!==null?p.appendChild(this._slotFor(m)):h!=null&&(p.textContent=String(h)),f.appendChild(p),r.appendChild(f)}return r.colSpan=Math.max(1,l),n.appendChild(r),n}_buildBodyCell(e,t,s,n,i){const r=document.createElement("td");if(this._applyCellClasses(r,e,t,i),e.minWidth&&(r.style.minWidth=e.minWidth),e.key===I){const d=this._getRowId(s,n),u=document.createElement("input");return u.type="checkbox",u.className="select-row-checkbox",u.setAttribute("data-noclick",""),u.setAttribute("aria-label","Select row"),u.checked=this._selection.has(d),u.addEventListener("change",()=>{u.checked?this.select(d):this.deselect(d)}),r.appendChild(u),this._stacked&&(r.setAttribute("data-noclick",""),r.addEventListener("click",c=>{c.target===r&&(u.checked=!u.checked,u.dispatchEvent(new Event("change")))})),r}if(e.key===z){if(!(this._subTable?!!this._subTable(s,n):!1))return r;const u=this._expanded.has(n),c=document.createElement("button");return c.type="button",c.className="expander",c.setAttribute("data-noclick",""),c.setAttribute("aria-expanded",u?"true":"false"),c.setAttribute("aria-label",u?"Collapse row":"Expand row"),c.textContent=u?"▾":"▸",c.addEventListener("click",f=>{this._toggleRow(n,s,f)}),r.appendChild(c),r}const a=s[e.key],l=ae(a);if(e.render){const d=e.render(a,s,n);this._mountCellContent(r,d)}else l!==null?r.appendChild(this._slotFor(l)):a!=null&&(r.textContent=String(a));return r}_slotFor(e){const t=document.createElement("slot");return t.name=e,t}_buildSubTableRow(e,t){const s=document.createElement("tr");s.classList.add("subtable"),s.setAttribute("part","subtable-row");const n=document.createElement("td");n.colSpan=t;const i=document.createElement("div");if(i.classList.add("subtable-inner"),e instanceof Node)i.appendChild(e);else if(bt(e))Y(e,i);else{const r=document.createElement("os-table");r.columns=e.columns,r.data=e.data,e.subTable&&(r.subTable=e.subTable),i.appendChild(r)}return n.appendChild(i),s.appendChild(n),s}_mountCellContent(e,t){if(typeof t=="string"){e.textContent=t;return}if(t instanceof Node){e.appendChild(t);return}bt(t)&&Y(t,e)}_onFilterChange(e,t){t===""?delete this._filters[e]:this._filters[e]=t,this.emit("os-table-filter-change",{filters:{...this._filters}});const n=this.shadowRoot?.querySelector("tbody");if(n){const i=this._effectiveColumns(),r=this._readStickyColumns();this._lastStickyIndex=this._computeLastStickyIndex(i,r),this._paintBody(n,i,r),this._applyStickyOffsets()}}_onRowClick(e,t,s){const n=s.composedPath?.()??[];for(const i of n){if(i instanceof Element&&i.hasAttribute("data-noclick"))return;if(i===this)break}this.emit("os-table-row-click",{row:e,index:t,originalEvent:s})}_toggleRow(e,t,s){s.stopPropagation();const n=this._expanded.has(e);n?this._expanded.delete(e):this._expanded.add(e),this.emit("os-table-expand-change",{row:t,index:e,expanded:!n}),this._schedulePaint()}_cycleSort(e){!this._sort||this._sort.key!==e?this._sort={key:e,direction:"asc"}:this._sort.direction==="asc"?this._sort={key:e,direction:"desc"}:this._sort=null,this.emit("os-table-sort-change",{sort:this._sort?{...this._sort}:null}),this._schedulePaint()}_emitSelectionChange(){this.emit("os-table-selection-change",{selection:Array.from(this._selection),rows:this.selectedRows})}_filteredRows(){const e=[],t=Object.keys(this._filters).filter(s=>this._filters[s]!=="");for(let s=0;s<this._data.length;s++){const n=this._data[s];let i=!0;for(const r of t){const a=this._columns.find(c=>c.key===r);if(a&&typeof a.filterRender=="function")continue;const l=this._filters[r]??"",d=n[r],u=$e(d);if(a?.filter==="select"){if(u!==l){i=!1;break}}else if(!u.toLowerCase().includes(l.toLowerCase())){i=!1;break}}i&&e.push({row:n,index:s})}return e}_sortedRows(e){if(!this._sort)return e;const t=this._columns.find(i=>i.key===this._sort.key);if(!t)return e;const s=this._sort.direction==="desc"?-1:1,n=e.slice();return n.sort((i,r)=>{const a=i.row[t.key],l=r.row[t.key],d=t.sortValue?t.sortValue(i.row,a):gt(a),u=t.sortValue?t.sortValue(r.row,l):gt(l);return fs(d,u)*s}),n}_uniqueValues(e){const t=new Set;for(const s of this._data){const n=s[e];n!=null&&t.add($e(n))}return Array.from(t).sort()}_visibleSelectionStats(){let e=0,t=0;for(const{row:s,index:n}of this._filteredRows())e++,this._selection.has(this._getRowId(s,n))&&t++;return{total:e,selected:t}}_readStickyColumns(){const e=parseInt(this.getAttribute("sticky-columns")||"0",10);return Number.isFinite(e)&&e>0?e:0}_readLoadingRows(){const e=parseInt(this.getAttribute("loading-rows")||"5",10);return Number.isFinite(e)&&e>0?Math.min(e,100):5}_readSelectable(){const e=this.getAttribute("selectable");return e==="single"?"single":e==="multi"||e===""?"multi":null}_isStickyIndex(e,t,s){return this._stacked||s.sticky===!1?!1:s.sticky===!0?!0:e<t}_computeLastStickyIndex(e,t){let s=-1;for(let n=0;n<e.length;n++)this._isStickyIndex(n,t,e[n])&&(s=n);return s}_applyCellClasses(e,t,s,n){t.key===z&&e.classList.add("col-expander"),t.key===I&&e.classList.add("col-select"),t.align==="center"&&e.classList.add("align-center"),t.align==="end"&&e.classList.add("align-end"),this._isStickyIndex(s,n,t)&&(e.classList.add("is-sticky"),s===this._lastStickyIndex&&e.classList.add("is-sticky-edge"))}_effectiveColumns(){const e=[];return this._readSelectable()&&e.push({key:I,label:"",width:"40px",align:"center"}),this._subTable&&e.push({key:z,label:"",width:"36px",align:"center"}),e.push(...this._columns),e}_applyStickyOffsets(){const e=this.shadowRoot;if(!e)return;const t=e.querySelector("thead tr");if(!t)return;const s=Array.from(t.children),n=[];let i=0;for(let a=0;a<s.length;a++)n[a]=i,s[a].classList.contains("is-sticky")&&(i+=s[a].offsetWidth);e.querySelectorAll("thead tr, tbody tr:not(.subtable):not(.empty):not(.skeleton)").forEach(a=>{const l=Array.from(a.children);for(let d=0;d<l.length;d++)l[d].classList.contains("is-sticky")&&(l[d].style.insetInlineStart=`${n[d]}px`)}),this._maybeWarnStickyOffsetRace(s,n)}_maybeWarnStickyOffsetRace(e,t){if(this._stickyRaceWarned)return;const s=this._readStickyColumns();if(s<2)return;const n=Math.min(s-1,e.length-1);if(n<=0||t[n]!==0||this.offsetWidth===0)return;this._stickyRaceWarned=!0;const i=e[0]?.offsetWidth??0;console.warn(`[os-table] sticky-columns: column ${n} resolved to inset-inline-start: 0px while the host is visible. ths[0].offsetWidth was ${i}px at measurement time. Likely a layout race — call recomputeLayout() after the panel finishes its mount/transition, or wrap the assignment of \`data\` in a requestAnimationFrame.`)}_measureHeaderHeight(){const e=this.shadowRoot;if(!e)return;const t=e.querySelector("thead tr");if(!t)return;const s=t.offsetHeight;s>0&&this.style.setProperty("--os-ui-table-header-height",`${s}px`)}_maybeWarnStickyHeader(){if(this._stickyHeaderWarned||!this.hasAttribute("sticky-header")||this.hasAttribute("loading")||this._data.length<8)return;const e=this.shadowRoot?.querySelector(".scroll");e&&e.offsetWidth!==0&&e.scrollHeight<=e.clientHeight+1&&(this._stickyHeaderWarned=!0,console.warn("[os-table] sticky-header is set but the table has no scroll container. Set --os-ui-table-max-height on the host (or wrap it in a scrolling parent) so the header has something to stick to."))}};X.props=["stickyColumns","stickyHeader","striped","hover","compact","bordered","empty","loading","loadingRows","selectable","stacked"],X.styles=[hs],X.help=void 0;let Ae=X;function bt(o){return!!o&&o.__wpdHtml===!0}function ps(o,e){return o.stack?o.stack:e===0?"title":o.label?"meta":"actions"}function ae(o){return o&&typeof o=="object"&&typeof o.slot=="string"?o.slot:null}function $e(o){if(o==null)return"";if(ae(o)!==null){const e=o.text;return e==null?"":String(e)}return String(o)}function gt(o){return ae(o)!==null?$e(o):o}function fs(o,e){if(o===e)return 0;if(o==null)return-1;if(e==null)return 1;if(typeof o=="number"&&typeof e=="number")return o-e;if(o instanceof Date&&e instanceof Date)return o.getTime()-e.getTime();const t=Number(o),s=Number(e);return Number.isFinite(t)&&Number.isFinite(s)?t-s:String(o).localeCompare(String(e))}R("os-table",Ae);const vt=25;function ms(){const o=window.wp;return Number(o?.os?.config?.currentUserId)||0}function bs(o){const e=Math.max(0,Math.round(Number(o)||0)),t=Math.floor(e/60),s=e%60;return`${t}:${String(s).padStart(2,"0")}`}function gs(o){const e=[{key:"userName",label:g("Player"),render:(t,s)=>{const n=document.createElement("span");n.style.cssText="display:inline-flex;align-items:center;gap:8px;min-width:0;";const i=document.createElement("os-avatar");i.setAttribute("src",s.userAvatar),i.setAttribute("name",s.userName),i.setAttribute("size","xs"),i.setAttribute("user-id",String(s.userId)),n.appendChild(i);const r=document.createElement("span");return r.textContent=s.userName,n.appendChild(r),n}}];for(const t of o.scoreColumns)e.push({key:t.key,label:t.label,render:(s,n)=>{const i=t.key==="score"?n.score:n.meta[t.key];return i==null?"—":t.type==="time"?bs(i):String(i)}});return e.push({key:"createdAtMs",label:g("When"),render:(t,s)=>{const n=document.createElement("os-relative-time");return n.setAttribute("datetime",new Date(s.createdAtMs).toISOString()),n}}),e.push({key:"__actions",label:"",render:(t,s)=>{if(s.userId!==ms())return"";const n=document.createElement("os-button");return n.setAttribute("variant","secondary"),n.setAttribute("size","sm"),n.textContent=g("Challenge…"),n.addEventListener("click",()=>{ht({game:o.id,gameTitle:o.title,score:s.score,meta:s.meta})}),n}}),e}function vs(o,e){o.innerHTML="";const t=document.createElement("div");t.className="os-games__scoreboard-table",o.appendChild(t);const s=document.createElement("div");s.className="os-games__pager",o.appendChild(s);let n=1,i=0,r=0,a=!1;const l=document.createElement("os-table");l.setAttribute("sticky-header",""),l.setAttribute("hover",""),l.setAttribute("striped","");const d=document.createElement("div");d.setAttribute("slot","empty"),d.className="os-games__scoreboard-empty",d.textContent=g("No scores yet — be the first to play!"),l.appendChild(d),t.appendChild(l),l.columns=gs(e),l.data=[];const u=()=>{s.innerHTML="";const p=Math.max(1,Math.ceil(i/vt));if(p<=1)return;const h=document.createElement("os-button");h.setAttribute("variant","ghost"),h.textContent=g("Previous"),n<=1&&h.setAttribute("disabled",""),h.addEventListener("click",()=>void c(n-1));const m=document.createElement("span");m.className="os-games__pager-label",m.textContent=`${n} / ${p}`;const b=document.createElement("os-button");b.setAttribute("variant","ghost"),b.textContent=g("Next"),n>=p&&b.setAttribute("disabled",""),b.addEventListener("click",()=>void c(n+1)),s.append(h,m,b)},c=async p=>{const h=++r;l.setAttribute("loading","");try{const m=await it(e.id,{page:p,perPage:vt});if(a||h!==r)return;n=p,i=m.total,l.data=m.scores}catch(m){typeof console<"u"&&console.error("[openstation] scoreboard load failed:",m)}finally{!a&&h===r&&(l.removeAttribute("loading"),u())}},f=be.subscribe("os/game-score-recorded",p=>{a||p?.game!==e.id||c(n)});return c(1),()=>{a=!0,f()}}ve("desktop-mode/heartbeat-bus",()=>({suppliers:new Map,subscribers:new Map,booted:!1}));function _s(o){return ye(o)?.title||o}async function ys(o){const{challenge:e}=await Ho(o.id);ie([e]),await lt(o.game,{challenge:{id:o.id,scoreToBeat:o.scoreToBeat,scoreMeta:o.scoreMeta,challengerName:o.challengerName}})}function ks(){const o=window.wp;return Number(o?.os?.config?.currentUserId)||0}function xs(o,e){const t=o.recipientId===e,s=t?o.challengerName:o.recipientName,n=_s(o.game),i=String(o.scoreToBeat);if(o.state==="pending")return k(g(t?"%1$s challenged you to %2$s — beat %3$s.":"Waiting for %1$s to accept your %2$s challenge (%3$s)."),s,n,i);if(o.state==="accepted")return t?k(g("You accepted — play %1$s and beat %2$s!"),n,i):k(g("%1$s accepted your %2$s challenge and is playing."),s,n);if(o.state==="declined")return k(g(t?"You declined %1$s’s %2$s challenge.":"%1$s declined your %2$s challenge."),s,n);const r=o.result==="beaten",a=String(o.resultScore??0);return t?k(g(r?"You beat the %1$s challenge: %2$s vs %3$s.":"You missed the %1$s challenge: %2$s vs %3$s."),n,a,i):k(g(r?"%1$s beat your score: %2$s vs %3$s.":"%1$s did not beat your score: %2$s vs %3$s."),s,a,i)}function ws(o,e){const t=o.recipientId===e,s=document.createElement("li");s.className=`os-games__challenge os-games__challenge--${o.state}`;const n=document.createElement("os-avatar"),i=t?o.challengerId:o.recipientId;n.setAttribute("src",t?o.challengerAvatar:o.recipientAvatar),n.setAttribute("name",t?o.challengerName:o.recipientName),n.setAttribute("size","sm"),n.setAttribute("user-id",String(i)),s.appendChild(n);const r=document.createElement("div");r.className="os-games__challenge-main";const a=document.createElement("p");a.textContent=xs(o,e),r.appendChild(a);const l=document.createElement("os-relative-time");if(l.setAttribute("datetime",new Date(o.updatedAtMs).toISOString()),r.appendChild(l),s.appendChild(r),t&&o.state==="pending"){const d=document.createElement("div");d.className="os-games__challenge-actions";const u=document.createElement("os-button");u.setAttribute("variant","primary"),u.setAttribute("size","sm"),u.textContent=g("Accept & Play"),u.addEventListener("click",()=>{u.setAttribute("disabled",""),ys(o).catch(f=>{u.removeAttribute("disabled"),F({message:f instanceof Error?f.message:g("Could not accept the challenge.")})})}),d.appendChild(u);const c=document.createElement("os-button");c.setAttribute("variant","ghost"),c.setAttribute("size","sm"),c.textContent=g("Decline"),c.addEventListener("click",()=>{c.setAttribute("disabled",""),Fo(o.id).then(({challenge:f})=>ie([f])).catch(f=>{c.removeAttribute("disabled"),F({message:f instanceof Error?f.message:g("Could not decline the challenge.")})})}),d.appendChild(c),s.appendChild(d)}return s}function Cs(o,e){o.innerHTML="";const t=document.createElement("ul");t.className="os-games__challenge-list",o.appendChild(t);const s=ks(),n=()=>{t.innerHTML="";const r=Go().filter(a=>!e||a.game===e);if(r.length===0){const a=document.createElement("os-empty-state");a.setAttribute("icon","awards"),a.setAttribute("heading",g("No challenges yet")),a.setAttribute("description",g("Press Challenge to throw down one of your scores, or pick a row from the scoreboard.")),t.appendChild(a);return}for(const a of r)t.appendChild(ws(a,s))},i=Wo(n);return n(),Mo({box:"all"}).then(({challenges:r})=>ie(r)).catch(r=>{typeof console<"u"&&console.error("[openstation] challenges resync failed:",r)}),i}const Ss="[data-os-games-root]",Es="[data-os-games-grid]",As="[data-os-games-detail]";function $s(){const o=window.wp;return Number(o?.os?.config?.currentUserId)||0}function _t(o){if(o.startsWith("data:")||/^https?:\/\//.test(o)){const t=document.createElement("img");return t.src=o,t.alt="",t.className="os-games__icon-img",t}const e=document.createElement("span");return e.className=`dashicons ${o||"dashicons-admin-generic"} os-games__icon-dashicon`,e.setAttribute("aria-hidden","true"),e}function Rs(o){const e=o.querySelector(Ss),t=o.querySelector(Es),s=o.querySelector(As);if(!e||!t||!s)return;const n=[];let i=[],r=null;const a=()=>{for(const p of i)try{p()}catch{}i=[]},l=async p=>{const h=$s(),b=(await it(p.id,{perPage:1,userId:h})).scores[0];if(!b){F({message:k(g("Play %s first — you need a score to challenge with."),p.title)});return}await ht({game:p.id,gameTitle:p.title,score:b.score,meta:b.meta})},d=p=>{a(),s.hidden=!1,s.innerHTML="";const h=document.createElement("div");h.className="os-games__hero";const m=document.createElement("div");m.className="os-games__hero-visual",m.appendChild(_t(p.icon)),h.appendChild(m);const b=document.createElement("div");b.className="os-games__hero-info";const w=document.createElement("h2");if(w.className="os-games__hero-title",w.textContent=p.title,b.appendChild(w),p.description){const S=document.createElement("p");S.className="os-games__hero-desc",S.textContent=p.description,b.appendChild(S)}const y=document.createElement("div");y.className="os-games__hero-playtime",y.hidden=!0,b.appendChild(y);let C=!1;i.push(()=>{C=!0});const M=(S,ue)=>{const L=document.createElement("span");L.className="os-games__playtime-stat";const Te=document.createElement("span");Te.className="os-games__playtime-label",Te.textContent=S,L.appendChild(Te);const Le=document.createElement("span");return Le.className="os-games__playtime-value",Le.textContent=ue,L.appendChild(Le),L};zo().then(S=>{const ue=Number(S.playtime[p.id])||0;if(C||ue<1)return;const L=Uo(S.daily?.[p.id]??{},S.today,14);L>0&&y.appendChild(M(g("Play time (last two weeks)"),rt(L))),y.appendChild(M(g("Play time (total)"),rt(ue))),y.hidden=!1}).catch(()=>{}),h.appendChild(b);const le=document.createElement("div");le.className="os-games__hero-actions";const T=document.createElement("os-button");T.setAttribute("variant","primary"),T.setAttribute("size","lg"),T.textContent=g("Play"),T.addEventListener("click",()=>{T.setAttribute("disabled",""),lt(p.id).catch(S=>{typeof console<"u"&&console.error("[openstation] game launch failed:",S)}).finally(()=>{T.removeAttribute("disabled")})}),le.appendChild(T);const P=document.createElement("os-button");P.setAttribute("variant","secondary"),P.textContent=g("Challenge…"),P.addEventListener("click",()=>{P.setAttribute("disabled",""),l(p).finally(()=>{P.removeAttribute("disabled")})}),le.appendChild(P),h.appendChild(le),s.appendChild(h);const ce=document.createElement("section");ce.className="os-games__section";const Re=document.createElement("h3");Re.className="os-games__section-heading",Re.textContent=g("Scoreboard"),ce.appendChild(Re);const yt=document.createElement("div");ce.appendChild(yt),s.appendChild(ce),i.push(vs(yt,p));const de=document.createElement("section");de.className="os-games__section";const Ne=document.createElement("h3");Ne.className="os-games__section-heading",Ne.textContent=g("Challenges"),de.appendChild(Ne);const kt=document.createElement("div");de.appendChild(kt),s.appendChild(de),i.push(Cs(kt,p.id))},u=p=>{const h=ye(p);if(h){r=p;for(const m of Array.from(t.querySelectorAll("[data-game-id]"))){const b=m.getAttribute("data-game-id")===p;m.classList.toggle("os-games__tile--selected",b),m.setAttribute("aria-selected",b?"true":"false")}d(h)}},c=p=>{const h=document.createElement("button");h.type="button",h.className="os-games__tile",h.setAttribute("data-game-id",p.id),h.setAttribute("role","option"),h.setAttribute("aria-selected","false");const m=document.createElement("span");m.className="os-games__tile-visual",m.appendChild(_t(p.icon)),h.appendChild(m);const b=document.createElement("span");return b.className="os-games__tile-title",b.textContent=p.title,h.appendChild(b),h.addEventListener("click",()=>u(p.id)),h},f=()=>{t.innerHTML="";const p=Je();if(p.length===0){const m=document.createElement("os-empty-state");m.setAttribute("icon","games"),m.setAttribute("heading",g("No games installed")),m.setAttribute("description",g("Plugins can add games with openstation_register_game().")),t.appendChild(m),a(),s.hidden=!0,s.innerHTML="",r=null;return}for(const m of p)t.appendChild(c(m));const h=r&&p.some(m=>m.id===r)?r:p[0].id;u(h)};return f(),n.push(vo(f)),()=>{a();for(const p of n)try{p()}catch{}}}const Ns=window.openStationNativeWindows??(window.openStationNativeWindows={});Ns["desktop-mode-games"]=Rs})(); | |