baraqex 1.0.76 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -0
- package/README.md +268 -315
- package/bin/baraqex.js +150 -12
- package/dist/browser.d.ts +1 -1
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +2319 -205
- package/dist/browser.js.map +4 -4
- package/dist/core/batch.d.ts +10 -0
- package/dist/core/batch.d.ts.map +1 -0
- package/dist/core/component.d.ts +69 -0
- package/dist/core/component.d.ts.map +1 -0
- package/dist/core/context.d.ts +22 -0
- package/dist/core/context.d.ts.map +1 -0
- package/dist/core/errors.d.ts +125 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/event-bus.d.ts +29 -0
- package/dist/core/event-bus.d.ts.map +1 -0
- package/dist/core/forms.d.ts +128 -0
- package/dist/core/forms.d.ts.map +1 -0
- package/dist/core/hooks.d.ts +84 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/index.d.ts +23 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/jsx-runtime.d.ts +45 -0
- package/dist/core/jsx-runtime.d.ts.map +1 -0
- package/dist/core/lifecycle-events.d.ts +71 -0
- package/dist/core/lifecycle-events.d.ts.map +1 -0
- package/dist/core/renderer.d.ts +39 -0
- package/dist/core/renderer.d.ts.map +1 -0
- package/dist/core/router.d.ts +108 -0
- package/dist/core/router.d.ts.map +1 -0
- package/dist/core/server-renderer.d.ts +26 -0
- package/dist/core/server-renderer.d.ts.map +1 -0
- package/dist/core/store.d.ts +102 -0
- package/dist/core/store.d.ts.map +1 -0
- package/dist/core/types.d.ts +66 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/utils.d.ts +153 -0
- package/dist/core/utils.d.ts.map +1 -0
- package/dist/core/vdom.d.ts +29 -0
- package/dist/core/vdom.d.ts.map +1 -0
- package/dist/index.d.ts +39 -35
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2592 -508
- package/dist/index.js.map +4 -4
- package/dist/server/auth.d.ts +8 -3
- package/dist/server/auth.d.ts.map +1 -1
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +173 -112
- package/dist/server/index.js.map +4 -4
- package/dist/server/middleware.d.ts +10 -1
- package/dist/server/middleware.d.ts.map +1 -1
- package/package.json +224 -124
- package/templates/basic-app/src/main.jsx +336 -0
- package/templates/complete-app/api/hello.js +0 -0
- package/templates/complete-app/client.js +58 -0
- package/templates/complete-app/lib/frontend-hamroun.js +182 -0
- package/templates/complete-app/package.json +18 -0
- package/templates/complete-app/pages/about.js +119 -0
- package/templates/complete-app/pages/about.jsx +0 -0
- package/templates/complete-app/pages/index.js +157 -0
- package/templates/complete-app/pages/index.jsx +0 -0
- package/templates/complete-app/pages/wasm-demo.js +290 -0
- package/templates/complete-app/pages/wasm-demo.jsx +0 -0
- package/templates/complete-app/public/client.js +89 -0
- package/templates/complete-app/public/index.html +118 -0
- package/templates/complete-app/public/styles.css +76 -0
- package/templates/complete-app/readme.md +188 -0
- package/templates/complete-app/server.js +226 -0
- package/templates/complete-app/server.ts +275 -0
- package/templates/complete-app/src/App.tsx +59 -0
- package/templates/complete-app/src/client.ts +61 -0
- package/templates/complete-app/src/client.tsx +18 -0
- package/templates/complete-app/src/pages/index.tsx +51 -0
- package/templates/complete-app/src/server.ts +218 -0
- package/templates/complete-app/tsconfig.json +22 -0
- package/templates/complete-app/tsconfig.server.json +19 -0
- package/templates/complete-app/vite.config.js +57 -0
- package/templates/complete-app/vite.config.ts +30 -0
- package/templates/complete-app/wasm/build.bat +0 -0
- package/templates/complete-app/wasm/build.sh +0 -0
- package/templates/complete-app/wasm/example.go +0 -0
- package/templates/fullstack-app/README.md +37 -0
- package/templates/fullstack-app/api/hello.js +11 -0
- 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/build/main.css +874 -0
- package/templates/fullstack-app/build/main.css.map +7 -0
- package/templates/fullstack-app/build/main.js +967 -0
- package/templates/fullstack-app/build/main.js.map +7 -0
- package/templates/fullstack-app/build.ts +210 -0
- package/templates/fullstack-app/index.html +36 -0
- package/templates/fullstack-app/package.json +35 -0
- package/templates/fullstack-app/postcss.config.js +6 -0
- package/templates/fullstack-app/process-tailwind.js +45 -0
- package/templates/fullstack-app/public/_redirects +1 -0
- package/templates/fullstack-app/public/route-handler.js +47 -0
- package/templates/fullstack-app/public/spa-fix.html +17 -0
- package/templates/fullstack-app/public/styles.css +975 -0
- package/templates/fullstack-app/public/tailwind.css +15 -0
- package/templates/fullstack-app/server.js +267 -0
- package/templates/fullstack-app/server.ts +474 -0
- package/templates/fullstack-app/src/README.md +55 -0
- package/templates/fullstack-app/src/client.js +87 -0
- package/templates/fullstack-app/src/components/ClientHome.tsx +0 -0
- package/templates/fullstack-app/src/components/ErrorBoundary.tsx +36 -0
- package/templates/fullstack-app/src/components/Layout.tsx +42 -0
- package/templates/fullstack-app/src/components/StateDemo.tsx +207 -0
- package/templates/fullstack-app/src/components/UserList.tsx +44 -0
- package/templates/fullstack-app/src/config.ts +42 -0
- package/templates/fullstack-app/src/data/api.ts +206 -0
- package/templates/fullstack-app/src/main.tsx +155 -0
- package/templates/fullstack-app/src/middleware.ts +28 -0
- package/templates/fullstack-app/src/pages/404.tsx +28 -0
- package/templates/fullstack-app/src/pages/[id].tsx +0 -0
- package/templates/fullstack-app/src/pages/_app.tsx +11 -0
- package/templates/fullstack-app/src/pages/_document.tsx +25 -0
- package/templates/fullstack-app/src/pages/_error.tsx +45 -0
- package/templates/fullstack-app/src/pages/about/index.tsx +67 -0
- package/templates/fullstack-app/src/pages/about.tsx +71 -0
- package/templates/fullstack-app/src/pages/api/users/[id].ts +73 -0
- package/templates/fullstack-app/src/pages/api/users/index.ts +43 -0
- package/templates/fullstack-app/src/pages/index.tsx +110 -0
- package/templates/fullstack-app/src/pages/users/[id].tsx +153 -0
- package/templates/fullstack-app/src/pages/users.tsx +60 -0
- package/templates/fullstack-app/src/pages/wasm-demo.tsx +1 -0
- package/templates/fullstack-app/src/router.ts +255 -0
- package/templates/fullstack-app/src/styles.css +5 -0
- package/templates/fullstack-app/tailwind.config.js +11 -0
- package/templates/fullstack-app/tsconfig.json +18 -0
- package/templates/fullstack-app/vite.config.js +87 -0
- package/templates/go/build.bat +36 -0
- package/templates/go/build.sh +43 -0
- package/templates/go/example.go +205 -0
- package/templates/go-wasm-app/README.md +38 -0
- package/templates/go-wasm-app/babel.config.js +21 -0
- package/templates/go-wasm-app/build-client.js +49 -0
- package/templates/go-wasm-app/build-wasm.js +237 -0
- package/templates/go-wasm-app/build.config.js +62 -0
- package/templates/go-wasm-app/build.js +218 -0
- package/templates/go-wasm-app/package.json +32 -0
- package/templates/go-wasm-app/public/index.html +128 -0
- package/templates/go-wasm-app/public/styles.css +197 -0
- package/templates/go-wasm-app/public/wasm/example.wasm +0 -0
- package/templates/go-wasm-app/public/wasm/wasm_exec.js +561 -0
- package/templates/go-wasm-app/public/wasm/wasm_exec_node.js +39 -0
- package/templates/go-wasm-app/server.js +70 -0
- package/templates/go-wasm-app/src/App.jsx +38 -0
- package/templates/go-wasm-app/src/app.js +173 -0
- package/templates/go-wasm-app/src/client.js +57 -0
- package/templates/go-wasm-app/src/components/Footer.jsx +13 -0
- package/templates/go-wasm-app/src/components/Header.jsx +19 -0
- package/templates/go-wasm-app/src/components/WasmDemo.jsx +120 -0
- package/templates/go-wasm-app/src/main.jsx +12 -0
- package/templates/go-wasm-app/src/wasm/example.go +75 -0
- package/templates/go-wasm-app/tsconfig.server.json +18 -0
- package/templates/go-wasm-app/vite.config.js +45 -0
- package/dist/forms/index.d.ts +0 -2
- package/dist/forms/index.d.ts.map +0 -1
- package/dist/forms/types.d.ts +0 -2
- package/dist/forms/types.d.ts.map +0 -1
- package/dist/frontend/components/WasmLoader.d.ts +0 -2
- package/dist/frontend/components/WasmLoader.d.ts.map +0 -1
- package/dist/frontend/hooks/useWasm.d.ts +0 -2
- package/dist/frontend/hooks/useWasm.d.ts.map +0 -1
- package/dist/frontend/index.d.ts +0 -2
- package/dist/frontend/index.d.ts.map +0 -1
- package/dist/router/index.d.ts +0 -2
- package/dist/router/index.d.ts.map +0 -1
- package/dist/router/types.d.ts +0 -2
- package/dist/router/types.d.ts.map +0 -1
- package/dist/store/index.d.ts +0 -2
- package/dist/store/index.d.ts.map +0 -1
- package/dist/store/types.d.ts +0 -2
- package/dist/store/types.d.ts.map +0 -1
- package/templates/basic-app/package-lock.json +0 -7173
- package/templates/fullstack-template/package-lock.json +0 -3558
- package/templates/ssr-template/package-lock.json +0 -5380
- package/templates/wasm/package-lock.json +0 -5347
- package/templates/wasm/public/example.wasm +0 -0
package/dist/index.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3
|
-
var
|
|
4
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
5
|
-
}) : x)(function(x) {
|
|
6
|
-
if (typeof require !== "undefined")
|
|
7
|
-
return require.apply(this, arguments);
|
|
8
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
9
|
-
});
|
|
3
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
4
|
var __esm = (fn, res) => function __init() {
|
|
11
5
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
12
6
|
};
|
|
@@ -14,324 +8,387 @@ var __export = (target, all) => {
|
|
|
14
8
|
for (var name in all)
|
|
15
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
10
|
};
|
|
11
|
+
var __publicField = (obj, key, value) => {
|
|
12
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
13
|
+
return value;
|
|
14
|
+
};
|
|
17
15
|
|
|
18
|
-
//
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
16
|
+
// src/core/context.ts
|
|
17
|
+
function createContext(defaultValue) {
|
|
18
|
+
const id = Symbol("context");
|
|
19
|
+
contextStacks.set(id, []);
|
|
20
|
+
const context = {
|
|
21
|
+
Provider: ({ value, children }) => {
|
|
22
|
+
const stack = contextStacks.get(id);
|
|
23
|
+
stack.push(value);
|
|
24
|
+
const result = children;
|
|
25
|
+
stack.pop();
|
|
26
|
+
return result;
|
|
27
|
+
},
|
|
28
|
+
Consumer: ({ children }) => {
|
|
29
|
+
const stack = contextStacks.get(id);
|
|
30
|
+
const value = stack && stack.length > 0 ? stack[stack.length - 1] : defaultValue;
|
|
31
|
+
return children(value);
|
|
32
|
+
},
|
|
33
|
+
_id: id,
|
|
34
|
+
_defaultValue: defaultValue,
|
|
35
|
+
useSelector: (selector) => {
|
|
36
|
+
const stack = contextStacks.get(id);
|
|
37
|
+
const value = stack && stack.length > 0 ? stack[stack.length - 1] : defaultValue;
|
|
38
|
+
return selector(value);
|
|
30
39
|
}
|
|
31
|
-
}
|
|
32
|
-
|
|
40
|
+
};
|
|
41
|
+
return context;
|
|
42
|
+
}
|
|
43
|
+
function useContext(context) {
|
|
44
|
+
const stack = contextStacks.get(context._id);
|
|
45
|
+
if (stack && stack.length > 0) {
|
|
46
|
+
return stack[stack.length - 1];
|
|
33
47
|
}
|
|
48
|
+
return context._defaultValue;
|
|
34
49
|
}
|
|
35
|
-
function
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
50
|
+
function getContextValue(context) {
|
|
51
|
+
return useContext(context);
|
|
52
|
+
}
|
|
53
|
+
var contextStacks;
|
|
54
|
+
var init_context = __esm({
|
|
55
|
+
"src/core/context.ts"() {
|
|
56
|
+
"use strict";
|
|
57
|
+
contextStacks = /* @__PURE__ */ new Map();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// src/core/hooks.ts
|
|
62
|
+
function createRootState() {
|
|
63
|
+
return {
|
|
64
|
+
id: ++rootIdCounter,
|
|
65
|
+
components: /* @__PURE__ */ new Map(),
|
|
66
|
+
nextComponentId: 0,
|
|
67
|
+
renderCallback: null,
|
|
68
|
+
container: null,
|
|
69
|
+
currentElement: null
|
|
70
|
+
};
|
|
39
71
|
}
|
|
40
|
-
function prepareRender() {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
72
|
+
function prepareRender(root, componentId) {
|
|
73
|
+
if (root) {
|
|
74
|
+
currentRoot = root;
|
|
75
|
+
}
|
|
76
|
+
if (componentId !== void 0) {
|
|
77
|
+
currentComponentId = componentId;
|
|
78
|
+
} else if (currentRoot) {
|
|
79
|
+
currentComponentId = ++currentRoot.nextComponentId;
|
|
80
|
+
}
|
|
81
|
+
hookIndex = 0;
|
|
82
|
+
return currentComponentId || 0;
|
|
44
83
|
}
|
|
45
84
|
function finishRender() {
|
|
46
|
-
|
|
47
|
-
|
|
85
|
+
currentComponentId = null;
|
|
86
|
+
}
|
|
87
|
+
function getCurrentRoot() {
|
|
88
|
+
return currentRoot;
|
|
89
|
+
}
|
|
90
|
+
function setCurrentRoot(root) {
|
|
91
|
+
currentRoot = root;
|
|
92
|
+
}
|
|
93
|
+
function getComponentState(root, compId) {
|
|
94
|
+
let state = root.components.get(compId);
|
|
95
|
+
if (!state) {
|
|
96
|
+
state = { states: [], effects: [], memos: [], refs: [] };
|
|
97
|
+
root.components.set(compId, state);
|
|
48
98
|
}
|
|
49
|
-
|
|
99
|
+
return state;
|
|
100
|
+
}
|
|
101
|
+
function setRenderCallback(callback, element, container) {
|
|
102
|
+
if (!currentRoot)
|
|
103
|
+
return;
|
|
104
|
+
currentRoot.renderCallback = callback;
|
|
105
|
+
currentRoot.currentElement = element;
|
|
106
|
+
currentRoot.container = container;
|
|
50
107
|
}
|
|
51
108
|
function useState(initial) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
const componentState = serverStates.get(currentRender);
|
|
60
|
-
const index2 = stateIndices.get(currentRender) || 0;
|
|
61
|
-
if (!componentState.has(index2)) {
|
|
62
|
-
componentState.set(index2, initial);
|
|
109
|
+
const root = currentRoot;
|
|
110
|
+
const compId = currentComponentId;
|
|
111
|
+
if (!root || compId === null) {
|
|
112
|
+
if (isServer) {
|
|
113
|
+
return [initial, () => {
|
|
114
|
+
}];
|
|
63
115
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
stateIndices.set(currentRender, index2 + 1);
|
|
68
|
-
return [state2, setState2];
|
|
69
|
-
}
|
|
70
|
-
if (!states.has(currentRender)) {
|
|
71
|
-
states.set(currentRender, []);
|
|
116
|
+
console.warn("useState called outside of render context");
|
|
117
|
+
return [initial, () => {
|
|
118
|
+
}];
|
|
72
119
|
}
|
|
73
|
-
const
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
120
|
+
const compState = getComponentState(root, compId);
|
|
121
|
+
const currentIndex = hookIndex;
|
|
122
|
+
hookIndex++;
|
|
123
|
+
if (currentIndex >= compState.states.length) {
|
|
124
|
+
compState.states.push(initial);
|
|
77
125
|
}
|
|
78
|
-
const state =
|
|
126
|
+
const state = compState.states[currentIndex];
|
|
79
127
|
const setState = (newValue) => {
|
|
80
|
-
const
|
|
81
|
-
|
|
128
|
+
const currentState = compState.states[currentIndex];
|
|
129
|
+
const value = typeof newValue === "function" ? newValue(currentState) : newValue;
|
|
130
|
+
if (Object.is(currentState, value))
|
|
82
131
|
return;
|
|
83
|
-
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
} else {
|
|
87
|
-
rerender(currentRender);
|
|
132
|
+
compState.states[currentIndex] = value;
|
|
133
|
+
if (root.renderCallback && root.container && root.currentElement) {
|
|
134
|
+
root.renderCallback(root.currentElement, root.container);
|
|
88
135
|
}
|
|
89
136
|
};
|
|
90
|
-
stateIndices.set(currentRender, index + 1);
|
|
91
137
|
return [state, setState];
|
|
92
138
|
}
|
|
93
139
|
function useEffect(callback, deps) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const prevEffect =
|
|
102
|
-
|
|
103
|
-
|
|
140
|
+
const root = currentRoot;
|
|
141
|
+
const compId = currentComponentId;
|
|
142
|
+
if (!root || compId === null || isServer)
|
|
143
|
+
return;
|
|
144
|
+
const compState = getComponentState(root, compId);
|
|
145
|
+
const currentIndex = hookIndex;
|
|
146
|
+
hookIndex++;
|
|
147
|
+
const prevEffect = compState.effects[currentIndex];
|
|
148
|
+
const shouldRun = !prevEffect || !deps || !prevEffect.deps || deps.some((dep, i) => !Object.is(dep, prevEffect.deps?.[i]));
|
|
149
|
+
if (shouldRun) {
|
|
150
|
+
if (prevEffect?.cleanup) {
|
|
104
151
|
prevEffect.cleanup();
|
|
105
152
|
}
|
|
106
153
|
queueMicrotask(() => {
|
|
107
|
-
const cleanup = callback()
|
|
108
|
-
|
|
154
|
+
const cleanup = callback();
|
|
155
|
+
compState.effects[currentIndex] = {
|
|
156
|
+
callback,
|
|
157
|
+
deps,
|
|
158
|
+
cleanup: typeof cleanup === "function" ? cleanup : void 0
|
|
159
|
+
};
|
|
109
160
|
});
|
|
110
161
|
}
|
|
111
|
-
|
|
162
|
+
if (!prevEffect) {
|
|
163
|
+
compState.effects.push({ callback, deps });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function useLayoutEffect(callback, deps) {
|
|
167
|
+
if (isServer)
|
|
168
|
+
return;
|
|
169
|
+
const root = currentRoot;
|
|
170
|
+
const compId = currentComponentId;
|
|
171
|
+
if (!root || compId === null)
|
|
172
|
+
return;
|
|
173
|
+
const compState = getComponentState(root, compId);
|
|
174
|
+
const currentIndex = hookIndex;
|
|
175
|
+
hookIndex++;
|
|
176
|
+
const prevEffect = compState.effects[currentIndex];
|
|
177
|
+
const shouldRun = !prevEffect || !deps || !prevEffect.deps || deps.some((dep, i) => !Object.is(dep, prevEffect.deps?.[i]));
|
|
178
|
+
if (shouldRun) {
|
|
179
|
+
if (prevEffect?.cleanup) {
|
|
180
|
+
prevEffect.cleanup();
|
|
181
|
+
}
|
|
182
|
+
const cleanup = callback();
|
|
183
|
+
compState.effects[currentIndex] = {
|
|
184
|
+
callback,
|
|
185
|
+
deps,
|
|
186
|
+
cleanup: typeof cleanup === "function" ? cleanup : void 0
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
if (!prevEffect) {
|
|
190
|
+
compState.effects.push({ callback, deps });
|
|
191
|
+
}
|
|
112
192
|
}
|
|
113
193
|
function useMemo(factory, deps) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
194
|
+
const root = currentRoot;
|
|
195
|
+
const compId = currentComponentId;
|
|
196
|
+
if (!root || compId === null) {
|
|
197
|
+
return factory();
|
|
198
|
+
}
|
|
199
|
+
const compState = getComponentState(root, compId);
|
|
200
|
+
const currentIndex = hookIndex;
|
|
201
|
+
hookIndex++;
|
|
202
|
+
const prevMemo = compState.memos[currentIndex];
|
|
203
|
+
const shouldRecalculate = !prevMemo || !deps || !prevMemo.deps || deps.some((dep, i) => !Object.is(dep, prevMemo.deps?.[i]));
|
|
204
|
+
if (shouldRecalculate) {
|
|
123
205
|
const value = factory();
|
|
124
|
-
|
|
125
|
-
stateIndices.set(currentRender, memoIndex + 1);
|
|
206
|
+
compState.memos[currentIndex] = { value, deps };
|
|
126
207
|
return value;
|
|
127
208
|
}
|
|
128
|
-
stateIndices.set(currentRender, memoIndex + 1);
|
|
129
209
|
return prevMemo.value;
|
|
130
210
|
}
|
|
211
|
+
function useCallback(callback, deps) {
|
|
212
|
+
return useMemo(() => callback, deps);
|
|
213
|
+
}
|
|
131
214
|
function useRef(initial) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
refs.set(currentRender, []);
|
|
137
|
-
}
|
|
138
|
-
const componentRefs = refs.get(currentRender);
|
|
139
|
-
if (refIndex >= componentRefs.length) {
|
|
140
|
-
const ref2 = { current: initial };
|
|
141
|
-
componentRefs.push(ref2);
|
|
142
|
-
stateIndices.set(currentRender, refIndex + 1);
|
|
143
|
-
return ref2;
|
|
144
|
-
}
|
|
145
|
-
const ref = componentRefs[refIndex];
|
|
146
|
-
stateIndices.set(currentRender, refIndex + 1);
|
|
147
|
-
return ref;
|
|
148
|
-
}
|
|
149
|
-
async function rerender(rendererId) {
|
|
150
|
-
try {
|
|
151
|
-
const componentEffects = effects.get(rendererId);
|
|
152
|
-
if (componentEffects) {
|
|
153
|
-
componentEffects.forEach((effect) => {
|
|
154
|
-
if (effect.cleanup)
|
|
155
|
-
effect.cleanup();
|
|
156
|
-
});
|
|
157
|
-
effects.set(rendererId, []);
|
|
158
|
-
}
|
|
159
|
-
if (globalRenderCallback && globalContainer && currentElement) {
|
|
160
|
-
await globalRenderCallback(currentElement, globalContainer);
|
|
161
|
-
}
|
|
162
|
-
} catch (error) {
|
|
163
|
-
console.error("Error during rerender:", error);
|
|
215
|
+
const root = currentRoot;
|
|
216
|
+
const compId = currentComponentId;
|
|
217
|
+
if (!root || compId === null) {
|
|
218
|
+
return { current: initial };
|
|
164
219
|
}
|
|
220
|
+
const compState = getComponentState(root, compId);
|
|
221
|
+
const currentIndex = hookIndex;
|
|
222
|
+
hookIndex++;
|
|
223
|
+
if (compState.refs[currentIndex] === void 0) {
|
|
224
|
+
compState.refs[currentIndex] = { current: initial };
|
|
225
|
+
}
|
|
226
|
+
return compState.refs[currentIndex];
|
|
165
227
|
}
|
|
166
|
-
function
|
|
167
|
-
const [
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
function createContext(defaultValue) {
|
|
171
|
-
const context = {
|
|
172
|
-
Provider: ({ value, children }) => {
|
|
173
|
-
return children;
|
|
174
|
-
},
|
|
175
|
-
Consumer: ({ children }) => {
|
|
176
|
-
return children(defaultValue);
|
|
177
|
-
},
|
|
178
|
-
_id: Symbol(),
|
|
179
|
-
useSelector: (selector) => {
|
|
180
|
-
return selector(defaultValue);
|
|
181
|
-
}
|
|
228
|
+
function useReducer(reducer, initialState) {
|
|
229
|
+
const [state, setState] = useState(initialState);
|
|
230
|
+
const dispatch = (action) => {
|
|
231
|
+
setState((prevState) => reducer(prevState, action));
|
|
182
232
|
};
|
|
183
|
-
return
|
|
233
|
+
return [state, dispatch];
|
|
184
234
|
}
|
|
185
|
-
function
|
|
186
|
-
|
|
235
|
+
function useErrorBoundary() {
|
|
236
|
+
const [error, setError] = useState(null);
|
|
237
|
+
const resetError = () => setError(null);
|
|
238
|
+
return [error, resetError];
|
|
187
239
|
}
|
|
188
|
-
function
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
processedProps.children = Array.prototype.slice.call(arguments, 2);
|
|
240
|
+
function useId() {
|
|
241
|
+
const ref = useRef(null);
|
|
242
|
+
if (ref.current === null) {
|
|
243
|
+
ref.current = `baraqex-id-${++idCounter}`;
|
|
193
244
|
}
|
|
194
|
-
return
|
|
245
|
+
return ref.current;
|
|
195
246
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
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;
|
|
247
|
+
function cleanupHooks(root, compId) {
|
|
248
|
+
const compState = root.components.get(compId);
|
|
249
|
+
if (compState) {
|
|
250
|
+
compState.effects.forEach((effect) => {
|
|
251
|
+
if (effect.cleanup)
|
|
252
|
+
effect.cleanup();
|
|
253
|
+
});
|
|
254
|
+
root.components.delete(compId);
|
|
263
255
|
}
|
|
264
|
-
return document.createTextNode(String(vnode));
|
|
265
256
|
}
|
|
266
|
-
|
|
267
|
-
|
|
257
|
+
function cleanupRoot(root) {
|
|
258
|
+
root.components.forEach((compState) => {
|
|
259
|
+
compState.effects.forEach((effect) => {
|
|
260
|
+
if (effect.cleanup)
|
|
261
|
+
effect.cleanup();
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
root.components.clear();
|
|
265
|
+
}
|
|
266
|
+
var rootIdCounter, currentRoot, currentComponentId, hookIndex, isServer, idCounter;
|
|
267
|
+
var init_hooks = __esm({
|
|
268
|
+
"src/core/hooks.ts"() {
|
|
269
|
+
"use strict";
|
|
270
|
+
rootIdCounter = 0;
|
|
271
|
+
currentRoot = null;
|
|
272
|
+
currentComponentId = null;
|
|
273
|
+
hookIndex = 0;
|
|
274
|
+
isServer = typeof window === "undefined";
|
|
275
|
+
idCounter = 0;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
// src/core/server-renderer.ts
|
|
280
|
+
function renderToString(vnode) {
|
|
281
|
+
prepareRender();
|
|
268
282
|
try {
|
|
269
|
-
|
|
283
|
+
return renderNodeToString(vnode);
|
|
270
284
|
} finally {
|
|
271
|
-
|
|
285
|
+
finishRender();
|
|
272
286
|
}
|
|
273
287
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const rendererId = prepareRender();
|
|
278
|
-
try {
|
|
279
|
-
setRenderCallback(render, element, container);
|
|
280
|
-
const domNode = await createElement(element);
|
|
281
|
-
if (!isHydrating) {
|
|
282
|
-
container.innerHTML = "";
|
|
283
|
-
}
|
|
284
|
-
container.appendChild(domNode);
|
|
285
|
-
} finally {
|
|
286
|
-
finishRender();
|
|
287
|
-
}
|
|
288
|
-
});
|
|
288
|
+
function renderToStringWithData(vnode) {
|
|
289
|
+
const html = renderToString(vnode);
|
|
290
|
+
return { html, data: {} };
|
|
289
291
|
}
|
|
290
|
-
function
|
|
291
|
-
|
|
292
|
-
const html = renderNodeToString(vnode);
|
|
293
|
-
finishRender();
|
|
294
|
-
return html;
|
|
292
|
+
async function* renderToStream(vnode) {
|
|
293
|
+
yield renderToString(vnode);
|
|
295
294
|
}
|
|
296
295
|
function renderNodeToString(vnode) {
|
|
297
|
-
var _a, _b, _c;
|
|
298
296
|
if (vnode === null || vnode === void 0)
|
|
299
297
|
return "";
|
|
300
298
|
if (typeof vnode === "boolean")
|
|
301
299
|
return "";
|
|
302
300
|
if (typeof vnode === "number" || typeof vnode === "string")
|
|
303
301
|
return escapeHtml(String(vnode));
|
|
304
|
-
if (
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
302
|
+
if (Array.isArray(vnode)) {
|
|
303
|
+
return vnode.map((child) => renderNodeToString(child)).join("");
|
|
304
|
+
}
|
|
305
|
+
if (typeof vnode !== "object" || vnode.type === void 0) {
|
|
306
|
+
return escapeHtml(String(vnode));
|
|
307
|
+
}
|
|
308
|
+
const { type, props } = vnode;
|
|
309
|
+
if (typeof type === "function") {
|
|
310
|
+
if (type.name === "Fragment" || type === Symbol.for("react.fragment")) {
|
|
311
|
+
const children = props?.children;
|
|
312
|
+
if (children == null)
|
|
313
|
+
return "";
|
|
314
|
+
return Array.isArray(children) ? children.map((child) => renderNodeToString(child)).join("") : renderNodeToString(children);
|
|
315
|
+
}
|
|
316
|
+
const Component2 = type;
|
|
317
|
+
try {
|
|
318
|
+
const renderedNode = Component2(props || {});
|
|
319
|
+
return renderNodeToString(renderedNode);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
console.error("Error rendering component:", error);
|
|
322
|
+
return `<!-- Error rendering component: ${escapeHtml(String(error))} -->`;
|
|
323
|
+
}
|
|
308
324
|
}
|
|
309
|
-
if (typeof
|
|
310
|
-
const tag =
|
|
325
|
+
if (typeof type === "string") {
|
|
326
|
+
const tag = type;
|
|
311
327
|
let attrs = "";
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
for (const [key, value] of Object.entries(vnode.props)) {
|
|
328
|
+
if (props) {
|
|
329
|
+
for (const [key, value] of Object.entries(props)) {
|
|
315
330
|
if (key === "children")
|
|
316
331
|
continue;
|
|
317
|
-
if (key
|
|
332
|
+
if (key === "dangerouslySetInnerHTML")
|
|
333
|
+
continue;
|
|
334
|
+
if (key === "ref")
|
|
335
|
+
continue;
|
|
336
|
+
if (value === void 0 || value === null || value === false)
|
|
318
337
|
continue;
|
|
319
|
-
|
|
320
|
-
|
|
338
|
+
let attrName = key;
|
|
339
|
+
let attrValue = value;
|
|
340
|
+
if (key === "className")
|
|
341
|
+
attrName = "class";
|
|
342
|
+
else if (key === "htmlFor")
|
|
343
|
+
attrName = "for";
|
|
344
|
+
else if (key === "tabIndex")
|
|
345
|
+
attrName = "tabindex";
|
|
346
|
+
if (attrName.startsWith("on") && typeof value === "function")
|
|
321
347
|
continue;
|
|
348
|
+
if (attrName === "style" && typeof value === "object") {
|
|
349
|
+
attrValue = Object.entries(value).map(([prop, val]) => {
|
|
350
|
+
const cssProperty = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
351
|
+
return `${cssProperty}: ${val}`;
|
|
352
|
+
}).join("; ");
|
|
322
353
|
}
|
|
323
|
-
if (
|
|
324
|
-
attrs += ` ${
|
|
325
|
-
} else
|
|
326
|
-
attrs += ` ${
|
|
354
|
+
if (value === true) {
|
|
355
|
+
attrs += ` ${attrName}`;
|
|
356
|
+
} else {
|
|
357
|
+
attrs += ` ${attrName}="${escapeHtml(String(attrValue))}"`;
|
|
327
358
|
}
|
|
328
359
|
}
|
|
329
360
|
}
|
|
330
|
-
|
|
361
|
+
if (VOID_ELEMENTS.has(tag)) {
|
|
362
|
+
return `<${tag}${attrs} />`;
|
|
363
|
+
}
|
|
364
|
+
if (props?.dangerouslySetInnerHTML?.__html) {
|
|
365
|
+
return `<${tag}${attrs}>${props.dangerouslySetInnerHTML.__html}</${tag}>`;
|
|
366
|
+
}
|
|
367
|
+
let children = "";
|
|
368
|
+
const childrenArray = props?.children ? Array.isArray(props.children) ? props.children : [props.children] : [];
|
|
331
369
|
for (const child of childrenArray) {
|
|
332
370
|
children += renderNodeToString(child);
|
|
333
371
|
}
|
|
334
|
-
|
|
372
|
+
return `<${tag}${attrs}>${children}</${tag}>`;
|
|
373
|
+
}
|
|
374
|
+
if (type === Symbol.for("react.fragment")) {
|
|
375
|
+
const children = props?.children;
|
|
376
|
+
if (children == null)
|
|
377
|
+
return "";
|
|
378
|
+
return Array.isArray(children) ? children.map((child) => renderNodeToString(child)).join("") : renderNodeToString(children);
|
|
379
|
+
}
|
|
380
|
+
console.warn("Unknown vnode type:", type);
|
|
381
|
+
return "";
|
|
382
|
+
}
|
|
383
|
+
function escapeHtml(text) {
|
|
384
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
385
|
+
}
|
|
386
|
+
var VOID_ELEMENTS;
|
|
387
|
+
var init_server_renderer = __esm({
|
|
388
|
+
"src/core/server-renderer.ts"() {
|
|
389
|
+
"use strict";
|
|
390
|
+
init_hooks();
|
|
391
|
+
VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
335
392
|
"area",
|
|
336
393
|
"base",
|
|
337
394
|
"br",
|
|
@@ -346,49 +403,7 @@ function renderNodeToString(vnode) {
|
|
|
346
403
|
"source",
|
|
347
404
|
"track",
|
|
348
405
|
"wbr"
|
|
349
|
-
];
|
|
350
|
-
if (selfClosing.includes(tag)) {
|
|
351
|
-
return `<${tag}${attrs}/>`;
|
|
352
|
-
}
|
|
353
|
-
return `<${tag}${attrs}>${children}</${tag}>`;
|
|
354
|
-
}
|
|
355
|
-
if (vnode.type === Symbol.for("react.fragment")) {
|
|
356
|
-
let fragmentOutput = "";
|
|
357
|
-
const children = Array.isArray((_b = vnode.props) == null ? void 0 : _b.children) ? vnode.props.children : ((_c = vnode.props) == null ? void 0 : _c.children) ? [vnode.props.children] : [];
|
|
358
|
-
for (const child of children) {
|
|
359
|
-
fragmentOutput += renderNodeToString(child);
|
|
360
|
-
}
|
|
361
|
-
return fragmentOutput;
|
|
362
|
-
}
|
|
363
|
-
console.warn("Unknown vnode type:", vnode.type);
|
|
364
|
-
return "";
|
|
365
|
-
}
|
|
366
|
-
function escapeHtml(text) {
|
|
367
|
-
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
368
|
-
}
|
|
369
|
-
var isBatching, queue, currentRender, states, stateIndices, effects, memos, refs, globalRenderCallback, globalContainer, currentElement, isServer, serverStates, Fragment, isHydrating, server;
|
|
370
|
-
var init_dist = __esm({
|
|
371
|
-
"node_modules/frontend-hamroun/dist/index.mjs"() {
|
|
372
|
-
isBatching = false;
|
|
373
|
-
queue = [];
|
|
374
|
-
currentRender = 0;
|
|
375
|
-
states = /* @__PURE__ */ new Map();
|
|
376
|
-
stateIndices = /* @__PURE__ */ new Map();
|
|
377
|
-
effects = /* @__PURE__ */ new Map();
|
|
378
|
-
memos = /* @__PURE__ */ new Map();
|
|
379
|
-
refs = /* @__PURE__ */ new Map();
|
|
380
|
-
globalRenderCallback = null;
|
|
381
|
-
globalContainer = null;
|
|
382
|
-
currentElement = null;
|
|
383
|
-
isServer = typeof window === "undefined";
|
|
384
|
-
serverStates = /* @__PURE__ */ new Map();
|
|
385
|
-
Fragment = ({ children }) => children;
|
|
386
|
-
isHydrating = false;
|
|
387
|
-
server = {
|
|
388
|
-
async getServer() {
|
|
389
|
-
throw new Error("Server module can only be used in Node.js environment");
|
|
390
|
-
}
|
|
391
|
-
};
|
|
406
|
+
]);
|
|
392
407
|
}
|
|
393
408
|
});
|
|
394
409
|
|
|
@@ -399,10 +414,11 @@ var init_database = __esm({
|
|
|
399
414
|
"use strict";
|
|
400
415
|
Database = class {
|
|
401
416
|
constructor(config) {
|
|
402
|
-
this
|
|
403
|
-
this
|
|
404
|
-
this
|
|
405
|
-
this
|
|
417
|
+
__publicField(this, "config");
|
|
418
|
+
__publicField(this, "mongoClient", null);
|
|
419
|
+
__publicField(this, "mongoDb", null);
|
|
420
|
+
__publicField(this, "mysqlPool", null);
|
|
421
|
+
__publicField(this, "pgPool", null);
|
|
406
422
|
this.config = config;
|
|
407
423
|
}
|
|
408
424
|
async connect() {
|
|
@@ -519,11 +535,27 @@ var init_auth = __esm({
|
|
|
519
535
|
"use strict";
|
|
520
536
|
AuthService = class {
|
|
521
537
|
constructor(config) {
|
|
538
|
+
__publicField(this, "config");
|
|
539
|
+
__publicField(this, "jwtPromise", null);
|
|
522
540
|
this.config = {
|
|
523
541
|
expiresIn: "24h",
|
|
524
542
|
...config
|
|
525
543
|
};
|
|
526
544
|
}
|
|
545
|
+
async getJwt() {
|
|
546
|
+
if (!this.jwtPromise) {
|
|
547
|
+
this.jwtPromise = import("jsonwebtoken").catch((error) => {
|
|
548
|
+
this.jwtPromise = null;
|
|
549
|
+
if (error.code === "MODULE_NOT_FOUND") {
|
|
550
|
+
throw new Error(
|
|
551
|
+
"jsonwebtoken not installed. Run: npm install jsonwebtoken @types/jsonwebtoken"
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
throw error;
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
return this.jwtPromise;
|
|
558
|
+
}
|
|
527
559
|
async hashPassword(password) {
|
|
528
560
|
try {
|
|
529
561
|
const bcrypt = await import("bcryptjs");
|
|
@@ -546,42 +578,31 @@ var init_auth = __esm({
|
|
|
546
578
|
throw error;
|
|
547
579
|
}
|
|
548
580
|
}
|
|
549
|
-
generateToken(user) {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
options.expiresIn = this.config.expiresIn;
|
|
555
|
-
}
|
|
556
|
-
return jwt.sign(
|
|
557
|
-
{ id: user.id, username: user.username, roles: user.roles || [] },
|
|
558
|
-
this.config.secret,
|
|
559
|
-
options
|
|
560
|
-
);
|
|
561
|
-
} catch (error) {
|
|
562
|
-
if (error.code === "MODULE_NOT_FOUND") {
|
|
563
|
-
throw new Error("jsonwebtoken not installed. Run: npm install jsonwebtoken @types/jsonwebtoken");
|
|
564
|
-
}
|
|
565
|
-
throw error;
|
|
581
|
+
async generateToken(user) {
|
|
582
|
+
const jwt = await this.getJwt();
|
|
583
|
+
const options = {};
|
|
584
|
+
if (this.config.expiresIn) {
|
|
585
|
+
options.expiresIn = this.config.expiresIn;
|
|
566
586
|
}
|
|
587
|
+
return jwt.sign(
|
|
588
|
+
{ id: user.id, username: user.username, roles: user.roles || [] },
|
|
589
|
+
this.config.secret,
|
|
590
|
+
options
|
|
591
|
+
);
|
|
567
592
|
}
|
|
568
|
-
verifyToken(token) {
|
|
593
|
+
async verifyToken(token) {
|
|
569
594
|
try {
|
|
570
|
-
const jwt =
|
|
595
|
+
const jwt = await this.getJwt();
|
|
571
596
|
return jwt.verify(token, this.config.secret);
|
|
572
|
-
} catch
|
|
573
|
-
if (error.code === "MODULE_NOT_FOUND") {
|
|
574
|
-
throw new Error("jsonwebtoken not installed. Run: npm install jsonwebtoken @types/jsonwebtoken");
|
|
575
|
-
}
|
|
597
|
+
} catch {
|
|
576
598
|
return null;
|
|
577
599
|
}
|
|
578
600
|
}
|
|
579
|
-
// Express middleware for authentication
|
|
580
601
|
initialize() {
|
|
581
|
-
return (req, res, next) => {
|
|
602
|
+
return async (req, res, next) => {
|
|
582
603
|
const token = this.extractToken(req);
|
|
583
604
|
if (token) {
|
|
584
|
-
const decoded = this.verifyToken(token);
|
|
605
|
+
const decoded = await this.verifyToken(token);
|
|
585
606
|
if (decoded) {
|
|
586
607
|
req.user = decoded;
|
|
587
608
|
}
|
|
@@ -589,7 +610,6 @@ var init_auth = __esm({
|
|
|
589
610
|
next();
|
|
590
611
|
};
|
|
591
612
|
}
|
|
592
|
-
// Express middleware for requiring authentication
|
|
593
613
|
requireAuth() {
|
|
594
614
|
return (req, res, next) => {
|
|
595
615
|
if (!req.user) {
|
|
@@ -598,7 +618,6 @@ var init_auth = __esm({
|
|
|
598
618
|
return next();
|
|
599
619
|
};
|
|
600
620
|
}
|
|
601
|
-
// Express middleware for requiring specific roles
|
|
602
621
|
requireRoles(roles) {
|
|
603
622
|
return (req, res, next) => {
|
|
604
623
|
if (!req.user) {
|
|
@@ -632,8 +651,10 @@ var init_api_router = __esm({
|
|
|
632
651
|
"use strict";
|
|
633
652
|
ApiRouter = class {
|
|
634
653
|
constructor(apiDir, auth = null) {
|
|
635
|
-
this
|
|
636
|
-
this
|
|
654
|
+
__publicField(this, "router", null);
|
|
655
|
+
__publicField(this, "apiDir");
|
|
656
|
+
__publicField(this, "auth");
|
|
657
|
+
__publicField(this, "initialized", false);
|
|
637
658
|
this.apiDir = path.resolve(process.cwd(), apiDir);
|
|
638
659
|
this.auth = auth;
|
|
639
660
|
}
|
|
@@ -739,8 +760,22 @@ var init_api_router = __esm({
|
|
|
739
760
|
// src/server/middleware.ts
|
|
740
761
|
function rateLimit(options) {
|
|
741
762
|
const requests = /* @__PURE__ */ new Map();
|
|
763
|
+
const cleanupInterval = setInterval(() => {
|
|
764
|
+
const now = Date.now();
|
|
765
|
+
for (const [ip, times] of requests) {
|
|
766
|
+
const valid = times.filter((t) => now - t < options.windowMs);
|
|
767
|
+
if (valid.length === 0) {
|
|
768
|
+
requests.delete(ip);
|
|
769
|
+
} else {
|
|
770
|
+
requests.set(ip, valid);
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
}, options.windowMs);
|
|
774
|
+
if (cleanupInterval.unref) {
|
|
775
|
+
cleanupInterval.unref();
|
|
776
|
+
}
|
|
742
777
|
return (req, res, next) => {
|
|
743
|
-
const ip = req.ip || req.socket
|
|
778
|
+
const ip = req.ip || req.socket?.remoteAddress || "unknown";
|
|
744
779
|
const now = Date.now();
|
|
745
780
|
const reqTimes = (requests.get(ip) || []).filter((time) => now - time < options.windowMs);
|
|
746
781
|
reqTimes.push(now);
|
|
@@ -764,7 +799,7 @@ var init_middleware = __esm({
|
|
|
764
799
|
console.log(`${(/* @__PURE__ */ new Date()).toISOString()} - ${req.method} ${req.url}`);
|
|
765
800
|
next();
|
|
766
801
|
};
|
|
767
|
-
errorHandler = (err, req, res,
|
|
802
|
+
errorHandler = (err, req, res, _next) => {
|
|
768
803
|
console.error(err.stack);
|
|
769
804
|
res.status(500).json({
|
|
770
805
|
error: {
|
|
@@ -925,7 +960,7 @@ __export(templates_exports, {
|
|
|
925
960
|
});
|
|
926
961
|
function generateDocument(content, options = {}) {
|
|
927
962
|
const {
|
|
928
|
-
title = "
|
|
963
|
+
title = "Baraqex App",
|
|
929
964
|
description = "",
|
|
930
965
|
lang = "en",
|
|
931
966
|
charset = "UTF-8",
|
|
@@ -939,38 +974,38 @@ function generateDocument(content, options = {}) {
|
|
|
939
974
|
initialData = {},
|
|
940
975
|
componentName = ""
|
|
941
976
|
} = options;
|
|
942
|
-
const htmlAttributes = Object.entries(htmlAttrs).map(([key, value]) => `${key}="${
|
|
943
|
-
const bodyAttributes = Object.entries(bodyAttrs).map(([key, value]) => `${key}="${
|
|
977
|
+
const htmlAttributes = Object.entries(htmlAttrs).map(([key, value]) => `${key}="${escapeHtml3(value)}"`).join(" ");
|
|
978
|
+
const bodyAttributes = Object.entries(bodyAttrs).map(([key, value]) => `${key}="${escapeHtml3(value)}"`).join(" ");
|
|
944
979
|
const metaTags = [
|
|
945
980
|
`<meta charset="${charset}">`,
|
|
946
981
|
`<meta name="viewport" content="${viewport}">`,
|
|
947
|
-
description ? `<meta name="description" content="${
|
|
982
|
+
description ? `<meta name="description" content="${escapeHtml3(description)}">` : ""
|
|
948
983
|
];
|
|
949
984
|
Object.entries(meta).forEach(([name, content2]) => {
|
|
950
|
-
metaTags.push(`<meta name="${
|
|
985
|
+
metaTags.push(`<meta name="${escapeHtml3(name)}" content="${escapeHtml3(content2)}">`);
|
|
951
986
|
});
|
|
952
987
|
const scriptTags = scripts.map((src) => {
|
|
953
988
|
if (src.startsWith("<script")) {
|
|
954
989
|
return src;
|
|
955
990
|
}
|
|
956
|
-
return `<script src="${
|
|
991
|
+
return `<script src="${escapeHtml3(src)}" ${src.endsWith(".js") ? 'type="module"' : ""} defer></script>`;
|
|
957
992
|
});
|
|
958
993
|
const styleTags = styles.map((href) => {
|
|
959
994
|
if (href.startsWith("<style")) {
|
|
960
995
|
return href;
|
|
961
996
|
}
|
|
962
|
-
return `<link rel="stylesheet" href="${
|
|
997
|
+
return `<link rel="stylesheet" href="${escapeHtml3(href)}">`;
|
|
963
998
|
});
|
|
964
|
-
const initialDataScript = Object.keys(initialData).length > 0 ? `<script id="__APP_DATA__" type="application/json">${
|
|
999
|
+
const initialDataScript = Object.keys(initialData).length > 0 ? `<script id="__APP_DATA__" type="application/json">${escapeHtml3(JSON.stringify(initialData))}</script>` : "";
|
|
965
1000
|
return `<!DOCTYPE html>
|
|
966
1001
|
<html lang="${lang}" ${htmlAttributes}>
|
|
967
1002
|
<head>
|
|
968
1003
|
${metaTags.filter(Boolean).join("\n ")}
|
|
969
|
-
<title>${
|
|
1004
|
+
<title>${escapeHtml3(title)}</title>
|
|
970
1005
|
${styleTags.join("\n ")}
|
|
971
1006
|
</head>
|
|
972
1007
|
<body class="${bodyClasses}" ${bodyAttributes}>
|
|
973
|
-
<div id="app-root" data-ssr-root${componentName ? ` data-component="${
|
|
1008
|
+
<div id="app-root" data-ssr-root${componentName ? ` data-component="${escapeHtml3(componentName)}"` : ""}>${content}</div>
|
|
974
1009
|
${initialDataScript}
|
|
975
1010
|
${scriptTags.join("\n ")}
|
|
976
1011
|
</body>
|
|
@@ -988,14 +1023,14 @@ function generateErrorPage(statusCode, message, error) {
|
|
|
988
1023
|
const isDev = process.env.NODE_ENV !== "production";
|
|
989
1024
|
const errorDetails = isDev && error ? `
|
|
990
1025
|
<div class="error-details">
|
|
991
|
-
<pre>${
|
|
1026
|
+
<pre>${escapeHtml3(error.stack || error.message)}</pre>
|
|
992
1027
|
</div>
|
|
993
1028
|
` : "";
|
|
994
1029
|
const content = `
|
|
995
1030
|
<div class="error-container">
|
|
996
1031
|
<h1>${statusCode}</h1>
|
|
997
|
-
<h2>${
|
|
998
|
-
<p>${
|
|
1032
|
+
<h2>${escapeHtml3(errorMessages[statusCode] || "Error")}</h2>
|
|
1033
|
+
<p>${escapeHtml3(message)}</p>
|
|
999
1034
|
${errorDetails}
|
|
1000
1035
|
<a href="/" class="home-link">Back to Home</a>
|
|
1001
1036
|
</div>
|
|
@@ -1069,7 +1104,7 @@ function generateLoadingPage(message = "Loading...") {
|
|
|
1069
1104
|
const content = `
|
|
1070
1105
|
<div class="loading-container">
|
|
1071
1106
|
<div class="spinner"></div>
|
|
1072
|
-
<p>${
|
|
1107
|
+
<p>${escapeHtml3(message)}</p>
|
|
1073
1108
|
</div>
|
|
1074
1109
|
`;
|
|
1075
1110
|
const styles = [`<style>
|
|
@@ -1105,7 +1140,7 @@ function generateLoadingPage(message = "Loading...") {
|
|
|
1105
1140
|
styles
|
|
1106
1141
|
});
|
|
1107
1142
|
}
|
|
1108
|
-
function
|
|
1143
|
+
function escapeHtml3(text) {
|
|
1109
1144
|
return String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
1110
1145
|
}
|
|
1111
1146
|
var init_templates = __esm({
|
|
@@ -1191,7 +1226,7 @@ async function loadGoWasmFromFile(wasmFilePath, options = {}) {
|
|
|
1191
1226
|
const GoRuntime = await loadGoRuntime(options.goWasmPath);
|
|
1192
1227
|
const go = new GoRuntime();
|
|
1193
1228
|
const wasmBuffer = await fs3.readFile(wasmFilePath);
|
|
1194
|
-
const wasmModule = await WebAssembly.compile(wasmBuffer);
|
|
1229
|
+
const wasmModule = await WebAssembly.compile(new Uint8Array(wasmBuffer));
|
|
1195
1230
|
const baseImports = go.importObject;
|
|
1196
1231
|
const finalImportObject = {
|
|
1197
1232
|
...baseImports,
|
|
@@ -1329,13 +1364,13 @@ function createDevServer(options = {}) {
|
|
|
1329
1364
|
});
|
|
1330
1365
|
}
|
|
1331
1366
|
function createProductionServer(config) {
|
|
1332
|
-
const
|
|
1367
|
+
const server = new Server({
|
|
1333
1368
|
...config,
|
|
1334
1369
|
// Fix the PORT parsing
|
|
1335
1370
|
port: config.port || (process.env.PORT ? parseInt(process.env.PORT) : 8080)
|
|
1336
1371
|
});
|
|
1337
|
-
|
|
1338
|
-
return
|
|
1372
|
+
server.addShutdownHandler();
|
|
1373
|
+
return server;
|
|
1339
1374
|
}
|
|
1340
1375
|
function getRequestIp(req) {
|
|
1341
1376
|
return req.ip || req.headers["x-forwarded-for"]?.split(",")[0].trim() || req.socket.remoteAddress || "";
|
|
@@ -1355,7 +1390,7 @@ var Server, renderComponent, server_default;
|
|
|
1355
1390
|
var init_server = __esm({
|
|
1356
1391
|
"src/server/index.ts"() {
|
|
1357
1392
|
"use strict";
|
|
1358
|
-
|
|
1393
|
+
init_server_renderer();
|
|
1359
1394
|
init_database();
|
|
1360
1395
|
init_auth();
|
|
1361
1396
|
init_api_router();
|
|
@@ -1372,10 +1407,12 @@ var init_server = __esm({
|
|
|
1372
1407
|
init_middleware();
|
|
1373
1408
|
Server = class {
|
|
1374
1409
|
constructor(config = {}) {
|
|
1375
|
-
this
|
|
1376
|
-
this
|
|
1377
|
-
this
|
|
1378
|
-
this
|
|
1410
|
+
__publicField(this, "app");
|
|
1411
|
+
__publicField(this, "server", null);
|
|
1412
|
+
__publicField(this, "config");
|
|
1413
|
+
__publicField(this, "db", null);
|
|
1414
|
+
__publicField(this, "auth", null);
|
|
1415
|
+
__publicField(this, "initialized", false);
|
|
1379
1416
|
this.config = {
|
|
1380
1417
|
port: 3e3,
|
|
1381
1418
|
apiDir: "./api",
|
|
@@ -1654,8 +1691,8 @@ var init_server = __esm({
|
|
|
1654
1691
|
if (!fs4.existsSync(clientJsPath)) {
|
|
1655
1692
|
const clientJsContent = `
|
|
1656
1693
|
// Auto-generated hydration script
|
|
1657
|
-
import { hydrate } from '
|
|
1658
|
-
|
|
1694
|
+
import { hydrate } from 'baraqex';
|
|
1695
|
+
|
|
1659
1696
|
// Find SSR content and hydrate it
|
|
1660
1697
|
document.addEventListener('DOMContentLoaded', () => {
|
|
1661
1698
|
const ssrRoots = document.querySelectorAll('[data-ssr-root]');
|
|
@@ -1695,9 +1732,9 @@ var init_server = __esm({
|
|
|
1695
1732
|
process.on("SIGINT", gracefulShutdown);
|
|
1696
1733
|
}
|
|
1697
1734
|
};
|
|
1698
|
-
renderComponent = (
|
|
1735
|
+
renderComponent = (Component2, props = {}) => {
|
|
1699
1736
|
try {
|
|
1700
|
-
const html = renderToString(
|
|
1737
|
+
const html = renderToString(Component2(props));
|
|
1701
1738
|
return {
|
|
1702
1739
|
html: typeof html === "string" ? html : String(html),
|
|
1703
1740
|
success: true
|
|
@@ -1763,70 +1800,1982 @@ function renderToString2(component) {
|
|
|
1763
1800
|
return "<div>Error rendering component</div>";
|
|
1764
1801
|
}
|
|
1765
1802
|
}
|
|
1766
|
-
var
|
|
1803
|
+
var init_server_renderer2 = __esm({
|
|
1767
1804
|
"src/server-renderer.ts"() {
|
|
1768
1805
|
"use strict";
|
|
1769
1806
|
}
|
|
1770
1807
|
});
|
|
1771
1808
|
|
|
1772
|
-
// src/
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
async function
|
|
1777
|
-
if (
|
|
1778
|
-
|
|
1809
|
+
// src/core/batch.ts
|
|
1810
|
+
var isBatching = false;
|
|
1811
|
+
var syncQueue = [];
|
|
1812
|
+
var asyncQueue = [];
|
|
1813
|
+
async function batchUpdates(fn) {
|
|
1814
|
+
if (isBatching) {
|
|
1815
|
+
if (fn.constructor.name === "AsyncFunction") {
|
|
1816
|
+
asyncQueue.push(fn);
|
|
1817
|
+
} else {
|
|
1818
|
+
syncQueue.push(fn);
|
|
1819
|
+
}
|
|
1820
|
+
return;
|
|
1779
1821
|
}
|
|
1822
|
+
isBatching = true;
|
|
1780
1823
|
try {
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
if (options.debug) {
|
|
1785
|
-
console.log("[WASM] Loading WASM from:", wasmUrl);
|
|
1786
|
-
}
|
|
1787
|
-
const response = await fetch(wasmUrl);
|
|
1788
|
-
if (!response.ok) {
|
|
1789
|
-
throw new Error(`Failed to fetch WASM file: ${response.status}`);
|
|
1790
|
-
}
|
|
1791
|
-
const wasmBytes = await response.arrayBuffer();
|
|
1792
|
-
const go = new window.Go();
|
|
1793
|
-
const wasmModule = await WebAssembly.instantiate(wasmBytes, go.importObject);
|
|
1794
|
-
go.run(wasmModule.instance);
|
|
1795
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
1796
|
-
if (options.debug) {
|
|
1797
|
-
console.log("[WASM] Go program started, checking for registered functions...");
|
|
1798
|
-
}
|
|
1799
|
-
const functions = {};
|
|
1800
|
-
for (const key in window) {
|
|
1801
|
-
if (typeof window[key] === "function" && key.startsWith("go")) {
|
|
1802
|
-
functions[key] = window[key];
|
|
1803
|
-
if (options.debug) {
|
|
1804
|
-
console.log(`[WASM] Found function: ${key}`);
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1824
|
+
const result = fn();
|
|
1825
|
+
if (result instanceof Promise) {
|
|
1826
|
+
await result;
|
|
1807
1827
|
}
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
exports: wasmModule.instance.exports,
|
|
1812
|
-
functions
|
|
1813
|
-
};
|
|
1814
|
-
if (options.onLoad) {
|
|
1815
|
-
options.onLoad(wasmInstance);
|
|
1828
|
+
while (syncQueue.length > 0) {
|
|
1829
|
+
const nextFn = syncQueue.shift();
|
|
1830
|
+
nextFn();
|
|
1816
1831
|
}
|
|
1817
|
-
|
|
1818
|
-
|
|
1832
|
+
while (asyncQueue.length > 0) {
|
|
1833
|
+
const nextFn = asyncQueue.shift();
|
|
1834
|
+
await nextFn();
|
|
1819
1835
|
}
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
console.error("[WASM] Error loading Go WASM module:", error);
|
|
1823
|
-
throw error;
|
|
1836
|
+
} finally {
|
|
1837
|
+
isBatching = false;
|
|
1824
1838
|
}
|
|
1825
1839
|
}
|
|
1826
|
-
function
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1840
|
+
function getIsBatching() {
|
|
1841
|
+
return isBatching;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
// src/core/index.ts
|
|
1845
|
+
init_context();
|
|
1846
|
+
init_hooks();
|
|
1847
|
+
|
|
1848
|
+
// src/core/jsx-runtime.ts
|
|
1849
|
+
init_hooks();
|
|
1850
|
+
var isBrowser = typeof document !== "undefined";
|
|
1851
|
+
function jsx(type, props, key) {
|
|
1852
|
+
const processedProps = { ...props };
|
|
1853
|
+
if (key !== void 0) {
|
|
1854
|
+
processedProps.key = key;
|
|
1855
|
+
}
|
|
1856
|
+
if (arguments.length > 3) {
|
|
1857
|
+
processedProps.children = Array.prototype.slice.call(arguments, 3);
|
|
1858
|
+
}
|
|
1859
|
+
return { type, props: processedProps, key: processedProps.key };
|
|
1860
|
+
}
|
|
1861
|
+
var jsxs = jsx;
|
|
1862
|
+
function jsxDEV(type, props, key, _isStaticChildren, _source, _self) {
|
|
1863
|
+
return jsx(type, props, key);
|
|
1864
|
+
}
|
|
1865
|
+
var Fragment = ({ children }) => children;
|
|
1866
|
+
function assertBrowser(method) {
|
|
1867
|
+
if (!isBrowser) {
|
|
1868
|
+
throw new Error(
|
|
1869
|
+
`[baraqex] ${method}() can only be called in a browser environment. Use renderToString() for server-side rendering.`
|
|
1870
|
+
);
|
|
1871
|
+
}
|
|
1872
|
+
}
|
|
1873
|
+
function createTextNode(text) {
|
|
1874
|
+
return document.createTextNode(text);
|
|
1875
|
+
}
|
|
1876
|
+
function applyProps(element, props) {
|
|
1877
|
+
for (const [key, value] of Object.entries(props)) {
|
|
1878
|
+
if (key === "children")
|
|
1879
|
+
continue;
|
|
1880
|
+
if (key === "className") {
|
|
1881
|
+
element.setAttribute("class", String(value));
|
|
1882
|
+
} else if (key === "htmlFor") {
|
|
1883
|
+
element.setAttribute("for", String(value));
|
|
1884
|
+
} else if (key.startsWith("on") && typeof value === "function") {
|
|
1885
|
+
const eventName = key.slice(2).toLowerCase();
|
|
1886
|
+
element.addEventListener(eventName, value);
|
|
1887
|
+
} else if (key === "style" && typeof value === "object") {
|
|
1888
|
+
Object.assign(element.style, value);
|
|
1889
|
+
} else if (key === "dangerouslySetInnerHTML" && value && value.__html) {
|
|
1890
|
+
element.innerHTML = value.__html;
|
|
1891
|
+
} else if (key === "ref") {
|
|
1892
|
+
if (typeof value === "function") {
|
|
1893
|
+
value(element);
|
|
1894
|
+
} else if (value && typeof value === "object" && "current" in value) {
|
|
1895
|
+
value.current = element;
|
|
1896
|
+
}
|
|
1897
|
+
} else if (value !== false && value != null) {
|
|
1898
|
+
if (value === true) {
|
|
1899
|
+
element.setAttribute(key, "");
|
|
1900
|
+
} else {
|
|
1901
|
+
element.setAttribute(key, String(value));
|
|
1902
|
+
}
|
|
1903
|
+
}
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
async function createElement(vnode) {
|
|
1907
|
+
assertBrowser("createElement");
|
|
1908
|
+
if (vnode == null || typeof vnode === "boolean") {
|
|
1909
|
+
return createTextNode("");
|
|
1910
|
+
}
|
|
1911
|
+
if (typeof vnode === "number" || typeof vnode === "string") {
|
|
1912
|
+
return createTextNode(String(vnode));
|
|
1913
|
+
}
|
|
1914
|
+
if (Array.isArray(vnode)) {
|
|
1915
|
+
const fragment = document.createDocumentFragment();
|
|
1916
|
+
for (const child of vnode) {
|
|
1917
|
+
const node = await createElement(child);
|
|
1918
|
+
fragment.appendChild(node);
|
|
1919
|
+
}
|
|
1920
|
+
return fragment;
|
|
1921
|
+
}
|
|
1922
|
+
if (typeof vnode === "object" && "type" in vnode && vnode.props !== void 0) {
|
|
1923
|
+
const { type, props } = vnode;
|
|
1924
|
+
if (typeof type === "function") {
|
|
1925
|
+
if (type === Fragment) {
|
|
1926
|
+
const children2 = props?.children;
|
|
1927
|
+
if (children2 == null)
|
|
1928
|
+
return createTextNode("");
|
|
1929
|
+
return createElement(children2);
|
|
1930
|
+
}
|
|
1931
|
+
const root = getCurrentRoot() ?? void 0;
|
|
1932
|
+
const renderId = prepareRender(root);
|
|
1933
|
+
try {
|
|
1934
|
+
const result = type(props || {});
|
|
1935
|
+
return await createElement(result);
|
|
1936
|
+
} finally {
|
|
1937
|
+
finishRender();
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
const element = document.createElement(type);
|
|
1941
|
+
applyProps(element, props || {});
|
|
1942
|
+
const children = props?.children;
|
|
1943
|
+
if (children != null) {
|
|
1944
|
+
const childArray = Array.isArray(children) ? children : [children];
|
|
1945
|
+
for (const child of childArray) {
|
|
1946
|
+
const childNode = await createElement(child);
|
|
1947
|
+
element.appendChild(childNode);
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
return element;
|
|
1951
|
+
}
|
|
1952
|
+
return createTextNode(String(vnode));
|
|
1953
|
+
}
|
|
1954
|
+
function createElementSync(vnode) {
|
|
1955
|
+
assertBrowser("createElementSync");
|
|
1956
|
+
if (vnode == null || typeof vnode === "boolean") {
|
|
1957
|
+
return createTextNode("");
|
|
1958
|
+
}
|
|
1959
|
+
if (typeof vnode === "number" || typeof vnode === "string") {
|
|
1960
|
+
return createTextNode(String(vnode));
|
|
1961
|
+
}
|
|
1962
|
+
if (Array.isArray(vnode)) {
|
|
1963
|
+
const fragment = document.createDocumentFragment();
|
|
1964
|
+
for (const child of vnode) {
|
|
1965
|
+
fragment.appendChild(createElementSync(child));
|
|
1966
|
+
}
|
|
1967
|
+
return fragment;
|
|
1968
|
+
}
|
|
1969
|
+
if (typeof vnode === "object" && "type" in vnode) {
|
|
1970
|
+
const { type, props } = vnode;
|
|
1971
|
+
if (typeof type === "function") {
|
|
1972
|
+
if (type === Fragment) {
|
|
1973
|
+
return createElementSync(props?.children);
|
|
1974
|
+
}
|
|
1975
|
+
const result = type(props || {});
|
|
1976
|
+
return createElementSync(result);
|
|
1977
|
+
}
|
|
1978
|
+
const element = document.createElement(type);
|
|
1979
|
+
applyProps(element, props || {});
|
|
1980
|
+
const children = props?.children;
|
|
1981
|
+
if (children != null) {
|
|
1982
|
+
const childArray = Array.isArray(children) ? children : [children];
|
|
1983
|
+
for (const child of childArray) {
|
|
1984
|
+
element.appendChild(createElementSync(child));
|
|
1985
|
+
}
|
|
1986
|
+
}
|
|
1987
|
+
return element;
|
|
1988
|
+
}
|
|
1989
|
+
return createTextNode(String(vnode));
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1992
|
+
// src/core/renderer.ts
|
|
1993
|
+
init_hooks();
|
|
1994
|
+
var isBrowser2 = typeof document !== "undefined";
|
|
1995
|
+
var rootMap = /* @__PURE__ */ new WeakMap();
|
|
1996
|
+
async function render(element, container) {
|
|
1997
|
+
if (!isBrowser2) {
|
|
1998
|
+
throw new Error(
|
|
1999
|
+
"[baraqex] render() can only be called in a browser. Use renderToString() for server-side rendering."
|
|
2000
|
+
);
|
|
2001
|
+
}
|
|
2002
|
+
if (!container) {
|
|
2003
|
+
throw new Error("[baraqex] render() requires a container element");
|
|
2004
|
+
}
|
|
2005
|
+
let root = rootMap.get(container);
|
|
2006
|
+
if (!root) {
|
|
2007
|
+
root = createRootState();
|
|
2008
|
+
rootMap.set(container, root);
|
|
2009
|
+
}
|
|
2010
|
+
await batchUpdates(async () => {
|
|
2011
|
+
prepareRender(root);
|
|
2012
|
+
try {
|
|
2013
|
+
setRenderCallback(render, element, container);
|
|
2014
|
+
const domNode = await createElement(element);
|
|
2015
|
+
container.textContent = "";
|
|
2016
|
+
container.appendChild(domNode);
|
|
2017
|
+
} finally {
|
|
2018
|
+
finishRender();
|
|
2019
|
+
}
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
async function hydrate(element, container) {
|
|
2023
|
+
await render(element, container);
|
|
2024
|
+
}
|
|
2025
|
+
function createRoot(container) {
|
|
2026
|
+
const root = createRootState();
|
|
2027
|
+
rootMap.set(container, root);
|
|
2028
|
+
return {
|
|
2029
|
+
render: (element) => render(element, container),
|
|
2030
|
+
unmount: () => {
|
|
2031
|
+
cleanupRoot(root);
|
|
2032
|
+
rootMap.delete(container);
|
|
2033
|
+
container.textContent = "";
|
|
2034
|
+
}
|
|
2035
|
+
};
|
|
2036
|
+
}
|
|
2037
|
+
function hasRoot(container) {
|
|
2038
|
+
return rootMap.has(container);
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
// src/core/index.ts
|
|
2042
|
+
init_server_renderer();
|
|
2043
|
+
|
|
2044
|
+
// src/core/vdom.ts
|
|
2045
|
+
var isBrowser3 = typeof document !== "undefined";
|
|
2046
|
+
function arePropsEqual(oldProps, newProps) {
|
|
2047
|
+
const oldKeys = Object.keys(oldProps || {}).filter((k) => k !== "children");
|
|
2048
|
+
const newKeys = Object.keys(newProps || {}).filter((k) => k !== "children");
|
|
2049
|
+
if (oldKeys.length !== newKeys.length)
|
|
2050
|
+
return false;
|
|
2051
|
+
return oldKeys.every((key) => Object.is(oldProps[key], newProps[key]));
|
|
2052
|
+
}
|
|
2053
|
+
function diff(oldNode, newNode) {
|
|
2054
|
+
if (oldNode == null || newNode == null) {
|
|
2055
|
+
return oldNode !== newNode;
|
|
2056
|
+
}
|
|
2057
|
+
if (typeof oldNode !== typeof newNode)
|
|
2058
|
+
return true;
|
|
2059
|
+
if (typeof newNode === "string" || typeof newNode === "number") {
|
|
2060
|
+
return oldNode !== newNode;
|
|
2061
|
+
}
|
|
2062
|
+
if (Array.isArray(oldNode) && Array.isArray(newNode)) {
|
|
2063
|
+
if (oldNode.length !== newNode.length)
|
|
2064
|
+
return true;
|
|
2065
|
+
return oldNode.some((child, i) => diff(child, newNode[i]));
|
|
2066
|
+
}
|
|
2067
|
+
if (typeof oldNode === "object" && typeof newNode === "object") {
|
|
2068
|
+
if (newNode.type !== oldNode.type)
|
|
2069
|
+
return true;
|
|
2070
|
+
if (newNode.key !== oldNode.key)
|
|
2071
|
+
return true;
|
|
2072
|
+
return !arePropsEqual(oldNode.props, newNode.props);
|
|
2073
|
+
}
|
|
2074
|
+
return oldNode !== newNode;
|
|
2075
|
+
}
|
|
2076
|
+
function shouldComponentUpdate(oldProps, newProps) {
|
|
2077
|
+
return !arePropsEqual(oldProps, newProps);
|
|
2078
|
+
}
|
|
2079
|
+
function calculatePatches(oldNode, newNode) {
|
|
2080
|
+
if (oldNode == null && newNode != null) {
|
|
2081
|
+
return { type: "CREATE", node: newNode };
|
|
2082
|
+
}
|
|
2083
|
+
if (oldNode != null && newNode == null) {
|
|
2084
|
+
return { type: "REMOVE" };
|
|
2085
|
+
}
|
|
2086
|
+
if (oldNode == null && newNode == null) {
|
|
2087
|
+
return null;
|
|
2088
|
+
}
|
|
2089
|
+
if (typeof oldNode !== typeof newNode) {
|
|
2090
|
+
return { type: "REPLACE", node: newNode };
|
|
2091
|
+
}
|
|
2092
|
+
if (typeof newNode === "string" || typeof newNode === "number") {
|
|
2093
|
+
if (oldNode !== newNode) {
|
|
2094
|
+
return { type: "REPLACE", node: newNode };
|
|
2095
|
+
}
|
|
2096
|
+
return null;
|
|
2097
|
+
}
|
|
2098
|
+
if (typeof oldNode === "object" && typeof newNode === "object" && "type" in newNode) {
|
|
2099
|
+
if (oldNode.type !== newNode.type) {
|
|
2100
|
+
return { type: "REPLACE", node: newNode };
|
|
2101
|
+
}
|
|
2102
|
+
const propPatches = {};
|
|
2103
|
+
let hasChanges = false;
|
|
2104
|
+
const newProps = newNode.props || {};
|
|
2105
|
+
const oldProps = oldNode.props || {};
|
|
2106
|
+
for (const key of Object.keys(newProps)) {
|
|
2107
|
+
if (key === "children")
|
|
2108
|
+
continue;
|
|
2109
|
+
if (!Object.is(newProps[key], oldProps[key])) {
|
|
2110
|
+
propPatches[key] = newProps[key];
|
|
2111
|
+
hasChanges = true;
|
|
2112
|
+
}
|
|
2113
|
+
}
|
|
2114
|
+
for (const key of Object.keys(oldProps)) {
|
|
2115
|
+
if (key === "children")
|
|
2116
|
+
continue;
|
|
2117
|
+
if (!(key in newProps)) {
|
|
2118
|
+
propPatches[key] = void 0;
|
|
2119
|
+
hasChanges = true;
|
|
2120
|
+
}
|
|
2121
|
+
}
|
|
2122
|
+
const oldChildren = normalizeChildren(oldProps.children);
|
|
2123
|
+
const newChildren = normalizeChildren(newProps.children);
|
|
2124
|
+
const childPatches = diffChildren(oldChildren, newChildren);
|
|
2125
|
+
if (childPatches.length > 0) {
|
|
2126
|
+
hasChanges = true;
|
|
2127
|
+
}
|
|
2128
|
+
if (hasChanges) {
|
|
2129
|
+
return {
|
|
2130
|
+
type: "UPDATE",
|
|
2131
|
+
props: propPatches,
|
|
2132
|
+
children: childPatches.length > 0 ? childPatches : void 0
|
|
2133
|
+
};
|
|
2134
|
+
}
|
|
2135
|
+
return null;
|
|
2136
|
+
}
|
|
2137
|
+
return null;
|
|
2138
|
+
}
|
|
2139
|
+
function normalizeChildren(children) {
|
|
2140
|
+
if (children == null)
|
|
2141
|
+
return [];
|
|
2142
|
+
return Array.isArray(children) ? children : [children];
|
|
2143
|
+
}
|
|
2144
|
+
function diffChildren(oldChildren, newChildren) {
|
|
2145
|
+
const patches = [];
|
|
2146
|
+
const oldKeyMap = /* @__PURE__ */ new Map();
|
|
2147
|
+
oldChildren.forEach((child, i) => {
|
|
2148
|
+
if (child && typeof child === "object" && child.key != null) {
|
|
2149
|
+
oldKeyMap.set(child.key, i);
|
|
2150
|
+
}
|
|
2151
|
+
});
|
|
2152
|
+
const newKeyMap = /* @__PURE__ */ new Map();
|
|
2153
|
+
newChildren.forEach((child, i) => {
|
|
2154
|
+
if (child && typeof child === "object" && child.key != null) {
|
|
2155
|
+
newKeyMap.set(child.key, i);
|
|
2156
|
+
}
|
|
2157
|
+
});
|
|
2158
|
+
const maxLen = Math.max(oldChildren.length, newChildren.length);
|
|
2159
|
+
for (let i = 0; i < maxLen; i++) {
|
|
2160
|
+
const oldChild = i < oldChildren.length ? oldChildren[i] : null;
|
|
2161
|
+
const newChild = i < newChildren.length ? newChildren[i] : null;
|
|
2162
|
+
const patch = calculatePatches(oldChild, newChild);
|
|
2163
|
+
if (patch) {
|
|
2164
|
+
patches.push(patch);
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
return patches;
|
|
2168
|
+
}
|
|
2169
|
+
function applyPatches(element, patch) {
|
|
2170
|
+
if (!isBrowser3)
|
|
2171
|
+
return element;
|
|
2172
|
+
switch (patch.type) {
|
|
2173
|
+
case "REMOVE":
|
|
2174
|
+
element.parentNode?.removeChild(element);
|
|
2175
|
+
return null;
|
|
2176
|
+
case "REPLACE": {
|
|
2177
|
+
if (!patch.node)
|
|
2178
|
+
return element;
|
|
2179
|
+
const newNode = patch.node;
|
|
2180
|
+
if (typeof newNode === "string" || typeof newNode === "number") {
|
|
2181
|
+
const textNode = document.createTextNode(String(newNode));
|
|
2182
|
+
element.parentNode?.replaceChild(textNode, element);
|
|
2183
|
+
return null;
|
|
2184
|
+
}
|
|
2185
|
+
element.textContent = "";
|
|
2186
|
+
return element;
|
|
2187
|
+
}
|
|
2188
|
+
case "UPDATE": {
|
|
2189
|
+
if (patch.props) {
|
|
2190
|
+
for (const [key, value] of Object.entries(patch.props)) {
|
|
2191
|
+
if (value === void 0) {
|
|
2192
|
+
const attrName = key === "className" ? "class" : key;
|
|
2193
|
+
element.removeAttribute(attrName);
|
|
2194
|
+
} else if (key === "className") {
|
|
2195
|
+
element.setAttribute("class", String(value));
|
|
2196
|
+
} else if (key === "style" && typeof value === "object") {
|
|
2197
|
+
const htmlEl = element;
|
|
2198
|
+
for (const [prop, val] of Object.entries(value)) {
|
|
2199
|
+
htmlEl.style[prop] = val;
|
|
2200
|
+
}
|
|
2201
|
+
} else if (key.startsWith("on") && typeof value === "function") {
|
|
2202
|
+
const eventName = key.slice(2).toLowerCase();
|
|
2203
|
+
const attrName = `data-baraqex-listener-${eventName}`;
|
|
2204
|
+
const oldHandler = element.__baraqexHandlers?.[eventName];
|
|
2205
|
+
if (oldHandler) {
|
|
2206
|
+
element.removeEventListener(eventName, oldHandler);
|
|
2207
|
+
}
|
|
2208
|
+
element.addEventListener(eventName, value);
|
|
2209
|
+
if (!element.__baraqexHandlers) {
|
|
2210
|
+
element.__baraqexHandlers = {};
|
|
2211
|
+
}
|
|
2212
|
+
element.__baraqexHandlers[eventName] = value;
|
|
2213
|
+
} else if (key === "ref") {
|
|
2214
|
+
if (typeof value === "function") {
|
|
2215
|
+
value(element);
|
|
2216
|
+
} else if (value && typeof value === "object" && "current" in value) {
|
|
2217
|
+
value.current = element;
|
|
2218
|
+
}
|
|
2219
|
+
} else {
|
|
2220
|
+
if (value === true) {
|
|
2221
|
+
element.setAttribute(key, "");
|
|
2222
|
+
} else {
|
|
2223
|
+
element.setAttribute(key, String(value));
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
}
|
|
2228
|
+
return element;
|
|
2229
|
+
}
|
|
2230
|
+
default:
|
|
2231
|
+
return element;
|
|
2232
|
+
}
|
|
2233
|
+
}
|
|
2234
|
+
|
|
2235
|
+
// src/core/component.ts
|
|
2236
|
+
var Component = class {
|
|
2237
|
+
constructor(props) {
|
|
2238
|
+
__publicField(this, "props");
|
|
2239
|
+
__publicField(this, "state");
|
|
2240
|
+
__publicField(this, "element", null);
|
|
2241
|
+
__publicField(this, "_mounted", false);
|
|
2242
|
+
__publicField(this, "_pendingState", null);
|
|
2243
|
+
this.props = props;
|
|
2244
|
+
this.state = {};
|
|
2245
|
+
}
|
|
2246
|
+
/**
|
|
2247
|
+
* Called after the component is mounted to the DOM
|
|
2248
|
+
*/
|
|
2249
|
+
componentDidMount() {
|
|
2250
|
+
}
|
|
2251
|
+
/**
|
|
2252
|
+
* Called before the component is unmounted from the DOM
|
|
2253
|
+
*/
|
|
2254
|
+
componentWillUnmount() {
|
|
2255
|
+
}
|
|
2256
|
+
/**
|
|
2257
|
+
* Called when the component receives new props
|
|
2258
|
+
*/
|
|
2259
|
+
componentDidUpdate(_prevProps, _prevState) {
|
|
2260
|
+
}
|
|
2261
|
+
/**
|
|
2262
|
+
* Determine if the component should re-render
|
|
2263
|
+
*/
|
|
2264
|
+
shouldComponentUpdate(_nextProps, _nextState) {
|
|
2265
|
+
return true;
|
|
2266
|
+
}
|
|
2267
|
+
/**
|
|
2268
|
+
* Update component state and trigger re-render
|
|
2269
|
+
*/
|
|
2270
|
+
setState(newState) {
|
|
2271
|
+
const prevState = { ...this.state };
|
|
2272
|
+
const stateUpdate = typeof newState === "function" ? newState(this.state, this.props) : newState;
|
|
2273
|
+
this.state = { ...this.state, ...stateUpdate };
|
|
2274
|
+
if (this._mounted) {
|
|
2275
|
+
if (this.shouldComponentUpdate(this.props, this.state)) {
|
|
2276
|
+
this._update();
|
|
2277
|
+
this.componentDidUpdate(this.props, prevState);
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
}
|
|
2281
|
+
/**
|
|
2282
|
+
* Force a re-render without checking shouldComponentUpdate
|
|
2283
|
+
*/
|
|
2284
|
+
forceUpdate() {
|
|
2285
|
+
this._update();
|
|
2286
|
+
}
|
|
2287
|
+
/**
|
|
2288
|
+
* Internal update method
|
|
2289
|
+
*/
|
|
2290
|
+
async _update() {
|
|
2291
|
+
const vdom = this.render();
|
|
2292
|
+
if (!vdom || !this.element?.parentNode)
|
|
2293
|
+
return;
|
|
2294
|
+
const newElement = await createElement(vdom);
|
|
2295
|
+
if (newElement instanceof HTMLElement) {
|
|
2296
|
+
this.element.parentNode.replaceChild(newElement, this.element);
|
|
2297
|
+
this.element = newElement;
|
|
2298
|
+
}
|
|
2299
|
+
}
|
|
2300
|
+
/**
|
|
2301
|
+
* Mount the component to a container
|
|
2302
|
+
*/
|
|
2303
|
+
async mount(container) {
|
|
2304
|
+
const vdom = this.render();
|
|
2305
|
+
if (!vdom)
|
|
2306
|
+
return;
|
|
2307
|
+
const element = await createElement(vdom);
|
|
2308
|
+
if (element instanceof HTMLElement) {
|
|
2309
|
+
this.element = element;
|
|
2310
|
+
container.appendChild(element);
|
|
2311
|
+
this._mounted = true;
|
|
2312
|
+
this.componentDidMount();
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
/**
|
|
2316
|
+
* Unmount the component
|
|
2317
|
+
*/
|
|
2318
|
+
unmount() {
|
|
2319
|
+
if (this.element?.parentNode) {
|
|
2320
|
+
this.componentWillUnmount();
|
|
2321
|
+
this.element.parentNode.removeChild(this.element);
|
|
2322
|
+
this._mounted = false;
|
|
2323
|
+
this.element = null;
|
|
2324
|
+
}
|
|
2325
|
+
}
|
|
2326
|
+
};
|
|
2327
|
+
function createClassComponent(ComponentClass) {
|
|
2328
|
+
return (props) => {
|
|
2329
|
+
const instance = new ComponentClass(props);
|
|
2330
|
+
return instance.render();
|
|
2331
|
+
};
|
|
2332
|
+
}
|
|
2333
|
+
var PureComponent = class extends Component {
|
|
2334
|
+
shouldComponentUpdate(nextProps, nextState) {
|
|
2335
|
+
const propsKeys = Object.keys(this.props);
|
|
2336
|
+
const nextPropsKeys = Object.keys(nextProps);
|
|
2337
|
+
if (propsKeys.length !== nextPropsKeys.length)
|
|
2338
|
+
return true;
|
|
2339
|
+
for (const key of propsKeys) {
|
|
2340
|
+
if (!Object.is(this.props[key], nextProps[key]))
|
|
2341
|
+
return true;
|
|
2342
|
+
}
|
|
2343
|
+
const stateKeys = Object.keys(this.state);
|
|
2344
|
+
const nextStateKeys = Object.keys(nextState);
|
|
2345
|
+
if (stateKeys.length !== nextStateKeys.length)
|
|
2346
|
+
return true;
|
|
2347
|
+
for (const key of stateKeys) {
|
|
2348
|
+
if (!Object.is(this.state[key], nextState[key]))
|
|
2349
|
+
return true;
|
|
2350
|
+
}
|
|
2351
|
+
return false;
|
|
2352
|
+
}
|
|
2353
|
+
};
|
|
2354
|
+
|
|
2355
|
+
// src/core/event-bus.ts
|
|
2356
|
+
function createEventBus() {
|
|
2357
|
+
const events = /* @__PURE__ */ new Map();
|
|
2358
|
+
const onceHandlers = /* @__PURE__ */ new WeakMap();
|
|
2359
|
+
const on = (event, handler) => {
|
|
2360
|
+
if (!events.has(event)) {
|
|
2361
|
+
events.set(event, /* @__PURE__ */ new Set());
|
|
2362
|
+
}
|
|
2363
|
+
events.get(event).add(handler);
|
|
2364
|
+
return () => off(event, handler);
|
|
2365
|
+
};
|
|
2366
|
+
const once = (event, handler) => {
|
|
2367
|
+
const onceWrapper = (...args) => {
|
|
2368
|
+
handler(...args);
|
|
2369
|
+
off(event, onceWrapper);
|
|
2370
|
+
};
|
|
2371
|
+
onceHandlers.set(handler, onceWrapper);
|
|
2372
|
+
return on(event, onceWrapper);
|
|
2373
|
+
};
|
|
2374
|
+
const off = (event, handler) => {
|
|
2375
|
+
if (!handler) {
|
|
2376
|
+
events.delete(event);
|
|
2377
|
+
return;
|
|
2378
|
+
}
|
|
2379
|
+
const handlers = events.get(event);
|
|
2380
|
+
if (!handlers)
|
|
2381
|
+
return;
|
|
2382
|
+
handlers.delete(handler);
|
|
2383
|
+
const onceWrapper = onceHandlers.get(handler);
|
|
2384
|
+
if (onceWrapper) {
|
|
2385
|
+
handlers.delete(onceWrapper);
|
|
2386
|
+
onceHandlers.delete(handler);
|
|
2387
|
+
}
|
|
2388
|
+
if (handlers.size === 0) {
|
|
2389
|
+
events.delete(event);
|
|
2390
|
+
}
|
|
2391
|
+
};
|
|
2392
|
+
const emit = (event, ...args) => {
|
|
2393
|
+
const handlers = events.get(event);
|
|
2394
|
+
if (!handlers)
|
|
2395
|
+
return;
|
|
2396
|
+
const handlersCopy = Array.from(handlers);
|
|
2397
|
+
for (const handler of handlersCopy) {
|
|
2398
|
+
try {
|
|
2399
|
+
handler(...args);
|
|
2400
|
+
} catch (error) {
|
|
2401
|
+
console.error(`Error in event handler for "${event}":`, error);
|
|
2402
|
+
}
|
|
2403
|
+
}
|
|
2404
|
+
};
|
|
2405
|
+
const clear = (event) => {
|
|
2406
|
+
if (event) {
|
|
2407
|
+
events.delete(event);
|
|
2408
|
+
} else {
|
|
2409
|
+
events.clear();
|
|
2410
|
+
}
|
|
2411
|
+
};
|
|
2412
|
+
return { on, once, off, emit, clear };
|
|
2413
|
+
}
|
|
2414
|
+
var eventBus = createEventBus();
|
|
2415
|
+
function useEvent(event, handler, options = {}) {
|
|
2416
|
+
return options.once ? eventBus.once(event, handler) : eventBus.on(event, handler);
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
// src/core/router.ts
|
|
2420
|
+
init_context();
|
|
2421
|
+
init_hooks();
|
|
2422
|
+
var RouterContext = createContext({
|
|
2423
|
+
pathname: "/",
|
|
2424
|
+
search: "",
|
|
2425
|
+
hash: "",
|
|
2426
|
+
params: {},
|
|
2427
|
+
query: {},
|
|
2428
|
+
navigate: () => {
|
|
2429
|
+
},
|
|
2430
|
+
back: () => {
|
|
2431
|
+
},
|
|
2432
|
+
forward: () => {
|
|
2433
|
+
},
|
|
2434
|
+
match: () => false
|
|
2435
|
+
});
|
|
2436
|
+
function parseQuery(search) {
|
|
2437
|
+
const query = {};
|
|
2438
|
+
const params = new URLSearchParams(search);
|
|
2439
|
+
params.forEach((value, key) => {
|
|
2440
|
+
query[key] = value;
|
|
2441
|
+
});
|
|
2442
|
+
return query;
|
|
2443
|
+
}
|
|
2444
|
+
function matchPath(pathname, pattern, exact = false) {
|
|
2445
|
+
const params = {};
|
|
2446
|
+
const patternParts = pattern.split("/").filter(Boolean);
|
|
2447
|
+
const pathParts = pathname.split("/").filter(Boolean);
|
|
2448
|
+
if (exact && patternParts.length !== pathParts.length) {
|
|
2449
|
+
return { match: false, params };
|
|
2450
|
+
}
|
|
2451
|
+
if (patternParts.length > pathParts.length) {
|
|
2452
|
+
return { match: false, params };
|
|
2453
|
+
}
|
|
2454
|
+
for (let i = 0; i < patternParts.length; i++) {
|
|
2455
|
+
const patternPart = patternParts[i];
|
|
2456
|
+
const pathPart = pathParts[i];
|
|
2457
|
+
if (patternPart.startsWith(":")) {
|
|
2458
|
+
const paramName = patternPart.slice(1);
|
|
2459
|
+
params[paramName] = decodeURIComponent(pathPart);
|
|
2460
|
+
} else if (patternPart === "*") {
|
|
2461
|
+
params["*"] = pathParts.slice(i).join("/");
|
|
2462
|
+
return { match: true, params };
|
|
2463
|
+
} else if (patternPart !== pathPart) {
|
|
2464
|
+
return { match: false, params };
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
return { match: true, params };
|
|
2468
|
+
}
|
|
2469
|
+
function RouterProvider({
|
|
2470
|
+
children
|
|
2471
|
+
}) {
|
|
2472
|
+
const [location, setLocation] = useState((() => {
|
|
2473
|
+
if (typeof window === "undefined") {
|
|
2474
|
+
return { pathname: "/", search: "", hash: "", params: {}, query: {} };
|
|
2475
|
+
}
|
|
2476
|
+
return {
|
|
2477
|
+
pathname: window.location.pathname,
|
|
2478
|
+
search: window.location.search,
|
|
2479
|
+
hash: window.location.hash,
|
|
2480
|
+
params: {},
|
|
2481
|
+
query: parseQuery(window.location.search)
|
|
2482
|
+
};
|
|
2483
|
+
})());
|
|
2484
|
+
useEffect(() => {
|
|
2485
|
+
if (typeof window === "undefined")
|
|
2486
|
+
return;
|
|
2487
|
+
const handlePopState = () => {
|
|
2488
|
+
setLocation({
|
|
2489
|
+
pathname: window.location.pathname,
|
|
2490
|
+
search: window.location.search,
|
|
2491
|
+
hash: window.location.hash,
|
|
2492
|
+
params: {},
|
|
2493
|
+
query: parseQuery(window.location.search)
|
|
2494
|
+
});
|
|
2495
|
+
};
|
|
2496
|
+
window.addEventListener("popstate", handlePopState);
|
|
2497
|
+
return () => window.removeEventListener("popstate", handlePopState);
|
|
2498
|
+
}, []);
|
|
2499
|
+
const navigate = (to, options = {}) => {
|
|
2500
|
+
if (typeof window === "undefined")
|
|
2501
|
+
return;
|
|
2502
|
+
const url = new URL(to, window.location.origin);
|
|
2503
|
+
if (options.replace) {
|
|
2504
|
+
window.history.replaceState(options.state || null, "", url.href);
|
|
2505
|
+
} else {
|
|
2506
|
+
window.history.pushState(options.state || null, "", url.href);
|
|
2507
|
+
}
|
|
2508
|
+
setLocation({
|
|
2509
|
+
pathname: url.pathname,
|
|
2510
|
+
search: url.search,
|
|
2511
|
+
hash: url.hash,
|
|
2512
|
+
params: {},
|
|
2513
|
+
query: parseQuery(url.search)
|
|
2514
|
+
});
|
|
2515
|
+
};
|
|
2516
|
+
const back = () => {
|
|
2517
|
+
if (typeof window !== "undefined") {
|
|
2518
|
+
window.history.back();
|
|
2519
|
+
}
|
|
2520
|
+
};
|
|
2521
|
+
const forward = () => {
|
|
2522
|
+
if (typeof window !== "undefined") {
|
|
2523
|
+
window.history.forward();
|
|
2524
|
+
}
|
|
2525
|
+
};
|
|
2526
|
+
const match = (pattern) => {
|
|
2527
|
+
return matchPath(location.pathname, pattern).match;
|
|
2528
|
+
};
|
|
2529
|
+
const contextValue = {
|
|
2530
|
+
...location,
|
|
2531
|
+
navigate,
|
|
2532
|
+
back,
|
|
2533
|
+
forward,
|
|
2534
|
+
match
|
|
2535
|
+
};
|
|
2536
|
+
return jsx(RouterContext.Provider, { value: contextValue, children });
|
|
2537
|
+
}
|
|
2538
|
+
function Router({ routes }) {
|
|
2539
|
+
const { pathname, params: existingParams } = useContext(RouterContext);
|
|
2540
|
+
for (const route of routes) {
|
|
2541
|
+
const { match, params } = matchPath(pathname, route.path, route.exact);
|
|
2542
|
+
if (match) {
|
|
2543
|
+
const Component2 = route.component;
|
|
2544
|
+
return jsx(Component2, { ...params, ...existingParams });
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
return null;
|
|
2548
|
+
}
|
|
2549
|
+
function Route({
|
|
2550
|
+
path: path5,
|
|
2551
|
+
component: Component2,
|
|
2552
|
+
exact = false
|
|
2553
|
+
}) {
|
|
2554
|
+
const { pathname } = useContext(RouterContext);
|
|
2555
|
+
const { match, params } = matchPath(pathname, path5, exact);
|
|
2556
|
+
if (match) {
|
|
2557
|
+
return jsx(Component2, params);
|
|
2558
|
+
}
|
|
2559
|
+
return null;
|
|
2560
|
+
}
|
|
2561
|
+
function Switch({ children }) {
|
|
2562
|
+
const { pathname } = useContext(RouterContext);
|
|
2563
|
+
const routes = Array.isArray(children) ? children : [children];
|
|
2564
|
+
for (const child of routes) {
|
|
2565
|
+
if (child?.props?.path) {
|
|
2566
|
+
const exact = child.props.exact ?? false;
|
|
2567
|
+
const { match } = matchPath(pathname, child.props.path, exact);
|
|
2568
|
+
if (match) {
|
|
2569
|
+
return child;
|
|
2570
|
+
}
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
return null;
|
|
2574
|
+
}
|
|
2575
|
+
function Link({
|
|
2576
|
+
to,
|
|
2577
|
+
children,
|
|
2578
|
+
replace = false,
|
|
2579
|
+
className = "",
|
|
2580
|
+
activeClassName = "",
|
|
2581
|
+
...rest
|
|
2582
|
+
}) {
|
|
2583
|
+
const { pathname, navigate } = useContext(RouterContext);
|
|
2584
|
+
const isActive = pathname === to || pathname.startsWith(to + "/");
|
|
2585
|
+
const handleClick = (e) => {
|
|
2586
|
+
e.preventDefault();
|
|
2587
|
+
navigate(to, { replace });
|
|
2588
|
+
};
|
|
2589
|
+
const combinedClassName = isActive && activeClassName ? `${className} ${activeClassName}`.trim() : className;
|
|
2590
|
+
return jsx("a", {
|
|
2591
|
+
href: to,
|
|
2592
|
+
onClick: handleClick,
|
|
2593
|
+
className: combinedClassName || void 0,
|
|
2594
|
+
...rest,
|
|
2595
|
+
children
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
2598
|
+
function Redirect({
|
|
2599
|
+
to,
|
|
2600
|
+
replace = true
|
|
2601
|
+
}) {
|
|
2602
|
+
const { navigate } = useContext(RouterContext);
|
|
2603
|
+
useEffect(() => {
|
|
2604
|
+
navigate(to, { replace });
|
|
2605
|
+
}, [to, replace]);
|
|
2606
|
+
return null;
|
|
2607
|
+
}
|
|
2608
|
+
function NavLink({
|
|
2609
|
+
to,
|
|
2610
|
+
children,
|
|
2611
|
+
activeClassName = "active",
|
|
2612
|
+
className = "",
|
|
2613
|
+
exact = false,
|
|
2614
|
+
...rest
|
|
2615
|
+
}) {
|
|
2616
|
+
const { pathname, navigate } = useContext(RouterContext);
|
|
2617
|
+
const { match } = matchPath(pathname, to, exact);
|
|
2618
|
+
const isActive = match;
|
|
2619
|
+
const combinedClassName = isActive ? `${className} ${activeClassName}`.trim() : className;
|
|
2620
|
+
const handleClick = (e) => {
|
|
2621
|
+
e.preventDefault();
|
|
2622
|
+
navigate(to);
|
|
2623
|
+
};
|
|
2624
|
+
return jsx("a", {
|
|
2625
|
+
href: to,
|
|
2626
|
+
onClick: handleClick,
|
|
2627
|
+
className: combinedClassName || void 0,
|
|
2628
|
+
"aria-current": isActive ? "page" : void 0,
|
|
2629
|
+
...rest,
|
|
2630
|
+
children
|
|
2631
|
+
});
|
|
2632
|
+
}
|
|
2633
|
+
function useRouter() {
|
|
2634
|
+
return useContext(RouterContext);
|
|
2635
|
+
}
|
|
2636
|
+
function useLocation() {
|
|
2637
|
+
const { pathname, search, hash, params, query } = useContext(RouterContext);
|
|
2638
|
+
return { pathname, search, hash, params, query };
|
|
2639
|
+
}
|
|
2640
|
+
function useParams() {
|
|
2641
|
+
const { params } = useContext(RouterContext);
|
|
2642
|
+
return params;
|
|
2643
|
+
}
|
|
2644
|
+
function useNavigate() {
|
|
2645
|
+
const { navigate } = useContext(RouterContext);
|
|
2646
|
+
return navigate;
|
|
2647
|
+
}
|
|
2648
|
+
function useSearchParams() {
|
|
2649
|
+
const { search, navigate, pathname } = useContext(RouterContext);
|
|
2650
|
+
const searchParams = new URLSearchParams(search);
|
|
2651
|
+
const setSearchParams = (newParams) => {
|
|
2652
|
+
navigate(`${pathname}?${newParams.toString()}`);
|
|
2653
|
+
};
|
|
2654
|
+
return [searchParams, setSearchParams];
|
|
2655
|
+
}
|
|
2656
|
+
function useMatch(pattern) {
|
|
2657
|
+
const { pathname } = useContext(RouterContext);
|
|
2658
|
+
const { match, params } = matchPath(pathname, pattern);
|
|
2659
|
+
return match ? params : null;
|
|
2660
|
+
}
|
|
2661
|
+
|
|
2662
|
+
// src/core/forms.ts
|
|
2663
|
+
init_hooks();
|
|
2664
|
+
function validateFieldValue(value, rules, allValues) {
|
|
2665
|
+
if (rules.required) {
|
|
2666
|
+
const isEmpty2 = value === void 0 || value === null || value === "" || Array.isArray(value) && value.length === 0;
|
|
2667
|
+
if (isEmpty2) {
|
|
2668
|
+
return typeof rules.required === "string" ? rules.required : "This field is required";
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
if (value === void 0 || value === null || value === "") {
|
|
2672
|
+
return void 0;
|
|
2673
|
+
}
|
|
2674
|
+
if (rules.minLength !== void 0) {
|
|
2675
|
+
const minLength = typeof rules.minLength === "object" ? rules.minLength.value : rules.minLength;
|
|
2676
|
+
const message = typeof rules.minLength === "object" ? rules.minLength.message : `Minimum length is ${minLength}`;
|
|
2677
|
+
if (String(value).length < minLength) {
|
|
2678
|
+
return message;
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
if (rules.maxLength !== void 0) {
|
|
2682
|
+
const maxLength = typeof rules.maxLength === "object" ? rules.maxLength.value : rules.maxLength;
|
|
2683
|
+
const message = typeof rules.maxLength === "object" ? rules.maxLength.message : `Maximum length is ${maxLength}`;
|
|
2684
|
+
if (String(value).length > maxLength) {
|
|
2685
|
+
return message;
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
if (rules.min !== void 0) {
|
|
2689
|
+
const min = typeof rules.min === "object" ? rules.min.value : rules.min;
|
|
2690
|
+
const message = typeof rules.min === "object" ? rules.min.message : `Minimum value is ${min}`;
|
|
2691
|
+
if (Number(value) < min) {
|
|
2692
|
+
return message;
|
|
2693
|
+
}
|
|
2694
|
+
}
|
|
2695
|
+
if (rules.max !== void 0) {
|
|
2696
|
+
const max = typeof rules.max === "object" ? rules.max.value : rules.max;
|
|
2697
|
+
const message = typeof rules.max === "object" ? rules.max.message : `Maximum value is ${max}`;
|
|
2698
|
+
if (Number(value) > max) {
|
|
2699
|
+
return message;
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
if (rules.pattern !== void 0) {
|
|
2703
|
+
const pattern = rules.pattern instanceof RegExp ? rules.pattern : rules.pattern.value;
|
|
2704
|
+
const message = rules.pattern instanceof RegExp ? "Invalid format" : rules.pattern.message;
|
|
2705
|
+
if (!pattern.test(String(value))) {
|
|
2706
|
+
return message;
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
if (rules.validate) {
|
|
2710
|
+
const result = rules.validate(value, allValues);
|
|
2711
|
+
if (result === false) {
|
|
2712
|
+
return "Invalid value";
|
|
2713
|
+
}
|
|
2714
|
+
if (typeof result === "string") {
|
|
2715
|
+
return result;
|
|
2716
|
+
}
|
|
2717
|
+
}
|
|
2718
|
+
return void 0;
|
|
2719
|
+
}
|
|
2720
|
+
function useForm(options) {
|
|
2721
|
+
const {
|
|
2722
|
+
initialValues,
|
|
2723
|
+
validate,
|
|
2724
|
+
validationRules,
|
|
2725
|
+
onSubmit,
|
|
2726
|
+
validateOnChange = true,
|
|
2727
|
+
validateOnBlur = true
|
|
2728
|
+
} = options;
|
|
2729
|
+
const [values, setValuesState] = useState(initialValues);
|
|
2730
|
+
const [errors, setErrorsState] = useState({});
|
|
2731
|
+
const [touched, setTouched] = useState({});
|
|
2732
|
+
const [dirty, setDirty] = useState({});
|
|
2733
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
2734
|
+
const [submitCount, setSubmitCount] = useState(0);
|
|
2735
|
+
const initialValuesRef = useRef(initialValues);
|
|
2736
|
+
const isValid = Object.keys(errors).length === 0;
|
|
2737
|
+
const isDirty = Object.values(dirty).some(Boolean);
|
|
2738
|
+
const validateField = useCallback((field) => {
|
|
2739
|
+
const value = values[field];
|
|
2740
|
+
if (validationRules && validationRules[field]) {
|
|
2741
|
+
return validateFieldValue(value, validationRules[field], values);
|
|
2742
|
+
}
|
|
2743
|
+
if (validate) {
|
|
2744
|
+
const allErrors = validate(values);
|
|
2745
|
+
return allErrors[field];
|
|
2746
|
+
}
|
|
2747
|
+
return void 0;
|
|
2748
|
+
}, [values, validate, validationRules]);
|
|
2749
|
+
const validateForm = useCallback(() => {
|
|
2750
|
+
const newErrors = {};
|
|
2751
|
+
if (validationRules) {
|
|
2752
|
+
for (const field in validationRules) {
|
|
2753
|
+
const error = validateFieldValue(values[field], validationRules[field], values);
|
|
2754
|
+
if (error) {
|
|
2755
|
+
newErrors[field] = error;
|
|
2756
|
+
}
|
|
2757
|
+
}
|
|
2758
|
+
}
|
|
2759
|
+
if (validate) {
|
|
2760
|
+
const customErrors = validate(values);
|
|
2761
|
+
Object.assign(newErrors, customErrors);
|
|
2762
|
+
}
|
|
2763
|
+
return newErrors;
|
|
2764
|
+
}, [values, validate, validationRules]);
|
|
2765
|
+
useEffect(() => {
|
|
2766
|
+
if (validateOnChange) {
|
|
2767
|
+
const newErrors = validateForm();
|
|
2768
|
+
setErrorsState(newErrors);
|
|
2769
|
+
}
|
|
2770
|
+
}, [values, validateOnChange, validateForm]);
|
|
2771
|
+
const handleChange = useCallback((e) => {
|
|
2772
|
+
const { name, value, type, checked } = e.target;
|
|
2773
|
+
const fieldValue = type === "checkbox" ? checked : value;
|
|
2774
|
+
setValuesState((prev) => ({ ...prev, [name]: fieldValue }));
|
|
2775
|
+
setDirty((prev) => ({ ...prev, [name]: true }));
|
|
2776
|
+
}, []);
|
|
2777
|
+
const handleBlur = useCallback((e) => {
|
|
2778
|
+
const { name } = e.target;
|
|
2779
|
+
setTouched((prev) => ({ ...prev, [name]: true }));
|
|
2780
|
+
if (validateOnBlur) {
|
|
2781
|
+
const error = validateField(name);
|
|
2782
|
+
setErrorsState((prev) => {
|
|
2783
|
+
if (error) {
|
|
2784
|
+
return { ...prev, [name]: error };
|
|
2785
|
+
}
|
|
2786
|
+
const { [name]: _, ...rest } = prev;
|
|
2787
|
+
return rest;
|
|
2788
|
+
});
|
|
2789
|
+
}
|
|
2790
|
+
}, [validateOnBlur, validateField]);
|
|
2791
|
+
const handleSubmit = useCallback(async (e) => {
|
|
2792
|
+
if (e?.preventDefault) {
|
|
2793
|
+
e.preventDefault();
|
|
2794
|
+
}
|
|
2795
|
+
setSubmitCount((prev) => prev + 1);
|
|
2796
|
+
const allTouched = {};
|
|
2797
|
+
for (const key in values) {
|
|
2798
|
+
allTouched[key] = true;
|
|
2799
|
+
}
|
|
2800
|
+
setTouched(allTouched);
|
|
2801
|
+
const formErrors = validateForm();
|
|
2802
|
+
setErrorsState(formErrors);
|
|
2803
|
+
if (Object.keys(formErrors).length > 0) {
|
|
2804
|
+
return;
|
|
2805
|
+
}
|
|
2806
|
+
if (onSubmit) {
|
|
2807
|
+
setIsSubmitting(true);
|
|
2808
|
+
try {
|
|
2809
|
+
await onSubmit(values, formConfig);
|
|
2810
|
+
} finally {
|
|
2811
|
+
setIsSubmitting(false);
|
|
2812
|
+
}
|
|
2813
|
+
}
|
|
2814
|
+
}, [values, validateForm, onSubmit]);
|
|
2815
|
+
const setFieldValue = useCallback((field, value) => {
|
|
2816
|
+
setValuesState((prev) => ({ ...prev, [field]: value }));
|
|
2817
|
+
setDirty((prev) => ({ ...prev, [field]: true }));
|
|
2818
|
+
}, []);
|
|
2819
|
+
const setFieldError = useCallback((field, error) => {
|
|
2820
|
+
setErrorsState((prev) => ({ ...prev, [field]: error }));
|
|
2821
|
+
}, []);
|
|
2822
|
+
const setFieldTouched = useCallback((field, isTouched = true) => {
|
|
2823
|
+
setTouched((prev) => ({ ...prev, [field]: isTouched }));
|
|
2824
|
+
}, []);
|
|
2825
|
+
const setValues = useCallback((newValues) => {
|
|
2826
|
+
setValuesState((prev) => ({ ...prev, ...newValues }));
|
|
2827
|
+
}, []);
|
|
2828
|
+
const setErrors = useCallback((newErrors) => {
|
|
2829
|
+
setErrorsState(newErrors);
|
|
2830
|
+
}, []);
|
|
2831
|
+
const resetForm = useCallback((nextValues) => {
|
|
2832
|
+
setValuesState(nextValues ? { ...initialValuesRef.current, ...nextValues } : initialValuesRef.current);
|
|
2833
|
+
setErrorsState({});
|
|
2834
|
+
setTouched({});
|
|
2835
|
+
setDirty({});
|
|
2836
|
+
setSubmitCount(0);
|
|
2837
|
+
}, []);
|
|
2838
|
+
const getFieldProps = useCallback((field) => ({
|
|
2839
|
+
name: field,
|
|
2840
|
+
value: values[field] ?? "",
|
|
2841
|
+
onChange: handleChange,
|
|
2842
|
+
onBlur: handleBlur
|
|
2843
|
+
}), [values, handleChange, handleBlur]);
|
|
2844
|
+
const formConfig = {
|
|
2845
|
+
values,
|
|
2846
|
+
errors,
|
|
2847
|
+
touched,
|
|
2848
|
+
dirty,
|
|
2849
|
+
isValid,
|
|
2850
|
+
isDirty,
|
|
2851
|
+
isSubmitting,
|
|
2852
|
+
submitCount,
|
|
2853
|
+
handleChange,
|
|
2854
|
+
handleBlur,
|
|
2855
|
+
handleSubmit,
|
|
2856
|
+
setFieldValue,
|
|
2857
|
+
setFieldError,
|
|
2858
|
+
setFieldTouched,
|
|
2859
|
+
setValues,
|
|
2860
|
+
setErrors,
|
|
2861
|
+
resetForm,
|
|
2862
|
+
validateField,
|
|
2863
|
+
validateForm,
|
|
2864
|
+
getFieldProps,
|
|
2865
|
+
register: getFieldProps
|
|
2866
|
+
};
|
|
2867
|
+
return formConfig;
|
|
2868
|
+
}
|
|
2869
|
+
function useField(name, form) {
|
|
2870
|
+
return {
|
|
2871
|
+
field: form.getFieldProps(name),
|
|
2872
|
+
meta: {
|
|
2873
|
+
touched: form.touched[name] || false,
|
|
2874
|
+
error: form.errors[name],
|
|
2875
|
+
dirty: form.dirty[name] || false
|
|
2876
|
+
},
|
|
2877
|
+
helpers: {
|
|
2878
|
+
setValue: (value) => form.setFieldValue(name, value),
|
|
2879
|
+
setError: (error) => form.setFieldError(name, error),
|
|
2880
|
+
setTouched: (touched) => form.setFieldTouched(name, touched)
|
|
2881
|
+
}
|
|
2882
|
+
};
|
|
2883
|
+
}
|
|
2884
|
+
var patterns = {
|
|
2885
|
+
email: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
|
|
2886
|
+
phone: /^\+?[1-9]\d{1,14}$/,
|
|
2887
|
+
url: /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/,
|
|
2888
|
+
alphanumeric: /^[a-zA-Z0-9]+$/,
|
|
2889
|
+
numeric: /^\d+$/,
|
|
2890
|
+
password: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$/
|
|
2891
|
+
};
|
|
2892
|
+
|
|
2893
|
+
// src/core/store.ts
|
|
2894
|
+
init_context();
|
|
2895
|
+
init_hooks();
|
|
2896
|
+
function createStore(reducer, initialState, middlewares = []) {
|
|
2897
|
+
let state = initialState;
|
|
2898
|
+
let listeners = /* @__PURE__ */ new Set();
|
|
2899
|
+
let currentReducer = reducer;
|
|
2900
|
+
const getState = () => state;
|
|
2901
|
+
const subscribe = (listener) => {
|
|
2902
|
+
listeners.add(listener);
|
|
2903
|
+
return () => {
|
|
2904
|
+
listeners.delete(listener);
|
|
2905
|
+
};
|
|
2906
|
+
};
|
|
2907
|
+
let dispatch = (action) => {
|
|
2908
|
+
state = currentReducer(state, action);
|
|
2909
|
+
listeners.forEach((listener) => listener());
|
|
2910
|
+
};
|
|
2911
|
+
if (middlewares.length > 0) {
|
|
2912
|
+
const store = { getState, dispatch, subscribe, replaceReducer: () => {
|
|
2913
|
+
} };
|
|
2914
|
+
const chain = middlewares.map((middleware) => middleware(store));
|
|
2915
|
+
dispatch = chain.reduceRight(
|
|
2916
|
+
(next, middleware) => middleware(next),
|
|
2917
|
+
dispatch
|
|
2918
|
+
);
|
|
2919
|
+
}
|
|
2920
|
+
const replaceReducer = (nextReducer) => {
|
|
2921
|
+
currentReducer = nextReducer;
|
|
2922
|
+
};
|
|
2923
|
+
dispatch({ type: "@@INIT" });
|
|
2924
|
+
return {
|
|
2925
|
+
getState,
|
|
2926
|
+
dispatch,
|
|
2927
|
+
subscribe,
|
|
2928
|
+
replaceReducer
|
|
2929
|
+
};
|
|
2930
|
+
}
|
|
2931
|
+
function combineReducers(reducers) {
|
|
2932
|
+
return (state, action) => {
|
|
2933
|
+
const nextState = {};
|
|
2934
|
+
let hasChanged = false;
|
|
2935
|
+
for (const key in reducers) {
|
|
2936
|
+
const reducer = reducers[key];
|
|
2937
|
+
const previousStateForKey = state[key];
|
|
2938
|
+
const nextStateForKey = reducer(previousStateForKey, action);
|
|
2939
|
+
nextState[key] = nextStateForKey;
|
|
2940
|
+
hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
|
|
2941
|
+
}
|
|
2942
|
+
return hasChanged ? nextState : state;
|
|
2943
|
+
};
|
|
2944
|
+
}
|
|
2945
|
+
var StoreContext = createContext({
|
|
2946
|
+
store: {
|
|
2947
|
+
getState: () => ({}),
|
|
2948
|
+
dispatch: () => {
|
|
2949
|
+
},
|
|
2950
|
+
subscribe: () => () => {
|
|
2951
|
+
},
|
|
2952
|
+
replaceReducer: () => {
|
|
2953
|
+
}
|
|
2954
|
+
},
|
|
2955
|
+
state: {}
|
|
2956
|
+
});
|
|
2957
|
+
function StoreProvider({
|
|
2958
|
+
store,
|
|
2959
|
+
children
|
|
2960
|
+
}) {
|
|
2961
|
+
const [state, setState] = useState(store.getState());
|
|
2962
|
+
useEffect(() => {
|
|
2963
|
+
const unsubscribe = store.subscribe(() => {
|
|
2964
|
+
setState(store.getState());
|
|
2965
|
+
});
|
|
2966
|
+
return unsubscribe;
|
|
2967
|
+
}, [store]);
|
|
2968
|
+
return jsx(StoreContext.Provider, {
|
|
2969
|
+
value: { store, state },
|
|
2970
|
+
children
|
|
2971
|
+
});
|
|
2972
|
+
}
|
|
2973
|
+
function useSelector(selector) {
|
|
2974
|
+
const { state } = useContext(StoreContext);
|
|
2975
|
+
return selector(state);
|
|
2976
|
+
}
|
|
2977
|
+
function useDispatch() {
|
|
2978
|
+
const { store } = useContext(StoreContext);
|
|
2979
|
+
return store.dispatch;
|
|
2980
|
+
}
|
|
2981
|
+
function useStore() {
|
|
2982
|
+
const { store } = useContext(StoreContext);
|
|
2983
|
+
return store;
|
|
2984
|
+
}
|
|
2985
|
+
var logger = (store) => (next) => (action) => {
|
|
2986
|
+
console.group(`Action: ${action.type}`);
|
|
2987
|
+
console.log("Payload:", action.payload);
|
|
2988
|
+
console.log("Previous State:", store.getState());
|
|
2989
|
+
const result = next(action);
|
|
2990
|
+
console.log("Next State:", store.getState());
|
|
2991
|
+
console.groupEnd();
|
|
2992
|
+
return result;
|
|
2993
|
+
};
|
|
2994
|
+
var thunk = (store) => (next) => (action) => {
|
|
2995
|
+
if (typeof action === "function") {
|
|
2996
|
+
return action(store.dispatch, store.getState);
|
|
2997
|
+
}
|
|
2998
|
+
return next(action);
|
|
2999
|
+
};
|
|
3000
|
+
var devTools = (store) => (next) => (action) => {
|
|
3001
|
+
if (typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION__) {
|
|
3002
|
+
const devToolsExtension = window.__REDUX_DEVTOOLS_EXTENSION__;
|
|
3003
|
+
devToolsExtension.send(action, store.getState());
|
|
3004
|
+
}
|
|
3005
|
+
return next(action);
|
|
3006
|
+
};
|
|
3007
|
+
function createAction(type) {
|
|
3008
|
+
const actionCreator = (payload) => ({ type, payload });
|
|
3009
|
+
actionCreator.type = type;
|
|
3010
|
+
actionCreator.match = (action) => action.type === type;
|
|
3011
|
+
return actionCreator;
|
|
3012
|
+
}
|
|
3013
|
+
function createSlice(config) {
|
|
3014
|
+
const { name, initialState, reducers } = config;
|
|
3015
|
+
const actions = {};
|
|
3016
|
+
for (const key in reducers) {
|
|
3017
|
+
const type = `${name}/${key}`;
|
|
3018
|
+
actions[key] = (payload) => ({ type, payload });
|
|
3019
|
+
}
|
|
3020
|
+
const reducer = (state = initialState, action) => {
|
|
3021
|
+
for (const key in reducers) {
|
|
3022
|
+
const type = `${name}/${key}`;
|
|
3023
|
+
if (action.type === type) {
|
|
3024
|
+
return reducers[key](state, action);
|
|
3025
|
+
}
|
|
3026
|
+
}
|
|
3027
|
+
return state;
|
|
3028
|
+
};
|
|
3029
|
+
return {
|
|
3030
|
+
name,
|
|
3031
|
+
reducer,
|
|
3032
|
+
actions
|
|
3033
|
+
};
|
|
3034
|
+
}
|
|
3035
|
+
|
|
3036
|
+
// src/core/lifecycle-events.ts
|
|
3037
|
+
var LifecycleEvents = /* @__PURE__ */ ((LifecycleEvents2) => {
|
|
3038
|
+
LifecycleEvents2["APP_INIT"] = "app:init";
|
|
3039
|
+
LifecycleEvents2["APP_MOUNTED"] = "app:mounted";
|
|
3040
|
+
LifecycleEvents2["APP_UPDATED"] = "app:updated";
|
|
3041
|
+
LifecycleEvents2["APP_ERROR"] = "app:error";
|
|
3042
|
+
LifecycleEvents2["APP_DESTROYED"] = "app:destroyed";
|
|
3043
|
+
LifecycleEvents2["COMPONENT_CREATED"] = "component:created";
|
|
3044
|
+
LifecycleEvents2["COMPONENT_MOUNTED"] = "component:mounted";
|
|
3045
|
+
LifecycleEvents2["COMPONENT_UPDATED"] = "component:updated";
|
|
3046
|
+
LifecycleEvents2["COMPONENT_ERROR"] = "component:error";
|
|
3047
|
+
LifecycleEvents2["COMPONENT_UNMOUNTED"] = "component:unmounted";
|
|
3048
|
+
LifecycleEvents2["ROUTER_BEFORE_CHANGE"] = "router:before-change";
|
|
3049
|
+
LifecycleEvents2["ROUTER_AFTER_CHANGE"] = "router:after-change";
|
|
3050
|
+
LifecycleEvents2["ROUTER_ERROR"] = "router:error";
|
|
3051
|
+
LifecycleEvents2["STORE_INITIALIZED"] = "store:initialized";
|
|
3052
|
+
LifecycleEvents2["STORE_BEFORE_ACTION"] = "store:before-action";
|
|
3053
|
+
LifecycleEvents2["STORE_AFTER_ACTION"] = "store:after-action";
|
|
3054
|
+
LifecycleEvents2["STORE_ERROR"] = "store:error";
|
|
3055
|
+
return LifecycleEvents2;
|
|
3056
|
+
})(LifecycleEvents || {});
|
|
3057
|
+
function emitAppInit(data) {
|
|
3058
|
+
eventBus.emit("app:init" /* APP_INIT */, data);
|
|
3059
|
+
}
|
|
3060
|
+
function emitAppMounted(rootElement) {
|
|
3061
|
+
eventBus.emit("app:mounted" /* APP_MOUNTED */, rootElement);
|
|
3062
|
+
}
|
|
3063
|
+
function emitAppUpdated() {
|
|
3064
|
+
eventBus.emit("app:updated" /* APP_UPDATED */);
|
|
3065
|
+
}
|
|
3066
|
+
function emitAppError(error) {
|
|
3067
|
+
eventBus.emit("app:error" /* APP_ERROR */, error);
|
|
3068
|
+
}
|
|
3069
|
+
function emitAppDestroyed() {
|
|
3070
|
+
eventBus.emit("app:destroyed" /* APP_DESTROYED */);
|
|
3071
|
+
}
|
|
3072
|
+
function emitComponentCreated(info) {
|
|
3073
|
+
eventBus.emit("component:created" /* COMPONENT_CREATED */, info);
|
|
3074
|
+
}
|
|
3075
|
+
function emitComponentMounted(info, element) {
|
|
3076
|
+
eventBus.emit("component:mounted" /* COMPONENT_MOUNTED */, info, element);
|
|
3077
|
+
}
|
|
3078
|
+
function emitComponentUpdated(info, prevProps, newProps) {
|
|
3079
|
+
eventBus.emit("component:updated" /* COMPONENT_UPDATED */, info, prevProps, newProps);
|
|
3080
|
+
}
|
|
3081
|
+
function emitComponentError(info, error) {
|
|
3082
|
+
eventBus.emit("component:error" /* COMPONENT_ERROR */, info, error);
|
|
3083
|
+
}
|
|
3084
|
+
function emitComponentUnmounted(info) {
|
|
3085
|
+
eventBus.emit("component:unmounted" /* COMPONENT_UNMOUNTED */, info);
|
|
3086
|
+
}
|
|
3087
|
+
function emitRouterBeforeChange(info) {
|
|
3088
|
+
return new Promise((resolve) => {
|
|
3089
|
+
let prevented = false;
|
|
3090
|
+
const prevent = () => {
|
|
3091
|
+
prevented = true;
|
|
3092
|
+
};
|
|
3093
|
+
eventBus.emit("router:before-change" /* ROUTER_BEFORE_CHANGE */, info, prevent);
|
|
3094
|
+
resolve(!prevented);
|
|
3095
|
+
});
|
|
3096
|
+
}
|
|
3097
|
+
function emitRouterAfterChange(info) {
|
|
3098
|
+
eventBus.emit("router:after-change" /* ROUTER_AFTER_CHANGE */, info);
|
|
3099
|
+
}
|
|
3100
|
+
function emitRouterError(error, info) {
|
|
3101
|
+
eventBus.emit("router:error" /* ROUTER_ERROR */, error, info);
|
|
3102
|
+
}
|
|
3103
|
+
function emitStoreInitialized(state) {
|
|
3104
|
+
eventBus.emit("store:initialized" /* STORE_INITIALIZED */, state);
|
|
3105
|
+
}
|
|
3106
|
+
function emitStoreBeforeAction(actionType, payload, state) {
|
|
3107
|
+
eventBus.emit("store:before-action" /* STORE_BEFORE_ACTION */, actionType, payload, state);
|
|
3108
|
+
}
|
|
3109
|
+
function emitStoreAfterAction(info) {
|
|
3110
|
+
eventBus.emit("store:after-action" /* STORE_AFTER_ACTION */, info);
|
|
3111
|
+
}
|
|
3112
|
+
function emitStoreError(error, actionType, payload) {
|
|
3113
|
+
eventBus.emit("store:error" /* STORE_ERROR */, error, actionType, payload);
|
|
3114
|
+
}
|
|
3115
|
+
function onAppInit(handler) {
|
|
3116
|
+
return eventBus.on("app:init" /* APP_INIT */, handler);
|
|
3117
|
+
}
|
|
3118
|
+
function onAppMounted(handler) {
|
|
3119
|
+
return eventBus.on("app:mounted" /* APP_MOUNTED */, handler);
|
|
3120
|
+
}
|
|
3121
|
+
function onAppUpdated(handler) {
|
|
3122
|
+
return eventBus.on("app:updated" /* APP_UPDATED */, handler);
|
|
3123
|
+
}
|
|
3124
|
+
function onAppError(handler) {
|
|
3125
|
+
return eventBus.on("app:error" /* APP_ERROR */, handler);
|
|
3126
|
+
}
|
|
3127
|
+
function onAppDestroyed(handler) {
|
|
3128
|
+
return eventBus.on("app:destroyed" /* APP_DESTROYED */, handler);
|
|
3129
|
+
}
|
|
3130
|
+
function onComponentCreated(handler) {
|
|
3131
|
+
return eventBus.on("component:created" /* COMPONENT_CREATED */, handler);
|
|
3132
|
+
}
|
|
3133
|
+
function onComponentMounted(handler) {
|
|
3134
|
+
return eventBus.on("component:mounted" /* COMPONENT_MOUNTED */, handler);
|
|
3135
|
+
}
|
|
3136
|
+
function onComponentUpdated(handler) {
|
|
3137
|
+
return eventBus.on("component:updated" /* COMPONENT_UPDATED */, handler);
|
|
3138
|
+
}
|
|
3139
|
+
function onComponentError(handler) {
|
|
3140
|
+
return eventBus.on("component:error" /* COMPONENT_ERROR */, handler);
|
|
3141
|
+
}
|
|
3142
|
+
function onComponentUnmounted(handler) {
|
|
3143
|
+
return eventBus.on("component:unmounted" /* COMPONENT_UNMOUNTED */, handler);
|
|
3144
|
+
}
|
|
3145
|
+
function onRouterBeforeChange(handler) {
|
|
3146
|
+
return eventBus.on("router:before-change" /* ROUTER_BEFORE_CHANGE */, handler);
|
|
3147
|
+
}
|
|
3148
|
+
function onRouterAfterChange(handler) {
|
|
3149
|
+
return eventBus.on("router:after-change" /* ROUTER_AFTER_CHANGE */, handler);
|
|
3150
|
+
}
|
|
3151
|
+
function onRouterError(handler) {
|
|
3152
|
+
return eventBus.on("router:error" /* ROUTER_ERROR */, handler);
|
|
3153
|
+
}
|
|
3154
|
+
function onStoreInitialized(handler) {
|
|
3155
|
+
return eventBus.on("store:initialized" /* STORE_INITIALIZED */, handler);
|
|
3156
|
+
}
|
|
3157
|
+
function onStoreBeforeAction(handler) {
|
|
3158
|
+
return eventBus.on("store:before-action" /* STORE_BEFORE_ACTION */, handler);
|
|
3159
|
+
}
|
|
3160
|
+
function onStoreAfterAction(handler) {
|
|
3161
|
+
return eventBus.on("store:after-action" /* STORE_AFTER_ACTION */, handler);
|
|
3162
|
+
}
|
|
3163
|
+
function onStoreError(handler) {
|
|
3164
|
+
return eventBus.on("store:error" /* STORE_ERROR */, handler);
|
|
3165
|
+
}
|
|
3166
|
+
|
|
3167
|
+
// src/core/utils.ts
|
|
3168
|
+
function debounce(func, wait, options = {}) {
|
|
3169
|
+
let timeoutId = null;
|
|
3170
|
+
let lastArgs = null;
|
|
3171
|
+
let lastThis = null;
|
|
3172
|
+
let result;
|
|
3173
|
+
let lastCallTime;
|
|
3174
|
+
let lastInvokeTime = 0;
|
|
3175
|
+
const { leading = false, trailing = true } = options;
|
|
3176
|
+
const invokeFunc = (time) => {
|
|
3177
|
+
const args = lastArgs;
|
|
3178
|
+
const thisArg = lastThis;
|
|
3179
|
+
lastArgs = null;
|
|
3180
|
+
lastThis = null;
|
|
3181
|
+
lastInvokeTime = time;
|
|
3182
|
+
result = func.apply(thisArg, args);
|
|
3183
|
+
return result;
|
|
3184
|
+
};
|
|
3185
|
+
const shouldInvoke = (time) => {
|
|
3186
|
+
const timeSinceLastCall = lastCallTime === void 0 ? 0 : time - lastCallTime;
|
|
3187
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
3188
|
+
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || timeSinceLastInvoke >= wait;
|
|
3189
|
+
};
|
|
3190
|
+
const trailingEdge = (time) => {
|
|
3191
|
+
timeoutId = null;
|
|
3192
|
+
if (trailing && lastArgs) {
|
|
3193
|
+
return invokeFunc(time);
|
|
3194
|
+
}
|
|
3195
|
+
lastArgs = null;
|
|
3196
|
+
lastThis = null;
|
|
3197
|
+
return result;
|
|
3198
|
+
};
|
|
3199
|
+
const remainingWait = (time) => {
|
|
3200
|
+
const timeSinceLastCall = lastCallTime === void 0 ? 0 : time - lastCallTime;
|
|
3201
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
3202
|
+
const timeWaiting = wait - timeSinceLastCall;
|
|
3203
|
+
return timeWaiting;
|
|
3204
|
+
};
|
|
3205
|
+
const timerExpired = () => {
|
|
3206
|
+
const time = Date.now();
|
|
3207
|
+
if (shouldInvoke(time)) {
|
|
3208
|
+
return trailingEdge(time);
|
|
3209
|
+
}
|
|
3210
|
+
timeoutId = setTimeout(timerExpired, remainingWait(time));
|
|
3211
|
+
return result;
|
|
3212
|
+
};
|
|
3213
|
+
const debounced = function(...args) {
|
|
3214
|
+
const time = Date.now();
|
|
3215
|
+
const isInvoking = shouldInvoke(time);
|
|
3216
|
+
lastArgs = args;
|
|
3217
|
+
lastThis = this;
|
|
3218
|
+
lastCallTime = time;
|
|
3219
|
+
if (isInvoking) {
|
|
3220
|
+
if (timeoutId === null) {
|
|
3221
|
+
lastInvokeTime = time;
|
|
3222
|
+
timeoutId = setTimeout(timerExpired, wait);
|
|
3223
|
+
if (leading) {
|
|
3224
|
+
return invokeFunc(time);
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
}
|
|
3228
|
+
if (timeoutId === null) {
|
|
3229
|
+
timeoutId = setTimeout(timerExpired, wait);
|
|
3230
|
+
}
|
|
3231
|
+
return result;
|
|
3232
|
+
};
|
|
3233
|
+
debounced.cancel = () => {
|
|
3234
|
+
if (timeoutId !== null) {
|
|
3235
|
+
clearTimeout(timeoutId);
|
|
3236
|
+
}
|
|
3237
|
+
lastInvokeTime = 0;
|
|
3238
|
+
lastArgs = null;
|
|
3239
|
+
lastThis = null;
|
|
3240
|
+
lastCallTime = void 0;
|
|
3241
|
+
timeoutId = null;
|
|
3242
|
+
};
|
|
3243
|
+
debounced.flush = () => {
|
|
3244
|
+
if (timeoutId !== null) {
|
|
3245
|
+
return trailingEdge(Date.now());
|
|
3246
|
+
}
|
|
3247
|
+
return result;
|
|
3248
|
+
};
|
|
3249
|
+
return debounced;
|
|
3250
|
+
}
|
|
3251
|
+
function throttle(func, wait, options = {}) {
|
|
3252
|
+
let timeoutId = null;
|
|
3253
|
+
let lastArgs = null;
|
|
3254
|
+
let lastThis = null;
|
|
3255
|
+
let result;
|
|
3256
|
+
let lastCallTime = 0;
|
|
3257
|
+
const { leading = true, trailing = true } = options;
|
|
3258
|
+
const invokeFunc = () => {
|
|
3259
|
+
const args = lastArgs;
|
|
3260
|
+
const thisArg = lastThis;
|
|
3261
|
+
lastArgs = null;
|
|
3262
|
+
lastThis = null;
|
|
3263
|
+
lastCallTime = Date.now();
|
|
3264
|
+
result = func.apply(thisArg, args);
|
|
3265
|
+
return result;
|
|
3266
|
+
};
|
|
3267
|
+
const throttled = function(...args) {
|
|
3268
|
+
const now = Date.now();
|
|
3269
|
+
const remaining = wait - (now - lastCallTime);
|
|
3270
|
+
lastArgs = args;
|
|
3271
|
+
lastThis = this;
|
|
3272
|
+
if (remaining <= 0 || remaining > wait) {
|
|
3273
|
+
if (timeoutId) {
|
|
3274
|
+
clearTimeout(timeoutId);
|
|
3275
|
+
timeoutId = null;
|
|
3276
|
+
}
|
|
3277
|
+
if (leading || lastCallTime !== 0) {
|
|
3278
|
+
return invokeFunc();
|
|
3279
|
+
}
|
|
3280
|
+
}
|
|
3281
|
+
if (!timeoutId && trailing) {
|
|
3282
|
+
timeoutId = setTimeout(() => {
|
|
3283
|
+
timeoutId = null;
|
|
3284
|
+
if (trailing && lastArgs) {
|
|
3285
|
+
invokeFunc();
|
|
3286
|
+
}
|
|
3287
|
+
}, remaining);
|
|
3288
|
+
}
|
|
3289
|
+
return result;
|
|
3290
|
+
};
|
|
3291
|
+
throttled.cancel = () => {
|
|
3292
|
+
if (timeoutId !== null) {
|
|
3293
|
+
clearTimeout(timeoutId);
|
|
3294
|
+
}
|
|
3295
|
+
timeoutId = null;
|
|
3296
|
+
lastArgs = null;
|
|
3297
|
+
lastThis = null;
|
|
3298
|
+
lastCallTime = 0;
|
|
3299
|
+
};
|
|
3300
|
+
return throttled;
|
|
3301
|
+
}
|
|
3302
|
+
function deepClone(obj) {
|
|
3303
|
+
if (obj === null || typeof obj !== "object") {
|
|
3304
|
+
return obj;
|
|
3305
|
+
}
|
|
3306
|
+
if (obj instanceof Date) {
|
|
3307
|
+
return new Date(obj.getTime());
|
|
3308
|
+
}
|
|
3309
|
+
if (obj instanceof RegExp) {
|
|
3310
|
+
return new RegExp(obj.source, obj.flags);
|
|
3311
|
+
}
|
|
3312
|
+
if (Array.isArray(obj)) {
|
|
3313
|
+
return obj.map((item) => deepClone(item));
|
|
3314
|
+
}
|
|
3315
|
+
if (obj instanceof Map) {
|
|
3316
|
+
const clonedMap = /* @__PURE__ */ new Map();
|
|
3317
|
+
obj.forEach((value, key) => {
|
|
3318
|
+
clonedMap.set(deepClone(key), deepClone(value));
|
|
3319
|
+
});
|
|
3320
|
+
return clonedMap;
|
|
3321
|
+
}
|
|
3322
|
+
if (obj instanceof Set) {
|
|
3323
|
+
const clonedSet = /* @__PURE__ */ new Set();
|
|
3324
|
+
obj.forEach((value) => {
|
|
3325
|
+
clonedSet.add(deepClone(value));
|
|
3326
|
+
});
|
|
3327
|
+
return clonedSet;
|
|
3328
|
+
}
|
|
3329
|
+
const clonedObj = {};
|
|
3330
|
+
for (const key in obj) {
|
|
3331
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
3332
|
+
clonedObj[key] = deepClone(obj[key]);
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3335
|
+
return clonedObj;
|
|
3336
|
+
}
|
|
3337
|
+
function deepMerge(target, ...sources) {
|
|
3338
|
+
if (!sources.length)
|
|
3339
|
+
return target;
|
|
3340
|
+
const source = sources.shift();
|
|
3341
|
+
if (source === void 0)
|
|
3342
|
+
return target;
|
|
3343
|
+
for (const key in source) {
|
|
3344
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
3345
|
+
const sourceValue = source[key];
|
|
3346
|
+
const targetValue = target[key];
|
|
3347
|
+
if (sourceValue !== null && typeof sourceValue === "object" && !Array.isArray(sourceValue) && targetValue !== null && typeof targetValue === "object" && !Array.isArray(targetValue)) {
|
|
3348
|
+
target[key] = deepMerge(targetValue, sourceValue);
|
|
3349
|
+
} else {
|
|
3350
|
+
target[key] = deepClone(sourceValue);
|
|
3351
|
+
}
|
|
3352
|
+
}
|
|
3353
|
+
}
|
|
3354
|
+
return deepMerge(target, ...sources);
|
|
3355
|
+
}
|
|
3356
|
+
function memoize(fn, options = {}) {
|
|
3357
|
+
const { maxSize = 100, keyGenerator = (...args) => JSON.stringify(args) } = options;
|
|
3358
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3359
|
+
const memoized = function(...args) {
|
|
3360
|
+
const key = keyGenerator(...args);
|
|
3361
|
+
if (cache.has(key)) {
|
|
3362
|
+
return cache.get(key);
|
|
3363
|
+
}
|
|
3364
|
+
const result = fn(...args);
|
|
3365
|
+
if (cache.size >= maxSize) {
|
|
3366
|
+
const firstKey = cache.keys().next().value;
|
|
3367
|
+
if (firstKey !== void 0) {
|
|
3368
|
+
cache.delete(firstKey);
|
|
3369
|
+
}
|
|
3370
|
+
}
|
|
3371
|
+
cache.set(key, result);
|
|
3372
|
+
return result;
|
|
3373
|
+
};
|
|
3374
|
+
memoized.cache = cache;
|
|
3375
|
+
memoized.clear = () => cache.clear();
|
|
3376
|
+
return memoized;
|
|
3377
|
+
}
|
|
3378
|
+
function uuid() {
|
|
3379
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
3380
|
+
return crypto.randomUUID();
|
|
3381
|
+
}
|
|
3382
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
|
|
3383
|
+
const r = Math.random() * 16 | 0;
|
|
3384
|
+
const v = c === "x" ? r : r & 3 | 8;
|
|
3385
|
+
return v.toString(16);
|
|
3386
|
+
});
|
|
3387
|
+
}
|
|
3388
|
+
function formatDate(date, format = "YYYY-MM-DD HH:mm:ss") {
|
|
3389
|
+
const d = date instanceof Date ? date : new Date(date);
|
|
3390
|
+
if (isNaN(d.getTime())) {
|
|
3391
|
+
return "Invalid Date";
|
|
3392
|
+
}
|
|
3393
|
+
const pad = (n, len = 2) => String(n).padStart(len, "0");
|
|
3394
|
+
const tokens = {
|
|
3395
|
+
"YYYY": String(d.getFullYear()),
|
|
3396
|
+
"YY": String(d.getFullYear()).slice(-2),
|
|
3397
|
+
"MM": pad(d.getMonth() + 1),
|
|
3398
|
+
"M": String(d.getMonth() + 1),
|
|
3399
|
+
"DD": pad(d.getDate()),
|
|
3400
|
+
"D": String(d.getDate()),
|
|
3401
|
+
"HH": pad(d.getHours()),
|
|
3402
|
+
"H": String(d.getHours()),
|
|
3403
|
+
"hh": pad(d.getHours() % 12 || 12),
|
|
3404
|
+
"h": String(d.getHours() % 12 || 12),
|
|
3405
|
+
"mm": pad(d.getMinutes()),
|
|
3406
|
+
"m": String(d.getMinutes()),
|
|
3407
|
+
"ss": pad(d.getSeconds()),
|
|
3408
|
+
"s": String(d.getSeconds()),
|
|
3409
|
+
"SSS": pad(d.getMilliseconds(), 3),
|
|
3410
|
+
"A": d.getHours() < 12 ? "AM" : "PM",
|
|
3411
|
+
"a": d.getHours() < 12 ? "am" : "pm"
|
|
3412
|
+
};
|
|
3413
|
+
let result = format;
|
|
3414
|
+
for (const token in tokens) {
|
|
3415
|
+
result = result.replace(new RegExp(token, "g"), tokens[token]);
|
|
3416
|
+
}
|
|
3417
|
+
return result;
|
|
3418
|
+
}
|
|
3419
|
+
function shallowEqual(a, b) {
|
|
3420
|
+
if (a === b)
|
|
3421
|
+
return true;
|
|
3422
|
+
if (!a || !b)
|
|
3423
|
+
return false;
|
|
3424
|
+
if (typeof a !== "object" || typeof b !== "object")
|
|
3425
|
+
return false;
|
|
3426
|
+
const keysA = Object.keys(a);
|
|
3427
|
+
const keysB = Object.keys(b);
|
|
3428
|
+
if (keysA.length !== keysB.length)
|
|
3429
|
+
return false;
|
|
3430
|
+
for (const key of keysA) {
|
|
3431
|
+
if (a[key] !== b[key])
|
|
3432
|
+
return false;
|
|
3433
|
+
}
|
|
3434
|
+
return true;
|
|
3435
|
+
}
|
|
3436
|
+
function deepEqual(a, b) {
|
|
3437
|
+
if (a === b)
|
|
3438
|
+
return true;
|
|
3439
|
+
if (a === null || b === null)
|
|
3440
|
+
return false;
|
|
3441
|
+
if (typeof a !== typeof b)
|
|
3442
|
+
return false;
|
|
3443
|
+
if (typeof a !== "object")
|
|
3444
|
+
return false;
|
|
3445
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
3446
|
+
return false;
|
|
3447
|
+
if (Array.isArray(a)) {
|
|
3448
|
+
if (a.length !== b.length)
|
|
3449
|
+
return false;
|
|
3450
|
+
return a.every((item, index) => deepEqual(item, b[index]));
|
|
3451
|
+
}
|
|
3452
|
+
if (a instanceof Date && b instanceof Date) {
|
|
3453
|
+
return a.getTime() === b.getTime();
|
|
3454
|
+
}
|
|
3455
|
+
if (a instanceof RegExp && b instanceof RegExp) {
|
|
3456
|
+
return a.source === b.source && a.flags === b.flags;
|
|
3457
|
+
}
|
|
3458
|
+
const keysA = Object.keys(a);
|
|
3459
|
+
const keysB = Object.keys(b);
|
|
3460
|
+
if (keysA.length !== keysB.length)
|
|
3461
|
+
return false;
|
|
3462
|
+
return keysA.every((key) => deepEqual(a[key], b[key]));
|
|
3463
|
+
}
|
|
3464
|
+
function escapeHtml2(str) {
|
|
3465
|
+
const htmlEscapes = {
|
|
3466
|
+
"&": "&",
|
|
3467
|
+
"<": "<",
|
|
3468
|
+
">": ">",
|
|
3469
|
+
'"': """,
|
|
3470
|
+
"'": "'"
|
|
3471
|
+
};
|
|
3472
|
+
return str.replace(/[&<>"']/g, (char) => htmlEscapes[char]);
|
|
3473
|
+
}
|
|
3474
|
+
function unescapeHtml(str) {
|
|
3475
|
+
const htmlUnescapes = {
|
|
3476
|
+
"&": "&",
|
|
3477
|
+
"<": "<",
|
|
3478
|
+
">": ">",
|
|
3479
|
+
""": '"',
|
|
3480
|
+
"'": "'"
|
|
3481
|
+
};
|
|
3482
|
+
return str.replace(/&(?:amp|lt|gt|quot|#39);/g, (entity) => htmlUnescapes[entity] || entity);
|
|
3483
|
+
}
|
|
3484
|
+
function capitalize(str) {
|
|
3485
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
3486
|
+
}
|
|
3487
|
+
function camelCase(str) {
|
|
3488
|
+
return str.replace(/[-_\s]+(.)?/g, (_, char) => char ? char.toUpperCase() : "").replace(/^(.)/, (char) => char.toLowerCase());
|
|
3489
|
+
}
|
|
3490
|
+
function kebabCase(str) {
|
|
3491
|
+
return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
|
|
3492
|
+
}
|
|
3493
|
+
function sleep(ms) {
|
|
3494
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
3495
|
+
}
|
|
3496
|
+
async function retry(fn, options = {}) {
|
|
3497
|
+
const { retries = 3, delay = 1e3, backoff = 2, onRetry } = options;
|
|
3498
|
+
let lastError;
|
|
3499
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
3500
|
+
try {
|
|
3501
|
+
return await fn();
|
|
3502
|
+
} catch (error) {
|
|
3503
|
+
lastError = error;
|
|
3504
|
+
if (attempt < retries) {
|
|
3505
|
+
if (onRetry) {
|
|
3506
|
+
onRetry(lastError, attempt + 1);
|
|
3507
|
+
}
|
|
3508
|
+
await sleep(delay * Math.pow(backoff, attempt));
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
throw lastError;
|
|
3513
|
+
}
|
|
3514
|
+
function deferred() {
|
|
3515
|
+
let resolve;
|
|
3516
|
+
let reject;
|
|
3517
|
+
const promise = new Promise((res, rej) => {
|
|
3518
|
+
resolve = res;
|
|
3519
|
+
reject = rej;
|
|
3520
|
+
});
|
|
3521
|
+
return { promise, resolve, reject };
|
|
3522
|
+
}
|
|
3523
|
+
function pick(obj, keys) {
|
|
3524
|
+
const result = {};
|
|
3525
|
+
for (const key of keys) {
|
|
3526
|
+
if (key in obj) {
|
|
3527
|
+
result[key] = obj[key];
|
|
3528
|
+
}
|
|
3529
|
+
}
|
|
3530
|
+
return result;
|
|
3531
|
+
}
|
|
3532
|
+
function omit(obj, keys) {
|
|
3533
|
+
const result = { ...obj };
|
|
3534
|
+
for (const key of keys) {
|
|
3535
|
+
delete result[key];
|
|
3536
|
+
}
|
|
3537
|
+
return result;
|
|
3538
|
+
}
|
|
3539
|
+
function groupBy(array, key) {
|
|
3540
|
+
return array.reduce((result, item) => {
|
|
3541
|
+
const groupKey = typeof key === "function" ? key(item) : String(item[key]);
|
|
3542
|
+
if (!result[groupKey]) {
|
|
3543
|
+
result[groupKey] = [];
|
|
3544
|
+
}
|
|
3545
|
+
result[groupKey].push(item);
|
|
3546
|
+
return result;
|
|
3547
|
+
}, {});
|
|
3548
|
+
}
|
|
3549
|
+
function isEmpty(value) {
|
|
3550
|
+
if (value === null || value === void 0)
|
|
3551
|
+
return true;
|
|
3552
|
+
if (typeof value === "string")
|
|
3553
|
+
return value.trim() === "";
|
|
3554
|
+
if (Array.isArray(value))
|
|
3555
|
+
return value.length === 0;
|
|
3556
|
+
if (value instanceof Map || value instanceof Set)
|
|
3557
|
+
return value.size === 0;
|
|
3558
|
+
if (typeof value === "object")
|
|
3559
|
+
return Object.keys(value).length === 0;
|
|
3560
|
+
return false;
|
|
3561
|
+
}
|
|
3562
|
+
function clamp(value, min, max) {
|
|
3563
|
+
return Math.min(Math.max(value, min), max);
|
|
3564
|
+
}
|
|
3565
|
+
function get(obj, path5, defaultValue) {
|
|
3566
|
+
const keys = Array.isArray(path5) ? path5 : path5.split(".");
|
|
3567
|
+
let result = obj;
|
|
3568
|
+
for (const key of keys) {
|
|
3569
|
+
if (result === null || result === void 0) {
|
|
3570
|
+
return defaultValue;
|
|
3571
|
+
}
|
|
3572
|
+
result = result[key];
|
|
3573
|
+
}
|
|
3574
|
+
return result === void 0 ? defaultValue : result;
|
|
3575
|
+
}
|
|
3576
|
+
function set(obj, path5, value) {
|
|
3577
|
+
const keys = Array.isArray(path5) ? path5 : path5.split(".");
|
|
3578
|
+
let current = obj;
|
|
3579
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
3580
|
+
const key = keys[i];
|
|
3581
|
+
if (!(key in current) || typeof current[key] !== "object") {
|
|
3582
|
+
current[key] = {};
|
|
3583
|
+
}
|
|
3584
|
+
current = current[key];
|
|
3585
|
+
}
|
|
3586
|
+
current[keys[keys.length - 1]] = value;
|
|
3587
|
+
return obj;
|
|
3588
|
+
}
|
|
3589
|
+
|
|
3590
|
+
// src/core/errors.ts
|
|
3591
|
+
var BaraqexError = class extends Error {
|
|
3592
|
+
constructor(message, options) {
|
|
3593
|
+
super(message);
|
|
3594
|
+
__publicField(this, "code");
|
|
3595
|
+
__publicField(this, "hint");
|
|
3596
|
+
__publicField(this, "docs");
|
|
3597
|
+
__publicField(this, "originalCause");
|
|
3598
|
+
this.name = "BaraqexError";
|
|
3599
|
+
this.code = options.code;
|
|
3600
|
+
this.hint = options.hint;
|
|
3601
|
+
this.docs = options.docs;
|
|
3602
|
+
this.originalCause = options.cause;
|
|
3603
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
3604
|
+
}
|
|
3605
|
+
/**
|
|
3606
|
+
* Format error for console output with helpful hints
|
|
3607
|
+
*/
|
|
3608
|
+
format() {
|
|
3609
|
+
let output = `
|
|
3610
|
+
\u274C ${this.name}: ${this.message}
|
|
3611
|
+
`;
|
|
3612
|
+
output += ` Code: ${this.code}
|
|
3613
|
+
`;
|
|
3614
|
+
if (this.hint) {
|
|
3615
|
+
output += ` \u{1F4A1} Hint: ${this.hint}
|
|
3616
|
+
`;
|
|
3617
|
+
}
|
|
3618
|
+
if (this.docs) {
|
|
3619
|
+
output += ` \u{1F4DA} Docs: ${this.docs}
|
|
3620
|
+
`;
|
|
3621
|
+
}
|
|
3622
|
+
return output;
|
|
3623
|
+
}
|
|
3624
|
+
};
|
|
3625
|
+
var ConfigError = class extends BaraqexError {
|
|
3626
|
+
constructor(message, options) {
|
|
3627
|
+
super(message, {
|
|
3628
|
+
code: "CONFIG_ERROR",
|
|
3629
|
+
hint: options?.hint || "Check your baraqex.config.js or server configuration",
|
|
3630
|
+
docs: "https://baraqex.tech/docs/configuration",
|
|
3631
|
+
cause: options?.cause
|
|
3632
|
+
});
|
|
3633
|
+
this.name = "ConfigError";
|
|
3634
|
+
}
|
|
3635
|
+
};
|
|
3636
|
+
var DatabaseError = class extends BaraqexError {
|
|
3637
|
+
constructor(message, options) {
|
|
3638
|
+
super(message, {
|
|
3639
|
+
code: "DATABASE_ERROR",
|
|
3640
|
+
hint: options?.hint || "Verify your database connection string and credentials",
|
|
3641
|
+
docs: "https://baraqex.tech/docs/database",
|
|
3642
|
+
cause: options?.cause
|
|
3643
|
+
});
|
|
3644
|
+
__publicField(this, "dbType");
|
|
3645
|
+
this.name = "DatabaseError";
|
|
3646
|
+
this.dbType = options?.dbType;
|
|
3647
|
+
}
|
|
3648
|
+
};
|
|
3649
|
+
var AuthError = class extends BaraqexError {
|
|
3650
|
+
constructor(message, options) {
|
|
3651
|
+
super(message, {
|
|
3652
|
+
code: "AUTH_ERROR",
|
|
3653
|
+
hint: options?.hint || "Check your JWT secret and token configuration",
|
|
3654
|
+
docs: "https://baraqex.tech/docs/authentication",
|
|
3655
|
+
cause: options?.cause
|
|
3656
|
+
});
|
|
3657
|
+
this.name = "AuthError";
|
|
3658
|
+
}
|
|
3659
|
+
};
|
|
3660
|
+
var WasmError = class extends BaraqexError {
|
|
3661
|
+
constructor(message, options) {
|
|
3662
|
+
super(message, {
|
|
3663
|
+
code: "WASM_ERROR",
|
|
3664
|
+
hint: options?.hint || "Ensure your .wasm file is accessible and properly compiled",
|
|
3665
|
+
docs: "https://baraqex.tech/docs/webassembly",
|
|
3666
|
+
cause: options?.cause
|
|
3667
|
+
});
|
|
3668
|
+
this.name = "WasmError";
|
|
3669
|
+
}
|
|
3670
|
+
};
|
|
3671
|
+
var RouterError = class extends BaraqexError {
|
|
3672
|
+
constructor(message, options) {
|
|
3673
|
+
super(message, {
|
|
3674
|
+
code: "ROUTER_ERROR",
|
|
3675
|
+
hint: options?.hint || "Check your API route file structure and exports",
|
|
3676
|
+
docs: "https://baraqex.tech/docs/routing",
|
|
3677
|
+
cause: options?.cause
|
|
3678
|
+
});
|
|
3679
|
+
this.name = "RouterError";
|
|
3680
|
+
}
|
|
3681
|
+
};
|
|
3682
|
+
var ValidationError = class extends BaraqexError {
|
|
3683
|
+
constructor(message, options) {
|
|
3684
|
+
super(message, {
|
|
3685
|
+
code: "VALIDATION_ERROR",
|
|
3686
|
+
hint: options?.hint,
|
|
3687
|
+
cause: options?.cause
|
|
3688
|
+
});
|
|
3689
|
+
__publicField(this, "field");
|
|
3690
|
+
__publicField(this, "value");
|
|
3691
|
+
this.name = "ValidationError";
|
|
3692
|
+
this.field = options?.field;
|
|
3693
|
+
this.value = options?.value;
|
|
3694
|
+
}
|
|
3695
|
+
};
|
|
3696
|
+
function formatError(error) {
|
|
3697
|
+
if (error instanceof BaraqexError) {
|
|
3698
|
+
return error.format();
|
|
3699
|
+
}
|
|
3700
|
+
if (error instanceof Error) {
|
|
3701
|
+
return `
|
|
3702
|
+
\u274C Error: ${error.message}
|
|
3703
|
+
`;
|
|
3704
|
+
}
|
|
3705
|
+
return `
|
|
3706
|
+
\u274C Unknown error: ${String(error)}
|
|
3707
|
+
`;
|
|
3708
|
+
}
|
|
3709
|
+
function withErrorHandling(fn, errorHandler3) {
|
|
3710
|
+
return async (...args) => {
|
|
3711
|
+
try {
|
|
3712
|
+
return await fn(...args);
|
|
3713
|
+
} catch (error) {
|
|
3714
|
+
if (errorHandler3) {
|
|
3715
|
+
errorHandler3(error);
|
|
3716
|
+
} else {
|
|
3717
|
+
console.error(formatError(error));
|
|
3718
|
+
}
|
|
3719
|
+
throw error;
|
|
3720
|
+
}
|
|
3721
|
+
};
|
|
3722
|
+
}
|
|
3723
|
+
|
|
3724
|
+
// src/wasm.ts
|
|
3725
|
+
async function loadGoWasm(wasmUrl, options = {}) {
|
|
3726
|
+
if (typeof window === "undefined") {
|
|
3727
|
+
throw new Error("loadGoWasm() is for browser use only. Use loadGoWasmFromFile() in Node.js.");
|
|
3728
|
+
}
|
|
3729
|
+
try {
|
|
3730
|
+
if (!window.Go) {
|
|
3731
|
+
throw new Error("Go WASM runtime not available. Make sure wasm_exec.js is loaded.");
|
|
3732
|
+
}
|
|
3733
|
+
if (options.debug) {
|
|
3734
|
+
console.log("[WASM] Loading WASM from:", wasmUrl);
|
|
3735
|
+
}
|
|
3736
|
+
const response = await fetch(wasmUrl);
|
|
3737
|
+
if (!response.ok) {
|
|
3738
|
+
throw new Error(`Failed to fetch WASM file: ${response.status}`);
|
|
3739
|
+
}
|
|
3740
|
+
const wasmBytes = await response.arrayBuffer();
|
|
3741
|
+
const go = new window.Go();
|
|
3742
|
+
const wasmModule = await WebAssembly.instantiate(wasmBytes, go.importObject);
|
|
3743
|
+
go.run(wasmModule.instance);
|
|
3744
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
3745
|
+
if (options.debug) {
|
|
3746
|
+
console.log("[WASM] Go program started, checking for registered functions...");
|
|
3747
|
+
}
|
|
3748
|
+
const functions = {};
|
|
3749
|
+
for (const key in window) {
|
|
3750
|
+
if (typeof window[key] === "function" && key.startsWith("go")) {
|
|
3751
|
+
functions[key] = window[key];
|
|
3752
|
+
if (options.debug) {
|
|
3753
|
+
console.log(`[WASM] Found function: ${key}`);
|
|
3754
|
+
}
|
|
3755
|
+
}
|
|
3756
|
+
}
|
|
3757
|
+
const wasmInstance = {
|
|
3758
|
+
instance: wasmModule.instance,
|
|
3759
|
+
module: wasmModule,
|
|
3760
|
+
exports: wasmModule.instance.exports,
|
|
3761
|
+
functions
|
|
3762
|
+
};
|
|
3763
|
+
if (options.onLoad) {
|
|
3764
|
+
options.onLoad(wasmInstance);
|
|
3765
|
+
}
|
|
3766
|
+
if (options.debug) {
|
|
3767
|
+
console.log(`[WASM] Module loaded successfully with ${Object.keys(functions).length} functions`);
|
|
3768
|
+
}
|
|
3769
|
+
return wasmInstance;
|
|
3770
|
+
} catch (error) {
|
|
3771
|
+
console.error("[WASM] Error loading Go WASM module:", error);
|
|
3772
|
+
throw error;
|
|
3773
|
+
}
|
|
3774
|
+
}
|
|
3775
|
+
function callWasmFunction(funcName, ...args) {
|
|
3776
|
+
if (typeof window === "undefined") {
|
|
3777
|
+
throw new Error("callWasmFunction() is for browser use only.");
|
|
3778
|
+
}
|
|
1830
3779
|
const func = window[funcName];
|
|
1831
3780
|
if (typeof func !== "function") {
|
|
1832
3781
|
throw new Error(`Function ${funcName} not found. Make sure the WASM module is loaded.`);
|
|
@@ -1862,34 +3811,6 @@ function useGoWasm(wasmUrl, options = {}) {
|
|
|
1862
3811
|
}
|
|
1863
3812
|
|
|
1864
3813
|
// src/index.ts
|
|
1865
|
-
var isNode = typeof process !== "undefined" && process.versions?.node;
|
|
1866
|
-
var isBrowser = typeof window !== "undefined";
|
|
1867
|
-
var BaraqexServer = null;
|
|
1868
|
-
var createServer2 = null;
|
|
1869
|
-
var createDevServer2 = null;
|
|
1870
|
-
var createProductionServer2 = null;
|
|
1871
|
-
var renderComponent2 = null;
|
|
1872
|
-
var Database2 = null;
|
|
1873
|
-
var AuthService2 = null;
|
|
1874
|
-
var ApiRouter2 = null;
|
|
1875
|
-
var requestLogger2 = null;
|
|
1876
|
-
var errorHandler2 = null;
|
|
1877
|
-
var notFoundHandler2 = null;
|
|
1878
|
-
var rateLimit2 = null;
|
|
1879
|
-
var initNodeWasm3 = null;
|
|
1880
|
-
var loadGoWasmFromFile2 = null;
|
|
1881
|
-
var hashString2 = null;
|
|
1882
|
-
var getPagination2 = null;
|
|
1883
|
-
var sendSuccess2 = null;
|
|
1884
|
-
var sendError2 = null;
|
|
1885
|
-
var validateFields2 = null;
|
|
1886
|
-
var validateFileUpload2 = null;
|
|
1887
|
-
var getEnvironmentInfo2 = null;
|
|
1888
|
-
var isDirectoryEmpty2 = null;
|
|
1889
|
-
var ensureDirectory2 = null;
|
|
1890
|
-
var writeJsonFile2 = null;
|
|
1891
|
-
var readJsonFile2 = null;
|
|
1892
|
-
var baraqexRenderToString = null;
|
|
1893
3814
|
var safeJsonParse2 = (json, fallback) => {
|
|
1894
3815
|
try {
|
|
1895
3816
|
return JSON.parse(json);
|
|
@@ -1906,133 +3827,296 @@ var generateToken2 = (length = 32) => {
|
|
|
1906
3827
|
array[i] = Math.floor(Math.random() * 256);
|
|
1907
3828
|
}
|
|
1908
3829
|
}
|
|
1909
|
-
return Array.from(array, (
|
|
3830
|
+
return Array.from(array, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
1910
3831
|
};
|
|
1911
3832
|
var generateDocument2 = (content, options = {}) => `<!DOCTYPE html><html><head><title>${options.title || "App"}</title></head><body>${content}</body></html>`;
|
|
1912
3833
|
var generateErrorPage2 = (code, message) => `<div>Error ${code}: ${message}</div>`;
|
|
1913
3834
|
var generateLoadingPage2 = (message = "Loading...") => `<div>${message}</div>`;
|
|
1914
|
-
var
|
|
3835
|
+
var fallbackRenderToString = (component) => {
|
|
1915
3836
|
try {
|
|
1916
3837
|
if (typeof component === "function") {
|
|
1917
3838
|
const result = component();
|
|
1918
3839
|
return typeof result === "string" ? result : String(result || "");
|
|
1919
3840
|
}
|
|
1920
3841
|
return String(component || "");
|
|
1921
|
-
} catch
|
|
3842
|
+
} catch {
|
|
1922
3843
|
return "<div>Error rendering component</div>";
|
|
1923
3844
|
}
|
|
1924
3845
|
};
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
ApiRouter2 = serverModule.ApiRouter;
|
|
1944
|
-
requestLogger2 = serverModule.requestLogger;
|
|
1945
|
-
errorHandler2 = serverModule.errorHandler;
|
|
1946
|
-
notFoundHandler2 = serverModule.notFoundHandler;
|
|
1947
|
-
rateLimit2 = serverModule.rateLimit;
|
|
1948
|
-
initNodeWasm3 = serverModule.initNodeWasm;
|
|
1949
|
-
loadGoWasmFromFile2 = serverModule.loadGoWasmFromFile;
|
|
1950
|
-
safeJsonParse2 = utilsModule.safeJsonParse;
|
|
1951
|
-
generateToken2 = utilsModule.generateToken;
|
|
1952
|
-
hashString2 = utilsModule.hashString;
|
|
1953
|
-
getPagination2 = utilsModule.getPagination;
|
|
1954
|
-
sendSuccess2 = utilsModule.sendSuccess;
|
|
1955
|
-
sendError2 = utilsModule.sendError;
|
|
1956
|
-
validateFields2 = utilsModule.validateFields;
|
|
1957
|
-
validateFileUpload2 = utilsModule.validateFileUpload;
|
|
1958
|
-
getEnvironmentInfo2 = utilsModule.getEnvironmentInfo;
|
|
1959
|
-
isDirectoryEmpty2 = utilsModule.isDirectoryEmpty;
|
|
1960
|
-
ensureDirectory2 = utilsModule.ensureDirectory;
|
|
1961
|
-
writeJsonFile2 = utilsModule.writeJsonFile;
|
|
1962
|
-
readJsonFile2 = utilsModule.readJsonFile;
|
|
1963
|
-
generateDocument2 = templatesModule.generateDocument;
|
|
1964
|
-
generateErrorPage2 = templatesModule.generateErrorPage;
|
|
1965
|
-
generateLoadingPage2 = templatesModule.generateLoadingPage;
|
|
1966
|
-
baraqexRenderToString = rendererModule.renderToString;
|
|
1967
|
-
} catch (expressError) {
|
|
1968
|
-
console.warn("Express not available - server functionality disabled");
|
|
1969
|
-
createServer2 = () => {
|
|
1970
|
-
throw new Error("Server functionality not available. Make sure you have Express installed: npm install express @types/express");
|
|
1971
|
-
};
|
|
1972
|
-
createDevServer2 = () => {
|
|
1973
|
-
throw new Error("Server functionality not available. Make sure you have Express installed: npm install express @types/express");
|
|
1974
|
-
};
|
|
1975
|
-
createProductionServer2 = () => {
|
|
1976
|
-
throw new Error("Server functionality not available. Make sure you have Express installed: npm install express @types/express");
|
|
1977
|
-
};
|
|
3846
|
+
function createLazyLoader(importFn, fallback) {
|
|
3847
|
+
let cached = null;
|
|
3848
|
+
let loading = null;
|
|
3849
|
+
async function ensure() {
|
|
3850
|
+
if (cached)
|
|
3851
|
+
return cached;
|
|
3852
|
+
if (!loading) {
|
|
3853
|
+
loading = importFn().then((mod) => {
|
|
3854
|
+
cached = mod;
|
|
3855
|
+
return mod;
|
|
3856
|
+
});
|
|
3857
|
+
}
|
|
3858
|
+
return loading;
|
|
3859
|
+
}
|
|
3860
|
+
return new Proxy({}, {
|
|
3861
|
+
get(_target, prop) {
|
|
3862
|
+
if (cached?.[prop] !== void 0) {
|
|
3863
|
+
return cached[prop];
|
|
1978
3864
|
}
|
|
1979
|
-
|
|
1980
|
-
|
|
3865
|
+
if (fallback && fallback[prop]) {
|
|
3866
|
+
return fallback[prop];
|
|
3867
|
+
}
|
|
3868
|
+
return async (...args) => {
|
|
3869
|
+
const mod = await ensure();
|
|
3870
|
+
const fn = mod[prop];
|
|
3871
|
+
if (typeof fn !== "function") {
|
|
3872
|
+
throw new Error(
|
|
3873
|
+
`[baraqex] '${prop}' is not exported from the server module.`
|
|
3874
|
+
);
|
|
3875
|
+
}
|
|
3876
|
+
return fn(...args);
|
|
3877
|
+
};
|
|
1981
3878
|
}
|
|
1982
|
-
})
|
|
3879
|
+
});
|
|
1983
3880
|
}
|
|
1984
|
-
|
|
3881
|
+
var notAvailable = (name) => () => {
|
|
3882
|
+
throw new Error(
|
|
3883
|
+
`[baraqex] ${name} is only available in a Node.js environment with Express installed. Run: npm install express @types/express`
|
|
3884
|
+
);
|
|
3885
|
+
};
|
|
3886
|
+
var serverNotFound = {
|
|
3887
|
+
createServer: notAvailable("createServer"),
|
|
3888
|
+
createDevServer: notAvailable("createDevServer"),
|
|
3889
|
+
createProductionServer: notAvailable("createProductionServer"),
|
|
3890
|
+
Server: notAvailable("Server"),
|
|
3891
|
+
renderComponent: notAvailable("renderComponent"),
|
|
3892
|
+
Database: notAvailable("Database"),
|
|
3893
|
+
AuthService: notAvailable("AuthService"),
|
|
3894
|
+
ApiRouter: notAvailable("ApiRouter"),
|
|
3895
|
+
requestLogger: notAvailable("requestLogger"),
|
|
3896
|
+
errorHandler: notAvailable("errorHandler"),
|
|
3897
|
+
notFoundHandler: notAvailable("notFoundHandler"),
|
|
3898
|
+
rateLimit: notAvailable("rateLimit"),
|
|
3899
|
+
initNodeWasm: notAvailable("initNodeWasm"),
|
|
3900
|
+
loadGoWasmFromFile: notAvailable("loadGoWasmFromFile")
|
|
3901
|
+
};
|
|
3902
|
+
var isNode = typeof process !== "undefined" && !!process.versions?.node;
|
|
3903
|
+
var isBrowser4 = typeof window !== "undefined";
|
|
3904
|
+
var serverModules = createLazyLoader(
|
|
3905
|
+
() => Promise.all([
|
|
3906
|
+
Promise.resolve().then(() => (init_server(), server_exports)),
|
|
3907
|
+
Promise.resolve().then(() => (init_utils(), utils_exports)),
|
|
3908
|
+
Promise.resolve().then(() => (init_templates(), templates_exports)),
|
|
3909
|
+
Promise.resolve().then(() => (init_server_renderer2(), server_renderer_exports))
|
|
3910
|
+
]).then(([server, utils, templates, renderer]) => ({
|
|
3911
|
+
...server,
|
|
3912
|
+
...utils,
|
|
3913
|
+
...templates,
|
|
3914
|
+
...renderer
|
|
3915
|
+
})),
|
|
3916
|
+
isNode && !isBrowser4 ? serverNotFound : serverNotFound
|
|
3917
|
+
);
|
|
3918
|
+
var lazy = (name) => (...args) => serverModules[name](...args);
|
|
3919
|
+
var createServer2 = lazy("createServer");
|
|
3920
|
+
var createDevServer2 = lazy("createDevServer");
|
|
3921
|
+
var createProductionServer2 = lazy("createProductionServer");
|
|
3922
|
+
var BaraqexServer = serverModules.Server;
|
|
3923
|
+
var Database2 = serverModules.Database;
|
|
3924
|
+
var AuthService2 = serverModules.AuthService;
|
|
3925
|
+
var ApiRouter2 = serverModules.ApiRouter;
|
|
3926
|
+
var requestLogger2 = lazy("requestLogger");
|
|
3927
|
+
var errorHandler2 = lazy("errorHandler");
|
|
3928
|
+
var notFoundHandler2 = lazy("notFoundHandler");
|
|
3929
|
+
var rateLimit2 = lazy("rateLimit");
|
|
3930
|
+
var initNodeWasm3 = lazy("initNodeWasm");
|
|
3931
|
+
var loadGoWasmFromFile2 = lazy("loadGoWasmFromFile");
|
|
3932
|
+
var hashString2 = lazy("hashString");
|
|
3933
|
+
var getPagination2 = lazy("getPagination");
|
|
3934
|
+
var sendSuccess2 = lazy("sendSuccess");
|
|
3935
|
+
var sendError2 = lazy("sendError");
|
|
3936
|
+
var validateFields2 = lazy("validateFields");
|
|
3937
|
+
var validateFileUpload2 = lazy("validateFileUpload");
|
|
3938
|
+
var getEnvironmentInfo2 = lazy("getEnvironmentInfo");
|
|
3939
|
+
var isDirectoryEmpty2 = lazy("isDirectoryEmpty");
|
|
3940
|
+
var ensureDirectory2 = lazy("ensureDirectory");
|
|
3941
|
+
var writeJsonFile2 = lazy("writeJsonFile");
|
|
3942
|
+
var readJsonFile2 = lazy("readJsonFile");
|
|
3943
|
+
var renderComponent2 = lazy("renderComponent");
|
|
1985
3944
|
export {
|
|
1986
3945
|
ApiRouter2 as ApiRouter,
|
|
3946
|
+
AuthError,
|
|
1987
3947
|
AuthService2 as AuthService,
|
|
3948
|
+
BaraqexError,
|
|
1988
3949
|
BaraqexServer,
|
|
3950
|
+
Component,
|
|
3951
|
+
ConfigError,
|
|
1989
3952
|
Database2 as Database,
|
|
3953
|
+
DatabaseError,
|
|
1990
3954
|
Fragment,
|
|
1991
|
-
|
|
3955
|
+
LifecycleEvents,
|
|
3956
|
+
Link,
|
|
3957
|
+
NavLink,
|
|
3958
|
+
PureComponent,
|
|
3959
|
+
Redirect,
|
|
3960
|
+
Route,
|
|
3961
|
+
Router,
|
|
3962
|
+
RouterContext,
|
|
3963
|
+
RouterError,
|
|
3964
|
+
RouterProvider,
|
|
3965
|
+
StoreContext,
|
|
3966
|
+
StoreProvider,
|
|
3967
|
+
Switch,
|
|
3968
|
+
ValidationError,
|
|
3969
|
+
WasmError,
|
|
3970
|
+
applyPatches,
|
|
1992
3971
|
batchUpdates,
|
|
3972
|
+
calculatePatches,
|
|
1993
3973
|
callWasmFunction,
|
|
3974
|
+
camelCase,
|
|
3975
|
+
capitalize,
|
|
3976
|
+
clamp,
|
|
3977
|
+
cleanupHooks,
|
|
3978
|
+
cleanupRoot,
|
|
3979
|
+
combineReducers,
|
|
3980
|
+
createAction,
|
|
3981
|
+
createClassComponent,
|
|
1994
3982
|
createContext,
|
|
1995
3983
|
createDevServer2 as createDevServer,
|
|
3984
|
+
createElement,
|
|
3985
|
+
createElementSync,
|
|
3986
|
+
createEventBus,
|
|
1996
3987
|
createProductionServer2 as createProductionServer,
|
|
3988
|
+
createRoot,
|
|
3989
|
+
createRootState,
|
|
1997
3990
|
createServer2 as createServer,
|
|
3991
|
+
createSlice,
|
|
3992
|
+
createStore,
|
|
3993
|
+
debounce,
|
|
3994
|
+
deepClone,
|
|
3995
|
+
deepEqual,
|
|
3996
|
+
deepMerge,
|
|
3997
|
+
deferred,
|
|
3998
|
+
devTools,
|
|
3999
|
+
diff,
|
|
4000
|
+
emitAppDestroyed,
|
|
4001
|
+
emitAppError,
|
|
4002
|
+
emitAppInit,
|
|
4003
|
+
emitAppMounted,
|
|
4004
|
+
emitAppUpdated,
|
|
4005
|
+
emitComponentCreated,
|
|
4006
|
+
emitComponentError,
|
|
4007
|
+
emitComponentMounted,
|
|
4008
|
+
emitComponentUnmounted,
|
|
4009
|
+
emitComponentUpdated,
|
|
4010
|
+
emitRouterAfterChange,
|
|
4011
|
+
emitRouterBeforeChange,
|
|
4012
|
+
emitRouterError,
|
|
4013
|
+
emitStoreAfterAction,
|
|
4014
|
+
emitStoreBeforeAction,
|
|
4015
|
+
emitStoreError,
|
|
4016
|
+
emitStoreInitialized,
|
|
1998
4017
|
ensureDirectory2 as ensureDirectory,
|
|
1999
4018
|
errorHandler2 as errorHandler,
|
|
4019
|
+
escapeHtml2 as escapeHtml,
|
|
4020
|
+
eventBus,
|
|
4021
|
+
fallbackRenderToString,
|
|
4022
|
+
finishRender,
|
|
4023
|
+
formatDate,
|
|
2000
4024
|
generateDocument2 as generateDocument,
|
|
2001
4025
|
generateErrorPage2 as generateErrorPage,
|
|
2002
4026
|
generateLoadingPage2 as generateLoadingPage,
|
|
2003
4027
|
generateToken2 as generateToken,
|
|
4028
|
+
get,
|
|
4029
|
+
getContextValue,
|
|
4030
|
+
getCurrentRoot,
|
|
2004
4031
|
getEnvironmentInfo2 as getEnvironmentInfo,
|
|
4032
|
+
getIsBatching,
|
|
2005
4033
|
getPagination2 as getPagination,
|
|
2006
4034
|
getWasmFunctions,
|
|
4035
|
+
groupBy,
|
|
4036
|
+
hasRoot,
|
|
2007
4037
|
hashString2 as hashString,
|
|
2008
4038
|
hydrate,
|
|
2009
4039
|
initNodeWasm3 as initNodeWasm,
|
|
2010
4040
|
isDirectoryEmpty2 as isDirectoryEmpty,
|
|
4041
|
+
isEmpty,
|
|
2011
4042
|
isWasmReady,
|
|
2012
4043
|
jsx,
|
|
2013
|
-
|
|
4044
|
+
jsxDEV,
|
|
4045
|
+
jsxs,
|
|
4046
|
+
kebabCase,
|
|
2014
4047
|
loadGoWasm,
|
|
2015
4048
|
loadGoWasmFromFile2 as loadGoWasmFromFile,
|
|
4049
|
+
logger,
|
|
4050
|
+
memoize,
|
|
2016
4051
|
notFoundHandler2 as notFoundHandler,
|
|
4052
|
+
omit,
|
|
4053
|
+
onAppDestroyed,
|
|
4054
|
+
onAppError,
|
|
4055
|
+
onAppInit,
|
|
4056
|
+
onAppMounted,
|
|
4057
|
+
onAppUpdated,
|
|
4058
|
+
onComponentCreated,
|
|
4059
|
+
onComponentError,
|
|
4060
|
+
onComponentMounted,
|
|
4061
|
+
onComponentUnmounted,
|
|
4062
|
+
onComponentUpdated,
|
|
4063
|
+
onRouterAfterChange,
|
|
4064
|
+
onRouterBeforeChange,
|
|
4065
|
+
onRouterError,
|
|
4066
|
+
onStoreAfterAction,
|
|
4067
|
+
onStoreBeforeAction,
|
|
4068
|
+
onStoreError,
|
|
4069
|
+
onStoreInitialized,
|
|
4070
|
+
patterns,
|
|
4071
|
+
pick,
|
|
4072
|
+
prepareRender,
|
|
2017
4073
|
rateLimit2 as rateLimit,
|
|
2018
4074
|
readJsonFile2 as readJsonFile,
|
|
2019
4075
|
render,
|
|
2020
4076
|
renderComponent2 as renderComponent,
|
|
2021
|
-
|
|
4077
|
+
renderToStream,
|
|
4078
|
+
renderToString,
|
|
4079
|
+
renderToStringWithData,
|
|
2022
4080
|
requestLogger2 as requestLogger,
|
|
4081
|
+
retry,
|
|
2023
4082
|
safeJsonParse2 as safeJsonParse,
|
|
2024
4083
|
sendError2 as sendError,
|
|
2025
4084
|
sendSuccess2 as sendSuccess,
|
|
2026
|
-
|
|
4085
|
+
set,
|
|
4086
|
+
setCurrentRoot,
|
|
4087
|
+
shallowEqual,
|
|
4088
|
+
shouldComponentUpdate,
|
|
4089
|
+
sleep,
|
|
4090
|
+
throttle,
|
|
4091
|
+
thunk,
|
|
4092
|
+
unescapeHtml,
|
|
4093
|
+
useCallback,
|
|
2027
4094
|
useContext,
|
|
4095
|
+
useDispatch,
|
|
2028
4096
|
useEffect,
|
|
2029
4097
|
useErrorBoundary,
|
|
4098
|
+
useEvent,
|
|
4099
|
+
useField,
|
|
4100
|
+
useForm,
|
|
2030
4101
|
useGoWasm,
|
|
4102
|
+
useId,
|
|
4103
|
+
useLayoutEffect,
|
|
4104
|
+
useLocation,
|
|
4105
|
+
useMatch,
|
|
2031
4106
|
useMemo,
|
|
4107
|
+
useNavigate,
|
|
4108
|
+
useParams,
|
|
4109
|
+
useReducer,
|
|
2032
4110
|
useRef,
|
|
4111
|
+
useRouter,
|
|
4112
|
+
useSearchParams,
|
|
4113
|
+
useSelector,
|
|
2033
4114
|
useState,
|
|
4115
|
+
useStore,
|
|
4116
|
+
uuid,
|
|
2034
4117
|
validateFields2 as validateFields,
|
|
2035
4118
|
validateFileUpload2 as validateFileUpload,
|
|
4119
|
+
withErrorHandling,
|
|
2036
4120
|
writeJsonFile2 as writeJsonFile
|
|
2037
4121
|
};
|
|
2038
4122
|
//# sourceMappingURL=index.js.map
|