@remyyy/velox 0.0.1

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.
@@ -0,0 +1 @@
1
+ "use strict";let u=null,m=0;const y=new Set;function T(e){m++;try{return e()}finally{if(m--,m===0){const t=[...y];y.clear(),t.forEach(n=>n.execute())}}}function A(e){let t=e;const n=new Set;return[()=>(u&&(n.add(u),u.dependencies.add(n)),t),a=>{const s=typeof a=="function"?a(t):a;t!==s&&(t=s,[...n].forEach(c=>{m>0?y.add(c):c.execute()}))}]}function j(e){u&&u.cleanups.push(e)}function C(e){const t={execute(){b(t);const n=u;u=t;try{e()}finally{u=n}},dependencies:new Set,cleanups:[]};return t.execute(),()=>b(t)}function B(e){const[t,n]=A(void 0);return C(()=>n(e())),t}function b(e){e.dependencies.forEach(t=>t.delete(e)),e.dependencies.clear(),e.cleanups.forEach(t=>t()),e.cleanups=[]}let l=[{hydrationPath:"0",routerBase:"",custom:new Map}];function N(e){const t=l[l.length-1];l.push({...t,...e})}function g(){l.pop()}function E(){return l[l.length-1]}function P(e=!1){l=[{hydrationPath:"0",routerBase:"",custom:e&&l.length>0?l[0].custom:new Map}]}let L=!1;function D(e){L=e}const p=Symbol("velox_cleanup");function S(e,t){const n=e;n[p]||(n[p]=[]),n[p].push(t)}function v(e){const t=e;t[p]&&(t[p].forEach(n=>n()),t[p]=void 0),e.hasChildNodes()&&e.childNodes.forEach(n=>v(n))}function I(e,t,...n){const i=t||{};let d=n.flat().filter(a=>a!=null&&a!==!0&&a!==!1);return d.length===0&&i.children&&(d=Array.isArray(i.children)?i.children.flat():[i.children]),{exec:()=>{if(typeof e=="function")return e({...i,children:d}).exec();const s=E().hydrationPath;let c=null;if(L){const o=document.querySelector(`[data-hid="${s}"]`);o&&o.tagName.toLowerCase()===e.toLowerCase()&&(c=o,c.removeAttribute("data-hid"))}c||(c=document.createElement(e));for(const[o,h]of Object.entries(i))if(o!=="children")if(o.startsWith("on")&&typeof h=="function"){const x=o.toLowerCase().substring(2);c.addEventListener(x,f=>{T(()=>h(f))})}else if(typeof h=="function"){const x=C(()=>{const f=h();w(c,o,f)});S(c,x)}else w(c,o,h);let r=c.firstChild;for(d.forEach((o,h)=>{const x=`${s}.${h}`;N({hydrationPath:x});let f=null;o&&typeof o=="object"&&"exec"in o?f=o.exec():typeof o=="function"?f=$(o,r):f=M(String(o),r),f&&(r===f?r=r.nextSibling:(f.parentNode,c.insertBefore(f,r))),g()});r;){const o=r.nextSibling;r.parentNode===c&&(v(r),c.removeChild(r)),r=o}return c}}}function $(e,t){let n;t&&t.nodeType===Node.TEXT_NODE?n=t:n=document.createTextNode("");const i=C(()=>{const d=e(),a=String(d??"");n.data!==a&&(n.data=a)});return S(n,i),n}function M(e,t){if(t&&t.nodeType===Node.TEXT_NODE){const n=t;return n.data!==e&&(n.data=e),n}return document.createTextNode(e)}function w(e,t,n){n==null?e.removeAttribute(t):t==="className"||t==="class"?e.className=n:t==="style"&&typeof n=="object"?Object.assign(e.style,n):e.setAttribute(t,String(n))}function O(e,t){P(),t.textContent="";const i=e({}).exec();t.appendChild(i)}const _=e=>({exec:()=>{const n=E().hydrationPath,i=document.createDocumentFragment(),d=e.children||[];return(Array.isArray(d)?d.flat():[d]).forEach((s,c)=>{const r=`${n}.${c}`;N({hydrationPath:r});let o=null;s&&s.exec?o=s.exec():typeof s=="function"?o=$(s,null):o=document.createTextNode(String(s)),o&&i.appendChild(o),g()}),i}});exports.Fragment=_;exports.addNodeCleanup=S;exports.batch=T;exports.createEffect=C;exports.createMemo=B;exports.createSignal=A;exports.dispose=v;exports.getContext=E;exports.h=I;exports.mount=O;exports.onCleanup=j;exports.popContext=g;exports.pushContext=N;exports.resetContext=P;exports.setHydrating=D;
@@ -0,0 +1,180 @@
1
+ let u = null, m = 0;
2
+ const y = /* @__PURE__ */ new Set();
3
+ function P(e) {
4
+ m++;
5
+ try {
6
+ return e();
7
+ } finally {
8
+ if (m--, m === 0) {
9
+ const t = [...y];
10
+ y.clear(), t.forEach((n) => n.execute());
11
+ }
12
+ }
13
+ }
14
+ function L(e) {
15
+ let t = e;
16
+ const n = /* @__PURE__ */ new Set();
17
+ return [() => (u && (n.add(u), u.dependencies.add(n)), t), (i) => {
18
+ const r = typeof i == "function" ? i(t) : i;
19
+ t !== r && (t = r, [...n].forEach((c) => {
20
+ m > 0 ? y.add(c) : c.execute();
21
+ }));
22
+ }];
23
+ }
24
+ function B(e) {
25
+ u && u.cleanups.push(e);
26
+ }
27
+ function C(e) {
28
+ const t = {
29
+ execute() {
30
+ N(t);
31
+ const n = u;
32
+ u = t;
33
+ try {
34
+ e();
35
+ } finally {
36
+ u = n;
37
+ }
38
+ },
39
+ dependencies: /* @__PURE__ */ new Set(),
40
+ cleanups: []
41
+ };
42
+ return t.execute(), () => N(t);
43
+ }
44
+ function D(e) {
45
+ const [t, n] = L(void 0);
46
+ return C(() => n(e())), t;
47
+ }
48
+ function N(e) {
49
+ e.dependencies.forEach((t) => t.delete(e)), e.dependencies.clear(), e.cleanups.forEach((t) => t()), e.cleanups = [];
50
+ }
51
+ let l = [{
52
+ hydrationPath: "0",
53
+ routerBase: "",
54
+ custom: /* @__PURE__ */ new Map()
55
+ }];
56
+ function E(e) {
57
+ const t = l[l.length - 1];
58
+ l.push({ ...t, ...e });
59
+ }
60
+ function S() {
61
+ l.pop();
62
+ }
63
+ function v() {
64
+ return l[l.length - 1];
65
+ }
66
+ function $(e = !1) {
67
+ l = [{
68
+ hydrationPath: "0",
69
+ routerBase: "",
70
+ custom: e && l.length > 0 ? l[0].custom : /* @__PURE__ */ new Map()
71
+ }];
72
+ }
73
+ let b = !1;
74
+ function I(e) {
75
+ b = e;
76
+ }
77
+ const p = Symbol("velox_cleanup");
78
+ function w(e, t) {
79
+ const n = e;
80
+ n[p] || (n[p] = []), n[p].push(t);
81
+ }
82
+ function T(e) {
83
+ const t = e;
84
+ t[p] && (t[p].forEach((n) => n()), t[p] = void 0), e.hasChildNodes() && e.childNodes.forEach((n) => T(n));
85
+ }
86
+ function O(e, t, ...n) {
87
+ const a = t || {};
88
+ let d = n.flat().filter((i) => i != null && i !== !0 && i !== !1);
89
+ return d.length === 0 && a.children && (d = Array.isArray(a.children) ? a.children.flat() : [a.children]), {
90
+ exec: () => {
91
+ if (typeof e == "function")
92
+ return e({ ...a, children: d }).exec();
93
+ const r = v().hydrationPath;
94
+ let c = null;
95
+ if (b) {
96
+ const o = document.querySelector(`[data-hid="${r}"]`);
97
+ o && o.tagName.toLowerCase() === e.toLowerCase() && (c = o, c.removeAttribute("data-hid"));
98
+ }
99
+ c || (c = document.createElement(e));
100
+ for (const [o, h] of Object.entries(a))
101
+ if (o !== "children")
102
+ if (o.startsWith("on") && typeof h == "function") {
103
+ const x = o.toLowerCase().substring(2);
104
+ c.addEventListener(x, (f) => {
105
+ P(() => h(f));
106
+ });
107
+ } else if (typeof h == "function") {
108
+ const x = C(() => {
109
+ const f = h();
110
+ g(c, o, f);
111
+ });
112
+ w(c, x);
113
+ } else
114
+ g(c, o, h);
115
+ let s = c.firstChild;
116
+ for (d.forEach((o, h) => {
117
+ const x = `${r}.${h}`;
118
+ E({ hydrationPath: x });
119
+ let f = null;
120
+ o && typeof o == "object" && "exec" in o ? f = o.exec() : typeof o == "function" ? f = A(o, s) : f = j(String(o), s), f && (s === f ? s = s.nextSibling : (f.parentNode, c.insertBefore(f, s))), S();
121
+ }); s; ) {
122
+ const o = s.nextSibling;
123
+ s.parentNode === c && (T(s), c.removeChild(s)), s = o;
124
+ }
125
+ return c;
126
+ }
127
+ };
128
+ }
129
+ function A(e, t) {
130
+ let n;
131
+ t && t.nodeType === Node.TEXT_NODE ? n = t : n = document.createTextNode("");
132
+ const a = C(() => {
133
+ const d = e(), i = String(d ?? "");
134
+ n.data !== i && (n.data = i);
135
+ });
136
+ return w(n, a), n;
137
+ }
138
+ function j(e, t) {
139
+ if (t && t.nodeType === Node.TEXT_NODE) {
140
+ const n = t;
141
+ return n.data !== e && (n.data = e), n;
142
+ }
143
+ return document.createTextNode(e);
144
+ }
145
+ function g(e, t, n) {
146
+ n == null ? e.removeAttribute(t) : t === "className" || t === "class" ? e.className = n : t === "style" && typeof n == "object" ? Object.assign(e.style, n) : e.setAttribute(t, String(n));
147
+ }
148
+ function _(e, t) {
149
+ $(), t.textContent = "";
150
+ const a = e({}).exec();
151
+ t.appendChild(a);
152
+ }
153
+ const F = (e) => ({
154
+ exec: () => {
155
+ const n = v().hydrationPath, a = document.createDocumentFragment(), d = e.children || [];
156
+ return (Array.isArray(d) ? d.flat() : [d]).forEach((r, c) => {
157
+ const s = `${n}.${c}`;
158
+ E({ hydrationPath: s });
159
+ let o = null;
160
+ r && r.exec ? o = r.exec() : typeof r == "function" ? o = A(r, null) : o = document.createTextNode(String(r)), o && a.appendChild(o), S();
161
+ }), a;
162
+ }
163
+ });
164
+ export {
165
+ F,
166
+ S as a,
167
+ w as b,
168
+ C as c,
169
+ T as d,
170
+ L as e,
171
+ D as f,
172
+ v as g,
173
+ O as h,
174
+ P as i,
175
+ _ as m,
176
+ B as o,
177
+ E as p,
178
+ $ as r,
179
+ I as s
180
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./jsx-runtime.cjs"),s=require("./dom-DRWrkvYh.cjs");exports.jsx=e.jsx;exports.jsxDEV=e.jsx;exports.jsxs=e.jsxs;exports.Fragment=s.Fragment;
@@ -0,0 +1,17 @@
1
+ declare type Component = (props: Props) => VNode;
2
+
3
+ export declare const Fragment: Component;
4
+
5
+ declare function jsx(tag: any, props: any, key: any): VNode;
6
+ export { jsx }
7
+ export { jsx as jsxDEV }
8
+
9
+ export declare const jsxs: typeof jsx;
10
+
11
+ declare type Props = Record<string, any>;
12
+
13
+ declare interface VNode {
14
+ exec: () => Node;
15
+ }
16
+
17
+ export { }
@@ -0,0 +1,8 @@
1
+ import { jsx as r, jsx as j, jsxs as o } from "./jsx-runtime.js";
2
+ import { F as e } from "./dom-xZDFYrGn.js";
3
+ export {
4
+ e as Fragment,
5
+ r as jsx,
6
+ j as jsxDEV,
7
+ o as jsxs
8
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./dom-DRWrkvYh.cjs");function n(o,c,s){const{children:e,...t}=c||{};s!==void 0&&(t.key=s);let r=[];return Array.isArray(e)?r=e:e!==void 0&&(r=[e]),i.h(o,t,...r)}const d=n;exports.Fragment=i.Fragment;exports.jsx=n;exports.jsxs=d;
@@ -0,0 +1,51 @@
1
+ declare type Component = (props: Props) => VNode;
2
+
3
+ export declare const Fragment: Component;
4
+
5
+ export declare function jsx(tag: any, props: any, key: any): VNode;
6
+
7
+ declare namespace JSX_2 {
8
+ interface Element {
9
+ exec: () => Node;
10
+ }
11
+ interface VeloxEvents {
12
+ onClick?: (e: MouseEvent) => void;
13
+ onDblClick?: (e: MouseEvent) => void;
14
+ onMouseDown?: (e: MouseEvent) => void;
15
+ onMouseUp?: (e: MouseEvent) => void;
16
+ onMouseEnter?: (e: MouseEvent) => void;
17
+ onMouseLeave?: (e: MouseEvent) => void;
18
+ onMouseMove?: (e: MouseEvent) => void;
19
+ onKeyDown?: (e: KeyboardEvent) => void;
20
+ onKeyUp?: (e: KeyboardEvent) => void;
21
+ onKeyPress?: (e: KeyboardEvent) => void;
22
+ onChange?: (e: Event) => void;
23
+ onInput?: (e: Event) => void;
24
+ onSubmit?: (e: Event) => void;
25
+ onFocus?: (e: FocusEvent) => void;
26
+ onBlur?: (e: FocusEvent) => void;
27
+ [key: `on${string}`]: any;
28
+ }
29
+ type IntrinsicElements = {
30
+ [K in keyof HTMLElementTagNameMap]: Partial<Omit<HTMLElementTagNameMap[K], 'children' | 'style'>> & VeloxEvents & {
31
+ children?: any;
32
+ style?: string | Partial<CSSStyleDeclaration>;
33
+ class?: string;
34
+ };
35
+ };
36
+ interface ElementChildrenAttribute {
37
+ children: {};
38
+ }
39
+ {};
40
+ }
41
+ export { JSX_2 as JSX }
42
+
43
+ export declare const jsxs: typeof jsx;
44
+
45
+ declare type Props = Record<string, any>;
46
+
47
+ declare interface VNode {
48
+ exec: () => Node;
49
+ }
50
+
51
+ export { }
@@ -0,0 +1,14 @@
1
+ import { h as n } from "./dom-xZDFYrGn.js";
2
+ import { F as m } from "./dom-xZDFYrGn.js";
3
+ function f(t, e, o) {
4
+ const { children: r, ...s } = e || {};
5
+ o !== void 0 && (s.key = o);
6
+ let i = [];
7
+ return Array.isArray(r) ? i = r : r !== void 0 && (i = [r]), n(t, s, ...i);
8
+ }
9
+ const a = f;
10
+ export {
11
+ m as Fragment,
12
+ f as jsx,
13
+ a as jsxs
14
+ };
package/dist/velox.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("./dom-DRWrkvYh.cjs");function B(e,t){n.setHydrating(!0),n.resetContext();try{const r=e({}).exec();r.parentNode!==t&&(console.warn("Velox: Hydration mismatch. Falling back to client render."),t.textContent="",t.appendChild(r))}catch(o){console.error("Velox: Hydration error",o),t.textContent=""}finally{n.setHydrating(!1)}}const I=n.resetContext,T=new Set(["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"]);class y{constructor(t){this.value=t}toString(){return this.value}}function b(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#039;")}function m(e,t,...o){t=t||{};let r=o.flat().filter(i=>i!=null&&i!==!0&&i!==!1);return r.length===0&&t.children&&(r=Array.isArray(t.children)?t.children.flat():[t.children]),{exec:()=>{if(typeof e=="function"){const l=e({...t,children:r});return l&&l.exec?l.exec():new y(String(l))}const a=n.getContext().hydrationPath,s=e;let c=`<${s} data-hid="${a}"`;for(const[l,u]of Object.entries(t))if(!(l==="children"||l.startsWith("on")))if(l==="className")c+=` class="${b(String(u))}"`;else if(l==="style"&&typeof u=="object"){const h=Object.entries(u).map(([f,x])=>`${f}:${x}`).join(";");c+=` style="${b(h)}"`}else u===!0?c+=` ${l}`:u!==!1&&u!=null&&(c+=` ${l}="${b(String(u))}"`);return T.has(s)?(c+=" />",new y(c)):(c+=">",r.forEach((l,u)=>{const h=`${a}.${u}`;n.pushContext({hydrationPath:h}),c+=F(l),n.popContext()}),c+=`</${s}>`,new y(c))}}}const E=e=>({exec:()=>{const o=n.getContext().hydrationPath;let r="";return(e.children||[]).flat().forEach((a,s)=>{const c=`${o}.${s}`;n.pushContext({hydrationPath:c}),r+=F(a),n.popContext()}),new y(r)}});function F(e){if(e&&e.exec){const t=e.exec();return t instanceof y?t.value:String(t)}if(e instanceof y)return e.value;if(typeof e=="string"||typeof e=="number")return b(String(e));if(typeof e=="function"){const t=e();return t instanceof y?t.value:b(String(t))}return String(e)}function H(e){return n.resetContext(),e({}).exec()}async function _(e){n.resetContext();const t=10;for(let o=0;o<t;o++){o>0&&n.resetContext(!0);const r=new Set;n.pushContext({suspense:r});const a=e({}).exec();if(n.popContext(),r.size===0)return a;await Promise.all(r)}return new y("<!-- Suspense Timeout -->")}const S=typeof window<"u";let P=null;function N(){if(!P){const e=S?window.location.pathname:"/";P=n.createSignal(e)}return P}function V(e){const[t,o]=N();o(e)}S&&window.addEventListener("popstate",()=>{const[e,t]=N();t(window.location.pathname)});const A=e=>(e.url&&V(e.url),S?n.h(n.Fragment,{children:e.children}):m(E,{children:e.children})),O=e=>S?n.h(n.Fragment,{children:e.children}):m(E,{children:e.children}),j=e=>{const{path:t,component:o,exact:r=!0,children:i}=e,[a]=N(),c=n.getContext().routerBase,l=M(c,t);if(!S){const f=a(),x=R(l,f,r);let g=null;if(x&&typeof o=="function"){const d=x.url||l,p=$(i,d);g=m(o,{params:x.params,children:p})}return m("div",{"data-router-outlet":t,style:{display:"contents"}},g)}const u=n.h("div",{"data-router-outlet":t,style:{display:"contents"}}),h=u.exec;return u.exec=()=>{const f=h(),x=n.createEffect(()=>{const g=a();f.childNodes.forEach(p=>n.dispose(p)),f.textContent="";const d=R(l,g,r);if(d&&typeof o=="function"){const p=d.url,w=$(i,p),v=o({params:d.params,children:w}).exec();f.appendChild(v)}});return n.addNodeCleanup(f,x),f},u},D=e=>{const{to:t,children:o,...r}=e,a=n.getContext().routerBase,s=M(a,t),c=l=>{if(l.preventDefault(),S){window.history.pushState({},"",s);const[u,h]=N();h(s)}};return S?n.h("a",{href:s,onClick:c,...r},o):m("a",{href:s,...r},o)};function L(e){if(S){window.history.pushState({},"",e);const[t,o]=N();o(e)}}function M(e,t){if(t.startsWith("/"))return t;const o=e==="/"?"":e,r=t.startsWith("/")?t.slice(1):t;return`${o}/${r}`}function $(e,t){return e.map(o=>o&&o.exec?{exec:()=>{n.pushContext({routerBase:t});const r=o.exec();return n.popContext(),r}}:o)}function R(e,t,o){if(e==="*")return{params:{},url:t};const r=e.split("/").filter(Boolean),i=t.split("/").filter(Boolean);if(o&&r.length!==i.length||!o&&i.length<r.length)return null;const a={};let s="";for(let c=0;c<r.length;c++){const l=r[c],u=i[c];if(l.startsWith(":"))a[l.slice(1)]=u;else if(l!==u)return null}return s="/"+i.slice(0,r.length).join("/"),{params:a,url:s}}const U=typeof window>"u",W=e=>{const t=e.each,o=e.children[0],r=e.key;if(U){const c=(t()||[]).map((l,u)=>o(l,()=>u));return m("div",{style:{display:"contents"}},...c)}const i=n.h("div",{style:{display:"contents"}}),a=i.exec;return i.exec=()=>{const s=a();let c=new Map;const l=n.createEffect(()=>{const u=t()||[],h=new Map,f=new Map;c.forEach((g,d)=>{f.set(d,[...g])});let x=s.firstChild;u.forEach((g,d)=>{const p=r?r(g,d):g;let w=f.get(p),C;if(w&&w.length>0&&(C=w.shift()),!C){const v=o(g,()=>d);v&&v.exec&&(C=v.exec())}C&&(h.has(p)||h.set(p,[]),h.get(p).push(C),C!==x?s.insertBefore(C,x):x=x.nextSibling)}),f.forEach(g=>{g.forEach(d=>{n.dispose(d),d.parentNode===s&&s.removeChild(d)})}),c=h});return n.addNodeCleanup(s,l),s},i};function z(e){const t=Symbol("context");return{id:t,defaultValue:e,Provider:r=>({exec:()=>{const i=n.getContext(),a=new Map(i.custom);a.set(t,r.value),n.pushContext({custom:a});try{return typeof window>"u"?m(E,{children:r.children}).exec():n.h(n.Fragment,{children:r.children}).exec()}finally{n.popContext()}}})}}function q(e){const t=n.getContext();return t.custom.has(e.id)?t.custom.get(e.id):e.defaultValue}const k=Symbol("resource_cache");function X(e,t){const[o,r]=n.createSignal(void 0),i=n.getContext();let a=i.custom.get(k);if(a||(a=new Map,i.custom.set(k,a)),a.has(e))r(a.get(e));else{const s=t().then(c=>(a.set(e,c),r(c),c));i.suspense&&i.suspense.add(s)}return[o]}const G=e=>{const t=e.fallback;return{exec:()=>{const r=n.getContext().suspense,i=new Set;n.pushContext({suspense:i});try{let a;if(typeof window>"u"?a=m(E,{children:e.children}).exec():a=n.h(n.Fragment,{children:e.children}).exec(),i.size>0){if(r&&i.forEach(s=>r.add(s)),typeof window>"u")return t?m(E,{children:t}).exec():new y("");{const c=n.h(n.Fragment,{children:t}).exec();return Promise.all(i).then(()=>{c instanceof Node&&c.parentNode&&c.parentNode.replaceChild(a,c)}),c}}return a}finally{n.popContext()}}}};exports.Fragment=n.Fragment;exports.batch=n.batch;exports.createEffect=n.createEffect;exports.createMemo=n.createMemo;exports.createSignal=n.createSignal;exports.h=n.h;exports.mount=n.mount;exports.onCleanup=n.onCleanup;exports.For=W;exports.Link=D;exports.Outlet=O;exports.Route=j;exports.Router=A;exports.Suspense=G;exports.configureRouter=V;exports.createContext=z;exports.createResource=X;exports.hSSR=m;exports.hydrate=B;exports.navigate=L;exports.renderToString=H;exports.renderToStringAsync=_;exports.resetHydrationId=I;exports.useContext=q;
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Batches signal updates to prevent multiple effect executions.
3
+ * @param fn The function to execute.
4
+ */
5
+ export declare function batch<T>(fn: () => T): T;
6
+
7
+ declare type Component = (props: Props) => VNode;
8
+
9
+ export declare function configureRouter(url: string): void;
10
+
11
+ declare interface Context<T> {
12
+ id: symbol;
13
+ defaultValue: T;
14
+ Provider: Component;
15
+ }
16
+
17
+ export declare function createContext<T>(defaultValue: T): Context<T>;
18
+
19
+ /**
20
+ * Creates a side effect that runs immediately and re-runs whenever its dependencies change.
21
+ * @param fn The function to execute.
22
+ * @returns A dispose function to stop the effect manually.
23
+ */
24
+ export declare function createEffect(fn: () => void): () => void;
25
+
26
+ /**
27
+ * Creates a computed value (memoized) that only updates when dependencies change.
28
+ * @param fn The function to calculate the value.
29
+ * @returns A getter for the computed value.
30
+ */
31
+ export declare function createMemo<T>(fn: () => T): Getter<T>;
32
+
33
+ export declare function createResource<T>(key: string, fetcher: () => Promise<T>): [() => T | undefined];
34
+
35
+ /**
36
+ * Creates a reactive signal.
37
+ * @param initialValue The initial value of the signal.
38
+ * @returns A tuple [getter, setter].
39
+ */
40
+ export declare function createSignal<T>(initialValue: T): [Getter<T>, Setter<T>];
41
+
42
+ export declare const For: Component;
43
+
44
+ export declare const Fragment: Component;
45
+
46
+ declare type Getter<T> = () => T;
47
+
48
+ export declare function h(tag: string | Component, props: Props | null, ...children: any[]): VNode;
49
+
50
+ export declare function hSSR(tag: string | SSRComponent, props: any, ...children: any[]): SSRVNode;
51
+
52
+ /**
53
+ * Hydrates a server-rendered application on the client.
54
+ */
55
+ export declare function hydrate(component: Component, root: HTMLElement): void;
56
+
57
+ export declare const Link: Component;
58
+
59
+ export declare function mount(component: Component, root: HTMLElement): void;
60
+
61
+ export declare function navigate(to: string): void;
62
+
63
+ /**
64
+ * Registers a cleanup function that runs before the current effect re-executes or is disposed.
65
+ * @param fn The cleanup function.
66
+ */
67
+ export declare function onCleanup(fn: () => void): void;
68
+
69
+ export declare const Outlet: Component;
70
+
71
+ declare type Props = Record<string, any>;
72
+
73
+ export declare function renderToString(component: SSRComponent): SafeString;
74
+
75
+ export declare function renderToStringAsync(component: SSRComponent): Promise<SafeString>;
76
+
77
+ declare function resetContext(keepCustom?: boolean): void;
78
+
79
+ export declare const resetHydrationId: typeof resetContext;
80
+
81
+ export declare const Route: Component;
82
+
83
+ export declare const Router: Component;
84
+
85
+ declare class SafeString {
86
+ value: string;
87
+ constructor(value: string);
88
+ toString(): string;
89
+ }
90
+
91
+ declare type Setter<T> = (newValue: T | ((prev: T) => T)) => void;
92
+
93
+ declare type SSRComponent = (props: any) => SSRVNode;
94
+
95
+ declare interface SSRVNode {
96
+ exec: () => SafeString;
97
+ }
98
+
99
+ export declare const Suspense: (props: any) => any;
100
+
101
+ export declare function useContext<T>(context: Context<T>): T;
102
+
103
+ declare interface VNode {
104
+ exec: () => Node;
105
+ }
106
+
107
+ export { }
package/dist/velox.js ADDED
@@ -0,0 +1,316 @@
1
+ import { r as $, s as I, p as C, g as v, a as b, h as w, F as k, c as A, d as H, b as T, e as j } from "./dom-xZDFYrGn.js";
2
+ import { i as ae, f as le, m as ue, o as de } from "./dom-xZDFYrGn.js";
3
+ function q(e, t) {
4
+ I(!0), $();
5
+ try {
6
+ const n = e({}).exec();
7
+ n.parentNode !== t && (console.warn("Velox: Hydration mismatch. Falling back to client render."), t.textContent = "", t.appendChild(n));
8
+ } catch (r) {
9
+ console.error("Velox: Hydration error", r), t.textContent = "";
10
+ } finally {
11
+ I(!1);
12
+ }
13
+ }
14
+ const X = $, U = /* @__PURE__ */ new Set([
15
+ "area",
16
+ "base",
17
+ "br",
18
+ "col",
19
+ "embed",
20
+ "hr",
21
+ "img",
22
+ "input",
23
+ "link",
24
+ "meta",
25
+ "param",
26
+ "source",
27
+ "track",
28
+ "wbr"
29
+ ]);
30
+ class x {
31
+ constructor(t) {
32
+ this.value = t;
33
+ }
34
+ toString() {
35
+ return this.value;
36
+ }
37
+ }
38
+ function P(e) {
39
+ return e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
40
+ }
41
+ function g(e, t, ...r) {
42
+ t = t || {};
43
+ let n = r.flat().filter((s) => s != null && s !== !0 && s !== !1);
44
+ return n.length === 0 && t.children && (n = Array.isArray(t.children) ? t.children.flat() : [t.children]), {
45
+ exec: () => {
46
+ if (typeof e == "function") {
47
+ const a = e({ ...t, children: n });
48
+ return a && a.exec ? a.exec() : new x(String(a));
49
+ }
50
+ const i = v().hydrationPath, c = e;
51
+ let o = `<${c} data-hid="${i}"`;
52
+ for (const [a, l] of Object.entries(t))
53
+ if (!(a === "children" || a.startsWith("on")))
54
+ if (a === "className")
55
+ o += ` class="${P(String(l))}"`;
56
+ else if (a === "style" && typeof l == "object") {
57
+ const f = Object.entries(l).map(([d, h]) => `${d}:${h}`).join(";");
58
+ o += ` style="${P(f)}"`;
59
+ } else
60
+ l === !0 ? o += ` ${a}` : l !== !1 && l != null && (o += ` ${a}="${P(String(l))}"`);
61
+ return U.has(c) ? (o += " />", new x(o)) : (o += ">", n.forEach((a, l) => {
62
+ const f = `${i}.${l}`;
63
+ C({ hydrationPath: f }), o += O(a), b();
64
+ }), o += `</${c}>`, new x(o));
65
+ }
66
+ };
67
+ }
68
+ const V = (e) => ({
69
+ exec: () => {
70
+ const r = v().hydrationPath;
71
+ let n = "";
72
+ return (e.children || []).flat().forEach((i, c) => {
73
+ const o = `${r}.${c}`;
74
+ C({ hydrationPath: o }), n += O(i), b();
75
+ }), new x(n);
76
+ }
77
+ });
78
+ function O(e) {
79
+ if (e && e.exec) {
80
+ const t = e.exec();
81
+ return t instanceof x ? t.value : String(t);
82
+ }
83
+ if (e instanceof x)
84
+ return e.value;
85
+ if (typeof e == "string" || typeof e == "number")
86
+ return P(String(e));
87
+ if (typeof e == "function") {
88
+ const t = e();
89
+ return t instanceof x ? t.value : P(String(t));
90
+ }
91
+ return String(e);
92
+ }
93
+ function G(e) {
94
+ return $(), e({}).exec();
95
+ }
96
+ async function J(e) {
97
+ $();
98
+ const t = 10;
99
+ for (let r = 0; r < t; r++) {
100
+ r > 0 && $(!0);
101
+ const n = /* @__PURE__ */ new Set();
102
+ C({ suspense: n });
103
+ const i = e({}).exec();
104
+ if (b(), n.size === 0)
105
+ return i;
106
+ await Promise.all(n);
107
+ }
108
+ return new x("<!-- Suspense Timeout -->");
109
+ }
110
+ const S = typeof window < "u";
111
+ let R = null;
112
+ function B() {
113
+ if (!R) {
114
+ const e = S ? window.location.pathname : "/";
115
+ R = j(e);
116
+ }
117
+ return R;
118
+ }
119
+ function W(e) {
120
+ const [t, r] = B();
121
+ r(e);
122
+ }
123
+ S && window.addEventListener("popstate", () => {
124
+ const [e, t] = B();
125
+ t(window.location.pathname);
126
+ });
127
+ const K = (e) => (e.url && W(e.url), S ? w(k, { children: e.children }) : g(V, { children: e.children })), Q = (e) => S ? w(k, { children: e.children }) : g(V, { children: e.children }), Y = (e) => {
128
+ const { path: t, component: r, exact: n = !0, children: s } = e, [i] = B(), o = v().routerBase, a = D(o, t);
129
+ if (!S) {
130
+ const d = i(), h = _(a, d, n);
131
+ let m = null;
132
+ if (h && typeof r == "function") {
133
+ const u = h.url || a, p = M(s, u);
134
+ m = g(r, { params: h.params, children: p });
135
+ }
136
+ return g("div", {
137
+ "data-router-outlet": t,
138
+ style: { display: "contents" }
139
+ }, m);
140
+ }
141
+ const l = w("div", {
142
+ "data-router-outlet": t,
143
+ style: { display: "contents" }
144
+ }), f = l.exec;
145
+ return l.exec = () => {
146
+ const d = f(), h = A(() => {
147
+ const m = i();
148
+ d.childNodes.forEach((p) => H(p)), d.textContent = "";
149
+ const u = _(a, m, n);
150
+ if (u && typeof r == "function") {
151
+ const p = u.url, E = M(s, p), N = r({ params: u.params, children: E }).exec();
152
+ d.appendChild(N);
153
+ }
154
+ });
155
+ return T(d, h), d;
156
+ }, l;
157
+ }, Z = (e) => {
158
+ const { to: t, children: r, ...n } = e, i = v().routerBase, c = D(i, t), o = (a) => {
159
+ if (a.preventDefault(), S) {
160
+ window.history.pushState({}, "", c);
161
+ const [l, f] = B();
162
+ f(c);
163
+ }
164
+ };
165
+ return S ? w("a", { href: c, onClick: o, ...n }, r) : g("a", { href: c, ...n }, r);
166
+ };
167
+ function ee(e) {
168
+ if (S) {
169
+ window.history.pushState({}, "", e);
170
+ const [t, r] = B();
171
+ r(e);
172
+ }
173
+ }
174
+ function D(e, t) {
175
+ if (t.startsWith("/")) return t;
176
+ const r = e === "/" ? "" : e, n = t.startsWith("/") ? t.slice(1) : t;
177
+ return `${r}/${n}`;
178
+ }
179
+ function M(e, t) {
180
+ return e.map((r) => r && r.exec ? {
181
+ exec: () => {
182
+ C({ routerBase: t });
183
+ const n = r.exec();
184
+ return b(), n;
185
+ }
186
+ } : r);
187
+ }
188
+ function _(e, t, r) {
189
+ if (e === "*") return { params: {}, url: t };
190
+ const n = e.split("/").filter(Boolean), s = t.split("/").filter(Boolean);
191
+ if (r && n.length !== s.length || !r && s.length < n.length) return null;
192
+ const i = {};
193
+ let c = "";
194
+ for (let o = 0; o < n.length; o++) {
195
+ const a = n[o], l = s[o];
196
+ if (a.startsWith(":"))
197
+ i[a.slice(1)] = l;
198
+ else if (a !== l)
199
+ return null;
200
+ }
201
+ return c = "/" + s.slice(0, n.length).join("/"), { params: i, url: c };
202
+ }
203
+ const z = typeof window > "u", te = (e) => {
204
+ const t = e.each, r = e.children[0], n = e.key;
205
+ if (z) {
206
+ const o = (t() || []).map((a, l) => r(a, () => l));
207
+ return g("div", { style: { display: "contents" } }, ...o);
208
+ }
209
+ const s = w("div", { style: { display: "contents" } }), i = s.exec;
210
+ return s.exec = () => {
211
+ const c = i();
212
+ let o = /* @__PURE__ */ new Map();
213
+ const a = A(() => {
214
+ const l = t() || [], f = /* @__PURE__ */ new Map(), d = /* @__PURE__ */ new Map();
215
+ o.forEach((m, u) => {
216
+ d.set(u, [...m]);
217
+ });
218
+ let h = c.firstChild;
219
+ l.forEach((m, u) => {
220
+ const p = n ? n(m, u) : m;
221
+ let E = d.get(p), y;
222
+ if (E && E.length > 0 && (y = E.shift()), !y) {
223
+ const N = r(m, () => u);
224
+ N && N.exec && (y = N.exec());
225
+ }
226
+ y && (f.has(p) || f.set(p, []), f.get(p).push(y), y !== h ? c.insertBefore(y, h) : h = h.nextSibling);
227
+ }), d.forEach((m) => {
228
+ m.forEach((u) => {
229
+ H(u), u.parentNode === c && c.removeChild(u);
230
+ });
231
+ }), o = f;
232
+ });
233
+ return T(c, a), c;
234
+ }, s;
235
+ };
236
+ function ne(e) {
237
+ const t = Symbol("context");
238
+ return { id: t, defaultValue: e, Provider: (n) => ({
239
+ exec: () => {
240
+ const s = v(), i = new Map(s.custom);
241
+ i.set(t, n.value), C({ custom: i });
242
+ try {
243
+ return typeof window > "u" ? g(V, { children: n.children }).exec() : w(k, { children: n.children }).exec();
244
+ } finally {
245
+ b();
246
+ }
247
+ }
248
+ }) };
249
+ }
250
+ function re(e) {
251
+ const t = v();
252
+ return t.custom.has(e.id) ? t.custom.get(e.id) : e.defaultValue;
253
+ }
254
+ const F = Symbol("resource_cache");
255
+ function oe(e, t) {
256
+ const [r, n] = j(void 0), s = v();
257
+ let i = s.custom.get(F);
258
+ if (i || (i = /* @__PURE__ */ new Map(), s.custom.set(F, i)), i.has(e))
259
+ n(i.get(e));
260
+ else {
261
+ const c = t().then((o) => (i.set(e, o), n(o), o));
262
+ s.suspense && s.suspense.add(c);
263
+ }
264
+ return [r];
265
+ }
266
+ const ce = (e) => {
267
+ const t = e.fallback;
268
+ return {
269
+ exec: () => {
270
+ const n = v().suspense, s = /* @__PURE__ */ new Set();
271
+ C({ suspense: s });
272
+ try {
273
+ let i;
274
+ if (typeof window > "u" ? i = g(V, { children: e.children }).exec() : i = w(k, { children: e.children }).exec(), s.size > 0) {
275
+ if (n && s.forEach((c) => n.add(c)), typeof window > "u")
276
+ return t ? g(V, { children: t }).exec() : new x("");
277
+ {
278
+ const o = w(k, { children: t }).exec();
279
+ return Promise.all(s).then(() => {
280
+ o instanceof Node && o.parentNode && o.parentNode.replaceChild(i, o);
281
+ }), o;
282
+ }
283
+ }
284
+ return i;
285
+ } finally {
286
+ b();
287
+ }
288
+ }
289
+ };
290
+ };
291
+ export {
292
+ te as For,
293
+ k as Fragment,
294
+ Z as Link,
295
+ Q as Outlet,
296
+ Y as Route,
297
+ K as Router,
298
+ ce as Suspense,
299
+ ae as batch,
300
+ W as configureRouter,
301
+ ne as createContext,
302
+ A as createEffect,
303
+ le as createMemo,
304
+ oe as createResource,
305
+ j as createSignal,
306
+ w as h,
307
+ g as hSSR,
308
+ q as hydrate,
309
+ ue as mount,
310
+ ee as navigate,
311
+ de as onCleanup,
312
+ G as renderToString,
313
+ J as renderToStringAsync,
314
+ X as resetHydrationId,
315
+ re as useContext
316
+ };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@remyyy/velox",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "description": "The fastest web framework in the universe",
9
+ "main": "./dist/velox.cjs",
10
+ "module": "./dist/velox.js",
11
+ "types": "./dist/velox.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/velox.js",
15
+ "require": "./dist/velox.cjs",
16
+ "types": "./dist/velox.d.ts"
17
+ },
18
+ "./jsx-runtime": {
19
+ "import": "./dist/jsx-runtime.js",
20
+ "require": "./dist/jsx-runtime.cjs",
21
+ "types": "./dist/jsx-runtime.d.ts"
22
+ },
23
+ "./jsx-dev-runtime": {
24
+ "import": "./dist/jsx-dev-runtime.js",
25
+ "require": "./dist/jsx-dev-runtime.cjs",
26
+ "types": "./dist/jsx-dev-runtime.d.ts"
27
+ }
28
+ },
29
+ "files": [
30
+ "dist"
31
+ ],
32
+ "scripts": {
33
+ "build": "vite build && tsc",
34
+ "test": "vitest"
35
+ },
36
+ "license": "MIT",
37
+ "devDependencies": {
38
+ "jsdom": "^27.3.0",
39
+ "typescript": "^5.0.0",
40
+ "vite": "^5.0.0",
41
+ "vite-plugin-dts": "^4.5.4"
42
+ }
43
+ }