~thewhodidthis/longform

6960614a1d544ca01833ad5961b9a777a1775292 — thewhodidthis 3 months ago 2195bbd
js/client/bundle: tweak for updated host finder, rebuild
2 files changed, 5 insertions(+), 4 deletions(-)

M bundle.js
M client.js
M bundle.js => bundle.js +2 -2
@@ 1,4 1,4 @@
(()=>{var d=(t={},...e)=>e.reduce((i,r)=>{let s=t[r];return s===void 0?i:s},()=>{}),m=(t=document)=>d(t,"webkitFullscreenElement","mozFullScreenElement","msFullscreenElement","fullscreenElement"),f=(t=document.body)=>d(t,"webkitRequestFullScreen","mozRequestFullScreen","msRequestFullscreen","requestFullscreen").call(t),g=(t=document)=>d(t,"webkitExitFullscreen","mozCancelFullScreen","msExitFullscreen","exitFullscreen").call(t),l=t=>m()!==null?g():f(t);l.state=m;l.enter=f;l.leave=g;var c=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(document.createElement("slot"))}connectedCallback(){this.isConnected&&this.firstElementChild&&this.addEventListener("click",()=>{l(this.firstElementChild)})}},u=class extends HTMLElement{constructor(){super();let e=document.createRange().createContextualFragment(`
(()=>{var m=(t={},...e)=>e.reduce((i,r)=>{let s=t[r];return s===void 0?i:s},()=>{}),g=(t=document)=>m(t,"webkitFullscreenElement","mozFullScreenElement","msFullscreenElement","fullscreenElement"),p=(t=document.body)=>m(t,"webkitRequestFullScreen","mozRequestFullScreen","msRequestFullscreen","requestFullscreen").call(t),y=(t=document)=>m(t,"webkitExitFullscreen","mozCancelFullScreen","msExitFullscreen","exitFullscreen").call(t),o=t=>g()!==null?y():p(t);o.state=g;o.enter=p;o.leave=y;var h=class extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(document.createElement("slot"))}connectedCallback(){this.isConnected&&this.firstElementChild&&this.addEventListener("click",()=>{o(this.firstElementChild)})}},d=class extends HTMLElement{constructor(){super();let e=document.createRange().createContextualFragment(`
      <style>
        :host {
          display: block;


@@ 8,4 8,4 @@
        }
      </style>
      <slot></slot>
    `);this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(e)}static get observedAttributes(){return["flash","ready"]}get flash(){return this.getAttribute("flash")}set flash(e){this.setAttribute("flash",e)}get ready(){return this.getAttribute("ready")}set ready(e){this.setAttribute("ready",e)}get timeout(){let e=this.hasAttribute("timeout")?this.getAttribute("timeout"):1500;return parseInt(e,10)}set timeout(e){Number.isNaN(e)||this.setAttribute("timeout",e)}attributeChangedCallback(e,i,r){switch(e){case"ready":{if(r!=="null"){let s=new Event("ready");this.innerText="",this.dispatchEvent(s)}break}case"flash":{let s=setTimeout(()=>{clearTimeout(s),this.ready=!0},this.timeout);this.innerText=r,this.ready=null;break}}}},v=(t="",...e)=>RegExp(e.join("|")).test(t),C=(t="")=>{let{origin:e}=location;if(v(e,"local","test"))return t;let{href:i=e}=document.querySelector('link[rel="canonical"]');return i!==e?i:e};"customElements"in self&&(customElements.define("just-scream",c),customElements.define("just-flash",u));var a=document.getElementById("figure"),n=document.querySelector("just-flash"),y=()=>{if(n.flash!==""){let e=new Date().toLocaleTimeString(void 0,{hour12:!1});n.style.fontFamily="monospace",n.flash=e;return}n.removeEventListener("ready",y)};n.addEventListener("ready",y);var h=new Date(9),E=new EventSource(`${C("http://localhost:8001").replace(/\/$/,"")}/001/io/`);E.addEventListener("message",({data:t})=>{let{clientHeight:e,firstElementChild:i,scrollHeight:r}=a,s=h.getTime(),p=Math.min(s,e);h.setTime(s+1);let o=document.createElement("span");o.setAttribute("style",`font-size: ${s}px; line-height: ${p}px`);let b=document.createTextNode(t);o.appendChild(b),i===null&&(n.flash=""),i&&r>e&&a.removeChild(i),a.appendChild(o)});E.addEventListener("error",()=>{n.style.fontFamily="inherit",n.flash="Sorry, trying to connect still"});self.addEventListener("load",()=>{"serviceWorker"in navigator&&navigator.serviceWorker.register("serviceworker.js").catch(t=>{console.log("serviceworker: register:",t.message)}),n.style.fontFamily="inherit",n.flash="Connecting..."});})();
    `);this.attachShadow({mode:"open"}),this.shadowRoot.appendChild(e)}static get observedAttributes(){return["flash","ready"]}get flash(){return this.getAttribute("flash")}set flash(e){this.setAttribute("flash",e)}get ready(){return this.getAttribute("ready")}set ready(e){this.setAttribute("ready",e)}get timeout(){let e=this.hasAttribute("timeout")?this.getAttribute("timeout"):1500;return parseInt(e,10)}set timeout(e){Number.isNaN(e)||this.setAttribute("timeout",e)}attributeChangedCallback(e,i,r){switch(e){case"ready":{if(r!=="null"){let s=new Event("ready");this.innerText="",this.dispatchEvent(s)}break}case"flash":{let s=setTimeout(()=>{clearTimeout(s),this.ready=!0},this.timeout);this.innerText=r,this.ready=null;break}}}};function w(t="http://localhost",e="/io/"){let{origin:i}=location,{href:r=i}=document.querySelector('link[rel="canonical"]'),s=RegExp("test|local").test(i)?t:r,{pathname:c,href:l}=new URL(s),a=String(c+e)?.replace(/\/{2}/g,"/"),{href:v}=new URL(a,l);return v}"customElements"in self&&(customElements.define("just-scream",h),customElements.define("just-flash",d));var u=document.getElementById("figure"),n=document.querySelector("just-flash"),E=()=>{if(n.flash!==""){let e=new Date().toLocaleTimeString(void 0,{hour12:!1});n.style.fontFamily="monospace",n.flash=e;return}n.removeEventListener("ready",E)};n.addEventListener("ready",E);var f=new Date(9),C=w("http://localhost:8001"),b=new EventSource(C);b.addEventListener("message",({data:t})=>{let{clientHeight:e,firstElementChild:i,scrollHeight:r}=u,s=f.getTime(),c=Math.min(s,e);f.setTime(s+1);let l=document.createElement("span");l.setAttribute("style",`font-size: ${s}px; line-height: ${c}px`);let a=document.createTextNode(t);l.appendChild(a),i===null&&(n.flash=""),i&&r>e&&u.removeChild(i),u.appendChild(l)});b.addEventListener("error",()=>{n.style.fontFamily="inherit",n.flash="Sorry, trying to connect still"});self.addEventListener("load",()=>{"serviceWorker"in navigator&&navigator.serviceWorker.register("serviceworker.js").catch(t=>{console.log("serviceworker: register:",t.message)}),n.style.fontFamily="inherit",n.flash="Connecting..."});})();

M client.js => client.js +3 -2
@@ 1,5 1,5 @@
import { Flash, Scream } from "@thewhodidthis/j"
import { findHost } from "./helper.js"
import { hostfinder } from "./helper.js"

if ("customElements" in self) {
  customElements.define("just-scream", Scream)


@@ 28,7 28,8 @@ flash.addEventListener("ready", flashTheTime)

// Maxes out 8,640,000,000,000,000 milliseconds from epoch (ECMA-262).
const counter = new Date(9)
const io = new EventSource(`${findHost("http://localhost:8001").replace(/\/$/, "")}/001/io/`)
const host = hostfinder("http://localhost:8001")
const io = new EventSource(host)

io.addEventListener("message", ({ data }) => {
  const { clientHeight, firstElementChild, scrollHeight } = figure