| @@ -1 +1,19 @@ | ||
| 1 | -(function(){"use strict";const le="desktop-mode";function J(){return window.wp?.i18n}function y(i,e=le){return J()?.__(i,e)??i}function Ne(i,e,t,n=le){return J()?._n(i,e,t,n)??(t===1?i:e)}function Y(i,...e){const t=J()?.sprintf;if(t)return t(i,...e);let n=0;return i.replace(/%(?:(\d+)\$)?[sd]/g,(s,o)=>{const r=o?Number.parseInt(o,10)-1:n++;return String(e[r]??"")})}const Se="http://localhost/";function ee(i,e){const t=typeof window<"u"&&window.location?window.location.href:Se,n=new URL(i,t),s=e.replace(/^\/+/,""),o=s.indexOf("?"),r=o===-1?s:s.slice(0,o),c=o===-1?"":s.slice(o+1);if(n.searchParams.has("rest_route")){const f=n.searchParams.get("rest_route")??"/",p=f.endsWith("/")?f:f+"/";n.searchParams.set("rest_route",p+r)}else{const f=n.pathname.endsWith("/")?n.pathname:n.pathname+"/";n.pathname=f+r}return c&&new URLSearchParams(c).forEach((p,u)=>{n.searchParams.append(u,p)}),n.toString()}const de="X-WP-Nonce";function Me(i,e){const t=Le();if(!t)return e;const n=Te(i);if(!n||!Ie(n))return e;const s=e?.headers??(typeof Request<"u"&&i instanceof Request?i.headers:void 0),o=new Headers(s??{});return o.has(de)?e:(o.set(de,t),{...e??{},headers:o})}function Le(){if(typeof window>"u")return;const e=window.desktopModeConfig?.restNonce;return typeof e=="string"&&e.length>0?e:void 0}function Te(i){try{const e=typeof window<"u"&&window.location?window.location.href:void 0;return typeof i=="string"?new URL(i,e):i instanceof URL?i:typeof Request<"u"&&i instanceof Request?new URL(i.url,e):null}catch{return null}}function Ie(i){return typeof window>"u"||!window.location||i.origin!==window.location.origin?!1:!!(i.pathname.includes("/wp-json/")||i.searchParams.has("rest_route"))}function W(i,e,t={}){const n=window.wp?.desktop?.fetch;if(typeof n=="function")return n(i,e,t);const s=Me(i,e);return fetch(i,s)}const G="desktop-mode-content-graph",H="desktop-mode/content-graph";function pe(){const e=(window.desktopModeWindowConfig??{})[G];if(!e)throw new Error("Corkboard config missing — desktop_mode_register_window args lost in transit.");return e}function V(i){return{Accept:"application/json","X-WP-Nonce":i.restNonce}}async function $e(i){const e=await W(`${i.apiBase}/post-types`,{headers:V(i)},{source:H,windowId:G});if(!e.ok)throw new Error(`post-types: ${e.status}`);return await e.json()}async function Ae(i,e){const t=new URL(`${i.apiBase}/nodes`);e.length>0&&t.searchParams.set("types",e.join(","));const n=await W(t.toString(),{headers:V(i)},{source:H,windowId:G});if(!n.ok)throw new Error(`nodes: ${n.status}`);return await n.json()}async function Oe(i,e){const t=await W(`${i.apiBase}/post/${e}`,{headers:V(i)},{source:H,windowId:G});if(!t.ok)throw new Error(`post/${e}: ${t.status}`);return await t.json()}async function Re(i,e){const t=await W(ee(i.restRoot,`desktop-mode/v1/user-stats/${e}`),{headers:V(i)},{source:H,windowId:G});if(!t.ok)throw new Error(`user-stats/${e}: ${t.status}`);return await t.json()}async function Fe(i,e,t){const n=await W(ee(i.restRoot,`desktop-mode/v1/term-stats/${encodeURIComponent(e)}/${t}`),{headers:V(i)},{source:H,windowId:G});if(!n.ok)throw new Error(`term-stats/${e}/${t}: ${n.status}`);return await n.json()}async function Pe(i,e){const t=await W(ee(i.restRoot,`desktop-mode/v1/comment-stats/${e}`),{headers:V(i)},{source:H,windowId:G});if(!t.ok)throw new Error(`comment-stats/${e}: ${t.status}`);return await t.json()}const z="none";function he(i,e,t){i.replaceChildren();const n=new Set(e.map(w=>w.slug)),s=document.createElement("div");s.className="desktop-mode-content-graph__filters",i.appendChild(s);for(const w of e){const g=document.createElement("button");g.type="button",g.className="desktop-mode-content-graph__chip is-active",g.dataset.slug=w.slug,g.innerHTML=`<span class="dashicons ${Ge(w.icon)}" aria-hidden="true"></span><span class="desktop-mode-content-graph__chip-label">${B(w.label)}</span><span class="desktop-mode-content-graph__chip-count">${w.count}</span>`,g.addEventListener("click",()=>{n.has(w.slug)?(n.delete(w.slug),g.classList.remove("is-active")):(n.add(w.slug),g.classList.add("is-active")),t.onTypesChange(Array.from(n))}),s.appendChild(g)}const o=document.createElement("div");o.className="desktop-mode-content-graph__search";const r=document.createElement("input");r.type="search",r.className="desktop-mode-content-graph__search-input",r.placeholder=y("Search nodes…"),r.setAttribute("aria-label",y("Search posts and pages in the graph")),o.appendChild(r);const c=document.createElement("ul");c.className="desktop-mode-content-graph__search-results",c.hidden=!0,o.appendChild(c),i.appendChild(o);const f=()=>{const w=r.value.trim().toLowerCase();if(w.length===0){c.hidden=!0,c.replaceChildren();return}const g=t.getNodes().filter(k=>k.title.toLowerCase().includes(w)).slice(0,10);c.replaceChildren();for(const k of g){const N=document.createElement("li"),E=document.createElement("button");E.type="button",E.className="desktop-mode-content-graph__search-result",E.innerHTML=`<span class="desktop-mode-content-graph__search-title">${B(k.title||"#"+k.id)}</span><span class="desktop-mode-content-graph__search-type">${B(k.type)}</span>`,E.addEventListener("click",()=>{r.value="",c.hidden=!0,c.replaceChildren(),t.onSearchSelect(k)}),N.appendChild(E),c.appendChild(N)}c.hidden=g.length===0};r.addEventListener("input",f),r.addEventListener("focus",f),r.addEventListener("blur",()=>{setTimeout(()=>{c.hidden=!0},120)});const p=document.createElement("wpd-select");p.className="desktop-mode-content-graph__group-by",p.setAttribute("value",z),p.setAttribute("aria-label",y("Group by")),p.title=y("Group posts by a shared facet");for(const[w,g]of[[z,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 k=document.createElement("wpd-option");k.setAttribute("value",w),k.textContent=g,p.appendChild(k)}p.addEventListener("wpd-pick",w=>{const k=w.detail?.value??z,N=k===z?null:k;t.onGroupChange(N)}),i.insertBefore(p,o);const u=document.createElement("div");u.className="desktop-mode-content-graph__actions";const _=document.createElement("button");_.type="button",_.className="desktop-mode-content-graph__btn",_.innerHTML=`<span class="dashicons dashicons-editor-expand" aria-hidden="true"></span><span>${B(y("Fit"))}</span>`,_.title=y("Fit graph to view"),_.addEventListener("click",()=>t.onFitToView()),u.appendChild(_);const x=document.createElement("span");x.className="desktop-mode-content-graph__toolbar-status",u.appendChild(x),i.appendChild(u);const h=w=>{o.contains(w.target)||(c.hidden=!0)};return document.addEventListener("click",h),{setStatus:w=>{x.textContent=w},destroy:()=>{document.removeEventListener("click",h)}}}function B(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function Ge(i){return i.replace(/[^a-zA-Z0-9 _\-]/g,"")}function De(i,e,t){i.replaceChildren(),i.hidden=!1,i.classList.add("desktop-mode-content-graph__panel--closed");const n=a=>{i.classList.toggle("desktop-mode-content-graph__panel--closed",!a)};let s=null,o={kind:"post"},r=0;const c=document.createElement("div");c.className="desktop-mode-content-graph__panel-frame";const f=document.createElement("nav");f.className="desktop-mode-content-graph__panel-breadcrumb",f.hidden=!0;const p=document.createElement("header");p.className="desktop-mode-content-graph__panel-head";const u=document.createElement("div");u.className="desktop-mode-content-graph__panel-title-wrap";const _=document.createElement("h2");_.className="desktop-mode-content-graph__panel-title";const x=document.createElement("p");x.className="desktop-mode-content-graph__panel-meta",u.appendChild(_),u.appendChild(x);const h=document.createElement("button");h.type="button",h.className="desktop-mode-content-graph__panel-close",h.innerHTML='<span class="dashicons dashicons-no-alt" aria-hidden="true"></span>',h.title=y("Close panel"),h.addEventListener("click",()=>t.onClose()),p.appendChild(u),p.appendChild(h);const w=document.createElement("div");w.className="desktop-mode-content-graph__panel-body",c.appendChild(f),c.appendChild(p),c.appendChild(w),i.appendChild(c);let g=E();w.append(g);let k=null,N=0;function E(){const a=document.createElement("div");return a.className="desktop-mode-content-graph__panel-page",a}const M=(a,d,l)=>{if(w.append(d),a===d||l==="none"){a!==d&&a.remove();return}const m=l==="forward"?"page-from-right":"page-from-left",v=l==="forward"?"page-to-left":"page-to-right";d.classList.add(`desktop-mode-content-graph__${m}`),d.offsetWidth;const C=++N;requestAnimationFrame(()=>{C===N&&(d.classList.remove(`desktop-mode-content-graph__${m}`),a.classList.add(`desktop-mode-content-graph__${v}`))});let S=!1;const I=()=>{S||(S=!0,a.removeEventListener("transitionend",I),a.remove())};a.addEventListener("transitionend",I),setTimeout(I,360)},b=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}`}},T=()=>(window.wp??{}).desktop??{},O=(a,d,l,m)=>{const v=T();if(!v.windowManager||!v.deriveWindowId||!a){a&&(window.location.href=a);return}const C=v.windowManager.getFocused?.();C?.isFullscreen?.()&&C.toggleFullscreen?.();let S=v.deriveWindowId(a);m&&(S=`${S}-${m}`),v.windowManager.open({id:S,baseId:S,url:a,title:d,icon:l})},R=()=>{if(f.replaceChildren(),o.kind==="post"||!s){f.hidden=!0;return}f.hidden=!1;const a=document.createElement("button");a.type="button",a.className="desktop-mode-content-graph__panel-breadcrumb-back";const d=document.createElement("span");d.className="dashicons dashicons-arrow-left-alt2 desktop-mode-content-graph__panel-breadcrumb-arrow",d.setAttribute("aria-hidden","true");const l=document.createElement("span");l.className="desktop-mode-content-graph__panel-breadcrumb-label",l.textContent=s.post.title||`#${s.post.id}`,a.appendChild(d),a.appendChild(l),a.title=y("Back to post"),a.addEventListener("click",()=>{o={kind:"post"},$()}),f.appendChild(a)},$=()=>{n(!0),R();const a=E(),d=g;switch(g=a,o.kind){case"post":j(s);break;case"user":yt(o);break;case"term":wt(o);break;case"comment":vt(o);break;case"media":_t(o.media);break;case"revision":bt(o.revision);break}let l="none";k!==null&&k!==o.kind&&(o.kind==="post"?l="back":l="forward"),M(d,a,l),t.onViewChange?.(b(o)),k=o.kind},j=a=>{if(!a){_.textContent="",x.textContent="";return}_.textContent=a.post.title||`#${a.post.id}`,x.textContent=`${a.post.type} · ${a.post.status}`,g.appendChild(mt(a)),g.appendChild(ft(a)),g.appendChild(Z([{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}])),g.appendChild(gt(a))},mt=a=>{const d=document.createElement("div");if(d.className="desktop-mode-content-graph__panel-author",!a.author)return d.hidden=!0,d;const l=document.createElement("span");l.className="desktop-mode-content-graph__panel-section-label",l.textContent=y("Author"),d.appendChild(l);const m=document.createElement("div");if(m.className="desktop-mode-content-graph__panel-author-row",a.author.avatar){const C=document.createElement("img");C.className="desktop-mode-content-graph__panel-avatar",C.src=a.author.avatar,C.alt="",m.appendChild(C)}const v=document.createElement("span");return v.className="desktop-mode-content-graph__panel-author-name",v.textContent=a.author.name,m.appendChild(v),d.appendChild(m),d},ft=a=>{const d=document.createElement("div");d.className="desktop-mode-content-graph__panel-dates";const l=[];if(a.post.date&&l.push({label:y("Published"),iso:a.post.date}),a.post.modified&&a.post.modified!==a.post.date&&l.push({label:y("Modified"),iso:a.post.modified}),l.length===0)return d.hidden=!0,d;for(const m of l){const v=document.createElement("div");v.className="desktop-mode-content-graph__panel-date-row";const C=document.createElement("span");C.className="desktop-mode-content-graph__panel-section-label",C.textContent=m.label;const S=document.createElement("span");S.className="desktop-mode-content-graph__panel-date-value",S.textContent=U(m.iso),v.appendChild(C),v.appendChild(S),d.appendChild(v)}return d},Z=a=>{const d=document.createElement("ul");d.className="desktop-mode-content-graph__panel-stats";for(const l of a){const m=document.createElement("li");m.className="desktop-mode-content-graph__panel-stat";const v=document.createElement("span");v.className="desktop-mode-content-graph__panel-stat-num",v.textContent=typeof l.value=="number"?X(l.value):l.value;const C=document.createElement("span");C.className="desktop-mode-content-graph__panel-stat-label",C.textContent=l.label,m.appendChild(v),m.appendChild(C),d.appendChild(m)}return d},gt=a=>{const d=document.createElement("div");d.className="desktop-mode-content-graph__panel-actions";const l=T();if(l.myWordpress){const m=Q({label:Y(y("Open in %s"),pe().siteName?.trim()||y("WordPress")),icon:"dashicons-wordpress",primary:!0});m.addEventListener("click",()=>{const v=a.post.type==="page"?"pages":"posts";l.myWordpress.openDetail({entityId:v,postId:a.post.id,postTitle:a.post.title||`#${a.post.id}`})}),d.appendChild(m)}if(a.post.edit_url){const m=Q({label:y("Edit"),icon:"dashicons-edit"});m.addEventListener("click",()=>O(a.post.edit_url,a.post.title,"dashicons-admin-post",`post-${a.post.id}`)),d.appendChild(m)}if(a.post.view_url){const m=Q({label:y("View"),icon:"dashicons-external"});m.addEventListener("click",()=>O(a.post.view_url,a.post.title,"dashicons-admin-post",`post-${a.post.id}`)),d.appendChild(m)}return d},yt=a=>{const{user:d,role:l,stats:m,loading:v}=a;_.textContent=m?.profile.name??d.name,x.textContent=y(l==="author"?"Author":"Contributor");const C=document.createElement("div");C.className="desktop-mode-content-graph__panel-detail-head";const S=m?.profile.avatarUrl||d.avatar;if(S){const L=document.createElement("img");L.className="desktop-mode-content-graph__panel-detail-avatar desktop-mode-content-graph__panel-detail-avatar--lg",L.src=S,L.alt="",C.appendChild(L)}const I=document.createElement("div");if(I.className="desktop-mode-content-graph__panel-detail-handle",I.innerHTML=`<strong>${A(m?.profile.name??d.name)}</strong><span>@${A(d.slug)}</span>`,C.appendChild(I),g.appendChild(C),m?.profile.roleLabels?.length&&g.appendChild(Ce(y("Roles"),m.profile.roleLabels)),m?.profile.description&&g.appendChild(ie(y("About"),m.profile.description)),m?.profile.website&&g.appendChild(xt(y("Website"),m.profile.website,m.profile.website)),m){const L=m.counts;g.appendChild(Z([{label:y("Posts"),value:L.posts.total},{label:y("Pages"),value:L.pages.total},{label:y("CPT"),value:L.cpt},{label:y("Comments received"),value:L.commentsReceived},{label:y("Comments left"),value:L.commentsLeft}]))}m?.topTerms?.length&&g.appendChild(ke(y("Top topics"),m.topTerms)),m&&g.appendChild(Ee([{label:y("First published"),iso:m.milestones.firstPublished},{label:y("Last published"),iso:m.milestones.lastPublished}])),v&&g.appendChild(ce()),g.appendChild(q({label:y("Open in WordPress"),icon:"dashicons-admin-users",href:d.edit_url,title:d.name,primary:!0,windowKey:`user-${d.id}`}))},wt=a=>{const{term:d,stats:l,loading:m}=a;_.textContent=l?.profile.name??d.name,x.textContent=`${l?.profile.taxonomyLabel??d.tax_label} · ${l?.profile.taxonomy??d.taxonomy}`,l?.profile.parentName&&g.appendChild(re([{label:y("Parent"),value:l.profile.parentName}])),l?.profile.description&&g.appendChild(ie(y("Description"),l.profile.description)),l?g.appendChild(Z([{label:y("Posts"),value:l.counts.posts.total},{label:y("Comments"),value:l.counts.commentsReceived},{label:y("Authors"),value:l.counts.distinctAuthors}])):g.appendChild(Z([{label:y("Posts"),value:d.count}])),l?.topAuthors?.length&&g.appendChild(Ct(y("Top authors"),l.topAuthors)),l?.coTerms?.length&&g.appendChild(ke(y("Co-occurring"),l.coTerms.map(v=>({...v,taxonomy:d.taxonomy})))),l&&g.appendChild(Ee([{label:y("First post"),iso:l.milestones.firstPosted},{label:y("Latest post"),iso:l.milestones.lastPosted}])),m&&g.appendChild(ce()),g.appendChild(q({label:y("Open in WordPress"),icon:"dashicons-tag",href:d.edit_url,title:d.name,primary:!0}))},vt=a=>{const{comment:d,stats:l,loading:m}=a,v=l?.author.name??d.author;_.textContent=v||`#${d.id}`,x.textContent=U(l?.comment.date??d.date);const C=l?.author.avatarUrl;if(C){const L=document.createElement("div");L.className="desktop-mode-content-graph__panel-detail-head";const P=document.createElement("img");P.className="desktop-mode-content-graph__panel-detail-avatar desktop-mode-content-graph__panel-detail-avatar--lg",P.src=C,P.alt="",L.appendChild(P);const D=document.createElement("div");D.className="desktop-mode-content-graph__panel-detail-handle",D.innerHTML=`<strong>${A(v)}</strong>`+(l?.author.totalApprovedComments?`<span>${X(l.author.totalApprovedComments)} ${A(y("comments"))}</span>`:""),L.appendChild(D),g.appendChild(L)}const S=l?.comment.status??y("—");g.appendChild(Ce(y("Status"),[S],{accent:S==="1"||S==="approved"?"green":"amber"}));const I=l?.comment.rendered;if(I){const L=document.createElement("div");L.className="desktop-mode-content-graph__panel-detail-section";const P=document.createElement("span");P.className="desktop-mode-content-graph__panel-section-label",P.textContent=y("Comment"),L.appendChild(P);const D=document.createElement("div");D.className="desktop-mode-content-graph__panel-detail-html",D.innerHTML=I,L.appendChild(D),g.appendChild(L)}else d.excerpt&&g.appendChild(ie(y("Comment"),d.excerpt));if(l?.parent){const L=document.createElement("blockquote");L.className="desktop-mode-content-graph__panel-detail-quote",L.innerHTML=`<strong>${A(l.parent.authorName)}</strong><span>${A(l.parent.excerpt)}</span>`,g.appendChild(L)}l?.replies?.length&&g.appendChild(kt(l.replies)),m&&g.appendChild(ce()),g.appendChild(q({label:y("Open in WordPress"),icon:"dashicons-admin-comments",href:d.edit_url,title:v||y("Comment"),primary:!0}))},_t=a=>{if(_.textContent=a.title||`#${a.id}`,x.textContent=a.mime||y("Media"),a.thumb){const d=document.createElement("div");d.className="desktop-mode-content-graph__panel-detail-thumb";const l=document.createElement("img");l.src=a.thumb,l.alt=a.title||"",d.appendChild(l),g.appendChild(d)}g.appendChild(re([{label:y("Type"),value:a.mime}])),g.appendChild(q({label:y("Open in WordPress"),icon:"dashicons-admin-media",href:a.edit_url,title:a.title,primary:!0}))},bt=a=>{if(_.textContent=a.author?.name??y("Revision"),x.textContent=U(a.date),a.author){const d=document.createElement("div");if(d.className="desktop-mode-content-graph__panel-detail-head",a.author.avatar){const m=document.createElement("img");m.className="desktop-mode-content-graph__panel-detail-avatar desktop-mode-content-graph__panel-detail-avatar--lg",m.src=a.author.avatar,m.alt="",d.appendChild(m)}const l=document.createElement("div");l.className="desktop-mode-content-graph__panel-detail-handle",l.innerHTML=`<strong>${A(a.author.name)}</strong><span>@${A(a.author.slug)}</span>`,d.appendChild(l),g.appendChild(d)}g.appendChild(re([{label:y("Saved"),value:U(a.date)}])),g.appendChild(q({label:y("Open revision in WordPress"),icon:"dashicons-backup",href:a.edit_url,title:y("Revision"),primary:!0,windowKey:`revision-${a.id}`}))},ie=(a,d)=>{const l=document.createElement("div");l.className="desktop-mode-content-graph__panel-detail-section";const m=document.createElement("span");m.className="desktop-mode-content-graph__panel-section-label",m.textContent=a;const v=document.createElement("p");return v.className="desktop-mode-content-graph__panel-detail-prose",v.textContent=d,l.appendChild(m),l.appendChild(v),l},Ce=(a,d,l={})=>{const m=document.createElement("div");m.className="desktop-mode-content-graph__panel-detail-section";const v=document.createElement("span");v.className="desktop-mode-content-graph__panel-section-label",v.textContent=a,m.appendChild(v);const C=document.createElement("div");C.className="desktop-mode-content-graph__panel-badges";for(const S of d){const I=document.createElement("span");I.className="desktop-mode-content-graph__panel-badge"+(l.accent?` desktop-mode-content-graph__panel-badge--${l.accent}`:""),I.textContent=S,C.appendChild(I)}return m.appendChild(C),m},re=a=>{const d=document.createElement("div");d.className="desktop-mode-content-graph__panel-inline-meta";for(const l of a){if(!l.value)continue;const m=document.createElement("div");m.className="desktop-mode-content-graph__panel-inline-meta-row";const v=document.createElement("span");v.className="desktop-mode-content-graph__panel-section-label",v.textContent=l.label;const C=document.createElement("span");C.className="desktop-mode-content-graph__panel-date-value",C.textContent=l.value,m.appendChild(v),m.appendChild(C),d.appendChild(m)}return d},xt=(a,d,l)=>{const m=document.createElement("div");m.className="desktop-mode-content-graph__panel-detail-section";const v=document.createElement("span");v.className="desktop-mode-content-graph__panel-section-label",v.textContent=a;const C=document.createElement("a");return C.className="desktop-mode-content-graph__panel-detail-link",C.href=l,C.textContent=d,C.target="_blank",C.rel="noopener noreferrer",m.appendChild(v),m.appendChild(C),m},ke=(a,d)=>{const l=document.createElement("div");l.className="desktop-mode-content-graph__panel-detail-section";const m=document.createElement("span");m.className="desktop-mode-content-graph__panel-section-label",m.textContent=a,l.appendChild(m);const v=document.createElement("ul");v.className="desktop-mode-content-graph__panel-chips";for(const C of d.slice(0,8)){const S=document.createElement("li");S.className="desktop-mode-content-graph__panel-chip",S.innerHTML=`<span>${A(C.name)}</span><span class="desktop-mode-content-graph__panel-chip-count">${X(C.count)}</span>`,v.appendChild(S)}return l.appendChild(v),l},Ct=(a,d)=>{const l=document.createElement("div");l.className="desktop-mode-content-graph__panel-detail-section";const m=document.createElement("span");m.className="desktop-mode-content-graph__panel-section-label",m.textContent=a,l.appendChild(m);const v=document.createElement("ul");v.className="desktop-mode-content-graph__panel-author-list";for(const C of d.slice(0,6)){const S=document.createElement("li");S.className="desktop-mode-content-graph__panel-author-list-row",S.innerHTML=(C.userAvatarUrl?`<img class="desktop-mode-content-graph__panel-avatar" src="${ue(C.userAvatarUrl)}" alt="" />`:"")+`<span class="desktop-mode-content-graph__panel-author-name">${A(C.userName)}</span><span class="desktop-mode-content-graph__panel-chip-count">${X(C.count)}</span>`,v.appendChild(S)}return l.appendChild(v),l},Ee=a=>{const d=a.filter(C=>C.iso),l=document.createElement("div");if(l.className="desktop-mode-content-graph__panel-detail-section",d.length===0)return l.hidden=!0,l;const m=document.createElement("span");m.className="desktop-mode-content-graph__panel-section-label",m.textContent=y("Milestones"),l.appendChild(m);const v=document.createElement("div");v.className="desktop-mode-content-graph__panel-milestones";for(const C of d){const S=document.createElement("div");S.className="desktop-mode-content-graph__panel-milestone-row";const I=document.createElement("span");I.className="desktop-mode-content-graph__panel-milestone-key",I.textContent=C.label;const L=document.createElement("span");L.className="desktop-mode-content-graph__panel-date-value",L.textContent=U(C.iso),S.appendChild(I),S.appendChild(L),v.appendChild(S)}return l.appendChild(v),l},kt=a=>{const d=document.createElement("div");d.className="desktop-mode-content-graph__panel-detail-section";const l=document.createElement("span");l.className="desktop-mode-content-graph__panel-section-label",l.textContent=Y(Ne("Reply (%d)","Replies (%d)",a.length),a.length),d.appendChild(l);const m=document.createElement("ul");m.className="desktop-mode-content-graph__panel-replies";for(const v of a.slice(0,5)){const C=document.createElement("li");C.className="desktop-mode-content-graph__panel-reply",C.innerHTML=`<header><strong>${A(v.authorName)}</strong><span>${U(v.date)}</span></header><p>${A(v.excerpt)}</p>`,m.appendChild(C)}return d.appendChild(m),d},ce=()=>{const a=document.createElement("div");return a.className="desktop-mode-content-graph__panel-detail-loading",a.innerHTML=`<wpd-spinner></wpd-spinner><span>${A(y("Loading details…"))}</span>`,a},q=a=>{const d=document.createElement("div");if(d.className="desktop-mode-content-graph__panel-actions",!a.href)return d.hidden=!0,d;const l=Q({label:a.label,icon:a.icon,primary:a.primary});return l.addEventListener("click",()=>O(a.href,a.title,a.icon,a.windowKey)),d.appendChild(l),d},Q=a=>{const d=document.createElement("button");return d.type="button",d.className="desktop-mode-content-graph__btn"+(a.primary?" desktop-mode-content-graph__btn--primary":""),d.innerHTML=`<span class="dashicons ${ue(a.icon)}" aria-hidden="true"></span><span>${A(a.label)}</span>`,d};return{setLoading:(a,d)=>{n(!0),f.hidden=!0,o={kind:"post"},k=null,_.textContent=d??`#${a}`,x.textContent=y("Loading…"),w.replaceChildren(),g=E(),w.append(g);const l=document.createElement("div");l.className="desktop-mode-content-graph__panel-loading",l.innerHTML="<wpd-spinner></wpd-spinner>",g.appendChild(l),t.onViewChange?.(null)},setError:a=>{n(!0),f.hidden=!0,o={kind:"post"},k=null,w.replaceChildren(),g=E(),w.append(g);const d=document.createElement("p");d.className="desktop-mode-content-graph__panel-empty",d.textContent=a,g.appendChild(d),t.onViewChange?.(null)},setDetail:a=>{s=a,o={kind:"post"},$()},showUser:a=>{if(!s)return;const d=s.author?.id===a,l=d?s.author:s.contributors.find(v=>v.id===a);if(!l)return;o={kind:"user",user:l,role:d?"author":"contributor",stats:null,loading:!0},$();const m=++r;Re(e,a).then(v=>{m!==r||o.kind!=="user"||o.user.id!==a||(o={...o,stats:v,loading:!1},$())}).catch(v=>{m!==r||o.kind!=="user"||o.user.id!==a||(o={...o,loading:!1},$(),console.warn("[content-graph] user-stats failed",v))})},showTerm:(a,d)=>{if(!s)return;const l=s.categories.find(v=>v.id===a&&v.taxonomy===d);if(!l)return;o={kind:"term",term:l,stats:null,loading:!0},$();const m=++r;Fe(e,d,a).then(v=>{m!==r||o.kind!=="term"||o.term.id!==a||(o={...o,stats:v,loading:!1},$())}).catch(v=>{m!==r||o.kind!=="term"||o.term.id!==a||(o={...o,loading:!1},$(),console.warn("[content-graph] term-stats failed",v))})},showComment:a=>{if(!s)return;const d=s.comments.find(m=>m.id===a);if(!d)return;o={kind:"comment",comment:d,stats:null,loading:!0},$();const l=++r;Pe(e,a).then(m=>{l!==r||o.kind!=="comment"||o.comment.id!==a||(o={...o,stats:m,loading:!1},$())}).catch(m=>{l!==r||o.kind!=="comment"||o.comment.id!==a||(o={...o,loading:!1},$(),console.warn("[content-graph] comment-stats failed",m))})},showMedia:a=>{if(!s)return;const d=s.attached_media.find(l=>l.id===a);d&&(o={kind:"media",media:d},$())},showRevision:a=>{if(!s)return;const d=s.revisions.find(l=>l.id===a);d&&(o={kind:"revision",revision:d},$())},hide:()=>{n(!1)},destroy:()=>{i.replaceChildren()}}}function U(i){if(!i)return"";try{return new Date(i).toLocaleString()}catch{return i}}function X(i){try{return new Intl.NumberFormat().format(i)}catch{return String(i)}}function A(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function ue(i){return i.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}let te=null;function We(i){let e=i.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 He(){const i=new Map;if(typeof document>"u")return i;const e=Array.from(document.styleSheets??[]);for(const t of e){let n=null;try{n=t.cssRules}catch{continue}if(n)for(const s of Array.from(n)){const o=s;if(!o||!o.selectorText)continue;const r=o.selectorText.match(/\.dashicons-([a-z0-9-]+)::?before/i);if(!r)continue;const c=o.style?.content;if(!c)continue;const f=We(c);f&&i.set(r[1],f)}}return i}function me(i){te||(te=He());const e=i.startsWith("dashicons-")?i.slice(10):i;return te.get(e)??null}function Ve(){return window.PIXI??null}const Ue={repulsion:26e3,springK:.04,springLen:200,gravity:.0035,damping:.86},Ye=.992,qe=.01,fe=1,F=12;class ze{constructor(e,t,n=Ue){this.dragOrigin=null,this.dragInfluenceRadius=500,this.groupAssignment=null,this.groupOrder=null,this.groupAttractorStrength=.12,this.groupOrderSpacing=320,this.groupOrderStaggerY=0,this.alpha=fe,this.nodes=e,this.edges=t,this.opts=n}reheat(e=fe,t=!0){if(this.alpha=Math.max(this.alpha,e),!t)return;const n=e*3;for(const s of this.nodes)s.pinned||(s.vx+=(Math.random()-.5)*n,s.vy+=(Math.random()-.5)*n)}get isSettled(){return this.alpha<qe}step(e=1){if(this.isSettled)return;const{repulsion:t,springK:n,springLen:s,gravity:o,damping:r}=this.opts,c=this.nodes,f=c.length;for(let h=0;h<f;h++){const w=c[h];for(let g=h+1;g<f;g++){const k=c[g];let N=w.x-k.x,E=w.y-k.y,M=N*N+E*E;M<.01&&(N=(h-g)*.5,E=(h+g)*.5,M=N*N+E*E);const b=t/M,T=Math.sqrt(M),O=N/T*b,R=E/T*b,$=w.pinned?0:1,j=k.pinned?0:1;w.vx+=O*$,w.vy+=R*$,k.vx-=O*j,k.vy-=R*j}}for(const h of this.edges){const w=h.to.x-h.from.x,g=h.to.y-h.from.y,k=Math.sqrt(w*w+g*g)||1e-4,N=(k-s)*n,E=w/k*N,M=g/k*N;h.from.pinned||(h.from.vx+=E,h.from.vy+=M),h.to.pinned||(h.to.vx-=E,h.to.vy-=M)}this.applyClusterAttractor();const p=this.alpha,u=this.dragOrigin,_=this.dragInfluenceRadius,x=_*_;for(const h of c)if(!h.pinned){h.vx-=h.x*o,h.vy-=h.y*o,h.vx*=r,h.vy*=r,h.vx>F?h.vx=F:h.vx<-F&&(h.vx=-F),h.vy>F?h.vy=F:h.vy<-F&&(h.vy=-F);let w=p;if(u){const g=h.x-u.x,k=h.y-u.y,N=g*g+k*k;if(N>=x)w=0;else{const E=1-Math.sqrt(N)/_;w*=E*E*(3-2*E)}}h.x+=h.vx*w*e,h.y+=h.vy*w*e}this.alpha*=Ye}applyClusterAttractor(){const e=this.groupAssignment;if(!e)return;const t=this.groupAttractorStrength;if(t<=0)return;const n=new Map,s=new Map;if(this.groupOrder&&this.groupOrder.length>0){const r=this.groupOrder.length,c=this.groupOrderSpacing,f=this.groupOrderStaggerY;for(let p=0;p<r;p++){const u=this.groupOrder[p];n.set(u,(p-(r-1)/2)*c),f>0&&s.set(u,p%2===0?-f:f)}}const o=new Map;for(const r of this.nodes){const c=e.get(r.id);if(!(!c||c.length===0))for(const f of c){const p=o.get(f);p?(p.sx+=r.x,p.sy+=r.y,p.count++):o.set(f,{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 f=t/c.length;for(const p of c){const u=o.get(p);if(!u||u.count===0)continue;const _=n.has(p)?n.get(p):u.sx/u.count,x=s.has(p)?s.get(p):u.sy/u.count;r.vx+=(_-r.x)*f,r.vy+=(x-r.y)*f}}}setGroupAssignment(e,t=null){this.groupAssignment=e,this.groupOrder=e?t:null,this.reheat(.3,!1)}}const ge={user:3829232,term:2926970,comment:15239482,media:10510036,revision:7042949},ye={user:"admin-users",term:"tag",comment:"admin-comments",media:"admin-media",revision:"backup"};function Be(i){switch(i.taxonomy){case"category":return"category";case"post_tag":return"tag";default:return ye.term}}const Xe={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}},K=14;class Ke{constructor(e,t,n,s,o,r){this.pixi=e,this.satelliteParent=t,this.spokeParent=n,this.onClick=s,this.hostEl=o,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="desktop-mode-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 s of this.views){const o=s.container.x-t,r=s.container.y-n,c=Math.sqrt(o*o+r*r);if(c<=e)continue;const f=e/c,p=t+o*f,u=n+r*f,_=ge[s.ref.kind];this.linkGfx.moveTo(p,u).lineTo(s.container.x,s.container.y).stroke({color:_,width:s.selected?1.8:1.4,alpha:s.selected?.85:.5})}}setFocused(e,t){this.clear(),this.focused=e;const n=this.flattenDetail(t);if(n.length===0)return;const s=e.radius,r=Math.max(s+86,s+70+n.length*36/(2*Math.PI)),c=-Math.PI/2,f=2*Math.PI/n.length;n.forEach((p,u)=>{const _=c+u*f,x=e.x+Math.cos(_)*r,h=e.y+Math.sin(_)*r,w=this.buildSatellite(p,e.x,e.y);w.targetX=x,w.targetY=h,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: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:Y(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||ve(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:ve(n.date)});return t}buildSatellite(e,t,n){const s=new this.pixi.Container;s.x=t,s.y=n,s.alpha=0,s.eventMode="static",s.cursor="pointer";const o=K+4;s.hitArea={contains:(M,b)=>M>=-o&&M<=o&&b>=-o&&b<=o+18};const r=new this.pixi.Graphics;s.addChild(r);const c=e.kind==="term"?Be(e):ye[e.kind],f=me(c),p=new this.pixi.Text({text:f??"?",style:{fontFamily:f?"dashicons":"sans-serif",fontSize:f?20:13,fill:16777215},resolution:2,anchor:{x:.5,y:.5}}),u=Xe[e.kind];p.x=u?.x??0,p.y=u?.y??0,s.addChild(p);const _=je(e.label||"—",28),x=new this.pixi.Graphics;s.addChild(x);const h=new this.pixi.Text({text:_,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}});h.x=0,h.y=K+2,s.addChild(h);const w=6,g=1,k=h.width+w*2,N=h.height+g*2;x.roundRect(-k/2,h.y-g,k,N,4).fill({color:16777215,alpha:.92}).stroke({color:0,alpha:.08,width:1}),s.on("pointerdown",M=>{M.stopPropagation?.(),this.claimPointer()}),s.on("pointerover",M=>{r.alpha=1;const b=M;this.showTooltip(e,b.global)}),s.on("pointermove",M=>{const b=M;this.showTooltip(e,b.global)}),s.on("pointerout",()=>{r.alpha=.95,this.hideTooltip()}),s.on("pointertap",M=>{M.stopPropagation?.(),this.hideTooltip(),this.setSelectedKey(we(e)),this.onClick(e)}),this.layer.addChild(s);const E={ref:e,key:we(e),container:s,disc:r,icon:p,label:h,targetX:t,targetY:n,selected:!1};return this.repaintDisc(E),E}repaintDisc(e){const t=ge[e.ref.kind];e.disc.clear(),e.selected&&e.disc.circle(0,0,K+6).fill({color:t,alpha:.18}),e.disc.circle(0,0,K).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(o=>({x:o.container.x,y:o.container.y})),s=o=>{const r=Math.min(1,(o-e)/t),c=1-Math.pow(1-r,3);for(let f=0;f<this.views.length;f++){const p=this.views[f],u=n[f];p.container.x=u.x+(p.targetX-u.x)*c,p.container.y=u.y+(p.targetY-u.y)*c,p.container.alpha=c}this.drawLinks(),r<1?this.rafId=requestAnimationFrame(s):this.rafId=null};this.rafId=requestAnimationFrame(s)}showTooltip(e,t){this.hoverEl.hidden=!1,this.hoverEl.innerHTML=`<strong>${_e(e.label||"—")}</strong>`+(e.meta?`<span>${_e(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 we(i){switch(i.kind){case"user":return`user:${i.userId}`;case"term":return`term:${i.taxonomy}:${i.termId}`;case"comment":return`comment:${i.commentId}`;case"media":return`media:${i.mediaId}`;case"revision":return`revision:${i.revisionId}`}}function je(i,e){return i.length<=e?i:i.slice(0,e-1).trimEnd()+"…"}function ve(i){if(!i)return"";try{return new Date(i).toLocaleString()}catch{return i}}function _e(i){return i.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}const ne=4937059,Ze=2911205,Qe=5213171,Je=10135222,et=2911205,tt=0,nt={"admin-post":{x:.06,y:.06}},st={category:"#2c6be5",tag:"#2ca97a",author:"#7c3aed",year:"#ea580c",year_month:"#ea580c"},se=.15,ot=4,at=8e-4,it=.18,oe=.001,be=24;class rt{constructor(e,t,n,s){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.lastResizeWidth=0,this.lastResizeHeight=0,this.targetScale=1,this.targetX=0,this.targetY=0,this.host=e,this.callbacks=t,this.onSatelliteClick=n;const o=new Map;this.postTypeBySlug=new Map;for(const r of s)o.set(r.slug,ct(r.icon)),this.postTypeBySlug.set(r.slug,r);this.postTypeIcon=r=>o.get(r)??dt(r)}async mount(e){typeof e.loadModules=="function"&&await e.loadModules(["pixijs"]);const t=Ve();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:Math.min(window.devicePixelRatio||1,2),sharedTicker:!1}),this.app=n,this.host.appendChild(n.canvas),n.canvas.classList.add("desktop-mode-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="desktop-mode-content-graph__group-labels",this.host.appendChild(this.groupLabelOverlay),n.canvas.addEventListener("webglcontextlost",r=>{r.preventDefault();try{this.app?.ticker?.stop()}catch{}},!1);const s=n.renderer,o=s.render.bind(s);s.render=(...r)=>{try{return o(...r)}catch(c){try{this.app?.ticker?.stop()}catch{}console.warn("[content-graph] Pixi render threw, stopping ticker:",c);return}},this.satellites=new Ke(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 c of this.nodes)t.set(c.id,c);this.groupCatalogs=e.groups??{authors:{},categories:{},tags:{}};const n=e.nodes.map(c=>{const f=t.get(c.id),p=Math.random()*Math.PI*2,u=150+Math.random()*250;return{...c,x:f?.x??Math.cos(p)*u,y:f?.y??Math.sin(p)*u,vx:0,vy:0,pinned:!1,radius:4,color:ne,degree:0}}),s=new Map;for(const c of n)s.set(c.id,c);const o=[];for(const c of e.edges){const f=s.get(c.from),p=s.get(c.to);!f||!p||(f.degree++,p.degree++,o.push({from:f,to:p}))}for(const c of n)c.radius=8+Math.min(8,Math.sqrt(c.degree)*2.4);this.nodes=n,this.edges=o,this.rebuildSprites(),this.sim=new ze(n,o),this.sim.reheat(.12,!1);const r=Math.min(90,30+n.length);for(let c=0;c<r;c++)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 s=this.postTypeIcon(e.type),o=me(s),r=new this.pixi.Text({text:o??"●",style:{fontFamily:o?"dashicons":"sans-serif",fontSize:2*e.radius,fill:ne},resolution:2,anchor:{x:.5,y:.5}});t.addChild(r);const c=new this.pixi.Container;this.labelLayer.addChild(c);const f=new this.pixi.Graphics;c.addChild(f);const p=new this.pixi.Text({text:this.truncate(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:2,anchor:{x:.5,y:0}});c.addChild(p);const u=5,_=1,x=p.width+u*2,h=p.height+_*2;f.roundRect(-x/2,-_,x,h,4).fill({color:16777215,alpha:.78}).stroke({color:0,alpha:.06,width:1}),this.nodeViews.set(e.id,{node:e,container:t,halo:n,icon:r,labelBox:c,labelBg:f,label:p,iconCharCode:o,iconName:s})}}truncate(e,t){return e.length<=t?e:e.slice(0,t-1).trimEnd()+"…"}bindNodeInput(e,t){let n={x:0,y:0},s=!1;const o=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,s=!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,f=c.global.x-n.x,p=c.global.y-n.y;!s&&f*f+p*p<=256&&this.callbacks.onNodeClick?.(t),t.pinned=this.focusedId===t.id,this.pressedNode=null,this.sim&&(this.sim.dragOrigin=null,s&&this.sim.reheat(.35,!1)),s=!1}),e.on("pointerupoutside",()=>{t.pinned=this.focusedId===t.id,this.pressedNode=null,this.sim&&(this.sim.dragOrigin=null),s=!1}),e.on("globalpointermove",r=>{if(this.pressedNode!==t)return;const c=r,f=c.global.x-n.x,p=c.global.y-n.y,u=f*f+p*p;if(!s){if(u<o)return;s=!0;const x=this.toWorld(c.global.x,c.global.y);this.dragOffset={x:t.x-x.x,y:t.y-x.y},this.sim&&(this.sim.dragOrigin={x:t.x,y:t.y},this.sim.reheat(.3,!1))}const _=this.toWorld(c.global.x,c.global.y);t.x=_.x+this.dragOffset.x,t.y=_.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*at),s=Math.max(se,Math.min(ot,this.targetScale*n)),o=e.getBoundingClientRect(),r=t.clientX-o.left,c=t.clientY-o.top,f=(r-this.targetX)/this.targetScale,p=(c-this.targetY)/this.targetScale;this.targetScale=s,this.targetX=r-f*s,this.targetY=c-p*s},{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),s=this.panStart.wy+(t.clientY-this.panStart.y);this.world.x=n,this.world.y=s,this.targetX=n,this.targetY=s}),window.addEventListener("pointerup",t=>{const n=this.nodeClickActive;if(this.nodeClickActive=!1,!this.isPanning)return;const s=t.clientX-this.panStart.x,o=t.clientY-this.panStart.y;this.isPanning=!1,!n&&s*s+o*o<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(e<=0||t<=0)return;try{this.app.renderer.resize(e,t)}catch{return}try{this.app.render()}catch{}const n=Math.abs(e-this.lastResizeWidth),s=Math.abs(t-this.lastResizeHeight);(n>=be||s>=be)&&(this.lastResizeWidth=e,this.lastResizeHeight=t)}),this.resizeObserver.observe(this.host)}toWorld(e,t){const n=this.app.canvas.getBoundingClientRect(),s=e-n.left,o=t-n.top;return{x:(s-this.world.x)/this.world.scale.x,y:(o-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-it,e),n=this.targetScale-this.world.scale.x;Math.abs(n)<oe?this.world.scale.set(this.targetScale):this.world.scale.set(this.world.scale.x+n*t);const s=this.targetX-this.world.x,o=this.targetY-this.world.y;Math.abs(s)<oe?this.world.x=this.targetX:this.world.x+=s*t,Math.abs(o)<oe?this.world.y=this.targetY:this.world.y+=o*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()):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,s=`author:${n}`,o=[s,s],r=Array.isArray(e.contributor_ids)?e.contributor_ids:[];for(const c of r)c>0&&c!==n&&o.push(`author:${c}`);return o}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),s=e.slice(t+1);switch(n){case"cat":{if(s==="uncat")return y("Uncategorized");if(s.startsWith("type_"))return this.postTypeLabel(s.slice(5));const o=Number(s);return this.groupCatalogs.categories[o]?.name??`#${o}`}case"tag":{if(s==="untagged")return y("Untagged");if(s.startsWith("type_"))return this.postTypeLabel(s.slice(5));const o=Number(s);return this.groupCatalogs.tags[o]?.name??`#${o}`}case"author":{const o=Number(s);return o<=0?y("Unknown author"):this.groupCatalogs.authors[o]?.name??`#${o}`}case"year":{const o=Number(s);return o<=0?y("Undated"):String(o)}case"ym":return s==="unknown"||s===""?y("Undated"):lt(s)}return e}buildGroupViews(e,t){if(!this.groupLabelOverlay)return;const n=st[t];for(const[s,o]of e){if(o.length===0)continue;const r=`${this.labelForGroupKey(s)} (${o.length})`,c=document.createElement("div");c.className="desktop-mode-content-graph__group-label",c.textContent=r,c.style.setProperty("--wpd-cg-cluster-color",n),this.groupLabelOverlay.appendChild(c),this.groupViews.set(s,{key:s,label:r,el:c,members:o})}}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-ae(1.2,2.4,this.world.scale.x),t=this.world.scale.x,n=this.world.x,s=this.world.y;for(const o of this.groupViews.values()){let r=0,c=0,f=0;for(const _ of o.members){const x=this.nodeViews.get(_)?.node;x&&(r+=x.x,c+=x.y,f++)}if(f===0||e<=.02){o.el.style.display="none";continue}const p=n+r/f*t,u=s+c/f*t;o.el.style.display="",o.el.style.transform=`translate(${p}px, ${u}px) translate(-50%, -50%)`,o.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 p of this.edges)p.from.id===e&&n.add(p.to.id),p.to.id===e&&n.add(p.from.id);n.add(e)}const s=e!==null,r=.2+ae(.45,1.1,this.world.scale.x)*.35;for(const p of this.edgeViews){const{edge:u,gfx:_}=p;_.clear();const x=e!==null&&(u.from.id===e||u.to.id===e),h=t!==null&&(u.from.id===t||u.to.id===t);let w;s?w=x?.85:0:h?w=.7:w=r;const g=x||h?et:Je,k=x||h?1.2:.7;let N=u.from.x,E=u.from.y,M=u.to.x,b=u.to.y;if(e!==null){if(u.from.id===e){const T=xe(u.from.x,u.from.y,u.to.x,u.to.y,u.from.radius+8);N=T.x,E=T.y}if(u.to.id===e){const T=xe(u.to.x,u.to.y,u.from.x,u.from.y,u.to.radius+8);M=T.x,b=T.y}}_.moveTo(N,E).lineTo(M,b).stroke({color:g,width:k,alpha:w})}const c=1/this.world.scale.x,f=ae(.55,.95,this.world.scale.x);for(const p of this.nodeViews.values()){const{node:u,container:_,halo:x,icon:h,labelBox:w}=p,g=u.id===e,k=u.id===t,N=e!==null&&n.has(u.id),E=e===null||N,M=E?1:.25;_.x=u.x,_.y=u.y,_.alpha=M;let b=ne;g?b=Ze:N&&(b=Qe),x.clear(),(g||k)&&x.circle(0,0,u.radius+8).fill({color:b,alpha:.18}),h.style.fill=b;const T=2*u.radius;h.style.fontSize=T;const O=nt[p.iconName];h.x=(O?.x??0)*T,h.y=(O?.y??tt)*T,w.x=u.x,w.y=u.y+u.radius+4,w.scale.set(c);let R;g?R=1:E?R=.92:R=.32,w.alpha=R*f,w.visible=w.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,s=Math.max(this.targetScale,1.6);this.targetScale=s,this.targetX=this.host.clientWidth/2-n.x*s,this.targetY=this.host.clientHeight/2-n.y*s}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 f=new Set;for(const p of c){if(f.has(p))continue;f.add(p);const u=n.get(p);u?u.push(r.id):n.set(p,[r.id])}}const s=this.chronologicalOrder(e,n);this.sim.groupOrderStaggerY=e==="year_month"?160:0,this.sim.setGroupAssignment(t,s);const o=this.buildGroupSeedTargets(t,n,s);this.startGroupingTween(o),this.fitToViewOfTargets(o),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[s,o]of e.starts){const r=e.targets.get(s);if(!r)continue;const c=this.nodeViews.get(s)?.node;!c||c.pinned||(c.x=o.x+(r.x-o.x)*n,c.y=o.y+(r.y-o.y)*n,c.vx=0,c.vy=0)}t>=1&&(this.groupingTween=null,this.sim?.reheat(.18,!1))}buildGroupSeedTargets(e,t,n){const s=new Map;if(!this.sim)return s;const o=Array.from(t.keys()),r=new Map,c=this.sim.groupOrderSpacing;if(n&&n.length>0){const p=n.length,u=this.sim.groupOrderStaggerY,_=h=>u<=0?0:h%2===0?-u:u;for(let h=0;h<p;h++)r.set(n[h],{x:(h-(p-1)/2)*c,y:_(h)});let x=p;for(const h of o)r.has(h)||(r.set(h,{x:(x-(p-1)/2)*c,y:_(x)}),x++)}else{const p=o.length,u=Math.max(220,120+p*40);for(let _=0;_<p;_++){const x=_/Math.max(1,p)*Math.PI*2-Math.PI/2;r.set(o[_],{x:Math.cos(x)*u,y:Math.sin(x)*u})}}const f=40;for(const p of this.nodes){if(p.pinned)continue;const u=e.get(p.id);if(!u||u.length===0)continue;let _=0,x=0,h=0;for(const w of u){const g=r.get(w);g&&(_+=g.x,x+=g.y,h++)}h!==0&&s.set(p.id,{x:_/h+(Math.random()-.5)*f,y:x/h+(Math.random()-.5)*f})}return s}startGroupingTween(e){if(e.size===0){this.groupingTween=null;return}const t=new Map;for(const n of e.keys()){const s=this.nodeViews.get(n)?.node;s&&t.set(n,{x:s.x,y:s.y})}this.groupingTween={startTime:performance.now(),duration:450,starts:t,targets:e}}fitToViewOfTargets(e){if(e.size===0)return;let t=1/0,n=1/0,s=-1/0,o=-1/0;for(const w of e.values())w.x<t&&(t=w.x),w.y<n&&(n=w.y),w.x>s&&(s=w.x),w.y>o&&(o=w.y);const r=100,c=s-t+r*2,f=o-n+r*2,p=this.host.clientWidth/c,u=this.host.clientHeight/f,_=Math.max(se,Math.min(1.5,Math.min(p,u))),x=(t+s)/2,h=(n+o)/2;this.targetScale=_,this.targetX=this.host.clientWidth/2-x*_,this.targetY=this.host.clientHeight/2-h*_}chronologicalOrder(e,t){if(e!=="year"&&e!=="year_month")return null;const n=[];for(const s of t.keys()){const o=s.indexOf(":"),r=s.slice(o+1);if(e==="year"){const c=Number(r);if(!Number.isFinite(c)||c<=0)continue;n.push({key:s,sort:String(c).padStart(6,"0")})}else{if(r==="unknown"||r==="")continue;n.push({key:s,sort:r})}}return n.sort((s,o)=>s.sort<o.sort?-1:s.sort>o.sort?1:0),n.map(s=>s.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}getFocusedId(){return this.focusedId}fitToView(){if(this.nodes.length===0)return;let e=1/0,t=1/0,n=-1/0,s=-1/0;for(const h of this.nodes)h.x<e&&(e=h.x),h.y<t&&(t=h.y),h.x>n&&(n=h.x),h.y>s&&(s=h.y);const o=100,r=n-e+o*2,c=s-t+o*2,f=this.host.clientWidth/r,p=this.host.clientHeight/c,u=Math.max(se,Math.min(1.5,Math.min(f,p))),_=(e+n)/2,x=(t+s)/2;this.targetScale=u,this.targetX=this.host.clientWidth/2-_*u,this.targetY=this.host.clientHeight/2-x*u}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.satellites?.destroy(),this.satellites=null,this.clearGroupViews(),this.groupLabelOverlay?.remove(),this.groupLabelOverlay=null;try{this.app.destroy({removeView:!0},{children:!0})}catch{}}}function ct(i){return typeof i!="string"||i===""||i.startsWith("http://")||i.startsWith("https://")?"admin-generic":i.replace(/^dashicons-/,"")}function xe(i,e,t,n,s){const o=t-i,r=n-e,c=Math.sqrt(o*o+r*r);if(c===0)return{x:i,y:e};const f=Math.min(s/c,1);return{x:i+o*f,y:e+r*f}}function ae(i,e,t){if(t<=i)return 0;if(t>=e)return 1;const n=(t-i)/(e-i);return n*n*(3-2*n)}function lt(i){const e=/^(\d{4})-(\d{2})$/.exec(i);if(!e)return i;const t=Number(e[2])-1;if(t<0||t>11)return i;const n=Number(e[1]);try{const s=new Date(Date.UTC(n,t,1));return new Intl.DateTimeFormat(void 0,{month:"short",year:"numeric",timeZone:"UTC"}).format(s)}catch{return i}}function dt(i){switch(i){case"post":return"admin-post";case"page":return"admin-page";case"attachment":return"admin-media";default:return"admin-generic"}}const pt="desktop-mode-content-graph";async function ht(i){const e=i.querySelector("[data-desktop-mode-content-graph-root]");if(!e)return i.textContent=y("Corkboard container missing."),{abort:()=>{}};const t=pe(),n=e.querySelector("[data-desktop-mode-content-graph-toolbar]"),s=e.querySelector("[data-desktop-mode-content-graph-stage]"),o=e.querySelector("[data-desktop-mode-content-graph-panel]"),r=e.querySelector("[data-desktop-mode-content-graph-loading]"),c=window.wp?.desktop??{};let f=t.postTypes.map(b=>b.slug),p=null,u=0,_=!1;const x=b=>{r&&(r.hidden=!b)},h=De(o,t,{onClose:()=>{h.hide(),p?.clearFocus()},onViewChange:b=>{p?.setSatelliteSelectedKey(b)}}),w=b=>{switch(b.kind){case"user":h.showUser(b.userId);break;case"term":h.showTerm(b.termId,b.taxonomy);break;case"comment":h.showComment(b.commentId);break;case"media":h.showMedia(b.mediaId);break;case"revision":h.showRevision(b.revisionId);break}},g=b=>{p?.focusNode(b.id),h.setLoading(b.id,b.title);const T=++u;(async()=>{try{const O=await Oe(t,b.id);if(_||T!==u)return;h.setDetail(O),p?.setFocusedDetail(O)}catch(O){if(_||T!==u)return;h.setError(Y(y("Could not load post #%d."),b.id)),console.warn("[content-graph] detail fetch failed",O)}})()},k=()=>({onTypesChange:b=>{f=b,E()},onFitToView:()=>p?.fitToView(),onSearchSelect:b=>g(b),onGroupChange:b=>{p?.setGrouping(b)},getNodes:()=>p?.getNodes()??[]});let N=he(n,t.postTypes,k());const E=async()=>{if(!_){x(!0),N.setStatus(y("Loading graph…"));try{const b=await Ae(t,f);if(_)return;p?.setData(b),N.setStatus(Y(y("%1$d nodes · %2$d links"),b.stats.nodes,b.stats.edges)),p?.fitToView(),p?.clearFocus(),h.hide()}catch(b){if(_)return;N.setStatus(y("Failed to load graph.")),console.warn("[content-graph] graph fetch failed",b)}finally{x(!1)}}},M=()=>{u++,h.hide(),p?.clearFocus()};p=new rt(s,{onNodeClick:b=>{if(p?.getFocusedId()===b.id){M();return}g(b)},onBackgroundClick:M},w,t.postTypes);try{await p.mount(c)}catch(b){return s.textContent=y("Could not initialise the graph renderer."),console.warn("[content-graph] scene mount failed",b),{abort:()=>{}}}try{const b=await $e(t);N.destroy(),N=he(n,b,k())}catch{}return await E(),{abort:()=>{_=!0,N.destroy(),h.destroy(),p?.destroy(),p=null}}}const ut=window.desktopModeNativeWindows??(window.desktopModeNativeWindows={});ut[pt]=async i=>(await ht(i)).abort})(); | |
| 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 | + class="os-icon__glyph os-icon__glyph--char dashicons dashicons-${t}" | |
| 3 | + aria-hidden="true" | |
| 4 | + >${o}</span>`:ae`<span | |
| 5 | + class="os-icon__glyph dashicons dashicons-${t}" | |
| 6 | + aria-hidden="true" | |
| 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 | + class="os-empty-state__icon" | |
| 10 | + name=${e} | |
| 11 | + size="28" | |
| 12 | + ></os-icon>`:null} | |
| 13 | + <h3 class="os-empty-state__heading">${t}</h3> | |
| 14 | + <p class="os-empty-state__description">${n}</p> | |
| 15 | + <div class="os-empty-state__cta"> | |
| 16 | + <slot name="cta"></slot> | |
| 17 | + </div> | |
| 18 | + <slot></slot> | |
| 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})(); | |