sinwan 1.1.0 → 1.1.1

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 (34) hide show
  1. package/dist/cjs/index.development.js +65 -33
  2. package/dist/cjs/index.development.js.map +9 -8
  3. package/dist/cjs/index.production.min.js +2 -2
  4. package/dist/cjs/index.production.min.js.map +9 -8
  5. package/dist/cjs/renderer/index.development.js +65 -33
  6. package/dist/cjs/renderer/index.development.js.map +9 -8
  7. package/dist/cjs/renderer/index.production.min.js +2 -2
  8. package/dist/cjs/renderer/index.production.min.js.map +9 -8
  9. package/dist/cjs/server/index.development.js +15 -2
  10. package/dist/cjs/server/index.development.js.map +5 -4
  11. package/dist/cjs/server/index.production.min.js +2 -2
  12. package/dist/cjs/server/index.production.min.js.map +5 -4
  13. package/dist/esm/index.development.js +65 -33
  14. package/dist/esm/index.development.js.map +9 -8
  15. package/dist/esm/index.production.min.js +2 -2
  16. package/dist/esm/index.production.min.js.map +9 -8
  17. package/dist/esm/renderer/index.development.js +65 -33
  18. package/dist/esm/renderer/index.development.js.map +9 -8
  19. package/dist/esm/renderer/index.production.min.js +2 -2
  20. package/dist/esm/renderer/index.production.min.js.map +9 -8
  21. package/dist/esm/server/index.development.js +15 -2
  22. package/dist/esm/server/index.development.js.map +5 -4
  23. package/dist/esm/server/index.production.min.js +2 -2
  24. package/dist/esm/server/index.production.min.js.map +5 -4
  25. package/dist/reactivity/index.d.ts +1 -0
  26. package/dist/reactivity/index.d.ts.map +1 -1
  27. package/dist/reactivity/normalization.d.ts +19 -0
  28. package/dist/reactivity/normalization.d.ts.map +1 -0
  29. package/dist/renderer/attributes.d.ts.map +1 -1
  30. package/dist/renderer/render-children.d.ts.map +1 -1
  31. package/dist/renderer/render-control-flow.d.ts.map +1 -1
  32. package/dist/types.d.ts +2 -2
  33. package/dist/types.d.ts.map +1 -1
  34. package/package.json +2 -2
@@ -383,7 +383,6 @@ function signal(initial) {
383
383
  function isSignal(value) {
384
384
  return value != null && typeof value === "object" && SIGNAL_BRAND in value;
385
385
  }
386
-
387
386
  // src/reactivity/computed.ts
388
387
  var COMPUTED_BRAND = Symbol("Sinwan:computed");
389
388
 
@@ -435,7 +434,32 @@ function computed(getter) {
435
434
  function isComputed(value) {
436
435
  return value != null && typeof value === "object" && COMPUTED_BRAND in value;
437
436
  }
438
-
437
+ // src/reactivity/batch.ts
438
+ var batchDepth = 0;
439
+ function batch(fn) {
440
+ batchDepth++;
441
+ try {
442
+ fn();
443
+ } finally {
444
+ batchDepth--;
445
+ if (batchDepth === 0) {
446
+ flushSync();
447
+ }
448
+ }
449
+ }
450
+ // src/reactivity/normalization.ts
451
+ function isReactive(value) {
452
+ return isSignal(value) || isComputed(value) || typeof value === "function";
453
+ }
454
+ function resolve(value) {
455
+ if (isSignal(value) || isComputed(value)) {
456
+ return value.value;
457
+ }
458
+ if (typeof value === "function") {
459
+ return value();
460
+ }
461
+ return value;
462
+ }
439
463
  // src/renderer/events.ts
440
464
  function isEventProp(key) {
441
465
  return key.length > 2 && key[0] === "o" && key[1] === "n" && key[2] >= "A" && key[2] <= "Z";
@@ -577,11 +601,11 @@ function applyAttributes(el, props) {
577
601
  for (const [key, value] of Object.entries(props)) {
578
602
  if (SKIP_PROPS.has(key) || isEventProp(key))
579
603
  continue;
580
- if (isSignal(value) || isComputed(value)) {
604
+ if (isReactive(value)) {
581
605
  const state = { previousStyleProps: new Set };
582
606
  let initialized = false;
583
607
  const dispose = effect(() => {
584
- setSingleAttribute(el, key, value.value, state);
608
+ setSingleAttribute(el, key, resolve(value), state);
585
609
  if (initialized) {
586
610
  queueUpdatedHooks(owner);
587
611
  }
@@ -681,19 +705,7 @@ function applyClass(el, value) {
681
705
  }
682
706
  domOps.setAttribute(el, "class", classStr);
683
707
  }
684
- // src/reactivity/batch.ts
685
- var batchDepth = 0;
686
- function batch(fn) {
687
- batchDepth++;
688
- try {
689
- fn();
690
- } finally {
691
- batchDepth--;
692
- if (batchDepth === 0) {
693
- flushSync();
694
- }
695
- }
696
- }
708
+
697
709
  // src/component/control-flow.ts
698
710
  var SHOW_TYPE = Symbol.for("Sinwan.Show");
699
711
  var FOR_TYPE = Symbol.for("Sinwan.For");
@@ -818,7 +830,7 @@ function normalizeChildren2(children) {
818
830
  return Array.isArray(children) ? children : [children];
819
831
  }
820
832
  function readReactive(value) {
821
- return isSignal(value) || isComputed(value) ? value.value : value;
833
+ return resolve(value);
822
834
  }
823
835
  function appendHiddenDisplay(style) {
824
836
  const trimmed = style.trim();
@@ -1240,7 +1252,7 @@ function withOptionalInstance(owner, fn) {
1240
1252
  return owner ? withInstance(owner, fn) : fn();
1241
1253
  }
1242
1254
  function readReactive2(value) {
1243
- return isSignal(value) || isComputed(value) ? value.value : value;
1255
+ return resolve(value);
1244
1256
  }
1245
1257
  function normalizeContent(content) {
1246
1258
  if (content == null || typeof content === "boolean") {
@@ -1461,19 +1473,8 @@ function renderNodeToDOM(node, parent, anchor = null, namespace = null) {
1461
1473
  insertNode2(parent, text2, anchor);
1462
1474
  return { type: "text", node: text2 };
1463
1475
  }
1464
- if (isSignal(node) || isComputed(node)) {
1465
- const text2 = domOps.createTextNode(String(node.value));
1466
- insertNode2(parent, text2, anchor);
1467
- const owner = getCurrentInstance();
1468
- let initialized = false;
1469
- const dispose = effect(() => {
1470
- domOps.setTextContent(text2, String(node.value));
1471
- if (initialized) {
1472
- queueUpdatedHooks(owner);
1473
- }
1474
- initialized = true;
1475
- });
1476
- return { type: "reactive-text", node: text2, dispose };
1476
+ if (isReactive(node)) {
1477
+ return renderReactiveNodeToDOM(node, parent, anchor, namespace);
1477
1478
  }
1478
1479
  if (Array.isArray(node)) {
1479
1480
  return renderArrayToDOM(node, parent, anchor, namespace);
@@ -1510,6 +1511,37 @@ function renderChildrenToDOM(children, parent, namespace = null) {
1510
1511
  }
1511
1512
  return mounted;
1512
1513
  }
1514
+ function renderReactiveNodeToDOM(reactive, parent, anchor, namespace) {
1515
+ const startAnchor = domOps.createComment("Sinwan-r");
1516
+ const endAnchor = domOps.createComment("/Sinwan-r");
1517
+ insertNode2(parent, startAnchor, anchor);
1518
+ insertNode2(parent, endAnchor, anchor);
1519
+ const owner = getCurrentInstance();
1520
+ let mountedContent = null;
1521
+ let initialized = false;
1522
+ const block = {
1523
+ type: "reactive-block",
1524
+ startAnchor,
1525
+ endAnchor,
1526
+ children: [],
1527
+ dispose: () => {}
1528
+ };
1529
+ block.dispose = effect(() => {
1530
+ if (mountedContent) {
1531
+ removeMountedNode(mountedContent);
1532
+ }
1533
+ const value = resolve(reactive);
1534
+ mountedContent = renderNodeToDOM(value, parent, endAnchor, namespace);
1535
+ block.children = [mountedContent];
1536
+ if (initialized) {
1537
+ if (owner)
1538
+ fireMountedHooks(owner);
1539
+ queueUpdatedHooks(owner);
1540
+ }
1541
+ initialized = true;
1542
+ });
1543
+ return block;
1544
+ }
1513
1545
  function insertNode2(parent, child, anchor) {
1514
1546
  if (anchor) {
1515
1547
  domOps.insertBefore(parent, child, anchor);
@@ -3152,5 +3184,5 @@ function hydrate(component, container, props) {
3152
3184
  };
3153
3185
  }
3154
3186
 
3155
- //# debugId=B2FFEB8D17EB811D64756E2164756E21
3187
+ //# debugId=446E2FDDC310248664756E2164756E21
3156
3188
  //# sourceMappingURL=index.development.js.map