elit 1.0.0 → 2.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/LICENSE +21 -0
- package/README.md +552 -19
- package/dist/build.d.mts +11 -0
- package/dist/build.d.ts +11 -0
- package/dist/build.js +1 -0
- package/dist/build.mjs +1 -0
- package/dist/cli.js +2307 -0
- package/dist/client.d.mts +9 -0
- package/dist/client.d.ts +9 -0
- package/dist/client.js +1 -0
- package/dist/client.mjs +1 -0
- package/dist/dom.d.mts +80 -0
- package/dist/dom.d.ts +80 -0
- package/dist/dom.js +1 -0
- package/dist/dom.mjs +1 -0
- package/dist/el.d.mts +227 -0
- package/dist/el.d.ts +227 -0
- package/dist/el.js +1 -0
- package/dist/el.mjs +1 -0
- package/dist/hmr.d.mts +38 -0
- package/dist/hmr.d.ts +38 -0
- package/dist/hmr.js +1 -0
- package/dist/hmr.mjs +1 -0
- package/dist/index.d.mts +38 -490
- package/dist/index.d.ts +38 -490
- package/dist/index.js +1 -2266
- package/dist/index.mjs +1 -2039
- package/dist/router.d.mts +45 -0
- package/dist/router.d.ts +45 -0
- package/dist/router.js +1 -0
- package/dist/router.mjs +1 -0
- package/dist/server.d.mts +3 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +1 -0
- package/dist/server.mjs +1 -0
- package/dist/state.d.mts +109 -0
- package/dist/state.d.ts +109 -0
- package/dist/state.js +1 -0
- package/dist/state.mjs +1 -0
- package/dist/style.d.mts +113 -0
- package/dist/style.d.ts +113 -0
- package/dist/style.js +1 -0
- package/dist/style.mjs +1 -0
- package/dist/types-DOAdFFJB.d.mts +330 -0
- package/dist/types-DOAdFFJB.d.ts +330 -0
- package/dist/types.d.mts +3 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +1 -0
- package/dist/types.mjs +0 -0
- package/package.json +77 -7
- package/dist/index.global.js +0 -2064
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DomNode, dom } from './dom.mjs';
|
|
2
|
+
export { SharedState, batchRender, bindChecked, bindValue, cleanupUnused, computed, createSharedState, createState, createVirtualList, debounce, effect, lazy, reactive, reactiveAs, renderChunked, sharedStateManager, text, throttle } from './state.mjs';
|
|
3
|
+
export { CSSRule, CSSVariable, ContainerRule, CreateStyle, FontFace, KeyframeStep, Keyframes, LayerRule, MediaRule, SupportsRule } from './style.mjs';
|
|
4
|
+
export { a, abbr, address, area, article, aside, audio, b, base, bdi, bdo, blockquote, body, br, button, canvas, caption, cite, code, col, colgroup, commentNode, createEl, createElementFactory, createMathEl, createSvgEl, data, datalist, dd, del, details, dfn, dialog, div, dl, doc, dt, el, elements, em, embed, fieldset, figcaption, figure, footer, form, fragment, getEl, getElClass, getElId, getElName, getElTag, getEls, h1, h2, h3, h4, h5, h6, head, header, hr, html, i, iframe, img, input, ins, kbd, label, legend, li, link, main, map, mark, mathMath, mathMfrac, mathMi, mathMn, mathMo, mathMroot, mathMrow, mathMs, mathMsqrt, mathMsub, mathMsup, mathMtext, menu, meta, meter, nav, noscript, object, ol, optgroup, option, output, p, param, picture, portal, pre, progress, q, rp, rt, ruby, s, samp, script, section, select, slot, small, source, span, strong, style, sub, summary, sup, svgAnimate, svgAnimateMotion, svgAnimateTransform, svgCircle, svgClipPath, svgDefs, svgEllipse, svgFeBlend, svgFeColorMatrix, svgFeComponentTransfer, svgFeComposite, svgFeConvolveMatrix, svgFeDiffuseLighting, svgFeDisplacementMap, svgFeFlood, svgFeGaussianBlur, svgFeMorphology, svgFeOffset, svgFeSpecularLighting, svgFeTile, svgFeTurbulence, svgFilter, svgForeignObject, svgG, svgImage, svgLine, svgLinearGradient, svgMarker, svgMask, svgPath, svgPattern, svgPolygon, svgPolyline, svgRadialGradient, svgRect, svgSet, svgStop, svgSvg, svgSymbol, svgText, svgTspan, svgUse, table, tbody, td, template, textNode, textarea, tfoot, th, thead, time, title, tr, track, u, ul, varElement, video, wbr } from './el.mjs';
|
|
5
|
+
export { Route, RouteLocation, RouteParams, Router, RouterOptions, createRouter, createRouterView, routerLink } from './router.mjs';
|
|
6
|
+
export { HMRClient, default as hmr } from './hmr.mjs';
|
|
7
|
+
import './types-DOAdFFJB.mjs';
|
|
8
|
+
import 'http';
|
|
9
|
+
import 'ws';
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { DomNode, dom } from './dom.js';
|
|
2
|
+
export { SharedState, batchRender, bindChecked, bindValue, cleanupUnused, computed, createSharedState, createState, createVirtualList, debounce, effect, lazy, reactive, reactiveAs, renderChunked, sharedStateManager, text, throttle } from './state.js';
|
|
3
|
+
export { CSSRule, CSSVariable, ContainerRule, CreateStyle, FontFace, KeyframeStep, Keyframes, LayerRule, MediaRule, SupportsRule } from './style.js';
|
|
4
|
+
export { a, abbr, address, area, article, aside, audio, b, base, bdi, bdo, blockquote, body, br, button, canvas, caption, cite, code, col, colgroup, commentNode, createEl, createElementFactory, createMathEl, createSvgEl, data, datalist, dd, del, details, dfn, dialog, div, dl, doc, dt, el, elements, em, embed, fieldset, figcaption, figure, footer, form, fragment, getEl, getElClass, getElId, getElName, getElTag, getEls, h1, h2, h3, h4, h5, h6, head, header, hr, html, i, iframe, img, input, ins, kbd, label, legend, li, link, main, map, mark, mathMath, mathMfrac, mathMi, mathMn, mathMo, mathMroot, mathMrow, mathMs, mathMsqrt, mathMsub, mathMsup, mathMtext, menu, meta, meter, nav, noscript, object, ol, optgroup, option, output, p, param, picture, portal, pre, progress, q, rp, rt, ruby, s, samp, script, section, select, slot, small, source, span, strong, style, sub, summary, sup, svgAnimate, svgAnimateMotion, svgAnimateTransform, svgCircle, svgClipPath, svgDefs, svgEllipse, svgFeBlend, svgFeColorMatrix, svgFeComponentTransfer, svgFeComposite, svgFeConvolveMatrix, svgFeDiffuseLighting, svgFeDisplacementMap, svgFeFlood, svgFeGaussianBlur, svgFeMorphology, svgFeOffset, svgFeSpecularLighting, svgFeTile, svgFeTurbulence, svgFilter, svgForeignObject, svgG, svgImage, svgLine, svgLinearGradient, svgMarker, svgMask, svgPath, svgPattern, svgPolygon, svgPolyline, svgRadialGradient, svgRect, svgSet, svgStop, svgSvg, svgSymbol, svgText, svgTspan, svgUse, table, tbody, td, template, textNode, textarea, tfoot, th, thead, time, title, tr, track, u, ul, varElement, video, wbr } from './el.js';
|
|
5
|
+
export { Route, RouteLocation, RouteParams, Router, RouterOptions, createRouter, createRouterView, routerLink } from './router.js';
|
|
6
|
+
export { HMRClient, default as hmr } from './hmr.js';
|
|
7
|
+
import './types-DOAdFFJB.js';
|
|
8
|
+
import 'http';
|
|
9
|
+
import 'ws';
|
package/dist/client.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=class{constructor(){this.elementCache=new WeakMap,this.reactiveNodes=new Map}createElement(e,t={},r=[]){return{tagName:e,props:t,children:r}}renderToDOM(e,t){if(null==e||!1===e)return;if("object"!=typeof e)return void t.appendChild(document.createTextNode(String(e)));let{tagName:r,props:s,children:o}=e,n="svg"===r||"s"===r[0]&&"v"===r[1]&&"g"===r[2]||"http://www.w3.org/2000/svg"===t.namespaceURI,i=n?document.createElementNS("http://www.w3.org/2000/svg",r.replace("svg","").toLowerCase()||r):document.createElement(r);for(let e in s){let t=s[e];if(null==t||!1===t)continue;let r=e.charCodeAt(0);if(99===r&&(e.length<6||"N"===e[5])){let e=Array.isArray(t)?t.join(" "):t;n?i.setAttribute("class",e):i.className=e}else if(115===r&&5===e.length)if("string"==typeof t)i.style.cssText=t;else{let e=i.style;for(let r in t)e[r]=t[r]}else 111===r&&110===e.charCodeAt(1)?i[e.toLowerCase()]=t:100===r&&e.length>20?i.innerHTML=t.__html:114===r&&3===e.length?setTimeout(()=>{"function"==typeof t?t(i):t.current=i},0):i.setAttribute(e,!0===t?"":String(t))}let a=o.length;if(!a)return void t.appendChild(i);let l=e=>{for(let t=0;t<a;t++){let r=o[t];if(null!=r&&!1!==r)if(Array.isArray(r))for(let t=0,s=r.length;t<s;t++){let s=r[t];null!=s&&!1!==s&&this.renderToDOM(s,e)}else this.renderToDOM(r,e)}};if(a>30){let e=document.createDocumentFragment();l(e),i.appendChild(e)}else l(i);t.appendChild(i)}render(e,t){let r="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!r)throw new Error(`Element not found: ${e}`);if(t.children&&t.children.length>500){let e=document.createDocumentFragment();this.renderToDOM(t,e),r.appendChild(e)}else this.renderToDOM(t,r);return r}batchRender(e,t){let r="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!r)throw new Error(`Element not found: ${e}`);let s=t.length;if(s>3e3){let e=document.createDocumentFragment(),o=0,n=1500,i=()=>{let a=Math.min(o+n,s);for(let r=o;r<a;r++)this.renderToDOM(t[r],e);o=a,o>=s?r.appendChild(e):requestAnimationFrame(i)};i()}else{let e=document.createDocumentFragment();for(let r=0;r<s;r++)this.renderToDOM(t[r],e);r.appendChild(e)}return r}renderChunked(e,t,r=5e3,s){let o="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!o)throw new Error(`Element not found: ${e}`);let n=t.length,i=0,a=()=>{let e=Math.min(i+r,n),l=document.createDocumentFragment();for(let r=i;r<e;r++)this.renderToDOM(t[r],l);o.appendChild(l),i=e,s&&s(i,n),i<n&&requestAnimationFrame(a)};return requestAnimationFrame(a),o}renderToHead(...e){let t=document.head;if(t)for(let r of e.flat())r&&this.renderToDOM(r,t);return t}addStyle(e){let t=document.createElement("style");return t.textContent=e,document.head.appendChild(t)}addMeta(e){let t=document.createElement("meta");for(let r in e)t.setAttribute(r,e[r]);return document.head.appendChild(t)}addLink(e){let t=document.createElement("link");for(let r in e)t.setAttribute(r,e[r]);return document.head.appendChild(t)}setTitle(e){return document.title=e}createState(e,t={}){let r=e,s=new Set,o=null,{throttle:n=0,deep:i=!1}=t,a=()=>s.forEach(e=>e(r));return{get value(){return r},set value(e){(i?JSON.stringify(r)!==JSON.stringify(e):r!==e)&&(r=e,n>0?o||(o=setTimeout(()=>{o=null,a()},n)):a())},subscribe:e=>(s.add(e),()=>s.delete(e)),destroy(){s.clear(),o&&clearTimeout(o)}}}computed(e,t){let r=e.map(e=>e.value),s=this.createState(t(...r));return e.forEach((e,o)=>{e.subscribe(e=>{r[o]=e,s.value=t(...r)})}),s}effect(e){e()}createVirtualList(e,t,r,s=50,o=5){let n=e.clientHeight,i=t.length*s,a=0,l=()=>{let{start:l,end:p}={start:Math.max(0,Math.floor(a/s)-o),end:Math.min(t.length,Math.ceil((a+n)/s)+o)},u=document.createElement("div");u.style.cssText=`height:${i}px;position:relative`;for(let e=l;e<p;e++){let o=document.createElement("div");o.style.cssText=`position:absolute;top:${e*s}px;height:${s}px;width:100%`,this.renderToDOM(r(t[e],e),o),u.appendChild(o)}e.innerHTML="",e.appendChild(u)},p=()=>{a=e.scrollTop,requestAnimationFrame(l)};return e.addEventListener("scroll",p),l(),{render:l,destroy:()=>{e.removeEventListener("scroll",p),e.innerHTML=""}}}lazy(e){let t=null,r=!1;return async(...s)=>(!t&&!r&&(r=!0,t=await e(),r=!1),t?t(...s):{tagName:"div",props:{class:"loading"},children:["Loading..."]})}cleanupUnusedElements(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),r=[];for(;t.nextNode();){let e=t.currentNode;e.id&&e.id.startsWith("r")&&!this.elementCache.has(e)&&r.push(e)}return r.forEach(e=>e.remove()),r.length}renderToString(e,t={}){let{pretty:r=!1,indent:s=0}=t,o=r?" ".repeat(s):"",n=r?"\n":"",i=this.resolveStateValue(e);if(i=this.unwrapReactive(i),Array.isArray(i))return i.map(e=>this.renderToString(e,t)).join("");if("object"!=typeof i||null===i)return null==i||!1===i?"":this.escapeHtml(String(i));let{tagName:a,props:l,children:p}=i,u=this.isSelfClosingTag(a),d=`${o}<${a}`,h=this.propsToAttributes(l);if(h&&(d+=` ${h}`),u)return d+=` />${n}`,d;if(d+=">",l.dangerouslySetInnerHTML)return d+=l.dangerouslySetInnerHTML.__html,d+=`</${a}>${n}`,d;if(p&&p.length>0){let e=p.map(e=>{let t=this.resolveStateValue(e);return this.unwrapReactive(t)}),t=e.some(e=>"object"==typeof e&&null!==e&&!Array.isArray(e)&&"tagName"in e);if(r&&t){d+=n;for(let t of e)if(null!=t&&!1!==t)if(Array.isArray(t))for(let e of t)null!=e&&!1!==e&&(d+=this.renderToString(e,{pretty:r,indent:s+1}));else d+=this.renderToString(t,{pretty:r,indent:s+1});d+=o}else for(let t of e)if(null!=t&&!1!==t)if(Array.isArray(t))for(let e of t)null!=e&&!1!==e&&(d+=this.renderToString(e,{pretty:!1,indent:0}));else d+=this.renderToString(t,{pretty:!1,indent:0})}return d+=`</${a}>${n}`,d}resolveStateValue(e){return e&&"object"==typeof e&&"value"in e&&"subscribe"in e?e.value:e}isReactiveWrapper(e){return!(!e||"object"!=typeof e||!e.tagName)&&("span"===e.tagName&&e.props?.id&&"string"==typeof e.props.id&&e.props.id.match(/^r[a-z0-9]{9}$/))}unwrapReactive(e){if(!this.isReactiveWrapper(e))return e;let t=e.children;if(!t||0===t.length)return"";if(1===t.length){let e=t[0];if(e&&"object"==typeof e&&"span"===e.tagName){let t=e.props,r=!t||0===Object.keys(t).length,s=e.children&&1===e.children.length&&"string"==typeof e.children[0];if(r&&s)return e.children[0]}return this.unwrapReactive(e)}return t.map(e=>this.unwrapReactive(e))}escapeHtml(e){let t={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,e=>t[e])}isSelfClosingTag(e){return new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]).has(e.toLowerCase())}propsToAttributes(e){let t=[];for(let r in e){if("children"===r||"dangerouslySetInnerHTML"===r||"ref"===r)continue;let s=e[r];if(s=this.resolveStateValue(s),null!=s&&!1!==s&&(!r.startsWith("on")||"function"!=typeof s)){if("className"===r||"class"===r){let e=Array.isArray(s)?s.join(" "):s;e&&t.push(`class="${this.escapeHtml(String(e))}"`);continue}if("style"===r){let e=this.styleToString(s);e&&t.push(`style="${this.escapeHtml(e)}"`);continue}if(!0===s){t.push(r);continue}t.push(`${r}="${this.escapeHtml(String(s))}"`)}}return t.join(" ")}styleToString(e){if("string"==typeof e)return e;if("object"==typeof e&&null!==e){let t=[];for(let r in e){let s=r.replace(/([A-Z])/g,"-$1").toLowerCase();t.push(`${s}:${e[r]}`)}return t.join(";")}return""}isState(e){return e&&"object"==typeof e&&"value"in e&&"subscribe"in e&&"function"==typeof e.subscribe}createReactiveChild(e,t){let r=t(e.value);if(typeof window<"u"&&typeof document<"u"){let r={node:null,renderFn:t};this.reactiveNodes.set(e,r),e.subscribe(()=>{if(r.node&&r.node.parentNode){let s=t(e.value);r.node.textContent=String(s??"")}})}return r}jsonToVNode(e){if(this.isState(e))return this.createReactiveChild(e,e=>e);if(null==e||"boolean"==typeof e||"string"==typeof e||"number"==typeof e)return e;let{tag:t,attributes:r={},children:s}=e,o={};for(let e in r){let t=r[e];"class"===e?o.className=this.isState(t)?t.value:t:o[e]=this.isState(t)?t.value:t}let n=[];if(null!=s)if(Array.isArray(s))for(let e of s)if(this.isState(e))n.push(this.createReactiveChild(e,e=>e));else{let t=this.jsonToVNode(e);null!=t&&!1!==t&&n.push(t)}else if(this.isState(s))n.push(this.createReactiveChild(s,e=>e));else if("object"==typeof s&&"tag"in s){let e=this.jsonToVNode(s);null!=e&&!1!==e&&n.push(e)}else n.push(s);return{tagName:t,props:o,children:n}}vNodeJsonToVNode(e){if(this.isState(e))return this.createReactiveChild(e,e=>e);if(null==e||"boolean"==typeof e||"string"==typeof e||"number"==typeof e)return e;let{tagName:t,props:r={},children:s=[]}=e,o={};for(let e in r){let t=r[e];o[e]=this.isState(t)?t.value:t}let n=[];for(let e of s)if(this.isState(e))n.push(this.createReactiveChild(e,e=>e));else{let t=this.vNodeJsonToVNode(e);null!=t&&!1!==t&&n.push(t)}return{tagName:t,props:o,children:n}}renderJson(e,t){let r=this.jsonToVNode(t);if(!r||"object"!=typeof r||!("tagName"in r))throw new Error("Invalid JSON structure");return this.render(e,r)}renderVNode(e,t){let r=this.vNodeJsonToVNode(t);if(!r||"object"!=typeof r||!("tagName"in r))throw new Error("Invalid VNode JSON structure");return this.render(e,r)}renderJsonToString(e,t={}){let r=this.jsonToVNode(e);return this.renderToString(r,t)}renderVNodeToString(e,t={}){let r=this.vNodeJsonToVNode(e);return this.renderToString(r,t)}renderServer(e){if("object"!=typeof e||null===e||!("tagName"in e))throw new Error("renderServer requires a VNode with html tag");if("html"!==e.tagName)throw new Error("renderServer requires a VNode with html tag as root");let t=e,r=null,s=null;for(let e of t.children||[])"object"==typeof e&&null!==e&&"tagName"in e&&("head"===e.tagName&&(r=e),"body"===e.tagName&&(s=e));if(t.props)for(let e in t.props){let r=t.props[e];null!=r&&!1!==r&&document.documentElement.setAttribute(e,String(r))}if(r){document.head.innerHTML="";for(let e of r.children||[])this.renderToDOM(e,document.head)}if(s){if(document.body.innerHTML="",s.props)for(let e in s.props){let t=s.props[e];null!=t&&!1!==t&&document.body.setAttribute(e,String(t))}for(let e of s.children||[])this.renderToDOM(e,document.body)}}renderToHTMLDocument(e,t={}){let{title:r="",meta:s=[],links:o=[],scripts:n=[],styles:i=[],lang:a="en",head:l="",bodyAttrs:p={},pretty:u=!1}=t,d=u?"\n":"",h=u?" ":"",c=u?" ":"",m=`<!DOCTYPE html>${d}<html lang="${a}">${d}${h}<head>${d}${c}<meta charset="UTF-8">${d}${c}<meta name="viewport" content="width=device-width, initial-scale=1.0">${d}`;r&&(m+=`${c}<title>${this.escapeHtml(r)}</title>${d}`);for(let e of s){m+=`${c}<meta`;for(let t in e)m+=` ${t}="${this.escapeHtml(e[t])}"`;m+=`>${d}`}for(let e of o){m+=`${c}<link`;for(let t in e)m+=` ${t}="${this.escapeHtml(e[t])}"`;m+=`>${d}`}for(let e of i)e.href?m+=`${c}<link rel="stylesheet" href="${this.escapeHtml(e.href)}">${d}`:e.content&&(m+=`${c}<style>${e.content}</style>${d}`);l&&(m+=l+d),m+=`${h}</head>${d}${h}<body`;for(let e in p)m+=` ${e}="${this.escapeHtml(p[e])}"`;m+=`>${d}`,m+=this.renderToString(e,{pretty:u,indent:2});for(let e of n)m+=`${c}<script`,e.type&&(m+=` type="${this.escapeHtml(e.type)}"`),e.async&&(m+=" async"),e.defer&&(m+=" defer"),e.src?m+=` src="${this.escapeHtml(e.src)}"><\/script>${d}`:e.content?m+=`>${e.content}<\/script>${d}`:m+=`><\/script>${d}`;return m+=`${h}</body>${d}</html>`,m}getElementCache(){return this.elementCache}},t=new e,r=(e,r)=>t.createState(e,r),s=class{constructor(e,t,s){this.key=e,this.wsUrl=s,this.ws=null,this.pendingUpdates=[],this.localState=r(t),this.previousValue=t,this.connect()}get value(){return this.localState.value}set value(e){this.previousValue=this.localState.value,this.localState.value=e,this.sendToServer(e)}get state(){return this.localState}onChange(e){return this.localState.subscribe(t=>{let r=this.previousValue;this.previousValue=t,e(t,r)})}update(e){this.value=e(this.value)}connect(){if(typeof window>"u")return;let e=this.wsUrl||`ws://${location.host}`;this.ws=new WebSocket(e),this.ws.addEventListener("open",()=>{for(this.subscribe();this.pendingUpdates.length>0;){let e=this.pendingUpdates.shift();this.sendToServer(e)}}),this.ws.addEventListener("message",e=>{this.handleMessage(e.data)}),this.ws.addEventListener("close",()=>{setTimeout(()=>this.connect(),1e3)}),this.ws.addEventListener("error",e=>{console.error("[SharedState] WebSocket error:",e)})}subscribe(){!this.ws||this.ws.readyState!==WebSocket.OPEN||this.ws.send(JSON.stringify({type:"state:subscribe",key:this.key}))}handleMessage(e){try{let t=JSON.parse(e);if(t.key!==this.key)return;("state:init"===t.type||"state:update"===t.type)&&(this.localState.value=t.value)}catch{}}sendToServer(e){if(this.ws){if(this.ws.readyState!==WebSocket.OPEN)return void this.pendingUpdates.push(e);this.ws.send(JSON.stringify({type:"state:change",key:this.key,value:e}))}}disconnect(){this.ws&&(this.ws.close(),this.ws=null)}destroy(){this.disconnect(),this.localState.destroy()}};var o=new class{constructor(){this.states=new Map}create(e,t,r){if(this.states.has(e))return this.states.get(e);let o=new s(e,t,r);return this.states.set(e,o),o}get(e){return this.states.get(e)}delete(e){let t=this.states.get(e);return!!t&&(t.destroy(),this.states.delete(e))}clear(){this.states.forEach(e=>e.destroy()),this.states.clear()}},n=(e,r)=>{let s=null,o=null,n=null,i=!0,a=r(e.value),l=a&&"object"==typeof a&&"tagName"in a,p=null==a||!1===a;e.subscribe(()=>{s&&cancelAnimationFrame(s),s=requestAnimationFrame(()=>{(()=>{if(!o&&!n)return;let s=r(e.value);if(null==s||!1===s)i&&o&&(n=document.createComment("reactive"),o.parentNode?.replaceChild(n,o),i=!1);else if(!i&&n&&o&&(n.parentNode?.replaceChild(o,n),n=null,i=!0),o){let e=document.createDocumentFragment();if(l&&s&&"object"==typeof s&&"tagName"in s){let{props:r,children:n}=s;for(let e in r){let t=r[e];if("ref"!==e)if("class"===e||"className"===e)o.className=Array.isArray(t)?t.join(" "):t||"";else if("style"===e&&"object"==typeof t){let e=o.style;for(let r in t)e[r]=t[r]}else e.startsWith("on")?o[e.toLowerCase()]=t:null!=t&&!1!==t?o.setAttribute(e,String(!0===t?"":t)):o.removeAttribute(e)}for(let r of n)t.renderToDOM(r,e)}else t.renderToDOM(s,e);o.textContent="",o.appendChild(e),t.getElementCache().set(o,!0)}})(),s=null})});let u=e=>{o=e,p&&e.parentNode&&(n=document.createComment("reactive"),e.parentNode.replaceChild(n,e),i=!1)};if(l){let e=a;return{tagName:e.tagName,props:{...e.props,ref:u},children:e.children}}return{tagName:"span",props:{ref:u},children:[a]}},i=e=>function(t,...r){if(!arguments.length)return{tagName:e,props:{},children:[]};let s=t&&"object"==typeof t&&"value"in t&&"subscribe"in t,o=t&&"object"==typeof t&&"tagName"in t,n="object"!=typeof t||Array.isArray(t)||null===t||s||o,i=n?{}:t,a=n?[t,...r]:r;if(!a.length)return{tagName:e,props:i,children:[]};let l=[];for(let e=0,t=a.length;e<t;e++){let t=a[e];if(null!=t&&!1!==t)if(Array.isArray(t))for(let e=0,r=t.length;e<r;e++){let r=t[e];null!=r&&!1!==r&&l.push(r)}else l.push(t)}return{tagName:e,props:i,children:l}},a={};["html","head","body","title","base","link","meta","style","address","article","aside","footer","header","h1","h2","h3","h4","h5","h6","main","nav","section","blockquote","dd","div","dl","dt","figcaption","figure","hr","li","ol","p","pre","ul","a","abbr","b","bdi","bdo","br","cite","code","data","dfn","em","i","kbd","mark","q","rp","rt","ruby","s","samp","small","span","strong","sub","sup","time","u","wbr","area","audio","img","map","track","video","embed","iframe","object","param","picture","portal","source","canvas","noscript","script","del","ins","caption","col","colgroup","table","tbody","td","tfoot","th","thead","tr","button","datalist","fieldset","form","input","label","legend","meter","optgroup","option","output","progress","select","textarea","details","dialog","menu","summary","slot","template"].forEach(e=>{a[e]=i(e)}),["svg","circle","rect","path","line","polyline","polygon","ellipse","g","text","tspan","defs","linearGradient","radialGradient","stop","pattern","mask","clipPath","use","symbol","marker","image","foreignObject","animate","animateTransform","animateMotion","set","filter","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feFlood","feGaussianBlur","feMorphology","feOffset","feSpecularLighting","feTile","feTurbulence"].forEach(e=>{let t="svg"+e.charAt(0).toUpperCase()+e.slice(1);a[t]=i(e)}),["math","mi","mn","mo","ms","mtext","mrow","mfrac","msqrt","mroot","msub","msup"].forEach(e=>{let t="math"+e.charAt(0).toUpperCase()+e.slice(1);a[t]=i(e)}),a.varElement=i("var");var{html:l,head:p,body:u,title:d,base:h,link:c,meta:m,style:f,address:g,article:y,aside:x,footer:v,header:b,h1:$,h2:w,h3:S,h4:M,h5:T,h6:C,main:N,nav:E,section:k,blockquote:R,dd:F,div:A,dl:j,dt:O,figcaption:L,figure:D,hr:H,li:W,ol:V,p:q,pre:P,ul:U,a:I,abbr:B,b:_,bdi:J,bdo:G,br:z,cite:K,code:Z,data:Y,dfn:Q,em:X,i:ee,kbd:te,mark:re,q:se,rp:oe,rt:ne,ruby:ie,s:ae,samp:le,small:pe,span:ue,strong:de,sub:he,sup:ce,time:me,u:fe,wbr:ge,area:ye,audio:xe,img:ve,map:be,track:$e,video:we,embed:Se,iframe:Me,object:Te,param:Ce,picture:Ne,portal:Ee,source:ke,canvas:Re,noscript:Fe,script:Ae,del:je,ins:Oe,caption:Le,col:De,colgroup:He,table:We,tbody:Ve,td:qe,tfoot:Pe,th:Ue,thead:Ie,tr:Be,button:_e,datalist:Je,fieldset:Ge,form:ze,input:Ke,label:Ze,legend:Ye,meter:Qe,optgroup:Xe,option:et,output:tt,progress:rt,select:st,textarea:ot,details:nt,dialog:it,menu:at,summary:lt,slot:pt,template:ut,svgSvg:dt,svgCircle:ht,svgRect:ct,svgPath:mt,svgLine:ft,svgPolyline:gt,svgPolygon:yt,svgEllipse:xt,svgG:vt,svgText:bt,svgTspan:$t,svgDefs:wt,svgLinearGradient:St,svgRadialGradient:Mt,svgStop:Tt,svgPattern:Ct,svgMask:Nt,svgClipPath:Et,svgUse:kt,svgSymbol:Rt,svgMarker:Ft,svgImage:At,svgForeignObject:jt,svgAnimate:Ot,svgAnimateTransform:Lt,svgAnimateMotion:Dt,svgSet:Ht,svgFilter:Wt,svgFeBlend:Vt,svgFeColorMatrix:qt,svgFeComponentTransfer:Pt,svgFeComposite:Ut,svgFeConvolveMatrix:It,svgFeDiffuseLighting:Bt,svgFeDisplacementMap:_t,svgFeFlood:Jt,svgFeGaussianBlur:Gt,svgFeMorphology:zt,svgFeOffset:Kt,svgFeSpecularLighting:Zt,svgFeTile:Yt,svgFeTurbulence:Qt,mathMath:Xt,mathMi:er,mathMn:tr,mathMo:rr,mathMs:sr,mathMtext:or,mathMrow:nr,mathMfrac:ir,mathMsqrt:ar,mathMroot:lr,mathMsub:pr,mathMsup:ur,varElement:dr}=a,hr=a,cr=document,mr=cr.querySelector.bind(cr),fr=cr.querySelectorAll.bind(cr),gr=cr.createElement.bind(cr),yr=cr.createElementNS.bind(cr,"http://www.w3.org/2000/svg"),xr=cr.createElementNS.bind(cr,"http://www.w3.org/1998/Math/MathML"),vr=cr.createDocumentFragment.bind(cr),br=cr.createTextNode.bind(cr),$r=cr.createComment.bind(cr),wr=cr.getElementById.bind(cr),Sr=cr.getElementsByClassName.bind(cr),Mr=cr.getElementsByTagName.bind(cr),Tr=cr.getElementsByName.bind(cr);function Cr(e,t){let r=e.split("/").filter(Boolean),s=t.split("/").filter(Boolean);if(e.endsWith("*")){let r=e.slice(0,-1);if(t.startsWith(r)||"/"===r||"*"===e)return{"*":t.slice(r.length)}}if(r.length!==s.length)return null;let o={};for(let e=0;e<r.length;e++){let t=r[e],n=s[e];if(t.startsWith(":"))o[t.slice(1)]=decodeURIComponent(n);else if(t!==n)return null}return o}var Nr=new class{constructor(){this.enabled=!1,this.ws=null,this.acceptCallbacks=[],this.disposeCallbacks=[],this.declined=!1,typeof window>"u"||this.connect()}connect(){let e="https:"===window.location.protocol?"wss:":"ws:",t=window.location.hostname,r=window.location.port||"3000";this.ws=new WebSocket(`${e}//${t}:${r}`),this.ws.onopen=()=>{this.enabled=!0,console.log("[Elit HMR] Connected ✓")},this.ws.onmessage=e=>{try{let t=JSON.parse(e.data);this.handleMessage(t)}catch(e){console.error("[Elit HMR] Error parsing message:",e)}},this.ws.onclose=()=>{this.enabled=!1,console.log("[Elit HMR] Disconnected - Attempting reconnect..."),setTimeout(()=>this.reload(),1e3)},this.ws.onerror=e=>{console.error("[Elit HMR] WebSocket error:",e)}}handleMessage(e){switch(e.type){case"connected":console.log("[Elit HMR] Ready");break;case"update":if(console.log(`[Elit HMR] Update detected: ${e.path}`),this.declined)return void this.reload();this.disposeCallbacks.forEach(e=>e()),this.disposeCallbacks=[],this.acceptCallbacks.length>0?this.acceptCallbacks.forEach(e=>e()):this.reload();break;case"reload":console.log("[Elit HMR] Full reload requested"),this.reload();break;case"error":console.error("[Elit HMR] Server error:",e.error)}}reload(){window.location.reload()}accept(e){e&&this.acceptCallbacks.push(e),this.declined=!1}decline(){this.declined=!0}dispose(e){this.disposeCallbacks.push(e)}};typeof window<"u"&&(window.__ELIT_HMR__=Nr);var Er=Nr;exports.CreateStyle=class{constructor(){this.variables=[],this.rules=[],this.mediaRules=[],this.keyframes=[],this.fontFaces=[],this.imports=[],this.containerRules=[],this.supportsRules=[],this.layerRules=[],this._layerOrder=[]}addVar(e,t){let r={name:e.startsWith("--")?e:`--${e}`,value:t,toString(){return`var(${this.name})`}};return this.variables.push(r),r}var(e,t){let r="string"==typeof e?e.startsWith("--")?e:`--${e}`:e.name;return t?`var(${r}, ${t})`:`var(${r})`}addTag(e,t){let r={selector:e,styles:t,type:"tag"};return this.rules.push(r),r}addClass(e,t){let r={selector:e.startsWith(".")?e:`.${e}`,styles:t,type:"class"};return this.rules.push(r),r}addId(e,t){let r={selector:e.startsWith("#")?e:`#${e}`,styles:t,type:"id"};return this.rules.push(r),r}addPseudoClass(e,t,r){let s=e.startsWith(":")?e:`:${e}`,o={selector:r?`${r}${s}`:s,styles:t,type:"pseudo-class"};return this.rules.push(o),o}addPseudoElement(e,t,r){let s=e.startsWith("::")?e:`::${e}`,o={selector:r?`${r}${s}`:s,styles:t,type:"pseudo-element"};return this.rules.push(o),o}addAttribute(e,t,r){let s=e.startsWith("[")?e:`[${e}]`,o={selector:r?`${r}${s}`:s,styles:t,type:"attribute"};return this.rules.push(o),o}attrEquals(e,t,r,s){return this.addAttribute(`${e}="${t}"`,r,s)}attrContainsWord(e,t,r,s){return this.addAttribute(`${e}~="${t}"`,r,s)}attrStartsWith(e,t,r,s){return this.addAttribute(`${e}^="${t}"`,r,s)}attrEndsWith(e,t,r,s){return this.addAttribute(`${e}$="${t}"`,r,s)}attrContains(e,t,r,s){return this.addAttribute(`${e}*="${t}"`,r,s)}descendant(e,t,r){let s={selector:`${e} ${t}`,styles:r,type:"custom"};return this.rules.push(s),s}child(e,t,r){let s={selector:`${e} > ${t}`,styles:r,type:"custom"};return this.rules.push(s),s}adjacentSibling(e,t,r){let s={selector:`${e} + ${t}`,styles:r,type:"custom"};return this.rules.push(s),s}generalSibling(e,t,r){let s={selector:`${e} ~ ${t}`,styles:r,type:"custom"};return this.rules.push(s),s}multiple(e,t){let r={selector:e.join(", "),styles:t,type:"custom"};return this.rules.push(r),r}addName(e,t){return{selector:e.startsWith("--")?`&${e}`:`&--${e}`,styles:t,type:"name"}}nesting(e,...t){return e.nested=t,e}keyframe(e,t){let r={name:e,steps:Object.entries(t).map(([e,t])=>({step:"from"===e?"from":"to"===e?"to":`${e}%`,styles:t}))};return this.keyframes.push(r),r}keyframeFromTo(e,t,r){return this.keyframe(e,{from:t,to:r})}fontFace(e){return this.fontFaces.push(e),e}import(e,t){let r=t?`@import url("${e}") ${t};`:`@import url("${e}");`;return this.imports.push(r),r}media(e,t,r){let s={type:e,condition:t,rules:Object.entries(r).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.mediaRules.push(s),s}mediaScreen(e,t){return this.media("screen",e,t)}mediaPrint(e){return this.media("print","",e)}mediaMinWidth(e,t){return this.media("screen",`min-width: ${e}`,t)}mediaMaxWidth(e,t){return this.media("screen",`max-width: ${e}`,t)}mediaDark(e){let t={type:"",condition:"prefers-color-scheme: dark",rules:Object.entries(e).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.mediaRules.push(t),t}mediaLight(e){let t={type:"",condition:"prefers-color-scheme: light",rules:Object.entries(e).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.mediaRules.push(t),t}mediaReducedMotion(e){let t={type:"",condition:"prefers-reduced-motion: reduce",rules:Object.entries(e).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.mediaRules.push(t),t}container(e,t,r){let s={name:r,condition:e,rules:Object.entries(t).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.containerRules.push(s),s}addContainer(e,t){let r={...t,containerName:e};return this.addClass(e,r)}supports(e,t){let r={condition:e,rules:Object.entries(t).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.supportsRules.push(r),r}layerOrder(...e){this._layerOrder=e}layer(e,t){let r={name:e,rules:Object.entries(t).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.layerRules.push(r),r}add(e){return Object.entries(e).map(([e,t])=>{let r={selector:e,styles:t,type:"custom"};return this.rules.push(r),r})}important(e){return`${e} !important`}toKebabCase(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}stylesToString(e,t=" "){return Object.entries(e).map(([e,r])=>{let s="object"==typeof r&&null!==r&&"name"in r?`var(${r.name})`:r;return`${t}${this.toKebabCase(e)}: ${s};`}).join("\n")}renderRule(e,t=""){let r=`${t}${e.selector} {\n${this.stylesToString(e.styles,t+" ")}\n`;if(e.nested&&e.nested.length>0)for(let s of e.nested){r+=`\n${t}${s.selector.startsWith("&")?s.selector.replace(/&/g,e.selector):`${e.selector} ${s.selector}`} {\n${this.stylesToString(s.styles,t+" ")}\n${t}}\n`}return r+=`${t}}`,r}renderMediaRule(e){let t=`@media ${e.type&&e.condition?`${e.type} and (${e.condition})`:e.type?e.type:`(${e.condition})`} {\n`;for(let r of e.rules)t+=this.renderRule(r," ")+"\n";return t+="}",t}renderKeyframes(e){let t=`@keyframes ${e.name} {\n`;for(let r of e.steps)t+=` ${r.step} {\n${this.stylesToString(r.styles," ")}\n }\n`;return t+="}",t}renderFontFace(e){let t="@font-face {\n";return t+=` font-family: "${e.fontFamily}";\n`,t+=` src: ${e.src};\n`,e.fontWeight&&(t+=` font-weight: ${e.fontWeight};\n`),e.fontStyle&&(t+=` font-style: ${e.fontStyle};\n`),e.fontDisplay&&(t+=` font-display: ${e.fontDisplay};\n`),e.unicodeRange&&(t+=` unicode-range: ${e.unicodeRange};\n`),t+="}",t}renderContainerRule(e){let t=`@container ${e.name?`${e.name} `:""}(${e.condition}) {\n`;for(let r of e.rules)t+=this.renderRule(r," ")+"\n";return t+="}",t}renderSupportsRule(e){let t=`@supports (${e.condition}) {\n`;for(let r of e.rules)t+=this.renderRule(r," ")+"\n";return t+="}",t}renderLayerRule(e){let t=`@layer ${e.name} {\n`;for(let r of e.rules)t+=this.renderRule(r," ")+"\n";return t+="}",t}render(...e){let t=[];if(this.imports.length>0&&t.push(this.imports.join("\n")),this._layerOrder.length>0&&t.push(`@layer ${this._layerOrder.join(", ")};`),this.variables.length>0){let e=this.variables.map(e=>` ${e.name}: ${e.value};`).join("\n");t.push(`:root {\n${e}\n}`)}for(let e of this.fontFaces)t.push(this.renderFontFace(e));for(let e of this.keyframes)t.push(this.renderKeyframes(e));let r=[...this.rules],s=[...this.mediaRules],o=[],n=[...this.containerRules],i=[...this.supportsRules],a=[...this.layerRules];for(let t of e)t&&(Array.isArray(t)?r.push(...t):!("condition"in t)||!("rules"in t)||"name"in t&&"steps"in t?"name"in t&&"steps"in t?o.push(t):"name"in t&&"rules"in t?a.push(t):r.push(t):"type"in t?s.push(t):"name"in t&&"string"==typeof t.name?n.push(t):i.push(t));for(let e of o)t.push(this.renderKeyframes(e));for(let e of a)t.push(this.renderLayerRule(e));for(let e of r)t.push(this.renderRule(e));for(let e of i)t.push(this.renderSupportsRule(e));for(let e of n)t.push(this.renderContainerRule(e));for(let e of s)t.push(this.renderMediaRule(e));return t.join("\n\n")}inject(e){let t=this.render(),r=document.createElement("style");return e&&(r.id=e),r.textContent=t,document.head.appendChild(r),r}clear(){this.variables=[],this.rules=[],this.mediaRules=[],this.keyframes=[],this.fontFaces=[],this.imports=[],this.containerRules=[],this.supportsRules=[],this.layerRules=[],this._layerOrder=[]}},exports.DomNode=e,exports.SharedState=s,exports.a=I,exports.abbr=B,exports.address=g,exports.area=ye,exports.article=y,exports.aside=x,exports.audio=xe,exports.b=_,exports.base=h,exports.batchRender=(e,r)=>t.batchRender(e,r),exports.bdi=J,exports.bdo=G,exports.bindChecked=e=>({checked:e.value,onchange:t=>{e.value=t.target.checked}}),exports.bindValue=e=>({value:e.value,oninput:t=>{e.value=t.target.value}}),exports.blockquote=R,exports.body=u,exports.br=z,exports.button=_e,exports.canvas=Re,exports.caption=Le,exports.cite=K,exports.cleanupUnused=e=>t.cleanupUnusedElements(e),exports.code=Z,exports.col=De,exports.colgroup=He,exports.commentNode=$r,exports.computed=(e,r)=>t.computed(e,r),exports.createEl=gr,exports.createElementFactory=i,exports.createMathEl=xr,exports.createRouter=function(e){let{mode:r="history",base:s="",routes:o}=e,n=[],i=e=>{let t={};return new URLSearchParams(e).forEach((e,r)=>{t[r]=e}),t},a=()=>"hash"===r?window.location.hash.slice(1)||"/":window.location.pathname.replace(s,"")||"/",l=e=>{let[t,r=""]=e.split("?"),[s,o=""]=t.split("#");return{path:s||"/",params:{},query:i(r),hash:o?"#"+o:""}},p=e=>{for(let t of o){let r=Cr(t.path,e);if(null!==r)return{route:t,params:r}}return null},u=t.createState(l(a())),d=(e,t=!1)=>{let o=l(e),i=p(o.path);i&&(o.params=i.params);for(let e of n){let r=e(o,u.value);if(!1===r)return;if("string"==typeof r)return void d(r,t)}if(i?.route.beforeEnter){let e=i.route.beforeEnter(o,u.value);if(!1===e)return;if("string"==typeof e)return void d(e,t)}let a="hash"===r?"#"+e:s+e;t?window.history.replaceState({path:e},"",a):window.history.pushState({path:e},"",a),u.value=o},h=()=>{let e=a(),t=l(e),r=p(t.path);r&&(t.params=r.params),u.value=t};return typeof window<"u"&&window.addEventListener("popstate",h),{currentRoute:u,push:e=>d(e,!1),replace:e=>d(e,!0),back:()=>window.history.back(),forward:()=>window.history.forward(),go:e=>window.history.go(e),beforeEach:e=>{n.push(e)},destroy:()=>{typeof window<"u"&&window.removeEventListener("popstate",h),u.destroy()}}},exports.createRouterView=function(e,t){let{routes:r,notFound:s}=t;return()=>{let t=e.currentRoute.value,o=r.find(e=>null!==Cr(e.path,t.path));if(o){let e=Cr(o.path,t.path)||{},r=o.component({...e,...t.query});return"object"==typeof r&&null!==r&&"tagName"in r?r:{tagName:"span",props:{},children:[r]}}if(s){let e=s(t.params);return"object"==typeof e&&null!==e&&"tagName"in e?e:{tagName:"span",props:{},children:[e]}}return{tagName:"div",props:{},children:["404 - Not Found"]}}},exports.createSharedState=function(e,t,r){return new s(e,t,r)},exports.createState=r,exports.createSvgEl=yr,exports.createVirtualList=(e,r,s,o,n)=>t.createVirtualList(e,r,s,o,n),exports.data=Y,exports.datalist=Je,exports.dd=F,exports.debounce=(e,t)=>{let r=null;return(...s)=>{r&&clearTimeout(r),r=setTimeout(()=>e(...s),t)}},exports.del=je,exports.details=nt,exports.dfn=Q,exports.dialog=it,exports.div=A,exports.dl=j,exports.doc=cr,exports.dom=t,exports.dt=O,exports.effect=e=>t.effect(e),exports.el=hr,exports.elements=a,exports.em=X,exports.embed=Se,exports.fieldset=Ge,exports.figcaption=L,exports.figure=D,exports.footer=v,exports.form=ze,exports.fragment=vr,exports.getEl=mr,exports.getElClass=Sr,exports.getElId=wr,exports.getElName=Tr,exports.getElTag=Mr,exports.getEls=fr,exports.h1=$,exports.h2=w,exports.h3=S,exports.h4=M,exports.h5=T,exports.h6=C,exports.head=p,exports.header=b,exports.hmr=Er,exports.hr=H,exports.html=l,exports.i=ee,exports.iframe=Me,exports.img=ve,exports.input=Ke,exports.ins=Oe,exports.kbd=te,exports.label=Ze,exports.lazy=e=>t.lazy(e),exports.legend=Ye,exports.li=W,exports.link=c,exports.main=N,exports.map=be,exports.mark=re,exports.mathMath=Xt,exports.mathMfrac=ir,exports.mathMi=er,exports.mathMn=tr,exports.mathMo=rr,exports.mathMroot=lr,exports.mathMrow=nr,exports.mathMs=sr,exports.mathMsqrt=ar,exports.mathMsub=pr,exports.mathMsup=ur,exports.mathMtext=or,exports.menu=at,exports.meta=m,exports.meter=Qe,exports.nav=E,exports.noscript=Fe,exports.object=Te,exports.ol=V,exports.optgroup=Xe,exports.option=et,exports.output=tt,exports.p=q,exports.param=Ce,exports.picture=Ne,exports.portal=Ee,exports.pre=P,exports.progress=rt,exports.q=se,exports.reactive=n,exports.reactiveAs=(e,r,s,o={})=>{let n=null,i=null;return r.subscribe(()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(()=>{if(i){let e=document.createDocumentFragment(),o=s(r.value);null==o||!1===o?(i.style.display="none",i.textContent=""):(i.style.display="",t.renderToDOM(o,e),i.textContent="",i.appendChild(e)),t.getElementCache().set(i,!0)}n=null})}),{tagName:e,props:{...o,ref:e=>{i=e}},children:[s(r.value)]}},exports.renderChunked=(e,r,s,o)=>t.renderChunked(e,r,s,o),exports.routerLink=(e,t,...r)=>({tagName:"a",props:{...t,href:t.to,onclick:r=>{r.preventDefault(),e.push(t.to)}},children:r}),exports.rp=oe,exports.rt=ne,exports.ruby=ie,exports.s=ae,exports.samp=le,exports.script=Ae,exports.section=k,exports.select=st,exports.sharedStateManager=o,exports.slot=pt,exports.small=pe,exports.source=ke,exports.span=ue,exports.strong=de,exports.style=f,exports.sub=he,exports.summary=lt,exports.sup=ce,exports.svgAnimate=Ot,exports.svgAnimateMotion=Dt,exports.svgAnimateTransform=Lt,exports.svgCircle=ht,exports.svgClipPath=Et,exports.svgDefs=wt,exports.svgEllipse=xt,exports.svgFeBlend=Vt,exports.svgFeColorMatrix=qt,exports.svgFeComponentTransfer=Pt,exports.svgFeComposite=Ut,exports.svgFeConvolveMatrix=It,exports.svgFeDiffuseLighting=Bt,exports.svgFeDisplacementMap=_t,exports.svgFeFlood=Jt,exports.svgFeGaussianBlur=Gt,exports.svgFeMorphology=zt,exports.svgFeOffset=Kt,exports.svgFeSpecularLighting=Zt,exports.svgFeTile=Yt,exports.svgFeTurbulence=Qt,exports.svgFilter=Wt,exports.svgForeignObject=jt,exports.svgG=vt,exports.svgImage=At,exports.svgLine=ft,exports.svgLinearGradient=St,exports.svgMarker=Ft,exports.svgMask=Nt,exports.svgPath=mt,exports.svgPattern=Ct,exports.svgPolygon=yt,exports.svgPolyline=gt,exports.svgRadialGradient=Mt,exports.svgRect=ct,exports.svgSet=Ht,exports.svgStop=Tt,exports.svgSvg=dt,exports.svgSymbol=Rt,exports.svgText=bt,exports.svgTspan=$t,exports.svgUse=kt,exports.table=We,exports.tbody=Ve,exports.td=qe,exports.template=ut,exports.text=e=>e&&void 0!==e.value?n(e,e=>({tagName:"span",props:{},children:[String(e)]})):String(e),exports.textNode=br,exports.textarea=ot,exports.tfoot=Pe,exports.th=Ue,exports.thead=Ie,exports.throttle=(e,t)=>{let r=null;return(...s)=>{r||(r=setTimeout(()=>{r=null,e(...s)},t))}},exports.time=me,exports.title=d,exports.tr=Be,exports.track=$e,exports.u=fe,exports.ul=U,exports.varElement=dr,exports.video=we,exports.wbr=ge;
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=class{constructor(){this.elementCache=new WeakMap,this.reactiveNodes=new Map}createElement(e,t={},s=[]){return{tagName:e,props:t,children:s}}renderToDOM(e,t){if(null==e||!1===e)return;if("object"!=typeof e)return void t.appendChild(document.createTextNode(String(e)));let{tagName:s,props:r,children:a}=e,n="svg"===s||"s"===s[0]&&"v"===s[1]&&"g"===s[2]||"http://www.w3.org/2000/svg"===t.namespaceURI,i=n?document.createElementNS("http://www.w3.org/2000/svg",s.replace("svg","").toLowerCase()||s):document.createElement(s);for(let e in r){let t=r[e];if(null==t||!1===t)continue;let s=e.charCodeAt(0);if(99===s&&(e.length<6||"N"===e[5])){let e=Array.isArray(t)?t.join(" "):t;n?i.setAttribute("class",e):i.className=e}else if(115===s&&5===e.length)if("string"==typeof t)i.style.cssText=t;else{let e=i.style;for(let s in t)e[s]=t[s]}else 111===s&&110===e.charCodeAt(1)?i[e.toLowerCase()]=t:100===s&&e.length>20?i.innerHTML=t.__html:114===s&&3===e.length?setTimeout(()=>{"function"==typeof t?t(i):t.current=i},0):i.setAttribute(e,!0===t?"":String(t))}let l=a.length;if(!l)return void t.appendChild(i);let o=e=>{for(let t=0;t<l;t++){let s=a[t];if(null!=s&&!1!==s)if(Array.isArray(s))for(let t=0,r=s.length;t<r;t++){let r=s[t];null!=r&&!1!==r&&this.renderToDOM(r,e)}else this.renderToDOM(s,e)}};if(l>30){let e=document.createDocumentFragment();o(e),i.appendChild(e)}else o(i);t.appendChild(i)}render(e,t){let s="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!s)throw new Error(`Element not found: ${e}`);if(t.children&&t.children.length>500){let e=document.createDocumentFragment();this.renderToDOM(t,e),s.appendChild(e)}else this.renderToDOM(t,s);return s}batchRender(e,t){let s="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!s)throw new Error(`Element not found: ${e}`);let r=t.length;if(r>3e3){let e=document.createDocumentFragment(),a=0,n=1500,i=()=>{let l=Math.min(a+n,r);for(let s=a;s<l;s++)this.renderToDOM(t[s],e);a=l,a>=r?s.appendChild(e):requestAnimationFrame(i)};i()}else{let e=document.createDocumentFragment();for(let s=0;s<r;s++)this.renderToDOM(t[s],e);s.appendChild(e)}return s}renderChunked(e,t,s=5e3,r){let a="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!a)throw new Error(`Element not found: ${e}`);let n=t.length,i=0,l=()=>{let e=Math.min(i+s,n),o=document.createDocumentFragment();for(let s=i;s<e;s++)this.renderToDOM(t[s],o);a.appendChild(o),i=e,r&&r(i,n),i<n&&requestAnimationFrame(l)};return requestAnimationFrame(l),a}renderToHead(...e){let t=document.head;if(t)for(let s of e.flat())s&&this.renderToDOM(s,t);return t}addStyle(e){let t=document.createElement("style");return t.textContent=e,document.head.appendChild(t)}addMeta(e){let t=document.createElement("meta");for(let s in e)t.setAttribute(s,e[s]);return document.head.appendChild(t)}addLink(e){let t=document.createElement("link");for(let s in e)t.setAttribute(s,e[s]);return document.head.appendChild(t)}setTitle(e){return document.title=e}createState(e,t={}){let s=e,r=new Set,a=null,{throttle:n=0,deep:i=!1}=t,l=()=>r.forEach(e=>e(s));return{get value(){return s},set value(e){(i?JSON.stringify(s)!==JSON.stringify(e):s!==e)&&(s=e,n>0?a||(a=setTimeout(()=>{a=null,l()},n)):l())},subscribe:e=>(r.add(e),()=>r.delete(e)),destroy(){r.clear(),a&&clearTimeout(a)}}}computed(e,t){let s=e.map(e=>e.value),r=this.createState(t(...s));return e.forEach((e,a)=>{e.subscribe(e=>{s[a]=e,r.value=t(...s)})}),r}effect(e){e()}createVirtualList(e,t,s,r=50,a=5){let n=e.clientHeight,i=t.length*r,l=0,o=()=>{let{start:o,end:u}={start:Math.max(0,Math.floor(l/r)-a),end:Math.min(t.length,Math.ceil((l+n)/r)+a)},d=document.createElement("div");d.style.cssText=`height:${i}px;position:relative`;for(let e=o;e<u;e++){let a=document.createElement("div");a.style.cssText=`position:absolute;top:${e*r}px;height:${r}px;width:100%`,this.renderToDOM(s(t[e],e),a),d.appendChild(a)}e.innerHTML="",e.appendChild(d)},u=()=>{l=e.scrollTop,requestAnimationFrame(o)};return e.addEventListener("scroll",u),o(),{render:o,destroy:()=>{e.removeEventListener("scroll",u),e.innerHTML=""}}}lazy(e){let t=null,s=!1;return async(...r)=>(!t&&!s&&(s=!0,t=await e(),s=!1),t?t(...r):{tagName:"div",props:{class:"loading"},children:["Loading..."]})}cleanupUnusedElements(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),s=[];for(;t.nextNode();){let e=t.currentNode;e.id&&e.id.startsWith("r")&&!this.elementCache.has(e)&&s.push(e)}return s.forEach(e=>e.remove()),s.length}renderToString(e,t={}){let{pretty:s=!1,indent:r=0}=t,a=s?" ".repeat(r):"",n=s?"\n":"",i=this.resolveStateValue(e);if(i=this.unwrapReactive(i),Array.isArray(i))return i.map(e=>this.renderToString(e,t)).join("");if("object"!=typeof i||null===i)return null==i||!1===i?"":this.escapeHtml(String(i));let{tagName:l,props:o,children:u}=i,d=this.isSelfClosingTag(l),h=`${a}<${l}`,c=this.propsToAttributes(o);if(c&&(h+=` ${c}`),d)return h+=` />${n}`,h;if(h+=">",o.dangerouslySetInnerHTML)return h+=o.dangerouslySetInnerHTML.__html,h+=`</${l}>${n}`,h;if(u&&u.length>0){let e=u.map(e=>{let t=this.resolveStateValue(e);return this.unwrapReactive(t)}),t=e.some(e=>"object"==typeof e&&null!==e&&!Array.isArray(e)&&"tagName"in e);if(s&&t){h+=n;for(let t of e)if(null!=t&&!1!==t)if(Array.isArray(t))for(let e of t)null!=e&&!1!==e&&(h+=this.renderToString(e,{pretty:s,indent:r+1}));else h+=this.renderToString(t,{pretty:s,indent:r+1});h+=a}else for(let t of e)if(null!=t&&!1!==t)if(Array.isArray(t))for(let e of t)null!=e&&!1!==e&&(h+=this.renderToString(e,{pretty:!1,indent:0}));else h+=this.renderToString(t,{pretty:!1,indent:0})}return h+=`</${l}>${n}`,h}resolveStateValue(e){return e&&"object"==typeof e&&"value"in e&&"subscribe"in e?e.value:e}isReactiveWrapper(e){return!(!e||"object"!=typeof e||!e.tagName)&&("span"===e.tagName&&e.props?.id&&"string"==typeof e.props.id&&e.props.id.match(/^r[a-z0-9]{9}$/))}unwrapReactive(e){if(!this.isReactiveWrapper(e))return e;let t=e.children;if(!t||0===t.length)return"";if(1===t.length){let e=t[0];if(e&&"object"==typeof e&&"span"===e.tagName){let t=e.props,s=!t||0===Object.keys(t).length,r=e.children&&1===e.children.length&&"string"==typeof e.children[0];if(s&&r)return e.children[0]}return this.unwrapReactive(e)}return t.map(e=>this.unwrapReactive(e))}escapeHtml(e){let t={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,e=>t[e])}isSelfClosingTag(e){return new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]).has(e.toLowerCase())}propsToAttributes(e){let t=[];for(let s in e){if("children"===s||"dangerouslySetInnerHTML"===s||"ref"===s)continue;let r=e[s];if(r=this.resolveStateValue(r),null!=r&&!1!==r&&(!s.startsWith("on")||"function"!=typeof r)){if("className"===s||"class"===s){let e=Array.isArray(r)?r.join(" "):r;e&&t.push(`class="${this.escapeHtml(String(e))}"`);continue}if("style"===s){let e=this.styleToString(r);e&&t.push(`style="${this.escapeHtml(e)}"`);continue}if(!0===r){t.push(s);continue}t.push(`${s}="${this.escapeHtml(String(r))}"`)}}return t.join(" ")}styleToString(e){if("string"==typeof e)return e;if("object"==typeof e&&null!==e){let t=[];for(let s in e){let r=s.replace(/([A-Z])/g,"-$1").toLowerCase();t.push(`${r}:${e[s]}`)}return t.join(";")}return""}isState(e){return e&&"object"==typeof e&&"value"in e&&"subscribe"in e&&"function"==typeof e.subscribe}createReactiveChild(e,t){let s=t(e.value);if(typeof window<"u"&&typeof document<"u"){let s={node:null,renderFn:t};this.reactiveNodes.set(e,s),e.subscribe(()=>{if(s.node&&s.node.parentNode){let r=t(e.value);s.node.textContent=String(r??"")}})}return s}jsonToVNode(e){if(this.isState(e))return this.createReactiveChild(e,e=>e);if(null==e||"boolean"==typeof e||"string"==typeof e||"number"==typeof e)return e;let{tag:t,attributes:s={},children:r}=e,a={};for(let e in s){let t=s[e];"class"===e?a.className=this.isState(t)?t.value:t:a[e]=this.isState(t)?t.value:t}let n=[];if(null!=r)if(Array.isArray(r))for(let e of r)if(this.isState(e))n.push(this.createReactiveChild(e,e=>e));else{let t=this.jsonToVNode(e);null!=t&&!1!==t&&n.push(t)}else if(this.isState(r))n.push(this.createReactiveChild(r,e=>e));else if("object"==typeof r&&"tag"in r){let e=this.jsonToVNode(r);null!=e&&!1!==e&&n.push(e)}else n.push(r);return{tagName:t,props:a,children:n}}vNodeJsonToVNode(e){if(this.isState(e))return this.createReactiveChild(e,e=>e);if(null==e||"boolean"==typeof e||"string"==typeof e||"number"==typeof e)return e;let{tagName:t,props:s={},children:r=[]}=e,a={};for(let e in s){let t=s[e];a[e]=this.isState(t)?t.value:t}let n=[];for(let e of r)if(this.isState(e))n.push(this.createReactiveChild(e,e=>e));else{let t=this.vNodeJsonToVNode(e);null!=t&&!1!==t&&n.push(t)}return{tagName:t,props:a,children:n}}renderJson(e,t){let s=this.jsonToVNode(t);if(!s||"object"!=typeof s||!("tagName"in s))throw new Error("Invalid JSON structure");return this.render(e,s)}renderVNode(e,t){let s=this.vNodeJsonToVNode(t);if(!s||"object"!=typeof s||!("tagName"in s))throw new Error("Invalid VNode JSON structure");return this.render(e,s)}renderJsonToString(e,t={}){let s=this.jsonToVNode(e);return this.renderToString(s,t)}renderVNodeToString(e,t={}){let s=this.vNodeJsonToVNode(e);return this.renderToString(s,t)}renderServer(e){if("object"!=typeof e||null===e||!("tagName"in e))throw new Error("renderServer requires a VNode with html tag");if("html"!==e.tagName)throw new Error("renderServer requires a VNode with html tag as root");let t=e,s=null,r=null;for(let e of t.children||[])"object"==typeof e&&null!==e&&"tagName"in e&&("head"===e.tagName&&(s=e),"body"===e.tagName&&(r=e));if(t.props)for(let e in t.props){let s=t.props[e];null!=s&&!1!==s&&document.documentElement.setAttribute(e,String(s))}if(s){document.head.innerHTML="";for(let e of s.children||[])this.renderToDOM(e,document.head)}if(r){if(document.body.innerHTML="",r.props)for(let e in r.props){let t=r.props[e];null!=t&&!1!==t&&document.body.setAttribute(e,String(t))}for(let e of r.children||[])this.renderToDOM(e,document.body)}}renderToHTMLDocument(e,t={}){let{title:s="",meta:r=[],links:a=[],scripts:n=[],styles:i=[],lang:l="en",head:o="",bodyAttrs:u={},pretty:d=!1}=t,h=d?"\n":"",c=d?" ":"",p=d?" ":"",m=`<!DOCTYPE html>${h}<html lang="${l}">${h}${c}<head>${h}${p}<meta charset="UTF-8">${h}${p}<meta name="viewport" content="width=device-width, initial-scale=1.0">${h}`;s&&(m+=`${p}<title>${this.escapeHtml(s)}</title>${h}`);for(let e of r){m+=`${p}<meta`;for(let t in e)m+=` ${t}="${this.escapeHtml(e[t])}"`;m+=`>${h}`}for(let e of a){m+=`${p}<link`;for(let t in e)m+=` ${t}="${this.escapeHtml(e[t])}"`;m+=`>${h}`}for(let e of i)e.href?m+=`${p}<link rel="stylesheet" href="${this.escapeHtml(e.href)}">${h}`:e.content&&(m+=`${p}<style>${e.content}</style>${h}`);o&&(m+=o+h),m+=`${c}</head>${h}${c}<body`;for(let e in u)m+=` ${e}="${this.escapeHtml(u[e])}"`;m+=`>${h}`,m+=this.renderToString(e,{pretty:d,indent:2});for(let e of n)m+=`${p}<script`,e.type&&(m+=` type="${this.escapeHtml(e.type)}"`),e.async&&(m+=" async"),e.defer&&(m+=" defer"),e.src?m+=` src="${this.escapeHtml(e.src)}"><\/script>${h}`:e.content?m+=`>${e.content}<\/script>${h}`:m+=`><\/script>${h}`;return m+=`${c}</body>${h}</html>`,m}getElementCache(){return this.elementCache}},t=new e,s=(e,s)=>t.createState(e,s),r=(e,s)=>t.computed(e,s),a=e=>t.effect(e),n=(e,s)=>t.batchRender(e,s),i=(e,s,r,a)=>t.renderChunked(e,s,r,a),l=(e,s,r,a,n)=>t.createVirtualList(e,s,r,a,n),o=e=>t.lazy(e),u=e=>t.cleanupUnusedElements(e),d=(e,t)=>{let s=null;return(...r)=>{s||(s=setTimeout(()=>{s=null,e(...r)},t))}},h=(e,t)=>{let s=null;return(...r)=>{s&&clearTimeout(s),s=setTimeout(()=>e(...r),t)}},c=class{constructor(e,t,r){this.key=e,this.wsUrl=r,this.ws=null,this.pendingUpdates=[],this.localState=s(t),this.previousValue=t,this.connect()}get value(){return this.localState.value}set value(e){this.previousValue=this.localState.value,this.localState.value=e,this.sendToServer(e)}get state(){return this.localState}onChange(e){return this.localState.subscribe(t=>{let s=this.previousValue;this.previousValue=t,e(t,s)})}update(e){this.value=e(this.value)}connect(){if(typeof window>"u")return;let e=this.wsUrl||`ws://${location.host}`;this.ws=new WebSocket(e),this.ws.addEventListener("open",()=>{for(this.subscribe();this.pendingUpdates.length>0;){let e=this.pendingUpdates.shift();this.sendToServer(e)}}),this.ws.addEventListener("message",e=>{this.handleMessage(e.data)}),this.ws.addEventListener("close",()=>{setTimeout(()=>this.connect(),1e3)}),this.ws.addEventListener("error",e=>{console.error("[SharedState] WebSocket error:",e)})}subscribe(){!this.ws||this.ws.readyState!==WebSocket.OPEN||this.ws.send(JSON.stringify({type:"state:subscribe",key:this.key}))}handleMessage(e){try{let t=JSON.parse(e);if(t.key!==this.key)return;("state:init"===t.type||"state:update"===t.type)&&(this.localState.value=t.value)}catch{}}sendToServer(e){if(this.ws){if(this.ws.readyState!==WebSocket.OPEN)return void this.pendingUpdates.push(e);this.ws.send(JSON.stringify({type:"state:change",key:this.key,value:e}))}}disconnect(){this.ws&&(this.ws.close(),this.ws=null)}destroy(){this.disconnect(),this.localState.destroy()}};function p(e,t,s){return new c(e,t,s)}var m=new class{constructor(){this.states=new Map}create(e,t,s){if(this.states.has(e))return this.states.get(e);let r=new c(e,t,s);return this.states.set(e,r),r}get(e){return this.states.get(e)}delete(e){let t=this.states.get(e);return!!t&&(t.destroy(),this.states.delete(e))}clear(){this.states.forEach(e=>e.destroy()),this.states.clear()}},f=(e,s)=>{let r=null,a=null,n=null,i=!0,l=s(e.value),o=l&&"object"==typeof l&&"tagName"in l,u=null==l||!1===l;e.subscribe(()=>{r&&cancelAnimationFrame(r),r=requestAnimationFrame(()=>{(()=>{if(!a&&!n)return;let r=s(e.value);if(null==r||!1===r)i&&a&&(n=document.createComment("reactive"),a.parentNode?.replaceChild(n,a),i=!1);else if(!i&&n&&a&&(n.parentNode?.replaceChild(a,n),n=null,i=!0),a){let e=document.createDocumentFragment();if(o&&r&&"object"==typeof r&&"tagName"in r){let{props:s,children:n}=r;for(let e in s){let t=s[e];if("ref"!==e)if("class"===e||"className"===e)a.className=Array.isArray(t)?t.join(" "):t||"";else if("style"===e&&"object"==typeof t){let e=a.style;for(let s in t)e[s]=t[s]}else e.startsWith("on")?a[e.toLowerCase()]=t:null!=t&&!1!==t?a.setAttribute(e,String(!0===t?"":t)):a.removeAttribute(e)}for(let s of n)t.renderToDOM(s,e)}else t.renderToDOM(r,e);a.textContent="",a.appendChild(e),t.getElementCache().set(a,!0)}})(),r=null})});let d=e=>{a=e,u&&e.parentNode&&(n=document.createComment("reactive"),e.parentNode.replaceChild(n,e),i=!1)};if(o){let e=l;return{tagName:e.tagName,props:{...e.props,ref:d},children:e.children}}return{tagName:"span",props:{ref:d},children:[l]}},g=(e,s,r,a={})=>{let n=null,i=null;return s.subscribe(()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(()=>{if(i){let e=document.createDocumentFragment(),a=r(s.value);null==a||!1===a?(i.style.display="none",i.textContent=""):(i.style.display="",t.renderToDOM(a,e),i.textContent="",i.appendChild(e)),t.getElementCache().set(i,!0)}n=null})}),{tagName:e,props:{...a,ref:e=>{i=e}},children:[r(s.value)]}},y=e=>e&&void 0!==e.value?f(e,e=>({tagName:"span",props:{},children:[String(e)]})):String(e),v=e=>({value:e.value,oninput:t=>{e.value=t.target.value}}),b=e=>({checked:e.value,onchange:t=>{e.value=t.target.checked}}),$=class{constructor(){this.variables=[],this.rules=[],this.mediaRules=[],this.keyframes=[],this.fontFaces=[],this.imports=[],this.containerRules=[],this.supportsRules=[],this.layerRules=[],this._layerOrder=[]}addVar(e,t){let s={name:e.startsWith("--")?e:`--${e}`,value:t,toString(){return`var(${this.name})`}};return this.variables.push(s),s}var(e,t){let s="string"==typeof e?e.startsWith("--")?e:`--${e}`:e.name;return t?`var(${s}, ${t})`:`var(${s})`}addTag(e,t){let s={selector:e,styles:t,type:"tag"};return this.rules.push(s),s}addClass(e,t){let s={selector:e.startsWith(".")?e:`.${e}`,styles:t,type:"class"};return this.rules.push(s),s}addId(e,t){let s={selector:e.startsWith("#")?e:`#${e}`,styles:t,type:"id"};return this.rules.push(s),s}addPseudoClass(e,t,s){let r=e.startsWith(":")?e:`:${e}`,a={selector:s?`${s}${r}`:r,styles:t,type:"pseudo-class"};return this.rules.push(a),a}addPseudoElement(e,t,s){let r=e.startsWith("::")?e:`::${e}`,a={selector:s?`${s}${r}`:r,styles:t,type:"pseudo-element"};return this.rules.push(a),a}addAttribute(e,t,s){let r=e.startsWith("[")?e:`[${e}]`,a={selector:s?`${s}${r}`:r,styles:t,type:"attribute"};return this.rules.push(a),a}attrEquals(e,t,s,r){return this.addAttribute(`${e}="${t}"`,s,r)}attrContainsWord(e,t,s,r){return this.addAttribute(`${e}~="${t}"`,s,r)}attrStartsWith(e,t,s,r){return this.addAttribute(`${e}^="${t}"`,s,r)}attrEndsWith(e,t,s,r){return this.addAttribute(`${e}$="${t}"`,s,r)}attrContains(e,t,s,r){return this.addAttribute(`${e}*="${t}"`,s,r)}descendant(e,t,s){let r={selector:`${e} ${t}`,styles:s,type:"custom"};return this.rules.push(r),r}child(e,t,s){let r={selector:`${e} > ${t}`,styles:s,type:"custom"};return this.rules.push(r),r}adjacentSibling(e,t,s){let r={selector:`${e} + ${t}`,styles:s,type:"custom"};return this.rules.push(r),r}generalSibling(e,t,s){let r={selector:`${e} ~ ${t}`,styles:s,type:"custom"};return this.rules.push(r),r}multiple(e,t){let s={selector:e.join(", "),styles:t,type:"custom"};return this.rules.push(s),s}addName(e,t){return{selector:e.startsWith("--")?`&${e}`:`&--${e}`,styles:t,type:"name"}}nesting(e,...t){return e.nested=t,e}keyframe(e,t){let s={name:e,steps:Object.entries(t).map(([e,t])=>({step:"from"===e?"from":"to"===e?"to":`${e}%`,styles:t}))};return this.keyframes.push(s),s}keyframeFromTo(e,t,s){return this.keyframe(e,{from:t,to:s})}fontFace(e){return this.fontFaces.push(e),e}import(e,t){let s=t?`@import url("${e}") ${t};`:`@import url("${e}");`;return this.imports.push(s),s}media(e,t,s){let r={type:e,condition:t,rules:Object.entries(s).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.mediaRules.push(r),r}mediaScreen(e,t){return this.media("screen",e,t)}mediaPrint(e){return this.media("print","",e)}mediaMinWidth(e,t){return this.media("screen",`min-width: ${e}`,t)}mediaMaxWidth(e,t){return this.media("screen",`max-width: ${e}`,t)}mediaDark(e){let t={type:"",condition:"prefers-color-scheme: dark",rules:Object.entries(e).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.mediaRules.push(t),t}mediaLight(e){let t={type:"",condition:"prefers-color-scheme: light",rules:Object.entries(e).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.mediaRules.push(t),t}mediaReducedMotion(e){let t={type:"",condition:"prefers-reduced-motion: reduce",rules:Object.entries(e).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.mediaRules.push(t),t}container(e,t,s){let r={name:s,condition:e,rules:Object.entries(t).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.containerRules.push(r),r}addContainer(e,t){let s={...t,containerName:e};return this.addClass(e,s)}supports(e,t){let s={condition:e,rules:Object.entries(t).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.supportsRules.push(s),s}layerOrder(...e){this._layerOrder=e}layer(e,t){let s={name:e,rules:Object.entries(t).map(([e,t])=>({selector:e,styles:t,type:"custom"}))};return this.layerRules.push(s),s}add(e){return Object.entries(e).map(([e,t])=>{let s={selector:e,styles:t,type:"custom"};return this.rules.push(s),s})}important(e){return`${e} !important`}toKebabCase(e){return e.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()}stylesToString(e,t=" "){return Object.entries(e).map(([e,s])=>{let r="object"==typeof s&&null!==s&&"name"in s?`var(${s.name})`:s;return`${t}${this.toKebabCase(e)}: ${r};`}).join("\n")}renderRule(e,t=""){let s=`${t}${e.selector} {\n${this.stylesToString(e.styles,t+" ")}\n`;if(e.nested&&e.nested.length>0)for(let r of e.nested){s+=`\n${t}${r.selector.startsWith("&")?r.selector.replace(/&/g,e.selector):`${e.selector} ${r.selector}`} {\n${this.stylesToString(r.styles,t+" ")}\n${t}}\n`}return s+=`${t}}`,s}renderMediaRule(e){let t=`@media ${e.type&&e.condition?`${e.type} and (${e.condition})`:e.type?e.type:`(${e.condition})`} {\n`;for(let s of e.rules)t+=this.renderRule(s," ")+"\n";return t+="}",t}renderKeyframes(e){let t=`@keyframes ${e.name} {\n`;for(let s of e.steps)t+=` ${s.step} {\n${this.stylesToString(s.styles," ")}\n }\n`;return t+="}",t}renderFontFace(e){let t="@font-face {\n";return t+=` font-family: "${e.fontFamily}";\n`,t+=` src: ${e.src};\n`,e.fontWeight&&(t+=` font-weight: ${e.fontWeight};\n`),e.fontStyle&&(t+=` font-style: ${e.fontStyle};\n`),e.fontDisplay&&(t+=` font-display: ${e.fontDisplay};\n`),e.unicodeRange&&(t+=` unicode-range: ${e.unicodeRange};\n`),t+="}",t}renderContainerRule(e){let t=`@container ${e.name?`${e.name} `:""}(${e.condition}) {\n`;for(let s of e.rules)t+=this.renderRule(s," ")+"\n";return t+="}",t}renderSupportsRule(e){let t=`@supports (${e.condition}) {\n`;for(let s of e.rules)t+=this.renderRule(s," ")+"\n";return t+="}",t}renderLayerRule(e){let t=`@layer ${e.name} {\n`;for(let s of e.rules)t+=this.renderRule(s," ")+"\n";return t+="}",t}render(...e){let t=[];if(this.imports.length>0&&t.push(this.imports.join("\n")),this._layerOrder.length>0&&t.push(`@layer ${this._layerOrder.join(", ")};`),this.variables.length>0){let e=this.variables.map(e=>` ${e.name}: ${e.value};`).join("\n");t.push(`:root {\n${e}\n}`)}for(let e of this.fontFaces)t.push(this.renderFontFace(e));for(let e of this.keyframes)t.push(this.renderKeyframes(e));let s=[...this.rules],r=[...this.mediaRules],a=[],n=[...this.containerRules],i=[...this.supportsRules],l=[...this.layerRules];for(let t of e)t&&(Array.isArray(t)?s.push(...t):!("condition"in t)||!("rules"in t)||"name"in t&&"steps"in t?"name"in t&&"steps"in t?a.push(t):"name"in t&&"rules"in t?l.push(t):s.push(t):"type"in t?r.push(t):"name"in t&&"string"==typeof t.name?n.push(t):i.push(t));for(let e of a)t.push(this.renderKeyframes(e));for(let e of l)t.push(this.renderLayerRule(e));for(let e of s)t.push(this.renderRule(e));for(let e of i)t.push(this.renderSupportsRule(e));for(let e of n)t.push(this.renderContainerRule(e));for(let e of r)t.push(this.renderMediaRule(e));return t.join("\n\n")}inject(e){let t=this.render(),s=document.createElement("style");return e&&(s.id=e),s.textContent=t,document.head.appendChild(s),s}clear(){this.variables=[],this.rules=[],this.mediaRules=[],this.keyframes=[],this.fontFaces=[],this.imports=[],this.containerRules=[],this.supportsRules=[],this.layerRules=[],this._layerOrder=[]}},w=e=>function(t,...s){if(!arguments.length)return{tagName:e,props:{},children:[]};let r=t&&"object"==typeof t&&"value"in t&&"subscribe"in t,a=t&&"object"==typeof t&&"tagName"in t,n="object"!=typeof t||Array.isArray(t)||null===t||r||a,i=n?{}:t,l=n?[t,...s]:s;if(!l.length)return{tagName:e,props:i,children:[]};let o=[];for(let e=0,t=l.length;e<t;e++){let t=l[e];if(null!=t&&!1!==t)if(Array.isArray(t))for(let e=0,s=t.length;e<s;e++){let s=t[e];null!=s&&!1!==s&&o.push(s)}else o.push(t)}return{tagName:e,props:i,children:o}},S={};["html","head","body","title","base","link","meta","style","address","article","aside","footer","header","h1","h2","h3","h4","h5","h6","main","nav","section","blockquote","dd","div","dl","dt","figcaption","figure","hr","li","ol","p","pre","ul","a","abbr","b","bdi","bdo","br","cite","code","data","dfn","em","i","kbd","mark","q","rp","rt","ruby","s","samp","small","span","strong","sub","sup","time","u","wbr","area","audio","img","map","track","video","embed","iframe","object","param","picture","portal","source","canvas","noscript","script","del","ins","caption","col","colgroup","table","tbody","td","tfoot","th","thead","tr","button","datalist","fieldset","form","input","label","legend","meter","optgroup","option","output","progress","select","textarea","details","dialog","menu","summary","slot","template"].forEach(e=>{S[e]=w(e)}),["svg","circle","rect","path","line","polyline","polygon","ellipse","g","text","tspan","defs","linearGradient","radialGradient","stop","pattern","mask","clipPath","use","symbol","marker","image","foreignObject","animate","animateTransform","animateMotion","set","filter","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feFlood","feGaussianBlur","feMorphology","feOffset","feSpecularLighting","feTile","feTurbulence"].forEach(e=>{let t="svg"+e.charAt(0).toUpperCase()+e.slice(1);S[t]=w(e)}),["math","mi","mn","mo","ms","mtext","mrow","mfrac","msqrt","mroot","msub","msup"].forEach(e=>{let t="math"+e.charAt(0).toUpperCase()+e.slice(1);S[t]=w(e)}),S.varElement=w("var");var{html:M,head:T,body:C,title:N,base:E,link:k,meta:R,style:F,address:A,article:j,aside:O,footer:L,header:D,h1:x,h2:H,h3:W,h4:V,h5:q,h6:P,main:U,nav:I,section:B,blockquote:_,dd:J,div:G,dl:z,dt:K,figcaption:Z,figure:Y,hr:Q,li:X,ol:ee,p:te,pre:se,ul:re,a:ae,abbr:ne,b:ie,bdi:le,bdo:oe,br:ue,cite:de,code:he,data:ce,dfn:pe,em:me,i:fe,kbd:ge,mark:ye,q:ve,rp:be,rt:$e,ruby:we,s:Se,samp:Me,small:Te,span:Ce,strong:Ne,sub:Ee,sup:ke,time:Re,u:Fe,wbr:Ae,area:je,audio:Oe,img:Le,map:De,track:xe,video:He,embed:We,iframe:Ve,object:qe,param:Pe,picture:Ue,portal:Ie,source:Be,canvas:_e,noscript:Je,script:Ge,del:ze,ins:Ke,caption:Ze,col:Ye,colgroup:Qe,table:Xe,tbody:et,td:tt,tfoot:st,th:rt,thead:at,tr:nt,button:it,datalist:lt,fieldset:ot,form:ut,input:dt,label:ht,legend:ct,meter:pt,optgroup:mt,option:ft,output:gt,progress:yt,select:vt,textarea:bt,details:$t,dialog:wt,menu:St,summary:Mt,slot:Tt,template:Ct,svgSvg:Nt,svgCircle:Et,svgRect:kt,svgPath:Rt,svgLine:Ft,svgPolyline:At,svgPolygon:jt,svgEllipse:Ot,svgG:Lt,svgText:Dt,svgTspan:xt,svgDefs:Ht,svgLinearGradient:Wt,svgRadialGradient:Vt,svgStop:qt,svgPattern:Pt,svgMask:Ut,svgClipPath:It,svgUse:Bt,svgSymbol:_t,svgMarker:Jt,svgImage:Gt,svgForeignObject:zt,svgAnimate:Kt,svgAnimateTransform:Zt,svgAnimateMotion:Yt,svgSet:Qt,svgFilter:Xt,svgFeBlend:es,svgFeColorMatrix:ts,svgFeComponentTransfer:ss,svgFeComposite:rs,svgFeConvolveMatrix:as,svgFeDiffuseLighting:ns,svgFeDisplacementMap:is,svgFeFlood:ls,svgFeGaussianBlur:os,svgFeMorphology:us,svgFeOffset:ds,svgFeSpecularLighting:hs,svgFeTile:cs,svgFeTurbulence:ps,mathMath:ms,mathMi:fs,mathMn:gs,mathMo:ys,mathMs:vs,mathMtext:bs,mathMrow:$s,mathMfrac:ws,mathMsqrt:Ss,mathMroot:Ms,mathMsub:Ts,mathMsup:Cs,varElement:Ns}=S,Es=S,ks=document,Rs=ks.querySelector.bind(ks),Fs=ks.querySelectorAll.bind(ks),As=ks.createElement.bind(ks),js=ks.createElementNS.bind(ks,"http://www.w3.org/2000/svg"),Os=ks.createElementNS.bind(ks,"http://www.w3.org/1998/Math/MathML"),Ls=ks.createDocumentFragment.bind(ks),Ds=ks.createTextNode.bind(ks),xs=ks.createComment.bind(ks),Hs=ks.getElementById.bind(ks),Ws=ks.getElementsByClassName.bind(ks),Vs=ks.getElementsByTagName.bind(ks),qs=ks.getElementsByName.bind(ks);function Ps(e,t){let s=e.split("/").filter(Boolean),r=t.split("/").filter(Boolean);if(e.endsWith("*")){let s=e.slice(0,-1);if(t.startsWith(s)||"/"===s||"*"===e)return{"*":t.slice(s.length)}}if(s.length!==r.length)return null;let a={};for(let e=0;e<s.length;e++){let t=s[e],n=r[e];if(t.startsWith(":"))a[t.slice(1)]=decodeURIComponent(n);else if(t!==n)return null}return a}function Us(e){let{mode:s="history",base:r="",routes:a}=e,n=[],i=e=>{let t={};return new URLSearchParams(e).forEach((e,s)=>{t[s]=e}),t},l=()=>"hash"===s?window.location.hash.slice(1)||"/":window.location.pathname.replace(r,"")||"/",o=e=>{let[t,s=""]=e.split("?"),[r,a=""]=t.split("#");return{path:r||"/",params:{},query:i(s),hash:a?"#"+a:""}},u=e=>{for(let t of a){let s=Ps(t.path,e);if(null!==s)return{route:t,params:s}}return null},d=t.createState(o(l())),h=(e,t=!1)=>{let a=o(e),i=u(a.path);i&&(a.params=i.params);for(let e of n){let s=e(a,d.value);if(!1===s)return;if("string"==typeof s)return void h(s,t)}if(i?.route.beforeEnter){let e=i.route.beforeEnter(a,d.value);if(!1===e)return;if("string"==typeof e)return void h(e,t)}let l="hash"===s?"#"+e:r+e;t?window.history.replaceState({path:e},"",l):window.history.pushState({path:e},"",l),d.value=a},c=()=>{let e=l(),t=o(e),s=u(t.path);s&&(t.params=s.params),d.value=t};return typeof window<"u"&&window.addEventListener("popstate",c),{currentRoute:d,push:e=>h(e,!1),replace:e=>h(e,!0),back:()=>window.history.back(),forward:()=>window.history.forward(),go:e=>window.history.go(e),beforeEach:e=>{n.push(e)},destroy:()=>{typeof window<"u"&&window.removeEventListener("popstate",c),d.destroy()}}}function Is(e,t){let{routes:s,notFound:r}=t;return()=>{let t=e.currentRoute.value,a=s.find(e=>null!==Ps(e.path,t.path));if(a){let e=Ps(a.path,t.path)||{},s=a.component({...e,...t.query});return"object"==typeof s&&null!==s&&"tagName"in s?s:{tagName:"span",props:{},children:[s]}}if(r){let e=r(t.params);return"object"==typeof e&&null!==e&&"tagName"in e?e:{tagName:"span",props:{},children:[e]}}return{tagName:"div",props:{},children:["404 - Not Found"]}}}var Bs=(e,t,...s)=>({tagName:"a",props:{...t,href:t.to,onclick:s=>{s.preventDefault(),e.push(t.to)}},children:s}),_s=new class{constructor(){this.enabled=!1,this.ws=null,this.acceptCallbacks=[],this.disposeCallbacks=[],this.declined=!1,typeof window>"u"||this.connect()}connect(){let e="https:"===window.location.protocol?"wss:":"ws:",t=window.location.hostname,s=window.location.port||"3000";this.ws=new WebSocket(`${e}//${t}:${s}`),this.ws.onopen=()=>{this.enabled=!0,console.log("[Elit HMR] Connected ✓")},this.ws.onmessage=e=>{try{let t=JSON.parse(e.data);this.handleMessage(t)}catch(e){console.error("[Elit HMR] Error parsing message:",e)}},this.ws.onclose=()=>{this.enabled=!1,console.log("[Elit HMR] Disconnected - Attempting reconnect..."),setTimeout(()=>this.reload(),1e3)},this.ws.onerror=e=>{console.error("[Elit HMR] WebSocket error:",e)}}handleMessage(e){switch(e.type){case"connected":console.log("[Elit HMR] Ready");break;case"update":if(console.log(`[Elit HMR] Update detected: ${e.path}`),this.declined)return void this.reload();this.disposeCallbacks.forEach(e=>e()),this.disposeCallbacks=[],this.acceptCallbacks.length>0?this.acceptCallbacks.forEach(e=>e()):this.reload();break;case"reload":console.log("[Elit HMR] Full reload requested"),this.reload();break;case"error":console.error("[Elit HMR] Server error:",e.error)}}reload(){window.location.reload()}accept(e){e&&this.acceptCallbacks.push(e),this.declined=!1}decline(){this.declined=!0}dispose(e){this.disposeCallbacks.push(e)}};typeof window<"u"&&(window.__ELIT_HMR__=_s);var Js=_s;export{$ as CreateStyle,e as DomNode,c as SharedState,ae as a,ne as abbr,A as address,je as area,j as article,O as aside,Oe as audio,ie as b,E as base,n as batchRender,le as bdi,oe as bdo,b as bindChecked,v as bindValue,_ as blockquote,C as body,ue as br,it as button,_e as canvas,Ze as caption,de as cite,u as cleanupUnused,he as code,Ye as col,Qe as colgroup,xs as commentNode,r as computed,As as createEl,w as createElementFactory,Os as createMathEl,Us as createRouter,Is as createRouterView,p as createSharedState,s as createState,js as createSvgEl,l as createVirtualList,ce as data,lt as datalist,J as dd,h as debounce,ze as del,$t as details,pe as dfn,wt as dialog,G as div,z as dl,ks as doc,t as dom,K as dt,a as effect,Es as el,S as elements,me as em,We as embed,ot as fieldset,Z as figcaption,Y as figure,L as footer,ut as form,Ls as fragment,Rs as getEl,Ws as getElClass,Hs as getElId,qs as getElName,Vs as getElTag,Fs as getEls,x as h1,H as h2,W as h3,V as h4,q as h5,P as h6,T as head,D as header,Js as hmr,Q as hr,M as html,fe as i,Ve as iframe,Le as img,dt as input,Ke as ins,ge as kbd,ht as label,o as lazy,ct as legend,X as li,k as link,U as main,De as map,ye as mark,ms as mathMath,ws as mathMfrac,fs as mathMi,gs as mathMn,ys as mathMo,Ms as mathMroot,$s as mathMrow,vs as mathMs,Ss as mathMsqrt,Ts as mathMsub,Cs as mathMsup,bs as mathMtext,St as menu,R as meta,pt as meter,I as nav,Je as noscript,qe as object,ee as ol,mt as optgroup,ft as option,gt as output,te as p,Pe as param,Ue as picture,Ie as portal,se as pre,yt as progress,ve as q,f as reactive,g as reactiveAs,i as renderChunked,Bs as routerLink,be as rp,$e as rt,we as ruby,Se as s,Me as samp,Ge as script,B as section,vt as select,m as sharedStateManager,Tt as slot,Te as small,Be as source,Ce as span,Ne as strong,F as style,Ee as sub,Mt as summary,ke as sup,Kt as svgAnimate,Yt as svgAnimateMotion,Zt as svgAnimateTransform,Et as svgCircle,It as svgClipPath,Ht as svgDefs,Ot as svgEllipse,es as svgFeBlend,ts as svgFeColorMatrix,ss as svgFeComponentTransfer,rs as svgFeComposite,as as svgFeConvolveMatrix,ns as svgFeDiffuseLighting,is as svgFeDisplacementMap,ls as svgFeFlood,os as svgFeGaussianBlur,us as svgFeMorphology,ds as svgFeOffset,hs as svgFeSpecularLighting,cs as svgFeTile,ps as svgFeTurbulence,Xt as svgFilter,zt as svgForeignObject,Lt as svgG,Gt as svgImage,Ft as svgLine,Wt as svgLinearGradient,Jt as svgMarker,Ut as svgMask,Rt as svgPath,Pt as svgPattern,jt as svgPolygon,At as svgPolyline,Vt as svgRadialGradient,kt as svgRect,Qt as svgSet,qt as svgStop,Nt as svgSvg,_t as svgSymbol,Dt as svgText,xt as svgTspan,Bt as svgUse,Xe as table,et as tbody,tt as td,Ct as template,y as text,Ds as textNode,bt as textarea,st as tfoot,rt as th,at as thead,d as throttle,Re as time,N as title,nt as tr,xe as track,Fe as u,re as ul,Ns as varElement,He as video,Ae as wbr};
|
package/dist/dom.d.mts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { P as Props, u as Children, V as VNode, C as Child, x as StateOptions, w as State, y as VirtualListController, J as JsonNode, z as VNodeJson } from './types-DOAdFFJB.mjs';
|
|
2
|
+
import 'http';
|
|
3
|
+
import 'ws';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Elit - DomNode Core Class
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare class DomNode {
|
|
10
|
+
private elementCache;
|
|
11
|
+
createElement(tagName: string, props?: Props, children?: Children): VNode;
|
|
12
|
+
renderToDOM(vNode: Child, parent: HTMLElement | SVGElement | DocumentFragment): void;
|
|
13
|
+
render(rootElement: string | HTMLElement, vNode: VNode): HTMLElement;
|
|
14
|
+
batchRender(rootElement: string | HTMLElement, vNodes: VNode[]): HTMLElement;
|
|
15
|
+
renderChunked(rootElement: string | HTMLElement, vNodes: VNode[], chunkSize?: number, onProgress?: (current: number, total: number) => void): HTMLElement;
|
|
16
|
+
renderToHead(...vNodes: Array<VNode | VNode[]>): HTMLHeadElement | null;
|
|
17
|
+
addStyle(cssText: string): HTMLStyleElement;
|
|
18
|
+
addMeta(attrs: Record<string, string>): HTMLMetaElement;
|
|
19
|
+
addLink(attrs: Record<string, string>): HTMLLinkElement;
|
|
20
|
+
setTitle(text: string): string;
|
|
21
|
+
createState<T>(initialValue: T, options?: StateOptions): State<T>;
|
|
22
|
+
computed<T extends any[], R>(states: {
|
|
23
|
+
[K in keyof T]: State<T[K]>;
|
|
24
|
+
}, computeFn: (...values: T) => R): State<R>;
|
|
25
|
+
effect(stateFn: () => void): void;
|
|
26
|
+
createVirtualList<T>(container: HTMLElement, items: T[], renderItem: (item: T, index: number) => VNode, itemHeight?: number, bufferSize?: number): VirtualListController;
|
|
27
|
+
lazy<T extends any[], R>(loadFn: () => Promise<(...args: T) => R>): (...args: T) => Promise<R | VNode>;
|
|
28
|
+
cleanupUnusedElements(root: HTMLElement): number;
|
|
29
|
+
renderToString(vNode: Child, options?: {
|
|
30
|
+
pretty?: boolean;
|
|
31
|
+
indent?: number;
|
|
32
|
+
}): string;
|
|
33
|
+
private resolveStateValue;
|
|
34
|
+
private isReactiveWrapper;
|
|
35
|
+
private unwrapReactive;
|
|
36
|
+
private escapeHtml;
|
|
37
|
+
private isSelfClosingTag;
|
|
38
|
+
private propsToAttributes;
|
|
39
|
+
private styleToString;
|
|
40
|
+
private isState;
|
|
41
|
+
private reactiveNodes;
|
|
42
|
+
private createReactiveChild;
|
|
43
|
+
jsonToVNode(json: JsonNode | string | number | boolean | null | undefined | State<any>): Child;
|
|
44
|
+
vNodeJsonToVNode(json: VNodeJson | State<any>): Child;
|
|
45
|
+
renderJson(rootElement: string | HTMLElement, json: JsonNode): HTMLElement;
|
|
46
|
+
renderVNode(rootElement: string | HTMLElement, json: VNodeJson): HTMLElement;
|
|
47
|
+
renderJsonToString(json: JsonNode, options?: {
|
|
48
|
+
pretty?: boolean;
|
|
49
|
+
indent?: number;
|
|
50
|
+
}): string;
|
|
51
|
+
renderVNodeToString(json: VNodeJson, options?: {
|
|
52
|
+
pretty?: boolean;
|
|
53
|
+
indent?: number;
|
|
54
|
+
}): string;
|
|
55
|
+
renderServer(vNode: Child): void;
|
|
56
|
+
renderToHTMLDocument(vNode: Child, options?: {
|
|
57
|
+
title?: string;
|
|
58
|
+
meta?: Array<Record<string, string>>;
|
|
59
|
+
links?: Array<Record<string, string>>;
|
|
60
|
+
scripts?: Array<{
|
|
61
|
+
src?: string;
|
|
62
|
+
content?: string;
|
|
63
|
+
async?: boolean;
|
|
64
|
+
defer?: boolean;
|
|
65
|
+
type?: string;
|
|
66
|
+
}>;
|
|
67
|
+
styles?: Array<{
|
|
68
|
+
href?: string;
|
|
69
|
+
content?: string;
|
|
70
|
+
}>;
|
|
71
|
+
lang?: string;
|
|
72
|
+
head?: string;
|
|
73
|
+
bodyAttrs?: Record<string, string>;
|
|
74
|
+
pretty?: boolean;
|
|
75
|
+
}): string;
|
|
76
|
+
getElementCache(): WeakMap<Element, boolean>;
|
|
77
|
+
}
|
|
78
|
+
declare const dom: DomNode;
|
|
79
|
+
|
|
80
|
+
export { DomNode, dom };
|
package/dist/dom.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { P as Props, u as Children, V as VNode, C as Child, x as StateOptions, w as State, y as VirtualListController, J as JsonNode, z as VNodeJson } from './types-DOAdFFJB.js';
|
|
2
|
+
import 'http';
|
|
3
|
+
import 'ws';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Elit - DomNode Core Class
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare class DomNode {
|
|
10
|
+
private elementCache;
|
|
11
|
+
createElement(tagName: string, props?: Props, children?: Children): VNode;
|
|
12
|
+
renderToDOM(vNode: Child, parent: HTMLElement | SVGElement | DocumentFragment): void;
|
|
13
|
+
render(rootElement: string | HTMLElement, vNode: VNode): HTMLElement;
|
|
14
|
+
batchRender(rootElement: string | HTMLElement, vNodes: VNode[]): HTMLElement;
|
|
15
|
+
renderChunked(rootElement: string | HTMLElement, vNodes: VNode[], chunkSize?: number, onProgress?: (current: number, total: number) => void): HTMLElement;
|
|
16
|
+
renderToHead(...vNodes: Array<VNode | VNode[]>): HTMLHeadElement | null;
|
|
17
|
+
addStyle(cssText: string): HTMLStyleElement;
|
|
18
|
+
addMeta(attrs: Record<string, string>): HTMLMetaElement;
|
|
19
|
+
addLink(attrs: Record<string, string>): HTMLLinkElement;
|
|
20
|
+
setTitle(text: string): string;
|
|
21
|
+
createState<T>(initialValue: T, options?: StateOptions): State<T>;
|
|
22
|
+
computed<T extends any[], R>(states: {
|
|
23
|
+
[K in keyof T]: State<T[K]>;
|
|
24
|
+
}, computeFn: (...values: T) => R): State<R>;
|
|
25
|
+
effect(stateFn: () => void): void;
|
|
26
|
+
createVirtualList<T>(container: HTMLElement, items: T[], renderItem: (item: T, index: number) => VNode, itemHeight?: number, bufferSize?: number): VirtualListController;
|
|
27
|
+
lazy<T extends any[], R>(loadFn: () => Promise<(...args: T) => R>): (...args: T) => Promise<R | VNode>;
|
|
28
|
+
cleanupUnusedElements(root: HTMLElement): number;
|
|
29
|
+
renderToString(vNode: Child, options?: {
|
|
30
|
+
pretty?: boolean;
|
|
31
|
+
indent?: number;
|
|
32
|
+
}): string;
|
|
33
|
+
private resolveStateValue;
|
|
34
|
+
private isReactiveWrapper;
|
|
35
|
+
private unwrapReactive;
|
|
36
|
+
private escapeHtml;
|
|
37
|
+
private isSelfClosingTag;
|
|
38
|
+
private propsToAttributes;
|
|
39
|
+
private styleToString;
|
|
40
|
+
private isState;
|
|
41
|
+
private reactiveNodes;
|
|
42
|
+
private createReactiveChild;
|
|
43
|
+
jsonToVNode(json: JsonNode | string | number | boolean | null | undefined | State<any>): Child;
|
|
44
|
+
vNodeJsonToVNode(json: VNodeJson | State<any>): Child;
|
|
45
|
+
renderJson(rootElement: string | HTMLElement, json: JsonNode): HTMLElement;
|
|
46
|
+
renderVNode(rootElement: string | HTMLElement, json: VNodeJson): HTMLElement;
|
|
47
|
+
renderJsonToString(json: JsonNode, options?: {
|
|
48
|
+
pretty?: boolean;
|
|
49
|
+
indent?: number;
|
|
50
|
+
}): string;
|
|
51
|
+
renderVNodeToString(json: VNodeJson, options?: {
|
|
52
|
+
pretty?: boolean;
|
|
53
|
+
indent?: number;
|
|
54
|
+
}): string;
|
|
55
|
+
renderServer(vNode: Child): void;
|
|
56
|
+
renderToHTMLDocument(vNode: Child, options?: {
|
|
57
|
+
title?: string;
|
|
58
|
+
meta?: Array<Record<string, string>>;
|
|
59
|
+
links?: Array<Record<string, string>>;
|
|
60
|
+
scripts?: Array<{
|
|
61
|
+
src?: string;
|
|
62
|
+
content?: string;
|
|
63
|
+
async?: boolean;
|
|
64
|
+
defer?: boolean;
|
|
65
|
+
type?: string;
|
|
66
|
+
}>;
|
|
67
|
+
styles?: Array<{
|
|
68
|
+
href?: string;
|
|
69
|
+
content?: string;
|
|
70
|
+
}>;
|
|
71
|
+
lang?: string;
|
|
72
|
+
head?: string;
|
|
73
|
+
bodyAttrs?: Record<string, string>;
|
|
74
|
+
pretty?: boolean;
|
|
75
|
+
}): string;
|
|
76
|
+
getElementCache(): WeakMap<Element, boolean>;
|
|
77
|
+
}
|
|
78
|
+
declare const dom: DomNode;
|
|
79
|
+
|
|
80
|
+
export { DomNode, dom };
|
package/dist/dom.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var e=class{constructor(){this.elementCache=new WeakMap,this.reactiveNodes=new Map}createElement(e,t={},r=[]){return{tagName:e,props:t,children:r}}renderToDOM(e,t){if(null==e||!1===e)return;if("object"!=typeof e)return void t.appendChild(document.createTextNode(String(e)));let{tagName:r,props:n,children:i}=e,l="svg"===r||"s"===r[0]&&"v"===r[1]&&"g"===r[2]||"http://www.w3.org/2000/svg"===t.namespaceURI,o=l?document.createElementNS("http://www.w3.org/2000/svg",r.replace("svg","").toLowerCase()||r):document.createElement(r);for(let e in n){let t=n[e];if(null==t||!1===t)continue;let r=e.charCodeAt(0);if(99===r&&(e.length<6||"N"===e[5])){let e=Array.isArray(t)?t.join(" "):t;l?o.setAttribute("class",e):o.className=e}else if(115===r&&5===e.length)if("string"==typeof t)o.style.cssText=t;else{let e=o.style;for(let r in t)e[r]=t[r]}else 111===r&&110===e.charCodeAt(1)?o[e.toLowerCase()]=t:100===r&&e.length>20?o.innerHTML=t.__html:114===r&&3===e.length?setTimeout(()=>{"function"==typeof t?t(o):t.current=o},0):o.setAttribute(e,!0===t?"":String(t))}let s=i.length;if(!s)return void t.appendChild(o);let a=e=>{for(let t=0;t<s;t++){let r=i[t];if(null!=r&&!1!==r)if(Array.isArray(r))for(let t=0,n=r.length;t<n;t++){let n=r[t];null!=n&&!1!==n&&this.renderToDOM(n,e)}else this.renderToDOM(r,e)}};if(s>30){let e=document.createDocumentFragment();a(e),o.appendChild(e)}else a(o);t.appendChild(o)}render(e,t){let r="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!r)throw new Error(`Element not found: ${e}`);if(t.children&&t.children.length>500){let e=document.createDocumentFragment();this.renderToDOM(t,e),r.appendChild(e)}else this.renderToDOM(t,r);return r}batchRender(e,t){let r="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!r)throw new Error(`Element not found: ${e}`);let n=t.length;if(n>3e3){let e=document.createDocumentFragment(),i=0,l=1500,o=()=>{let s=Math.min(i+l,n);for(let r=i;r<s;r++)this.renderToDOM(t[r],e);i=s,i>=n?r.appendChild(e):requestAnimationFrame(o)};o()}else{let e=document.createDocumentFragment();for(let r=0;r<n;r++)this.renderToDOM(t[r],e);r.appendChild(e)}return r}renderChunked(e,t,r=5e3,n){let i="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!i)throw new Error(`Element not found: ${e}`);let l=t.length,o=0,s=()=>{let e=Math.min(o+r,l),a=document.createDocumentFragment();for(let r=o;r<e;r++)this.renderToDOM(t[r],a);i.appendChild(a),o=e,n&&n(o,l),o<l&&requestAnimationFrame(s)};return requestAnimationFrame(s),i}renderToHead(...e){let t=document.head;if(t)for(let r of e.flat())r&&this.renderToDOM(r,t);return t}addStyle(e){let t=document.createElement("style");return t.textContent=e,document.head.appendChild(t)}addMeta(e){let t=document.createElement("meta");for(let r in e)t.setAttribute(r,e[r]);return document.head.appendChild(t)}addLink(e){let t=document.createElement("link");for(let r in e)t.setAttribute(r,e[r]);return document.head.appendChild(t)}setTitle(e){return document.title=e}createState(e,t={}){let r=e,n=new Set,i=null,{throttle:l=0,deep:o=!1}=t,s=()=>n.forEach(e=>e(r));return{get value(){return r},set value(e){(o?JSON.stringify(r)!==JSON.stringify(e):r!==e)&&(r=e,l>0?i||(i=setTimeout(()=>{i=null,s()},l)):s())},subscribe:e=>(n.add(e),()=>n.delete(e)),destroy(){n.clear(),i&&clearTimeout(i)}}}computed(e,t){let r=e.map(e=>e.value),n=this.createState(t(...r));return e.forEach((e,i)=>{e.subscribe(e=>{r[i]=e,n.value=t(...r)})}),n}effect(e){e()}createVirtualList(e,t,r,n=50,i=5){let l=e.clientHeight,o=t.length*n,s=0,a=()=>{let{start:a,end:d}={start:Math.max(0,Math.floor(s/n)-i),end:Math.min(t.length,Math.ceil((s+l)/n)+i)},u=document.createElement("div");u.style.cssText=`height:${o}px;position:relative`;for(let e=a;e<d;e++){let i=document.createElement("div");i.style.cssText=`position:absolute;top:${e*n}px;height:${n}px;width:100%`,this.renderToDOM(r(t[e],e),i),u.appendChild(i)}e.innerHTML="",e.appendChild(u)},d=()=>{s=e.scrollTop,requestAnimationFrame(a)};return e.addEventListener("scroll",d),a(),{render:a,destroy:()=>{e.removeEventListener("scroll",d),e.innerHTML=""}}}lazy(e){let t=null,r=!1;return async(...n)=>(!t&&!r&&(r=!0,t=await e(),r=!1),t?t(...n):{tagName:"div",props:{class:"loading"},children:["Loading..."]})}cleanupUnusedElements(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),r=[];for(;t.nextNode();){let e=t.currentNode;e.id&&e.id.startsWith("r")&&!this.elementCache.has(e)&&r.push(e)}return r.forEach(e=>e.remove()),r.length}renderToString(e,t={}){let{pretty:r=!1,indent:n=0}=t,i=r?" ".repeat(n):"",l=r?"\n":"",o=this.resolveStateValue(e);if(o=this.unwrapReactive(o),Array.isArray(o))return o.map(e=>this.renderToString(e,t)).join("");if("object"!=typeof o||null===o)return null==o||!1===o?"":this.escapeHtml(String(o));let{tagName:s,props:a,children:d}=o,u=this.isSelfClosingTag(s),c=`${i}<${s}`,h=this.propsToAttributes(a);if(h&&(c+=` ${h}`),u)return c+=` />${l}`,c;if(c+=">",a.dangerouslySetInnerHTML)return c+=a.dangerouslySetInnerHTML.__html,c+=`</${s}>${l}`,c;if(d&&d.length>0){let e=d.map(e=>{let t=this.resolveStateValue(e);return this.unwrapReactive(t)}),t=e.some(e=>"object"==typeof e&&null!==e&&!Array.isArray(e)&&"tagName"in e);if(r&&t){c+=l;for(let t of e)if(null!=t&&!1!==t)if(Array.isArray(t))for(let e of t)null!=e&&!1!==e&&(c+=this.renderToString(e,{pretty:r,indent:n+1}));else c+=this.renderToString(t,{pretty:r,indent:n+1});c+=i}else for(let t of e)if(null!=t&&!1!==t)if(Array.isArray(t))for(let e of t)null!=e&&!1!==e&&(c+=this.renderToString(e,{pretty:!1,indent:0}));else c+=this.renderToString(t,{pretty:!1,indent:0})}return c+=`</${s}>${l}`,c}resolveStateValue(e){return e&&"object"==typeof e&&"value"in e&&"subscribe"in e?e.value:e}isReactiveWrapper(e){return!(!e||"object"!=typeof e||!e.tagName)&&("span"===e.tagName&&e.props?.id&&"string"==typeof e.props.id&&e.props.id.match(/^r[a-z0-9]{9}$/))}unwrapReactive(e){if(!this.isReactiveWrapper(e))return e;let t=e.children;if(!t||0===t.length)return"";if(1===t.length){let e=t[0];if(e&&"object"==typeof e&&"span"===e.tagName){let t=e.props,r=!t||0===Object.keys(t).length,n=e.children&&1===e.children.length&&"string"==typeof e.children[0];if(r&&n)return e.children[0]}return this.unwrapReactive(e)}return t.map(e=>this.unwrapReactive(e))}escapeHtml(e){let t={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,e=>t[e])}isSelfClosingTag(e){return new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]).has(e.toLowerCase())}propsToAttributes(e){let t=[];for(let r in e){if("children"===r||"dangerouslySetInnerHTML"===r||"ref"===r)continue;let n=e[r];if(n=this.resolveStateValue(n),null!=n&&!1!==n&&(!r.startsWith("on")||"function"!=typeof n)){if("className"===r||"class"===r){let e=Array.isArray(n)?n.join(" "):n;e&&t.push(`class="${this.escapeHtml(String(e))}"`);continue}if("style"===r){let e=this.styleToString(n);e&&t.push(`style="${this.escapeHtml(e)}"`);continue}if(!0===n){t.push(r);continue}t.push(`${r}="${this.escapeHtml(String(n))}"`)}}return t.join(" ")}styleToString(e){if("string"==typeof e)return e;if("object"==typeof e&&null!==e){let t=[];for(let r in e){let n=r.replace(/([A-Z])/g,"-$1").toLowerCase();t.push(`${n}:${e[r]}`)}return t.join(";")}return""}isState(e){return e&&"object"==typeof e&&"value"in e&&"subscribe"in e&&"function"==typeof e.subscribe}createReactiveChild(e,t){let r=t(e.value);if(typeof window<"u"&&typeof document<"u"){let r={node:null,renderFn:t};this.reactiveNodes.set(e,r),e.subscribe(()=>{if(r.node&&r.node.parentNode){let n=t(e.value);r.node.textContent=String(n??"")}})}return r}jsonToVNode(e){if(this.isState(e))return this.createReactiveChild(e,e=>e);if(null==e||"boolean"==typeof e||"string"==typeof e||"number"==typeof e)return e;let{tag:t,attributes:r={},children:n}=e,i={};for(let e in r){let t=r[e];"class"===e?i.className=this.isState(t)?t.value:t:i[e]=this.isState(t)?t.value:t}let l=[];if(null!=n)if(Array.isArray(n))for(let e of n)if(this.isState(e))l.push(this.createReactiveChild(e,e=>e));else{let t=this.jsonToVNode(e);null!=t&&!1!==t&&l.push(t)}else if(this.isState(n))l.push(this.createReactiveChild(n,e=>e));else if("object"==typeof n&&"tag"in n){let e=this.jsonToVNode(n);null!=e&&!1!==e&&l.push(e)}else l.push(n);return{tagName:t,props:i,children:l}}vNodeJsonToVNode(e){if(this.isState(e))return this.createReactiveChild(e,e=>e);if(null==e||"boolean"==typeof e||"string"==typeof e||"number"==typeof e)return e;let{tagName:t,props:r={},children:n=[]}=e,i={};for(let e in r){let t=r[e];i[e]=this.isState(t)?t.value:t}let l=[];for(let e of n)if(this.isState(e))l.push(this.createReactiveChild(e,e=>e));else{let t=this.vNodeJsonToVNode(e);null!=t&&!1!==t&&l.push(t)}return{tagName:t,props:i,children:l}}renderJson(e,t){let r=this.jsonToVNode(t);if(!r||"object"!=typeof r||!("tagName"in r))throw new Error("Invalid JSON structure");return this.render(e,r)}renderVNode(e,t){let r=this.vNodeJsonToVNode(t);if(!r||"object"!=typeof r||!("tagName"in r))throw new Error("Invalid VNode JSON structure");return this.render(e,r)}renderJsonToString(e,t={}){let r=this.jsonToVNode(e);return this.renderToString(r,t)}renderVNodeToString(e,t={}){let r=this.vNodeJsonToVNode(e);return this.renderToString(r,t)}renderServer(e){if("object"!=typeof e||null===e||!("tagName"in e))throw new Error("renderServer requires a VNode with html tag");if("html"!==e.tagName)throw new Error("renderServer requires a VNode with html tag as root");let t=e,r=null,n=null;for(let e of t.children||[])"object"==typeof e&&null!==e&&"tagName"in e&&("head"===e.tagName&&(r=e),"body"===e.tagName&&(n=e));if(t.props)for(let e in t.props){let r=t.props[e];null!=r&&!1!==r&&document.documentElement.setAttribute(e,String(r))}if(r){document.head.innerHTML="";for(let e of r.children||[])this.renderToDOM(e,document.head)}if(n){if(document.body.innerHTML="",n.props)for(let e in n.props){let t=n.props[e];null!=t&&!1!==t&&document.body.setAttribute(e,String(t))}for(let e of n.children||[])this.renderToDOM(e,document.body)}}renderToHTMLDocument(e,t={}){let{title:r="",meta:n=[],links:i=[],scripts:l=[],styles:o=[],lang:s="en",head:a="",bodyAttrs:d={},pretty:u=!1}=t,c=u?"\n":"",h=u?" ":"",p=u?" ":"",f=`<!DOCTYPE html>${c}<html lang="${s}">${c}${h}<head>${c}${p}<meta charset="UTF-8">${c}${p}<meta name="viewport" content="width=device-width, initial-scale=1.0">${c}`;r&&(f+=`${p}<title>${this.escapeHtml(r)}</title>${c}`);for(let e of n){f+=`${p}<meta`;for(let t in e)f+=` ${t}="${this.escapeHtml(e[t])}"`;f+=`>${c}`}for(let e of i){f+=`${p}<link`;for(let t in e)f+=` ${t}="${this.escapeHtml(e[t])}"`;f+=`>${c}`}for(let e of o)e.href?f+=`${p}<link rel="stylesheet" href="${this.escapeHtml(e.href)}">${c}`:e.content&&(f+=`${p}<style>${e.content}</style>${c}`);a&&(f+=a+c),f+=`${h}</head>${c}${h}<body`;for(let e in d)f+=` ${e}="${this.escapeHtml(d[e])}"`;f+=`>${c}`,f+=this.renderToString(e,{pretty:u,indent:2});for(let e of l)f+=`${p}<script`,e.type&&(f+=` type="${this.escapeHtml(e.type)}"`),e.async&&(f+=" async"),e.defer&&(f+=" defer"),e.src?f+=` src="${this.escapeHtml(e.src)}"><\/script>${c}`:e.content?f+=`>${e.content}<\/script>${c}`:f+=`><\/script>${c}`;return f+=`${h}</body>${c}</html>`,f}getElementCache(){return this.elementCache}},t=new e;exports.DomNode=e,exports.dom=t;
|
package/dist/dom.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e=class{constructor(){this.elementCache=new WeakMap,this.reactiveNodes=new Map}createElement(e,t={},r=[]){return{tagName:e,props:t,children:r}}renderToDOM(e,t){if(null==e||!1===e)return;if("object"!=typeof e)return void t.appendChild(document.createTextNode(String(e)));let{tagName:r,props:n,children:i}=e,l="svg"===r||"s"===r[0]&&"v"===r[1]&&"g"===r[2]||"http://www.w3.org/2000/svg"===t.namespaceURI,o=l?document.createElementNS("http://www.w3.org/2000/svg",r.replace("svg","").toLowerCase()||r):document.createElement(r);for(let e in n){let t=n[e];if(null==t||!1===t)continue;let r=e.charCodeAt(0);if(99===r&&(e.length<6||"N"===e[5])){let e=Array.isArray(t)?t.join(" "):t;l?o.setAttribute("class",e):o.className=e}else if(115===r&&5===e.length)if("string"==typeof t)o.style.cssText=t;else{let e=o.style;for(let r in t)e[r]=t[r]}else 111===r&&110===e.charCodeAt(1)?o[e.toLowerCase()]=t:100===r&&e.length>20?o.innerHTML=t.__html:114===r&&3===e.length?setTimeout(()=>{"function"==typeof t?t(o):t.current=o},0):o.setAttribute(e,!0===t?"":String(t))}let s=i.length;if(!s)return void t.appendChild(o);let a=e=>{for(let t=0;t<s;t++){let r=i[t];if(null!=r&&!1!==r)if(Array.isArray(r))for(let t=0,n=r.length;t<n;t++){let n=r[t];null!=n&&!1!==n&&this.renderToDOM(n,e)}else this.renderToDOM(r,e)}};if(s>30){let e=document.createDocumentFragment();a(e),o.appendChild(e)}else a(o);t.appendChild(o)}render(e,t){let r="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!r)throw new Error(`Element not found: ${e}`);if(t.children&&t.children.length>500){let e=document.createDocumentFragment();this.renderToDOM(t,e),r.appendChild(e)}else this.renderToDOM(t,r);return r}batchRender(e,t){let r="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!r)throw new Error(`Element not found: ${e}`);let n=t.length;if(n>3e3){let e=document.createDocumentFragment(),i=0,l=1500,o=()=>{let s=Math.min(i+l,n);for(let r=i;r<s;r++)this.renderToDOM(t[r],e);i=s,i>=n?r.appendChild(e):requestAnimationFrame(o)};o()}else{let e=document.createDocumentFragment();for(let r=0;r<n;r++)this.renderToDOM(t[r],e);r.appendChild(e)}return r}renderChunked(e,t,r=5e3,n){let i="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!i)throw new Error(`Element not found: ${e}`);let l=t.length,o=0,s=()=>{let e=Math.min(o+r,l),a=document.createDocumentFragment();for(let r=o;r<e;r++)this.renderToDOM(t[r],a);i.appendChild(a),o=e,n&&n(o,l),o<l&&requestAnimationFrame(s)};return requestAnimationFrame(s),i}renderToHead(...e){let t=document.head;if(t)for(let r of e.flat())r&&this.renderToDOM(r,t);return t}addStyle(e){let t=document.createElement("style");return t.textContent=e,document.head.appendChild(t)}addMeta(e){let t=document.createElement("meta");for(let r in e)t.setAttribute(r,e[r]);return document.head.appendChild(t)}addLink(e){let t=document.createElement("link");for(let r in e)t.setAttribute(r,e[r]);return document.head.appendChild(t)}setTitle(e){return document.title=e}createState(e,t={}){let r=e,n=new Set,i=null,{throttle:l=0,deep:o=!1}=t,s=()=>n.forEach(e=>e(r));return{get value(){return r},set value(e){(o?JSON.stringify(r)!==JSON.stringify(e):r!==e)&&(r=e,l>0?i||(i=setTimeout(()=>{i=null,s()},l)):s())},subscribe:e=>(n.add(e),()=>n.delete(e)),destroy(){n.clear(),i&&clearTimeout(i)}}}computed(e,t){let r=e.map(e=>e.value),n=this.createState(t(...r));return e.forEach((e,i)=>{e.subscribe(e=>{r[i]=e,n.value=t(...r)})}),n}effect(e){e()}createVirtualList(e,t,r,n=50,i=5){let l=e.clientHeight,o=t.length*n,s=0,a=()=>{let{start:a,end:d}={start:Math.max(0,Math.floor(s/n)-i),end:Math.min(t.length,Math.ceil((s+l)/n)+i)},u=document.createElement("div");u.style.cssText=`height:${o}px;position:relative`;for(let e=a;e<d;e++){let i=document.createElement("div");i.style.cssText=`position:absolute;top:${e*n}px;height:${n}px;width:100%`,this.renderToDOM(r(t[e],e),i),u.appendChild(i)}e.innerHTML="",e.appendChild(u)},d=()=>{s=e.scrollTop,requestAnimationFrame(a)};return e.addEventListener("scroll",d),a(),{render:a,destroy:()=>{e.removeEventListener("scroll",d),e.innerHTML=""}}}lazy(e){let t=null,r=!1;return async(...n)=>(!t&&!r&&(r=!0,t=await e(),r=!1),t?t(...n):{tagName:"div",props:{class:"loading"},children:["Loading..."]})}cleanupUnusedElements(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT),r=[];for(;t.nextNode();){let e=t.currentNode;e.id&&e.id.startsWith("r")&&!this.elementCache.has(e)&&r.push(e)}return r.forEach(e=>e.remove()),r.length}renderToString(e,t={}){let{pretty:r=!1,indent:n=0}=t,i=r?" ".repeat(n):"",l=r?"\n":"",o=this.resolveStateValue(e);if(o=this.unwrapReactive(o),Array.isArray(o))return o.map(e=>this.renderToString(e,t)).join("");if("object"!=typeof o||null===o)return null==o||!1===o?"":this.escapeHtml(String(o));let{tagName:s,props:a,children:d}=o,u=this.isSelfClosingTag(s),h=`${i}<${s}`,c=this.propsToAttributes(a);if(c&&(h+=` ${c}`),u)return h+=` />${l}`,h;if(h+=">",a.dangerouslySetInnerHTML)return h+=a.dangerouslySetInnerHTML.__html,h+=`</${s}>${l}`,h;if(d&&d.length>0){let e=d.map(e=>{let t=this.resolveStateValue(e);return this.unwrapReactive(t)}),t=e.some(e=>"object"==typeof e&&null!==e&&!Array.isArray(e)&&"tagName"in e);if(r&&t){h+=l;for(let t of e)if(null!=t&&!1!==t)if(Array.isArray(t))for(let e of t)null!=e&&!1!==e&&(h+=this.renderToString(e,{pretty:r,indent:n+1}));else h+=this.renderToString(t,{pretty:r,indent:n+1});h+=i}else for(let t of e)if(null!=t&&!1!==t)if(Array.isArray(t))for(let e of t)null!=e&&!1!==e&&(h+=this.renderToString(e,{pretty:!1,indent:0}));else h+=this.renderToString(t,{pretty:!1,indent:0})}return h+=`</${s}>${l}`,h}resolveStateValue(e){return e&&"object"==typeof e&&"value"in e&&"subscribe"in e?e.value:e}isReactiveWrapper(e){return!(!e||"object"!=typeof e||!e.tagName)&&("span"===e.tagName&&e.props?.id&&"string"==typeof e.props.id&&e.props.id.match(/^r[a-z0-9]{9}$/))}unwrapReactive(e){if(!this.isReactiveWrapper(e))return e;let t=e.children;if(!t||0===t.length)return"";if(1===t.length){let e=t[0];if(e&&"object"==typeof e&&"span"===e.tagName){let t=e.props,r=!t||0===Object.keys(t).length,n=e.children&&1===e.children.length&&"string"==typeof e.children[0];if(r&&n)return e.children[0]}return this.unwrapReactive(e)}return t.map(e=>this.unwrapReactive(e))}escapeHtml(e){let t={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,e=>t[e])}isSelfClosingTag(e){return new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]).has(e.toLowerCase())}propsToAttributes(e){let t=[];for(let r in e){if("children"===r||"dangerouslySetInnerHTML"===r||"ref"===r)continue;let n=e[r];if(n=this.resolveStateValue(n),null!=n&&!1!==n&&(!r.startsWith("on")||"function"!=typeof n)){if("className"===r||"class"===r){let e=Array.isArray(n)?n.join(" "):n;e&&t.push(`class="${this.escapeHtml(String(e))}"`);continue}if("style"===r){let e=this.styleToString(n);e&&t.push(`style="${this.escapeHtml(e)}"`);continue}if(!0===n){t.push(r);continue}t.push(`${r}="${this.escapeHtml(String(n))}"`)}}return t.join(" ")}styleToString(e){if("string"==typeof e)return e;if("object"==typeof e&&null!==e){let t=[];for(let r in e){let n=r.replace(/([A-Z])/g,"-$1").toLowerCase();t.push(`${n}:${e[r]}`)}return t.join(";")}return""}isState(e){return e&&"object"==typeof e&&"value"in e&&"subscribe"in e&&"function"==typeof e.subscribe}createReactiveChild(e,t){let r=t(e.value);if(typeof window<"u"&&typeof document<"u"){let r={node:null,renderFn:t};this.reactiveNodes.set(e,r),e.subscribe(()=>{if(r.node&&r.node.parentNode){let n=t(e.value);r.node.textContent=String(n??"")}})}return r}jsonToVNode(e){if(this.isState(e))return this.createReactiveChild(e,e=>e);if(null==e||"boolean"==typeof e||"string"==typeof e||"number"==typeof e)return e;let{tag:t,attributes:r={},children:n}=e,i={};for(let e in r){let t=r[e];"class"===e?i.className=this.isState(t)?t.value:t:i[e]=this.isState(t)?t.value:t}let l=[];if(null!=n)if(Array.isArray(n))for(let e of n)if(this.isState(e))l.push(this.createReactiveChild(e,e=>e));else{let t=this.jsonToVNode(e);null!=t&&!1!==t&&l.push(t)}else if(this.isState(n))l.push(this.createReactiveChild(n,e=>e));else if("object"==typeof n&&"tag"in n){let e=this.jsonToVNode(n);null!=e&&!1!==e&&l.push(e)}else l.push(n);return{tagName:t,props:i,children:l}}vNodeJsonToVNode(e){if(this.isState(e))return this.createReactiveChild(e,e=>e);if(null==e||"boolean"==typeof e||"string"==typeof e||"number"==typeof e)return e;let{tagName:t,props:r={},children:n=[]}=e,i={};for(let e in r){let t=r[e];i[e]=this.isState(t)?t.value:t}let l=[];for(let e of n)if(this.isState(e))l.push(this.createReactiveChild(e,e=>e));else{let t=this.vNodeJsonToVNode(e);null!=t&&!1!==t&&l.push(t)}return{tagName:t,props:i,children:l}}renderJson(e,t){let r=this.jsonToVNode(t);if(!r||"object"!=typeof r||!("tagName"in r))throw new Error("Invalid JSON structure");return this.render(e,r)}renderVNode(e,t){let r=this.vNodeJsonToVNode(t);if(!r||"object"!=typeof r||!("tagName"in r))throw new Error("Invalid VNode JSON structure");return this.render(e,r)}renderJsonToString(e,t={}){let r=this.jsonToVNode(e);return this.renderToString(r,t)}renderVNodeToString(e,t={}){let r=this.vNodeJsonToVNode(e);return this.renderToString(r,t)}renderServer(e){if("object"!=typeof e||null===e||!("tagName"in e))throw new Error("renderServer requires a VNode with html tag");if("html"!==e.tagName)throw new Error("renderServer requires a VNode with html tag as root");let t=e,r=null,n=null;for(let e of t.children||[])"object"==typeof e&&null!==e&&"tagName"in e&&("head"===e.tagName&&(r=e),"body"===e.tagName&&(n=e));if(t.props)for(let e in t.props){let r=t.props[e];null!=r&&!1!==r&&document.documentElement.setAttribute(e,String(r))}if(r){document.head.innerHTML="";for(let e of r.children||[])this.renderToDOM(e,document.head)}if(n){if(document.body.innerHTML="",n.props)for(let e in n.props){let t=n.props[e];null!=t&&!1!==t&&document.body.setAttribute(e,String(t))}for(let e of n.children||[])this.renderToDOM(e,document.body)}}renderToHTMLDocument(e,t={}){let{title:r="",meta:n=[],links:i=[],scripts:l=[],styles:o=[],lang:s="en",head:a="",bodyAttrs:d={},pretty:u=!1}=t,h=u?"\n":"",c=u?" ":"",p=u?" ":"",f=`<!DOCTYPE html>${h}<html lang="${s}">${h}${c}<head>${h}${p}<meta charset="UTF-8">${h}${p}<meta name="viewport" content="width=device-width, initial-scale=1.0">${h}`;r&&(f+=`${p}<title>${this.escapeHtml(r)}</title>${h}`);for(let e of n){f+=`${p}<meta`;for(let t in e)f+=` ${t}="${this.escapeHtml(e[t])}"`;f+=`>${h}`}for(let e of i){f+=`${p}<link`;for(let t in e)f+=` ${t}="${this.escapeHtml(e[t])}"`;f+=`>${h}`}for(let e of o)e.href?f+=`${p}<link rel="stylesheet" href="${this.escapeHtml(e.href)}">${h}`:e.content&&(f+=`${p}<style>${e.content}</style>${h}`);a&&(f+=a+h),f+=`${c}</head>${h}${c}<body`;for(let e in d)f+=` ${e}="${this.escapeHtml(d[e])}"`;f+=`>${h}`,f+=this.renderToString(e,{pretty:u,indent:2});for(let e of l)f+=`${p}<script`,e.type&&(f+=` type="${this.escapeHtml(e.type)}"`),e.async&&(f+=" async"),e.defer&&(f+=" defer"),e.src?f+=` src="${this.escapeHtml(e.src)}"><\/script>${h}`:e.content?f+=`>${e.content}<\/script>${h}`:f+=`><\/script>${h}`;return f+=`${c}</body>${h}</html>`,f}getElementCache(){return this.elementCache}},t=new e;export{e as DomNode,t as dom};
|