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.
Files changed (51) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +552 -19
  3. package/dist/build.d.mts +11 -0
  4. package/dist/build.d.ts +11 -0
  5. package/dist/build.js +1 -0
  6. package/dist/build.mjs +1 -0
  7. package/dist/cli.js +2307 -0
  8. package/dist/client.d.mts +9 -0
  9. package/dist/client.d.ts +9 -0
  10. package/dist/client.js +1 -0
  11. package/dist/client.mjs +1 -0
  12. package/dist/dom.d.mts +80 -0
  13. package/dist/dom.d.ts +80 -0
  14. package/dist/dom.js +1 -0
  15. package/dist/dom.mjs +1 -0
  16. package/dist/el.d.mts +227 -0
  17. package/dist/el.d.ts +227 -0
  18. package/dist/el.js +1 -0
  19. package/dist/el.mjs +1 -0
  20. package/dist/hmr.d.mts +38 -0
  21. package/dist/hmr.d.ts +38 -0
  22. package/dist/hmr.js +1 -0
  23. package/dist/hmr.mjs +1 -0
  24. package/dist/index.d.mts +38 -490
  25. package/dist/index.d.ts +38 -490
  26. package/dist/index.js +1 -2266
  27. package/dist/index.mjs +1 -2039
  28. package/dist/router.d.mts +45 -0
  29. package/dist/router.d.ts +45 -0
  30. package/dist/router.js +1 -0
  31. package/dist/router.mjs +1 -0
  32. package/dist/server.d.mts +3 -0
  33. package/dist/server.d.ts +3 -0
  34. package/dist/server.js +1 -0
  35. package/dist/server.mjs +1 -0
  36. package/dist/state.d.mts +109 -0
  37. package/dist/state.d.ts +109 -0
  38. package/dist/state.js +1 -0
  39. package/dist/state.mjs +1 -0
  40. package/dist/style.d.mts +113 -0
  41. package/dist/style.d.ts +113 -0
  42. package/dist/style.js +1 -0
  43. package/dist/style.mjs +1 -0
  44. package/dist/types-DOAdFFJB.d.mts +330 -0
  45. package/dist/types-DOAdFFJB.d.ts +330 -0
  46. package/dist/types.d.mts +3 -0
  47. package/dist/types.d.ts +3 -0
  48. package/dist/types.js +1 -0
  49. package/dist/types.mjs +0 -0
  50. package/package.json +77 -7
  51. package/dist/index.global.js +0 -2064
package/dist/state.mjs ADDED
@@ -0,0 +1 @@
1
+ var e=new 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:s}=e,i="svg"===r||"s"===r[0]&&"v"===r[1]&&"g"===r[2]||"http://www.w3.org/2000/svg"===t.namespaceURI,l=i?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;i?l.setAttribute("class",e):l.className=e}else if(115===r&&5===e.length)if("string"==typeof t)l.style.cssText=t;else{let e=l.style;for(let r in t)e[r]=t[r]}else 111===r&&110===e.charCodeAt(1)?l[e.toLowerCase()]=t:100===r&&e.length>20?l.innerHTML=t.__html:114===r&&3===e.length?setTimeout(()=>{"function"==typeof t?t(l):t.current=l},0):l.setAttribute(e,!0===t?"":String(t))}let a=s.length;if(!a)return void t.appendChild(l);let o=e=>{for(let t=0;t<a;t++){let r=s[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(a>30){let e=document.createDocumentFragment();o(e),l.appendChild(e)}else o(l);t.appendChild(l)}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(),s=0,i=1500,l=()=>{let a=Math.min(s+i,n);for(let r=s;r<a;r++)this.renderToDOM(t[r],e);s=a,s>=n?r.appendChild(e):requestAnimationFrame(l)};l()}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 s="string"==typeof e?document.getElementById(e.replace("#","")):e;if(!s)throw new Error(`Element not found: ${e}`);let i=t.length,l=0,a=()=>{let e=Math.min(l+r,i),o=document.createDocumentFragment();for(let r=l;r<e;r++)this.renderToDOM(t[r],o);s.appendChild(o),l=e,n&&n(l,i),l<i&&requestAnimationFrame(a)};return requestAnimationFrame(a),s}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,s=null,{throttle:i=0,deep:l=!1}=t,a=()=>n.forEach(e=>e(r));return{get value(){return r},set value(e){(l?JSON.stringify(r)!==JSON.stringify(e):r!==e)&&(r=e,i>0?s||(s=setTimeout(()=>{s=null,a()},i)):a())},subscribe:e=>(n.add(e),()=>n.delete(e)),destroy(){n.clear(),s&&clearTimeout(s)}}}computed(e,t){let r=e.map(e=>e.value),n=this.createState(t(...r));return e.forEach((e,s)=>{e.subscribe(e=>{r[s]=e,n.value=t(...r)})}),n}effect(e){e()}createVirtualList(e,t,r,n=50,s=5){let i=e.clientHeight,l=t.length*n,a=0,o=()=>{let{start:o,end:u}={start:Math.max(0,Math.floor(a/n)-s),end:Math.min(t.length,Math.ceil((a+i)/n)+s)},d=document.createElement("div");d.style.cssText=`height:${l}px;position:relative`;for(let e=o;e<u;e++){let s=document.createElement("div");s.style.cssText=`position:absolute;top:${e*n}px;height:${n}px;width:100%`,this.renderToDOM(r(t[e],e),s),d.appendChild(s)}e.innerHTML="",e.appendChild(d)},u=()=>{a=e.scrollTop,requestAnimationFrame(o)};return e.addEventListener("scroll",u),o(),{render:o,destroy:()=>{e.removeEventListener("scroll",u),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,s=r?" ".repeat(n):"",i=r?"\n":"",l=this.resolveStateValue(e);if(l=this.unwrapReactive(l),Array.isArray(l))return l.map(e=>this.renderToString(e,t)).join("");if("object"!=typeof l||null===l)return null==l||!1===l?"":this.escapeHtml(String(l));let{tagName:a,props:o,children:u}=l,d=this.isSelfClosingTag(a),c=`${s}<${a}`,h=this.propsToAttributes(o);if(h&&(c+=` ${h}`),d)return c+=` />${i}`,c;if(c+=">",o.dangerouslySetInnerHTML)return c+=o.dangerouslySetInnerHTML.__html,c+=`</${a}>${i}`,c;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(r&&t){c+=i;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+=s}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+=`</${a}>${i}`,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={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#x27;"};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,s={};for(let e in r){let t=r[e];"class"===e?s.className=this.isState(t)?t.value:t:s[e]=this.isState(t)?t.value:t}let i=[];if(null!=n)if(Array.isArray(n))for(let e of n)if(this.isState(e))i.push(this.createReactiveChild(e,e=>e));else{let t=this.jsonToVNode(e);null!=t&&!1!==t&&i.push(t)}else if(this.isState(n))i.push(this.createReactiveChild(n,e=>e));else if("object"==typeof n&&"tag"in n){let e=this.jsonToVNode(n);null!=e&&!1!==e&&i.push(e)}else i.push(n);return{tagName:t,props:s,children:i}}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,s={};for(let e in r){let t=r[e];s[e]=this.isState(t)?t.value:t}let i=[];for(let e of n)if(this.isState(e))i.push(this.createReactiveChild(e,e=>e));else{let t=this.vNodeJsonToVNode(e);null!=t&&!1!==t&&i.push(t)}return{tagName:t,props:s,children:i}}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:s=[],scripts:i=[],styles:l=[],lang:a="en",head:o="",bodyAttrs:u={},pretty:d=!1}=t,c=d?"\n":"",h=d?" ":"",p=d?" ":"",f=`<!DOCTYPE html>${c}<html lang="${a}">${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 s){f+=`${p}<link`;for(let t in e)f+=` ${t}="${this.escapeHtml(e[t])}"`;f+=`>${c}`}for(let e of l)e.href?f+=`${p}<link rel="stylesheet" href="${this.escapeHtml(e.href)}">${c}`:e.content&&(f+=`${p}<style>${e.content}</style>${c}`);o&&(f+=o+c),f+=`${h}</head>${c}${h}<body`;for(let e in u)f+=` ${e}="${this.escapeHtml(u[e])}"`;f+=`>${c}`,f+=this.renderToString(e,{pretty:d,indent:2});for(let e of i)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=(t,r)=>e.createState(t,r),r=(t,r)=>e.computed(t,r),n=t=>e.effect(t),s=(t,r)=>e.batchRender(t,r),i=(t,r,n,s)=>e.renderChunked(t,r,n,s),l=(t,r,n,s,i)=>e.createVirtualList(t,r,n,s,i),a=t=>e.lazy(t),o=t=>e.cleanupUnusedElements(t),u=(e,t)=>{let r=null;return(...n)=>{r||(r=setTimeout(()=>{r=null,e(...n)},t))}},d=(e,t)=>{let r=null;return(...n)=>{r&&clearTimeout(r),r=setTimeout(()=>e(...n),t)}},c=class{constructor(e,r,n){this.key=e,this.wsUrl=n,this.ws=null,this.pendingUpdates=[],this.localState=t(r),this.previousValue=r,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()}};function h(e,t,r){return new c(e,t,r)}var p=new class{constructor(){this.states=new Map}create(e,t,r){if(this.states.has(e))return this.states.get(e);let n=new c(e,t,r);return this.states.set(e,n),n}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=(t,r)=>{let n=null,s=null,i=null,l=!0,a=r(t.value),o=a&&"object"==typeof a&&"tagName"in a,u=null==a||!1===a;t.subscribe(()=>{n&&cancelAnimationFrame(n),n=requestAnimationFrame(()=>{(()=>{if(!s&&!i)return;let n=r(t.value);if(null==n||!1===n)l&&s&&(i=document.createComment("reactive"),s.parentNode?.replaceChild(i,s),l=!1);else if(!l&&i&&s&&(i.parentNode?.replaceChild(s,i),i=null,l=!0),s){let t=document.createDocumentFragment();if(o&&n&&"object"==typeof n&&"tagName"in n){let{props:r,children:i}=n;for(let e in r){let t=r[e];if("ref"!==e)if("class"===e||"className"===e)s.className=Array.isArray(t)?t.join(" "):t||"";else if("style"===e&&"object"==typeof t){let e=s.style;for(let r in t)e[r]=t[r]}else e.startsWith("on")?s[e.toLowerCase()]=t:null!=t&&!1!==t?s.setAttribute(e,String(!0===t?"":t)):s.removeAttribute(e)}for(let r of i)e.renderToDOM(r,t)}else e.renderToDOM(n,t);s.textContent="",s.appendChild(t),e.getElementCache().set(s,!0)}})(),n=null})});let d=e=>{s=e,u&&e.parentNode&&(i=document.createComment("reactive"),e.parentNode.replaceChild(i,e),l=!1)};if(o){let e=a;return{tagName:e.tagName,props:{...e.props,ref:d},children:e.children}}return{tagName:"span",props:{ref:d},children:[a]}},m=(t,r,n,s={})=>{let i=null,l=null;return r.subscribe(()=>{i&&cancelAnimationFrame(i),i=requestAnimationFrame(()=>{if(l){let t=document.createDocumentFragment(),s=n(r.value);null==s||!1===s?(l.style.display="none",l.textContent=""):(l.style.display="",e.renderToDOM(s,t),l.textContent="",l.appendChild(t)),e.getElementCache().set(l,!0)}i=null})}),{tagName:t,props:{...s,ref:e=>{l=e}},children:[n(r.value)]}},g=e=>e&&void 0!==e.value?f(e,e=>({tagName:"span",props:{},children:[String(e)]})):String(e),y=e=>({value:e.value,oninput:t=>{e.value=t.target.value}}),v=e=>({checked:e.value,onchange:t=>{e.value=t.target.checked}});export{c as SharedState,s as batchRender,v as bindChecked,y as bindValue,o as cleanupUnused,r as computed,h as createSharedState,t as createState,l as createVirtualList,d as debounce,n as effect,a as lazy,f as reactive,m as reactiveAs,i as renderChunked,p as sharedStateManager,g as text,u as throttle};
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Elit - CreateStyle CSS Generation System
3
+ */
4
+ interface CSSVariable {
5
+ name: string;
6
+ value: string;
7
+ toString(): string;
8
+ }
9
+ interface CSSRule {
10
+ selector: string;
11
+ styles: Record<string, string | number>;
12
+ nested?: CSSRule[];
13
+ type: 'tag' | 'class' | 'id' | 'pseudo-class' | 'pseudo-element' | 'name' | 'custom' | 'media' | 'attribute';
14
+ }
15
+ interface MediaRule {
16
+ type: string;
17
+ condition: string;
18
+ rules: CSSRule[];
19
+ }
20
+ interface KeyframeStep {
21
+ step: string | number;
22
+ styles: Record<string, string | number>;
23
+ }
24
+ interface Keyframes {
25
+ name: string;
26
+ steps: KeyframeStep[];
27
+ }
28
+ interface FontFace {
29
+ fontFamily: string;
30
+ src: string;
31
+ fontWeight?: string | number;
32
+ fontStyle?: string;
33
+ fontDisplay?: string;
34
+ unicodeRange?: string;
35
+ }
36
+ interface ContainerRule {
37
+ name?: string;
38
+ condition: string;
39
+ rules: CSSRule[];
40
+ }
41
+ interface SupportsRule {
42
+ condition: string;
43
+ rules: CSSRule[];
44
+ }
45
+ interface LayerRule {
46
+ name: string;
47
+ rules: CSSRule[];
48
+ }
49
+ declare class CreateStyle {
50
+ private variables;
51
+ private rules;
52
+ private mediaRules;
53
+ private keyframes;
54
+ private fontFaces;
55
+ private imports;
56
+ private containerRules;
57
+ private supportsRules;
58
+ private layerRules;
59
+ private _layerOrder;
60
+ addVar(name: string, value: string): CSSVariable;
61
+ var(variable: CSSVariable | string, fallback?: string): string;
62
+ addTag(tag: string, styles: Record<string, string | number>): CSSRule;
63
+ addClass(name: string, styles: Record<string, string | number>): CSSRule;
64
+ addId(name: string, styles: Record<string, string | number>): CSSRule;
65
+ addPseudoClass(pseudo: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
66
+ addPseudoElement(pseudo: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
67
+ addAttribute(attr: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
68
+ attrEquals(attr: string, value: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
69
+ attrContainsWord(attr: string, value: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
70
+ attrStartsWith(attr: string, value: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
71
+ attrEndsWith(attr: string, value: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
72
+ attrContains(attr: string, value: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
73
+ descendant(ancestor: string, descendant: string, styles: Record<string, string | number>): CSSRule;
74
+ child(parent: string, childSel: string, styles: Record<string, string | number>): CSSRule;
75
+ adjacentSibling(element: string, sibling: string, styles: Record<string, string | number>): CSSRule;
76
+ generalSibling(element: string, sibling: string, styles: Record<string, string | number>): CSSRule;
77
+ multiple(selectors: string[], styles: Record<string, string | number>): CSSRule;
78
+ addName(name: string, styles: Record<string, string | number>): CSSRule;
79
+ nesting(parentRule: CSSRule, ...childRules: CSSRule[]): CSSRule;
80
+ keyframe(name: string, steps: Record<string | number, Record<string, string | number>>): Keyframes;
81
+ keyframeFromTo(name: string, from: Record<string, string | number>, to: Record<string, string | number>): Keyframes;
82
+ fontFace(options: FontFace): FontFace;
83
+ import(url: string, mediaQuery?: string): string;
84
+ media(type: string, condition: string, rules: Record<string, Record<string, string | number>>): MediaRule;
85
+ mediaScreen(condition: string, rules: Record<string, Record<string, string | number>>): MediaRule;
86
+ mediaPrint(rules: Record<string, Record<string, string | number>>): MediaRule;
87
+ mediaMinWidth(minWidth: string, rules: Record<string, Record<string, string | number>>): MediaRule;
88
+ mediaMaxWidth(maxWidth: string, rules: Record<string, Record<string, string | number>>): MediaRule;
89
+ mediaDark(rules: Record<string, Record<string, string | number>>): MediaRule;
90
+ mediaLight(rules: Record<string, Record<string, string | number>>): MediaRule;
91
+ mediaReducedMotion(rules: Record<string, Record<string, string | number>>): MediaRule;
92
+ container(condition: string, rules: Record<string, Record<string, string | number>>, name?: string): ContainerRule;
93
+ addContainer(name: string, styles: Record<string, string | number>): CSSRule;
94
+ supports(condition: string, rules: Record<string, Record<string, string | number>>): SupportsRule;
95
+ layerOrder(...layers: string[]): void;
96
+ layer(name: string, rules: Record<string, Record<string, string | number>>): LayerRule;
97
+ add(rules: Record<string, Record<string, string | number>>): CSSRule[];
98
+ important(value: string | number): string;
99
+ private toKebabCase;
100
+ private stylesToString;
101
+ private renderRule;
102
+ private renderMediaRule;
103
+ private renderKeyframes;
104
+ private renderFontFace;
105
+ private renderContainerRule;
106
+ private renderSupportsRule;
107
+ private renderLayerRule;
108
+ render(...additionalRules: (CSSRule | CSSRule[] | MediaRule | Keyframes | ContainerRule | SupportsRule | LayerRule | undefined | null)[]): string;
109
+ inject(styleId?: string): HTMLStyleElement;
110
+ clear(): void;
111
+ }
112
+
113
+ export { type CSSRule, type CSSVariable, type ContainerRule, CreateStyle, type FontFace, type KeyframeStep, type Keyframes, type LayerRule, type MediaRule, type SupportsRule };
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Elit - CreateStyle CSS Generation System
3
+ */
4
+ interface CSSVariable {
5
+ name: string;
6
+ value: string;
7
+ toString(): string;
8
+ }
9
+ interface CSSRule {
10
+ selector: string;
11
+ styles: Record<string, string | number>;
12
+ nested?: CSSRule[];
13
+ type: 'tag' | 'class' | 'id' | 'pseudo-class' | 'pseudo-element' | 'name' | 'custom' | 'media' | 'attribute';
14
+ }
15
+ interface MediaRule {
16
+ type: string;
17
+ condition: string;
18
+ rules: CSSRule[];
19
+ }
20
+ interface KeyframeStep {
21
+ step: string | number;
22
+ styles: Record<string, string | number>;
23
+ }
24
+ interface Keyframes {
25
+ name: string;
26
+ steps: KeyframeStep[];
27
+ }
28
+ interface FontFace {
29
+ fontFamily: string;
30
+ src: string;
31
+ fontWeight?: string | number;
32
+ fontStyle?: string;
33
+ fontDisplay?: string;
34
+ unicodeRange?: string;
35
+ }
36
+ interface ContainerRule {
37
+ name?: string;
38
+ condition: string;
39
+ rules: CSSRule[];
40
+ }
41
+ interface SupportsRule {
42
+ condition: string;
43
+ rules: CSSRule[];
44
+ }
45
+ interface LayerRule {
46
+ name: string;
47
+ rules: CSSRule[];
48
+ }
49
+ declare class CreateStyle {
50
+ private variables;
51
+ private rules;
52
+ private mediaRules;
53
+ private keyframes;
54
+ private fontFaces;
55
+ private imports;
56
+ private containerRules;
57
+ private supportsRules;
58
+ private layerRules;
59
+ private _layerOrder;
60
+ addVar(name: string, value: string): CSSVariable;
61
+ var(variable: CSSVariable | string, fallback?: string): string;
62
+ addTag(tag: string, styles: Record<string, string | number>): CSSRule;
63
+ addClass(name: string, styles: Record<string, string | number>): CSSRule;
64
+ addId(name: string, styles: Record<string, string | number>): CSSRule;
65
+ addPseudoClass(pseudo: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
66
+ addPseudoElement(pseudo: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
67
+ addAttribute(attr: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
68
+ attrEquals(attr: string, value: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
69
+ attrContainsWord(attr: string, value: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
70
+ attrStartsWith(attr: string, value: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
71
+ attrEndsWith(attr: string, value: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
72
+ attrContains(attr: string, value: string, styles: Record<string, string | number>, baseSelector?: string): CSSRule;
73
+ descendant(ancestor: string, descendant: string, styles: Record<string, string | number>): CSSRule;
74
+ child(parent: string, childSel: string, styles: Record<string, string | number>): CSSRule;
75
+ adjacentSibling(element: string, sibling: string, styles: Record<string, string | number>): CSSRule;
76
+ generalSibling(element: string, sibling: string, styles: Record<string, string | number>): CSSRule;
77
+ multiple(selectors: string[], styles: Record<string, string | number>): CSSRule;
78
+ addName(name: string, styles: Record<string, string | number>): CSSRule;
79
+ nesting(parentRule: CSSRule, ...childRules: CSSRule[]): CSSRule;
80
+ keyframe(name: string, steps: Record<string | number, Record<string, string | number>>): Keyframes;
81
+ keyframeFromTo(name: string, from: Record<string, string | number>, to: Record<string, string | number>): Keyframes;
82
+ fontFace(options: FontFace): FontFace;
83
+ import(url: string, mediaQuery?: string): string;
84
+ media(type: string, condition: string, rules: Record<string, Record<string, string | number>>): MediaRule;
85
+ mediaScreen(condition: string, rules: Record<string, Record<string, string | number>>): MediaRule;
86
+ mediaPrint(rules: Record<string, Record<string, string | number>>): MediaRule;
87
+ mediaMinWidth(minWidth: string, rules: Record<string, Record<string, string | number>>): MediaRule;
88
+ mediaMaxWidth(maxWidth: string, rules: Record<string, Record<string, string | number>>): MediaRule;
89
+ mediaDark(rules: Record<string, Record<string, string | number>>): MediaRule;
90
+ mediaLight(rules: Record<string, Record<string, string | number>>): MediaRule;
91
+ mediaReducedMotion(rules: Record<string, Record<string, string | number>>): MediaRule;
92
+ container(condition: string, rules: Record<string, Record<string, string | number>>, name?: string): ContainerRule;
93
+ addContainer(name: string, styles: Record<string, string | number>): CSSRule;
94
+ supports(condition: string, rules: Record<string, Record<string, string | number>>): SupportsRule;
95
+ layerOrder(...layers: string[]): void;
96
+ layer(name: string, rules: Record<string, Record<string, string | number>>): LayerRule;
97
+ add(rules: Record<string, Record<string, string | number>>): CSSRule[];
98
+ important(value: string | number): string;
99
+ private toKebabCase;
100
+ private stylesToString;
101
+ private renderRule;
102
+ private renderMediaRule;
103
+ private renderKeyframes;
104
+ private renderFontFace;
105
+ private renderContainerRule;
106
+ private renderSupportsRule;
107
+ private renderLayerRule;
108
+ render(...additionalRules: (CSSRule | CSSRule[] | MediaRule | Keyframes | ContainerRule | SupportsRule | LayerRule | undefined | null)[]): string;
109
+ inject(styleId?: string): HTMLStyleElement;
110
+ clear(): void;
111
+ }
112
+
113
+ export { type CSSRule, type CSSVariable, type ContainerRule, CreateStyle, type FontFace, type KeyframeStep, type Keyframes, type LayerRule, type MediaRule, type SupportsRule };
package/dist/style.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";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 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}`,n={selector:s?`${s}${r}`:r,styles:t,type:"pseudo-class"};return this.rules.push(n),n}addPseudoElement(e,t,s){let r=e.startsWith("::")?e:`::${e}`,n={selector:s?`${s}${r}`:r,styles:t,type:"pseudo-element"};return this.rules.push(n),n}addAttribute(e,t,s){let r=e.startsWith("[")?e:`[${e}]`,n={selector:s?`${s}${r}`:r,styles:t,type:"attribute"};return this.rules.push(n),n}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],n=[],i=[...this.containerRules],l=[...this.supportsRules],u=[...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?n.push(t):"name"in t&&"rules"in t?u.push(t):s.push(t):"type"in t?r.push(t):"name"in t&&"string"==typeof t.name?i.push(t):l.push(t));for(let e of n)t.push(this.renderKeyframes(e));for(let e of u)t.push(this.renderLayerRule(e));for(let e of s)t.push(this.renderRule(e));for(let e of l)t.push(this.renderSupportsRule(e));for(let e of i)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=[]}};
package/dist/style.mjs ADDED
@@ -0,0 +1 @@
1
+ var e=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}`,n={selector:s?`${s}${r}`:r,styles:t,type:"pseudo-class"};return this.rules.push(n),n}addPseudoElement(e,t,s){let r=e.startsWith("::")?e:`::${e}`,n={selector:s?`${s}${r}`:r,styles:t,type:"pseudo-element"};return this.rules.push(n),n}addAttribute(e,t,s){let r=e.startsWith("[")?e:`[${e}]`,n={selector:s?`${s}${r}`:r,styles:t,type:"attribute"};return this.rules.push(n),n}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],n=[],i=[...this.containerRules],l=[...this.supportsRules],u=[...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?n.push(t):"name"in t&&"rules"in t?u.push(t):s.push(t):"type"in t?r.push(t):"name"in t&&"string"==typeof t.name?i.push(t):l.push(t));for(let e of n)t.push(this.renderKeyframes(e));for(let e of u)t.push(this.renderLayerRule(e));for(let e of s)t.push(this.renderRule(e));for(let e of l)t.push(this.renderSupportsRule(e));for(let e of i)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=[]}};export{e as CreateStyle};
@@ -0,0 +1,330 @@
1
+ import { IncomingMessage, ServerResponse, Server } from 'http';
2
+ import { WebSocket, WebSocketServer } from 'ws';
3
+
4
+ /**
5
+ * Development server with HMR support
6
+ */
7
+
8
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'HEAD';
9
+ interface ServerRouteContext {
10
+ req: IncomingMessage;
11
+ res: ServerResponse;
12
+ params: Record<string, string>;
13
+ query: Record<string, string>;
14
+ body: any;
15
+ headers: Record<string, string | string[] | undefined>;
16
+ }
17
+ type ServerRouteHandler = (ctx: ServerRouteContext) => void | Promise<void>;
18
+ type Middleware = (ctx: ServerRouteContext, next: () => Promise<void>) => void | Promise<void>;
19
+ declare class ServerRouter {
20
+ private routes;
21
+ private middlewares;
22
+ use(middleware: Middleware): this;
23
+ get(path: string, handler: ServerRouteHandler): this;
24
+ post(path: string, handler: ServerRouteHandler): this;
25
+ put(path: string, handler: ServerRouteHandler): this;
26
+ delete(path: string, handler: ServerRouteHandler): this;
27
+ patch(path: string, handler: ServerRouteHandler): this;
28
+ options(path: string, handler: ServerRouteHandler): this;
29
+ private addRoute;
30
+ private pathToRegex;
31
+ private parseQuery;
32
+ private parseBody;
33
+ handle(req: IncomingMessage, res: ServerResponse): Promise<boolean>;
34
+ }
35
+ declare const json: (res: ServerResponse, data: any, status?: number) => void;
36
+ declare const text: (res: ServerResponse, data: string, status?: number) => void;
37
+ declare const html: (res: ServerResponse, data: string, status?: number) => void;
38
+ declare const status: (res: ServerResponse, code: number, message?: string) => void;
39
+ declare function cors(options?: {
40
+ origin?: string | string[];
41
+ methods?: string[];
42
+ credentials?: boolean;
43
+ maxAge?: number;
44
+ }): Middleware;
45
+ declare function logger(options?: {
46
+ format?: 'simple' | 'detailed';
47
+ }): Middleware;
48
+ declare function errorHandler(): Middleware;
49
+ declare function rateLimit(options?: {
50
+ windowMs?: number;
51
+ max?: number;
52
+ message?: string;
53
+ }): Middleware;
54
+ declare function bodyLimit(options?: {
55
+ limit?: number;
56
+ }): Middleware;
57
+ declare function cacheControl(options?: {
58
+ maxAge?: number;
59
+ public?: boolean;
60
+ }): Middleware;
61
+ declare function compress(): Middleware;
62
+ declare function security(): Middleware;
63
+ declare function createProxyHandler(proxyConfigs: ProxyConfig[]): (req: IncomingMessage, res: ServerResponse) => Promise<boolean>;
64
+ type StateChangeHandler<T = any> = (value: T, oldValue: T) => void;
65
+ interface SharedStateOptions<T = any> {
66
+ initial: T;
67
+ persist?: boolean;
68
+ validate?: (value: T) => boolean;
69
+ }
70
+ declare class SharedState<T = any> {
71
+ readonly key: string;
72
+ private _value;
73
+ private listeners;
74
+ private changeHandlers;
75
+ private options;
76
+ constructor(key: string, options: SharedStateOptions<T>);
77
+ get value(): T;
78
+ set value(newValue: T);
79
+ update(updater: (current: T) => T): void;
80
+ subscribe(ws: WebSocket): void;
81
+ unsubscribe(ws: WebSocket): void;
82
+ onChange(handler: StateChangeHandler<T>): () => void;
83
+ private broadcast;
84
+ private sendTo;
85
+ get subscriberCount(): number;
86
+ clear(): void;
87
+ }
88
+ declare class StateManager$1 {
89
+ private states;
90
+ create<T>(key: string, options: SharedStateOptions<T>): SharedState<T>;
91
+ get<T>(key: string): SharedState<T> | undefined;
92
+ has(key: string): boolean;
93
+ delete(key: string): boolean;
94
+ subscribe(key: string, ws: WebSocket): void;
95
+ unsubscribe(key: string, ws: WebSocket): void;
96
+ unsubscribeAll(ws: WebSocket): void;
97
+ handleStateChange(key: string, value: any): void;
98
+ keys(): string[];
99
+ clear(): void;
100
+ }
101
+ declare function createDevServer(options: DevServerOptions): DevServer;
102
+
103
+ /**
104
+ * Elit - Types and Interfaces
105
+ */
106
+ interface VNode {
107
+ tagName: string;
108
+ props: Props;
109
+ children: Children;
110
+ }
111
+ type Child = VNode | string | number | boolean | null | undefined;
112
+ type Children = Child[];
113
+ interface Props {
114
+ [key: string]: any;
115
+ className?: string | string[];
116
+ class?: string | string[];
117
+ style?: Partial<CSSStyleDeclaration> | string;
118
+ dangerouslySetInnerHTML?: {
119
+ __html: string;
120
+ };
121
+ ref?: RefCallback | RefObject;
122
+ onClick?: (event: MouseEvent) => void;
123
+ onChange?: (event: Event) => void;
124
+ onInput?: (event: Event) => void;
125
+ onSubmit?: (event: Event) => void;
126
+ value?: string | number;
127
+ checked?: boolean;
128
+ }
129
+ type RefCallback = (element: HTMLElement | SVGElement) => void;
130
+ interface RefObject {
131
+ current: HTMLElement | SVGElement | null;
132
+ }
133
+ interface State<T> {
134
+ value: T;
135
+ subscribe(fn: (value: T) => void): () => void;
136
+ destroy(): void;
137
+ }
138
+ interface StateOptions {
139
+ throttle?: number;
140
+ deep?: boolean;
141
+ }
142
+ interface VirtualListController {
143
+ render: () => void;
144
+ destroy: () => void;
145
+ }
146
+ interface JsonNode {
147
+ tag: string;
148
+ attributes?: Record<string, any>;
149
+ children?: JsonNode | JsonNode[] | string | number | boolean | null;
150
+ }
151
+ type VNodeJson = {
152
+ tagName: string;
153
+ props?: Record<string, any>;
154
+ children?: (VNodeJson | string | number | boolean | null)[];
155
+ } | string | number | boolean | null;
156
+ type ElementFactory = {
157
+ (...children: Child[]): VNode;
158
+ (props: Props | null, ...children: Child[]): VNode;
159
+ };
160
+
161
+ type Router = ServerRouter;
162
+ type StateManager = StateManager$1;
163
+ interface ClientConfig {
164
+ /** Root directory to serve files from */
165
+ root: string;
166
+ /** Base path for the client application (e.g., '/app1', '/app2') */
167
+ basePath: string;
168
+ /** SSR render function - returns HTML VNode or string */
169
+ ssr?: () => Child | string;
170
+ /** Watch patterns for file changes */
171
+ watch?: string[];
172
+ /** Ignore patterns for file watching */
173
+ ignore?: string[];
174
+ /** Proxy configuration specific to this client */
175
+ proxy?: ProxyConfig[];
176
+ /** Worker scripts specific to this client */
177
+ worker?: WorkerConfig[];
178
+ /** API router for REST endpoints specific to this client */
179
+ api?: Router;
180
+ /** Custom middleware specific to this client */
181
+ middleware?: ((req: any, res: any, next: () => void) => void)[];
182
+ }
183
+ interface ProxyConfig {
184
+ /** Path prefix to match for proxying (e.g., '/api', '/graphql') */
185
+ context: string;
186
+ /** Target URL to proxy to (e.g., 'http://localhost:8080') */
187
+ target: string;
188
+ /** Change the origin of the host header to the target URL */
189
+ changeOrigin?: boolean;
190
+ /** Rewrite path before sending to target */
191
+ pathRewrite?: Record<string, string>;
192
+ /** Additional headers to add to the proxied request */
193
+ headers?: Record<string, string>;
194
+ /** Enable WebSocket proxying */
195
+ ws?: boolean;
196
+ }
197
+ interface WorkerConfig {
198
+ /** Worker script path relative to root directory */
199
+ path: string;
200
+ /** Worker name/identifier (optional, defaults to filename) */
201
+ name?: string;
202
+ /** Worker type: 'module' (ESM) or 'classic' (default: 'module') */
203
+ type?: 'module' | 'classic';
204
+ }
205
+ interface DevServerOptions {
206
+ /** Port to run the server on (default: 3000) */
207
+ port?: number;
208
+ /** Host to bind to (default: 'localhost') */
209
+ host?: string;
210
+ /** Root directory to serve files from */
211
+ root?: string;
212
+ /** Base path for the client application (e.g., '/app1', '/app2') */
213
+ basePath?: string;
214
+ /** Array of client configurations - allows multiple clients on same port */
215
+ clients?: ClientConfig[];
216
+ /** Enable HTTPS (default: false) */
217
+ https?: boolean;
218
+ /** Open browser automatically (default: true) */
219
+ open?: boolean;
220
+ /** Watch patterns for file changes */
221
+ watch?: string[];
222
+ /** Ignore patterns for file watcher */
223
+ ignore?: string[];
224
+ /** Global worker scripts (applies to all clients) */
225
+ worker?: WorkerConfig[];
226
+ /** Enable logging (default: true) */
227
+ logging?: boolean;
228
+ /** Custom middleware */
229
+ middleware?: ((req: any, res: any, next: () => void) => void)[];
230
+ /** API router for REST endpoints */
231
+ api?: Router;
232
+ /** SSR render function - returns HTML VNode or string */
233
+ ssr?: () => Child | string;
234
+ /** Proxy configuration for API requests */
235
+ proxy?: ProxyConfig[];
236
+ }
237
+ interface DevServer {
238
+ /** HTTP server instance */
239
+ server: Server;
240
+ /** WebSocket server for HMR */
241
+ wss: WebSocketServer;
242
+ /** Server URL */
243
+ url: string;
244
+ /** Shared state manager */
245
+ state: StateManager;
246
+ /** Close the server */
247
+ close: () => Promise<void>;
248
+ }
249
+ interface HMRMessage {
250
+ type: 'update' | 'reload' | 'error' | 'connected';
251
+ path?: string;
252
+ timestamp?: number;
253
+ error?: string;
254
+ }
255
+ interface BuildOptions {
256
+ /** Entry file to build */
257
+ entry: string;
258
+ /** Output directory */
259
+ outDir?: string;
260
+ /** Output filename */
261
+ outFile?: string;
262
+ /** Enable minification */
263
+ minify?: boolean;
264
+ /** Generate sourcemap */
265
+ sourcemap?: boolean;
266
+ /** Target environment */
267
+ target?: 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'esnext';
268
+ /** Output format */
269
+ format?: 'esm' | 'cjs' | 'iife';
270
+ /** Global name for IIFE format */
271
+ globalName?: string;
272
+ /** Target platform */
273
+ platform?: 'browser' | 'node' | 'neutral';
274
+ /** Base path for the application (injected into HTML) */
275
+ basePath?: string;
276
+ /** External dependencies (not bundled) */
277
+ external?: string[];
278
+ /** Enable tree shaking */
279
+ treeshake?: boolean;
280
+ /** Enable logging */
281
+ logging?: boolean;
282
+ /** Environment variables to inject (prefix with VITE_ for client access) */
283
+ env?: Record<string, string>;
284
+ /** Copy static files after build */
285
+ copy?: Array<{
286
+ from: string;
287
+ to: string;
288
+ transform?: (content: string, config: BuildOptions) => string;
289
+ }>;
290
+ /** Post-build hook */
291
+ onBuildEnd?: (result: BuildResult) => void | Promise<void>;
292
+ }
293
+ interface BuildResult {
294
+ /** Output file path */
295
+ outputPath: string;
296
+ /** Build time in milliseconds */
297
+ buildTime: number;
298
+ /** Output file size in bytes */
299
+ size: number;
300
+ }
301
+ interface PreviewOptions {
302
+ /** Port to run the preview server on (default: 4173) */
303
+ port?: number;
304
+ /** Host to bind to (default: 'localhost') */
305
+ host?: string;
306
+ /** Root directory to serve files from (default: dist or build.outDir) */
307
+ root?: string;
308
+ /** Base path for the application (e.g., '/app') */
309
+ basePath?: string;
310
+ /** Array of client configurations - allows multiple clients on same port */
311
+ clients?: ClientConfig[];
312
+ /** Enable HTTPS (default: false) */
313
+ https?: boolean;
314
+ /** Open browser automatically (default: true) */
315
+ open?: boolean;
316
+ /** Enable logging (default: true) */
317
+ logging?: boolean;
318
+ /** Custom middleware */
319
+ middleware?: ((req: any, res: any, next: () => void) => void)[];
320
+ /** API router for REST endpoints */
321
+ api?: Router;
322
+ /** SSR render function - returns HTML VNode or string */
323
+ ssr?: () => Child | string;
324
+ /** Proxy configuration for API requests */
325
+ proxy?: ProxyConfig[];
326
+ /** Global worker scripts (applies to all clients) */
327
+ worker?: WorkerConfig[];
328
+ }
329
+
330
+ export { type ClientConfig as A, type BuildOptions as B, type Child as C, type DevServerOptions as D, type ElementFactory as E, type ProxyConfig as F, type DevServer as G, type HttpMethod as H, type HMRMessage as I, type JsonNode as J, type PreviewOptions as K, createProxyHandler as L, type Middleware as M, type Router as N, type StateManager as O, type Props as P, type RefCallback as R, ServerRouter as S, type VNode as V, type WorkerConfig as W, type ServerRouteContext as a, type ServerRouteHandler as b, createDevServer as c, cors as d, errorHandler as e, bodyLimit as f, cacheControl as g, html as h, compress as i, json as j, security as k, logger as l, StateManager$1 as m, SharedState as n, type SharedStateOptions as o, type StateChangeHandler as p, type BuildResult as q, rateLimit as r, status as s, text as t, type Children as u, type RefObject as v, type State as w, type StateOptions as x, type VirtualListController as y, type VNodeJson as z };