@koppajs/koppajs-core 3.0.7 → 3.0.9

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/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@koppajs/koppajs-core",
3
- "version": "3.0.7",
3
+ "version": "3.0.9",
4
4
  "type": "module",
5
5
  "types": "./dist/index.d.ts",
6
- "main": "./dist/index.cjs.js",
6
+ "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.es.js",
8
8
  "files": [
9
9
  "dist",
@@ -16,7 +16,7 @@
16
16
  ".": {
17
17
  "types": "./dist/index.d.ts",
18
18
  "import": "./dist/index.es.js",
19
- "require": "./dist/index.cjs.js"
19
+ "require": "./dist/index.cjs"
20
20
  }
21
21
  },
22
22
  "sideEffects": false,
@@ -58,6 +58,8 @@
58
58
  "typecheck": "pnpm run typecheck:src && pnpm run typecheck:test",
59
59
  "prebuild": "rimraf dist",
60
60
  "build": "pnpm run typecheck:src && vite build && pnpm generate:types && pnpm run copy:dts",
61
+ "prepack": "pnpm run build",
62
+ "test:package": "pnpm run build && node --test test/package-consumer.test.mjs",
61
63
  "rebuild": "pnpm run clean && pnpm run build",
62
64
  "test": "vitest --run",
63
65
  "test:coverage": "vitest --coverage",
@@ -68,7 +70,7 @@
68
70
  "format": "prettier --write .",
69
71
  "format:check": "prettier --check .",
70
72
  "check": "pnpm run check:docs && pnpm run typecheck && pnpm run lint && pnpm run format:check && pnpm run test:ci",
71
- "validate": "pnpm run check:docs && pnpm run check && pnpm run build",
73
+ "validate": "pnpm run check:docs && pnpm run check && pnpm run test:package",
72
74
  "check:docs": "node scripts/check-doc-contract.mjs"
73
75
  },
74
76
  "packageManager": "pnpm@10.24.0",
package/dist/index.cjs.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var me=(e=>(e[e.DEBUG=0]="DEBUG",e[e.INFO=1]="INFO",e[e.WARN=2]="WARN",e[e.ERROR=3]="ERROR",e[e.NONE=4]="NONE",e))(me||{});const B={ERROR:"❌",WARN:"⚠️",INFO:"ℹ️",DEBUG:"🔍"};class Pe{level=3;isDevelopment=!1;init(t){this.isDevelopment=t?.isDevelopment??(typeof process<"u"&&process.env?.NODE_ENV==="development")??!1,this.level=t?.level??(this.isDevelopment?0:3)}setLevel(t){this.level=t}getLevel(){return this.level}shouldLog(t){return t>=this.level}formatMessage(t,n,o){const r=[t,n];if(o){const a=Object.entries(o).map(([i,s])=>`${i}: ${s}`).join(", ");a&&r.push(`[${a}]`)}return r.join(" ")}error(t,...n){this.shouldLog(3)&&console.error(this.formatMessage(B.ERROR,t),...n)}warn(t,...n){this.shouldLog(2)&&console.warn(this.formatMessage(B.WARN,t),...n)}info(t,...n){this.shouldLog(1)&&console.info(this.formatMessage(B.INFO,t),...n)}debug(t,...n){this.shouldLog(0)&&console.debug(this.formatMessage(B.DEBUG,t),...n)}errorWithContext(t,n,o){if(!this.shouldLog(3))return;const r=this.formatMessage(B.ERROR,t,n);o?console.error(r,o):console.error(r)}warnWithContext(t,n){this.shouldLog(2)&&console.warn(this.formatMessage(B.WARN,t,n))}}const _=new Pe;_.init();const ae=Symbol("isBounded"),ye=Symbol("isProxy"),Ie=["created","beforeMount","mounted","beforeUpdate","updated","beforeDestroy","destroyed","processed"];function K(e,t){if(typeof e!="function"||e[ae])return e;const o=e.bind(t);return o[ae]=!0,o}function Le(e,t){for(const n in e){const o=e[n];if(Object.prototype.hasOwnProperty.call(e,n)&&typeof o=="function")try{e[n]=K(o,t)}catch(r){_.errorWithContext(`Failed to bind method "${n}"`,{methodName:n},r)}}}function Fe(e){return/<\/?[a-z][^>]*>/i.test(e)}function ne(e,t){if(e==null||typeof t!="string")return;const n=t.trim().replace(/\[(\w+)\]/g,".$1").split(".").filter(Boolean);try{return n.reduce((o,r)=>{if(o!=null)return o[r]},e)}catch{return}}function We(e){return typeof e=="string"?e.toLowerCase():typeof e=="function"&&typeof e.name=="string"?e.name.toLowerCase():"unknown"}function ge(e){const t=e.trim();return/^[a-zA-Z_$][0-9a-zA-Z_$]*(?:\[(?:\d+|\w+)\]|\.[a-zA-Z_$][0-9a-zA-Z_$]*)*$/.test(t)}function De(e,t,n){if(e==null||typeof e!="object"&&typeof e!="function")throw new Error("❌ setValueByPath: target must be an object.");if(typeof t!="string"||!t.trim())throw new Error("❌ setValueByPath: path must be a non-empty string.");const o=t.trim().replace(/\[(\w+)\]/g,".$1").split(".").filter(Boolean);if(o.length===0)throw new Error(`❌ setValueByPath: invalid path "${t}".`);const r=(c,l)=>Object.prototype.hasOwnProperty.call(c,l),a=o.pop();let i=e;for(const c of o){if(i==null||typeof i!="object"&&typeof i!="function")throw new Error(`❌ setValueByPath: invalid path "${t}". Segment "${c}" is not an object.`);if(!r(i,c))throw new Error(`❌ setValueByPath: invalid path "${t}". Missing segment "${c}".`);const l=i[c];if(l==null||typeof l!="object"&&typeof l!="function")throw new Error(`❌ setValueByPath: invalid path "${t}". Segment "${c}" is not an object.`);i=l}if(i==null||typeof i!="object"&&typeof i!="function")throw new Error(`❌ setValueByPath: invalid path "${t}". Final target is not an object.`);if(!r(i,a))throw new Error(`❌ setValueByPath: invalid path "${t}". Final key "${a}" does not exist.`);const s=Object.getOwnPropertyDescriptor(i,a);if(s&&s.writable===!1&&!s.set)throw new Error(`❌ setValueByPath: cannot write "${t}". Property "${a}" is read-only.`);i[a]=n}const je={select:{get(){return e=>this instanceof HTMLInputElement||this instanceof HTMLTextAreaElement?(this.select(),null):this.querySelector(e)}},selectAll:{get(){return e=>this.querySelectorAll(e)}},addClass:{get(){return e=>(e.split(/\s+/).map(t=>t.trim()).filter(t=>t.length>0).forEach(t=>this.classList.add(t)),this)}},removeClass:{get(){return e=>(e.split(/\s+/).map(t=>t.trim()).filter(t=>t.length>0).forEach(t=>this.classList.remove(t)),this)}},toggleClass:{get(){return e=>(e.split(/\s+/).map(t=>t.trim()).filter(t=>t.length>0).forEach(t=>this.classList.toggle(t)),this)}},hasClass:{get(){return e=>this.classList.contains(e.trim())}},replaceWith:{get(){return e=>{this.parentNode&&(e instanceof HTMLElement?this.parentNode.replaceChild(e,this):typeof e=="string"&&(this.insertAdjacentText("beforebegin",e),this.remove()))}}},siblings:{get(){return e=>{if(!this.parentNode)return[];const t=[];let n=this.parentNode.firstChild;for(;n;)n.nodeType===Node.ELEMENT_NODE&&n!==this&&n instanceof HTMLElement&&(e?.(n),t.push(n)),n=n.nextSibling;return t}}},before:{get(){return e=>{this.parentNode&&(e instanceof HTMLElement?this.parentNode.insertBefore(e,this):this.insertAdjacentHTML("beforebegin",e.toString()))}}},after:{get(){return e=>{this.parentNode&&(e instanceof HTMLElement?this.parentNode.insertBefore(e,this.nextSibling):this.insertAdjacentHTML("afterend",e.toString()))}}},attr:{get(){return(e,t)=>(t!==void 0&&this.setAttribute(e,t||"true"),this.getAttribute(e))}}},Ve={};function He(e){return e.replace(/-./g,t=>t[1].toUpperCase())}const Be=/(?:\bwindow\b|\bdocument\b|\bglobalThis\b|\bFunction\b|\beval\b|\bsetTimeout\b|\bsetInterval\b|\bfetch\b|\bXMLHttpRequest\b|\bimport\b|\brequire\b|\bthis\b)/,q=new Map,qe=1e3,le=new WeakMap;function ze(e){const t=Object.keys(e),n=t.join("\0"),o=le.get(e);if(o&&o.fingerprint===n)return o.keys;const r=t.sort();return le.set(e,{keys:r,fingerprint:n}),r}function H(e,t={}){const n=(e??"").trim();if(n)try{if(Be.test(n))return;if(ge(n)){const i=ne(t,n);return typeof i=="function"?i.call(t):i}const o=ze(t),r=`${n}|${o.join(",")}`;let a=q.get(r);if(!a){const i=`"use strict"; return (${n});`;if(a=new Function(...o,i),q.size>=qe){const s=q.keys().next().value;s&&q.delete(s)}q.set(r,a)}return a(...o.map(i=>t[i]))}catch(o){_.debug(`Expression evaluation failed: ${n}`,o);return}}function Ue(e){return e.length===0?"":e.map(t=>`var ${t} = __deps.${t};`).join(`
2
- `)+`
3
- `}function Xe(e,t){const n=e.replace(/\$-\{/g,"${"),o=t?Object.keys(t):[],a=`
4
- const { $refs, $parent, $emit, $take, $handleEventFromChild, ...rest } = context;
5
-
6
- // Expose all $*-prefixed context entries (e.g. $router, $store) as local variables
7
- for (const [key, value] of Object.entries(rest)) {
8
- if (key.startsWith('$')) {
9
- // NOTE: this runs inside a dynamically generated function anyway
10
- // so using eval here does not make the environment less safe than it already is.
11
- eval('var ' + key + ' = value');
12
- }
13
- }
14
-
15
- // Inject resolved dependencies as local variables
16
- ${Ue(o)}
17
-
18
- return (${n});
19
- `;try{const i=t?new Function("context","__deps",a):new Function("context",a);return(c=>t?i(c,t):i(c))}catch(i){throw _.errorWithContext("Failed to compile dynamic code",{functionBody:a},i),i}}function be(){return new Map}const Ee=be();function ve(e,t,n){e==="global"&&(e=Ee),e.has(t)||e.set(t,new Set),e.get(t).add(n)}async function R(e,t,n){e==="global"&&(e=Ee);const o=Array.from(e.get(t)??[]);for(const r of o)try{await r(n)}catch(a){_.errorWithContext(`Hook "${t}" callback failed`,{hook:t},a)}}const G={modules:{},plugins:{}};function Ge(e){if(e==null||typeof e!="object")return!1;const t=e;return typeof t.template=="string"&&typeof t.script=="string"&&typeof t.style=="string"}function Z(e){if(e==null||typeof e!="object")return!1;const t=e;return typeof t.setup=="function"&&t.attach===void 0}function Ke(e){if(e==null||typeof e!="object")return!1;const t=e;return typeof t.attach=="function"&&t.setup===void 0}function Ze(e){return e instanceof HTMLElement&&"instance"in e&&e.instance!==void 0}const Ye=()=>{Object.defineProperties(Object.prototype,Ve),typeof HTMLElement<"u"&&Object.defineProperties(HTMLElement.prototype,je)};function z(e){return e.nodeType===Node.ELEMENT_NODE&&e.tagName.includes("-")}function Je(e,t){const n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:r=>z(r)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let o=n.nextNode();for(;o;){const r=o.getAttribute(t);r!==null&&(Ae(o)===void 0&&Ce(o,r),o.removeAttribute(t)),o=n.nextNode()}}function fe(e,t){if(!z(e))return null;const n=e.tagName;let o=Ae(e);const r=nt(e);if(o===void 0&&t){const a=e.getAttribute(t);a!==null&&(Ce(e,a),o=a,e.removeAttribute(t))}return o===void 0?null:r!==void 0?`${n}:${String(o)}:${String(r)}`:`${n}:${String(o)}`}function Qe(e,t){return e.nodeType!==t.nodeType?!1:e.nodeType===Node.TEXT_NODE||e.nodeType===Node.COMMENT_NODE?!0:e.nodeType===Node.ELEMENT_NODE?e.tagName===t.tagName:!1}function Y(e,t){const n=new Set(e.getAttributeNames()),o=new Set(t.getAttributeNames());for(const r of n)!o.has(r)&&!r.startsWith("@")&&e.removeAttribute(r);for(const r of o){const a=t.getAttribute(r),i=e.getAttribute(r);a!==i&&(a===null?e.removeAttribute(r):e.setAttribute(r,a))}}function we(e,t,n){const o=Array.from(e.childNodes),r=Array.from(t.childNodes),a=new Map,i=new Set;for(const s of o){const c=fe(s,n);c!==null&&!a.has(c)&&a.set(c,s)}for(let s=0;s<r.length;s++){const c=r[s],l=o[s],m=fe(c,n);let p=null;if(m!==null&&a.has(m)&&(p=a.get(m),i.add(p)),p&&z(p)){l!==p&&(s<e.childNodes.length?e.insertBefore(p,e.childNodes[s]):e.appendChild(p)),Y(p,c);continue}if(z(c)&&m!==null){l?e.replaceChild(c,l):e.appendChild(c);continue}if(!l){e.appendChild(c);continue}if(!Qe(l,c)){e.replaceChild(c,l);continue}if(l.nodeType===Node.TEXT_NODE){l.textContent!==c.textContent&&(l.textContent=c.textContent);continue}if(l.nodeType===Node.COMMENT_NODE){l.textContent!==c.textContent&&(l.textContent=c.textContent);continue}if(l.nodeType===Node.ELEMENT_NODE){const N=l,x=c;if(z(N)){Y(N,x);continue}Y(N,x),we(N,x,n)}}for(;e.childNodes.length>r.length;){const s=e.lastChild;s&&e.removeChild(s)}}function et(e,t,n,o){if(n||e.childNodes.length===0){o&&Je(t,o),e.replaceChildren(t);return}const r=document.createElement("div");r.appendChild(t),we(e,r,o)}const oe=Symbol("STRUCT_ID"),re=Symbol("SLOT_ID");function Ne(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,configurable:!0,enumerable:!1})}function Ce(e,t){Ne(e,oe,t)}function Ae(e){return Object.prototype.hasOwnProperty.call(e,oe)?e[oe]:void 0}function tt(e,t){Ne(e,re,t)}function nt(e){return Object.prototype.hasOwnProperty.call(e,re)?e[re]:void 0}function ot(e,t,n,o){if(!Array.isArray(t))return()=>{};const r=[];return t.forEach(([a,i,s])=>{if(typeof a!="string"||typeof s!="function"){_.error("Provided handler is not a function",s);return}let c=[];if(i==="window")c=[window];else if(typeof i=="string")if(i.startsWith("$refs.")){const[l,...m]=i.slice(6).split(" "),p=o[l];p&&(c=m.length?Array.from(p.querySelectorAll(m.join(" "))):[p])}else c=Array.from(n.querySelectorAll(i));else if(i instanceof Element||i instanceof Window)c=[i];else if(typeof i=="object"&&i&&"ref"in i){const{ref:l,selector:m}=i,p=o[l];p&&(c=m?Array.from(p.querySelectorAll(m)):[p])}for(const l of c){const m=K(s,e);l.addEventListener(a,m),r.push({target:l,type:a,handler:m})}}),()=>{for(const{target:a,type:i,handler:s}of r)a.removeEventListener(i,s);r.length=0}}const _e=/^on([a-z]+)$/i;function rt(e,t){const n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT);let o=n.nextNode();for(;o;){for(const r of Array.from(o.attributes)){const a=r.name.match(_e);if(a){const i=a[1].toLowerCase(),s=r.value;if(s){const c=e[s];typeof c=="function"&&(o.removeAttribute(r.name),o.addEventListener(i,c))}}}o=n.nextNode()}}function it(e,t){const n=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT);let o=n.nextNode();for(;o;){for(const r of Array.from(o.attributes)){const a=r.name.match(_e);if(a){const i=a[1].toLowerCase(),s=r.value;if(s){const c=e[s];typeof c=="function"&&(o.removeAttribute(r.name),o.addEventListener(i,c))}}}o=n.nextNode()}}function st(e,t,n,o,r){if(!Array.isArray(n))return()=>{};const a=[];return n.forEach(([i,s,c])=>{if(typeof i!="string"||typeof c!="function"){_.error("Provided handler is not a function",c);return}let l=[];if(s==="window")l=[window];else if(typeof s=="string")if(s.startsWith("$refs.")){const[m,...p]=s.slice(6).split(" "),N=r[m];N&&(l=p.length?Array.from(N.querySelectorAll(p.join(" "))):[N])}else l=Array.from(o.querySelectorAll(s));else if(s instanceof Element||s instanceof Window)l=[s];else if(typeof s=="object"&&s&&"ref"in s){const{ref:m,selector:p}=s,N=r[m];N&&(l=p?Array.from(N.querySelectorAll(p)):[N])}for(const m of l){const p=K(c,t);m.addEventListener(i,p),a.push({target:m,type:i,handler:p})}}),()=>{for(const{target:i,type:s,handler:c}of a)i.removeEventListener(s,c);a.length=0}}const j=new WeakMap;let J;function ct(){if(typeof EventTarget>"u")return;const e=globalThis;if(e.__koppajsEventTrackingPatched)return;e.__koppajsEventTrackingPatched=!0;const t=EventTarget.prototype.addEventListener,n=EventTarget.prototype.removeEventListener;EventTarget.prototype.addEventListener=function(o,r,a){return j.has(this)||j.set(this,new Set),j.get(this).add({type:o,listener:r,options:a}),t.call(this,o,r,a)},EventTarget.prototype.removeEventListener=function(o,r,a){const i=j.get(this);if(i){for(const s of i)if(s.type===o&&s.listener===r){i.delete(s);break}i.size===0&&j.delete(this)}return n.call(this,o,r,a)}}function at(e){const t=j.get(e);if(t){for(const{type:n,listener:o,options:r}of t)e.removeEventListener(n,o,r);j.delete(e)}}function Te(e){if(typeof document>"u"||typeof NodeFilter>"u"||typeof Element>"u")return;const t=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT);let n=e instanceof Element?e:null;for(;n;)j.has(n)&&at(n),n=t.nextNode()}function lt(){J||typeof MutationObserver>"u"||typeof document>"u"||document.body&&(J=new MutationObserver(e=>{for(const t of e)t.removedNodes.forEach(n=>{n.nodeType===Node.ELEMENT_NODE&&Te(n)})}),J.observe(document.body,{childList:!0,subtree:!0}))}const Se=new WeakMap,xe=new WeakMap,U=new WeakMap;let ft=0;const V=()=>`slot-${++ft}`,W=e=>typeof e=="object"&&e!==null,Q=e=>typeof e=="symbol"?e.toString():String(e),ut=e=>{const t=Se.get(e);return t&&W(t)?t:void 0};function Oe(e){const t=xe.get(e);return t||e}const D=e=>W(e)?Reflect.get(e,ye)===!0:!1;function dt(e){const t=D(e)?Oe(e):e;return U.get(t)}const ht=e=>e!==null&&(typeof e=="string"||typeof e=="number"||typeof e=="boolean"||typeof e=="function"||typeof e>"u"),X=e=>{let t=U.get(e);return t||(t=e.map(()=>V()),U.set(e,t)),t},ue=e=>{const t=U.get(e);if(t&&t.length!==e.length)throw new Error(`Slot sidecar invariant violation: slotIds length (${t.length}) does not match array length (${e.length})`)};function pt(e){const t=new Set,n=new WeakMap;let o=0,r=new Set;const a=new Map,i=(f,y)=>!!(f===y||f.startsWith(y+".")),s=(f,y)=>{const b=n.get(f)??"";return b?`${b}.${y}`:y};let c=!1;const l=f=>{r.add(f),o++,c||(c=!0,queueMicrotask(()=>{c=!1,t.forEach(y=>{try{y()}catch(b){console.error("Observer error:",b)}})}))},m=(f,y,b)=>{if(f===y)return;let w=f.length!==y.length;if(!w){for(let u=0;u<f.length;u++)if(f[u]!==y[u]){w=!0;break}}f.splice(0,f.length,...y),w&&l(b)},p=(f,y,b)=>{const w=new Set(f),u=new Set(y);let d=!1;for(const g of w)if(!u.has(g)){d=!0;break}if(!d){for(const g of u)if(!w.has(g)){d=!0;break}}d&&(f.splice(0,f.length,...y),l(b))},N=(f,y,b)=>{const w=new Set(f),u=new Set(y);f.length!==y.length||[...w].some(g=>!u.has(g))||[...u].some(g=>!w.has(g))?p(f,y,b):m(f,y,b)},x=(f,y,b)=>{if(f===y)return!1;let w=!1;for(const u of Object.keys(f))u in y||(w=!0,Reflect.deleteProperty(f,u));for(const u of Object.keys(y)){const d=f[u],g=y[u];d!==g&&(W(d)&&D(d)&&W(g)&&!D(g)?(x(d,g)&&(w=!0),d!==g&&(w=!0,Reflect.set(f,u,g))):(w=!0,Reflect.set(f,u,g)))}return w},S=(f,y,b)=>{const w=X(f);switch(y){case"push":{const u=Array.from({length:b.length},()=>V());w.push(...u);break}case"pop":{w.pop();break}case"shift":{w.shift();break}case"unshift":{const u=Array.from({length:b.length},()=>V());w.unshift(...u);break}case"splice":{const u=b[0]??0,d=b[1]!==void 0?b[1]:f.length-u,g=b.slice(2),T=Array.from({length:g.length},()=>V());w.splice(u,d,...T);break}case"reverse":{w.reverse();break}}ue(f)},v=(f,y="")=>{if(f instanceof Node||f instanceof Window||f instanceof Document)return f;const b=ut(f);if(b)return b;y&&n.set(f,y),Array.isArray(f)&&X(f);const w=new Proxy(f,{get:(u,d,g)=>{if(d===ye)return!0;if(d==="toJSON")return function(){return Oe(u)};if(Array.isArray(u)&&typeof d=="string"&&["push","pop","shift","unshift","splice","reverse","sort"].includes(d)){const O=u[d];if(typeof O=="function")return function(...I){if(d==="sort"){const k=X(u),h=u.map((C,F)=>({el:C,slotId:k[F]||V()})),E=O.apply(this,I),A=new Map;for(let C=0;C<h.length;C++){const F=h[C].el;let $=A.get(F);$||($=[],A.set(F,$)),$.push(C)}for(let C=0;C<u.length;C++){const F=u[C],$=A.get(F);if($&&$.length>0){const Re=$.shift();k[C]=h[Re].slotId}else k[C]=V()}return ue(u),E}else{const k=O.apply(this,I);return S(u,d,I),k}}}const T=Reflect.get(u,d,g),M=Array.isArray(u)&&typeof d=="string"&&/^\d+$/.test(d);if(W(T)&&!D(T)&&!M&&(Array.isArray(T)||!Array.isArray(u))){const L=Q(d),O=s(u,L);return v(T,O)}return T},set:(u,d,g,T)=>{const M=Reflect.get(u,d,T);if(M===g)return!0;const L=Q(d),O=s(u,L);if(Array.isArray(u)&&typeof d=="string"&&/^\d+$/.test(d)){const k=parseInt(d,10);if(k>=0&&k<u.length){const h=Reflect.set(u,d,g,T);return l(O),h}}if(Array.isArray(M)&&!ht(g)&&Array.isArray(g)){N(M,g,O);const k=M.map(()=>V());return U.set(M,k),!0}if(W(M)&&D(M)&&W(g)&&!D(g)){if(x(M,g)){let h=g;W(h)&&!D(h)&&(h=v(h,O)),Reflect.set(u,d,h,T),l(O)}return!0}const I=Reflect.set(u,d,g,T);if(W(g)&&!D(g)){const k=v(g,O);Reflect.set(u,d,k,T),Array.isArray(g)&&X(g)}return l(O),I},deleteProperty:(u,d)=>{if(d==="changedPaths")return Reflect.deleteProperty(u,d);const g=Q(d),T=s(u,g),M=Reflect.get(u,d),L=Reflect.deleteProperty(u,d);return L&&M!==void 0&&l(T),L}});return Se.set(f,w),xe.set(w,f),w};return{state:v(e),watch(f,y){let b=a.get(f);b||(b=new Set,a.set(f,b)),b.add(y);let w=!1;return()=>{if(w)return;w=!0;const u=a.get(f);u&&(u.delete(y),u.size===0&&a.delete(f))}},addObserver(f){t.add(f)},removeObserver(f){t.delete(f)},getStateVersion(){return o},hasPendingChangesFor(f){for(const y of r)for(const b of f)if(y===b||y.startsWith(b+"."))return!0;return!1},flushChanges(){const f=new Set(r);if(f.size>0&&a.size>0){const y=new Map;for(const[b,w]of a){const u=new Set;for(const d of f)i(d,b)&&u.add(d);if(u.size>0)for(const d of w){const g=y.get(d);if(g)for(const T of u)g.add(T);else y.set(d,new Set(u))}}for(const[b,w]of y)b({changedPaths:w})}return r=new Set,f}}}const ee=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function mt(e){const t=e.trim();if(t.startsWith("[")&&t.endsWith("]")){const o=t.slice(1,-1).split(",").map(i=>i.trim());if(o.length!==2)throw new Error("Invalid loop binding: expected <id> or [<id>, <id>]");const[r,a]=o;if(!ee.test(r)||!ee.test(a))throw new Error("Invalid loop binding: expected <id> or [<id>, <id>]");return{type:"tuple",keyVar:r,itemVar:a}}if(!ee.test(t))throw new Error("Invalid loop binding: expected <id> or [<id>, <id>]");return{type:"single",itemVar:t}}function yt(e){const t={acceptNode(n){return n.nodeType===Node.ELEMENT_NODE||n.nodeType===Node.TEXT_NODE&&/\{\{(.+?)\}\}/g.test(n.nodeValue||"")?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}};return document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,t)}function gt(e){const t=e.currentNode;return t?.nextSibling?e.currentNode=t.nextSibling:e.nextNode()}function bt(e,t){let n=t.nextSibling;if(!n){let o=t.parentNode;for(;o&&o!==e.root;){if(o.nextSibling){n=o.nextSibling;break}o=o.parentNode}}return n?(e.currentNode=n,n):null}function Et(e){return e==null||e===!0||e===!1?"":String(e)}function $e(e,t){return e.replace(/\{\{(.+?)\}\}/g,(n,o)=>{const r=H(o.trim(),t);return Et(r)})}async function vt(e,t,n){const o=e.getAttribute("loop");if(!o)return;e.removeAttribute("loop");const r=e.getAttribute("if");r&&e.removeAttribute("if");const a=o.match(/^(.+?)\s+in\s+(.+)$/);if(!a)throw new Error("Invalid loop binding: expected <id> or [<id>, <id>]");const[,i,s]=a,c=mt(i),l=H(s.trim(),t);if(l==null){e.remove();return}if(typeof l!="object"){_.error("State source is not iterable",{collectionExp:s,raw:l});return}const m=Array.isArray(l),p=m?l.map((f,y)=>[String(y),f]):Object.entries(l),N=p.length,x=document.createDocumentFragment(),S=m?dt(l):void 0,v={...t};let P=0;for(const[f,y]of p){if(v.index=P,v.key=f,v.isFirst=P===0,v.isLast=P===N-1,v.isEven=P%2===0,v.isOdd=P%2!==0,c.type==="single"||(v[c.keyVar]=f),v[c.itemVar]=y,r&&!H(r,v)){P++;continue}const b=e.cloneNode(!0);m&&b instanceof HTMLElement&&S&&S[P]!==void 0&&tt(b,S[P]),b instanceof HTMLElement&&(await ke(b,v,n),x.appendChild(b)),P++}x.childNodes.length>0&&e.parentNode?e.parentNode.replaceChild(x,e):e.remove()}function wt(e,t,n){const o=e.parentNode,r=()=>{if(o)return n.get(o)},a=l=>{o&&n.set(o,l)},i=()=>{o&&n.delete(o)},s=e.getAttribute("if");if(s!==null){const l=!!H(s,t);a({hasHead:!0,resolved:l}),l?e.removeAttribute("if"):e.remove();return}const c=e.getAttribute("else-if");if(c!==null){const l=r();if(!l?.hasHead){e.remove();return}if(l.resolved){e.remove();return}const m=!!H(c,t);a({hasHead:!0,resolved:m}),m?e.removeAttribute("else-if"):e.remove();return}if(e.hasAttribute("else")){const l=r();if(!l?.hasHead){e.remove();return}l.resolved?e.remove():e.removeAttribute("else"),i();return}}async function Nt(e,t,n=50){const o=new WeakMap;for(let r=0;r<e.length;r+=n){const a=e.slice(r,r+n);for(const{node:i,state:s}of a){if(i instanceof HTMLElement){if(i.hasAttribute("loop")){await vt(i,s,t);continue}if(i.hasAttribute("if")||i.hasAttribute("else")||i.hasAttribute("else-if")){wt(i,s,o);continue}continue}const c=$e(i.nodeValue,s);if(Fe(c)){const l=document.createRange().createContextualFragment(c);i.replaceWith(l)}else i.nodeValue=c}r+n<e.length&&await new Promise(requestAnimationFrame)}}async function ke(e,t,n){try{const o=yt(e),r=new Set,a=[];let i=o.currentNode;for(;i;){if(r.has(i)){i=o.nextNode();continue}if(r.add(i),i.nodeType===Node.ELEMENT_NODE&&i instanceof HTMLElement){const s=i;if(s.hasAttribute("loop")){a.push({node:s,state:t}),i=bt(o,s);continue}(s.hasAttribute("if")||s.hasAttribute("else")||s.hasAttribute("else-if"))&&a.push({node:s,state:t});for(const c of Array.from(s.attributes)){if(c.name==="ref"&&(n[c.value]=s),c.name.startsWith(":")){const l=c.name.slice(1),m=c.value.trim();try{const p=H(m,t);if(l==="class"&&typeof p=="object"&&p!==null){const N=[];for(const[x,S]of Object.entries(p))S&&N.push(x);if(N.length>0){const x=s.getAttribute("class")||"",S=x?`${x} ${N.join(" ")}`:N.join(" ");s.setAttribute("class",S)}}else p!=null&&p!==!1&&(p===!0?s.setAttribute(l,""):s.setAttribute(l,String(p)));s.removeAttribute(c.name)}catch(p){_.errorWithContext(`Error evaluating dynamic attribute "${c.name}"`,{attributeName:c.name,expression:m},p)}continue}if(c.value.includes("{{"))try{let l=$e(c.value,t);c.name==="class"&&(l=l.replace(/\s+/g," ").trim()),l!==c.value&&s.setAttribute(c.name,l)}catch(l){_.errorWithContext(`Error replacing attribute "${c.name}"`,{attributeName:c.name},l)}}if(s.tagName.includes("-")){i=gt(o)||o.nextNode();continue}}else if(i.nodeType===Node.TEXT_NODE&&i instanceof Text){let s=i.parentElement,c=!1;for(;s;){if(s.tagName.includes("-")){c=!0;break}s=s.parentElement}c||a.push({node:i,state:t})}i=o.nextNode()}await Nt(a,n)}catch(o){throw _.errorWithContext("Error processing template",{},o),o}}function Ct(e,t={}){if(!Array.isArray(e)||e.length===0)throw new Error("composeBySource: layers must be a non-empty array");if(e.some(s=>s==null||typeof s!="object"))throw new Error("composeBySource: all layers must be objects");const{defaultWriteIndex:n=e.length-1,includePrototype:o=!1}=t,r=n>=0&&n<e.length&&Number.isInteger(n)?n:e.length-1;n!==r&&_.warnWithContext(`Invalid defaultWriteIndex ${n}, using ${r}`,{defaultWriteIndex:n,validWriteIndex:r,layersLength:e.length});const a=(s,c)=>o?c in s:Object.prototype.hasOwnProperty.call(s,c),i=s=>{for(let c=0;c<e.length;c++)if(a(e[c],s))return c;return-1};return new Proxy(e[r],{get(s,c){const l=i(c);if(l!==-1)return e[l][c]},set(s,c,l){const m=i(c),p=m!==-1?m:r;return e[p][c]=l,!0},deleteProperty(s,c){const l=i(c);return l===-1?!0:delete e[l][c]},has(s,c){return i(c)!==-1},ownKeys(){const s=new Set;for(const c of e)Reflect.ownKeys(c).forEach(l=>{typeof l!="number"&&s.add(l)});return Array.from(s)},getOwnPropertyDescriptor(s,c){for(const l of e){const m=Object.getOwnPropertyDescriptor(l,c);if(m)return m}}})}function de(e){const t=e.getRootNode(),n=e.parentElement??(t instanceof ShadowRoot?t.host:void 0);if(Ze(n))return n.instance}function At({container:e,host:t}){const n=Array.from(t.childNodes).filter(r=>r.nodeType===Node.ELEMENT_NODE||r.nodeType===Node.TEXT_NODE),o={};for(const r of n){const a=r instanceof HTMLElement&&r.hasAttribute("slot")?r.getAttribute("slot"):"default";o[a]||(o[a]=[]),o[a].push(r)}e.querySelectorAll("slot").forEach(r=>{const a=r.getAttribute("name")||"default",i=o[a];i&&i.length>0&&i.forEach(s=>{r.parentNode.insertBefore(s,r)}),r.remove()})}function te({propName:e,propValue:t,props:n}){const o=n[e],r=t??o?.default;if(!o)return!0;const a=We(o.type),i=Array.isArray(r)?"array":typeof r,s={string:i==="string",number:i==="number",boolean:i==="boolean",array:Array.isArray(r),object:i==="object"&&r!==null&&!Array.isArray(r),function:i==="function"};return(a==="unknown"?!0:s[a]??!1)?o.regex&&typeof r=="string"&&!new RegExp(o.regex).test(r)?(_.error(`Prop "${e}" does not match regex "${o.regex}".`),!1):!0:(_.error(`Prop "${e}" should be of type "${a}", but got "${i}".`,r),!1)}function he({ele:e,parent:t,props:n,state:o}){const r=Object.keys(n).length>0,a=(i,s)=>{Object.defineProperty(o,i,{enumerable:!0,configurable:!0,get(){if(t)return ne(t.state,s)},set(c){if(!(!t||!t.state))try{De(t.state,s,c)}catch(l){_.errorWithContext(`Failed to set bound prop "${i}" → "${s}"`,{propName:i,parentPath:s},l)}}})};for(const i of e.attributes){const s=i.name.startsWith(":"),c=He(i.name.substring(s?1:0));if(s&&!t||!(!r||n[c]&&n[c]!==void 0))continue;if(!s){const N=i.value!==""?i.value:!0;(!r||te({propName:c,propValue:N,props:n}))&&(o[c]=N);continue}const m=i.value?.trim()??"";if(m&&ge(m)){const N=ne(t.state,m);(!r||te({propName:c,propValue:N,props:n}))&&a(c,m);continue}const p=m?H(m,t.state):void 0;(!r||te({propName:c,propValue:p,props:n}))&&(o[c]=p)}for(const[i,s]of Object.entries(n))i in o||(s.default!==void 0?o[i]=s.default:s.required&&_.error(`Required prop "${i}" is missing.`))}function _t(e,t){customElements.define(e,class extends HTMLElement{template;instance;_isDisconnected=!1;_isMounted=!1;_model;_observerFn;_renderAborted=!1;_pendingRender=null;_eventCleanup=null;constructor(){super(),this.template=document.createElement("template"),this.template.innerHTML=t.template}async connectedCallback(){const n=this;if(n.instance&&this._model&&this._observerFn){const h=n.instance,E=de(n);h.$parent=E,this._isDisconnected=!1,this._renderAborted=!1,this._pendingRender=null,this._model.addObserver(this._observerFn),this._isMounted=!0,h.props&&h.state&&he({ele:n,parent:E,props:h.props,state:h.state});return}const r=(t.type||"options")==="options",a=de(n),i=this.template.cloneNode(!0);let s;if(t.deps){s={};const h=Object.entries(t.deps),E=await Promise.all(h.map(([,A])=>A()));for(let A=0;A<h.length;A++)s[h[A][0]]=E[A]}const c=Xe(t.script,s),l={};let m=!1,p=-1;this._isDisconnected=!1,this._renderAborted=!1,this._pendingRender=null;const N=be(),x=(()=>{let h;return{promise:new Promise(A=>{h=A}),resolve:h}})();if(!document.head.querySelector(`style#style-${e}`)){const h=document.createElement("style");h.id=`style-${e}`,h.textContent=t.style,document.head.appendChild(h)}let S,v;const P=h=>{const E=G.plugins[h];if(!E||typeof E.setup!="function"){_.warnWithContext(`Plugin "${h}" not found or has no setup method`,{pluginName:h});return}try{const A=r&&v?v:S;return E.setup.call(A)}catch(A){_.errorWithContext(`Plugin "${h}" setup failed`,{pluginName:h},A);return}},f={};for(const[h,E]of Object.entries(G.modules))if(typeof E.attach=="function"){const A=E.attach.call({element:n,parent:a,core:{take:ce.take}});A&&(f[`$${h}`]=A)}const y=new Map,b=h=>{let E=y.get(h);return E||(E=`on${h.charAt(0).toUpperCase()}${h.slice(1)}`,y.set(h,E)),E},w=(h,...E)=>{const A=b(h);let C=a;for(;C;){const F=C.userContext;if(F){const $=F[A];typeof $=="function"&&$(...E)}else if(C.methods){const $=C.methods[A];typeof $=="function"&&$(...E)}C=C.$parent}},u={$refs:l,$parent:a,$emit:w,$take:P,...f},d=c(u),g=pt(d.state??{});S=g.state;const T=d.methods||{},M=d.props||{},L=d.events||[];let O=d.watchList||[];r&&(v=Ct([T,S])),he({ele:n,parent:a,props:M,state:S}),r&&v&&Le(T,v);for(const h of Ie){const E=d[h];if(typeof E=="function"){const A=r&&v?K(E,v):E;ve(N,h,async()=>{const C=A();C instanceof Promise&&await C})}}this._model=g;const I=async()=>{if(this._isDisconnected)return;if(m){this._renderAborted=!0,this._pendingRender=I;return}const h=g.getStateVersion();if(p!==h){m=!0,this._renderAborted=!1,n.instance&&(n.instance.isRendering=!0);try{const E=i.content.cloneNode(!0);if(At({container:E,host:n}),await ke(E,r&&v?v:S,l),this._renderAborted){this._pendingRender=I;return}const C=r&&v?v:S;if(await R("global","processed",C),await R(N,"processed"),this._renderAborted){this._pendingRender=I;return}r&&v?(rt(v,E),this._eventCleanup&&this._eventCleanup(),this._eventCleanup=ot(v,L,E,l)):(it(T,E),this._eventCleanup&&this._eventCleanup(),this._eventCleanup=st(T,S,L,E,l));const F=g.flushChanges();Object.defineProperty(C,"changedPaths",{value:F,writable:!0,configurable:!0,enumerable:!1});const $=!this._isMounted;if(await R("global",$?"beforeMount":"beforeUpdate",C),await R(N,$?"beforeMount":"beforeUpdate",C),this._renderAborted){delete C.changedPaths,this._pendingRender=I;return}et(n,E,!this._isMounted,t.structAttr),this._isMounted&&(await R("global","updated",C),await R(N,"updated",C)),delete C.changedPaths,p=h,n.instance&&(n.instance._lastRenderedStateVersion=p)}catch(E){_.errorWithContext("Error during render",{componentName:e},E)}finally{const E=r&&v?v:S;if(delete E.changedPaths,m=!1,n.instance&&(n.instance.isRendering=!1),this._pendingRender&&!this._isDisconnected){const A=this._pendingRender;this._pendingRender=null,requestAnimationFrame(()=>{this._isDisconnected||A().catch(C=>{_.errorWithContext("Error during pending render",{componentName:e},C)})})}}}};n.instance={element:n,template:i,state:S,userContext:r?v:void 0,props:M,methods:T,events:L,watchList:O,$refs:l,$parent:a,$emit:w,$take:P,readyPromise:x.promise,lifecycleRegistry:N,...f,isRendering:!1},this._observerFn=()=>{if(this._isDisconnected||O&&O.length>0&&!g.hasPendingChangesFor(O))return;let h=a;for(;h;){if(h.isRendering)return;h=h.$parent}requestAnimationFrame(()=>{this._isDisconnected||I().catch(E=>{_.errorWithContext("Error during render (observer)",{componentName:e},E)})})},g.addObserver(this._observerFn);const k=r&&v?v:S;await R("global","created",k),await R(N,"created"),await I(),this._isMounted||(await R("global","mounted",k),await R(N,"mounted"),this._isMounted=!0),x.resolve()}async disconnectedCallback(){const n=this;if(!n.instance)return;this._isMounted=!1;const o=n.instance;this._isDisconnected=!0,this._renderAborted=!0,this._pendingRender=null,this._model&&this._observerFn&&this._model.removeObserver(this._observerFn);const r=o.userContext||o.state;await R("global","beforeDestroy",r),await R(o.lifecycleRegistry,"beforeDestroy"),this._isDisconnected&&(Te(this),this._eventCleanup&&(this._eventCleanup(),this._eventCleanup=null),document.body.querySelector(this.tagName.toLowerCase())||document.head.querySelector(`style#style-${this.tagName.toLowerCase()}`)?.remove(),await R("global","destroyed",r),await R(o.lifecycleRegistry,"destroyed"),this._isDisconnected&&(this._model=void 0,this._observerFn=void 0,this._eventCleanup=null,n.instance=void 0))}})}let ie=!1,pe=!1,se=[];function Tt(){pe||(pe=!0,!(typeof document>"u"||typeof HTMLElement>"u")&&(ct(),Ye(),lt()))}function Me(...e){const t=e[0],n=e[1];if(Ge(t)){if(!n){_.error("ComponentSource requires a component name when calling take()");return}_t(n,t);return}if(Z(t)||Ke(t)){const o={registerHook:(r,a)=>{ve("global",r,a)},take:ce.take};try{t.install(o),Z(t)?G.plugins[t.name]=t:G.modules[t.name]=t}catch(r){_.errorWithContext("Failed to install extension",{name:t.name,type:Z(t)?"plugin":"module"},r)}return}_.error("Unknown extension type",t)}function St(){ie||(ie=!0,se.forEach(e=>Me(...e)),se=[],_.info("Core initialized"))}const ce=Object.assign(()=>{Tt(),St()},{take:(...t)=>{ie?Me(...t):se.push(t)}});exports.Core=ce;exports.LogLevel=me;exports.logger=_;