tutuca 0.9.67 → 0.9.69

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.
@@ -8841,10 +8841,18 @@ class RequestHandler {
8841
8841
 
8842
8842
  // src/vdom.js
8843
8843
  var HTML_NS = "http://www.w3.org/1999/xhtml";
8844
+ var SVG_NS = "http://www.w3.org/2000/svg";
8845
+ var MATH_NS = "http://www.w3.org/1998/Math/MathML";
8844
8846
  var isNamespaced = (node) => {
8845
8847
  const ns = node.namespaceURI;
8846
8848
  return ns !== null && ns !== HTML_NS;
8847
8849
  };
8850
+ var isForeignObject = (tag) => tag.length === 13 && tag.toLowerCase() === "foreignobject";
8851
+ var effectiveNs = (vnode, opts) => vnode.namespace ?? opts.namespace ?? null;
8852
+ function childOpts(vnode, ns, opts) {
8853
+ const target = ns === SVG_NS && isForeignObject(vnode.tag) ? null : ns;
8854
+ return target === (opts.namespace ?? null) ? opts : { ...opts, namespace: target };
8855
+ }
8848
8856
  var NEVER_ASSIGN = new Set([
8849
8857
  "width",
8850
8858
  "height",
@@ -8858,7 +8866,7 @@ var NEVER_ASSIGN = new Set([
8858
8866
  "role",
8859
8867
  "popover"
8860
8868
  ]);
8861
- function applyProperties(node, props, _previous) {
8869
+ function applyProperties(node, props) {
8862
8870
  const namespaced = isNamespaced(node);
8863
8871
  for (const name in props)
8864
8872
  setProp2(node, name, props[name], namespaced);
@@ -8867,8 +8875,11 @@ function setProp2(node, name, value, namespaced) {
8867
8875
  if (name === "dangerouslySetInnerHTML") {
8868
8876
  if (value === undefined)
8869
8877
  node.replaceChildren();
8870
- else
8871
- node.innerHTML = value.__html ?? "";
8878
+ else {
8879
+ const html = value.__html ?? "";
8880
+ if (html !== node.innerHTML)
8881
+ node.innerHTML = html;
8882
+ }
8872
8883
  return;
8873
8884
  }
8874
8885
  if (typeof value === "function")
@@ -8884,6 +8895,13 @@ function setProp2(node, name, value, namespaced) {
8884
8895
  else
8885
8896
  node.setAttribute(name, value);
8886
8897
  }
8898
+ function applyValueLast(node, value) {
8899
+ if (node.tagName === "PROGRESS" && (value == null || value === 0)) {
8900
+ node.removeAttribute("value");
8901
+ } else {
8902
+ setProp2(node, "value", value, isNamespaced(node));
8903
+ }
8904
+ }
8887
8905
 
8888
8906
  class VBase {
8889
8907
  }
@@ -9002,15 +9020,23 @@ class VNode2 extends VBase {
9002
9020
  }
9003
9021
  toDom(opts) {
9004
9022
  const doc = opts.document;
9005
- const node = this.namespace === null ? doc.createElement(this.tag) : doc.createElementNS(this.namespace, this.tag);
9006
- if (this.tag === "SELECT" && "value" in this.attrs) {
9007
- const { value, ...rest } = this.attrs;
9008
- applyProperties(node, rest, {});
9009
- appendChildNodes(node, this.childs, opts);
9010
- applyProperties(node, { value }, {});
9023
+ const ns = effectiveNs(this, opts);
9024
+ const tag = ns !== null && this.tag === this.tag.toUpperCase() ? this.tag.toLowerCase() : this.tag;
9025
+ const attrs = this.attrs;
9026
+ const createOpts = attrs.is != null ? { is: attrs.is } : undefined;
9027
+ const node = ns === null ? doc.createElement(tag, createOpts) : doc.createElementNS(ns, tag, createOpts);
9028
+ const cOpts = childOpts(this, ns, opts);
9029
+ if ("value" in attrs || "checked" in attrs) {
9030
+ const { value, checked, ...rest } = attrs;
9031
+ applyProperties(node, rest);
9032
+ appendChildNodes(node, this.childs, cOpts);
9033
+ if (value !== undefined)
9034
+ applyValueLast(node, value);
9035
+ if (checked !== undefined)
9036
+ setProp2(node, "checked", checked, false);
9011
9037
  } else {
9012
- applyProperties(node, this.attrs, {});
9013
- appendChildNodes(node, this.childs, opts);
9038
+ applyProperties(node, attrs);
9039
+ appendChildNodes(node, this.childs, cOpts);
9014
9040
  }
9015
9041
  return node;
9016
9042
  }
@@ -9047,18 +9073,37 @@ function morphNode(domNode, source, target, opts) {
9047
9073
  }
9048
9074
  if (type3 === 1 && source.isSameKind(target)) {
9049
9075
  const propsDiff = diffProps(source.attrs, target.attrs);
9050
- const isSelect = source.tag === "SELECT";
9076
+ let pendingValue;
9077
+ let pendingChecked;
9078
+ let applyValue = false;
9079
+ let applyChecked = false;
9051
9080
  if (propsDiff) {
9052
- if (isSelect && "value" in propsDiff) {
9053
- const { value: _v, ...rest } = propsDiff;
9054
- applyProperties(domNode, rest, source.attrs);
9081
+ if ("value" in propsDiff || "checked" in propsDiff) {
9082
+ const { value, checked, ...rest } = propsDiff;
9083
+ applyProperties(domNode, rest);
9084
+ if ("value" in propsDiff) {
9085
+ pendingValue = value;
9086
+ applyValue = true;
9087
+ }
9088
+ if ("checked" in propsDiff) {
9089
+ pendingChecked = checked;
9090
+ applyChecked = true;
9091
+ }
9055
9092
  } else
9056
- applyProperties(domNode, propsDiff, source.attrs);
9093
+ applyProperties(domNode, propsDiff);
9094
+ }
9095
+ if (!target.attrs.dangerouslySetInnerHTML) {
9096
+ const ns = effectiveNs(target, opts);
9097
+ morphChildren(domNode, source.childs, target.childs, childOpts(target, ns, opts));
9057
9098
  }
9058
- if (!target.attrs.dangerouslySetInnerHTML)
9059
- morphChildren(domNode, source.childs, target.childs, opts);
9060
- if (isSelect && target.attrs.value !== undefined)
9061
- applyProperties(domNode, { value: target.attrs.value }, source.attrs);
9099
+ if (!applyValue && source.tag === "SELECT" && target.attrs.value !== undefined) {
9100
+ pendingValue = target.attrs.value;
9101
+ applyValue = true;
9102
+ }
9103
+ if (applyValue)
9104
+ applyValueLast(domNode, pendingValue);
9105
+ if (applyChecked)
9106
+ setProp2(domNode, "checked", pendingChecked, false);
9062
9107
  return domNode;
9063
9108
  }
9064
9109
  if (type3 === 11) {
@@ -9162,8 +9207,18 @@ function h(tagName, properties, children, namespace) {
9162
9207
  props[propName] = propVal;
9163
9208
  }
9164
9209
  }
9210
+ if (namespace == null) {
9211
+ const lower = tagName.toLowerCase();
9212
+ if (lower === "svg") {
9213
+ namespace = SVG_NS;
9214
+ tagName = "svg";
9215
+ } else if (lower === "math") {
9216
+ namespace = MATH_NS;
9217
+ tagName = "math";
9218
+ }
9219
+ }
9165
9220
  const c = tagName.charCodeAt(0);
9166
- const tag = namespace == null && c >= 97 && c <= 122 ? tagName.toUpperCase() : tagName;
9221
+ const tag = namespace == null && c >= 97 && c <= 122 && tagName === tagName.toLowerCase() ? tagName.toUpperCase() : tagName;
9167
9222
  const normalizedChildren = [];
9168
9223
  addChild(normalizedChildren, children);
9169
9224
  return new VNode2(tag, props, normalizedChildren, key, namespace);
@@ -9415,16 +9470,16 @@ function parseXOpVal(opName, value, px, parserFn) {
9415
9470
  return val;
9416
9471
  }
9417
9472
  function processXExtras(node, attrs, opName, startIdx, px) {
9418
- const consumed = X_OP_CONSUMED[opName];
9419
- const wrappable = X_OP_WRAPPABLE.has(opName);
9473
+ const { consumed, wrappable } = X_OPS[opName];
9420
9474
  const wrappers = [];
9421
9475
  for (let i = startIdx;i < attrs.length; i++) {
9422
9476
  const a = attrs[i];
9423
9477
  const aName = a.name;
9424
9478
  if (consumed.has(aName))
9425
9479
  continue;
9426
- if (wrappable && X_ATTR_WRAPPERS[aName]) {
9427
- wrappers.push([X_ATTR_WRAPPERS[aName], vp.parseBool(a.value, px)]);
9480
+ const wrapper = wrappable ? X_OPS[aName]?.wrapper : null;
9481
+ if (wrapper) {
9482
+ wrappers.push([wrapper, vp.parseBool(a.value, px)]);
9428
9483
  continue;
9429
9484
  }
9430
9485
  const issueInfo = { op: opName, name: aName, value: a.value };
@@ -9516,6 +9571,12 @@ class RenderViewId extends ANode {
9516
9571
  }
9517
9572
  setDataAttr(_key, _val) {}
9518
9573
  }
9574
+ function dynRenderStep(comp, name, key) {
9575
+ const p = resolveDynProducer(comp, name);
9576
+ if (!p)
9577
+ return null;
9578
+ return key === undefined ? new DynStep(p.producerCompId, p.producerSteps) : new DynEachStep(p.producerCompId, p.producerSteps, key);
9579
+ }
9519
9580
 
9520
9581
  class RenderNode extends RenderViewId {
9521
9582
  render(stack, rx) {
@@ -9523,10 +9584,8 @@ class RenderNode extends RenderViewId {
9523
9584
  return rx.renderIt(newStack, this, "", this.viewId);
9524
9585
  }
9525
9586
  toPathStep(ctx) {
9526
- if (this.val instanceof DynVal) {
9527
- const p = resolveDynProducer(ctx.comp, this.val.name);
9528
- return p ? new DynStep(p.producerCompId, p.producerSteps) : null;
9529
- }
9587
+ if (this.val instanceof DynVal)
9588
+ return dynRenderStep(ctx.comp, this.val.name);
9530
9589
  return super.toPathStep(ctx);
9531
9590
  }
9532
9591
  }
@@ -9542,10 +9601,8 @@ class RenderItNode extends RenderViewId {
9542
9601
  return null;
9543
9602
  const nextNode = next.resolveNode();
9544
9603
  if (nextNode instanceof EachNode && next.hasKey) {
9545
- if (nextNode.val instanceof DynVal) {
9546
- const p = resolveDynProducer(ctx.comp, nextNode.val.name);
9547
- return p ? new DynEachStep(p.producerCompId, p.producerSteps, next.key) : null;
9548
- }
9604
+ if (nextNode.val instanceof DynVal)
9605
+ return dynRenderStep(ctx.comp, nextNode.val.name, next.key);
9549
9606
  return new EachRenderItStep(nextNode.val.name, next.key);
9550
9607
  }
9551
9608
  return null;
@@ -9561,12 +9618,8 @@ class RenderEachNode extends RenderViewId {
9561
9618
  return rx.renderEach(stack, this.iterInfo, this, this.viewId);
9562
9619
  }
9563
9620
  toPathStep(ctx) {
9564
- if (this.val instanceof DynVal) {
9565
- if (!ctx.hasKey)
9566
- return null;
9567
- const p = resolveDynProducer(ctx.comp, this.val.name);
9568
- return p ? new DynEachStep(p.producerCompId, p.producerSteps, ctx.key) : null;
9569
- }
9621
+ if (this.val instanceof DynVal)
9622
+ return ctx.hasKey ? dynRenderStep(ctx.comp, this.val.name, ctx.key) : null;
9570
9623
  return super.toPathStep(ctx);
9571
9624
  }
9572
9625
  static parse(px, vp2, s, as, attrs) {
@@ -9696,17 +9749,18 @@ class IterInfo {
9696
9749
  }
9697
9750
  var filterAlwaysTrue = (_v, _k, _seq) => true;
9698
9751
  var nullLoopWith = (seq) => ({ iterData: { seq } });
9699
- var X_OP_CONSUMED = {
9700
- slot: new Set,
9701
- text: new Set,
9702
- render: new Set(["as"]),
9703
- "render-it": new Set(["as"]),
9704
- "render-each": new Set(["as", "when", "loop-with"]),
9705
- show: new Set,
9706
- hide: new Set
9707
- };
9708
- var X_OP_WRAPPABLE = new Set(["text", "render", "render-it", "render-each"]);
9709
- var X_ATTR_WRAPPERS = { show: ShowNode, hide: HideNode };
9752
+ function xOp(consumed = [], { wrappable = false, wrapper = null } = {}) {
9753
+ return { consumed: new Set(consumed), wrappable, wrapper };
9754
+ }
9755
+ var X_OPS = {
9756
+ slot: xOp(),
9757
+ text: xOp([], { wrappable: true }),
9758
+ render: xOp(["as"], { wrappable: true }),
9759
+ "render-it": xOp(["as"], { wrappable: true }),
9760
+ "render-each": xOp(["as", "when", "loop-with"], { wrappable: true }),
9761
+ show: xOp([], { wrapper: ShowNode }),
9762
+ hide: xOp([], { wrapper: HideNode })
9763
+ };
9710
9764
  var WRAPPER_NODES = {
9711
9765
  slot: SlotNode,
9712
9766
  show: ShowNode,
@@ -9794,29 +9848,30 @@ var isBlockDomNode = (n) => {
9794
9848
  const node = n instanceof FragmentNode ? n.childs[0] : n;
9795
9849
  return node instanceof DomNode && HTML_BLOCK_TAGS.has(node.tagName);
9796
9850
  };
9851
+ var isEmptyText = (c) => c instanceof TextNode && c.val === "";
9852
+ function trimEdgeWhite(node) {
9853
+ if (!node.isWhiteSpace?.())
9854
+ return false;
9855
+ node.condenseWhiteSpace();
9856
+ return true;
9857
+ }
9797
9858
  function condenseChildsWhites(childs) {
9798
9859
  if (childs.length === 0)
9799
9860
  return childs;
9800
- let changed = false;
9801
- if (childs[0].isWhiteSpace?.()) {
9802
- childs[0].condenseWhiteSpace();
9803
- changed = true;
9804
- }
9805
9861
  const last = childs.length - 1;
9806
- if (last > 0 && childs[last].isWhiteSpace?.()) {
9807
- childs[last].condenseWhiteSpace();
9808
- changed = true;
9809
- }
9862
+ let emptied = trimEdgeWhite(childs[0]);
9863
+ if (last > 0 && trimEdgeWhite(childs[last]))
9864
+ emptied = true;
9810
9865
  for (let i = 1;i < last; i++) {
9811
9866
  const cur = childs[i];
9812
- if (cur.isWhiteSpace?.() && cur.hasNewLine()) {
9813
- const bothBlock = isBlockDomNode(childs[i - 1]) && isBlockDomNode(childs[i + 1]);
9814
- cur.condenseWhiteSpace(bothBlock ? "" : " ");
9815
- if (bothBlock)
9816
- changed = true;
9817
- }
9867
+ if (!(cur.isWhiteSpace?.() && cur.hasNewLine()))
9868
+ continue;
9869
+ const bothBlock = isBlockDomNode(childs[i - 1]) && isBlockDomNode(childs[i + 1]);
9870
+ cur.condenseWhiteSpace(bothBlock ? "" : " ");
9871
+ if (bothBlock)
9872
+ emptied = true;
9818
9873
  }
9819
- return changed ? childs.filter((c) => !(c instanceof TextNode && c.val === "")) : childs;
9874
+ return emptied ? childs.filter((c) => !isEmptyText(c)) : childs;
9820
9875
  }
9821
9876
 
9822
9877
  class View {