@koppajs/koppajs-core 3.0.8 → 3.0.10
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/CHANGELOG.md +42 -0
- package/README.md +18 -0
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.es.js +756 -730
- package/dist/index.es.js.map +1 -1
- package/package.json +6 -4
- package/dist/index.cjs.js +0 -19
- package/dist/index.cjs.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koppajs/koppajs-core",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
|
-
"main": "./dist/index.cjs
|
|
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
|
|
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
|
|
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 be=(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))(be||{});const q={ERROR:"❌",WARN:"⚠️",INFO:"ℹ️",DEBUG:"🔍"};class Le{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,o,n){const i=[t,o];if(n){const l=Object.entries(n).map(([r,s])=>`${r}: ${s}`).join(", ");l&&i.push(`[${l}]`)}return i.join(" ")}error(t,...o){this.shouldLog(3)&&console.error(this.formatMessage(q.ERROR,t),...o)}warn(t,...o){this.shouldLog(2)&&console.warn(this.formatMessage(q.WARN,t),...o)}info(t,...o){this.shouldLog(1)&&console.info(this.formatMessage(q.INFO,t),...o)}debug(t,...o){this.shouldLog(0)&&console.debug(this.formatMessage(q.DEBUG,t),...o)}errorWithContext(t,o,n){if(!this.shouldLog(3))return;const i=this.formatMessage(q.ERROR,t,o);n?console.error(i,n):console.error(i)}warnWithContext(t,o){this.shouldLog(2)&&console.warn(this.formatMessage(q.WARN,t,o))}}const T=new Le;T.init();const ue=Symbol("isBounded"),Ee=Symbol("isProxy"),De=["created","beforeMount","mounted","beforeUpdate","updated","beforeDestroy","destroyed","processed"];function Y(e,t){if(typeof e!="function"||e[ue])return e;const n=e.bind(t);return n[ue]=!0,n}function We(e,t){for(const o in e){const n=e[o];if(Object.prototype.hasOwnProperty.call(e,o)&&typeof n=="function")try{e[o]=Y(n,t)}catch(i){T.errorWithContext(`Failed to bind method "${o}"`,{methodName:o},i)}}}function Fe(e){return/<\/?[a-z][^>]*>/i.test(e)}function re(e,t){if(e==null||typeof t!="string")return;const o=t.trim().replace(/\[(\w+)\]/g,".$1").split(".").filter(Boolean);try{return o.reduce((n,i)=>{if(n!=null)return n[i]},e)}catch{return}}function Ve(e){return typeof e=="string"?e.toLowerCase():typeof e=="function"&&typeof e.name=="string"?e.name.toLowerCase():"unknown"}function ve(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 je(e,t,o){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 n=t.trim().replace(/\[(\w+)\]/g,".$1").split(".").filter(Boolean);if(n.length===0)throw new Error(`❌ setValueByPath: invalid path "${t}".`);const i=(c,a)=>Object.prototype.hasOwnProperty.call(c,a),l=n.pop();let r=e;for(const c of n){if(r==null||typeof r!="object"&&typeof r!="function")throw new Error(`❌ setValueByPath: invalid path "${t}". Segment "${c}" is not an object.`);if(!i(r,c))throw new Error(`❌ setValueByPath: invalid path "${t}". Missing segment "${c}".`);const a=r[c];if(a==null||typeof a!="object"&&typeof a!="function")throw new Error(`❌ setValueByPath: invalid path "${t}". Segment "${c}" is not an object.`);r=a}if(r==null||typeof r!="object"&&typeof r!="function")throw new Error(`❌ setValueByPath: invalid path "${t}". Final target is not an object.`);if(!i(r,l))throw new Error(`❌ setValueByPath: invalid path "${t}". Final key "${l}" does not exist.`);const s=Object.getOwnPropertyDescriptor(r,l);if(s&&s.writable===!1&&!s.set)throw new Error(`❌ setValueByPath: cannot write "${t}". Property "${l}" is read-only.`);r[l]=o}const He={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 o=this.parentNode.firstChild;for(;o;)o.nodeType===Node.ELEMENT_NODE&&o!==this&&o instanceof HTMLElement&&(e?.(o),t.push(o)),o=o.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))}}},Be={};function qe(e){return e.replace(/-./g,t=>t[1].toUpperCase())}const ze=/(?:\bwindow\b|\bdocument\b|\bglobalThis\b|\bFunction\b|\beval\b|\bsetTimeout\b|\bsetInterval\b|\bfetch\b|\bXMLHttpRequest\b|\bimport\b|\brequire\b|\bthis\b)/,z=new Map,Ue=1e3,de=new WeakMap;function Xe(e){const t=Object.keys(e),o=t.join("\0"),n=de.get(e);if(n&&n.fingerprint===o)return n.keys;const i=t.sort();return de.set(e,{keys:i,fingerprint:o}),i}function B(e,t={}){const o=(e??"").trim();if(o)try{if(ze.test(o))return;if(ve(o)){const r=re(t,o);return typeof r=="function"?r.call(t):r}const n=Xe(t),i=`${o}|${n.join(",")}`;let l=z.get(i);if(!l){const r=`"use strict"; return (${o});`;if(l=new Function(...n,r),z.size>=Ue){const s=z.keys().next().value;s&&z.delete(s)}z.set(i,l)}return l(...n.map(r=>t[r]))}catch(n){T.debug(`Expression evaluation failed: ${o}`,n);return}}function Ge(e){return e.length===0?"":e.map(t=>`var ${t} = __deps.${t};`).join(`
|
|
2
|
-
`)+`
|
|
3
|
-
`}function Ke(e,t){const o=e.replace(/\$-\{/g,"${"),n=t?Object.keys(t):[],l=`
|
|
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
|
-
${Ge(n)}
|
|
17
|
-
|
|
18
|
-
return (${o});
|
|
19
|
-
`;try{const r=t?new Function("context","__deps",l):new Function("context",l);return(c=>t?r(c,t):r(c))}catch(r){throw T.errorWithContext("Failed to compile dynamic code",{functionBody:l},r),r}}function we(){return new Map}const Ne=we();function _e(e,t,o){e==="global"&&(e=Ne),e.has(t)||e.set(t,new Set),e.get(t).add(o)}async function P(e,t,o){e==="global"&&(e=Ne);const n=Array.from(e.get(t)??[]);for(const i of n)try{await i(o)}catch(l){T.errorWithContext(`Hook "${t}" callback failed`,{hook:t},l)}}const Z={modules:{},plugins:{}};function Ze(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 J(e){if(e==null||typeof e!="object")return!1;const t=e;return typeof t.setup=="function"&&t.attach===void 0}function Ye(e){if(e==null||typeof e!="object")return!1;const t=e;return typeof t.attach=="function"&&t.setup===void 0}function Je(e){return e instanceof HTMLElement&&"instance"in e&&e.instance!==void 0}const Qe=()=>{Object.defineProperties(Object.prototype,Be),typeof HTMLElement<"u"&&Object.defineProperties(HTMLElement.prototype,He)};function U(e){return e.nodeType===Node.ELEMENT_NODE&&e.tagName.includes("-")}function et(e,t){const o=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:i=>U(i)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP});let n=o.nextNode();for(;n;){const i=n.getAttribute(t);i!==null&&(Se(n)===void 0&&Te(n,i),n.removeAttribute(t)),n=o.nextNode()}}function he(e,t){if(!U(e))return null;const o=e.tagName;let n=Se(e);const i=rt(e);if(n===void 0&&t){const l=e.getAttribute(t);l!==null&&(Te(e,l),n=l,e.removeAttribute(t))}return n===void 0?null:i!==void 0?`${o}:${String(n)}:${String(i)}`:`${o}:${String(n)}`}function tt(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 Q(e,t){const o=new Set(e.getAttributeNames()),n=new Set(t.getAttributeNames());for(const i of o)!n.has(i)&&!i.startsWith("@")&&e.removeAttribute(i);for(const i of n){const l=t.getAttribute(i),r=e.getAttribute(i);l!==r&&(l===null?e.removeAttribute(i):e.setAttribute(i,l))}}function Ce(e,t,o){const n=Array.from(e.childNodes),i=Array.from(t.childNodes),l=new Map,r=new Set;for(const s of n){const c=he(s,o);c!==null&&!l.has(c)&&l.set(c,s)}for(let s=0;s<i.length;s++){const c=i[s],a=n[s],u=he(c,o);let d=null;if(u!==null&&l.has(u)&&(d=l.get(u),r.add(d)),d&&U(d)){a!==d&&(s<e.childNodes.length?e.insertBefore(d,e.childNodes[s]):e.appendChild(d)),Q(d,c);continue}if(U(c)&&u!==null){a?e.replaceChild(c,a):e.appendChild(c);continue}if(!a){e.appendChild(c);continue}if(!tt(a,c)){e.replaceChild(c,a);continue}if(a.nodeType===Node.TEXT_NODE){a.textContent!==c.textContent&&(a.textContent=c.textContent);continue}if(a.nodeType===Node.COMMENT_NODE){a.textContent!==c.textContent&&(a.textContent=c.textContent);continue}if(a.nodeType===Node.ELEMENT_NODE){const v=a,x=c;if(U(v)){Q(v,x);continue}Q(v,x),Ce(v,x,o)}}for(;e.childNodes.length>i.length;){const s=e.lastChild;s&&e.removeChild(s)}}function nt(e,t,o,n){if(o||e.childNodes.length===0){n&&et(t,n),e.replaceChildren(t);return}const i=document.createElement("div");i.appendChild(t),Ce(e,i,n)}const ie=Symbol("STRUCT_ID"),se=Symbol("SLOT_ID");function Ae(e,t,o){Object.defineProperty(e,t,{value:o,writable:!0,configurable:!0,enumerable:!1})}function Te(e,t){Ae(e,ie,t)}function Se(e){return Object.prototype.hasOwnProperty.call(e,ie)?e[ie]:void 0}function ot(e,t){Ae(e,se,t)}function rt(e){return Object.prototype.hasOwnProperty.call(e,se)?e[se]:void 0}function it(e,t,o,n){if(!Array.isArray(t))return()=>{};const i=[];return t.forEach(([l,r,s])=>{if(typeof l!="string"||typeof s!="function"){T.error("Provided handler is not a function",s);return}let c=[];if(r==="window")c=[window];else if(typeof r=="string")if(r.startsWith("$refs.")){const[a,...u]=r.slice(6).split(" "),d=n[a];d&&(c=u.length?Array.from(d.querySelectorAll(u.join(" "))):[d])}else c=Array.from(o.querySelectorAll(r));else if(r instanceof Element||r instanceof Window)c=[r];else if(typeof r=="object"&&r&&"ref"in r){const{ref:a,selector:u}=r,d=n[a];d&&(c=u?Array.from(d.querySelectorAll(u)):[d])}for(const a of c){const u=Y(s,e);a.addEventListener(l,u),i.push({target:a,type:l,handler:u})}}),()=>{for(const{target:l,type:r,handler:s}of i)l.removeEventListener(r,s);i.length=0}}const xe=/^on([a-z]+)$/i;function st(e,t){const o=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT);let n=o.nextNode();for(;n;){for(const i of Array.from(n.attributes)){const l=i.name.match(xe);if(l){const r=l[1].toLowerCase(),s=i.value;if(s){const c=e[s];typeof c=="function"&&(n.removeAttribute(i.name),n.addEventListener(r,c))}}}n=o.nextNode()}}function ct(e,t){const o=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT);let n=o.nextNode();for(;n;){for(const i of Array.from(n.attributes)){const l=i.name.match(xe);if(l){const r=l[1].toLowerCase(),s=i.value;if(s){const c=e[s];typeof c=="function"&&(n.removeAttribute(i.name),n.addEventListener(r,c))}}}n=o.nextNode()}}function at(e,t,o,n,i){if(!Array.isArray(o))return()=>{};const l=[];return o.forEach(([r,s,c])=>{if(typeof r!="string"||typeof c!="function"){T.error("Provided handler is not a function",c);return}let a=[];if(s==="window")a=[window];else if(typeof s=="string")if(s.startsWith("$refs.")){const[u,...d]=s.slice(6).split(" "),v=i[u];v&&(a=d.length?Array.from(v.querySelectorAll(d.join(" "))):[v])}else a=Array.from(n.querySelectorAll(s));else if(s instanceof Element||s instanceof Window)a=[s];else if(typeof s=="object"&&s&&"ref"in s){const{ref:u,selector:d}=s,v=i[u];v&&(a=d?Array.from(v.querySelectorAll(d)):[v])}for(const u of a){const d=Y(c,t);u.addEventListener(r,d),l.push({target:u,type:r,handler:d})}}),()=>{for(const{target:r,type:s,handler:c}of l)r.removeEventListener(s,c);l.length=0}}const V=new WeakMap;let ee;function lt(){if(typeof EventTarget>"u")return;const e=globalThis;if(e.__koppajsEventTrackingPatched)return;e.__koppajsEventTrackingPatched=!0;const t=EventTarget.prototype.addEventListener,o=EventTarget.prototype.removeEventListener;EventTarget.prototype.addEventListener=function(n,i,l){return V.has(this)||V.set(this,new Set),V.get(this).add({type:n,listener:i,options:l}),t.call(this,n,i,l)},EventTarget.prototype.removeEventListener=function(n,i,l){const r=V.get(this);if(r){for(const s of r)if(s.type===n&&s.listener===i){r.delete(s);break}r.size===0&&V.delete(this)}return o.call(this,n,i,l)}}function ft(e){const t=V.get(e);if(t){for(const{type:o,listener:n,options:i}of t)e.removeEventListener(o,n,i);V.delete(e)}}function Me(e){if(typeof document>"u"||typeof NodeFilter>"u"||typeof Element>"u")return;const t=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT);let o=e instanceof Element?e:null;for(;o;)V.has(o)&&ft(o),o=t.nextNode()}function ut(){ee||typeof MutationObserver>"u"||typeof document>"u"||document.body&&(ee=new MutationObserver(e=>{for(const t of e)t.removedNodes.forEach(o=>{o.nodeType===Node.ELEMENT_NODE&&Me(o)})}),ee.observe(document.body,{childList:!0,subtree:!0}))}const Oe=new WeakMap,ke=new WeakMap,X=new WeakMap;let dt=0;const H=()=>`slot-${++dt}`,W=e=>typeof e=="object"&&e!==null,te=e=>typeof e=="symbol"?e.toString():String(e),ht=e=>{const t=Oe.get(e);return t&&W(t)?t:void 0};function $e(e){const t=ke.get(e);return t||e}const F=e=>W(e)?Reflect.get(e,Ee)===!0:!1;function pt(e){const t=F(e)?$e(e):e;return X.get(t)}const mt=e=>e!==null&&(typeof e=="string"||typeof e=="number"||typeof e=="boolean"||typeof e=="function"||typeof e>"u"),K=e=>{let t=X.get(e);return t||(t=e.map(()=>H()),X.set(e,t)),t},pe=e=>{const t=X.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 yt(e){const t=new Set,o=new WeakMap;let n=0,i=new Set;const l=new Map,r=(f,y)=>!!(f===y||f.startsWith(y+".")),s=(f,y)=>{const b=o.get(f)??"";return b?`${b}.${y}`:y};let c=!1;const a=f=>{i.add(f),n++,c||(c=!0,queueMicrotask(()=>{c=!1,t.forEach(y=>{try{y()}catch(b){console.error("Observer error:",b)}})}))},u=(f,y,b)=>{if(f===y)return;let w=f.length!==y.length;if(!w){for(let h=0;h<f.length;h++)if(f[h]!==y[h]){w=!0;break}}f.splice(0,f.length,...y),w&&a(b)},d=(f,y,b)=>{const w=new Set(f),h=new Set(y);let m=!1;for(const E of w)if(!h.has(E)){m=!0;break}if(!m){for(const E of h)if(!w.has(E)){m=!0;break}}m&&(f.splice(0,f.length,...y),a(b))},v=(f,y,b)=>{const w=new Set(f),h=new Set(y);f.length!==y.length||[...w].some(E=>!h.has(E))||[...h].some(E=>!w.has(E))?d(f,y,b):u(f,y,b)},x=(f,y,b)=>{if(f===y)return!1;let w=!1;for(const h of Object.keys(f))h in y||(w=!0,Reflect.deleteProperty(f,h));for(const h of Object.keys(y)){const m=f[h],E=y[h];m!==E&&(W(m)&&F(m)&&W(E)&&!F(E)?(x(m,E)&&(w=!0),m!==E&&(w=!0,Reflect.set(f,h,E))):(w=!0,Reflect.set(f,h,E)))}return w},M=(f,y,b)=>{const w=K(f);switch(y){case"push":{const h=Array.from({length:b.length},()=>H());w.push(...h);break}case"pop":{w.pop();break}case"shift":{w.shift();break}case"unshift":{const h=Array.from({length:b.length},()=>H());w.unshift(...h);break}case"splice":{const h=b[0]??0,m=b[1]!==void 0?b[1]:f.length-h,E=b.slice(2),S=Array.from({length:E.length},()=>H());w.splice(h,m,...S);break}case"reverse":{w.reverse();break}}pe(f)},N=(f,y="")=>{if(f instanceof Node||f instanceof Window||f instanceof Document)return f;const b=ht(f);if(b)return b;y&&o.set(f,y),Array.isArray(f)&&K(f);const w=new Proxy(f,{get:(h,m,E)=>{if(m===Ee)return!0;if(m==="toJSON")return function(){return $e(h)};if(Array.isArray(h)&&typeof m=="string"&&["push","pop","shift","unshift","splice","reverse","sort"].includes(m)){const R=h[m];if(typeof R=="function")return function(...D){if(m==="sort"){const k=K(h),$=h.map((p,_)=>({el:p,slotId:k[_]||H()})),G=R.apply(this,D),g=new Map;for(let p=0;p<$.length;p++){const _=$[p].el;let O=g.get(_);O||(O=[],g.set(_,O)),O.push(p)}for(let p=0;p<h.length;p++){const _=h[p],O=g.get(_);if(O&&O.length>0){const L=O.shift();k[p]=$[L].slotId}else k[p]=H()}return pe(h),G}else{const k=R.apply(this,D);return M(h,m,D),k}}}const S=Reflect.get(h,m,E),A=Array.isArray(h)&&typeof m=="string"&&/^\d+$/.test(m);if(W(S)&&!F(S)&&!A&&(Array.isArray(S)||!Array.isArray(h))){const I=te(m),R=s(h,I);return N(S,R)}return S},set:(h,m,E,S)=>{const A=Reflect.get(h,m,S);if(A===E)return!0;const I=te(m),R=s(h,I);if(Array.isArray(h)&&typeof m=="string"&&/^\d+$/.test(m)){const k=parseInt(m,10);if(k>=0&&k<h.length){const $=Reflect.set(h,m,E,S);return a(R),$}}if(Array.isArray(A)&&!mt(E)&&Array.isArray(E)){v(A,E,R);const k=A.map(()=>H());return X.set(A,k),!0}if(W(A)&&F(A)&&W(E)&&!F(E)){if(x(A,E)){let $=E;W($)&&!F($)&&($=N($,R)),Reflect.set(h,m,$,S),a(R)}return!0}const D=Reflect.set(h,m,E,S);if(W(E)&&!F(E)){const k=N(E,R);Reflect.set(h,m,k,S),Array.isArray(E)&&K(E)}return a(R),D},deleteProperty:(h,m)=>{if(m==="changedPaths")return Reflect.deleteProperty(h,m);const E=te(m),S=s(h,E),A=Reflect.get(h,m),I=Reflect.deleteProperty(h,m);return I&&A!==void 0&&a(S),I}});return Oe.set(f,w),ke.set(w,f),w};return{state:N(e),watch(f,y){let b=l.get(f);b||(b=new Set,l.set(f,b)),b.add(y);let w=!1;return()=>{if(w)return;w=!0;const h=l.get(f);h&&(h.delete(y),h.size===0&&l.delete(f))}},addObserver(f){t.add(f)},removeObserver(f){t.delete(f)},getStateVersion(){return n},hasPendingChangesFor(f){for(const y of i)for(const b of f)if(y===b||y.startsWith(b+"."))return!0;return!1},flushChanges(){const f=new Set(i);if(f.size>0&&l.size>0){const y=new Map;for(const[b,w]of l){const h=new Set;for(const m of f)r(m,b)&&h.add(m);if(h.size>0)for(const m of w){const E=y.get(m);if(E)for(const S of h)E.add(S);else y.set(m,new Set(h))}}for(const[b,w]of y)b({changedPaths:w})}return i=new Set,f}}}const ne=/^[A-Za-z_$][A-Za-z0-9_$]*$/;function gt(e){const t=e.trim();if(t.startsWith("[")&&t.endsWith("]")){const n=t.slice(1,-1).split(",").map(r=>r.trim());if(n.length!==2)throw new Error("Invalid loop binding: expected <id> or [<id>, <id>]");const[i,l]=n;if(!ne.test(i)||!ne.test(l))throw new Error("Invalid loop binding: expected <id> or [<id>, <id>]");return{type:"tuple",keyVar:i,itemVar:l}}if(!ne.test(t))throw new Error("Invalid loop binding: expected <id> or [<id>, <id>]");return{type:"single",itemVar:t}}function bt(e){const t={acceptNode(o){return o.nodeType===Node.ELEMENT_NODE||o.nodeType===Node.TEXT_NODE&&/\{\{(.+?)\}\}/g.test(o.nodeValue||"")?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}};return document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,t)}function Et(e){const t=e.currentNode;return t?.nextSibling?e.currentNode=t.nextSibling:e.nextNode()}function vt(e,t){let o=t.nextSibling;if(!o){let n=t.parentNode;for(;n&&n!==e.root;){if(n.nextSibling){o=n.nextSibling;break}n=n.parentNode}}return o?(e.currentNode=o,o):null}function wt(e){return e==null||e===!0||e===!1?"":String(e)}function Re(e,t){return e.replace(/\{\{(.+?)\}\}/g,(o,n)=>{const i=B(n.trim(),t);return wt(i)})}async function Nt(e,t,o){const n=e.getAttribute("loop");if(!n)return;e.removeAttribute("loop");const i=e.getAttribute("if");i&&e.removeAttribute("if");const l=n.match(/^(.+?)\s+in\s+(.+)$/);if(!l)throw new Error("Invalid loop binding: expected <id> or [<id>, <id>]");const[,r,s]=l,c=gt(r),a=B(s.trim(),t);if(a==null){e.remove();return}if(typeof a!="object"){T.error("State source is not iterable",{collectionExp:s,raw:a});return}const u=Array.isArray(a),d=u?a.map((f,y)=>[String(y),f]):Object.entries(a),v=d.length,x=document.createDocumentFragment(),M=u?pt(a):void 0,N={...t};let C=0;for(const[f,y]of d){if(N.index=C,N.key=f,N.isFirst=C===0,N.isLast=C===v-1,N.isEven=C%2===0,N.isOdd=C%2!==0,c.type==="single"||(N[c.keyVar]=f),N[c.itemVar]=y,i&&!B(i,N)){C++;continue}const b=e.cloneNode(!0);u&&b instanceof HTMLElement&&M&&M[C]!==void 0&&ot(b,M[C]),b instanceof HTMLElement&&(await Pe(b,N,o),x.appendChild(b)),C++}x.childNodes.length>0&&e.parentNode?e.parentNode.replaceChild(x,e):e.remove()}function _t(e,t,o){const n=e.parentNode,i=()=>{if(n)return o.get(n)},l=a=>{n&&o.set(n,a)},r=()=>{n&&o.delete(n)},s=e.getAttribute("if");if(s!==null){const a=!!B(s,t);l({hasHead:!0,resolved:a}),a?e.removeAttribute("if"):e.remove();return}const c=e.getAttribute("else-if");if(c!==null){const a=i();if(!a?.hasHead){e.remove();return}if(a.resolved){e.remove();return}const u=!!B(c,t);l({hasHead:!0,resolved:u}),u?e.removeAttribute("else-if"):e.remove();return}if(e.hasAttribute("else")){const a=i();if(!a?.hasHead){e.remove();return}a.resolved?e.remove():e.removeAttribute("else"),r();return}}async function Ct(e,t,o=50){const n=new WeakMap;for(let i=0;i<e.length;i+=o){const l=e.slice(i,i+o);for(const{node:r,state:s}of l){if(r instanceof HTMLElement){if(r.hasAttribute("loop")){await Nt(r,s,t);continue}if(r.hasAttribute("if")||r.hasAttribute("else")||r.hasAttribute("else-if")){_t(r,s,n);continue}continue}const c=Re(r.nodeValue,s);if(Fe(c)){const a=document.createRange().createContextualFragment(c);r.replaceWith(a)}else r.nodeValue=c}i+o<e.length&&await new Promise(requestAnimationFrame)}}async function Pe(e,t,o){try{const n=bt(e),i=new Set,l=[];let r=n.currentNode;for(;r;){if(i.has(r)){r=n.nextNode();continue}if(i.add(r),r.nodeType===Node.ELEMENT_NODE&&r instanceof HTMLElement){const s=r;if(s.hasAttribute("loop")){l.push({node:s,state:t}),r=vt(n,s);continue}(s.hasAttribute("if")||s.hasAttribute("else")||s.hasAttribute("else-if"))&&l.push({node:s,state:t});for(const c of Array.from(s.attributes)){if(c.name==="ref"&&(o[c.value]=s),c.name.startsWith(":")){const a=c.name.slice(1),u=c.value.trim();try{const d=B(u,t);if(a==="class"&&typeof d=="object"&&d!==null){const v=[];for(const[x,M]of Object.entries(d))M&&v.push(x);if(v.length>0){const x=s.getAttribute("class")||"",M=x?`${x} ${v.join(" ")}`:v.join(" ");s.setAttribute("class",M)}}else d!=null&&d!==!1&&(d===!0?s.setAttribute(a,""):s.setAttribute(a,String(d)));s.removeAttribute(c.name)}catch(d){T.errorWithContext(`Error evaluating dynamic attribute "${c.name}"`,{attributeName:c.name,expression:u},d)}continue}if(c.value.includes("{{"))try{let a=Re(c.value,t);c.name==="class"&&(a=a.replace(/\s+/g," ").trim()),a!==c.value&&s.setAttribute(c.name,a)}catch(a){T.errorWithContext(`Error replacing attribute "${c.name}"`,{attributeName:c.name},a)}}if(s.tagName.includes("-")){r=Et(n)||n.nextNode();continue}}else if(r.nodeType===Node.TEXT_NODE&&r instanceof Text){let s=r.parentElement,c=!1;for(;s;){if(s.tagName.includes("-")){c=!0;break}s=s.parentElement}c||l.push({node:r,state:t})}r=n.nextNode()}await Ct(l,o)}catch(n){throw T.errorWithContext("Error processing template",{},n),n}}function At(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:o=e.length-1,includePrototype:n=!1}=t,i=o>=0&&o<e.length&&Number.isInteger(o)?o:e.length-1;o!==i&&T.warnWithContext(`Invalid defaultWriteIndex ${o}, using ${i}`,{defaultWriteIndex:o,validWriteIndex:i,layersLength:e.length});const l=(s,c)=>n?c in s:Object.prototype.hasOwnProperty.call(s,c),r=s=>{for(let c=0;c<e.length;c++)if(l(e[c],s))return c;return-1};return new Proxy(e[i],{get(s,c){const a=r(c);if(a!==-1)return e[a][c]},set(s,c,a){const u=r(c),d=u!==-1?u:i;return e[d][c]=a,!0},deleteProperty(s,c){const a=r(c);return a===-1?!0:delete e[a][c]},has(s,c){return r(c)!==-1},ownKeys(){const s=new Set;for(const c of e)Reflect.ownKeys(c).forEach(a=>{typeof a!="number"&&s.add(a)});return Array.from(s)},getOwnPropertyDescriptor(s,c){for(const a of e){const u=Object.getOwnPropertyDescriptor(a,c);if(u)return u}}})}function me(e){const t=e.getRootNode(),o=e.parentElement??(t instanceof ShadowRoot?t.host:void 0);if(Je(o))return o.instance}function Tt({container:e,host:t}){const o=Array.from(t.childNodes).filter(i=>i.nodeType===Node.ELEMENT_NODE||i.nodeType===Node.TEXT_NODE),n={};for(const i of o){const l=i instanceof HTMLElement&&i.hasAttribute("slot")?i.getAttribute("slot"):"default";n[l]||(n[l]=[]),n[l].push(i)}e.querySelectorAll("slot").forEach(i=>{const l=i.getAttribute("name")||"default",r=n[l];r&&r.length>0&&r.forEach(s=>{i.parentNode.insertBefore(s,i)}),i.remove()})}function St(e,t,o){const n=new Map,i=new Map,l=()=>{for(const a of Object.keys(o)){const u=n.get(o[a]);u instanceof HTMLElement&&(o[a]=u)}};if(!e.querySelector("slot"))return{commit:()=>{},remapRefs:l};const r=document.createElement("div"),s=a=>{const u=a.cloneNode(!1);if(n.set(u,a),!(a instanceof HTMLElement&&a.tagName.includes("-")))for(const d of a.childNodes)u.appendChild(s(d));return i.set(u,{attributes:new Map(a instanceof HTMLElement?Array.from(a.attributes,d=>[d.name,d.value]):[]),children:Array.from(u.childNodes),value:u.nodeValue}),u};for(const a of t.childNodes)r.appendChild(s(a));return Tt({container:e,host:r}),{commit:()=>{const a=u=>{const d=n.get(u),v=i.get(u),x=Array.from(u.childNodes),M=x.map(a);if(!d||!v)return x.forEach((N,C)=>{M[C]!==N&&N.replaceWith(M[C])}),u;if(d instanceof HTMLElement&&u instanceof HTMLElement){for(const N of v.attributes.keys())u.hasAttribute(N)||d.removeAttribute(N);for(const N of Array.from(u.attributes))v.attributes.get(N.name)!==N.value&&d.setAttribute(N.name,N.value);!d.tagName.includes("-")&&(x.length!==v.children.length||x.some((N,C)=>N!==v.children[C]))&&d.replaceChildren(...M)}else u.nodeValue!==v.value&&(d.nodeValue=u.nodeValue);return d};for(const u of Array.from(e.childNodes)){const d=a(u);d!==u&&u.replaceWith(d)}l()},remapRefs:l}}function oe({propName:e,propValue:t,props:o}){const n=o[e],i=t??n?.default;if(!n)return!0;const l=Ve(n.type),r=Array.isArray(i)?"array":typeof i,s={string:r==="string",number:r==="number",boolean:r==="boolean",array:Array.isArray(i),object:r==="object"&&i!==null&&!Array.isArray(i),function:r==="function"};return(l==="unknown"?!0:s[l]??!1)?n.regex&&typeof i=="string"&&!new RegExp(n.regex).test(i)?(T.error(`Prop "${e}" does not match regex "${n.regex}".`),!1):!0:(T.error(`Prop "${e}" should be of type "${l}", but got "${r}".`,i),!1)}function ye({ele:e,parent:t,props:o,state:n}){const i=Object.keys(o).length>0,l=(r,s)=>{Object.defineProperty(n,r,{enumerable:!0,configurable:!0,get(){if(t)return re(t.state,s)},set(c){if(!(!t||!t.state))try{je(t.state,s,c)}catch(a){T.errorWithContext(`Failed to set bound prop "${r}" → "${s}"`,{propName:r,parentPath:s},a)}}})};for(const r of e.attributes){const s=r.name.startsWith(":"),c=qe(r.name.substring(s?1:0));if(s&&!t||!(!i||o[c]&&o[c]!==void 0))continue;if(!s){const v=r.value!==""?r.value:!0;(!i||oe({propName:c,propValue:v,props:o}))&&(n[c]=v);continue}const u=r.value?.trim()??"";if(u&&ve(u)){const v=re(t.state,u);(!i||oe({propName:c,propValue:v,props:o}))&&l(c,u);continue}const d=u?B(u,t.state):void 0;(!i||oe({propName:c,propValue:d,props:o}))&&(n[c]=d)}for(const[r,s]of Object.entries(o))r in n||(s.default!==void 0?n[r]=s.default:s.required&&T.error(`Required prop "${r}" is missing.`))}function xt(e,t){const o=new Set;customElements.define(e,class extends HTMLElement{template;instance;_connectionVersion=0;_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,i=++this._connectionVersion;if(this._isDisconnected=!1,this._renderAborted=!1,this._pendingRender=null,o.add(this),!document.head.querySelector(`style#style-${e}`)){const g=document.createElement("style");g.id=`style-${e}`,g.textContent=t.style,document.head.appendChild(g)}if(n.instance&&this._model&&this._observerFn){const g=n.instance,p=me(n);g.$parent=p,this._isDisconnected=!1,this._renderAborted=!1,this._pendingRender=null,this._model.addObserver(this._observerFn),g.props&&g.state&&ye({ele:n,parent:p,props:g.props,state:g.state});return}const r=(t.type||"options")==="options",s=me(n),c=this.template.cloneNode(!0);let a;if(t.deps){a={};const g=Object.entries(t.deps),p=await Promise.all(g.map(([,_])=>_()));for(let _=0;_<g.length;_++)a[g[_][0]]=p[_]}if(i!==this._connectionVersion||this._isDisconnected)return;const u=Ke(t.script,a),d={};let v=!1,x=-1;this._isDisconnected=!1,this._renderAborted=!1,this._pendingRender=null;const M=we(),N=(()=>{let g;return{promise:new Promise(_=>{g=_}),resolve:g}})();let C,f;const y=g=>{const p=Z.plugins[g];if(!p||typeof p.setup!="function"){T.warnWithContext(`Plugin "${g}" not found or has no setup method`,{pluginName:g});return}try{const _=r&&f?f:C;return p.setup.call(_)}catch(_){T.errorWithContext(`Plugin "${g}" setup failed`,{pluginName:g},_);return}},b={};for(const[g,p]of Object.entries(Z.modules))if(typeof p.attach=="function"){const _=p.attach.call({element:n,parent:s,core:{take:le.take}});_&&(b[`$${g}`]=_)}const w=new Map,h=g=>{let p=w.get(g);return p||(p=`on${g.charAt(0).toUpperCase()}${g.slice(1)}`,w.set(g,p)),p},m=(g,...p)=>{const _=h(g);let O=s;for(;O;){const L=O.userContext;if(L){const j=L[_];typeof j=="function"&&j(...p)}else if(O.methods){const j=O.methods[_];typeof j=="function"&&j(...p)}O=O.$parent}},E={$refs:d,$parent:s,$emit:m,$take:y,...b},S=u(E),A=yt(S.state??{});C=A.state;const I=S.methods||{},R=S.props||{},D=S.events||[];let k=S.watchList||[];r&&(f=At([I,C])),ye({ele:n,parent:s,props:R,state:C}),r&&f&&We(I,f);for(const g of De){const p=S[g];if(typeof p=="function"){const _=r&&f?Y(p,f):p;_e(M,g,async()=>{const O=_();O instanceof Promise&&await O})}}this._model=A;const $=async()=>{if(this._isDisconnected)return;if(v){this._renderAborted=!0,this._pendingRender=$;return}const g=A.getStateVersion();if(x!==g){v=!0,this._renderAborted=!1,n.instance&&(n.instance.isRendering=!0);try{const p=c.content.cloneNode(!0),_=St(p,n,d);if(await Pe(p,r&&f?f:C,d),_.remapRefs(),this._renderAborted||this._model!==A){this._pendingRender=$;return}const L=r&&f?f:C;if(await P("global","processed",L),await P(M,"processed"),this._renderAborted||this._model!==A){this._pendingRender=$;return}const j=A.flushChanges();Object.defineProperty(L,"changedPaths",{value:j,writable:!0,configurable:!0,enumerable:!1});const fe=!this._isMounted;if(await P("global",fe?"beforeMount":"beforeUpdate",L),await P(M,fe?"beforeMount":"beforeUpdate",L),this._renderAborted||this._model!==A){delete L.changedPaths,this._pendingRender=$;return}_.commit(),r&&f?(st(f,p),this._eventCleanup&&this._eventCleanup(),this._eventCleanup=it(f,D,p,d)):(ct(I,p),this._eventCleanup&&this._eventCleanup(),this._eventCleanup=at(I,C,D,p,d)),nt(n,p,!this._isMounted,t.structAttr),this._isMounted&&(await P("global","updated",L),await P(M,"updated",L)),delete L.changedPaths,x=g,n.instance&&(n.instance._lastRenderedStateVersion=x)}catch(p){T.errorWithContext("Error during render",{componentName:e},p)}finally{const p=r&&f?f:C;if(delete p.changedPaths,v=!1,n.instance&&(n.instance.isRendering=!1),this._pendingRender&&!this._isDisconnected){const _=this._pendingRender;this._pendingRender=null,requestAnimationFrame(()=>{this._isDisconnected||_().catch(O=>{T.errorWithContext("Error during pending render",{componentName:e},O)})})}}}};n.instance={element:n,template:c,state:C,userContext:r?f:void 0,props:R,methods:I,events:D,watchList:k,$refs:d,$parent:s,$emit:m,$take:y,readyPromise:N.promise,lifecycleRegistry:M,...b,isRendering:!1},this._observerFn=()=>{if(this._isDisconnected||k&&k.length>0&&!A.hasPendingChangesFor(k))return;let g=s;for(;g;){if(g.isRendering)return;g=g.$parent}requestAnimationFrame(()=>{this._isDisconnected||$().catch(p=>{T.errorWithContext("Error during render (observer)",{componentName:e},p)})})},A.addObserver(this._observerFn);const G=r&&f?f:C;if(await P("global","created",G),await P(M,"created"),!(this._isDisconnected||this._model!==A)&&(await $(),!(this._isDisconnected||this._model!==A))){if(!this._isMounted){if(await P("global","mounted",G),this._isDisconnected||this._model!==A||(await P(M,"mounted"),this._isDisconnected||this._model!==A))return;this._isMounted=!0}N.resolve()}}async disconnectedCallback(){const n=this,i=++this._connectionVersion;if(this._isDisconnected=!0,this._renderAborted=!0,this._pendingRender=null,o.delete(this),o.size===0&&document.head.querySelector(`style#style-${e}`)?.remove(),!n.instance)return;const l=n.instance;this._isDisconnected=!0,this._renderAborted=!0,this._pendingRender=null,this._model&&this._observerFn&&this._model.removeObserver(this._observerFn);const r=l.userContext||l.state;await P("global","beforeDestroy",r),await P(l.lifecycleRegistry,"beforeDestroy"),!(!this._isDisconnected||i!==this._connectionVersion)&&(Me(this),this._eventCleanup&&(this._eventCleanup(),this._eventCleanup=null),await P("global","destroyed",r),await P(l.lifecycleRegistry,"destroyed"),!(!this._isDisconnected||i!==this._connectionVersion)&&(this._isMounted=!1,this._model=void 0,this._observerFn=void 0,this._eventCleanup=null,n.instance=void 0))}})}let ce=!1,ge=!1,ae=[];function Mt(){ge||(ge=!0,!(typeof document>"u"||typeof HTMLElement>"u")&&(lt(),Qe(),ut()))}function Ie(...e){const t=e[0],o=e[1];if(Ze(t)){if(!o){T.error("ComponentSource requires a component name when calling take()");return}xt(o,t);return}if(J(t)||Ye(t)){const n={registerHook:(i,l)=>{_e("global",i,l)},take:le.take};try{t.install(n),J(t)?Z.plugins[t.name]=t:Z.modules[t.name]=t}catch(i){T.errorWithContext("Failed to install extension",{name:t.name,type:J(t)?"plugin":"module"},i)}return}T.error("Unknown extension type",t)}function Ot(){ce||(ce=!0,ae.forEach(e=>Ie(...e)),ae=[],T.info("Core initialized"))}const le=Object.assign(()=>{Mt(),Ot()},{take:(...t)=>{ce?Ie(...t):ae.push(t)}});exports.Core=le;exports.LogLevel=be;exports.logger=T;
|