tutuca 0.9.67 → 0.9.68

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.
@@ -1284,10 +1284,18 @@ class RequestHandler {
1284
1284
 
1285
1285
  // src/vdom.js
1286
1286
  var HTML_NS = "http://www.w3.org/1999/xhtml";
1287
+ var SVG_NS = "http://www.w3.org/2000/svg";
1288
+ var MATH_NS = "http://www.w3.org/1998/Math/MathML";
1287
1289
  var isNamespaced = (node) => {
1288
1290
  const ns = node.namespaceURI;
1289
1291
  return ns !== null && ns !== HTML_NS;
1290
1292
  };
1293
+ var isForeignObject = (tag) => tag.length === 13 && tag.toLowerCase() === "foreignobject";
1294
+ var effectiveNs = (vnode, opts) => vnode.namespace ?? opts.namespace ?? null;
1295
+ function childOpts(vnode, ns, opts) {
1296
+ const target = ns === SVG_NS && isForeignObject(vnode.tag) ? null : ns;
1297
+ return target === (opts.namespace ?? null) ? opts : { ...opts, namespace: target };
1298
+ }
1291
1299
  var NEVER_ASSIGN = new Set([
1292
1300
  "width",
1293
1301
  "height",
@@ -1301,7 +1309,7 @@ var NEVER_ASSIGN = new Set([
1301
1309
  "role",
1302
1310
  "popover"
1303
1311
  ]);
1304
- function applyProperties(node, props, _previous) {
1312
+ function applyProperties(node, props) {
1305
1313
  const namespaced = isNamespaced(node);
1306
1314
  for (const name in props)
1307
1315
  setProp(node, name, props[name], namespaced);
@@ -1310,8 +1318,11 @@ function setProp(node, name, value, namespaced) {
1310
1318
  if (name === "dangerouslySetInnerHTML") {
1311
1319
  if (value === undefined)
1312
1320
  node.replaceChildren();
1313
- else
1314
- node.innerHTML = value.__html ?? "";
1321
+ else {
1322
+ const html = value.__html ?? "";
1323
+ if (html !== node.innerHTML)
1324
+ node.innerHTML = html;
1325
+ }
1315
1326
  return;
1316
1327
  }
1317
1328
  if (typeof value === "function")
@@ -1327,6 +1338,13 @@ function setProp(node, name, value, namespaced) {
1327
1338
  else
1328
1339
  node.setAttribute(name, value);
1329
1340
  }
1341
+ function applyValueLast(node, value) {
1342
+ if (node.tagName === "PROGRESS" && (value == null || value === 0)) {
1343
+ node.removeAttribute("value");
1344
+ } else {
1345
+ setProp(node, "value", value, isNamespaced(node));
1346
+ }
1347
+ }
1330
1348
 
1331
1349
  class VBase {
1332
1350
  }
@@ -1445,15 +1463,23 @@ class VNode extends VBase {
1445
1463
  }
1446
1464
  toDom(opts) {
1447
1465
  const doc = opts.document;
1448
- const node = this.namespace === null ? doc.createElement(this.tag) : doc.createElementNS(this.namespace, this.tag);
1449
- if (this.tag === "SELECT" && "value" in this.attrs) {
1450
- const { value, ...rest } = this.attrs;
1451
- applyProperties(node, rest, {});
1452
- appendChildNodes(node, this.childs, opts);
1453
- applyProperties(node, { value }, {});
1466
+ const ns = effectiveNs(this, opts);
1467
+ const tag = ns !== null && this.tag === this.tag.toUpperCase() ? this.tag.toLowerCase() : this.tag;
1468
+ const attrs = this.attrs;
1469
+ const createOpts = attrs.is != null ? { is: attrs.is } : undefined;
1470
+ const node = ns === null ? doc.createElement(tag, createOpts) : doc.createElementNS(ns, tag, createOpts);
1471
+ const cOpts = childOpts(this, ns, opts);
1472
+ if ("value" in attrs || "checked" in attrs) {
1473
+ const { value, checked, ...rest } = attrs;
1474
+ applyProperties(node, rest);
1475
+ appendChildNodes(node, this.childs, cOpts);
1476
+ if (value !== undefined)
1477
+ applyValueLast(node, value);
1478
+ if (checked !== undefined)
1479
+ setProp(node, "checked", checked, false);
1454
1480
  } else {
1455
- applyProperties(node, this.attrs, {});
1456
- appendChildNodes(node, this.childs, opts);
1481
+ applyProperties(node, attrs);
1482
+ appendChildNodes(node, this.childs, cOpts);
1457
1483
  }
1458
1484
  return node;
1459
1485
  }
@@ -1490,18 +1516,37 @@ function morphNode(domNode, source, target, opts) {
1490
1516
  }
1491
1517
  if (type === 1 && source.isSameKind(target)) {
1492
1518
  const propsDiff = diffProps(source.attrs, target.attrs);
1493
- const isSelect = source.tag === "SELECT";
1519
+ let pendingValue;
1520
+ let pendingChecked;
1521
+ let applyValue = false;
1522
+ let applyChecked = false;
1494
1523
  if (propsDiff) {
1495
- if (isSelect && "value" in propsDiff) {
1496
- const { value: _v, ...rest } = propsDiff;
1497
- applyProperties(domNode, rest, source.attrs);
1524
+ if ("value" in propsDiff || "checked" in propsDiff) {
1525
+ const { value, checked, ...rest } = propsDiff;
1526
+ applyProperties(domNode, rest);
1527
+ if ("value" in propsDiff) {
1528
+ pendingValue = value;
1529
+ applyValue = true;
1530
+ }
1531
+ if ("checked" in propsDiff) {
1532
+ pendingChecked = checked;
1533
+ applyChecked = true;
1534
+ }
1498
1535
  } else
1499
- applyProperties(domNode, propsDiff, source.attrs);
1536
+ applyProperties(domNode, propsDiff);
1537
+ }
1538
+ if (!target.attrs.dangerouslySetInnerHTML) {
1539
+ const ns = effectiveNs(target, opts);
1540
+ morphChildren(domNode, source.childs, target.childs, childOpts(target, ns, opts));
1500
1541
  }
1501
- if (!target.attrs.dangerouslySetInnerHTML)
1502
- morphChildren(domNode, source.childs, target.childs, opts);
1503
- if (isSelect && target.attrs.value !== undefined)
1504
- applyProperties(domNode, { value: target.attrs.value }, source.attrs);
1542
+ if (!applyValue && source.tag === "SELECT" && target.attrs.value !== undefined) {
1543
+ pendingValue = target.attrs.value;
1544
+ applyValue = true;
1545
+ }
1546
+ if (applyValue)
1547
+ applyValueLast(domNode, pendingValue);
1548
+ if (applyChecked)
1549
+ setProp(domNode, "checked", pendingChecked, false);
1505
1550
  return domNode;
1506
1551
  }
1507
1552
  if (type === 11) {
@@ -1605,8 +1650,18 @@ function h(tagName, properties, children, namespace) {
1605
1650
  props[propName] = propVal;
1606
1651
  }
1607
1652
  }
1653
+ if (namespace == null) {
1654
+ const lower = tagName.toLowerCase();
1655
+ if (lower === "svg") {
1656
+ namespace = SVG_NS;
1657
+ tagName = "svg";
1658
+ } else if (lower === "math") {
1659
+ namespace = MATH_NS;
1660
+ tagName = "math";
1661
+ }
1662
+ }
1608
1663
  const c = tagName.charCodeAt(0);
1609
- const tag = namespace == null && c >= 97 && c <= 122 ? tagName.toUpperCase() : tagName;
1664
+ const tag = namespace == null && c >= 97 && c <= 122 && tagName === tagName.toLowerCase() ? tagName.toUpperCase() : tagName;
1610
1665
  const normalizedChildren = [];
1611
1666
  addChild(normalizedChildren, children);
1612
1667
  return new VNode(tag, props, normalizedChildren, key, namespace);
@@ -5546,10 +5546,18 @@ class RequestHandler {
5546
5546
 
5547
5547
  // src/vdom.js
5548
5548
  var HTML_NS = "http://www.w3.org/1999/xhtml";
5549
+ var SVG_NS = "http://www.w3.org/2000/svg";
5550
+ var MATH_NS = "http://www.w3.org/1998/Math/MathML";
5549
5551
  var isNamespaced = (node) => {
5550
5552
  const ns = node.namespaceURI;
5551
5553
  return ns !== null && ns !== HTML_NS;
5552
5554
  };
5555
+ var isForeignObject = (tag) => tag.length === 13 && tag.toLowerCase() === "foreignobject";
5556
+ var effectiveNs = (vnode, opts) => vnode.namespace ?? opts.namespace ?? null;
5557
+ function childOpts(vnode, ns, opts) {
5558
+ const target = ns === SVG_NS && isForeignObject(vnode.tag) ? null : ns;
5559
+ return target === (opts.namespace ?? null) ? opts : { ...opts, namespace: target };
5560
+ }
5553
5561
  var NEVER_ASSIGN = new Set([
5554
5562
  "width",
5555
5563
  "height",
@@ -5563,7 +5571,7 @@ var NEVER_ASSIGN = new Set([
5563
5571
  "role",
5564
5572
  "popover"
5565
5573
  ]);
5566
- function applyProperties(node, props, _previous) {
5574
+ function applyProperties(node, props) {
5567
5575
  const namespaced = isNamespaced(node);
5568
5576
  for (const name in props)
5569
5577
  setProp2(node, name, props[name], namespaced);
@@ -5572,8 +5580,11 @@ function setProp2(node, name, value, namespaced) {
5572
5580
  if (name === "dangerouslySetInnerHTML") {
5573
5581
  if (value === undefined)
5574
5582
  node.replaceChildren();
5575
- else
5576
- node.innerHTML = value.__html ?? "";
5583
+ else {
5584
+ const html = value.__html ?? "";
5585
+ if (html !== node.innerHTML)
5586
+ node.innerHTML = html;
5587
+ }
5577
5588
  return;
5578
5589
  }
5579
5590
  if (typeof value === "function")
@@ -5589,6 +5600,13 @@ function setProp2(node, name, value, namespaced) {
5589
5600
  else
5590
5601
  node.setAttribute(name, value);
5591
5602
  }
5603
+ function applyValueLast(node, value) {
5604
+ if (node.tagName === "PROGRESS" && (value == null || value === 0)) {
5605
+ node.removeAttribute("value");
5606
+ } else {
5607
+ setProp2(node, "value", value, isNamespaced(node));
5608
+ }
5609
+ }
5592
5610
 
5593
5611
  class VBase {
5594
5612
  }
@@ -5707,15 +5725,23 @@ class VNode2 extends VBase {
5707
5725
  }
5708
5726
  toDom(opts) {
5709
5727
  const doc = opts.document;
5710
- const node = this.namespace === null ? doc.createElement(this.tag) : doc.createElementNS(this.namespace, this.tag);
5711
- if (this.tag === "SELECT" && "value" in this.attrs) {
5712
- const { value, ...rest } = this.attrs;
5713
- applyProperties(node, rest, {});
5714
- appendChildNodes(node, this.childs, opts);
5715
- applyProperties(node, { value }, {});
5728
+ const ns = effectiveNs(this, opts);
5729
+ const tag = ns !== null && this.tag === this.tag.toUpperCase() ? this.tag.toLowerCase() : this.tag;
5730
+ const attrs = this.attrs;
5731
+ const createOpts = attrs.is != null ? { is: attrs.is } : undefined;
5732
+ const node = ns === null ? doc.createElement(tag, createOpts) : doc.createElementNS(ns, tag, createOpts);
5733
+ const cOpts = childOpts(this, ns, opts);
5734
+ if ("value" in attrs || "checked" in attrs) {
5735
+ const { value, checked, ...rest } = attrs;
5736
+ applyProperties(node, rest);
5737
+ appendChildNodes(node, this.childs, cOpts);
5738
+ if (value !== undefined)
5739
+ applyValueLast(node, value);
5740
+ if (checked !== undefined)
5741
+ setProp2(node, "checked", checked, false);
5716
5742
  } else {
5717
- applyProperties(node, this.attrs, {});
5718
- appendChildNodes(node, this.childs, opts);
5743
+ applyProperties(node, attrs);
5744
+ appendChildNodes(node, this.childs, cOpts);
5719
5745
  }
5720
5746
  return node;
5721
5747
  }
@@ -5752,18 +5778,37 @@ function morphNode(domNode, source, target, opts) {
5752
5778
  }
5753
5779
  if (type === 1 && source.isSameKind(target)) {
5754
5780
  const propsDiff = diffProps(source.attrs, target.attrs);
5755
- const isSelect = source.tag === "SELECT";
5781
+ let pendingValue;
5782
+ let pendingChecked;
5783
+ let applyValue = false;
5784
+ let applyChecked = false;
5756
5785
  if (propsDiff) {
5757
- if (isSelect && "value" in propsDiff) {
5758
- const { value: _v, ...rest } = propsDiff;
5759
- applyProperties(domNode, rest, source.attrs);
5786
+ if ("value" in propsDiff || "checked" in propsDiff) {
5787
+ const { value, checked, ...rest } = propsDiff;
5788
+ applyProperties(domNode, rest);
5789
+ if ("value" in propsDiff) {
5790
+ pendingValue = value;
5791
+ applyValue = true;
5792
+ }
5793
+ if ("checked" in propsDiff) {
5794
+ pendingChecked = checked;
5795
+ applyChecked = true;
5796
+ }
5760
5797
  } else
5761
- applyProperties(domNode, propsDiff, source.attrs);
5798
+ applyProperties(domNode, propsDiff);
5799
+ }
5800
+ if (!target.attrs.dangerouslySetInnerHTML) {
5801
+ const ns = effectiveNs(target, opts);
5802
+ morphChildren(domNode, source.childs, target.childs, childOpts(target, ns, opts));
5762
5803
  }
5763
- if (!target.attrs.dangerouslySetInnerHTML)
5764
- morphChildren(domNode, source.childs, target.childs, opts);
5765
- if (isSelect && target.attrs.value !== undefined)
5766
- applyProperties(domNode, { value: target.attrs.value }, source.attrs);
5804
+ if (!applyValue && source.tag === "SELECT" && target.attrs.value !== undefined) {
5805
+ pendingValue = target.attrs.value;
5806
+ applyValue = true;
5807
+ }
5808
+ if (applyValue)
5809
+ applyValueLast(domNode, pendingValue);
5810
+ if (applyChecked)
5811
+ setProp2(domNode, "checked", pendingChecked, false);
5767
5812
  return domNode;
5768
5813
  }
5769
5814
  if (type === 11) {
@@ -5867,8 +5912,18 @@ function h(tagName, properties, children, namespace) {
5867
5912
  props[propName] = propVal;
5868
5913
  }
5869
5914
  }
5915
+ if (namespace == null) {
5916
+ const lower = tagName.toLowerCase();
5917
+ if (lower === "svg") {
5918
+ namespace = SVG_NS;
5919
+ tagName = "svg";
5920
+ } else if (lower === "math") {
5921
+ namespace = MATH_NS;
5922
+ tagName = "math";
5923
+ }
5924
+ }
5870
5925
  const c = tagName.charCodeAt(0);
5871
- const tag = namespace == null && c >= 97 && c <= 122 ? tagName.toUpperCase() : tagName;
5926
+ const tag = namespace == null && c >= 97 && c <= 122 && tagName === tagName.toLowerCase() ? tagName.toUpperCase() : tagName;
5872
5927
  const normalizedChildren = [];
5873
5928
  addChild(normalizedChildren, children);
5874
5929
  return new VNode2(tag, props, normalizedChildren, key, namespace);