malevic
Version:
Malevič.js - minimalistic reactive UI library
2 lines (1 loc) • 29.1 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).Malevic={})}(this,(function(t){"use strict";function e(t){return null!=t&&"object"==typeof t}function n(t){return e(t)&&Object.getPrototypeOf(t)===Object.prototype}function r(t,e){return void 0===e&&(e=0),t[t.length-1-e]}function i(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(e=e||{},"string"==typeof t)return{type:t,props:e,children:n};if("function"==typeof t)return{type:t,props:e,children:n};throw new Error("Unsupported spec type")}function o(t){return e(t)&&null!=t.type&&null==t.nodeType}function u(t){return o(t)&&"string"==typeof t.type}function a(t){return o(t)&&"function"==typeof t.type}function s(){var t=[];return{add:function(e){return t.push(e),this},apply:function(e){for(var n,r,i=new Set,o=t.length-1;o>=0;o--)if(r=t[o],!i.has(r)){if(null!=(n=r(e)))return n;i.add(r)}return null},delete:function(e){for(var n=t.length-1;n>=0;n--)if(t[n]===e){t.splice(n,1);break}return this},empty:function(){return 0===t.length}}}function c(t,e,n){e.filter((function(e){var n=e[0];return t[n]})).forEach((function(e){var r=e[0],i=e[1];return t[r].forEach((function(t){return n(i,t)}))}))}function l(t,e){c(t,e,(function(t,e){return t.add(e)}))}function p(t,e){c(t,e,(function(t,e){return t.delete(e)}))}function f(t){var e={add:function(n,r){return n[t]||(n[t]=[]),n[t].push(r),e}};return e}var h="http://www.w3.org/1999/xhtml",d=Symbol(),v=s();function y(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=[],r=function(t){t&&("string"==typeof t?n.push(t):Array.isArray(t)?t.forEach(r):"object"==typeof t&&n.push.apply(n,Object.keys(t).filter((function(e){return Boolean(t[e])}))))};return t.forEach(r),n.join(" ")}function g(t){return Object.keys(t).filter((function(e){return null!=t[e]})).map((function(e){return"".concat(e,": ").concat(t[e],";")})).join(" ")}function m(t,e,n){if(null!=n&&""!==n){var r=String(n),i="";r.endsWith("!important")&&(r=r.substring(0,r.length-10),i="important"),t.style.setProperty(e,r,i)}else t.style.removeProperty(e)}var E=new WeakMap;function b(t,e){var n=new Map,r=new Set(Object.keys(t));return Object.keys(e).filter((function(t){return!r.has(t)})).forEach((function(t){return n.set(t,null)})),r.forEach((function(e){return n.set(e,t[e])})),n}function w(t,e,n){"function"==typeof n?function(t,e,n){var r;E.has(t)?r=E.get(t):(r=new Map,E.set(t,r)),r.get(e)!==n&&(r.has(e)&&t.removeEventListener(e,r.get(e)),t.addEventListener(e,n),r.set(e,n))}(t,e,n):function(t,e){if(E.has(t)){var n=E.get(t);t.removeEventListener(e,n.get(e)),n.delete(e)}}(t,e)}var x=new Set(["key","oncreate","onupdate","onrender","onremove"]),S=Symbol(),A=s();function N(t,e){return t&&t.hasOwnProperty(e)?t[e]:null}function k(t,n,r){b(n,r||{}).forEach((function(n,i){if(!A.empty()&&null!=A.apply({element:t,attr:i,value:n,get prev(){return N(r,i)}}))return;if("class"===i&&e(n))!function(t,e){var n=Array.isArray(e)?y.apply(void 0,e):y(e);n?t.setAttribute("class",n):t.removeAttribute("class")}(t,n);else if("style"===i&&e(n)){var o=N(r,i);!function(t,n,r){var i;e(r)?i=r:(i={},t.removeAttribute("style")),b(n,i).forEach((function(e,n){return m(t,n,e)}))}(t,n,o)}else if(i.startsWith("on")){var u=i.substring(2);w(t,u,n)}else x.has(i)||(null==n||!1===n?t.removeAttribute(i):t.setAttribute(i,!0===n?"":String(n)))}))}var C=function(){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=this;this.nexts=new WeakMap,this.prevs=new WeakMap,this.first=null,this.last=null,t.forEach((function(t){return n.push(t)}))}return t.prototype.empty=function(){return null==this.first},t.prototype.push=function(t){this.empty()?(this.first=t,this.last=t):(this.nexts.set(this.last,t),this.prevs.set(t,this.last),this.last=t)},t.prototype.insertBefore=function(t,e){var n=this.before(e);this.prevs.set(t,n),this.nexts.set(t,e),this.prevs.set(e,t),n&&this.nexts.set(n,t),e===this.first&&(this.first=t)},t.prototype.delete=function(t){var e=this.before(t),n=this.after(t);e&&this.nexts.set(e,n),n&&this.prevs.set(n,e),t===this.first&&(this.first=n),t===this.last&&(this.last=e)},t.prototype.before=function(t){return this.prevs.get(t)||null},t.prototype.after=function(t){return this.nexts.get(t)||null},t.prototype.loop=function(t){if(!this.empty()){var e=this.first;do{if(t(e))break}while(e=this.after(e))}},t.prototype.copy=function(){var e=new t;return this.loop((function(t){return e.push(t),!1})),e},t.prototype.forEach=function(t){this.loop((function(e){return t(e),!1}))},t.prototype.find=function(t){var e=null;return this.loop((function(n){return!!t(n)&&(e=n,!0)})),e},t.prototype.map=function(t){var e=[];return this.loop((function(n){return e.push(t(n)),!1})),e},t}();function M(t,e,n){var r=t&&e&&t.matches(e);r&&t.parent()===e.parent()?n.replaceVNode(e,t):t&&n.addVNode(t);var i=n.getVNodeContext(t),o=n.getVNodeContext(e);if((e&&!r&&(e.detach(o),e.children().forEach((function(t){return M(null,t,n)})),e.detached(o)),t&&!r&&(t.attach(i),t.children().forEach((function(t){return M(t,null,n)})),t.attached(i)),r)&&t.update(e,i)!==n.LEAVE){var u=function(t,e){var n=e.children(),r=new Map,i=[];n.forEach((function(t){var e=t.key();null==e?i.push(t):r.set(e,t)}));var o=t.children(),u=[],a=new Set(n),s=new Set;return o.forEach((function(t){var e=null,n=null,o=t.key();if(null!=o){if(s.has(o))throw new Error("Duplicate key");s.add(o),r.has(o)&&(n=r.get(o))}else i.length>0&&(n=i.shift());t.matches(n)&&(e=n),u.push([t,e]),e&&a.delete(e)})),{matches:u,unmatched:a}}(t,e),a=u.matches;u.unmatched.forEach((function(t){return M(null,t,n)})),a.forEach((function(t){return M(t[0],t[1],n)})),t.updated(i)}}var O=function(t,e){return O=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},O(t,e)};function V(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}O(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var D=function(){return D=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},D.apply(this,arguments)};function _(t,e,n){if(n||2===arguments.length)for(var r,i=0,o=e.length;i<o;i++)!r&&i in e||(r||(r=Array.prototype.slice.call(e,0,i)),r[i]=e[i]);return t.concat(r||Array.prototype.slice.call(e))}"function"==typeof SuppressedError&&SuppressedError;var j=function(){function t(t){this.parentVNode=t}return t.prototype.key=function(){return null},t.prototype.parent=function(t){if(!t)return this.parentVNode;this.parentVNode=t},t.prototype.children=function(){return[]},t.prototype.attach=function(t){},t.prototype.detach=function(t){},t.prototype.update=function(t,e){return null},t.prototype.attached=function(t){},t.prototype.detached=function(t){},t.prototype.updated=function(t){},t}();function T(t,e){return t instanceof Element&&(t.namespaceURI===h&&e.type===t.tagName.toLocaleLowerCase()||t.namespaceURI!==h&&e.type===t.tagName)}var P=new WeakMap;function R(t,e){var n;P.has(e)?n=P.get(e):(n=new WeakSet,P.set(e,n)),n.add(t)}function L(t,e){return P.has(e)&&P.get(e).has(t)}var I=function(t){function e(e,n){var r=t.call(this,n)||this;return r.spec=e,r}return V(e,t),e.prototype.matches=function(t){return t instanceof e&&this.spec.type===t.spec.type},e.prototype.key=function(){return this.spec.props.key},e.prototype.children=function(){return[this.child]},e.prototype.getExistingElement=function(t){var e,n=t.parent,r=t.node;if(T(r,this.spec))e=r;else if(!L(n,t.vdom)&&t.vdom.isDOMNodeCaptured(n)){var i=t.sibling,o=i?i.nextElementSibling:n.firstElementChild;o&&!t.vdom.isDOMNodeCaptured(o)&&(T(o,this.spec)?e=o:n.removeChild(o))}return e},e.prototype.attach=function(t){var e,n=this.getExistingElement(t);n?e=n:R(e=function(t,e){var n=v.apply({spec:t,parent:e});if(n)return n;var r=t.type;if("svg"===r)return document.createElementNS("http://www.w3.org/2000/svg","svg");var i=e.namespaceURI;return i===h||null==i?document.createElement(r):document.createElementNS(i,r)}(this.spec,t.parent),t.vdom),k(e,this.spec.props,null),this.child=J(e,this.spec.children,this,!1)},e.prototype.update=function(t,e){var n=e.vdom.getVNodeContext(t).node;k(n,this.spec.props,t.spec.props),this.child=J(n,this.spec.children,this,!1)},e.prototype.attached=function(t){var e=this.spec.props,n=e.oncreate,r=e.onrender;n&&n(t.node),r&&r(t.node)},e.prototype.detached=function(t){var e=this.spec.props.onremove;e&&e(t.node)},e.prototype.updated=function(t){var e=this.spec.props,n=e.onupdate,r=e.onrender;n&&n(t.node),r&&r(t.node)},e}(j),W={CREATED:Symbol(),REMOVED:Symbol(),UPDATED:Symbol(),RENDERED:Symbol(),ACTIVE:Symbol(),DEFAULTS_ASSIGNED:Symbol()},U=[[d,v],[S,A]],$=function(t){function e(e,n){var r=t.call(this,n)||this;return r.lock=!1,r.spec=e,r.prev=null,r.store={},r.store[W.ACTIVE]=r,r}return V(e,t),e.prototype.matches=function(t){return t instanceof e&&this.spec.type===t.spec.type},e.prototype.key=function(){return this.spec.props.key},e.prototype.children=function(){return[this.child]},e.prototype.createContext=function(t){var e=t.parent,n=this,r=n.spec,i=n.prev,o=n.store;return{spec:r,prev:i,store:o,get node(){return t.node},get nodes(){return t.nodes},parent:e,onCreate:function(t){return o[W.CREATED]=t},onUpdate:function(t){return o[W.UPDATED]=t},onRemove:function(t){return o[W.REMOVED]=t},onRender:function(t){return o[W.RENDERED]=t},refresh:function(){o[W.ACTIVE].refresh(t)},leave:function(){return t.vdom.LEAVE},getStore:function(t){return t&&!o[W.DEFAULTS_ASSIGNED]&&(Object.entries(t).forEach((function(t){var e=t[0],n=t[1];o[e]=n})),o[W.DEFAULTS_ASSIGNED]=!0),o}}},e.prototype.unbox=function(t){var n=this.spec.type,r=this.spec.props,i=this.spec.children;this.lock=!0;var o=e.context;e.context=this.createContext(t);var u=null;try{u=n.apply(void 0,_([r],i,!1))}finally{e.context=o,this.lock=!1}return u},e.prototype.refresh=function(t){if(this.lock)throw new Error("Calling refresh during unboxing causes infinite loop");this.prev=this.spec;var e=t.vdom.getVNodeContext(this),n=this.unbox(e);if(n!==t.vdom.LEAVE){var r=this.child;this.child=Q(n,this),t.vdom.execute(this.child,r),this.updated(t)}},e.prototype.addPlugins=function(){l(this.spec.type,U)},e.prototype.deletePlugins=function(){p(this.spec.type,U)},e.prototype.attach=function(t){this.addPlugins();var e=this.unbox(t),n=e===t.vdom.LEAVE?null:e;this.child=Q(n,this)},e.prototype.update=function(t,e){this.store=t.store,this.prev=t.spec,this.store[W.ACTIVE]=this;var n=e.vdom.getVNodeContext(t);this.addPlugins();var r=this.unbox(n),i=null;return r===e.vdom.LEAVE?(i=r,this.child=t.child,e.vdom.adoptVNode(this.child,this)):this.child=Q(r,this),i},e.prototype.handle=function(t,e){var n=this.store[t];if(n){var r=0===e.nodes.length?[null]:e.nodes;n.apply(void 0,r)}},e.prototype.attached=function(t){this.deletePlugins(),this.handle(W.CREATED,t),this.handle(W.RENDERED,t)},e.prototype.detached=function(t){this.handle(W.REMOVED,t)},e.prototype.updated=function(t){this.deletePlugins(),this.handle(W.UPDATED,t),this.handle(W.RENDERED,t)},e.context=null,e}(j);function F(){return $.context}var z=function(t){function e(e,n){var r=t.call(this,n)||this;return r.text=e,r}return V(e,t),e.prototype.matches=function(t){return t instanceof e},e.prototype.children=function(){return[this.child]},e.prototype.getExistingNode=function(t){var e,n=t.parent;if(t.node instanceof Text)e=t.node;else if(!L(n,t.vdom)&&t.vdom.isDOMNodeCaptured(n)){var r=t.sibling,i=r?r.nextSibling:n.firstChild;i&&!t.vdom.isDOMNodeCaptured(i)&&i instanceof Text&&(e=i)}return e},e.prototype.attach=function(t){var e,n=this.getExistingNode(t);n?(e=n).textContent=this.text:e=document.createTextNode(this.text),this.child=Q(e,this)},e.prototype.update=function(t,e){var n=e.vdom.getVNodeContext(t).node;this.text!==t.text&&(n.textContent=this.text),this.child=Q(n,this)},e}(j),B=function(t){function e(e,n){var r=t.call(this,n)||this;return r.fn=e,r}return V(e,t),e.prototype.matches=function(t){return t instanceof e},e.prototype.children=function(){return[this.child]},e.prototype.call=function(t){var e=(0,this.fn)({parent:t.parent,get node(){return t.node},get nodes(){return t.nodes}});this.child=Q(e,this)},e.prototype.attach=function(t){this.call(t)},e.prototype.update=function(t,e){var n=e.vdom.getVNodeContext(t);this.call(n)},e}(j),q=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return V(e,t),e.prototype.matches=function(t){return t instanceof e},e}(j),G=function(t){function e(e,n,r,i){var o=t.call(this,r)||this;return o.node=e,o.childSpecs=n,o.isNative=i,o}return V(e,t),e.prototype.matches=function(t){return t instanceof e&&this.node===t.node},e.prototype.wrap=function(){var t=this;this.childVNodes=this.childSpecs.map((function(e){return Q(e,t)}))},e.prototype.insertNode=function(t){var e=t.parent,n=t.sibling;if(!(e===this.node.parentElement&&n===this.node.previousSibling)){var r=n?n.nextSibling:e.firstChild;e.insertBefore(this.node,r)}},e.prototype.attach=function(t){this.wrap(),this.insertNode(t)},e.prototype.detach=function(t){t.parent.removeChild(this.node)},e.prototype.update=function(t,e){this.wrap(),this.insertNode(e)},e.prototype.cleanupDOMChildren=function(t){for(var e=this.node,n=e.lastChild;null!=n;)if(t.vdom.isDOMNodeCaptured(n))n=n.previousSibling;else{var r=n.previousSibling;e.removeChild(n),n=r}},e.prototype.refine=function(t){this.isNative||this.cleanupDOMChildren(t),R(this.node,t.vdom)},e.prototype.attached=function(t){var e=this.node;e instanceof Element&&!L(e,t.vdom)&&t.vdom.isDOMNodeCaptured(e)&&this.refine(t)},e.prototype.children=function(){return this.childVNodes},e}(j);function H(t){return t instanceof G}function J(t,e,n,r){return new G(t,e,n,r)}var K=function(t){function e(e,n,r){var i=t.call(this,r)||this;return i.items=e,i.id=n,i}return V(e,t),e.prototype.matches=function(t){return t instanceof e},e.prototype.key=function(){return this.id},e.prototype.children=function(){return this.childVNodes},e.prototype.wrap=function(){var t=this;this.childVNodes=this.items.map((function(e){return Q(e,t)}))},e.prototype.attach=function(){this.wrap()},e.prototype.update=function(){this.wrap()},e}(j);function Q(t,e){if(u(t))return new I(t,e);if(a(t))return t.type===Array?new K(t.children,t.props.key,e):new $(t,e);if("string"==typeof t)return new z(t,e);if(null==t)return new q(e);if("function"==typeof t)return new B(t,e);if(t instanceof Node)return J(t,[],e,!0);if(Array.isArray(t))return new K(t,null,e);throw new Error("Unable to create virtual node for spec")}function X(t){var e=new WeakMap,n=new WeakMap,r=new WeakMap,i=new WeakMap,o=new WeakSet;function u(o){var u=r.get(o);e.set(o,{parent:u,get node(){var t=i.get(o).find((function(t){return null!=t.node}));return t?t.node:null},get nodes(){return i.get(o).map((function(t){return t.node})).filter((function(t){return t}))},get sibling(){if(u===t.parentElement)return i.get(o).first.node.previousSibling;for(var e=n.get(u),r=i.get(o).first;r=e.links.before(r);)if(r.node)return r.node;return null},vdom:c})}function a(e){null==e.parent()?function(e){var o=t.parentElement||document.createDocumentFragment(),u=new C({parentNode:o,node:t});i.set(e,u.copy()),r.set(e,o),n.set(o,{node:o,links:u})}(e):function(t){var e=t.parent(),u=o.has(e),a=H(e)?e.node:r.get(e);r.set(t,a);var s=new C;if(i.set(t,s),u){var c={parentNode:a,node:null},l=t;do{i.get(l).push(c),l=l.parent()}while(l&&!H(l));n.get(a).links.push(c)}else o.add(e),(H(e)?n.get(a).links:i.get(e)).forEach((function(t){return s.push(t)}))}(e),function(t){if(H(t)){var e=t.node;n.set(e,{node:e,links:new C({parentNode:e,node:null})}),i.get(t).forEach((function(t){return t.node=e}))}}(e),u(e)}function s(t){for(var e=r.get(t),o=n.get(e),u=[],a=t;(a=a.parent())&&!H(a);)u.push(i.get(a));return u.push(o.links),u}var c={execute:function(t,e){M(t,e,c)},addVNode:a,getVNodeContext:function(t){return e.get(t)},replaceVNode:function(t,n){if(null!=n.parent()){var o=e.get(t).parent;r.set(n,o);var c=i.get(t),l={parentNode:o,node:null};s(n).forEach((function(t){var e=t.after(c.last);c.forEach((function(e){return t.delete(e)})),e?t.insertBefore(l,e):t.push(l)}));var p=new C(l);i.set(n,p),u(n)}else a(n)},adoptVNode:function(t,e){var n=i.get(t),r=i.get(e).copy();t.parent(e),s(t).forEach((function(t){n.forEach((function(e){return t.insertBefore(e,r.first)})),r.forEach((function(e){return t.delete(e)}))}))},isDOMNodeCaptured:function(e){return n.has(e)&&e!==t.parentElement},LEAVE:Symbol()};return c}var Y=new WeakMap,Z=new WeakMap;function tt(t,e){var n,r=Y.get(t)||null;return Y.set(t,e),Z.has(t)?n=Z.get(t):(n=X(t),Z.set(t,n)),n.execute(e,r),n.getVNodeContext(e)}function et(t){return function(n){for(var r=[],u=1;u<arguments.length;u++)r[u-1]=arguments[u];var a=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var i=e(t)&&!o(t)?t:null;return{attrs:i,children:null==i?[t].concat(n):n}}(n,r),s=a.attrs,c=a.children;return i(t,s,c)}}var nt=new Proxy({},{get:function(t,e){return et(e)}});function rt(t){if(t instanceof Text)return t.textContent.trim().replaceAll(/\r/g,"").replaceAll(/\s*?\n\s*/g,"\n");if(!(t instanceof Element))return null;for(var e=t.namespaceURI===h?t.tagName.toLocaleLowerCase():t.tagName,n={},r=0;r<t.attributes.length;r++){var o=t.attributes[r];n[o.name]=String(o.value)}var u=Array.from(t.childNodes).map(rt).filter((function(t){return null===t||"string"==typeof t&&""!==t||"object"==typeof t}));return i.apply(void 0,_([e,n],u,!1))}var it={createElement:f(d),setAttribute:f(S)},ot=Object.freeze({__proto__:null,component:function(t){var e=function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var i=F();return t.apply(void 0,_([i,e],n,!1))};return function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return i.apply(void 0,_([e,t],n,!1))}},getContext:F,plugins:it,render:function(t,e){return tt(t,J(t,Array.isArray(e)?e:[e],null,!1)),t},specFromNode:function(t){return rt(t)},sync:function(t,e){var n=tt(t,Q(e,null)).nodes;if(1!==n.length||n[0]!==t)throw new Error("Spec does not match the node");return n[0]},tag:et,tags:nt,teardown:function(t){Y.delete(t),Z.delete(t)}});function ut(t){return t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}var at=Symbol(),st=s();var ct=Symbol(),lt=s(),pt=new Set(["key","oncreate","onupdate","onrender","onremove"]);var ft=Symbol(),ht=s();var dt=new Set(["area","base","br","col","embed","hr","img","input","link","menuitem","meta","param","source","track","wbr"]),vt=null;var yt=[[at,st],[ct,lt],[ft,ht]],gt=function(){};function mt(t,e){return"".padEnd(t.length*e,t)}var Et=function(t){function n(n){var r=t.call(this)||this;return r.children=[],r.tag=n.type,r.attrs=new Map,Object.entries(n.props).filter((function(t){return!function(t,e){if(!lt.empty()){var n=lt.apply({attr:t,value:e});if(null!=n)return n}return pt.has(t)||t.startsWith("on")||null==e||!1===e}(t[0],t[1])})).forEach((function(t){var n=t[0],i=t[1];return r.attrs.set(n,function(t,n){if(!st.empty()){var r=st.apply({attr:t,value:n});if(null!=r)return r}return"class"===t&&e(n)?ut(Array.isArray(n)?y.apply(void 0,n):y(n)):"style"===t&&e(n)?ut(g(n)):!0===n?"":ut(String(n))}(n,i))})),r.isVoid=function(t){if(!ht.empty()){var e=ht.apply(t);if(null!=e)return e}return dt.has(t)}(r.tag),r}return V(n,t),n.prototype.stringify=function(t){var e=t.indent,n=t.depth,r=t.xmlSelfClosing,i=[],o=mt(e,n),u=Array.from(this.attrs.entries()).map((function(t){var e=t[0],n=t[1];return""===n?e:"".concat(e,'="').concat(n,'"')})).join(" "),a=r&&0===this.children.length,s="".concat(o,"<").concat(this.tag).concat(u?" ".concat(u):"").concat(a?"/>":">");if(this.isVoid||a)i.push(s);else{var c="</".concat(this.tag,">");0===this.children.length?i.push("".concat(s).concat(c)):1===this.children.length&&this.children[0]instanceof bt&&!this.children[0].text.includes("\n")?i.push("".concat(s).concat(this.children[0].stringify({indent:e,depth:0,xmlSelfClosing:r})).concat(c)):(i.push(s),this.children.forEach((function(t){return i.push(t.stringify({indent:e,depth:n+1,xmlSelfClosing:r}))})),i.push("".concat(o).concat(c)))}return i.join("\n")},n}(gt),bt=function(t){function e(e){var n=t.call(this)||this;return n.text=function(t){return ut(t)}(e),n}return V(e,t),e.prototype.stringify=function(t){var e=mt(t.indent,t.depth);return"".concat(e).concat(this.text.replace(/\n/g,"\n".concat(e)))},e}(gt),wt=function(t){function e(e){var n=t.call(this)||this;return n.text=ut(e),n}return V(e,t),e.prototype.stringify=function(t){var e=t.indent,n=t.depth;return"".concat(mt(e,n),"\x3c!--").concat(this.text,"--\x3e")},e}(gt);function xt(t,e){if(u(t)){var n=new Et(t);e.children.push(n),t.children.forEach((function(t){return xt(t,n)}))}else if(a(t))if(t.type===Array)t.children.forEach((function(t){return xt(t,e)}));else{l(t.type,yt);var r=function(t){var e=t.type,n=t.props,r=t.children,i=vt;vt={};var o=e.apply(void 0,_([n],r,!1));return vt=i,o}(t);xt(r,e),p(t.type,yt)}else if("string"==typeof t){var i=new bt(t);e.children.push(i)}else if(null==t){i=new wt("");e.children.push(i)}else{if(!Array.isArray(t))throw new Error("Unable to stringify spec");t.forEach((function(t){return xt(t,e)}))}}var St={stringifyAttribute:f(at),skipAttribute:f(ct),isVoidTag:f(ft)};var At=Object.freeze({__proto__:null,escapeHTML:ut,isStringifying:function(){return null!=vt},plugins:St,stringify:function(t,e){var n=void 0===e?{}:e,r=n.indent,i=void 0===r?" ":r,u=n.depth,a=void 0===u?0:u,s=n.xmlSelfClosing,c=void 0!==s&&s;if(o(t)){var l=function(t){var e=new Et({type:"div",props:{},children:[]});return xt(t,e),e.children}(t);return l.map((function(t){return t.stringify({indent:i,depth:a,xmlSelfClosing:c})})).join("\n")}throw new Error("Not a spec")}});function Nt(t,e,n){return e*(1-t)+n*t}var kt=function(t,e){return function(n){return Nt(n,t,e)}};function Ct(t){for(var e,n=[],r=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[e][-+]?\d+)?/gim;e=r.exec(t);)n.push({index:e.index,length:e[0].length});return n}var Mt=function(t,e){var n=Ct(t),r=Ct(e);return function(i){for(var o="",u=0,a=0;a<r.length;a++)o+=e.substring(u,r[a].index),o+=Nt(i,parseFloat(t.substr(n[a].index,n[a].length)),parseFloat(e.substr(r[a].index,r[a].length))).toString(),u=r[a].index+r[a].length;return o+=e.substring(u)}};function Ot(t){return t}var Vt={delay:0,duration:250,easing:"ease"},Dt=function(){function t(){this.$spec={initial:null,timeline:[],interpolate:null,output:Ot,done:null}}return t.prototype.initial=function(t){return this.$spec.initial=t,this},t.prototype.from=function(t){if(this.$spec.timeline.length>0)throw new Error("Starting keyframe was already declared");return this.$spec.timeline.push({from:t,to:null,timing:D({},Vt)}),this},t.prototype.to=function(t,e){this.$spec.interpolate||("number"==typeof t?this.$spec.interpolate=kt:"string"==typeof t&&(this.$spec.interpolate=Mt));var n=r(this.$spec.timeline);return n&&null==n.to?(n.to=t,e&&(n.timing=D(D({},n.timing),e))):this.$spec.timeline.push({from:n?n.to:null,to:t,timing:D(D({},Vt),e||{})}),this},t.prototype.interpolate=function(t){return this.$spec.interpolate=t,this},t.prototype.output=function(t){return this.$spec.output=t,this},t.prototype.done=function(t){return this.$spec.done=t,this},t.prototype.spec=function(){return this.$spec},t}();var _t={linear:function(t){return t},ease:function(t){var e=(1-Math.cos(t*Math.PI))/2,n=Math.sqrt(1-Math.pow(t-1,2)),r=Math.sin(t*Math.PI/2);return e*(1-r)+n*r},"ease-in":function(t){var e=1-Math.cos(t*Math.PI/2);return e>1-1e-15?1:e},"ease-out":function(t){return Math.sin(t*Math.PI/2)},"ease-in-out":function(t){return(1-Math.cos(t*Math.PI))/2}},jt=function(){function t(t,e){if(!t.interpolate)throw new Error("No interpolator provided");this.interpolate=t.interpolate,this.output=t.output,this.callback=e,this.doneCallback=t.done;var n=0;this.timeline=t.timeline.map((function(t){var e=n,r=e+t.timing.delay,i=r+t.timing.duration;return n=i,{standby:e,start:r,end:i,spec:t,interpolate:null}})),this.isComplete=!1}return t.prototype.tick=function(t){null==this.startTime&&(this.startTime=t);for(var e,n=t-this.startTime,i=this.timeline,o=i.length-1;o>=0;o--){var u=i[o],a=u.standby,s=u.end;if(n>=s||n>=a&&n<=s){e=i[o];break}}var c=e.start,l=e.end,p=e.spec;e===r(i)&&n>=l&&(this.isComplete=!0),e.interpolate||(e.interpolate=this.interpolate(p.from,p.to));var f,h,d,v=("string"==typeof p.timing.easing?_t[p.timing.easing]:p.timing.easing)(n<c?0:c===l?1:(f=(n-c)/(l-c),h=0,d=1,Math.min(d,Math.max(h,f)))),y=e.interpolate.call(null,v);this.lastValue=y;var g=this.output.call(null,y);this.callback.call(null,g)},t.prototype.value=function(){return this.lastValue},t.prototype.complete=function(){return this.isComplete},t.prototype.finalize=function(){this.doneCallback&&this.doneCallback.call(null)},t}();var Tt=function(){var t=null,e=null,n=!1,r=[];function i(){t=performance.now(),r.forEach((function(e){return e(t)})),n&&(e=requestAnimationFrame(i))}return{run:function(){n=!0,t=performance.now(),e=requestAnimationFrame(i)},stop:function(){cancelAnimationFrame(e),e=null,t=null,n=!1},tick:function(t){r.push(t)},time:function(){return t},running:function(){return n}}}();function Pt(t,e){t.tick(e),t.complete()&&(It(t),t.finalize())}Tt.tick((function(t){return Array.from(Lt.values()).forEach((function(e){return Pt(e,t)}))}));var Rt=new WeakMap,Lt=new Set;function It(t){Lt.delete(t),0===Lt.size&&Tt.stop()}function Wt(t){var e=Rt.get(t);return e&&Lt.has(e)?e:null}function Ut(t){return n(t)&&Object.values(t).some((function(t){return t instanceof Dt}))}function $t(t,e,n){var i,o,u,a,s,c=t.spec(),l=c.timeline[0].from,p=r(c.timeline).to;if(e instanceof Dt){var f=Wt(e);if(f)It(f),i=f.value();else i=r(e.spec().timeline).to}else typeof e==typeof p&&null!=e&&null!=p&&e.constructor===p.constructor&&(i=e);(null!=l?o=l:null!=i?o=i:null!=c.initial&&(o=c.initial),null==o)?n(c.output(p)):(c.timeline[0].from=o,a=n,s=new jt((u=t).spec(),a),Lt.add(s),Rt.set(u,s),!Tt.running()&&Tt.run(),Pt(s,Tt.time()))}function Ft(t){if(t instanceof Dt){var e=Wt(t);e&&It(e)}}var zt=function(t){var e=t.element,n=t.attr,r=t.value,i=t.prev;return r instanceof Dt?($t(r,i,(function(t){return e.setAttribute(n,t)})),!0):(Ut(i)?Object.values(i).forEach((function(t){return Ft(t)})):Ft(i),null)},Bt=function(t){var e=t.element,r=t.attr,i=t.value,o=t.prev;if("style"===r){if(Ut(i)){var u,a=i;return n(o)?(u=o,Object.keys(u).filter((function(t){return!a.hasOwnProperty(t)})).forEach((function(t){Ft(u[t]),m(e,t,null)}))):(u={},e.removeAttribute("style"),Ft(o)),Object.entries(a).forEach((function(t){var n=t[0],r=t[1],i=u[n];r instanceof Dt?$t(r,i,(function(t){m(e,n,t)})):(Ft(i),m(e,n,r))})),!0}Ut(o)&&Object.values(o).forEach((function(t){return Ft(t)}))}return null};function qt(t){return t.output(null!=t.timeline[0].from?t.timeline[0].from:null!=t.initial?t.initial:r(t.timeline).to)}var Gt=function(t){var e=t.value;if(e instanceof Dt){var n=e.spec();return ut(String(qt(n)))}return null},Ht=function(t){var e=t.attr,n=t.value;if("style"===e&&Ut(n)){var r={};return Object.keys(n).forEach((function(t){var e=n[t];if(e instanceof Dt){var i=e.spec();r[t]=qt(i)}else r[t]=e})),ut(g(r))}return null};var Jt=Object.freeze({__proto__:null,animate:function(t,e){var n=new Dt;return null!=t&&n.to(t,e),n},withAnimation:function(t){if(ot){var e=it;e.setAttribute.add(t,zt),e.setAttribute.add(t,Bt)}if(At){var n=St;n.stringifyAttribute.add(t,Gt),n.stringifyAttribute.add(t,Ht)}return t}}),Kt=[],Qt=null;function Xt(t,e){if(null!=e)if(a(e))e.type===Array?e.children.forEach((function(e){return Xt(t,e)})):function(t,e){var n=e.type,r=e.props,i=e.children;l(n,Kt);var o=Qt;Qt=t,Xt(t,n.apply(void 0,_([r],i,!1))),Qt=o,p(n,Kt)}(t,e);else if(Array.isArray(e))e.forEach((function(e){return Xt(t,e)}));else{if("function"!=typeof e)throw new Error("Unable to draw spec");e(t)}}var Yt=Object.freeze({__proto__:null,draw:Xt,getContext:function(){return Qt}});var Zt=Object.freeze({__proto__:null,withForms:function(t){return it.setAttribute.add(t,(function(t){var e=t.element,n=t.attr,r=t.value;if("value"===n&&e instanceof HTMLInputElement){var i=e.value=null==r?"":r;return e.value=i,!0}return null})),t}}),te=null;var ee=Object.freeze({__proto__:null,useState:function(t){if(!te)throw new Error("`useState()` should be called inside a component");return te(t)},withState:function(t){return function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];var i,o=F(),u=!0,a=te;te=function(t){if(!o)return{state:t,setState:null};var e=o.store,n=o.refresh;e.state=e.state||t;return{state:e.state,setState:function(t){if(u)throw new Error("Setting state during unboxing causes infinite loop");e.state=D(D({},e.state),t),n()}}};try{i=t.apply(void 0,_([e],n,!1))}finally{te=a,u=!1}return i}}});t.Animation=Jt,t.Canvas=Yt,t.DOM=ot,t.Forms=Zt,t.State=ee,t.String=At,t.m=i}));