baraqex 1.0.43 → 1.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/README_WASM.md +472 -0
  2. package/bin/baraqex.js +1 -1
  3. package/dist/browser.js +1 -1067
  4. package/dist/browser.js.map +4 -4
  5. package/dist/index.js +28 -1087
  6. package/dist/index.js.map +4 -4
  7. package/dist/{server/index.js → server.js} +21 -249
  8. package/dist/server.js.map +7 -0
  9. package/package.json +49 -58
  10. package/templates/ssr-template/index.html +35 -0
  11. package/templates/ssr-template/package-lock.json +2665 -446
  12. package/templates/ssr-template/package.json +20 -14
  13. package/templates/ssr-template/src/App.tsx +65 -42
  14. package/templates/ssr-template/src/client.tsx +2 -10
  15. package/templates/wasm/package-lock.json +3169 -2710
  16. package/templates/wasm/package.json +9 -12
  17. package/templates/wasm/src/App.tsx +50 -19
  18. package/templates/wasm/vite.config.ts +24 -59
  19. package/dist/api/hello.d.ts +0 -3
  20. package/dist/api/hello.d.ts.map +0 -1
  21. package/dist/api/users/[id].d.ts +0 -5
  22. package/dist/api/users/[id].d.ts.map +0 -1
  23. package/dist/browser.d.ts +0 -29
  24. package/dist/browser.d.ts.map +0 -1
  25. package/dist/browser.package.json +0 -4
  26. package/dist/frontend/components/WasmLoader.d.ts +0 -2
  27. package/dist/frontend/components/WasmLoader.d.ts.map +0 -1
  28. package/dist/frontend/hooks/useWasm.d.ts +0 -2
  29. package/dist/frontend/hooks/useWasm.d.ts.map +0 -1
  30. package/dist/frontend/index.d.ts +0 -2
  31. package/dist/frontend/index.d.ts.map +0 -1
  32. package/dist/index.d.ts +0 -34
  33. package/dist/index.d.ts.map +0 -1
  34. package/dist/renderComponent.d.ts +0 -9
  35. package/dist/renderComponent.d.ts.map +0 -1
  36. package/dist/server/api-router.d.ts +0 -16
  37. package/dist/server/api-router.d.ts.map +0 -1
  38. package/dist/server/auth.d.ts +0 -25
  39. package/dist/server/auth.d.ts.map +0 -1
  40. package/dist/server/database.d.ts +0 -22
  41. package/dist/server/database.d.ts.map +0 -1
  42. package/dist/server/index.d.ts +0 -115
  43. package/dist/server/index.d.ts.map +0 -1
  44. package/dist/server/index.js.map +0 -7
  45. package/dist/server/middleware.d.ts +0 -11
  46. package/dist/server/middleware.d.ts.map +0 -1
  47. package/dist/server/package.json +0 -4
  48. package/dist/server/templates.d.ts +0 -31
  49. package/dist/server/templates.d.ts.map +0 -1
  50. package/dist/server/types.d.ts +0 -69
  51. package/dist/server/types.d.ts.map +0 -1
  52. package/dist/server/utils.d.ts +0 -70
  53. package/dist/server/utils.d.ts.map +0 -1
  54. package/dist/server/wasm.d.ts +0 -29
  55. package/dist/server/wasm.d.ts.map +0 -1
  56. package/dist/server-renderer.d.ts +0 -5
  57. package/dist/server-renderer.d.ts.map +0 -1
  58. package/dist/wasm.d.ts +0 -51
  59. package/dist/wasm.d.ts.map +0 -1
  60. package/templates/wasm/src/index.html +0 -14
  61. package/templates/wasm/src/main.tsx +0 -5
  62. package/templates/wasm/src/wasm-loader.ts +0 -119
package/dist/browser.js CHANGED
@@ -1,897 +1,3 @@
1
- // node_modules/frontend-hamroun/dist/index.js
2
- function jsx(type, props) {
3
- console.log("JSX Transform:", { type, props });
4
- const processedProps = { ...props };
5
- if (arguments.length > 2) {
6
- processedProps.children = Array.prototype.slice.call(arguments, 2);
7
- }
8
- return { type, props: processedProps };
9
- }
10
- var Fragment = ({ children }) => children;
11
- async function createElement(vnode) {
12
- console.log("Creating element from:", vnode);
13
- if (vnode == null) {
14
- return document.createTextNode("");
15
- }
16
- if (typeof vnode === "boolean") {
17
- return document.createTextNode("");
18
- }
19
- if (typeof vnode === "number" || typeof vnode === "string") {
20
- return document.createTextNode(String(vnode));
21
- }
22
- if (Array.isArray(vnode)) {
23
- const fragment = document.createDocumentFragment();
24
- for (const child of vnode) {
25
- const node = await createElement(child);
26
- fragment.appendChild(node);
27
- }
28
- return fragment;
29
- }
30
- if ("type" in vnode && vnode.props !== void 0) {
31
- const { type, props } = vnode;
32
- if (typeof type === "function") {
33
- try {
34
- const result = await type(props || {});
35
- const node = await createElement(result);
36
- if (node instanceof Element) {
37
- node.setAttribute("data-component-id", type.name || type.toString());
38
- }
39
- return node;
40
- } catch (error) {
41
- console.error("Error rendering component:", error);
42
- return document.createTextNode("");
43
- }
44
- }
45
- const element = document.createElement(type);
46
- for (const [key, value] of Object.entries(props || {})) {
47
- if (key === "children")
48
- continue;
49
- if (key.startsWith("on") && typeof value === "function") {
50
- const eventName = key.toLowerCase().slice(2);
51
- const existingHandler = element.__events?.[eventName];
52
- if (existingHandler) {
53
- element.removeEventListener(eventName, existingHandler);
54
- }
55
- element.addEventListener(eventName, value);
56
- if (!element.__events) {
57
- element.__events = {};
58
- }
59
- element.__events[eventName] = value;
60
- } else if (key === "style" && typeof value === "object") {
61
- Object.assign(element.style, value);
62
- } else if (key === "className") {
63
- element.setAttribute("class", String(value));
64
- } else if (key !== "key" && key !== "ref") {
65
- element.setAttribute(key, String(value));
66
- }
67
- }
68
- const children = props?.children;
69
- if (children != null) {
70
- const childArray = Array.isArray(children) ? children.flat() : [children];
71
- for (const child of childArray) {
72
- const childNode = await createElement(child);
73
- element.appendChild(childNode);
74
- }
75
- }
76
- return element;
77
- }
78
- return document.createTextNode(String(vnode));
79
- }
80
- var isBatching = false;
81
- var queue = [];
82
- function batchUpdates(fn) {
83
- if (isBatching) {
84
- queue.push(fn);
85
- return;
86
- }
87
- isBatching = true;
88
- try {
89
- fn();
90
- while (queue.length > 0) {
91
- const nextFn = queue.shift();
92
- nextFn?.();
93
- }
94
- } finally {
95
- isBatching = false;
96
- }
97
- }
98
- var contexts = /* @__PURE__ */ new Map();
99
- function createContext(defaultValue) {
100
- const contextId = Symbol("context");
101
- const Provider = ({ value, children }) => {
102
- contexts.set(contextId, value);
103
- return children;
104
- };
105
- const Consumer = ({ children }) => {
106
- const value = contexts.get(contextId) ?? defaultValue;
107
- return children(value);
108
- };
109
- const context = {
110
- Provider,
111
- Consumer,
112
- displayName: "Context"
113
- };
114
- return context;
115
- }
116
- function useContext(context) {
117
- return {};
118
- }
119
- var currentRender = 0;
120
- var isSSR = false;
121
- var states = /* @__PURE__ */ new Map();
122
- var stateIndices = /* @__PURE__ */ new Map();
123
- var effects = /* @__PURE__ */ new Map();
124
- var memos = /* @__PURE__ */ new Map();
125
- var refs = /* @__PURE__ */ new Map();
126
- var globalRenderCallback = null;
127
- var globalContainer = null;
128
- var currentElement = null;
129
- function setRenderCallback(callback, element, container) {
130
- globalRenderCallback = callback;
131
- globalContainer = container;
132
- currentElement = element;
133
- }
134
- function prepareRender(component = null, isServerSideRender = false) {
135
- currentRender++;
136
- isSSR = isServerSideRender;
137
- stateIndices.set(currentRender, 0);
138
- if (!states.has(currentRender)) {
139
- states.set(currentRender, []);
140
- }
141
- return currentRender;
142
- }
143
- function finishRender() {
144
- }
145
- function useState(initial) {
146
- if (!currentRender) {
147
- throw new Error("useState must be called within a render");
148
- }
149
- if (!states.has(currentRender)) {
150
- states.set(currentRender, []);
151
- }
152
- const componentStates = states.get(currentRender);
153
- const index = stateIndices.get(currentRender) || 0;
154
- if (index >= componentStates.length) {
155
- componentStates.push(initial);
156
- }
157
- const state = componentStates[index];
158
- const setState = (newValue) => {
159
- if (isSSR) {
160
- return;
161
- }
162
- const nextValue = typeof newValue === "function" ? newValue(componentStates[index]) : newValue;
163
- if (componentStates[index] === nextValue)
164
- return;
165
- componentStates[index] = nextValue;
166
- if (isBatching) {
167
- batchUpdates(() => rerender(currentRender));
168
- } else {
169
- rerender(currentRender);
170
- }
171
- };
172
- stateIndices.set(currentRender, index + 1);
173
- return [state, setState];
174
- }
175
- function useEffect(callback, deps) {
176
- if (!currentRender)
177
- throw new Error("useEffect must be called within a render");
178
- if (isSSR) {
179
- const effectIndex2 = stateIndices.get(currentRender) || 0;
180
- stateIndices.set(currentRender, effectIndex2 + 1);
181
- return;
182
- }
183
- const effectIndex = stateIndices.get(currentRender) || 0;
184
- if (!effects.has(currentRender)) {
185
- effects.set(currentRender, []);
186
- }
187
- const componentEffects = effects.get(currentRender);
188
- const prevEffect = componentEffects[effectIndex];
189
- if (!prevEffect || !deps || !prevEffect.deps || deps.some((dep, i) => dep !== prevEffect.deps[i])) {
190
- if (prevEffect?.cleanup) {
191
- prevEffect.cleanup();
192
- }
193
- queueMicrotask(() => {
194
- const cleanup = callback() || void 0;
195
- componentEffects[effectIndex] = { cleanup, deps: deps || [] };
196
- });
197
- }
198
- stateIndices.set(currentRender, effectIndex + 1);
199
- }
200
- function useMemo(factory, deps) {
201
- if (!currentRender)
202
- throw new Error("useMemo must be called within a render");
203
- const memoIndex = stateIndices.get(currentRender) || 0;
204
- if (!memos.has(currentRender)) {
205
- memos.set(currentRender, []);
206
- }
207
- const componentMemos = memos.get(currentRender);
208
- const prevMemo = componentMemos[memoIndex];
209
- if (!prevMemo || deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i]))) {
210
- const value = factory();
211
- componentMemos[memoIndex] = { value, deps: deps || [] };
212
- stateIndices.set(currentRender, memoIndex + 1);
213
- return value;
214
- }
215
- stateIndices.set(currentRender, memoIndex + 1);
216
- return prevMemo.value;
217
- }
218
- function useRef(initial) {
219
- if (!currentRender)
220
- throw new Error("useRef must be called within a render");
221
- const refIndex = stateIndices.get(currentRender) || 0;
222
- if (!refs.has(currentRender)) {
223
- refs.set(currentRender, []);
224
- }
225
- const componentRefs = refs.get(currentRender);
226
- if (refIndex >= componentRefs.length) {
227
- const ref2 = { current: initial };
228
- componentRefs.push(ref2);
229
- stateIndices.set(currentRender, refIndex + 1);
230
- return ref2;
231
- }
232
- const ref = componentRefs[refIndex];
233
- stateIndices.set(currentRender, refIndex + 1);
234
- return ref;
235
- }
236
- async function rerender(rendererId) {
237
- try {
238
- if (isSSR) {
239
- return;
240
- }
241
- const componentEffects = effects.get(rendererId);
242
- if (componentEffects) {
243
- componentEffects.forEach((effect) => {
244
- if (effect.cleanup)
245
- effect.cleanup();
246
- });
247
- effects.set(rendererId, []);
248
- }
249
- if (globalRenderCallback && globalContainer && currentElement) {
250
- await globalRenderCallback(currentElement, globalContainer);
251
- }
252
- } catch (error) {
253
- console.error("Error during rerender:", error);
254
- }
255
- }
256
- function useErrorBoundary() {
257
- const [error, setError] = useState(null);
258
- return [error, () => setError(null)];
259
- }
260
- async function render(element, container) {
261
- try {
262
- setRenderCallback(render, element, container);
263
- const renderId = prepareRender(element);
264
- const domNode = await createElement(element);
265
- if (container instanceof Element) {
266
- container.innerHTML = "";
267
- } else {
268
- while (container.firstChild) {
269
- container.removeChild(container.firstChild);
270
- }
271
- }
272
- container.appendChild(domNode);
273
- finishRender();
274
- console.log("Render completed successfully");
275
- } catch (error) {
276
- console.error("Error during render:", error);
277
- throw error;
278
- }
279
- }
280
- async function hydrate(element, container) {
281
- try {
282
- console.log("Starting hydration...");
283
- await render(element, container);
284
- console.log("Hydration completed successfully");
285
- } catch (error) {
286
- console.error("Error during hydration:", error);
287
- throw error;
288
- }
289
- }
290
- function arePropsEqual(oldProps, newProps) {
291
- const oldKeys = Object.keys(oldProps).filter((k) => k !== "children");
292
- const newKeys = Object.keys(newProps).filter((k) => k !== "children");
293
- if (oldKeys.length !== newKeys.length)
294
- return false;
295
- return oldKeys.every((key) => oldProps[key] === newProps[key]);
296
- }
297
- function diff(oldNode, newNode) {
298
- if (oldNode == null || newNode == null)
299
- return oldNode !== newNode;
300
- if (typeof oldNode !== typeof newNode)
301
- return true;
302
- if (typeof newNode === "string" || typeof newNode === "number")
303
- return oldNode !== newNode;
304
- if (newNode.type !== oldNode.type)
305
- return true;
306
- return !arePropsEqual(oldNode.props, newNode.props);
307
- }
308
- function shouldComponentUpdate(oldProps, newProps) {
309
- return !arePropsEqual(oldProps, newProps);
310
- }
311
- var Component = class {
312
- constructor(props = {}) {
313
- this.state = {};
314
- this.element = null;
315
- this._mounted = false;
316
- this.props = props;
317
- }
318
- componentDidMount() {
319
- }
320
- async setState(newState) {
321
- const prevState = { ...this.state };
322
- this.state = { ...prevState, ...newState };
323
- console.log(`${this.constructor.name} state updated:`, {
324
- prev: prevState,
325
- next: this.state
326
- });
327
- await Promise.resolve();
328
- if (this._mounted) {
329
- await this.update();
330
- } else {
331
- await this.update();
332
- }
333
- }
334
- _replayEvents(oldElement, newElement) {
335
- const oldEvents = oldElement.__events || {};
336
- Object.entries(oldEvents).forEach(([event, handler]) => {
337
- newElement.addEventListener(event, handler);
338
- });
339
- newElement.__events = oldEvents;
340
- }
341
- _deepCloneWithEvents(node) {
342
- const clone = node.cloneNode(false);
343
- const events = node.__events || {};
344
- clone.__events = events;
345
- Object.entries(events).forEach(([event, handler]) => {
346
- clone.addEventListener(event, handler);
347
- });
348
- Array.from(node.childNodes).forEach((child) => {
349
- if (child instanceof HTMLElement) {
350
- clone.appendChild(this._deepCloneWithEvents(child));
351
- } else {
352
- clone.appendChild(child.cloneNode(true));
353
- }
354
- });
355
- return clone;
356
- }
357
- async update() {
358
- const vdom = this.render();
359
- if (!vdom)
360
- return document.createTextNode("");
361
- const rendered = await createElement(vdom);
362
- if (rendered instanceof HTMLElement) {
363
- return this._updateElement(rendered);
364
- }
365
- const wrapper = document.createElement("div");
366
- wrapper.appendChild(rendered);
367
- return this._updateElement(wrapper);
368
- }
369
- async _updateElement(rendered) {
370
- const newElement = this._deepCloneWithEvents(rendered);
371
- newElement.__instance = this;
372
- if (!this.element) {
373
- this.element = newElement;
374
- if (!this._mounted) {
375
- this._mounted = true;
376
- queueMicrotask(() => this.componentDidMount());
377
- }
378
- } else if (this.element.parentNode) {
379
- this.element.parentNode.replaceChild(newElement, this.element);
380
- this.element = newElement;
381
- }
382
- return this.element;
383
- }
384
- render() {
385
- throw new Error("Component must implement render() method");
386
- }
387
- };
388
- var RouterContext = createContext({
389
- location: {
390
- pathname: "/",
391
- search: "",
392
- hash: ""
393
- },
394
- params: {},
395
- navigate: () => {
396
- },
397
- match: () => false
398
- });
399
- function parsePath(path) {
400
- const pattern = path.replace(/\/+$/, "").replace(/^\/+/, "/").replace(/\/:([^/]+)/g, "/([^/]+)");
401
- const paramNames = [];
402
- path.replace(/\/:([^/]+)/g, (_, paramName) => {
403
- paramNames.push(paramName);
404
- return "";
405
- });
406
- return { pattern, paramNames };
407
- }
408
- function matchPath(pathname, route) {
409
- const { path, exact = false } = route;
410
- const { pattern, paramNames } = parsePath(path);
411
- const regex = new RegExp(`^${pattern}${exact ? "$" : ""}`);
412
- const match = pathname.match(regex);
413
- if (!match)
414
- return null;
415
- const params = {};
416
- paramNames.forEach((name, index) => {
417
- params[name] = match[index + 1];
418
- });
419
- return params;
420
- }
421
- function RouterProvider({ routes, children }) {
422
- const getInitialLocation = () => {
423
- if (typeof window === "undefined") {
424
- return { pathname: "/", search: "", hash: "" };
425
- }
426
- return {
427
- pathname: window.location.pathname,
428
- search: window.location.search,
429
- hash: window.location.hash
430
- };
431
- };
432
- const [location, setLocation] = useState(getInitialLocation());
433
- const [params, setParams] = useState({});
434
- useEffect(() => {
435
- for (const route of routes) {
436
- const matchedParams = matchPath(location.pathname, route);
437
- if (matchedParams) {
438
- setParams(matchedParams);
439
- break;
440
- }
441
- }
442
- }, [location, routes]);
443
- useEffect(() => {
444
- if (typeof window === "undefined")
445
- return;
446
- const handlePopState = () => {
447
- setLocation({
448
- pathname: window.location.pathname,
449
- search: window.location.search,
450
- hash: window.location.hash
451
- });
452
- };
453
- window.addEventListener("popstate", handlePopState);
454
- return () => window.removeEventListener("popstate", handlePopState);
455
- }, []);
456
- const navigate = (to, options = {}) => {
457
- if (typeof window === "undefined")
458
- return;
459
- const { replace = false, state = null } = options;
460
- if (replace) {
461
- window.history.replaceState(state, "", to);
462
- } else {
463
- window.history.pushState(state, "", to);
464
- }
465
- setLocation({
466
- pathname: window.location.pathname,
467
- search: window.location.search,
468
- hash: window.location.hash
469
- });
470
- };
471
- const match = (path) => {
472
- const { pattern } = parsePath(path);
473
- const regex = new RegExp(`^${pattern}`);
474
- return regex.test(location.pathname);
475
- };
476
- const routerValue = {
477
- location: {
478
- pathname: location.pathname,
479
- search: location.search,
480
- hash: location.hash
481
- },
482
- params,
483
- navigate,
484
- match
485
- };
486
- return jsx(RouterContext.Provider, { value: routerValue, children });
487
- }
488
- function Route({ path, component: Component2, props = {} }) {
489
- const context = useContext();
490
- const params = context.params;
491
- const locationPathname = context.location.pathname;
492
- const routeToMatch = { path, component: Component2 };
493
- const match = matchPath(locationPathname, routeToMatch);
494
- if (!match)
495
- return null;
496
- return jsx(Component2, { ...props, params });
497
- }
498
- function Switch({ children }) {
499
- const context = useContext();
500
- const locationPathname = context.location.pathname;
501
- const child = Array.isArray(children) ? children.find((child2) => {
502
- if (!child2 || typeof child2.type !== "function" || !child2.props.path)
503
- return false;
504
- const routeObj = {
505
- path: child2.props.path,
506
- component: child2.type,
507
- exact: child2.props.exact || false
508
- };
509
- return matchPath(locationPathname, routeObj);
510
- }) : children;
511
- return child || null;
512
- }
513
- function Link({ to, replace = false, state = null, className = "", activeClassName = "", children, ...rest }) {
514
- const context = useContext();
515
- const navigate = context.navigate;
516
- const match = context.match;
517
- const handleClick = (e) => {
518
- e.preventDefault();
519
- navigate(to, { replace, state });
520
- };
521
- const isActive = match(to);
522
- const classes = [
523
- className,
524
- isActive ? activeClassName : ""
525
- ].filter(Boolean).join(" ");
526
- return jsx("a", {
527
- href: to,
528
- className: classes || void 0,
529
- onClick: handleClick,
530
- ...rest,
531
- children
532
- });
533
- }
534
- function Redirect({ to, replace = true }) {
535
- const context = useContext();
536
- const navigate = context.navigate;
537
- useEffect(() => {
538
- navigate(to, { replace });
539
- }, [to]);
540
- return null;
541
- }
542
- function useLocation() {
543
- const context = useContext();
544
- return context.location;
545
- }
546
- function useParams() {
547
- const context = useContext();
548
- return context.params;
549
- }
550
- function useNavigate() {
551
- const context = useContext();
552
- return context.navigate;
553
- }
554
- function useForm(options) {
555
- const { initialValues, validate, onSubmit } = options;
556
- const [values, setValues] = useState(initialValues);
557
- const [errors, setErrors] = useState({});
558
- const [touched, setTouched] = useState({});
559
- const [dirty, setDirty] = useState({});
560
- const [isSubmitting, setIsSubmitting] = useState(false);
561
- const [submitCount, setSubmitCount] = useState(0);
562
- const isValid = Object.keys(errors).length === 0;
563
- const isDirty = Object.values(dirty).some(Boolean);
564
- useEffect(() => {
565
- if (validate) {
566
- const validationErrors = validate(values);
567
- setErrors(validationErrors || {});
568
- }
569
- }, [values, validate]);
570
- const handleChange = (e) => {
571
- const { name, value, type, checked } = e.target;
572
- const fieldValue = type === "checkbox" ? checked : value;
573
- setValues((prev) => ({
574
- ...prev,
575
- [name]: fieldValue
576
- }));
577
- setDirty((prev) => ({
578
- ...prev,
579
- [name]: true
580
- }));
581
- };
582
- const handleBlur = (e) => {
583
- const { name } = e.target;
584
- setTouched((prev) => ({
585
- ...prev,
586
- [name]: true
587
- }));
588
- };
589
- const setFieldValue = (field, value) => {
590
- setValues((prev) => ({
591
- ...prev,
592
- [field]: value
593
- }));
594
- setDirty((prev) => ({
595
- ...prev,
596
- [field]: true
597
- }));
598
- };
599
- const setFieldError = (field, error) => {
600
- setErrors((prev) => ({
601
- ...prev,
602
- [field]: error
603
- }));
604
- };
605
- const updateValues = (newValues) => {
606
- setValues((prev) => ({
607
- ...prev,
608
- ...newValues
609
- }));
610
- const dirtyFields = {};
611
- Object.keys(newValues).forEach((key) => {
612
- dirtyFields[key] = true;
613
- });
614
- setDirty((prev) => ({
615
- ...prev,
616
- ...dirtyFields
617
- }));
618
- };
619
- const resetForm = () => {
620
- setValues(initialValues);
621
- setErrors({});
622
- setTouched({});
623
- setDirty({});
624
- setIsSubmitting(false);
625
- };
626
- const handleSubmit = async (e) => {
627
- e.preventDefault();
628
- const allTouched = {};
629
- Object.keys(values).forEach((key) => {
630
- allTouched[key] = true;
631
- });
632
- setTouched(allTouched);
633
- let validationErrors = {};
634
- if (validate) {
635
- validationErrors = validate(values);
636
- setErrors(validationErrors || {});
637
- }
638
- if (Object.keys(validationErrors).length === 0 && onSubmit) {
639
- setIsSubmitting(true);
640
- setSubmitCount((count) => count + 1);
641
- try {
642
- await onSubmit(values, {
643
- fields: Object.keys(values).reduce((acc, key) => {
644
- acc[key] = {
645
- value: values[key],
646
- error: errors[key],
647
- touched: touched[key] || false,
648
- dirty: dirty[key] || false
649
- };
650
- return acc;
651
- }, {}),
652
- isValid,
653
- isDirty,
654
- isSubmitting: true,
655
- submitCount: submitCount + 1
656
- });
657
- } finally {
658
- setIsSubmitting(false);
659
- }
660
- }
661
- };
662
- return {
663
- values,
664
- errors,
665
- touched,
666
- dirty,
667
- isValid,
668
- isDirty,
669
- isSubmitting,
670
- submitCount,
671
- handleChange,
672
- handleBlur,
673
- handleSubmit,
674
- setFieldValue,
675
- setFieldError,
676
- setValues: updateValues,
677
- resetForm
678
- };
679
- }
680
- function createEventBus() {
681
- const events = /* @__PURE__ */ new Map();
682
- const onceHandlers = /* @__PURE__ */ new WeakMap();
683
- const on = (event, handler) => {
684
- if (!events.has(event)) {
685
- events.set(event, /* @__PURE__ */ new Set());
686
- }
687
- events.get(event).add(handler);
688
- return () => off(event, handler);
689
- };
690
- const once = (event, handler) => {
691
- const onceWrapper = (...args) => {
692
- off(event, onceWrapper);
693
- handler(...args);
694
- };
695
- onceHandlers.set(handler, onceWrapper);
696
- return on(event, onceWrapper);
697
- };
698
- const off = (event, handler) => {
699
- if (!handler) {
700
- events.delete(event);
701
- return;
702
- }
703
- const wrappedHandler = onceHandlers.get(handler);
704
- const handlerToRemove = wrappedHandler || handler;
705
- if (events.has(event)) {
706
- events.get(event).delete(handlerToRemove);
707
- if (events.get(event).size === 0) {
708
- events.delete(event);
709
- }
710
- }
711
- };
712
- const emit = (event, ...args) => {
713
- if (!events.has(event)) {
714
- return;
715
- }
716
- const handlers = Array.from(events.get(event));
717
- for (const handler of handlers) {
718
- handler(...args);
719
- }
720
- };
721
- const clear = (event) => {
722
- if (event) {
723
- events.delete(event);
724
- } else {
725
- events.clear();
726
- }
727
- };
728
- return { on, once, off, emit, clear };
729
- }
730
- var globalEventBus = createEventBus();
731
- function useEvent(event, handler, options = {}) {
732
- return options.once ? globalEventBus.once(event, handler) : globalEventBus.on(event, handler);
733
- }
734
- function createStore(reducer, initialState, middlewares = []) {
735
- let state = initialState;
736
- let listeners = [];
737
- let dispatch = (action) => {
738
- state = reducer(state, action);
739
- listeners.forEach((listener) => listener());
740
- return action;
741
- };
742
- if (middlewares.length > 0) {
743
- const middlewareAPI = {
744
- getState: () => state,
745
- dispatch: (action) => dispatch(action),
746
- subscribe: (listener) => subscribe(listener)
747
- };
748
- const chain = middlewares.map((middleware) => middleware(middlewareAPI));
749
- dispatch = chain.reduce((a, b) => (next) => a(b(next)))(dispatch);
750
- }
751
- function subscribe(listener) {
752
- listeners.push(listener);
753
- return function unsubscribe() {
754
- listeners = listeners.filter((l) => l !== listener);
755
- };
756
- }
757
- dispatch({ type: "@@INIT" });
758
- return {
759
- getState: () => state,
760
- dispatch,
761
- subscribe
762
- };
763
- }
764
- var StoreContext = createContext({
765
- store: {
766
- getState: () => ({}),
767
- dispatch: () => {
768
- },
769
- subscribe: () => () => {
770
- }
771
- },
772
- state: {}
773
- });
774
- function StoreProvider({ store, children }) {
775
- const [state, setState] = useState(store.getState());
776
- useEffect(() => {
777
- const unsubscribe = store.subscribe(() => {
778
- setState(store.getState());
779
- });
780
- return unsubscribe;
781
- }, [store]);
782
- return jsx(StoreContext.Provider, {
783
- value: { store, state },
784
- children
785
- });
786
- }
787
- function useSelector(selector) {
788
- const context = useContext();
789
- return selector(context.state);
790
- }
791
- function useDispatch() {
792
- const context = useContext();
793
- return context.store.dispatch;
794
- }
795
- function useStore() {
796
- const context = useContext();
797
- return context.store;
798
- }
799
- var logger = (store) => (next) => (action) => {
800
- console.group(action.type);
801
- console.log("Previous state:", store.getState());
802
- console.log("Action:", action);
803
- const result = next(action);
804
- console.log("Next state:", store.getState());
805
- console.groupEnd();
806
- return result;
807
- };
808
- var thunk = (store) => (next) => (action) => {
809
- if (typeof action === "function") {
810
- return action(store.dispatch, store.getState);
811
- }
812
- return next(action);
813
- };
814
- var LifecycleEvents;
815
- (function(LifecycleEvents2) {
816
- LifecycleEvents2["APP_INIT"] = "app:init";
817
- LifecycleEvents2["APP_MOUNTED"] = "app:mounted";
818
- LifecycleEvents2["APP_UPDATED"] = "app:updated";
819
- LifecycleEvents2["APP_ERROR"] = "app:error";
820
- LifecycleEvents2["APP_DESTROYED"] = "app:destroyed";
821
- LifecycleEvents2["COMPONENT_CREATED"] = "component:created";
822
- LifecycleEvents2["COMPONENT_MOUNTED"] = "component:mounted";
823
- LifecycleEvents2["COMPONENT_UPDATED"] = "component:updated";
824
- LifecycleEvents2["COMPONENT_ERROR"] = "component:error";
825
- LifecycleEvents2["COMPONENT_UNMOUNTED"] = "component:unmounted";
826
- LifecycleEvents2["ROUTER_BEFORE_CHANGE"] = "router:before-change";
827
- LifecycleEvents2["ROUTER_AFTER_CHANGE"] = "router:after-change";
828
- LifecycleEvents2["ROUTER_ERROR"] = "router:error";
829
- LifecycleEvents2["STORE_INITIALIZED"] = "store:initialized";
830
- LifecycleEvents2["STORE_BEFORE_ACTION"] = "store:before-action";
831
- LifecycleEvents2["STORE_AFTER_ACTION"] = "store:after-action";
832
- LifecycleEvents2["STORE_ERROR"] = "store:error";
833
- })(LifecycleEvents || (LifecycleEvents = {}));
834
- function emitAppInit(data) {
835
- globalEventBus.emit(LifecycleEvents.APP_INIT, data);
836
- }
837
- function emitAppMounted(rootElement) {
838
- globalEventBus.emit(LifecycleEvents.APP_MOUNTED, rootElement);
839
- }
840
- function emitAppUpdated() {
841
- globalEventBus.emit(LifecycleEvents.APP_UPDATED);
842
- }
843
- function emitAppError(error) {
844
- globalEventBus.emit(LifecycleEvents.APP_ERROR, error);
845
- }
846
- function emitAppDestroyed() {
847
- globalEventBus.emit(LifecycleEvents.APP_DESTROYED);
848
- }
849
- function emitComponentCreated(info) {
850
- globalEventBus.emit(LifecycleEvents.COMPONENT_CREATED, info);
851
- }
852
- function emitComponentMounted(info, element) {
853
- globalEventBus.emit(LifecycleEvents.COMPONENT_MOUNTED, info, element);
854
- }
855
- function emitComponentUpdated(info, prevProps, newProps) {
856
- globalEventBus.emit(LifecycleEvents.COMPONENT_UPDATED, info, prevProps, newProps);
857
- }
858
- function emitComponentError(info, error) {
859
- globalEventBus.emit(LifecycleEvents.COMPONENT_ERROR, info, error);
860
- }
861
- function emitComponentUnmounted(info) {
862
- globalEventBus.emit(LifecycleEvents.COMPONENT_UNMOUNTED, info);
863
- }
864
- function onAppInit(handler) {
865
- return globalEventBus.on(LifecycleEvents.APP_INIT, handler);
866
- }
867
- function onAppMounted(handler) {
868
- return globalEventBus.on(LifecycleEvents.APP_MOUNTED, handler);
869
- }
870
- function onAppUpdated(handler) {
871
- return globalEventBus.on(LifecycleEvents.APP_UPDATED, handler);
872
- }
873
- function onAppError(handler) {
874
- return globalEventBus.on(LifecycleEvents.APP_ERROR, handler);
875
- }
876
- function onAppDestroyed(handler) {
877
- return globalEventBus.on(LifecycleEvents.APP_DESTROYED, handler);
878
- }
879
- function onComponentCreated(handler) {
880
- return globalEventBus.on(LifecycleEvents.COMPONENT_CREATED, handler);
881
- }
882
- function onComponentMounted(handler) {
883
- return globalEventBus.on(LifecycleEvents.COMPONENT_MOUNTED, handler);
884
- }
885
- function onComponentUpdated(handler) {
886
- return globalEventBus.on(LifecycleEvents.COMPONENT_UPDATED, handler);
887
- }
888
- function onComponentError(handler) {
889
- return globalEventBus.on(LifecycleEvents.COMPONENT_ERROR, handler);
890
- }
891
- function onComponentUnmounted(handler) {
892
- return globalEventBus.on(LifecycleEvents.COMPONENT_UNMOUNTED, handler);
893
- }
894
-
895
1
  // src/wasm.ts
896
2
  async function loadGoWasm(wasmUrl, options = {}) {
897
3
  if (typeof window === "undefined") {
@@ -980,183 +86,11 @@ function useGoWasm(wasmUrl, options = {}) {
980
86
  getFunctions: getWasmFunctions
981
87
  };
982
88
  }
983
-
984
- // src/browser.ts
985
- function generateDocument(content, options = {}) {
986
- const { title = "App", description = "", styles = [], scripts = [] } = options;
987
- return `<!DOCTYPE html>
988
- <html lang="en">
989
- <head>
990
- <meta charset="UTF-8">
991
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
992
- <title>${escapeHtml(title)}</title>
993
- ${description ? `<meta name="description" content="${escapeHtml(description)}">` : ""}
994
- ${styles.map((href) => `<link rel="stylesheet" href="${escapeHtml(href)}">`).join("\n ")}
995
- </head>
996
- <body>
997
- <div id="app-root">${content}</div>
998
- ${scripts.map((src) => `<script src="${escapeHtml(src)}" defer><\/script>`).join("\n ")}
999
- </body>
1000
- </html>`;
1001
- }
1002
- function generateErrorPage(statusCode, message) {
1003
- return generateDocument(`
1004
- <div style="text-align: center; padding: 2rem;">
1005
- <h1>${statusCode}</h1>
1006
- <p>${escapeHtml(message)}</p>
1007
- <a href="/">Back to Home</a>
1008
- </div>
1009
- `, { title: `Error ${statusCode}` });
1010
- }
1011
- function generateLoadingPage(message = "Loading...") {
1012
- return generateDocument(`
1013
- <div style="text-align: center; padding: 2rem;">
1014
- <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>
1015
- <p>${escapeHtml(message)}</p>
1016
- <style>
1017
- @keyframes spin {
1018
- 0% { transform: rotate(0deg); }
1019
- 100% { transform: rotate(360deg); }
1020
- }
1021
- </style>
1022
- </div>
1023
- `, { title: "Loading" });
1024
- }
1025
- function escapeHtml(text) {
1026
- return String(text).replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
1027
- }
1028
- function renderToString(content) {
1029
- if (typeof content === "string") {
1030
- return content;
1031
- }
1032
- if (typeof content === "function") {
1033
- try {
1034
- const result = content();
1035
- return String(result);
1036
- } catch (error) {
1037
- return `<!-- Error rendering: ${error} -->`;
1038
- }
1039
- }
1040
- return String(content);
1041
- }
1042
- function generateToken(length = 32) {
1043
- const array = new Uint8Array(length);
1044
- if (typeof crypto !== "undefined" && crypto.getRandomValues) {
1045
- crypto.getRandomValues(array);
1046
- } else {
1047
- for (let i = 0; i < array.length; i++) {
1048
- array[i] = Math.floor(Math.random() * 256);
1049
- }
1050
- }
1051
- return Array.from(array, (byte) => byte.toString(16).padStart(2, "0")).join("");
1052
- }
1053
- function safeJsonParse(json, fallback) {
1054
- try {
1055
- return JSON.parse(json);
1056
- } catch (error) {
1057
- return fallback;
1058
- }
1059
- }
1060
- var isBrowser = typeof window !== "undefined";
1061
- var isNode = false;
1062
- var Server = null;
1063
- var createServer = null;
1064
- var createDevServer = null;
1065
- var createProductionServer = null;
1066
- var Database = null;
1067
- var AuthService = null;
1068
- var ApiRouter = null;
1069
- var requestLogger = null;
1070
- var errorHandler = null;
1071
- var notFoundHandler = null;
1072
- var rateLimit = null;
1073
- var initNodeWasm = null;
1074
- var loadGoWasmFromFile = null;
1075
- console.log("Baraqex - Browser version loaded");
1076
89
  export {
1077
- ApiRouter,
1078
- AuthService,
1079
- Component,
1080
- Database,
1081
- Fragment,
1082
- LifecycleEvents,
1083
- Link,
1084
- Redirect,
1085
- Route,
1086
- RouterProvider,
1087
- Server,
1088
- StoreProvider,
1089
- Switch,
1090
- batchUpdates,
1091
90
  callWasmFunction,
1092
- createContext,
1093
- createDevServer,
1094
- createElement,
1095
- createEventBus,
1096
- createProductionServer,
1097
- createServer,
1098
- createStore,
1099
- diff,
1100
- emitAppDestroyed,
1101
- emitAppError,
1102
- emitAppInit,
1103
- emitAppMounted,
1104
- emitAppUpdated,
1105
- emitComponentCreated,
1106
- emitComponentError,
1107
- emitComponentMounted,
1108
- emitComponentUnmounted,
1109
- emitComponentUpdated,
1110
- errorHandler,
1111
- globalEventBus as eventBus,
1112
- generateDocument,
1113
- generateErrorPage,
1114
- generateLoadingPage,
1115
- generateToken,
1116
91
  getWasmFunctions,
1117
- hydrate,
1118
- initNodeWasm,
1119
- isBrowser,
1120
- isNode,
1121
92
  isWasmReady,
1122
- jsx,
1123
- jsx as jsxDEV,
1124
- jsx as jsxs,
1125
93
  loadGoWasm,
1126
- loadGoWasmFromFile,
1127
- logger,
1128
- notFoundHandler,
1129
- onAppDestroyed,
1130
- onAppError,
1131
- onAppInit,
1132
- onAppMounted,
1133
- onAppUpdated,
1134
- onComponentCreated,
1135
- onComponentError,
1136
- onComponentMounted,
1137
- onComponentUnmounted,
1138
- onComponentUpdated,
1139
- rateLimit,
1140
- render,
1141
- renderToString,
1142
- requestLogger,
1143
- safeJsonParse,
1144
- shouldComponentUpdate,
1145
- thunk,
1146
- useContext,
1147
- useDispatch,
1148
- useEffect,
1149
- useErrorBoundary,
1150
- useEvent,
1151
- useForm,
1152
- useGoWasm,
1153
- useLocation,
1154
- useMemo,
1155
- useNavigate,
1156
- useParams,
1157
- useRef,
1158
- useSelector,
1159
- useState,
1160
- useStore
94
+ useGoWasm
1161
95
  };
1162
96
  //# sourceMappingURL=browser.js.map