diff --git a/CHANGELOG.md b/CHANGELOG.md index 4da971a..808dc39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,23 @@ * apprun@latest: 2.x, stable, es2015, web component * apprun@next: 3.x, dev, es2015, lit-html +## 1.28/ 2.28 / 3.28 + +* New app.query function that returns the returned values of all then event handlers + ```ts + app.query(name: string, ...args): Promise; + ``` +* Event pattern matching + ```ts + app.on('ws:*', _ => 0); // handles all events that have name start with ws: + ``` +* Event context + ```ts + @on('event', {c:1}) // define the context + fn = ({c}) => {...}; // get the context in the handler + + ``` + ## 1.27/ 2.27 / 3.27 * BREAKING CHANGES: New logic for creating stateful components @@ -33,6 +50,7 @@ * Support the list attribute * Support webpack 5 * Set jsxFactory to app.h for TypeScript 4 + ## 1.24 / 2.24 / 3.24 * Support the list attribute diff --git a/demo-html/app.js b/demo-html/app.js index 5174dff..be22208 100644 --- a/demo-html/app.js +++ b/demo-html/app.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.apprun=e():t.apprun=e()}(this,(function(){return(()=>{"use strict";var t={643:(t,e,n)=>{n.r(e);var s=n(107);let o=class extends s.Component{constructor(){super(...arguments),this.view=({num:t,children:e})=>s.default.h("div",null,s.default.h("h1",null,t),e),this.update={"-1":t=>Object.assign(Object.assign({},t),{num:t.num-1}),"+1":t=>Object.assign(Object.assign({},t),{num:t.num+1})},this.mounted=({num:t},e)=>({num:parseInt(t),children:e}),this.rendered=({num:t})=>{this.element.setAttribute("num",t)}}};o=function(t,e,n,s){var o,i=arguments.length,r=i<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(i<3?o(r):i>3?o(e,n,r):o(e,n))||r);return i>3&&r&&Object.defineProperty(e,n,r),r}([(0,s.customElement)("my-counter")],o);let i=class extends s.Component{constructor(){super(...arguments),this.state={},this.view=t=>s.default.h(s.default.Fragment,null,s.default.h("div",null,s.default.h("button",{$onclick:"fetchComic"},"XKCD")),t.loading?s.default.h("div",null,"loading ... "):"",t.comic&&s.default.h(s.default.Fragment,null,s.default.h("h3",null,t.comic.title),s.default.h("img",{src:t.comic.url}))),this.update={loading:(t,e)=>({loading:!0}),fetchComic:t=>{return e=this,n=void 0,o=function*(){this.run("loading",!0);const t=yield fetch("https://xkcd-imgs.herokuapp.com/");return{comic:yield t.json(),loading:!1}},new((s=void 0)||(s=Promise))((function(t,i){function r(t){try{c(o.next(t))}catch(t){i(t)}}function a(t){try{c(o.throw(t))}catch(t){i(t)}}function c(e){var n;e.done?t(e.value):(n=e.value,n instanceof s?n:new s((function(t){t(n)}))).then(r,a)}c((o=o.apply(e,n||[])).next())}));var e,n,s,o}},this.mounted=()=>this.run("fetchComic")}};i=function(t,e,n,s){var o,i=arguments.length,r=i<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(i<3?o(r):i>3?o(e,n,r):o(e,n))||r);return i>3&&r&&Object.defineProperty(e,n,r),r}([(0,s.customElement)("my-xkcd",{shadow:!0,render:!1})],i)},107:(t,e,n)=>{n.d(e,{Component:()=>g,customElement:()=>u,default:()=>w});class s{constructor(){this._events={}}on(t,e,n={}){this._events[t]=this._events[t]||[],this._events[t].push({fn:e,options:n})}off(t,e){const n=this._events[t]||[];this._events[t]=n.filter((t=>t.fn!==e))}find(t){return this._events[t]}run(t,...e){const n=this._events[t]||[];return console.assert(n&&n.length>0,"No subscriber for event: "+t),this._events[t]=n.filter((t=>!t.options.once)),n.forEach((n=>{const{fn:s,options:o}=n;return o.delay?this.delay(t,s,e,o):s.apply(this,e),!n.options.once})),n.length}once(t,e,n={}){this.on(t,e,Object.assign(Object.assign({},n),{once:!0}))}delay(t,e,n,s){s._t&&clearTimeout(s._t),s._t=setTimeout((()=>{clearTimeout(s._t),e.apply(this,n)}),s.delay)}}let o;const i="object"==typeof self&&self.self===self&&self||"object"==typeof n.g&&n.g.global===n.g&&n.g;i.app&&i._AppRunVersions?o=i.app:(o=new s,i.app=o,i._AppRunVersions="AppRun-2");const r=o;var a=n(559);const c=(t,e={})=>class extends HTMLElement{constructor(){super()}get component(){return this._component}get state(){return this._component.state}static get observedAttributes(){return(e.observedAttributes||[]).map((t=>t.toLowerCase()))}connectedCallback(){if(this.isConnected&&!this._component){const n=e||{};this._shadowRoot=n.shadow?this.attachShadow({mode:"open"}):this;const s=n.observedAttributes||[],o=s.reduce(((t,e)=>{const n=e.toLowerCase();return n!==e&&(t[n]=e),t}),{});this._attrMap=t=>o[t]||t;const i={};Array.from(this.attributes).forEach((t=>i[this._attrMap(t.name)]=t.value)),s.forEach((t=>{void 0!==this[t]&&(i[t]=this[t]),Object.defineProperty(this,t,{get:()=>i[t],set(e){this.attributeChangedCallback(t,i[t],e)},configurable:!0,enumerable:!0})}));const r=this.children?Array.from(this.children):[];if(r.forEach((t=>t.parentElement.removeChild(t))),this._component=new t(Object.assign(Object.assign({},i),{children:r})).mount(this._shadowRoot,n),this._component._props=i,this._component.dispatchEvent=this.dispatchEvent.bind(this),this._component.mounted){const t=this._component.mounted(i,r,this._component.state);void 0!==t&&(this._component.state=t)}this.on=this._component.on.bind(this._component),this.run=this._component.run.bind(this._component),!1!==n.render&&this._component.run(".")}}disconnectedCallback(){var t,e,n,s;null===(e=null===(t=this._component)||void 0===t?void 0:t.unload)||void 0===e||e.call(t),null===(s=null===(n=this._component)||void 0===n?void 0:n.unmount)||void 0===s||s.call(n),this._component=null}attributeChangedCallback(t,n,s){if(this._component){const o=this._attrMap(t);this._component._props[o]=s,this._component.run("attributeChanged",o,n,s),s!==n&&!1!==e.render&&window.requestAnimationFrame((()=>{this._component.run(".")}))}}},h=(t,e,n)=>{"undefined"!=typeof customElements&&customElements.define(t,c(e,n))},l={meta:new WeakMap,defineMetadata(t,e,n){this.meta.has(n)||this.meta.set(n,{}),this.meta.get(n)[t]=e},getMetadataKeys(t){return t=Object.getPrototypeOf(t),this.meta.get(t)?Object.keys(this.meta.get(t)):[]},getMetadata(t,e){return e=Object.getPrototypeOf(e),this.meta.get(e)?this.meta.get(e)[t]:null}};function u(t,e){return function(n){return h(t,n,e),n}}const d=(t,e)=>(e?t.state[e]:t.state)||"",p=(t,e,n)=>{if(e){const s=t.state||{};s[e]=n,t.setState(s)}else t.setState(n)},f=new Map;r.on("get-components",(t=>t.components=f));const m=t=>t;class g{constructor(t,e,n,o){this.state=t,this.view=e,this.update=n,this.options=o,this._app=new s,this._actions=[],this._global_events=[],this._history=[],this._history_idx=-1,this._history_prev=()=>{this._history_idx--,this._history_idx>=0?this.setState(this._history[this._history_idx],{render:!0,history:!1}):this._history_idx=0},this._history_next=()=>{this._history_idx++,this._history_idxthis.mount(t,Object.assign(Object.assign({},e),{render:!0}))}render(t,e){r.render(t,e,this)}_view(t){if(!this.view)return;const e=r.createElement;r.h=r.createElement=(t,n,...s)=>(n&&Object.keys(n).forEach((e=>{e.startsWith("$")&&(((t,e,n,s)=>{if(t.startsWith("$on")){const n=e[t];if(t=t.substring(1),"boolean"==typeof n)e[t]=e=>s.run(t,e);else if("string"==typeof n)e[t]=t=>s.run(n,t);else if("function"==typeof n)e[t]=t=>s.setState(n(s.state,t));else if(Array.isArray(n)){const[o,...i]=n;"string"==typeof o?e[t]=t=>s.run(o,...i,t):"function"==typeof o&&(e[t]=t=>s.setState(o(s.state,...i,t)))}}else if("$bind"===t){const o=e.type||"text",i="string"==typeof e[t]?e[t]:e.name;if("input"===n)switch(o){case"checkbox":e.checked=d(s,i),e.onclick=t=>p(s,i||t.target.name,t.target.checked);break;case"radio":e.checked=d(s,i)===e.value,e.onclick=t=>p(s,i||t.target.name,t.target.value);break;case"number":case"range":e.value=d(s,i),e.oninput=t=>p(s,i||t.target.name,Number(t.target.value));break;default:e.value=d(s,i),e.oninput=t=>p(s,i||t.target.name,t.target.value)}else"select"===n?(e.value=d(s,i),e.onchange=t=>{t.target.multiple||p(s,i||t.target.name,t.target.value)}):"option"===n?(e.selected=d(s,i),e.onclick=t=>p(s,i||t.target.name,t.target.selected)):"textarea"===n&&(e.innerHTML=d(s,i),e.oninput=t=>p(s,i||t.target.name,t.target.value))}else r.run("$",{key:t,tag:n,props:e,component:s})})(e,n,t,this),delete n[e])})),e(t,n,...s));const n=this.view(t);return r.h=r.createElement=e,n}renderState(t,e=null){if(!this.view)return;let n=e||this._view(t);if(r.debug&&r.run("debug",{component:this,_:n?".":"-",state:t,vdom:n,el:this.element}),"object"!=typeof document)return;const s="string"==typeof this.element?document.getElementById(this.element):this.element;if(s){const t="_c";this.unload?s._component===this&&s.getAttribute(t)===this.tracking_id||(this.tracking_id=(new Date).valueOf().toString(),s.setAttribute(t,this.tracking_id),"undefined"!=typeof MutationObserver&&(this.observer||(this.observer=new MutationObserver((t=>{t[0].oldValue!==this.tracking_id&&document.body.contains(s)||(this.unload(this.state),this.observer.disconnect(),this.observer=null)}))),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:[t]}))):s.removeAttribute&&s.removeAttribute(t),s._component=this}e||this.render(s,n),this.rendered&&this.rendered(this.state)}setState(t,e={render:!0,history:!1}){if(t instanceof Promise)Promise.all([t,this._state]).then((t=>{t[0]&&this.setState(t[0])})).catch((t=>{throw console.error(t),t})),this._state=t;else{if(this._state=t,null==t)return;this.state=t,!1!==e.render&&this.renderState(t),!1!==e.history&&this.enable_history&&(this._history=[...this._history,t],this._history_idx=this._history.length-1),"function"==typeof e.callback&&e.callback(this.state)}}mount(t=null,e){var n,s;return console.assert(!this.element,"Component already mounted."),this.options=e=Object.assign(Object.assign({},this.options),e),this.element=t,this.global_event=e.global_event,this.enable_history=!!e.history,this.enable_history&&(this.on(e.history.prev||"history-prev",this._history_prev),this.on(e.history.next||"history-next",this._history_next)),e.route&&(this.update=this.update||{},this.update[e.route]=m),this.add_actions(),this.state=null!==(s=null!==(n=this.state)&&void 0!==n?n:this.model)&&void 0!==s?s:{},"function"==typeof this.state&&(this.state=this.state()),e.render?this.setState(this.state,{render:!0,history:!0}):this.setState(this.state,{render:!1,history:!0}),r.debug&&(f.get(t)?f.get(t).push(this):f.set(t,[this])),this}is_global_event(t){return t&&(this.global_event||this._global_events.indexOf(t)>=0||t.startsWith("#")||t.startsWith("/")||t.startsWith("@"))}add_action(t,e,n={}){e&&"function"==typeof e&&(n.global&&this._global_events.push(t),this.on(t,((...s)=>{r.debug&&r.run("debug",{component:this,_:">",event:t,p:s,current_state:this.state,options:n});const o=e(this.state,...s);r.debug&&r.run("debug",{component:this,_:"<",event:t,p:s,newState:o,state:this.state,options:n}),this.setState(o,n)}),n))}add_actions(){const t=this.update||{};l.getMetadataKeys(this).forEach((e=>{if(e.startsWith("apprun-update:")){const n=l.getMetadata(e,this);t[n.name]=[this[n.key].bind(this),n.options]}}));const e={};Array.isArray(t)?t.forEach((t=>{const[n,s,o]=t;n.toString().split(",").forEach((t=>e[t.trim()]=[s,o]))})):Object.keys(t).forEach((n=>{const s=t[n];("function"==typeof s||Array.isArray(s))&&n.split(",").forEach((t=>e[t.trim()]=s))})),e["."]||(e["."]=m),Object.keys(e).forEach((t=>{const n=e[t];"function"==typeof n?this.add_action(t,n):Array.isArray(n)&&this.add_action(t,n[0],n[1])}))}run(t,...e){const n=t.toString();return this.is_global_event(n)?r.run(n,...e):this._app.run(n,...e)}on(t,e,n){const s=t.toString();return this._actions.push({name:s,fn:e}),this.is_global_event(s)?r.on(s,e,n):this._app.on(s,e,n)}unmount(){var t;null===(t=this.observer)||void 0===t||t.disconnect(),this._actions.forEach((t=>{const{name:e,fn:n}=t;this.is_global_event(e)?r.off(e,n):this._app.off(e,n)}))}}g.__isAppRunComponent=!0;const y="//",_="///",b=t=>{if(t||(t="#"),t.startsWith("#")){const[e,...n]=t.split("/");r.run(e,...n)||r.run(_,e,...n),r.run(y,e,...n)}else if(t.startsWith("/")){const[e,n,...s]=t.split("/");r.run("/"+n,...s)||r.run(_,"/"+n,...s),r.run(y,"/"+n,...s)}else r.run(t)||r.run(_,t),r.run(y,t)};r.h=r.createElement=a.az,r.render=function(t,e,n){(0,a.yj)(t,e,n)},r.Fragment=a.HY,r.webComponent=h,r.start=(t,e,n,s,o)=>{const i=Object.assign(Object.assign({},o),{render:!0,global_event:!0}),r=new g(e,n,s);return o&&o.rendered&&(r.rendered=o.rendered),r.mount(t,i),r};const v=t=>{};r.on("$",v),r.on("debug",(t=>v)),r.on(y,v),r.on("#",v),r.route=b,r.on("route",(t=>r.route&&r.route(t))),"object"==typeof document&&document.addEventListener("DOMContentLoaded",(()=>{r.route===b&&(window.onpopstate=()=>b(location.hash),document.body.hasAttribute("apprun-no-init")||b(location.hash))}));const w=r;"object"==typeof window&&(window.Component=g,window.React=r,window.on=function(t,e={}){return function(n,s){const o=t?t.toString():s;l.defineMetadata(`apprun-update:${o}`,{name:o,key:s,options:e},n)}},window.customElement=u)},559:(t,e,n)=>{function s(t,...e){return o(e)}function o(t){const e=[],n=t=>{null!=t&&""!==t&&!1!==t&&e.push("function"==typeof t||"object"==typeof t?t:`${t}`)};return t&&t.forEach((t=>{Array.isArray(t)?t.forEach((t=>n(t))):n(t)})),e}function i(t,e,...n){const s=o(n);if("string"==typeof t)return{tag:t,props:e,children:s};if(Array.isArray(t))return t;if(void 0===t&&n)return s;if(Object.getPrototypeOf(t).__isAppRunComponent)return{tag:t,props:e,children:s};if("function"==typeof t)return t(e,s);throw new Error(`Unknown tag in vdom ${t}`)}n.d(e,{HY:()=>s,az:()=>i,yj:()=>a});const r=new WeakMap,a=function(t,e,n={}){if(null==e||!1===e)return;e=p(e,n);const s="SVG"===(null==t?void 0:t.nodeName);t&&(Array.isArray(e)?h(t,e,s):h(t,[e],s))};function c(t,e,n){3!==e._op&&(n=n||"svg"===e.tag,function(t,e){const n=t.nodeName,s=`${e.tag||""}`;return n.toUpperCase()===s.toUpperCase()}(t,e)?(!(2&e._op)&&h(t,e.children,n),!(1&e._op)&&d(t,e.props,n)):t.parentNode.replaceChild(u(e,n),t))}function h(t,e,n){var s;const o=(null===(s=t.childNodes)||void 0===s?void 0:s.length)||0,i=(null==e?void 0:e.length)||0,a=Math.min(o,i);for(let s=0;sa;)t.removeChild(t.lastChild),h--;if(i>a){const s=document.createDocumentFragment();for(let t=a;tn.appendChild(u(t,e)))),n}function d(t,e,n){const s=t._props||{};e=function(t,e){e.class=e.class||e.className,delete e.className;const n={};return t&&Object.keys(t).forEach((t=>n[t]=null)),e&&Object.keys(e).forEach((t=>n[t]=e[t])),n}(s,e||{}),t._props=e;for(const s in e){const o=e[s];if(s.startsWith("data-")){const e=s.substring(5).replace(/-(\w)/g,(t=>t[1].toUpperCase()));t.dataset[e]!==o&&(o||""===o?t.dataset[e]=o:delete t.dataset[e])}else if("style"===s)if(t.style.cssText&&(t.style.cssText=""),"string"==typeof o)t.style.cssText=o;else for(const e in o)t.style[e]!==o[e]&&(t.style[e]=o[e]);else if(s.startsWith("xlink")){const e=s.replace("xlink","").toLowerCase();null==o||!1===o?t.removeAttributeNS("http://www.w3.org/1999/xlink",e):t.setAttributeNS("http://www.w3.org/1999/xlink",e,o)}else s.startsWith("on")?o&&"function"!=typeof o?"string"==typeof o&&(o?t.setAttribute(s,o):t.removeAttribute(s)):t[s]=o:/^id$|^class$|^list$|^readonly$|^contenteditable$|^role|-/g.test(s)||n?t.getAttribute(s)!==o&&(o?t.setAttribute(s,o):t.removeAttribute(s)):t[s]!==o&&(t[s]=o);"key"===s&&o&&(r[o]=t)}e&&"function"==typeof e.ref&&window.requestAnimationFrame((()=>e.ref(t)))}function p(t,e,n=0){var s;if("string"==typeof t)return t;if(Array.isArray(t))return t.map((t=>p(t,e,n++)));let o=t;if(t&&"function"==typeof t.tag&&Object.getPrototypeOf(t.tag).__isAppRunComponent&&(o=function(t,e,n){const{tag:s,props:o,children:i}=t;let r=`_${n}`,a=o&&o.id;a?r=a:a=`_${n}${Date.now()}`;let c="section";o&&o.as&&(c=o.as,delete o.as),e.__componentCache||(e.__componentCache={});let h=e.__componentCache[r];if(!(h&&h instanceof s&&h.element)){const t=document.createElement(c);h=e.__componentCache[r]=new s(Object.assign(Object.assign({},o),{children:i})).start(t)}if(h.mounted){const t=h.mounted(o,i,h.state);void 0!==t&&h.setState(t)}return d(h.element,o,!1),h.element}(t,e,n)),o&&Array.isArray(o.children)){const t=null===(s=o.props)||void 0===s?void 0:s._component;if(t){let e=0;o.children=o.children.map((n=>p(n,t,e++)))}else o.children=o.children.map((t=>p(t,e,n++)))}return o}}},e={};function n(s){if(e[s])return e[s].exports;var o=e[s]={exports:{}};return t[s](o,o.exports,n),o.exports}return n.d=(t,e)=>{for(var s in e)n.o(e,s)&&!n.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n(643)})()})); +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.apprun=e():t.apprun=e()}(this,(function(){return(()=>{"use strict";var t={107:(t,e,n)=>{n.d(e,{Component:()=>g,customElement:()=>u,default:()=>w});class s{constructor(){this._events={}}on(t,e,n={}){this._events[t]=this._events[t]||[],this._events[t].push({fn:e,options:n})}off(t,e){const n=this._events[t]||[];this._events[t]=n.filter((t=>t.fn!==e))}find(t){return this._events[t]}run(t,...e){const n=this.getSubscribers(t,this._events);return console.assert(n&&n.length>0,"No subscriber for event: "+t),this._events[t]=n.filter((t=>!t.options.once)),n.forEach((n=>{const{fn:s,options:o}=n;return o.delay?this.delay(t,s,e,o):Object.keys(o).length>0?s.apply(this,[...e,o]):s.apply(this,e),!n.options.once})),n.length}once(t,e,n={}){this.on(t,e,Object.assign(Object.assign({},n),{once:!0}))}delay(t,e,n,s){s._t&&clearTimeout(s._t),s._t=setTimeout((()=>{clearTimeout(s._t),Object.keys(s).length>0?e.apply(this,[...n,s]):e.apply(this,n)}),s.delay)}query(t,...e){const n=this.getSubscribers(t,this._events);console.assert(n&&n.length>0,"No subscriber for event: "+t);const s=n.map((t=>{const{fn:n,options:s}=t;return Object.keys(s).length>0?n.apply(this,[...e,s]):n.apply(this,e)}));return Promise.all(s)}getSubscribers(t,e){const n=this._events[t]||[];return n.length,Object.keys(e).filter((e=>e.endsWith("*")&&t.startsWith(e.replace("*","")))).sort(((t,e)=>e.length-t.length)).forEach((s=>n.push(...e[s].map((e=>(e.options=Object.assign(Object.assign({},e.options),{event:t}),e)))))),n}}let o;const i="object"==typeof self&&self.self===self&&self||"object"==typeof n.g&&n.g.global===n.g&&n.g;i.app&&i._AppRunVersions?o=i.app:(o=new s,i.app=o,i._AppRunVersions="AppRun-2");const r=o;var a=n(559);const c=(t,e={})=>class extends HTMLElement{constructor(){super()}get component(){return this._component}get state(){return this._component.state}static get observedAttributes(){return(e.observedAttributes||[]).map((t=>t.toLowerCase()))}connectedCallback(){if(this.isConnected&&!this._component){const n=e||{};this._shadowRoot=n.shadow?this.attachShadow({mode:"open"}):this;const s=n.observedAttributes||[],o=s.reduce(((t,e)=>{const n=e.toLowerCase();return n!==e&&(t[n]=e),t}),{});this._attrMap=t=>o[t]||t;const i={};Array.from(this.attributes).forEach((t=>i[this._attrMap(t.name)]=t.value)),s.forEach((t=>{void 0!==this[t]&&(i[t]=this[t]),Object.defineProperty(this,t,{get:()=>i[t],set(e){this.attributeChangedCallback(t,i[t],e)},configurable:!0,enumerable:!0})}));const r=this.children?Array.from(this.children):[];if(r.forEach((t=>t.parentElement.removeChild(t))),this._component=new t(Object.assign(Object.assign({},i),{children:r})).mount(this._shadowRoot,n),this._component._props=i,this._component.dispatchEvent=this.dispatchEvent.bind(this),this._component.mounted){const t=this._component.mounted(i,r,this._component.state);void 0!==t&&(this._component.state=t)}this.on=this._component.on.bind(this._component),this.run=this._component.run.bind(this._component),!1!==n.render&&this._component.run(".")}}disconnectedCallback(){var t,e,n,s;null===(e=null===(t=this._component)||void 0===t?void 0:t.unload)||void 0===e||e.call(t),null===(s=null===(n=this._component)||void 0===n?void 0:n.unmount)||void 0===s||s.call(n),this._component=null}attributeChangedCallback(t,n,s){if(this._component){const o=this._attrMap(t);this._component._props[o]=s,this._component.run("attributeChanged",o,n,s),s!==n&&!1!==e.render&&window.requestAnimationFrame((()=>{this._component.run(".")}))}}},h=(t,e,n)=>{"undefined"!=typeof customElements&&customElements.define(t,c(e,n))},l={meta:new WeakMap,defineMetadata(t,e,n){this.meta.has(n)||this.meta.set(n,{}),this.meta.get(n)[t]=e},getMetadataKeys(t){return t=Object.getPrototypeOf(t),this.meta.get(t)?Object.keys(this.meta.get(t)):[]},getMetadata(t,e){return e=Object.getPrototypeOf(e),this.meta.get(e)?this.meta.get(e)[t]:null}};function u(t,e){return function(n){return h(t,n,e),n}}const d=(t,e)=>(e?t.state[e]:t.state)||"",p=(t,e,n)=>{if(e){const s=t.state||{};s[e]=n,t.setState(s)}else t.setState(n)},f=new Map;r.on("get-components",(t=>t.components=f));const m=t=>t;class g{constructor(t,e,n,o){this.state=t,this.view=e,this.update=n,this.options=o,this._app=new s,this._actions=[],this._global_events=[],this._history=[],this._history_idx=-1,this._history_prev=()=>{this._history_idx--,this._history_idx>=0?this.setState(this._history[this._history_idx],{render:!0,history:!1}):this._history_idx=0},this._history_next=()=>{this._history_idx++,this._history_idxthis.mount(t,Object.assign(Object.assign({},e),{render:!0}))}render(t,e){r.render(t,e,this)}_view(t){if(!this.view)return;const e=r.createElement;r.h=r.createElement=(t,n,...s)=>(n&&Object.keys(n).forEach((e=>{e.startsWith("$")&&(((t,e,n,s)=>{if(t.startsWith("$on")){const n=e[t];if(t=t.substring(1),"boolean"==typeof n)e[t]=e=>s.run(t,e);else if("string"==typeof n)e[t]=t=>s.run(n,t);else if("function"==typeof n)e[t]=t=>s.setState(n(s.state,t));else if(Array.isArray(n)){const[o,...i]=n;"string"==typeof o?e[t]=t=>s.run(o,...i,t):"function"==typeof o&&(e[t]=t=>s.setState(o(s.state,...i,t)))}}else if("$bind"===t){const o=e.type||"text",i="string"==typeof e[t]?e[t]:e.name;if("input"===n)switch(o){case"checkbox":e.checked=d(s,i),e.onclick=t=>p(s,i||t.target.name,t.target.checked);break;case"radio":e.checked=d(s,i)===e.value,e.onclick=t=>p(s,i||t.target.name,t.target.value);break;case"number":case"range":e.value=d(s,i),e.oninput=t=>p(s,i||t.target.name,Number(t.target.value));break;default:e.value=d(s,i),e.oninput=t=>p(s,i||t.target.name,t.target.value)}else"select"===n?(e.value=d(s,i),e.onchange=t=>{t.target.multiple||p(s,i||t.target.name,t.target.value)}):"option"===n?(e.selected=d(s,i),e.onclick=t=>p(s,i||t.target.name,t.target.selected)):"textarea"===n&&(e.innerHTML=d(s,i),e.oninput=t=>p(s,i||t.target.name,t.target.value))}else r.run("$",{key:t,tag:n,props:e,component:s})})(e,n,t,this),delete n[e])})),e(t,n,...s));const n=this.view(t);return r.h=r.createElement=e,n}renderState(t,e=null){if(!this.view)return;let n=e||this._view(t);if(r.debug&&r.run("debug",{component:this,_:n?".":"-",state:t,vdom:n,el:this.element}),"object"!=typeof document)return;const s="string"==typeof this.element?document.getElementById(this.element):this.element;if(s){const t="_c";this.unload?s._component===this&&s.getAttribute(t)===this.tracking_id||(this.tracking_id=(new Date).valueOf().toString(),s.setAttribute(t,this.tracking_id),"undefined"!=typeof MutationObserver&&(this.observer||(this.observer=new MutationObserver((t=>{t[0].oldValue!==this.tracking_id&&document.body.contains(s)||(this.unload(this.state),this.observer.disconnect(),this.observer=null)}))),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:[t]}))):s.removeAttribute&&s.removeAttribute(t),s._component=this}e||this.render(s,n),this.rendered&&this.rendered(this.state)}setState(t,e={render:!0,history:!1}){if(t instanceof Promise)Promise.all([t,this._state]).then((t=>{t[0]&&this.setState(t[0])})).catch((t=>{throw console.error(t),t})),this._state=t;else{if(this._state=t,null==t)return;this.state=t,!1!==e.render&&this.renderState(t),!1!==e.history&&this.enable_history&&(this._history=[...this._history,t],this._history_idx=this._history.length-1),"function"==typeof e.callback&&e.callback(this.state)}}mount(t=null,e){var n,s;return console.assert(!this.element,"Component already mounted."),this.options=e=Object.assign(Object.assign({},this.options),e),this.element=t,this.global_event=e.global_event,this.enable_history=!!e.history,this.enable_history&&(this.on(e.history.prev||"history-prev",this._history_prev),this.on(e.history.next||"history-next",this._history_next)),e.route&&(this.update=this.update||{},this.update[e.route]=m),this.add_actions(),this.state=null!==(s=null!==(n=this.state)&&void 0!==n?n:this.model)&&void 0!==s?s:{},"function"==typeof this.state&&(this.state=this.state()),e.render?this.setState(this.state,{render:!0,history:!0}):this.setState(this.state,{render:!1,history:!0}),r.debug&&(f.get(t)?f.get(t).push(this):f.set(t,[this])),this}is_global_event(t){return t&&(this.global_event||this._global_events.indexOf(t)>=0||t.startsWith("#")||t.startsWith("/")||t.startsWith("@"))}add_action(t,e,n={}){e&&"function"==typeof e&&(n.global&&this._global_events.push(t),this.on(t,((...s)=>{r.debug&&r.run("debug",{component:this,_:">",event:t,p:s,current_state:this.state,options:n});const o=e(this.state,...s);r.debug&&r.run("debug",{component:this,_:"<",event:t,p:s,newState:o,state:this.state,options:n}),this.setState(o,n)}),n))}add_actions(){const t=this.update||{};l.getMetadataKeys(this).forEach((e=>{if(e.startsWith("apprun-update:")){const n=l.getMetadata(e,this);t[n.name]=[this[n.key].bind(this),n.options]}}));const e={};Array.isArray(t)?t.forEach((t=>{const[n,s,o]=t;n.toString().split(",").forEach((t=>e[t.trim()]=[s,o]))})):Object.keys(t).forEach((n=>{const s=t[n];("function"==typeof s||Array.isArray(s))&&n.split(",").forEach((t=>e[t.trim()]=s))})),e["."]||(e["."]=m),Object.keys(e).forEach((t=>{const n=e[t];"function"==typeof n?this.add_action(t,n):Array.isArray(n)&&this.add_action(t,n[0],n[1])}))}run(t,...e){const n=t.toString();return this.is_global_event(n)?r.run(n,...e):this._app.run(n,...e)}on(t,e,n){const s=t.toString();return this._actions.push({name:s,fn:e}),this.is_global_event(s)?r.on(s,e,n):this._app.on(s,e,n)}unmount(){var t;null===(t=this.observer)||void 0===t||t.disconnect(),this._actions.forEach((t=>{const{name:e,fn:n}=t;this.is_global_event(e)?r.off(e,n):this._app.off(e,n)}))}}g.__isAppRunComponent=!0;const y="//",b="///",_=t=>{if(t||(t="#"),t.startsWith("#")){const[e,...n]=t.split("/");r.run(e,...n)||r.run(b,e,...n),r.run(y,e,...n)}else if(t.startsWith("/")){const[e,n,...s]=t.split("/");r.run("/"+n,...s)||r.run(b,"/"+n,...s),r.run(y,"/"+n,...s)}else r.run(t)||r.run(b,t),r.run(y,t)};r.h=r.createElement=a.az,r.render=function(t,e,n){(0,a.yj)(t,e,n)},r.Fragment=a.HY,r.webComponent=h,r.start=(t,e,n,s,o)=>{const i=Object.assign(Object.assign({},o),{render:!0,global_event:!0}),r=new g(e,n,s);return o&&o.rendered&&(r.rendered=o.rendered),r.mount(t,i),r};const v=t=>{};r.on("$",v),r.on("debug",(t=>v)),r.on(y,v),r.on("#",v),r.route=_,r.on("route",(t=>r.route&&r.route(t))),"object"==typeof document&&document.addEventListener("DOMContentLoaded",(()=>{r.route===_&&(window.onpopstate=()=>_(location.hash),document.body.hasAttribute("apprun-no-init")||_(location.hash))}));const w=r;"object"==typeof window&&(window.Component=g,window.React=r,window.on=function(t,e={}){return function(n,s){const o=t?t.toString():s;l.defineMetadata(`apprun-update:${o}`,{name:o,key:s,options:e},n)}},window.customElement=u)},559:(t,e,n)=>{function s(t,...e){return o(e)}function o(t){const e=[],n=t=>{null!=t&&""!==t&&!1!==t&&e.push("function"==typeof t||"object"==typeof t?t:`${t}`)};return t&&t.forEach((t=>{Array.isArray(t)?t.forEach((t=>n(t))):n(t)})),e}function i(t,e,...n){const s=o(n);if("string"==typeof t)return{tag:t,props:e,children:s};if(Array.isArray(t))return t;if(void 0===t&&n)return s;if(Object.getPrototypeOf(t).__isAppRunComponent)return{tag:t,props:e,children:s};if("function"==typeof t)return t(e,s);throw new Error(`Unknown tag in vdom ${t}`)}n.d(e,{HY:()=>s,az:()=>i,yj:()=>a});const r=new WeakMap,a=function(t,e,n={}){if(null==e||!1===e)return;e=p(e,n);const s="SVG"===(null==t?void 0:t.nodeName);t&&(Array.isArray(e)?h(t,e,s):h(t,[e],s))};function c(t,e,n){3!==e._op&&(n=n||"svg"===e.tag,function(t,e){const n=t.nodeName,s=`${e.tag||""}`;return n.toUpperCase()===s.toUpperCase()}(t,e)?(!(2&e._op)&&h(t,e.children,n),!(1&e._op)&&d(t,e.props,n)):t.parentNode.replaceChild(u(e,n),t))}function h(t,e,n){var s;const o=(null===(s=t.childNodes)||void 0===s?void 0:s.length)||0,i=(null==e?void 0:e.length)||0,a=Math.min(o,i);for(let s=0;sa;)t.removeChild(t.lastChild),h--;if(i>a){const s=document.createDocumentFragment();for(let t=a;tn.appendChild(u(t,e)))),n}function d(t,e,n){const s=t._props||{};e=function(t,e){e.class=e.class||e.className,delete e.className;const n={};return t&&Object.keys(t).forEach((t=>n[t]=null)),e&&Object.keys(e).forEach((t=>n[t]=e[t])),n}(s,e||{}),t._props=e;for(const s in e){const o=e[s];if(s.startsWith("data-")){const e=s.substring(5).replace(/-(\w)/g,(t=>t[1].toUpperCase()));t.dataset[e]!==o&&(o||""===o?t.dataset[e]=o:delete t.dataset[e])}else if("style"===s)if(t.style.cssText&&(t.style.cssText=""),"string"==typeof o)t.style.cssText=o;else for(const e in o)t.style[e]!==o[e]&&(t.style[e]=o[e]);else if(s.startsWith("xlink")){const e=s.replace("xlink","").toLowerCase();null==o||!1===o?t.removeAttributeNS("http://www.w3.org/1999/xlink",e):t.setAttributeNS("http://www.w3.org/1999/xlink",e,o)}else s.startsWith("on")?o&&"function"!=typeof o?"string"==typeof o&&(o?t.setAttribute(s,o):t.removeAttribute(s)):t[s]=o:/^id$|^class$|^list$|^readonly$|^contenteditable$|^role|-/g.test(s)||n?t.getAttribute(s)!==o&&(o?t.setAttribute(s,o):t.removeAttribute(s)):t[s]!==o&&(t[s]=o);"key"===s&&o&&(r[o]=t)}e&&"function"==typeof e.ref&&window.requestAnimationFrame((()=>e.ref(t)))}function p(t,e,n=0){var s;if("string"==typeof t)return t;if(Array.isArray(t))return t.map((t=>p(t,e,n++)));let o=t;if(t&&"function"==typeof t.tag&&Object.getPrototypeOf(t.tag).__isAppRunComponent&&(o=function(t,e,n){const{tag:s,props:o,children:i}=t;let r=`_${n}`,a=o&&o.id;a?r=a:a=`_${n}${Date.now()}`;let c="section";o&&o.as&&(c=o.as,delete o.as),e.__componentCache||(e.__componentCache={});let h=e.__componentCache[r];if(!(h&&h instanceof s&&h.element)){const t=document.createElement(c);h=e.__componentCache[r]=new s(Object.assign(Object.assign({},o),{children:i})).start(t)}if(h.mounted){const t=h.mounted(o,i,h.state);void 0!==t&&h.setState(t)}return d(h.element,o,!1),h.element}(t,e,n)),o&&Array.isArray(o.children)){const t=null===(s=o.props)||void 0===s?void 0:s._component;if(t){let e=0;o.children=o.children.map((n=>p(n,t,e++)))}else o.children=o.children.map((t=>p(t,e,n++)))}return o}}},e={};function n(s){var o=e[s];if(void 0!==o)return o.exports;var i=e[s]={exports:{}};return t[s](i,i.exports,n),i.exports}n.d=(t,e)=>{for(var s in e)n.o(e,s)&&!n.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:e[s]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};return(()=>{n.r(s);var t=n(107);let e=class extends t.Component{constructor(){super(...arguments),this.view=({num:e,children:n})=>t.default.h("div",null,t.default.h("h1",null,e),n),this.update={"-1":t=>Object.assign(Object.assign({},t),{num:t.num-1}),"+1":t=>Object.assign(Object.assign({},t),{num:t.num+1})},this.mounted=({num:t},e)=>({num:parseInt(t),children:e}),this.rendered=({num:t})=>{this.element.setAttribute("num",t)}}};e=function(t,e,n,s){var o,i=arguments.length,r=i<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(i<3?o(r):i>3?o(e,n,r):o(e,n))||r);return i>3&&r&&Object.defineProperty(e,n,r),r}([(0,t.customElement)("my-counter")],e);let o=class extends t.Component{constructor(){super(...arguments),this.state={},this.view=e=>t.default.h(t.default.Fragment,null,t.default.h("div",null,t.default.h("button",{$onclick:"fetchComic"},"XKCD")),e.loading?t.default.h("div",null,"loading ... "):"",e.comic&&t.default.h(t.default.Fragment,null,t.default.h("h3",null,e.comic.title),t.default.h("img",{src:e.comic.url}))),this.update={loading:(t,e)=>({loading:!0}),fetchComic:async t=>{this.run("loading",!0);const e=await fetch("https://xkcd-imgs.herokuapp.com/");return{comic:await e.json(),loading:!1}}},this.mounted=()=>this.run("fetchComic")}};o=function(t,e,n,s){var o,i=arguments.length,r=i<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,n):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,n,s);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(r=(i<3?o(r):i>3?o(e,n,r):o(e,n))||r);return i>3&&r&&Object.defineProperty(e,n,r),r}([(0,t.customElement)("my-xkcd",{shadow:!0,render:!1})],o)})(),s})()})); //# sourceMappingURL=app.js.map \ No newline at end of file diff --git a/demo-html/app.js.map b/demo-html/app.js.map index 1372c65..80fcf59 100644 --- a/demo-html/app.js.map +++ b/demo-html/app.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack://apprun/webpack/universalModuleDefinition","webpack://apprun/./demo-html/components/counter.tsx","webpack://apprun/./demo-html/components/xkcd.tsx","webpack://apprun/./src/app.ts","webpack://apprun/./src/web-component.ts","webpack://apprun/./src/decorator.ts","webpack://apprun/./src/directive.ts","webpack://apprun/./src/component.ts","webpack://apprun/./src/router.ts","webpack://apprun/./src/apprun.ts","webpack://apprun/./src/vdom.ts","webpack://apprun/./src/vdom-my.ts","webpack://apprun/webpack/bootstrap","webpack://apprun/webpack/startup","webpack://apprun/webpack/runtime/define property getters","webpack://apprun/webpack/runtime/global","webpack://apprun/webpack/runtime/hasOwnProperty shorthand","webpack://apprun/webpack/runtime/make namespace object"],"names":["root","factory","exports","module","define","amd","this","MyApp","Component","view","num","children","update","state","mounted","parseInt","rendered","element","setAttribute","customElement","loading","comic","title","src","url","_","run","response","fetch","json","shadow","render","App","_events","name","fn","options","push","subscribers","filter","sub","args","console","assert","length","once","forEach","delay","apply","on","_t","clearTimeout","setTimeout","app","self","g","global","componentClass","HTMLElement","super","_component","observedAttributes","map","attr","toLowerCase","isConnected","opts","_shadowRoot","attachShadow","mode","attrMap","reduce","lc","_attrMap","props","Array","from","attributes","item","value","undefined","Object","defineProperty","get","attributeChangedCallback","configurable","enumerable","el","parentElement","removeChild","mount","_props","dispatchEvent","bind","new_state","unload","unmount","oldValue","mappedName","window","requestAnimationFrame","customElements","Reflect","meta","WeakMap","metadataKey","metadataValue","target","has","set","getPrototypeOf","keys","constructor","getStateValue","component","setStateValue","setState","componentCache","Map","o","components","REFRESH","_app","_actions","_global_events","_history","_history_idx","_history_prev","history","_history_next","start","node","h","tag","key","startsWith","event","substring","e","isArray","handler","p","type","checked","Number","multiple","selected","directive","html","vdom","_view","document","getElementById","tracking_attr","getAttribute","tracking_id","Date","valueOf","toString","MutationObserver","observer","changes","body","contains","disconnect","observe","childList","subtree","attributeOldValue","attributeFilter","removeAttribute","Promise","all","_state","then","v","catch","err","error","renderState","enable_history","callback","global_event","prev","next","route","add_actions","indexOf","action","current_state","newState","actions","getMetadataKeys","getMetadata","act","split","n","trim","add_action","is_global_event","off","__isAppRunComponent","ROUTER_EVENT","ROUTER_404_EVENT","rest","parent","model","NOOP","addEventListener","onpopstate","location","hash","hasAttribute","events","defineMetadata","Fragment","collect","ch","c","i","createElement","Error","keyCache","updateElement","nodes","createComponent","isSvg","nodeName","updateChildren","key1","key2","toUpperCase","same","updateProps","parentNode","replaceChild","create","old_len","childNodes","new_len","len","Math","min","child","textContent","nodeType","nodeValue","createText","SVGElement","insertBefore","old","temp","nextSibling","appendChild","lastChild","d","createDocumentFragment","div","insertAdjacentHTML","createTextNode","JSON","stringify","createElementNS","cached","oldProps","newProps","mergeProps","cname","replace","match","dataset","style","cssText","s","xname","removeAttributeNS","setAttributeNS","test","idx","id","now","asTag","__componentCache","render_component","new_parent","__webpack_module_cache__","__webpack_require__","moduleId","__webpack_modules__","definition","globalThis","Function","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag"],"mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAgB,OAAID,IAEpBD,EAAa,OAAIC,IARnB,CASGK,MAAM,WACT,M,4DCPA,IAAMC,EAAN,cAAoB,EAAAC,UAApB,c,oBAEE,KAAAC,KAAO,EAAGC,MAAKC,cAAe,uBAC5B,sBAAKD,GACJC,GAGH,KAAAC,OAAS,CACP,KAAMC,GAAU,OAAD,wBAAKA,GAAK,CAAEH,IAAKG,EAAMH,IAAM,IAC5C,KAAMG,GAAU,OAAD,wBAAKA,GAAK,CAAEH,IAAKG,EAAMH,IAAM,KAG9C,KAAAI,QAAU,EAAGJ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QyE,OAG9E,OAAOjI,KCpQLwI,EAA2B,GAG/B,SAASC,EAAoBC,GAE5B,GAAGF,EAAyBE,GAC3B,OAAOF,EAAyBE,GAAU7R,QAG3C,IAAIC,EAAS0R,EAAyBE,GAAY,CAGjD7R,QAAS,IAOV,OAHA8R,EAAoBD,GAAU5R,EAAQA,EAAOD,QAAS4R,GAG/C3R,EAAOD,QCjBf,OCFA4R,EAAoB/B,EAAI,CAAC7P,EAAS+R,KACjC,IAAI,IAAI3J,KAAO2J,EACXH,EAAoBvK,EAAE0K,EAAY3J,KAASwJ,EAAoBvK,EAAErH,EAASoI,IAC5ErD,OAAOC,eAAehF,EAASoI,EAAK,CAAEhD,YAAY,EAAMH,IAAK8M,EAAW3J,MCJ3EwJ,EAAoBvO,EAAI,WACvB,GAA0B,iBAAf2O,WAAyB,OAAOA,WAC3C,IACC,OAAO5R,MAAQ,IAAI6R,SAAS,cAAb,GACd,MAAOzJ,GACR,GAAsB,iBAAXvC,OAAqB,OAAOA,QALjB,GCAxB2L,EAAoBvK,EAAI,CAAC6K,EAAKC,IAASpN,OAAOqN,UAAUC,eAAeC,KAAKJ,EAAKC,GCCjFP,EAAoBW,EAAKvS,IACH,oBAAXwS,QAA0BA,OAAOC,aAC1C1N,OAAOC,eAAehF,EAASwS,OAAOC,YAAa,CAAE5N,MAAO,WAE7DE,OAAOC,eAAehF,EAAS,aAAc,CAAE6E,OAAO,KJFhD+M,EAAoB,M","file":"demo-html/app.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"apprun\"] = factory();\n\telse\n\t\troot[\"apprun\"] = factory();\n})(this, function() {\nreturn ","import app, { Component, customElement } from '../../src/apprun';\n\n@customElement(\"my-counter\")\nclass MyApp extends Component {\n\n view = ({ num, children }) =>
\n

{num}

\n {children}\n
\n\n update = {\n '-1': state => ({...state, num: state.num - 1}),\n '+1': state => ({...state, num: state.num + 1})\n }\n\n mounted = ({ num }, children) => ({ num: parseInt(num), children });\n\n rendered = ({ num }) => {\n this.element.setAttribute('num', num);\n }\n}\n","import app, { Component, customElement } from '../../src/apprun';\n\n// example of async fetch using mounted\n\n@customElement('my-xkcd', {shadow: true, render: false})\nexport default class extends Component {\n state = {};\n\n view = (state) => <>\n
\n {state.loading ?
loading ...
: ''}\n {state.comic && <>\n

{state.comic.title}

\n \n }\n ;\n\n update = {\n 'loading': (_, loading) => ({ loading: true }),\n 'fetchComic': async _ => {\n this.run('loading', true);\n const response = await fetch('https://xkcd-imgs.herokuapp.com/');\n const comic = await response.json();\n return { comic, loading: false };\n }\n };\n\n mounted = () => this.run('fetchComic');\n}","import { EventOptions} from './types'\nexport class App {\n\n private _events: Object;\n\n public start;\n public h;\n public createElement;\n public render;\n public Fragment;\n public webComponent;\n\n constructor() {\n this._events = {};\n }\n\n on(name: string, fn: (...args) => void, options: EventOptions = {}): void {\n this._events[name] = this._events[name] || [];\n this._events[name].push({ fn, options });\n }\n\n off(name: string, fn: (...args) => void): void {\n const subscribers = this._events[name] || [];\n\n this._events[name] = subscribers.filter((sub) => sub.fn !== fn);\n }\n\n find(name: string): any {\n return this._events[name];\n }\n\n run(name: string, ...args): number {\n const subscribers = this._events[name] || [];\n\n console.assert(subscribers && subscribers.length > 0, 'No subscriber for event: ' + name);\n\n // Update the list of subscribers by pulling out those which will run once.\n // We must do this update prior to running any of the events in case they\n // cause additional events to be turned off or on.\n this._events[name] = subscribers.filter((sub) => {\n return !sub.options.once;\n });\n\n subscribers.forEach((sub) => {\n const { fn, options } = sub;\n if (options.delay) {\n this.delay(name, fn, args, options);\n } else {\n fn.apply(this, args);\n }\n return !sub.options.once;\n });\n\n return subscribers.length;\n }\n\n once(name: string, fn, options: EventOptions = {}): void {\n this.on(name, fn, { ...options, once: true });\n }\n\n private delay(name, fn, args, options): void {\n if (options._t) clearTimeout(options._t);\n options._t = setTimeout(() => {\n clearTimeout(options._t);\n fn.apply(this, args);\n }, options.delay);\n }\n}\n\nconst AppRunVersions = 'AppRun-2';\nlet app: App;\nconst root = (typeof self === 'object' && self.self === self && self) ||\n (typeof global === 'object' && global.global === global && global)\nif (root['app'] && root['_AppRunVersions']) {\n app = root['app'];\n} else {\n app = new App();\n root['app'] = app;\n root['_AppRunVersions'] = AppRunVersions;\n}\nexport default app;\n","declare var customElements;\n\nexport type CustomElementOptions = {\n render?: boolean;\n shadow?: boolean;\n history?: boolean;\n global_event?: boolean;\n observedAttributes?: string[];\n};\n\nexport const customElement = (componentClass, options: CustomElementOptions = {}) => class CustomElement extends HTMLElement {\n private _shadowRoot;\n private _component;\n private _attrMap: (arg0: string) => string;\n public on;\n public run;\n constructor() {\n super();\n }\n get component() { return this._component; }\n get state() { return this._component.state; }\n\n static get observedAttributes() {\n // attributes need to be set to lowercase in order to get observed\n return (options.observedAttributes || []).map(attr => attr.toLowerCase());\n }\n\n connectedCallback() {\n if (this.isConnected && !this._component) {\n const opts = options || {};\n this._shadowRoot = opts.shadow ? this.attachShadow({ mode: 'open' }) : this;\n const observedAttributes = (opts.observedAttributes || [])\n\n const attrMap = observedAttributes.reduce((map, name) => {\n const lc = name.toLowerCase()\n if (lc !== name) {\n map[lc] = name\n }\n return map\n }, {})\n this._attrMap = (name: string) : string => attrMap[name] || name\n\n const props = {};\n Array.from(this.attributes).forEach(item => props[this._attrMap(item.name)] = item.value);\n\n // add getters/ setters to allow observation on observedAttributes\n observedAttributes.forEach(name => {\n if (this[name] !== undefined) props[name] = this[name];\n Object.defineProperty(this, name, {\n get(): any {\n return props[name];\n },\n set(this: CustomElement, value: unknown) {\n // trigger change event\n this.attributeChangedCallback(name, props[name], value)\n },\n configurable: true,\n enumerable: true\n });\n })\n\n const children = this.children ? Array.from(this.children) : [];\n children.forEach(el => el.parentElement.removeChild(el));\n this._component = new componentClass({ ...props, children }).mount(this._shadowRoot, opts);\n // attach props to component\n this._component._props = props;\n // expose dispatchEvent\n this._component.dispatchEvent = this.dispatchEvent.bind(this)\n if (this._component.mounted) {\n const new_state = this._component.mounted(props, children, this._component.state);\n if (typeof new_state !== 'undefined') this._component.state = new_state;\n }\n this.on = this._component.on.bind(this._component);\n this.run = this._component.run.bind(this._component);\n if (!(opts.render===false)) this._component.run('.');\n }\n }\n\n disconnectedCallback() {\n this._component?.unload?.();\n this._component?.unmount?.();\n this._component = null;\n }\n\n attributeChangedCallback(name: string, oldValue: unknown, value: unknown) {\n if (this._component) {\n // camelCase attributes arrive only in lowercase\n const mappedName = this._attrMap(name);\n // store the new property/ attribute\n this._component._props[mappedName] = value;\n this._component.run('attributeChanged', mappedName, oldValue, value);\n\n if (value !== oldValue && !(options.render === false)) {\n window.requestAnimationFrame(() => {\n // re-render state with new combined props on next animation frame\n this._component.run('.')\n })\n }\n }\n }\n}\n\nexport default (name: string, componentClass, options?: CustomElementOptions) => {\n (typeof customElements !== 'undefined') && customElements.define(name, customElement(componentClass, options))\n}\n","import webComponent, { CustomElementOptions } from './web-component';\n\n// tslint:disable:no-invalid-this\nexport const Reflect = {\n\n meta: new WeakMap(),\n\n defineMetadata(metadataKey, metadataValue, target) {\n if (!this.meta.has(target)) this.meta.set(target, {});\n this.meta.get(target)[metadataKey] = metadataValue;\n },\n\n getMetadataKeys(target) {\n target = Object.getPrototypeOf(target);\n return this.meta.get(target) ? Object.keys(this.meta.get(target)) : [];\n },\n\n getMetadata(metadataKey, target) {\n target = Object.getPrototypeOf(target);\n return this.meta.get(target) ? this.meta.get(target)[metadataKey] : null;\n }\n}\n\nexport function update(events?: E, options: any = {}) {\n return (target: any, key: string, descriptor: any) => {\n const name = events ? events.toString() : key;\n Reflect.defineMetadata(`apprun-update:${name}`,\n { name, key, options }, target);\n return descriptor;\n }\n}\n\nexport function on(events?: E, options: any = {}) {\n return function (target: any, key: string) {\n const name = events ? events.toString() : key;\n Reflect.defineMetadata(`apprun-update:${name}`,\n { name, key, options }, target)\n }\n}\n\nexport function customElement(name: string, options?: CustomElementOptions) {\n return function _customElement(constructor: T) {\n webComponent(name, constructor, options);\n return constructor;\n }\n}\n\n","import app from './app';\n\nconst getStateValue = (component, name) => {\n return (name ? component['state'][name] : component['state']) || '';\n}\n\nconst setStateValue = (component, name, value) => {\n if (name) {\n const state = component['state'] || {};\n state[name] = value;\n component.setState(state);\n } else {\n component.setState(value);\n }\n}\n\nexport default (key: string, props: {}, tag, component) => {\n if (key.startsWith('$on')) {\n const event = props[key];\n key = key.substring(1)\n if (typeof event === 'boolean') {\n props[key] = e => component.run(key, e);\n } else if (typeof event === 'string') {\n props[key] = e => component.run(event, e);\n } else if (typeof event === 'function') {\n props[key] = e => component.setState(event(component.state, e));\n } else if (Array.isArray(event)) {\n const [handler, ...p] = event;\n if (typeof handler === 'string') {\n props[key] = e => component.run(handler, ...p, e);\n } else if (typeof handler === 'function') {\n props[key] = e => component.setState(handler(component.state, ...p, e));\n }\n }\n\n } else if (key === '$bind') {\n const type = props['type'] || 'text';\n const name = typeof props[key] === 'string' ? props[key] : props['name'];\n if (tag === 'input') {\n switch (type) {\n case 'checkbox':\n props['checked'] = getStateValue(component, name);\n props['onclick'] = e => setStateValue(component, name || e.target.name, e.target.checked);\n break;\n case 'radio':\n props['checked'] = getStateValue(component, name) === props['value'];\n props['onclick'] = e => setStateValue(component, name || e.target.name, e.target.value);\n break;\n case 'number':\n case 'range':\n props['value'] = getStateValue(component, name);\n props['oninput'] = e => setStateValue(component, name || e.target.name, Number(e.target.value));\n break;\n default:\n props['value'] = getStateValue(component, name);\n props['oninput'] = e => setStateValue(component, name || e.target.name, e.target.value);\n }\n } else if (tag === 'select') {\n props['value'] = getStateValue(component, name);\n props['onchange'] = e => {\n if (!e.target.multiple) { // multiple selection use $bind on option\n setStateValue(component, name || e.target.name, e.target.value);\n }\n }\n } else if (tag === 'option') {\n props['selected'] = getStateValue(component, name);\n props['onclick'] = e => setStateValue(component, name || e.target.name, e.target.selected);\n } else if (tag === 'textarea') {\n props['innerHTML'] = getStateValue(component, name);\n props['oninput'] = e => setStateValue(component, name || e.target.name, e.target.value);\n }\n } else {\n app.run('$', { key, tag, props, component });\n }\n}","\r\nimport app, { App } from './app';\r\nimport { Reflect } from './decorator'\r\nimport { View, Update, ActionDef, ActionOptions, MountOptions } from './types';\r\nimport directive from './directive';\r\n\r\nconst componentCache = new Map();\r\napp.on('get-components', o => o.components = componentCache);\r\n\r\nconst REFRESH = state => state;\r\n\r\nexport class Component {\r\n static __isAppRunComponent = true;\r\n private _app = new App();\r\n private _actions = [];\r\n private _global_events = [];\r\n private _state;\r\n private _history = [];\r\n private _history_idx = -1;\r\n private enable_history;\r\n private global_event;\r\n public element;\r\n public rendered;\r\n public mounted;\r\n public unload;\r\n private tracking_id;\r\n private observer;\r\n\r\n render(element: HTMLElement, node) {\r\n app.render(element, node, this);\r\n }\r\n\r\n private _view(state) {\r\n if (!this.view) return;\r\n const h = app.createElement;\r\n app.h = app.createElement = (tag, props, ...children) => {\r\n props && Object.keys(props).forEach(key => {\r\n if (key.startsWith('$')) {\r\n directive(key, props, tag, this);\r\n delete props[key];\r\n }\r\n });\r\n return h(tag, props, ...children);\r\n }\r\n const html = this.view(state);\r\n app.h = app.createElement = h;\r\n return html;\r\n }\r\n\r\n private renderState(state: T, vdom = null) {\r\n if (!this.view) return;\r\n let html = vdom || this._view(state);\r\n\r\n app['debug'] && app.run('debug', {\r\n component: this,\r\n _: html ? '.' : '-',\r\n state,\r\n vdom: html,\r\n el: this.element\r\n });\r\n\r\n if (typeof document !== 'object') return;\r\n\r\n const el = (typeof this.element === 'string') ?\r\n document.getElementById(this.element) : this.element;\r\n\r\n if (el) {\r\n const tracking_attr = '_c';\r\n if (!this.unload) {\r\n el.removeAttribute && el.removeAttribute(tracking_attr);\r\n } else if (el['_component'] !== this || el.getAttribute(tracking_attr) !== this.tracking_id) {\r\n this.tracking_id = new Date().valueOf().toString();\r\n el.setAttribute(tracking_attr, this.tracking_id);\r\n if (typeof MutationObserver !== 'undefined') {\r\n if (!this.observer) this.observer = new MutationObserver(changes => {\r\n if (changes[0].oldValue === this.tracking_id || !document.body.contains(el)) {\r\n this.unload(this.state);\r\n this.observer.disconnect();\r\n this.observer = null;\r\n }\r\n });\r\n this.observer.observe(document.body, {\r\n childList: true, subtree: true,\r\n attributes: true, attributeOldValue: true, attributeFilter: [tracking_attr]\r\n });\r\n }\r\n }\r\n el['_component'] = this;\r\n }\r\n if (!vdom) {\r\n this.render(el, html);\r\n }\r\n this.rendered && this.rendered(this.state);\r\n }\r\n\r\n public setState(state: T, options: ActionOptions\r\n = { render: true, history: false }) {\r\n if (state instanceof Promise) {\r\n // Promise will not be saved or rendered\r\n // state will be saved and rendered when promise is resolved\r\n // Wait for previous promise to complete first\r\n Promise.all([state, this._state]).then(v => {\r\n if (v[0]) this.setState(v[0]);\r\n }).catch(err => {\r\n console.error(err);\r\n throw err;\r\n });\r\n this._state = state;\r\n } else {\r\n this._state = state;\r\n if (state == null) return;\r\n this.state = state;\r\n if (options.render !== false) this.renderState(state);\r\n if (options.history !== false && this.enable_history) {\r\n this._history = [...this._history, state];\r\n this._history_idx = this._history.length - 1;\r\n }\r\n if (typeof options.callback === 'function') options.callback(this.state);\r\n }\r\n }\r\n\r\n private _history_prev = () => {\r\n this._history_idx--;\r\n if (this._history_idx >= 0) {\r\n this.setState(this._history[this._history_idx], { render: true, history: false });\r\n }\r\n else {\r\n this._history_idx = 0;\r\n }\r\n };\r\n\r\n private _history_next = () => {\r\n this._history_idx++;\r\n if (this._history_idx < this._history.length) {\r\n this.setState(this._history[this._history_idx], { render: true, history: false });\r\n }\r\n else {\r\n this._history_idx = this._history.length - 1;\r\n }\r\n };\r\n\r\n constructor(\r\n protected state?: T,\r\n protected view?: View,\r\n protected update?: Update,\r\n protected options?) {\r\n }\r\n\r\n start = (element = null, options?: MountOptions): Component => {\r\n return this.mount(element, { ...options, render: true });\r\n }\r\n\r\n public mount(element = null, options?: MountOptions): Component {\r\n console.assert(!this.element, 'Component already mounted.')\r\n this.options = options = { ...this.options, ...options };\r\n this.element = element;\r\n this.global_event = options.global_event;\r\n this.enable_history = !!options.history;\r\n\r\n if (this.enable_history) {\r\n this.on(options.history.prev || 'history-prev', this._history_prev);\r\n this.on(options.history.next || 'history-next', this._history_next);\r\n }\r\n\r\n if (options.route) {\r\n this.update = this.update || {};\r\n this.update[options.route] = REFRESH;\r\n }\r\n\r\n this.add_actions();\r\n this.state = this.state ?? this['model'] ?? {};\r\n if (typeof this.state === 'function') this.state = this.state();\r\n if (options.render) {\r\n this.setState(this.state, { render: true, history: true });\r\n } else {\r\n this.setState(this.state, { render: false, history: true });\r\n }\r\n if (app['debug']) {\r\n if (componentCache.get(element)) { componentCache.get(element).push(this) }\r\n else { componentCache.set(element, [this])}\r\n }\r\n return this;\r\n }\r\n\r\n is_global_event(name: string): boolean {\r\n return name && (\r\n this.global_event ||\r\n this._global_events.indexOf(name) >= 0 ||\r\n name.startsWith('#') || name.startsWith('/') || name.startsWith('@'));\r\n }\r\n\r\n add_action(name: string, action, options: ActionOptions = {}) {\r\n if (!action || typeof action !== 'function') return;\r\n if (options.global) this._global_events.push(name);\r\n this.on(name as any, (...p) => {\r\n\r\n app['debug'] && app.run('debug', {\r\n component: this,\r\n _: '>',\r\n event: name, p,\r\n current_state: this.state,\r\n options\r\n });\r\n\r\n const newState = action(this.state, ...p);\r\n\r\n app['debug'] && app.run('debug', {\r\n component: this,\r\n _: '<',\r\n event: name, p,\r\n newState,\r\n state: this.state,\r\n options\r\n });\r\n\r\n this.setState(newState, options)\r\n }, options);\r\n }\r\n\r\n add_actions() {\r\n const actions = this.update || {};\r\n Reflect.getMetadataKeys(this).forEach(key => {\r\n if (key.startsWith('apprun-update:')) {\r\n const meta = Reflect.getMetadata(key, this)\r\n actions[meta.name] = [this[meta.key].bind(this), meta.options];\r\n }\r\n })\r\n\r\n const all = {};\r\n if (Array.isArray(actions)) {\r\n actions.forEach(act => {\r\n const [name, action, opts] = act as ActionDef;\r\n const names = name.toString();\r\n names.split(',').forEach(n => all[n.trim()] = [action, opts])\r\n })\r\n } else {\r\n Object.keys(actions).forEach(name => {\r\n const action = actions[name];\r\n if (typeof action === 'function' || Array.isArray(action)) {\r\n name.split(',').forEach(n => all[n.trim()] = action)\r\n }\r\n })\r\n }\r\n\r\n if (!all['.']) all['.'] = REFRESH;\r\n Object.keys(all).forEach(name => {\r\n const action = all[name];\r\n if (typeof action === 'function') {\r\n this.add_action(name, action);\r\n } else if (Array.isArray(action)) {\r\n this.add_action(name, action[0], action[1]);\r\n }\r\n });\r\n }\r\n\r\n public run(event: E, ...args) {\r\n const name = event.toString();\r\n return this.is_global_event(name) ?\r\n app.run(name, ...args) :\r\n this._app.run(name, ...args);\r\n }\r\n\r\n public on(event: E, fn: (...args) => void, options?: any) {\r\n const name = event.toString();\r\n this._actions.push({ name, fn });\r\n return this.is_global_event(name) ?\r\n app.on(name, fn, options) :\r\n this._app.on(name, fn, options);\r\n }\r\n\r\n public unmount() {\r\n this.observer?.disconnect();\r\n this._actions.forEach(action => {\r\n const { name, fn } = action;\r\n this.is_global_event(name) ?\r\n app.off(name, fn) :\r\n this._app.off(name, fn);\r\n });\r\n }\r\n}\r\n","import app from './app';\n\nexport type Route = (url: string, ...args: any[]) => any;\n\nexport const ROUTER_EVENT: string = '//';\nexport const ROUTER_404_EVENT: string = '///';\n\nexport const route: Route = (url: string) => {\n if (!url) url = '#';\n if (url.startsWith('#')) {\n const [name, ...rest] = url.split('/');\n app.run(name, ...rest) || app.run(ROUTER_404_EVENT, name, ...rest);\n app.run(ROUTER_EVENT, name, ...rest);\n } else if (url.startsWith('/')) {\n const [_, name, ...rest] = url.split('/');\n app.run('/' + name, ...rest) || app.run(ROUTER_404_EVENT, '/' + name, ...rest);\n app.run(ROUTER_EVENT, '/' + name, ...rest);\n } else {\n app.run(url) || app.run(ROUTER_404_EVENT, url);\n app.run(ROUTER_EVENT, url);\n }\n}\nexport default route;","import app from './app';\nimport { createElement, render, Fragment } from './vdom';\nimport { Component } from './component';\nimport { VNode, View, Action, Update, EventOptions, ActionOptions, MountOptions, AppStartOptions } from './types';\nimport { on, update, customElement } from './decorator';\nimport webComponent, { CustomElementOptions } from './web-component';\nimport { Route, route, ROUTER_EVENT, ROUTER_404_EVENT } from './router';\n\nexport interface IApp {\n start(element?: Element | string, model?: T, view?: View, update?: Update,\n options?: AppStartOptions): Component;\n on(name: string, fn: (...args: any[]) => void, options?: any): void;\n off(name: string, fn: (...args: any[]) => void): void;\n run(name: string, ...args: any[]): number;\n h(tag: string | Function, props, ...children): VNode | VNode[];\n createElement(tag: string | Function, props, ...children): VNode | VNode[];\n render(element: HTMLElement, node: VNode): void;\n Fragment(props, ...children): any[];\n route?: Route;\n webComponent(name: string, componentClass, options?: CustomElementOptions): void;\n}\n\napp.h = app.createElement = createElement;\napp.render = render;\napp.Fragment = Fragment;\napp.webComponent = webComponent;\n\napp.start = (element?: Element, model?: T, view?: View, update?: Update,\n options?: AppStartOptions): Component => {\n const opts = { ...options, render: true, global_event: true };\n const component = new Component(model, view, update);\n if (options && options.rendered) component.rendered = options.rendered;\n component.mount(element, opts);\n return component;\n};\n\nconst NOOP = _ => {/* Intentionally empty */ }\napp.on('$', NOOP);\napp.on('debug', _ => NOOP);\napp.on(ROUTER_EVENT, NOOP);\napp.on('#', NOOP);\napp['route'] = route;\napp.on('route', url => app['route'] && app['route'](url));\n\nif (typeof document === 'object') {\n document.addEventListener(\"DOMContentLoaded\", () => {\n if (app['route'] === route) {\n window.onpopstate = () => route(location.hash);\n if (!document.body.hasAttribute('apprun-no-init')) route(location.hash);\n }\n });\n}\n\nexport type StatelessComponent = (args: T) => string | VNode | void;\nexport { app, Component, View, Action, Update, on, update, EventOptions, ActionOptions, MountOptions, Fragment }\nexport { update as event };\nexport { ROUTER_EVENT, ROUTER_404_EVENT };\nexport { customElement, CustomElementOptions, AppStartOptions };\nexport default app as IApp;\n\nif (typeof window === 'object') {\n window['Component'] = Component;\n window['React'] = app;\n window['on'] = on;\n window['customElement'] = customElement;\n}\n\n\n","import { createElement, updateElement, Fragment } from './vdom-my';\nexport function render(element, html, parent?) {\n updateElement(element, html, parent);\n}\nexport { createElement, Fragment };\n\n\n","import { VDOM, VNode } from './types';\nexport type Element = any; //HTMLElement | SVGSVGElement | SVGElement;\n\nexport function Fragment(props, ...children): any[] {\n return collect(children);\n}\n\nconst ATTR_PROPS = '_props';\n\nfunction collect(children) {\n const ch = [];\n const push = (c) => {\n if (c !== null && c !== undefined && c !== '' && c !== false) {\n ch.push((typeof c === 'function' || typeof c === 'object') ? c : `${c}`);\n }\n }\n children && children.forEach(c => {\n if (Array.isArray(c)) {\n c.forEach(i => push(i));\n } else {\n push(c);\n }\n });\n return ch;\n}\n\nexport function createElement(tag: string | Function | [], props?: {}, ...children) {\n const ch = collect(children);\n if (typeof tag === 'string') return { tag, props, children: ch };\n else if (Array.isArray(tag)) return tag; // JSX fragments - babel\n else if (tag === undefined && children) return ch; // JSX fragments - typescript\n else if (Object.getPrototypeOf(tag).__isAppRunComponent) return { tag, props, children: ch } // createComponent(tag, { ...props, children });\n else if (typeof tag === 'function') return tag(props, ch);\n else throw new Error(`Unknown tag in vdom ${tag}`);\n};\n\nconst keyCache = new WeakMap();\n\nexport const updateElement = render;\n\nexport function render(element: Element, nodes: VDOM, parent = {}) {\n // console.log('render', element, node);\n // tslint:disable-next-line\n if (nodes == null || nodes === false) return;\n\n nodes = createComponent(nodes, parent);\n\n const isSvg = element?.nodeName === \"SVG\";\n\n if (!element) return;\n if (Array.isArray(nodes)) {\n updateChildren(element, nodes, isSvg);\n } else {\n updateChildren(element, [nodes], isSvg);\n }\n}\n\nfunction same(el: Element, node: VNode) {\n // if (!el || !node) return false;\n const key1 = el.nodeName;\n const key2 = `${node.tag || ''}`;\n return key1.toUpperCase() === key2.toUpperCase();\n}\n\nfunction update(element: Element, node: VNode, isSvg: boolean) {\n if (node['_op'] === 3) return;\n // console.assert(!!element);\n isSvg = isSvg || node.tag === \"svg\";\n if (!same(element, node)) {\n element.parentNode.replaceChild(create(node, isSvg), element);\n return;\n }\n !(node['_op'] & 2) && updateChildren(element, node.children, isSvg);\n !(node['_op'] & 1) && updateProps(element, node.props, isSvg);\n}\n\nfunction updateChildren(element, children, isSvg: boolean) {\n const old_len = element.childNodes?.length || 0;\n const new_len = children?.length || 0;\n const len = Math.min(old_len, new_len);\n for (let i = 0; i < len; i++) {\n const child = children[i];\n if (child['_op'] === 3) continue;\n const el = element.childNodes[i];\n if (typeof child === 'string') {\n if (el.textContent !== child) {\n if (el.nodeType === 3) {\n el.nodeValue = child\n } else {\n element.replaceChild(createText(child), el);\n }\n }\n } else if (child instanceof HTMLElement || child instanceof SVGElement) {\n element.insertBefore(child, el);\n } else {\n const key = child.props && child.props['key'];\n if (key) {\n if (el.key === key) {\n update(element.childNodes[i], child, isSvg);\n } else {\n // console.log(el.key, key);\n const old = keyCache[key];\n if (old) {\n const temp = old.nextSibling;\n element.insertBefore(old, el);\n temp ? element.insertBefore(el, temp) : element.appendChild(el);\n update(element.childNodes[i], child, isSvg);\n } else {\n element.replaceChild(create(child, isSvg), el);\n }\n }\n } else {\n update(element.childNodes[i], child, isSvg);\n }\n }\n }\n\n let n = element.childNodes.length;\n while (n > len) {\n element.removeChild(element.lastChild);\n n--;\n }\n\n if (new_len > len) {\n const d = document.createDocumentFragment();\n for (let i = len; i < children.length; i++) {\n d.appendChild(create(children[i], isSvg));\n }\n element.appendChild(d);\n }\n}\n\nfunction createText(node) {\n if (node?.indexOf('_html:') === 0) { // ?\n const div = document.createElement('div');\n div.insertAdjacentHTML('afterbegin', node.substring(6))\n return div;\n } else {\n return document.createTextNode(node??'');\n }\n}\n\nfunction create(node: VNode | string | HTMLElement | SVGElement, isSvg: boolean): Element {\n // console.assert(node !== null && node !== undefined);\n if ((node instanceof HTMLElement) || (node instanceof SVGElement)) return node;\n if (typeof node === \"string\") return createText(node);\n if (!node.tag || (typeof node.tag === 'function')) return createText(JSON.stringify(node));\n isSvg = isSvg || node.tag === \"svg\";\n const element = isSvg\n ? document.createElementNS(\"http://www.w3.org/2000/svg\", node.tag)\n : document.createElement(node.tag);\n\n updateProps(element, node.props, isSvg);\n if (node.children) node.children.forEach(child => element.appendChild(create(child, isSvg)));\n return element\n}\n\nfunction mergeProps(oldProps: {}, newProps: {}): {} {\n newProps['class'] = newProps['class'] || newProps['className'];\n delete newProps['className'];\n const props = {};\n if (oldProps) Object.keys(oldProps).forEach(p => props[p] = null);\n if (newProps) Object.keys(newProps).forEach(p => props[p] = newProps[p]);\n return props;\n}\n\nexport function updateProps(element: Element, props: {}, isSvg) {\n // console.assert(!!element);\n const cached = element[ATTR_PROPS] || {};\n props = mergeProps(cached, props || {});\n element[ATTR_PROPS] = props;\n\n for (const name in props) {\n const value = props[name];\n // if (cached[name] === value) continue;\n // console.log('updateProps', name, value);\n if (name.startsWith('data-')) {\n const dname = name.substring(5);\n const cname = dname.replace(/-(\\w)/g, (match) => match[1].toUpperCase());\n if (element.dataset[cname] !== value) {\n if (value || value === \"\") element.dataset[cname] = value;\n else delete element.dataset[cname];\n }\n } else if (name === 'style') {\n if (element.style.cssText) element.style.cssText = '';\n if (typeof value === 'string') element.style.cssText = value;\n else {\n for (const s in value) {\n if (element.style[s] !== value[s]) element.style[s] = value[s];\n }\n }\n } else if (name.startsWith('xlink')) {\n const xname = name.replace('xlink', '').toLowerCase();\n if (value == null || value === false) {\n element.removeAttributeNS('http://www.w3.org/1999/xlink', xname);\n } else {\n element.setAttributeNS('http://www.w3.org/1999/xlink', xname, value);\n }\n } else if (name.startsWith('on')) {\n if (!value || typeof value === 'function') {\n element[name] = value;\n } else if (typeof value === 'string') {\n if (value) element.setAttribute(name, value);\n else element.removeAttribute(name);\n }\n } else if (/^id$|^class$|^list$|^readonly$|^contenteditable$|^role|-/g.test(name) || isSvg) {\n if (element.getAttribute(name) !== value) {\n if (value) element.setAttribute(name, value);\n else element.removeAttribute(name);\n }\n } else if (element[name] !== value) {\n element[name] = value;\n }\n if (name === 'key' && value) keyCache[value] = element;\n }\n if (props && typeof props['ref'] === 'function') {\n window.requestAnimationFrame(() => props['ref'](element));\n }\n}\n\nfunction render_component(node, parent, idx) {\n const { tag, props, children } = node;\n let key = `_${idx}`;\n let id = props && props['id'];\n if (!id) id = `_${idx}${Date.now()}`;\n else key = id;\n let asTag = 'section';\n if (props && props['as']) {\n asTag = props['as'];\n delete props['as'];\n }\n if (!parent.__componentCache) parent.__componentCache = {};\n let component = parent.__componentCache[key];\n if (!component || !(component instanceof tag) || !component.element) {\n const element = document.createElement(asTag);\n component = parent.__componentCache[key] = new tag({ ...props, children }).start(element);\n }\n if (component.mounted) {\n const new_state = component.mounted(props, children, component.state);\n (typeof new_state !== 'undefined') && component.setState(new_state);\n }\n updateProps(component.element, props, false);\n return component.element;\n}\n\nfunction createComponent(node, parent, idx = 0) {\n if (typeof node === 'string') return node;\n if (Array.isArray(node)) return node.map(child => createComponent(child, parent, idx++));\n let vdom = node;\n if (node && typeof node.tag === 'function' && Object.getPrototypeOf(node.tag).__isAppRunComponent) {\n vdom = render_component(node, parent, idx);\n }\n if (vdom && Array.isArray(vdom.children)) {\n const new_parent = vdom.props?._component;\n if (new_parent) {\n let i = 0;\n vdom.children = vdom.children.map(child => createComponent(child, new_parent, i++));\n } else {\n vdom.children = vdom.children.map(child => createComponent(child, parent, idx++));\n }\n }\n return vdom;\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tif(__webpack_module_cache__[moduleId]) {\n\t\treturn __webpack_module_cache__[moduleId].exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// module exports must be returned from runtime so entry inlining is disabled\n// startup\n// Load entry module and return exports\nreturn __webpack_require__(643);\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.g = (function() {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();","__webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack://apprun/webpack/universalModuleDefinition","webpack://apprun/./src/app.ts","webpack://apprun/./src/web-component.ts","webpack://apprun/./src/decorator.ts","webpack://apprun/./src/directive.ts","webpack://apprun/./src/component.ts","webpack://apprun/./src/router.ts","webpack://apprun/./src/apprun.ts","webpack://apprun/./src/vdom.ts","webpack://apprun/./src/vdom-my.ts","webpack://apprun/webpack/bootstrap","webpack://apprun/webpack/runtime/define property getters","webpack://apprun/webpack/runtime/global","webpack://apprun/webpack/runtime/hasOwnProperty shorthand","webpack://apprun/webpack/runtime/make namespace object","webpack://apprun/./demo-html/components/counter.tsx","webpack://apprun/./demo-html/components/xkcd.tsx"],"names":["root","factory","exports","module","define","amd","this","App","_events","name","fn","options","push","subscribers","filter","sub","args","getSubscribers","console","assert","length","once","forEach","delay","Object","keys","apply","on","_t","clearTimeout","setTimeout","promises","map","Promise","all","events","evt","endsWith","startsWith","replace","sort","a","b","event","app","self","g","global","customElement","componentClass","HTMLElement","super","_component","state","observedAttributes","attr","toLowerCase","isConnected","opts","_shadowRoot","shadow","attachShadow","mode","attrMap","reduce","lc","_attrMap","props","Array","from","attributes","item","value","undefined","defineProperty","get","attributeChangedCallback","configurable","enumerable","children","el","parentElement","removeChild","mount","_props","dispatchEvent","bind","mounted","new_state","run","render","unload","unmount","oldValue","mappedName","window","requestAnimationFrame","customElements","Reflect","meta","WeakMap","metadataKey","metadataValue","target","has","set","getPrototypeOf","constructor","getStateValue","component","setStateValue","setState","componentCache","Map","o","components","REFRESH","Component","view","update","_app","_actions","_global_events","_history","_history_idx","_history_prev","history","_history_next","start","element","node","h","tag","key","substring","e","isArray","handler","p","type","checked","Number","multiple","selected","directive","html","vdom","_view","_","document","getElementById","tracking_attr","getAttribute","tracking_id","Date","valueOf","toString","setAttribute","MutationObserver","observer","changes","body","contains","disconnect","observe","childList","subtree","attributeOldValue","attributeFilter","removeAttribute","rendered","_state","then","v","catch","err","error","renderState","enable_history","callback","global_event","prev","next","route","add_actions","indexOf","action","current_state","newState","actions","getMetadataKeys","getMetadata","act","split","n","trim","add_action","is_global_event","off","__isAppRunComponent","ROUTER_EVENT","ROUTER_404_EVENT","url","rest","parent","model","NOOP","addEventListener","onpopstate","location","hash","hasAttribute","defineMetadata","Fragment","collect","ch","c","i","createElement","Error","keyCache","updateElement","nodes","createComponent","isSvg","nodeName","updateChildren","key1","key2","toUpperCase","same","updateProps","parentNode","replaceChild","create","old_len","childNodes","new_len","len","Math","min","child","textContent","nodeType","nodeValue","createText","SVGElement","insertBefore","old","temp","nextSibling","appendChild","lastChild","d","createDocumentFragment","div","insertAdjacentHTML","createTextNode","JSON","stringify","createElementNS","cached","oldProps","newProps","mergeProps","cname","match","dataset","style","cssText","s","xname","removeAttributeNS","setAttributeNS","test","idx","id","now","asTag","__componentCache","render_component","new_parent","__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","definition","globalThis","Function","obj","prop","prototype","hasOwnProperty","call","r","Symbol","toStringTag","MyApp","num","parseInt","loading","comic","title","src","async","response","fetch","json"],"mappings":"CAAA,SAA2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eAAexE,EAAS,aAAc,CAAEsE,OAAO,K,yCCFvD,IAAMkO,EAAN,cAAoB,EAAArL,UAApB,c,oBAEE,KAAAC,KAAO,EAAGqL,MAAK5N,cAAe,uBAC5B,sBAAK4N,GACJ5N,GAGH,KAAAwC,OAAS,CACP,KAAMlE,GAAU,OAAD,wBAAKA,GAAK,CAAEsP,IAAKtP,EAAMsP,IAAM,IAC5C,KAAMtP,GAAU,OAAD,wBAAKA,GAAK,CAAEsP,IAAKtP,EAAMsP,IAAM,KAG9C,KAAApN,QAAU,EAAGoN,OAAO5N,KAAa,CAAG4N,IAAKC,SAASD,GAAM5N,aAExD,KAAA2F,SAAW,EAAGiI,UACZrS,KAAK2H,QAAQ4B,aAAa,MAAO8I,MAf/BD,E,mUAAK,GADV,IAAA1P,eAAc,eACT0P,GCEN,oBAA6B,EAAArL,UAA7B,c,oBACE,KAAAhE,MAAQ,GAER,KAAAiE,KAAQjE,GAAU,oCAChB,uBAAK,+BAAiB,cAAY,SACjCA,EAAMwP,QAAU,uCAA0B,GAC1CxP,EAAMyP,OAAS,oCACd,sBAAKzP,EAAMyP,MAAMC,OACjB,mBAAKC,IAAK3P,EAAMyP,MAAMpG,QAI1B,KAAAnF,OAAS,CACP,QAAW,CAAC6B,EAAGyJ,KAAY,CAAGA,SAAS,IACvC,WAAcI,MAAM7J,IAClB9I,KAAKmF,IAAI,WAAW,GACpB,MAAMyN,QAAiBC,MAAM,oCAE7B,MAAO,CAAEL,YADWI,EAASE,OACbP,SAAS,KAI7B,KAAAtN,QAAU,IAAMjF,KAAKmF,IAAI,gBAtB3B,E,mUAAA,GADC,IAAAzC,eAAc,UAAW,CAACY,QAAQ,EAAM8B,QAAQ,K","file":"demo-html/app.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"apprun\"] = factory();\n\telse\n\t\troot[\"apprun\"] = factory();\n})(this, function() {\nreturn ","import { EventOptions} from './types'\nexport class App {\n\n private _events: Object;\n\n public start;\n public h;\n public createElement;\n public render;\n public Fragment;\n public webComponent;\n\n constructor() {\n this._events = {};\n }\n\n on(name: string, fn: (...args) => void, options: EventOptions = {}): void {\n this._events[name] = this._events[name] || [];\n this._events[name].push({ fn, options });\n }\n\n off(name: string, fn: (...args) => void): void {\n const subscribers = this._events[name] || [];\n\n this._events[name] = subscribers.filter((sub) => sub.fn !== fn);\n }\n\n find(name: string): any {\n return this._events[name];\n }\n\n run(name: string, ...args): number {\n const subscribers = this.getSubscribers(name, this._events);\n\n console.assert(subscribers && subscribers.length > 0, 'No subscriber for event: ' + name);\n\n // Update the list of subscribers by pulling out those which will run once.\n // We must do this update prior to running any of the events in case they\n // cause additional events to be turned off or on.\n this._events[name] = subscribers.filter((sub) => {\n return !sub.options.once;\n });\n\n subscribers.forEach((sub) => {\n const { fn, options } = sub;\n if (options.delay) {\n this.delay(name, fn, args, options);\n } else {\n Object.keys(options).length > 0 ? fn.apply(this, [...args, options]) : fn.apply(this, args);\n }\n return !sub.options.once;\n });\n\n return subscribers.length;\n }\n\n once(name: string, fn, options: EventOptions = {}): void {\n this.on(name, fn, { ...options, once: true });\n }\n\n private delay(name, fn, args, options): void {\n if (options._t) clearTimeout(options._t);\n options._t = setTimeout(() => {\n clearTimeout(options._t);\n Object.keys(options).length > 0 ? fn.apply(this, [...args, options]) : fn.apply(this, args);\n }, options.delay);\n }\n\n query(name: string, ...args): Promise {\n const subscribers = this.getSubscribers(name, this._events);\n console.assert(subscribers && subscribers.length > 0, 'No subscriber for event: ' + name);\n const promises = subscribers.map(sub => {\n const { fn, options } = sub;\n return Object.keys(options).length > 0 ? fn.apply(this, [...args, options]) : fn.apply(this, args);\n });\n return Promise.all(promises);\n }\n\n private getSubscribers(name: string, events) {\n const subscribers = this._events[name] || [];\n const p = subscribers.length;\n Object.keys(events).filter(evt => evt.endsWith('*') && name.startsWith(evt.replace('*', '')))\n .sort((a, b) => b.length - a.length)\n .forEach(evt => subscribers.push(...events[evt].map(\n sub => {\n sub.options = {...sub.options, event: name };\n return sub;\n })));\n\n return subscribers;\n }\n}\n\nconst AppRunVersions = 'AppRun-2';\nlet app: App;\nconst root = (typeof self === 'object' && self.self === self && self) ||\n (typeof global === 'object' && global.global === global && global)\nif (root['app'] && root['_AppRunVersions']) {\n app = root['app'];\n} else {\n app = new App();\n root['app'] = app;\n root['_AppRunVersions'] = AppRunVersions;\n}\nexport default app;\n","declare var customElements;\n\nexport type CustomElementOptions = {\n render?: boolean;\n shadow?: boolean;\n history?: boolean;\n global_event?: boolean;\n observedAttributes?: string[];\n};\n\nexport const customElement = (componentClass, options: CustomElementOptions = {}) => class CustomElement extends HTMLElement {\n private _shadowRoot;\n private _component;\n private _attrMap: (arg0: string) => string;\n public on;\n public run;\n constructor() {\n super();\n }\n get component() { return this._component; }\n get state() { return this._component.state; }\n\n static get observedAttributes() {\n // attributes need to be set to lowercase in order to get observed\n return (options.observedAttributes || []).map(attr => attr.toLowerCase());\n }\n\n connectedCallback() {\n if (this.isConnected && !this._component) {\n const opts = options || {};\n this._shadowRoot = opts.shadow ? this.attachShadow({ mode: 'open' }) : this;\n const observedAttributes = (opts.observedAttributes || [])\n\n const attrMap = observedAttributes.reduce((map, name) => {\n const lc = name.toLowerCase()\n if (lc !== name) {\n map[lc] = name\n }\n return map\n }, {})\n this._attrMap = (name: string) : string => attrMap[name] || name\n\n const props = {};\n Array.from(this.attributes).forEach(item => props[this._attrMap(item.name)] = item.value);\n\n // add getters/ setters to allow observation on observedAttributes\n observedAttributes.forEach(name => {\n if (this[name] !== undefined) props[name] = this[name];\n Object.defineProperty(this, name, {\n get(): any {\n return props[name];\n },\n set(this: CustomElement, value: unknown) {\n // trigger change event\n this.attributeChangedCallback(name, props[name], value)\n },\n configurable: true,\n enumerable: true\n });\n })\n\n const children = this.children ? Array.from(this.children) : [];\n children.forEach(el => el.parentElement.removeChild(el));\n this._component = new componentClass({ ...props, children }).mount(this._shadowRoot, opts);\n // attach props to component\n this._component._props = props;\n // expose dispatchEvent\n this._component.dispatchEvent = this.dispatchEvent.bind(this)\n if (this._component.mounted) {\n const new_state = this._component.mounted(props, children, this._component.state);\n if (typeof new_state !== 'undefined') this._component.state = new_state;\n }\n this.on = this._component.on.bind(this._component);\n this.run = this._component.run.bind(this._component);\n if (!(opts.render===false)) this._component.run('.');\n }\n }\n\n disconnectedCallback() {\n this._component?.unload?.();\n this._component?.unmount?.();\n this._component = null;\n }\n\n attributeChangedCallback(name: string, oldValue: unknown, value: unknown) {\n if (this._component) {\n // camelCase attributes arrive only in lowercase\n const mappedName = this._attrMap(name);\n // store the new property/ attribute\n this._component._props[mappedName] = value;\n this._component.run('attributeChanged', mappedName, oldValue, value);\n\n if (value !== oldValue && !(options.render === false)) {\n window.requestAnimationFrame(() => {\n // re-render state with new combined props on next animation frame\n this._component.run('.')\n })\n }\n }\n }\n}\n\nexport default (name: string, componentClass, options?: CustomElementOptions) => {\n (typeof customElements !== 'undefined') && customElements.define(name, customElement(componentClass, options))\n}\n","import webComponent, { CustomElementOptions } from './web-component';\n\n// tslint:disable:no-invalid-this\nexport const Reflect = {\n\n meta: new WeakMap(),\n\n defineMetadata(metadataKey, metadataValue, target) {\n if (!this.meta.has(target)) this.meta.set(target, {});\n this.meta.get(target)[metadataKey] = metadataValue;\n },\n\n getMetadataKeys(target) {\n target = Object.getPrototypeOf(target);\n return this.meta.get(target) ? Object.keys(this.meta.get(target)) : [];\n },\n\n getMetadata(metadataKey, target) {\n target = Object.getPrototypeOf(target);\n return this.meta.get(target) ? this.meta.get(target)[metadataKey] : null;\n }\n}\n\nexport function update(events?: E, options: any = {}) {\n return (target: any, key: string, descriptor: any) => {\n const name = events ? events.toString() : key;\n Reflect.defineMetadata(`apprun-update:${name}`,\n { name, key, options }, target);\n return descriptor;\n }\n}\n\nexport function on(events?: E, options: any = {}) {\n return function (target: any, key: string) {\n const name = events ? events.toString() : key;\n Reflect.defineMetadata(`apprun-update:${name}`,\n { name, key, options }, target)\n }\n}\n\nexport function customElement(name: string, options?: CustomElementOptions) {\n return function _customElement(constructor: T) {\n webComponent(name, constructor, options);\n return constructor;\n }\n}\n\n","import app from './app';\n\nconst getStateValue = (component, name) => {\n return (name ? component['state'][name] : component['state']) || '';\n}\n\nconst setStateValue = (component, name, value) => {\n if (name) {\n const state = component['state'] || {};\n state[name] = value;\n component.setState(state);\n } else {\n component.setState(value);\n }\n}\n\nexport default (key: string, props: {}, tag, component) => {\n if (key.startsWith('$on')) {\n const event = props[key];\n key = key.substring(1)\n if (typeof event === 'boolean') {\n props[key] = e => component.run(key, e);\n } else if (typeof event === 'string') {\n props[key] = e => component.run(event, e);\n } else if (typeof event === 'function') {\n props[key] = e => component.setState(event(component.state, e));\n } else if (Array.isArray(event)) {\n const [handler, ...p] = event;\n if (typeof handler === 'string') {\n props[key] = e => component.run(handler, ...p, e);\n } else if (typeof handler === 'function') {\n props[key] = e => component.setState(handler(component.state, ...p, e));\n }\n }\n\n } else if (key === '$bind') {\n const type = props['type'] || 'text';\n const name = typeof props[key] === 'string' ? props[key] : props['name'];\n if (tag === 'input') {\n switch (type) {\n case 'checkbox':\n props['checked'] = getStateValue(component, name);\n props['onclick'] = e => setStateValue(component, name || e.target.name, e.target.checked);\n break;\n case 'radio':\n props['checked'] = getStateValue(component, name) === props['value'];\n props['onclick'] = e => setStateValue(component, name || e.target.name, e.target.value);\n break;\n case 'number':\n case 'range':\n props['value'] = getStateValue(component, name);\n props['oninput'] = e => setStateValue(component, name || e.target.name, Number(e.target.value));\n break;\n default:\n props['value'] = getStateValue(component, name);\n props['oninput'] = e => setStateValue(component, name || e.target.name, e.target.value);\n }\n } else if (tag === 'select') {\n props['value'] = getStateValue(component, name);\n props['onchange'] = e => {\n if (!e.target.multiple) { // multiple selection use $bind on option\n setStateValue(component, name || e.target.name, e.target.value);\n }\n }\n } else if (tag === 'option') {\n props['selected'] = getStateValue(component, name);\n props['onclick'] = e => setStateValue(component, name || e.target.name, e.target.selected);\n } else if (tag === 'textarea') {\n props['innerHTML'] = getStateValue(component, name);\n props['oninput'] = e => setStateValue(component, name || e.target.name, e.target.value);\n }\n } else {\n app.run('$', { key, tag, props, component });\n }\n}","\r\nimport app, { App } from './app';\r\nimport { Reflect } from './decorator'\r\nimport { View, Update, ActionDef, ActionOptions, MountOptions } from './types';\r\nimport directive from './directive';\r\n\r\nconst componentCache = new Map();\r\napp.on('get-components', o => o.components = componentCache);\r\n\r\nconst REFRESH = state => state;\r\n\r\nexport class Component {\r\n static __isAppRunComponent = true;\r\n private _app = new App();\r\n private _actions = [];\r\n private _global_events = [];\r\n private _state;\r\n private _history = [];\r\n private _history_idx = -1;\r\n private enable_history;\r\n private global_event;\r\n public element;\r\n public rendered;\r\n public mounted;\r\n public unload;\r\n private tracking_id;\r\n private observer;\r\n\r\n render(element: HTMLElement, node) {\r\n app.render(element, node, this);\r\n }\r\n\r\n private _view(state) {\r\n if (!this.view) return;\r\n const h = app.createElement;\r\n app.h = app.createElement = (tag, props, ...children) => {\r\n props && Object.keys(props).forEach(key => {\r\n if (key.startsWith('$')) {\r\n directive(key, props, tag, this);\r\n delete props[key];\r\n }\r\n });\r\n return h(tag, props, ...children);\r\n }\r\n const html = this.view(state);\r\n app.h = app.createElement = h;\r\n return html;\r\n }\r\n\r\n private renderState(state: T, vdom = null) {\r\n if (!this.view) return;\r\n let html = vdom || this._view(state);\r\n\r\n app['debug'] && app.run('debug', {\r\n component: this,\r\n _: html ? '.' : '-',\r\n state,\r\n vdom: html,\r\n el: this.element\r\n });\r\n\r\n if (typeof document !== 'object') return;\r\n\r\n const el = (typeof this.element === 'string') ?\r\n document.getElementById(this.element) : this.element;\r\n\r\n if (el) {\r\n const tracking_attr = '_c';\r\n if (!this.unload) {\r\n el.removeAttribute && el.removeAttribute(tracking_attr);\r\n } else if (el['_component'] !== this || el.getAttribute(tracking_attr) !== this.tracking_id) {\r\n this.tracking_id = new Date().valueOf().toString();\r\n el.setAttribute(tracking_attr, this.tracking_id);\r\n if (typeof MutationObserver !== 'undefined') {\r\n if (!this.observer) this.observer = new MutationObserver(changes => {\r\n if (changes[0].oldValue === this.tracking_id || !document.body.contains(el)) {\r\n this.unload(this.state);\r\n this.observer.disconnect();\r\n this.observer = null;\r\n }\r\n });\r\n this.observer.observe(document.body, {\r\n childList: true, subtree: true,\r\n attributes: true, attributeOldValue: true, attributeFilter: [tracking_attr]\r\n });\r\n }\r\n }\r\n el['_component'] = this;\r\n }\r\n if (!vdom) {\r\n this.render(el, html);\r\n }\r\n this.rendered && this.rendered(this.state);\r\n }\r\n\r\n public setState(state: T, options: ActionOptions\r\n = { render: true, history: false }) {\r\n if (state instanceof Promise) {\r\n // Promise will not be saved or rendered\r\n // state will be saved and rendered when promise is resolved\r\n // Wait for previous promise to complete first\r\n Promise.all([state, this._state]).then(v => {\r\n if (v[0]) this.setState(v[0]);\r\n }).catch(err => {\r\n console.error(err);\r\n throw err;\r\n });\r\n this._state = state;\r\n } else {\r\n this._state = state;\r\n if (state == null) return;\r\n this.state = state;\r\n if (options.render !== false) this.renderState(state);\r\n if (options.history !== false && this.enable_history) {\r\n this._history = [...this._history, state];\r\n this._history_idx = this._history.length - 1;\r\n }\r\n if (typeof options.callback === 'function') options.callback(this.state);\r\n }\r\n }\r\n\r\n private _history_prev = () => {\r\n this._history_idx--;\r\n if (this._history_idx >= 0) {\r\n this.setState(this._history[this._history_idx], { render: true, history: false });\r\n }\r\n else {\r\n this._history_idx = 0;\r\n }\r\n };\r\n\r\n private _history_next = () => {\r\n this._history_idx++;\r\n if (this._history_idx < this._history.length) {\r\n this.setState(this._history[this._history_idx], { render: true, history: false });\r\n }\r\n else {\r\n this._history_idx = this._history.length - 1;\r\n }\r\n };\r\n\r\n constructor(\r\n protected state?: T,\r\n protected view?: View,\r\n protected update?: Update,\r\n protected options?) {\r\n }\r\n\r\n start = (element = null, options?: MountOptions): Component => {\r\n return this.mount(element, { ...options, render: true });\r\n }\r\n\r\n public mount(element = null, options?: MountOptions): Component {\r\n console.assert(!this.element, 'Component already mounted.')\r\n this.options = options = { ...this.options, ...options };\r\n this.element = element;\r\n this.global_event = options.global_event;\r\n this.enable_history = !!options.history;\r\n\r\n if (this.enable_history) {\r\n this.on(options.history.prev || 'history-prev', this._history_prev);\r\n this.on(options.history.next || 'history-next', this._history_next);\r\n }\r\n\r\n if (options.route) {\r\n this.update = this.update || {};\r\n this.update[options.route] = REFRESH;\r\n }\r\n\r\n this.add_actions();\r\n this.state = this.state ?? this['model'] ?? {};\r\n if (typeof this.state === 'function') this.state = this.state();\r\n if (options.render) {\r\n this.setState(this.state, { render: true, history: true });\r\n } else {\r\n this.setState(this.state, { render: false, history: true });\r\n }\r\n if (app['debug']) {\r\n if (componentCache.get(element)) { componentCache.get(element).push(this) }\r\n else { componentCache.set(element, [this])}\r\n }\r\n return this;\r\n }\r\n\r\n is_global_event(name: string): boolean {\r\n return name && (\r\n this.global_event ||\r\n this._global_events.indexOf(name) >= 0 ||\r\n name.startsWith('#') || name.startsWith('/') || name.startsWith('@'));\r\n }\r\n\r\n add_action(name: string, action, options: ActionOptions = {}) {\r\n if (!action || typeof action !== 'function') return;\r\n if (options.global) this._global_events.push(name);\r\n this.on(name as any, (...p) => {\r\n\r\n app['debug'] && app.run('debug', {\r\n component: this,\r\n _: '>',\r\n event: name, p,\r\n current_state: this.state,\r\n options\r\n });\r\n\r\n const newState = action(this.state, ...p);\r\n\r\n app['debug'] && app.run('debug', {\r\n component: this,\r\n _: '<',\r\n event: name, p,\r\n newState,\r\n state: this.state,\r\n options\r\n });\r\n\r\n this.setState(newState, options)\r\n }, options);\r\n }\r\n\r\n add_actions() {\r\n const actions = this.update || {};\r\n Reflect.getMetadataKeys(this).forEach(key => {\r\n if (key.startsWith('apprun-update:')) {\r\n const meta = Reflect.getMetadata(key, this)\r\n actions[meta.name] = [this[meta.key].bind(this), meta.options];\r\n }\r\n })\r\n\r\n const all = {};\r\n if (Array.isArray(actions)) {\r\n actions.forEach(act => {\r\n const [name, action, opts] = act as ActionDef;\r\n const names = name.toString();\r\n names.split(',').forEach(n => all[n.trim()] = [action, opts])\r\n })\r\n } else {\r\n Object.keys(actions).forEach(name => {\r\n const action = actions[name];\r\n if (typeof action === 'function' || Array.isArray(action)) {\r\n name.split(',').forEach(n => all[n.trim()] = action)\r\n }\r\n })\r\n }\r\n\r\n if (!all['.']) all['.'] = REFRESH;\r\n Object.keys(all).forEach(name => {\r\n const action = all[name];\r\n if (typeof action === 'function') {\r\n this.add_action(name, action);\r\n } else if (Array.isArray(action)) {\r\n this.add_action(name, action[0], action[1]);\r\n }\r\n });\r\n }\r\n\r\n public run(event: E, ...args) {\r\n const name = event.toString();\r\n return this.is_global_event(name) ?\r\n app.run(name, ...args) :\r\n this._app.run(name, ...args);\r\n }\r\n\r\n public on(event: E, fn: (...args) => void, options?: any) {\r\n const name = event.toString();\r\n this._actions.push({ name, fn });\r\n return this.is_global_event(name) ?\r\n app.on(name, fn, options) :\r\n this._app.on(name, fn, options);\r\n }\r\n\r\n public unmount() {\r\n this.observer?.disconnect();\r\n this._actions.forEach(action => {\r\n const { name, fn } = action;\r\n this.is_global_event(name) ?\r\n app.off(name, fn) :\r\n this._app.off(name, fn);\r\n });\r\n }\r\n}\r\n","import app from './app';\n\nexport type Route = (url: string, ...args: any[]) => any;\n\nexport const ROUTER_EVENT: string = '//';\nexport const ROUTER_404_EVENT: string = '///';\n\nexport const route: Route = (url: string) => {\n if (!url) url = '#';\n if (url.startsWith('#')) {\n const [name, ...rest] = url.split('/');\n app.run(name, ...rest) || app.run(ROUTER_404_EVENT, name, ...rest);\n app.run(ROUTER_EVENT, name, ...rest);\n } else if (url.startsWith('/')) {\n const [_, name, ...rest] = url.split('/');\n app.run('/' + name, ...rest) || app.run(ROUTER_404_EVENT, '/' + name, ...rest);\n app.run(ROUTER_EVENT, '/' + name, ...rest);\n } else {\n app.run(url) || app.run(ROUTER_404_EVENT, url);\n app.run(ROUTER_EVENT, url);\n }\n}\nexport default route;","import app from './app';\nimport { createElement, render, Fragment } from './vdom';\nimport { Component } from './component';\nimport { VNode, View, Action, Update, EventOptions, ActionOptions, MountOptions, AppStartOptions } from './types';\nimport { on, update, customElement } from './decorator';\nimport webComponent, { CustomElementOptions } from './web-component';\nimport { Route, route, ROUTER_EVENT, ROUTER_404_EVENT } from './router';\n\nexport interface IApp {\n start(element?: Element | string, model?: T, view?: View, update?: Update,\n options?: AppStartOptions): Component;\n on(name: string, fn: (...args: any[]) => void, options?: any): void;\n off(name: string, fn: (...args: any[]) => void): void;\n run(name: string, ...args: any[]): number;\n h(tag: string | Function, props, ...children): VNode | VNode[];\n createElement(tag: string | Function, props, ...children): VNode | VNode[];\n render(element: HTMLElement, node: VNode): void;\n Fragment(props, ...children): any[];\n route?: Route;\n webComponent(name: string, componentClass, options?: CustomElementOptions): void;\n}\n\napp.h = app.createElement = createElement;\napp.render = render;\napp.Fragment = Fragment;\napp.webComponent = webComponent;\n\napp.start = (element?: Element, model?: T, view?: View, update?: Update,\n options?: AppStartOptions): Component => {\n const opts = { ...options, render: true, global_event: true };\n const component = new Component(model, view, update);\n if (options && options.rendered) component.rendered = options.rendered;\n component.mount(element, opts);\n return component;\n};\n\nconst NOOP = _ => {/* Intentionally empty */ }\napp.on('$', NOOP);\napp.on('debug', _ => NOOP);\napp.on(ROUTER_EVENT, NOOP);\napp.on('#', NOOP);\napp['route'] = route;\napp.on('route', url => app['route'] && app['route'](url));\n\nif (typeof document === 'object') {\n document.addEventListener(\"DOMContentLoaded\", () => {\n if (app['route'] === route) {\n window.onpopstate = () => route(location.hash);\n if (!document.body.hasAttribute('apprun-no-init')) route(location.hash);\n }\n });\n}\n\nexport type StatelessComponent = (args: T) => string | VNode | void;\nexport { app, Component, View, Action, Update, on, update, EventOptions, ActionOptions, MountOptions, Fragment }\nexport { update as event };\nexport { ROUTER_EVENT, ROUTER_404_EVENT };\nexport { customElement, CustomElementOptions, AppStartOptions };\nexport default app as IApp;\n\nif (typeof window === 'object') {\n window['Component'] = Component;\n window['React'] = app;\n window['on'] = on;\n window['customElement'] = customElement;\n}\n\n\n","import { createElement, updateElement, Fragment } from './vdom-my';\nexport function render(element, html, parent?) {\n updateElement(element, html, parent);\n}\nexport { createElement, Fragment };\n\n\n","import { VDOM, VNode } from './types';\nexport type Element = any; //HTMLElement | SVGSVGElement | SVGElement;\n\nexport function Fragment(props, ...children): any[] {\n return collect(children);\n}\n\nconst ATTR_PROPS = '_props';\n\nfunction collect(children) {\n const ch = [];\n const push = (c) => {\n if (c !== null && c !== undefined && c !== '' && c !== false) {\n ch.push((typeof c === 'function' || typeof c === 'object') ? c : `${c}`);\n }\n }\n children && children.forEach(c => {\n if (Array.isArray(c)) {\n c.forEach(i => push(i));\n } else {\n push(c);\n }\n });\n return ch;\n}\n\nexport function createElement(tag: string | Function | [], props?: {}, ...children) {\n const ch = collect(children);\n if (typeof tag === 'string') return { tag, props, children: ch };\n else if (Array.isArray(tag)) return tag; // JSX fragments - babel\n else if (tag === undefined && children) return ch; // JSX fragments - typescript\n else if (Object.getPrototypeOf(tag).__isAppRunComponent) return { tag, props, children: ch } // createComponent(tag, { ...props, children });\n else if (typeof tag === 'function') return tag(props, ch);\n else throw new Error(`Unknown tag in vdom ${tag}`);\n};\n\nconst keyCache = new WeakMap();\n\nexport const updateElement = render;\n\nexport function render(element: Element, nodes: VDOM, parent = {}) {\n // console.log('render', element, node);\n // tslint:disable-next-line\n if (nodes == null || nodes === false) return;\n\n nodes = createComponent(nodes, parent);\n\n const isSvg = element?.nodeName === \"SVG\";\n\n if (!element) return;\n if (Array.isArray(nodes)) {\n updateChildren(element, nodes, isSvg);\n } else {\n updateChildren(element, [nodes], isSvg);\n }\n}\n\nfunction same(el: Element, node: VNode) {\n // if (!el || !node) return false;\n const key1 = el.nodeName;\n const key2 = `${node.tag || ''}`;\n return key1.toUpperCase() === key2.toUpperCase();\n}\n\nfunction update(element: Element, node: VNode, isSvg: boolean) {\n if (node['_op'] === 3) return;\n // console.assert(!!element);\n isSvg = isSvg || node.tag === \"svg\";\n if (!same(element, node)) {\n element.parentNode.replaceChild(create(node, isSvg), element);\n return;\n }\n !(node['_op'] & 2) && updateChildren(element, node.children, isSvg);\n !(node['_op'] & 1) && updateProps(element, node.props, isSvg);\n}\n\nfunction updateChildren(element, children, isSvg: boolean) {\n const old_len = element.childNodes?.length || 0;\n const new_len = children?.length || 0;\n const len = Math.min(old_len, new_len);\n for (let i = 0; i < len; i++) {\n const child = children[i];\n if (child['_op'] === 3) continue;\n const el = element.childNodes[i];\n if (typeof child === 'string') {\n if (el.textContent !== child) {\n if (el.nodeType === 3) {\n el.nodeValue = child\n } else {\n element.replaceChild(createText(child), el);\n }\n }\n } else if (child instanceof HTMLElement || child instanceof SVGElement) {\n element.insertBefore(child, el);\n } else {\n const key = child.props && child.props['key'];\n if (key) {\n if (el.key === key) {\n update(element.childNodes[i], child, isSvg);\n } else {\n // console.log(el.key, key);\n const old = keyCache[key];\n if (old) {\n const temp = old.nextSibling;\n element.insertBefore(old, el);\n temp ? element.insertBefore(el, temp) : element.appendChild(el);\n update(element.childNodes[i], child, isSvg);\n } else {\n element.replaceChild(create(child, isSvg), el);\n }\n }\n } else {\n update(element.childNodes[i], child, isSvg);\n }\n }\n }\n\n let n = element.childNodes.length;\n while (n > len) {\n element.removeChild(element.lastChild);\n n--;\n }\n\n if (new_len > len) {\n const d = document.createDocumentFragment();\n for (let i = len; i < children.length; i++) {\n d.appendChild(create(children[i], isSvg));\n }\n element.appendChild(d);\n }\n}\n\nfunction createText(node) {\n if (node?.indexOf('_html:') === 0) { // ?\n const div = document.createElement('div');\n div.insertAdjacentHTML('afterbegin', node.substring(6))\n return div;\n } else {\n return document.createTextNode(node??'');\n }\n}\n\nfunction create(node: VNode | string | HTMLElement | SVGElement, isSvg: boolean): Element {\n // console.assert(node !== null && node !== undefined);\n if ((node instanceof HTMLElement) || (node instanceof SVGElement)) return node;\n if (typeof node === \"string\") return createText(node);\n if (!node.tag || (typeof node.tag === 'function')) return createText(JSON.stringify(node));\n isSvg = isSvg || node.tag === \"svg\";\n const element = isSvg\n ? document.createElementNS(\"http://www.w3.org/2000/svg\", node.tag)\n : document.createElement(node.tag);\n\n updateProps(element, node.props, isSvg);\n if (node.children) node.children.forEach(child => element.appendChild(create(child, isSvg)));\n return element\n}\n\nfunction mergeProps(oldProps: {}, newProps: {}): {} {\n newProps['class'] = newProps['class'] || newProps['className'];\n delete newProps['className'];\n const props = {};\n if (oldProps) Object.keys(oldProps).forEach(p => props[p] = null);\n if (newProps) Object.keys(newProps).forEach(p => props[p] = newProps[p]);\n return props;\n}\n\nexport function updateProps(element: Element, props: {}, isSvg) {\n // console.assert(!!element);\n const cached = element[ATTR_PROPS] || {};\n props = mergeProps(cached, props || {});\n element[ATTR_PROPS] = props;\n\n for (const name in props) {\n const value = props[name];\n // if (cached[name] === value) continue;\n // console.log('updateProps', name, value);\n if (name.startsWith('data-')) {\n const dname = name.substring(5);\n const cname = dname.replace(/-(\\w)/g, (match) => match[1].toUpperCase());\n if (element.dataset[cname] !== value) {\n if (value || value === \"\") element.dataset[cname] = value;\n else delete element.dataset[cname];\n }\n } else if (name === 'style') {\n if (element.style.cssText) element.style.cssText = '';\n if (typeof value === 'string') element.style.cssText = value;\n else {\n for (const s in value) {\n if (element.style[s] !== value[s]) element.style[s] = value[s];\n }\n }\n } else if (name.startsWith('xlink')) {\n const xname = name.replace('xlink', '').toLowerCase();\n if (value == null || value === false) {\n element.removeAttributeNS('http://www.w3.org/1999/xlink', xname);\n } else {\n element.setAttributeNS('http://www.w3.org/1999/xlink', xname, value);\n }\n } else if (name.startsWith('on')) {\n if (!value || typeof value === 'function') {\n element[name] = value;\n } else if (typeof value === 'string') {\n if (value) element.setAttribute(name, value);\n else element.removeAttribute(name);\n }\n } else if (/^id$|^class$|^list$|^readonly$|^contenteditable$|^role|-/g.test(name) || isSvg) {\n if (element.getAttribute(name) !== value) {\n if (value) element.setAttribute(name, value);\n else element.removeAttribute(name);\n }\n } else if (element[name] !== value) {\n element[name] = value;\n }\n if (name === 'key' && value) keyCache[value] = element;\n }\n if (props && typeof props['ref'] === 'function') {\n window.requestAnimationFrame(() => props['ref'](element));\n }\n}\n\nfunction render_component(node, parent, idx) {\n const { tag, props, children } = node;\n let key = `_${idx}`;\n let id = props && props['id'];\n if (!id) id = `_${idx}${Date.now()}`;\n else key = id;\n let asTag = 'section';\n if (props && props['as']) {\n asTag = props['as'];\n delete props['as'];\n }\n if (!parent.__componentCache) parent.__componentCache = {};\n let component = parent.__componentCache[key];\n if (!component || !(component instanceof tag) || !component.element) {\n const element = document.createElement(asTag);\n component = parent.__componentCache[key] = new tag({ ...props, children }).start(element);\n }\n if (component.mounted) {\n const new_state = component.mounted(props, children, component.state);\n (typeof new_state !== 'undefined') && component.setState(new_state);\n }\n updateProps(component.element, props, false);\n return component.element;\n}\n\nfunction createComponent(node, parent, idx = 0) {\n if (typeof node === 'string') return node;\n if (Array.isArray(node)) return node.map(child => createComponent(child, parent, idx++));\n let vdom = node;\n if (node && typeof node.tag === 'function' && Object.getPrototypeOf(node.tag).__isAppRunComponent) {\n vdom = render_component(node, parent, idx);\n }\n if (vdom && Array.isArray(vdom.children)) {\n const new_parent = vdom.props?._component;\n if (new_parent) {\n let i = 0;\n vdom.children = vdom.children.map(child => createComponent(child, new_parent, i++));\n } else {\n vdom.children = vdom.children.map(child => createComponent(child, parent, idx++));\n }\n }\n return vdom;\n}\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.g = (function() {\n\tif (typeof globalThis === 'object') return globalThis;\n\ttry {\n\t\treturn this || new Function('return this')();\n\t} catch (e) {\n\t\tif (typeof window === 'object') return window;\n\t}\n})();","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import app, { Component, customElement } from '../../src/apprun';\n\n@customElement(\"my-counter\")\nclass MyApp extends Component {\n\n view = ({ num, children }) =>
\n

{num}

\n {children}\n
\n\n update = {\n '-1': state => ({...state, num: state.num - 1}),\n '+1': state => ({...state, num: state.num + 1})\n }\n\n mounted = ({ num }, children) => ({ num: parseInt(num), children });\n\n rendered = ({ num }) => {\n this.element.setAttribute('num', num);\n }\n}\n","import app, { Component, customElement } from '../../src/apprun';\n\n// example of async fetch using mounted\n\n@customElement('my-xkcd', {shadow: true, render: false})\nexport default class extends Component {\n state = {};\n\n view = (state) => <>\n
\n {state.loading ?
loading ...
: ''}\n {state.comic && <>\n

{state.comic.title}

\n \n }\n ;\n\n update = {\n 'loading': (_, loading) => ({ loading: true }),\n 'fetchComic': async _ => {\n this.run('loading', true);\n const response = await fetch('https://xkcd-imgs.herokuapp.com/');\n const comic = await response.json();\n return { comic, loading: false };\n }\n };\n\n mounted = () => this.run('fetchComic');\n}"],"sourceRoot":""} \ No newline at end of file diff --git a/demo/app.js b/demo/app.js index fe99712..797d892 100644 --- a/demo/app.js +++ b/demo/app.js @@ -1,2 +1,2 @@ -!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.apprun=e():t.apprun=e()}(this,(function(){return(()=>{"use strict";var __webpack_modules__={740:(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{__webpack_require__.d(__webpack_exports__,{Z:()=>__WEBPACK_DEFAULT_EXPORT__});var _src_apprun__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(107),_state_machine__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__(863);const state={_state:"START",display:"0",arg1:0,arg2:0,op:"",stack:[]},view=({_state:t,op:e,arg1:n,arg2:o,display:a,stack:s})=>_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h(_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.Fragment,null,_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("style",null," ","\n .calculator { width: 200px; }\n .buttons {\n display: grid;\n grid-template-columns: repeat(4, 1fr);\n grid-gap: 2px;\n }\n button { padding: 10px; width:100%; }\n button:nth-of-type(1) {\n grid-column: span 2;\n }\n button:nth-of-type(16) {\n grid-column: span 2;\n }\n "),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("div",{class:"calculator"},_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("h1",null,a),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("div",{class:"buttons",$onclick:button_click},_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"CE"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"+/-"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"/"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"7"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"8"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"9"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"*"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"4"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"5"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"6"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"-"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"1"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"2"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"3"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"+"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"0"),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"."),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("button",null,"=")),_src_apprun__WEBPACK_IMPORTED_MODULE_0__.default.h("small",null,s.length>0&&`${s[0][0]} ${s[0][1]} `,t.startsWith("FIRST_")&&`${a}`,"OP"===t&&`${n} ${e}`,t.startsWith("SECOND_")&&`${n} ${e} ${a}`,"EQ"===t&&`${n} ${e} ${o} = ${a}`))),button_click=(state,e)=>{var _a;const priority={"*":2,"/":2,"+":1,"-":1},getEvent=t=>{switch(t){case"+/-":return"+/-";case"CE":return"CE";case".":return"DOT";case"=":return"EQ";default:return/\d/.test(t)?"NUM":"OP"}},key=(null===(_a=e.target)||void 0===_a?void 0:_a.textContent)||e,event=getEvent(key);let{_state,op,arg1,arg2,display,stack}=state;const clear=()=>{display="0",arg1=arg2=0,op="",stack.length=0},negative=()=>{display=display.startsWith("-")?display.substring(1):"-"+display},calc=()=>{display=eval(`${arg1}${op}${arg2}`).toString()},op1=()=>{op=key,arg1=parseFloat(display)},op2=()=>{if(priority[key]===priority[op])arg2=parseFloat(display),calc(),op=key,arg1=parseFloat(display);else if(priority[key]{arg1=parseFloat(display),calc()},eq2=()=>{if(arg2=parseFloat(display),calc(),stack.length){arg2=parseFloat(display);const f=stack.pop();display=eval(`${f[0]}${f[1]}${display}`).toString(),arg1=f[0],op=f[1]}},state_machine={START:[["NUM","FIRST_ARG",()=>display=key],["DOT","FIRST_ARG_FLOAT",()=>display="0."]],FIRST_ARG:[["+/-","FIRST_ARG",negative],["NUM","FIRST_ARG",()=>display+=key],["DOT","FIRST_ARG_FLOAT",()=>display+=key],["OP","OP",op1],["CE","START",clear]],FIRST_ARG_FLOAT:[["+/-","FIRST_ARG_FLOAT",negative],["NUM","FIRST_ARG_FLOAT",()=>display+=key],["OP","OP",op1],["CE","START",clear]],OP:[["NUM","SECOND_ARG",()=>display=key],["DOT","SECOND_ARG",()=>display="0."],["OP","OP",()=>op=key],["CE","START",clear]],SECOND_ARG:[["+/-","SECOND_ARG",negative],["NUM","SECOND_ARG",()=>display+=key],["DOT","SECOND_ARG_FLOAT",()=>display+=key],["EQ","EQ",eq2],["OP","OP",op2],["CE","OP",()=>display="0"]],SECOND_ARG_FLOAT:[["+/-","SECOND_ARG_FLOAT",negative],["NUM","SECOND_ARG_FLOAT",()=>display+=key],["EQ","EQ",eq2],["OP","OP",op2],["CE","OP",()=>display="0"]],EQ:[["+/-","FIRST_ARG",negative],["NUM","FIRST_ARG",()=>display=key],["DOT","FIRST_ARG_FLOAT",()=>display="0."],["EQ","EQ",eq0],["OP","OP",op1],["CE","START",clear]]},{next_state,transition}=(0,_state_machine__WEBPACK_IMPORTED_MODULE_1__.k)(state_machine,_state,event);return _state=next_state||_state,transition&&transition(),{_state,op,arg1,arg2,display,stack}},update={"#calculator":t=>t},__WEBPACK_DEFAULT_EXPORT__=t=>new _src_apprun__WEBPACK_IMPORTED_MODULE_0__.Component(state,view,update).mount(t)},863:(t,e,n)=>{n.d(e,{k:()=>o});const o=(t,e,n)=>{const o=t[e];if(!o)throw new Error(`No state: ${o} found in state machine`);const a=o.find((t=>t[0]===n));return a?{next_state:a[1],transition:a[2]}:{}}},215:(t,e,n)=>{n.r(e);var o=n(107);let a;const s=({url:t})=>{a.innerHTML="
",$(a.firstChild).load(t)};o.default.on("#",(()=>o.default.render(a,o.default.h(s,{url:"demo/home.html"})))),o.default.on("#new",(()=>o.default.render(a,o.default.h(s,{url:"demo/new.html"}))));const i=t=>o.default.h("div",null,o.default.h("h1",null,t),o.default.h("button",{onclick:()=>o.default.run("DECREASE")},"-1"),o.default.h("button",{onclick:()=>o.default.run("INCREASE")},"+1")),r={"#counter":t=>t,INCREASE:t=>t+1,DECREASE:t=>t-1},l=[],c=({num:t,idx:e})=>o.default.h("div",null,o.default.h("h1",null,t),o.default.h("button",{onclick:()=>o.default.run("-1",e)},"-1"),o.default.h("button",{onclick:()=>o.default.run("+1",e)},"+1"),o.default.h("button",{onclick:()=>o.default.run("remove-counter",e)},"x")),d=({counters:t})=>t.map(((t,e)=>o.default.h(c,{num:t,idx:e}))),u=t=>(console.log(t),o.default.h("div",null,o.default.h("div",null,o.default.h("button",{onclick:()=>o.default.run("history-prev")}," << "),o.default.h("button",{onclick:()=>o.default.run("history-next")}," >> "),o.default.h("button",{onclick:()=>o.default.run("add-counter")},"add counter"),o.default.h("button",{onclick:()=>o.default.run("remove-counter",t.length-1),disabled:t.length<=0},"remove counter")),o.default.h("br",null),o.default.h(d,{counters:t}))),p={"#counters":t=>t,"add-counter":t=>[...t,0],"remove-counter":(t,e)=>[...t.slice(0,e),...t.slice(e+1)],"+1":(t,e)=>[...t.slice(0,e),t[e]+1,...t.slice(e+1)],"-1":(t,e)=>[...t.slice(0,e),t[e]-1,...t.slice(e+1)]};class h extends o.Component{constructor(){super(...arguments),this.model={dragging:!1,position:{x:100,y:100},start:{x:0,y:0}},this.view=t=>{const e={userSelect:"none",cursor:"move",position:"absolute",padding:"50px",border:"1px solid black",color:t.dragging?"gold":"white","background-color":"#3C8D2F",left:`${t.position.x}px`,top:`${t.position.y}px`};return o.app.h("div",{ref:e=>t.el=e,$onpointerdown:"drag",$onpointermove:"move",$onpointerup:"drop",style:e}," Drag me!")},this.update={"#dragdrop":t=>t,drag:(t,e)=>(e.target.setPointerCapture(e.pointerId),Object.assign(Object.assign({},t),{dragging:!0,start:{x:e.pageX,y:e.pageY}})),move:(t,e)=>{if(!t.dragging)return;const n={x:e.pageX,y:e.pageY},o={x:t.position.x+e.pageX-t.start.x,y:t.position.y+e.pageY-t.start.y};return Object.assign(Object.assign({},t),{start:n,position:o})},drop:(t,e)=>(e.target.releasePointerCapture(e.pointerId),Object.assign(Object.assign({},t),{dragging:!1}))},this.unload=({el:t})=>{console.log("dragdrop.unload"),t.onpointerdown=t.onpointerup=t.onpointermove=null}}}var m,_=n(740);!function(t){t[t.all=0]="all",t[t.todo=1]="todo",t[t.done=2]="done"}(m||(m={}));const f=({todo:t,idx:e})=>o.default.h("li",{onclick:()=>g.run("toggle",e),style:{color:t.done?"green":"red",textDecoration:t.done?"line-through":"none",cursor:"pointer"}},t.value),b=t=>{const e=document.getElementById("new-todo");13===t&&e.value&&(g.run("add",e.value),e.value="")},v={"#todo":t=>t,add:(t,e)=>Object.assign(Object.assign({},t),{todos:[...t.todos,{value:e,done:!1}]}),toggle:(t,e)=>Object.assign(Object.assign({},t),{todos:[...t.todos.slice(0,e),Object.assign(Object.assign({},t.todos[e]),{done:!t.todos[e].done}),...t.todos.slice(e+1)]}),filter:(t,e)=>Object.assign(Object.assign({},t),{filter:e}),clear:t=>Object.assign(Object.assign({},t),{todos:[]})};let g=new o.Component({filter:0,todos:[]},(t=>{const e=e=>({"font-weight":t.filter===e?"bold":"normal",cursor:"pointer"});return o.default.h("div",null,o.default.h("h1",null,"Todo"),o.default.h("div",null,o.default.h("span",null,"Show:"),o.default.h("span",null," ",o.default.h("a",{style:e(0),onclick:()=>g.run("filter",0)},"All"))," |",o.default.h("span",null," ",o.default.h("a",{style:e(1),onclick:()=>g.run("filter",1)},"Todo"))," |",o.default.h("span",null," ",o.default.h("a",{style:e(2),onclick:()=>g.run("filter",2)},"Done"))),o.default.h("ul",null,t.todos.filter((e=>0===t.filter||1===t.filter&&!e.done||2===t.filter&&e.done)).map(((t,e)=>o.default.h(f,{todo:t,idx:e})))),o.default.h("div",null,o.default.h("input",{id:"new-todo",placeholder:"add todo",onkeyup:t=>b(t.keyCode)}),o.default.h("button",{onclick:t=>b(13)},"Add"),o.default.h("button",{onclick:()=>g.run("clear")},"Clear")),o.default.h("br",null),o.default.h("div",null,o.default.h("button",{onclick:()=>g.run("todo-undo")}," Undo "),o.default.h("button",{onclick:()=>g.run("todo-redo")}," Redo ")))}),v);function y(t){return Math.round(1e3*Math.random())%t}const w=["pretty","large","big","small","tall","short","long","handsome","plain","quaint","clean","elegant","easy","angry","crazy","helpful","mushy","odd","unsightly","adorable","important","inexpensive","cheap","expensive","fancy"],C=["red","yellow","blue","green","pink","brown","purple","brown","white","black","orange"],E=["table","chair","house","bbq","desk","car","pony","cookie","sandwich","burger","pizza","mouse","keyboard"];let k=1;function O(t){return new Array(t).fill(0).map((t=>({id:k++,label:`${w[y(w.length)]} ${C[y(C.length)]} ${E[y(E.length)]}`})))}const A={run:()=>({data:O(1e3),selected:0}),add:t=>({data:t.data.concat(O(1e3)),selected:t.selected}),runlots:()=>({data:O(1e4),selected:0}),clear:()=>({data:[],selected:0}),update:t=>({data:t.data.map(((t,e)=>(e%10==0&&(t.label=`${t.label} !!!`),t))),selected:t.selected}),swaprows:t=>{if(t.data.length>4){const e=t.data.length-2,n=t.data[1];t.data[1]=t.data[e],t.data[e]=n}return t},select:(t,e)=>Object.assign(Object.assign({},t),{selected:e}),delete:(t,e)=>(t.selected==e&&(t.selected=0),t.data=t.data.filter((t=>t.id!=e)),t)};let x,T;const S=function(t){T=t,x=performance.now()},R=t=>t.closest("tr").id,D=(t,e)=>{const n=e.target;if(n){if(e.preventDefault(),"BUTTON"===n.tagName&&n.id)S(n.id),P.run(n.id);else if(n.matches(".remove")){S("delete");const t=R(n);P.run("delete",t)}else if(n.matches(".lbl")){S("select");const t=R(n);P.run("select",t)}window.setTimeout((function(){const t=performance.now();console.log(T+" took "+(t-x))}),0)}},P=new o.Component({data:[],selected:0},(t=>o.app.h("div",{class:"container",$onclick:D},o.app.h("div",null,o.app.h("button",{id:"run"},"Create 1,000 rows"),o.app.h("button",{id:"runlots"},"Create 10,000 rows"),o.app.h("button",{id:"add"},"Append 1,000 rows"),o.app.h("button",{id:"update"},"Update every 10th row"),o.app.h("button",{id:"clear"},"Clear"),o.app.h("button",{id:"swaprows"},"Swap Rows")),o.app.h("br",null),o.app.h("table",{class:"table table-hover table-striped test-data",id:"main-table"},o.app.h("tbody",null,t.data.map((e=>{const n=e.id==t.selected?"danger":void 0;return o.app.h("tr",{class:n,id:e.id,key:e.id},o.app.h("td",{class:"col-md-1"},e.id),o.app.h("td",{class:"col-md-4"},o.app.h("a",{class:"lbl"},e.label)),o.app.h("td",{class:"col-md-1"},o.app.h("a",{class:"remove"},o.app.h("span",{class:"glyphicon glyphicon-remove remove","aria-hidden":"true"}))),o.app.h("td",{class:"col-md-6"}))})))),o.app.h("span",{class:"preloadicon glyphicon glyphicon-remove hidden","aria-hidden":"true"}))),A);P.unload=()=>{console.log("benchmark.unload")},P.rendered=()=>{let t=[],e=[];const n=document.querySelector("#main-table");function o(t){let e=[];return t.forEach((t=>{"TR"===t.tagName&&(e.push(t),e=e.concat(o(t.childNodes)))})),e}var a=new MutationObserver((function(n){n.forEach((function(n){"childList"===n.type&&(t=t.concat(o(n.addedNodes)),e=e.concat(o(n.removedNodes)))})),console.log("tr addded: ",t.length,"tr removed: ",e.length)}));n.observed||(a.observe(n,{childList:!0,attributes:!0,subtree:!0,characterData:!0}),n.observed=!0)};var M=function(t,e,n,o){var a,s=arguments.length,i=s<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,n):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(t,e,n,o);else for(var r=t.length-1;r>=0;r--)(a=t[r])&&(i=(s<3?a(i):s>3?a(e,n,i):a(e,n))||i);return s>3&&i&&Object.defineProperty(e,n,i),i};class N extends o.Component{constructor(){super(...arguments),this.model="world",this.view=t=>o.default.h("div",null,o.default.h("h1",null,"Hello: ",t),o.default.h("input",{autofocus:!0,oninput:t=>this.run("input",t)})),this.hello=t=>t,this.oninput=(t,e)=>e.target.value}}M([(0,o.on)("#hello")],N.prototype,"hello",void 0),M([(0,o.on)("input")],N.prototype,"oninput",void 0);class j extends o.Component{constructor(){super(...arguments),this.model="world",this.view=t=>o.default.h("div",null,o.default.h("div",null,"Test push state"),o.default.h("h1",null,"Hello: ",t),o.default.h("input",{oninput:t=>this.run("input",t)})),this.hello=(t,e)=>e||t,this.oninput=(t,e)=>(history.pushState(null,null,"#hello-pushstate/"+e.target.value),e.target.value)}}M([(0,o.on)("#hello-pushstate")],j.prototype,"hello",void 0),M([(0,o.on)("input")],j.prototype,"oninput",void 0);class L extends o.Component{constructor(){super(...arguments),this.model="world",this.view=t=>o.default.h("div",null,o.default.h("div",null,"Test delayed event (1s)"),o.default.h("h1",null,"Hello: ",t),o.default.h("input",{oninput:t=>this.run("input",t)})),this.hello=t=>t,this.update={input:[(t,e)=>e.target.value,{delay:1e3,debug:!0}]}}}M([(0,o.on)("#hello-delayed")],L.prototype,"hello",void 0);class I extends o.Component{constructor(){super(...arguments),this.model="world",this.view=t=>o.default.h("div",null,o.default.h("div",null,"Test directive"),o.default.h("h1",null,"Hello: ",t),o.default.h("table",null,o.default.h("tr",null,o.default.h("td",null,"Default event:"),o.default.h("td",null,""),o.default.h("td",null,o.default.h("input",{value:t,$oninput:!0}))),o.default.h("tr",null,o.default.h("td",null,"Named event:"),o.default.h("td",null,""),o.default.h("td",null,o.default.h("input",{value:t,$oninput:"ev1"}))),o.default.h("tr",null,o.default.h("td",null,"Bind:"),o.default.h("td",null,""),o.default.h("td",null,o.default.h("input",{value:t,$bind:!0}))))),this.hello=t=>t,this.oninput=(t,e)=>e.target.value}}M([(0,o.on)("#hello-directive")],I.prototype,"hello",void 0),M([(0,o.on)("oninput, ev1")],I.prototype,"oninput",void 0);var U=n(80);const W=[{id:"yellow",rot:0},{id:"green",rot:60},{id:"magenta",rot:120},{id:"red",rot:180},{id:"cyan",rot:240},{id:"blue",rot:300}];class B extends U.Component{constructor(){super(...arguments),this.state=0,this.view=t=>`
\n

AppRun SVG Carousel

\n \n \n ${W.map((t=>``)).join("")}\n \n \n \n \n \n
It is a reimplementation of a snabbdom example by Jon Kleiser.
\n
`,this.update={"@rot+60":t=>t+60,"@rot-60":t=>t-60,"@reset":()=>0,"#svg":t=>t}}}let F=new B;o.default.on("$",(({key:t,props:e})=>{if("$animation"===t){const n=e[t];"string"==typeof n&&(e.class=`animated ${n}`)}}));class H extends o.Component{constructor(){super(...arguments),this.state={animation:!0},this.view=t=>o.default.h(o.default.Fragment,null,o.default.h("img",{$animation:t.animation&&"bounce infinite",src:"logo.png"}),o.default.h("div",{$animation:"bounceInRight"},o.default.h("button",{disabled:t.animation,$onclick:"start-animation"},"start"),o.default.h("button",{disabled:!t.animation,$onclick:"stop-animation"},"stop"))),this.update={"#animation":t=>t,"start-animation":t=>Object.assign(Object.assign({},t),{animation:!0}),"stop-animation":t=>Object.assign(Object.assign({},t),{animation:!1})}}}const V=[{name:"Hello World ($bind)",code:"// Hello World ($bind)\nconst state = '';\nconst view = state =>
\n

Hello {state}

\n \n
;\napp.start(document.body, state, view);\n"},{name:"Hello World ($on)",code:"// Hello World ($on)\nconst state = '';\nconst view = state => <>\n

Hello {state}

\n \n;\nconst oninput = (_, e) => e.target.value;\napp.start(document.body, state, view);\n"},{name:"Hello World (debounce)",code:"// Hello World (debounce)\nconst state = '';\nconst view = state => <>\n

Hello {state}

\n \n;\nconst oninput = [(_, e) => e.target.value, { delay: 300 }];\napp.start(document.body, state, view, {oninput});\n"},{name:"Clock",code:"// Clock\nconst state = new Date();\nconst view = state =>

{state.toLocaleTimeString()}

;\nconst timer = state => new Date();\nwindow.setInterval(() => { app.run('timer') }, 1000);\napp.start(document.body, state, view, {timer});\n"},{name:"Clock (Component Lifecycle)",code:"// Clock (Component Lifecycle)\nclass Clock extends Component {\n id;\n state = new Date();\n view = state => <>\n

{state.toLocaleTimeString()}

\n \n ;\n update = {\n timer: state => new Date()\n }\n mounted = () => {\n this.id = window.setInterval(() => { this.run('timer') }, 1000);\n console.log('timer started');\n }\n unload = () => {\n window.clearInterval(this.id);\n console.log('timer cleared');\n }\n}\napp.render(document.body, );\n"},{name:"Stopwatch",code:"// Stopwatch\nconst state = {\n id: null,\n start: new Date(),\n elapsed: '0'\n}\nconst view = state =>
\n

{state.elapsed}

\n \n \n
;\n\nconst update = {\n start:state => {\n state.start = new Date();\n state.id = state.id || window.setInterval(() => { app.run('timer') }, 100);\n },\n stop: state => {\n state.id = state.id && window.clearInterval(state.id) && false;\n },\n timer: state => {\n state.elapsed = ((new Date() - state.start) / 1000).toFixed(3) + ' seconds';\n return state\n }\n};\napp.start(document.body, state, view, update);\n"},{name:"Counter (HTML)",code:"// Counter (HTML)\nconst state = 0;\nconst view = state => `
\n

${state}

\n \n \n
`;\nconst update = {\n '+1': state => state + 1,\n '-1': state => state - 1\n};\napp.start(document.body, state, view, update);\n"},{name:"Counter (JSX)",code:"// Counter (JSX)\nconst state = 0;\nconst view = state =>
\n

{state}

\n \n \n
;\nconst update = {\n '+1': state => state + 1,\n '-1': state => state - 1\n};\napp.start(document.body, state, view, update);\n"},{name:"Counter ($onclick)",code:"// Counter ($onclick)\nconst state = 0;\nconst view = state =>
\n

{state}

\n \n \n
;\napp.start(document.body, state, view);\n "},{name:"Counter (Web Component)",code:"// Counter (Web Component)\nclass Counter extends Component {\n state = 0;\n view = state => {\n const add = (state, num) => state + num;\n return <>\n

{state}

\n \n \n ;\n }\n}\napp.webComponent('my-app', Counter);\napp.render(document.body, );\n"},{name:"Async fetch",code:"// Async fetch\nconst state = {};\nconst view = state => <>\n
\n {state.loading &&
loading ...
}\n {state.comic && }\n;\nconst update = {\n 'loading': (state, loading) => ({...state, loading }),\n 'fetchComic': async _ => {\n app.run('loading', true);\n const response = await fetch('https://xkcd-imgs.herokuapp.com/');\n const comic = await response.json();\n return {comic};\n }\n};\napp.start(document.body, state, view, update);\n"},{name:"Custom Directive",code:"// Animation Directive Using animate.css\napp.on('$', ({key, props}) => {\n if (key === '$animation') {\n const value = props[key];\n if (typeof value === 'string') {\n props.class = `animated ${value}`;\n }\n }\n});\n\nconst state = {\n animation: true\n}\n\nconst start_animation = state => ({ animation: true })\nconst stop_animation = state => ({ animation: false })\n\nconst view = state => <>\n \n
\n \n \n
\n\n\napp.start(document.body, state, view);\n"},{name:"Ref - Examples",code:"// Ref - Examples\nconst focus = e => e.focus()\nconst edit = e => e.setAttribute('contenteditable', 'true');\nconst View = () => <>\n \n
\n
\n This text is editable. Click to edit.\n
\n;\n\napp.render(document.body, );\n"},{name:"Child Components",code:"// Child Components\n\nclass Counter extends Component {\n state = 0;\n view = state => (\n
\n

{state}

\n \n \n
\n );\n update = {\n '+1': state => state + 1,\n '-1': state => state - 1\n };\n}\n\nclass App extends Component {\n state = 0;\n view = state => (\n
\n \n
\n \n \n \n
\n );\n update = {\n '+1': state => state + 1,\n };\n}\n\nnew App().start(document.body);\n"},{name:"Element in JSX - canvas",code:"// Element in JSX - canvas\nconst View = () => {\n const canvas = document.createElement('canvas');\n const ctx = canvas.getContext(\"2d\");\n ctx.beginPath();\n ctx.arc(95, 50, 40, 0, 2 * Math.PI);\n ctx.stroke();\n return
\n {canvas}\n
\n}\napp.render(document.body, );\n"},{name:"Shadow DOM",code:"// Shadow DOM\nconst Shadow = (_, children) => {\n const el = document.createElement('section');\n el.attachShadow({ mode: 'open' });\n app.render(el.shadowRoot, children);\n return <>{el};\n};\n\nconst View = () => <>\n
black
\n \n \n
red
\n
red
\n
\n
black
\n\napp.render(document.body, );\n"},{name:"Decorators",code:"// Decorators\n//@customElement decorator creates a web component\n@customElement('my-counter')\nclass Counter extends Component {\n state = 0;\n\n //@on decorator creates an event handler\n @on('+') add = (state, delta) => state + delta;\n\n view = state => <>\n

{state}

\n \n \n ;\n}\n\n//now, create three web components\ndocument.body.append(document.createElement('my-counter'));\ndocument.body.append(document.createElement('my-counter'));\ndocument.body.append(document.createElement('my-counter'));\n"},{name:"Reactivity - getter",code:'// Reactivity - getter\nconst state = {\n a: 1,\n b: 2,\n get c() {\n return this.a + this.b;\n }\n};\nconst view = ({a, b, c}) => <>\n \n \n

{a} + {b} = { c }

\n;\napp.start(document.body, state, view);\n'},{name:"Reactivity - Proxy",code:"// Reactivity - Proxy\nconst handler = {\n get: (target, name) => {\n const text = target.text || '';\n switch (name) {\n case 'text': return target.text;\n case 'characters': return text.replace(/\\s/g, '').length;\n case 'words': return !text ? 0 : text.split(/\\s/).length;\n case 'lines': return text.split('\\n').length;\n default: return null\n }\n }\n};\nconst state = new Proxy(\n { text: \"let's count\" },\n handler\n);\nconst view = state =>
\n \n
chars: {state.characters} words: {state.words} lines: {state.lines}
\n
{state.text}
\n
;\napp.start(document.body, state, view);\n"},{name:"Routing (component event)",code:"// Routing (component event)\nclass Home extends Component {\n view = () =>
Home
;\n update = {'#, #home': state => state };\n}\n\nclass Contact extends Component {\n view = () =>
Contact
;\n update = {'#contact': state => state };\n}\n\nclass About extends Component {\n view = () =>
About
;\n update = {'#about': state => state };\n}\n\nconst App = () => <>\n
\n Home{' | '}\n Contact{' | '}\n About
\n
\n\n\napp.render(document.body, );\n[About, Contact, Home].map(C => new C().start('pages'));\n"},{name:"Routing (mount options)",code:"// Routing (mount options)\nclass Home extends Component {\n view = () =>
Home
;\n}\n\nclass Contact extends Component {\n view = () =>
Contact
;\n}\n\nclass About extends Component {\n view = () =>
About
;\n}\n\nconst App = () => <>\n
\n Home{' | '}\n Contact{' | '}\n About
\n
\n\n\napp.render(document.body, );\n[\n [About, '#about'],\n [Contact, '#contact'],\n [Home, '#, #home'],\n].map(([C, route]) => new C().start('pages', {route}));\n"},{name:"SVG - animation",code:'// SVG - animation\nconst view = () => <>\n \n \n \n \n \n \n \n \n;\n\napp.start(document.body, {}, view);\n'},{name:"SVG - xlink",code:'// SVG - xlink\nconst view = () => \n \n Click => AppRun\n\n\napp.start(document.body, {}, view);\n'},{name:"SVG - $onclick",code:'// SVG - $onclick\nconst view = state => \n \n \n\n\nconst update = {\n test: (state, evt) => alert("You have clicked the " + evt.target.tagName)\n}\napp.start(document.body, \'\', view, update);\n'},{name:"Content Editable",code:'// Content Editable\nconst view = () => <>\n
\n This text is editable. Click to edit.\n
\n \n \n\napp.start(document.body, {}, view);\n'},{name:"List attribute",code:'// List attribute\nconst view = () => <>\n \n \n \n\napp.start(document.body, {}, view);\n'},{name:"Init State as an Async Function",code:"// Init State as an Async Function\nconst state = async () => {\n const response = await fetch('https://xkcd-imgs.herokuapp.com/');\n const comic = await response.json();\n return { comic };\n};\n\nconst view = state => <>\n { state.comic && }\n;\n\napp.start(document.body, state, view);\n"}],K=t=>`\n\n\n \n \n \n \n \n AppRun Playground\n \n \n \n \n\n\n\n\n\n`;\n\nconst tab = ({ code }) => {\n const doc = window.open().document;\n doc.open();\n doc.write(html(code));\n doc.close();\n};\n\nconst run = ({ code }) => {\n let iframe = document.getElementById('iframe') as HTMLIFrameElement;\n iframe.parentNode.replaceChild(iframe.cloneNode(), iframe);\n iframe = document.getElementById('iframe') as HTMLIFrameElement;\n const doc = iframe.contentWindow.document;\n doc.open();\n doc.write(html(code));\n doc.close();\n};\n\nexport class PlayComponent extends Component {\n\n codeEditor = null\n state = {...examples[0], selectedIndex: 0}\n\n view = (state) =>
\n
\n
\n Examples: \n \n
\n
\n \n
\n
\n
\n
\n \n
\n
\n