frontend-hamroun 1.2.16 → 1.2.17
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/README.md +4 -0
- package/bin/cli.js +673 -0
- package/dist/component.d.ts +1 -1
- package/dist/context.d.ts +4 -3
- package/dist/index.client.d.ts +11 -0
- package/dist/index.d.ts +9 -89
- package/dist/index.js +396 -67
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +392 -0
- package/dist/index.mjs.map +1 -0
- package/dist/jsx-runtime/jsx-runtime.d.ts +0 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/renderer.d.ts +0 -10
- package/dist/server-renderer.d.ts +0 -3
- package/dist/server-types.d.ts +42 -0
- package/package.json +69 -41
- package/templates/basic-app/index.html +6 -6
- package/templates/basic-app/package.json +18 -7
- package/templates/basic-app/postcss.config.js +0 -1
- package/templates/basic-app/src/main.tsx +1 -10
- package/templates/basic-app/tailwind.config.js +2 -23
- package/templates/basic-app/tsconfig.json +4 -17
- package/templates/basic-app/vite.config.ts +3 -54
- package/templates/fullstack-app/api/hello.ts +18 -0
- package/templates/fullstack-app/api/users/[id].ts +73 -0
- package/templates/fullstack-app/api/users/index.ts +32 -0
- package/templates/fullstack-app/package.json +31 -0
- package/templates/fullstack-app/server.ts +46 -0
- package/templates/fullstack-app/src/pages/index.tsx +59 -0
- package/templates/ssr-template/vite.config.ts +1 -11
- package/bin/cli.cjs +0 -16
- package/bin/cli.mjs +0 -237
- package/dist/backend/api-utils.d.ts +0 -38
- package/dist/backend/api-utils.js +0 -135
- package/dist/backend/auth.d.ts +0 -134
- package/dist/backend/auth.js +0 -387
- package/dist/backend/database.d.ts +0 -27
- package/dist/backend/database.js +0 -91
- package/dist/backend/model.d.ts +0 -43
- package/dist/backend/model.js +0 -178
- package/dist/backend/router.d.ts +0 -27
- package/dist/backend/router.js +0 -137
- package/dist/backend/server.d.ts +0 -19
- package/dist/backend/server.js +0 -268
- package/dist/backend/types.d.ts +0 -217
- package/dist/backend/types.js +0 -1
- package/dist/batch.js +0 -22
- package/dist/cli/index.d.ts +0 -2
- package/dist/cli/index.js +0 -215
- package/dist/component.js +0 -84
- package/dist/components/Counter.js +0 -2
- package/dist/context.js +0 -18
- package/dist/frontend-hamroun.es.js +0 -1378
- package/dist/frontend-hamroun.umd.js +0 -66
- package/dist/hooks.js +0 -164
- package/dist/jsx-runtime/index.d.ts +0 -11
- package/dist/jsx-runtime/index.js +0 -19
- package/dist/jsx-runtime/jsx-dev-runtime.js +0 -1
- package/dist/jsx-runtime/jsx-runtime.js +0 -95
- package/dist/jsx-runtime.js +0 -192
- package/dist/renderer.js +0 -51
- package/dist/server-renderer.js +0 -102
- package/dist/types.js +0 -1
- package/dist/vdom.js +0 -27
- package/scripts/build-cli.js +0 -1199
- package/scripts/generate.js +0 -134
- package/src/backend/api-utils.ts +0 -178
- package/src/backend/auth.ts +0 -544
- package/src/backend/database.ts +0 -104
- package/src/backend/model.ts +0 -198
- package/src/backend/router.ts +0 -176
- package/src/backend/server.ts +0 -330
- package/src/backend/types.ts +0 -257
- package/src/batch.ts +0 -24
- package/src/cli/index.js +0 -554
- package/src/cli/index.ts +0 -257
- package/src/component.ts +0 -98
- package/src/components/Counter.tsx +0 -4
- package/src/context.ts +0 -29
- package/src/hooks.ts +0 -211
- package/src/index.ts +0 -144
- package/src/jsx-runtime/index.ts +0 -27
- package/src/jsx-runtime/jsx-dev-runtime.ts +0 -0
- package/src/jsx-runtime/jsx-runtime.ts +0 -104
- package/src/jsx-runtime.ts +0 -226
- package/src/renderer.ts +0 -55
- package/src/server-renderer.ts +0 -114
- package/src/shims.d.ts +0 -20
- package/src/types/bcrypt.d.ts +0 -30
- package/src/types/jsonwebtoken.d.ts +0 -55
- package/src/types.d.ts +0 -26
- package/src/types.ts +0 -21
- package/src/vdom.ts +0 -34
- package/templates/basic/.eslintignore +0 -5
- package/templates/basic/.eslintrc.json +0 -25
- package/templates/basic/docs/rapport_pfe.aux +0 -27
- package/templates/basic/docs/rapport_pfe.log +0 -399
- package/templates/basic/docs/rapport_pfe.out +0 -10
- package/templates/basic/docs/rapport_pfe.pdf +0 -0
- package/templates/basic/docs/rapport_pfe.tex +0 -68
- package/templates/basic/docs/rapport_pfe.toc +0 -14
- package/templates/basic/index.html +0 -12
- package/templates/basic/jsconfig.json +0 -14
- package/templates/basic/package.json +0 -18
- package/templates/basic/postcss.config.js +0 -7
- package/templates/basic/src/App.js +0 -105
- package/templates/basic/src/App.tsx +0 -65
- package/templates/basic/src/api.ts +0 -58
- package/templates/basic/src/components/Counter.tsx +0 -26
- package/templates/basic/src/components/Header.tsx +0 -9
- package/templates/basic/src/components/TodoList.tsx +0 -90
- package/templates/basic/src/main.css +0 -3
- package/templates/basic/src/main.js +0 -11
- package/templates/basic/src/main.ts +0 -20
- package/templates/basic/src/main.tsx +0 -144
- package/templates/basic/src/server.ts +0 -99
- package/templates/basic/tailwind.config.js +0 -32
- package/templates/basic/tsconfig.json +0 -20
- package/templates/basic/tsconfig.node.json +0 -10
- package/templates/basic/vite.config.js +0 -18
- package/templates/basic/vite.config.ts +0 -86
- package/templates/basic-app/src/App.js +0 -105
- package/templates/basic-app/src/App.tsx +0 -143
- package/templates/basic-app/src/api.ts +0 -58
- package/templates/basic-app/src/components/Counter.tsx +0 -26
- package/templates/basic-app/src/components/Header.tsx +0 -9
- package/templates/basic-app/src/components/TodoList.tsx +0 -90
- package/templates/basic-app/src/main.js +0 -10
- package/templates/basic-app/src/main.ts +0 -21
- package/templates/basic-app/src/react/index.ts +0 -35
- package/templates/basic-app/src/react/jsx-dev-runtime.ts +0 -13
- package/templates/basic-app/src/react/jsx-runtime.ts +0 -12
- package/templates/basic-app/src/server.ts +0 -99
- package/templates/basic-app/src/shims.ts +0 -9
- package/templates/basic-app/tsconfig.node.json +0 -10
- package/templates/basic-app/vite.config.js +0 -22
- package/templates/full-stack/.env.example +0 -11
- package/templates/full-stack/README.md +0 -51
- package/templates/full-stack/index.html +0 -12
- package/templates/full-stack/jsconfig.json +0 -14
- package/templates/full-stack/package.json +0 -21
- package/templates/full-stack/src/App.js +0 -105
- package/templates/full-stack/src/client/App.tsx +0 -50
- package/templates/full-stack/src/client/components/Header.tsx +0 -42
- package/templates/full-stack/src/client/components/UserList.tsx +0 -29
- package/templates/full-stack/src/client/main.tsx +0 -5
- package/templates/full-stack/src/main.css +0 -3
- package/templates/full-stack/src/main.js +0 -11
- package/templates/full-stack/src/main.ts +0 -20
- package/templates/full-stack/src/server/index.ts +0 -99
- package/templates/full-stack/src/server/routes/auth.ts +0 -39
- package/templates/full-stack/src/server/routes/users.ts +0 -48
- package/templates/full-stack/src/shims.ts +0 -9
- package/templates/full-stack/tsconfig.json +0 -20
- package/templates/full-stack/tsconfig.node.json +0 -10
- package/templates/full-stack/tsconfig.server.json +0 -15
- package/templates/full-stack/vite.config.js +0 -18
- package/templates/full-stack/vite.config.ts +0 -85
package/dist/context.d.ts
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
export interface Context<T> {
|
2
2
|
Provider: (props: {
|
3
3
|
value: T;
|
4
|
-
children
|
4
|
+
children?: any;
|
5
5
|
}) => any;
|
6
6
|
Consumer: (props: {
|
7
7
|
children: (value: T) => any;
|
8
8
|
}) => any;
|
9
|
-
|
9
|
+
_id: symbol;
|
10
|
+
useSelector: <S>(selector: (state: T) => S) => S;
|
10
11
|
}
|
11
12
|
export declare function createContext<T>(defaultValue: T): Context<T>;
|
12
|
-
export declare function useContext<T>(context:
|
13
|
+
export declare function useContext<T>(context: any): T;
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export { useState, useEffect, useMemo, useRef, useErrorBoundary } from './hooks';
|
2
|
+
export { createContext, useContext } from './context';
|
3
|
+
export { batchUpdates } from './batch';
|
4
|
+
export { jsx, jsxs, Fragment } from './jsx-runtime';
|
5
|
+
export { render, hydrate } from './renderer';
|
6
|
+
export { renderToString } from './server-renderer';
|
7
|
+
export type { Context } from './context';
|
8
|
+
export type { VNode } from './types';
|
9
|
+
export declare const server: {
|
10
|
+
getServer(): Promise<never>;
|
11
|
+
};
|
package/dist/index.d.ts
CHANGED
@@ -1,92 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
import { batchUpdates } from './batch';
|
8
|
-
import { createContext, useContext } from './context';
|
9
|
-
import { createServer } from './backend/server';
|
10
|
-
import { createAuth } from './backend/auth';
|
11
|
-
import { createModel, FieldTypes } from './backend/model';
|
12
|
-
import { createModelRouter, createApiRouter as createCustomRouter } from './backend/router';
|
13
|
-
import { sendSuccess, sendError, apiResponse, getPaginationParams, paginationMiddleware, validateRequest, asyncHandler, createRestEndpoints, createApiRouter } from './backend/api-utils';
|
14
|
-
import { DatabaseConnector } from './backend/database';
|
15
|
-
export { jsx, jsxs, jsxDEV, // Add jsxDEV export
|
16
|
-
createElement, Fragment };
|
17
|
-
export { useState, useEffect, useRef, useMemo, useErrorBoundary, prepareRender, finishRender, batchUpdates, createContext, useContext };
|
18
|
-
export { Component };
|
19
|
-
export { render, hydrate, renderToString };
|
20
|
-
export { createServer, createAuth, createModel, FieldTypes, createModelRouter, createCustomRouter, createApiRouter, sendSuccess, sendError, apiResponse, getPaginationParams, paginationMiddleware, validateRequest, asyncHandler, createRestEndpoints, DatabaseConnector };
|
1
|
+
export { useState, useEffect, useMemo, useRef, useErrorBoundary } from './hooks';
|
2
|
+
export { createContext, useContext } from './context';
|
3
|
+
export { batchUpdates } from './batch';
|
4
|
+
export { jsx, jsxs, Fragment } from './jsx-runtime';
|
5
|
+
export { render, hydrate } from './renderer';
|
6
|
+
export { renderToString } from './server-renderer';
|
21
7
|
export type { Context } from './context';
|
22
8
|
export type { VNode } from './types';
|
23
|
-
export type {
|
24
|
-
export
|
25
|
-
|
26
|
-
jsx: typeof jsx;
|
27
|
-
jsxs: typeof jsxs;
|
28
|
-
jsxDEV: typeof jsx;
|
29
|
-
createElement: typeof createElement;
|
30
|
-
Fragment: symbol;
|
31
|
-
Component: typeof Component;
|
32
|
-
useState: typeof useState;
|
33
|
-
useEffect: typeof useEffect;
|
34
|
-
useRef: typeof useRef;
|
35
|
-
useMemo: typeof useMemo;
|
36
|
-
useErrorBoundary: typeof useErrorBoundary;
|
37
|
-
render: typeof render;
|
38
|
-
hydrate: typeof hydrate;
|
39
|
-
renderToString: typeof renderToString;
|
40
|
-
prepareRender: typeof prepareRender;
|
41
|
-
finishRender: typeof finishRender;
|
42
|
-
batchUpdates: typeof batchUpdates;
|
43
|
-
createContext: typeof createContext;
|
44
|
-
useContext: typeof useContext;
|
45
|
-
createServer: typeof createServer;
|
46
|
-
createAuth: typeof createAuth;
|
47
|
-
createModel: typeof createModel;
|
48
|
-
FieldTypes: {
|
49
|
-
String: {
|
50
|
-
type: StringConstructor;
|
51
|
-
};
|
52
|
-
Number: {
|
53
|
-
type: NumberConstructor;
|
54
|
-
};
|
55
|
-
Boolean: {
|
56
|
-
type: BooleanConstructor;
|
57
|
-
};
|
58
|
-
Date: {
|
59
|
-
type: DateConstructor;
|
60
|
-
};
|
61
|
-
ObjectId: {
|
62
|
-
type: StringConstructor;
|
63
|
-
};
|
64
|
-
Required: (fieldType: any) => any;
|
65
|
-
Unique: (fieldType: any) => any;
|
66
|
-
Ref: (model: string) => {
|
67
|
-
type: StringConstructor;
|
68
|
-
ref: string;
|
69
|
-
};
|
70
|
-
Enum: (values: any[]) => {
|
71
|
-
type: StringConstructor;
|
72
|
-
enum: any[];
|
73
|
-
};
|
74
|
-
Default: (fieldType: any, defaultValue: any) => any;
|
75
|
-
Array: (fieldType: any) => {
|
76
|
-
type: any[];
|
77
|
-
};
|
78
|
-
};
|
79
|
-
createModelRouter: typeof createModelRouter;
|
80
|
-
createCustomRouter: typeof createCustomRouter;
|
81
|
-
createApiRouter: typeof createApiRouter;
|
82
|
-
sendSuccess: typeof sendSuccess;
|
83
|
-
sendError: typeof sendError;
|
84
|
-
apiResponse: typeof apiResponse;
|
85
|
-
getPaginationParams: typeof getPaginationParams;
|
86
|
-
paginationMiddleware: typeof paginationMiddleware;
|
87
|
-
validateRequest: typeof validateRequest;
|
88
|
-
asyncHandler: typeof asyncHandler;
|
89
|
-
createRestEndpoints: typeof createRestEndpoints;
|
90
|
-
DatabaseConnector: typeof DatabaseConnector;
|
9
|
+
export type { Server, ServerConfig, User, DbConfig, MiddlewareFunction } from './server-types';
|
10
|
+
export declare const server: {
|
11
|
+
getServer(): Promise<any>;
|
91
12
|
};
|
92
|
-
export default _default;
|
package/dist/index.js
CHANGED
@@ -1,67 +1,396 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
1
|
+
(function(global, factory) {
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.FrontendHamroun = {}));
|
3
|
+
})(this, function(exports2) {
|
4
|
+
"use strict";
|
5
|
+
let isBatching = false;
|
6
|
+
const queue = [];
|
7
|
+
function batchUpdates(fn) {
|
8
|
+
if (isBatching) {
|
9
|
+
queue.push(fn);
|
10
|
+
return;
|
11
|
+
}
|
12
|
+
isBatching = true;
|
13
|
+
try {
|
14
|
+
fn();
|
15
|
+
while (queue.length > 0) {
|
16
|
+
const nextFn = queue.shift();
|
17
|
+
nextFn == null ? void 0 : nextFn();
|
18
|
+
}
|
19
|
+
} finally {
|
20
|
+
isBatching = false;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
let currentRender = 0;
|
24
|
+
const states = /* @__PURE__ */ new Map();
|
25
|
+
const stateIndices = /* @__PURE__ */ new Map();
|
26
|
+
const effects = /* @__PURE__ */ new Map();
|
27
|
+
const memos = /* @__PURE__ */ new Map();
|
28
|
+
const refs = /* @__PURE__ */ new Map();
|
29
|
+
let globalRenderCallback = null;
|
30
|
+
let globalContainer = null;
|
31
|
+
let currentElement = null;
|
32
|
+
const isServer = typeof window === "undefined";
|
33
|
+
const serverStates = /* @__PURE__ */ new Map();
|
34
|
+
function setRenderCallback(callback, element, container) {
|
35
|
+
globalRenderCallback = callback;
|
36
|
+
globalContainer = container;
|
37
|
+
currentElement = element;
|
38
|
+
}
|
39
|
+
function prepareRender() {
|
40
|
+
currentRender++;
|
41
|
+
stateIndices.set(currentRender, 0);
|
42
|
+
return currentRender;
|
43
|
+
}
|
44
|
+
function finishRender() {
|
45
|
+
if (isServer) {
|
46
|
+
serverStates.delete(currentRender);
|
47
|
+
}
|
48
|
+
currentRender = 0;
|
49
|
+
}
|
50
|
+
function useState(initial) {
|
51
|
+
if (!currentRender) {
|
52
|
+
throw new Error("useState must be called within a render");
|
53
|
+
}
|
54
|
+
if (isServer) {
|
55
|
+
if (!serverStates.has(currentRender)) {
|
56
|
+
serverStates.set(currentRender, /* @__PURE__ */ new Map());
|
57
|
+
}
|
58
|
+
const componentState = serverStates.get(currentRender);
|
59
|
+
const index2 = stateIndices.get(currentRender) || 0;
|
60
|
+
if (!componentState.has(index2)) {
|
61
|
+
componentState.set(index2, initial);
|
62
|
+
}
|
63
|
+
const state2 = componentState.get(index2);
|
64
|
+
const setState2 = (newValue) => {
|
65
|
+
};
|
66
|
+
stateIndices.set(currentRender, index2 + 1);
|
67
|
+
return [state2, setState2];
|
68
|
+
}
|
69
|
+
if (!states.has(currentRender)) {
|
70
|
+
states.set(currentRender, []);
|
71
|
+
}
|
72
|
+
const componentStates = states.get(currentRender);
|
73
|
+
const index = stateIndices.get(currentRender);
|
74
|
+
if (index >= componentStates.length) {
|
75
|
+
componentStates.push(initial);
|
76
|
+
}
|
77
|
+
const state = componentStates[index];
|
78
|
+
const setState = (newValue) => {
|
79
|
+
const nextValue = typeof newValue === "function" ? newValue(componentStates[index]) : newValue;
|
80
|
+
if (componentStates[index] === nextValue)
|
81
|
+
return;
|
82
|
+
componentStates[index] = nextValue;
|
83
|
+
if (isBatching) {
|
84
|
+
batchUpdates(() => rerender(currentRender));
|
85
|
+
} else {
|
86
|
+
rerender(currentRender);
|
87
|
+
}
|
88
|
+
};
|
89
|
+
stateIndices.set(currentRender, index + 1);
|
90
|
+
return [state, setState];
|
91
|
+
}
|
92
|
+
function useEffect(callback, deps) {
|
93
|
+
if (!currentRender)
|
94
|
+
throw new Error("useEffect must be called within a render");
|
95
|
+
const effectIndex = stateIndices.get(currentRender);
|
96
|
+
if (!effects.has(currentRender)) {
|
97
|
+
effects.set(currentRender, []);
|
98
|
+
}
|
99
|
+
const componentEffects = effects.get(currentRender);
|
100
|
+
const prevEffect = componentEffects[effectIndex];
|
101
|
+
if (!prevEffect || !deps || !prevEffect.deps || deps.some((dep, i) => dep !== prevEffect.deps[i])) {
|
102
|
+
if (prevEffect == null ? void 0 : prevEffect.cleanup) {
|
103
|
+
prevEffect.cleanup();
|
104
|
+
}
|
105
|
+
queueMicrotask(() => {
|
106
|
+
const cleanup = callback() || void 0;
|
107
|
+
componentEffects[effectIndex] = { cleanup, deps };
|
108
|
+
});
|
109
|
+
}
|
110
|
+
stateIndices.set(currentRender, effectIndex + 1);
|
111
|
+
}
|
112
|
+
function useMemo(factory, deps) {
|
113
|
+
if (!currentRender)
|
114
|
+
throw new Error("useMemo must be called within a render");
|
115
|
+
const memoIndex = stateIndices.get(currentRender);
|
116
|
+
if (!memos.has(currentRender)) {
|
117
|
+
memos.set(currentRender, []);
|
118
|
+
}
|
119
|
+
const componentMemos = memos.get(currentRender);
|
120
|
+
const prevMemo = componentMemos[memoIndex];
|
121
|
+
if (!prevMemo || deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i]))) {
|
122
|
+
const value = factory();
|
123
|
+
componentMemos[memoIndex] = { value, deps };
|
124
|
+
stateIndices.set(currentRender, memoIndex + 1);
|
125
|
+
return value;
|
126
|
+
}
|
127
|
+
stateIndices.set(currentRender, memoIndex + 1);
|
128
|
+
return prevMemo.value;
|
129
|
+
}
|
130
|
+
function useRef(initial) {
|
131
|
+
if (!currentRender)
|
132
|
+
throw new Error("useRef must be called within a render");
|
133
|
+
const refIndex = stateIndices.get(currentRender);
|
134
|
+
if (!refs.has(currentRender)) {
|
135
|
+
refs.set(currentRender, []);
|
136
|
+
}
|
137
|
+
const componentRefs = refs.get(currentRender);
|
138
|
+
if (refIndex >= componentRefs.length) {
|
139
|
+
const ref2 = { current: initial };
|
140
|
+
componentRefs.push(ref2);
|
141
|
+
stateIndices.set(currentRender, refIndex + 1);
|
142
|
+
return ref2;
|
143
|
+
}
|
144
|
+
const ref = componentRefs[refIndex];
|
145
|
+
stateIndices.set(currentRender, refIndex + 1);
|
146
|
+
return ref;
|
147
|
+
}
|
148
|
+
async function rerender(rendererId) {
|
149
|
+
try {
|
150
|
+
const componentEffects = effects.get(rendererId);
|
151
|
+
if (componentEffects) {
|
152
|
+
componentEffects.forEach((effect) => {
|
153
|
+
if (effect.cleanup)
|
154
|
+
effect.cleanup();
|
155
|
+
});
|
156
|
+
effects.set(rendererId, []);
|
157
|
+
}
|
158
|
+
if (globalRenderCallback && globalContainer && currentElement) {
|
159
|
+
await globalRenderCallback(currentElement, globalContainer);
|
160
|
+
}
|
161
|
+
} catch (error) {
|
162
|
+
console.error("Error during rerender:", error);
|
163
|
+
}
|
164
|
+
}
|
165
|
+
function useErrorBoundary() {
|
166
|
+
const [error, setError] = useState(null);
|
167
|
+
return [error, () => setError(null)];
|
168
|
+
}
|
169
|
+
function createContext(defaultValue) {
|
170
|
+
const context = {
|
171
|
+
Provider: ({ value, children }) => {
|
172
|
+
return children;
|
173
|
+
},
|
174
|
+
Consumer: ({ children }) => {
|
175
|
+
return children(defaultValue);
|
176
|
+
},
|
177
|
+
_id: Symbol(),
|
178
|
+
useSelector: (selector) => {
|
179
|
+
return selector(defaultValue);
|
180
|
+
}
|
181
|
+
};
|
182
|
+
return context;
|
183
|
+
}
|
184
|
+
function useContext(context) {
|
185
|
+
return context;
|
186
|
+
}
|
187
|
+
function jsx(type, props) {
|
188
|
+
console.log("JSX Transform:", { type, props });
|
189
|
+
const processedProps = { ...props };
|
190
|
+
if (arguments.length > 2) {
|
191
|
+
processedProps.children = Array.prototype.slice.call(arguments, 2);
|
192
|
+
}
|
193
|
+
return { type, props: processedProps };
|
194
|
+
}
|
195
|
+
const Fragment = ({ children }) => children;
|
196
|
+
async function createElement(vnode) {
|
197
|
+
var _a;
|
198
|
+
console.log("Creating element from:", vnode);
|
199
|
+
if (vnode == null) {
|
200
|
+
return document.createTextNode("");
|
201
|
+
}
|
202
|
+
if (typeof vnode === "boolean") {
|
203
|
+
return document.createTextNode("");
|
204
|
+
}
|
205
|
+
if (typeof vnode === "number" || typeof vnode === "string") {
|
206
|
+
return document.createTextNode(String(vnode));
|
207
|
+
}
|
208
|
+
if (Array.isArray(vnode)) {
|
209
|
+
const fragment = document.createDocumentFragment();
|
210
|
+
for (const child of vnode) {
|
211
|
+
const node = await createElement(child);
|
212
|
+
fragment.appendChild(node);
|
213
|
+
}
|
214
|
+
return fragment;
|
215
|
+
}
|
216
|
+
if ("type" in vnode && vnode.props !== void 0) {
|
217
|
+
const { type, props } = vnode;
|
218
|
+
if (typeof type === "function") {
|
219
|
+
try {
|
220
|
+
const result = await type(props || {});
|
221
|
+
const node = await createElement(result);
|
222
|
+
if (node instanceof Element) {
|
223
|
+
node.setAttribute("data-component-id", type.name || type.toString());
|
224
|
+
}
|
225
|
+
return node;
|
226
|
+
} catch (error) {
|
227
|
+
console.error("Error rendering component:", error);
|
228
|
+
return document.createTextNode("");
|
229
|
+
}
|
230
|
+
}
|
231
|
+
const element = document.createElement(type);
|
232
|
+
for (const [key, value] of Object.entries(props || {})) {
|
233
|
+
if (key === "children")
|
234
|
+
continue;
|
235
|
+
if (key.startsWith("on") && typeof value === "function") {
|
236
|
+
const eventName = key.toLowerCase().slice(2);
|
237
|
+
const existingHandler = (_a = element.__events) == null ? void 0 : _a[eventName];
|
238
|
+
if (existingHandler) {
|
239
|
+
element.removeEventListener(eventName, existingHandler);
|
240
|
+
}
|
241
|
+
element.addEventListener(eventName, value);
|
242
|
+
if (!element.__events) {
|
243
|
+
element.__events = {};
|
244
|
+
}
|
245
|
+
element.__events[eventName] = value;
|
246
|
+
} else if (key === "style" && typeof value === "object") {
|
247
|
+
Object.assign(element.style, value);
|
248
|
+
} else if (key === "className") {
|
249
|
+
element.setAttribute("class", String(value));
|
250
|
+
} else if (key !== "key" && key !== "ref") {
|
251
|
+
element.setAttribute(key, String(value));
|
252
|
+
}
|
253
|
+
}
|
254
|
+
const children = props == null ? void 0 : props.children;
|
255
|
+
if (children != null) {
|
256
|
+
const childArray = Array.isArray(children) ? children.flat() : [children];
|
257
|
+
for (const child of childArray) {
|
258
|
+
const childNode = await createElement(child);
|
259
|
+
element.appendChild(childNode);
|
260
|
+
}
|
261
|
+
}
|
262
|
+
return element;
|
263
|
+
}
|
264
|
+
return document.createTextNode(String(vnode));
|
265
|
+
}
|
266
|
+
let isHydrating = false;
|
267
|
+
async function hydrate(element, container) {
|
268
|
+
isHydrating = true;
|
269
|
+
try {
|
270
|
+
await render(element, container);
|
271
|
+
} finally {
|
272
|
+
isHydrating = false;
|
273
|
+
}
|
274
|
+
}
|
275
|
+
async function render(element, container) {
|
276
|
+
console.log("Rendering to:", container.id);
|
277
|
+
batchUpdates(async () => {
|
278
|
+
const rendererId = prepareRender();
|
279
|
+
try {
|
280
|
+
setRenderCallback(render, element, container);
|
281
|
+
const domNode = await createElement(element);
|
282
|
+
if (!isHydrating) {
|
283
|
+
container.innerHTML = "";
|
284
|
+
}
|
285
|
+
container.appendChild(domNode);
|
286
|
+
} finally {
|
287
|
+
finishRender();
|
288
|
+
}
|
289
|
+
});
|
290
|
+
}
|
291
|
+
async function renderToString(element) {
|
292
|
+
prepareRender();
|
293
|
+
setRenderCallback(() => {
|
294
|
+
}, element, null);
|
295
|
+
try {
|
296
|
+
if (element == null)
|
297
|
+
return "";
|
298
|
+
if (typeof element === "boolean")
|
299
|
+
return "";
|
300
|
+
if (typeof element === "number" || typeof element === "string") {
|
301
|
+
return escapeHtml(String(element));
|
302
|
+
}
|
303
|
+
if (Array.isArray(element)) {
|
304
|
+
const children = await Promise.all(element.map(renderToString));
|
305
|
+
return children.join("");
|
306
|
+
}
|
307
|
+
if ("type" in element && element.props !== void 0) {
|
308
|
+
const { type, props } = element;
|
309
|
+
if (typeof type === "function") {
|
310
|
+
try {
|
311
|
+
prepareRender();
|
312
|
+
const result = await type(props || {});
|
313
|
+
const html2 = await renderToString(result);
|
314
|
+
finishRender();
|
315
|
+
return html2;
|
316
|
+
} catch (error) {
|
317
|
+
console.error("Error rendering component:", error);
|
318
|
+
return "";
|
319
|
+
}
|
320
|
+
}
|
321
|
+
let html = `<${type}`;
|
322
|
+
for (const [key, value] of Object.entries(props || {})) {
|
323
|
+
if (key === "children")
|
324
|
+
continue;
|
325
|
+
if (key === "className") {
|
326
|
+
html += ` class="${escapeHtml(String(value))}"`;
|
327
|
+
} else if (key === "style" && typeof value === "object") {
|
328
|
+
html += ` style="${stringifyStyle(value || {})}"`;
|
329
|
+
} else if (!key.startsWith("on")) {
|
330
|
+
html += ` ${key}="${escapeHtml(String(value))}"`;
|
331
|
+
}
|
332
|
+
}
|
333
|
+
const voidElements = /* @__PURE__ */ new Set([
|
334
|
+
"area",
|
335
|
+
"base",
|
336
|
+
"br",
|
337
|
+
"col",
|
338
|
+
"embed",
|
339
|
+
"hr",
|
340
|
+
"img",
|
341
|
+
"input",
|
342
|
+
"link",
|
343
|
+
"meta",
|
344
|
+
"param",
|
345
|
+
"source",
|
346
|
+
"track",
|
347
|
+
"wbr"
|
348
|
+
]);
|
349
|
+
if (voidElements.has(type)) {
|
350
|
+
return html + "/>";
|
351
|
+
}
|
352
|
+
html += ">";
|
353
|
+
if (props == null ? void 0 : props.children) {
|
354
|
+
const children = Array.isArray(props.children) ? props.children : [props.children];
|
355
|
+
const renderedChildren = await Promise.all(children.map(renderToString));
|
356
|
+
html += renderedChildren.join("");
|
357
|
+
}
|
358
|
+
return html + `</${type}>`;
|
359
|
+
}
|
360
|
+
return escapeHtml(String(element));
|
361
|
+
} finally {
|
362
|
+
finishRender();
|
363
|
+
}
|
364
|
+
}
|
365
|
+
function escapeHtml(str) {
|
366
|
+
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
367
|
+
}
|
368
|
+
function stringifyStyle(style) {
|
369
|
+
return Object.entries(style).map(([key, value]) => `${hyphenate(key)}:${value}`).join(";");
|
370
|
+
}
|
371
|
+
function hyphenate(str) {
|
372
|
+
return str.replace(/[A-Z]/g, (match) => "-" + match.toLowerCase());
|
373
|
+
}
|
374
|
+
const server = {
|
375
|
+
async getServer() {
|
376
|
+
throw new Error("Server module can only be used in Node.js environment");
|
377
|
+
}
|
378
|
+
};
|
379
|
+
exports2.Fragment = Fragment;
|
380
|
+
exports2.batchUpdates = batchUpdates;
|
381
|
+
exports2.createContext = createContext;
|
382
|
+
exports2.hydrate = hydrate;
|
383
|
+
exports2.jsx = jsx;
|
384
|
+
exports2.jsxs = jsx;
|
385
|
+
exports2.render = render;
|
386
|
+
exports2.renderToString = renderToString;
|
387
|
+
exports2.server = server;
|
388
|
+
exports2.useContext = useContext;
|
389
|
+
exports2.useEffect = useEffect;
|
390
|
+
exports2.useErrorBoundary = useErrorBoundary;
|
391
|
+
exports2.useMemo = useMemo;
|
392
|
+
exports2.useRef = useRef;
|
393
|
+
exports2.useState = useState;
|
394
|
+
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
395
|
+
});
|
396
|
+
//# sourceMappingURL=index.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/batch.ts","../src/hooks.ts","../src/context.ts","../src/jsx-runtime.ts","../src/renderer.ts","../src/server-renderer.ts","../src/index.client.ts"],"sourcesContent":["export let isBatching = false;\r\nconst queue: Function[] = [];\r\n\r\nexport function batchUpdates(fn: Function) {\r\n if (isBatching) {\r\n queue.push(fn);\r\n return;\r\n }\r\n\r\n isBatching = true;\r\n try {\r\n fn();\r\n while (queue.length > 0) {\r\n const nextFn = queue.shift();\r\n nextFn?.();\r\n }\r\n } finally {\r\n isBatching = false;\r\n }\r\n}\r\n\r\nexport function getIsBatching() {\r\n return isBatching;\r\n}\r\n","import { createElement } from './jsx-runtime';\r\nimport { batchUpdates, isBatching } from './batch';\r\nimport { diff } from './vdom';\r\n\r\nlet currentRender: number = 0;\r\nconst states = new Map<number, any[]>();\r\nconst stateIndices = new Map<number, number>();\r\nconst effects = new Map<number, Effect[]>();\r\nconst memos = new Map<number, { value: any; deps: any[] }[]>();\r\nconst refs = new Map<number, any[]>();\r\n\r\ninterface Effect {\r\n cleanup?: () => void;\r\n deps?: any[];\r\n}\r\n\r\n// Add at the top with other declarations\r\nlet globalRenderCallback: ((element: any, container: HTMLElement) => void) | null = null;\r\nlet globalContainer: HTMLElement | null = null;\r\nlet currentElement: any = null;\r\n\r\nconst isServer = typeof window === 'undefined';\r\nconst serverStates = new Map<number, any>();\r\n\r\nexport function setRenderCallback(\r\n callback: (element: any, container: HTMLElement) => void,\r\n element: any,\r\n container: HTMLElement\r\n) {\r\n globalRenderCallback = callback;\r\n globalContainer = container;\r\n currentElement = element;\r\n}\r\n\r\nexport function prepareRender() {\r\n currentRender++;\r\n stateIndices.set(currentRender, 0);\r\n return currentRender;\r\n}\r\n\r\nexport function finishRender() {\r\n if (isServer) {\r\n serverStates.delete(currentRender);\r\n }\r\n currentRender = 0;\r\n}\r\n\r\nexport function useState<T>(initial: T): [T, (value: T | ((prev: T) => T)) => void] {\r\n if (!currentRender) {\r\n throw new Error('useState must be called within a render');\r\n }\r\n\r\n if (isServer) {\r\n // Server-side state handling\r\n if (!serverStates.has(currentRender)) {\r\n serverStates.set(currentRender, new Map());\r\n }\r\n const componentState = serverStates.get(currentRender)!;\r\n const index = stateIndices.get(currentRender) || 0;\r\n \r\n if (!componentState.has(index)) {\r\n componentState.set(index, initial);\r\n }\r\n\r\n const state = componentState.get(index);\r\n const setState = (newValue: T | ((prev: T) => T)) => {\r\n // No-op for server-side\r\n };\r\n\r\n stateIndices.set(currentRender, index + 1);\r\n return [state, setState];\r\n }\r\n\r\n if (!states.has(currentRender)) {\r\n states.set(currentRender, []);\r\n }\r\n\r\n const componentStates = states.get(currentRender)!;\r\n const index = stateIndices.get(currentRender)!;\r\n \r\n if (index >= componentStates.length) {\r\n componentStates.push(initial);\r\n }\r\n\r\n const state = componentStates[index];\r\n const setState = (newValue: T | ((prev: T) => T)) => {\r\n const nextValue = typeof newValue === 'function' \r\n ? (newValue as Function)(componentStates[index])\r\n : newValue;\r\n\r\n if (componentStates[index] === nextValue) return; // Skip if value hasn't changed\r\n \r\n componentStates[index] = nextValue;\r\n \r\n if (isBatching) {\r\n batchUpdates(() => rerender(currentRender));\r\n } else {\r\n rerender(currentRender);\r\n }\r\n };\r\n\r\n stateIndices.set(currentRender, index + 1);\r\n return [state, setState];\r\n}\r\n\r\nexport function useEffect(callback: () => (() => void) | void, deps?: any[]) {\r\n if (!currentRender) throw new Error('useEffect must be called within a render');\r\n \r\n const effectIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!effects.has(currentRender)) {\r\n effects.set(currentRender, []);\r\n }\r\n\r\n const componentEffects = effects.get(currentRender)!;\r\n const prevEffect = componentEffects[effectIndex];\r\n \r\n // Run effect if deps changed\r\n if (!prevEffect || !deps || !prevEffect.deps || \r\n deps.some((dep, i) => dep !== prevEffect.deps![i])) {\r\n \r\n // Cleanup previous effect\r\n if (prevEffect?.cleanup) {\r\n prevEffect.cleanup();\r\n }\r\n\r\n // Schedule new effect\r\n queueMicrotask(() => {\r\n const cleanup = callback() || undefined;\r\n componentEffects[effectIndex] = { cleanup: cleanup, deps };\r\n });\r\n }\r\n \r\n stateIndices.set(currentRender, effectIndex + 1);\r\n}\r\n\r\nexport function useMemo<T>(factory: () => T, deps: any[]): T {\r\n if (!currentRender) throw new Error('useMemo must be called within a render');\r\n \r\n const memoIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!memos.has(currentRender)) {\r\n memos.set(currentRender, []);\r\n }\r\n\r\n const componentMemos = memos.get(currentRender)!;\r\n const prevMemo = componentMemos[memoIndex];\r\n \r\n if (!prevMemo || (deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i])))) {\r\n const value = factory();\r\n componentMemos[memoIndex] = { value, deps };\r\n stateIndices.set(currentRender, memoIndex + 1);\r\n return value;\r\n }\r\n\r\n stateIndices.set(currentRender, memoIndex + 1);\r\n return prevMemo.value;\r\n}\r\n\r\nexport function useRef<T>(initial: T) {\r\n if (!currentRender) throw new Error('useRef must be called within a render');\r\n \r\n const refIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!refs.has(currentRender)) {\r\n refs.set(currentRender, []);\r\n }\r\n\r\n const componentRefs = refs.get(currentRender)!;\r\n if (refIndex >= componentRefs.length) {\r\n // Initialize with an object that has a current property\r\n const ref = { current: initial };\r\n componentRefs.push(ref);\r\n stateIndices.set(currentRender, refIndex + 1);\r\n return ref;\r\n }\r\n\r\n const ref = componentRefs[refIndex];\r\n stateIndices.set(currentRender, refIndex + 1);\r\n return ref;\r\n}\r\n\r\n// Add a map to track component DOM nodes\r\nconst componentNodes = new Map<Function, Node>();\r\n\r\nasync function rerender(rendererId: number) {\r\n try {\r\n // Clean up effects\r\n const componentEffects = effects.get(rendererId);\r\n if (componentEffects) {\r\n componentEffects.forEach(effect => {\r\n if (effect.cleanup) effect.cleanup();\r\n });\r\n effects.set(rendererId, []);\r\n }\r\n\r\n if (globalRenderCallback && globalContainer && currentElement) {\r\n await globalRenderCallback(currentElement, globalContainer);\r\n }\r\n } catch (error) {\r\n console.error('Error during rerender:', error);\r\n }\r\n}\r\n\r\n// Add new hook for error boundaries\r\nexport function useErrorBoundary(): [Error | null, () => void] {\r\n const [error, setError] = useState<Error | null>(null);\r\n return [error, () => setError(null)];\r\n}\r\n\r\n// Remove withHooks export\r\n","\r\n\r\nconst contexts = new Map<symbol, any>();\r\nlet currentRender: Function | null = null;\r\n\r\nexport interface Context<T> {\r\n Provider: (props: { value: T; children?: any }) => any;\r\n Consumer: (props: { children: (value: T) => any }) => any;\r\n _id: symbol;\r\n useSelector: <S>(selector: (state: T) => S) => S;\r\n}\r\n\r\nexport function createContext<T>(defaultValue: T): Context<T> {\r\n const context = {\r\n Provider: ({ value, children }: { value: T, children?: any }) => {\r\n return children;\r\n },\r\n Consumer: ({ children }: { children: (value: T) => any }) => {\r\n return children(defaultValue);\r\n },\r\n _id: Symbol(),\r\n useSelector: <S>(selector: (state: T) => S) => {\r\n return selector(defaultValue);\r\n }\r\n };\r\n\r\n return context;\r\n}\r\n\r\nexport function useContext<T>(context: any): T {\r\n return context;\r\n}\r\n","import type { Component } from './component';\r\n\r\ninterface VNode {\r\n type: string | Function;\r\n props: Record<string, any>;\r\n}\r\n\r\nfunction jsx(type: string | Function, props: any): VNode {\r\n console.log('JSX Transform:', { type, props });\r\n const processedProps = { ...props };\r\n \r\n // Handle children properly\r\n if (arguments.length > 2) {\r\n processedProps.children = Array.prototype.slice.call(arguments, 2);\r\n }\r\n \r\n return { type, props: processedProps };\r\n}\r\n\r\nconst Fragment = ({ children }: { children: any }) => children;\r\n\r\nasync function createElement(vnode: VNode | any): Promise<Node> {\r\n console.log('Creating element from:', vnode);\r\n\r\n // Handle primitives and null\r\n if (vnode == null) {\r\n return document.createTextNode('');\r\n }\r\n \r\n if (typeof vnode === 'boolean') {\r\n return document.createTextNode('');\r\n }\r\n\r\n if (typeof vnode === 'number' || typeof vnode === 'string') {\r\n return document.createTextNode(String(vnode));\r\n }\r\n\r\n // Handle arrays\r\n if (Array.isArray(vnode)) {\r\n const fragment = document.createDocumentFragment();\r\n for (const child of vnode) {\r\n const node = await createElement(child);\r\n fragment.appendChild(node);\r\n }\r\n return fragment;\r\n }\r\n\r\n // Handle VNode\r\n if ('type' in vnode && vnode.props !== undefined) {\r\n const { type, props } = vnode;\r\n \r\n // Handle function components\r\n if (typeof type === 'function') {\r\n try {\r\n const result = await type(props || {});\r\n const node = await createElement(result);\r\n if (node instanceof Element) {\r\n node.setAttribute('data-component-id', type.name || type.toString());\r\n }\r\n return node;\r\n } catch (error) {\r\n console.error('Error rendering component:', error);\r\n return document.createTextNode('');\r\n }\r\n }\r\n\r\n // Create DOM element\r\n const element = document.createElement(type as string);\r\n \r\n // Handle props\r\n for (const [key, value] of Object.entries(props || {})) {\r\n if (key === 'children') continue;\r\n if (key.startsWith('on') && typeof value === 'function') {\r\n const eventName = key.toLowerCase().slice(2);\r\n // Remove existing event listener if any\r\n const existingHandler = (element as any).__events?.[eventName];\r\n if (existingHandler) {\r\n element.removeEventListener(eventName, existingHandler);\r\n }\r\n \r\n // Add new event listener\r\n element.addEventListener(eventName, value as EventListener);\r\n if (!(element as any).__events) {\r\n (element as any).__events = {};\r\n }\r\n (element as any).__events[eventName] = value;\r\n } else if (key === 'style' && typeof value === 'object') {\r\n Object.assign(element.style, value);\r\n } else if (key === 'className') {\r\n element.setAttribute('class', String(value));\r\n } else if (key !== 'key' && key !== 'ref') {\r\n element.setAttribute(key, String(value));\r\n }\r\n }\r\n\r\n // Handle children\r\n const children = props?.children;\r\n if (children != null) {\r\n const childArray = Array.isArray(children) ? children.flat() : [children];\r\n for (const child of childArray) {\r\n const childNode = await createElement(child);\r\n element.appendChild(childNode);\r\n }\r\n }\r\n\r\n return element;\r\n }\r\n\r\n // Handle other objects by converting to string\r\n return document.createTextNode(String(vnode));\r\n}\r\n\r\n// Export named functions and aliases without duplicates\r\nexport {\r\n jsx,\r\n jsx as jsxs,\r\n jsx as jsxDEV,\r\n Fragment,\r\n createElement\r\n};\r\n\r\n// Named exports object\r\nconst jsxRuntime = {\r\n jsx,\r\n jsxs: jsx,\r\n jsxDEV: jsx,\r\n Fragment,\r\n createElement\r\n};\r\n\r\nexport default jsxRuntime;\r\n","import { createElement } from './jsx-runtime';\r\nimport { prepareRender, finishRender, setRenderCallback } from './hooks';\r\nimport { batchUpdates } from './batch';\r\n\r\nlet isHydrating = false;\r\n\r\nexport async function hydrate(element: any, container: HTMLElement) {\r\n isHydrating = true;\r\n try {\r\n await render(element, container);\r\n } finally {\r\n isHydrating = false;\r\n }\r\n}\r\n\r\nexport async function render(element: any, container: HTMLElement) {\r\n console.log('Rendering to:', container.id);\r\n \r\n batchUpdates(async () => {\r\n const rendererId = prepareRender();\r\n try {\r\n setRenderCallback(render, element, container);\r\n const domNode = await createElement(element);\r\n \r\n if (!isHydrating) {\r\n container.innerHTML = '';\r\n }\r\n container.appendChild(domNode);\r\n \r\n } finally {\r\n finishRender();\r\n }\r\n });\r\n}\r\n","import { prepareRender, finishRender, setRenderCallback } from './hooks';\r\n\r\nexport async function renderToString(element: any): Promise<string> {\r\n // Setup render context\r\n const rendererId = prepareRender();\r\n setRenderCallback(() => {}, element, null as any);\r\n \r\n try {\r\n if (element == null) return '';\r\n \r\n if (typeof element === 'boolean') return '';\r\n \r\n if (typeof element === 'number' || typeof element === 'string') {\r\n return escapeHtml(String(element));\r\n }\r\n\r\n if (Array.isArray(element)) {\r\n const children = await Promise.all(element.map(renderToString));\r\n return children.join('');\r\n }\r\n\r\n if ('type' in element && element.props !== undefined) {\r\n const { type, props } = element;\r\n\r\n // Handle function components\r\n if (typeof type === 'function') {\r\n try {\r\n // Prepare new render context for the component\r\n prepareRender();\r\n const result = await type(props || {});\r\n const html = await renderToString(result);\r\n finishRender();\r\n return html;\r\n } catch (error) {\r\n console.error('Error rendering component:', error);\r\n return '';\r\n }\r\n }\r\n\r\n // Handle regular elements\r\n let html = `<${type}`;\r\n\r\n // Add attributes\r\n for (const [key, value] of Object.entries(props || {})) {\r\n if (key === 'children') continue;\r\n if (key === 'className') {\r\n html += ` class=\"${escapeHtml(String(value))}\"`;\r\n } else if (key === 'style' && typeof value === 'object') {\r\n html += ` style=\"${stringifyStyle(value || {})}\"`;\r\n } else if (!key.startsWith('on')) {\r\n html += ` ${key}=\"${escapeHtml(String(value))}\"`;\r\n }\r\n }\r\n\r\n // Handle self-closing tags\r\n const voidElements = new Set([\r\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\r\n 'link', 'meta', 'param', 'source', 'track', 'wbr'\r\n ]);\r\n \r\n if (voidElements.has(type)) {\r\n return html + '/>';\r\n }\r\n\r\n html += '>';\r\n\r\n // Add children\r\n if (props?.children) {\r\n const children = Array.isArray(props.children) ? props.children : [props.children];\r\n const renderedChildren = await Promise.all(children.map(renderToString));\r\n html += renderedChildren.join('');\r\n }\r\n\r\n return html + `</${type}>`;\r\n }\r\n\r\n return escapeHtml(String(element));\r\n } finally {\r\n finishRender();\r\n }\r\n}\r\n\r\nfunction escapeHtml(str: string): string {\r\n return str\r\n .replace(/&/g, '&')\r\n .replace(/</g, '<')\r\n .replace(/>/g, '>')\r\n .replace(/\"/g, '"')\r\n .replace(/'/g, ''');\r\n}\r\n\r\nfunction stringifyStyle(style: Record<string, any>): string {\r\n return Object.entries(style)\r\n .map(([key, value]) => `${hyphenate(key)}:${value}`)\r\n .join(';');\r\n}\r\n\r\nfunction hyphenate(str: string): string {\r\n return str.replace(/[A-Z]/g, match => '-' + match.toLowerCase());\r\n}\r\n","import { createElement } from './jsx-runtime';\r\nimport { prepareRender, finishRender, setRenderCallback } from './hooks';\r\n\r\nexport { \r\n useState, \r\n useEffect, \r\n useMemo, \r\n useRef,\r\n useErrorBoundary \r\n} from './hooks';\r\n\r\nexport { createContext, useContext } from './context';\r\nexport { batchUpdates } from './batch';\r\nexport { jsx, jsxs, Fragment } from './jsx-runtime';\r\nexport { render, hydrate } from './renderer';\r\nexport { renderToString } from './server-renderer';\r\n\r\n// Re-export types for client-side usage\r\nexport type { Context } from './context';\r\nexport type { VNode } from './types';\r\n\r\n// Export a placeholder for server functionality that works in browser environments\r\nexport const server = {\r\n async getServer() {\r\n throw new Error('Server module can only be used in Node.js environment');\r\n }\r\n};\r\n\r\nlet isHydrating = false;\r\n"],"names":["index","state","setState","ref","html"],"mappings":";;;;AAAO,MAAI,aAAa;AACxB,QAAM,QAAoB,CAAA;AAEnB,WAAS,aAAa,IAAc;AACzC,QAAI,YAAY;AACd,YAAM,KAAK,EAAE;AACb;AAAA,IACF;AAEa,iBAAA;AACT,QAAA;AACC;AACI,aAAA,MAAM,SAAS,GAAG;AACjB,cAAA,SAAS,MAAM;AACZ;AAAA,MACX;AAAA,IAAA,UACA;AACa,mBAAA;AAAA,IACf;AAAA,EACF;ACfA,MAAI,gBAAwB;AAC5B,QAAM,6BAAa;AACnB,QAAM,mCAAmB;AACzB,QAAM,8BAAc;AACpB,QAAM,4BAAY;AAClB,QAAM,2BAAW;AAQjB,MAAI,uBAAgF;AACpF,MAAI,kBAAsC;AAC1C,MAAI,iBAAsB;AAE1B,QAAM,WAAW,OAAO,WAAW;AACnC,QAAM,mCAAmB;AAET,WAAA,kBACd,UACA,SACA,WACA;AACuB,2BAAA;AACL,sBAAA;AACD,qBAAA;AAAA,EACnB;AAEO,WAAS,gBAAgB;AAC9B;AACa,iBAAA,IAAI,eAAe,CAAC;AAC1B,WAAA;AAAA,EACT;AAEO,WAAS,eAAe;AAC7B,QAAI,UAAU;AACZ,mBAAa,OAAO,aAAa;AAAA,IACnC;A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