tutuca 0.9.63 → 0.9.65

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.
@@ -5528,6 +5528,337 @@ class RequestHandler {
5528
5528
  }
5529
5529
  }
5530
5530
 
5531
+ // src/vdom.js
5532
+ var isHtmlAttribute = (propName) => propName[4] === "-" && (propName[0] === "d" || propName[0] === "a");
5533
+ var HTML_NS = "http://www.w3.org/1999/xhtml";
5534
+ var isNamespaced = (node) => {
5535
+ const ns = node.namespaceURI;
5536
+ return ns !== null && ns !== HTML_NS;
5537
+ };
5538
+ function applyProperties(node, props, previous) {
5539
+ const namespaced = isNamespaced(node);
5540
+ for (const propName in props) {
5541
+ const propValue = props[propName];
5542
+ if (propValue === undefined)
5543
+ removeProperty(node, propName, previous);
5544
+ else if (propName === "dangerouslySetInnerHTML")
5545
+ node.innerHTML = propValue.__html ?? "";
5546
+ else if (propName === "className")
5547
+ node.setAttribute("class", propValue);
5548
+ else if (namespaced || isHtmlAttribute(propName))
5549
+ node.setAttribute(propName, propValue);
5550
+ else
5551
+ node[propName] = propValue;
5552
+ }
5553
+ }
5554
+ function removeProperty(node, propName, previous) {
5555
+ const previousValue = previous[propName];
5556
+ if (propName === "dangerouslySetInnerHTML")
5557
+ node.replaceChildren();
5558
+ else if (propName === "className")
5559
+ node.removeAttribute("class");
5560
+ else if (propName === "htmlFor")
5561
+ node.removeAttribute("for");
5562
+ else if (isNamespaced(node) || typeof previousValue === "string" || isHtmlAttribute(propName))
5563
+ node.removeAttribute(propName);
5564
+ else
5565
+ node[propName] = null;
5566
+ }
5567
+
5568
+ class VBase {
5569
+ }
5570
+ var getKey = (child) => child instanceof VNode2 ? child.key : undefined;
5571
+ var isIterable = (obj) => obj != null && typeof obj !== "string" && typeof obj[Symbol.iterator] === "function";
5572
+ function childsEqual(a, b) {
5573
+ if (a === b)
5574
+ return true;
5575
+ for (let i = 0;i < a.length; i++)
5576
+ if (!a[i].isEqualTo(b[i]))
5577
+ return false;
5578
+ return true;
5579
+ }
5580
+ function appendChildNodes(parent, childs, opts) {
5581
+ for (const child of childs)
5582
+ parent.appendChild(child.toDom(opts));
5583
+ }
5584
+ function addChild(normalizedChildren, child) {
5585
+ if (child == null)
5586
+ return;
5587
+ if (isIterable(child)) {
5588
+ for (const c of child)
5589
+ addChild(normalizedChildren, c);
5590
+ } else if (child instanceof VBase) {
5591
+ if (child instanceof VFragment)
5592
+ normalizedChildren.push(...child.childs);
5593
+ else
5594
+ normalizedChildren.push(child);
5595
+ } else
5596
+ normalizedChildren.push(new VText(child));
5597
+ }
5598
+
5599
+ class VText extends VBase {
5600
+ constructor(text) {
5601
+ super();
5602
+ this.text = String(text);
5603
+ }
5604
+ get nodeType() {
5605
+ return 3;
5606
+ }
5607
+ isEqualTo(other) {
5608
+ return other instanceof VText && this.text === other.text;
5609
+ }
5610
+ toDom(opts) {
5611
+ return opts.document.createTextNode(this.text);
5612
+ }
5613
+ }
5614
+
5615
+ class VComment extends VBase {
5616
+ constructor(text) {
5617
+ super();
5618
+ this.text = text;
5619
+ }
5620
+ get nodeType() {
5621
+ return 8;
5622
+ }
5623
+ isEqualTo(other) {
5624
+ return other instanceof VComment && this.text === other.text;
5625
+ }
5626
+ toDom(opts) {
5627
+ return opts.document.createComment(this.text);
5628
+ }
5629
+ }
5630
+
5631
+ class VFragment extends VBase {
5632
+ constructor(childs) {
5633
+ super();
5634
+ this.childs = [];
5635
+ addChild(this.childs, childs);
5636
+ }
5637
+ get nodeType() {
5638
+ return 11;
5639
+ }
5640
+ isEqualTo(other) {
5641
+ if (!(other instanceof VFragment) || this.childs.length !== other.childs.length)
5642
+ return false;
5643
+ return childsEqual(this.childs, other.childs);
5644
+ }
5645
+ toDom(opts) {
5646
+ const fragment = opts.document.createDocumentFragment();
5647
+ appendChildNodes(fragment, this.childs, opts);
5648
+ return fragment;
5649
+ }
5650
+ }
5651
+
5652
+ class VNode2 extends VBase {
5653
+ constructor(tag, attrs, childs, key, namespace) {
5654
+ super();
5655
+ this.tag = tag;
5656
+ this.attrs = attrs ?? {};
5657
+ this.childs = childs ?? [];
5658
+ this.key = key != null ? String(key) : undefined;
5659
+ this.namespace = typeof namespace === "string" ? namespace : null;
5660
+ }
5661
+ get nodeType() {
5662
+ return 1;
5663
+ }
5664
+ isSameKind(other) {
5665
+ return this.tag === other.tag && this.namespace === other.namespace && this.key === other.key;
5666
+ }
5667
+ isEqualTo(other) {
5668
+ if (this === other)
5669
+ return true;
5670
+ if (!(other instanceof VNode2) || !this.isSameKind(other) || this.childs.length !== other.childs.length) {
5671
+ return false;
5672
+ }
5673
+ if (this.attrs !== other.attrs) {
5674
+ for (const key in this.attrs)
5675
+ if (this.attrs[key] !== other.attrs[key])
5676
+ return false;
5677
+ for (const key in other.attrs)
5678
+ if (!Object.hasOwn(this.attrs, key))
5679
+ return false;
5680
+ }
5681
+ return childsEqual(this.childs, other.childs);
5682
+ }
5683
+ toDom(opts) {
5684
+ const doc = opts.document;
5685
+ const node = this.namespace === null ? doc.createElement(this.tag) : doc.createElementNS(this.namespace, this.tag);
5686
+ if (this.tag === "SELECT" && "value" in this.attrs) {
5687
+ const { value, ...rest } = this.attrs;
5688
+ applyProperties(node, rest, {});
5689
+ appendChildNodes(node, this.childs, opts);
5690
+ applyProperties(node, { value }, {});
5691
+ } else {
5692
+ applyProperties(node, this.attrs, {});
5693
+ appendChildNodes(node, this.childs, opts);
5694
+ }
5695
+ return node;
5696
+ }
5697
+ }
5698
+ function diffProps(a, b) {
5699
+ if (a === b)
5700
+ return null;
5701
+ let diff = null;
5702
+ for (const aKey in a) {
5703
+ if (!Object.hasOwn(b, aKey)) {
5704
+ diff ??= {};
5705
+ diff[aKey] = undefined;
5706
+ } else if (a[aKey] !== b[aKey]) {
5707
+ diff ??= {};
5708
+ diff[aKey] = b[aKey];
5709
+ }
5710
+ }
5711
+ for (const bKey in b) {
5712
+ if (!Object.hasOwn(a, bKey)) {
5713
+ diff ??= {};
5714
+ diff[bKey] = b[bKey];
5715
+ }
5716
+ }
5717
+ return diff;
5718
+ }
5719
+ function morphNode(domNode, source, target, opts) {
5720
+ if (source === target || source.isEqualTo(target))
5721
+ return domNode;
5722
+ const type = source.nodeType;
5723
+ if (type === target.nodeType) {
5724
+ if (type === 3 || type === 8) {
5725
+ domNode.data = target.text;
5726
+ return domNode;
5727
+ }
5728
+ if (type === 1 && source.isSameKind(target)) {
5729
+ const propsDiff = diffProps(source.attrs, target.attrs);
5730
+ const isSelect = source.tag === "SELECT";
5731
+ if (propsDiff) {
5732
+ if (isSelect && "value" in propsDiff) {
5733
+ const { value: _v, ...rest } = propsDiff;
5734
+ applyProperties(domNode, rest, source.attrs);
5735
+ } else
5736
+ applyProperties(domNode, propsDiff, source.attrs);
5737
+ }
5738
+ if (!target.attrs.dangerouslySetInnerHTML)
5739
+ morphChildren(domNode, source.childs, target.childs, opts);
5740
+ if (isSelect && target.attrs.value !== undefined)
5741
+ applyProperties(domNode, { value: target.attrs.value }, source.attrs);
5742
+ return domNode;
5743
+ }
5744
+ if (type === 11) {
5745
+ morphChildren(domNode, source.childs, target.childs, opts);
5746
+ return domNode;
5747
+ }
5748
+ }
5749
+ const newNode = target.toDom(opts);
5750
+ domNode.parentNode?.replaceChild(newNode, domNode);
5751
+ return newNode;
5752
+ }
5753
+ function morphChildren(parentDom, oldChilds, newChilds, opts) {
5754
+ if (oldChilds.length === 0) {
5755
+ appendChildNodes(parentDom, newChilds, opts);
5756
+ return;
5757
+ }
5758
+ if (newChilds.length === 0) {
5759
+ parentDom.replaceChildren();
5760
+ return;
5761
+ }
5762
+ if (oldChilds.length === newChilds.length) {
5763
+ let hasKey = false;
5764
+ for (let i = 0;i < oldChilds.length; i++) {
5765
+ if (getKey(oldChilds[i]) != null || getKey(newChilds[i]) != null) {
5766
+ hasKey = true;
5767
+ break;
5768
+ }
5769
+ }
5770
+ if (!hasKey) {
5771
+ let dom = parentDom.firstChild;
5772
+ for (let i = 0;i < oldChilds.length; i++) {
5773
+ const next = dom.nextSibling;
5774
+ morphNode(dom, oldChilds[i], newChilds[i], opts);
5775
+ dom = next;
5776
+ }
5777
+ return;
5778
+ }
5779
+ }
5780
+ const domNodes = Array.from(parentDom.childNodes);
5781
+ const oldKeyMap = Object.create(null);
5782
+ for (let i = 0;i < oldChilds.length; i++) {
5783
+ const key = getKey(oldChilds[i]);
5784
+ if (key != null)
5785
+ oldKeyMap[key] = i;
5786
+ }
5787
+ const used = new Uint8Array(oldChilds.length);
5788
+ let unkeyedCursor = 0;
5789
+ for (let j = 0;j < newChilds.length; j++) {
5790
+ const newChild = newChilds[j];
5791
+ const newKey = getKey(newChild);
5792
+ let oldIdx = -1;
5793
+ if (newKey != null) {
5794
+ if (newKey in oldKeyMap && !used[oldKeyMap[newKey]])
5795
+ oldIdx = oldKeyMap[newKey];
5796
+ } else {
5797
+ while (unkeyedCursor < oldChilds.length) {
5798
+ if (!used[unkeyedCursor] && getKey(oldChilds[unkeyedCursor]) == null) {
5799
+ oldIdx = unkeyedCursor++;
5800
+ break;
5801
+ }
5802
+ unkeyedCursor++;
5803
+ }
5804
+ }
5805
+ if (oldIdx >= 0) {
5806
+ used[oldIdx] = 1;
5807
+ const newDom = morphNode(domNodes[oldIdx], oldChilds[oldIdx], newChild, opts);
5808
+ const ref = parentDom.childNodes[j] ?? null;
5809
+ if (newDom !== ref)
5810
+ parentDom.insertBefore(newDom, ref);
5811
+ } else {
5812
+ const ref = parentDom.childNodes[j] ?? null;
5813
+ parentDom.insertBefore(newChild.toDom(opts), ref);
5814
+ }
5815
+ }
5816
+ for (let i = oldChilds.length - 1;i >= 0; i--)
5817
+ if (!used[i] && domNodes[i].parentNode === parentDom)
5818
+ parentDom.removeChild(domNodes[i]);
5819
+ }
5820
+ function render(vnode, container, options, prev) {
5821
+ const isFragment = vnode instanceof VFragment;
5822
+ if (prev && prev.vnode instanceof VFragment === isFragment) {
5823
+ const oldDom = isFragment ? container : prev.dom;
5824
+ const newDom = morphNode(oldDom, prev.vnode, vnode, options);
5825
+ return { vnode, dom: isFragment ? container : newDom };
5826
+ }
5827
+ const domNode = vnode.toDom(options);
5828
+ container.replaceChildren(domNode);
5829
+ return { vnode, dom: isFragment ? container : domNode };
5830
+ }
5831
+ function h(tagName, properties, children, namespace) {
5832
+ const props = {};
5833
+ let key;
5834
+ if (properties) {
5835
+ for (const propName in properties) {
5836
+ const propVal = properties[propName];
5837
+ switch (propName) {
5838
+ case "key":
5839
+ key = propVal;
5840
+ break;
5841
+ case "namespace":
5842
+ namespace = namespace ?? propVal;
5843
+ break;
5844
+ case "class":
5845
+ props.className = propVal;
5846
+ break;
5847
+ case "for":
5848
+ props.htmlFor = propVal;
5849
+ break;
5850
+ default:
5851
+ props[propName] = isHtmlAttribute(propName) ? String(propVal) : propVal;
5852
+ }
5853
+ }
5854
+ }
5855
+ const c = tagName.charCodeAt(0);
5856
+ const tag = namespace == null && c >= 97 && c <= 122 ? tagName.toUpperCase() : tagName;
5857
+ const normalizedChildren = [];
5858
+ addChild(normalizedChildren, children);
5859
+ return new VNode2(tag, props, normalizedChildren, key, namespace);
5860
+ }
5861
+
5531
5862
  // src/anode.js
5532
5863
  function resolveDynProducer(comp, dynName) {
5533
5864
  const dyn = comp?.dynamic?.[dynName];
@@ -5628,16 +5959,17 @@ class ChildsNode extends BaseNode {
5628
5959
  }
5629
5960
 
5630
5961
  class DomNode extends ChildsNode {
5631
- constructor(tagName, attrs, childs) {
5962
+ constructor(tagName, attrs, childs, namespace = null) {
5632
5963
  super(childs);
5633
5964
  this.tagName = tagName;
5634
5965
  this.attrs = attrs;
5966
+ this.namespace = namespace;
5635
5967
  }
5636
5968
  render(stack, rx) {
5637
5969
  const childNodes = new Array(this.childs.length);
5638
5970
  for (let i = 0;i < childNodes.length; i++)
5639
5971
  childNodes[i] = this.childs[i]?.render?.(stack, rx) ?? null;
5640
- return rx.renderTag(this.tagName, this.attrs.eval(stack), childNodes);
5972
+ return rx.renderTag(this.tagName, this.attrs.eval(stack), childNodes, this.namespace);
5641
5973
  }
5642
5974
  setDataAttr(key, val) {
5643
5975
  this.attrs.setDataAttr(key, val);
@@ -5718,7 +6050,9 @@ class ANode extends BaseNode {
5718
6050
  if (textChild)
5719
6051
  childs.unshift(new RenderTextNode(null, textChild));
5720
6052
  const domChilds = tag !== "PRE" ? condenseChildsWhites(childs) : childs;
5721
- return wrap(new DomNode(tag, nAttrs, domChilds), px, wrappers);
6053
+ const ns = node.namespaceURI;
6054
+ const namespace = ns && ns !== HTML_NS ? ns : null;
6055
+ return wrap(new DomNode(tag, nAttrs, domChilds, namespace), px, wrappers);
5722
6056
  }
5723
6057
  return new CommentNode(`Error: InvalidTagName ${tag}`);
5724
6058
  } finally {
@@ -6049,7 +6383,7 @@ class IterInfo {
6049
6383
  }
6050
6384
  }
6051
6385
  var filterAlwaysTrue = (_v, _k, _seq) => true;
6052
- var nullLoopWith = (seq) => ({ seq });
6386
+ var nullLoopWith = (seq) => ({ iterData: { seq } });
6053
6387
  var X_OP_CONSUMED = {
6054
6388
  slot: new Set,
6055
6389
  text: new Set,
@@ -6856,403 +7190,78 @@ class Task {
6856
7190
  });
6857
7191
  this.isCompleted = false;
6858
7192
  }
6859
- addDep(task) {
6860
- console.assert(!this.isCompleted, "addDep for completed task", this, task);
6861
- this.deps.push(task);
6862
- task.promise.then((_) => this._check());
6863
- }
6864
- complete(val) {
6865
- this.val = val;
6866
- this._check();
6867
- }
6868
- _check() {
6869
- if (this.deps.every((task) => task.isCompleted)) {
6870
- this.isCompleted = true;
6871
- this.resolve(this);
6872
- }
6873
- }
6874
- }
6875
-
6876
- class Dispatcher {
6877
- constructor(path, transactor, parentTransaction) {
6878
- this.path = path;
6879
- this.transactor = transactor;
6880
- this.parent = parentTransaction;
6881
- }
6882
- get at() {
6883
- return new PathChanges(this);
6884
- }
6885
- send(name, args, opts) {
6886
- return this.sendAtPath(this.path, name, args, opts);
6887
- }
6888
- bubble(name, args, opts) {
6889
- return this.send(name, args, { skipSelf: true, bubbles: true, ...opts });
6890
- }
6891
- sendAtPath(path, name, args, opts) {
6892
- return this.transactor.pushSend(path, name, args, opts, this.parent);
6893
- }
6894
- request(name, args, opts) {
6895
- return this.requestAtPath(this.path, name, args, opts);
6896
- }
6897
- requestAtPath(path, name, args, opts) {
6898
- return this.transactor.pushRequest(path, name, args, opts, this.parent);
6899
- }
6900
- lookupTypeFor(name, inst) {
6901
- return this.transactor.comps.getCompFor(inst).scope.lookupComponent(name);
6902
- }
6903
- }
6904
-
6905
- class EventContext extends Dispatcher {
6906
- get name() {
6907
- return this.parent?.name ?? null;
6908
- }
6909
- get targetPath() {
6910
- return this.parent.targetPath;
6911
- }
6912
- stopPropagation() {
6913
- return this.parent.stopPropagation();
6914
- }
6915
- }
6916
-
6917
- class PathChanges extends PathBuilder {
6918
- constructor(dispatcher) {
6919
- super();
6920
- this.dispatcher = dispatcher;
6921
- }
6922
- send(name, args, opts) {
6923
- return this.dispatcher.sendAtPath(this.buildPath(), name, args, opts);
6924
- }
6925
- bubble(name, args, opts) {
6926
- return this.send(name, args, { skipSelf: true, bubbles: true, ...opts });
6927
- }
6928
- buildPath() {
6929
- return this.dispatcher.path.concat(this.pathChanges);
6930
- }
6931
- }
6932
-
6933
- // src/vdom.js
6934
- var isHtmlAttribute = (propName) => propName[4] === "-" && (propName[0] === "d" || propName[0] === "a");
6935
- function applyProperties(node, props, previous) {
6936
- for (const propName in props) {
6937
- const propValue = props[propName];
6938
- if (propValue === undefined)
6939
- removeProperty(node, propName, previous);
6940
- else if (isHtmlAttribute(propName))
6941
- node.setAttribute(propName, propValue);
6942
- else if (propName === "dangerouslySetInnerHTML")
6943
- node.innerHTML = propValue.__html ?? "";
6944
- else if (propName === "className")
6945
- node.setAttribute("class", propValue);
6946
- else
6947
- node[propName] = propValue;
6948
- }
6949
- }
6950
- function removeProperty(node, propName, previous) {
6951
- const previousValue = previous[propName];
6952
- if (propName === "dangerouslySetInnerHTML")
6953
- node.replaceChildren();
6954
- else if (propName === "className")
6955
- node.removeAttribute("class");
6956
- else if (propName === "htmlFor")
6957
- node.removeAttribute("for");
6958
- else if (typeof previousValue === "string" || isHtmlAttribute(propName))
6959
- node.removeAttribute(propName);
6960
- else
6961
- node[propName] = null;
6962
- }
6963
-
6964
- class VBase {
6965
- }
6966
- var getKey = (child) => child instanceof VNode2 ? child.key : undefined;
6967
- var isIterable = (obj) => obj != null && typeof obj !== "string" && typeof obj[Symbol.iterator] === "function";
6968
- function childsEqual(a, b) {
6969
- if (a === b)
6970
- return true;
6971
- for (let i = 0;i < a.length; i++)
6972
- if (!a[i].isEqualTo(b[i]))
6973
- return false;
6974
- return true;
6975
- }
6976
- function appendChildNodes(parent, childs, opts) {
6977
- for (const child of childs)
6978
- parent.appendChild(child.toDom(opts));
6979
- }
6980
- function addChild(normalizedChildren, child) {
6981
- if (child == null)
6982
- return;
6983
- if (isIterable(child)) {
6984
- for (const c of child)
6985
- addChild(normalizedChildren, c);
6986
- } else if (child instanceof VBase) {
6987
- if (child instanceof VFragment)
6988
- normalizedChildren.push(...child.childs);
6989
- else
6990
- normalizedChildren.push(child);
6991
- } else
6992
- normalizedChildren.push(new VText(child));
6993
- }
6994
-
6995
- class VText extends VBase {
6996
- constructor(text) {
6997
- super();
6998
- this.text = String(text);
6999
- }
7000
- get nodeType() {
7001
- return 3;
7002
- }
7003
- isEqualTo(other) {
7004
- return other instanceof VText && this.text === other.text;
7005
- }
7006
- toDom(opts) {
7007
- return opts.document.createTextNode(this.text);
7008
- }
7009
- }
7010
-
7011
- class VComment extends VBase {
7012
- constructor(text) {
7013
- super();
7014
- this.text = text;
7015
- }
7016
- get nodeType() {
7017
- return 8;
7018
- }
7019
- isEqualTo(other) {
7020
- return other instanceof VComment && this.text === other.text;
7021
- }
7022
- toDom(opts) {
7023
- return opts.document.createComment(this.text);
7024
- }
7025
- }
7026
-
7027
- class VFragment extends VBase {
7028
- constructor(childs) {
7029
- super();
7030
- this.childs = [];
7031
- addChild(this.childs, childs);
7032
- }
7033
- get nodeType() {
7034
- return 11;
7035
- }
7036
- isEqualTo(other) {
7037
- if (!(other instanceof VFragment) || this.childs.length !== other.childs.length)
7038
- return false;
7039
- return childsEqual(this.childs, other.childs);
7193
+ addDep(task) {
7194
+ console.assert(!this.isCompleted, "addDep for completed task", this, task);
7195
+ this.deps.push(task);
7196
+ task.promise.then((_) => this._check());
7040
7197
  }
7041
- toDom(opts) {
7042
- const fragment = opts.document.createDocumentFragment();
7043
- appendChildNodes(fragment, this.childs, opts);
7044
- return fragment;
7198
+ complete(val) {
7199
+ this.val = val;
7200
+ this._check();
7201
+ }
7202
+ _check() {
7203
+ if (this.deps.every((task) => task.isCompleted)) {
7204
+ this.isCompleted = true;
7205
+ this.resolve(this);
7206
+ }
7045
7207
  }
7046
7208
  }
7047
7209
 
7048
- class VNode2 extends VBase {
7049
- constructor(tag, attrs, childs, key, namespace) {
7050
- super();
7051
- this.tag = tag;
7052
- this.attrs = attrs ?? {};
7053
- this.childs = childs ?? [];
7054
- this.key = key != null ? String(key) : undefined;
7055
- this.namespace = typeof namespace === "string" ? namespace : null;
7210
+ class Dispatcher {
7211
+ constructor(path, transactor, parentTransaction) {
7212
+ this.path = path;
7213
+ this.transactor = transactor;
7214
+ this.parent = parentTransaction;
7056
7215
  }
7057
- get nodeType() {
7058
- return 1;
7216
+ get at() {
7217
+ return new PathChanges(this);
7059
7218
  }
7060
- isSameKind(other) {
7061
- return this.tag === other.tag && this.namespace === other.namespace && this.key === other.key;
7219
+ send(name, args, opts) {
7220
+ return this.sendAtPath(this.path, name, args, opts);
7062
7221
  }
7063
- isEqualTo(other) {
7064
- if (this === other)
7065
- return true;
7066
- if (!(other instanceof VNode2) || !this.isSameKind(other) || this.childs.length !== other.childs.length) {
7067
- return false;
7068
- }
7069
- if (this.attrs !== other.attrs) {
7070
- for (const key in this.attrs)
7071
- if (this.attrs[key] !== other.attrs[key])
7072
- return false;
7073
- for (const key in other.attrs)
7074
- if (!Object.hasOwn(this.attrs, key))
7075
- return false;
7076
- }
7077
- return childsEqual(this.childs, other.childs);
7222
+ bubble(name, args, opts) {
7223
+ return this.send(name, args, { skipSelf: true, bubbles: true, ...opts });
7078
7224
  }
7079
- toDom(opts) {
7080
- const doc = opts.document;
7081
- const node = this.namespace === null ? doc.createElement(this.tag) : doc.createElementNS(this.namespace, this.tag);
7082
- if (this.tag === "SELECT" && "value" in this.attrs) {
7083
- const { value, ...rest } = this.attrs;
7084
- applyProperties(node, rest, {});
7085
- appendChildNodes(node, this.childs, opts);
7086
- applyProperties(node, { value }, {});
7087
- } else {
7088
- applyProperties(node, this.attrs, {});
7089
- appendChildNodes(node, this.childs, opts);
7090
- }
7091
- return node;
7225
+ sendAtPath(path, name, args, opts) {
7226
+ return this.transactor.pushSend(path, name, args, opts, this.parent);
7092
7227
  }
7093
- }
7094
- function diffProps(a, b) {
7095
- if (a === b)
7096
- return null;
7097
- let diff = null;
7098
- for (const aKey in a) {
7099
- if (!Object.hasOwn(b, aKey)) {
7100
- diff ??= {};
7101
- diff[aKey] = undefined;
7102
- } else if (a[aKey] !== b[aKey]) {
7103
- diff ??= {};
7104
- diff[aKey] = b[aKey];
7105
- }
7228
+ request(name, args, opts) {
7229
+ return this.requestAtPath(this.path, name, args, opts);
7106
7230
  }
7107
- for (const bKey in b) {
7108
- if (!Object.hasOwn(a, bKey)) {
7109
- diff ??= {};
7110
- diff[bKey] = b[bKey];
7111
- }
7231
+ requestAtPath(path, name, args, opts) {
7232
+ return this.transactor.pushRequest(path, name, args, opts, this.parent);
7112
7233
  }
7113
- return diff;
7114
- }
7115
- function morphNode(domNode, source, target, opts) {
7116
- if (source === target || source.isEqualTo(target))
7117
- return domNode;
7118
- const type = source.nodeType;
7119
- if (type === target.nodeType) {
7120
- if (type === 3 || type === 8) {
7121
- domNode.data = target.text;
7122
- return domNode;
7123
- }
7124
- if (type === 1 && source.isSameKind(target)) {
7125
- const propsDiff = diffProps(source.attrs, target.attrs);
7126
- const isSelect = source.tag === "SELECT";
7127
- if (propsDiff) {
7128
- if (isSelect && "value" in propsDiff) {
7129
- const { value: _v, ...rest } = propsDiff;
7130
- applyProperties(domNode, rest, source.attrs);
7131
- } else
7132
- applyProperties(domNode, propsDiff, source.attrs);
7133
- }
7134
- if (!target.attrs.dangerouslySetInnerHTML)
7135
- morphChildren(domNode, source.childs, target.childs, opts);
7136
- if (isSelect && target.attrs.value !== undefined)
7137
- applyProperties(domNode, { value: target.attrs.value }, source.attrs);
7138
- return domNode;
7139
- }
7140
- if (type === 11) {
7141
- morphChildren(domNode, source.childs, target.childs, opts);
7142
- return domNode;
7143
- }
7234
+ lookupTypeFor(name, inst) {
7235
+ return this.transactor.comps.getCompFor(inst).scope.lookupComponent(name);
7144
7236
  }
7145
- const newNode = target.toDom(opts);
7146
- domNode.parentNode?.replaceChild(newNode, domNode);
7147
- return newNode;
7148
7237
  }
7149
- function morphChildren(parentDom, oldChilds, newChilds, opts) {
7150
- if (oldChilds.length === 0) {
7151
- appendChildNodes(parentDom, newChilds, opts);
7152
- return;
7238
+
7239
+ class EventContext extends Dispatcher {
7240
+ get name() {
7241
+ return this.parent?.name ?? null;
7153
7242
  }
7154
- if (newChilds.length === 0) {
7155
- parentDom.replaceChildren();
7156
- return;
7243
+ get targetPath() {
7244
+ return this.parent.targetPath;
7157
7245
  }
7158
- if (oldChilds.length === newChilds.length) {
7159
- let hasKey = false;
7160
- for (let i = 0;i < oldChilds.length; i++) {
7161
- if (getKey(oldChilds[i]) != null || getKey(newChilds[i]) != null) {
7162
- hasKey = true;
7163
- break;
7164
- }
7165
- }
7166
- if (!hasKey) {
7167
- let dom = parentDom.firstChild;
7168
- for (let i = 0;i < oldChilds.length; i++) {
7169
- const next = dom.nextSibling;
7170
- morphNode(dom, oldChilds[i], newChilds[i], opts);
7171
- dom = next;
7172
- }
7173
- return;
7174
- }
7246
+ stopPropagation() {
7247
+ return this.parent.stopPropagation();
7175
7248
  }
7176
- const domNodes = Array.from(parentDom.childNodes);
7177
- const oldKeyMap = Object.create(null);
7178
- for (let i = 0;i < oldChilds.length; i++) {
7179
- const key = getKey(oldChilds[i]);
7180
- if (key != null)
7181
- oldKeyMap[key] = i;
7249
+ }
7250
+
7251
+ class PathChanges extends PathBuilder {
7252
+ constructor(dispatcher) {
7253
+ super();
7254
+ this.dispatcher = dispatcher;
7182
7255
  }
7183
- const used = new Uint8Array(oldChilds.length);
7184
- let unkeyedCursor = 0;
7185
- for (let j = 0;j < newChilds.length; j++) {
7186
- const newChild = newChilds[j];
7187
- const newKey = getKey(newChild);
7188
- let oldIdx = -1;
7189
- if (newKey != null) {
7190
- if (newKey in oldKeyMap && !used[oldKeyMap[newKey]])
7191
- oldIdx = oldKeyMap[newKey];
7192
- } else {
7193
- while (unkeyedCursor < oldChilds.length) {
7194
- if (!used[unkeyedCursor] && getKey(oldChilds[unkeyedCursor]) == null) {
7195
- oldIdx = unkeyedCursor++;
7196
- break;
7197
- }
7198
- unkeyedCursor++;
7199
- }
7200
- }
7201
- if (oldIdx >= 0) {
7202
- used[oldIdx] = 1;
7203
- const newDom = morphNode(domNodes[oldIdx], oldChilds[oldIdx], newChild, opts);
7204
- const ref = parentDom.childNodes[j] ?? null;
7205
- if (newDom !== ref)
7206
- parentDom.insertBefore(newDom, ref);
7207
- } else {
7208
- const ref = parentDom.childNodes[j] ?? null;
7209
- parentDom.insertBefore(newChild.toDom(opts), ref);
7210
- }
7256
+ send(name, args, opts) {
7257
+ return this.dispatcher.sendAtPath(this.buildPath(), name, args, opts);
7211
7258
  }
7212
- for (let i = oldChilds.length - 1;i >= 0; i--)
7213
- if (!used[i] && domNodes[i].parentNode === parentDom)
7214
- parentDom.removeChild(domNodes[i]);
7215
- }
7216
- function render(vnode, container, options, prev) {
7217
- const isFragment = vnode instanceof VFragment;
7218
- if (prev && prev.vnode instanceof VFragment === isFragment) {
7219
- const oldDom = isFragment ? container : prev.dom;
7220
- const newDom = morphNode(oldDom, prev.vnode, vnode, options);
7221
- return { vnode, dom: isFragment ? container : newDom };
7259
+ bubble(name, args, opts) {
7260
+ return this.send(name, args, { skipSelf: true, bubbles: true, ...opts });
7222
7261
  }
7223
- const domNode = vnode.toDom(options);
7224
- container.replaceChildren(domNode);
7225
- return { vnode, dom: isFragment ? container : domNode };
7226
- }
7227
- function h(tagName, properties, children) {
7228
- const c = tagName.charCodeAt(0);
7229
- const tag = c >= 97 && c <= 122 ? tagName.toUpperCase() : tagName;
7230
- const props = {};
7231
- let key, namespace;
7232
- if (properties) {
7233
- for (const propName in properties) {
7234
- const propVal = properties[propName];
7235
- switch (propName) {
7236
- case "key":
7237
- key = propVal;
7238
- break;
7239
- case "namespace":
7240
- namespace = propVal;
7241
- break;
7242
- case "class":
7243
- props.className = propVal;
7244
- break;
7245
- case "for":
7246
- props.htmlFor = propVal;
7247
- break;
7248
- default:
7249
- props[propName] = isHtmlAttribute(propName) ? String(propVal) : propVal;
7250
- }
7251
- }
7262
+ buildPath() {
7263
+ return this.dispatcher.path.concat(this.pathChanges);
7252
7264
  }
7253
- const normalizedChildren = [];
7254
- addChild(normalizedChildren, children);
7255
- return new VNode2(tag, props, normalizedChildren, key, namespace);
7256
7265
  }
7257
7266
 
7258
7267
  // src/app.js
@@ -8090,20 +8099,20 @@ class Renderer {
8090
8099
  renderEach(stack, iterInfo, node, viewName) {
8091
8100
  const { seq, filter, loopWith } = iterInfo.eval(stack);
8092
8101
  const r = [];
8093
- const iterData = loopWith.call(stack.it, seq);
8102
+ const { iterData, start, end } = unpackLoopResult(loopWith.call(stack.it, seq), seq);
8094
8103
  getSeqInfo(seq)(seq, (key, value, attrName) => {
8095
8104
  if (filter.call(stack.it, key, value, iterData)) {
8096
8105
  const dom = this.renderIt(stack.enter(value, { key }, true), node, key, viewName);
8097
8106
  this.pushEachEntry(r, node.nodeId, attrName, key, dom);
8098
8107
  }
8099
- });
8108
+ }, start, end);
8100
8109
  return r;
8101
8110
  }
8102
8111
  renderEachWhen(stack, iterInfo, view, nid) {
8103
8112
  const { seq, filter, loopWith, enricher } = iterInfo.eval(stack);
8104
8113
  const r = [];
8105
8114
  const it = stack.it;
8106
- const iterData = loopWith.call(it, seq);
8115
+ const { iterData, start, end } = unpackLoopResult(loopWith.call(it, seq), seq);
8107
8116
  getSeqInfo(seq)(seq, (key, value, attrName) => {
8108
8117
  if (filter.call(it, key, value, iterData)) {
8109
8118
  const cachePath = enricher ? [view, it, value] : [view, value];
@@ -8120,7 +8129,7 @@ class Renderer {
8120
8129
  this.cache.set(cachePath, cacheKey, dom);
8121
8130
  }
8122
8131
  }
8123
- });
8132
+ }, start, end);
8124
8133
  return r;
8125
8134
  }
8126
8135
  renderView(view, stack) {
@@ -8142,14 +8151,32 @@ class Renderer {
8142
8151
  }
8143
8152
  }
8144
8153
  var getSeqInfo = (seq) => isIndexed(seq) ? imIndexedIter : isKeyed(seq) ? imKeyedIter : seq?.[SEQ_INFO] ?? unkIter;
8145
- var imIndexedIter = (seq, visit) => {
8146
- let i = 0;
8147
- for (const v of seq)
8148
- visit(i++, v, "si");
8154
+ var normalizeRange = (start, end, size) => {
8155
+ let s = start == null ? 0 : start < 0 ? size + start : start;
8156
+ let e = end == null ? size : end < 0 ? size + end : end;
8157
+ s = s < 0 ? 0 : s > size ? size : s;
8158
+ e = e < 0 ? 0 : e > size ? size : e;
8159
+ return [s, e < s ? s : e];
8160
+ };
8161
+ var unpackLoopResult = (result, seq) => {
8162
+ const r = result ?? {};
8163
+ return { iterData: r.iterData ?? { seq }, start: r.start, end: r.end };
8149
8164
  };
8150
- var imKeyedIter = (seq, visit) => {
8151
- for (const [k, v] of seq.toSeq().entries())
8152
- visit(k, v, "sk");
8165
+ var imIndexedIter = (seq, visit, start, end) => {
8166
+ const [s, e] = normalizeRange(start, end, seq.size);
8167
+ for (let i = s;i < e; i++)
8168
+ visit(i, seq.get(i), "si");
8169
+ };
8170
+ var imKeyedIter = (seq, visit, start, end) => {
8171
+ const [s, e] = normalizeRange(start, end, seq.size);
8172
+ let i = 0;
8173
+ for (const [k, v] of seq.toSeq().entries()) {
8174
+ if (i >= e)
8175
+ break;
8176
+ if (i >= s)
8177
+ visit(k, v, "sk");
8178
+ i++;
8179
+ }
8153
8180
  };
8154
8181
  var unkIter = () => {};
8155
8182
  var SEQ_INFO = Symbol.for("tutuca.seqInfo");