10 lines
8.9 KiB
JavaScript
10 lines
8.9 KiB
JavaScript
|
/**
|
||
|
* Litedom v0.12.1
|
||
|
* Copyright 2019 Mardix mcx2082@gmail.com
|
||
|
* License: MIT
|
||
|
* https://github.com/mardix/litedom
|
||
|
* Build date: 11/27/2019, 11:33:17 PM
|
||
|
*
|
||
|
*/
|
||
|
const t=t=>t.replace(/[-_\s+]([a-z])/g,t=>t[1].toUpperCase()),e=(t,e,n)=>{let r=t;const o=e.split(".");for(;o.length;){const t=o.shift();r[t]=o.length?r[t]?r[t]:{}:n,r=r[t]}},n=(t,e)=>e.split(".").reduce((t,e)=>t&&t[e],t),r=t=>"function"==typeof t,o=(t,e)=>t&&r(t[e]),i=t=>"string"==typeof t?document.querySelector(t):t,s=t=>window.getComputedStyle(t),c=t=>"hidden"===s(t).visibility,l=t=>"none"===s(t).display,a=t=>(new DOMParser).parseFromString(t,"text/html").body,u=[["<","<"],[">",">"],["&","&"]],d=(e,n=!1)=>Object.freeze(Array.from(e.attributes).map(e=>({[n?t(e.name):e.name]:e.value})).reduce((t,e)=>({...t,...e}),{})),f=(t,e)=>{let n=!1,r=!1;const o=new WeakMap,i=()=>{n?r||(r=!0):e()},s={get(t,e,n){if("#"===e)return t;const r=Reflect.get(t,e,n);if((t=>null===t||!["function","object"].includes(typeof t))(r)||"constructor"===e)return r;const i=((t,e)=>{let n=o.get(t);if(n)return n;n=new Map,o.set(t,n);let r=n.get(e);return r||(r=Reflect.getOwnPropertyDescriptor(t,e),n.set(e,r)),r})(t,e);if(i&&!i.configurable){if(i.set&&!i.get)return;if(!1===i.writable)return r}return new Proxy(r,s)},set(t,e,n,r){n&&void 0!==n["#"]&&(n=n["#"]);const o=Reflect.get(t,e,r),s=Reflect.set(t,e,n);return o!==n&&i(),s},defineProperty(t,e,n){const r=Reflect.defineProperty(t,e,n);return i(),r},deleteProperty(t,e){const n=Reflect.deleteProperty(t,e);return i(),n},apply(t,o,i){if(!n){n=!0;const s=Reflect.apply(t,o,i);return r&&e(),n=r=!1,s}return Reflect.apply(t,o,i)}};return new Proxy(t,s)};const p=t=>(function t(e){return null===e||"object"!=typeof e?e:(Object.keys(e).forEach(function(n){const r=e[n];null!==r&&"object"==typeof r&&t(r)}),Object.freeze(e))})(function(t){if(null===t||"object"!=typeof t)return t;var e=t.constructor();for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=p(t[n]));return e}(t)),h=[];for(const t in document){const e=null===document[t]||r(document[t]);t.startsWith("on")&&e&&h.push(t.substring(2))}const m="ld--elist",b=t=>`ld-on-${t}`;const y=(t,e)=>Array.from(t.childNodes).filter(t=>e(t)).map(t=>({[e(t)]:t})).reduce((t,e)=>({...t,...e}),{}),g=t=>(t=>t instanceof HTMLElement)(t)&&t.hasAttribute("ref-key")?t.getAttribute("ref-key"):t.id;const $={$key:function(t,e,n){t.setAttribute("ref-key",e),k(t,n)},$class:function(t,e,n){const r=e.split(";").map(t=>t.split(":",2).map(t=>t.trim())).map(t=>`\${${t[1]} ? '${t[0]}': ''}`).join(" "),o=t.getAttribute("class")||""+` ${r}`;t.setAttribute("class",o),k(t,n)},$style:function(t,e,n){const r=t.getAttribute("style")||"",o=`\${function() { return this.__$styleMap(${e});}.call(this)}`;t.setAttribute("style",(r?r+"; ":"")+o),k(t,n)},$for:function(t,e,n){const r=/(.*)\s+(in)\s+(.*)$/.exec(e);if(4===r.length){const e=r[1].replace("(","").replace(")",""),o=r[3];x(t,`\${${o}.map(function(${e}) { return \``,"`}.bind(this)).join('')}"),k(t,n)}},$if:function(t,e,n){k(t,n),N(t,`\${${e} ? `);const r=t.nextElementSibling;r&&v(r,"else")?(x(t,"`","`"),k(r,"else"),x(r,":`","`}")):x(t,"`","`:``}")}},A=t=>`:${t}`,v=(t,e)=>t.hasAttribute(A(e)),M=(t,e)=>t.getAttribute(A(e)),k=(t,e)=>t.removeAttribute(A(e)),w=(t,e)=>t.querySelectorAll(`[\\${A(e)}]`),N=(t,e)=>t.insertAdjacentText("beforebegin",e),x=(t,e,n)=>{N(t,e),((t,e)=>t.insertAdjacentText("afterend",e))(t,n)};const j=["data","el","shadowDOM","template","created","updated","removed","$store","prop","tagName"],T=t=>Object.keys(t).filter(t=>!j.includes(t)).filter(t=>!t.startsWith("$")).filter(e=>o(t,e)).reduce((e,n)=>({...e,[n]:t[n]}),{}),E=t=>Object.keys(t).filter(e=>!o(t,e)).reduce((e,n)=>({...e,[n]:t[n]}),{}),O=t=>Object.keys(t).filter(e=>o(t,e)).map(e=>((t,e)=>n=>n[t]=e({...n}))(e,t[e])),_=t=>Object.keys(t).filter(t=>t.startsWith("$")).filter(t=>!j.includes(t)).reduce((e,n)=>({...e,[n]:t[n]}),{}),C=t=>e=>(e.$store=t.getState(),t.subscribe(n=>e.$store={...t.getState()})),L=(t,e,n)=>{Object.keys(e).filter(t=>!t.startsWith("_")).map(r=>t[r]=e[r].bind(n))},S=t=>{const e=a((t=>t.replace(/\$?\{([^\;\{]+)\}/g,(t,e)=>`\${${e}}`))(t));!function(t,e={}){const n={...e,...$};for(const e in n){const r=e.replace("$","");for(const o of w(t,r))i
|