baraqex 1.0.38 → 1.0.39

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/dist/browser.js CHANGED
@@ -1,4 +1,82 @@
1
- // node_modules/frontend-hamroun/dist/index.mjs
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
+ }
2
80
  var isBatching = false;
3
81
  var queue = [];
4
82
  function batchUpdates(fn) {
@@ -11,12 +89,33 @@ function batchUpdates(fn) {
11
89
  fn();
12
90
  while (queue.length > 0) {
13
91
  const nextFn = queue.shift();
14
- nextFn == null ? void 0 : nextFn();
92
+ nextFn?.();
15
93
  }
16
94
  } finally {
17
95
  isBatching = false;
18
96
  }
19
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
+ }
20
119
  var currentRender = 0;
21
120
  var states = /* @__PURE__ */ new Map();
22
121
  var stateIndices = /* @__PURE__ */ new Map();
@@ -26,48 +125,28 @@ var refs = /* @__PURE__ */ new Map();
26
125
  var globalRenderCallback = null;
27
126
  var globalContainer = null;
28
127
  var currentElement = null;
29
- var isServer = typeof window === "undefined";
30
- var serverStates = /* @__PURE__ */ new Map();
31
128
  function setRenderCallback(callback, element, container) {
32
129
  globalRenderCallback = callback;
33
130
  globalContainer = container;
34
131
  currentElement = element;
35
132
  }
36
- function prepareRender() {
133
+ function prepareRender(component = null) {
37
134
  currentRender++;
38
135
  stateIndices.set(currentRender, 0);
39
136
  return currentRender;
40
137
  }
41
138
  function finishRender() {
42
- if (isServer) {
43
- serverStates.delete(currentRender);
44
- }
45
139
  currentRender = 0;
46
140
  }
47
141
  function useState(initial) {
48
142
  if (!currentRender) {
49
143
  throw new Error("useState must be called within a render");
50
144
  }
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
145
  if (!states.has(currentRender)) {
67
146
  states.set(currentRender, []);
68
147
  }
69
148
  const componentStates = states.get(currentRender);
70
- const index = stateIndices.get(currentRender);
149
+ const index = stateIndices.get(currentRender) || 0;
71
150
  if (index >= componentStates.length) {
72
151
  componentStates.push(initial);
73
152
  }
@@ -89,19 +168,19 @@ function useState(initial) {
89
168
  function useEffect(callback, deps) {
90
169
  if (!currentRender)
91
170
  throw new Error("useEffect must be called within a render");
92
- const effectIndex = stateIndices.get(currentRender);
171
+ const effectIndex = stateIndices.get(currentRender) || 0;
93
172
  if (!effects.has(currentRender)) {
94
173
  effects.set(currentRender, []);
95
174
  }
96
175
  const componentEffects = effects.get(currentRender);
97
176
  const prevEffect = componentEffects[effectIndex];
98
177
  if (!prevEffect || !deps || !prevEffect.deps || deps.some((dep, i) => dep !== prevEffect.deps[i])) {
99
- if (prevEffect == null ? void 0 : prevEffect.cleanup) {
178
+ if (prevEffect?.cleanup) {
100
179
  prevEffect.cleanup();
101
180
  }
102
181
  queueMicrotask(() => {
103
182
  const cleanup = callback() || void 0;
104
- componentEffects[effectIndex] = { cleanup, deps };
183
+ componentEffects[effectIndex] = { cleanup, deps: deps || [] };
105
184
  });
106
185
  }
107
186
  stateIndices.set(currentRender, effectIndex + 1);
@@ -109,7 +188,7 @@ function useEffect(callback, deps) {
109
188
  function useMemo(factory, deps) {
110
189
  if (!currentRender)
111
190
  throw new Error("useMemo must be called within a render");
112
- const memoIndex = stateIndices.get(currentRender);
191
+ const memoIndex = stateIndices.get(currentRender) || 0;
113
192
  if (!memos.has(currentRender)) {
114
193
  memos.set(currentRender, []);
115
194
  }
@@ -117,7 +196,7 @@ function useMemo(factory, deps) {
117
196
  const prevMemo = componentMemos[memoIndex];
118
197
  if (!prevMemo || deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i]))) {
119
198
  const value = factory();
120
- componentMemos[memoIndex] = { value, deps };
199
+ componentMemos[memoIndex] = { value, deps: deps || [] };
121
200
  stateIndices.set(currentRender, memoIndex + 1);
122
201
  return value;
123
202
  }
@@ -127,7 +206,7 @@ function useMemo(factory, deps) {
127
206
  function useRef(initial) {
128
207
  if (!currentRender)
129
208
  throw new Error("useRef must be called within a render");
130
- const refIndex = stateIndices.get(currentRender);
209
+ const refIndex = stateIndices.get(currentRender) || 0;
131
210
  if (!refs.has(currentRender)) {
132
211
  refs.set(currentRender, []);
133
212
  }
@@ -163,133 +242,641 @@ function useErrorBoundary() {
163
242
  const [error, setError] = useState(null);
164
243
  return [error, () => setError(null)];
165
244
  }
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);
245
+ async function render(element, container) {
246
+ try {
247
+ setRenderCallback(render, element, container);
248
+ const renderId = prepareRender(element);
249
+ const domNode = await createElement(element);
250
+ if (container instanceof Element) {
251
+ container.innerHTML = "";
252
+ } else {
253
+ while (container.firstChild) {
254
+ container.removeChild(container.firstChild);
255
+ }
177
256
  }
178
- };
179
- return context;
180
- }
181
- function useContext(context) {
182
- return context;
257
+ container.appendChild(domNode);
258
+ finishRender();
259
+ console.log("Render completed successfully");
260
+ } catch (error) {
261
+ console.error("Error during render:", error);
262
+ finishRender();
263
+ throw error;
264
+ }
183
265
  }
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);
266
+ async function hydrate(element, container) {
267
+ try {
268
+ console.log("Starting hydration...");
269
+ await render(element, container);
270
+ console.log("Hydration completed successfully");
271
+ } catch (error) {
272
+ console.error("Error during hydration:", error);
273
+ throw error;
189
274
  }
190
- return { type, props: processedProps };
191
275
  }
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("");
276
+ function arePropsEqual(oldProps, newProps) {
277
+ const oldKeys = Object.keys(oldProps).filter((k) => k !== "children");
278
+ const newKeys = Object.keys(newProps).filter((k) => k !== "children");
279
+ if (oldKeys.length !== newKeys.length)
280
+ return false;
281
+ return oldKeys.every((key) => oldProps[key] === newProps[key]);
282
+ }
283
+ function diff(oldNode, newNode) {
284
+ if (oldNode == null || newNode == null)
285
+ return oldNode !== newNode;
286
+ if (typeof oldNode !== typeof newNode)
287
+ return true;
288
+ if (typeof newNode === "string" || typeof newNode === "number")
289
+ return oldNode !== newNode;
290
+ if (newNode.type !== oldNode.type)
291
+ return true;
292
+ return !arePropsEqual(oldNode.props, newNode.props);
293
+ }
294
+ function shouldComponentUpdate(oldProps, newProps) {
295
+ return !arePropsEqual(oldProps, newProps);
296
+ }
297
+ var Component = class {
298
+ constructor(props = {}) {
299
+ this.state = {};
300
+ this.element = null;
301
+ this._mounted = false;
302
+ this.props = props;
198
303
  }
199
- if (typeof vnode === "boolean") {
200
- return document.createTextNode("");
304
+ componentDidMount() {
201
305
  }
202
- if (typeof vnode === "number" || typeof vnode === "string") {
203
- return document.createTextNode(String(vnode));
306
+ async setState(newState) {
307
+ const prevState = { ...this.state };
308
+ this.state = { ...prevState, ...newState };
309
+ console.log(`${this.constructor.name} state updated:`, {
310
+ prev: prevState,
311
+ next: this.state
312
+ });
313
+ await Promise.resolve();
314
+ if (this._mounted) {
315
+ await this.update();
316
+ } else {
317
+ await this.update();
318
+ }
204
319
  }
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);
320
+ _replayEvents(oldElement, newElement) {
321
+ const oldEvents = oldElement.__events || {};
322
+ Object.entries(oldEvents).forEach(([event, handler]) => {
323
+ newElement.addEventListener(event, handler);
324
+ });
325
+ newElement.__events = oldEvents;
326
+ }
327
+ _deepCloneWithEvents(node) {
328
+ const clone = node.cloneNode(false);
329
+ const events = node.__events || {};
330
+ clone.__events = events;
331
+ Object.entries(events).forEach(([event, handler]) => {
332
+ clone.addEventListener(event, handler);
333
+ });
334
+ Array.from(node.childNodes).forEach((child) => {
335
+ if (child instanceof HTMLElement) {
336
+ clone.appendChild(this._deepCloneWithEvents(child));
337
+ } else {
338
+ clone.appendChild(child.cloneNode(true));
339
+ }
340
+ });
341
+ return clone;
342
+ }
343
+ async update() {
344
+ const vdom = this.render();
345
+ if (!vdom)
346
+ return document.createTextNode("");
347
+ const rendered = await createElement(vdom);
348
+ if (rendered instanceof HTMLElement) {
349
+ return this._updateElement(rendered);
210
350
  }
211
- return fragment;
351
+ const wrapper = document.createElement("div");
352
+ wrapper.appendChild(rendered);
353
+ return this._updateElement(wrapper);
212
354
  }
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("");
355
+ async _updateElement(rendered) {
356
+ const newElement = this._deepCloneWithEvents(rendered);
357
+ newElement.__instance = this;
358
+ if (!this.element) {
359
+ this.element = newElement;
360
+ if (!this._mounted) {
361
+ this._mounted = true;
362
+ queueMicrotask(() => this.componentDidMount());
226
363
  }
364
+ } else if (this.element.parentNode) {
365
+ this.element.parentNode.replaceChild(newElement, this.element);
366
+ this.element = newElement;
227
367
  }
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));
368
+ return this.element;
369
+ }
370
+ render() {
371
+ throw new Error("Component must implement render() method");
372
+ }
373
+ };
374
+ var RouterContext = createContext({
375
+ location: {
376
+ pathname: "/",
377
+ search: "",
378
+ hash: ""
379
+ },
380
+ params: {},
381
+ navigate: () => {
382
+ },
383
+ match: () => false
384
+ });
385
+ function parsePath(path) {
386
+ const pattern = path.replace(/\/+$/, "").replace(/^\/+/, "/").replace(/\/:([^/]+)/g, "/([^/]+)");
387
+ const paramNames = [];
388
+ path.replace(/\/:([^/]+)/g, (_, paramName) => {
389
+ paramNames.push(paramName);
390
+ return "";
391
+ });
392
+ return { pattern, paramNames };
393
+ }
394
+ function matchPath(pathname, route) {
395
+ const { path, exact = false } = route;
396
+ const { pattern, paramNames } = parsePath(path);
397
+ const regex = new RegExp(`^${pattern}${exact ? "$" : ""}`);
398
+ const match = pathname.match(regex);
399
+ if (!match)
400
+ return null;
401
+ const params = {};
402
+ paramNames.forEach((name, index) => {
403
+ params[name] = match[index + 1];
404
+ });
405
+ return params;
406
+ }
407
+ function RouterProvider({ routes, children }) {
408
+ const getInitialLocation = () => {
409
+ if (typeof window === "undefined") {
410
+ return { pathname: "/", search: "", hash: "" };
411
+ }
412
+ return {
413
+ pathname: window.location.pathname,
414
+ search: window.location.search,
415
+ hash: window.location.hash
416
+ };
417
+ };
418
+ const [location, setLocation] = useState(getInitialLocation());
419
+ const [params, setParams] = useState({});
420
+ useEffect(() => {
421
+ for (const route of routes) {
422
+ const matchedParams = matchPath(location.pathname, route);
423
+ if (matchedParams) {
424
+ setParams(matchedParams);
425
+ break;
249
426
  }
250
427
  }
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);
428
+ }, [location, routes]);
429
+ useEffect(() => {
430
+ if (typeof window === "undefined")
431
+ return;
432
+ const handlePopState = () => {
433
+ setLocation({
434
+ pathname: window.location.pathname,
435
+ search: window.location.search,
436
+ hash: window.location.hash
437
+ });
438
+ };
439
+ window.addEventListener("popstate", handlePopState);
440
+ return () => window.removeEventListener("popstate", handlePopState);
441
+ }, []);
442
+ const navigate = (to, options = {}) => {
443
+ if (typeof window === "undefined")
444
+ return;
445
+ const { replace = false, state = null } = options;
446
+ if (replace) {
447
+ window.history.replaceState(state, "", to);
448
+ } else {
449
+ window.history.pushState(state, "", to);
450
+ }
451
+ setLocation({
452
+ pathname: window.location.pathname,
453
+ search: window.location.search,
454
+ hash: window.location.hash
455
+ });
456
+ };
457
+ const match = (path) => {
458
+ const { pattern } = parsePath(path);
459
+ const regex = new RegExp(`^${pattern}`);
460
+ return regex.test(location.pathname);
461
+ };
462
+ const routerValue = {
463
+ location: {
464
+ pathname: location.pathname,
465
+ search: location.search,
466
+ hash: location.hash
467
+ },
468
+ params,
469
+ navigate,
470
+ match
471
+ };
472
+ return jsx(RouterContext.Provider, { value: routerValue, children });
473
+ }
474
+ function Route({ path, component: Component2, props = {} }) {
475
+ const context = useContext();
476
+ const params = context.params;
477
+ const locationPathname = context.location.pathname;
478
+ const routeToMatch = { path, component: Component2 };
479
+ const match = matchPath(locationPathname, routeToMatch);
480
+ if (!match)
481
+ return null;
482
+ return jsx(Component2, { ...props, params });
483
+ }
484
+ function Switch({ children }) {
485
+ const context = useContext();
486
+ const locationPathname = context.location.pathname;
487
+ const child = Array.isArray(children) ? children.find((child2) => {
488
+ if (!child2 || typeof child2.type !== "function" || !child2.props.path)
489
+ return false;
490
+ const routeObj = {
491
+ path: child2.props.path,
492
+ component: child2.type,
493
+ exact: child2.props.exact || false
494
+ };
495
+ return matchPath(locationPathname, routeObj);
496
+ }) : children;
497
+ return child || null;
498
+ }
499
+ function Link({ to, replace = false, state = null, className = "", activeClassName = "", children, ...rest }) {
500
+ const context = useContext();
501
+ const navigate = context.navigate;
502
+ const match = context.match;
503
+ const handleClick = (e) => {
504
+ e.preventDefault();
505
+ navigate(to, { replace, state });
506
+ };
507
+ const isActive = match(to);
508
+ const classes = [
509
+ className,
510
+ isActive ? activeClassName : ""
511
+ ].filter(Boolean).join(" ");
512
+ return jsx("a", {
513
+ href: to,
514
+ className: classes || void 0,
515
+ onClick: handleClick,
516
+ ...rest,
517
+ children
518
+ });
519
+ }
520
+ function Redirect({ to, replace = true }) {
521
+ const context = useContext();
522
+ const navigate = context.navigate;
523
+ useEffect(() => {
524
+ navigate(to, { replace });
525
+ }, [to]);
526
+ return null;
527
+ }
528
+ function useLocation() {
529
+ const context = useContext();
530
+ return context.location;
531
+ }
532
+ function useParams() {
533
+ const context = useContext();
534
+ return context.params;
535
+ }
536
+ function useNavigate() {
537
+ const context = useContext();
538
+ return context.navigate;
539
+ }
540
+ function useForm(options) {
541
+ const { initialValues, validate, onSubmit } = options;
542
+ const [values, setValues] = useState(initialValues);
543
+ const [errors, setErrors] = useState({});
544
+ const [touched, setTouched] = useState({});
545
+ const [dirty, setDirty] = useState({});
546
+ const [isSubmitting, setIsSubmitting] = useState(false);
547
+ const [submitCount, setSubmitCount] = useState(0);
548
+ const isValid = Object.keys(errors).length === 0;
549
+ const isDirty = Object.values(dirty).some(Boolean);
550
+ useEffect(() => {
551
+ if (validate) {
552
+ const validationErrors = validate(values);
553
+ setErrors(validationErrors || {});
554
+ }
555
+ }, [values, validate]);
556
+ const handleChange = (e) => {
557
+ const { name, value, type, checked } = e.target;
558
+ const fieldValue = type === "checkbox" ? checked : value;
559
+ setValues((prev) => ({
560
+ ...prev,
561
+ [name]: fieldValue
562
+ }));
563
+ setDirty((prev) => ({
564
+ ...prev,
565
+ [name]: true
566
+ }));
567
+ };
568
+ const handleBlur = (e) => {
569
+ const { name } = e.target;
570
+ setTouched((prev) => ({
571
+ ...prev,
572
+ [name]: true
573
+ }));
574
+ };
575
+ const setFieldValue = (field, value) => {
576
+ setValues((prev) => ({
577
+ ...prev,
578
+ [field]: value
579
+ }));
580
+ setDirty((prev) => ({
581
+ ...prev,
582
+ [field]: true
583
+ }));
584
+ };
585
+ const setFieldError = (field, error) => {
586
+ setErrors((prev) => ({
587
+ ...prev,
588
+ [field]: error
589
+ }));
590
+ };
591
+ const updateValues = (newValues) => {
592
+ setValues((prev) => ({
593
+ ...prev,
594
+ ...newValues
595
+ }));
596
+ const dirtyFields = {};
597
+ Object.keys(newValues).forEach((key) => {
598
+ dirtyFields[key] = true;
599
+ });
600
+ setDirty((prev) => ({
601
+ ...prev,
602
+ ...dirtyFields
603
+ }));
604
+ };
605
+ const resetForm = () => {
606
+ setValues(initialValues);
607
+ setErrors({});
608
+ setTouched({});
609
+ setDirty({});
610
+ setIsSubmitting(false);
611
+ };
612
+ const handleSubmit = async (e) => {
613
+ e.preventDefault();
614
+ const allTouched = {};
615
+ Object.keys(values).forEach((key) => {
616
+ allTouched[key] = true;
617
+ });
618
+ setTouched(allTouched);
619
+ let validationErrors = {};
620
+ if (validate) {
621
+ validationErrors = validate(values);
622
+ setErrors(validationErrors || {});
623
+ }
624
+ if (Object.keys(validationErrors).length === 0 && onSubmit) {
625
+ setIsSubmitting(true);
626
+ setSubmitCount((count) => count + 1);
627
+ try {
628
+ await onSubmit(values, {
629
+ fields: Object.keys(values).reduce((acc, key) => {
630
+ acc[key] = {
631
+ value: values[key],
632
+ error: errors[key],
633
+ touched: touched[key] || false,
634
+ dirty: dirty[key] || false
635
+ };
636
+ return acc;
637
+ }, {}),
638
+ isValid,
639
+ isDirty,
640
+ isSubmitting: true,
641
+ submitCount: submitCount + 1
642
+ });
643
+ } finally {
644
+ setIsSubmitting(false);
257
645
  }
258
646
  }
259
- return element;
260
- }
261
- return document.createTextNode(String(vnode));
647
+ };
648
+ return {
649
+ values,
650
+ errors,
651
+ touched,
652
+ dirty,
653
+ isValid,
654
+ isDirty,
655
+ isSubmitting,
656
+ submitCount,
657
+ handleChange,
658
+ handleBlur,
659
+ handleSubmit,
660
+ setFieldValue,
661
+ setFieldError,
662
+ setValues: updateValues,
663
+ resetForm
664
+ };
262
665
  }
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;
666
+ function createEventBus() {
667
+ const events = /* @__PURE__ */ new Map();
668
+ const onceHandlers = /* @__PURE__ */ new WeakMap();
669
+ const on = (event, handler) => {
670
+ if (!events.has(event)) {
671
+ events.set(event, /* @__PURE__ */ new Set());
672
+ }
673
+ events.get(event).add(handler);
674
+ return () => off(event, handler);
675
+ };
676
+ const once = (event, handler) => {
677
+ const onceWrapper = (...args) => {
678
+ off(event, onceWrapper);
679
+ handler(...args);
680
+ };
681
+ onceHandlers.set(handler, onceWrapper);
682
+ return on(event, onceWrapper);
683
+ };
684
+ const off = (event, handler) => {
685
+ if (!handler) {
686
+ events.delete(event);
687
+ return;
688
+ }
689
+ const wrappedHandler = onceHandlers.get(handler);
690
+ const handlerToRemove = wrappedHandler || handler;
691
+ if (events.has(event)) {
692
+ events.get(event).delete(handlerToRemove);
693
+ if (events.get(event).size === 0) {
694
+ events.delete(event);
695
+ }
696
+ }
697
+ };
698
+ const emit = (event, ...args) => {
699
+ if (!events.has(event)) {
700
+ return;
701
+ }
702
+ const handlers = Array.from(events.get(event));
703
+ for (const handler of handlers) {
704
+ handler(...args);
705
+ }
706
+ };
707
+ const clear = (event) => {
708
+ if (event) {
709
+ events.delete(event);
710
+ } else {
711
+ events.clear();
712
+ }
713
+ };
714
+ return { on, once, off, emit, clear };
715
+ }
716
+ var globalEventBus = createEventBus();
717
+ function useEvent(event, handler, options = {}) {
718
+ return options.once ? globalEventBus.once(event, handler) : globalEventBus.on(event, handler);
719
+ }
720
+ function createStore(reducer, initialState, middlewares = []) {
721
+ let state = initialState;
722
+ let listeners = [];
723
+ let dispatch = (action) => {
724
+ state = reducer(state, action);
725
+ listeners.forEach((listener) => listener());
726
+ return action;
727
+ };
728
+ if (middlewares.length > 0) {
729
+ const middlewareAPI = {
730
+ getState: () => state,
731
+ dispatch: (action) => dispatch(action),
732
+ subscribe: (listener) => subscribe(listener)
733
+ };
734
+ const chain = middlewares.map((middleware) => middleware(middlewareAPI));
735
+ dispatch = chain.reduce((a, b) => (next) => a(b(next)))(dispatch);
736
+ }
737
+ function subscribe(listener) {
738
+ listeners.push(listener);
739
+ return function unsubscribe() {
740
+ listeners = listeners.filter((l) => l !== listener);
741
+ };
270
742
  }
743
+ dispatch({ type: "@@INIT" });
744
+ return {
745
+ getState: () => state,
746
+ dispatch,
747
+ subscribe
748
+ };
271
749
  }
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();
750
+ var StoreContext = createContext({
751
+ store: {
752
+ getState: () => ({}),
753
+ dispatch: () => {
754
+ },
755
+ subscribe: () => () => {
285
756
  }
757
+ },
758
+ state: {}
759
+ });
760
+ function StoreProvider({ store, children }) {
761
+ const [state, setState] = useState(store.getState());
762
+ useEffect(() => {
763
+ const unsubscribe = store.subscribe(() => {
764
+ setState(store.getState());
765
+ });
766
+ return unsubscribe;
767
+ }, [store]);
768
+ return jsx(StoreContext.Provider, {
769
+ value: { store, state },
770
+ children
286
771
  });
287
772
  }
288
- var server = {
289
- async getServer() {
290
- throw new Error("Server module can only be used in Node.js environment");
773
+ function useSelector(selector) {
774
+ const context = useContext();
775
+ return selector(context.state);
776
+ }
777
+ function useDispatch() {
778
+ const context = useContext();
779
+ return context.store.dispatch;
780
+ }
781
+ function useStore() {
782
+ const context = useContext();
783
+ return context.store;
784
+ }
785
+ var logger = (store) => (next) => (action) => {
786
+ console.group(action.type);
787
+ console.log("Previous state:", store.getState());
788
+ console.log("Action:", action);
789
+ const result = next(action);
790
+ console.log("Next state:", store.getState());
791
+ console.groupEnd();
792
+ return result;
793
+ };
794
+ var thunk = (store) => (next) => (action) => {
795
+ if (typeof action === "function") {
796
+ return action(store.dispatch, store.getState);
291
797
  }
798
+ return next(action);
292
799
  };
800
+ var LifecycleEvents;
801
+ (function(LifecycleEvents2) {
802
+ LifecycleEvents2["APP_INIT"] = "app:init";
803
+ LifecycleEvents2["APP_MOUNTED"] = "app:mounted";
804
+ LifecycleEvents2["APP_UPDATED"] = "app:updated";
805
+ LifecycleEvents2["APP_ERROR"] = "app:error";
806
+ LifecycleEvents2["APP_DESTROYED"] = "app:destroyed";
807
+ LifecycleEvents2["COMPONENT_CREATED"] = "component:created";
808
+ LifecycleEvents2["COMPONENT_MOUNTED"] = "component:mounted";
809
+ LifecycleEvents2["COMPONENT_UPDATED"] = "component:updated";
810
+ LifecycleEvents2["COMPONENT_ERROR"] = "component:error";
811
+ LifecycleEvents2["COMPONENT_UNMOUNTED"] = "component:unmounted";
812
+ LifecycleEvents2["ROUTER_BEFORE_CHANGE"] = "router:before-change";
813
+ LifecycleEvents2["ROUTER_AFTER_CHANGE"] = "router:after-change";
814
+ LifecycleEvents2["ROUTER_ERROR"] = "router:error";
815
+ LifecycleEvents2["STORE_INITIALIZED"] = "store:initialized";
816
+ LifecycleEvents2["STORE_BEFORE_ACTION"] = "store:before-action";
817
+ LifecycleEvents2["STORE_AFTER_ACTION"] = "store:after-action";
818
+ LifecycleEvents2["STORE_ERROR"] = "store:error";
819
+ })(LifecycleEvents || (LifecycleEvents = {}));
820
+ function emitAppInit(data) {
821
+ globalEventBus.emit(LifecycleEvents.APP_INIT, data);
822
+ }
823
+ function emitAppMounted(rootElement) {
824
+ globalEventBus.emit(LifecycleEvents.APP_MOUNTED, rootElement);
825
+ }
826
+ function emitAppUpdated() {
827
+ globalEventBus.emit(LifecycleEvents.APP_UPDATED);
828
+ }
829
+ function emitAppError(error) {
830
+ globalEventBus.emit(LifecycleEvents.APP_ERROR, error);
831
+ }
832
+ function emitAppDestroyed() {
833
+ globalEventBus.emit(LifecycleEvents.APP_DESTROYED);
834
+ }
835
+ function emitComponentCreated(info) {
836
+ globalEventBus.emit(LifecycleEvents.COMPONENT_CREATED, info);
837
+ }
838
+ function emitComponentMounted(info, element) {
839
+ globalEventBus.emit(LifecycleEvents.COMPONENT_MOUNTED, info, element);
840
+ }
841
+ function emitComponentUpdated(info, prevProps, newProps) {
842
+ globalEventBus.emit(LifecycleEvents.COMPONENT_UPDATED, info, prevProps, newProps);
843
+ }
844
+ function emitComponentError(info, error) {
845
+ globalEventBus.emit(LifecycleEvents.COMPONENT_ERROR, info, error);
846
+ }
847
+ function emitComponentUnmounted(info) {
848
+ globalEventBus.emit(LifecycleEvents.COMPONENT_UNMOUNTED, info);
849
+ }
850
+ function onAppInit(handler) {
851
+ return globalEventBus.on(LifecycleEvents.APP_INIT, handler);
852
+ }
853
+ function onAppMounted(handler) {
854
+ return globalEventBus.on(LifecycleEvents.APP_MOUNTED, handler);
855
+ }
856
+ function onAppUpdated(handler) {
857
+ return globalEventBus.on(LifecycleEvents.APP_UPDATED, handler);
858
+ }
859
+ function onAppError(handler) {
860
+ return globalEventBus.on(LifecycleEvents.APP_ERROR, handler);
861
+ }
862
+ function onAppDestroyed(handler) {
863
+ return globalEventBus.on(LifecycleEvents.APP_DESTROYED, handler);
864
+ }
865
+ function onComponentCreated(handler) {
866
+ return globalEventBus.on(LifecycleEvents.COMPONENT_CREATED, handler);
867
+ }
868
+ function onComponentMounted(handler) {
869
+ return globalEventBus.on(LifecycleEvents.COMPONENT_MOUNTED, handler);
870
+ }
871
+ function onComponentUpdated(handler) {
872
+ return globalEventBus.on(LifecycleEvents.COMPONENT_UPDATED, handler);
873
+ }
874
+ function onComponentError(handler) {
875
+ return globalEventBus.on(LifecycleEvents.COMPONENT_ERROR, handler);
876
+ }
877
+ function onComponentUnmounted(handler) {
878
+ return globalEventBus.on(LifecycleEvents.COMPONENT_UNMOUNTED, handler);
879
+ }
293
880
 
294
881
  // src/wasm.ts
295
882
  async function loadGoWasm(wasmUrl, options = {}) {
@@ -570,17 +1157,17 @@ function escapeHtml(text) {
570
1157
  // src/browser.ts
571
1158
  function renderToString(content) {
572
1159
  if (typeof content === "string") {
573
- return Promise.resolve(content);
1160
+ return content;
574
1161
  }
575
1162
  if (typeof content === "function") {
576
1163
  try {
577
1164
  const result = content();
578
- return Promise.resolve(String(result));
1165
+ return String(result);
579
1166
  } catch (error) {
580
- return Promise.resolve(`<!-- Error rendering: ${error} -->`);
1167
+ return `<!-- Error rendering: ${error} -->`;
581
1168
  }
582
1169
  }
583
- return Promise.resolve(String(content));
1170
+ return String(content);
584
1171
  }
585
1172
  function generateToken(length = 32) {
586
1173
  const array = new Uint8Array(length);
@@ -604,10 +1191,33 @@ var isBrowser = typeof window !== "undefined";
604
1191
  var isNode = false;
605
1192
  console.log("Baraqex - Browser version loaded");
606
1193
  export {
1194
+ Component,
607
1195
  Fragment,
1196
+ LifecycleEvents,
1197
+ Link,
1198
+ Redirect,
1199
+ Route,
1200
+ RouterProvider,
1201
+ StoreProvider,
1202
+ Switch,
608
1203
  batchUpdates,
609
1204
  callWasmFunction,
610
1205
  createContext,
1206
+ createElement,
1207
+ createEventBus,
1208
+ createStore,
1209
+ diff,
1210
+ emitAppDestroyed,
1211
+ emitAppError,
1212
+ emitAppInit,
1213
+ emitAppMounted,
1214
+ emitAppUpdated,
1215
+ emitComponentCreated,
1216
+ emitComponentError,
1217
+ emitComponentMounted,
1218
+ emitComponentUnmounted,
1219
+ emitComponentUpdated,
1220
+ globalEventBus as eventBus,
611
1221
  generateDocument,
612
1222
  generateErrorPage,
613
1223
  generateLoadingPage,
@@ -618,18 +1228,39 @@ export {
618
1228
  isNode,
619
1229
  isWasmReady,
620
1230
  jsx,
1231
+ jsx as jsxDEV,
621
1232
  jsx as jsxs,
622
1233
  loadGoWasm,
1234
+ logger,
1235
+ onAppDestroyed,
1236
+ onAppError,
1237
+ onAppInit,
1238
+ onAppMounted,
1239
+ onAppUpdated,
1240
+ onComponentCreated,
1241
+ onComponentError,
1242
+ onComponentMounted,
1243
+ onComponentUnmounted,
1244
+ onComponentUpdated,
623
1245
  render,
624
1246
  renderToString,
625
1247
  safeJsonParse,
626
- server,
1248
+ shouldComponentUpdate,
1249
+ thunk,
627
1250
  useContext,
1251
+ useDispatch,
628
1252
  useEffect,
629
1253
  useErrorBoundary,
1254
+ useEvent,
1255
+ useForm,
630
1256
  useGoWasm,
1257
+ useLocation,
631
1258
  useMemo,
1259
+ useNavigate,
1260
+ useParams,
632
1261
  useRef,
633
- useState
1262
+ useSelector,
1263
+ useState,
1264
+ useStore
634
1265
  };
635
1266
  //# sourceMappingURL=browser.js.map