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
@@ -316,7 +316,6 @@ function signal(initial) {
316
316
  function isSignal(value) {
317
317
  return value != null && typeof value === "object" && SIGNAL_BRAND in value;
318
318
  }
319
-
320
319
  // src/reactivity/computed.ts
321
320
  var COMPUTED_BRAND = Symbol("Sinwan:computed");
322
321
 
@@ -368,7 +367,32 @@ function computed(getter) {
368
367
  function isComputed(value) {
369
368
  return value != null && typeof value === "object" && COMPUTED_BRAND in value;
370
369
  }
371
-
370
+ // src/reactivity/batch.ts
371
+ var batchDepth = 0;
372
+ function batch(fn) {
373
+ batchDepth++;
374
+ try {
375
+ fn();
376
+ } finally {
377
+ batchDepth--;
378
+ if (batchDepth === 0) {
379
+ flushSync();
380
+ }
381
+ }
382
+ }
383
+ // src/reactivity/normalization.ts
384
+ function isReactive(value) {
385
+ return isSignal(value) || isComputed(value) || typeof value === "function";
386
+ }
387
+ function resolve(value) {
388
+ if (isSignal(value) || isComputed(value)) {
389
+ return value.value;
390
+ }
391
+ if (typeof value === "function") {
392
+ return value();
393
+ }
394
+ return value;
395
+ }
372
396
  // src/renderer/events.ts
373
397
  function isEventProp(key) {
374
398
  return key.length > 2 && key[0] === "o" && key[1] === "n" && key[2] >= "A" && key[2] <= "Z";
@@ -510,11 +534,11 @@ function applyAttributes(el, props) {
510
534
  for (const [key, value] of Object.entries(props)) {
511
535
  if (SKIP_PROPS.has(key) || isEventProp(key))
512
536
  continue;
513
- if (isSignal(value) || isComputed(value)) {
537
+ if (isReactive(value)) {
514
538
  const state = { previousStyleProps: new Set };
515
539
  let initialized = false;
516
540
  const dispose = effect(() => {
517
- setSingleAttribute(el, key, value.value, state);
541
+ setSingleAttribute(el, key, resolve(value), state);
518
542
  if (initialized) {
519
543
  queueUpdatedHooks(owner);
520
544
  }
@@ -614,19 +638,7 @@ function applyClass(el, value) {
614
638
  }
615
639
  domOps.setAttribute(el, "class", classStr);
616
640
  }
617
- // src/reactivity/batch.ts
618
- var batchDepth = 0;
619
- function batch(fn) {
620
- batchDepth++;
621
- try {
622
- fn();
623
- } finally {
624
- batchDepth--;
625
- if (batchDepth === 0) {
626
- flushSync();
627
- }
628
- }
629
- }
641
+
630
642
  // src/component/control-flow.ts
631
643
  var SHOW_TYPE = Symbol.for("Sinwan.Show");
632
644
  var FOR_TYPE = Symbol.for("Sinwan.For");
@@ -751,7 +763,7 @@ function normalizeChildren2(children) {
751
763
  return Array.isArray(children) ? children : [children];
752
764
  }
753
765
  function readReactive(value) {
754
- return isSignal(value) || isComputed(value) ? value.value : value;
766
+ return resolve(value);
755
767
  }
756
768
  function appendHiddenDisplay(style) {
757
769
  const trimmed = style.trim();
@@ -1173,7 +1185,7 @@ function withOptionalInstance(owner, fn) {
1173
1185
  return owner ? withInstance(owner, fn) : fn();
1174
1186
  }
1175
1187
  function readReactive2(value) {
1176
- return isSignal(value) || isComputed(value) ? value.value : value;
1188
+ return resolve(value);
1177
1189
  }
1178
1190
  function normalizeContent(content) {
1179
1191
  if (content == null || typeof content === "boolean") {
@@ -1394,19 +1406,8 @@ function renderNodeToDOM(node, parent, anchor = null, namespace = null) {
1394
1406
  insertNode2(parent, text2, anchor);
1395
1407
  return { type: "text", node: text2 };
1396
1408
  }
1397
- if (isSignal(node) || isComputed(node)) {
1398
- const text2 = domOps.createTextNode(String(node.value));
1399
- insertNode2(parent, text2, anchor);
1400
- const owner = getCurrentInstance();
1401
- let initialized = false;
1402
- const dispose = effect(() => {
1403
- domOps.setTextContent(text2, String(node.value));
1404
- if (initialized) {
1405
- queueUpdatedHooks(owner);
1406
- }
1407
- initialized = true;
1408
- });
1409
- return { type: "reactive-text", node: text2, dispose };
1409
+ if (isReactive(node)) {
1410
+ return renderReactiveNodeToDOM(node, parent, anchor, namespace);
1410
1411
  }
1411
1412
  if (Array.isArray(node)) {
1412
1413
  return renderArrayToDOM(node, parent, anchor, namespace);
@@ -1443,6 +1444,37 @@ function renderChildrenToDOM(children, parent, namespace = null) {
1443
1444
  }
1444
1445
  return mounted;
1445
1446
  }
1447
+ function renderReactiveNodeToDOM(reactive, parent, anchor, namespace) {
1448
+ const startAnchor = domOps.createComment("Sinwan-r");
1449
+ const endAnchor = domOps.createComment("/Sinwan-r");
1450
+ insertNode2(parent, startAnchor, anchor);
1451
+ insertNode2(parent, endAnchor, anchor);
1452
+ const owner = getCurrentInstance();
1453
+ let mountedContent = null;
1454
+ let initialized = false;
1455
+ const block = {
1456
+ type: "reactive-block",
1457
+ startAnchor,
1458
+ endAnchor,
1459
+ children: [],
1460
+ dispose: () => {}
1461
+ };
1462
+ block.dispose = effect(() => {
1463
+ if (mountedContent) {
1464
+ removeMountedNode(mountedContent);
1465
+ }
1466
+ const value = resolve(reactive);
1467
+ mountedContent = renderNodeToDOM(value, parent, endAnchor, namespace);
1468
+ block.children = [mountedContent];
1469
+ if (initialized) {
1470
+ if (owner)
1471
+ fireMountedHooks(owner);
1472
+ queueUpdatedHooks(owner);
1473
+ }
1474
+ initialized = true;
1475
+ });
1476
+ return block;
1477
+ }
1446
1478
  function insertNode2(parent, child, anchor) {
1447
1479
  if (anchor) {
1448
1480
  domOps.insertBefore(parent, child, anchor);
@@ -1526,5 +1558,5 @@ export {
1526
1558
  applyAttributes
1527
1559
  };
1528
1560
 
1529
- //# debugId=5F0DDB77CC3157EE64756E2164756E21
1561
+ //# debugId=ECCB38F4A76AE39C64756E2164756E21
1530
1562
  //# sourceMappingURL=index.development.js.map