@koppajs/koppajs-core 3.0.0
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 +153 -0
- package/LICENSE +201 -0
- package/README.md +152 -0
- package/dist/component.d.ts +29 -0
- package/dist/compose.d.ts +11 -0
- package/dist/event-handler.d.ts +40 -0
- package/dist/global-event-cleaner.d.ts +28 -0
- package/dist/globals.d.ts +82 -0
- package/dist/index.cjs.js +19 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.es.js +1603 -0
- package/dist/index.es.js.map +1 -0
- package/dist/kpa.d.ts +4 -0
- package/dist/model.d.ts +40 -0
- package/dist/template-processor.d.ts +17 -0
- package/dist/types.d.ts +364 -0
- package/dist/utils/dom.d.ts +3 -0
- package/dist/utils/extend.d.ts +9 -0
- package/dist/utils/extension-registry.d.ts +10 -0
- package/dist/utils/helper.d.ts +55 -0
- package/dist/utils/hook-registry.d.ts +34 -0
- package/dist/utils/identity.d.ts +6 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/logger.d.ts +87 -0
- package/dist/utils/object.d.ts +3 -0
- package/dist/utils/reconcile.d.ts +23 -0
- package/dist/utils/script.d.ts +18 -0
- package/dist/utils/string.d.ts +18 -0
- package/dist/utils/template-watch.d.ts +7 -0
- package/dist/utils/type-guards.d.ts +82 -0
- package/package.json +107 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
export {}
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
interface HTMLElement {
|
|
5
|
+
/**
|
|
6
|
+
* Query and return the first matching descendant element.
|
|
7
|
+
* If called on an <input> or <textarea>, selects its text instead.
|
|
8
|
+
* @param selector - CSS selector string
|
|
9
|
+
* @returns the first matching HTMLElement or null/void if none
|
|
10
|
+
*/
|
|
11
|
+
select(selector: string): HTMLElement | null | void
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Query and return all matching descendant nodes.
|
|
15
|
+
* @param selector - CSS selector string
|
|
16
|
+
* @returns a NodeList of matching elements
|
|
17
|
+
*/
|
|
18
|
+
selectAll(selector: string): NodeList
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Add one or more CSS classes to the element.
|
|
22
|
+
* @param classes - space-delimited list of class names
|
|
23
|
+
* @returns the element, for chaining
|
|
24
|
+
*/
|
|
25
|
+
addClass(classes: string): HTMLElement
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Remove one or more CSS classes from the element.
|
|
29
|
+
* @param classes - space-delimited list of class names
|
|
30
|
+
* @returns the element, for chaining
|
|
31
|
+
*/
|
|
32
|
+
removeClass(classes: string): HTMLElement
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Toggle one or more CSS classes on the element.
|
|
36
|
+
* @param classes - space-delimited list of class names
|
|
37
|
+
* @returns the element, for chaining
|
|
38
|
+
*/
|
|
39
|
+
toggleClass(classes: string): HTMLElement
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Check if the element has the given CSS class.
|
|
43
|
+
* @param className - name of the class to test
|
|
44
|
+
* @returns true if present, false otherwise
|
|
45
|
+
*/
|
|
46
|
+
hasClass(className: string): boolean
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Replace this element in the DOM with another element or raw HTML/text.
|
|
50
|
+
* @param newNode - HTMLElement or HTML string to insert
|
|
51
|
+
*/
|
|
52
|
+
replaceWith(newNode: HTMLElement | string): void
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Get all sibling elements of this node.
|
|
56
|
+
* Optionally, invoke a callback for each sibling.
|
|
57
|
+
* @param callback - optional function to receive each sibling
|
|
58
|
+
* @returns an array of sibling HTMLElements
|
|
59
|
+
*/
|
|
60
|
+
siblings(callback?: (sibling: HTMLElement) => void): HTMLElement[]
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Insert a new node or HTML string immediately before this element.
|
|
64
|
+
* @param newNode - HTMLElement or HTML string to insert
|
|
65
|
+
*/
|
|
66
|
+
before(newNode: HTMLElement | string): void
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Insert a new node or HTML string immediately after this element.
|
|
70
|
+
* @param newNode - HTMLElement or HTML string to insert
|
|
71
|
+
*/
|
|
72
|
+
after(newNode: HTMLElement | string): void
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Get or set an attribute on the element.
|
|
76
|
+
* @param attrName - attribute name
|
|
77
|
+
* @param attrValue - if provided, sets the attribute to this value
|
|
78
|
+
* @returns the current value, or null/undefined if not set
|
|
79
|
+
*/
|
|
80
|
+
attr(attrName: string, attrValue?: string): string | undefined
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 Ie{constructor(){this.level=3,this.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 T=new Ie;T.init();const ae=Symbol("isBounded"),ye=Symbol("isProxy"),Le=["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 De(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){T.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 je(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 Ve={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))}}},He={};function Be(e){return e.replace(/-./g,t=>t[1].toUpperCase())}const qe=/(?:\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,ze=1e3,le=new WeakMap;function Ue(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(qe.test(n))return;if(ge(n)){const i=ne(t,n);return typeof i=="function"?i.call(t):i}const o=Ue(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>=ze){const s=q.keys().next().value;s&&q.delete(s)}q.set(r,a)}return a(...o.map(i=>t[i]))}catch(o){T.debug(`Expression evaluation failed: ${n}`,o);return}}function Xe(e){return e.length===0?"":e.map(t=>`var ${t} = __deps.${t};`).join(`
|
|
2
|
+
`)+`
|
|
3
|
+
`}function Ge(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
|
+
${Xe(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 T.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){T.errorWithContext(`Hook "${t}" callback failed`,{hook:t},a)}}const G={modules:{},plugins:{}};function Ke(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 Ze(e){if(e==null||typeof e!="object")return!1;const t=e;return typeof t.attach=="function"&&t.setup===void 0}function Ye(e){return e instanceof HTMLElement&&"instance"in e&&e.instance!==void 0}const Je=()=>{Object.defineProperties(Object.prototype,He),typeof HTMLElement<"u"&&Object.defineProperties(HTMLElement.prototype,Ve)};function z(e){return e.nodeType===Node.ELEMENT_NODE&&e.tagName.includes("-")}function Qe(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=ot(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 et(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(!et(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 tt(e,t,n,o){if(n||e.childNodes.length===0){o&&Qe(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 nt(e,t){Ne(e,re,t)}function ot(e){return Object.prototype.hasOwnProperty.call(e,re)?e[re]:void 0}function rt(e,t,n,o){if(!Array.isArray(t))return()=>{};const r=[];return t.forEach(([a,i,s])=>{if(typeof a!="string"||typeof s!="function"){T.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 Te=/^on([a-z]+)$/i;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(Te);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){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(Te);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 ct(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"){T.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 at(){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 lt(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 _e(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)&<(n),n=t.nextNode()}function ft(){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&&_e(n)})}),J.observe(document.body,{childList:!0,subtree:!0}))}const Se=new WeakMap,xe=new WeakMap,U=new WeakMap;let ut=0;const V=()=>`slot-${++ut}`,F=e=>typeof e=="object"&&e!==null,Q=e=>typeof e=="symbol"?e.toString():String(e),dt=e=>{const t=Se.get(e);return t&&F(t)?t:void 0};function Oe(e){const t=xe.get(e);return t||e}const W=e=>F(e)?Reflect.get(e,ye)===!0:!1;function ht(e){const t=W(e)?Oe(e):e;return U.get(t)}const pt=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 mt(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&&(F(d)&&W(d)&&F(g)&&!W(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),_=Array.from({length:g.length},()=>V());w.splice(u,d,..._);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=dt(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,D)=>({el:C,slotId:k[D]||V()})),E=O.apply(this,I),A=new Map;for(let C=0;C<h.length;C++){const D=h[C].el;let $=A.get(D);$||($=[],A.set(D,$)),$.push(C)}for(let C=0;C<u.length;C++){const D=u[C],$=A.get(D);if($&&$.length>0){const Pe=$.shift();k[C]=h[Pe].slotId}else k[C]=V()}return ue(u),E}else{const k=O.apply(this,I);return S(u,d,I),k}}}const _=Reflect.get(u,d,g),M=Array.isArray(u)&&typeof d=="string"&&/^\d+$/.test(d);if(F(_)&&!W(_)&&!M&&(Array.isArray(_)||!Array.isArray(u))){const L=Q(d),O=s(u,L);return v(_,O)}return _},set:(u,d,g,_)=>{const M=Reflect.get(u,d,_);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,_);return l(O),h}}if(Array.isArray(M)&&!pt(g)&&Array.isArray(g)){N(M,g,O);const k=M.map(()=>V());return U.set(M,k),!0}if(F(M)&&W(M)&&F(g)&&!W(g)){if(x(M,g)){let h=g;F(h)&&!W(h)&&(h=v(h,O)),Reflect.set(u,d,h,_),l(O)}return!0}const I=Reflect.set(u,d,g,_);if(F(g)&&!W(g)){const k=v(g,O);Reflect.set(u,d,k,_),Array.isArray(g)&&X(g)}return l(O),I},deleteProperty:(u,d)=>{if(d==="changedPaths")return Reflect.deleteProperty(u,d);const g=Q(d),_=s(u,g),M=Reflect.get(u,d),L=Reflect.deleteProperty(u,d);return L&&M!==void 0&&l(_),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 _ of u)g.add(_);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 yt(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 gt(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 bt(e){const t=e.currentNode;return t?.nextSibling?e.currentNode=t.nextSibling:e.nextNode()}function Et(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 vt(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 vt(r)})}async function wt(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=yt(i),l=H(s.trim(),t);if(l==null){e.remove();return}if(typeof l!="object"){T.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?ht(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&&nt(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 Nt(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 Ct(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 wt(i,s,t);continue}if(i.hasAttribute("if")||i.hasAttribute("else")||i.hasAttribute("else-if")){Nt(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=gt(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=Et(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){T.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){T.errorWithContext(`Error replacing attribute "${c.name}"`,{attributeName:c.name},l)}}if(s.tagName.includes("-")){i=bt(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 Ct(a,n)}catch(o){throw T.errorWithContext("Error processing template",{},o),o}}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:n=e.length-1,includePrototype:o=!1}=t,r=n>=0&&n<e.length&&Number.isInteger(n)?n:e.length-1;n!==r&&T.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(Ye(n))return n.instance}function Tt({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)?(T.error(`Prop "${e}" does not match regex "${o.regex}".`),!1):!0:(T.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{je(t.state,s,c)}catch(l){T.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=Be(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&&T.error(`Required prop "${i}" is missing.`))}function _t(e,t){customElements.define(e,class extends HTMLElement{constructor(){super(),this._isDisconnected=!1,this._isMounted=!1,this._renderAborted=!1,this._pendingRender=null,this._eventCleanup=null,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=Ge(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"){T.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){T.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 D=C.userContext;if(D){const $=D[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=mt(d.state??{});S=g.state;const _=d.methods||{},M=d.props||{},L=d.events||[];let O=d.watchList||[];r&&(v=At([_,S])),he({ele:n,parent:a,props:M,state:S}),r&&v&&De(_,v);for(const h of Le){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(Tt({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?(it(v,E),this._eventCleanup&&this._eventCleanup(),this._eventCleanup=rt(v,L,E,l)):(st(_,E),this._eventCleanup&&this._eventCleanup(),this._eventCleanup=ct(_,S,L,E,l));const D=g.flushChanges();Object.defineProperty(C,"changedPaths",{value:D,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}tt(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){T.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=>{T.errorWithContext("Error during pending render",{componentName:e},C)})})}}}};n.instance={element:n,template:i,state:S,userContext:r?v:void 0,props:M,methods:_,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=>{T.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&&(_e(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 Me(){pe||(pe=!0,!(typeof document>"u"||typeof HTMLElement>"u")&&(at(),Je(),ft()))}function Re(...e){const t=e[0],n=e[1];if(Ke(t)){if(!n){T.error("ComponentSource requires a component name when calling take()");return}_t(n,t);return}if(Z(t)||Ze(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){T.errorWithContext("Failed to install extension",{name:t.name,type:Z(t)?"plugin":"module"},r)}return}T.error("Unknown extension type",t)}function St(){ie||(ie=!0,se.forEach(e=>Re(...e)),se=[],T.info("Core initialized"))}const ce=Object.assign(()=>{Me(),St()},{take:(...t)=>{ie?Re(...t):se.push(t)}});exports.Core=ce;exports.LogLevel=me;exports.initDomEnvironment=Me;exports.logger=T;
|