baraqex 1.0.43 → 1.0.44

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,82 +1,4 @@
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
- }
1
+ // node_modules/frontend-hamroun/dist/index.mjs
80
2
  var isBatching = false;
81
3
  var queue = [];
82
4
  function batchUpdates(fn) {
@@ -89,35 +11,13 @@ function batchUpdates(fn) {
89
11
  fn();
90
12
  while (queue.length > 0) {
91
13
  const nextFn = queue.shift();
92
- nextFn?.();
14
+ nextFn == null ? void 0 : nextFn();
93
15
  }
94
16
  } finally {
95
17
  isBatching = false;
96
18
  }
97
19
  }
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
20
  var currentRender = 0;
120
- var isSSR = false;
121
21
  var states = /* @__PURE__ */ new Map();
122
22
  var stateIndices = /* @__PURE__ */ new Map();
123
23
  var effects = /* @__PURE__ */ new Map();
@@ -126,39 +26,53 @@ var refs = /* @__PURE__ */ new Map();
126
26
  var globalRenderCallback = null;
127
27
  var globalContainer = null;
128
28
  var currentElement = null;
29
+ var isServer = typeof window === "undefined";
30
+ var serverStates = /* @__PURE__ */ new Map();
129
31
  function setRenderCallback(callback, element, container) {
130
32
  globalRenderCallback = callback;
131
33
  globalContainer = container;
132
34
  currentElement = element;
133
35
  }
134
- function prepareRender(component = null, isServerSideRender = false) {
36
+ function prepareRender() {
135
37
  currentRender++;
136
- isSSR = isServerSideRender;
137
38
  stateIndices.set(currentRender, 0);
138
- if (!states.has(currentRender)) {
139
- states.set(currentRender, []);
140
- }
141
39
  return currentRender;
142
40
  }
143
41
  function finishRender() {
42
+ if (isServer) {
43
+ serverStates.delete(currentRender);
44
+ }
45
+ currentRender = 0;
144
46
  }
145
47
  function useState(initial) {
146
48
  if (!currentRender) {
147
49
  throw new Error("useState must be called within a render");
148
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
+ }
149
66
  if (!states.has(currentRender)) {
150
67
  states.set(currentRender, []);
151
68
  }
152
69
  const componentStates = states.get(currentRender);
153
- const index = stateIndices.get(currentRender) || 0;
70
+ const index = stateIndices.get(currentRender);
154
71
  if (index >= componentStates.length) {
155
72
  componentStates.push(initial);
156
73
  }
157
74
  const state = componentStates[index];
158
75
  const setState = (newValue) => {
159
- if (isSSR) {
160
- return;
161
- }
162
76
  const nextValue = typeof newValue === "function" ? newValue(componentStates[index]) : newValue;
163
77
  if (componentStates[index] === nextValue)
164
78
  return;
@@ -175,24 +89,19 @@ function useState(initial) {
175
89
  function useEffect(callback, deps) {
176
90
  if (!currentRender)
177
91
  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;
92
+ const effectIndex = stateIndices.get(currentRender);
184
93
  if (!effects.has(currentRender)) {
185
94
  effects.set(currentRender, []);
186
95
  }
187
96
  const componentEffects = effects.get(currentRender);
188
97
  const prevEffect = componentEffects[effectIndex];
189
98
  if (!prevEffect || !deps || !prevEffect.deps || deps.some((dep, i) => dep !== prevEffect.deps[i])) {
190
- if (prevEffect?.cleanup) {
99
+ if (prevEffect == null ? void 0 : prevEffect.cleanup) {
191
100
  prevEffect.cleanup();
192
101
  }
193
102
  queueMicrotask(() => {
194
103
  const cleanup = callback() || void 0;
195
- componentEffects[effectIndex] = { cleanup, deps: deps || [] };
104
+ componentEffects[effectIndex] = { cleanup, deps };
196
105
  });
197
106
  }
198
107
  stateIndices.set(currentRender, effectIndex + 1);
@@ -200,7 +109,7 @@ function useEffect(callback, deps) {
200
109
  function useMemo(factory, deps) {
201
110
  if (!currentRender)
202
111
  throw new Error("useMemo must be called within a render");
203
- const memoIndex = stateIndices.get(currentRender) || 0;
112
+ const memoIndex = stateIndices.get(currentRender);
204
113
  if (!memos.has(currentRender)) {
205
114
  memos.set(currentRender, []);
206
115
  }
@@ -208,7 +117,7 @@ function useMemo(factory, deps) {
208
117
  const prevMemo = componentMemos[memoIndex];
209
118
  if (!prevMemo || deps && deps.some((dep, i) => !Object.is(dep, prevMemo.deps[i]))) {
210
119
  const value = factory();
211
- componentMemos[memoIndex] = { value, deps: deps || [] };
120
+ componentMemos[memoIndex] = { value, deps };
212
121
  stateIndices.set(currentRender, memoIndex + 1);
213
122
  return value;
214
123
  }
@@ -218,7 +127,7 @@ function useMemo(factory, deps) {
218
127
  function useRef(initial) {
219
128
  if (!currentRender)
220
129
  throw new Error("useRef must be called within a render");
221
- const refIndex = stateIndices.get(currentRender) || 0;
130
+ const refIndex = stateIndices.get(currentRender);
222
131
  if (!refs.has(currentRender)) {
223
132
  refs.set(currentRender, []);
224
133
  }
@@ -235,9 +144,6 @@ function useRef(initial) {
235
144
  }
236
145
  async function rerender(rendererId) {
237
146
  try {
238
- if (isSSR) {
239
- return;
240
- }
241
147
  const componentEffects = effects.get(rendererId);
242
148
  if (componentEffects) {
243
149
  componentEffects.forEach((effect) => {
@@ -257,640 +163,133 @@ function useErrorBoundary() {
257
163
  const [error, setError] = useState(null);
258
164
  return [error, () => setError(null)];
259
165
  }
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
- }
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);
271
177
  }
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);
178
+ };
179
+ return context;
307
180
  }
308
- function shouldComponentUpdate(oldProps, newProps) {
309
- return !arePropsEqual(oldProps, newProps);
181
+ function useContext(context) {
182
+ return context;
310
183
  }
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
- }
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);
333
189
  }
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;
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("");
340
198
  }
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;
199
+ if (typeof vnode === "boolean") {
200
+ return document.createTextNode("");
356
201
  }
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);
202
+ if (typeof vnode === "number" || typeof vnode === "string") {
203
+ return document.createTextNode(String(vnode));
368
204
  }
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;
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);
381
210
  }
382
- return this.element;
383
- }
384
- render() {
385
- throw new Error("Component must implement render() method");
211
+ return fragment;
386
212
  }
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);
213
+ if ("type" in vnode && vnode.props !== void 0) {
214
+ const { type, props } = vnode;
215
+ if (typeof type === "function") {
641
216
  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);
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("");
659
226
  }
660
227
  }
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);
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));
709
249
  }
710
250
  }
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();
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
+ }
726
258
  }
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);
259
+ return element;
750
260
  }
751
- function subscribe(listener) {
752
- listeners.push(listener);
753
- return function unsubscribe() {
754
- listeners = listeners.filter((l) => l !== listener);
755
- };
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;
756
270
  }
757
- dispatch({ type: "@@INIT" });
758
- return {
759
- getState: () => state,
760
- dispatch,
761
- subscribe
762
- };
763
271
  }
764
- var StoreContext = createContext({
765
- store: {
766
- getState: () => ({}),
767
- dispatch: () => {
768
- },
769
- subscribe: () => () => {
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();
770
285
  }
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
286
  });
786
287
  }
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);
288
+ var server = {
289
+ async getServer() {
290
+ throw new Error("Server module can only be used in Node.js environment");
811
291
  }
812
- return next(action);
813
292
  };
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
293
 
895
294
  // src/wasm.ts
896
295
  async function loadGoWasm(wasmUrl, options = {}) {
@@ -1076,39 +475,16 @@ console.log("Baraqex - Browser version loaded");
1076
475
  export {
1077
476
  ApiRouter,
1078
477
  AuthService,
1079
- Component,
1080
478
  Database,
1081
479
  Fragment,
1082
- LifecycleEvents,
1083
- Link,
1084
- Redirect,
1085
- Route,
1086
- RouterProvider,
1087
480
  Server,
1088
- StoreProvider,
1089
- Switch,
1090
481
  batchUpdates,
1091
482
  callWasmFunction,
1092
483
  createContext,
1093
484
  createDevServer,
1094
- createElement,
1095
- createEventBus,
1096
485
  createProductionServer,
1097
486
  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
487
  errorHandler,
1111
- globalEventBus as eventBus,
1112
488
  generateDocument,
1113
489
  generateErrorPage,
1114
490
  generateLoadingPage,
@@ -1120,43 +496,22 @@ export {
1120
496
  isNode,
1121
497
  isWasmReady,
1122
498
  jsx,
1123
- jsx as jsxDEV,
1124
499
  jsx as jsxs,
1125
500
  loadGoWasm,
1126
501
  loadGoWasmFromFile,
1127
- logger,
1128
502
  notFoundHandler,
1129
- onAppDestroyed,
1130
- onAppError,
1131
- onAppInit,
1132
- onAppMounted,
1133
- onAppUpdated,
1134
- onComponentCreated,
1135
- onComponentError,
1136
- onComponentMounted,
1137
- onComponentUnmounted,
1138
- onComponentUpdated,
1139
503
  rateLimit,
1140
504
  render,
1141
505
  renderToString,
1142
506
  requestLogger,
1143
507
  safeJsonParse,
1144
- shouldComponentUpdate,
1145
- thunk,
508
+ server,
1146
509
  useContext,
1147
- useDispatch,
1148
510
  useEffect,
1149
511
  useErrorBoundary,
1150
- useEvent,
1151
- useForm,
1152
512
  useGoWasm,
1153
- useLocation,
1154
513
  useMemo,
1155
- useNavigate,
1156
- useParams,
1157
514
  useRef,
1158
- useSelector,
1159
- useState,
1160
- useStore
515
+ useState
1161
516
  };
1162
517
  //# sourceMappingURL=browser.js.map