apprun 3.33.8 → 3.33.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.clinerules +1 -0
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/WHATSNEW.md +59 -0
- package/apprun-cli.js +5 -5
- package/apprun.d.ts +12 -0
- package/dist/apprun-dev-tools.js +1 -1
- package/dist/apprun-dev-tools.js.map +1 -1
- package/dist/apprun-html.esm.js +21 -4
- package/dist/apprun-html.esm.js.map +1 -1
- package/dist/apprun-html.js +1 -1
- package/dist/apprun-html.js.LICENSE.txt +6 -0
- package/dist/apprun-html.js.map +1 -1
- package/dist/apprun-play-html.esm.js +21 -4
- package/dist/apprun-play-html.esm.js.map +1 -1
- package/dist/apprun-play.js +1 -1
- package/dist/apprun-play.js.map +1 -1
- package/dist/apprun.esm.js +1 -1
- package/dist/apprun.esm.js.map +1 -1
- package/dist/apprun.js +1 -1
- package/dist/apprun.js.map +1 -1
- package/esm/app.js +37 -9
- package/esm/app.js.map +1 -1
- package/esm/apprun-code.js.map +1 -1
- package/esm/apprun-dev-tools-tests.js.map +1 -1
- package/esm/apprun-dev-tools.js.map +1 -1
- package/esm/apprun-html.js.map +1 -1
- package/esm/apprun-play.js.map +1 -1
- package/esm/apprun.js +55 -3
- package/esm/apprun.js.map +1 -1
- package/esm/component.js +59 -1
- package/esm/component.js.map +1 -1
- package/esm/decorator.js +33 -0
- package/esm/decorator.js.map +1 -1
- package/esm/directive.js +31 -0
- package/esm/directive.js.map +1 -1
- package/esm/router.js +24 -0
- package/esm/router.js.map +1 -1
- package/esm/types.js +28 -0
- package/esm/types.js.map +1 -1
- package/esm/vdom-lit-html.js +19 -17
- package/esm/vdom-lit-html.js.map +1 -1
- package/esm/vdom-my.js.map +1 -1
- package/esm/vdom-patch.js.map +1 -1
- package/esm/vdom-to-html.js.map +1 -1
- package/esm/vdom.js +25 -0
- package/esm/vdom.js.map +1 -1
- package/esm/web-component.js +32 -0
- package/esm/web-component.js.map +1 -1
- package/index.html +2 -2
- package/jest.config.js +63 -0
- package/jest.setup.js +47 -0
- package/jsx-runtime.js +2 -0
- package/jsx-runtime.js.map +1 -0
- package/package.json +16 -43
- package/react.js +0 -15
- package/rollup.config.js +27 -10
- package/src/app.ts +61 -28
- package/src/apprun.ts +82 -7
- package/src/component.ts +57 -1
- package/src/decorator.ts +34 -1
- package/src/directive.ts +33 -1
- package/src/global.d.ts +22 -0
- package/src/router.ts +26 -1
- package/src/types/apprun.d.ts +56 -0
- package/src/types.ts +30 -1
- package/src/vdom-lit-html.ts +21 -19
- package/src/vdom.ts +26 -2
- package/src/web-component.ts +33 -0
- package/tsconfig.jest.json +27 -3
- package/tsconfig.json +3 -3
- package/webpack.config.cjs +10 -2
|
@@ -1,17 +1,34 @@
|
|
|
1
|
-
class t{constructor(){this._events={}}on(t,n,i={}){this._events[t]=this._events[t]||[],this._events[t].push({fn:n,options:i})}off(t,n){const i=this._events[t]||[];this._events[t]=i.filter((t=>t.fn!==n))}find(t){return this._events[t]}run(t,...n){const i=this.getSubscribers(t,this._events);return console.assert(i&&i.length>0,"No subscriber for event: "+t),i.forEach((i=>{const{fn:e,options:s}=i;return s.delay?this.delay(t,e,n,s):Object.keys(s).length>0?e.apply(this,[...n,s]):e.apply(this,n),!i.options.once})),i.length}once(t,n,i={}){this.on(t,n,Object.assign(Object.assign({},i),{once:!0}))}delay(t,n,i,e){e._t&&clearTimeout(e._t),e._t=setTimeout((()=>{clearTimeout(e._t),Object.keys(e).length>0?n.apply(this,[...i,e]):n.apply(this,i)}),e.delay)}runAsync(t,...n){const i=this.getSubscribers(t,this._events);console.assert(i&&i.length>0,"No subscriber for event: "+t);const e=i.map((t=>{const{fn:i,options:e}=t;return Object.keys(e).length>0?i.apply(this,[...n,e]):i.apply(this,n)}));return Promise.all(e)}query(t,...n){return this.runAsync(t,...n)}getSubscribers(t,n){const i=n[t]||[];return n[t]=i.filter((t=>!t.options.once)),Object.keys(n).filter((n=>n.endsWith("*")&&t.startsWith(n.replace("*","")))).sort(((t,n)=>n.length-t.length)).forEach((e=>i.push(...n[e].map((n=>Object.assign(Object.assign({},n),{options:Object.assign(Object.assign({},n.options),{event:t})})))))),i}}let n;const i="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global;i.app&&i._AppRunVersions?n=i.app:(n=new t,i.app=n,i._AppRunVersions="AppRun-3");var e=n;const s=(t,n)=>(n?t.state[n]:t.state)||"",o=(t,n,i)=>{if(n){const e=t.state||{};e[n]=i,t.setState(e)}else t.setState(i)},r=(t,n)=>{if(Array.isArray(t))return t.map((t=>r(t,n)));{let{type:i,tag:h,props:l,children:c}=t;return h=h||i,c=c||(null==l?void 0:l.children),l&&Object.keys(l).forEach((t=>{t.startsWith("$")&&(((t,n,i,r)=>{if(t.startsWith("$on")){const i=n[t];if(t=t.substring(1),"boolean"==typeof i)n[t]=n=>r.run?r.run(t,n):e.run(t,n);else if("string"==typeof i)n[t]=t=>r.run?r.run(i,t):e.run(i,t);else if("function"==typeof i)n[t]=t=>r.setState(i(r.state,t));else if(Array.isArray(i)){const[s,...o]=i;"string"==typeof s?n[t]=t=>r.run?r.run(s,...o,t):e.run(s,...o,t):"function"==typeof s&&(n[t]=t=>r.setState(s(r.state,...o,t)))}}else if("$bind"===t){const e=n.type||"text",h="string"==typeof n[t]?n[t]:n.name;if("input"===i)switch(e){case"checkbox":n.checked=s(r,h),n.onclick=t=>o(r,h||t.target.name,t.target.checked);break;case"radio":n.checked=s(r,h)===n.value,n.onclick=t=>o(r,h||t.target.name,t.target.value);break;case"number":case"range":n.value=s(r,h),n.oninput=t=>o(r,h||t.target.name,Number(t.target.value));break;default:n.value=s(r,h),n.oninput=t=>o(r,h||t.target.name,t.target.value)}else"select"===i?(n.value=s(r,h),n.onchange=t=>{t.target.multiple||o(r,h||t.target.name,t.target.value)}):"option"===i?(n.selected=s(r,h),n.onclick=t=>o(r,h||t.target.name,t.target.selected)):"textarea"===i&&(n.innerHTML=s(r,h),n.oninput=t=>o(r,h||t.target.name,t.target.value))}else e.run("$",{key:t,tag:i,props:n,component:r})})(t,l,h,n),delete l[t])})),c&&r(c,n),t}};function h(t,...n){return c(n)}const l="_props";function c(t){const n=[],i=t=>{null!=t&&""!==t&&!1!==t&&n.push("function"==typeof t||"object"==typeof t?t:`${t}`)};return t&&t.forEach((t=>{Array.isArray(t)?t.forEach((t=>i(t))):i(t)})),n}function u(t,n,...i){const e=c(i);if("string"==typeof t)return{tag:t,props:n,children:e};if(Array.isArray(t))return t;if(void 0===t&&i)return e;if(Object.getPrototypeOf(t).t)return{tag:t,props:n,children:e};if("function"==typeof t)return t(n,e);throw new Error(`Unknown tag in vdom ${t}`)}const a=new WeakMap,d=(t,n,i={})=>{if(null==n||!1===n)return;!function(t,n,i={}){if(null==n||!1===n)return;if(n=g(n,i),!t)return;const e="SVG"===t.nodeName;Array.isArray(n)?f(t,n,e):f(t,[n],e)}("string"==typeof t&&t?document.getElementById(t)||document.querySelector(t):t,n=r(n,i),i)};function p(t,n,i){3!==n._op&&(i=i||"svg"===n.tag,!function(t,n){const i=t.nodeName,e=`${n.tag||""}`;return i.toUpperCase()===e.toUpperCase()}(t,n)?t.parentNode.replaceChild(m(n,i),t):(!(2&n._op)&&f(t,n.children,i),!(1&n._op)&&b(t,n.props,i)))}function f(t,n,i){var e,s;const o=(null===(e=t.childNodes)||void 0===e?void 0:e.length)||0,r=(null==n?void 0:n.length)||0,h=Math.min(o,r);for(let e=0;e<h;e++){const s=n[e];if(3===s._op)continue;const o=t.childNodes[e];if("string"==typeof s)o.textContent!==s&&(3===o.nodeType?o.nodeValue=s:t.replaceChild(y(s),o));else if(s instanceof HTMLElement||s instanceof SVGElement)t.insertBefore(s,o);else{const n=s.props&&s.props.key;if(n)if(o.key===n)p(t.childNodes[e],s,i);else{const r=a[n];if(r){const n=r.nextSibling;t.insertBefore(r,o),n?t.insertBefore(o,n):t.appendChild(o),p(t.childNodes[e],s,i)}else t.replaceChild(m(s,i),o)}else p(t.childNodes[e],s,i)}}let l=(null===(s=t.childNodes)||void 0===s?void 0:s.length)||0;for(;l>h;)t.removeChild(t.lastChild),l--;if(r>h){const e=document.createDocumentFragment();for(let t=h;t<n.length;t++)e.appendChild(m(n[t],i));t.appendChild(e)}}const v=t=>{const n=document.createElement("section");return n.insertAdjacentHTML("afterbegin",t),Array.from(n.children)};function y(t){if(0===(null==t?void 0:t.indexOf("_html:"))){const n=document.createElement("div");return n.insertAdjacentHTML("afterbegin",t.substring(6)),n}return document.createTextNode(null!=t?t:"")}function m(t,n){if(t instanceof HTMLElement||t instanceof SVGElement)return t;if("string"==typeof t)return y(t);if(!t.tag||"function"==typeof t.tag)return y(JSON.stringify(t));const i=(n=n||"svg"===t.tag)?document.createElementNS("http://www.w3.org/2000/svg",t.tag):document.createElement(t.tag);return b(i,t.props,n),t.children&&t.children.forEach((t=>i.appendChild(m(t,n)))),i}function b(t,n,i){const e=t[l]||{};n=function(t,n){n.class=n.class||n.className,delete n.className;const i={};return t&&Object.keys(t).forEach((t=>i[t]=null)),n&&Object.keys(n).forEach((t=>i[t]=n[t])),i}(e,n||{}),t[l]=n;for(const e in n){const s=n[e];if(e.startsWith("data-")){const n=e.substring(5).replace(/-(\w)/g,(t=>t[1].toUpperCase()));t.dataset[n]!==s&&(s||""===s?t.dataset[n]=s:delete t.dataset[n])}else if("style"===e)if(t.style.cssText&&(t.style.cssText=""),"string"==typeof s)t.style.cssText=s;else for(const n in s)t.style[n]!==s[n]&&(t.style[n]=s[n]);else if(e.startsWith("xlink")){const n=e.replace("xlink","").toLowerCase();null==s||!1===s?t.removeAttributeNS("http://www.w3.org/1999/xlink",n):t.setAttributeNS("http://www.w3.org/1999/xlink",n,s)}else e.startsWith("on")?s&&"function"!=typeof s?"string"==typeof s&&(s?t.setAttribute(e,s):t.removeAttribute(e)):t[e]=s:/^id$|^class$|^list$|^readonly$|^contenteditable$|^role|-|^for$/g.test(e)||i?t.getAttribute(e)!==s&&(s?t.setAttribute(e,s):t.removeAttribute(e)):t[e]!==s&&(t[e]=s);"key"===e&&s&&(a[s]=t)}n&&"function"==typeof n.ref&&window.requestAnimationFrame((()=>n.ref(t)))}function g(t,n,i=0){var e;if("string"==typeof t)return t;if(Array.isArray(t))return t.map((t=>g(t,n,i++)));let s=t;if(t&&"function"==typeof t.tag&&Object.getPrototypeOf(t.tag).t&&(s=function(t,n,i){const{tag:e,props:s,children:o}=t;let r=`_${i}`,h=s&&s.id;h?r=h:h=`_${i}${Date.now()}`;let l="section";s&&s.as&&(l=s.as,delete s.as),n.i||(n.i={});let c=n.i[r];if(c&&c instanceof e&&c.element)c.renderState(c.state);else{const t=document.createElement(l);c=n.i[r]=new e(Object.assign(Object.assign({},s),{children:o})).mount(t,{render:!0})}if(c.mounted){const t=c.mounted(s,o,c.state);void 0!==t&&c.setState(t)}return b(c.element,s,!1),c.element}(t,n,i)),s&&Array.isArray(s.children)){const t=null===(e=s.props)||void 0===e?void 0:e._component;if(t){let n=0;s.children=s.children.map((i=>g(i,t,n++)))}else s.children=s.children.map((t=>g(t,n,i++)))}return s}const w=(t,n={})=>class extends HTMLElement{constructor(){super()}get component(){return this._component}get state(){return this._component.state}static get observedAttributes(){return(n.observedAttributes||[]).map((t=>t.toLowerCase()))}connectedCallback(){if(this.isConnected&&!this._component){const i=n||{};this._shadowRoot=i.shadow?this.attachShadow({mode:"open"}):this;const e=i.observedAttributes||[],s=e.reduce(((t,n)=>{const i=n.toLowerCase();return i!==n&&(t[i]=n),t}),{});this._attrMap=t=>s[t]||t;const o={};Array.from(this.attributes).forEach((t=>o[this._attrMap(t.name)]=t.value)),e.forEach((t=>{void 0!==this[t]&&(o[t]=this[t]),Object.defineProperty(this,t,{get:()=>o[t],set(n){this.attributeChangedCallback(t,o[t],n)},configurable:!0,enumerable:!0})})),requestAnimationFrame((()=>{const n=this.children?Array.from(this.children):[];if(this._component=new t(Object.assign(Object.assign({},o),{children:n})).mount(this._shadowRoot,i),this._component._props=o,this._component.dispatchEvent=this.dispatchEvent.bind(this),this._component.mounted){const t=this._component.mounted(o,n,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!==i.render&&this._component.run(".")}))}}disconnectedCallback(){var t,n,i,e;null===(n=null===(t=this._component)||void 0===t?void 0:t.unload)||void 0===n||n.call(t),null===(e=null===(i=this._component)||void 0===i?void 0:i.unmount)||void 0===e||e.call(i),this._component=null}attributeChangedCallback(t,i,e){if(this._component){const s=this._attrMap(t);this._component._props[s]=e,this._component.run("attributeChanged",s,i,e),e!==i&&!1!==n.render&&window.requestAnimationFrame((()=>{this._component.run(".")}))}}};var $=(t,n,i)=>{"undefined"!=typeof customElements&&customElements.define(t,w(n,i))};const j={meta:new WeakMap,defineMetadata(t,n,i){this.meta.has(i)||this.meta.set(i,{}),this.meta.get(i)[t]=n},getMetadataKeys(t){return t=Object.getPrototypeOf(t),this.meta.get(t)?Object.keys(this.meta.get(t)):[]},getMetadata(t,n){return n=Object.getPrototypeOf(n),this.meta.get(n)?this.meta.get(n)[t]:null}};const x=new Map;e.find("get-components")||e.on("get-components",(t=>t.components=x));const A=t=>t;class O{renderState(t,n=null){if(!this.view)return;let i=n||this.view(t);if(e.debug&&e.run("debug",{component:this,_:i?".":"-",state:t,vdom:i,el:this.element}),"object"!=typeof document)return;const s="string"==typeof this.element&&this.element?document.getElementById(this.element)||document.querySelector(this.element):this.element;if(!s)return;const o="_c";this.unload?s._component===this&&s.getAttribute(o)===this.tracking_id||(this.tracking_id=(new Date).valueOf().toString(),s.setAttribute(o,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:[o]}))):s.removeAttribute&&s.removeAttribute(o),s._component=this,!n&&i&&(i=r(i,this),this.options.transition&&document&&document.startViewTransition?document.startViewTransition((()=>e.render(s,i,this))):e.render(s,i,this)),this.rendered&&this.rendered(this.state)}setState(t,n={render:!0,history:!1}){if(t instanceof Promise)Promise.resolve(t).then((i=>{this.setState(i,n),this._state=t}));else{if(this._state=t,null==t)return;this.state=t,!1!==n.render&&(n.transition&&document&&document.startViewTransition?document.startViewTransition((()=>this.renderState(t))):this.renderState(t)),!1!==n.history&&this.enable_history&&(this._history=[...this._history,t],this._history_idx=this._history.length-1),"function"==typeof n.callback&&n.callback(this.state)}}constructor(n,i,e,s){this.state=n,this.view=i,this.update=e,this.options=s,this._app=new t,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_idx<this._history.length?this.setState(this._history[this._history_idx],{render:!0,history:!1}):this._history_idx=this._history.length-1},this.start=(t=null,n)=>{if(this.mount(t,Object.assign({render:!0},n)),this.mounted&&"function"==typeof this.mounted){const t=this.mounted({},[],this.state);void 0!==t&&this.setState(t)}return this}}mount(t=null,n){var i,s;return console.assert(!this.element,"Component already mounted."),this.options=n=Object.assign(Object.assign({},this.options),n),this.element=t,this.global_event=n.global_event,this.enable_history=!!n.history,this.enable_history&&(this.on(n.history.prev||"history-prev",this._history_prev),this.on(n.history.next||"history-next",this._history_next)),n.route&&(this.update=this.update||{},this.update[n.route]||(this.update[n.route]=A)),this.add_actions(),this.state=null!==(s=null!==(i=this.state)&&void 0!==i?i:this.model)&&void 0!==s?s:{},"function"==typeof this.state&&(this.state=this.state()),this.setState(this.state,{render:!!n.render,history:!0}),e.debug&&(x.get(t)?x.get(t).push(this):x.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,n,i={}){n&&"function"==typeof n&&(i.global&&this._global_events.push(t),this.on(t,((...s)=>{e.debug&&e.run("debug",{component:this,_:">",event:t,p:s,current_state:this.state,options:i});const o=n(this.state,...s);e.debug&&e.run("debug",{component:this,_:"<",event:t,p:s,newState:o,state:this.state,options:i}),this.setState(o,i)}),i))}add_actions(){const t=this.update||{};j.getMetadataKeys(this).forEach((n=>{if(n.startsWith("apprun-update:")){const i=j.getMetadata(n,this);t[i.name]=[this[i.key].bind(this),i.options]}}));const n={};Array.isArray(t)?t.forEach((t=>{const[i,e,s]=t;i.toString().split(",").forEach((t=>n[t.trim()]=[e,s]))})):Object.keys(t).forEach((i=>{const e=t[i];("function"==typeof e||Array.isArray(e))&&i.split(",").forEach((t=>n[t.trim()]=e))})),n["."]||(n["."]=A),Object.keys(n).forEach((t=>{const i=n[t];"function"==typeof i?this.add_action(t,i):Array.isArray(i)&&this.add_action(t,i[0],i[1])}))}run(t,...n){if(this.state instanceof Promise)return Promise.resolve(this.state).then((i=>{this.state=i,this.run(t,...n)}));{const i=t.toString();return this.is_global_event(i)?e.run(i,...n):this._app.run(i,...n)}}on(t,n,i){const s=t.toString();return this._actions.push({name:s,fn:n}),this.is_global_event(s)?e.on(s,n,i):this._app.on(s,n,i)}runAsync(t,...n){const i=t.toString();return this.is_global_event(i)?e.runAsync(i,...n):this._app.runAsync(i,...n)}query(t,...n){return this.runAsync(t,...n)}unmount(){var t;null===(t=this.observer)||void 0===t||t.disconnect(),this._actions.forEach((t=>{const{name:n,fn:i}=t;this.is_global_event(n)?e.off(n,i):this._app.off(n,i)}))}}O.t=!0;const _="//",k="///",E=t=>{if(t||(t="#"),t.startsWith("#")){const[n,...i]=t.split("/");e.run(n,...i)||e.run(k,n,...i),e.run(_,n,...i)}else if(t.startsWith("/")){const[n,i,...s]=t.split("/");e.run("/"+i,...s)||e.run(k,"/"+i,...s),e.run(_,"/"+i,...s)}else e.run(t)||e.run(k,t),e.run(_,t)};if(!e.start){e.h=e.createElement=u,e.render=d,e.Fragment=h,e.webComponent=$,e.safeHTML=v,e.start=(t,n,i,e,s)=>{const o=Object.assign({render:!0,global_event:!0},s),r=new O(n,i,e);return s&&s.rendered&&(r.rendered=s.rendered),s&&s.mounted&&(r.mounted=s.mounted),r.start(t,o),r};const t=t=>{};e.on("$",t),e.on("debug",(n=>t)),e.on(_,t),e.on("#",t),e.route=E,e.on("route",(t=>e.route&&e.route(t))),"object"==typeof document&&document.addEventListener("DOMContentLoaded",(()=>{e.route===E&&(window.onpopstate=()=>E(location.hash),document.body.hasAttribute("apprun-no-init")||e["no-init-route"]||E(location.hash))})),"object"==typeof window&&(window.Component=O,window._React=window.React,window.React=e,window.on=function(t,n={}){return function(i,e){const s=t?t.toString():e;j.defineMetadata(`apprun-update:${s}`,{name:s,key:e,options:n},i)}},window.customElement=function(t,n){return function(i){return $(t,i,n),i}},window.safeHTML=v),e.use_render=(t,n=0)=>e.render=0===n?(n,i)=>t(i,n):(n,i)=>t(n,i),e.use_react=(t,n)=>{e.h=e.createElement=t.createElement,e.Fragment=t.Fragment,e.render=(t,i)=>n.render(i,t),t.version&&t.version.startsWith("18")&&(e.render=(t,i)=>{t&&i&&(t._root||(t._root=n.createRoot(t)),t._root.render(i))})}}
|
|
1
|
+
class t{constructor(){this._events={}}on(t,i,s={}){this._events[t]=this._events[t]||[],this._events[t].push({fn:i,options:s})}off(t,i){const s=this._events[t]||[];this._events[t]=s.filter((t=>t.fn!==i))}find(t){return this._events[t]}run(t,...i){const s=this.getSubscribers(t,this._events);return console.assert(s&&s.length>0,"No subscriber for event: "+t),s.forEach((s=>{const{fn:e,options:n}=s;return n.delay?this.delay(t,e,i,n):Object.keys(n).length>0?e.apply(this,[...i,n]):e.apply(this,i),!s.options.once})),s.length}once(t,i,s={}){this.on(t,i,Object.assign(Object.assign({},s),{once:!0}))}delay(t,i,s,e){e._t&&clearTimeout(e._t),e._t=setTimeout((()=>{clearTimeout(e._t),Object.keys(e).length>0?i.apply(this,[...s,e]):i.apply(this,s)}),e.delay)}runAsync(t,...i){const s=this.getSubscribers(t,this._events);console.assert(s&&s.length>0,"No subscriber for event: "+t);const e=s.map((t=>{const{fn:s,options:e}=t;return Object.keys(e).length>0?s.apply(this,[...i,e]):s.apply(this,i)}));return Promise.all(e)}query(t,...i){return this.runAsync(t,...i)}getSubscribers(t,i){const s=i[t]||[];return i[t]=s.filter((t=>!t.options.once)),Object.keys(i).filter((i=>i.endsWith("*")&&t.startsWith(i.replace("*","")))).sort(((t,i)=>i.length-t.length)).forEach((e=>s.push(...i[e].map((i=>Object.assign(Object.assign({},i),{options:Object.assign(Object.assign({},i.options),{event:t})})))))),s}}let i;const s="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};s.app&&s._AppRunVersions?i=s.app:(i=new t,s.app=i,s._AppRunVersions="AppRun-3");var e=i;const n=(t,i)=>(i?t.state[i]:t.state)||"",o=(t,i,s)=>{if(i){const e=t.state||{};e[i]=s,t.setState(e)}else t.setState(s)},r=(t,i)=>{if(Array.isArray(t))return t.map((t=>r(t,i)));{let{type:s,tag:h,props:c,children:l}=t;return h=h||s,l=l||(null==c?void 0:c.children),c&&Object.keys(c).forEach((t=>{t.startsWith("$")&&(((t,i,s,r)=>{if(t.startsWith("$on")){const s=i[t];if(t=t.substring(1),"boolean"==typeof s)i[t]=i=>r.run?r.run(t,i):e.run(t,i);else if("string"==typeof s)i[t]=t=>r.run?r.run(s,t):e.run(s,t);else if("function"==typeof s)i[t]=t=>r.setState(s(r.state,t));else if(Array.isArray(s)){const[n,...o]=s;"string"==typeof n?i[t]=t=>r.run?r.run(n,...o,t):e.run(n,...o,t):"function"==typeof n&&(i[t]=t=>r.setState(n(r.state,...o,t)))}}else if("$bind"===t){const e=i.type||"text",h="string"==typeof i[t]?i[t]:i.name;if("input"===s)switch(e){case"checkbox":i.checked=n(r,h),i.onclick=t=>o(r,h||t.target.name,t.target.checked);break;case"radio":i.checked=n(r,h)===i.value,i.onclick=t=>o(r,h||t.target.name,t.target.value);break;case"number":case"range":i.value=n(r,h),i.oninput=t=>o(r,h||t.target.name,Number(t.target.value));break;default:i.value=n(r,h),i.oninput=t=>o(r,h||t.target.name,t.target.value)}else"select"===s?(i.value=n(r,h),i.onchange=t=>{t.target.multiple||o(r,h||t.target.name,t.target.value)}):"option"===s?(i.selected=n(r,h),i.onclick=t=>o(r,h||t.target.name,t.target.selected)):"textarea"===s&&(i.innerHTML=n(r,h),i.oninput=t=>o(r,h||t.target.name,t.target.value))}else e.run("$",{key:t,tag:s,props:i,component:r})})(t,c,h,i),delete c[t])})),l&&r(l,i),t}};function h(t,...i){return l(i)}const c="_props";function l(t){const i=[],s=t=>{null!=t&&""!==t&&!1!==t&&i.push("function"==typeof t||"object"==typeof t?t:`${t}`)};return t&&t.forEach((t=>{Array.isArray(t)?t.forEach((t=>s(t))):s(t)})),i}function a(t,i,...s){const e=l(s);if("string"==typeof t)return{tag:t,props:i,children:e};if(Array.isArray(t))return t;if(void 0===t&&s)return e;if(Object.getPrototypeOf(t).i)return{tag:t,props:i,children:e};if("function"==typeof t)return t(i,e);throw new Error(`Unknown tag in vdom ${t}`)}const u=new WeakMap,d=(t,i,s={})=>{if(null==i||!1===i)return;!function(t,i,s={}){if(null==i||!1===i)return;if(i=g(i,s),!t)return;const e="SVG"===t.nodeName;Array.isArray(i)?f(t,i,e):f(t,[i],e)}("string"==typeof t&&t?document.getElementById(t)||document.querySelector(t):t,i=r(i,s),s)};function p(t,i,s){3!==i._op&&(s=s||"svg"===i.tag,!function(t,i){const s=t.nodeName,e=`${i.tag||""}`;return s.toUpperCase()===e.toUpperCase()}(t,i)?t.parentNode.replaceChild(b(i,s),t):(!(2&i._op)&&f(t,i.children,s),!(1&i._op)&&m(t,i.props,s)))}function f(t,i,s){var e,n;const o=(null===(e=t.childNodes)||void 0===e?void 0:e.length)||0,r=(null==i?void 0:i.length)||0,h=Math.min(o,r);for(let e=0;e<h;e++){const n=i[e];if(3===n._op)continue;const o=t.childNodes[e];if("string"==typeof n)o.textContent!==n&&(3===o.nodeType?o.nodeValue=n:t.replaceChild(v(n),o));else if(n instanceof HTMLElement||n instanceof SVGElement)t.insertBefore(n,o);else{const i=n.props&&n.props.key;if(i)if(o.key===i)p(t.childNodes[e],n,s);else{const r=u[i];if(r){const i=r.nextSibling;t.insertBefore(r,o),i?t.insertBefore(o,i):t.appendChild(o),p(t.childNodes[e],n,s)}else t.replaceChild(b(n,s),o)}else p(t.childNodes[e],n,s)}}let c=(null===(n=t.childNodes)||void 0===n?void 0:n.length)||0;for(;c>h;)t.removeChild(t.lastChild),c--;if(r>h){const e=document.createDocumentFragment();for(let t=h;t<i.length;t++)e.appendChild(b(i[t],s));t.appendChild(e)}}const y=t=>{const i=document.createElement("section");return i.insertAdjacentHTML("afterbegin",t),Array.from(i.children)};function v(t){if(0===(null==t?void 0:t.indexOf("_html:"))){const i=document.createElement("div");return i.insertAdjacentHTML("afterbegin",t.substring(6)),i}return document.createTextNode(null!=t?t:"")}function b(t,i){if(t instanceof HTMLElement||t instanceof SVGElement)return t;if("string"==typeof t)return v(t);if(!t.tag||"function"==typeof t.tag)return v(JSON.stringify(t));const s=(i=i||"svg"===t.tag)?document.createElementNS("http://www.w3.org/2000/svg",t.tag):document.createElement(t.tag);return m(s,t.props,i),t.children&&t.children.forEach((t=>s.appendChild(b(t,i)))),s}function m(t,i,s){const e=t[c]||{};i=function(t,i){i.class=i.class||i.className,delete i.className;const s={};return t&&Object.keys(t).forEach((t=>s[t]=null)),Object.keys(i).forEach((t=>s[t]=i[t])),s}(e,i||{}),t[c]=i;for(const e in i){const n=i[e];if(e.startsWith("data-")){const i=e.substring(5).replace(/-(\w)/g,(t=>t[1].toUpperCase()));t.dataset[i]!==n&&(n||""===n?t.dataset[i]=n:delete t.dataset[i])}else if("style"===e)if(t.style.cssText&&(t.style.cssText=""),"string"==typeof n)t.style.cssText=n;else for(const i in n)t.style[i]!==n[i]&&(t.style[i]=n[i]);else if(e.startsWith("xlink")){const i=e.replace("xlink","").toLowerCase();null==n||!1===n?t.removeAttributeNS("http://www.w3.org/1999/xlink",i):t.setAttributeNS("http://www.w3.org/1999/xlink",i,n)}else e.startsWith("on")?n&&"function"!=typeof n?"string"==typeof n&&(n?t.setAttribute(e,n):t.removeAttribute(e)):t[e]=n:/^id$|^class$|^list$|^readonly$|^contenteditable$|^role|-|^for$/g.test(e)||s?t.getAttribute(e)!==n&&(n?t.setAttribute(e,n):t.removeAttribute(e)):t[e]!==n&&(t[e]=n);"key"===e&&n&&(u[n]=t)}i&&"function"==typeof i.ref&&window.requestAnimationFrame((()=>i.ref(t)))}function g(t,i,s=0){var e;if("string"==typeof t)return t;if(Array.isArray(t))return t.map((t=>g(t,i,s++)));let n=t;if(t&&"function"==typeof t.tag&&Object.getPrototypeOf(t.tag).i&&(n=function(t,i,s){const{tag:e,props:n,children:o}=t;let r=`_${s}`,h=n&&n.id;h?r=h:h=`_${s}${Date.now()}`;let c="section";n&&n.as&&(c=n.as,delete n.as),i.v||(i.v={});let l=i.v[r];if(l&&l instanceof e&&l.element)l.renderState(l.state);else{const t=document.createElement(c);l=i.v[r]=new e(Object.assign(Object.assign({},n),{children:o})).mount(t,{render:!0})}if(l.mounted){const t=l.mounted(n,o,l.state);void 0!==t&&l.setState(t)}return m(l.element,n,!1),l.element}(t,i,s)),n&&Array.isArray(n.children)){const t=null===(e=n.props)||void 0===e?void 0:e._component;if(t){let i=0;n.children=n.children.map((s=>g(s,t,i++)))}else n.children=n.children.map((t=>g(t,i,s++)))}return n}const w=(t,i={})=>class extends HTMLElement{constructor(){super()}get component(){return this._component}get state(){return this._component.state}static get observedAttributes(){return(i.observedAttributes||[]).map((t=>t.toLowerCase()))}connectedCallback(){if(this.isConnected&&!this._component){const s=i||{};this._shadowRoot=s.shadow?this.attachShadow({mode:"open"}):this;const e=s.observedAttributes||[],n=e.reduce(((t,i)=>{const s=i.toLowerCase();return s!==i&&(t[s]=i),t}),{});this._attrMap=t=>n[t]||t;const o={};Array.from(this.attributes).forEach((t=>o[this._attrMap(t.name)]=t.value)),e.forEach((t=>{void 0!==this[t]&&(o[t]=this[t]),Object.defineProperty(this,t,{get:()=>o[t],set(i){this.attributeChangedCallback(t,o[t],i)},configurable:!0,enumerable:!0})})),requestAnimationFrame((()=>{const i=this.children?Array.from(this.children):[];if(this._component=new t(Object.assign(Object.assign({},o),{children:i})).mount(this._shadowRoot,s),this._component._props=o,this._component.dispatchEvent=this.dispatchEvent.bind(this),this._component.mounted){const t=this._component.mounted(o,i,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!==s.render&&this._component.run(".")}))}}disconnectedCallback(){var t,i,s,e;null===(i=null===(t=this._component)||void 0===t?void 0:t.unload)||void 0===i||i.call(t),null===(e=null===(s=this._component)||void 0===s?void 0:s.unmount)||void 0===e||e.call(s),this._component=null}attributeChangedCallback(t,s,e){if(this._component){const n=this._attrMap(t);this._component._props[n]=e,this._component.run("attributeChanged",n,s,e),e!==s&&!1!==i.render&&window.requestAnimationFrame((()=>{this._component.run(".")}))}}};var $=(t,i,s)=>{"undefined"!=typeof customElements&&customElements.define(t,w(i,s))};const S={meta:new WeakMap,defineMetadata(t,i,s){this.meta.has(s)||this.meta.set(s,{}),this.meta.get(s)[t]=i},getMetadataKeys(t){return t=Object.getPrototypeOf(t),this.meta.get(t)?Object.keys(this.meta.get(t)):[]},getMetadata(t,i){return i=Object.getPrototypeOf(i),this.meta.get(i)?this.meta.get(i)[t]:null}};const A=new Map;e.find("get-components")||e.on("get-components",(t=>t.components=A));const j=t=>t;class x{renderState(t,i=null){if(!this.view)return;let s=i||this.view(t);if(e.debug&&e.run("debug",{component:this,_:s?".":"-",state:t,vdom:s,el:this.element}),"object"!=typeof document)return;const n="string"==typeof this.element&&this.element?document.getElementById(this.element)||document.querySelector(this.element):this.element;if(!n)return;const o="_c";this.unload?n._component===this&&n.getAttribute(o)===this.tracking_id||(this.tracking_id=(new Date).valueOf().toString(),n.setAttribute(o,this.tracking_id),"undefined"!=typeof MutationObserver&&(this.observer||(this.observer=new MutationObserver((t=>{t[0].oldValue!==this.tracking_id&&document.body.contains(n)||(this.unload(this.state),this.observer.disconnect(),this.observer=null)}))),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeOldValue:!0,attributeFilter:[o]}))):n.removeAttribute&&n.removeAttribute(o),n._component=this,!i&&s&&(s=r(s,this),this.options.transition&&document&&document.startViewTransition?document.startViewTransition((()=>e.render(n,s,this))):e.render(n,s,this)),this.rendered&&this.rendered(this.state)}setState(t,i={render:!0,history:!1}){const s=async t=>{try{for(;;){const{value:s,done:e}=await t.next();if(e)break;this.setState(s,i)}}catch(t){console.error("Error in async iterator:",t)}},e=t;if(null==e?void 0:e[Symbol.asyncIterator])this.setState(s(e[Symbol.asyncIterator]()),i);else if((null==e?void 0:e[Symbol.iterator])&&"function"==typeof e.next)for(const t of e)this.setState(t,i);else if(t&&t instanceof Promise)Promise.resolve(t).then((s=>{this.setState(s,i),this._state=t}));else{if(this._state=t,null==t)return;this.state=t,!1!==i.render&&(i.transition&&document&&document.startViewTransition?document.startViewTransition((()=>this.renderState(t))):this.renderState(t)),!1!==i.history&&this.enable_history&&(this._history=[...this._history,t],this._history_idx=this._history.length-1),"function"==typeof i.callback&&i.callback(this.state)}}constructor(i,s,e,n){this.state=i,this.view=s,this.update=e,this.options=n,this._app=new t,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_idx<this._history.length?this.setState(this._history[this._history_idx],{render:!0,history:!1}):this._history_idx=this._history.length-1},this.start=(t=null,i)=>{if(this.mount(t,Object.assign({render:!0},i)),this.mounted&&"function"==typeof this.mounted){const t=this.mounted({},[],this.state);void 0!==t&&this.setState(t)}return this}}mount(t=null,i){var s,n;return console.assert(!this.element,"Component already mounted."),this.options=i=Object.assign(Object.assign({},this.options),i),this.element=t,this.global_event=i.global_event,this.enable_history=!!i.history,this.enable_history&&(this.on(i.history.prev||"history-prev",this._history_prev),this.on(i.history.next||"history-next",this._history_next)),i.route&&(this.update=this.update||{},this.update[i.route]||(this.update[i.route]=j)),this.add_actions(),this.state=null!==(n=null!==(s=this.state)&&void 0!==s?s:this.model)&&void 0!==n?n:{},"function"==typeof this.state&&(this.state=this.state()),this.setState(this.state,{render:!!i.render,history:!0}),e.debug&&(A.get(t)?A.get(t).push(this):A.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,i,s={}){i&&"function"==typeof i&&(s.global&&this._global_events.push(t),this.on(t,((...n)=>{e.debug&&e.run("debug",{component:this,_:">",event:t,p:n,current_state:this.state,options:s});const o=i(this.state,...n);e.debug&&e.run("debug",{component:this,_:"<",event:t,p:n,newState:o,state:this.state,options:s}),this.setState(o,s)}),s))}add_actions(){const t=this.update||{};S.getMetadataKeys(this).forEach((i=>{if(i.startsWith("apprun-update:")){const s=S.getMetadata(i,this);t[s.name]=[this[s.key].bind(this),s.options]}}));const i={};Array.isArray(t)?t.forEach((t=>{const[s,e,n]=t;s.toString().split(",").forEach((t=>i[t.trim()]=[e,n]))})):Object.keys(t).forEach((s=>{const e=t[s];("function"==typeof e||Array.isArray(e))&&s.split(",").forEach((t=>i[t.trim()]=e))})),i["."]||(i["."]=j),Object.keys(i).forEach((t=>{const s=i[t];"function"==typeof s?this.add_action(t,s):Array.isArray(s)&&this.add_action(t,s[0],s[1])}))}run(t,...i){if(this.state instanceof Promise)return Promise.resolve(this.state).then((s=>{this.state=s,this.run(t,...i)}));{const s=t.toString();return this.is_global_event(s)?e.run(s,...i):this._app.run(s,...i)}}on(t,i,s){const n=t.toString();return this._actions.push({name:n,fn:i}),this.is_global_event(n)?e.on(n,i,s):this._app.on(n,i,s)}runAsync(t,...i){const s=t.toString();return this.is_global_event(s)?e.runAsync(s,...i):this._app.runAsync(s,...i)}query(t,...i){return this.runAsync(t,...i)}unmount(){var t;null===(t=this.observer)||void 0===t||t.disconnect(),this._actions.forEach((t=>{const{name:i,fn:s}=t;this.is_global_event(i)?e.off(i,s):this._app.off(i,s)}))}}x.i=!0;const O="//",_="///",k=t=>{if(t||(t="#"),t.startsWith("#")){const[i,...s]=t.split("/");e.run(i,...s)||e.run(_,i,...s),e.run(O,i,...s)}else if(t.startsWith("/")){const[i,s,...n]=t.split("/");e.run("/"+s,...n)||e.run(_,"/"+s,...n),e.run(O,"/"+s,...n)}else e.run(t)||e.run(_,t),e.run(O,t)};if(!e.start){e.h=e.createElement=a,e.render=d,e.Fragment=h,e.webComponent=$,e.safeHTML=y,e.start=(t,i,s,e,n)=>{const o=Object.assign({render:!0,global_event:!0},n),r=new x(i,s,e);return n&&n.rendered&&(r.rendered=n.rendered),n&&n.mounted&&(r.mounted=n.mounted),r.start(t,o),r};const t=t=>{};e.on("$",t),e.on("debug",(i=>t)),e.on(O,t),e.on("#",t),e.route=k,e.on("route",(t=>e.route&&e.route(t))),"object"==typeof document&&document.addEventListener("DOMContentLoaded",(()=>{e.route===k&&(window.onpopstate=()=>k(location.hash),document.body.hasAttribute("apprun-no-init")||e["no-init-route"]||k(location.hash))})),"object"==typeof window&&(window.Component=x,window._React=window.React,window.React=e,window.on=function(t,i={}){return function(s,e){const n=t?t.toString():e;S.defineMetadata(`apprun-update:${n}`,{name:n,key:e,options:i},s)}},window.customElement=function(t,i){return function(s){return $(t,s,i),s}},window.safeHTML=y),e.use_render=(t,i=0)=>{e.render=0===i?(i,s)=>t(s,i):(i,s)=>t(i,s)},e.use_react=(t,i)=>{e.h=e.createElement=t.createElement,e.Fragment=t.Fragment,e.render=(t,s)=>i.render(s,t),t.version&&t.version.startsWith("18")&&(e.render=(t,s)=>{t&&s&&(t._root||(t._root=i.createRoot(t)),t._root.render(s))})},e.use_prettyLink=()=>{window.onload=()=>e.route(location.pathname),window.addEventListener("popstate",(()=>e.route(location.pathname))),document.body.addEventListener("click",(t=>{const i=t.target,s="A"===i.tagName?i:i.closest("a");s&&s.origin===location.origin&&(t.preventDefault(),history.pushState(null,"",s.pathname),e.route(s.pathname))}))}}
|
|
2
|
+
/**
|
|
3
|
+
* @license
|
|
4
|
+
* Copyright 2019 Google LLC
|
|
5
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
6
|
+
*/const C=globalThis,E=C.ShadowRoot&&(void 0===C.ShadyCSS||C.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,M=Symbol(),P=new WeakMap;let T=class{constructor(t,i,s){if(this._$cssResult$=!0,s!==M)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=i}get styleSheet(){let t=this.o;const i=this.t;if(E&&void 0===t){const s=void 0!==i&&1===i.length;s&&(t=P.get(i)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),s&&P.set(i,t))}return t}toString(){return this.cssText}};const U=E?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let i="";for(const s of t.cssRules)i+=s.cssText;return(t=>new T("string"==typeof t?t:t+"",void 0,M))(i)})(t):t
|
|
7
|
+
/**
|
|
8
|
+
* @license
|
|
9
|
+
* Copyright 2017 Google LLC
|
|
10
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
11
|
+
*/,{is:N,defineProperty:R,getOwnPropertyDescriptor:z,getOwnPropertyNames:D,getOwnPropertySymbols:L,getPrototypeOf:B}=Object,H=globalThis,q=H.trustedTypes,I=q?q.emptyScript:"",W=H.reactiveElementPolyfillSupport,F=(t,i)=>t,V={toAttribute(t,i){switch(i){case Boolean:t=t?I:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,i){let s=t;switch(i){case Boolean:s=null!==t;break;case Number:s=null===t?null:Number(t);break;case Object:case Array:try{s=JSON.parse(t)}catch(t){s=null}}return s}},G=(t,i)=>!N(t,i),J={attribute:!0,type:String,converter:V,reflect:!1,useDefault:!1,hasChanged:G};Symbol.metadata??=Symbol("metadata"),H.litPropertyMetadata??=new WeakMap;let K=class extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,i=J){if(i.state&&(i.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((i=Object.create(i)).wrapped=!0),this.elementProperties.set(t,i),!i.noAccessor){const s=Symbol(),e=this.getPropertyDescriptor(t,s,i);void 0!==e&&R(this.prototype,t,e)}}static getPropertyDescriptor(t,i,s){const{get:e,set:n}=z(this.prototype,t)??{get(){return this[i]},set(t){this[i]=t}};return{get:e,set(i){const o=e?.call(this);n?.call(this,i),this.requestUpdate(t,o,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??J}static _$Ei(){if(this.hasOwnProperty(F("elementProperties")))return;const t=B(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(F("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(F("properties"))){const t=this.properties,i=[...D(t),...L(t)];for(const s of i)this.createProperty(s,t[s])}const t=this[Symbol.metadata];if(null!==t){const i=litPropertyMetadata.get(t);if(void 0!==i)for(const[t,s]of i)this.elementProperties.set(t,s)}this._$Eh=new Map;for(const[t,i]of this.elementProperties){const s=this._$Eu(t,i);void 0!==s&&this._$Eh.set(s,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const i=[];if(Array.isArray(t)){const s=new Set(t.flat(1/0).reverse());for(const t of s)i.unshift(U(t))}else void 0!==t&&i.push(U(t));return i}static _$Eu(t,i){const s=i.attribute;return!1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach((t=>t(this)))}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.()}removeController(t){this._$EO?.delete(t)}_$E_(){const t=new Map,i=this.constructor.elementProperties;for(const s of i.keys())this.hasOwnProperty(s)&&(t.set(s,this[s]),delete this[s]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return((t,i)=>{if(E)t.adoptedStyleSheets=i.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet));else for(const s of i){const i=document.createElement("style"),e=C.litNonce;void 0!==e&&i.setAttribute("nonce",e),i.textContent=s.cssText,t.appendChild(i)}})(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach((t=>t.hostConnected?.()))}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach((t=>t.hostDisconnected?.()))}attributeChangedCallback(t,i,s){this._$AK(t,s)}_$ET(t,i){const s=this.constructor.elementProperties.get(t),e=this.constructor._$Eu(t,s);if(void 0!==e&&!0===s.reflect){const n=(void 0!==s.converter?.toAttribute?s.converter:V).toAttribute(i,s.type);this._$Em=t,null==n?this.removeAttribute(e):this.setAttribute(e,n),this._$Em=null}}_$AK(t,i){const s=this.constructor,e=s._$Eh.get(t);if(void 0!==e&&this._$Em!==e){const t=s.getPropertyOptions(e),n="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:V;this._$Em=e,this[e]=n.fromAttribute(i,t.type)??this._$Ej?.get(e)??null,this._$Em=null}}requestUpdate(t,i,s){if(void 0!==t){const e=this.constructor,n=this[t];if(s??=e.getPropertyOptions(t),!((s.hasChanged??G)(n,i)||s.useDefault&&s.reflect&&n===this._$Ej?.get(t)&&!this.hasAttribute(e._$Eu(t,s))))return;this.C(t,i,s)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(t,i,{useDefault:s,reflect:e,wrapped:n},o){s&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,o??i??this[t]),!0!==n||void 0!==o)||(this._$AL.has(t)||(this.hasUpdated||s||(i=void 0),this._$AL.set(t,i)),!0===e&&this._$Em!==t&&(this._$Eq??=new Set).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,i]of this._$Ep)this[t]=i;this._$Ep=void 0}const t=this.constructor.elementProperties;if(t.size>0)for(const[i,s]of t){const{wrapped:t}=s,e=this[i];!0!==t||this._$AL.has(i)||void 0===e||this.C(i,void 0,s,e)}}let t=!1;const i=this._$AL;try{t=this.shouldUpdate(i),t?(this.willUpdate(i),this._$EO?.forEach((t=>t.hostUpdate?.())),this.update(i)):this._$EM()}catch(i){throw t=!1,this._$EM(),i}t&&this._$AE(i)}willUpdate(t){}_$AE(t){this._$EO?.forEach((t=>t.hostUpdated?.())),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&=this._$Eq.forEach((t=>this._$ET(t,this[t]))),this._$EM()}updated(t){}firstUpdated(t){}};K.elementStyles=[],K.shadowRootOptions={mode:"open"},K[F("elementProperties")]=new Map,K[F("finalized")]=new Map,W?.({ReactiveElement:K}),(H.reactiveElementVersions??=[]).push("2.1.0");
|
|
12
|
+
/**
|
|
13
|
+
* @license
|
|
14
|
+
* Copyright 2017 Google LLC
|
|
15
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
16
|
+
*/
|
|
17
|
+
const X=globalThis,Z=X.trustedTypes,Y=Z?Z.createPolicy("lit-html",{createHTML:t=>t}):void 0,Q="$lit$",tt=`lit$${Math.random().toFixed(9).slice(2)}$`,it="?"+tt,st=`<${it}>`,et=document,nt=()=>et.createComment(""),ot=t=>null===t||"object"!=typeof t&&"function"!=typeof t,rt=Array.isArray,ht="[ \t\n\f\r]",ct=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,lt=/-->/g,at=/>/g,ut=RegExp(`>|${ht}(?:([^\\s"'>=/]+)(${ht}*=${ht}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),dt=/'/g,pt=/"/g,ft=/^(?:script|style|textarea|title)$/i,yt=t=>(i,...s)=>({_$litType$:t,strings:i,values:s}),vt=yt(1),bt=yt(2),mt=Symbol.for("lit-noChange"),gt=Symbol.for("lit-nothing"),wt=new WeakMap,$t=et.createTreeWalker(et,129);function St(t,i){if(!rt(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==Y?Y.createHTML(i):i}const At=(t,i)=>{const s=t.length-1,e=[];let n,o=2===i?"<svg>":3===i?"<math>":"",r=ct;for(let i=0;i<s;i++){const s=t[i];let h,c,l=-1,a=0;for(;a<s.length&&(r.lastIndex=a,c=r.exec(s),null!==c);)a=r.lastIndex,r===ct?"!--"===c[1]?r=lt:void 0!==c[1]?r=at:void 0!==c[2]?(ft.test(c[2])&&(n=RegExp("</"+c[2],"g")),r=ut):void 0!==c[3]&&(r=ut):r===ut?">"===c[0]?(r=n??ct,l=-1):void 0===c[1]?l=-2:(l=r.lastIndex-c[2].length,h=c[1],r=void 0===c[3]?ut:'"'===c[3]?pt:dt):r===pt||r===dt?r=ut:r===lt||r===at?r=ct:(r=ut,n=void 0);const u=r===ut&&t[i+1].startsWith("/>")?" ":"";o+=r===ct?s+st:l>=0?(e.push(h),s.slice(0,l)+Q+s.slice(l)+tt+u):s+tt+(-2===l?i:u)}return[St(t,o+(t[s]||"<?>")+(2===i?"</svg>":3===i?"</math>":"")),e]};class jt{constructor({strings:t,_$litType$:i},s){let e;this.parts=[];let n=0,o=0;const r=t.length-1,h=this.parts,[c,l]=At(t,i);if(this.el=jt.createElement(c,s),$t.currentNode=this.el.content,2===i||3===i){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(e=$t.nextNode())&&h.length<r;){if(1===e.nodeType){if(e.hasAttributes())for(const t of e.getAttributeNames())if(t.endsWith(Q)){const i=l[o++],s=e.getAttribute(t).split(tt),r=/([.?@])?(.*)/.exec(i);h.push({type:1,index:n,name:r[2],strings:s,ctor:"."===r[1]?Ct:"?"===r[1]?Et:"@"===r[1]?Mt:kt}),e.removeAttribute(t)}else t.startsWith(tt)&&(h.push({type:6,index:n}),e.removeAttribute(t));if(ft.test(e.tagName)){const t=e.textContent.split(tt),i=t.length-1;if(i>0){e.textContent=Z?Z.emptyScript:"";for(let s=0;s<i;s++)e.append(t[s],nt()),$t.nextNode(),h.push({type:2,index:++n});e.append(t[i],nt())}}}else if(8===e.nodeType)if(e.data===it)h.push({type:2,index:n});else{let t=-1;for(;-1!==(t=e.data.indexOf(tt,t+1));)h.push({type:7,index:n}),t+=tt.length-1}n++}}static createElement(t,i){const s=et.createElement("template");return s.innerHTML=t,s}}function xt(t,i,s=t,e){if(i===mt)return i;let n=void 0!==e?s._$Co?.[e]:s._$Cl;const o=ot(i)?void 0:i._$litDirective$;return n?.constructor!==o&&(n?._$AO?.(!1),void 0===o?n=void 0:(n=new o(t),n._$AT(t,s,e)),void 0!==e?(s._$Co??=[])[e]=n:s._$Cl=n),void 0!==n&&(i=xt(t,n._$AS(t,i.values),n,e)),i}class Ot{constructor(t,i){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=i}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:i},parts:s}=this._$AD,e=(t?.creationScope??et).importNode(i,!0);$t.currentNode=e;let n=$t.nextNode(),o=0,r=0,h=s[0];for(;void 0!==h;){if(o===h.index){let i;2===h.type?i=new _t(n,n.nextSibling,this,t):1===h.type?i=new h.ctor(n,h.name,h.strings,this,t):6===h.type&&(i=new Pt(n,this,t)),this._$AV.push(i),h=s[++r]}o!==h?.index&&(n=$t.nextNode(),o++)}return $t.currentNode=et,e}p(t){let i=0;for(const s of this._$AV)void 0!==s&&(void 0!==s.strings?(s._$AI(t,s,i),i+=s.strings.length-2):s._$AI(t[i])),i++}}class _t{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,i,s,e){this.type=2,this._$AH=gt,this._$AN=void 0,this._$AA=t,this._$AB=i,this._$AM=s,this.options=e,this._$Cv=e?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode;const i=this._$AM;return void 0!==i&&11===t?.nodeType&&(t=i.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,i=this){t=xt(this,t,i),ot(t)?t===gt||null==t||""===t?(this._$AH!==gt&&this._$AR(),this._$AH=gt):t!==this._$AH&&t!==mt&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):(t=>rt(t)||"function"==typeof t?.[Symbol.iterator])(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==gt&&ot(this._$AH)?this._$AA.nextSibling.data=t:this.T(et.createTextNode(t)),this._$AH=t}$(t){const{values:i,_$litType$:s}=t,e="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=jt.createElement(St(s.h,s.h[0]),this.options)),s);if(this._$AH?._$AD===e)this._$AH.p(i);else{const t=new Ot(e,this),s=t.u(this.options);t.p(i),this.T(s),this._$AH=t}}_$AC(t){let i=wt.get(t.strings);return void 0===i&&wt.set(t.strings,i=new jt(t)),i}k(t){rt(this._$AH)||(this._$AH=[],this._$AR());const i=this._$AH;let s,e=0;for(const n of t)e===i.length?i.push(s=new _t(this.O(nt()),this.O(nt()),this,this.options)):s=i[e],s._$AI(n),e++;e<i.length&&(this._$AR(s&&s._$AB.nextSibling,e),i.length=e)}_$AR(t=this._$AA.nextSibling,i){for(this._$AP?.(!1,!0,i);t&&t!==this._$AB;){const i=t.nextSibling;t.remove(),t=i}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t))}}class kt{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,i,s,e,n){this.type=1,this._$AH=gt,this._$AN=void 0,this.element=t,this.name=i,this._$AM=e,this.options=n,s.length>2||""!==s[0]||""!==s[1]?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=gt}_$AI(t,i=this,s,e){const n=this.strings;let o=!1;if(void 0===n)t=xt(this,t,i,0),o=!ot(t)||t!==this._$AH&&t!==mt,o&&(this._$AH=t);else{const e=t;let r,h;for(t=n[0],r=0;r<n.length-1;r++)h=xt(this,e[s+r],i,r),h===mt&&(h=this._$AH[r]),o||=!ot(h)||h!==this._$AH[r],h===gt?t=gt:t!==gt&&(t+=(h??"")+n[r+1]),this._$AH[r]=h}o&&!e&&this.j(t)}j(t){t===gt?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class Ct extends kt{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===gt?void 0:t}}class Et extends kt{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==gt)}}class Mt extends kt{constructor(t,i,s,e,n){super(t,i,s,e,n),this.type=5}_$AI(t,i=this){if((t=xt(this,t,i,0)??gt)===mt)return;const s=this._$AH,e=t===gt&&s!==gt||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,n=t!==gt&&(s===gt||e);e&&this.element.removeEventListener(this.name,this,s),n&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t)}}class Pt{constructor(t,i,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=i,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){xt(this,t)}}const Tt=X.litHtmlPolyfillSupport;Tt?.(jt,_t),(X.litHtmlVersions??=[]).push("3.3.0");const Ut=(t,i,s)=>{const e=s?.renderBefore??i;let n=e._$litPart$;if(void 0===n){const t=s?.renderBefore??null;e._$litPart$=n=new _t(i.insertBefore(nt(),t),t,void 0,s??{})}return n._$AI(t),n
|
|
2
18
|
/**
|
|
3
19
|
* @license
|
|
4
20
|
* Copyright 2017 Google LLC
|
|
5
21
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
6
|
-
*/
|
|
22
|
+
*/},Nt=globalThis;let Rt=class extends K{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){const t=super.createRenderRoot();return this.renderOptions.renderBefore??=t.firstChild,t}update(t){const i=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=Ut(i,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return mt}};Rt._$litElement$=!0,Rt.finalized=!0,Nt.litElementHydrateSupport?.({LitElement:Rt});const zt=Nt.litElementPolyfillSupport;zt?.({LitElement:Rt}),(Nt.litElementVersions??=[]).push("4.2.0");
|
|
7
23
|
/**
|
|
8
24
|
* @license
|
|
9
25
|
* Copyright 2017 Google LLC
|
|
10
26
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
11
|
-
*/
|
|
27
|
+
*/
|
|
28
|
+
const Dt=2,Lt=5,Bt=t=>(...i)=>({_$litDirective$:t,values:i});class Ht{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,i,s){this._$Ct=t,this._$AM=i,this._$Ci=s}_$AS(t,i){return this.update(t,i)}update(t,i){return this.render(...i)}}
|
|
12
29
|
/**
|
|
13
30
|
* @license
|
|
14
31
|
* Copyright 2017 Google LLC
|
|
15
32
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
16
|
-
*/class
|
|
33
|
+
*/class qt extends Ht{constructor(t){if(super(t),this.it=gt,t.type!==Dt)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===gt||null==t)return this._t=void 0,this.it=t;if(t===mt)return t;if("string"!=typeof t)throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.it)return this._t;this.it=t;const i=[t];return i.raw=i,this._t={_$litType$:this.constructor.resultType,strings:i,values:[]}}}qt.directiveName="unsafeHTML",qt.resultType=1;const It=Bt(qt);const Wt=Bt(class extends Ht{constructor(t){if(super(t),t.type!==Lt)throw new Error("run() can only be used in event handlers")}update(t,i){const s=t.element,n=t.name,[o,...r]=i,h=()=>{let t=s,i=t._component;for(;!i&&t;)t=t.parentElement,i=t&&t._component;return console.assert(!!i,"Component not found."),i};return"string"==typeof o?s[`on${n}`]=t=>{const i=h();i?i.run(o,...r,t):e.run(o,...r,t)}:"function"==typeof o&&(s[`on${n}`]=t=>h().setState(o(h().state,...r,t))),this.render()}render(){return mt}});e.createElement=a,e.render=function(t,i,s){i&&("string"==typeof i?(t._$litPart$||t.replaceChildren(),Ut(vt`${It(i)}`,t)):i._$litType$?(t._$litPart$||t.replaceChildren(),Ut(i,t)):(d(t,i,s),t._$litPart$=void 0))},e.Fragment=h,"object"==typeof window&&(window.React=window._React||e,window.html=vt,window.svg=bt,window.run=Wt);const Ft=(t,i,s,e)=>{if(!i||!s)return;const n=t=>{var s,e;const n=i.cloneNode();null===(s=i.parentNode)||void 0===s||s.replaceChild(n,i);const o=null===(e=(i=n).contentWindow)||void 0===e?void 0:e.document;o&&(o.open(),t.indexOf("<html")>=0?o.write(t):o.write((t=>`<!DOCTYPE html>\n<html lang="en">\n<head>\n <meta charset="UTF-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <meta http-equiv="X-UA-Compatible" content="ie=edge">\n <script src="https://cdnjs.cloudflare.com/ajax/libs/custom-elements/1.1.2/custom-elements.min.js"><\/script>\n <title>AppRun Playground</title>\n <style>\n body {\n font-family: "Benton Sans", "Helvetica Neue", helvetica, arial, sans-serif;\n margin: 2em;\n }\n </style>\n <script src="https://unpkg.com/@babel/standalone/babel.min.js"><\/script>\n <script src="https://unpkg.com/apprun/dist/apprun-html.js"><\/script>\n</head>\n<body>\n<script>\n Babel.registerPlugin("d", [Babel.availablePlugins["proposal-decorators"], {legacy: true}]);\n Babel.registerPlugin("c", [Babel.availablePlugins["proposal-class-properties"], {loose: true}]);\n Babel.registerPlugin("b", [Babel.availablePlugins["proposal-private-methods"], {loose: true}]);\n<\/script>\n<script type="text/babel" data-plugins="d, c, b">\n ${t}\n<\/script>\n</body>\n</html>`)(t)),o.close())};n(s),!e&&t&&"TEXTAREA"===t.nodeName&&("undefined"==typeof CodeMirror?t.onkeyup=()=>n(t.value):t.editor||(t.editor=CodeMirror.fromTextArea(t,{lineNumbers:!0,mode:"jsx"}),t.editor.on("change",(t=>n(t.getValue())))))};e.webComponent("apprun-play",class extends x{constructor(){super(...arguments),this.view=t=>{const i=t["code-element"],s=this.element;let e,n;return e=i?document.querySelector(i):s.previousElementSibling||s.parentElement.previousElementSibling,n=(null==e?void 0:e.innerText)||(null==e?void 0:e.value)||t.code,this.state.code_area=e,this.state.code=n,n?`<div class="toolbox">\n ${!t.hide_button&&'<a class="button" onclick="app.run("@show-popup")" >Try the Code</a>'}\n </div>`:"<div>AppRun Play cannot find code to run, please set code-element selector.</div>"},this.rendered=({style:t,hide_src:i,code_area:s,code:e})=>{if(!e)return;if(!document.getElementById("play-popup")){document.body.insertAdjacentHTML("beforeend",'<div id="play-popup" class="overlay">\n<style id="apprun-play-style">\n.apprun-play .col {\n height: 100%;\n flex: 1;\n}\n.apprun-preview {\n width: 100%\n}\n.apprun-play .editor, .apprun-play .preview {\n display: inline-block;\n width: calc(100% - 20px);\n height: calc(100% - 10px);\n}\n\na.button {\n font-size: .8em;\n padding: 10px;\n cursor: pointer;\n color: var(--md-primary-bg-color);\n background: var(--md-primary-fg-color)\n}\na.button:hover {\n color: var(--md-primary-fg-color);\n background: var(--md-primary-bg-color)\n}\n\n.overlay {\n position: fixed;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n background: rgba(0, 0, 0, 0.7);\n visibility: hidden;\n opacity: 0;\n z-index: 999;\n}\n.overlay.show {\n visibility: visible;\n opacity: 1;\n}\n\n.popup {\n margin: 80px auto;\n padding: 20px;\n background: #fff;\n border-radius: 3px;\n position: relative;\n width: 90%;\n height: calc(100% - 150px);\n}\n\n.popup .close {\n position: absolute;\n top: 10px;\n right: 20px;\n font-size: 20px;\n font-weight: bold;\n text-decoration: none;\n color: #333;\n}\n.popup .close:hover {\n color: #06D85F;\n}\n.popup .content {\n height: 100%;\n overflow: hidden;\n display: flex;\n}\n\n.cm-s-default {\n height: 100%;\n font-size: small;\n line-height: 1.5em;\n z-index: 0;\n}\n</style>\n\n\t<div class="popup apprun-play">\n\t\t<a class="close" href="javascript:app.run(\'@close-popup\')">×</a>\n\t\t<div class="content">\n\t\t\t<div class="col">\n <textarea class="editor"></textarea>\n </div>\n <div class="col">\n <iframe class="preview"/>\n </div>\n </div>\n\t</div>\n</div>');const t=document.querySelector(".apprun-play .editor"),i=document.querySelector(".apprun-play .preview");t.value=e,Ft(t,i,e,!1)}const n=document.createElement("iframe");n.classList.add("apprun-preview"),n.style.cssText=t,this.element.before(n),i&&(s.style.display="none"),Ft(s,n,e,i)},this.update={"@show-popup":({code:t})=>{var i;null===(i=document.querySelector(".apprun-play .editor").editor)||void 0===i||i.setValue(t),document.getElementById("play-popup").classList.add("show")},"@close-popup":()=>{document.getElementById("play-popup").classList.remove("show")}}}});
|
|
17
34
|
//# sourceMappingURL=apprun-play-html.esm.js.map
|