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