baraqex 1.0.44 → 1.0.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README_WASM.md +472 -0
- package/dist/browser.js +1 -422
- package/dist/browser.js.map +4 -4
- package/dist/index.js +31 -421
- package/dist/index.js.map +4 -4
- package/dist/{server/index.js → server.js} +21 -114
- package/dist/server.js.map +7 -0
- package/package.json +48 -57
- package/templates/ssr-template/package-lock.json +2 -2
- package/templates/ssr-template/src/App.tsx +1 -1
- package/templates/ssr-template/src/client.tsx +1 -1
- package/templates/ssr-template/src/server.ts +1 -1
- package/templates/wasm/package-lock.json +3169 -2710
- package/templates/wasm/package.json +10 -12
- package/templates/wasm/src/App.tsx +50 -19
- package/templates/wasm/vite.config.ts +24 -59
- package/dist/api/hello.d.ts +0 -3
- package/dist/api/hello.d.ts.map +0 -1
- package/dist/api/users/[id].d.ts +0 -5
- package/dist/api/users/[id].d.ts.map +0 -1
- package/dist/browser.d.ts +0 -29
- package/dist/browser.d.ts.map +0 -1
- package/dist/browser.package.json +0 -4
- 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/index.d.ts +0 -34
- package/dist/index.d.ts.map +0 -1
- package/dist/renderComponent.d.ts +0 -9
- package/dist/renderComponent.d.ts.map +0 -1
- package/dist/server/api-router.d.ts +0 -16
- package/dist/server/api-router.d.ts.map +0 -1
- package/dist/server/auth.d.ts +0 -25
- package/dist/server/auth.d.ts.map +0 -1
- package/dist/server/database.d.ts +0 -22
- package/dist/server/database.d.ts.map +0 -1
- package/dist/server/index.d.ts +0 -115
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js.map +0 -7
- package/dist/server/middleware.d.ts +0 -11
- package/dist/server/middleware.d.ts.map +0 -1
- package/dist/server/package.json +0 -4
- package/dist/server/templates.d.ts +0 -31
- package/dist/server/templates.d.ts.map +0 -1
- package/dist/server/types.d.ts +0 -69
- package/dist/server/types.d.ts.map +0 -1
- package/dist/server/utils.d.ts +0 -70
- package/dist/server/utils.d.ts.map +0 -1
- package/dist/server/wasm.d.ts +0 -29
- package/dist/server/wasm.d.ts.map +0 -1
- package/dist/server-renderer.d.ts +0 -5
- package/dist/server-renderer.d.ts.map +0 -1
- package/dist/wasm.d.ts +0 -51
- package/dist/wasm.d.ts.map +0 -1
- package/templates/wasm/src/index.html +0 -14
- package/templates/wasm/src/main.tsx +0 -5
- package/templates/wasm/src/wasm-loader.ts +0 -119
package/dist/browser.js
CHANGED
|
@@ -1,296 +1,3 @@
|
|
|
1
|
-
// node_modules/frontend-hamroun/dist/index.mjs
|
|
2
|
-
var isBatching = false;
|
|
3
|
-
var queue = [];
|
|
4
|
-
function batchUpdates(fn) {
|
|
5
|
-
if (isBatching) {
|
|
6
|
-
queue.push(fn);
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
isBatching = true;
|
|
10
|
-
try {
|
|
11
|
-
fn();
|
|
12
|
-
while (queue.length > 0) {
|
|
13
|
-
const nextFn = queue.shift();
|
|
14
|
-
nextFn == null ? void 0 : nextFn();
|
|
15
|
-
}
|
|
16
|
-
} finally {
|
|
17
|
-
isBatching = false;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
var currentRender = 0;
|
|
21
|
-
var states = /* @__PURE__ */ new Map();
|
|
22
|
-
var stateIndices = /* @__PURE__ */ new Map();
|
|
23
|
-
var effects = /* @__PURE__ */ new Map();
|
|
24
|
-
var memos = /* @__PURE__ */ new Map();
|
|
25
|
-
var refs = /* @__PURE__ */ new Map();
|
|
26
|
-
var globalRenderCallback = null;
|
|
27
|
-
var globalContainer = null;
|
|
28
|
-
var currentElement = null;
|
|
29
|
-
var isServer = typeof window === "undefined";
|
|
30
|
-
var serverStates = /* @__PURE__ */ new Map();
|
|
31
|
-
function setRenderCallback(callback, element, container) {
|
|
32
|
-
globalRenderCallback = callback;
|
|
33
|
-
globalContainer = container;
|
|
34
|
-
currentElement = element;
|
|
35
|
-
}
|
|
36
|
-
function prepareRender() {
|
|
37
|
-
currentRender++;
|
|
38
|
-
stateIndices.set(currentRender, 0);
|
|
39
|
-
return currentRender;
|
|
40
|
-
}
|
|
41
|
-
function finishRender() {
|
|
42
|
-
if (isServer) {
|
|
43
|
-
serverStates.delete(currentRender);
|
|
44
|
-
}
|
|
45
|
-
currentRender = 0;
|
|
46
|
-
}
|
|
47
|
-
function useState(initial) {
|
|
48
|
-
if (!currentRender) {
|
|
49
|
-
throw new Error("useState must be called within a render");
|
|
50
|
-
}
|
|
51
|
-
if (isServer) {
|
|
52
|
-
if (!serverStates.has(currentRender)) {
|
|
53
|
-
serverStates.set(currentRender, /* @__PURE__ */ new Map());
|
|
54
|
-
}
|
|
55
|
-
const componentState = serverStates.get(currentRender);
|
|
56
|
-
const index2 = stateIndices.get(currentRender) || 0;
|
|
57
|
-
if (!componentState.has(index2)) {
|
|
58
|
-
componentState.set(index2, initial);
|
|
59
|
-
}
|
|
60
|
-
const state2 = componentState.get(index2);
|
|
61
|
-
const setState2 = (newValue) => {
|
|
62
|
-
};
|
|
63
|
-
stateIndices.set(currentRender, index2 + 1);
|
|
64
|
-
return [state2, setState2];
|
|
65
|
-
}
|
|
66
|
-
if (!states.has(currentRender)) {
|
|
67
|
-
states.set(currentRender, []);
|
|
68
|
-
}
|
|
69
|
-
const componentStates = states.get(currentRender);
|
|
70
|
-
const index = stateIndices.get(currentRender);
|
|
71
|
-
if (index >= componentStates.length) {
|
|
72
|
-
componentStates.push(initial);
|
|
73
|
-
}
|
|
74
|
-
const state = componentStates[index];
|
|
75
|
-
const setState = (newValue) => {
|
|
76
|
-
const nextValue = typeof newValue === "function" ? newValue(componentStates[index]) : newValue;
|
|
77
|
-
if (componentStates[index] === nextValue)
|
|
78
|
-
return;
|
|
79
|
-
componentStates[index] = nextValue;
|
|
80
|
-
if (isBatching) {
|
|
81
|
-
batchUpdates(() => rerender(currentRender));
|
|
82
|
-
} else {
|
|
83
|
-
rerender(currentRender);
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
stateIndices.set(currentRender, index + 1);
|
|
87
|
-
return [state, setState];
|
|
88
|
-
}
|
|
89
|
-
function useEffect(callback, deps) {
|
|
90
|
-
if (!currentRender)
|
|
91
|
-
throw new Error("useEffect must be called within a render");
|
|
92
|
-
const effectIndex = stateIndices.get(currentRender);
|
|
93
|
-
if (!effects.has(currentRender)) {
|
|
94
|
-
effects.set(currentRender, []);
|
|
95
|
-
}
|
|
96
|
-
const componentEffects = effects.get(currentRender);
|
|
97
|
-
const prevEffect = componentEffects[effectIndex];
|
|
98
|
-
if (!prevEffect || !deps || !prevEffect.deps || deps.some((dep, i) => dep !== prevEffect.deps[i])) {
|
|
99
|
-
if (prevEffect == null ? void 0 : prevEffect.cleanup) {
|
|
100
|
-
prevEffect.cleanup();
|
|
101
|
-
}
|
|
102
|
-
queueMicrotask(() => {
|
|
103
|
-
const cleanup = callback() || void 0;
|
|
104
|
-
componentEffects[effectIndex] = { cleanup, deps };
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
stateIndices.set(currentRender, effectIndex + 1);
|
|
108
|
-
}
|
|
109
|
-
function useMemo(factory, deps) {
|
|
110
|
-
if (!currentRender)
|
|
111
|
-
throw new Error("useMemo must be called within a render");
|
|
112
|
-
const memoIndex = stateIndices.get(currentRender);
|
|
113
|
-
if (!memos.has(currentRender)) {
|
|
114
|
-
memos.set(currentRender, []);
|
|
115
|
-
}
|
|
116
|
-
const componentMemos = memos.get(currentRender);
|
|
117
|
-
const prevMemo = componentMemos[memoIndex];
|
|
118
|
-
if (!prevMemo || deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i]))) {
|
|
119
|
-
const value = factory();
|
|
120
|
-
componentMemos[memoIndex] = { value, deps };
|
|
121
|
-
stateIndices.set(currentRender, memoIndex + 1);
|
|
122
|
-
return value;
|
|
123
|
-
}
|
|
124
|
-
stateIndices.set(currentRender, memoIndex + 1);
|
|
125
|
-
return prevMemo.value;
|
|
126
|
-
}
|
|
127
|
-
function useRef(initial) {
|
|
128
|
-
if (!currentRender)
|
|
129
|
-
throw new Error("useRef must be called within a render");
|
|
130
|
-
const refIndex = stateIndices.get(currentRender);
|
|
131
|
-
if (!refs.has(currentRender)) {
|
|
132
|
-
refs.set(currentRender, []);
|
|
133
|
-
}
|
|
134
|
-
const componentRefs = refs.get(currentRender);
|
|
135
|
-
if (refIndex >= componentRefs.length) {
|
|
136
|
-
const ref2 = { current: initial };
|
|
137
|
-
componentRefs.push(ref2);
|
|
138
|
-
stateIndices.set(currentRender, refIndex + 1);
|
|
139
|
-
return ref2;
|
|
140
|
-
}
|
|
141
|
-
const ref = componentRefs[refIndex];
|
|
142
|
-
stateIndices.set(currentRender, refIndex + 1);
|
|
143
|
-
return ref;
|
|
144
|
-
}
|
|
145
|
-
async function rerender(rendererId) {
|
|
146
|
-
try {
|
|
147
|
-
const componentEffects = effects.get(rendererId);
|
|
148
|
-
if (componentEffects) {
|
|
149
|
-
componentEffects.forEach((effect) => {
|
|
150
|
-
if (effect.cleanup)
|
|
151
|
-
effect.cleanup();
|
|
152
|
-
});
|
|
153
|
-
effects.set(rendererId, []);
|
|
154
|
-
}
|
|
155
|
-
if (globalRenderCallback && globalContainer && currentElement) {
|
|
156
|
-
await globalRenderCallback(currentElement, globalContainer);
|
|
157
|
-
}
|
|
158
|
-
} catch (error) {
|
|
159
|
-
console.error("Error during rerender:", error);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
function useErrorBoundary() {
|
|
163
|
-
const [error, setError] = useState(null);
|
|
164
|
-
return [error, () => setError(null)];
|
|
165
|
-
}
|
|
166
|
-
function createContext(defaultValue) {
|
|
167
|
-
const context = {
|
|
168
|
-
Provider: ({ value, children }) => {
|
|
169
|
-
return children;
|
|
170
|
-
},
|
|
171
|
-
Consumer: ({ children }) => {
|
|
172
|
-
return children(defaultValue);
|
|
173
|
-
},
|
|
174
|
-
_id: Symbol(),
|
|
175
|
-
useSelector: (selector) => {
|
|
176
|
-
return selector(defaultValue);
|
|
177
|
-
}
|
|
178
|
-
};
|
|
179
|
-
return context;
|
|
180
|
-
}
|
|
181
|
-
function useContext(context) {
|
|
182
|
-
return context;
|
|
183
|
-
}
|
|
184
|
-
function jsx(type, props) {
|
|
185
|
-
console.log("JSX Transform:", { type, props });
|
|
186
|
-
const processedProps = { ...props };
|
|
187
|
-
if (arguments.length > 2) {
|
|
188
|
-
processedProps.children = Array.prototype.slice.call(arguments, 2);
|
|
189
|
-
}
|
|
190
|
-
return { type, props: processedProps };
|
|
191
|
-
}
|
|
192
|
-
var Fragment = ({ children }) => children;
|
|
193
|
-
async function createElement(vnode) {
|
|
194
|
-
var _a;
|
|
195
|
-
console.log("Creating element from:", vnode);
|
|
196
|
-
if (vnode == null) {
|
|
197
|
-
return document.createTextNode("");
|
|
198
|
-
}
|
|
199
|
-
if (typeof vnode === "boolean") {
|
|
200
|
-
return document.createTextNode("");
|
|
201
|
-
}
|
|
202
|
-
if (typeof vnode === "number" || typeof vnode === "string") {
|
|
203
|
-
return document.createTextNode(String(vnode));
|
|
204
|
-
}
|
|
205
|
-
if (Array.isArray(vnode)) {
|
|
206
|
-
const fragment = document.createDocumentFragment();
|
|
207
|
-
for (const child of vnode) {
|
|
208
|
-
const node = await createElement(child);
|
|
209
|
-
fragment.appendChild(node);
|
|
210
|
-
}
|
|
211
|
-
return fragment;
|
|
212
|
-
}
|
|
213
|
-
if ("type" in vnode && vnode.props !== void 0) {
|
|
214
|
-
const { type, props } = vnode;
|
|
215
|
-
if (typeof type === "function") {
|
|
216
|
-
try {
|
|
217
|
-
const result = await type(props || {});
|
|
218
|
-
const node = await createElement(result);
|
|
219
|
-
if (node instanceof Element) {
|
|
220
|
-
node.setAttribute("data-component-id", type.name || type.toString());
|
|
221
|
-
}
|
|
222
|
-
return node;
|
|
223
|
-
} catch (error) {
|
|
224
|
-
console.error("Error rendering component:", error);
|
|
225
|
-
return document.createTextNode("");
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
const element = document.createElement(type);
|
|
229
|
-
for (const [key, value] of Object.entries(props || {})) {
|
|
230
|
-
if (key === "children")
|
|
231
|
-
continue;
|
|
232
|
-
if (key.startsWith("on") && typeof value === "function") {
|
|
233
|
-
const eventName = key.toLowerCase().slice(2);
|
|
234
|
-
const existingHandler = (_a = element.__events) == null ? void 0 : _a[eventName];
|
|
235
|
-
if (existingHandler) {
|
|
236
|
-
element.removeEventListener(eventName, existingHandler);
|
|
237
|
-
}
|
|
238
|
-
element.addEventListener(eventName, value);
|
|
239
|
-
if (!element.__events) {
|
|
240
|
-
element.__events = {};
|
|
241
|
-
}
|
|
242
|
-
element.__events[eventName] = value;
|
|
243
|
-
} else if (key === "style" && typeof value === "object") {
|
|
244
|
-
Object.assign(element.style, value);
|
|
245
|
-
} else if (key === "className") {
|
|
246
|
-
element.setAttribute("class", String(value));
|
|
247
|
-
} else if (key !== "key" && key !== "ref") {
|
|
248
|
-
element.setAttribute(key, String(value));
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
const children = props == null ? void 0 : props.children;
|
|
252
|
-
if (children != null) {
|
|
253
|
-
const childArray = Array.isArray(children) ? children.flat() : [children];
|
|
254
|
-
for (const child of childArray) {
|
|
255
|
-
const childNode = await createElement(child);
|
|
256
|
-
element.appendChild(childNode);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
return element;
|
|
260
|
-
}
|
|
261
|
-
return document.createTextNode(String(vnode));
|
|
262
|
-
}
|
|
263
|
-
var isHydrating = false;
|
|
264
|
-
async function hydrate(element, container) {
|
|
265
|
-
isHydrating = true;
|
|
266
|
-
try {
|
|
267
|
-
await render(element, container);
|
|
268
|
-
} finally {
|
|
269
|
-
isHydrating = false;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
async function render(element, container) {
|
|
273
|
-
console.log("Rendering to:", container.id);
|
|
274
|
-
batchUpdates(async () => {
|
|
275
|
-
const rendererId = prepareRender();
|
|
276
|
-
try {
|
|
277
|
-
setRenderCallback(render, element, container);
|
|
278
|
-
const domNode = await createElement(element);
|
|
279
|
-
if (!isHydrating) {
|
|
280
|
-
container.innerHTML = "";
|
|
281
|
-
}
|
|
282
|
-
container.appendChild(domNode);
|
|
283
|
-
} finally {
|
|
284
|
-
finishRender();
|
|
285
|
-
}
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
var server = {
|
|
289
|
-
async getServer() {
|
|
290
|
-
throw new Error("Server module can only be used in Node.js environment");
|
|
291
|
-
}
|
|
292
|
-
};
|
|
293
|
-
|
|
294
1
|
// src/wasm.ts
|
|
295
2
|
async function loadGoWasm(wasmUrl, options = {}) {
|
|
296
3
|
if (typeof window === "undefined") {
|
|
@@ -379,139 +86,11 @@ function useGoWasm(wasmUrl, options = {}) {
|
|
|
379
86
|
getFunctions: getWasmFunctions
|
|
380
87
|
};
|
|
381
88
|
}
|
|
382
|
-
|
|
383
|
-
// src/browser.ts
|
|
384
|
-
function generateDocument(content, options = {}) {
|
|
385
|
-
const { title = "App", description = "", styles = [], scripts = [] } = options;
|
|
386
|
-
return `<!DOCTYPE html>
|
|
387
|
-
<html lang="en">
|
|
388
|
-
<head>
|
|
389
|
-
<meta charset="UTF-8">
|
|
390
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
391
|
-
<title>${escapeHtml(title)}</title>
|
|
392
|
-
${description ? `<meta name="description" content="${escapeHtml(description)}">` : ""}
|
|
393
|
-
${styles.map((href) => `<link rel="stylesheet" href="${escapeHtml(href)}">`).join("\n ")}
|
|
394
|
-
</head>
|
|
395
|
-
<body>
|
|
396
|
-
<div id="app-root">${content}</div>
|
|
397
|
-
${scripts.map((src) => `<script src="${escapeHtml(src)}" defer><\/script>`).join("\n ")}
|
|
398
|
-
</body>
|
|
399
|
-
</html>`;
|
|
400
|
-
}
|
|
401
|
-
function generateErrorPage(statusCode, message) {
|
|
402
|
-
return generateDocument(`
|
|
403
|
-
<div style="text-align: center; padding: 2rem;">
|
|
404
|
-
<h1>${statusCode}</h1>
|
|
405
|
-
<p>${escapeHtml(message)}</p>
|
|
406
|
-
<a href="/">Back to Home</a>
|
|
407
|
-
</div>
|
|
408
|
-
`, { title: `Error ${statusCode}` });
|
|
409
|
-
}
|
|
410
|
-
function generateLoadingPage(message = "Loading...") {
|
|
411
|
-
return generateDocument(`
|
|
412
|
-
<div style="text-align: center; padding: 2rem;">
|
|
413
|
-
<div style="display: inline-block; width: 40px; height: 40px; border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; animation: spin 1s linear infinite;"></div>
|
|
414
|
-
<p>${escapeHtml(message)}</p>
|
|
415
|
-
<style>
|
|
416
|
-
@keyframes spin {
|
|
417
|
-
0% { transform: rotate(0deg); }
|
|
418
|
-
100% { transform: rotate(360deg); }
|
|
419
|
-
}
|
|
420
|
-
</style>
|
|
421
|
-
</div>
|
|
422
|
-
`, { title: "Loading" });
|
|
423
|
-
}
|
|
424
|
-
function escapeHtml(text) {
|
|
425
|
-
return String(text).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
426
|
-
}
|
|
427
|
-
function renderToString(content) {
|
|
428
|
-
if (typeof content === "string") {
|
|
429
|
-
return content;
|
|
430
|
-
}
|
|
431
|
-
if (typeof content === "function") {
|
|
432
|
-
try {
|
|
433
|
-
const result = content();
|
|
434
|
-
return String(result);
|
|
435
|
-
} catch (error) {
|
|
436
|
-
return `<!-- Error rendering: ${error} -->`;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
return String(content);
|
|
440
|
-
}
|
|
441
|
-
function generateToken(length = 32) {
|
|
442
|
-
const array = new Uint8Array(length);
|
|
443
|
-
if (typeof crypto !== "undefined" && crypto.getRandomValues) {
|
|
444
|
-
crypto.getRandomValues(array);
|
|
445
|
-
} else {
|
|
446
|
-
for (let i = 0; i < array.length; i++) {
|
|
447
|
-
array[i] = Math.floor(Math.random() * 256);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
return Array.from(array, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
451
|
-
}
|
|
452
|
-
function safeJsonParse(json, fallback) {
|
|
453
|
-
try {
|
|
454
|
-
return JSON.parse(json);
|
|
455
|
-
} catch (error) {
|
|
456
|
-
return fallback;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
var isBrowser = typeof window !== "undefined";
|
|
460
|
-
var isNode = false;
|
|
461
|
-
var Server = null;
|
|
462
|
-
var createServer = null;
|
|
463
|
-
var createDevServer = null;
|
|
464
|
-
var createProductionServer = null;
|
|
465
|
-
var Database = null;
|
|
466
|
-
var AuthService = null;
|
|
467
|
-
var ApiRouter = null;
|
|
468
|
-
var requestLogger = null;
|
|
469
|
-
var errorHandler = null;
|
|
470
|
-
var notFoundHandler = null;
|
|
471
|
-
var rateLimit = null;
|
|
472
|
-
var initNodeWasm = null;
|
|
473
|
-
var loadGoWasmFromFile = null;
|
|
474
|
-
console.log("Baraqex - Browser version loaded");
|
|
475
89
|
export {
|
|
476
|
-
ApiRouter,
|
|
477
|
-
AuthService,
|
|
478
|
-
Database,
|
|
479
|
-
Fragment,
|
|
480
|
-
Server,
|
|
481
|
-
batchUpdates,
|
|
482
90
|
callWasmFunction,
|
|
483
|
-
createContext,
|
|
484
|
-
createDevServer,
|
|
485
|
-
createProductionServer,
|
|
486
|
-
createServer,
|
|
487
|
-
errorHandler,
|
|
488
|
-
generateDocument,
|
|
489
|
-
generateErrorPage,
|
|
490
|
-
generateLoadingPage,
|
|
491
|
-
generateToken,
|
|
492
91
|
getWasmFunctions,
|
|
493
|
-
hydrate,
|
|
494
|
-
initNodeWasm,
|
|
495
|
-
isBrowser,
|
|
496
|
-
isNode,
|
|
497
92
|
isWasmReady,
|
|
498
|
-
jsx,
|
|
499
|
-
jsx as jsxs,
|
|
500
93
|
loadGoWasm,
|
|
501
|
-
|
|
502
|
-
notFoundHandler,
|
|
503
|
-
rateLimit,
|
|
504
|
-
render,
|
|
505
|
-
renderToString,
|
|
506
|
-
requestLogger,
|
|
507
|
-
safeJsonParse,
|
|
508
|
-
server,
|
|
509
|
-
useContext,
|
|
510
|
-
useEffect,
|
|
511
|
-
useErrorBoundary,
|
|
512
|
-
useGoWasm,
|
|
513
|
-
useMemo,
|
|
514
|
-
useRef,
|
|
515
|
-
useState
|
|
94
|
+
useGoWasm
|
|
516
95
|
};
|
|
517
96
|
//# sourceMappingURL=browser.js.map
|
package/dist/browser.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../
|
|
4
|
-
"sourcesContent": ["export let isBatching = false;\r\nconst queue: Function[] = [];\r\n\r\nexport function batchUpdates(fn: Function) {\r\n if (isBatching) {\r\n queue.push(fn);\r\n return;\r\n }\r\n\r\n isBatching = true;\r\n try {\r\n fn();\r\n while (queue.length > 0) {\r\n const nextFn = queue.shift();\r\n nextFn?.();\r\n }\r\n } finally {\r\n isBatching = false;\r\n }\r\n}\r\n\r\nexport function getIsBatching() {\r\n return isBatching;\r\n}\r\n", "import { createElement } from './jsx-runtime';\r\nimport { batchUpdates, isBatching } from './batch';\r\nimport { diff } from './vdom';\r\n\r\nlet currentRender: number = 0;\r\nconst states = new Map<number, any[]>();\r\nconst stateIndices = new Map<number, number>();\r\nconst effects = new Map<number, Effect[]>();\r\nconst memos = new Map<number, { value: any; deps: any[] }[]>();\r\nconst refs = new Map<number, any[]>();\r\n\r\ninterface Effect {\r\n cleanup?: () => void;\r\n deps?: any[];\r\n}\r\n\r\n// Add at the top with other declarations\r\nlet globalRenderCallback: ((element: any, container: HTMLElement) => void) | null = null;\r\nlet globalContainer: HTMLElement | null = null;\r\nlet currentElement: any = null;\r\n\r\nconst isServer = typeof window === 'undefined';\r\nconst serverStates = new Map<number, any>();\r\n\r\nexport function setRenderCallback(\r\n callback: (element: any, container: HTMLElement) => void,\r\n element: any,\r\n container: HTMLElement\r\n) {\r\n globalRenderCallback = callback;\r\n globalContainer = container;\r\n currentElement = element;\r\n}\r\n\r\nexport function prepareRender() {\r\n currentRender++;\r\n stateIndices.set(currentRender, 0);\r\n return currentRender;\r\n}\r\n\r\nexport function finishRender() {\r\n if (isServer) {\r\n serverStates.delete(currentRender);\r\n }\r\n currentRender = 0;\r\n}\r\n\r\nexport function useState<T>(initial: T): [T, (value: T | ((prev: T) => T)) => void] {\r\n if (!currentRender) {\r\n throw new Error('useState must be called within a render');\r\n }\r\n\r\n if (isServer) {\r\n // Server-side state handling\r\n if (!serverStates.has(currentRender)) {\r\n serverStates.set(currentRender, new Map());\r\n }\r\n const componentState = serverStates.get(currentRender)!;\r\n const index = stateIndices.get(currentRender) || 0;\r\n \r\n if (!componentState.has(index)) {\r\n componentState.set(index, initial);\r\n }\r\n\r\n const state = componentState.get(index);\r\n const setState = (newValue: T | ((prev: T) => T)) => {\r\n // No-op for server-side\r\n };\r\n\r\n stateIndices.set(currentRender, index + 1);\r\n return [state, setState];\r\n }\r\n\r\n if (!states.has(currentRender)) {\r\n states.set(currentRender, []);\r\n }\r\n\r\n const componentStates = states.get(currentRender)!;\r\n const index = stateIndices.get(currentRender)!;\r\n \r\n if (index >= componentStates.length) {\r\n componentStates.push(initial);\r\n }\r\n\r\n const state = componentStates[index];\r\n const setState = (newValue: T | ((prev: T) => T)) => {\r\n const nextValue = typeof newValue === 'function' \r\n ? (newValue as Function)(componentStates[index])\r\n : newValue;\r\n\r\n if (componentStates[index] === nextValue) return; // Skip if value hasn't changed\r\n \r\n componentStates[index] = nextValue;\r\n \r\n if (isBatching) {\r\n batchUpdates(() => rerender(currentRender));\r\n } else {\r\n rerender(currentRender);\r\n }\r\n };\r\n\r\n stateIndices.set(currentRender, index + 1);\r\n return [state, setState];\r\n}\r\n\r\nexport function useEffect(callback: () => (() => void) | void, deps?: any[]) {\r\n if (!currentRender) throw new Error('useEffect must be called within a render');\r\n \r\n const effectIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!effects.has(currentRender)) {\r\n effects.set(currentRender, []);\r\n }\r\n\r\n const componentEffects = effects.get(currentRender)!;\r\n const prevEffect = componentEffects[effectIndex];\r\n \r\n // Run effect if deps changed\r\n if (!prevEffect || !deps || !prevEffect.deps || \r\n deps.some((dep, i) => dep !== prevEffect.deps![i])) {\r\n \r\n // Cleanup previous effect\r\n if (prevEffect?.cleanup) {\r\n prevEffect.cleanup();\r\n }\r\n\r\n // Schedule new effect\r\n queueMicrotask(() => {\r\n const cleanup = callback() || undefined;\r\n componentEffects[effectIndex] = { cleanup: cleanup, deps };\r\n });\r\n }\r\n \r\n stateIndices.set(currentRender, effectIndex + 1);\r\n}\r\n\r\nexport function useMemo<T>(factory: () => T, deps: any[]): T {\r\n if (!currentRender) throw new Error('useMemo must be called within a render');\r\n \r\n const memoIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!memos.has(currentRender)) {\r\n memos.set(currentRender, []);\r\n }\r\n\r\n const componentMemos = memos.get(currentRender)!;\r\n const prevMemo = componentMemos[memoIndex];\r\n \r\n if (!prevMemo || (deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i])))) {\r\n const value = factory();\r\n componentMemos[memoIndex] = { value, deps };\r\n stateIndices.set(currentRender, memoIndex + 1);\r\n return value;\r\n }\r\n\r\n stateIndices.set(currentRender, memoIndex + 1);\r\n return prevMemo.value;\r\n}\r\n\r\nexport function useRef<T>(initial: T) {\r\n if (!currentRender) throw new Error('useRef must be called within a render');\r\n \r\n const refIndex = stateIndices.get(currentRender)!;\r\n \r\n if (!refs.has(currentRender)) {\r\n refs.set(currentRender, []);\r\n }\r\n\r\n const componentRefs = refs.get(currentRender)!;\r\n if (refIndex >= componentRefs.length) {\r\n // Initialize with an object that has a current property\r\n const ref = { current: initial };\r\n componentRefs.push(ref);\r\n stateIndices.set(currentRender, refIndex + 1);\r\n return ref;\r\n }\r\n\r\n const ref = componentRefs[refIndex];\r\n stateIndices.set(currentRender, refIndex + 1);\r\n return ref;\r\n}\r\n\r\n// Add a map to track component DOM nodes\r\nconst componentNodes = new Map<Function, Node>();\r\n\r\nasync function rerender(rendererId: number) {\r\n try {\r\n // Clean up effects\r\n const componentEffects = effects.get(rendererId);\r\n if (componentEffects) {\r\n componentEffects.forEach(effect => {\r\n if (effect.cleanup) effect.cleanup();\r\n });\r\n effects.set(rendererId, []);\r\n }\r\n\r\n if (globalRenderCallback && globalContainer && currentElement) {\r\n await globalRenderCallback(currentElement, globalContainer);\r\n }\r\n } catch (error) {\r\n console.error('Error during rerender:', error);\r\n }\r\n}\r\n\r\n// Add new hook for error boundaries\r\nexport function useErrorBoundary(): [Error | null, () => void] {\r\n const [error, setError] = useState<Error | null>(null);\r\n return [error, () => setError(null)];\r\n}\r\n\r\n// Remove withHooks export\r\n", "\r\n\r\nconst contexts = new Map<symbol, any>();\r\nlet currentRender: Function | null = null;\r\n\r\nexport interface Context<T> {\r\n Provider: (props: { value: T; children?: any }) => any;\r\n Consumer: (props: { children: (value: T) => any }) => any;\r\n _id: symbol;\r\n useSelector: <S>(selector: (state: T) => S) => S;\r\n}\r\n\r\nexport function createContext<T>(defaultValue: T): Context<T> {\r\n const context = {\r\n Provider: ({ value, children }: { value: T, children?: any }) => {\r\n return children;\r\n },\r\n Consumer: ({ children }: { children: (value: T) => any }) => {\r\n return children(defaultValue);\r\n },\r\n _id: Symbol(),\r\n useSelector: <S>(selector: (state: T) => S) => {\r\n return selector(defaultValue);\r\n }\r\n };\r\n\r\n return context;\r\n}\r\n\r\nexport function useContext<T>(context: any): T {\r\n return context;\r\n}\r\n", "import type { Component } from './component';\r\n\r\ninterface VNode {\r\n type: string | Function;\r\n props: Record<string, any>;\r\n}\r\n\r\nfunction jsx(type: string | Function, props: any): VNode {\r\n console.log('JSX Transform:', { type, props });\r\n const processedProps = { ...props };\r\n \r\n // Handle children properly\r\n if (arguments.length > 2) {\r\n processedProps.children = Array.prototype.slice.call(arguments, 2);\r\n }\r\n \r\n return { type, props: processedProps };\r\n}\r\n\r\nconst Fragment = ({ children }: { children: any }) => children;\r\n\r\nasync function createElement(vnode: VNode | any): Promise<Node> {\r\n console.log('Creating element from:', vnode);\r\n\r\n // Handle primitives and null\r\n if (vnode == null) {\r\n return document.createTextNode('');\r\n }\r\n \r\n if (typeof vnode === 'boolean') {\r\n return document.createTextNode('');\r\n }\r\n\r\n if (typeof vnode === 'number' || typeof vnode === 'string') {\r\n return document.createTextNode(String(vnode));\r\n }\r\n\r\n // Handle arrays\r\n if (Array.isArray(vnode)) {\r\n const fragment = document.createDocumentFragment();\r\n for (const child of vnode) {\r\n const node = await createElement(child);\r\n fragment.appendChild(node);\r\n }\r\n return fragment;\r\n }\r\n\r\n // Handle VNode\r\n if ('type' in vnode && vnode.props !== undefined) {\r\n const { type, props } = vnode;\r\n \r\n // Handle function components\r\n if (typeof type === 'function') {\r\n try {\r\n const result = await type(props || {});\r\n const node = await createElement(result);\r\n if (node instanceof Element) {\r\n node.setAttribute('data-component-id', type.name || type.toString());\r\n }\r\n return node;\r\n } catch (error) {\r\n console.error('Error rendering component:', error);\r\n return document.createTextNode('');\r\n }\r\n }\r\n\r\n // Create DOM element\r\n const element = document.createElement(type as string);\r\n \r\n // Handle props\r\n for (const [key, value] of Object.entries(props || {})) {\r\n if (key === 'children') continue;\r\n if (key.startsWith('on') && typeof value === 'function') {\r\n const eventName = key.toLowerCase().slice(2);\r\n // Remove existing event listener if any\r\n const existingHandler = (element as any).__events?.[eventName];\r\n if (existingHandler) {\r\n element.removeEventListener(eventName, existingHandler);\r\n }\r\n \r\n // Add new event listener\r\n element.addEventListener(eventName, value as EventListener);\r\n if (!(element as any).__events) {\r\n (element as any).__events = {};\r\n }\r\n (element as any).__events[eventName] = value;\r\n } else if (key === 'style' && typeof value === 'object') {\r\n Object.assign(element.style, value);\r\n } else if (key === 'className') {\r\n element.setAttribute('class', String(value));\r\n } else if (key !== 'key' && key !== 'ref') {\r\n element.setAttribute(key, String(value));\r\n }\r\n }\r\n\r\n // Handle children\r\n const children = props?.children;\r\n if (children != null) {\r\n const childArray = Array.isArray(children) ? children.flat() : [children];\r\n for (const child of childArray) {\r\n const childNode = await createElement(child);\r\n element.appendChild(childNode);\r\n }\r\n }\r\n\r\n return element;\r\n }\r\n\r\n // Handle other objects by converting to string\r\n return document.createTextNode(String(vnode));\r\n}\r\n\r\n// Export named functions and aliases without duplicates\r\nexport {\r\n jsx,\r\n jsx as jsxs,\r\n jsx as jsxDEV,\r\n Fragment,\r\n createElement\r\n};\r\n\r\n// Named exports object\r\nconst jsxRuntime = {\r\n jsx,\r\n jsxs: jsx,\r\n jsxDEV: jsx,\r\n Fragment,\r\n createElement\r\n};\r\n\r\nexport default jsxRuntime;\r\n", "import { createElement } from './jsx-runtime';\r\nimport { prepareRender, finishRender, setRenderCallback } from './hooks';\r\nimport { batchUpdates } from './batch';\r\n\r\nlet isHydrating = false;\r\n\r\nexport async function hydrate(element: any, container: HTMLElement) {\r\n isHydrating = true;\r\n try {\r\n await render(element, container);\r\n } finally {\r\n isHydrating = false;\r\n }\r\n}\r\n\r\nexport async function render(element: any, container: HTMLElement) {\r\n console.log('Rendering to:', container.id);\r\n \r\n batchUpdates(async () => {\r\n const rendererId = prepareRender();\r\n try {\r\n setRenderCallback(render, element, container);\r\n const domNode = await createElement(element);\r\n \r\n if (!isHydrating) {\r\n container.innerHTML = '';\r\n }\r\n container.appendChild(domNode);\r\n \r\n } finally {\r\n finishRender();\r\n }\r\n });\r\n}\r\n", "import { VNode, Component } from './types';\r\nimport { prepareRender, finishRender } from './hooks';\r\n\r\n/**\r\n * Renders a virtual DOM tree to an HTML string\r\n */\r\nexport function renderToString(vnode: VNode): string {\r\n // Reset hook state for this render\r\n prepareRender();\r\n \r\n // Render the tree to HTML\r\n const html = renderNodeToString(vnode);\r\n \r\n // Clean up after rendering\r\n finishRender();\r\n \r\n return html;\r\n}\r\n\r\n/**\r\n * Internal function to convert a virtual node to an HTML string\r\n */\r\nfunction renderNodeToString(vnode: VNode | string | number | boolean | null | undefined): string {\r\n // Handle primitive values\r\n if (vnode === null || vnode === undefined) return '';\r\n if (typeof vnode === 'boolean') return '';\r\n if (typeof vnode === 'number' || typeof vnode === 'string') return escapeHtml(String(vnode));\r\n \r\n // Handle function components\r\n if (typeof vnode.type === 'function') {\r\n const Component = vnode.type as Component;\r\n const renderedNode = Component(vnode.props || {});\r\n return renderNodeToString(renderedNode);\r\n }\r\n \r\n // Handle intrinsic elements (regular HTML tags)\r\n if (typeof vnode.type === 'string') {\r\n const tag = vnode.type;\r\n let attrs = '';\r\n let children = '';\r\n \r\n // Convert props to HTML attributes\r\n if (vnode.props) {\r\n for (const [key, value] of Object.entries(vnode.props)) {\r\n // Skip children prop as we handle it separately\r\n if (key === 'children') continue;\r\n \r\n // Skip event handlers (they start with 'on')\r\n if (key.startsWith('on')) continue;\r\n \r\n // Handle the className prop specially\r\n if (key === 'className') {\r\n attrs += ` class=\"${escapeHtml(value as string)}\"`;\r\n continue;\r\n }\r\n \r\n // Handle other attributes\r\n if (typeof value === 'string' || typeof value === 'number') {\r\n attrs += ` ${key}=\"${escapeHtml(String(value))}\"`;\r\n } else if (value === true) {\r\n // Boolean attributes\r\n attrs += ` ${key}`;\r\n }\r\n }\r\n }\r\n \r\n // Process children\r\n const childrenArray = (vnode.props?.children) \r\n ? Array.isArray(vnode.props.children) \r\n ? vnode.props.children \r\n : [vnode.props.children]\r\n : [];\r\n \r\n for (const child of childrenArray) {\r\n children += renderNodeToString(child);\r\n }\r\n \r\n // Self-closing tags\r\n const selfClosing = [\r\n 'area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input',\r\n 'link', 'meta', 'param', 'source', 'track', 'wbr'\r\n ];\r\n \r\n if (selfClosing.includes(tag)) {\r\n return `<${tag}${attrs}/>`;\r\n }\r\n \r\n // Regular tags with closing\r\n return `<${tag}${attrs}>${children}</${tag}>`;\r\n }\r\n \r\n // Handle fragments\r\n if (vnode.type === Symbol.for('react.fragment')) {\r\n let fragmentOutput = '';\r\n const children = Array.isArray(vnode.props?.children)\r\n ? vnode.props.children\r\n : vnode.props?.children ? [vnode.props.children] : [];\r\n \r\n for (const child of children) {\r\n fragmentOutput += renderNodeToString(child);\r\n }\r\n \r\n return fragmentOutput;\r\n }\r\n \r\n // Fallback for unknown node types\r\n console.warn('Unknown vnode type:', vnode.type);\r\n return '';\r\n}\r\n\r\n/**\r\n * Escape HTML special characters to prevent XSS\r\n */\r\nfunction escapeHtml(text: string): string {\r\n return text\r\n .replace(/&/g, '&')\r\n .replace(/</g, '<')\r\n .replace(/>/g, '>')\r\n .replace(/\"/g, '"')\r\n .replace(/'/g, ''');\r\n}\r\n", "import { createElement } from './jsx-runtime';\r\nimport { prepareRender, finishRender, setRenderCallback } from './hooks';\r\n\r\nexport { \r\n useState, \r\n useEffect, \r\n useMemo, \r\n useRef,\r\n useErrorBoundary \r\n} from './hooks';\r\n\r\nexport { createContext, useContext } from './context';\r\nexport { batchUpdates } from './batch';\r\nexport { jsx, jsxs, Fragment } from './jsx-runtime';\r\nexport { render, hydrate } from './renderer';\r\nexport { renderToString } from './server-renderer';\r\n\r\n// Re-export types for client-side usage\r\nexport type { Context } from './context';\r\nexport type { VNode } from './types';\r\n\r\n// Export server types for type checking\r\nexport type {\r\n Server,\r\n ServerConfig,\r\n User,\r\n DbConfig,\r\n MiddlewareFunction\r\n} from './server-types';\r\n\r\n// Provide placeholder server functionality\r\nexport const server = {\r\n async getServer() {\r\n throw new Error('Server module can only be used in Node.js environment');\r\n }\r\n};\r\n\r\nlet isHydrating = false;\r\n", "/**\r\n * WebAssembly integration for Frontend Hamroun\r\n * Works in both browser and Node.js environments\r\n */\r\n\r\nexport interface GoWasmOptions {\r\n debug?: boolean;\r\n goWasmPath?: string;\r\n importObject?: any;\r\n onLoad?: (instance: GoWasmInstance) => void;\r\n}\r\n\r\nexport interface GoWasmInstance {\r\n instance: WebAssembly.Instance;\r\n module: WebAssembly.Module;\r\n exports: WebAssembly.Exports;\r\n functions: Record<string, Function>;\r\n}\r\n\r\n/**\r\n * Load Go WASM module in the browser (like your working frontend code)\r\n */\r\nexport async function loadGoWasm(\r\n wasmUrl: string,\r\n options: GoWasmOptions = {}\r\n): Promise<GoWasmInstance> {\r\n if (typeof window === 'undefined') {\r\n throw new Error('loadGoWasm() is for browser use only. Use loadGoWasmFromFile() in Node.js.');\r\n }\r\n\r\n try {\r\n // Check if Go WASM runtime is available (like your frontend code)\r\n if (!window.Go) {\r\n throw new Error('Go WASM runtime not available. Make sure wasm_exec.js is loaded.');\r\n }\r\n\r\n if (options.debug) {\r\n console.log('[WASM] Loading WASM from:', wasmUrl);\r\n }\r\n\r\n // Fetch the WASM file (exactly like your frontend code)\r\n const response = await fetch(wasmUrl);\r\n \r\n if (!response.ok) {\r\n throw new Error(`Failed to fetch WASM file: ${response.status}`);\r\n }\r\n\r\n const wasmBytes = await response.arrayBuffer();\r\n \r\n // Initialize Go runtime (exactly like your frontend code)\r\n const go = new window.Go();\r\n const wasmModule = await WebAssembly.instantiate(wasmBytes, go.importObject);\r\n \r\n // Run the Go program (exactly like your frontend code)\r\n go.run(wasmModule.instance);\r\n \r\n // Wait a bit for Go functions to be registered (like your frontend code)\r\n await new Promise(resolve => setTimeout(resolve, 100));\r\n \r\n if (options.debug) {\r\n console.log('[WASM] Go program started, checking for registered functions...');\r\n }\r\n\r\n // Extract exported functions from global scope (like your frontend code)\r\n const functions: Record<string, Function> = {};\r\n \r\n // Look for Go functions in global scope\r\n for (const key in window) {\r\n if (typeof window[key] === 'function' && key.startsWith('go')) {\r\n functions[key] = window[key] as Function;\r\n if (options.debug) {\r\n console.log(`[WASM] Found function: ${key}`);\r\n }\r\n }\r\n }\r\n\r\n const wasmInstance: GoWasmInstance = {\r\n instance: wasmModule.instance,\r\n module: wasmModule,\r\n exports: wasmModule.instance.exports,\r\n functions\r\n };\r\n\r\n if (options.onLoad) {\r\n options.onLoad(wasmInstance);\r\n }\r\n\r\n if (options.debug) {\r\n console.log(`[WASM] Module loaded successfully with ${Object.keys(functions).length} functions`);\r\n }\r\n\r\n return wasmInstance;\r\n\r\n } catch (error) {\r\n console.error('[WASM] Error loading Go WASM module:', error);\r\n throw error;\r\n }\r\n}\r\n\r\n/**\r\n * Call a Go WASM function (like your frontend code's callWasmFunction)\r\n */\r\nexport function callWasmFunction(funcName: string, ...args: any[]): any {\r\n if (typeof window === 'undefined') {\r\n throw new Error('callWasmFunction() is for browser use only.');\r\n }\r\n\r\n const func = (window as any)[funcName];\r\n if (typeof func !== 'function') {\r\n throw new Error(`Function ${funcName} not found. Make sure the WASM module is loaded.`);\r\n }\r\n \r\n return func(...args);\r\n}\r\n\r\n/**\r\n * Check if Go WASM is ready (like your frontend code's wasmReady state)\r\n */\r\nexport function isWasmReady(): boolean {\r\n if (typeof window === 'undefined') {\r\n return false;\r\n }\r\n\r\n // Check if Go runtime is available and at least one Go function exists\r\n return !!(window.Go && Object.keys(window).some(key => \r\n key.startsWith('go') && typeof window[key] === 'function'\r\n ));\r\n}\r\n\r\n/**\r\n * Get all available Go WASM functions\r\n */\r\nexport function getWasmFunctions(): string[] {\r\n if (typeof window === 'undefined') {\r\n return [];\r\n }\r\n\r\n return Object.keys(window).filter(key => \r\n key.startsWith('go') && typeof window[key] === 'function'\r\n );\r\n}\r\n\r\n/**\r\n * Hook for React components (like your frontend code's useEffect pattern)\r\n */\r\nexport function useGoWasm(wasmUrl: string, options: GoWasmOptions = {}) {\r\n if (typeof window === 'undefined') {\r\n throw new Error('useGoWasm() is for browser use only.');\r\n }\r\n\r\n // This would need to be implemented as a React hook in frontend-hamroun\r\n // For now, return the basic functionality\r\n return {\r\n loadWasm: () => loadGoWasm(wasmUrl, options),\r\n callFunction: callWasmFunction,\r\n isReady: isWasmReady,\r\n getFunctions: getWasmFunctions\r\n };\r\n}\r\n\r\n// Browser-specific type declarations\r\ndeclare global {\r\n interface Window {\r\n Go: new () => {\r\n importObject: any;\r\n run: (instance: WebAssembly.Instance) => void;\r\n };\r\n [key: string]: any;\r\n }\r\n}\r\n", "/**\r\n * Browser-only entry point for baraqex\r\n * This file excludes all server dependencies to ensure browser compatibility\r\n */\r\n\r\n// Re-export everything from frontend-hamroun\r\nexport * from 'frontend-hamroun';\r\n\r\n// Export browser-compatible WASM functionality\r\nexport { loadGoWasm, callWasmFunction, isWasmReady, getWasmFunctions, useGoWasm } from './wasm.js';\r\n\r\n// Export type definitions (safe for all environments)\r\nexport type { GoWasmOptions, GoWasmInstance } from './wasm.js';\r\n\r\n// Export basic template utilities (no server dependencies)\r\n// Create browser-safe versions of template functions\r\nexport function generateDocument(content: string, options: any = {}): string {\r\n const { title = 'App', description = '', styles = [], scripts = [] } = options;\r\n \r\n return `<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta charset=\"UTF-8\">\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n <title>${escapeHtml(title)}</title>\r\n ${description ? `<meta name=\"description\" content=\"${escapeHtml(description)}\">` : ''}\r\n ${styles.map((href: string) => `<link rel=\"stylesheet\" href=\"${escapeHtml(href)}\">`).join('\\n ')}\r\n</head>\r\n<body>\r\n <div id=\"app-root\">${content}</div>\r\n ${scripts.map((src: string) => `<script src=\"${escapeHtml(src)}\" defer></script>`).join('\\n ')}\r\n</body>\r\n</html>`;\r\n}\r\n\r\nexport function generateErrorPage(statusCode: number, message: string): string {\r\n return generateDocument(`\r\n <div style=\"text-align: center; padding: 2rem;\">\r\n <h1>${statusCode}</h1>\r\n <p>${escapeHtml(message)}</p>\r\n <a href=\"/\">Back to Home</a>\r\n </div>\r\n `, { title: `Error ${statusCode}` });\r\n}\r\n\r\nexport function generateLoadingPage(message: string = 'Loading...'): string {\r\n return generateDocument(`\r\n <div style=\"text-align: center; padding: 2rem;\">\r\n <div style=\"display: inline-block; width: 40px; height: 40px; border: 4px solid #f3f3f3; border-top: 4px solid #3498db; border-radius: 50%; animation: spin 1s linear infinite;\"></div>\r\n <p>${escapeHtml(message)}</p>\r\n <style>\r\n @keyframes spin {\r\n 0% { transform: rotate(0deg); }\r\n 100% { transform: rotate(360deg); }\r\n }\r\n </style>\r\n </div>\r\n `, { title: 'Loading' });\r\n}\r\n\r\nfunction escapeHtml(text: string): string {\r\n return String(text)\r\n .replace(/&/g, '&')\r\n .replace(/</g, '<')\r\n .replace(/>/g, '>')\r\n .replace(/\"/g, '"')\r\n .replace(/'/g, ''');\r\n}\r\n\r\n// Simple renderToString function for browser SSR compatibility\r\nexport function renderToString(content: any): string {\r\n if (typeof content === 'string') {\r\n return content;\r\n }\r\n if (typeof content === 'function') {\r\n try {\r\n const result = content();\r\n return String(result);\r\n } catch (error) {\r\n return `<!-- Error rendering: ${error} -->`;\r\n }\r\n }\r\n return String(content);\r\n}\r\n\r\n// Browser-compatible utility functions\r\nexport function generateToken(length: number = 32): string {\r\n const array = new Uint8Array(length);\r\n if (typeof crypto !== 'undefined' && crypto.getRandomValues) {\r\n crypto.getRandomValues(array);\r\n } else {\r\n // Fallback for environments without crypto\r\n for (let i = 0; i < array.length; i++) {\r\n array[i] = Math.floor(Math.random() * 256);\r\n }\r\n }\r\n return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');\r\n}\r\n\r\nexport function safeJsonParse<T>(json: string, fallback: T): T {\r\n try {\r\n return JSON.parse(json) as T;\r\n } catch (error) {\r\n return fallback;\r\n }\r\n}\r\n\r\n// Browser environment detection\r\nexport const isBrowser = typeof window !== 'undefined';\r\nexport const isNode = false; // Always false in browser build\r\n\r\n// Export stubs for server-only functions to prevent import errors\r\nexport const Server = null;\r\nexport const createServer = null;\r\nexport const createDevServer = null;\r\nexport const createProductionServer = null;\r\nexport const Database = null;\r\nexport const AuthService = null;\r\nexport const ApiRouter = null;\r\nexport const requestLogger = null;\r\nexport const errorHandler = null;\r\nexport const notFoundHandler = null;\r\nexport const rateLimit = null;\r\nexport const initNodeWasm = null;\r\nexport const loadGoWasmFromFile = null;\r\n\r\nconsole.log('Baraqex - Browser version loaded');\r\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": [
|
|
3
|
+
"sources": ["../src/wasm.ts"],
|
|
4
|
+
"sourcesContent": ["/**\r\n * WebAssembly integration for Frontend Hamroun\r\n * Works in both browser and Node.js environments\r\n */\r\n\r\nexport interface GoWasmOptions {\r\n debug?: boolean;\r\n goWasmPath?: string;\r\n importObject?: any;\r\n onLoad?: (instance: GoWasmInstance) => void;\r\n}\r\n\r\nexport interface GoWasmInstance {\r\n instance: WebAssembly.Instance;\r\n module: WebAssembly.Module;\r\n exports: WebAssembly.Exports;\r\n functions: Record<string, Function>;\r\n}\r\n\r\n/**\r\n * Load Go WASM module in the browser (like your working frontend code)\r\n */\r\nexport async function loadGoWasm(\r\n wasmUrl: string,\r\n options: GoWasmOptions = {}\r\n): Promise<GoWasmInstance> {\r\n if (typeof window === 'undefined') {\r\n throw new Error('loadGoWasm() is for browser use only. Use loadGoWasmFromFile() in Node.js.');\r\n }\r\n\r\n try {\r\n // Check if Go WASM runtime is available (like your frontend code)\r\n if (!window.Go) {\r\n throw new Error('Go WASM runtime not available. Make sure wasm_exec.js is loaded.');\r\n }\r\n\r\n if (options.debug) {\r\n console.log('[WASM] Loading WASM from:', wasmUrl);\r\n }\r\n\r\n // Fetch the WASM file (exactly like your frontend code)\r\n const response = await fetch(wasmUrl);\r\n \r\n if (!response.ok) {\r\n throw new Error(`Failed to fetch WASM file: ${response.status}`);\r\n }\r\n\r\n const wasmBytes = await response.arrayBuffer();\r\n \r\n // Initialize Go runtime (exactly like your frontend code)\r\n const go = new window.Go();\r\n const wasmModule = await WebAssembly.instantiate(wasmBytes, go.importObject);\r\n \r\n // Run the Go program (exactly like your frontend code)\r\n go.run(wasmModule.instance);\r\n \r\n // Wait a bit for Go functions to be registered (like your frontend code)\r\n await new Promise(resolve => setTimeout(resolve, 100));\r\n \r\n if (options.debug) {\r\n console.log('[WASM] Go program started, checking for registered functions...');\r\n }\r\n\r\n // Extract exported functions from global scope (like your frontend code)\r\n const functions: Record<string, Function> = {};\r\n \r\n // Look for Go functions in global scope\r\n for (const key in window) {\r\n if (typeof window[key] === 'function' && key.startsWith('go')) {\r\n functions[key] = window[key] as Function;\r\n if (options.debug) {\r\n console.log(`[WASM] Found function: ${key}`);\r\n }\r\n }\r\n }\r\n\r\n const wasmInstance: GoWasmInstance = {\r\n instance: wasmModule.instance,\r\n module: wasmModule,\r\n exports: wasmModule.instance.exports,\r\n functions\r\n };\r\n\r\n if (options.onLoad) {\r\n options.onLoad(wasmInstance);\r\n }\r\n\r\n if (options.debug) {\r\n console.log(`[WASM] Module loaded successfully with ${Object.keys(functions).length} functions`);\r\n }\r\n\r\n return wasmInstance;\r\n\r\n } catch (error) {\r\n console.error('[WASM] Error loading Go WASM module:', error);\r\n throw error;\r\n }\r\n}\r\n\r\n/**\r\n * Call a Go WASM function (like your frontend code's callWasmFunction)\r\n */\r\nexport function callWasmFunction(funcName: string, ...args: any[]): any {\r\n if (typeof window === 'undefined') {\r\n throw new Error('callWasmFunction() is for browser use only.');\r\n }\r\n\r\n const func = (window as any)[funcName];\r\n if (typeof func !== 'function') {\r\n throw new Error(`Function ${funcName} not found. Make sure the WASM module is loaded.`);\r\n }\r\n \r\n return func(...args);\r\n}\r\n\r\n/**\r\n * Check if Go WASM is ready (like your frontend code's wasmReady state)\r\n */\r\nexport function isWasmReady(): boolean {\r\n if (typeof window === 'undefined') {\r\n return false;\r\n }\r\n\r\n // Check if Go runtime is available and at least one Go function exists\r\n return !!(window.Go && Object.keys(window).some(key => \r\n key.startsWith('go') && typeof window[key] === 'function'\r\n ));\r\n}\r\n\r\n/**\r\n * Get all available Go WASM functions\r\n */\r\nexport function getWasmFunctions(): string[] {\r\n if (typeof window === 'undefined') {\r\n return [];\r\n }\r\n\r\n return Object.keys(window).filter(key => \r\n key.startsWith('go') && typeof window[key] === 'function'\r\n );\r\n}\r\n\r\n/**\r\n * Hook for React components (like your frontend code's useEffect pattern)\r\n */\r\nexport function useGoWasm(wasmUrl: string, options: GoWasmOptions = {}) {\r\n if (typeof window === 'undefined') {\r\n throw new Error('useGoWasm() is for browser use only.');\r\n }\r\n\r\n // This would need to be implemented as a React hook in frontend-hamroun\r\n // For now, return the basic functionality\r\n return {\r\n loadWasm: () => loadGoWasm(wasmUrl, options),\r\n callFunction: callWasmFunction,\r\n isReady: isWasmReady,\r\n getFunctions: getWasmFunctions\r\n };\r\n}\r\n\r\n// Browser-specific type declarations\r\ndeclare global {\r\n interface Window {\r\n Go: new () => {\r\n importObject: any;\r\n run: (instance: WebAssembly.Instance) => void;\r\n };\r\n [key: string]: any;\r\n }\r\n}\r\n"],
|
|
5
|
+
"mappings": ";AAsBA,eAAsB,WACpB,SACA,UAAyB,CAAC,GACD;AACzB,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,MAAM,4EAA4E;AAAA,EAC9F;AAEA,MAAI;AAEF,QAAI,CAAC,OAAO,IAAI;AACd,YAAM,IAAI,MAAM,kEAAkE;AAAA,IACpF;AAEA,QAAI,QAAQ,OAAO;AACjB,cAAQ,IAAI,6BAA6B,OAAO;AAAA,IAClD;AAGA,UAAM,WAAW,MAAM,MAAM,OAAO;AAEpC,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,MAAM,8BAA8B,SAAS,MAAM,EAAE;AAAA,IACjE;AAEA,UAAM,YAAY,MAAM,SAAS,YAAY;AAG7C,UAAM,KAAK,IAAI,OAAO,GAAG;AACzB,UAAM,aAAa,MAAM,YAAY,YAAY,WAAW,GAAG,YAAY;AAG3E,OAAG,IAAI,WAAW,QAAQ;AAG1B,UAAM,IAAI,QAAQ,aAAW,WAAW,SAAS,GAAG,CAAC;AAErD,QAAI,QAAQ,OAAO;AACjB,cAAQ,IAAI,iEAAiE;AAAA,IAC/E;AAGA,UAAM,YAAsC,CAAC;AAG7C,eAAW,OAAO,QAAQ;AACxB,UAAI,OAAO,OAAO,GAAG,MAAM,cAAc,IAAI,WAAW,IAAI,GAAG;AAC7D,kBAAU,GAAG,IAAI,OAAO,GAAG;AAC3B,YAAI,QAAQ,OAAO;AACjB,kBAAQ,IAAI,0BAA0B,GAAG,EAAE;AAAA,QAC7C;AAAA,MACF;AAAA,IACF;AAEA,UAAM,eAA+B;AAAA,MACnC,UAAU,WAAW;AAAA,MACrB,QAAQ;AAAA,MACR,SAAS,WAAW,SAAS;AAAA,MAC7B;AAAA,IACF;AAEA,QAAI,QAAQ,QAAQ;AAClB,cAAQ,OAAO,YAAY;AAAA,IAC7B;AAEA,QAAI,QAAQ,OAAO;AACjB,cAAQ,IAAI,0CAA0C,OAAO,KAAK,SAAS,EAAE,MAAM,YAAY;AAAA,IACjG;AAEA,WAAO;AAAA,EAET,SAAS,OAAO;AACd,YAAQ,MAAM,wCAAwC,KAAK;AAC3D,UAAM;AAAA,EACR;AACF;AAKO,SAAS,iBAAiB,aAAqB,MAAkB;AACtE,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,MAAM,6CAA6C;AAAA,EAC/D;AAEA,QAAM,OAAQ,OAAe,QAAQ;AACrC,MAAI,OAAO,SAAS,YAAY;AAC9B,UAAM,IAAI,MAAM,YAAY,QAAQ,kDAAkD;AAAA,EACxF;AAEA,SAAO,KAAK,GAAG,IAAI;AACrB;AAKO,SAAS,cAAuB;AACrC,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO;AAAA,EACT;AAGA,SAAO,CAAC,EAAE,OAAO,MAAM,OAAO,KAAK,MAAM,EAAE;AAAA,IAAK,SAC9C,IAAI,WAAW,IAAI,KAAK,OAAO,OAAO,GAAG,MAAM;AAAA,EACjD;AACF;AAKO,SAAS,mBAA6B;AAC3C,MAAI,OAAO,WAAW,aAAa;AACjC,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,OAAO,KAAK,MAAM,EAAE;AAAA,IAAO,SAChC,IAAI,WAAW,IAAI,KAAK,OAAO,OAAO,GAAG,MAAM;AAAA,EACjD;AACF;AAKO,SAAS,UAAU,SAAiB,UAAyB,CAAC,GAAG;AACtE,MAAI,OAAO,WAAW,aAAa;AACjC,UAAM,IAAI,MAAM,sCAAsC;AAAA,EACxD;AAIA,SAAO;AAAA,IACL,UAAU,MAAM,WAAW,SAAS,OAAO;AAAA,IAC3C,cAAc;AAAA,IACd,SAAS;AAAA,IACT,cAAc;AAAA,EAChB;AACF;",
|
|
6
|
+
"names": []
|
|
7
7
|
}
|