baraqex 2.0.6 → 2.0.8

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.
@@ -23,6 +23,10 @@ export declare function jsxDEV(type: string | Function, props: any, key?: string
23
23
  export declare const Fragment: ({ children }: {
24
24
  children: any;
25
25
  }) => any;
26
+ /**
27
+ * Apply props to a real DOM element
28
+ */
29
+ export declare function applyProps(element: HTMLElement, props: Record<string, any>): void;
26
30
  /**
27
31
  * Create a DOM element from a virtual node (async for component support)
28
32
  */
@@ -1 +1 @@
1
- {"version":3,"file":"jsx-runtime.d.ts","sourceRoot":"","sources":["../../src/core/jsx-runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AASnC;;GAEG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,EAAE,GAAG,KAAK,CAWlF;AAED;;GAEG;AACH,eAAO,MAAM,IAAI,YAAM,CAAC;AAExB;;GAEG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,GAAG,QAAQ,EACvB,KAAK,EAAE,GAAG,EACV,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EACrB,iBAAiB,CAAC,EAAE,OAAO,EAC3B,OAAO,CAAC,EAAE,GAAG,EACb,KAAK,CAAC,EAAE,GAAG,GACV,KAAK,CAKP;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,cAAc;IAAE,QAAQ,EAAE,GAAG,CAAA;CAAE,QAAa,CAAC;AAqDtE;;GAEG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CA+DrE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,GAAG,IAAI,CA6C1D;;;;;6BAzKsC;QAAE,QAAQ,EAAE,GAAG,CAAA;KAAE;;;;AA4KxD,wBAOE"}
1
+ {"version":3,"file":"jsx-runtime.d.ts","sourceRoot":"","sources":["../../src/core/jsx-runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AASnC;;GAEG;AACH,wBAAgB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,EAAE,GAAG,KAAK,CAWlF;AAED;;GAEG;AACH,eAAO,MAAM,IAAI,YAAM,CAAC;AAExB;;GAEG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,MAAM,GAAG,QAAQ,EACvB,KAAK,EAAE,GAAG,EACV,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,EACrB,iBAAiB,CAAC,EAAE,OAAO,EAC3B,OAAO,CAAC,EAAE,GAAG,EACb,KAAK,CAAC,EAAE,GAAG,GACV,KAAK,CAKP;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,cAAc;IAAE,QAAQ,EAAE,GAAG,CAAA;CAAE,QAAa,CAAC;AAmBtE;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CA6BjF;AAED;;GAEG;AACH,wBAAsB,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CA+DrE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,GAAG,IAAI,CA6C1D;;;;;6BAzKsC;QAAE,QAAQ,EAAE,GAAG,CAAA;KAAE;;;;AA4KxD,wBAOE"}
@@ -11,11 +11,12 @@ import { VNode } from './types.js';
11
11
  */
12
12
  export declare function render(element: VNode, container: HTMLElement): Promise<void>;
13
13
  /**
14
- * Hydrate server-rendered HTML.
14
+ * Hydrate server-rendered HTML in place.
15
15
  *
16
- * In this initial implementation, hydration re-renders the component tree
17
- * and replaces the server HTML. A production implementation would walk the
18
- * existing DOM, attach event listeners, and reconcile without full replace.
16
+ * Attaches event listeners and applies props to the DOM produced by
17
+ * server-side rendering without replacing it, so there is no visual flash
18
+ * between the SSR HTML and an interactive page. Fallback: if the existing DOM
19
+ * can't be matched, performs a fresh render into an empty container.
19
20
  */
20
21
  export declare function hydrate(element: VNode, container: HTMLElement): Promise<void>;
21
22
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/core/renderer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAcnC;;GAEG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BlF;AAED;;;;;;GAMG;AACH,wBAAsB,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAMnF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,WAAW;sBAK3B,KAAK;;EAO1B;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,WAAW,GAAG,OAAO,CAEvD;;;;;;;AAED,wBAKE"}
1
+ {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/core/renderer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAcH,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAcnC;;GAEG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA+BlF;AAqFD;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CA+CnF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,WAAW;sBAK3B,KAAK;;EAO1B;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,SAAS,EAAE,WAAW,GAAG,OAAO,CAEvD;;;;;;;AAED,wBAKE"}
package/dist/index.js CHANGED
@@ -465,8 +465,107 @@ async function render(element, container) {
465
465
  }
466
466
  });
467
467
  }
468
+ function* walkElements(node) {
469
+ for (const child of node.childNodes) {
470
+ if (child.nodeType === 1) {
471
+ yield child;
472
+ yield* walkElements(child);
473
+ }
474
+ }
475
+ }
476
+ async function hydrateElement(vnode, nextElement) {
477
+ if (vnode == null || typeof vnode === "boolean") {
478
+ return true;
479
+ }
480
+ if (typeof vnode === "number" || typeof vnode === "string") {
481
+ return true;
482
+ }
483
+ if (Array.isArray(vnode)) {
484
+ for (const child of vnode) {
485
+ if (!await hydrateElement(child, nextElement))
486
+ return false;
487
+ }
488
+ return true;
489
+ }
490
+ if (typeof vnode === "object" && "type" in vnode && vnode.props !== void 0) {
491
+ const { type, props } = vnode;
492
+ if (typeof type === "function") {
493
+ if (type === Fragment) {
494
+ const children = props?.children;
495
+ if (children == null)
496
+ return true;
497
+ return hydrateElement(children, nextElement);
498
+ }
499
+ const root = getCurrentRoot() ?? void 0;
500
+ prepareRender(root);
501
+ try {
502
+ const result = type(props || {});
503
+ return await hydrateElement(result, nextElement);
504
+ } finally {
505
+ finishRender();
506
+ }
507
+ }
508
+ if (typeof type === "string") {
509
+ const el = nextElement();
510
+ if (!el)
511
+ return false;
512
+ if (el.tagName.toLowerCase() !== type.toLowerCase())
513
+ return false;
514
+ applyProps(el, props || {});
515
+ const children = props?.children;
516
+ if (children != null) {
517
+ const childArray = Array.isArray(children) ? children : [children];
518
+ for (const child of childArray) {
519
+ if (!await hydrateElement(child, nextElement))
520
+ return false;
521
+ }
522
+ }
523
+ return true;
524
+ }
525
+ return false;
526
+ }
527
+ return true;
528
+ }
468
529
  async function hydrate(element, container) {
469
- await render(element, container);
530
+ if (!isBrowser2) {
531
+ throw new Error("[baraqex] hydrate() can only be called in a browser.");
532
+ }
533
+ if (!container) {
534
+ throw new Error("[baraqex] hydrate() requires a container element");
535
+ }
536
+ if (!container.hasChildNodes()) {
537
+ return render(element, container);
538
+ }
539
+ let root = rootMap.get(container);
540
+ if (!root) {
541
+ root = createRootState();
542
+ rootMap.set(container, root);
543
+ }
544
+ await batchUpdates(async () => {
545
+ prepareRender(root);
546
+ try {
547
+ setRenderCallback(render, element, container);
548
+ const generator = walkElements(container);
549
+ const nextElement = () => {
550
+ const { value, done } = generator.next();
551
+ return done ? null : value;
552
+ };
553
+ const matched = await hydrateElement(element, nextElement);
554
+ if (!matched) {
555
+ const freshRoot = createRootState();
556
+ rootMap.set(container, freshRoot);
557
+ prepareRender(freshRoot);
558
+ setRenderCallback(render, element, container);
559
+ const domNode = await createElement(element);
560
+ container.textContent = "";
561
+ container.appendChild(domNode);
562
+ finishRender();
563
+ return;
564
+ }
565
+ } finally {
566
+ finishRender();
567
+ }
568
+ });
470
569
  }
471
570
  function createRoot(container) {
472
571
  const root = createRootState();
@@ -2284,10 +2383,22 @@ function withErrorHandling(fn, errorHandler2) {
2284
2383
  }
2285
2384
 
2286
2385
  // src/wasm.ts
2287
- async function loadGoWasm(wasmUrl, options = {}) {
2386
+ var wasmCache = /* @__PURE__ */ new Map();
2387
+ function loadGoWasm(wasmUrl, options = {}) {
2288
2388
  if (typeof window === "undefined") {
2289
2389
  throw new Error("loadGoWasm() is for browser use only. Use loadGoWasmFromFile() in Node.js.");
2290
2390
  }
2391
+ const cached = wasmCache.get(wasmUrl);
2392
+ if (cached)
2393
+ return cached;
2394
+ const request = loadGoWasmInternal(wasmUrl, options).catch((error) => {
2395
+ wasmCache.delete(wasmUrl);
2396
+ throw error;
2397
+ });
2398
+ wasmCache.set(wasmUrl, request);
2399
+ return request;
2400
+ }
2401
+ async function loadGoWasmInternal(wasmUrl, options = {}) {
2291
2402
  try {
2292
2403
  if (!window.Go) {
2293
2404
  throw new Error("Go WASM runtime not available. Make sure wasm_exec.js is loaded.");