PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.0
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.0
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
desktop-mode / assets / js / widget-heartbeat.min.js

widget-heartbeat.min.js in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.0, at assets/js/widget-heartbeat.min.js

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