Current section
Files
Jump to
Current section
Files
priv/static/off-topic.min.mjs
var de=e=>e.head,O=e=>e.tail;var ke=5,ct=(1<<ke)-1,at=Symbol(),pt=Symbol();var ge=[" "," ",`
`,"\v","\f","\r","\x85","\u2028","\u2029"].join(""),Rt=new RegExp(`^[${ge}]*`),Pt=new RegExp(`[${ge}]*$`);var Vt=-(2**31),Wt=2**31-1,Gt=2**32,Ht=Number.MAX_SAFE_INTEGER,Xt=Number.MIN_SAFE_INTEGER;function Se(e,t){if(Array.isArray(e))for(let r=0;r<e.length;r++)t(e[r]);else if(e)for(e;O(e);e=O(e))t(de(e))}function u(e,t){return e instanceof EventTarget?e:e==="root"||e===":scope"?t:e==="host"?t?.host:e==="document"?document:e==="window"?window:(t||(t=document),t instanceof Element&&t.matches(e)?t:t.querySelector(e))}function $(e,t,r,n){let i=u(e,n);if(!i)throw new Error("invalid target");return i.addEventListener(t,r,{passive:!0}),()=>i.removeEventListener(t,r)}function U(e){let t=()=>document.visibilityState==="hidden"?"hidden":document.hasFocus()?"active":"passive",r=s=>{s!==n&&(e(s),n=s)},n=t();n!=="active"&&e(n);let i=new AbortController,o={capture:!0,signal:i.signal};return["pageshow","focus","blur","visibilitychange","resume"].forEach(s=>{window.addEventListener(s,()=>r(t()),o)}),window.addEventListener("freeze",()=>{r("frozen")},o),window.addEventListener("pagehide",s=>{r(s.persisted?"frozen":"terminated")},o),()=>i.abort()}function j(e){let t=()=>-new Date().getTimezoneOffset(),r=t();e(r);let n=setInterval(()=>{let i=t();i!==r&&(r=i,e(i))},6e4);return()=>clearInterval(n)}var et=ze(window,"online","offline",()=>navigator.onLine),D=ze(document.documentElement,"pointerenter","pointerleave",()=>document.documentElement.matches(":hover"));function F(e){let t=r=>{r.preventDefault(),e()};return window.addEventListener("beforeunload",t),()=>window.removeEventListener("beforeunload",t)}function R(e,t){let r=!1,n=null,i=()=>{r&&(r=!1,t(!1)),clearTimeout(n),n=setTimeout(()=>{r=!0,t(!0)},e)},o=()=>{document.hidden||i()},s=["pointermove","pointerdown","keydown","scroll","wheel","resize"];for(let l of s)window.addEventListener(l,i,{passive:!0});return document.addEventListener("visibilitychange",o),i(),()=>{clearTimeout(n);for(let l of s)window.removeEventListener(l,i);document.removeEventListener("visibilitychange",o)}}function P(e){return I(null,window,"resize",()=>e(window.innerWidth,window.innerHeight))}function V(e){return I(null,window,"scroll",()=>e(window.scrollX,window.scrollY))}function W(e){return I(null,screen.orientation,"change",()=>e(screen.orientation.type))}function G(e){return I(null,window,"languagechange",()=>e(navigator.language))}function H(e,t,r){let n=[];Se(t,([s,l])=>{n.push([window.matchMedia(s),l])});let i=()=>n.find(([s])=>s.matches)?.[1]??e,o=()=>r(i());o();for(let[s]of n)s.addEventListener("change",o);return()=>{for(let[s]of n)s.removeEventListener("change",o)}}var X=Ee(localStorage),K=Ee(sessionStorage);function Ee(e){return(t,r)=>{let n=e.getItem(t);return r(n!==null,n??""),$(window,"storage",o=>{if(o.storageArea===e&&o.key===t){let s=o.newValue;r(s!==null,s??"")}})}}function Y(e,t,r){let n=u(e,r);if(!n)return c;let{width:i,height:o}=n.getBoundingClientRect();t(Math.round(i),Math.round(o));let s=new ResizeObserver(l=>{let{width:p,height:y}=l[0].contentRect;t(Math.round(p),Math.round(y))});return s.observe(n),()=>s.disconnect()}function J(e,t,r){let n=u(e,r);if(!n)return c;let i=n.getBoundingClientRect();t(i.bottom>0&&i.right>0&&i.top<window.innerHeight&&i.left<window.innerWidth);let o=new IntersectionObserver(s=>{t(s[0].isIntersecting)});return o.observe(n),()=>o.disconnect()}function Q(e,t,r){let n=u(e,r);if(!n)return c;let i=()=>t(Math.round(n.scrollLeft),Math.round(n.scrollTop));return i(),n.addEventListener("scroll",i,{passive:!0}),()=>n.removeEventListener("scroll",i)}function Z(e){return document.title=e,c}function ee(e,t){let r=document.head.querySelector(`meta[name="${CSS.escape(e)}"]`);return r||(r=document.createElement("meta"),r.setAttribute("name",e),document.head.appendChild(r)),r.setAttribute("content",t),c}function te(e){let t=e.split(" ");return document.body.classList.add(...t),()=>document.body.classList.remove(...t)}function ne(e,t,r,n){let o=(n instanceof ShadowRoot?n.host:n)?.internals;if(o){let s=e==="role"?"role":"aria"+e.slice(5).replace(/-([a-z])/g,(l,p)=>p.toUpperCase()).replace(/^./,l=>l.toUpperCase());o[s]=t}return c}function re(e,t,r,n){let o=(n instanceof ShadowRoot?n.host:n)?.internals;return o&&(t?o.states.add(e):o.states.delete(e)),c}function ie(e,t,r,n){return(n instanceof ShadowRoot?n.host:n)?.internals?.setFormValue(e?t:void 0),c}function I(e,t,r,n){let i=u(t,e);return n(),$(i,r,n)}function ze(e,t,r,n){return i=>{i(n());let o=()=>i(!0),s=()=>i(!1);return e.addEventListener(t,o),e.addEventListener(r,s),()=>{e.removeEventListener(t,o),e.removeEventListener(r,s)}}}function c(){}function Be(e,t,r,n){window.dispatchEvent(new StorageEvent("storage",{key:t,oldValue:r,newValue:n,storageArea:e,url:window.location.href}))}function oe(e,t,r){let n=r?localStorage.getItem(e):null;localStorage.setItem(e,t),r&&Be(localStorage,e,n,t)}function se(e,t,r){let n=r?sessionStorage.getItem(e):null;sessionStorage.setItem(e,t),r&&Be(sessionStorage,e,n,t)}function le(e,t,r,n,i){u(e,i)?.scrollTo({left:t,top:r,behavior:n})}function fe(e,t,r,n,i){u(e,i)?.scrollIntoView({block:t,inline:r,behavior:n})}function ue(e,t){u(e,t)?.focus()}function ce(){document.activeElement?.blur()}var ae=class extends HTMLElement{#e=null;#t=new Map;connectedCallback(){this.#e=rt(this),this.#e&&(this.#e.addEventListener("off-topic:subscribe",this.#n),this.#e.addEventListener("off-topic:unsubscribe",this.#r),this.#e.addEventListener("off-topic:command",this.#i)),this.dispatchEvent(new CustomEvent("off-topic:mount"))}connectedMoveCallback(){}disconnectedCallback(){this.#e&&(this.#e.removeEventListener("off-topic:subscribe",this.#n),this.#e.removeEventListener("off-topic:unsubscribe",this.#r),this.#e=null),queueMicrotask(()=>{if(!this.isConnected){for(let t of this.#t.values())clearTimeout(t.delayTimeout),t.cleanup?.();this.#t.clear()}})}#n=t=>{let{detail:{tick:r,path:n,name:i,params:o,include:s,throttle:l=0,delay:p=0}}=t,y=`${r}:${n.join(":")}`;if(this.#t.has(y))return;let pe=window.OffTopic.subscriptions[i];if(!pe){console.warn(`off-topic: subscription '${i}' requested, but not registered`);return}let a={tick:r,path:n,params:o,cleanup:void 0,lastFired:0,lastThrottledData:void 0,delayTimeout:void 0},C=d=>{let _=Array.isArray(d)?d.map(Ie=>Ae(Ie,s)):Ae(d,s),S=new CustomEvent("off-topic:dispatch",{detail:{tick:r,path:n,message:_}});this.dispatchEvent(S)},ve=(...d)=>{let _=d.length===1?d[0]:d;if(l>0){let S=Date.now();S>=a.lastFired+l&&(a.lastFired=S,a.lastThrottledData=_,C(_))}p>0&&(clearTimeout(a.delayTimeout),a.delayTimeout=setTimeout(()=>{_!==a.lastThrottledData&&C(_)},p)),!l&&!p&&C(_)};a.cleanup=pe(...o,ve,this.#e),this.#t.set(y,a)};#r=t=>{let{detail:{tick:r,path:n}}=t,i=`${r}:${n.join(":")}`,o=this.#t.get(i);o&&(this.#t.delete(i),clearTimeout(o.delayTimeout),o.cleanup?.())};#i=t=>{let{detail:{name:r,params:n}}=t;window.OffTopic.commands[r]?.(...n,this.#e)}};function rt(e){for(;e!=null;){if(e instanceof ShadowRoot&&e.host.tagName.toLowerCase()==="lustre-server-component")return e.host;e=e.parentNode}return console.error(`<ot-client-runtime> is not mounted inside a Lustre server component and will not work!
If you are using lustre.start, you can use off_topic's effects directly and can remove this component.`),null}function Ae(e,t){if(typeof e!="object")return e;let r={};for(let n of t){let i=n.split(".");for(let o=0,s=e,l=r;o<i.length;o++)o===i.length-1?l[i[o]]=s[i[o]]:(l=l[i[o]]??={},s=s[i[o]])}return r}window.OffTopic??={};window.OffTopic.subscriptions??={};window.OffTopic.commands??={};customElements.define("ot-client-runtime",ae);Object.assign(window.OffTopic.subscriptions,{"off-topic/event":$,"off-topic/page-state":U,"off-topic/prevent-unload":F,"off-topic/media-query":H,"off-topic/window-hover":D,"off-topic/here":j,"off-topic/window-size":P,"off-topic/window-scroll":V,"off-topic/screen-orientation":W,"off-topic/language":G,"off-topic/local-storage":X,"off-topic/session-storage":K,"off-topic/title":Z,"off-topic/meta":ee,"off-topic/body-class":te,"off-topic/aria":ne,"off-topic/pseudo-state":re,"off-topic/form-value":ie,"off-topic/element-size":Y,"off-topic/element-scroll":Q,"off-topic/element-visible":J,"off-topic/on-idle":R});Object.assign(window.OffTopic.commands,{"off-topic/set-local-storage":oe,"off-topic/set-session-storage":se,"off-topic/scroll-to":le,"off-topic/scroll-into-view":fe,"off-topic/focus":ue,"off-topic/blur":ce});