fwebc.min.js (2429B)
1 (e=>{"object"==typeof module&&"exports"in module?module.exports=e({fetch:require("node-fetch")}):"object"==typeof window&&(window.fwebc=e({fetch:window.fetch}))})(({fetch:e})=>{const t={},n=[],o={ext:"tag",base:"/partial"},s=t.util={unescape(e){const t=document.createElement("textarea");return t.innerHTML=e,0===t.childNodes.length?"":t.childNodes[0].nodeValue},observable(e,t,n=""){if(Object(e)!==e)throw new Error(`Object is not an object, got: ${e}`);if("function"!=typeof t)throw new Error(`Callback is not a function, got: ${t}`);for(const o of Object.keys(e))Object(e[o])===e[o]&&(e[o]=s.observable(e[o],t,`${n}${o}.`));return new Proxy(e,{set(e,o,r,c){if(e[o]===r)return;let i=o in e?"update":"add";const a={name:o,type:i,object:e};return"update"==i&&(a.oldValue=e[o]),e[o]=Object(r)===r?s.observable(r,t,`${n}${o}.`):r,t([a]),!0},deleteProperty(e,n,o){if(!(n in e))return;const s={name:n,type:"delete",object:e,oldValue:e[n]};return delete e[n],t([s]),!0}})}};return t.cfg=(e=>{Object.assign(o,e)}),t.install=(e=>{"function"==typeof e&&n.push(e)}),t.uninstall=(e=>{const t=n.indexOf(e);~t&&n.splice(t,1)}),t.register=((e,o)=>{if(window.customElements.get(e))return;const r=document.createElement("template");r.innerHTML=o;let c=null,i=[],a=[];for(const e of[...r.content.children])e instanceof HTMLTemplateElement&&(c=e),e instanceof HTMLScriptElement&&(i.push(e),r.content.removeChild(e)),e instanceof HTMLStyleElement&&(a.push(e),r.content.removeChild(e));c||(c=r),c=s.unescape(c.innerHTML);let l="";for(const e of i)e.getAttribute("src")||(l+=e.innerHTML);window.customElements.define(e,class extends HTMLElement{constructor(){super(),this.root=this.attachShadow({mode:"open"}),this.state={};for(const e of n)e(this);new Function(l).call(this),this.dependencies&&this.dependencies.forEach(t.load),this.state=s.observable(this.state,()=>this.emit("update")),this.on("update",this.render.bind(this)),this.render()}render(){const e=new Function(...Object.keys(this.state),"return `"+c+"`;"),t=Array.from(this.root.ownerDocument.styleSheets).map(e=>e.ownerNode.outerHTML).concat(a.map(e=>e.outerHTML));try{this.root.innerHTML=t.join("")+e.call(this,...Object.values(this.state))}catch(e){console.error(e)}}emit(e,t={}){const n=new CustomEvent(e,t);this.dispatchEvent(n)}on(e,t){this.addEventListener(e,t)}})}),t.load=(n=>{e(`${o.base}/${n.replace(/-/g,"/")}.${o.ext}`).then(e=>e.text()).then(e=>{t.register(n,e)})}),t});