| @@ -1,12 +1,12 @@ | ||
| 1 | -(function(){"use strict";const Me="desktop-mode";function ye(){return window.wp?.i18n}function _(s,e=Me){return ye()?.__(s,e)??s}function gt(s,e,t,n=Me){return ye()?._n(s,e,t,n)??(t===1?s:e)}function J(s,...e){const t=ye()?.sprintf;if(t)return t(s,...e);let n=0;return s.replace(/%(?:(\d+)\$)?[sd]/g,(o,i)=>{const a=i?Number.parseInt(i,10)-1:n++;return String(e[a]??"")})}class yt extends Error{constructor(e,t,n){super(`[openstation] ${e} registration rejected — fields: `+t.join(", ")+"."),this.name="RegistrationError",this.kind=e,this.errors=t,this.def=n}}function wt(s,e,t){if(e.length!==0)throw new yt(s,e,t)}const $e="__openStationSharedStores";function _t(){const s=window;let e=s[$e];return e||(e=new Map,s[$e]=e),e}function Re(s,e){const t=_t();let n=t.get(s);n||(n={state:e(),listeners:new Set,rebuild:e},t.set(s,n));const o={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(a){console.error(`[desktop-mode/shared-store:${s}] subscriber threw:`,a)}},subscribe(i){return n.listeners.add(i),()=>{n.listeners.delete(i)}},setState(i){const a=n.state;if(typeof a!="object"||a===null){console.warn(`[desktop-mode/shared-store:${s}] setState called on a primitive store; use the state setter instead.`);return}Object.assign(a,i),o.notify()},reset(){const i=n.rebuild(),a=n.state;if(typeof a=="object"&&a!==null&&typeof i=="object"&&i!==null){const c=a;for(const g of Object.keys(c))delete c[g];Object.assign(c,i)}else n.state=i;n.listeners.clear()}};return o}const Oe=Re("desktop-mode/window-actions-registry",()=>({registry:new Map,listeners:new Set})),bt=Oe.state.registry,xt=Oe.state.listeners,Pe=/^[a-z0-9_/-]+$/;function vt(){for(const s of Array.from(xt))try{s()}catch{}}function Ct(s){const e=[];!s||typeof s!="object"?e.push("def (not an object)"):(typeof s.id!="string"||s.id.trim()===""?e.push("id (missing)"):Pe.test(s.id.trim().toLowerCase())||e.push(`id (must match ${Pe} — lowercase alphanum, hyphens, underscores, slashes for vendor/sub-id)`),typeof s.label!="string"&&typeof s.label!="function"?e.push("label (must be a string or a function)"):typeof s.label=="string"&&s.label.trim()===""&&e.push("label (empty)"),typeof s.onSelect!="function"&&e.push("onSelect (must be a function)"),s.isVisible!==void 0&&typeof s.isVisible!="function"&&e.push("isVisible (must be a function when set)"),s.checked!==void 0&&typeof s.checked!="function"?e.push("checked (must be a function when set)"):s.checkable&&typeof s.checked!="function"&&e.push("checked (required when checkable is set)")),wt("WindowAction",e,s);const t=s.id.trim().toLowerCase();bt.set(t,{...s,id:t}),vt()}function oe(s,...e){return{__wpdHtml:!0,strings:s,values:e}}function Et(s){return!!s&&s.__wpdHtml===!0}const St="$$wpd$$",$=/\$\$wpd\$\$(\d+)\$\$/g;function Nt(s){let e=s[0];for(let t=1;t<s.length;t++)e+=`${St}${t-1}$$`+s[t];return e}const De=new WeakMap;function Fe(s){const e=De.get(s);if(e)return e;const t=document.createElement("template");t.innerHTML=Nt(s);const n=[],o=(c,g)=>{if(c.nodeType===Node.ELEMENT_NODE){const u=c;for(const b of Array.from(u.attributes)){const m=b.name,w=b.value,f=m[0];if($.test(w))if($.lastIndex=0,f==="@"){const v=$.exec(w);$.lastIndex=0,n.push({path:g,kind:"event",name:m.slice(1),valueIndex:v?Number(v[1]):0}),u.removeAttribute(m)}else if(f==="."){const v=$.exec(w);$.lastIndex=0,n.push({path:g,kind:"prop",name:m.slice(1),valueIndex:v?Number(v[1]):0}),u.removeAttribute(m)}else if(f==="?"){const v=$.exec(w);$.lastIndex=0,n.push({path:g,kind:"bool",name:m.slice(1),valueIndex:v?Number(v[1]):0}),u.removeAttribute(m)}else{const v=[],N=[];let S=0,k;for($.lastIndex=0;(k=$.exec(w))!==null;)v.push(w.slice(S,k.index)),N.push(Number(k[1])),S=k.index+k[0].length;v.push(w.slice(S)),n.push({path:g,kind:"attr",name:m,template:v,valueIndices:N}),u.setAttribute(m,"")}}}const l=Array.from(c.childNodes);let d=0;for(let u=0;u<l.length;u++){const b=l[u],m=u+d;if(b.nodeType===Node.TEXT_NODE){const w=b.textContent||"";if(!$.test(w)){$.lastIndex=0;continue}$.lastIndex=0;const f=b.parentNode;let v=0,N;const S=[],k=[];for($.lastIndex=0;(N=$.exec(w))!==null;){N.index>v&&S.push(document.createTextNode(w.slice(v,N.index)));const L=document.createTextNode("");S.push(L),k.push({path:[...g,m+S.length-1],kind:"node",valueIndex:Number(N[1])}),v=N.index+N[0].length}v<w.length&&S.push(document.createTextNode(w.slice(v)));for(const L of S)f.insertBefore(L,b);f.removeChild(b),d+=S.length-1,n.push(...k)}else o(b,[...g,m])}};o(t.content,[]);const a={template:t,buildParts:c=>{const g=[];for(const l of n){let d=c;for(const u of l.path)d=d.childNodes[u];l.kind==="node"?g.push({kind:"node",valueIndex:l.valueIndex,child:{anchor:d,state:null}}):l.kind==="attr"?g.push({kind:"attr",element:d,name:l.name,template:l.template,valueIndices:l.valueIndices}):l.kind==="event"?g.push({kind:"event",valueIndex:l.valueIndex,element:d,name:l.name}):l.kind==="prop"?g.push({kind:"prop",valueIndex:l.valueIndex,element:d,name:l.name}):l.kind==="bool"&&g.push({kind:"bool",valueIndex:l.valueIndex,element:d,name:l.name})}return g}};return De.set(s,a),a}const Ve=new WeakMap;function kt(s,e){for(const t of s.nodes)if(t.parentNode!==e)return!1;return!0}function Tt(s,e){const t=Ve.get(e);if(t&&t.strings===s.strings&&kt(t,e)){ie(t.parts,s.values);return}const n=Fe(s.strings),o=n.template.content.cloneNode(!0),i=n.buildParts(o),a=Array.from(o.childNodes);for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(o),ie(i,s.values),Ve.set(e,{strings:s.strings,parts:i,nodes:a})}function ie(s,e){for(const t of s)if(t.kind==="node")we(t.child,e[t.valueIndex]);else if(t.kind==="attr"){let n=t.template[0];for(let o=0;o<t.valueIndices.length;o++)n+=We(e[t.valueIndices[o]]),n+=t.template[o+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 we(s,e){if(e==null||e===!1){s.state&&(W(s.state),s.state=null);return}if(Array.isArray(e)){Mt(s,e);return}if(Et(e)){It(s,e);return}if(e instanceof Node){At(s,e);return}Lt(s,We(e))}function At(s,e){const t=s.state;t?.shape==="node"&&t.node===e||(t&&W(t),re(s,[e]),s.state={shape:"node",node:e})}function Lt(s,e){const t=s.state;if(t?.shape==="text"){t.text!==e&&(t.node.textContent=e,t.text=e);return}t&&W(t);const n=document.createTextNode(e);re(s,[n]),s.state={shape:"text",node:n,text:e}}function It(s,e){const t=s.state;if(t?.shape==="template"&&t.strings===e.strings){ie(t.parts,e.values);return}t&&W(t);const n=Fe(e.strings),o=n.template.content.cloneNode(!0),i=n.buildParts(o),a=Array.from(o.childNodes);re(s,[o]),ie(i,e.values),s.state={shape:"template",strings:e.strings,parts:i,nodes:a}}function Mt(s,e){const t=s.state;if(t?.shape==="array"&&t.entries.length===e.length){for(let o=0;o<e.length;o++)we(t.entries[o],e[o]);return}t&&W(t);const n=[];for(const o of e){const i=document.createTextNode("");re(s,[i]);const a={anchor:i,state:null};we(a,o),n.push(a)}s.state={shape:"array",entries:n}}function re(s,e){const t=s.anchor.parentNode;if(t)for(const n of e)t.insertBefore(n,s.anchor)}function W(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&&(W(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&&W(e.state),e.anchor.remove()}function We(s){return s==null||s===!1?"":String(s)}const F=class F 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,n){if(t===n)return;const o=$t(e);this._propValues[o]=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(o=>String(o).trim()).filter(o=>o!=="");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=He(t);Object.defineProperty(this,t,{get:()=>t in this._propValues?this._propValues[t]:this.getAttribute(n),set:o=>{let i;o==null||o===!1?i=null:o===!0?i="":i=String(o),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&&Tt(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 o=document.createElement("style");o.textContent=n.cssText,this.shadowRoot.appendChild(o)}}}else this._adoptLightStyles(e)}_adoptLightStyles(e){if(!F._lightStylesAdopted.has(e)){F._lightStylesAdopted.add(e);for(const t of e.styles){const n=document.createElement("style");n.dataset.osUi=this.tagName.toLowerCase(),n.textContent=t.cssText,document.head.appendChild(n)}}}};F.props=[],F.styles=[],F.shadow=!0,F._lightStylesAdopted=new WeakSet;let ae=F;function Ge(s,e){customElements.get(s)||customElements.define(s,e)}function He(s){return s.replace(/[A-Z]/g,e=>"-"+e.toLowerCase())}function $t(s){return s.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}const Rt=(()=>{try{return typeof new CSSStyleSheet().replaceSync=="function"}catch{return!1}})();function Ue(s,...e){let t=s[0];for(let n=1;n<s.length;n++){const o=e[n-1];if(typeof o=="string"||typeof o=="number")t+=String(o);else if(o&&o.__wpdCss)t+=o.cssText;else throw new TypeError("[os-ui] css`` interpolations must be strings, numbers, or other css`` results. Got: "+typeof o);t+=s[n]}if(Rt){const n=new CSSStyleSheet;return n.replaceSync(t),{__wpdCss:!0,sheet:n,cssText:t}}return{__wpdCss:!0,sheet:null,cssText:t}}const Ot=Ue`: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 ce=null;function Pt(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 ze(){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 o of Array.from(n)){const i=o;if(!i||!i.selectorText)continue;const a=i.selectorText.match(/\.dashicons-([a-z0-9-]+)::?before/i);if(!a)continue;const c=i.style?.content;if(!c)continue;const g=Pt(c);g&&s.set(a[1],g)}}return s}function _e(s){ce||(ce=ze());const e=s.startsWith("dashicons-")?s.slice(10):s;return ce.get(e)??null}function Dt(){ce=ze()}let Be=!1;function Ft(){if(Be||typeof window>"u")return;Be=!0;const s=()=>{Dt()};document.readyState==="loading"&&document.addEventListener("DOMContentLoaded",s,{once:!0}),window.addEventListener("load",s,{once:!0})}Ft();const ee=class ee extends ae{render(){const e=this.name||"",t=e.startsWith("dashicons-")?e.slice(10):e,n=this.size;n&&/^\d+$/.test(n)&&this.style.setProperty("--os-ui-icon-size",`${n}px`);const o=_e(t);return o?oe`<span | |
| 1 | +(function(){"use strict";const Pe="desktop-mode";function _e(){return window.wp?.i18n}function y(s,e=Pe){return _e()?.__(s,e)??s}function vt(s,e,t,n=Pe){return _e()?._n(s,e,t,n)??(t===1?s:e)}function te(s,...e){const t=_e()?.sprintf;if(t)return t(s,...e);let n=0;return s.replace(/%(?:(\d+)\$)?[sd]/g,(o,i)=>{const r=i?Number.parseInt(i,10)-1:n++;return String(e[r]??"")})}class Ct extends Error{constructor(e,t,n){super(`[openstation] ${e} registration rejected — fields: `+t.join(", ")+"."),this.name="RegistrationError",this.kind=e,this.errors=t,this.def=n}}function Et(s,e,t){if(e.length!==0)throw new Ct(s,e,t)}const De="__openStationSharedStores";function St(){const s=window;let e=s[De];return e||(e=new Map,s[De]=e),e}function xe(s,e){const t=St();let n=t.get(s);n||(n={state:e(),listeners:new Set,rebuild:e},t.set(s,n));const o={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(r){console.error(`[desktop-mode/shared-store:${s}] subscriber threw:`,r)}},subscribe(i){return n.listeners.add(i),()=>{n.listeners.delete(i)}},setState(i){const r=n.state;if(typeof r!="object"||r===null){console.warn(`[desktop-mode/shared-store:${s}] setState called on a primitive store; use the state setter instead.`);return}Object.assign(r,i),o.notify()},reset(){const i=n.rebuild(),r=n.state;if(typeof r=="object"&&r!==null&&typeof i=="object"&&i!==null){const c=r;for(const u of Object.keys(c))delete c[u];Object.assign(c,i)}else n.state=i;n.listeners.clear()}};return o}const Fe=xe("desktop-mode/window-actions-registry",()=>({registry:new Map,listeners:new Set})),Nt=Fe.state.registry,kt=Fe.state.listeners,We=/^[a-z0-9_/-]+$/;function At(){for(const s of Array.from(kt))try{s()}catch{}}function Tt(s){const e=[];!s||typeof s!="object"?e.push("def (not an object)"):(typeof s.id!="string"||s.id.trim()===""?e.push("id (missing)"):We.test(s.id.trim().toLowerCase())||e.push(`id (must match ${We} — lowercase alphanum, hyphens, underscores, slashes for vendor/sub-id)`),typeof s.label!="string"&&typeof s.label!="function"?e.push("label (must be a string or a function)"):typeof s.label=="string"&&s.label.trim()===""&&e.push("label (empty)"),typeof s.onSelect!="function"&&e.push("onSelect (must be a function)"),s.isVisible!==void 0&&typeof s.isVisible!="function"&&e.push("isVisible (must be a function when set)"),s.checked!==void 0&&typeof s.checked!="function"?e.push("checked (must be a function when set)"):s.checkable&&typeof s.checked!="function"&&e.push("checked (required when checkable is set)")),Et("WindowAction",e,s);const t=s.id.trim().toLowerCase();Nt.set(t,{...s,id:t}),At()}function ae(s,...e){return{__wpdHtml:!0,strings:s,values:e}}function It(s){return!!s&&s.__wpdHtml===!0}const Lt="$$wpd$$",$=/\$\$wpd\$\$(\d+)\$\$/g,Mt="$$wpd-node$$",$t=/^\$\$wpd-node\$\$(\d+)\$\$$/,Rt=new Set(["style","script","textarea","title"]);function Ot(s){let e="",t=!1,n=null,o=!1,i=null,r="",c=!1;for(let u=0;u<s.length;u++){const d=s[u];e+=d;for(let l=0;l<d.length;l++){const p=d[l];if(o){d.startsWith("-->",l)&&(o=!1,l+=2);continue}if(i!==null){p==="<"&&d[l+1]==="/"&&d.slice(l+2,l+2+i.length).toLowerCase()===i&&(l+=1+i.length,i=null,t=!0,c=!1,r="");continue}if(n!==null){p===n&&(n=null);continue}if(t){p==='"'||p==="'"?(n=p,c=!1):p===">"?(t=!1,c=!1,Rt.has(r)&&(i=r),r=""):c&&(/[a-zA-Z0-9-]/.test(p)?r+=p.toLowerCase():c=!1);continue}if(d.startsWith("<!--",l)){o=!0,l+=3;continue}const b=d[l+1]??"";p==="<"&&/[a-zA-Z/!]/.test(b)&&(t=!0,r="",c=/[a-zA-Z]/.test(b))}u<s.length-1&&(e+=t||o||i!==null?`${Lt}${u}$$`:`<!--${Mt}${u}$$-->`)}return e}const Ve=new WeakMap;function Ge(s){const e=Ve.get(s);if(e)return e;const t=document.createElement("template");t.innerHTML=Ot(s);const n=[],o=(c,u)=>{if(c.nodeType===Node.ELEMENT_NODE){const p=c;for(const b of Array.from(p.attributes)){const g=b.name,_=b.value,m=g[0];if($.test(_))if($.lastIndex=0,m==="@"){const v=$.exec(_);$.lastIndex=0,n.push({path:u,kind:"event",name:g.slice(1),valueIndex:v?Number(v[1]):0}),p.removeAttribute(g)}else if(m==="."){const v=$.exec(_);$.lastIndex=0,n.push({path:u,kind:"prop",name:g.slice(1),valueIndex:v?Number(v[1]):0}),p.removeAttribute(g)}else if(m==="?"){const v=$.exec(_);$.lastIndex=0,n.push({path:u,kind:"bool",name:g.slice(1),valueIndex:v?Number(v[1]):0}),p.removeAttribute(g)}else{const v=[],E=[];let k=0,N;for($.lastIndex=0;(N=$.exec(_))!==null;)v.push(_.slice(k,N.index)),E.push(Number(N[1])),k=N.index+N[0].length;v.push(_.slice(k)),n.push({path:u,kind:"attr",name:g,template:v,valueIndices:E}),p.setAttribute(g,"")}}}const d=Array.from(c.childNodes);let l=0;for(let p=0;p<d.length;p++){const b=d[p],g=p+l;if(b.nodeType===Node.COMMENT_NODE){const _=$t.exec(b.data);if(_){const m=document.createTextNode("");b.parentNode.replaceChild(m,b),n.push({path:[...u,g],kind:"node",valueIndex:Number(_[1])})}continue}if(b.nodeType===Node.TEXT_NODE){const _=b.textContent||"";if(!$.test(_)){$.lastIndex=0;continue}$.lastIndex=0;const m=b.parentNode;let v=0,E;const k=[],N=[];for($.lastIndex=0;(E=$.exec(_))!==null;){E.index>v&&k.push(document.createTextNode(_.slice(v,E.index)));const I=document.createTextNode("");k.push(I),N.push({path:[...u,g+k.length-1],kind:"node",valueIndex:Number(E[1])}),v=E.index+E[0].length}v<_.length&&k.push(document.createTextNode(_.slice(v)));for(const I of k)m.insertBefore(I,b);m.removeChild(b),l+=k.length-1,n.push(...N)}else o(b,[...u,g])}};o(t.content,[]);const r={template:t,buildParts:c=>{const u=[];for(const d of n){let l=c;for(const p of d.path)l=l.childNodes[p];d.kind==="node"?u.push({kind:"node",valueIndex:d.valueIndex,child:{anchor:l,state:null}}):d.kind==="attr"?u.push({kind:"attr",element:l,name:d.name,template:d.template,valueIndices:d.valueIndices}):d.kind==="event"?u.push({kind:"event",valueIndex:d.valueIndex,element:l,name:d.name}):d.kind==="prop"?u.push({kind:"prop",valueIndex:d.valueIndex,element:l,name:d.name}):d.kind==="bool"&&u.push({kind:"bool",valueIndex:d.valueIndex,element:l,name:d.name})}return u}};return Ve.set(s,r),r}const He=new WeakMap;function Pt(s,e){for(const t of s.nodes)if(t.parentNode!==e)return!1;return!0}function Dt(s,e){const t=He.get(e);if(t&&t.strings===s.strings&&Pt(t,e)){ce(t.parts,s.values);return}const n=Ge(s.strings),o=n.template.content.cloneNode(!0),i=n.buildParts(o),r=Array.from(o.childNodes);for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(o),ce(i,s.values),He.set(e,{strings:s.strings,parts:i,nodes:r})}function ce(s,e){for(const t of s)if(t.kind==="node")le(t.child,e[t.valueIndex]);else if(t.kind==="attr"){let n=t.template[0];for(let o=0;o<t.valueIndices.length;o++)n+=ze(e[t.valueIndices[o]]),n+=t.template[o+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 le(s,e){if(e==null||e===!1){s.state&&(D(s.state),s.state=null);return}if(Array.isArray(e)){Gt(s,e);return}if(It(e)){Vt(s,e);return}if(e instanceof Node){Ft(s,e);return}Wt(s,ze(e))}function Ft(s,e){const t=s.state;t?.shape==="node"&&t.node===e||(t&&D(t),ne(s,[e]),s.state={shape:"node",node:e})}function Wt(s,e){const t=s.state;if(t?.shape==="text"){t.text!==e&&(t.node.textContent=e,t.text=e);return}t&&D(t);const n=document.createTextNode(e);ne(s,[n]),s.state={shape:"text",node:n,text:e}}function Vt(s,e){const t=s.state;if(t?.shape==="template"&&t.strings===e.strings){ce(t.parts,e.values);return}t&&D(t);const n=Ge(e.strings),o=n.template.content.cloneNode(!0),i=n.buildParts(o),r=Array.from(o.childNodes);ne(s,[o]),ce(i,e.values),s.state={shape:"template",strings:e.strings,parts:i,nodes:r}}function Gt(s,e){const t=s.state;if(t?.shape==="array"){const o=Math.min(t.entries.length,e.length);for(let i=0;i<o;i++)le(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&&D(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("");ne(s,[r]);const c={anchor:r,state:null};le(c,e[i]),t.entries.push(c)}return}t&&D(t);const n=[];for(const o of e){const i=document.createTextNode("");ne(s,[i]);const r={anchor:i,state:null};le(r,o),n.push(r)}s.state={shape:"array",entries:n}}function ne(s,e){const t=s.anchor.parentNode;if(t)for(const n of e)t.insertBefore(n,s.anchor)}function D(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&&(D(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&&D(e.state),e.anchor.remove()}function ze(s){return s==null||s===!1?"":String(s)}const W=class W 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(Be)}connectedCallback(){this._adoptStyles(),this.requestUpdate()}attributeChangedCallback(e,t,n){if(t===n)return;const o=Ht(e);this._propValues[o]=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(o=>String(o).trim()).filter(o=>o!=="");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=Be(t);Object.defineProperty(this,t,{get:()=>t in this._propValues?this._propValues[t]:this.getAttribute(n),set:o=>{let i;o==null||o===!1?i=null:o===!0?i="":i=String(o),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&&Dt(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 o=document.createElement("style");o.textContent=n.cssText,this.shadowRoot.appendChild(o)}}}else this._adoptLightStyles(e)}_adoptLightStyles(e){if(!W._lightStylesAdopted.has(e)){W._lightStylesAdopted.add(e);for(const t of e.styles){const n=document.createElement("style");n.dataset.osUi=this.tagName.toLowerCase(),n.textContent=t.cssText,document.head.appendChild(n)}}}};W.props=[],W.styles=[],W.shadow=!0,W._lightStylesAdopted=new WeakSet;let de=W;function Ue(s,e){customElements.get(s)||customElements.define(s,e)}function Be(s){return s.replace(/[A-Z]/g,e=>"-"+e.toLowerCase())}function Ht(s){return s.replace(/-([a-z])/g,(e,t)=>t.toUpperCase())}const zt=(()=>{try{return typeof new CSSStyleSheet().replaceSync=="function"}catch{return!1}})();function Ye(s,...e){let t=s[0];for(let n=1;n<s.length;n++){const o=e[n-1];if(typeof o=="string"||typeof o=="number")t+=String(o);else if(o&&o.__wpdCss)t+=o.cssText;else throw new TypeError("[os-ui] css`` interpolations must be strings, numbers, or other css`` results. Got: "+typeof o);t+=s[n]}if(zt){const n=new CSSStyleSheet;return n.replaceSync(t),{__wpdCss:!0,sheet:n,cssText:t}}return{__wpdCss:!0,sheet:null,cssText:t}}const Ut=Ye`: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 he=null;function Bt(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 qe(){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 o of Array.from(n)){const i=o;if(!i||!i.selectorText)continue;const r=i.selectorText.match(/\.dashicons-([a-z0-9-]+)::?before/i);if(!r)continue;const c=i.style?.content;if(!c)continue;const u=Bt(c);u&&s.set(r[1],u)}}return s}function ve(s){he||(he=qe());const e=s.startsWith("dashicons-")?s.slice(10):s;return he.get(e)??null}function Yt(){he=qe()}let Xe=!1;function qt(){if(Xe||typeof window>"u")return;Xe=!0;const s=()=>{Yt()};document.readyState==="loading"&&document.addEventListener("DOMContentLoaded",s,{once:!0}),window.addEventListener("load",s,{once:!0})}qt();const se=class se extends de{render(){const e=this.name||"",t=e.startsWith("dashicons-")?e.slice(10):e,n=this.size;n&&/^\d+$/.test(n)&&this.style.setProperty("--os-ui-icon-size",`${n}px`);const o=ve(t);return o?ae`<span | |
| 2 | 2 | class="os-icon__glyph os-icon__glyph--char dashicons dashicons-${t}" |
| 3 | 3 | aria-hidden="true" |
| 4 | - >${o}</span>`:oe`<span | |
| 4 | + >${o}</span>`:ae`<span | |
| 5 | 5 | class="os-icon__glyph dashicons dashicons-${t}" |
| 6 | 6 | aria-hidden="true" |
| 7 | - ></span>`}};ee.props=["name","size"],ee.styles=[Ot],ee.help=void 0;let be=ee;Ge("os-icon",be);const Vt=Ue`: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}`,te=class te extends ae{render(){const e=this.icon||"",t=this.heading||"",n=this.description||"";return oe` | |
| 8 | - ${e?oe`<os-icon | |
| 7 | + ></span>`}};se.props=["name","size"],se.styles=[Ut],se.help=void 0;let Ce=se;Ue("os-icon",Ce);const Xt=Ye`: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}`,oe=class oe extends de{render(){const e=this.icon||"",t=this.heading||"",n=this.description||"";return ae` | |
| 8 | + ${e?ae`<os-icon | |
| 9 | 9 | class="os-empty-state__icon" |
| 10 | 10 | name=${e} |
| 11 | 11 | size="28" |
| 12 | 12 | ></os-icon>`:null} |
| @@ -15,5 +15,5 @@ | ||
| 15 | 15 | <div class="os-empty-state__cta"> |
| 16 | 16 | <slot name="cta"></slot> |
| 17 | 17 | </div> |
| 18 | 18 | <slot></slot> |
| 19 | - `}};te.props=["icon","heading","description"],te.styles=[Vt],te.help=void 0;let xe=te;Ge("os-empty-state",xe);function Wt(s){if(s.nodes>0)return s.edges>0?{kind:"none"}:{kind:"no-threads"};if(s.activeTypes.length===0&&s.types.length>0)return{kind:"all-off"};const e=new Set(s.activeTypes),t=s.types.some(o=>typeof o.count=="number");let n=0;for(const o of s.types)e.has(o.slug)||(n+=t?o.count??0:1);return n>0?{kind:"filtered-out"}:{kind:"no-content"}}const Gt="os-content-graph__empty",ve="os-content-graph__hint";function Ht(s){let e=null,t="none",n={kind:"none"},o=!1;const i=()=>{e?.remove(),e=null,t="none"},a=(d,u,b)=>{const m=document.createElement("os-empty-state");return m.className=Gt,m.setAttribute("icon",d),m.setAttribute("heading",u),m.setAttribute("description",b),m},c=(d,u)=>{const b=document.createElement("div");b.className=ve,b.setAttribute("role","note");const m=document.createElement("strong");m.className=`${ve}-title`,m.textContent=d;const w=document.createElement("p");return w.className=`${ve}-body`,w.textContent=u,b.append(m,w),b},g=d=>{switch(d.kind){case"none":return null;case"no-content":return a("admin-post",_("Nothing on the board yet"),_("Publish a post or a page and it is pinned here. Threads are drawn between posts when one links to another."));case"filtered-out":return a("filter",_("Nothing to show for these types"),_("The post types switched on in the toolbar have no content yet. Switch another one on to see its posts."));case"all-off":return a("filter",_("Every post type is switched off"),_("Switch a type back on in the toolbar to see its posts."));case"no-threads":return c(_("No threads yet"),_("A thread joins two posts when one links to the other. Click a node to see its author, terms, comments, media and revisions, or group the board by category, tag, author, year or month from the toolbar."))}},l=()=>{const d=o&&n.kind==="no-threads"?{kind:"none"}:n;if(d.kind===t)return;i();const u=g(d);u&&(s.appendChild(u),e=u,t=d.kind)};return{set:d=>{n=d,l()},setSuppressed:d=>{o=d,l()},destroy:i}}const Ut=400,Y="os-content-graph__loading--visible";function zt(s,e=Ut){let t=null;const n=()=>{t!==null&&(clearTimeout(t),t=null)};return s&&(s.hidden=!1,s.classList.remove(Y)),{show:()=>{!s||t!==null||s.classList.contains(Y)||(t=setTimeout(()=>{t=null,s.classList.add(Y)},e))},hide:()=>{n(),s?.classList.remove(Y)},destroy:()=>{n(),s?.classList.remove(Y)},isVisible:()=>!!s?.classList.contains(Y)}}const Bt="http://localhost/";function Ce(s,e){const t=typeof window<"u"&&window.location?window.location.href:Bt,n=new URL(s,t),o=e.replace(/^\/+/,""),i=o.indexOf("?"),a=i===-1?o:o.slice(0,i),c=i===-1?"":o.slice(i+1);if(n.searchParams.has("rest_route")){const g=n.searchParams.get("rest_route")??"/",l=g.endsWith("/")?g:g+"/";n.searchParams.set("rest_route",l+a)}else{const g=n.pathname.endsWith("/")?n.pathname:n.pathname+"/";n.pathname=g+a}return c&&new URLSearchParams(c).forEach((l,d)=>{n.searchParams.append(d,l)}),n.toString()}const Ye="X-WP-Nonce";function Yt(s,e){const t=qt();if(!t)return e;const n=Kt(s);if(!n||!Xt(n))return e;const o=e?.headers??(typeof Request<"u"&&s instanceof Request?s.headers:void 0),i=new Headers(o??{});return i.has(Ye)?e:(i.set(Ye,t),{...e??{},headers:i})}function qt(){if(typeof window>"u")return;const e=window.openStationConfig?.restNonce;return typeof e=="string"&&e.length>0?e:void 0}function Kt(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 Xt(s){return typeof window>"u"||!window.location||s.origin!==window.location.origin?!1:!!(s.pathname.includes("/wp-json/")||s.searchParams.has("rest_route"))}function q(s,e,t={}){const n=window.wp?.os?.fetch;if(typeof n=="function")return n(s,e,t);const o=Yt(s,e);return fetch(s,o)}const G="desktop-mode-content-graph",K="desktop-mode/content-graph";function qe(){const e=(window.openStationWindowConfig??{})[G];if(!e)throw new Error("Corkboard config missing — openstation_register_window args lost in transit.");return e}function X(s){return{Accept:"application/json","X-WP-Nonce":s.restNonce}}async function jt(s){const e=await q(`${s.apiBase}/post-types`,{headers:X(s)},{source:K,windowId:G});if(!e.ok)throw new Error(`post-types: ${e.status}`);return await e.json()}async function Zt(s,e){const t=new URL(`${s.apiBase}/nodes`);t.searchParams.set("types",e.join(","));const n=await q(t.toString(),{headers:X(s)},{source:K,windowId:G});if(!n.ok)throw new Error(`nodes: ${n.status}`);return await n.json()}async function Qt(s,e){const t=await q(`${s.apiBase}/post/${e}`,{headers:X(s)},{source:K,windowId:G});if(!t.ok)throw new Error(`post/${e}: ${t.status}`);return await t.json()}async function Jt(s,e){const t=await q(Ce(s.restRoot,`desktop-mode/v1/user-stats/${e}`),{headers:X(s)},{source:K,windowId:G});if(!t.ok)throw new Error(`user-stats/${e}: ${t.status}`);return await t.json()}async function en(s,e,t){const n=await q(Ce(s.restRoot,`desktop-mode/v1/term-stats/${encodeURIComponent(e)}/${t}`),{headers:X(s)},{source:K,windowId:G});if(!n.ok)throw new Error(`term-stats/${e}/${t}: ${n.status}`);return await n.json()}async function tn(s,e){const t=await q(Ce(s.restRoot,`desktop-mode/v1/comment-stats/${e}`),{headers:X(s)},{source:K,windowId:G});if(!t.ok)throw new Error(`comment-stats/${e}: ${t.status}`);return await t.json()}const le="none";function nn(s,e,t){s.replaceChildren();const n=new Set(e.map(w=>w.slug)),o=document.createElement("div");o.className="os-content-graph__filters",s.appendChild(o);for(const w of e){const f=document.createElement("button");f.type="button",f.className="os-content-graph__chip is-active",f.dataset.slug=w.slug,f.innerHTML=`<span class="dashicons ${Ke(w.icon)}" aria-hidden="true"></span><span class="os-content-graph__chip-label">${de(w.label)}</span><span class="os-content-graph__chip-count">${w.count}</span>`,f.addEventListener("click",()=>{n.has(w.slug)?(n.delete(w.slug),f.classList.remove("is-active")):(n.add(w.slug),f.classList.add("is-active")),t.onTypesChange(Array.from(n))}),o.appendChild(f)}const i=document.createElement("div");i.className="os-content-graph__search";const a=document.createElement("input");a.type="search",a.className="os-content-graph__search-input",a.placeholder=_("Search nodes…"),a.setAttribute("aria-label",_("Search posts and pages in the graph")),i.appendChild(a);const c=document.createElement("ul");c.className="os-content-graph__search-results",c.hidden=!0,i.appendChild(c),s.appendChild(i);const g=()=>{const w=a.value.trim().toLowerCase();if(w.length===0){c.hidden=!0,c.replaceChildren();return}const f=t.getNodes().filter(v=>v.title.toLowerCase().includes(w)).slice(0,10);c.replaceChildren();for(const v of f){const N=document.createElement("li"),S=document.createElement("button");S.type="button",S.className="os-content-graph__search-result",S.innerHTML=`<span class="os-content-graph__search-title">${de(v.title||"#"+v.id)}</span><span class="os-content-graph__search-type">${de(v.type)}</span>`,S.addEventListener("click",()=>{a.value="",c.hidden=!0,c.replaceChildren(),t.onSearchSelect(v)}),N.appendChild(S),c.appendChild(N)}c.hidden=f.length===0};a.addEventListener("input",g),a.addEventListener("focus",g),a.addEventListener("blur",()=>{setTimeout(()=>{c.hidden=!0},120)});const l=document.createElement("os-select");l.className="os-content-graph__group-by",l.setAttribute("value",le),l.setAttribute("aria-label",_("Group by")),l.title=_("Group posts by a shared facet");for(const[w,f]of[[le,_("No grouping")],["category",_("Group by category")],["tag",_("Group by tag")],["author",_("Group by author")],["year",_("Group by year")],["year_month",_("Group by year-month")]]){const v=document.createElement("os-option");v.setAttribute("value",w),v.textContent=f,l.appendChild(v)}l.addEventListener("os-pick",w=>{const v=w.detail?.value??le,N=v===le?null:v;t.onGroupChange(N)}),s.insertBefore(l,i);const d=document.createElement("div");d.className="os-content-graph__actions";const u=document.createElement("button");u.type="button",u.className="os-content-graph__btn",u.innerHTML=`<span class="dashicons dashicons-editor-expand" aria-hidden="true"></span><span>${de(_("Fit"))}</span>`,u.title=_("Fit graph to view"),u.addEventListener("click",()=>t.onFitToView()),d.appendChild(u);const b=document.createElement("span");b.className="os-content-graph__toolbar-status",d.appendChild(b),s.appendChild(d);const m=w=>{i.contains(w.target)||(c.hidden=!0)};return document.addEventListener("click",m),{setStatus:w=>{b.textContent=w},updateCounts:w=>{for(const f of w){const v=o.querySelector(`.os-content-graph__chip[data-slug="${Ke(f.slug)}"] .os-content-graph__chip-count`);v&&(v.textContent=String(f.count??0))}},destroy:()=>{document.removeEventListener("click",m)}}}function de(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Ke(s){return s.replace(/[^a-zA-Z0-9 _\-]/g,"")}function H(s){const e=document.createElement("textarea");return e.innerHTML=s,e.value}function sn(s,e,t){s.replaceChildren(),s.hidden=!1,s.classList.add("os-content-graph__panel--closed");const n=r=>{s.classList.toggle("os-content-graph__panel--closed",!r)};let o=null,i={kind:"post"},a=0;const c=document.createElement("div");c.className="os-content-graph__panel-frame";const g=document.createElement("nav");g.className="os-content-graph__panel-breadcrumb",g.hidden=!0;const l=document.createElement("header");l.className="os-content-graph__panel-head";const d=document.createElement("div");d.className="os-content-graph__panel-title-wrap";const u=document.createElement("h2");u.className="os-content-graph__panel-title";const b=document.createElement("p");b.className="os-content-graph__panel-meta",d.appendChild(u),d.appendChild(b);const m=document.createElement("button");m.type="button",m.className="os-content-graph__panel-close",m.innerHTML='<span class="dashicons dashicons-no-alt" aria-hidden="true"></span>',m.title=_("Close panel"),m.addEventListener("click",()=>t.onClose()),l.appendChild(d),l.appendChild(m);const w=document.createElement("div");w.className="os-content-graph__panel-body",c.appendChild(g),c.appendChild(l),c.appendChild(w),s.appendChild(c);let f=S();w.append(f);let v=null,N=0;function S(){const r=document.createElement("div");return r.className="os-content-graph__panel-page",r}const k=(r,p,h)=>{if(w.append(p),r===p||h==="none"){r!==p&&r.remove();return}const y=h==="forward"?"page-from-right":"page-from-left",x=h==="forward"?"page-to-left":"page-to-right";p.classList.add(`os-content-graph__${y}`),p.offsetWidth;const E=++N;requestAnimationFrame(()=>{E===N&&(p.classList.remove(`os-content-graph__${y}`),r.classList.add(`os-content-graph__${x}`))});let T=!1;const M=()=>{T||(T=!0,r.removeEventListener("transitionend",M),r.remove())};r.addEventListener("transitionend",M),setTimeout(M,360)},L=r=>{switch(r.kind){case"post":return null;case"user":return`user:${r.user.id}`;case"term":return`term:${r.term.taxonomy}:${r.term.id}`;case"comment":return`comment:${r.comment.id}`;case"media":return`media:${r.media.id}`;case"revision":return`revision:${r.revision.id}`}},O=()=>(window.wp??{}).os??{},C=(r,p,h,y)=>{const x=O();if(!x.windowManager||!x.deriveWindowId||!r){r&&(window.location.href=r);return}const E=x.windowManager.getFocused?.();E?.isFullscreen?.()&&E.toggleFullscreen?.();let T=x.deriveWindowId(r);y&&(T=`${T}-${y}`),x.windowManager.open({id:T,baseId:T,url:r,title:p,icon:h})},P=()=>{if(g.replaceChildren(),i.kind==="post"||!o){g.hidden=!0;return}g.hidden=!1;const r=document.createElement("button");r.type="button",r.className="os-content-graph__panel-breadcrumb-back";const p=document.createElement("span");p.className="dashicons dashicons-arrow-left-alt2 os-content-graph__panel-breadcrumb-arrow",p.setAttribute("aria-hidden","true");const h=document.createElement("span");h.className="os-content-graph__panel-breadcrumb-label",h.textContent=H(o.post.title)||`#${o.post.id}`,r.appendChild(p),r.appendChild(h),r.title=_("Back to post"),r.addEventListener("click",()=>{i={kind:"post"},I()}),g.appendChild(r)},I=()=>{n(!0),P();const r=S(),p=f;switch(f=r,i.kind){case"post":U(o);break;case"user":Yn(i);break;case"term":qn(i);break;case"comment":Kn(i);break;case"media":Xn(i.media);break;case"revision":jn(i.revision);break}let h="none";v!==null&&v!==i.kind&&(i.kind==="post"?h="back":h="forward"),k(p,r,h),t.onViewChange?.(L(i)),v=i.kind},U=r=>{if(!r){u.textContent="",b.textContent="";return}u.textContent=H(r.post.title)||`#${r.post.id}`,b.textContent=`${r.post.type} · ${r.post.status}`,f.appendChild(fe(r)),f.appendChild(ne(r)),f.appendChild(z([{label:_("Contributors"),value:r.contributors.length},{label:_("Comments"),value:r.comments.length},{label:_("Taxonomies"),value:r.categories.length},{label:_("Media"),value:r.attached_media.length},{label:_("Revisions"),value:r.revisions.length}])),f.appendChild(Q(r))},fe=r=>{const p=document.createElement("div");if(p.className="os-content-graph__panel-author",!r.author)return p.hidden=!0,p;const h=document.createElement("span");h.className="os-content-graph__panel-section-label",h.textContent=_("Author"),p.appendChild(h);const y=document.createElement("div");if(y.className="os-content-graph__panel-author-row",r.author.avatar){const E=document.createElement("img");E.className="os-content-graph__panel-avatar",E.src=r.author.avatar,E.alt="",y.appendChild(E)}const x=document.createElement("span");return x.className="os-content-graph__panel-author-name",x.textContent=r.author.name,y.appendChild(x),p.appendChild(y),p},ne=r=>{const p=document.createElement("div");p.className="os-content-graph__panel-dates";const h=[];if(r.post.date&&h.push({label:_("Published"),iso:r.post.date}),r.post.modified&&r.post.modified!==r.post.date&&h.push({label:_("Modified"),iso:r.post.modified}),h.length===0)return p.hidden=!0,p;for(const y of h){const x=document.createElement("div");x.className="os-content-graph__panel-date-row";const E=document.createElement("span");E.className="os-content-graph__panel-section-label",E.textContent=y.label;const T=document.createElement("span");T.className="os-content-graph__panel-date-value",T.textContent=j(y.iso),x.appendChild(E),x.appendChild(T),p.appendChild(x)}return p},z=r=>{const p=document.createElement("ul");p.className="os-content-graph__panel-stats";for(const h of r){const y=document.createElement("li");y.className="os-content-graph__panel-stat";const x=document.createElement("span");x.className="os-content-graph__panel-stat-num",x.textContent=typeof h.value=="number"?he(h.value):h.value;const E=document.createElement("span");E.className="os-content-graph__panel-stat-label",E.textContent=h.label,y.appendChild(x),y.appendChild(E),p.appendChild(y)}return p},Q=r=>{const p=document.createElement("div");p.className="os-content-graph__panel-actions";const h=O();if(h.myWordpress){const y=ge({label:J(_("Open in %s"),qe().siteName?.trim()||_("WordPress")),icon:"dashicons-wordpress",primary:!0});y.addEventListener("click",()=>{const x=r.post.type==="page"?"pages":"posts";h.myWordpress.openDetail({entityId:x,postId:r.post.id,postTitle:H(r.post.title)||`#${r.post.id}`})}),p.appendChild(y)}if(r.post.edit_url){const y=ge({label:_("Edit"),icon:"dashicons-edit"});y.addEventListener("click",()=>C(r.post.edit_url,H(r.post.title),"dashicons-admin-post",`post-${r.post.id}`)),p.appendChild(y)}if(r.post.view_url){const y=ge({label:_("View"),icon:"dashicons-external"});y.addEventListener("click",()=>C(r.post.view_url,H(r.post.title),"dashicons-admin-post",`post-${r.post.id}`)),p.appendChild(y)}return p},Yn=r=>{const{user:p,role:h,stats:y,loading:x}=r;u.textContent=y?.profile.name??p.name,b.textContent=_(h==="author"?"Author":"Contributor");const E=document.createElement("div");E.className="os-content-graph__panel-detail-head";const T=y?.profile.avatarUrl||p.avatar;if(T){const A=document.createElement("img");A.className="os-content-graph__panel-detail-avatar os-content-graph__panel-detail-avatar--lg",A.src=T,A.alt="",E.appendChild(A)}const M=document.createElement("div");if(M.className="os-content-graph__panel-detail-handle",M.innerHTML=`<strong>${R(y?.profile.name??p.name)}</strong><span>@${R(p.slug)}</span>`,E.appendChild(M),f.appendChild(E),y?.profile.roleLabels?.length&&f.appendChild(ut(_("Roles"),y.profile.roleLabels)),y?.profile.description&&f.appendChild(Ae(_("About"),y.profile.description)),y?.profile.website&&f.appendChild(Zn(_("Website"),y.profile.website,y.profile.website)),y){const A=y.counts;f.appendChild(z([{label:_("Posts"),value:A.posts.total},{label:_("Pages"),value:A.pages.total},{label:_("CPT"),value:A.cpt},{label:_("Comments received"),value:A.commentsReceived},{label:_("Comments left"),value:A.commentsLeft}]))}y?.topTerms?.length&&f.appendChild(mt(_("Top topics"),y.topTerms)),y&&f.appendChild(ft([{label:_("First published"),iso:y.milestones.firstPublished},{label:_("Last published"),iso:y.milestones.lastPublished}])),x&&f.appendChild(Ie()),f.appendChild(se({label:_("Open in WordPress"),icon:"dashicons-admin-users",href:p.edit_url,title:p.name,primary:!0,windowKey:`user-${p.id}`}))},qn=r=>{const{term:p,stats:h,loading:y}=r;u.textContent=h?.profile.name??p.name,b.textContent=`${h?.profile.taxonomyLabel??p.tax_label} · ${h?.profile.taxonomy??p.taxonomy}`,h?.profile.parentName&&f.appendChild(Le([{label:_("Parent"),value:h.profile.parentName}])),h?.profile.description&&f.appendChild(Ae(_("Description"),h.profile.description)),h?f.appendChild(z([{label:_("Posts"),value:h.counts.posts.total},{label:_("Comments"),value:h.counts.commentsReceived},{label:_("Authors"),value:h.counts.distinctAuthors}])):f.appendChild(z([{label:_("Posts"),value:p.count}])),h?.topAuthors?.length&&f.appendChild(Qn(_("Top authors"),h.topAuthors)),h?.coTerms?.length&&f.appendChild(mt(_("Co-occurring"),h.coTerms.map(x=>({...x,taxonomy:p.taxonomy})))),h&&f.appendChild(ft([{label:_("First post"),iso:h.milestones.firstPosted},{label:_("Latest post"),iso:h.milestones.lastPosted}])),y&&f.appendChild(Ie()),f.appendChild(se({label:_("Open in WordPress"),icon:"dashicons-tag",href:p.edit_url,title:p.name,primary:!0}))},Kn=r=>{const{comment:p,stats:h,loading:y}=r,x=h?.author.name??p.author;u.textContent=x||`#${p.id}`,b.textContent=j(h?.comment.date??p.date);const E=h?.author.avatarUrl;if(E){const A=document.createElement("div");A.className="os-content-graph__panel-detail-head";const V=document.createElement("img");V.className="os-content-graph__panel-detail-avatar os-content-graph__panel-detail-avatar--lg",V.src=E,V.alt="",A.appendChild(V);const B=document.createElement("div");B.className="os-content-graph__panel-detail-handle",B.innerHTML=`<strong>${R(x)}</strong>`+(h?.author.totalApprovedComments?`<span>${he(h.author.totalApprovedComments)} ${R(_("comments"))}</span>`:""),A.appendChild(B),f.appendChild(A)}const T=h?.comment.status??_("—");f.appendChild(ut(_("Status"),[T],{accent:T==="1"||T==="approved"?"green":"amber"}));const M=h?.comment.rendered;if(M){const A=document.createElement("div");A.className="os-content-graph__panel-detail-section";const V=document.createElement("span");V.className="os-content-graph__panel-section-label",V.textContent=_("Comment"),A.appendChild(V);const B=document.createElement("div");B.className="os-content-graph__panel-detail-html",B.innerHTML=M,A.appendChild(B),f.appendChild(A)}else p.excerpt&&f.appendChild(Ae(_("Comment"),p.excerpt));if(h?.parent){const A=document.createElement("blockquote");A.className="os-content-graph__panel-detail-quote",A.innerHTML=`<strong>${R(h.parent.authorName)}</strong><span>${R(h.parent.excerpt)}</span>`,f.appendChild(A)}h?.replies?.length&&f.appendChild(Jn(h.replies)),y&&f.appendChild(Ie()),f.appendChild(se({label:_("Open in WordPress"),icon:"dashicons-admin-comments",href:p.edit_url,title:x||_("Comment"),primary:!0}))},Xn=r=>{if(u.textContent=r.title||`#${r.id}`,b.textContent=r.mime||_("Media"),r.thumb){const p=document.createElement("div");p.className="os-content-graph__panel-detail-thumb";const h=document.createElement("img");h.src=r.thumb,h.alt=r.title||"",p.appendChild(h),f.appendChild(p)}f.appendChild(Le([{label:_("Type"),value:r.mime}])),f.appendChild(se({label:_("Open in WordPress"),icon:"dashicons-admin-media",href:r.edit_url,title:r.title,primary:!0}))},jn=r=>{if(u.textContent=r.author?.name??_("Revision"),b.textContent=j(r.date),r.author){const p=document.createElement("div");if(p.className="os-content-graph__panel-detail-head",r.author.avatar){const y=document.createElement("img");y.className="os-content-graph__panel-detail-avatar os-content-graph__panel-detail-avatar--lg",y.src=r.author.avatar,y.alt="",p.appendChild(y)}const h=document.createElement("div");h.className="os-content-graph__panel-detail-handle",h.innerHTML=`<strong>${R(r.author.name)}</strong><span>@${R(r.author.slug)}</span>`,p.appendChild(h),f.appendChild(p)}f.appendChild(Le([{label:_("Saved"),value:j(r.date)}])),f.appendChild(se({label:_("Open revision in WordPress"),icon:"dashicons-backup",href:r.edit_url,title:_("Revision"),primary:!0,windowKey:`revision-${r.id}`}))},Ae=(r,p)=>{const h=document.createElement("div");h.className="os-content-graph__panel-detail-section";const y=document.createElement("span");y.className="os-content-graph__panel-section-label",y.textContent=r;const x=document.createElement("p");return x.className="os-content-graph__panel-detail-prose",x.textContent=p,h.appendChild(y),h.appendChild(x),h},ut=(r,p,h={})=>{const y=document.createElement("div");y.className="os-content-graph__panel-detail-section";const x=document.createElement("span");x.className="os-content-graph__panel-section-label",x.textContent=r,y.appendChild(x);const E=document.createElement("div");E.className="os-content-graph__panel-badges";for(const T of p){const M=document.createElement("span");M.className="os-content-graph__panel-badge"+(h.accent?` os-content-graph__panel-badge--${h.accent}`:""),M.textContent=T,E.appendChild(M)}return y.appendChild(E),y},Le=r=>{const p=document.createElement("div");p.className="os-content-graph__panel-inline-meta";for(const h of r){if(!h.value)continue;const y=document.createElement("div");y.className="os-content-graph__panel-inline-meta-row";const x=document.createElement("span");x.className="os-content-graph__panel-section-label",x.textContent=h.label;const E=document.createElement("span");E.className="os-content-graph__panel-date-value",E.textContent=h.value,y.appendChild(x),y.appendChild(E),p.appendChild(y)}return p},Zn=(r,p,h)=>{const y=document.createElement("div");y.className="os-content-graph__panel-detail-section";const x=document.createElement("span");x.className="os-content-graph__panel-section-label",x.textContent=r;const E=document.createElement("a");return E.className="os-content-graph__panel-detail-link",E.href=h,E.textContent=p,E.target="_blank",E.rel="noopener noreferrer",y.appendChild(x),y.appendChild(E),y},mt=(r,p)=>{const h=document.createElement("div");h.className="os-content-graph__panel-detail-section";const y=document.createElement("span");y.className="os-content-graph__panel-section-label",y.textContent=r,h.appendChild(y);const x=document.createElement("ul");x.className="os-content-graph__panel-chips";for(const E of p.slice(0,8)){const T=document.createElement("li");T.className="os-content-graph__panel-chip",T.innerHTML=`<span>${R(E.name)}</span><span class="os-content-graph__panel-chip-count">${he(E.count)}</span>`,x.appendChild(T)}return h.appendChild(x),h},Qn=(r,p)=>{const h=document.createElement("div");h.className="os-content-graph__panel-detail-section";const y=document.createElement("span");y.className="os-content-graph__panel-section-label",y.textContent=r,h.appendChild(y);const x=document.createElement("ul");x.className="os-content-graph__panel-author-list";for(const E of p.slice(0,6)){const T=document.createElement("li");T.className="os-content-graph__panel-author-list-row",T.innerHTML=(E.userAvatarUrl?`<img class="os-content-graph__panel-avatar" src="${Xe(E.userAvatarUrl)}" alt="" />`:"")+`<span class="os-content-graph__panel-author-name">${R(E.userName)}</span><span class="os-content-graph__panel-chip-count">${he(E.count)}</span>`,x.appendChild(T)}return h.appendChild(x),h},ft=r=>{const p=r.filter(E=>E.iso),h=document.createElement("div");if(h.className="os-content-graph__panel-detail-section",p.length===0)return h.hidden=!0,h;const y=document.createElement("span");y.className="os-content-graph__panel-section-label",y.textContent=_("Milestones"),h.appendChild(y);const x=document.createElement("div");x.className="os-content-graph__panel-milestones";for(const E of p){const T=document.createElement("div");T.className="os-content-graph__panel-milestone-row";const M=document.createElement("span");M.className="os-content-graph__panel-milestone-key",M.textContent=E.label;const A=document.createElement("span");A.className="os-content-graph__panel-date-value",A.textContent=j(E.iso),T.appendChild(M),T.appendChild(A),x.appendChild(T)}return h.appendChild(x),h},Jn=r=>{const p=document.createElement("div");p.className="os-content-graph__panel-detail-section";const h=document.createElement("span");h.className="os-content-graph__panel-section-label",h.textContent=J(gt("Reply (%d)","Replies (%d)",r.length),r.length),p.appendChild(h);const y=document.createElement("ul");y.className="os-content-graph__panel-replies";for(const x of r.slice(0,5)){const E=document.createElement("li");E.className="os-content-graph__panel-reply",E.innerHTML=`<header><strong>${R(x.authorName)}</strong><span>${j(x.date)}</span></header><p>${R(x.excerpt)}</p>`,y.appendChild(E)}return p.appendChild(y),p},Ie=()=>{const r=document.createElement("div");return r.className="os-content-graph__panel-detail-loading",r.innerHTML=`<os-spinner></os-spinner><span>${R(_("Loading details…"))}</span>`,r},se=r=>{const p=document.createElement("div");if(p.className="os-content-graph__panel-actions",!r.href)return p.hidden=!0,p;const h=ge({label:r.label,icon:r.icon,primary:r.primary});return h.addEventListener("click",()=>C(r.href,r.title,r.icon,r.windowKey)),p.appendChild(h),p},ge=r=>{const p=document.createElement("button");return p.type="button",p.className="os-content-graph__btn"+(r.primary?" os-content-graph__btn--primary":""),p.innerHTML=`<span class="dashicons ${Xe(r.icon)}" aria-hidden="true"></span><span>${R(r.label)}</span>`,p};return{setLoading:(r,p)=>{n(!0),g.hidden=!0,i={kind:"post"},v=null,u.textContent=p?H(p):`#${r}`,b.textContent=_("Loading…"),w.replaceChildren(),f=S(),w.append(f);const h=document.createElement("div");h.className="os-content-graph__panel-loading",h.innerHTML="<os-spinner></os-spinner>",f.appendChild(h),t.onViewChange?.(null)},setError:r=>{n(!0),g.hidden=!0,i={kind:"post"},v=null,w.replaceChildren(),f=S(),w.append(f);const p=document.createElement("p");p.className="os-content-graph__panel-empty",p.textContent=r,f.appendChild(p),t.onViewChange?.(null)},setDetail:r=>{o=r,i={kind:"post"},I()},showUser:r=>{if(!o)return;const p=o.author?.id===r,h=p?o.author:o.contributors.find(x=>x.id===r);if(!h)return;i={kind:"user",user:h,role:p?"author":"contributor",stats:null,loading:!0},I();const y=++a;Jt(e,r).then(x=>{y!==a||i.kind!=="user"||i.user.id!==r||(i={...i,stats:x,loading:!1},I())}).catch(x=>{y!==a||i.kind!=="user"||i.user.id!==r||(i={...i,loading:!1},I(),console.warn("[content-graph] user-stats failed",x))})},showTerm:(r,p)=>{if(!o)return;const h=o.categories.find(x=>x.id===r&&x.taxonomy===p);if(!h)return;i={kind:"term",term:h,stats:null,loading:!0},I();const y=++a;en(e,p,r).then(x=>{y!==a||i.kind!=="term"||i.term.id!==r||(i={...i,stats:x,loading:!1},I())}).catch(x=>{y!==a||i.kind!=="term"||i.term.id!==r||(i={...i,loading:!1},I(),console.warn("[content-graph] term-stats failed",x))})},showComment:r=>{if(!o)return;const p=o.comments.find(y=>y.id===r);if(!p)return;i={kind:"comment",comment:p,stats:null,loading:!0},I();const h=++a;tn(e,r).then(y=>{h!==a||i.kind!=="comment"||i.comment.id!==r||(i={...i,stats:y,loading:!1},I())}).catch(y=>{h!==a||i.kind!=="comment"||i.comment.id!==r||(i={...i,loading:!1},I(),console.warn("[content-graph] comment-stats failed",y))})},showMedia:r=>{if(!o)return;const p=o.attached_media.find(h=>h.id===r);p&&(i={kind:"media",media:p},I())},showRevision:r=>{if(!o)return;const p=o.revisions.find(h=>h.id===r);p&&(i={kind:"revision",revision:p},I())},hide:()=>{n(!1)},destroy:()=>{s.replaceChildren()}}}function j(s){if(!s)return"";try{return new Date(s).toLocaleString()}catch{return s}}function he(s){try{return new Intl.NumberFormat().format(s)}catch{return String(s)}}function R(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Xe(s){return s.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}const je=Object.freeze({top:0,right:0,bottom:0,left:0});function on(s,e,t,n){return{left:s,top:e,width:t,height:n,right:s+t,bottom:e+n}}function rn(s,e){const t=o=>Math.min(Math.max(0,e.width),Math.max(0,o)),n=o=>Math.min(Math.max(0,e.height),Math.max(0,o));return{top:n(s.top-e.top),bottom:n(e.bottom-s.bottom),left:t(s.left-e.left),right:t(e.right-s.right)}}const an="os/work-area";function cn(){return{insets:{...je},rect:{x:0,y:0,width:0,height:0},viewport:{x:0,y:0,width:0,height:0},area:{width:0,height:0}}}const Ze=Re(an,()=>({snapshot:cn(),installed:!1,areaEl:null}));function ln(s){return{insets:{...s.insets},rect:{...s.rect},viewport:{...s.viewport},area:{...s.area}}}function pe(s){const{installed:e,snapshot:t}=Ze.state;if(!e)return{...je};const n=t.viewport;return rn(on(n.x,n.y,n.width,n.height),s.getBoundingClientRect())}function dn(s){return Ze.subscribe(e=>{s(ln(e.snapshot))})}function hn(){return window.PIXI??null}const pn=12,un=80,mn=700;function fn(s){return 120+18*s}function Qe(s=Math.random){const e=s()*Math.PI*2,t=150+s()*250;return{x:Math.cos(e)*t,y:Math.sin(e)*t}}function gn(s,e=Math.random){if(s<=0)return[];if(s===1)return[{x:0,y:0}];if(s<=pn){const c=fn(s),g=[];for(let l=0;l<s;l++){const d=Math.PI+l*Math.PI*2/s;g.push({x:Math.cos(d)*c,y:Math.sin(d)*c})}return g}const t=[];let n=0,o=0;for(let c=0;c<s;c++){const g=Qe(e);t.push(g),n+=g.x,o+=g.y}const i=n/s,a=o/s;for(const c of t)c.x-=i,c.y-=a;return t}const Je=90;function yn(s){return s<=un?mn:Je}function wn(s,e,t){if(e.width<=0||e.height<=0)return null;let n=1/0,o=1/0,i=-1/0,a=-1/0;for(const w of s)w.x<n&&(n=w.x),w.y<o&&(o=w.y),w.x>i&&(i=w.x),w.y>a&&(a=w.y);if(n===1/0)return null;const c=i-n+t.padding*2,g=a-o+t.padding*2,l=e.width/c,d=e.height/g,u=Math.max(t.minScale,Math.min(t.maxScale,Math.min(l,d))),b=(n+i)/2,m=(o+a)/2;return{scale:u,x:e.width/2-b*u,y:e.height/2-m*u}}const _n={repulsion:26e3,springK:.04,springLen:200,gravity:.0035,damping:.86},bn=.992,xn=.01,et=1,D=12;class vn{constructor(e,t,n=_n){this.dragOrigin=null,this.dragInfluenceRadius=500,this.groupAssignment=null,this.groupOrder=null,this.groupAttractorStrength=.12,this.groupOrderSpacing=320,this.groupOrderStaggerY=0,this.alpha=et,this.nodes=e,this.edges=t,this.opts=n}reheat(e=et,t=!0){if(this.alpha=Math.max(this.alpha,e),!t)return;const n=e*3;for(const o of this.nodes)o.pinned||(o.vx+=(Math.random()-.5)*n,o.vy+=(Math.random()-.5)*n)}get isSettled(){return this.alpha<xn}step(e=1){if(this.isSettled)return;const{repulsion:t,springK:n,springLen:o,gravity:i,damping:a}=this.opts,c=this.nodes,g=c.length;for(let m=0;m<g;m++){const w=c[m];for(let f=m+1;f<g;f++){const v=c[f];let N=w.x-v.x,S=w.y-v.y,k=N*N+S*S;k<.01&&(N=(m-f)*.5,S=(m+f)*.5,k=N*N+S*S);const L=t/k,O=Math.sqrt(k),C=N/O*L,P=S/O*L,I=w.pinned?0:1,U=v.pinned?0:1;w.vx+=C*I,w.vy+=P*I,v.vx-=C*U,v.vy-=P*U}}for(const m of this.edges){const w=m.to.x-m.from.x,f=m.to.y-m.from.y,v=Math.sqrt(w*w+f*f)||1e-4,N=(v-o)*n,S=w/v*N,k=f/v*N;m.from.pinned||(m.from.vx+=S,m.from.vy+=k),m.to.pinned||(m.to.vx-=S,m.to.vy-=k)}this.applyClusterAttractor();const l=this.alpha,d=this.dragOrigin,u=this.dragInfluenceRadius,b=u*u;for(const m of c)if(!m.pinned){m.vx-=m.x*i,m.vy-=m.y*i,m.vx*=a,m.vy*=a,m.vx>D?m.vx=D:m.vx<-D&&(m.vx=-D),m.vy>D?m.vy=D:m.vy<-D&&(m.vy=-D);let w=l;if(d){const f=m.x-d.x,v=m.y-d.y,N=f*f+v*v;if(N>=b)w=0;else{const S=1-Math.sqrt(N)/u;w*=S*S*(3-2*S)}}m.x+=m.vx*w*e,m.y+=m.vy*w*e}this.alpha*=bn}applyClusterAttractor(){const e=this.groupAssignment;if(!e)return;const t=this.groupAttractorStrength;if(t<=0)return;const n=new Map,o=new Map;if(this.groupOrder&&this.groupOrder.length>0){const a=this.groupOrder.length,c=this.groupOrderSpacing,g=this.groupOrderStaggerY;for(let l=0;l<a;l++){const d=this.groupOrder[l];n.set(d,(l-(a-1)/2)*c),g>0&&o.set(d,l%2===0?-g:g)}}const i=new Map;for(const a of this.nodes){const c=e.get(a.id);if(!(!c||c.length===0))for(const g of c){const l=i.get(g);l?(l.sx+=a.x,l.sy+=a.y,l.count++):i.set(g,{sx:a.x,sy:a.y,count:1})}}for(const a of this.nodes){if(a.pinned)continue;const c=e.get(a.id);if(!c||c.length===0)continue;const g=t/c.length;for(const l of c){const d=i.get(l);if(!d||d.count===0)continue;const u=n.has(l)?n.get(l):d.sx/d.count,b=o.has(l)?o.get(l):d.sy/d.count;a.vx+=(u-a.x)*g,a.vy+=(b-a.y)*g}}}setGroupAssignment(e,t=null){this.groupAssignment=e,this.groupOrder=e?t:null,this.reheat(.3,!1)}}const tt={user:3829232,term:2926970,comment:15239482,media:10510036,revision:7042949},nt={user:"admin-users",term:"tag",comment:"admin-comments",media:"admin-media",revision:"backup"};function Cn(s){switch(s.taxonomy){case"category":return"category";case"post_tag":return"tag";default:return nt.term}}const En={user:{x:0,y:3},term:{x:0,y:3},comment:{x:1,y:4},media:{x:-1,y:1},revision:{x:0,y:3}},ue=14;class Sn{constructor(e,t,n,o,i,a){this.pixi=e,this.satelliteParent=t,this.spokeParent=n,this.onClick=o,this.hostEl=i,this.claimPointer=a,this.views=[],this.focused=null,this.rafId=null,this.selectedKey=null,this.linkGfx=new e.Graphics,this.spokeParent.addChild(this.linkGfx),this.layer=new e.Container,this.satelliteParent.addChild(this.layer),this.hoverEl=document.createElement("div"),this.hoverEl.className="os-content-graph__tooltip",this.hoverEl.hidden=!0,this.hostEl.appendChild(this.hoverEl)}clear(){this.linkGfx.clear(),this.layer.removeChildren(),this.views=[],this.focused=null,this.selectedKey=null,this.hideTooltip()}drawLinks(){if(this.linkGfx.clear(),!this.focused||this.views.length===0)return;const e=this.focused.radius+8,t=this.focused.x,n=this.focused.y;for(const o of this.views){const i=o.container.x-t,a=o.container.y-n,c=Math.sqrt(i*i+a*a);if(c<=e)continue;const g=e/c,l=t+i*g,d=n+a*g,u=tt[o.ref.kind];this.linkGfx.moveTo(l,d).lineTo(o.container.x,o.container.y).stroke({color:u,width:o.selected?1.8:1.4,alpha:o.selected?.85:.5})}}setFocused(e,t){this.clear(),this.focused=e;const n=this.flattenDetail(t);if(n.length===0)return;const o=e.radius,a=Math.max(o+86,o+70+n.length*36/(2*Math.PI)),c=-Math.PI/2,g=2*Math.PI/n.length;n.forEach((l,d)=>{const u=c+d*g,b=e.x+Math.cos(u)*a,m=e.y+Math.sin(u)*a,w=this.buildSatellite(l,e.x,e.y);w.targetX=b,w.targetY=m,this.views.push(w)}),this.animateIn()}setSelectedKey(e){if(this.selectedKey!==e){this.selectedKey=e;for(const t of this.views){const n=t.key===e;n!==t.selected&&(t.selected=n,this.repaintDisc(t))}this.drawLinks()}}destroy(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.clear(),this.layer.destroy({children:!0}),this.linkGfx.destroy(),this.hoverEl.remove()}flattenDetail(e){const t=[];e.author&&t.push({kind:"user",userId:e.author.id,label:e.author.name,meta:_("Author"),avatar:e.author.avatar});for(const n of e.contributors.slice(0,8))t.push({kind:"user",userId:n.id,label:n.name,meta:_("Contributor"),avatar:n.avatar});for(const n of e.categories.slice(0,12))t.push({kind:"term",termId:n.id,taxonomy:n.taxonomy,label:n.name,meta:J(_("%1$s · %2$d posts"),n.tax_label,n.count)});for(const n of e.comments.slice(0,8))t.push({kind:"comment",commentId:n.id,label:n.author,meta:n.excerpt||ot(n.date)});for(const n of e.attached_media.slice(0,12))t.push({kind:"media",mediaId:n.id,label:n.title,meta:n.mime,thumb:n.thumb});for(const n of e.revisions.slice(0,8))t.push({kind:"revision",revisionId:n.id,parentId:e.post.id,label:n.author?.name??_("Revision"),meta:ot(n.date)});return t}buildSatellite(e,t,n){const o=new this.pixi.Container;o.x=t,o.y=n,o.alpha=0,o.eventMode="static",o.cursor="pointer";const i=ue+4;o.hitArea={contains:(k,L)=>k>=-i&&k<=i&&L>=-i&&L<=i+18};const a=new this.pixi.Graphics;o.addChild(a);const c=e.kind==="term"?Cn(e):nt[e.kind],g=_e(c),l=new this.pixi.Text({text:g??"?",style:{fontFamily:g?"dashicons":"sans-serif",fontSize:g?20:13,fill:16777215},resolution:2,anchor:{x:.5,y:.5}}),d=En[e.kind];l.x=d?.x??0,l.y=d?.y??0,o.addChild(l);const u=Nn(e.label||"—",28),b=new this.pixi.Graphics;o.addChild(b);const m=new this.pixi.Text({text:u,style:{fill:1711915,fontSize:11,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',fontWeight:"500"},resolution:2,anchor:{x:.5,y:0}});m.x=0,m.y=ue+2,o.addChild(m);const w=6,f=1,v=m.width+w*2,N=m.height+f*2;b.roundRect(-v/2,m.y-f,v,N,4).fill({color:16777215,alpha:.92}).stroke({color:0,alpha:.08,width:1}),o.on("pointerdown",k=>{k.stopPropagation?.(),this.claimPointer()}),o.on("pointerover",k=>{a.alpha=1;const L=k;this.showTooltip(e,L.global)}),o.on("pointermove",k=>{const L=k;this.showTooltip(e,L.global)}),o.on("pointerout",()=>{a.alpha=.95,this.hideTooltip()}),o.on("pointertap",k=>{k.stopPropagation?.(),this.hideTooltip(),this.setSelectedKey(st(e)),this.onClick(e)}),this.layer.addChild(o);const S={ref:e,key:st(e),container:o,disc:a,icon:l,label:m,targetX:t,targetY:n,selected:!1};return this.repaintDisc(S),S}repaintDisc(e){const t=tt[e.ref.kind];e.disc.clear(),e.selected&&e.disc.circle(0,0,ue+6).fill({color:t,alpha:.18}),e.disc.circle(0,0,ue).fill({color:t,alpha:.95}).stroke({color:16777215,width:e.selected?2.5:1.5,alpha:1})}animateIn(){const e=performance.now(),t=240,n=this.views.map(i=>({x:i.container.x,y:i.container.y})),o=i=>{const a=Math.min(1,(i-e)/t),c=1-Math.pow(1-a,3);for(let g=0;g<this.views.length;g++){const l=this.views[g],d=n[g];l.container.x=d.x+(l.targetX-d.x)*c,l.container.y=d.y+(l.targetY-d.y)*c,l.container.alpha=c}this.drawLinks(),a<1?this.rafId=requestAnimationFrame(o):this.rafId=null};this.rafId=requestAnimationFrame(o)}showTooltip(e,t){this.hoverEl.hidden=!1,this.hoverEl.innerHTML=`<strong>${it(e.label||"—")}</strong>`+(e.meta?`<span>${it(e.meta)}</span>`:""),t&&(this.hoverEl.style.left=`${t.x+14}px`,this.hoverEl.style.top=`${t.y+14}px`)}hideTooltip(){this.hoverEl.hidden=!0}}function st(s){switch(s.kind){case"user":return`user:${s.userId}`;case"term":return`term:${s.taxonomy}:${s.termId}`;case"comment":return`comment:${s.commentId}`;case"media":return`media:${s.mediaId}`;case"revision":return`revision:${s.revisionId}`}}function Nn(s,e){return s.length<=e?s:s.slice(0,e-1).trimEnd()+"…"}function ot(s){if(!s)return"";try{return new Date(s).toLocaleString()}catch{return s}}function it(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const Ee=4937059,rt=2911205,kn=5213171,Tn=10135222,An=2911205,Se=Math.min((typeof window<"u"&&window.devicePixelRatio||1)*1.5,3),Ne=[3829232,2926970,15239482,10510036,3122616,13914255,7042949],at=16777215,Ln=1.3,In=0,Mn={"admin-post":{x:.06,y:.06}},$n={category:"#2c6be5",tag:"#2ca97a",author:"#7c3aed",year:"#ea580c",year_month:"#ea580c"},ct=.15,Rn=4,On={padding:100,minScale:ct,maxScale:1.5},Pn=8e-4,Dn=.18,ke=.001,lt=24;class Fn{constructor(e,t,n,o,i="disc"){this.groupLabelOverlay=null,this.satellites=null,this.nodeViews=new Map,this.edgeViews=[],this.groupViews=new Map,this.currentGrouping=null,this.groupCatalogs={authors:{},categories:{},tags:{}},this.groupingTween=null,this.fitFollowActive=!1,this.fitFollowStartedAt=0,this.fitFollowSawMotion=!1,this.fitFollowMaxDurationMs=3e3,this.fitFollowVelocityThreshold=1,this.nodes=[],this.edges=[],this.sim=null,this.focusedId=null,this.hoveredId=null,this.pressedNode=null,this.dragOffset={x:0,y:0},this.isPanning=!1,this.panStart={x:0,y:0,wx:0,wy:0},this.nodeClickActive=!1,this.destroyed=!1,this.tickerCb=null,this.resizeObserver=null,this.fitInsets={top:0,right:0,bottom:0,left:0},this.unsubscribeWorkArea=null,this.lastResizeWidth=0,this.lastResizeHeight=0,this.fitPending=!1,this.targetScale=1,this.targetX=0,this.targetY=0,this.postTypeColor=new Map,this.nodeStyle="disc",this.host=e,this.callbacks=t,this.onSatelliteClick=n,this.nodeStyle=i;const a=new Map;this.postTypeBySlug=new Map;for(const c of o)a.set(c.slug,Vn(c.icon)),this.postTypeBySlug.set(c.slug,c);o.forEach((c,g)=>{this.postTypeColor.set(c.slug,Ne[g%Ne.length])}),this.postTypeIcon=c=>a.get(c)??Gn(c)}async mount(e){typeof e.loadModules=="function"&&await e.loadModules(["pixijs"]);const t=hn();if(!t)throw new Error("PIXI namespace missing after loadModules.");if(this.pixi=t,typeof document<"u"&&document.fonts)try{await document.fonts.load("16px dashicons")}catch{}const n=new t.Application;await n.init({resizeTo:this.host,backgroundAlpha:0,antialias:!0,autoDensity:!0,resolution:Se,sharedTicker:!1}),this.app=n,this.host.appendChild(n.canvas),n.canvas.classList.add("os-content-graph__canvas"),this.world=new t.Container,this.world.x=this.host.clientWidth/2,this.world.y=this.host.clientHeight/2,this.world.scale.set(1),this.targetX=this.world.x,this.targetY=this.world.y,this.targetScale=1,n.stage.addChild(this.world),this.edgeLayer=new t.Container,this.spokeLayer=new t.Container,this.nodeLayer=new t.Container,this.labelLayer=new t.Container,this.world.addChild(this.edgeLayer,this.spokeLayer,this.nodeLayer,this.labelLayer),this.groupLabelOverlay=document.createElement("div"),this.groupLabelOverlay.className="os-content-graph__group-labels",this.host.appendChild(this.groupLabelOverlay),n.canvas.addEventListener("webglcontextlost",a=>{a.preventDefault();try{this.app?.ticker?.stop()}catch{}},!1);const o=n.renderer,i=o.render.bind(o);o.render=(...a)=>{try{return i(...a)}catch(c){try{this.app?.ticker?.stop()}catch{}console.warn("[content-graph] Pixi render threw, stopping ticker:",c);return}},this.satellites=new Sn(t,this.world,this.spokeLayer,this.onSatelliteClick,this.host,()=>{this.nodeClickActive=!0}),this.bindStageInput(n.canvas),this.bindResize(),this.tickerCb=a=>this.tick(a.deltaTime),n.ticker.add(this.tickerCb)}setData(e){const t=new Map;for(const l of this.nodes)t.set(l.id,l);this.groupCatalogs=e.groups??{authors:{},categories:{},tags:{}};const n=e.nodes.every(l=>!t.has(l.id)),o=n?gn(e.nodes.length):null,i=e.nodes.map((l,d)=>{const u=t.get(l.id),b=o?o[d]:Qe();return{...l,x:u?.x??b.x,y:u?.y??b.y,vx:0,vy:0,pinned:!1,radius:4,color:Ee,degree:0}}),a=new Map;for(const l of i)a.set(l.id,l);const c=[];for(const l of e.edges){const d=a.get(l.from),u=a.get(l.to);!d||!u||(d.degree++,u.degree++,c.push({from:d,to:u}))}for(const l of i)l.radius=8+Math.min(8,Math.sqrt(l.degree)*2.4);this.nodes=i,this.edges=c,this.rebuildSprites(),this.sim=new vn(i,c),this.sim.reheat(.12,!1);const g=n?yn(i.length):Je;for(let l=0;l<g&&!this.sim.isSettled;l++)this.sim.step(1);this.currentGrouping&&this.setGrouping(this.currentGrouping)}rebuildSprites(){this.edgeLayer.removeChildren(),this.nodeLayer.removeChildren(),this.labelLayer.removeChildren(),this.nodeViews.clear(),this.edgeViews=[];for(const e of this.edges){const t=new this.pixi.Graphics;this.edgeLayer.addChild(t),this.edgeViews.push({edge:e,gfx:t})}for(const e of this.nodes){const t=new this.pixi.Container;t.eventMode="static",t.cursor="pointer",t.hitArea=new this.pixi.Circle(0,0,Math.max(18,e.radius+8)),this.bindNodeInput(t,e),this.nodeLayer.addChild(t);const n=new this.pixi.Graphics;t.addChild(n);const o=new this.pixi.Graphics;t.addChild(o);const i=this.postTypeIcon(e.type),a=_e(i),c=new this.pixi.Text({text:a??"●",style:{fontFamily:a?"dashicons":"sans-serif",fontSize:2*e.radius,fill:Ee},resolution:Se,anchor:{x:.5,y:.5}});t.addChild(c);const g=new this.pixi.Container;this.labelLayer.addChild(g);const l=new this.pixi.Graphics;g.addChild(l);const d=new this.pixi.Text({text:this.truncate(H(e.title)||`#${e.id}`,32),style:{fill:2042167,fontSize:11,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',fontWeight:"500"},resolution:Se,anchor:{x:.5,y:0}});g.addChild(d);const u=5,b=1,m=d.width+u*2,w=d.height+b*2;l.roundRect(-m/2,-b,m,w,4).fill({color:16777215,alpha:.78}).stroke({color:0,alpha:.06,width:1}),this.nodeViews.set(e.id,{node:e,container:t,halo:n,disc:o,icon:c,labelBox:g,labelBg:l,label:d,iconCharCode:a,iconName:i,typeColor:this.postTypeColor.get(e.type)??Ne[0],discKey:""})}}truncate(e,t){return e.length<=t?e:e.slice(0,t-1).trimEnd()+"…"}bindNodeInput(e,t){let n={x:0,y:0},o=!1;const i=36;e.on("pointerdown",a=>{const c=a;c.stopPropagation?.(),n={x:c.global.x,y:c.global.y},this.nodeClickActive=!0,this.pressedNode=t,o=!1,t.pinned=!0,t.vx=0,t.vy=0}),e.on("pointerover",()=>{this.hoveredId=t.id,this.draw()}),e.on("pointerout",()=>{this.hoveredId===t.id&&(this.hoveredId=null,this.draw())}),e.on("pointerup",a=>{const c=a,g=c.global.x-n.x,l=c.global.y-n.y;!o&&g*g+l*l<=256&&this.callbacks.onNodeClick?.(t),t.pinned=this.focusedId===t.id,this.pressedNode=null,this.sim&&(this.sim.dragOrigin=null,o&&this.sim.reheat(.35,!1)),o=!1}),e.on("pointerupoutside",()=>{t.pinned=this.focusedId===t.id,this.pressedNode=null,this.sim&&(this.sim.dragOrigin=null),o=!1}),e.on("globalpointermove",a=>{if(this.pressedNode!==t)return;const c=a,g=c.global.x-n.x,l=c.global.y-n.y,d=g*g+l*l;if(!o){if(d<i)return;o=!0;const b=this.toWorld(c.global.x,c.global.y);this.dragOffset={x:t.x-b.x,y:t.y-b.y},this.sim&&(this.sim.dragOrigin={x:t.x,y:t.y},this.sim.reheat(.3,!1))}const u=this.toWorld(c.global.x,c.global.y);t.x=u.x+this.dragOffset.x,t.y=u.y+this.dragOffset.y,t.vx=0,t.vy=0,this.sim&&(this.sim.dragOrigin={x:t.x,y:t.y})})}bindStageInput(e){e.addEventListener("wheel",t=>{t.preventDefault();const n=Math.exp(-t.deltaY*Pn),o=Math.max(ct,Math.min(Rn,this.targetScale*n)),i=e.getBoundingClientRect(),a=t.clientX-i.left,c=t.clientY-i.top,g=(a-this.targetX)/this.targetScale,l=(c-this.targetY)/this.targetScale;this.targetScale=o,this.targetX=a-g*o,this.targetY=c-l*o},{passive:!1}),e.addEventListener("pointerdown",t=>{t.target===e&&(this.nodeClickActive||(this.isPanning=!0,this.panStart={x:t.clientX,y:t.clientY,wx:this.world.x,wy:this.world.y}))}),window.addEventListener("pointermove",t=>{if(!this.isPanning||this.nodeClickActive)return;const n=this.panStart.wx+(t.clientX-this.panStart.x),o=this.panStart.wy+(t.clientY-this.panStart.y);this.world.x=n,this.world.y=o,this.targetX=n,this.targetY=o}),window.addEventListener("pointerup",t=>{const n=this.nodeClickActive;if(this.nodeClickActive=!1,!this.isPanning)return;const o=t.clientX-this.panStart.x,i=t.clientY-this.panStart.y;this.isPanning=!1,!n&&o*o+i*i<9&&this.callbacks.onBackgroundClick?.()})}bindResize(){this.lastResizeWidth=this.host.clientWidth,this.lastResizeHeight=this.host.clientHeight,this.resizeObserver=new ResizeObserver(()=>{if(this.destroyed)return;const e=this.host.clientWidth,t=this.host.clientHeight;if(this.fitInsets=pe(this.host),e<=0||t<=0)return;try{this.app.renderer.resize(e,t)}catch{return}try{this.app.render()}catch{}this.fitPending&&this.fitToView();const n=Math.abs(e-this.lastResizeWidth),o=Math.abs(t-this.lastResizeHeight);(n>=lt||o>=lt)&&(this.lastResizeWidth=e,this.lastResizeHeight=t)}),this.resizeObserver.observe(this.host),this.unsubscribeWorkArea=dn(()=>{this.destroyed||(this.fitInsets=pe(this.host))})}toWorld(e,t){const n=this.app.canvas.getBoundingClientRect(),o=e-n.left,i=t-n.top;return{x:(o-this.world.x)/this.world.scale.x,y:(i-this.world.y)/this.world.scale.y}}tick(e){if(this.destroyed||!this.app||!this.world)return;this.groupingTween?this.advanceGroupingTween():this.sim?.step(e);const t=1-Math.pow(1-Dn,e),n=this.targetScale-this.world.scale.x;Math.abs(n)<ke?this.world.scale.set(this.targetScale):this.world.scale.set(this.world.scale.x+n*t);const o=this.targetX-this.world.x,i=this.targetY-this.world.y;Math.abs(o)<ke?this.world.x=this.targetX:this.world.x+=o*t,Math.abs(i)<ke?this.world.y=this.targetY:this.world.y+=i*t,this.draw(),this.drawGroupLabels(),this.satellites?.drawLinks(),this.advanceFitFollow()}advanceFitFollow(){if(!this.fitFollowActive)return;if(performance.now()-this.fitFollowStartedAt>this.fitFollowMaxDurationMs){this.fitFollowActive=!1;return}if(this.groupingTween)return;let e=0;for(const t of this.nodes){if(t.pinned)continue;const n=Math.hypot(t.vx,t.vy);n>e&&(e=n)}e>=this.fitFollowVelocityThreshold?(this.fitFollowSawMotion=!0,this.fitToView(!1)):this.fitFollowSawMotion&&(this.fitFollowActive=!1)}postTypeSupportsTaxonomy(e,t){return this.postTypeBySlug.get(e)?.taxonomies?.[t]??!1}postTypeLabel(e){return this.postTypeBySlug.get(e)?.label??e}deriveGroupKeys(e,t){switch(t){case"category":return this.postTypeSupportsTaxonomy(e.type,"category")?e.category_ids.length===0?["cat:uncat"]:e.category_ids.map(n=>`cat:${n}`):[`cat:type_${e.type}`];case"tag":return this.postTypeSupportsTaxonomy(e.type,"post_tag")?e.tag_ids.length===0?["tag:untagged"]:e.tag_ids.map(n=>`tag:${n}`):[`tag:type_${e.type}`];case"author":{const n=e.author_id||0,o=`author:${n}`,i=[o,o],a=Array.isArray(e.contributor_ids)?e.contributor_ids:[];for(const c of a)c>0&&c!==n&&i.push(`author:${c}`);return i}case"year":return[`year:${e.year||0}`];case"year_month":return[`ym:${e.year_month||"unknown"}`]}}labelForGroupKey(e){const t=e.indexOf(":"),n=e.slice(0,t),o=e.slice(t+1);switch(n){case"cat":{if(o==="uncat")return _("Uncategorized");if(o.startsWith("type_"))return this.postTypeLabel(o.slice(5));const i=Number(o);return this.groupCatalogs.categories[i]?.name??`#${i}`}case"tag":{if(o==="untagged")return _("Untagged");if(o.startsWith("type_"))return this.postTypeLabel(o.slice(5));const i=Number(o);return this.groupCatalogs.tags[i]?.name??`#${i}`}case"author":{const i=Number(o);return i<=0?_("Unknown author"):this.groupCatalogs.authors[i]?.name??`#${i}`}case"year":{const i=Number(o);return i<=0?_("Undated"):String(i)}case"ym":return o==="unknown"||o===""?_("Undated"):Wn(o)}return e}buildGroupViews(e,t){if(!this.groupLabelOverlay)return;const n=$n[t];for(const[o,i]of e){if(i.length===0)continue;const a=`${this.labelForGroupKey(o)} (${i.length})`,c=document.createElement("div");c.className="os-content-graph__group-label",c.textContent=a,c.style.setProperty("--os-ui-cg-cluster-color",n),this.groupLabelOverlay.appendChild(c),this.groupViews.set(o,{key:o,label:a,el:c,members:i})}}clearGroupViews(){for(const e of this.groupViews.values())e.el.remove();this.groupViews.clear()}drawGroupLabels(){if(this.destroyed||this.groupViews.size===0)return;const e=1-Te(1.2,2.4,this.world.scale.x),t=this.world.scale.x,n=this.world.x,o=this.world.y;for(const i of this.groupViews.values()){let a=0,c=0,g=0;for(const u of i.members){const b=this.nodeViews.get(u)?.node;b&&(a+=b.x,c+=b.y,g++)}if(g===0||e<=.02){i.el.style.display="none";continue}const l=n+a/g*t,d=o+c/g*t;i.el.style.display="",i.el.style.transform=`translate(${l}px, ${d}px) translate(-50%, -50%)`,i.el.style.opacity=String(e)}}draw(){if(this.destroyed)return;const e=this.focusedId,t=this.hoveredId,n=new Set;if(e!==null){for(const d of this.edges)d.from.id===e&&n.add(d.to.id),d.to.id===e&&n.add(d.from.id);n.add(e)}const o=e!==null,a=.2+Te(.45,1.1,this.world.scale.x)*.35;for(const d of this.edgeViews){const{edge:u,gfx:b}=d;b.clear();const m=e!==null&&(u.from.id===e||u.to.id===e),w=t!==null&&(u.from.id===t||u.to.id===t);let f;o?f=m?.85:0:w?f=.7:f=a;const v=m||w?An:Tn,N=m||w?1.2:.7;let S=u.from.x,k=u.from.y,L=u.to.x,O=u.to.y;if(e!==null){if(u.from.id===e){const C=dt(u.from.x,u.from.y,u.to.x,u.to.y,u.from.radius+8);S=C.x,k=C.y}if(u.to.id===e){const C=dt(u.to.x,u.to.y,u.from.x,u.from.y,u.to.radius+8);L=C.x,O=C.y}}b.moveTo(S,k).lineTo(L,O).stroke({color:v,width:N,alpha:f})}const c=1/this.world.scale.x,g=Te(.55,.95,this.world.scale.x),l=this.nodeStyle==="disc";for(const d of this.nodeViews.values()){const{node:u,container:b,halo:m,disc:w,icon:f,labelBox:v}=d,N=u.id===e,S=u.id===t,k=e!==null&&n.has(u.id),L=e===null||k,O=L?1:.25;b.x=u.x,b.y=u.y,b.alpha=O;let C=Ee;N?C=rt:k&&(C=kn);const P=N?rt:d.typeColor;m.clear(),(N||S)&&m.circle(0,0,u.radius+8).fill({color:l?P:C,alpha:.18});const I=N?u.radius*Ln:u.radius,U=N||S?2.5:1.5,fe=l?`${P}|${I}|${U}`:"off";d.discKey!==fe&&(d.discKey=fe,w.clear(),l&&w.circle(0,0,I).fill({color:P,alpha:.95}).stroke({color:at,width:U,alpha:1})),f.visible=!l||N||S,f.style.fill=l?at:C;const ne=l?I*1.35:2*u.radius;f.style.fontSize=ne;const z=Mn[d.iconName];f.x=(z?.x??0)*ne,f.y=(z?.y??In)*ne,v.x=u.x,v.y=u.y+(l?I:u.radius)+4,v.scale.set(c);let Q;N?Q=1:L?Q=.92:Q=.32,v.alpha=Q*g,v.visible=v.alpha>.01}}focusNode(e){if(this.focusedId!==null){const n=this.nodeViews.get(this.focusedId);n&&(n.node.pinned=!1)}this.focusedId=e;const t=this.nodeViews.get(e);if(t){t.node.pinned=!0,t.node.vx=0,t.node.vy=0;const n=t.node,o=Math.max(this.targetScale,1.6);this.targetScale=o,this.targetX=this.host.clientWidth/2-n.x*o,this.targetY=this.host.clientHeight/2-n.y*o}this.draw()}setFocusedDetail(e){if(!this.satellites)return;if(!e||this.focusedId===null){this.satellites.clear();return}const t=this.nodeViews.get(this.focusedId)?.node;if(!t){this.satellites.clear();return}this.satellites.setFocused(t,e)}setGrouping(e){if(this.currentGrouping=e,this.clearGroupViews(),!e||!this.sim){this.sim?.setGroupAssignment(null);return}const t=new Map,n=new Map;for(const a of this.nodes){const c=this.deriveGroupKeys(a,e);t.set(a.id,c);const g=new Set;for(const l of c){if(g.has(l))continue;g.add(l);const d=n.get(l);d?d.push(a.id):n.set(l,[a.id])}}const o=this.chronologicalOrder(e,n);this.sim.groupOrderStaggerY=e==="year_month"?160:0,this.sim.setGroupAssignment(t,o);const i=this.buildGroupSeedTargets(t,n,o);this.startGroupingTween(i),this.fitToViewOfTargets(i),this.buildGroupViews(n,e),this.fitFollowActive=!0,this.fitFollowStartedAt=performance.now(),this.fitFollowSawMotion=!1}advanceGroupingTween(){if(this.destroyed)return;const e=this.groupingTween;if(!e)return;const t=Math.min(1,(performance.now()-e.startTime)/e.duration),n=1-Math.pow(1-t,3);for(const[o,i]of e.starts){const a=e.targets.get(o);if(!a)continue;const c=this.nodeViews.get(o)?.node;!c||c.pinned||(c.x=i.x+(a.x-i.x)*n,c.y=i.y+(a.y-i.y)*n,c.vx=0,c.vy=0)}t>=1&&(this.groupingTween=null,this.sim?.reheat(.18,!1))}buildGroupSeedTargets(e,t,n){const o=new Map;if(!this.sim)return o;const i=Array.from(t.keys()),a=new Map,c=this.sim.groupOrderSpacing;if(n&&n.length>0){const l=n.length,d=this.sim.groupOrderStaggerY,u=m=>d<=0?0:m%2===0?-d:d;for(let m=0;m<l;m++)a.set(n[m],{x:(m-(l-1)/2)*c,y:u(m)});let b=l;for(const m of i)a.has(m)||(a.set(m,{x:(b-(l-1)/2)*c,y:u(b)}),b++)}else{const l=i.length,d=Math.max(220,120+l*40);for(let u=0;u<l;u++){const b=u/Math.max(1,l)*Math.PI*2-Math.PI/2;a.set(i[u],{x:Math.cos(b)*d,y:Math.sin(b)*d})}}const g=40;for(const l of this.nodes){if(l.pinned)continue;const d=e.get(l.id);if(!d||d.length===0)continue;let u=0,b=0,m=0;for(const w of d){const f=a.get(w);f&&(u+=f.x,b+=f.y,m++)}m!==0&&o.set(l.id,{x:u/m+(Math.random()-.5)*g,y:b/m+(Math.random()-.5)*g})}return o}startGroupingTween(e){if(e.size===0){this.groupingTween=null;return}const t=new Map;for(const n of e.keys()){const o=this.nodeViews.get(n)?.node;o&&t.set(n,{x:o.x,y:o.y})}this.groupingTween={startTime:performance.now(),duration:450,starts:t,targets:e}}fitToViewOfTargets(e){e.size!==0&&(this.fitInsets=pe(this.host),this.frame(e.values()))}frame(e){const t=this.fitInsets,n=wn(e,{width:this.host.clientWidth-t.left-t.right,height:this.host.clientHeight-t.top-t.bottom},On);if(!n){this.fitPending=!0;return}this.fitPending=!1,this.targetScale=n.scale,this.targetX=t.left+n.x,this.targetY=t.top+n.y}chronologicalOrder(e,t){if(e!=="year"&&e!=="year_month")return null;const n=[];for(const o of t.keys()){const i=o.indexOf(":"),a=o.slice(i+1);if(e==="year"){const c=Number(a);if(!Number.isFinite(c)||c<=0)continue;n.push({key:o,sort:String(c).padStart(6,"0")})}else{if(a==="unknown"||a==="")continue;n.push({key:o,sort:a})}}return n.sort((o,i)=>o.sort<i.sort?-1:o.sort>i.sort?1:0),n.map(o=>o.key)}clearFocus(){if(this.focusedId!==null){const e=this.nodeViews.get(this.focusedId);e&&(e.node.pinned=!1)}this.focusedId=null,this.satellites?.clear(),this.sim?.reheat(.25,!1),this.draw()}setSatelliteSelectedKey(e){this.satellites?.setSelectedKey(e)}getNode(e){return this.nodes.find(t=>t.id===e)}getNodes(){return this.nodes}setNodeStyle(e){if(this.nodeStyle!==e){this.nodeStyle=e;for(const t of this.nodeViews.values())t.discKey=""}}getNodeStyle(){return this.nodeStyle}getFocusedId(){return this.focusedId}fitToView(e=!0){this.nodes.length!==0&&(e&&(this.fitInsets=pe(this.host)),this.frame(this.nodes))}destroy(){this.destroyed=!0;try{this.app?.ticker?.stop()}catch{}if(this.tickerCb){try{this.app?.ticker?.remove(this.tickerCb)}catch{}this.tickerCb=null}this.resizeObserver?.disconnect(),this.resizeObserver=null,this.unsubscribeWorkArea?.(),this.unsubscribeWorkArea=null,this.satellites?.destroy(),this.satellites=null,this.clearGroupViews(),this.groupLabelOverlay?.remove(),this.groupLabelOverlay=null;try{this.app.destroy({removeView:!0},{children:!0})}catch{}}}function Vn(s){return typeof s!="string"||s===""||s.startsWith("http://")||s.startsWith("https://")?"admin-generic":s.replace(/^dashicons-/,"")}function dt(s,e,t,n,o){const i=t-s,a=n-e,c=Math.sqrt(i*i+a*a);if(c===0)return{x:s,y:e};const g=Math.min(o/c,1);return{x:s+i*g,y:e+a*g}}function Te(s,e,t){if(t<=s)return 0;if(t>=e)return 1;const n=(t-s)/(e-s);return n*n*(3-2*n)}function Wn(s){const e=/^(\d{4})-(\d{2})$/.exec(s);if(!e)return s;const t=Number(e[2])-1;if(t<0||t>11)return s;const n=Number(e[1]);try{const o=new Date(Date.UTC(n,t,1));return new Intl.DateTimeFormat(void 0,{month:"short",year:"numeric",timeZone:"UTC"}).format(o)}catch{return s}}function Gn(s){switch(s){case"post":return"admin-post";case"page":return"admin-page";case"attachment":return"admin-media";default:return"admin-generic"}}const ht="desktop-mode-content-graph",pt="desktop-mode/corkboard-node-style",me=new Set;let Z=Hn();function Hn(){try{return window.localStorage.getItem(pt)==="icon"?"icon":"disc"}catch{return"disc"}}function Un(s){try{window.localStorage.setItem(pt,s)}catch{}}Ct({id:"desktop-mode/corkboard-pins",label:_("Show pins"),checkable:!0,checked:()=>Z==="icon",isVisible:s=>(s.config.baseId??s.id)===ht,onSelect:()=>{Z=Z==="icon"?"disc":"icon",Un(Z);for(const s of me)s.setNodeStyle(Z)}});async function zn(s){const e=s.querySelector("[data-os-content-graph-root]");if(!e)return s.textContent=_("Corkboard container missing."),{abort:()=>{}};const t=qe(),n=e.querySelector("[data-os-content-graph-toolbar]"),o=e.querySelector("[data-os-content-graph-stage]"),i=e.querySelector("[data-os-content-graph-panel]"),a=e.querySelector("[data-os-content-graph-loading]"),c=window.wp?.os??{};let g=t.postTypes.map(C=>C.slug),l=t.postTypes,d=null,u=0,b=!1;const m=zt(a),w=Ht(o),f=sn(i,t,{onClose:()=>{f.hide(),d?.clearFocus()},onViewChange:C=>{d?.setSatelliteSelectedKey(C)}}),v=C=>{switch(C.kind){case"user":f.showUser(C.userId);break;case"term":f.showTerm(C.termId,C.taxonomy);break;case"comment":f.showComment(C.commentId);break;case"media":f.showMedia(C.mediaId);break;case"revision":f.showRevision(C.revisionId);break}},N=C=>{d?.focusNode(C.id),f.setLoading(C.id,C.title);const P=++u;(async()=>{try{const I=await Qt(t,C.id);if(b||P!==u)return;f.setDetail(I),d?.setFocusedDetail(I)}catch(I){if(b||P!==u)return;f.setError(J(_("Could not load post #%d."),C.id)),console.warn("[content-graph] detail fetch failed",I)}})()},S=()=>({onTypesChange:C=>{g=C,L()},onFitToView:()=>d?.fitToView(),onSearchSelect:C=>N(C),onGroupChange:C=>{d?.setGrouping(C),w.setSuppressed(C!==null)},getNodes:()=>d?.getNodes()??[]}),k=nn(n,t.postTypes,S()),L=async()=>{if(!b){m.show(),k.setStatus(_("Loading graph…"));try{const C=await Zt(t,g);if(b)return;d?.setData(C),k.setStatus(J(_("%1$d nodes · %2$d links"),C.stats.nodes,C.stats.edges)),w.set(Wt({nodes:C.stats.nodes,edges:C.stats.edges,types:l,activeTypes:g})),d?.fitToView(),d?.clearFocus(),f.hide()}catch(C){if(b)return;w.set({kind:"none"}),k.setStatus(_("Failed to load graph.")),console.warn("[content-graph] graph fetch failed",C)}finally{m.hide()}}},O=()=>{u++,f.hide(),d?.clearFocus()};d=new Fn(o,{onNodeClick:C=>{if(d?.getFocusedId()===C.id){O();return}N(C)},onBackgroundClick:O},v,t.postTypes,Z),me.add(d);try{await d.mount(c)}catch(C){return o.textContent=_("Could not initialise the graph renderer."),console.warn("[content-graph] scene mount failed",C),me.delete(d),{abort:()=>{}}}return(async()=>{try{const C=await jt(t);if(b)return;l=C,k.updateCounts(C)}catch{}await L()})(),{abort:()=>{b=!0,m.destroy(),w.destroy(),k.destroy(),f.destroy(),d&&(me.delete(d),d.destroy()),d=null}}}const Bn=window.openStationNativeWindows??(window.openStationNativeWindows={});Bn[ht]=async s=>(await zn(s)).abort})(); | |
| 19 | + `}};oe.props=["icon","heading","description"],oe.styles=[Xt],oe.help=void 0;let Ee=oe;Ue("os-empty-state",Ee);function Kt(s){if(s.nodes>0)return s.edges>0?{kind:"none"}:{kind:"no-threads"};if(s.activeTypes.length===0&&s.types.length>0)return{kind:"all-off"};const e=new Set(s.activeTypes),t=s.types.some(o=>typeof o.count=="number");let n=0;for(const o of s.types)e.has(o.slug)||(n+=t?o.count??0:1);return n>0?{kind:"filtered-out"}:{kind:"no-content"}}const jt="os-content-graph__empty",Se="os-content-graph__hint";function Zt(s){let e=null,t="none",n={kind:"none"},o=!1;const i=()=>{e?.remove(),e=null,t="none"},r=(l,p,b)=>{const g=document.createElement("os-empty-state");return g.className=jt,g.setAttribute("icon",l),g.setAttribute("heading",p),g.setAttribute("description",b),g},c=(l,p)=>{const b=document.createElement("div");b.className=Se,b.setAttribute("role","note");const g=document.createElement("strong");g.className=`${Se}-title`,g.textContent=l;const _=document.createElement("p");return _.className=`${Se}-body`,_.textContent=p,b.append(g,_),b},u=l=>{switch(l.kind){case"none":return null;case"no-content":return r("admin-post",y("Nothing on the board yet"),y("Publish a post or a page and it is pinned here. Threads are drawn between posts when one links to another."));case"filtered-out":return r("filter",y("Nothing to show for these types"),y("The post types switched on in the toolbar have no content yet. Switch another one on to see its posts."));case"all-off":return r("filter",y("Every post type is switched off"),y("Switch a type back on in the toolbar to see its posts."));case"no-threads":return c(y("No threads yet"),y("A thread joins two posts when one links to the other. Click a node to see its author, terms, comments, media and revisions, or group the board by category, tag, author, year or month from the toolbar."))}},d=()=>{const l=o&&n.kind==="no-threads"?{kind:"none"}:n;if(l.kind===t)return;i();const p=u(l);p&&(s.appendChild(p),e=p,t=l.kind)};return{set:l=>{n=l,d()},setSuppressed:l=>{o=l,d()},destroy:i}}const Qt=400,Y="os-content-graph__loading--visible";function Jt(s,e=Qt){let t=null;const n=()=>{t!==null&&(clearTimeout(t),t=null)};return s&&(s.hidden=!1,s.classList.remove(Y)),{show:()=>{!s||t!==null||s.classList.contains(Y)||(t=setTimeout(()=>{t=null,s.classList.add(Y)},e))},hide:()=>{n(),s?.classList.remove(Y)},destroy:()=>{n(),s?.classList.remove(Y)},isVisible:()=>!!s?.classList.contains(Y)}}const en="http://localhost/";function Ne(s,e){const t=typeof window<"u"&&window.location?window.location.href:en,n=new URL(s,t),o=e.replace(/^\/+/,""),i=o.indexOf("?"),r=i===-1?o:o.slice(0,i),c=i===-1?"":o.slice(i+1);if(n.searchParams.has("rest_route")){const u=n.searchParams.get("rest_route")??"/",d=u.endsWith("/")?u:u+"/";n.searchParams.set("rest_route",d+r)}else{const u=n.pathname.endsWith("/")?n.pathname:n.pathname+"/";n.pathname=u+r}return c&&new URLSearchParams(c).forEach((d,l)=>{n.searchParams.append(l,d)}),n.toString()}const Ke="X-WP-Nonce";function tn(s,e){const t=nn();if(!t)return e;const n=sn(s);if(!n||!on(n))return e;const o=e?.headers??(typeof Request<"u"&&s instanceof Request?s.headers:void 0),i=new Headers(o??{});return i.has(Ke)?e:(i.set(Ke,t),{...e??{},headers:i})}function nn(){if(typeof window>"u")return;const e=window.openStationConfig?.restNonce;return typeof e=="string"&&e.length>0?e:void 0}function sn(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 on(s){return typeof window>"u"||!window.location||s.origin!==window.location.origin?!1:!!(s.pathname.includes("/wp-json/")||s.searchParams.has("rest_route"))}function q(s,e,t={}){const n=window.wp?.os?.fetch;if(typeof n=="function")return n(s,e,t);const o=tn(s,e);return fetch(s,o)}class rn 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 an(s){const e=typeof s=="object"&&s!==null?s:void 0;return{code:typeof e?.code=="string"?e.code:void 0,data:e?.data,serverMessage:typeof e?.message=="string"?e.message:""}}function cn(s,e,t=""){return new rn(t,{status:s,...an(e)})}async function X(s,e=""){let t=null;try{t=await s.json()}catch{t=null}return cn(s.status,t,e)}const G="desktop-mode-content-graph",K="desktop-mode/content-graph";function je(){const e=(window.openStationWindowConfig??{})[G];if(!e)throw new Error("Corkboard config missing — openstation_register_window args lost in transit.");return e}function j(s){return{Accept:"application/json","X-WP-Nonce":s.restNonce}}async function ln(s){const e=await q(`${s.apiBase}/post-types`,{headers:j(s)},{source:K,windowId:G});if(!e.ok)throw await X(e,`post-types: ${e.status}`);return await e.json()}async function dn(s,e){const t=new URL(`${s.apiBase}/nodes`);t.searchParams.set("types",e.join(","));const n=await q(t.toString(),{headers:j(s)},{source:K,windowId:G});if(!n.ok)throw await X(n,`nodes: ${n.status}`);return await n.json()}async function hn(s,e){const t=await q(`${s.apiBase}/post/${e}`,{headers:j(s)},{source:K,windowId:G});if(!t.ok)throw await X(t,`post/${e}: ${t.status}`);return await t.json()}async function pn(s,e){const t=await q(Ne(s.restRoot,`desktop-mode/v1/user-stats/${e}`),{headers:j(s)},{source:K,windowId:G});if(!t.ok)throw await X(t,`user-stats/${e}: ${t.status}`);return await t.json()}async function un(s,e,t){const n=await q(Ne(s.restRoot,`desktop-mode/v1/term-stats/${encodeURIComponent(e)}/${t}`),{headers:j(s)},{source:K,windowId:G});if(!n.ok)throw await X(n,`term-stats/${e}/${t}: ${n.status}`);return await n.json()}async function fn(s,e){const t=await q(Ne(s.restRoot,`desktop-mode/v1/comment-stats/${e}`),{headers:j(s)},{source:K,windowId:G});if(!t.ok)throw await X(t,`comment-stats/${e}: ${t.status}`);return await t.json()}const pe="none";function mn(s,e,t){s.replaceChildren();const n=new Set(e.map(m=>m.slug)),o=document.createElement("div");o.className="os-content-graph__filters",o.setAttribute("role","group"),o.setAttribute("aria-label",y("Show post types")),s.appendChild(o);for(const m of e){const v=document.createElement("button");v.type="button",v.className="os-content-graph__chip",v.setAttribute("aria-pressed","true"),v.dataset.slug=m.slug,v.innerHTML=`<span class="dashicons ${Ze(m.icon)}" aria-hidden="true"></span><span class="os-content-graph__chip-label">${ue(m.label)}</span><span class="os-content-graph__chip-count">${m.count}</span>`,v.addEventListener("click",()=>{n.has(m.slug)?n.delete(m.slug):n.add(m.slug),v.setAttribute("aria-pressed",String(n.has(m.slug))),t.onTypesChange(Array.from(n))}),o.appendChild(v)}const i=document.createElement("div");i.className="os-content-graph__search";const r=document.createElement("os-text-field");r.setAttribute("type","search"),r.setAttribute("label",y("Search posts and pages in the graph")),r.setAttribute("hide-label",""),r.setAttribute("clearable",""),r.setAttribute("placeholder",y("Search nodes…")),i.appendChild(r);const c=document.createElement("ul");c.className="os-content-graph__search-results",c.hidden=!0,i.appendChild(c),s.appendChild(i);const u=()=>r.value??"",d=()=>{const m=u().trim().toLowerCase();if(m.length===0){c.hidden=!0,c.replaceChildren();return}const v=t.getNodes().filter(E=>E.title.toLowerCase().includes(m)).slice(0,10);c.replaceChildren();for(const E of v){const k=document.createElement("li"),N=document.createElement("button");N.type="button",N.className="os-content-graph__search-result",N.innerHTML=`<span class="os-content-graph__search-title">${ue(E.title||"#"+E.id)}</span><span class="os-content-graph__search-type">${ue(E.type)}</span>`,N.addEventListener("click",()=>{r.value="",c.hidden=!0,c.replaceChildren(),t.onSearchSelect(E)}),k.appendChild(N),c.appendChild(k)}c.hidden=v.length===0};r.addEventListener("os-input-change",d),r.addEventListener("focusin",d),r.addEventListener("focusout",()=>{setTimeout(()=>{c.hidden=!0},120)});const l=document.createElement("os-select");l.className="os-content-graph__group-by",l.setAttribute("value",pe),l.setAttribute("aria-label",y("Group by")),l.title=y("Group posts by a shared facet");for(const[m,v]of[[pe,y("No grouping")],["category",y("Group by category")],["tag",y("Group by tag")],["author",y("Group by author")],["year",y("Group by year")],["year_month",y("Group by year-month")]]){const E=document.createElement("os-option");E.setAttribute("value",m),E.textContent=v,l.appendChild(E)}l.addEventListener("os-pick",m=>{const E=m.detail?.value??pe,k=E===pe?null:E;t.onGroupChange(k)}),s.insertBefore(l,i);const p=document.createElement("div");p.className="os-content-graph__actions";const b=document.createElement("os-button");b.setAttribute("variant","ghost"),b.innerHTML=`<span class="dashicons dashicons-editor-expand" aria-hidden="true"></span><span>${ue(y("Fit"))}</span>`,b.title=y("Fit graph to view"),b.addEventListener("click",()=>t.onFitToView()),p.appendChild(b);const g=document.createElement("span");g.className="os-content-graph__toolbar-status",g.setAttribute("role","status"),p.appendChild(g),s.appendChild(p);const _=m=>{i.contains(m.target)||(c.hidden=!0)};return document.addEventListener("click",_),{setStatus:m=>{g.textContent=m},updateCounts:m=>{for(const v of m){const E=o.querySelector(`.os-content-graph__chip[data-slug="${Ze(v.slug)}"] .os-content-graph__chip-count`);E&&(E.textContent=String(v.count??0))}},destroy:()=>{document.removeEventListener("click",_)}}}function ue(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Ze(s){return s.replace(/[^a-zA-Z0-9 _\-]/g,"")}const gn="my-wordpress",Z=xe("desktop-mode/my-wordpress/open-target",()=>({kind:null,entityId:"",id:0,title:"",requestedAt:0}));function yn(s){Z.state.kind=s.kind,Z.state.entityId=s.entityId,Z.state.id=s.id,Z.state.title=s.title,Z.state.requestedAt=Date.now(),Z.notify()}function wn(s){const e=window.wp?.os?.openWindow;e?.(gn,{source:s})}function bn(s){const e=Number(s.postId);!Number.isFinite(e)||e<=0||(yn({kind:"detail",entityId:s.entityId||"posts",id:e,title:s.postTitle??""}),wn("my-wordpress/open-detail"))}function H(s){const e=document.createElement("textarea");return e.innerHTML=s,e.value}function _n(s,e,t){s.replaceChildren(),s.hidden=!1,s.classList.add("os-content-graph__panel--closed");const n=a=>{s.classList.toggle("os-content-graph__panel--closed",!a)};let o=null,i={kind:"post"},r=0;const c=document.createElement("div");c.className="os-content-graph__panel-frame";const u=document.createElement("nav");u.className="os-content-graph__panel-breadcrumb",u.hidden=!0;const d=document.createElement("header");d.className="os-content-graph__panel-head";const l=document.createElement("div");l.className="os-content-graph__panel-title-wrap";const p=document.createElement("h2");p.className="os-content-graph__panel-title";const b=document.createElement("p");b.className="os-content-graph__panel-meta",l.appendChild(p),l.appendChild(b);const g=document.createElement("button");g.type="button",g.className="os-content-graph__panel-close",g.innerHTML='<span class="dashicons dashicons-no-alt" aria-hidden="true"></span>',g.title=y("Close panel"),g.addEventListener("click",()=>t.onClose()),d.appendChild(l),d.appendChild(g);const _=document.createElement("div");_.className="os-content-graph__panel-body",c.appendChild(u),c.appendChild(d),c.appendChild(_),s.appendChild(c);let m=k();_.append(m);let v=null,E=0;function k(){const a=document.createElement("div");return a.className="os-content-graph__panel-page",a}const N=(a,f,h)=>{if(_.append(f),a===f||h==="none"){a!==f&&a.remove();return}const w=h==="forward"?"page-from-right":"page-from-left",x=h==="forward"?"page-to-left":"page-to-right";f.classList.add(`os-content-graph__${w}`),f.offsetWidth;const S=++E;requestAnimationFrame(()=>{S===E&&(f.classList.remove(`os-content-graph__${w}`),a.classList.add(`os-content-graph__${x}`))});let A=!1;const M=()=>{A||(A=!0,a.removeEventListener("transitionend",M),a.remove())};a.addEventListener("transitionend",M),setTimeout(M,360)},I=a=>{switch(a.kind){case"post":return null;case"user":return`user:${a.user.id}`;case"term":return`term:${a.term.taxonomy}:${a.term.id}`;case"comment":return`comment:${a.comment.id}`;case"media":return`media:${a.media.id}`;case"revision":return`revision:${a.revision.id}`}},O=()=>(window.wp??{}).os??{},C=(a,f,h,w)=>{const x=O();if(!x.windowManager||!x.deriveWindowId||!a){a&&(window.location.href=a);return}const S=x.windowManager.getFocused?.();S?.isFullscreen?.()&&S.toggleFullscreen?.();let A=x.deriveWindowId(a);w&&(A=`${A}-${w}`),x.windowManager.open({id:A,baseId:A,url:a,title:f,icon:h})},P=()=>{if(u.replaceChildren(),i.kind==="post"||!o){u.hidden=!0;return}u.hidden=!1;const a=document.createElement("button");a.type="button",a.className="os-content-graph__panel-breadcrumb-back";const f=document.createElement("span");f.className="dashicons dashicons-arrow-left-alt2 os-content-graph__panel-breadcrumb-arrow",f.setAttribute("aria-hidden","true");const h=document.createElement("span");h.className="os-content-graph__panel-breadcrumb-label",h.textContent=H(o.post.title)||`#${o.post.id}`,a.appendChild(f),a.appendChild(h),a.title=y("Back to post"),a.addEventListener("click",()=>{i={kind:"post"},L()}),u.appendChild(a)},L=()=>{n(!0),P();const a=k(),f=m;switch(m=a,i.kind){case"post":z(o);break;case"user":cs(i);break;case"term":ls(i);break;case"comment":ds(i);break;case"media":hs(i.media);break;case"revision":ps(i.revision);break}let h="none";v!==null&&v!==i.kind&&(i.kind==="post"?h="back":h="forward"),N(f,a,h),t.onViewChange?.(I(i)),v=i.kind},z=a=>{if(!a){p.textContent="",b.textContent="";return}p.textContent=H(a.post.title)||`#${a.post.id}`,b.textContent=`${a.post.type} · ${a.post.status}`,m.appendChild(we(a)),m.appendChild(ie(a)),m.appendChild(U([{label:y("Contributors"),value:a.contributors.length},{label:y("Comments"),value:a.comments.length},{label:y("Taxonomies"),value:a.categories.length},{label:y("Media"),value:a.attached_media.length},{label:y("Revisions"),value:a.revisions.length}])),m.appendChild(ee(a))},we=a=>{const f=document.createElement("div");if(f.className="os-content-graph__panel-author",!a.author)return f.hidden=!0,f;const h=document.createElement("span");h.className="os-content-graph__panel-section-label",h.textContent=y("Author"),f.appendChild(h);const w=document.createElement("div");if(w.className="os-content-graph__panel-author-row",a.author.avatar){const S=document.createElement("img");S.className="os-content-graph__panel-avatar",S.src=a.author.avatar,S.alt="",w.appendChild(S)}const x=document.createElement("span");return x.className="os-content-graph__panel-author-name",x.textContent=a.author.name,w.appendChild(x),f.appendChild(w),f},ie=a=>{const f=document.createElement("div");f.className="os-content-graph__panel-dates";const h=[];if(a.post.date&&h.push({label:y("Published"),iso:a.post.date}),a.post.modified&&a.post.modified!==a.post.date&&h.push({label:y("Modified"),iso:a.post.modified}),h.length===0)return f.hidden=!0,f;for(const w of h){const x=document.createElement("div");x.className="os-content-graph__panel-date-row";const S=document.createElement("span");S.className="os-content-graph__panel-section-label",S.textContent=w.label;const A=document.createElement("span");A.className="os-content-graph__panel-date-value",A.textContent=Q(w.iso),x.appendChild(S),x.appendChild(A),f.appendChild(x)}return f},U=a=>{const f=document.createElement("ul");f.className="os-content-graph__panel-stats";for(const h of a){const w=document.createElement("li");w.className="os-content-graph__panel-stat";const x=document.createElement("span");x.className="os-content-graph__panel-stat-num",x.textContent=typeof h.value=="number"?fe(h.value):h.value;const S=document.createElement("span");S.className="os-content-graph__panel-stat-label",S.textContent=h.label,w.appendChild(x),w.appendChild(S),f.appendChild(w)}return f},ee=a=>{const f=document.createElement("div");f.className="os-content-graph__panel-actions";{const h=be({label:te(y("Open in %s"),je().siteName?.trim()||y("WordPress")),icon:"dashicons-wordpress",primary:!0});h.addEventListener("click",()=>{bn({entityId:a.post.type==="page"?"pages":"posts",postId:a.post.id,postTitle:H(a.post.title)||`#${a.post.id}`})}),f.appendChild(h)}if(a.post.edit_url){const h=be({label:y("Edit"),icon:"dashicons-edit"});h.addEventListener("click",()=>C(a.post.edit_url,H(a.post.title),"dashicons-admin-post",`post-${a.post.id}`)),f.appendChild(h)}if(a.post.view_url){const h=be({label:y("View"),icon:"dashicons-external"});h.addEventListener("click",()=>C(a.post.view_url,H(a.post.title),"dashicons-admin-post",`post-${a.post.id}`)),f.appendChild(h)}return f},cs=a=>{const{user:f,role:h,stats:w,loading:x}=a;p.textContent=w?.profile.name??f.name,b.textContent=y(h==="author"?"Author":"Contributor");const S=document.createElement("div");S.className="os-content-graph__panel-detail-head";const A=w?.profile.avatarUrl||f.avatar;if(A){const T=document.createElement("img");T.className="os-content-graph__panel-detail-avatar os-content-graph__panel-detail-avatar--lg",T.src=A,T.alt="",S.appendChild(T)}const M=document.createElement("div");if(M.className="os-content-graph__panel-detail-handle",M.innerHTML=`<strong>${R(w?.profile.name??f.name)}</strong><span>@${R(f.slug)}</span>`,S.appendChild(M),m.appendChild(S),w?.profile.roleLabels?.length&&m.appendChild(bt(y("Roles"),w.profile.roleLabels)),w?.profile.description&&m.appendChild($e(y("About"),w.profile.description)),w?.profile.website&&m.appendChild(us(y("Website"),w.profile.website,w.profile.website)),w){const T=w.counts;m.appendChild(U([{label:y("Posts"),value:T.posts.total},{label:y("Pages"),value:T.pages.total},{label:y("CPT"),value:T.cpt},{label:y("Comments received"),value:T.commentsReceived},{label:y("Comments left"),value:T.commentsLeft}]))}w?.topTerms?.length&&m.appendChild(_t(y("Top topics"),w.topTerms)),w&&m.appendChild(xt([{label:y("First published"),iso:w.milestones.firstPublished},{label:y("Last published"),iso:w.milestones.lastPublished}])),x&&m.appendChild(Oe()),m.appendChild(re({label:y("Open in WordPress"),icon:"dashicons-admin-users",href:f.edit_url,title:f.name,primary:!0,windowKey:`user-${f.id}`}))},ls=a=>{const{term:f,stats:h,loading:w}=a;p.textContent=h?.profile.name??f.name,b.textContent=`${h?.profile.taxonomyLabel??f.tax_label} · ${h?.profile.taxonomy??f.taxonomy}`,h?.profile.parentName&&m.appendChild(Re([{label:y("Parent"),value:h.profile.parentName}])),h?.profile.description&&m.appendChild($e(y("Description"),h.profile.description)),h?m.appendChild(U([{label:y("Posts"),value:h.counts.posts.total},{label:y("Comments"),value:h.counts.commentsReceived},{label:y("Authors"),value:h.counts.distinctAuthors}])):m.appendChild(U([{label:y("Posts"),value:f.count}])),h?.topAuthors?.length&&m.appendChild(fs(y("Top authors"),h.topAuthors)),h?.coTerms?.length&&m.appendChild(_t(y("Co-occurring"),h.coTerms.map(x=>({...x,taxonomy:f.taxonomy})))),h&&m.appendChild(xt([{label:y("First post"),iso:h.milestones.firstPosted},{label:y("Latest post"),iso:h.milestones.lastPosted}])),w&&m.appendChild(Oe()),m.appendChild(re({label:y("Open in WordPress"),icon:"dashicons-tag",href:f.edit_url,title:f.name,primary:!0}))},ds=a=>{const{comment:f,stats:h,loading:w}=a,x=h?.author.name??f.author;p.textContent=x||`#${f.id}`,b.textContent=Q(h?.comment.date??f.date);const S=h?.author.avatarUrl;if(S){const T=document.createElement("div");T.className="os-content-graph__panel-detail-head";const V=document.createElement("img");V.className="os-content-graph__panel-detail-avatar os-content-graph__panel-detail-avatar--lg",V.src=S,V.alt="",T.appendChild(V);const B=document.createElement("div");B.className="os-content-graph__panel-detail-handle",B.innerHTML=`<strong>${R(x)}</strong>`+(h?.author.totalApprovedComments?`<span>${fe(h.author.totalApprovedComments)} ${R(y("comments"))}</span>`:""),T.appendChild(B),m.appendChild(T)}const A=h?.comment.status??y("—");m.appendChild(bt(y("Status"),[A],{accent:A==="1"||A==="approved"?"green":"amber"}));const M=h?.comment.rendered;if(M){const T=document.createElement("div");T.className="os-content-graph__panel-detail-section";const V=document.createElement("span");V.className="os-content-graph__panel-section-label",V.textContent=y("Comment"),T.appendChild(V);const B=document.createElement("div");B.className="os-content-graph__panel-detail-html",B.innerHTML=M,T.appendChild(B),m.appendChild(T)}else f.excerpt&&m.appendChild($e(y("Comment"),f.excerpt));if(h?.parent){const T=document.createElement("blockquote");T.className="os-content-graph__panel-detail-quote",T.innerHTML=`<strong>${R(h.parent.authorName)}</strong><span>${R(h.parent.excerpt)}</span>`,m.appendChild(T)}h?.replies?.length&&m.appendChild(ms(h.replies)),w&&m.appendChild(Oe()),m.appendChild(re({label:y("Open in WordPress"),icon:"dashicons-admin-comments",href:f.edit_url,title:x||y("Comment"),primary:!0}))},hs=a=>{if(p.textContent=a.title||`#${a.id}`,b.textContent=a.mime||y("Media"),a.thumb){const f=document.createElement("div");f.className="os-content-graph__panel-detail-thumb";const h=document.createElement("img");h.src=a.thumb,h.alt=a.title||"",f.appendChild(h),m.appendChild(f)}m.appendChild(Re([{label:y("Type"),value:a.mime}])),m.appendChild(re({label:y("Open in WordPress"),icon:"dashicons-admin-media",href:a.edit_url,title:a.title,primary:!0}))},ps=a=>{if(p.textContent=a.author?.name??y("Revision"),b.textContent=Q(a.date),a.author){const f=document.createElement("div");if(f.className="os-content-graph__panel-detail-head",a.author.avatar){const w=document.createElement("img");w.className="os-content-graph__panel-detail-avatar os-content-graph__panel-detail-avatar--lg",w.src=a.author.avatar,w.alt="",f.appendChild(w)}const h=document.createElement("div");h.className="os-content-graph__panel-detail-handle",h.innerHTML=`<strong>${R(a.author.name)}</strong><span>@${R(a.author.slug)}</span>`,f.appendChild(h),m.appendChild(f)}m.appendChild(Re([{label:y("Saved"),value:Q(a.date)}])),m.appendChild(re({label:y("Open revision in WordPress"),icon:"dashicons-backup",href:a.edit_url,title:y("Revision"),primary:!0,windowKey:`revision-${a.id}`}))},$e=(a,f)=>{const h=document.createElement("div");h.className="os-content-graph__panel-detail-section";const w=document.createElement("span");w.className="os-content-graph__panel-section-label",w.textContent=a;const x=document.createElement("p");return x.className="os-content-graph__panel-detail-prose",x.textContent=f,h.appendChild(w),h.appendChild(x),h},bt=(a,f,h={})=>{const w=document.createElement("div");w.className="os-content-graph__panel-detail-section";const x=document.createElement("span");x.className="os-content-graph__panel-section-label",x.textContent=a,w.appendChild(x);const S=document.createElement("div");S.className="os-content-graph__panel-badges";for(const A of f){const M=document.createElement("span");M.className="os-content-graph__panel-badge"+(h.accent?` os-content-graph__panel-badge--${h.accent}`:""),M.textContent=A,S.appendChild(M)}return w.appendChild(S),w},Re=a=>{const f=document.createElement("div");f.className="os-content-graph__panel-inline-meta";for(const h of a){if(!h.value)continue;const w=document.createElement("div");w.className="os-content-graph__panel-inline-meta-row";const x=document.createElement("span");x.className="os-content-graph__panel-section-label",x.textContent=h.label;const S=document.createElement("span");S.className="os-content-graph__panel-date-value",S.textContent=h.value,w.appendChild(x),w.appendChild(S),f.appendChild(w)}return f},us=(a,f,h)=>{const w=document.createElement("div");w.className="os-content-graph__panel-detail-section";const x=document.createElement("span");x.className="os-content-graph__panel-section-label",x.textContent=a;const S=document.createElement("a");return S.className="os-content-graph__panel-detail-link",S.href=h,S.textContent=f,S.target="_blank",S.rel="noopener noreferrer",w.appendChild(x),w.appendChild(S),w},_t=(a,f)=>{const h=document.createElement("div");h.className="os-content-graph__panel-detail-section";const w=document.createElement("span");w.className="os-content-graph__panel-section-label",w.textContent=a,h.appendChild(w);const x=document.createElement("ul");x.className="os-content-graph__panel-chips";for(const S of f.slice(0,8)){const A=document.createElement("li");A.className="os-content-graph__panel-chip",A.innerHTML=`<span>${R(S.name)}</span><span class="os-content-graph__panel-chip-count">${fe(S.count)}</span>`,x.appendChild(A)}return h.appendChild(x),h},fs=(a,f)=>{const h=document.createElement("div");h.className="os-content-graph__panel-detail-section";const w=document.createElement("span");w.className="os-content-graph__panel-section-label",w.textContent=a,h.appendChild(w);const x=document.createElement("ul");x.className="os-content-graph__panel-author-list";for(const S of f.slice(0,6)){const A=document.createElement("li");A.className="os-content-graph__panel-author-list-row",A.innerHTML=(S.userAvatarUrl?`<img class="os-content-graph__panel-avatar" src="${Qe(S.userAvatarUrl)}" alt="" />`:"")+`<span class="os-content-graph__panel-author-name">${R(S.userName)}</span><span class="os-content-graph__panel-chip-count">${fe(S.count)}</span>`,x.appendChild(A)}return h.appendChild(x),h},xt=a=>{const f=a.filter(S=>S.iso),h=document.createElement("div");if(h.className="os-content-graph__panel-detail-section",f.length===0)return h.hidden=!0,h;const w=document.createElement("span");w.className="os-content-graph__panel-section-label",w.textContent=y("Milestones"),h.appendChild(w);const x=document.createElement("div");x.className="os-content-graph__panel-milestones";for(const S of f){const A=document.createElement("div");A.className="os-content-graph__panel-milestone-row";const M=document.createElement("span");M.className="os-content-graph__panel-milestone-key",M.textContent=S.label;const T=document.createElement("span");T.className="os-content-graph__panel-date-value",T.textContent=Q(S.iso),A.appendChild(M),A.appendChild(T),x.appendChild(A)}return h.appendChild(x),h},ms=a=>{const f=document.createElement("div");f.className="os-content-graph__panel-detail-section";const h=document.createElement("span");h.className="os-content-graph__panel-section-label",h.textContent=te(vt("Reply (%d)","Replies (%d)",a.length),a.length),f.appendChild(h);const w=document.createElement("ul");w.className="os-content-graph__panel-replies";for(const x of a.slice(0,5)){const S=document.createElement("li");S.className="os-content-graph__panel-reply",S.innerHTML=`<header><strong>${R(x.authorName)}</strong><span>${Q(x.date)}</span></header><p>${R(x.excerpt)}</p>`,w.appendChild(S)}return f.appendChild(w),f},Oe=()=>{const a=document.createElement("div");return a.className="os-content-graph__panel-detail-loading",a.innerHTML=`<os-spinner></os-spinner><span>${R(y("Loading details…"))}</span>`,a},re=a=>{const f=document.createElement("div");if(f.className="os-content-graph__panel-actions",!a.href)return f.hidden=!0,f;const h=be({label:a.label,icon:a.icon,primary:a.primary});return h.addEventListener("click",()=>C(a.href,a.title,a.icon,a.windowKey)),f.appendChild(h),f},be=a=>{const f=document.createElement("button");return f.type="button",f.className="os-content-graph__btn"+(a.primary?" os-content-graph__btn--primary":""),f.innerHTML=`<span class="dashicons ${Qe(a.icon)}" aria-hidden="true"></span><span>${R(a.label)}</span>`,f};return{setLoading:(a,f)=>{n(!0),u.hidden=!0,i={kind:"post"},v=null,p.textContent=f?H(f):`#${a}`,b.textContent=y("Loading…"),_.replaceChildren(),m=k(),_.append(m);const h=document.createElement("div");h.className="os-content-graph__panel-loading",h.innerHTML="<os-spinner></os-spinner>",m.appendChild(h),t.onViewChange?.(null)},setError:a=>{n(!0),u.hidden=!0,i={kind:"post"},v=null,_.replaceChildren(),m=k(),_.append(m);const f=document.createElement("p");f.className="os-content-graph__panel-empty",f.textContent=a,m.appendChild(f),t.onViewChange?.(null)},setDetail:a=>{o=a,i={kind:"post"},L()},showUser:a=>{if(!o)return;const f=o.author?.id===a,h=f?o.author:o.contributors.find(x=>x.id===a);if(!h)return;i={kind:"user",user:h,role:f?"author":"contributor",stats:null,loading:!0},L();const w=++r;pn(e,a).then(x=>{w!==r||i.kind!=="user"||i.user.id!==a||(i={...i,stats:x,loading:!1},L())}).catch(x=>{w!==r||i.kind!=="user"||i.user.id!==a||(i={...i,loading:!1},L(),console.warn("[content-graph] user-stats failed",x))})},showTerm:(a,f)=>{if(!o)return;const h=o.categories.find(x=>x.id===a&&x.taxonomy===f);if(!h)return;i={kind:"term",term:h,stats:null,loading:!0},L();const w=++r;un(e,f,a).then(x=>{w!==r||i.kind!=="term"||i.term.id!==a||(i={...i,stats:x,loading:!1},L())}).catch(x=>{w!==r||i.kind!=="term"||i.term.id!==a||(i={...i,loading:!1},L(),console.warn("[content-graph] term-stats failed",x))})},showComment:a=>{if(!o)return;const f=o.comments.find(w=>w.id===a);if(!f)return;i={kind:"comment",comment:f,stats:null,loading:!0},L();const h=++r;fn(e,a).then(w=>{h!==r||i.kind!=="comment"||i.comment.id!==a||(i={...i,stats:w,loading:!1},L())}).catch(w=>{h!==r||i.kind!=="comment"||i.comment.id!==a||(i={...i,loading:!1},L(),console.warn("[content-graph] comment-stats failed",w))})},showMedia:a=>{if(!o)return;const f=o.attached_media.find(h=>h.id===a);f&&(i={kind:"media",media:f},L())},showRevision:a=>{if(!o)return;const f=o.revisions.find(h=>h.id===a);f&&(i={kind:"revision",revision:f},L())},hide:()=>{n(!1)},destroy:()=>{s.replaceChildren()}}}function Q(s){if(!s)return"";try{return new Date(s).toLocaleString()}catch{return s}}function fe(s){try{return new Intl.NumberFormat().format(s)}catch{return String(s)}}function R(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Qe(s){return s.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}const Je=Object.freeze({top:0,right:0,bottom:0,left:0});function xn(s,e,t,n){return{left:s,top:e,width:t,height:n,right:s+t,bottom:e+n}}function vn(s,e){const t=o=>Math.min(Math.max(0,e.width),Math.max(0,o)),n=o=>Math.min(Math.max(0,e.height),Math.max(0,o));return{top:n(s.top-e.top),bottom:n(e.bottom-s.bottom),left:t(s.left-e.left),right:t(e.right-s.right)}}const Cn="os/work-area";function En(){return{insets:{...Je},rect:{x:0,y:0,width:0,height:0},viewport:{x:0,y:0,width:0,height:0},area:{width:0,height:0}}}const et=xe(Cn,()=>({snapshot:En(),installed:!1,areaEl:null}));function Sn(s){return{insets:{...s.insets},rect:{...s.rect},viewport:{...s.viewport},area:{...s.area}}}function me(s){const{installed:e,snapshot:t}=et.state;if(!e)return{...Je};const n=t.viewport;return vn(xn(n.x,n.y,n.width,n.height),s.getBoundingClientRect())}function Nn(s){return et.subscribe(e=>{s(Sn(e.snapshot))})}function kn(){return window.PIXI??null}const An=12,Tn=80,In=700;function Ln(s){return 120+18*s}function tt(s=Math.random){const e=s()*Math.PI*2,t=150+s()*250;return{x:Math.cos(e)*t,y:Math.sin(e)*t}}function Mn(s,e=Math.random){if(s<=0)return[];if(s===1)return[{x:0,y:0}];if(s<=An){const c=Ln(s),u=[];for(let d=0;d<s;d++){const l=Math.PI+d*Math.PI*2/s;u.push({x:Math.cos(l)*c,y:Math.sin(l)*c})}return u}const t=[];let n=0,o=0;for(let c=0;c<s;c++){const u=tt(e);t.push(u),n+=u.x,o+=u.y}const i=n/s,r=o/s;for(const c of t)c.x-=i,c.y-=r;return t}const nt=90;function $n(s){return s<=Tn?In:nt}function Rn(s,e,t){if(e.width<=0||e.height<=0)return null;let n=1/0,o=1/0,i=-1/0,r=-1/0;for(const _ of s)_.x<n&&(n=_.x),_.y<o&&(o=_.y),_.x>i&&(i=_.x),_.y>r&&(r=_.y);if(n===1/0)return null;const c=i-n+t.padding*2,u=r-o+t.padding*2,d=e.width/c,l=e.height/u,p=Math.max(t.minScale,Math.min(t.maxScale,Math.min(d,l))),b=(n+i)/2,g=(o+r)/2;return{scale:p,x:e.width/2-b*p,y:e.height/2-g*p}}function st(s){return Math.hypot(s.b.x-s.a.x,s.b.y-s.a.y)}function ot(s){return{x:(s.a.x+s.b.x)/2,y:(s.a.y+s.b.y)/2}}function On(s,e,t,n){const o=st(e),i=st(t),r=o>0&&i>0?i/o:1,c=Math.max(n.min,Math.min(n.max,s.scale*r)),u=ot(e),d=ot(t),l=(u.x-s.x)/s.scale,p=(u.y-s.y)/s.scale;return{scale:c,x:d.x-l*c,y:d.y-p*c}}const Pn={repulsion:26e3,springK:.04,springLen:200,gravity:.0035,damping:.86},Dn=.992,Fn=.01,it=1,F=12;class Wn{constructor(e,t,n=Pn){this.dragOrigin=null,this.dragInfluenceRadius=500,this.groupAssignment=null,this.groupOrder=null,this.groupAttractorStrength=.12,this.groupOrderSpacing=320,this.groupOrderStaggerY=0,this.alpha=it,this.nodes=e,this.edges=t,this.opts=n}reheat(e=it,t=!0){if(this.alpha=Math.max(this.alpha,e),!t)return;const n=e*3;for(const o of this.nodes)o.pinned||(o.vx+=(Math.random()-.5)*n,o.vy+=(Math.random()-.5)*n)}get isSettled(){return this.alpha<Fn}step(e=1){if(this.isSettled)return;const{repulsion:t,springK:n,springLen:o,gravity:i,damping:r}=this.opts,c=this.nodes,u=c.length;for(let g=0;g<u;g++){const _=c[g];for(let m=g+1;m<u;m++){const v=c[m];let E=_.x-v.x,k=_.y-v.y,N=E*E+k*k;N<.01&&(E=(g-m)*.5,k=(g+m)*.5,N=E*E+k*k);const I=t/N,O=Math.sqrt(N),C=E/O*I,P=k/O*I,L=_.pinned?0:1,z=v.pinned?0:1;_.vx+=C*L,_.vy+=P*L,v.vx-=C*z,v.vy-=P*z}}for(const g of this.edges){const _=g.to.x-g.from.x,m=g.to.y-g.from.y,v=Math.sqrt(_*_+m*m)||1e-4,E=(v-o)*n,k=_/v*E,N=m/v*E;g.from.pinned||(g.from.vx+=k,g.from.vy+=N),g.to.pinned||(g.to.vx-=k,g.to.vy-=N)}this.applyClusterAttractor();const d=this.alpha,l=this.dragOrigin,p=this.dragInfluenceRadius,b=p*p;for(const g of c)if(!g.pinned){g.vx-=g.x*i,g.vy-=g.y*i,g.vx*=r,g.vy*=r,g.vx>F?g.vx=F:g.vx<-F&&(g.vx=-F),g.vy>F?g.vy=F:g.vy<-F&&(g.vy=-F);let _=d;if(l){const m=g.x-l.x,v=g.y-l.y,E=m*m+v*v;if(E>=b)_=0;else{const k=1-Math.sqrt(E)/p;_*=k*k*(3-2*k)}}g.x+=g.vx*_*e,g.y+=g.vy*_*e}this.alpha*=Dn}applyClusterAttractor(){const e=this.groupAssignment;if(!e)return;const t=this.groupAttractorStrength;if(t<=0)return;const n=new Map,o=new Map;if(this.groupOrder&&this.groupOrder.length>0){const r=this.groupOrder.length,c=this.groupOrderSpacing,u=this.groupOrderStaggerY;for(let d=0;d<r;d++){const l=this.groupOrder[d];n.set(l,(d-(r-1)/2)*c),u>0&&o.set(l,d%2===0?-u:u)}}const i=new Map;for(const r of this.nodes){const c=e.get(r.id);if(!(!c||c.length===0))for(const u of c){const d=i.get(u);d?(d.sx+=r.x,d.sy+=r.y,d.count++):i.set(u,{sx:r.x,sy:r.y,count:1})}}for(const r of this.nodes){if(r.pinned)continue;const c=e.get(r.id);if(!c||c.length===0)continue;const u=t/c.length;for(const d of c){const l=i.get(d);if(!l||l.count===0)continue;const p=n.has(d)?n.get(d):l.sx/l.count,b=o.has(d)?o.get(d):l.sy/l.count;r.vx+=(p-r.x)*u,r.vy+=(b-r.y)*u}}}setGroupAssignment(e,t=null){this.groupAssignment=e,this.groupOrder=e?t:null,this.reheat(.3,!1)}}const rt={user:3829232,term:2926970,comment:15239482,media:10510036,revision:7042949},at={user:"admin-users",term:"tag",comment:"admin-comments",media:"admin-media",revision:"backup"};function Vn(s){switch(s.taxonomy){case"category":return"category";case"post_tag":return"tag";default:return at.term}}const Gn={user:{x:0,y:3},term:{x:0,y:3},comment:{x:1,y:4},media:{x:-1,y:1},revision:{x:0,y:3}},ge=14;class Hn{constructor(e,t,n,o,i,r){this.pixi=e,this.satelliteParent=t,this.spokeParent=n,this.onClick=o,this.hostEl=i,this.claimPointer=r,this.views=[],this.focused=null,this.rafId=null,this.selectedKey=null,this.linkGfx=new e.Graphics,this.spokeParent.addChild(this.linkGfx),this.layer=new e.Container,this.satelliteParent.addChild(this.layer),this.hoverEl=document.createElement("div"),this.hoverEl.className="os-content-graph__tooltip",this.hoverEl.hidden=!0,this.hostEl.appendChild(this.hoverEl)}clear(){this.linkGfx.clear(),this.layer.removeChildren(),this.views=[],this.focused=null,this.selectedKey=null,this.hideTooltip()}drawLinks(){if(this.linkGfx.clear(),!this.focused||this.views.length===0)return;const e=this.focused.radius+8,t=this.focused.x,n=this.focused.y;for(const o of this.views){const i=o.container.x-t,r=o.container.y-n,c=Math.sqrt(i*i+r*r);if(c<=e)continue;const u=e/c,d=t+i*u,l=n+r*u,p=rt[o.ref.kind];this.linkGfx.moveTo(d,l).lineTo(o.container.x,o.container.y).stroke({color:p,width:o.selected?1.8:1.4,alpha:o.selected?.85:.5})}}setFocused(e,t){this.clear(),this.focused=e;const n=this.flattenDetail(t);if(n.length===0)return;const o=e.radius,r=Math.max(o+86,o+70+n.length*36/(2*Math.PI)),c=-Math.PI/2,u=2*Math.PI/n.length;n.forEach((d,l)=>{const p=c+l*u,b=e.x+Math.cos(p)*r,g=e.y+Math.sin(p)*r,_=this.buildSatellite(d,e.x,e.y);_.targetX=b,_.targetY=g,this.views.push(_)}),this.animateIn()}setSelectedKey(e){if(this.selectedKey!==e){this.selectedKey=e;for(const t of this.views){const n=t.key===e;n!==t.selected&&(t.selected=n,this.repaintDisc(t))}this.drawLinks()}}destroy(){this.rafId!==null&&(cancelAnimationFrame(this.rafId),this.rafId=null),this.clear(),this.layer.destroy({children:!0}),this.linkGfx.destroy(),this.hoverEl.remove()}flattenDetail(e){const t=[];e.author&&t.push({kind:"user",userId:e.author.id,label:e.author.name,meta:y("Author"),avatar:e.author.avatar});for(const n of e.contributors.slice(0,8))t.push({kind:"user",userId:n.id,label:n.name,meta:y("Contributor"),avatar:n.avatar});for(const n of e.categories.slice(0,12))t.push({kind:"term",termId:n.id,taxonomy:n.taxonomy,label:n.name,meta:te(y("%1$s · %2$d posts"),n.tax_label,n.count)});for(const n of e.comments.slice(0,8))t.push({kind:"comment",commentId:n.id,label:n.author,meta:n.excerpt||lt(n.date)});for(const n of e.attached_media.slice(0,12))t.push({kind:"media",mediaId:n.id,label:n.title,meta:n.mime,thumb:n.thumb});for(const n of e.revisions.slice(0,8))t.push({kind:"revision",revisionId:n.id,parentId:e.post.id,label:n.author?.name??y("Revision"),meta:lt(n.date)});return t}buildSatellite(e,t,n){const o=new this.pixi.Container;o.x=t,o.y=n,o.alpha=0,o.eventMode="static",o.cursor="pointer";const i=ge+4;o.hitArea={contains:(N,I)=>N>=-i&&N<=i&&I>=-i&&I<=i+18};const r=new this.pixi.Graphics;o.addChild(r);const c=e.kind==="term"?Vn(e):at[e.kind],u=ve(c),d=new this.pixi.Text({text:u??"?",style:{fontFamily:u?"dashicons":"sans-serif",fontSize:u?20:13,fill:16777215},resolution:2,anchor:{x:.5,y:.5}}),l=Gn[e.kind];d.x=l?.x??0,d.y=l?.y??0,o.addChild(d);const p=zn(e.label||"—",28),b=new this.pixi.Graphics;o.addChild(b);const g=new this.pixi.Text({text:p,style:{fill:1711915,fontSize:11,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',fontWeight:"500"},resolution:2,anchor:{x:.5,y:0}});g.x=0,g.y=ge+2,o.addChild(g);const _=6,m=1,v=g.width+_*2,E=g.height+m*2;b.roundRect(-v/2,g.y-m,v,E,4).fill({color:16777215,alpha:.92}).stroke({color:0,alpha:.08,width:1}),o.on("pointerdown",N=>{N.stopPropagation?.(),this.claimPointer()}),o.on("pointerover",N=>{r.alpha=1;const I=N;this.showTooltip(e,I.global)}),o.on("pointermove",N=>{const I=N;this.showTooltip(e,I.global)}),o.on("pointerout",()=>{r.alpha=.95,this.hideTooltip()}),o.on("pointertap",N=>{N.stopPropagation?.(),this.hideTooltip(),this.setSelectedKey(ct(e)),this.onClick(e)}),this.layer.addChild(o);const k={ref:e,key:ct(e),container:o,disc:r,icon:d,label:g,targetX:t,targetY:n,selected:!1};return this.repaintDisc(k),k}repaintDisc(e){const t=rt[e.ref.kind];e.disc.clear(),e.selected&&e.disc.circle(0,0,ge+6).fill({color:t,alpha:.18}),e.disc.circle(0,0,ge).fill({color:t,alpha:.95}).stroke({color:16777215,width:e.selected?2.5:1.5,alpha:1})}animateIn(){const e=performance.now(),t=240,n=this.views.map(i=>({x:i.container.x,y:i.container.y})),o=i=>{const r=Math.min(1,(i-e)/t),c=1-Math.pow(1-r,3);for(let u=0;u<this.views.length;u++){const d=this.views[u],l=n[u];d.container.x=l.x+(d.targetX-l.x)*c,d.container.y=l.y+(d.targetY-l.y)*c,d.container.alpha=c}this.drawLinks(),r<1?this.rafId=requestAnimationFrame(o):this.rafId=null};this.rafId=requestAnimationFrame(o)}showTooltip(e,t){this.hoverEl.hidden=!1,this.hoverEl.innerHTML=`<strong>${dt(e.label||"—")}</strong>`+(e.meta?`<span>${dt(e.meta)}</span>`:""),t&&(this.hoverEl.style.left=`${t.x+14}px`,this.hoverEl.style.top=`${t.y+14}px`)}hideTooltip(){this.hoverEl.hidden=!0}}function ct(s){switch(s.kind){case"user":return`user:${s.userId}`;case"term":return`term:${s.taxonomy}:${s.termId}`;case"comment":return`comment:${s.commentId}`;case"media":return`media:${s.mediaId}`;case"revision":return`revision:${s.revisionId}`}}function zn(s,e){return s.length<=e?s:s.slice(0,e-1).trimEnd()+"…"}function lt(s){if(!s)return"";try{return new Date(s).toLocaleString()}catch{return s}}function dt(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const ke=4937059,ht=2911205,Un=5213171,Bn=10135222,Yn=2911205,Ae=Math.min((typeof window<"u"&&window.devicePixelRatio||1)*1.5,3),Te=[3829232,2926970,15239482,10510036,3122616,13914255,7042949],pt=16777215,qn=1.3,Xn=0,Kn={"admin-post":{x:.06,y:.06}},jn={category:"#2c6be5",tag:"#2ca97a",author:"#7c3aed",year:"#ea580c",year_month:"#ea580c"},Ie=.15,ut=4,Zn={padding:100,minScale:Ie,maxScale:1.5},Qn=8e-4,ft=300,Jn=.18,Le=.001,mt=24;class es{constructor(e,t,n,o,i="disc"){this.groupLabelOverlay=null,this.satellites=null,this.nodeViews=new Map,this.edgeViews=[],this.groupViews=new Map,this.currentGrouping=null,this.groupCatalogs={authors:{},categories:{},tags:{}},this.groupingTween=null,this.fitFollowActive=!1,this.fitFollowStartedAt=0,this.fitFollowSawMotion=!1,this.fitFollowMaxDurationMs=3e3,this.fitFollowVelocityThreshold=1,this.nodes=[],this.edges=[],this.sim=null,this.focusedId=null,this.hoveredId=null,this.pressedNode=null,this.dragOffset={x:0,y:0},this.isPanning=!1,this.panStart={x:0,y:0,wx:0,wy:0},this.nodeClickActive=!1,this.pointers=new Map,this.pinchUntil=0,this.destroyed=!1,this.tickerCb=null,this.resizeObserver=null,this.fitInsets={top:0,right:0,bottom:0,left:0},this.unsubscribeWorkArea=null,this.lastResizeWidth=0,this.lastResizeHeight=0,this.fitPending=!1,this.targetScale=1,this.targetX=0,this.targetY=0,this.postTypeColor=new Map,this.nodeStyle="disc",this.host=e,this.callbacks=t,this.onSatelliteClick=n,this.nodeStyle=i;const r=new Map;this.postTypeBySlug=new Map;for(const c of o)r.set(c.slug,ts(c.icon)),this.postTypeBySlug.set(c.slug,c);o.forEach((c,u)=>{this.postTypeColor.set(c.slug,Te[u%Te.length])}),this.postTypeIcon=c=>r.get(c)??ss(c)}async mount(e){typeof e.loadModules=="function"&&await e.loadModules(["pixijs"]);const t=kn();if(!t)throw new Error("PIXI namespace missing after loadModules.");if(this.pixi=t,typeof document<"u"&&document.fonts)try{await document.fonts.load("16px dashicons")}catch{}const n=new t.Application;await n.init({resizeTo:this.host,backgroundAlpha:0,antialias:!0,autoDensity:!0,resolution:Ae,sharedTicker:!1}),this.app=n,this.host.appendChild(n.canvas),n.canvas.classList.add("os-content-graph__canvas"),this.world=new t.Container,this.world.x=this.host.clientWidth/2,this.world.y=this.host.clientHeight/2,this.world.scale.set(1),this.targetX=this.world.x,this.targetY=this.world.y,this.targetScale=1,n.stage.addChild(this.world),this.edgeLayer=new t.Container,this.spokeLayer=new t.Container,this.nodeLayer=new t.Container,this.labelLayer=new t.Container,this.world.addChild(this.edgeLayer,this.spokeLayer,this.nodeLayer,this.labelLayer),this.groupLabelOverlay=document.createElement("div"),this.groupLabelOverlay.className="os-content-graph__group-labels",this.host.appendChild(this.groupLabelOverlay),n.canvas.addEventListener("webglcontextlost",r=>{r.preventDefault();try{this.app?.ticker?.stop()}catch{}},!1);const o=n.renderer,i=o.render.bind(o);o.render=(...r)=>{try{return i(...r)}catch(c){try{this.app?.ticker?.stop()}catch{}console.warn("[content-graph] Pixi render threw, stopping ticker:",c);return}},this.satellites=new Hn(t,this.world,this.spokeLayer,this.onSatelliteClick,this.host,()=>{this.nodeClickActive=!0}),this.bindStageInput(n.canvas),this.bindResize(),this.tickerCb=r=>this.tick(r.deltaTime),n.ticker.add(this.tickerCb)}setData(e){const t=new Map;for(const d of this.nodes)t.set(d.id,d);this.groupCatalogs=e.groups??{authors:{},categories:{},tags:{}};const n=e.nodes.every(d=>!t.has(d.id)),o=n?Mn(e.nodes.length):null,i=e.nodes.map((d,l)=>{const p=t.get(d.id),b=o?o[l]:tt();return{...d,x:p?.x??b.x,y:p?.y??b.y,vx:0,vy:0,pinned:!1,radius:4,color:ke,degree:0}}),r=new Map;for(const d of i)r.set(d.id,d);const c=[];for(const d of e.edges){const l=r.get(d.from),p=r.get(d.to);!l||!p||(l.degree++,p.degree++,c.push({from:l,to:p}))}for(const d of i)d.radius=8+Math.min(8,Math.sqrt(d.degree)*2.4);this.nodes=i,this.edges=c,this.rebuildSprites(),this.sim=new Wn(i,c),this.sim.reheat(.12,!1);const u=n?$n(i.length):nt;for(let d=0;d<u&&!this.sim.isSettled;d++)this.sim.step(1);this.currentGrouping&&this.setGrouping(this.currentGrouping)}rebuildSprites(){this.edgeLayer.removeChildren(),this.nodeLayer.removeChildren(),this.labelLayer.removeChildren(),this.nodeViews.clear(),this.edgeViews=[];for(const e of this.edges){const t=new this.pixi.Graphics;this.edgeLayer.addChild(t),this.edgeViews.push({edge:e,gfx:t})}for(const e of this.nodes){const t=new this.pixi.Container;t.eventMode="static",t.cursor="pointer",t.hitArea=new this.pixi.Circle(0,0,Math.max(18,e.radius+8)),this.bindNodeInput(t,e),this.nodeLayer.addChild(t);const n=new this.pixi.Graphics;t.addChild(n);const o=new this.pixi.Graphics;t.addChild(o);const i=this.postTypeIcon(e.type),r=ve(i),c=new this.pixi.Text({text:r??"●",style:{fontFamily:r?"dashicons":"sans-serif",fontSize:2*e.radius,fill:ke},resolution:Ae,anchor:{x:.5,y:.5}});t.addChild(c);const u=new this.pixi.Container;this.labelLayer.addChild(u);const d=new this.pixi.Graphics;u.addChild(d);const l=new this.pixi.Text({text:this.truncate(H(e.title)||`#${e.id}`,32),style:{fill:2042167,fontSize:11,fontFamily:'-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',fontWeight:"500"},resolution:Ae,anchor:{x:.5,y:0}});u.addChild(l);const p=5,b=1,g=l.width+p*2,_=l.height+b*2;d.roundRect(-g/2,-b,g,_,4).fill({color:16777215,alpha:.78}).stroke({color:0,alpha:.06,width:1}),this.nodeViews.set(e.id,{node:e,container:t,halo:n,disc:o,icon:c,labelBox:u,labelBg:d,label:l,iconCharCode:r,iconName:i,typeColor:this.postTypeColor.get(e.type)??Te[0],discKey:""})}}truncate(e,t){return e.length<=t?e:e.slice(0,t-1).trimEnd()+"…"}bindNodeInput(e,t){let n={x:0,y:0},o=!1;const i=36;e.on("pointerdown",r=>{const c=r;c.stopPropagation?.(),n={x:c.global.x,y:c.global.y},this.nodeClickActive=!0,this.pressedNode=t,o=!1,t.pinned=!0,t.vx=0,t.vy=0}),e.on("pointerover",()=>{this.hoveredId=t.id,this.draw()}),e.on("pointerout",()=>{this.hoveredId===t.id&&(this.hoveredId=null,this.draw())}),e.on("pointerup",r=>{const c=r,u=c.global.x-n.x,d=c.global.y-n.y;!o&&u*u+d*d<=256&&!this.pinchRecent()&&this.callbacks.onNodeClick?.(t),t.pinned=this.focusedId===t.id,this.pressedNode=null,this.sim&&(this.sim.dragOrigin=null,o&&this.sim.reheat(.35,!1)),o=!1}),e.on("pointerupoutside",()=>{t.pinned=this.focusedId===t.id,this.pressedNode=null,this.sim&&(this.sim.dragOrigin=null),o=!1}),e.on("globalpointermove",r=>{if(this.pressedNode!==t)return;const c=r,u=c.global.x-n.x,d=c.global.y-n.y,l=u*u+d*d;if(!o){if(l<i)return;o=!0;const b=this.toWorld(c.global.x,c.global.y);this.dragOffset={x:t.x-b.x,y:t.y-b.y},this.sim&&(this.sim.dragOrigin={x:t.x,y:t.y},this.sim.reheat(.3,!1))}const p=this.toWorld(c.global.x,c.global.y);t.x=p.x+this.dragOffset.x,t.y=p.y+this.dragOffset.y,t.vx=0,t.vy=0,this.sim&&(this.sim.dragOrigin={x:t.x,y:t.y})})}pinchRecent(){return this.pointers.size>=2||performance.now()<this.pinchUntil}canvasPoint(e,t){const n=e.getBoundingClientRect();return{x:t.clientX-n.left,y:t.clientY-n.top}}bindStageInput(e){e.style.touchAction="none",e.addEventListener("wheel",n=>{n.preventDefault();const o=Math.exp(-n.deltaY*Qn),i=Math.max(Ie,Math.min(ut,this.targetScale*o)),r=e.getBoundingClientRect(),c=n.clientX-r.left,u=n.clientY-r.top,d=(c-this.targetX)/this.targetScale,l=(u-this.targetY)/this.targetScale;this.targetScale=i,this.targetX=c-d*i,this.targetY=u-l*i},{passive:!1}),e.addEventListener("pointerdown",n=>{if(this.pointers.set(n.pointerId,this.canvasPoint(e,n)),this.pointers.size===2){this.isPanning=!1,this.nodeClickActive=!1,this.pressedNode&&(this.pressedNode.pinned=this.focusedId===this.pressedNode.id,this.pressedNode=null,this.sim&&(this.sim.dragOrigin=null));return}n.target===e&&(this.nodeClickActive||this.pointers.size>1||(this.isPanning=!0,this.panStart={x:n.clientX,y:n.clientY,wx:this.world.x,wy:this.world.y}))}),window.addEventListener("pointermove",n=>{if(this.pointers.has(n.pointerId)){const r=this.pointers.get(n.pointerId),c=this.canvasPoint(e,n);if(this.pointers.set(n.pointerId,c),this.pointers.size===2){this.pinch(n.pointerId,r);return}}if(!this.isPanning||this.nodeClickActive||this.pointers.size>1)return;const o=this.panStart.wx+(n.clientX-this.panStart.x),i=this.panStart.wy+(n.clientY-this.panStart.y);this.world.x=o,this.world.y=i,this.targetX=o,this.targetY=i});const t=n=>{const o=this.pointers.size>=2;this.pointers.delete(n.pointerId),o&&(this.isPanning=!1,this.pinchUntil=performance.now()+ft)};window.addEventListener("pointercancel",t),window.addEventListener("pointerup",n=>{t(n);const o=this.nodeClickActive;if(this.nodeClickActive=!1,!this.isPanning)return;const i=n.clientX-this.panStart.x,r=n.clientY-this.panStart.y;this.isPanning=!1,!o&&!this.pinchRecent()&&i*i+r*r<9&&this.callbacks.onBackgroundClick?.()})}pinch(e,t){let n=null,o=null;for(const[r,c]of this.pointers)r===e?o=c:n=c;if(!o||!n)return;const i=On({scale:this.world.scale.x,x:this.world.x,y:this.world.y},{a:t,b:n},{a:o,b:n},{min:Ie,max:ut});this.world.scale.set(i.scale),this.world.x=i.x,this.world.y=i.y,this.targetScale=i.scale,this.targetX=i.x,this.targetY=i.y,this.pinchUntil=performance.now()+ft}bindResize(){this.lastResizeWidth=this.host.clientWidth,this.lastResizeHeight=this.host.clientHeight,this.resizeObserver=new ResizeObserver(()=>{if(this.destroyed)return;const e=this.host.clientWidth,t=this.host.clientHeight;if(this.fitInsets=me(this.host),e<=0||t<=0)return;try{this.app.renderer.resize(e,t)}catch{return}try{this.app.render()}catch{}this.fitPending&&this.fitToView();const n=Math.abs(e-this.lastResizeWidth),o=Math.abs(t-this.lastResizeHeight);(n>=mt||o>=mt)&&(this.lastResizeWidth=e,this.lastResizeHeight=t)}),this.resizeObserver.observe(this.host),this.unsubscribeWorkArea=Nn(()=>{this.destroyed||(this.fitInsets=me(this.host))})}toWorld(e,t){const n=this.app.canvas.getBoundingClientRect(),o=e-n.left,i=t-n.top;return{x:(o-this.world.x)/this.world.scale.x,y:(i-this.world.y)/this.world.scale.y}}tick(e){if(this.destroyed||!this.app||!this.world)return;this.groupingTween?this.advanceGroupingTween():this.sim?.step(e);const t=1-Math.pow(1-Jn,e),n=this.targetScale-this.world.scale.x;Math.abs(n)<Le?this.world.scale.set(this.targetScale):this.world.scale.set(this.world.scale.x+n*t);const o=this.targetX-this.world.x,i=this.targetY-this.world.y;Math.abs(o)<Le?this.world.x=this.targetX:this.world.x+=o*t,Math.abs(i)<Le?this.world.y=this.targetY:this.world.y+=i*t,this.draw(),this.drawGroupLabels(),this.satellites?.drawLinks(),this.advanceFitFollow()}advanceFitFollow(){if(!this.fitFollowActive)return;if(performance.now()-this.fitFollowStartedAt>this.fitFollowMaxDurationMs){this.fitFollowActive=!1;return}if(this.groupingTween)return;let e=0;for(const t of this.nodes){if(t.pinned)continue;const n=Math.hypot(t.vx,t.vy);n>e&&(e=n)}e>=this.fitFollowVelocityThreshold?(this.fitFollowSawMotion=!0,this.fitToView(!1)):this.fitFollowSawMotion&&(this.fitFollowActive=!1)}postTypeSupportsTaxonomy(e,t){return this.postTypeBySlug.get(e)?.taxonomies?.[t]??!1}postTypeLabel(e){return this.postTypeBySlug.get(e)?.label??e}deriveGroupKeys(e,t){switch(t){case"category":return this.postTypeSupportsTaxonomy(e.type,"category")?e.category_ids.length===0?["cat:uncat"]:e.category_ids.map(n=>`cat:${n}`):[`cat:type_${e.type}`];case"tag":return this.postTypeSupportsTaxonomy(e.type,"post_tag")?e.tag_ids.length===0?["tag:untagged"]:e.tag_ids.map(n=>`tag:${n}`):[`tag:type_${e.type}`];case"author":{const n=e.author_id||0,o=`author:${n}`,i=[o,o],r=Array.isArray(e.contributor_ids)?e.contributor_ids:[];for(const c of r)c>0&&c!==n&&i.push(`author:${c}`);return i}case"year":return[`year:${e.year||0}`];case"year_month":return[`ym:${e.year_month||"unknown"}`]}}labelForGroupKey(e){const t=e.indexOf(":"),n=e.slice(0,t),o=e.slice(t+1);switch(n){case"cat":{if(o==="uncat")return y("Uncategorized");if(o.startsWith("type_"))return this.postTypeLabel(o.slice(5));const i=Number(o);return this.groupCatalogs.categories[i]?.name??`#${i}`}case"tag":{if(o==="untagged")return y("Untagged");if(o.startsWith("type_"))return this.postTypeLabel(o.slice(5));const i=Number(o);return this.groupCatalogs.tags[i]?.name??`#${i}`}case"author":{const i=Number(o);return i<=0?y("Unknown author"):this.groupCatalogs.authors[i]?.name??`#${i}`}case"year":{const i=Number(o);return i<=0?y("Undated"):String(i)}case"ym":return o==="unknown"||o===""?y("Undated"):ns(o)}return e}buildGroupViews(e,t){if(!this.groupLabelOverlay)return;const n=jn[t];for(const[o,i]of e){if(i.length===0)continue;const r=`${this.labelForGroupKey(o)} (${i.length})`,c=document.createElement("div");c.className="os-content-graph__group-label",c.textContent=r,c.style.setProperty("--os-ui-cg-cluster-color",n),this.groupLabelOverlay.appendChild(c),this.groupViews.set(o,{key:o,label:r,el:c,members:i})}}clearGroupViews(){for(const e of this.groupViews.values())e.el.remove();this.groupViews.clear()}drawGroupLabels(){if(this.destroyed||this.groupViews.size===0)return;const e=1-Me(1.2,2.4,this.world.scale.x),t=this.world.scale.x,n=this.world.x,o=this.world.y;for(const i of this.groupViews.values()){let r=0,c=0,u=0;for(const p of i.members){const b=this.nodeViews.get(p)?.node;b&&(r+=b.x,c+=b.y,u++)}if(u===0||e<=.02){i.el.style.display="none";continue}const d=n+r/u*t,l=o+c/u*t;i.el.style.display="",i.el.style.transform=`translate(${d}px, ${l}px) translate(-50%, -50%)`,i.el.style.opacity=String(e)}}draw(){if(this.destroyed)return;const e=this.focusedId,t=this.hoveredId,n=new Set;if(e!==null){for(const l of this.edges)l.from.id===e&&n.add(l.to.id),l.to.id===e&&n.add(l.from.id);n.add(e)}const o=e!==null,r=.2+Me(.45,1.1,this.world.scale.x)*.35;for(const l of this.edgeViews){const{edge:p,gfx:b}=l;b.clear();const g=e!==null&&(p.from.id===e||p.to.id===e),_=t!==null&&(p.from.id===t||p.to.id===t);let m;o?m=g?.85:0:_?m=.7:m=r;const v=g||_?Yn:Bn,E=g||_?1.2:.7;let k=p.from.x,N=p.from.y,I=p.to.x,O=p.to.y;if(e!==null){if(p.from.id===e){const C=gt(p.from.x,p.from.y,p.to.x,p.to.y,p.from.radius+8);k=C.x,N=C.y}if(p.to.id===e){const C=gt(p.to.x,p.to.y,p.from.x,p.from.y,p.to.radius+8);I=C.x,O=C.y}}b.moveTo(k,N).lineTo(I,O).stroke({color:v,width:E,alpha:m})}const c=1/this.world.scale.x,u=Me(.55,.95,this.world.scale.x),d=this.nodeStyle==="disc";for(const l of this.nodeViews.values()){const{node:p,container:b,halo:g,disc:_,icon:m,labelBox:v}=l,E=p.id===e,k=p.id===t,N=e!==null&&n.has(p.id),I=e===null||N,O=I?1:.25;b.x=p.x,b.y=p.y,b.alpha=O;let C=ke;E?C=ht:N&&(C=Un);const P=E?ht:l.typeColor;g.clear(),(E||k)&&g.circle(0,0,p.radius+8).fill({color:d?P:C,alpha:.18});const L=E?p.radius*qn:p.radius,z=E||k?2.5:1.5,we=d?`${P}|${L}|${z}`:"off";l.discKey!==we&&(l.discKey=we,_.clear(),d&&_.circle(0,0,L).fill({color:P,alpha:.95}).stroke({color:pt,width:z,alpha:1})),m.visible=!d||E||k,m.style.fill=d?pt:C;const ie=d?L*1.35:2*p.radius;m.style.fontSize=ie;const U=Kn[l.iconName];m.x=(U?.x??0)*ie,m.y=(U?.y??Xn)*ie,v.x=p.x,v.y=p.y+(d?L:p.radius)+4,v.scale.set(c);let ee;E?ee=1:I?ee=.92:ee=.32,v.alpha=ee*u,v.visible=v.alpha>.01}}focusNode(e){if(this.focusedId!==null){const n=this.nodeViews.get(this.focusedId);n&&(n.node.pinned=!1)}this.focusedId=e;const t=this.nodeViews.get(e);if(t){t.node.pinned=!0,t.node.vx=0,t.node.vy=0;const n=t.node,o=Math.max(this.targetScale,1.6);this.targetScale=o,this.targetX=this.host.clientWidth/2-n.x*o,this.targetY=this.host.clientHeight/2-n.y*o}this.draw()}setFocusedDetail(e){if(!this.satellites)return;if(!e||this.focusedId===null){this.satellites.clear();return}const t=this.nodeViews.get(this.focusedId)?.node;if(!t){this.satellites.clear();return}this.satellites.setFocused(t,e)}setGrouping(e){if(this.currentGrouping=e,this.clearGroupViews(),!e||!this.sim){this.sim?.setGroupAssignment(null);return}const t=new Map,n=new Map;for(const r of this.nodes){const c=this.deriveGroupKeys(r,e);t.set(r.id,c);const u=new Set;for(const d of c){if(u.has(d))continue;u.add(d);const l=n.get(d);l?l.push(r.id):n.set(d,[r.id])}}const o=this.chronologicalOrder(e,n);this.sim.groupOrderStaggerY=e==="year_month"?160:0,this.sim.setGroupAssignment(t,o);const i=this.buildGroupSeedTargets(t,n,o);this.startGroupingTween(i),this.fitToViewOfTargets(i),this.buildGroupViews(n,e),this.fitFollowActive=!0,this.fitFollowStartedAt=performance.now(),this.fitFollowSawMotion=!1}advanceGroupingTween(){if(this.destroyed)return;const e=this.groupingTween;if(!e)return;const t=Math.min(1,(performance.now()-e.startTime)/e.duration),n=1-Math.pow(1-t,3);for(const[o,i]of e.starts){const r=e.targets.get(o);if(!r)continue;const c=this.nodeViews.get(o)?.node;!c||c.pinned||(c.x=i.x+(r.x-i.x)*n,c.y=i.y+(r.y-i.y)*n,c.vx=0,c.vy=0)}t>=1&&(this.groupingTween=null,this.sim?.reheat(.18,!1))}buildGroupSeedTargets(e,t,n){const o=new Map;if(!this.sim)return o;const i=Array.from(t.keys()),r=new Map,c=this.sim.groupOrderSpacing;if(n&&n.length>0){const d=n.length,l=this.sim.groupOrderStaggerY,p=g=>l<=0?0:g%2===0?-l:l;for(let g=0;g<d;g++)r.set(n[g],{x:(g-(d-1)/2)*c,y:p(g)});let b=d;for(const g of i)r.has(g)||(r.set(g,{x:(b-(d-1)/2)*c,y:p(b)}),b++)}else{const d=i.length,l=Math.max(220,120+d*40);for(let p=0;p<d;p++){const b=p/Math.max(1,d)*Math.PI*2-Math.PI/2;r.set(i[p],{x:Math.cos(b)*l,y:Math.sin(b)*l})}}const u=40;for(const d of this.nodes){if(d.pinned)continue;const l=e.get(d.id);if(!l||l.length===0)continue;let p=0,b=0,g=0;for(const _ of l){const m=r.get(_);m&&(p+=m.x,b+=m.y,g++)}g!==0&&o.set(d.id,{x:p/g+(Math.random()-.5)*u,y:b/g+(Math.random()-.5)*u})}return o}startGroupingTween(e){if(e.size===0){this.groupingTween=null;return}const t=new Map;for(const n of e.keys()){const o=this.nodeViews.get(n)?.node;o&&t.set(n,{x:o.x,y:o.y})}this.groupingTween={startTime:performance.now(),duration:450,starts:t,targets:e}}fitToViewOfTargets(e){e.size!==0&&(this.fitInsets=me(this.host),this.frame(e.values()))}frame(e){const t=this.fitInsets,n=Rn(e,{width:this.host.clientWidth-t.left-t.right,height:this.host.clientHeight-t.top-t.bottom},Zn);if(!n){this.fitPending=!0;return}this.fitPending=!1,this.targetScale=n.scale,this.targetX=t.left+n.x,this.targetY=t.top+n.y}chronologicalOrder(e,t){if(e!=="year"&&e!=="year_month")return null;const n=[];for(const o of t.keys()){const i=o.indexOf(":"),r=o.slice(i+1);if(e==="year"){const c=Number(r);if(!Number.isFinite(c)||c<=0)continue;n.push({key:o,sort:String(c).padStart(6,"0")})}else{if(r==="unknown"||r==="")continue;n.push({key:o,sort:r})}}return n.sort((o,i)=>o.sort<i.sort?-1:o.sort>i.sort?1:0),n.map(o=>o.key)}clearFocus(){if(this.focusedId!==null){const e=this.nodeViews.get(this.focusedId);e&&(e.node.pinned=!1)}this.focusedId=null,this.satellites?.clear(),this.sim?.reheat(.25,!1),this.draw()}setSatelliteSelectedKey(e){this.satellites?.setSelectedKey(e)}getNode(e){return this.nodes.find(t=>t.id===e)}getNodes(){return this.nodes}setNodeStyle(e){if(this.nodeStyle!==e){this.nodeStyle=e;for(const t of this.nodeViews.values())t.discKey=""}}getNodeStyle(){return this.nodeStyle}getFocusedId(){return this.focusedId}fitToView(e=!0){this.nodes.length!==0&&(e&&(this.fitInsets=me(this.host)),this.frame(this.nodes))}destroy(){this.destroyed=!0;try{this.app?.ticker?.stop()}catch{}if(this.tickerCb){try{this.app?.ticker?.remove(this.tickerCb)}catch{}this.tickerCb=null}this.resizeObserver?.disconnect(),this.resizeObserver=null,this.unsubscribeWorkArea?.(),this.unsubscribeWorkArea=null,this.satellites?.destroy(),this.satellites=null,this.clearGroupViews(),this.groupLabelOverlay?.remove(),this.groupLabelOverlay=null;try{this.app.destroy({removeView:!0},{children:!0})}catch{}}}function ts(s){return typeof s!="string"||s===""||s.startsWith("http://")||s.startsWith("https://")?"admin-generic":s.replace(/^dashicons-/,"")}function gt(s,e,t,n,o){const i=t-s,r=n-e,c=Math.sqrt(i*i+r*r);if(c===0)return{x:s,y:e};const u=Math.min(o/c,1);return{x:s+i*u,y:e+r*u}}function Me(s,e,t){if(t<=s)return 0;if(t>=e)return 1;const n=(t-s)/(e-s);return n*n*(3-2*n)}function ns(s){const e=/^(\d{4})-(\d{2})$/.exec(s);if(!e)return s;const t=Number(e[2])-1;if(t<0||t>11)return s;const n=Number(e[1]);try{const o=new Date(Date.UTC(n,t,1));return new Intl.DateTimeFormat(void 0,{month:"short",year:"numeric",timeZone:"UTC"}).format(o)}catch{return s}}function ss(s){switch(s){case"post":return"admin-post";case"page":return"admin-page";case"attachment":return"admin-media";default:return"admin-generic"}}const yt="desktop-mode-content-graph",wt="desktop-mode/corkboard-node-style",ye=new Set;let J=os();function os(){try{return window.localStorage.getItem(wt)==="icon"?"icon":"disc"}catch{return"disc"}}function is(s){try{window.localStorage.setItem(wt,s)}catch{}}Tt({id:"desktop-mode/corkboard-pins",label:y("Show pins"),checkable:!0,checked:()=>J==="icon",isVisible:s=>(s.config.baseId??s.id)===yt,onSelect:()=>{J=J==="icon"?"disc":"icon",is(J);for(const s of ye)s.setNodeStyle(J)}});async function rs(s){const e=s.querySelector("[data-os-content-graph-root]");if(!e)return s.textContent=y("Corkboard container missing."),{abort:()=>{}};const t=je(),n=e.querySelector("[data-os-content-graph-toolbar]"),o=e.querySelector("[data-os-content-graph-stage]"),i=e.querySelector("[data-os-content-graph-panel]"),r=e.querySelector("[data-os-content-graph-loading]"),c=window.wp?.os??{};let u=t.postTypes.map(C=>C.slug),d=t.postTypes,l=null,p=0,b=!1;const g=Jt(r),_=Zt(o),m=_n(i,t,{onClose:()=>{m.hide(),l?.clearFocus()},onViewChange:C=>{l?.setSatelliteSelectedKey(C)}}),v=C=>{switch(C.kind){case"user":m.showUser(C.userId);break;case"term":m.showTerm(C.termId,C.taxonomy);break;case"comment":m.showComment(C.commentId);break;case"media":m.showMedia(C.mediaId);break;case"revision":m.showRevision(C.revisionId);break}},E=C=>{l?.focusNode(C.id),m.setLoading(C.id,C.title);const P=++p;(async()=>{try{const L=await hn(t,C.id);if(b||P!==p)return;m.setDetail(L),l?.setFocusedDetail(L)}catch(L){if(b||P!==p)return;m.setError(te(y("Could not load post #%d."),C.id)),console.warn("[content-graph] detail fetch failed",L)}})()},k=()=>({onTypesChange:C=>{u=C,I()},onFitToView:()=>l?.fitToView(),onSearchSelect:C=>E(C),onGroupChange:C=>{l?.setGrouping(C),_.setSuppressed(C!==null)},getNodes:()=>l?.getNodes()??[]}),N=mn(n,t.postTypes,k()),I=async()=>{if(!b){g.show(),N.setStatus(y("Loading graph…"));try{const C=await dn(t,u);if(b)return;l?.setData(C),N.setStatus(te(y("%1$d nodes · %2$d links"),C.stats.nodes,C.stats.edges)),_.set(Kt({nodes:C.stats.nodes,edges:C.stats.edges,types:d,activeTypes:u})),l?.fitToView(),l?.clearFocus(),m.hide()}catch(C){if(b)return;_.set({kind:"none"}),N.setStatus(y("Failed to load graph.")),console.warn("[content-graph] graph fetch failed",C)}finally{g.hide()}}},O=()=>{p++,m.hide(),l?.clearFocus()};l=new es(o,{onNodeClick:C=>{if(l?.getFocusedId()===C.id){O();return}E(C)},onBackgroundClick:O},v,t.postTypes,J),ye.add(l);try{await l.mount(c)}catch(C){return o.textContent=y("Could not initialise the graph renderer."),console.warn("[content-graph] scene mount failed",C),ye.delete(l),{abort:()=>{}}}return(async()=>{try{const C=await ln(t);if(b)return;d=C,N.updateCounts(C)}catch{}await I()})(),{abort:()=>{b=!0,g.destroy(),_.destroy(),N.destroy(),m.destroy(),l&&(ye.delete(l),l.destroy()),l=null}}}const as=window.openStationNativeWindows??(window.openStationNativeWindows={});as[yt]=async s=>(await rs(s)).abort})(); | |