tutuca 0.9.63 → 0.9.64

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.
@@ -5350,6 +5350,331 @@ var init_attribute = __esm(() => {
5350
5350
  };
5351
5351
  });
5352
5352
 
5353
+ // src/vdom.js
5354
+ function applyProperties(node, props, previous) {
5355
+ const namespaced = isNamespaced(node);
5356
+ for (const propName in props) {
5357
+ const propValue = props[propName];
5358
+ if (propValue === undefined)
5359
+ removeProperty(node, propName, previous);
5360
+ else if (propName === "dangerouslySetInnerHTML")
5361
+ node.innerHTML = propValue.__html ?? "";
5362
+ else if (propName === "className")
5363
+ node.setAttribute("class", propValue);
5364
+ else if (namespaced || isHtmlAttribute(propName))
5365
+ node.setAttribute(propName, propValue);
5366
+ else
5367
+ node[propName] = propValue;
5368
+ }
5369
+ }
5370
+ function removeProperty(node, propName, previous) {
5371
+ const previousValue = previous[propName];
5372
+ if (propName === "dangerouslySetInnerHTML")
5373
+ node.replaceChildren();
5374
+ else if (propName === "className")
5375
+ node.removeAttribute("class");
5376
+ else if (propName === "htmlFor")
5377
+ node.removeAttribute("for");
5378
+ else if (isNamespaced(node) || typeof previousValue === "string" || isHtmlAttribute(propName))
5379
+ node.removeAttribute(propName);
5380
+ else
5381
+ node[propName] = null;
5382
+ }
5383
+
5384
+ class VBase {
5385
+ }
5386
+ function childsEqual(a, b) {
5387
+ if (a === b)
5388
+ return true;
5389
+ for (let i = 0;i < a.length; i++)
5390
+ if (!a[i].isEqualTo(b[i]))
5391
+ return false;
5392
+ return true;
5393
+ }
5394
+ function appendChildNodes(parent, childs, opts) {
5395
+ for (const child of childs)
5396
+ parent.appendChild(child.toDom(opts));
5397
+ }
5398
+ function addChild(normalizedChildren, child) {
5399
+ if (child == null)
5400
+ return;
5401
+ if (isIterable(child)) {
5402
+ for (const c of child)
5403
+ addChild(normalizedChildren, c);
5404
+ } else if (child instanceof VBase) {
5405
+ if (child instanceof VFragment)
5406
+ normalizedChildren.push(...child.childs);
5407
+ else
5408
+ normalizedChildren.push(child);
5409
+ } else
5410
+ normalizedChildren.push(new VText(child));
5411
+ }
5412
+ function diffProps(a, b) {
5413
+ if (a === b)
5414
+ return null;
5415
+ let diff = null;
5416
+ for (const aKey in a) {
5417
+ if (!Object.hasOwn(b, aKey)) {
5418
+ diff ??= {};
5419
+ diff[aKey] = undefined;
5420
+ } else if (a[aKey] !== b[aKey]) {
5421
+ diff ??= {};
5422
+ diff[aKey] = b[aKey];
5423
+ }
5424
+ }
5425
+ for (const bKey in b) {
5426
+ if (!Object.hasOwn(a, bKey)) {
5427
+ diff ??= {};
5428
+ diff[bKey] = b[bKey];
5429
+ }
5430
+ }
5431
+ return diff;
5432
+ }
5433
+ function morphNode(domNode, source, target, opts) {
5434
+ if (source === target || source.isEqualTo(target))
5435
+ return domNode;
5436
+ const type = source.nodeType;
5437
+ if (type === target.nodeType) {
5438
+ if (type === 3 || type === 8) {
5439
+ domNode.data = target.text;
5440
+ return domNode;
5441
+ }
5442
+ if (type === 1 && source.isSameKind(target)) {
5443
+ const propsDiff = diffProps(source.attrs, target.attrs);
5444
+ const isSelect = source.tag === "SELECT";
5445
+ if (propsDiff) {
5446
+ if (isSelect && "value" in propsDiff) {
5447
+ const { value: _v, ...rest } = propsDiff;
5448
+ applyProperties(domNode, rest, source.attrs);
5449
+ } else
5450
+ applyProperties(domNode, propsDiff, source.attrs);
5451
+ }
5452
+ if (!target.attrs.dangerouslySetInnerHTML)
5453
+ morphChildren(domNode, source.childs, target.childs, opts);
5454
+ if (isSelect && target.attrs.value !== undefined)
5455
+ applyProperties(domNode, { value: target.attrs.value }, source.attrs);
5456
+ return domNode;
5457
+ }
5458
+ if (type === 11) {
5459
+ morphChildren(domNode, source.childs, target.childs, opts);
5460
+ return domNode;
5461
+ }
5462
+ }
5463
+ const newNode = target.toDom(opts);
5464
+ domNode.parentNode?.replaceChild(newNode, domNode);
5465
+ return newNode;
5466
+ }
5467
+ function morphChildren(parentDom, oldChilds, newChilds, opts) {
5468
+ if (oldChilds.length === 0) {
5469
+ appendChildNodes(parentDom, newChilds, opts);
5470
+ return;
5471
+ }
5472
+ if (newChilds.length === 0) {
5473
+ parentDom.replaceChildren();
5474
+ return;
5475
+ }
5476
+ if (oldChilds.length === newChilds.length) {
5477
+ let hasKey = false;
5478
+ for (let i = 0;i < oldChilds.length; i++) {
5479
+ if (getKey(oldChilds[i]) != null || getKey(newChilds[i]) != null) {
5480
+ hasKey = true;
5481
+ break;
5482
+ }
5483
+ }
5484
+ if (!hasKey) {
5485
+ let dom = parentDom.firstChild;
5486
+ for (let i = 0;i < oldChilds.length; i++) {
5487
+ const next = dom.nextSibling;
5488
+ morphNode(dom, oldChilds[i], newChilds[i], opts);
5489
+ dom = next;
5490
+ }
5491
+ return;
5492
+ }
5493
+ }
5494
+ const domNodes = Array.from(parentDom.childNodes);
5495
+ const oldKeyMap = Object.create(null);
5496
+ for (let i = 0;i < oldChilds.length; i++) {
5497
+ const key = getKey(oldChilds[i]);
5498
+ if (key != null)
5499
+ oldKeyMap[key] = i;
5500
+ }
5501
+ const used = new Uint8Array(oldChilds.length);
5502
+ let unkeyedCursor = 0;
5503
+ for (let j = 0;j < newChilds.length; j++) {
5504
+ const newChild = newChilds[j];
5505
+ const newKey = getKey(newChild);
5506
+ let oldIdx = -1;
5507
+ if (newKey != null) {
5508
+ if (newKey in oldKeyMap && !used[oldKeyMap[newKey]])
5509
+ oldIdx = oldKeyMap[newKey];
5510
+ } else {
5511
+ while (unkeyedCursor < oldChilds.length) {
5512
+ if (!used[unkeyedCursor] && getKey(oldChilds[unkeyedCursor]) == null) {
5513
+ oldIdx = unkeyedCursor++;
5514
+ break;
5515
+ }
5516
+ unkeyedCursor++;
5517
+ }
5518
+ }
5519
+ if (oldIdx >= 0) {
5520
+ used[oldIdx] = 1;
5521
+ const newDom = morphNode(domNodes[oldIdx], oldChilds[oldIdx], newChild, opts);
5522
+ const ref = parentDom.childNodes[j] ?? null;
5523
+ if (newDom !== ref)
5524
+ parentDom.insertBefore(newDom, ref);
5525
+ } else {
5526
+ const ref = parentDom.childNodes[j] ?? null;
5527
+ parentDom.insertBefore(newChild.toDom(opts), ref);
5528
+ }
5529
+ }
5530
+ for (let i = oldChilds.length - 1;i >= 0; i--)
5531
+ if (!used[i] && domNodes[i].parentNode === parentDom)
5532
+ parentDom.removeChild(domNodes[i]);
5533
+ }
5534
+ function render(vnode, container, options, prev) {
5535
+ const isFragment = vnode instanceof VFragment;
5536
+ if (prev && prev.vnode instanceof VFragment === isFragment) {
5537
+ const oldDom = isFragment ? container : prev.dom;
5538
+ const newDom = morphNode(oldDom, prev.vnode, vnode, options);
5539
+ return { vnode, dom: isFragment ? container : newDom };
5540
+ }
5541
+ const domNode = vnode.toDom(options);
5542
+ container.replaceChildren(domNode);
5543
+ return { vnode, dom: isFragment ? container : domNode };
5544
+ }
5545
+ function h(tagName, properties, children, namespace) {
5546
+ const props = {};
5547
+ let key;
5548
+ if (properties) {
5549
+ for (const propName in properties) {
5550
+ const propVal = properties[propName];
5551
+ switch (propName) {
5552
+ case "key":
5553
+ key = propVal;
5554
+ break;
5555
+ case "namespace":
5556
+ namespace = namespace ?? propVal;
5557
+ break;
5558
+ case "class":
5559
+ props.className = propVal;
5560
+ break;
5561
+ case "for":
5562
+ props.htmlFor = propVal;
5563
+ break;
5564
+ default:
5565
+ props[propName] = isHtmlAttribute(propName) ? String(propVal) : propVal;
5566
+ }
5567
+ }
5568
+ }
5569
+ const c = tagName.charCodeAt(0);
5570
+ const tag = namespace == null && c >= 97 && c <= 122 ? tagName.toUpperCase() : tagName;
5571
+ const normalizedChildren = [];
5572
+ addChild(normalizedChildren, children);
5573
+ return new VNode2(tag, props, normalizedChildren, key, namespace);
5574
+ }
5575
+ var isHtmlAttribute = (propName) => propName[4] === "-" && (propName[0] === "d" || propName[0] === "a"), HTML_NS = "http://www.w3.org/1999/xhtml", isNamespaced = (node) => {
5576
+ const ns = node.namespaceURI;
5577
+ return ns !== null && ns !== HTML_NS;
5578
+ }, getKey = (child) => child instanceof VNode2 ? child.key : undefined, isIterable = (obj) => obj != null && typeof obj !== "string" && typeof obj[Symbol.iterator] === "function", VText, VComment, VFragment, VNode2;
5579
+ var init_vdom = __esm(() => {
5580
+ VText = class VText extends VBase {
5581
+ constructor(text) {
5582
+ super();
5583
+ this.text = String(text);
5584
+ }
5585
+ get nodeType() {
5586
+ return 3;
5587
+ }
5588
+ isEqualTo(other) {
5589
+ return other instanceof VText && this.text === other.text;
5590
+ }
5591
+ toDom(opts) {
5592
+ return opts.document.createTextNode(this.text);
5593
+ }
5594
+ };
5595
+ VComment = class VComment extends VBase {
5596
+ constructor(text) {
5597
+ super();
5598
+ this.text = text;
5599
+ }
5600
+ get nodeType() {
5601
+ return 8;
5602
+ }
5603
+ isEqualTo(other) {
5604
+ return other instanceof VComment && this.text === other.text;
5605
+ }
5606
+ toDom(opts) {
5607
+ return opts.document.createComment(this.text);
5608
+ }
5609
+ };
5610
+ VFragment = class VFragment extends VBase {
5611
+ constructor(childs) {
5612
+ super();
5613
+ this.childs = [];
5614
+ addChild(this.childs, childs);
5615
+ }
5616
+ get nodeType() {
5617
+ return 11;
5618
+ }
5619
+ isEqualTo(other) {
5620
+ if (!(other instanceof VFragment) || this.childs.length !== other.childs.length)
5621
+ return false;
5622
+ return childsEqual(this.childs, other.childs);
5623
+ }
5624
+ toDom(opts) {
5625
+ const fragment = opts.document.createDocumentFragment();
5626
+ appendChildNodes(fragment, this.childs, opts);
5627
+ return fragment;
5628
+ }
5629
+ };
5630
+ VNode2 = class VNode2 extends VBase {
5631
+ constructor(tag, attrs, childs, key, namespace) {
5632
+ super();
5633
+ this.tag = tag;
5634
+ this.attrs = attrs ?? {};
5635
+ this.childs = childs ?? [];
5636
+ this.key = key != null ? String(key) : undefined;
5637
+ this.namespace = typeof namespace === "string" ? namespace : null;
5638
+ }
5639
+ get nodeType() {
5640
+ return 1;
5641
+ }
5642
+ isSameKind(other) {
5643
+ return this.tag === other.tag && this.namespace === other.namespace && this.key === other.key;
5644
+ }
5645
+ isEqualTo(other) {
5646
+ if (this === other)
5647
+ return true;
5648
+ if (!(other instanceof VNode2) || !this.isSameKind(other) || this.childs.length !== other.childs.length) {
5649
+ return false;
5650
+ }
5651
+ if (this.attrs !== other.attrs) {
5652
+ for (const key in this.attrs)
5653
+ if (this.attrs[key] !== other.attrs[key])
5654
+ return false;
5655
+ for (const key in other.attrs)
5656
+ if (!Object.hasOwn(this.attrs, key))
5657
+ return false;
5658
+ }
5659
+ return childsEqual(this.childs, other.childs);
5660
+ }
5661
+ toDom(opts) {
5662
+ const doc = opts.document;
5663
+ const node = this.namespace === null ? doc.createElement(this.tag) : doc.createElementNS(this.namespace, this.tag);
5664
+ if (this.tag === "SELECT" && "value" in this.attrs) {
5665
+ const { value, ...rest } = this.attrs;
5666
+ applyProperties(node, rest, {});
5667
+ appendChildNodes(node, this.childs, opts);
5668
+ applyProperties(node, { value }, {});
5669
+ } else {
5670
+ applyProperties(node, this.attrs, {});
5671
+ appendChildNodes(node, this.childs, opts);
5672
+ }
5673
+ return node;
5674
+ }
5675
+ };
5676
+ });
5677
+
5353
5678
  // src/anode.js
5354
5679
  function resolveDynProducer(comp, dynName) {
5355
5680
  const dyn = comp?.dynamic?.[dynName];
@@ -5661,6 +5986,7 @@ var init_anode = __esm(() => {
5661
5986
  init_attribute();
5662
5987
  init_path();
5663
5988
  init_value();
5989
+ init_vdom();
5664
5990
  TextNode = class TextNode extends BaseNode {
5665
5991
  constructor(val) {
5666
5992
  super();
@@ -5711,16 +6037,17 @@ var init_anode = __esm(() => {
5711
6037
  }
5712
6038
  };
5713
6039
  DomNode = class DomNode extends ChildsNode {
5714
- constructor(tagName, attrs, childs) {
6040
+ constructor(tagName, attrs, childs, namespace = null) {
5715
6041
  super(childs);
5716
6042
  this.tagName = tagName;
5717
6043
  this.attrs = attrs;
6044
+ this.namespace = namespace;
5718
6045
  }
5719
6046
  render(stack, rx) {
5720
6047
  const childNodes = new Array(this.childs.length);
5721
6048
  for (let i = 0;i < childNodes.length; i++)
5722
6049
  childNodes[i] = this.childs[i]?.render?.(stack, rx) ?? null;
5723
- return rx.renderTag(this.tagName, this.attrs.eval(stack), childNodes);
6050
+ return rx.renderTag(this.tagName, this.attrs.eval(stack), childNodes, this.namespace);
5724
6051
  }
5725
6052
  setDataAttr(key, val) {
5726
6053
  this.attrs.setDataAttr(key, val);
@@ -5798,7 +6125,9 @@ var init_anode = __esm(() => {
5798
6125
  if (textChild)
5799
6126
  childs.unshift(new RenderTextNode(null, textChild));
5800
6127
  const domChilds = tag !== "PRE" ? condenseChildsWhites(childs) : childs;
5801
- return wrap(new DomNode(tag, nAttrs, domChilds), px, wrappers);
6128
+ const ns = node.namespaceURI;
6129
+ const namespace = ns && ns !== HTML_NS ? ns : null;
6130
+ return wrap(new DomNode(tag, nAttrs, domChilds, namespace), px, wrappers);
5802
6131
  }
5803
6132
  return new CommentNode(`Error: InvalidTagName ${tag}`);
5804
6133
  } finally {
@@ -13343,455 +13672,134 @@ var init_transactor = __esm(() => {
13343
13672
  this._dispatchPath = null;
13344
13673
  }
13345
13674
  get dispatchPath() {
13346
- this._dispatchPath ??= this.path.compact();
13347
- return this._dispatchPath;
13348
- }
13349
- buildRootStack(root, comps) {
13350
- return Stack2.root(comps, root, this);
13351
- }
13352
- getHandlerAndArgs(root, _instance, comps) {
13353
- const stack = this.buildStack(root, comps);
13354
- const [handler, args] = this.handler.getHandlerAndArgs(stack, this);
13355
- const path = this.dispatchPath;
13356
- let dispatcher;
13357
- for (let i = 0;i < args.length; i++) {
13358
- if (args[i]?.toHandlerArg) {
13359
- dispatcher ??= new Dispatcher(path, this.transactor, this);
13360
- args[i] = args[i].toHandlerArg(dispatcher);
13361
- }
13362
- }
13363
- args.push(new EventContext(path, this.transactor, this));
13364
- return [handler, args];
13365
- }
13366
- lookupName(name) {
13367
- const { e } = this;
13368
- switch (name) {
13369
- case "value":
13370
- return getValue(e);
13371
- case "valueAsInt":
13372
- return toNullIfNaN(parseInt(getValue(e), 10));
13373
- case "valueAsFloat":
13374
- return toNullIfNaN(parseFloat(getValue(e)));
13375
- case "target":
13376
- return e.target;
13377
- case "event":
13378
- return e;
13379
- case "isAlt":
13380
- return e.altKey;
13381
- case "isShift":
13382
- return e.shiftKey;
13383
- case "isCtrl":
13384
- case "isCmd":
13385
- return isMac2 && e.metaKey || e.ctrlKey;
13386
- case "key":
13387
- return e.key;
13388
- case "keyCode":
13389
- return e.keyCode;
13390
- case "isUpKey":
13391
- return e.key === "ArrowUp";
13392
- case "isDownKey":
13393
- return e.key === "ArrowDown";
13394
- case "isSend":
13395
- return e.key === "Enter";
13396
- case "isCancel":
13397
- return e.key === "Escape";
13398
- case "isTabKey":
13399
- return e.key === "Tab";
13400
- case "ctx":
13401
- return new EventContext(this.dispatchPath, this.transactor, this);
13402
- case "dragInfo":
13403
- return this.dragInfo;
13404
- }
13405
- return null;
13406
- }
13407
- };
13408
- NameArgsTransaction = class NameArgsTransaction extends Transaction {
13409
- constructor(path, transactor, name, args, parentTransaction, opts = {}) {
13410
- super(path, transactor, parentTransaction);
13411
- this.name = name;
13412
- this.args = args;
13413
- this.opts = opts;
13414
- this.targetPath = path;
13415
- }
13416
- handlerProp = null;
13417
- getHandlerForName(comp) {
13418
- const handlers = comp?.[this.handlerProp];
13419
- return handlers?.[this.name] ?? handlers?.$unknown ?? nullHandler;
13420
- }
13421
- getHandlerAndArgs(_root, instance, comps) {
13422
- const handler = this.getHandlerForName(comps.getCompFor(instance));
13423
- return [handler, [...this.args, new EventContext(this.path, this.transactor, this)]];
13424
- }
13425
- };
13426
- ResponseEvent = class ResponseEvent extends NameArgsTransaction {
13427
- handlerProp = "response";
13428
- };
13429
- SendEvent = class SendEvent extends NameArgsTransaction {
13430
- handlerProp = "receive";
13431
- run(rootVal, comps) {
13432
- return this.opts.skipSelf ? rootVal : this.updateRootValue(rootVal, comps);
13433
- }
13434
- afterTransaction() {
13435
- const { path, name, args, opts, targetPath } = this;
13436
- if (opts.bubbles && path.steps.length > 0)
13437
- this.transactor.pushBubble(path.popStep(), name, args, opts, this, targetPath);
13438
- }
13439
- };
13440
- BubbleEvent = class BubbleEvent extends SendEvent {
13441
- handlerProp = "bubble";
13442
- constructor(path, transactor, name, args, parent, opts, targetPath) {
13443
- super(path, transactor, name, args, parent, opts);
13444
- this.targetPath = targetPath ?? path;
13445
- }
13446
- stopPropagation() {
13447
- this.opts.bubbles = false;
13448
- }
13449
- };
13450
- EventContext = class EventContext extends Dispatcher {
13451
- get name() {
13452
- return this.parent?.name ?? null;
13453
- }
13454
- get targetPath() {
13455
- return this.parent.targetPath;
13456
- }
13457
- stopPropagation() {
13458
- return this.parent.stopPropagation();
13459
- }
13460
- };
13461
- PathChanges = class PathChanges extends PathBuilder {
13462
- constructor(dispatcher) {
13463
- super();
13464
- this.dispatcher = dispatcher;
13465
- }
13466
- send(name, args, opts) {
13467
- return this.dispatcher.sendAtPath(this.buildPath(), name, args, opts);
13468
- }
13469
- bubble(name, args, opts) {
13470
- return this.send(name, args, { skipSelf: true, bubbles: true, ...opts });
13471
- }
13472
- buildPath() {
13473
- return this.dispatcher.path.concat(this.pathChanges);
13474
- }
13475
- };
13476
- });
13477
-
13478
- // src/vdom.js
13479
- function applyProperties(node, props, previous) {
13480
- for (const propName in props) {
13481
- const propValue = props[propName];
13482
- if (propValue === undefined)
13483
- removeProperty(node, propName, previous);
13484
- else if (isHtmlAttribute(propName))
13485
- node.setAttribute(propName, propValue);
13486
- else if (propName === "dangerouslySetInnerHTML")
13487
- node.innerHTML = propValue.__html ?? "";
13488
- else if (propName === "className")
13489
- node.setAttribute("class", propValue);
13490
- else
13491
- node[propName] = propValue;
13492
- }
13493
- }
13494
- function removeProperty(node, propName, previous) {
13495
- const previousValue = previous[propName];
13496
- if (propName === "dangerouslySetInnerHTML")
13497
- node.replaceChildren();
13498
- else if (propName === "className")
13499
- node.removeAttribute("class");
13500
- else if (propName === "htmlFor")
13501
- node.removeAttribute("for");
13502
- else if (typeof previousValue === "string" || isHtmlAttribute(propName))
13503
- node.removeAttribute(propName);
13504
- else
13505
- node[propName] = null;
13506
- }
13507
-
13508
- class VBase {
13509
- }
13510
- function childsEqual(a, b) {
13511
- if (a === b)
13512
- return true;
13513
- for (let i = 0;i < a.length; i++)
13514
- if (!a[i].isEqualTo(b[i]))
13515
- return false;
13516
- return true;
13517
- }
13518
- function appendChildNodes(parent, childs, opts) {
13519
- for (const child of childs)
13520
- parent.appendChild(child.toDom(opts));
13521
- }
13522
- function addChild(normalizedChildren, child) {
13523
- if (child == null)
13524
- return;
13525
- if (isIterable(child)) {
13526
- for (const c of child)
13527
- addChild(normalizedChildren, c);
13528
- } else if (child instanceof VBase) {
13529
- if (child instanceof VFragment)
13530
- normalizedChildren.push(...child.childs);
13531
- else
13532
- normalizedChildren.push(child);
13533
- } else
13534
- normalizedChildren.push(new VText(child));
13535
- }
13536
- function diffProps(a, b) {
13537
- if (a === b)
13538
- return null;
13539
- let diff = null;
13540
- for (const aKey in a) {
13541
- if (!Object.hasOwn(b, aKey)) {
13542
- diff ??= {};
13543
- diff[aKey] = undefined;
13544
- } else if (a[aKey] !== b[aKey]) {
13545
- diff ??= {};
13546
- diff[aKey] = b[aKey];
13547
- }
13548
- }
13549
- for (const bKey in b) {
13550
- if (!Object.hasOwn(a, bKey)) {
13551
- diff ??= {};
13552
- diff[bKey] = b[bKey];
13553
- }
13554
- }
13555
- return diff;
13556
- }
13557
- function morphNode(domNode, source, target, opts) {
13558
- if (source === target || source.isEqualTo(target))
13559
- return domNode;
13560
- const type3 = source.nodeType;
13561
- if (type3 === target.nodeType) {
13562
- if (type3 === 3 || type3 === 8) {
13563
- domNode.data = target.text;
13564
- return domNode;
13565
- }
13566
- if (type3 === 1 && source.isSameKind(target)) {
13567
- const propsDiff = diffProps(source.attrs, target.attrs);
13568
- const isSelect = source.tag === "SELECT";
13569
- if (propsDiff) {
13570
- if (isSelect && "value" in propsDiff) {
13571
- const { value: _v, ...rest } = propsDiff;
13572
- applyProperties(domNode, rest, source.attrs);
13573
- } else
13574
- applyProperties(domNode, propsDiff, source.attrs);
13575
- }
13576
- if (!target.attrs.dangerouslySetInnerHTML)
13577
- morphChildren(domNode, source.childs, target.childs, opts);
13578
- if (isSelect && target.attrs.value !== undefined)
13579
- applyProperties(domNode, { value: target.attrs.value }, source.attrs);
13580
- return domNode;
13581
- }
13582
- if (type3 === 11) {
13583
- morphChildren(domNode, source.childs, target.childs, opts);
13584
- return domNode;
13585
- }
13586
- }
13587
- const newNode = target.toDom(opts);
13588
- domNode.parentNode?.replaceChild(newNode, domNode);
13589
- return newNode;
13590
- }
13591
- function morphChildren(parentDom, oldChilds, newChilds, opts) {
13592
- if (oldChilds.length === 0) {
13593
- appendChildNodes(parentDom, newChilds, opts);
13594
- return;
13595
- }
13596
- if (newChilds.length === 0) {
13597
- parentDom.replaceChildren();
13598
- return;
13599
- }
13600
- if (oldChilds.length === newChilds.length) {
13601
- let hasKey = false;
13602
- for (let i = 0;i < oldChilds.length; i++) {
13603
- if (getKey(oldChilds[i]) != null || getKey(newChilds[i]) != null) {
13604
- hasKey = true;
13605
- break;
13606
- }
13675
+ this._dispatchPath ??= this.path.compact();
13676
+ return this._dispatchPath;
13607
13677
  }
13608
- if (!hasKey) {
13609
- let dom = parentDom.firstChild;
13610
- for (let i = 0;i < oldChilds.length; i++) {
13611
- const next = dom.nextSibling;
13612
- morphNode(dom, oldChilds[i], newChilds[i], opts);
13613
- dom = next;
13614
- }
13615
- return;
13678
+ buildRootStack(root, comps) {
13679
+ return Stack2.root(comps, root, this);
13616
13680
  }
13617
- }
13618
- const domNodes = Array.from(parentDom.childNodes);
13619
- const oldKeyMap = Object.create(null);
13620
- for (let i = 0;i < oldChilds.length; i++) {
13621
- const key = getKey(oldChilds[i]);
13622
- if (key != null)
13623
- oldKeyMap[key] = i;
13624
- }
13625
- const used2 = new Uint8Array(oldChilds.length);
13626
- let unkeyedCursor = 0;
13627
- for (let j = 0;j < newChilds.length; j++) {
13628
- const newChild = newChilds[j];
13629
- const newKey = getKey(newChild);
13630
- let oldIdx = -1;
13631
- if (newKey != null) {
13632
- if (newKey in oldKeyMap && !used2[oldKeyMap[newKey]])
13633
- oldIdx = oldKeyMap[newKey];
13634
- } else {
13635
- while (unkeyedCursor < oldChilds.length) {
13636
- if (!used2[unkeyedCursor] && getKey(oldChilds[unkeyedCursor]) == null) {
13637
- oldIdx = unkeyedCursor++;
13638
- break;
13681
+ getHandlerAndArgs(root, _instance, comps) {
13682
+ const stack = this.buildStack(root, comps);
13683
+ const [handler, args] = this.handler.getHandlerAndArgs(stack, this);
13684
+ const path = this.dispatchPath;
13685
+ let dispatcher;
13686
+ for (let i = 0;i < args.length; i++) {
13687
+ if (args[i]?.toHandlerArg) {
13688
+ dispatcher ??= new Dispatcher(path, this.transactor, this);
13689
+ args[i] = args[i].toHandlerArg(dispatcher);
13639
13690
  }
13640
- unkeyedCursor++;
13641
13691
  }
13692
+ args.push(new EventContext(path, this.transactor, this));
13693
+ return [handler, args];
13642
13694
  }
13643
- if (oldIdx >= 0) {
13644
- used2[oldIdx] = 1;
13645
- const newDom = morphNode(domNodes[oldIdx], oldChilds[oldIdx], newChild, opts);
13646
- const ref = parentDom.childNodes[j] ?? null;
13647
- if (newDom !== ref)
13648
- parentDom.insertBefore(newDom, ref);
13649
- } else {
13650
- const ref = parentDom.childNodes[j] ?? null;
13651
- parentDom.insertBefore(newChild.toDom(opts), ref);
13652
- }
13653
- }
13654
- for (let i = oldChilds.length - 1;i >= 0; i--)
13655
- if (!used2[i] && domNodes[i].parentNode === parentDom)
13656
- parentDom.removeChild(domNodes[i]);
13657
- }
13658
- function render(vnode, container, options, prev) {
13659
- const isFragment = vnode instanceof VFragment;
13660
- if (prev && prev.vnode instanceof VFragment === isFragment) {
13661
- const oldDom = isFragment ? container : prev.dom;
13662
- const newDom = morphNode(oldDom, prev.vnode, vnode, options);
13663
- return { vnode, dom: isFragment ? container : newDom };
13664
- }
13665
- const domNode = vnode.toDom(options);
13666
- container.replaceChildren(domNode);
13667
- return { vnode, dom: isFragment ? container : domNode };
13668
- }
13669
- function h(tagName, properties, children) {
13670
- const c = tagName.charCodeAt(0);
13671
- const tag = c >= 97 && c <= 122 ? tagName.toUpperCase() : tagName;
13672
- const props = {};
13673
- let key, namespace;
13674
- if (properties) {
13675
- for (const propName in properties) {
13676
- const propVal = properties[propName];
13677
- switch (propName) {
13695
+ lookupName(name) {
13696
+ const { e } = this;
13697
+ switch (name) {
13698
+ case "value":
13699
+ return getValue(e);
13700
+ case "valueAsInt":
13701
+ return toNullIfNaN(parseInt(getValue(e), 10));
13702
+ case "valueAsFloat":
13703
+ return toNullIfNaN(parseFloat(getValue(e)));
13704
+ case "target":
13705
+ return e.target;
13706
+ case "event":
13707
+ return e;
13708
+ case "isAlt":
13709
+ return e.altKey;
13710
+ case "isShift":
13711
+ return e.shiftKey;
13712
+ case "isCtrl":
13713
+ case "isCmd":
13714
+ return isMac2 && e.metaKey || e.ctrlKey;
13678
13715
  case "key":
13679
- key = propVal;
13680
- break;
13681
- case "namespace":
13682
- namespace = propVal;
13683
- break;
13684
- case "class":
13685
- props.className = propVal;
13686
- break;
13687
- case "for":
13688
- props.htmlFor = propVal;
13689
- break;
13690
- default:
13691
- props[propName] = isHtmlAttribute(propName) ? String(propVal) : propVal;
13716
+ return e.key;
13717
+ case "keyCode":
13718
+ return e.keyCode;
13719
+ case "isUpKey":
13720
+ return e.key === "ArrowUp";
13721
+ case "isDownKey":
13722
+ return e.key === "ArrowDown";
13723
+ case "isSend":
13724
+ return e.key === "Enter";
13725
+ case "isCancel":
13726
+ return e.key === "Escape";
13727
+ case "isTabKey":
13728
+ return e.key === "Tab";
13729
+ case "ctx":
13730
+ return new EventContext(this.dispatchPath, this.transactor, this);
13731
+ case "dragInfo":
13732
+ return this.dragInfo;
13692
13733
  }
13734
+ return null;
13693
13735
  }
13694
- }
13695
- const normalizedChildren = [];
13696
- addChild(normalizedChildren, children);
13697
- return new VNode2(tag, props, normalizedChildren, key, namespace);
13698
- }
13699
- var isHtmlAttribute = (propName) => propName[4] === "-" && (propName[0] === "d" || propName[0] === "a"), getKey = (child) => child instanceof VNode2 ? child.key : undefined, isIterable = (obj) => obj != null && typeof obj !== "string" && typeof obj[Symbol.iterator] === "function", VText, VComment, VFragment, VNode2;
13700
- var init_vdom = __esm(() => {
13701
- VText = class VText extends VBase {
13702
- constructor(text) {
13703
- super();
13704
- this.text = String(text);
13705
- }
13706
- get nodeType() {
13707
- return 3;
13736
+ };
13737
+ NameArgsTransaction = class NameArgsTransaction extends Transaction {
13738
+ constructor(path, transactor, name, args, parentTransaction, opts = {}) {
13739
+ super(path, transactor, parentTransaction);
13740
+ this.name = name;
13741
+ this.args = args;
13742
+ this.opts = opts;
13743
+ this.targetPath = path;
13708
13744
  }
13709
- isEqualTo(other) {
13710
- return other instanceof VText && this.text === other.text;
13745
+ handlerProp = null;
13746
+ getHandlerForName(comp) {
13747
+ const handlers = comp?.[this.handlerProp];
13748
+ return handlers?.[this.name] ?? handlers?.$unknown ?? nullHandler;
13711
13749
  }
13712
- toDom(opts) {
13713
- return opts.document.createTextNode(this.text);
13750
+ getHandlerAndArgs(_root, instance, comps) {
13751
+ const handler = this.getHandlerForName(comps.getCompFor(instance));
13752
+ return [handler, [...this.args, new EventContext(this.path, this.transactor, this)]];
13714
13753
  }
13715
13754
  };
13716
- VComment = class VComment extends VBase {
13717
- constructor(text) {
13718
- super();
13719
- this.text = text;
13755
+ ResponseEvent = class ResponseEvent extends NameArgsTransaction {
13756
+ handlerProp = "response";
13757
+ };
13758
+ SendEvent = class SendEvent extends NameArgsTransaction {
13759
+ handlerProp = "receive";
13760
+ run(rootVal, comps) {
13761
+ return this.opts.skipSelf ? rootVal : this.updateRootValue(rootVal, comps);
13720
13762
  }
13721
- get nodeType() {
13722
- return 8;
13763
+ afterTransaction() {
13764
+ const { path, name, args, opts, targetPath } = this;
13765
+ if (opts.bubbles && path.steps.length > 0)
13766
+ this.transactor.pushBubble(path.popStep(), name, args, opts, this, targetPath);
13723
13767
  }
13724
- isEqualTo(other) {
13725
- return other instanceof VComment && this.text === other.text;
13768
+ };
13769
+ BubbleEvent = class BubbleEvent extends SendEvent {
13770
+ handlerProp = "bubble";
13771
+ constructor(path, transactor, name, args, parent, opts, targetPath) {
13772
+ super(path, transactor, name, args, parent, opts);
13773
+ this.targetPath = targetPath ?? path;
13726
13774
  }
13727
- toDom(opts) {
13728
- return opts.document.createComment(this.text);
13775
+ stopPropagation() {
13776
+ this.opts.bubbles = false;
13729
13777
  }
13730
13778
  };
13731
- VFragment = class VFragment extends VBase {
13732
- constructor(childs) {
13733
- super();
13734
- this.childs = [];
13735
- addChild(this.childs, childs);
13736
- }
13737
- get nodeType() {
13738
- return 11;
13779
+ EventContext = class EventContext extends Dispatcher {
13780
+ get name() {
13781
+ return this.parent?.name ?? null;
13739
13782
  }
13740
- isEqualTo(other) {
13741
- if (!(other instanceof VFragment) || this.childs.length !== other.childs.length)
13742
- return false;
13743
- return childsEqual(this.childs, other.childs);
13783
+ get targetPath() {
13784
+ return this.parent.targetPath;
13744
13785
  }
13745
- toDom(opts) {
13746
- const fragment = opts.document.createDocumentFragment();
13747
- appendChildNodes(fragment, this.childs, opts);
13748
- return fragment;
13786
+ stopPropagation() {
13787
+ return this.parent.stopPropagation();
13749
13788
  }
13750
13789
  };
13751
- VNode2 = class VNode2 extends VBase {
13752
- constructor(tag, attrs, childs, key, namespace) {
13790
+ PathChanges = class PathChanges extends PathBuilder {
13791
+ constructor(dispatcher) {
13753
13792
  super();
13754
- this.tag = tag;
13755
- this.attrs = attrs ?? {};
13756
- this.childs = childs ?? [];
13757
- this.key = key != null ? String(key) : undefined;
13758
- this.namespace = typeof namespace === "string" ? namespace : null;
13759
- }
13760
- get nodeType() {
13761
- return 1;
13793
+ this.dispatcher = dispatcher;
13762
13794
  }
13763
- isSameKind(other) {
13764
- return this.tag === other.tag && this.namespace === other.namespace && this.key === other.key;
13795
+ send(name, args, opts) {
13796
+ return this.dispatcher.sendAtPath(this.buildPath(), name, args, opts);
13765
13797
  }
13766
- isEqualTo(other) {
13767
- if (this === other)
13768
- return true;
13769
- if (!(other instanceof VNode2) || !this.isSameKind(other) || this.childs.length !== other.childs.length) {
13770
- return false;
13771
- }
13772
- if (this.attrs !== other.attrs) {
13773
- for (const key in this.attrs)
13774
- if (this.attrs[key] !== other.attrs[key])
13775
- return false;
13776
- for (const key in other.attrs)
13777
- if (!Object.hasOwn(this.attrs, key))
13778
- return false;
13779
- }
13780
- return childsEqual(this.childs, other.childs);
13798
+ bubble(name, args, opts) {
13799
+ return this.send(name, args, { skipSelf: true, bubbles: true, ...opts });
13781
13800
  }
13782
- toDom(opts) {
13783
- const doc = opts.document;
13784
- const node = this.namespace === null ? doc.createElement(this.tag) : doc.createElementNS(this.namespace, this.tag);
13785
- if (this.tag === "SELECT" && "value" in this.attrs) {
13786
- const { value, ...rest } = this.attrs;
13787
- applyProperties(node, rest, {});
13788
- appendChildNodes(node, this.childs, opts);
13789
- applyProperties(node, { value }, {});
13790
- } else {
13791
- applyProperties(node, this.attrs, {});
13792
- appendChildNodes(node, this.childs, opts);
13793
- }
13794
- return node;
13801
+ buildPath() {
13802
+ return this.dispatcher.path.concat(this.pathChanges);
13795
13803
  }
13796
13804
  };
13797
13805
  });