@getforma/core 1.0.6 → 1.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.
Files changed (50) hide show
  1. package/README.md +4 -4
  2. package/dist/{chunk-V732ZBCU.cjs → chunk-7L3KHGEA.cjs} +95 -50
  3. package/dist/chunk-7L3KHGEA.cjs.map +1 -0
  4. package/dist/{chunk-VTPFK5TJ.js → chunk-7Q7LIV23.js} +59 -14
  5. package/dist/chunk-7Q7LIV23.js.map +1 -0
  6. package/dist/{chunk-DCTOXHPF.cjs → chunk-BARF67I6.cjs} +8 -8
  7. package/dist/chunk-BARF67I6.cjs.map +1 -0
  8. package/dist/{chunk-OZCHIVAZ.js → chunk-HLM5BZZQ.js} +2 -2
  9. package/dist/chunk-HLM5BZZQ.js.map +1 -0
  10. package/dist/{chunk-3U57L2TY.cjs → chunk-QLPCVK7C.cjs} +2 -2
  11. package/dist/chunk-QLPCVK7C.cjs.map +1 -0
  12. package/dist/{chunk-OUVOAYIO.js → chunk-TBWZZ3SI.js} +3 -3
  13. package/dist/chunk-TBWZZ3SI.js.map +1 -0
  14. package/dist/formajs-runtime-hardened.global.js.map +1 -1
  15. package/dist/formajs-runtime.global.js.map +1 -1
  16. package/dist/formajs.global.js +55 -10
  17. package/dist/formajs.global.js.map +1 -1
  18. package/dist/http.cjs +13 -13
  19. package/dist/http.cjs.map +1 -1
  20. package/dist/http.js +4 -4
  21. package/dist/http.js.map +1 -1
  22. package/dist/index.cjs +61 -61
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +141 -10
  25. package/dist/index.d.ts +141 -10
  26. package/dist/index.js +6 -6
  27. package/dist/index.js.map +1 -1
  28. package/dist/{resource-Cd0cGOxS.d.ts → resource-BHsgURy0.d.ts} +3 -1
  29. package/dist/{resource-DK98lW5e.d.cts → resource-DeEzxUz6.d.cts} +3 -1
  30. package/dist/runtime-hardened.cjs.map +1 -1
  31. package/dist/runtime-hardened.js.map +1 -1
  32. package/dist/runtime.cjs +29 -29
  33. package/dist/runtime.js +3 -3
  34. package/dist/server.cjs +7 -7
  35. package/dist/server.d.cts +2 -2
  36. package/dist/server.d.ts +2 -2
  37. package/dist/server.js +2 -2
  38. package/dist/{signal-YlS1kgfh.d.cts → signal-C9v4akyJ.d.cts} +2 -0
  39. package/dist/{signal-YlS1kgfh.d.ts → signal-C9v4akyJ.d.ts} +2 -0
  40. package/dist/tc39-compat.cjs +3 -3
  41. package/dist/tc39-compat.d.cts +1 -1
  42. package/dist/tc39-compat.d.ts +1 -1
  43. package/dist/tc39-compat.js +1 -1
  44. package/package.json +1 -1
  45. package/dist/chunk-3U57L2TY.cjs.map +0 -1
  46. package/dist/chunk-DCTOXHPF.cjs.map +0 -1
  47. package/dist/chunk-OUVOAYIO.js.map +0 -1
  48. package/dist/chunk-OZCHIVAZ.js.map +0 -1
  49. package/dist/chunk-V732ZBCU.cjs.map +0 -1
  50. package/dist/chunk-VTPFK5TJ.js.map +0 -1
@@ -1349,9 +1349,9 @@ var FormaJS = (() => {
1349
1349
  }
1350
1350
 
1351
1351
  // src/dom/show.ts
1352
- function createShow(when, thenFn, elseFn) {
1352
+ function createShow(when, thenFn, elseFn = () => null) {
1353
1353
  if (hydrating) {
1354
- const branch = when() ? thenFn() : elseFn?.() ?? null;
1354
+ const branch = when() ? thenFn() : elseFn();
1355
1355
  return {
1356
1356
  type: "show",
1357
1357
  condition: when,
@@ -2286,7 +2286,11 @@ var FormaJS = (() => {
2286
2286
  function applyStaticProp(el, key, value2) {
2287
2287
  if (value2 == null || value2 === false) return;
2288
2288
  if (key === "class" || key === "className") {
2289
- el.className = value2;
2289
+ if (el instanceof HTMLElement) {
2290
+ el.className = value2;
2291
+ } else {
2292
+ el.setAttribute("class", value2);
2293
+ }
2290
2294
  return;
2291
2295
  }
2292
2296
  if (key === "style") {
@@ -2347,17 +2351,58 @@ var FormaJS = (() => {
2347
2351
  parent2[DYNAMIC_CHILD_SYM2] = true;
2348
2352
  }
2349
2353
  let currentNode = null;
2354
+ let currentFragChildren = null;
2355
+ let warnedArray = false;
2356
+ const DEBUG = typeof globalThis.__FORMA_DEBUG__ !== "undefined";
2357
+ const clearCurrent = () => {
2358
+ if (currentFragChildren) {
2359
+ for (const c of currentFragChildren) {
2360
+ if (c.parentNode === parent2) parent2.removeChild(c);
2361
+ }
2362
+ currentFragChildren = null;
2363
+ }
2364
+ if (currentNode && currentNode.parentNode === parent2) {
2365
+ parent2.removeChild(currentNode);
2366
+ }
2367
+ currentNode = null;
2368
+ };
2350
2369
  internalEffect(() => {
2351
2370
  const v = child();
2352
- if (v instanceof Node) {
2353
- if (currentNode) {
2354
- parent2.replaceChild(v, currentNode);
2355
- } else {
2356
- parent2.appendChild(v);
2371
+ let resolved = v;
2372
+ if (Array.isArray(v)) {
2373
+ const frag = document.createDocumentFragment();
2374
+ for (const item of v) {
2375
+ if (item instanceof Node) frag.appendChild(item);
2376
+ else if (Array.isArray(item)) {
2377
+ if (DEBUG) console.warn("[forma] Nested arrays in function children are not supported. Flatten the array or use createList().");
2378
+ } else if (item != null && item !== false && item !== true) {
2379
+ frag.appendChild(new Text(String(item)));
2380
+ }
2381
+ }
2382
+ resolved = frag.childNodes.length > 0 ? frag : null;
2383
+ if (DEBUG && !warnedArray) {
2384
+ warnedArray = true;
2385
+ console.warn("[forma] Function child returned an array \u2014 auto-wrapped in DocumentFragment. Consider using createList() or wrapping in a container element for better performance.");
2357
2386
  }
2358
- currentNode = v;
2387
+ }
2388
+ if (resolved instanceof Node) {
2389
+ clearCurrent();
2390
+ const isNewFrag = resolved instanceof DocumentFragment;
2391
+ if (isNewFrag) {
2392
+ currentFragChildren = Array.from(resolved.childNodes);
2393
+ }
2394
+ parent2.appendChild(resolved);
2395
+ currentNode = isNewFrag ? null : resolved;
2396
+ } else if (resolved == null || resolved === false || resolved === true) {
2397
+ clearCurrent();
2359
2398
  } else {
2360
- const text = typeof v === "symbol" ? String(v) : String(v ?? "");
2399
+ if (currentFragChildren) {
2400
+ for (const c of currentFragChildren) {
2401
+ if (c.parentNode === parent2) parent2.removeChild(c);
2402
+ }
2403
+ currentFragChildren = null;
2404
+ }
2405
+ const text = typeof resolved === "symbol" ? String(resolved) : String(resolved ?? "");
2361
2406
  if (!currentNode) {
2362
2407
  currentNode = new Text(text);
2363
2408
  parent2.appendChild(currentNode);