olova 1.0.17 → 1.0.19
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:r={},watch:n={},mounted:o,beforeMount:a,beforeUpdate:i,template:s,plugins:c=[],components:l={},mixins:u=[],directives:d={}}={})=>{let f;const h={},m={},p={},y={},E={...d},b=new Map,v=new Map,w=new Map,g=(e,t)=>{v.set(e,t);const r=t({});if(r.styles){const t=`olova-component-${e}`;if(!document.getElementById(t)){const e=document.createElement("style");e.id=t,e.textContent=r.styles,document.head.appendChild(e)}w.set(e,t)}},A=(e,t)=>{E[e]=t},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,M(t)),!0)});Error;class C extends Error{constructor(e){super(e),this.name="StateError"}}const L=(e,t,r=Error)=>function(...n){try{return e.apply(this,n)}catch(e){throw new r(`${t}: ${e.message}`)}};a&&L(a,"Error in beforeMount hook",C).call(H);new Set;const x=e=>{h[e]&&h[e].forEach(L((t=>{t.node?t.node.textContent=t.originalText.replace(/\{(.*?)\}/g,((e,t)=>{try{return new Function("state","helpers",`with(state) { with(helpers) { return ${t} } }`)(H,U)}catch(e){return console.error(`Error evaluating expression: ${t}`,e),""}})):t.element&&t.attrName?(t.element.setAttribute(t.attrName,H[e]),t.element.removeAttribute(`:${t.attrName}`)):t.update&&t.update()}),"Error updating bindings"))},M=e=>{Object.entries(N).forEach((([t,r])=>{r.has&&r.has(e)&&(delete m[t],x(t))})),i&&i.call(H,e),x(e),$(e),p.__updated__&&p.__updated__.forEach((e=>e.callback.call(H)))},$=e=>{p[e]&&p[e].forEach((t=>{t.debounce?(clearTimeout(t.timeout),t.timeout=setTimeout((()=>t.callback.call(H,H[e])),t.debounce)):t.throttle?(!t.lastCalled||Date.now()-t.lastCalled>t.throttle)&&(t.callback.call(H,H[e]),t.lastCalled=Date.now()):t.callback.call(H,H[e])}))};n&&Object.entries(n).forEach((([e,t])=>{p[e]=Array.isArray(t)?t.map((e=>({callback:e}))):["function"==typeof t?{callback:t}:{...t}]}));const H=T({...e,$refs:new Proxy(y,{get:(e,t)=>{const r=e[t];return r instanceof HTMLElement?new Proxy(r,{get:(e,t)=>"function"==typeof e[t]?e[t].bind(e):e[t]}):r},set:()=>{throw new Error("$refs is read-only")}})}),N={};t&&Object.entries(t).forEach((([e,t])=>{N[e]=new Set,Object.defineProperty(H,e,{get(){if(!m.hasOwnProperty(e)){const r=new Proxy(H,{get:(t,r)=>(r!==e&&N[e].add(r),t[r])});m[e]=t.call(r)}return m[e]},enumerable:!0,configurable:!0})}));const S=()=>{const e=new WeakMap,t={};f.querySelectorAll("[\\i-model]").forEach((r=>{const n=r.getAttribute("i-model");if(!n)return;const o=()=>{const 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&&(H[n]=e,M(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,H[n])};if(e.has(r)){e.get(r).forEach((([e,t])=>{r.removeEventListener(e,t)}))}const i=[];if(r instanceof HTMLSelectElement||"checkbox"===r.type||"radio"===r.type){const e=()=>o();r.addEventListener("change",e),i.push(["change",e])}else{const e=()=>o();r.addEventListener("input",e),i.push(["input",e])}e.set(r,i),r instanceof HTMLInputElement&&"radio"===r.type&&(t[n]||(t[n]=[]),t[n].push(r),r.name=`radio-group-${n}`),(h[n]??=[]).push({element:r,updateModel:a}),a(),r.removeAttribute("i-model")})),Object.entries(t).forEach((([e,t])=>{(h[e]??=[]).push({updateModel:()=>{t.forEach((t=>{t.checked=t.value===H[e]}))}})}))},O=e=>{e.querySelectorAll("[i-for]").forEach((e=>{e instanceof HTMLElement&&B(e)})),e.querySelectorAll("*").forEach((e=>{if(e instanceof HTMLElement){if(e.closest("[data-i-for-id]"))return;(e=>{Array.from(e.attributes).forEach((t=>{const r=t.name.startsWith("i-")?t.name.slice(1):null;r&&E[r]&&(E[r](e,t.value,H),e.removeAttribute(t.name))}))})(e),(e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-if");if(!t)return;const r=[];let n=null,o=e.nextElementSibling;for(;o&&(o.hasAttribute("i-else-if")||o.hasAttribute("i-else"));){if(o.hasAttribute("i-else-if"))r.push(o);else if(o.hasAttribute("i-else")){n=o;break}o=o.nextElementSibling}const a=e.parentNode,i=document.createComment("i-if placeholder");a?.insertBefore(i,e);const s=()=>{try{if(j(t))e.isConnected||a?.insertBefore(e,i.nextSibling),r.forEach((e=>{e.isConnected&&a?.removeChild(e)})),n?.isConnected&&a?.removeChild(n);else{let t=!1;e.isConnected&&a?.removeChild(e);for(const e of r){const r=e.getAttribute("i-else-if");if(j(r)){e.isConnected||a?.insertBefore(e,i.nextSibling),t=!0;break}e.isConnected&&a?.removeChild(e)}!t&&n?n.isConnected||a?.insertBefore(n,i.nextSibling):n?.isConnected&&a?.removeChild(n)}}catch(e){console.error("Error evaluating i-if directive:",e)}};s(),(h[t]??=[]).push({element:e,update:s}),e.removeAttribute("i-if"),r.forEach((e=>e.removeAttribute("i-else-if"))),n?.removeAttribute("i-else")})(e),I(e),(e=>{e instanceof HTMLElement&&Array.from(e.attributes).forEach((t=>{const r=t.name.match(/^(?:i-bind:|:)(.+)$/);if(!r)return;const[,n]=r,o=t.value,a=()=>{try{let t=j(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(),_(o).forEach((e=>{(h[e]??=[]).push({update:a})})),e.removeAttribute(t.name)}))})(e)}})),k(e)},k=e=>{const t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,!1);let r;for(;r=t.nextNode();){const e=r.textContent;if(e.includes("{")&&e.includes("}")){const t=e.split(/(\{@html\s+.*?\}|\{.*?\})/),n=document.createDocumentFragment();t.forEach((e=>{if(e.startsWith("{@html")&&e.endsWith("}")){const t=e.slice(6,-1).trim(),r=document.createElement("span"),o=()=>{try{const e=j(t);r.innerHTML=e,r.querySelectorAll("*").forEach((e=>{e instanceof HTMLElement&&O(e)}))}catch(e){console.error(`Error evaluating HTML expression: ${t}`,e)}};o();_(t).forEach((e=>{(h[e]??=[]).push({update:o})})),n.appendChild(r)}else if(e.startsWith("{")&&e.endsWith("}")){const t=e.slice(1,-1).trim(),r=document.createTextNode(""),o=()=>{try{r.textContent=j(t)}catch(e){console.error(`Error evaluating expression: ${t}`,e)}};o();_(t).forEach((e=>{(h[e]??=[]).push({update:o})})),n.appendChild(r)}else n.appendChild(document.createTextNode(e))})),r.parentNode.replaceChild(n,r)}}},j=e=>{try{return new Function("state","helpers",`with(state) { with(helpers) { return ${e} } }`)(H,U)}catch(t){return console.error(`Error evaluating expression: ${e}`,t),""}},_=e=>{const t=e.match(/\b\w+\b/g);return t?t.filter((e=>e in H)):[]};Object.entries(l).forEach((([e,t])=>{g(e,t)}));const 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(H)))},W=e=>{e.data&&Object.assign(H,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(W);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 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)=>{const 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=""}},I=e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-show");if(!t)return;let r=null;const n=async()=>{try{const n=new Function("state","helpers",`with(state) { with(helpers) { return ${t} } }`)(H,U);e._transitionShow&&e._transitionHide?(r&&(await r,r=null),r=n?e._transitionShow():e._transitionHide(),await r):e.style.display=n?"":"none"}catch(e){console.error("Error evaluating i-show directive:",e)}};n(),(h[t]??=[]).push({element:e,update:n}),e.removeAttribute("i-show")},B=e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-for");if(!t)return;const r=t.match(/(\w+)\s+in\s+(\w+)/);if(!r)return void console.error("Invalid i-for expression:",t);const[,n,o]=r,a=e.parentNode,i=document.createComment(`i-for: ${t}`);a?.insertBefore(i,e);const s=e.cloneNode(!0);s.removeAttribute("i-for");const c=()=>{try{const e=H[o];if(!Array.isArray(e))return void console.error(`Collection ${o} is not an array`);const t=document.createDocumentFragment();let r=i.nextSibling;for(;r&&r.hasAttribute?.("data-i-for-id");){const e=r;r=r.nextSibling,e.remove()}e.forEach(((e,r)=>{const a=s.cloneNode(!0);a.setAttribute("data-i-for-id",`${o}-${r}`);const i=t=>{if(t.nodeType===Node.ELEMENT_NODE)t=(t=>{if(t.nodeType===Node.ELEMENT_NODE){const r=t.tagName.toLowerCase();if(v.has(r)){const o=v.get(r),a=Array.from(t.attributes).reduce(((t,r)=>{const o=r.value.replace(/\{(.*?)\}/g,((t,o)=>{try{const t={[n]:e};return new Function("scope","state","helpers",`with(scope) { with(state) { with(helpers) { return ${o} } } }`)(t,H,U)}catch(e){return console.error(`Error evaluating prop expression: ${o}`,e),r.value}}));return{...t,[r.name]:o}}),{}),i=o(a),s=document.createElement("div");s.innerHTML=i.template||i;const c=s.firstElementChild;if(c)return Array.from(t.attributes).forEach((e=>{a[e.name]||c.setAttribute(e.name,e.value)})),t.parentNode?.replaceChild(c,t),c}}return t})(t),Array.from(t.childNodes).forEach(i);else if(t.nodeType===Node.TEXT_NODE){const r=t.textContent;r.includes("{")&&r.includes("}")&&(t.textContent=r.replace(/\{(.*?)\}/g,((t,r)=>{try{const t={[n]:e};return new Function("scope","state","helpers",`with(scope) { with(state) { with(helpers) { return ${r} } } }`)(t,H,U)}catch(e){return console.error(`Error evaluating expression: ${r}`,e),""}})))}};Array.from(a.childNodes).forEach(i),t.appendChild(a)})),a.insertBefore(t,i.nextSibling)}catch(e){console.error("Error in i-for directive:",e)}};c(),(h[o]??=[]).push({update:c}),e.remove()},U={};return{mount:L((function(e){if(f=document.querySelector(e),!f)throw new Error(`Element with selector "${e}" not found.`);var t;D("beforeCreate"),D("created"),a&&a.call(H),D("beforeMount"),c.forEach((e=>{"function"==typeof e&&e({createPlugin:A,state:H,bindings:h})})),(()=>{const e=f.querySelector("template"),t=e?e.innerHTML.trim():"string"==typeof s?s.trim():s instanceof HTMLElement?s.innerHTML:f.innerHTML.trim();if(!t)throw new Error("No template provided and container is empty");f.innerHTML="";const r=document.createElement("template");r.innerHTML=t;const n=r.content;var o;o=n,Array.from(o.children).forEach((e=>{const t=e.tagName.toLowerCase();if(v.has(t)){const 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.template||o;const i=a.firstElementChild;i&&(Array.from(e.attributes).forEach((e=>{n[e.name]||i.setAttribute(e.name,e.value)})),e.parentNode?.replaceChild(i,e))}})),O(n),f.appendChild(n)})(),f.querySelectorAll("*").forEach((e=>{Array.from(e.attributes).forEach((t=>{if(t.name.startsWith("@")){const[n,...o]=t.name.slice(1).split("."),a=t.value.trim(),i={capture:o.includes("capture"),once:o.includes("once"),passive:o.includes("passive")},s=t=>{try{if(o.includes("stop")&&t.stopPropagation(),o.includes("prevent")&&t.preventDefault(),o.includes("self")&&t.target!==e)return;if(t instanceof KeyboardEvent){const e=o.filter((e=>["ctrl","alt","shift","meta","Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e))),r=e.every((e=>t[`${e}Key`]));if(e.length>0&&!r)return;const n=o.find((e=>/^[0-9]+$/.test(e)));if(n&&t.keyCode!==parseInt(n))return;const a=o.find((t=>!e.includes(t)&&!/^[0-9]+$/.test(t)));if(a&&t.key.toLowerCase()!==a.toLowerCase())return}if(t instanceof MouseEvent){const e={left:0,middle:1,right:2},r=o.find((t=>Object.keys(e).includes(t)));if(r&&t.button!==e[r])return}r&&r[a]?r[a].call(H,t):new Function("state","event",`with(state) { ${a} }`).call(H,H,t),M()}catch(e){console.error(`Error executing event handler: ${a}`,e)}};let c=s;if(o.includes("debounce")){const e=parseInt(o[o.indexOf("debounce")+1])||300;c=debounce(s,e)}if(o.includes("throttle")){const e=parseInt(o[o.indexOf("throttle")+1])||300;c=throttle(s,e)}e.addEventListener(n,c,i),e.removeAttribute(t.name)}}))})),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"))})),S(),f.querySelectorAll("[\\i-html]").forEach((e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-html");if(!t)return;const r=()=>{try{let r=new Function("state","helpers",`with(state) { with(helpers) { return ${t} } }`)(H,U);r=r.replace(/\{(.*?)\}/g,((e,t)=>new Function("state",`with(state) { return ${t} }`)(H))),e.innerHTML=r,e.querySelectorAll("*").forEach((e=>{e instanceof HTMLElement&&n(e)}))}catch(e){console.error("Error applying i-html directive:",e)}},n=e=>{Array.from(e.childNodes).forEach((e=>{e.nodeType===Node.TEXT_NODE&&o(e)})),Array.from(e.attributes).forEach((t=>{t.value.includes("{")&&t.value.includes("}")&&a(e,t)}))},o=e=>{const t=e.textContent||"";if(t.includes("{")&&t.includes("}")){const r=t.split(/(\{.*?\})/),n=document.createDocumentFragment();r.forEach((e=>{if(e.startsWith("{")&&e.endsWith("}")){const t=e.slice(1,-1).trim(),r=document.createTextNode("");n.appendChild(r);const o=()=>{r.textContent=j(t)};o(),Object.keys(H).forEach((e=>{(h[e]??=[]).push({update:o})}))}else n.appendChild(document.createTextNode(e))})),e.parentNode.replaceChild(n,e)}},a=(e,t)=>{const r=t.value,n=()=>{const n=r.replace(/\{(.*?)\}/g,((e,t)=>new Function("state",`with(state) { return ${t} }`)(H)));e.setAttribute(t.name,n)};n(),Object.keys(H).forEach((e=>{(h[e]??=[]).push({update:n})}))};r(),Object.keys(H).forEach((e=>{(h[e]??=[]).push({update:r})})),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[r,n,o]=t.split(",").map((e=>e.trim())),a=n?`${n}ms`:"300ms",i=o||"ease";e.style.transition=`opacity ${a} ${i}, transform ${a} ${i}`;const s=(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 s({before:P.beforeEnter,during:P.enter,after:P.afterEnter,cancelled:P.enterCancelled},t)},e._transitionHide=async e=>{await s({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 r=t.name.match(/^(?:i-bind:|:)(.+)$/);if(!r)return;const[,n]=r,o=t.value,a=()=>{try{let t=new Function("state","helpers",`with(state) { with(helpers) { return ${o} } }`)(H,U);"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(),(h[o]??=[]).push({update:a}),e.removeAttribute(t.name)}))})),Object.entries(N).forEach((([e,r])=>{r instanceof Set&&r.has(t)&&(delete m[e],x(e))})),f.querySelectorAll("[\\i-show]").forEach((e=>{e instanceof HTMLElement&&I(e)})),o&&o.call(H),D("mounted"),Object.keys(H).forEach((e=>x(e)))}),"Error mounting application"),onUpdated:e=>{if("function"==typeof e){const t=L(e,"Error in onUpdated callback");(p.__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),()=>{const r=b.get(e),n=r.indexOf(t);-1!==n&&r.splice(n,1)}),addLifecycleHook:q,applyMixin:W,component:g,render:e=>{const t=document.createElement("template");return t.innerHTML=e.trim(),t.content},power:e=>{Object.entries(e).forEach((([e,t])=>{U[e]="function"==typeof t?(...r)=>{try{return t(...r.map((e=>"string"==typeof e&&e.includes("{")&&e.includes("}")?new Function("state","helpers",`with(state) { with(helpers) { return ${e.slice(1,-1)} } }`)(H,U):e)))}catch(t){return console.error(`Error in helper function '${e}':`,t),""}}:t}))}}};export const debounce=(e,t)=>{let r;return function(...n){clearTimeout(r),r=setTimeout((()=>{clearTimeout(r),e(...n)}),t)}};export const throttle=(e,t)=>{let r;return function(...n){r||(e(...n),r=!0,setTimeout((()=>r=!1),t))}};export{createApp};
|
|
1
|
+
const createApp=({data:e={},computed:t={},methods:r={},watch:n={},mounted:o,beforeMount:a,beforeUpdate:i,template:c,plugins:s=[],components:l={},mixins:u=[],directives:d={}}={})=>{let f;const h={},p={},m={},y={},E={...d},b=new Map,v=new Map,w=new Map,g=(e,t)=>{v.set(e,t);const r=t({});if(r.styles){const t=`olova-component-${e}`;if(!document.getElementById(t)){const e=document.createElement("style");e.id=t,e.textContent=r.styles,document.head.appendChild(e)}w.set(e,t)}},A=(e,t)=>{E[e]=t},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,M(t)),!0)});Error;class L extends Error{constructor(e){super(e),this.name="StateError"}}const C=(e,t,r=Error)=>function(...n){try{return e.apply(this,n)}catch(e){throw new r(`${t}: ${e.message}`)}};a&&C(a,"Error in beforeMount hook",L).call(H);new Set;const x=e=>{h[e]&&h[e].forEach(C((t=>{t.node?t.node.textContent=t.originalText.replace(/\{(.*?)\}/g,((e,t)=>{try{return new Function("state","helpers",`with(state) { with(helpers) { return ${t} } }`)(H,U)}catch(e){return console.error(`Error evaluating expression: ${t}`,e),""}})):t.element&&t.attrName?(t.element.setAttribute(t.attrName,H[e]),t.element.removeAttribute(`:${t.attrName}`)):t.update&&t.update()}),"Error updating bindings"))},M=e=>{Object.entries(N).forEach((([t,r])=>{r.has&&r.has(e)&&(delete p[t],x(t))})),i&&i.call(H,e),x(e),$(e),m.__updated__&&m.__updated__.forEach((e=>e.callback.call(H)))},$=e=>{m[e]&&m[e].forEach((t=>{t.debounce?(clearTimeout(t.timeout),t.timeout=setTimeout((()=>t.callback.call(H,H[e])),t.debounce)):t.throttle?(!t.lastCalled||Date.now()-t.lastCalled>t.throttle)&&(t.callback.call(H,H[e]),t.lastCalled=Date.now()):t.callback.call(H,H[e])}))};n&&Object.entries(n).forEach((([e,t])=>{m[e]=Array.isArray(t)?t.map((e=>({callback:e}))):["function"==typeof t?{callback:t}:{...t}]}));const H=T({...e,$refs:new Proxy(y,{get:(e,t)=>{const r=e[t];return r instanceof HTMLElement?new Proxy(r,{get:(e,t)=>"function"==typeof e[t]?e[t].bind(e):e[t]}):r},set:()=>{throw new Error("$refs is read-only")}})}),N={};t&&Object.entries(t).forEach((([e,t])=>{N[e]=new Set,Object.defineProperty(H,e,{get(){if(!p.hasOwnProperty(e)){const r=new Proxy(H,{get:(t,r)=>(r!==e&&N[e].add(r),t[r])});p[e]=t.call(r)}return p[e]},enumerable:!0,configurable:!0})}));const S=()=>{const e=new WeakMap,t={};f.querySelectorAll("[\\i-model]").forEach((r=>{const n=r.getAttribute("i-model");if(!n)return;const o=()=>{const 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&&(H[n]=e,M(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,H[n])};if(e.has(r)){e.get(r).forEach((([e,t])=>{r.removeEventListener(e,t)}))}const i=[];if(r instanceof HTMLSelectElement||"checkbox"===r.type||"radio"===r.type){const e=()=>o();r.addEventListener("change",e),i.push(["change",e])}else{const e=()=>o();r.addEventListener("input",e),i.push(["input",e])}e.set(r,i),r instanceof HTMLInputElement&&"radio"===r.type&&(t[n]||(t[n]=[]),t[n].push(r),r.name=`radio-group-${n}`),(h[n]??=[]).push({element:r,updateModel:a}),a(),r.removeAttribute("i-model")})),Object.entries(t).forEach((([e,t])=>{(h[e]??=[]).push({updateModel:()=>{t.forEach((t=>{t.checked=t.value===H[e]}))}})}))},O=e=>{e.querySelectorAll("[i-data]").forEach((e=>{e instanceof HTMLElement&&Y(e)}));e.querySelectorAll("[i-for]").forEach((e=>{e instanceof HTMLElement&&B(e)})),e.querySelectorAll("*").forEach((e=>{if(e instanceof HTMLElement){if(e.closest("[data-i-for-id]"))return;(e=>{Array.from(e.attributes).forEach((t=>{const r=t.name.startsWith("i-")?t.name.slice(1):null;r&&E[r]&&(E[r](e,t.value,H),e.removeAttribute(t.name))}))})(e),(e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-if");if(!t)return;const r=[];let n=null,o=e.nextElementSibling;for(;o&&(o.hasAttribute("i-else-if")||o.hasAttribute("i-else"));){if(o.hasAttribute("i-else-if"))r.push(o);else if(o.hasAttribute("i-else")){n=o;break}o=o.nextElementSibling}const a=e.parentNode,i=document.createComment("i-if placeholder");a?.insertBefore(i,e);const c=()=>{try{if(k(t))e.isConnected||a?.insertBefore(e,i.nextSibling),r.forEach((e=>{e.isConnected&&a?.removeChild(e)})),n?.isConnected&&a?.removeChild(n);else{let t=!1;e.isConnected&&a?.removeChild(e);for(const e of r){const r=e.getAttribute("i-else-if");if(k(r)){e.isConnected||a?.insertBefore(e,i.nextSibling),t=!0;break}e.isConnected&&a?.removeChild(e)}!t&&n?n.isConnected||a?.insertBefore(n,i.nextSibling):n?.isConnected&&a?.removeChild(n)}}catch(e){console.error("Error evaluating i-if directive:",e)}};c(),(h[t]??=[]).push({element:e,update:c}),e.removeAttribute("i-if"),r.forEach((e=>e.removeAttribute("i-else-if"))),n?.removeAttribute("i-else")})(e),I(e),(e=>{e instanceof HTMLElement&&Array.from(e.attributes).forEach((t=>{const r=t.name.match(/^(?:i-bind:|:)(.+)$/);if(!r)return;const[,n]=r,o=t.value,a=()=>{try{let t=k(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(),_(o).forEach((e=>{(h[e]??=[]).push({update:a})})),e.removeAttribute(t.name)}))})(e)}})),j(e)},j=e=>{const t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT,null,!1);let r;for(;r=t.nextNode();){const e=r.textContent;if(e.includes("{")&&e.includes("}")){const t=e.split(/(\{@html\s+.*?\}|\{.*?\})/),n=document.createDocumentFragment();t.forEach((e=>{if(e.startsWith("{@html")&&e.endsWith("}")){const t=e.slice(6,-1).trim(),r=document.createElement("span"),o=()=>{try{const e=k(t);r.innerHTML=e,r.querySelectorAll("*").forEach((e=>{e instanceof HTMLElement&&O(e)}))}catch(e){console.error(`Error evaluating HTML expression: ${t}`,e)}};o();_(t).forEach((e=>{(h[e]??=[]).push({update:o})})),n.appendChild(r)}else if(e.startsWith("{")&&e.endsWith("}")){const t=e.slice(1,-1).trim(),r=document.createTextNode(""),o=()=>{try{r.textContent=k(t)}catch(e){console.error(`Error evaluating expression: ${t}`,e)}};o();_(t).forEach((e=>{(h[e]??=[]).push({update:o})})),n.appendChild(r)}else n.appendChild(document.createTextNode(e))})),r.parentNode.replaceChild(n,r)}}},k=e=>{try{return new Function("state","helpers",`with(state) { with(helpers) { return ${e} } }`)(H,U)}catch(t){return console.error(`Error evaluating expression: ${e}`,t),""}},_=e=>{const t=e.match(/\b\w+\b/g);return t?t.filter((e=>e in H)):[]};Object.entries(l).forEach((([e,t])=>{g(e,t)}));const 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(H)))},W=e=>{e.data&&Object.assign(H,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(W);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 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)=>{const 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=""}},I=e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-show");if(!t)return;let r=null;const n=async()=>{try{const n=new Function("state","helpers",`with(state) { with(helpers) { return ${t} } }`)(H,U);e._transitionShow&&e._transitionHide?(r&&(await r,r=null),r=n?e._transitionShow():e._transitionHide(),await r):e.style.display=n?"":"none"}catch(e){console.error("Error evaluating i-show directive:",e)}};n(),(h[t]??=[]).push({element:e,update:n}),e.removeAttribute("i-show")},B=e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-for");if(!t)return;const r=t.match(/(\w+)\s+in\s+(\w+)/);if(!r)return void console.error("Invalid i-for expression:",t);const[,n,o]=r,a=e.parentNode,i=document.createComment(`i-for: ${t}`);a?.insertBefore(i,e);const c=e.cloneNode(!0);c.removeAttribute("i-for");const s=()=>{try{const e=H[o];if(!Array.isArray(e))return void console.error(`Collection ${o} is not an array`);const t=document.createDocumentFragment();let r=i.nextSibling;for(;r&&r.hasAttribute?.("data-i-for-id");){const e=r;r=r.nextSibling,e.remove()}e.forEach(((e,r)=>{const a=c.cloneNode(!0);a.setAttribute("data-i-for-id",`${o}-${r}`);const i=t=>{if(t.nodeType===Node.ELEMENT_NODE)t=(t=>{if(t.nodeType===Node.ELEMENT_NODE){const r=t.tagName.toLowerCase();if(v.has(r)){const o=v.get(r),a=Array.from(t.attributes).reduce(((t,r)=>{const o=r.value.replace(/\{(.*?)\}/g,((t,o)=>{try{const t={[n]:e};return new Function("scope","state","helpers",`with(scope) { with(state) { with(helpers) { return ${o} } } }`)(t,H,U)}catch(e){return console.error(`Error evaluating prop expression: ${o}`,e),r.value}}));return{...t,[r.name]:o}}),{}),i=o(a),c=document.createElement("div");c.innerHTML=i.template||i;const s=c.firstElementChild;if(s)return Array.from(t.attributes).forEach((e=>{a[e.name]||s.setAttribute(e.name,e.value)})),t.parentNode?.replaceChild(s,t),s}}return t})(t),Array.from(t.childNodes).forEach(i);else if(t.nodeType===Node.TEXT_NODE){const r=t.textContent;r.includes("{")&&r.includes("}")&&(t.textContent=r.replace(/\{(.*?)\}/g,((t,r)=>{try{const t={[n]:e};return new Function("scope","state","helpers",`with(scope) { with(state) { with(helpers) { return ${r} } } }`)(t,H,U)}catch(e){return console.error(`Error evaluating expression: ${r}`,e),""}})))}};Array.from(a.childNodes).forEach(i),t.appendChild(a)})),a.insertBefore(t,i.nextSibling)}catch(e){console.error("Error in i-for directive:",e)}};s(),(h[o]??=[]).push({update:s}),e.remove()},U={},Y=e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-data");if(!t)return;const r=()=>{try{const e=new Function("state","helpers",`with(state) { with(helpers) { return ${t} } }`)(H,U);"object"==typeof e&&null!==e?Object.entries(e).forEach((([e,t])=>{H[e]=t})):console.error("i-data directive must return an object")}catch(e){console.error("Error evaluating i-data directive:",e)}};r();_(t).forEach((e=>{(h[e]??=[]).push({update:r})})),e.removeAttribute("i-data")};return{mount:C((function(e){if(f=document.querySelector(e),!f)throw new Error(`Element with selector "${e}" not found.`);var t;D("beforeCreate"),D("created"),a&&a.call(H),D("beforeMount"),s.forEach((e=>{"function"==typeof e&&e({createPlugin:A,state:H,bindings:h})})),(()=>{const e=f.querySelector("template"),t=e?e.innerHTML.trim():"string"==typeof c?c.trim():c instanceof HTMLElement?c.innerHTML:f.innerHTML.trim();if(!t)throw new Error("No template provided and container is empty");f.innerHTML="";const r=document.createElement("template");r.innerHTML=t;const n=r.content;var o;o=n,Array.from(o.children).forEach((e=>{const t=e.tagName.toLowerCase();if(v.has(t)){const 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.template||o;const i=a.firstElementChild;i&&(Array.from(e.attributes).forEach((e=>{n[e.name]||i.setAttribute(e.name,e.value)})),e.parentNode?.replaceChild(i,e))}})),O(n),f.appendChild(n)})(),f.querySelectorAll("*").forEach((e=>{Array.from(e.attributes).forEach((t=>{if(t.name.startsWith("@")){const[n,...o]=t.name.slice(1).split("."),a=t.value.trim(),i={capture:o.includes("capture"),once:o.includes("once"),passive:o.includes("passive")},c=t=>{try{if(o.includes("stop")&&t.stopPropagation(),o.includes("prevent")&&t.preventDefault(),o.includes("self")&&t.target!==e)return;if(t instanceof KeyboardEvent){const e=o.filter((e=>["ctrl","alt","shift","meta","Tab","ArrowUp","ArrowDown","ArrowLeft","ArrowRight"].includes(e))),r=e.every((e=>t[`${e}Key`]));if(e.length>0&&!r)return;const n=o.find((e=>/^[0-9]+$/.test(e)));if(n&&t.keyCode!==parseInt(n))return;const a=o.find((t=>!e.includes(t)&&!/^[0-9]+$/.test(t)));if(a&&t.key.toLowerCase()!==a.toLowerCase())return}if(t instanceof MouseEvent){const e={left:0,middle:1,right:2},r=o.find((t=>Object.keys(e).includes(t)));if(r&&t.button!==e[r])return}r&&r[a]?r[a].call(H,t):new Function("state","event",`with(state) { ${a} }`).call(H,H,t),M()}catch(e){console.error(`Error executing event handler: ${a}`,e)}};let s=c;if(o.includes("debounce")){const e=parseInt(o[o.indexOf("debounce")+1])||300;s=debounce(c,e)}if(o.includes("throttle")){const e=parseInt(o[o.indexOf("throttle")+1])||300;s=throttle(c,e)}e.addEventListener(n,s,i),e.removeAttribute(t.name)}}))})),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"))})),S(),f.querySelectorAll("[\\i-html]").forEach((e=>{if(!(e instanceof HTMLElement))return;const t=e.getAttribute("i-html");if(!t)return;const r=()=>{try{let r=new Function("state","helpers",`with(state) { with(helpers) { return ${t} } }`)(H,U);r=r.replace(/\{(.*?)\}/g,((e,t)=>new Function("state",`with(state) { return ${t} }`)(H))),e.innerHTML=r,e.querySelectorAll("*").forEach((e=>{e instanceof HTMLElement&&n(e)}))}catch(e){console.error("Error applying i-html directive:",e)}},n=e=>{Array.from(e.childNodes).forEach((e=>{e.nodeType===Node.TEXT_NODE&&o(e)})),Array.from(e.attributes).forEach((t=>{t.value.includes("{")&&t.value.includes("}")&&a(e,t)}))},o=e=>{const t=e.textContent||"";if(t.includes("{")&&t.includes("}")){const r=t.split(/(\{.*?\})/),n=document.createDocumentFragment();r.forEach((e=>{if(e.startsWith("{")&&e.endsWith("}")){const t=e.slice(1,-1).trim(),r=document.createTextNode("");n.appendChild(r);const o=()=>{r.textContent=k(t)};o(),Object.keys(H).forEach((e=>{(h[e]??=[]).push({update:o})}))}else n.appendChild(document.createTextNode(e))})),e.parentNode.replaceChild(n,e)}},a=(e,t)=>{const r=t.value,n=()=>{const n=r.replace(/\{(.*?)\}/g,((e,t)=>new Function("state",`with(state) { return ${t} }`)(H)));e.setAttribute(t.name,n)};n(),Object.keys(H).forEach((e=>{(h[e]??=[]).push({update:n})}))};r(),Object.keys(H).forEach((e=>{(h[e]??=[]).push({update:r})})),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[r,n,o]=t.split(",").map((e=>e.trim())),a=n?`${n}ms`:"300ms",i=o||"ease";e.style.transition=`opacity ${a} ${i}, transform ${a} ${i}`;const c=(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 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 r=t.name.match(/^(?:i-bind:|:)(.+)$/);if(!r)return;const[,n]=r,o=t.value,a=()=>{try{let t=new Function("state","helpers",`with(state) { with(helpers) { return ${o} } }`)(H,U);"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(),(h[o]??=[]).push({update:a}),e.removeAttribute(t.name)}))})),Object.entries(N).forEach((([e,r])=>{r instanceof Set&&r.has(t)&&(delete p[e],x(e))})),Y(),f.querySelectorAll("[\\i-show]").forEach((e=>{e instanceof HTMLElement&&I(e)})),o&&o.call(H),D("mounted"),Object.keys(H).forEach((e=>x(e)))}),"Error mounting application"),onUpdated:e=>{if("function"==typeof e){const t=C(e,"Error in onUpdated callback");(m.__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),()=>{const r=b.get(e),n=r.indexOf(t);-1!==n&&r.splice(n,1)}),addLifecycleHook:q,applyMixin:W,component:g,render:e=>{const t=document.createElement("template");return t.innerHTML=e.trim(),t.content},power:e=>{Object.entries(e).forEach((([e,t])=>{U[e]="function"==typeof t?(...r)=>{try{return t(...r.map((e=>"string"==typeof e&&e.includes("{")&&e.includes("}")?new Function("state","helpers",`with(state) { with(helpers) { return ${e.slice(1,-1)} } }`)(H,U):e)))}catch(t){return console.error(`Error in helper function '${e}':`,t),""}}:t}))}}};export const debounce=(e,t)=>{let r;return function(...n){clearTimeout(r),r=setTimeout((()=>{clearTimeout(r),e(...n)}),t)}};export const throttle=(e,t)=>{let r;return function(...n){r||(e(...n),r=!0,setTimeout((()=>r=!1),t))}};export{createApp};
|