| 1 |
(function(){"use strict";const A="__desktopModeSharedStores";function F(){const t=window;let e=t[A];return e||(e=new Map,t[A]=e),e}function z(t,e){const n=F();let s=n.get(t);s||(s={state:e(),listeners:new Set,rebuild:e},n.set(t,s));const a={get state(){return s.state},set state(o){s.state=o},getState(){return s.state},notify(){for(const o of Array.from(s.listeners))try{o(s.state)}catch(r){console.error(`[desktop-mode/shared-store:${t}] subscriber threw:`,r)}},subscribe(o){return s.listeners.add(o),()=>{s.listeners.delete(o)}},setState(o){const r=s.state;if(typeof r!="object"||r===null){console.warn(`[desktop-mode/shared-store:${t}] setState called on a primitive store; use the state setter instead.`);return}Object.assign(r,o),a.notify()},reset(){const o=s.rebuild(),r=s.state;if(typeof r=="object"&&r!==null&&typeof o=="object"&&o!==null){const i=r;for(const h of Object.keys(i))delete i[h];Object.assign(i,o)}else s.state=o;s.listeners.clear()}};return a}async function X(){const e=window.wp?.desktop?.loadModules;if(typeof e!="function")throw new Error("wp.desktop.loadModules is not available — main shell may not have booted yet.");await e(["pixijs"])}const f=z("desktop-mode/heartbeat-widget/wp-beats",()=>({lastTickAt:0,lastSendAt:0,intervalSecs:15,tickSeq:0,booted:!1}));function D(){const t=f;if(t.state.booted)return;t.state.booted=!0,t.state.intervalSecs=I(),t.state.lastTickAt=performance.now();const e=window.jQuery;if(!e)return;const n=e(document);n.on("heartbeat-send",()=>{t.state.lastSendAt=performance.now()}),n.on("heartbeat-tick",()=>{t.state.lastTickAt=performance.now(),t.state.intervalSecs=I(),t.state.tickSeq+=1,t.notify()})}const T={bright:16731501,hi:16754104},Q=T.bright,H=T.hi,d=52,U=async(t,e)=>{try{await X()}catch(n){return L(t,n.message),()=>{}}return J(t,e)};function K(t){return`${(t?.pluginUrl??"").replace(/\/+$/,"")}/assets/images/wp-logo.png`}function L(t,e){t.classList.add("desktop-mode-widget-heartbeat"),t.classList.add("desktop-mode-widget-heartbeat--fallback");const n=document.createElement("div");n.className="desktop-mode-widget-heartbeat__fallback",n.textContent=e||"Could not load animation engine.",t.appendChild(n)}const V=230,Z=88;async function J(t,e){const n=window.PIXI;if(!n)return L(t,"PIXI not available."),()=>{};t.classList.add("desktop-mode-widget-heartbeat");let s=e.storage.get("showHeart")??!0;s||t.classList.add("desktop-mode-widget-heartbeat--no-heart");const a=document.createElement("div");a.className="desktop-mode-widget-heartbeat__stage",t.appendChild(a);const o=document.createElement("div");o.className="desktop-mode-widget-heartbeat__meta";const r=document.createElement("div");r.className="desktop-mode-widget-heartbeat__label",r.textContent="Next beat in",o.appendChild(r);const i=document.createElement("div");i.className="desktop-mode-widget-heartbeat__remaining",i.textContent="—",o.appendChild(i),t.appendChild(o);const h=document.createElement("div");h.className="desktop-mode-widget-heartbeat__bar";const l=document.createElement("div");l.className="desktop-mode-widget-heartbeat__bar-fill",h.appendChild(l),t.appendChild(h);const c=new n.Application;await c.init({resizeTo:a,backgroundAlpha:0,antialias:!0,autoDensity:!0,resolution:Math.min(window.devicePixelRatio||1,2)}),a.appendChild(c.canvas);const p=et(n),u=nt(n),it=at(n,K(e));c.stage.addChild(p),c.stage.addChild(u),u.addChild(it);const C=()=>{p.x=c.screen.width/2,p.y=c.screen.height/2,u.x=c.screen.width/2,u.y=c.screen.height/2};C();const P=new ResizeObserver(()=>C());P.observe(a),D();let q=0,b=0,k=0,N=f.state.tickSeq;const dt=f.subscribe(m=>{m.tickSeq!==N&&(N=m.tickSeq,b=1,k=1)}),lt=window.jQuery;let _=null;lt||(_=setInterval(()=>{f.state.lastTickAt=performance.now(),f.state.tickSeq+=1,f.notify()},f.state.intervalSecs*1e3));const ht=()=>{dt(),_!==null&&clearInterval(_)},O=()=>{const m=c.ticker.deltaMS/1e3;q+=m;const w=q/4*Math.PI*2;let x=1+.008*Math.sin(w),G=0,W=0;if(b>0){b=Math.max(0,b-m/.9);const g=1-b;let v;if(g<.1)v=.55*(g/.1);else if(g<.28)v=.55-.5*((g-.1)/.18);else if(g<.55)v=.05+.1*Math.sin((g-.28)/.27*Math.PI);else{const y=(g-.55)/.45;v=.05*(1-y)*Math.exp(-2.5*y)}if(x+=v,g<.2){const y=Math.sin(g/.2*Math.PI);G=.1*y,W=-.05*y}}u.scale.x=x*(1+G),u.scale.y=x*(1+W),k=Math.max(0,k-m/1.2),p.alpha=.1+k*.55;const pt=1+k*.15;p.scale.set(pt),u.tint=rt(Q,H,Math.min(1,k*.6+b*.4));const B=(performance.now()-f.state.lastTickAt)/1e3,Y=f.state.intervalSecs,ut=ct(B/Math.max(Y,1),0,1);l.style.width=`${(ut*100).toFixed(1)}%`;const mt=Math.max(0,Y-B);i.textContent=`${mt.toFixed(1)}s`};c.ticker.add(O);const $=()=>{requestAnimationFrame(()=>{try{c.resize?.()}catch{try{const w=a.clientWidth,E=a.clientHeight;w>0&&E>0&&c.renderer.resize(w,E)}catch{}}C()})},j=m=>{m.preventDefault(),m.stopPropagation(),tt(m,s,w=>{s=w,e.storage.set("showHeart",w),R(t,w),w&&$()})};return t.addEventListener("contextmenu",j),R(t,s),s&&$(),()=>{t.removeEventListener("contextmenu",j),ht(),P.disconnect(),c.ticker.remove(O);try{c.canvas?.remove()}catch{}t.classList.remove("desktop-mode-widget-heartbeat"),t.classList.remove("desktop-mode-widget-heartbeat--no-heart")}}function R(t,e){t.classList.toggle("desktop-mode-widget-heartbeat--no-heart",!e);const n=t.closest(".desktop-mode-widgets__card");if(n){n.classList.add("desktop-mode-widgets__card--heartbeat");const s=e?V:Z;n.style.height=`${s}px`}}function tt(t,e,n){document.querySelectorAll(".desktop-mode-widget-heartbeat__menu").forEach(l=>l.remove());const s=document.createElement("wpd-context-menu");s.className="desktop-mode-widget-heartbeat__menu",s.setAttribute("open",""),s.style.position="fixed",s.style.left=`${t.clientX}px`,s.style.top=`${t.clientY}px`,s.style.zIndex="10500";const a=document.createElement("wpd-context-menu-option");a.setAttribute("value","show-heart"),e&&a.setAttribute("checked",""),a.textContent="Show heart",s.appendChild(a);const o=()=>{s.remove(),document.removeEventListener("pointerdown",r,!0),document.removeEventListener("keydown",i,!0)},r=l=>{s.contains(l.target)||o()},i=l=>{l.key==="Escape"&&o()};s.addEventListener("wpd-context-menu-pick",()=>{n(!e),o()}),document.body.appendChild(s);const h=s.getBoundingClientRect();h.right>window.innerWidth&&(s.style.left=`${Math.max(4,window.innerWidth-h.width-8)}px`),h.bottom>window.innerHeight&&(s.style.top=`${Math.max(4,window.innerHeight-h.height-8)}px`),document.addEventListener("pointerdown",r,!0),document.addEventListener("keydown",i,!0)}function et(t){const e=new t.Graphics,n=[d*1.2,d*1.05,d*.85],s=[.12,.18,.28];return n.forEach((a,o)=>{e.circle(0,0,a),e.fill({color:H,alpha:s[o]})}),e.alpha=.1,e}function S(t=1){const n=[],s=d/17*t;for(let a=0;a<=240;a++){const o=a/240*Math.PI*2,r=16*1.08*Math.sin(o)**3,i=-(13*Math.cos(o)-5*Math.cos(2*o)-2*Math.cos(3*o)-Math.cos(4*o));n.push(r*s,i*s)}return n}function nt(t){const e=new t.Container,n=st(),s=new t.Graphics;s.poly(S(1.05)),s.fill({color:0,alpha:.55}),s.y=5,s.alpha=.55,e.addChild(s);const a=ot(),o=t.Texture.from(a),r=new t.Sprite(o),i=n.maxY-n.minY,h=d*2.5;r.width=h,r.height=i,r.x=-h/2,r.y=n.minY;const l=new t.Graphics;l.poly(S(1)),l.fill({color:16777215,alpha:1}),r.mask=l,e.addChild(l),e.addChild(r);const c=new t.Graphics;c.ellipse(-d*.32,-d*.5,d*.18,d*.1),c.fill({color:16777215,alpha:.45}),c.rotation=-.5,e.addChild(c);const p=new t.Graphics;p.ellipse(d*.2,-d*.38,d*.09,d*.05),p.fill({color:16777215,alpha:.22}),p.rotation=.4,e.addChild(p);const u=new t.Graphics;return u.poly(S(1)),u.stroke({color:16777215,alpha:.18,width:1}),e.addChild(u),e}function st(){const t=d/17;return{minY:-15*t,maxY:9*t}}function ot(){const t=document.createElement("canvas");t.width=2,t.height=512;const e=t.getContext("2d");if(!e)return t;const n=e.createLinearGradient(0,0,0,512);return n.addColorStop(0,"#ffd6e3"),n.addColorStop(.18,"#ff8ba3"),n.addColorStop(.42,"#ff4d6d"),n.addColorStop(.72,"#9a1f3d"),n.addColorStop(1,"#3d061a"),e.fillStyle=n,e.fillRect(0,0,2,512),t}function at(t,e){const n=new t.Sprite;n.anchor.set(.5),n.alpha=.95,n.y=d*.08;const s=d*.92;return t.Assets.load(e).then(a=>{n.texture=a;const o=s/Math.max(1,a.width);n.scale.set(o)}).catch(()=>{}),n}function I(){const t=window.wp;try{const e=t?.heartbeat?.interval;if(typeof e=="function"){const n=Number(e());if(Number.isFinite(n)&&n>0)return n}}catch{}return 15}function rt(t,e,n){const s=Math.trunc(t/65536)%256,a=Math.trunc(t/256)%256,o=t%256,r=Math.trunc(e/65536)%256,i=Math.trunc(e/256)%256,h=e%256,l=Math.round(s+(r-s)*n),c=Math.round(a+(i-a)*n),p=Math.round(o+(h-o)*n);return l*65536+c*256+p}function ct(t,e,n){return t<e?e:t>n?n:t}const M=window;M.desktopModeWidgets=M.desktopModeWidgets||{},M.desktopModeWidgets["desktop-mode/heartbeat"]=U})(); |