hyperbole-0.5.0: client/dist/hyperbole.js
/*! For license information please see hyperbole.js.LICENSE.txt */
(()=>{var e={296:e=>{function t(e,t=100,n={}){if("function"!=typeof e)throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw new RangeError("`wait` must not be negative.");const{immediate:r}="boolean"==typeof n?{immediate:n}:n;let o,i,a,u,c;function s(){const t=o,n=i;return o=void 0,i=void 0,c=e.apply(t,n),c}function l(){const e=Date.now()-u;e<t&&e>=0?a=setTimeout(l,t-e):(a=void 0,r||(c=s()))}const d=function(...e){if(o&&this!==o&&Object.getPrototypeOf(this)===Object.getPrototypeOf(o))throw new Error("Debounced method called with different contexts of the same prototype.");o=this,i=e,u=Date.now();const n=r&&!a;return a||(a=setTimeout(l,t)),n&&(c=s()),c};return Object.defineProperty(d,"isPending",{get:()=>void 0!==a}),d.clear=()=>{a&&(clearTimeout(a),a=void 0)},d.flush=()=>{a&&d.trigger()},d.trigger=()=>{c=s(),d.clear()},d}e.exports.debounce=t,e.exports=t},147:e=>{"use strict";e.exports=JSON.parse('{"name":"web-ui","version":"0.5.0","description":"Development -----------","main":"index.js","directories":{"client":"client"},"scripts":{"build":"npx webpack"},"author":"","license":"ISC","devDependencies":{"ts-loader":"^9.4.1","typescript":"^4.8.3","uglify":"^0.1.5","webpack":"^5.88.2","webpack-cli":"^4.10.0"},"dependencies":{"omdomdom":"^0.3.2","debounce":"^2.2.0"}}')}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}(()=>{"use strict";var e=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t=function(e,t){var n=e.length,r=-1;if(n)for(;++r<n&&!1!==t(e[r],r););},r=function(e,t,n){return e.node.insertBefore(t.node,n)};function o(e,t){return function(e){if(Array.isArray(e))return e}(e)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,o,i,a,u=[],c=!0,s=!1;try{if(i=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=i.call(n)).done)&&(u.push(r.value),u.length!==t);c=!0);}catch(e){s=!0,o=e}finally{try{if(!c&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(s)throw o}}return u}}(e,t)||function(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}(e,t)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}var a="string",u="number",c="boolean",s={},l=function(e,t,n){return{attrName:e,propName:t,type:n}};t([["style","cssText"],["class","className"]],(function(e){var t=o(e,2),n=t[0],r=t[1];s[n]=l(n,r||n,a)})),t(["autofocus","draggable","hidden","checked","multiple","muted","selected"],(function(e){s[e]=l(e,e,c)})),t([["tabindex","tabIndex"]],(function(e){var t=o(e,2),n=t[0],r=t[1];s[n]=l(n,r,u)}));var d="xlink:",f="http://www.w3.org/1999/xlink",v="xml:",p="http://www.w3.org/XML/1998/namespace",h=function(e,t,n,r){switch(t){case a:n===s.style.propName?e.style[n]=null===r?"":r:e[n]=null===r?"":r;break;case u:if(null===r){var o=n.toLowerCase();e.removeAttribute(o)}else if("0"===r)e[n]=0;else if("-1"===r)e[n]=-1;else{var i=parseInt(r,10);isNaN(i)||(e[n]=i)}break;case c:["","true"].indexOf(r)<0?e[n]=!1:e[n]=!0}},y=function n(o,i,u){if(o&&i){u=u||i.node.parentNode;var c=o.content&&o.content!==i.content;if(o.type!==i.type||c)return u.replaceChild(o.node,i.node),function(e,t){for(var n in e)t[n]=e[n]}(o,i);(function(n,r){var o=[],i={};for(var u in r.attributes){var c=r.attributes[u],l=n.attributes[u];c!==l&&void 0===l&&o.push(u)}for(var y in n.attributes){var m=r.attributes[y],b=n.attributes[y];m!==b&&void 0!==b&&(i[y]=b)}!function(n,r){t(r,(function(t){if(e(s,t)){var r=s[t];h(n.node,r.type,r.propName,null)}else t in n.node&&h(n.node,a,t,null),n.node.removeAttribute(t);delete n.attributes[t]}))}(r,o),function(t,n){for(var r in n){var o=n[r];if(t.attributes[r]=o,e(s,r)){var i=s[r];h(t.node,i.type,i.propName,o)}else r.startsWith(d)?t.node.setAttributeNS(f,r,o):r.startsWith(v)?t.node.setAttributeNS(p,r,o):(r in t.node&&h(t.node,a,r,o),t.node.setAttribute(r,o||""))}}(r,i)})(o,i),function(n,o,i){var a=n.children.length,u=o.children.length;if(a||u){var c=function(n){var r={};for(var o in t(n,(function(t){var n=t.attributes["data-key"];(function(t,n){return!(!n||e(t,n)&&(console.warn("[OmDomDom]: Children with duplicate keys detected. Children with duplicate keys will be skipped, resulting in dropped node references. Keys must be unique and non-indexed."),1))})(r,n)&&(r[n]=t)})),r)return r}(o.children),s=Array(a);t(n.children,void 0!==c?function(e,t){var n=o.node.childNodes,a=e.attributes["data-key"];if(Object.prototype.hasOwnProperty.call(c,a)){var u=c[a];Array.prototype.indexOf.call(n,u.node)!==t&&r(o,u,n[t]),s[t]=u,delete c[a],i(e,s[t])}else r(o,e,n[t]),s[t]=e}:function(e,t){var n=o.children[t];void 0!==n?(i(e,n),s[t]=n):(o.node.appendChild(e.node),s[t]=e)}),o.children=s;var l=o.node.childNodes.length,d=l-a;if(d>0)for(;d>0;)o.node.removeChild(o.node.childNodes[l-1]),l--,d--}}(o,i,n)}},m=function n(r){var o,i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];"string"==typeof r&&(o=r.trim().replace(/\s+</g,"<").replace(/>\s+/g,">"),r=(new DOMParser).parseFromString(o,"text/html").body);var a="BODY"===r.tagName,u=r.childNodes,c=u?u.length:0;if(a){if(c>1)throw new Error("[OmDomDom]: Your element should not have more than one root node.");if(0===c)throw new Error("[OmDomDom]: Your element should have at least one root node.");return n(u[0])}var l=3===r.nodeType?"text":8===r.nodeType?"comment":r.tagName.toLowerCase(),d=i||"svg"===l,f=1===r.nodeType?function(t){var n=function(t){return Array.prototype.reduce.call(t.attributes,(function(t,n){return e(s,n.name)||(t[n.name]=n.value),t}),{})}(t);return function(e,t){for(var n in s){var r=s[n].propName,o=e.getAttribute(n);n===s.style.attrName?t[n]=e.style[r]:"string"==typeof o&&(t[n]=o)}}(t,n),n}(r):{},v=c>0?null:r.textContent,p=Array(c);return t(u,(function(e,t){p[t]=n(e,d)})),{type:l,attributes:f,children:p,content:v,node:r,isSVGContext:d}};function b(e){if(e){var t=new URLSearchParams;return e.forEach((function(e,n){t.append(n,e)})),t}}function w(e){return g(e.trim().split("\n")).metadata}function g(e){var t,n,r,o,i,a,u,c=function(e,t){for(var n=[],r=0,o=t;r<o.length;r++){var i=e(o[r]);if(!i)break;n.push(i)}return n}(k,e),s=e.slice(c.length);return{metadata:(t=c,u=null===(n=t.find((function(e){return"RequestId"==e.key})))||void 0===n?void 0:n.value,{cookies:t.filter((function(e){return"Cookie"==e.key})).map((function(e){return e.value})),redirect:null===(r=t.find((function(e){return"Redirect"==e.key})))||void 0===r?void 0:r.value,error:null===(o=t.find((function(e){return"Error"==e.key})))||void 0===o?void 0:o.value,query:null===(i=t.find((function(e){return"Query"==e.key})))||void 0===i?void 0:i.value,events:t.filter((function(e){return"Event"==e.key})).map((function(e){return function(e){var t=E(e),n=t[0],r=t[1];return{name:n,detail:JSON.parse(r)}}(e.value)})),actions:t.filter((function(e){return"Trigger"==e.key})).map((function(e){return function(e){var t=E(e);return[t[0],t[1]]}(e.value)})),pageTitle:null===(a=t.find((function(e){return"PageTitle"==e.key})))||void 0===a?void 0:a.value,requestId:u}),rest:s}}function E(e){var t=e.indexOf("|");if(-1===t){var n=new Error("Bad Encoding, Expected Segment");throw n.message=e,n}return[e.slice(0,t),e.slice(t+1)]}function k(e){var t=e.match(/^(\w+)\: (.*)$/);if(t)return{key:t[1],value:t[2]}}function x(e,t){return e+" "+function(e){return""==e?"|":e.replace(/_/g,"\\_").replace(/\s+/g,"_")}(t)}var I,S=(I=function(e,t){return I=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},I(e,t)},function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}I(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),C=function(e){function t(t,n,r){var o=e.call(this,n)||this;return o.viewId=t,o.name="Fetch Error",o.body=r,o}return S(t,e),t}(Error),A=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function u(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}c((r=r.apply(e,t||[])).next())}))},T=function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}},O="https:"===window.location.protocol?"wss:":"ws:",q="".concat(O,"//").concat(window.location.host).concat(window.location.pathname),L=function(){function e(){this.reconnectDelay=0}return e.prototype.connect=function(e){var t=this;void 0===e&&(e=q);var n=new WebSocket(e);function r(e){console.log("Connection Error",e)}this.socket=n,n.addEventListener("error",r),n.addEventListener("open",(function(e){console.log("Websocket Connected"),t.hasEverConnected&&document.dispatchEvent(new Event("hyp-socket-reconnect")),t.isConnected=!0,t.hasEverConnected=!0,t.reconnectDelay=1e3,t.socket.removeEventListener("error",r),document.dispatchEvent(new Event("hyp-socket-connect"))})),n.addEventListener("close",(function(n){t.isConnected&&document.dispatchEvent(new Event("hyp-socket-disconnect")),t.isConnected=!1,t.hasEverConnected&&(console.log("Reconnecting in "+t.reconnectDelay/1e3+"s"),setTimeout((function(){return t.connect(e)}),t.reconnectDelay))}))},e.prototype.sendAction=function(e){return A(this,void 0,void 0,(function(){var t,n,r,o;return T(this,(function(i){switch(i.label){case 0:return t=function(e){var t,n;return[["|ACTION|","ViewId: "+e.viewId,"Action: "+e.action,"RequestId: "+e.requestId].join("\n"),(n=e.meta,n.map((function(e){return e.key+": "+e.value})).join("\n"))].join("\n")+((t=e.form)?"\n\n"+t:"")}(e),[4,this.fetch(e.requestId,e.viewId,t)];case 1:return n=i.sent(),r=n.metadata,o=n.rest,[2,{meta:r,body:o.join("\n")}]}}))}))},e.prototype.fetch=function(e,t,n){return A(this,void 0,void 0,(function(){return T(this,(function(r){switch(r.label){case 0:return this.sendMessage(n),[4,this.waitMessage(e,t)];case 1:return[2,r.sent()]}}))}))},e.prototype.sendMessage=function(e){this.socket.send(e)},e.prototype.waitMessage=function(e,t){return A(this,void 0,void 0,(function(){var n=this;return T(this,(function(r){return[2,new Promise((function(r,o){var i=function(a){var u=g(a.data.split("\n").slice(1)),c=u.metadata;c.requestId?c.requestId==e&&(n.socket.removeEventListener("message",i),c.cookies.forEach((function(e){document.cookie=e})),c.error?o(new C(t,c.error,u.rest.join("\n"))):r(u)):console.error("Missing RequestId!",c,a.data)};n.socket.addEventListener("message",i),n.socket.addEventListener("error",o)}))]}))}))},e.prototype.disconnect=function(){this.socket.close()},e}(),D=n(296);function N(e,t){document.addEventListener(e.toLowerCase(),(function(n){var r=n.target,o="on"+e+n.key,i=r.dataset[o];i&&(n.preventDefault(),t(R(r),i))}))}function M(e,t){document.addEventListener(e,(function(n){var r=n.target.closest("[data-on"+e+"]");if(r){n.preventDefault();var o=R(r);t(o,r.dataset["on"+e])}}))}function j(e){e.querySelectorAll("[data-onload]").forEach((function(e){var t=parseInt(e.dataset.delay)||0,n=e.dataset.onload;setTimeout((function(){var t=R(e);if(e.dataset.onload==n){var r=new CustomEvent("hyp-load",{bubbles:!0,detail:{target:t,onLoad:n}});e.dispatchEvent(r)}}),t)}))}function P(e){e.querySelectorAll("[data-onmouseenter]").forEach((function(e){var t=e.dataset.onmouseenter,n=R(e);e.onmouseenter=function(){var r=new CustomEvent("hyp-mouseenter",{bubbles:!0,detail:{target:n,onMouseEnter:t}});e.dispatchEvent(r)}}))}function H(e){e.querySelectorAll("[data-onmouseleave]").forEach((function(e){var t=e.dataset.onmouseleave,n=R(e);e.onmouseleave=function(){var r=new CustomEvent("hyp-mouseleave",{bubbles:!0,detail:{target:n,onMouseLeave:t}});e.dispatchEvent(r)}}))}function R(e){var t=function(e){var t,n=e.closest("[data-target]");return(null==n?void 0:n.dataset.target)||(null===(t=e.closest("[id]"))||void 0===t?void 0:t.id)}(e),n=document.getElementById(t);if(n)return n;console.error("Cannot find target: ",t,e)}var _=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function u(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}c((r=r.apply(e,t||[])).next())}))},V=function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}};function B(e){return _(this,void 0,void 0,(function(){var t,n,r,o,i,a;return V(this,(function(u){switch(u.label){case 0:return t=window.location.href,[4,fetch(t,{method:"POST",headers:{Accept:"text/html","Content-Type":"application/x-www-form-urlencoded","Hyp-RequestId":e.requestId,"Hyp-ViewId":e.viewId,"Hyp-Action":e.action},body:e.form,redirect:"manual"})];case 1:return[4,(n=u.sent()).text()];case 2:if(r=u.sent(),o=function(e){var t=g(e.split("\n").slice(1));return{metadata:t.metadata,rest:t.rest.slice(2)}}(r),i=o.metadata,a=o.rest,!n.ok)throw new C(e.viewId,r,r);return[2,{meta:i,body:a.join("\n")}]}}))}))}var G,U=function(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function u(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,u)}c((r=r.apply(e,t||[])).next())}))},W=function(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(c){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}catch(e){u=[6,e],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,c])}}},F=n(147);console.log("Hyperbole "+F.version);var J=new Set;function K(e){return U(this,void 0,void 0,(function(){return W(this,(function(t){return Z.isConnected?[2,Z.sendAction(e)]:[2,B(e)]}))}))}function Y(e,t,n){return U(this,void 0,void 0,(function(){var r,o,i,a,u,c,s,l,d,f;return W(this,(function(v){switch(v.label){case 0:if(void 0===e)return console.error("Undefined HyperView!"),[2];if(void 0===t)return console.error("Undefined Action!",e,"this is a bug, please report: https://github.com/seanhess/hyperbole"),[2];if(r=setTimeout((function(){e.classList.add("hyp-loading")}),100),o=Math.random().toString(36).substring(2,8),i=function(e,t,n,r){return{viewId:e,action:t,requestId:n,meta:[{key:"Cookie",value:decodeURI(document.cookie)},{key:"Query",value:window.location.search}],form:b(r)}}(e.id,t,o,n),e.dataset.requestId)return console.warn("Action overlaps with active request ("+e.dataset.requestId+")",t),[2];e.dataset.requestId=o,v.label=1;case 1:return v.trys.push([1,3,,4]),[4,K(i)];case 2:if((a=v.sent()).meta.requestId!=e.dataset.requestId)throw(u=new Error).name="Concurrency Error",u.message="Stale Action ("+o+"):"+t,u;return delete e.dataset.requestId,$(a.meta)?[2]:(c=function(e){var t=(new DOMParser).parseFromString(e,"text/html"),n=t.querySelector("style");return{content:t.querySelector("div"),css:n}}(a.body),c.content?(function(e){if(e)for(var t=0,n=e.sheet.cssRules;t<n.length;t++){var r=n[t];0==J.has(r.cssText)&&(G.sheet.insertRule(r.cssText),J.add(r.cssText))}}(c.css),s=m(e),(l=m(c.content)).attributes=s.attributes,y(l,s),z(d=document.getElementById(e.id)),d?(Q(a.meta,d),j(d),P(d),H(d),function(e){var t=e.querySelector("[autofocus]");(null==t?void 0:t.focus)&&t.focus(),e.querySelectorAll("input[value]").forEach((function(e){var t=e.getAttribute("value");void 0!==t&&(e.value=t)})),e.querySelectorAll("input[type=checkbox]").forEach((function(e){var t="True"==e.dataset.checked;e.checked=t}))}(d),X(d)):console.warn("Target Missing: ",e.id),[3,4]):(console.error("Empty Response!",a.body),[2]));case 3:return f=v.sent(),console.error("Caught Error in HyperView ("+e.id+"):\n",f),e.innerHTML=f.body||"<div style='background:red;color:white;padding:10px'>Hyperbole Internal Error</div>",[3,4];case 4:return clearTimeout(r),e.classList.remove("hyp-loading"),[2]}}))}))}function $(e){if(e.redirect)return window.location.href=e.redirect,!0;null!=e.query&&function(e){if(e!=function(){var e=window.location.search;return e.startsWith("?")?e.substring(1):e}()){""!=e&&(e="?"+e);var t=location.pathname+e;window.history.replaceState({},"",t)}}(e.query),null!=e.pageTitle&&(document.title=e.pageTitle)}function Q(e,t){for(var n=0,r=e.events;n<r.length;n++){var o=r[n];setTimeout((function(){var e=new CustomEvent(o.name,{bubbles:!0,detail:o.detail});(t||document).dispatchEvent(e)}),10)}e.actions.forEach((function(e){var t=e[0],n=e[1];setTimeout((function(){var e=window.Hyperbole.hyperView(t);e&&Y(e,n)}),10)}))}function X(e){e.querySelectorAll("[id]").forEach((function(t){t.runAction=function(e){Y(this,e)}.bind(t),z(e)}))}function z(e){var t=new Event("hyp-content",{bubbles:!0});e.dispatchEvent(t)}document.addEventListener("DOMContentLoaded",(function(){var e,t=w(document.getElementById("hyp.metadata").innerText);$(t),Q(t),G=document.querySelector("style"),e=function(e,t){return U(this,void 0,void 0,(function(){return W(this,(function(n){return Y(e,t),[2]}))}))},document.addEventListener("hyp-load",(function(t){var n=t.detail.onLoad,r=t.detail.target;e(r,n)})),document.addEventListener("hyp-mouseenter",(function(t){var n=t.detail.onMouseEnter,r=t.detail.target;e(r,n)})),document.addEventListener("hyp-mouseleave",(function(t){var n=t.detail.onMouseLeave,r=t.detail.target;e(r,n)})),j(document.body),P(document.body),H(document.body),X(document.body),M("click",(function(e,t){return U(this,void 0,void 0,(function(){return W(this,(function(n){return Y(e,t),[2]}))}))})),M("dblclick",(function(e,t){return U(this,void 0,void 0,(function(){return W(this,(function(n){return Y(e,t),[2]}))}))})),N("Keydown",(function(e,t){return U(this,void 0,void 0,(function(){return W(this,(function(n){return Y(e,t),[2]}))}))})),N("Keyup",(function(e,t){return U(this,void 0,void 0,(function(){return W(this,(function(n){return Y(e,t),[2]}))}))})),document.addEventListener("submit",(function(e){var t=e.target;if(null==t?void 0:t.dataset.onsubmit){e.preventDefault();var n=R(t),r=new FormData(t);!function(e,t,n){U(this,void 0,void 0,(function(){return W(this,(function(r){return Y(e,t,n),[2]}))}))}(n,t.dataset.onsubmit,r)}else console.error("Missing onSubmit: ",t)})),document.addEventListener("change",(function(e){var t=e.target.closest("[data-onchange]");t&&(e.preventDefault(),null!=t.value?function(e,t){U(this,void 0,void 0,(function(){return W(this,(function(n){return console.log("CHANGE",e.id,"("+t+")"),Y(e,t),[2]}))}))}(R(t),x(t.dataset.onchange,t.value)):console.error("Missing input value:",t))})),document.addEventListener("input",(function(e){var t=e.target.closest("[data-oninput]");if(t){var n=parseInt(t.dataset.delay)||250;if(n<250&&console.warn("Input delay < 250 can result in poor performance."),null==t?void 0:t.dataset.oninput){e.preventDefault();var r=R(t);t.debouncedCallback||(t.debouncedCallback=D((function(){var e=x(t.dataset.oninput,t.value);!function(e,t){U(this,void 0,void 0,(function(){return W(this,(function(n){return Y(e,t),[2]}))}))}(r,e)}),n)),t.debouncedCallback()}else console.error("Missing onInput: ",t)}}))}));var Z=new L;Z.connect(),window.Hyperbole={runAction:Y,parseMetadata:w,action:function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return e+t.reduce((function(e,t){return e+" "+JSON.stringify(t)}),"")},hyperView:function(e){var t=document.getElementById(e);if(null==t?void 0:t.runAction)return t;console.error("Element id="+e+" was not a HyperView")},socket:Z}})()})();
//# sourceMappingURL=hyperbole.js.map