olova 1.0.7 → 1.0.8
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/dist/olova.js +1 -1
- package/package.json +1 -1
package/dist/olova.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const createApp=({data:e,computed:t,methods:n,watch:r,mounted:o,beforeMount:a,beforeUpdate:i,template:c,plugins:s=[],components:l={},mixins:u=[],directives:d={}})=>{let f;const m={},p={},h={},y={},E={...d},b=new Map,v=new Map,w=(e,t)=>{v.set(e,t)},g=(e,t)=>{E[e]=t},A=e=>{Array.from(e.attributes).forEach((t=>{const n=t.name.startsWith("i-")?t.name.slice(1):null;n&&E[n]&&(E[n](e,t.value,$),e.removeAttribute(t.name))}))},T=e=>new Proxy(e,{get:(e,t)=>"object"==typeof e[t]&&null!==e[t]?T(e[t]):e[t],set:(e,t,n)=>(e[t]!==n&&(e[t]=n,H(t)),!0)});Error;class L extends Error{constructor(e){super(e),this.name="StateError"}}const M=(e,t,n=Error)=>function(...r){try{return e.apply(this,r)}catch(e){throw new n(`${t}: ${e.message}`)}};a&&M(a,"Error in beforeMount hook",L).call($);const x=new Set,C=e=>{m[e]&&(x.add(e),requestAnimationFrame((()=>{x.forEach((e=>{m[e].forEach(M((t=>{t.node?t.node.textContent=t.originalText.replace(/\{(.*?)\}/g,((e,t)=>{try{return new Function("state",`with(state) { return ${t} }`)($)}catch(e){return console.error(`Error evaluating expression: ${t}`,e),""}})):t.element&&t.attrName?(t.element.setAttribute(t.attrName,$[e]),t.element.removeAttribute(`:${t.attrName}`)):t.update&&t.update()}),"Error updating bindings"))})),x.clear()})))},H=e=>{i&&M(i,"Error in beforeUpdate hook").call($,e),C(e),N(),S(e),h.__updated__?.forEach((e=>e.callback.call($)))},N=()=>{Object.keys(p).forEach((e=>delete p[e]))},S=e=>{h[e]&&h[e].forEach((t=>{t.debounce?(clearTimeout(t.timeout),t.timeout=setTimeout((()=>t.callback.call($,$[e])),t.debounce)):t.throttle?(!t.lastCalled||Date.now()-t.lastCalled>t.throttle)&&(t.callback.call($,$[e]),t.lastCalled=Date.now()):t.callback.call($,$[e])}))};r&&Object.entries(r).forEach((([e,t])=>{h[e]=Array.isArray(t)?t.map((e=>({callback:e}))):["function"==typeof t?{callback:t}:{...t}]}));const $=T({...e,$refs:new Proxy(y,{get:(e,t)=>e[t],set:()=>{throw new Error("$refs is read-only")}})}),O={},k={};t&&Object.entries(t).forEach((([e,t])=>{O[e]=[],Object.defineProperty($,e,{get:()=>"function"==typeof t&&"AsyncFunction"===t.constructor.name?(k[e]||(p[e]=new Proxy($,{get:(t,n)=>(O[e].includes(n)||O[e].push(n),t[n])}),k[e]=t.call($).then((t=>(p[e]=t,delete k[e],C(e),t))).catch((t=>{console.error(`Error in async computed property "${e}":`,t)}))),k[e]):(p.hasOwnProperty(e)||(p[e]=new Proxy($,{get:(t,n)=>(O[e].includes(n)||O[e].push(n),t[n])}),p[e]=t.call($)),p[e]),enumerable:!0})}));const _=()=>{const e="string"==typeof c?c.trim():c instanceof HTMLElement?c.innerHTML:f.innerHTML.trim();if(!e)throw new Error("No template provided and container is empty");const t=document.createElement("template");t.innerHTML=e,f.innerHTML="",f.appendChild(t.content.cloneNode(!0));const n=e=>{e.nodeType===Node.ELEMENT_NODE&&((e=(e=>{if(e.nodeType===Node.ELEMENT_NODE){const t=e.tagName.toLowerCase();if(v.has(t)){const n=v.get(t)(Array.from(e.attributes).reduce(((e,t)=>({...e,[t.name]:t.value})),{})),r=document.createElement("div");r.innerHTML=n;const o=r.firstElementChild;if(o)return e.parentNode?.replaceChild(o,e),o}}return e})(e))instanceof HTMLElement&&(e.hasAttribute("i-if")&&(e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-if");if(!t)return;const n=e.nextElementSibling?.hasAttribute("i-else")?e.nextElementSibling:null,r=e.parentNode,o=document.createComment("i-if placeholder");r?.insertBefore(o,e);const a=()=>{try{new Function("state",`with(state) { return ${t} }`)($)?(e.isConnected||r?.insertBefore(e,o.nextSibling),n?.isConnected&&r?.removeChild(n)):(e.isConnected&&r?.removeChild(e),n&&!n.isConnected&&r?.insertBefore(n,o.nextSibling))}catch(e){console.error("Error evaluating i-if directive:",e)}};a(),(m[t]??=[]).push({element:e,update:a}),e.removeAttribute("i-if"),n?.removeAttribute("i-else")})(e),e.hasAttribute("i-show")&&U(e),A(e)),Array.from(e.childNodes).forEach(n))};Array.from(f.childNodes).forEach(n),f.querySelectorAll("*").forEach((e=>{if(e instanceof HTMLElement){A(e);const t=e=>{const t=e.textContent||"";if(t.includes("{")&&t.includes("}")){const n=t.split(/(\{.*?\})/),r=document.createDocumentFragment();n.forEach((e=>{if(e.startsWith("{")&&e.endsWith("}")){const t=e.slice(1,-1).trim(),n=document.createTextNode("");r.appendChild(n);const o=()=>{try{const e=new Function("state",`with(state) { return ${t} }`)($);n.textContent=e}catch(e){console.error(`Error evaluating expression: ${t}`,e),n.textContent=""}};o(),Object.keys($).forEach((e=>{(m[e]??=[]).push({update:o})}))}else r.appendChild(document.createTextNode(e))})),e.parentNode.replaceChild(r,e)}};e.childNodes.forEach((e=>{e.nodeType===Node.TEXT_NODE&&t(e)}))}}))};Object.entries(l).forEach((([e,t])=>{w(e,t)}));const F={beforeCreate:[],created:[],beforeMount:[],mounted:[],beforeUpdate:[],updated:[],beforeUnmount:[],unmounted:[]},j=(e,t)=>{F[e]&&F[e].push(t)},q=e=>{F[e]?.forEach((e=>e.call($)))},D=e=>{e.data&&Object.assign($,e.data()),e.methods&&Object.assign(n,e.methods),e.computed&&Object.assign(t,e.computed),e.watch&&Object.entries(e.watch).forEach((([e,t])=>{(r[e]??=[]).push(t)})),e.mounted&&j("mounted",e.mounted)};u.forEach(D);window.addEventListener("error",(e=>{console.error("Global error:",e)}));const P={beforeEnter:e=>{e.style.opacity="0",e.style.transform="translateY(-20px)",e.style.display=""},enter:(e,t)=>{const n=1e3*parseFloat(getComputedStyle(e).transitionDuration);requestAnimationFrame((()=>{e.style.opacity="1",e.style.transform="translateY(0)",setTimeout(t,n)}))},afterEnter:e=>{e.style.opacity="",e.style.transform=""},enterCancelled:e=>{e.style.opacity="",e.style.transform=""},beforeLeave:e=>{e.style.opacity="1",e.style.transform="translateY(0)"},leave:(e,t)=>{const n=1e3*parseFloat(getComputedStyle(e).transitionDuration);requestAnimationFrame((()=>{e.style.opacity="0",e.style.transform="translateY(-20px)",setTimeout(t,n)}))},afterLeave:e=>{e.style.display="none",e.style.opacity="",e.style.transform=""},leaveCancelled:e=>{e.style.opacity="",e.style.transform=""}},U=e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-show");if(!t)return;let n=null;const r=async()=>{try{const r=new Function("state",`with(state) { return ${t} }`)($);e._transitionShow&&e._transitionHide?(n&&(await n,n=null),n=r?e._transitionShow():e._transitionHide(),await n):e.style.display=r?"":"none"}catch(e){console.error("Error evaluating i-show directive:",e)}};r(),(m[t]??=[]).push({element:e,update:r}),e.removeAttribute("i-show")};return{mount:M((function(e){if(f=document.querySelector(e),!f)throw new Error(`Element with selector "${e}" not found.`);q("beforeCreate"),q("created"),a&&a.call($),q("beforeMount"),s.forEach((e=>{"function"==typeof e&&e({createPlugin:g,state:$,bindings:m})}));const t=f.querySelector("template");var r;t&&(f.innerHTML=t.innerHTML),_(),f.querySelectorAll("*").forEach((e=>{Array.from(e.attributes).forEach((t=>{if(t.name.startsWith("@")){const[r,...o]=t.name.slice(1).split("."),a=t.value.trim(),i={once:o.includes("once"),capture:o.includes("capture")};e.addEventListener(r,(e=>{try{o.includes("prevent")&&e.preventDefault(),o.includes("stop")&&e.stopPropagation(),n&&n[a]?n[a].call($,e):new Function("state","event",`with(state) { ${a} }`).call($,$,e),H()}catch(e){console.error(`Error executing event handler: ${a}`,e)}}),i),e.removeAttribute(t.name)}}))})),f.querySelectorAll("[\\i-for]").forEach((e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-for");if(!t)return;const n=t.match(/^\s*(\w+)(?:\s*,\s*(\w+))?\s+(?:of|in)\s+(\w+)\s*$/);if(!n)return void console.error("Invalid i-for expression:",t);const[,r,o,a]=n,i=e.parentNode,c=document.createComment("i-for placeholder");i?.insertBefore(c,e),e.removeAttribute("i-for");const s=e.cloneNode(!0);i?.removeChild(e);const l=()=>{const e=document.createDocumentFragment(),t=$[a];for((Array.isArray(t)&&t.forEach(((t,n)=>{const a=s.cloneNode(!0),i={[r]:t,...o&&{[o]:n}},c=new Proxy(i,{get:(e,t)=>t in e?e[t]:$[t]}),l=e=>{if(e.nodeType===Node.TEXT_NODE){const t=e.textContent;t.includes("{")&&t.includes("}")&&(e.textContent=t.replace(/\{(.*?)\}/g,((e,t)=>new Function("state",`with(state) { return ${t} }`)(c))))}else e.nodeType===Node.ELEMENT_NODE&&Array.from(e.childNodes).forEach(l)};l(a),a.querySelectorAll("*").forEach((e=>{Array.from(e.attributes).forEach((t=>{if(t.value.includes("{")&&t.value.includes("}")){const n=t.value.replace(/\{(.*?)\}/g,((e,t)=>new Function("state",`with(state) { return ${t} }`)(c)));e.setAttribute(t.name,n)}}))})),e.appendChild(a)})));c.nextSibling;)i?.removeChild(c.nextSibling);i?.insertBefore(e,c.nextSibling)};l(),(m[a]??=[]).push({updateFor:l})})),f.querySelectorAll("[\\i-ref]").forEach((e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-ref");t&&(y[t]=e,e.removeAttribute("i-ref"))})),f.querySelectorAll("[\\i-model]").forEach((e=>{if(!(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement))return;const t=e.getAttribute("i-model");if(!t)return;const n=()=>{e instanceof HTMLInputElement?"checkbox"===e.type?$[t]=e.checked:"radio"===e.type?e.checked&&($[t]=e.value):$[t]=e.value:(e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)&&($[t]=e.value)},r=()=>{e instanceof HTMLInputElement?"checkbox"===e.type?e.checked=$[t]:"radio"===e.type?e.checked=e.value===$[t]:e.value=$[t]||"":(e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)&&(e.value=$[t]||"")};e.addEventListener("input",n),e.addEventListener("change",n),(m[t]??=[]).push({element:e,updateModel:r}),r(),e.removeAttribute("i-model")})),f.querySelectorAll("[\\i-html]").forEach((e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-html");if(!t)return;const n=()=>{try{const n=new Function("state",`with(state) { return ${t} }`)($);e.innerHTML=n}catch(e){console.error("Error applying i-html directive:",e)}};n(),(m[t]??=[]).push({updateHtml:n}),e.removeAttribute("i-html")})),f.querySelectorAll("[i-transition]").forEach((e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-transition");if(!t)return;const[n,r,o]=t.split(",").map((e=>e.trim())),a=r?`${r}ms`:"300ms",i=o||"ease";e.style.transition=`opacity ${a} ${i}, transform ${a} ${i}`;const c=(t,n)=>new Promise((r=>{let o=!1;return t.before(e),t.during(e,(()=>{o||(t.after(e),n&&n(),r())})),()=>{o=!0,t.cancelled(e),r()}}));e._transitionShow=async t=>{e.style.display="",await c({before:P.beforeEnter,during:P.enter,after:P.afterEnter,cancelled:P.enterCancelled},t)},e._transitionHide=async e=>{await c({before:P.beforeLeave,during:P.leave,after:P.afterLeave,cancelled:P.leaveCancelled},e)},e.style.display="none",e.removeAttribute("i-transition")})),f.querySelectorAll("*").forEach((e=>{e instanceof HTMLElement&&Array.from(e.attributes).forEach((t=>{const n=t.name.match(/^(?:i-bind:|:)(.+)$/);if(!n)return;const[,r]=n,o=t.value,a=()=>{try{let t=new Function("state",`with(state) { return ${o} }`)($);"class"===r?"object"==typeof t&&null!==t?Object.entries(t).forEach((([t,n])=>{e.classList.toggle(t,!!n)})):e.className=t:"style"===r?"object"==typeof t&&null!==t?Object.entries(t).forEach((([t,n])=>{e.style[t]=n})):e.setAttribute("style",t):!1===t?e.removeAttribute(r):e.setAttribute(r,!0===t?"":t)}catch(e){console.error(`Error applying bind directive for ${r}:`,e)}};a(),(m[o]??=[]).push({update:a}),e.removeAttribute(t.name)}))})),Object.entries(O).forEach((([e,t])=>{t.includes(r)&&(delete p[e],C(e))})),f.querySelectorAll("[\\i-show]").forEach((e=>{e instanceof HTMLElement&&U(e)})),o&&o.call($),q("mounted"),Object.keys($).forEach((e=>C(e)))}),"Error mounting application"),onUpdated:e=>{if("function"==typeof e){const t=M(e,"Error in onUpdated callback");(h.__updated__??=[]).push({callback:t})}},createPlugin:g,emit:(e,t)=>{(b.get(e)??[]).forEach((e=>e(t)))},on:(e,t)=>(b.has(e)||b.set(e,[]),b.get(e).push(t),()=>{const n=b.get(e),r=n.indexOf(t);-1!==r&&n.splice(r,1)}),addLifecycleHook:j,applyMixin:D,component:w,render:e=>{const t=document.createElement("template");return t.innerHTML=e.trim(),t.content}}};export{createApp};
|
|
1
|
+
let createApp=({data:e,computed:t,methods:r,watch:n,mounted:o,beforeMount:a,beforeUpdate:l,template:i,plugins:c=[],components:s={},mixins:u=[],directives:d={}})=>{let f,m={},p={},h={},y={},E={...d},b=new Map,v=new Map,g=(e,t)=>{v.set(e,t)},A=(e,t)=>{E[e]=t},w=e=>{Array.from(e.attributes).forEach((t=>{let r=t.name.startsWith("i-")?t.name.slice(1):null;r&&E[r]&&(E[r](e,t.value,$),e.removeAttribute(t.name))}))},T=e=>new Proxy(e,{get:(e,t)=>"object"==typeof e[t]&&null!==e[t]?T(e[t]):e[t],set:(e,t,r)=>(e[t]!==r&&(e[t]=r,H(t)),!0)});Error;class L extends Error{constructor(e){super(e),this.name="StateError"}}let M=(e,t,r=Error)=>function(...n){try{return e.apply(this,n)}catch(e){throw new r(`${t}: ${e.message}`)}};a&&M(a,"Error in beforeMount hook",L).call($);let x=new Set,C=e=>{m[e]&&(x.add(e),requestAnimationFrame((()=>{x.forEach((e=>{m[e].forEach(M((t=>{t.node?t.node.textContent=t.originalText.replace(/\{(.*?)\}/g,((e,t)=>{try{return Function("state",`with(state) { return ${t} }`)($)}catch(e){return console.error(`Error evaluating expression: ${t}`,e),""}})):t.element&&t.attrName?(t.element.setAttribute(t.attrName,$[e]),t.element.removeAttribute(`:${t.attrName}`)):t.update&&t.update()}),"Error updating bindings"))})),x.clear()})))},H=e=>{l&&M(l,"Error in beforeUpdate hook").call($,e),C(e),N(),S(e),h.__updated__?.forEach((e=>e.callback.call($)))},N=()=>{Object.keys(p).forEach((e=>delete p[e]))},S=e=>{h[e]&&h[e].forEach((t=>{t.debounce?(clearTimeout(t.timeout),t.timeout=setTimeout((()=>t.callback.call($,$[e])),t.debounce)):t.throttle?(!t.lastCalled||Date.now()-t.lastCalled>t.throttle)&&(t.callback.call($,$[e]),t.lastCalled=Date.now()):t.callback.call($,$[e])}))};n&&Object.entries(n).forEach((([e,t])=>{h[e]=Array.isArray(t)?t.map((e=>({callback:e}))):["function"==typeof t?{callback:t}:{...t}]}));let $=T({...e,$refs:new Proxy(y,{get:(e,t)=>e[t],set(){throw Error("$refs is read-only")}})}),k={},O={};t&&Object.entries(t).forEach((([e,t])=>{k[e]=[],Object.defineProperty($,e,{get:()=>"function"==typeof t&&"AsyncFunction"===t.constructor.name?(O[e]||(p[e]=new Proxy($,{get:(t,r)=>(k[e].includes(r)||k[e].push(r),t[r])}),O[e]=t.call($).then((t=>(p[e]=t,delete O[e],C(e),t))).catch((t=>{console.error(`Error in async computed property "${e}":`,t)}))),O[e]):(p.hasOwnProperty(e)||(p[e]=new Proxy($,{get:(t,r)=>(k[e].includes(r)||k[e].push(r),t[r])}),p[e]=t.call($)),p[e]),enumerable:!0})}));let _=()=>{let e=new WeakMap,t={};f.querySelectorAll("[\\i-model]").forEach((r=>{let n=r.getAttribute("i-model");if(!n)return;let o=()=>{let e=(e=>e instanceof HTMLInputElement?"checkbox"===e.type?e.checked:"radio"===e.type?e.checked?e.value:void 0:e.value:e instanceof HTMLSelectElement?e.multiple?Array.from(e.selectedOptions).map((e=>e.value)):e.value:e instanceof HTMLTextAreaElement?e.value:void 0)(r);void 0!==e&&($[n]=e,H(n))},a=()=>{((e,t)=>{e instanceof HTMLInputElement?"checkbox"===e.type?e.checked=!!t:"radio"===e.type?e.checked=e.value===t:e.value=t:e instanceof HTMLSelectElement?e.multiple?Array.from(e.options).forEach((e=>{e.selected=t.includes(e.value)})):e.value=t:e instanceof HTMLTextAreaElement&&(e.value=t)})(r,$[n])};if(e.has(r)){e.get(r).forEach((([e,t])=>{r.removeEventListener(e,t)}))}let l=[];if(r instanceof HTMLSelectElement||"checkbox"===r.type||"radio"===r.type){let e=()=>o();r.addEventListener("change",e),l.push(["change",e])}else{let e=()=>o();r.addEventListener("input",e),l.push(["input",e])}e.set(r,l),r instanceof HTMLInputElement&&"radio"===r.type&&(t[n]||(t[n]=[]),t[n].push(r),r.name=`radio-group-${n}`),(m[n]??=[]).push({element:r,updateModel:a}),a(),r.removeAttribute("i-model")})),Object.entries(t).forEach((([e,t])=>{(m[e]??=[]).push({updateModel(){t.forEach((t=>{t.checked=t.value===$[e]}))}})}))},j=()=>{let e="string"==typeof i?i.trim():i instanceof HTMLElement?i.innerHTML:f.innerHTML.trim();if(!e)throw Error("No template provided and container is empty");let t=document.createElement("template");t.innerHTML=e,f.innerHTML="",f.appendChild(t.content.cloneNode(!0));let r=e=>{e.nodeType===Node.ELEMENT_NODE&&((e=(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=e.tagName.toLowerCase();if(v.has(t)){let r=v.get(t),n=Array.from(e.attributes).reduce(((e,t)=>({...e,[t.name]:t.value})),{}),o=r(n),a=document.createElement("div");a.innerHTML=o;let l=a.firstElementChild;if(l)return e.parentNode?.replaceChild(l,e),l}}return e})(e))instanceof HTMLElement&&(e.hasAttribute("i-if")&&(e=>{if(!(e instanceof HTMLElement))return;let t=e.getAttribute("i-if");if(!t)return;let r=e.nextElementSibling?.hasAttribute("i-else")?e.nextElementSibling:null,n=e.parentNode,o=document.createComment("i-if placeholder");n?.insertBefore(o,e);let a=()=>{try{Function("state",`with(state) { return ${t} }`)($)?(e.isConnected||n?.insertBefore(e,o.nextSibling),r?.isConnected&&n?.removeChild(r)):(e.isConnected&&n?.removeChild(e),r&&!r.isConnected&&n?.insertBefore(r,o.nextSibling))}catch(e){console.error("Error evaluating i-if directive:",e)}};a(),(m[t]??=[]).push({element:e,update:a}),e.removeAttribute("i-if"),r?.removeAttribute("i-else")})(e),e.hasAttribute("i-show")&&B(e),w(e)),Array.from(e.childNodes).forEach(r))};Array.from(f.childNodes).forEach(r),f.querySelectorAll("*").forEach((e=>{if(e instanceof HTMLElement){w(e);let t=e=>{let t=e.textContent||"";if(t.includes("{")&&t.includes("}")){let r=t.split(/(\{.*?\})/),n=document.createDocumentFragment();r.forEach((e=>{if(e.startsWith("{")&&e.endsWith("}")){let t=e.slice(1,-1).trim(),r=document.createTextNode("");n.appendChild(r);let o=()=>{try{let e=Function("state",`with(state) { return ${t} }`)($);r.textContent=e}catch(e){console.error(`Error evaluating expression: ${t}`,e),r.textContent=""}};o(),Object.keys($).forEach((e=>{(m[e]??=[]).push({update:o})}))}else n.appendChild(document.createTextNode(e))})),e.parentNode.replaceChild(n,e)}};e.childNodes.forEach((e=>{e.nodeType===Node.TEXT_NODE&&t(e)}))}}))};Object.entries(s).forEach((([e,t])=>{g(e,t)}));let F={beforeCreate:[],created:[],beforeMount:[],mounted:[],beforeUpdate:[],updated:[],beforeUnmount:[],unmounted:[]},q=(e,t)=>{F[e]&&F[e].push(t)},D=e=>{F[e]?.forEach((e=>e.call($)))},P=e=>{e.data&&Object.assign($,e.data()),e.methods&&Object.assign(r,e.methods),e.computed&&Object.assign(t,e.computed),e.watch&&Object.entries(e.watch).forEach((([e,t])=>{(n[e]??=[]).push(t)})),e.mounted&&q("mounted",e.mounted)};u.forEach(P);window.addEventListener("error",(e=>{console.error("Global error:",e)}));let U={beforeEnter(e){e.style.opacity="0",e.style.transform="translateY(-20px)",e.style.display=""},enter(e,t){let r=1e3*parseFloat(getComputedStyle(e).transitionDuration);requestAnimationFrame((()=>{e.style.opacity="1",e.style.transform="translateY(0)",setTimeout(t,r)}))},afterEnter(e){e.style.opacity="",e.style.transform=""},enterCancelled(e){e.style.opacity="",e.style.transform=""},beforeLeave(e){e.style.opacity="1",e.style.transform="translateY(0)"},leave(e,t){let r=1e3*parseFloat(getComputedStyle(e).transitionDuration);requestAnimationFrame((()=>{e.style.opacity="0",e.style.transform="translateY(-20px)",setTimeout(t,r)}))},afterLeave(e){e.style.display="none",e.style.opacity="",e.style.transform=""},leaveCancelled(e){e.style.opacity="",e.style.transform=""}},B=e=>{if(!(e instanceof HTMLElement))return;let t=e.getAttribute("i-show");if(!t)return;let r=null,n=async()=>{try{let n=Function("state",`with(state) { return ${t} }`)($);e._transitionShow&&e._transitionHide?(r&&(await r,r=null),await(r=n?e._transitionShow():e._transitionHide())):e.style.display=n?"":"none"}catch(e){console.error("Error evaluating i-show directive:",e)}};n(),(m[t]??=[]).push({element:e,update:n}),e.removeAttribute("i-show")};return{mount:M((function(e){if(!(f=document.querySelector(e)))throw Error(`Element with selector "${e}" not found.`);D("beforeCreate"),D("created"),a&&a.call($),D("beforeMount"),c.forEach((e=>{"function"==typeof e&&e({createPlugin:A,state:$,bindings:m})}));let t=f.querySelector("template");t&&(f.innerHTML=t.innerHTML),j(),f.querySelectorAll("*").forEach((e=>{Array.from(e.attributes).forEach((t=>{if(t.name.startsWith("@")){let[n,...o]=t.name.slice(1).split("."),a=t.value.trim(),l={once:o.includes("once"),capture:o.includes("capture")};e.addEventListener(n,(e=>{try{o.includes("prevent")&&e.preventDefault(),o.includes("stop")&&e.stopPropagation(),r&&r[a]?r[a].call($,e):Function("state","event",`with(state) { ${a} }`).call($,$,e),H()}catch(e){console.error(`Error executing event handler: ${a}`,e)}}),l),e.removeAttribute(t.name)}}))})),f.querySelectorAll("[\\i-for]").forEach((e=>{if(!(e instanceof HTMLElement))return;let t=e.getAttribute("i-for");if(!t)return;let r=t.match(/^\s*(\w+)(?:\s*,\s*(\w+))?\s+(?:of|in)\s+(\w+)\s*$/);if(!r)return void console.error("Invalid i-for expression:",t);let[,n,o,a]=r,l=e.parentNode,i=document.createComment("i-for placeholder");l?.insertBefore(i,e),e.removeAttribute("i-for");let c=e.cloneNode(!0);l?.removeChild(e);let s=()=>{let e=document.createDocumentFragment(),t=$[a];for((Array.isArray(t)&&t.forEach(((t,r)=>{let a=c.cloneNode(!0),l={[n]:t,...o&&{[o]:r}},i=new Proxy(l,{get:(e,t)=>t in e?e[t]:$[t]}),s=e=>{if(e.nodeType===Node.TEXT_NODE){let t=e.textContent;t.includes("{")&&t.includes("}")&&(e.textContent=t.replace(/\{(.*?)\}/g,((e,t)=>Function("state",`with(state) { return ${t} }`)(i))))}else e.nodeType===Node.ELEMENT_NODE&&Array.from(e.childNodes).forEach(s)};s(a),a.querySelectorAll("*").forEach((e=>{Array.from(e.attributes).forEach((t=>{if(t.value.includes("{")&&t.value.includes("}")){let r=t.value.replace(/\{(.*?)\}/g,((e,t)=>Function("state",`with(state) { return ${t} }`)(i)));e.setAttribute(t.name,r)}}))})),e.appendChild(a)})));i.nextSibling;)l?.removeChild(i.nextSibling);l?.insertBefore(e,i.nextSibling)};s(),(m[a]??=[]).push({updateFor:s})})),f.querySelectorAll("[\\i-ref]").forEach((e=>{if(!(e instanceof HTMLElement))return;let t=e.getAttribute("i-ref");t&&(y[t]=e,e.removeAttribute("i-ref"))})),_(),f.querySelectorAll("[\\i-html]").forEach((e=>{if(!(e instanceof HTMLElement))return;let t=e.getAttribute("i-html");if(!t)return;let r=()=>{try{let r=Function("state",`with(state) { return ${t} }`)($);e.innerHTML=r}catch(e){console.error("Error applying i-html directive:",e)}};r(),(m[t]??=[]).push({updateHtml:r}),e.removeAttribute("i-html")})),f.querySelectorAll("[i-transition]").forEach((e=>{if(!(e instanceof HTMLElement))return;let t=e.getAttribute("i-transition");if(!t)return;let[r,n,o]=t.split(",").map((e=>e.trim())),a=n?`${n}ms`:"300ms",l=o||"ease";e.style.transition=`opacity ${a} ${l}, transform ${a} ${l}`;let i=(t,r)=>new Promise((n=>{let o=!1;return t.before(e),t.during(e,(()=>{o||(t.after(e),r&&r(),n())})),()=>{o=!0,t.cancelled(e),n()}}));e._transitionShow=async t=>{e.style.display="",await i({before:U.beforeEnter,during:U.enter,after:U.afterEnter,cancelled:U.enterCancelled},t)},e._transitionHide=async e=>{await i({before:U.beforeLeave,during:U.leave,after:U.afterLeave,cancelled:U.leaveCancelled},e)},e.style.display="none",e.removeAttribute("i-transition")})),f.querySelectorAll("*").forEach((e=>{e instanceof HTMLElement&&Array.from(e.attributes).forEach((t=>{let r=t.name.match(/^(?:i-bind:|:)(.+)$/);if(!r)return;let[,n]=r,o=t.value,a=()=>{try{let t=Function("state",`with(state) { return ${o} }`)($);"class"===n?"object"==typeof t&&null!==t?Object.entries(t).forEach((([t,r])=>{e.classList.toggle(t,!!r)})):e.className=t:"style"===n?"object"==typeof t&&null!==t?Object.entries(t).forEach((([t,r])=>{e.style[t]=r})):e.setAttribute("style",t):!1===t?e.removeAttribute(n):e.setAttribute(n,!0===t?"":t)}catch(e){console.error(`Error applying bind directive for ${n}:`,e)}};a(),(m[o]??=[]).push({update:a}),e.removeAttribute(t.name)}))})),(e=>{Object.entries(k).forEach((([t,r])=>{r.includes(e)&&(delete p[t],C(t))}))})(),f.querySelectorAll("[\\i-show]").forEach((e=>{e instanceof HTMLElement&&B(e)})),o&&o.call($),D("mounted"),Object.keys($).forEach((e=>C(e)))}),"Error mounting application"),onUpdated:e=>{if("function"==typeof e){let t=M(e,"Error in onUpdated callback");(h.__updated__??=[]).push({callback:t})}},createPlugin:A,emit:(e,t)=>{(b.get(e)??[]).forEach((e=>e(t)))},on:(e,t)=>(b.has(e)||b.set(e,[]),b.get(e).push(t),()=>{let r=b.get(e),n=r.indexOf(t);-1!==n&&r.splice(n,1)}),addLifecycleHook:q,applyMixin:P,component:g,render:e=>{let t=document.createElement("template");return t.innerHTML=e.trim(),t.content}}};export{createApp};
|