tutuca 0.9.82 → 0.9.83

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.
@@ -850,9 +850,6 @@ class DynVal extends RenderNameVal {
850
850
  eval(stack) {
851
851
  return stack.lookupDynamic(this.name);
852
852
  }
853
- toPathItem() {
854
- return null;
855
- }
856
853
  toString() {
857
854
  return `*${this.name}`;
858
855
  }
@@ -1090,7 +1087,7 @@ class ConstAttrs extends Attributes {
1090
1087
  toMacroVars() {
1091
1088
  const r = {};
1092
1089
  for (const name in this.items)
1093
- r[name] = `'${this.items[name]}'`;
1090
+ r[name] = new ConstVal(`${this.items[name]}`).toString();
1094
1091
  return r;
1095
1092
  }
1096
1093
  isConstant() {
@@ -1196,6 +1193,79 @@ class RequestHandler {
1196
1193
  }
1197
1194
  }
1198
1195
 
1196
+ // src/renderer.js
1197
+ import { isIndexed, isKeyed } from "immutable";
1198
+
1199
+ // src/cache.js
1200
+ class NullDomCache {
1201
+ get(_keys, _cacheKey) {}
1202
+ set(_keys, _cacheKey, _v) {}
1203
+ evict() {
1204
+ return { hit: 0, miss: 0, badKey: 0 };
1205
+ }
1206
+ }
1207
+
1208
+ class WeakMapDomCache {
1209
+ constructor() {
1210
+ this.hit = this.miss = this.badKey = 0;
1211
+ this.keysByLen = new Map;
1212
+ }
1213
+ _returnValue(r) {
1214
+ if (r === undefined)
1215
+ this.miss += 1;
1216
+ else
1217
+ this.hit += 1;
1218
+ return r;
1219
+ }
1220
+ get(keys, cacheKey) {
1221
+ const len = keys.length;
1222
+ let cur = this.keysByLen.get(len);
1223
+ if (!cur)
1224
+ return this._returnValue(undefined);
1225
+ for (let i = 0;i < len - 1; i++) {
1226
+ cur = cur.get(keys[i]);
1227
+ if (!cur)
1228
+ return this._returnValue(undefined);
1229
+ }
1230
+ return this._returnValue(cur.get(keys[len - 1])?.[cacheKey]);
1231
+ }
1232
+ set(keys, cacheKey, v) {
1233
+ const len = keys.length;
1234
+ let cur = this.keysByLen.get(len);
1235
+ if (!cur) {
1236
+ cur = new WeakMap;
1237
+ this.keysByLen.set(len, cur);
1238
+ }
1239
+ for (let i = 0;i < len - 1; i++) {
1240
+ const key = keys[i];
1241
+ let next = cur.get(key);
1242
+ if (!next) {
1243
+ if (typeof key !== "object") {
1244
+ this.badKey += 1;
1245
+ return;
1246
+ }
1247
+ next = new WeakMap;
1248
+ cur.set(key, next);
1249
+ }
1250
+ cur = next;
1251
+ }
1252
+ const lastKey = keys[len - 1];
1253
+ const leaf = cur.get(lastKey);
1254
+ if (leaf)
1255
+ leaf[cacheKey] = v;
1256
+ else if (typeof lastKey === "object")
1257
+ cur.set(lastKey, { [cacheKey]: v });
1258
+ else
1259
+ this.badKey += 1;
1260
+ }
1261
+ evict() {
1262
+ const { hit, miss, badKey } = this;
1263
+ this.hit = this.miss = this.badKey = 0;
1264
+ this.keysByLen = new Map;
1265
+ return { hit, miss, badKey };
1266
+ }
1267
+ }
1268
+
1199
1269
  // src/vdom.js
1200
1270
  var HTML_NS = "http://www.w3.org/1999/xhtml";
1201
1271
  var SVG_NS = "http://www.w3.org/2000/svg";
@@ -1223,6 +1293,7 @@ var NEVER_ASSIGN = new Set([
1223
1293
  "role",
1224
1294
  "popover"
1225
1295
  ]);
1296
+ var PROP_ATTR_NAME = { className: "class", htmlFor: "for" };
1226
1297
  function applyProperties(node, props) {
1227
1298
  const namespaced = isNamespaced(node);
1228
1299
  for (const name in props)
@@ -1241,15 +1312,22 @@ function setProp(node, name, value, namespaced) {
1241
1312
  }
1242
1313
  if (typeof value === "function")
1243
1314
  return;
1244
- if (!namespaced && !NEVER_ASSIGN.has(name) && name in node) {
1315
+ const usesProp = !namespaced && !NEVER_ASSIGN.has(name) && name in node;
1316
+ if (usesProp && value != null) {
1245
1317
  try {
1246
- node[name] = value == null ? "" : value;
1318
+ node[name] = value;
1247
1319
  return;
1248
1320
  } catch {}
1249
1321
  }
1250
- if (value == null || value === false && name[4] !== "-")
1251
- node.removeAttribute(name);
1252
- else
1322
+ if (value == null || value === false && name[4] !== "-") {
1323
+ if (usesProp) {
1324
+ try {
1325
+ node[name] = "";
1326
+ } catch {}
1327
+ node.removeAttribute(PROP_ATTR_NAME[name] ?? name);
1328
+ } else
1329
+ node.removeAttribute(name);
1330
+ } else
1253
1331
  node.setAttribute(name, value);
1254
1332
  }
1255
1333
  function applyValueLast(node, value) {
@@ -1430,22 +1508,12 @@ function morphNode(domNode, source, target, opts) {
1430
1508
  }
1431
1509
  if (type === 1 && source.isSameKind(target)) {
1432
1510
  const propsDiff = diffProps(source.attrs, target.attrs);
1433
- let pendingValue;
1434
- let pendingChecked;
1435
- let applyValue = false;
1436
- let applyChecked = false;
1511
+ const hasValue = propsDiff != null && "value" in propsDiff;
1512
+ const hasChecked = propsDiff != null && "checked" in propsDiff;
1437
1513
  if (propsDiff) {
1438
- if ("value" in propsDiff || "checked" in propsDiff) {
1439
- const { value, checked, ...rest } = propsDiff;
1514
+ if (hasValue || hasChecked) {
1515
+ const { value: _v, checked: _c, ...rest } = propsDiff;
1440
1516
  applyProperties(domNode, rest);
1441
- if ("value" in propsDiff) {
1442
- pendingValue = value;
1443
- applyValue = true;
1444
- }
1445
- if ("checked" in propsDiff) {
1446
- pendingChecked = checked;
1447
- applyChecked = true;
1448
- }
1449
1517
  } else
1450
1518
  applyProperties(domNode, propsDiff);
1451
1519
  }
@@ -1453,14 +1521,12 @@ function morphNode(domNode, source, target, opts) {
1453
1521
  const ns = effectiveNs(target, opts);
1454
1522
  morphChildren(domNode, source.childs, target.childs, childOpts(target, ns, opts));
1455
1523
  }
1456
- if (!applyValue && source.tag === "SELECT" && target.attrs.value !== undefined) {
1457
- pendingValue = target.attrs.value;
1458
- applyValue = true;
1459
- }
1460
- if (applyValue)
1461
- applyValueLast(domNode, pendingValue);
1462
- if (applyChecked)
1463
- setProp(domNode, "checked", pendingChecked, false);
1524
+ if (hasValue)
1525
+ applyValueLast(domNode, propsDiff.value);
1526
+ else if (source.tag === "SELECT" && target.attrs.value !== undefined)
1527
+ applyValueLast(domNode, target.attrs.value);
1528
+ if (hasChecked)
1529
+ setProp(domNode, "checked", propsDiff.checked, false);
1464
1530
  return domNode;
1465
1531
  }
1466
1532
  if (type === 11) {
@@ -1581,6 +1647,161 @@ function h(tagName, properties, children, namespace) {
1581
1647
  return new VNode(tag, props, normalizedChildren, key, namespace);
1582
1648
  }
1583
1649
 
1650
+ // src/renderer.js
1651
+ var DATASET_ATTRS = ["nid", "cid", "eid", "vid", "si", "sk"];
1652
+
1653
+ class Renderer {
1654
+ constructor(comps) {
1655
+ this.comps = comps;
1656
+ this.cache = new WeakMapDomCache;
1657
+ this.renderTag = h;
1658
+ }
1659
+ renderFragment(childs) {
1660
+ return new VFragment(childs);
1661
+ }
1662
+ renderComment(text) {
1663
+ return new VComment(text);
1664
+ }
1665
+ setNullCache() {
1666
+ this.cache = new NullDomCache;
1667
+ }
1668
+ renderToDOM(stack, val) {
1669
+ const rootNode = document.createElement("div");
1670
+ const rOpts = { document };
1671
+ render(h("DIV", null, [this.renderRoot(stack, val)]), rootNode, rOpts);
1672
+ return rootNode.childNodes[0];
1673
+ }
1674
+ renderToString(stack, val, cleanAttrs = true) {
1675
+ const dom = this.renderToDOM(stack, val);
1676
+ if (cleanAttrs) {
1677
+ const nodes = dom.querySelectorAll("[data-nid],[data-cid],[data-eid]");
1678
+ for (const { dataset } of nodes)
1679
+ for (const name of DATASET_ATTRS)
1680
+ delete dataset[name];
1681
+ }
1682
+ return dom.innerHTML;
1683
+ }
1684
+ renderRoot(stack, val, viewName = null) {
1685
+ const comp = this.comps.getCompFor(val);
1686
+ if (comp === null)
1687
+ return null;
1688
+ return this._rValComp(stack, val, comp, comp.getView(viewName).anode, "ROOT", viewName);
1689
+ }
1690
+ renderIt(stack, node, key, viewName) {
1691
+ const comp = this.comps.getCompFor(stack.it);
1692
+ return comp ? this._rValComp(stack, stack.it, comp, node, key, viewName) : null;
1693
+ }
1694
+ _rValComp(stack, val, comp, node, key, viewName) {
1695
+ const cacheKey = `${viewName ?? stack.viewsId ?? ""}-${key}`;
1696
+ const cachePath = [node, val];
1697
+ stack._pushDynBindValuesToArray(cachePath, comp);
1698
+ const cachedNode = this.cache.get(cachePath, cacheKey);
1699
+ if (cachedNode)
1700
+ return cachedNode;
1701
+ const view = viewName ? comp.getView(viewName) : stack.lookupBestView(comp.views, "main");
1702
+ const meta = this._renderMetadata({
1703
+ $: "Comp",
1704
+ nid: node?.nodeId ?? null,
1705
+ cid: comp.id,
1706
+ vid: view.name
1707
+ });
1708
+ const dom = new VFragment([meta, this.renderView(view, stack)]);
1709
+ this.cache.set(cachePath, cacheKey, dom);
1710
+ return dom;
1711
+ }
1712
+ pushEachEntry(r, nid, attrName, key, dom) {
1713
+ r.push(this._renderMetadata({ $: "Each", nid, [attrName]: key }), dom);
1714
+ }
1715
+ renderEach(stack, iterInfo, node, viewName) {
1716
+ const { seq, filter, loopWith } = iterInfo.eval(stack);
1717
+ const r = [];
1718
+ const { iterData, start, end } = unpackLoopResult(loopWith.call(stack.it, seq), seq);
1719
+ getSeqInfo(seq)(seq, (key, value, attrName) => {
1720
+ if (filter.call(stack.it, key, value, iterData)) {
1721
+ const dom = this.renderIt(stack.enter(value, { key }, true), node, key, viewName);
1722
+ this.pushEachEntry(r, node.nodeId, attrName, key, dom);
1723
+ }
1724
+ }, start, end);
1725
+ return r;
1726
+ }
1727
+ renderEachWhen(stack, iterInfo, view, nid) {
1728
+ const { seq, filter, loopWith, enricher } = iterInfo.eval(stack);
1729
+ const r = [];
1730
+ const it = stack.it;
1731
+ const { iterData, start, end } = unpackLoopResult(loopWith.call(it, seq), seq);
1732
+ getSeqInfo(seq)(seq, (key, value, attrName) => {
1733
+ if (filter.call(it, key, value, iterData)) {
1734
+ const cachePath = enricher ? [view, it, value] : [view, value];
1735
+ const binds = { key, value };
1736
+ const cacheKey = `${nid}-${key}`;
1737
+ if (enricher)
1738
+ enricher.call(it, binds, key, value, iterData);
1739
+ const cachedNode = this.cache.get(cachePath, cacheKey);
1740
+ if (cachedNode)
1741
+ this.pushEachEntry(r, nid, attrName, key, cachedNode);
1742
+ else {
1743
+ const dom = this.renderView(view, stack.enter(value, binds, false));
1744
+ this.pushEachEntry(r, nid, attrName, key, dom);
1745
+ this.cache.set(cachePath, cacheKey, dom);
1746
+ }
1747
+ }
1748
+ }, start, end);
1749
+ return r;
1750
+ }
1751
+ renderView(view, stack) {
1752
+ let n = stack.binds[1];
1753
+ while (n !== null) {
1754
+ const b = n[0];
1755
+ if (b.isFrame) {
1756
+ if (stack.it !== b.it)
1757
+ break;
1758
+ console.error("recursion detected", stack.it, b.it);
1759
+ return new VComment("RECURSION AVOIDED");
1760
+ }
1761
+ n = n[1];
1762
+ }
1763
+ return view.render(stack, this);
1764
+ }
1765
+ _renderMetadata(info) {
1766
+ return new VComment(`§${JSON.stringify(info)}§`);
1767
+ }
1768
+ }
1769
+ var getSeqInfo = (seq) => isIndexed(seq) ? imIndexedIter : isKeyed(seq) ? imKeyedIter : seq?.[SEQ_INFO] ?? unkIter;
1770
+ var normalizeRange = (start, end, size) => {
1771
+ let s = start == null ? 0 : start < 0 ? size + start : start;
1772
+ let e = end == null ? size : end < 0 ? size + end : end;
1773
+ s = s < 0 ? 0 : s > size ? size : s;
1774
+ e = e < 0 ? 0 : e > size ? size : e;
1775
+ return [s, e < s ? s : e];
1776
+ };
1777
+ var filterAlwaysTrue = (_v, _k, _seq) => true;
1778
+ var nullLoopWith = (seq) => ({ iterData: { seq } });
1779
+ var unpackLoopResult = (result, seq) => {
1780
+ const r = result ?? {};
1781
+ return { iterData: r.iterData ?? { seq }, start: r.start, end: r.end };
1782
+ };
1783
+ var imIndexedIter = (seq, visit, start, end) => {
1784
+ const [s, e] = normalizeRange(start, end, seq.size);
1785
+ for (let i = s;i < e; i++)
1786
+ visit(i, seq.get(i), "si");
1787
+ };
1788
+ var imKeyedIter = (seq, visit, start, end) => {
1789
+ const [s, e] = normalizeRange(start, end, seq.size);
1790
+ let i = 0;
1791
+ for (const [k, v] of seq.toSeq().entries()) {
1792
+ if (i >= e)
1793
+ break;
1794
+ if (i >= s)
1795
+ visit(k, v, "sk");
1796
+ i++;
1797
+ }
1798
+ };
1799
+ var unkIter = () => {};
1800
+ var SEQ_INFO = Symbol.for("tutuca.seqInfo");
1801
+
1802
+ // src/util/env.js
1803
+ var isMac = (globalThis.navigator?.userAgent ?? "").toLowerCase().includes("mac");
1804
+
1584
1805
  // src/anode.js
1585
1806
  function resolveDynProducer(comp, name) {
1586
1807
  let producerComp, producerProvide;
@@ -1784,7 +2005,7 @@ class ANode extends BaseNode {
1784
2005
  }
1785
2006
  }
1786
2007
  function parseXOp(attrs, childs, opIdx, px) {
1787
- if (attrs.length === 0)
2008
+ if (attrs.length <= opIdx)
1788
2009
  return maybeFragment(childs);
1789
2010
  const { name, value } = attrs[opIdx];
1790
2011
  const as = attrs.getNamedItem("as")?.value ?? null;
@@ -2105,8 +2326,6 @@ class IterInfo {
2105
2326
  return { seq, filter, loopWith, enricher };
2106
2327
  }
2107
2328
  }
2108
- var filterAlwaysTrue = (_v, _k, _seq) => true;
2109
- var nullLoopWith = (seq) => ({ iterData: { seq } });
2110
2329
  function xOp(consumed = [], { wrappable = false, wrapper = null } = {}) {
2111
2330
  return { consumed: new Set(consumed), wrappable, wrapper };
2112
2331
  }
@@ -2293,7 +2512,6 @@ class NodeEvent {
2293
2512
  return r;
2294
2513
  }
2295
2514
  }
2296
- var isMac = (globalThis.navigator?.userAgent ?? "").toLowerCase().includes("mac");
2297
2515
  var fwdIfCtxPred = (pred) => (w) => (that, f, args, ctx) => pred(ctx) ? w(that, f, args, ctx) : that;
2298
2516
  var fwdIfKey = (keyName) => fwdIfCtxPred((ctx) => ctx.e.key === keyName);
2299
2517
  var fwdCtrl = fwdIfCtxPred(({ e }) => isMac && e.metaKey || e.ctrlKey);
@@ -2801,7 +3019,6 @@ class Transaction {
2801
3019
  return null;
2802
3020
  }
2803
3021
  }
2804
- var isMac2 = (globalThis.navigator?.userAgent ?? "").toLowerCase().includes("mac");
2805
3022
  var toNullIfNaN = (v) => Number.isNaN(v) ? null : v;
2806
3023
  function getValue(e) {
2807
3024
  return e.target.type === "checkbox" ? e.target.checked : (e instanceof CustomEvent ? e.detail : e.target.value) ?? null;
@@ -2855,7 +3072,7 @@ class InputEvent extends Transaction {
2855
3072
  return e.shiftKey;
2856
3073
  case "isCtrl":
2857
3074
  case "isCmd":
2858
- return isMac2 && e.metaKey || e.ctrlKey;
3075
+ return isMac && e.metaKey || e.ctrlKey;
2859
3076
  case "key":
2860
3077
  return e.key;
2861
3078
  case "keyCode":
@@ -3335,18 +3552,82 @@ class ParseCtxClassSetCollector extends ParseContext {
3335
3552
  return false;
3336
3553
  }
3337
3554
  }
3555
+ function collectAppClassesInSet(app) {
3556
+ const classes = new Set;
3557
+ for (const Comp of app.comps.byId.values()) {
3558
+ for (const key in Comp.views) {
3559
+ const view = Comp.views[key];
3560
+ for (const name of view.ctx.classes) {
3561
+ classes.add(name);
3562
+ }
3563
+ }
3564
+ }
3565
+ return classes;
3566
+ }
3338
3567
 
3339
- // extra/klist.js
3340
- import { Map as IMap2, List as List2 } from "immutable";
3341
-
3342
- // src/oo.js
3343
- import { Map as IMap, Set as ISet, List, OrderedMap, Record } from "immutable";
3344
- var BAD_VALUE = Symbol("BadValue");
3345
- var nullCoercer = (v) => v;
3346
-
3347
- class Field {
3348
- constructor(type, name, typeCheck, coercer, defaultValue = null) {
3349
- this.type = type;
3568
+ // index.js
3569
+ import {
3570
+ Collection,
3571
+ fromJS,
3572
+ get,
3573
+ getIn,
3574
+ has,
3575
+ hash,
3576
+ hasIn,
3577
+ is as is2,
3578
+ isAssociative,
3579
+ isCollection,
3580
+ isImmutable,
3581
+ isIndexed as isIndexed2,
3582
+ isKeyed as isKeyed2,
3583
+ isList,
3584
+ isMap,
3585
+ isMap as isMap2,
3586
+ isOrdered,
3587
+ isOrderedMap,
3588
+ isOrderedMap as isOrderedMap2,
3589
+ isOrderedSet,
3590
+ isPlainObject,
3591
+ isRecord,
3592
+ isSeq,
3593
+ isSet,
3594
+ isStack,
3595
+ isValueObject,
3596
+ List as List2,
3597
+ Map as Map2,
3598
+ Map as Map3,
3599
+ merge,
3600
+ mergeDeep,
3601
+ mergeDeepWith,
3602
+ mergeWith,
3603
+ OrderedMap as OrderedMap2,
3604
+ OrderedMap as OrderedMap3,
3605
+ OrderedSet,
3606
+ PairSorting,
3607
+ Range,
3608
+ Record as Record2,
3609
+ Repeat,
3610
+ remove,
3611
+ removeIn,
3612
+ Seq,
3613
+ Set as Set2,
3614
+ Set as Set3,
3615
+ Stack as Stack2,
3616
+ set,
3617
+ setIn,
3618
+ update,
3619
+ updateIn,
3620
+ version
3621
+ } from "immutable";
3622
+
3623
+ // src/oo.js
3624
+ import { Map as IMap, Set as ISet, List, OrderedMap, Record } from "immutable";
3625
+ var BAD_VALUE = Symbol("BadValue");
3626
+ var nullCoercer = (v) => v;
3627
+
3628
+ class Field {
3629
+ constructor(type, name, typeCheck, coercer, defaultValue = null) {
3630
+ this.type = type;
3350
3631
  this.name = name;
3351
3632
  this.typeCheck = typeCheck;
3352
3633
  this.coercer = coercer;
@@ -3606,8 +3887,8 @@ class FieldSet extends Field {
3606
3887
  }
3607
3888
  }
3608
3889
  function mkCompField(field, scope, args) {
3609
- const Comp = scope.lookupComponent(field.type);
3610
- console.assert(Comp !== null, "component not found", { field });
3890
+ const Comp = scope?.lookupComponent(field.type) ?? null;
3891
+ console.assert(!scope || Comp !== null, "component not found", { field });
3611
3892
  return Comp?.make({ ...field.args, ...args }, { scope }) ?? null;
3612
3893
  }
3613
3894
 
@@ -3724,378 +4005,7 @@ function classFromData(name, { fields = {}, methods, statics }) {
3724
4005
  Component.fromSpec = (opts) => new Component(classFromData(opts.name, opts), opts);
3725
4006
  var component = (opts) => Component.fromSpec(opts);
3726
4007
 
3727
- // src/renderer.js
3728
- import { isIndexed, isKeyed } from "immutable";
3729
-
3730
- // src/cache.js
3731
- class NullDomCache {
3732
- get(_keys, _cacheKey) {}
3733
- set(_keys, _cacheKey, _v) {}
3734
- evict() {
3735
- return { hit: 0, miss: 0, badKey: 0 };
3736
- }
3737
- }
3738
-
3739
- class WeakMapDomCache {
3740
- constructor() {
3741
- this.hit = this.miss = this.badKey = 0;
3742
- this.keysByLen = new Map;
3743
- }
3744
- _returnValue(r) {
3745
- if (r === undefined)
3746
- this.miss += 1;
3747
- else
3748
- this.hit += 1;
3749
- return r;
3750
- }
3751
- get(keys, cacheKey) {
3752
- const len = keys.length;
3753
- let cur = this.keysByLen.get(len);
3754
- if (!cur)
3755
- return this._returnValue(undefined);
3756
- for (let i = 0;i < len - 1; i++) {
3757
- cur = cur.get(keys[i]);
3758
- if (!cur)
3759
- return this._returnValue(undefined);
3760
- }
3761
- return this._returnValue(cur.get(keys[len - 1])?.[cacheKey]);
3762
- }
3763
- set(keys, cacheKey, v) {
3764
- const len = keys.length;
3765
- let cur = this.keysByLen.get(len);
3766
- if (!cur) {
3767
- cur = new WeakMap;
3768
- this.keysByLen.set(len, cur);
3769
- }
3770
- for (let i = 0;i < len - 1; i++) {
3771
- const key = keys[i];
3772
- let next = cur.get(key);
3773
- if (!next) {
3774
- if (typeof key !== "object") {
3775
- this.badKey += 1;
3776
- return;
3777
- }
3778
- next = new WeakMap;
3779
- cur.set(key, next);
3780
- }
3781
- cur = next;
3782
- }
3783
- const lastKey = keys[len - 1];
3784
- const leaf = cur.get(lastKey);
3785
- if (leaf)
3786
- leaf[cacheKey] = v;
3787
- else if (typeof lastKey === "object")
3788
- cur.set(lastKey, { [cacheKey]: v });
3789
- else
3790
- this.badKey += 1;
3791
- }
3792
- evict() {
3793
- const { hit, miss, badKey } = this;
3794
- this.hit = this.miss = this.badKey = 0;
3795
- this.keysByLen = new Map;
3796
- return { hit, miss, badKey };
3797
- }
3798
- }
3799
-
3800
- // src/renderer.js
3801
- var DATASET_ATTRS = ["nid", "cid", "eid", "vid", "si", "sk"];
3802
-
3803
- class Renderer {
3804
- constructor(comps) {
3805
- this.comps = comps;
3806
- this.cache = new WeakMapDomCache;
3807
- this.renderTag = h;
3808
- }
3809
- renderFragment(childs) {
3810
- return new VFragment(childs);
3811
- }
3812
- renderComment(text) {
3813
- return new VComment(text);
3814
- }
3815
- setNullCache() {
3816
- this.cache = new NullDomCache;
3817
- }
3818
- renderToDOM(stack, val) {
3819
- const rootNode = document.createElement("div");
3820
- const rOpts = { document };
3821
- render(h("DIV", null, [this.renderRoot(stack, val)]), rootNode, rOpts);
3822
- return rootNode.childNodes[0];
3823
- }
3824
- renderToString(stack, val, cleanAttrs = true) {
3825
- const dom = this.renderToDOM(stack, val);
3826
- if (cleanAttrs) {
3827
- const nodes = dom.querySelectorAll("[data-nid],[data-cid],[data-eid]");
3828
- for (const { dataset } of nodes)
3829
- for (const name of DATASET_ATTRS)
3830
- delete dataset[name];
3831
- }
3832
- return dom.innerHTML;
3833
- }
3834
- renderRoot(stack, val, viewName = null) {
3835
- const comp = this.comps.getCompFor(val);
3836
- if (comp === null)
3837
- return null;
3838
- return this._rValComp(stack, val, comp, comp.getView(viewName).anode, "ROOT", viewName);
3839
- }
3840
- renderIt(stack, node, key, viewName) {
3841
- const comp = this.comps.getCompFor(stack.it);
3842
- return comp ? this._rValComp(stack, stack.it, comp, node, key, viewName) : null;
3843
- }
3844
- _rValComp(stack, val, comp, node, key, viewName) {
3845
- const cacheKey = `${viewName ?? stack.viewsId ?? ""}-${key}`;
3846
- const cachePath = [node, val];
3847
- stack._pushDynBindValuesToArray(cachePath, comp);
3848
- const cachedNode = this.cache.get(cachePath, cacheKey);
3849
- if (cachedNode)
3850
- return cachedNode;
3851
- const view = viewName ? comp.getView(viewName) : stack.lookupBestView(comp.views, "main");
3852
- const meta = this._renderMetadata({
3853
- $: "Comp",
3854
- nid: node?.nodeId ?? null,
3855
- cid: comp.id,
3856
- vid: view.name
3857
- });
3858
- const dom = new VFragment([meta, this.renderView(view, stack)]);
3859
- this.cache.set(cachePath, cacheKey, dom);
3860
- return dom;
3861
- }
3862
- pushEachEntry(r, nid, attrName, key, dom) {
3863
- r.push(this._renderMetadata({ $: "Each", nid, [attrName]: key }), dom);
3864
- }
3865
- renderEach(stack, iterInfo, node, viewName) {
3866
- const { seq, filter, loopWith } = iterInfo.eval(stack);
3867
- const r = [];
3868
- const { iterData, start, end } = unpackLoopResult(loopWith.call(stack.it, seq), seq);
3869
- getSeqInfo(seq)(seq, (key, value, attrName) => {
3870
- if (filter.call(stack.it, key, value, iterData)) {
3871
- const dom = this.renderIt(stack.enter(value, { key }, true), node, key, viewName);
3872
- this.pushEachEntry(r, node.nodeId, attrName, key, dom);
3873
- }
3874
- }, start, end);
3875
- return r;
3876
- }
3877
- renderEachWhen(stack, iterInfo, view, nid) {
3878
- const { seq, filter, loopWith, enricher } = iterInfo.eval(stack);
3879
- const r = [];
3880
- const it = stack.it;
3881
- const { iterData, start, end } = unpackLoopResult(loopWith.call(it, seq), seq);
3882
- getSeqInfo(seq)(seq, (key, value, attrName) => {
3883
- if (filter.call(it, key, value, iterData)) {
3884
- const cachePath = enricher ? [view, it, value] : [view, value];
3885
- const binds = { key, value };
3886
- const cacheKey = `${nid}-${key}`;
3887
- if (enricher)
3888
- enricher.call(it, binds, key, value, iterData);
3889
- const cachedNode = this.cache.get(cachePath, cacheKey);
3890
- if (cachedNode)
3891
- this.pushEachEntry(r, nid, attrName, key, cachedNode);
3892
- else {
3893
- const dom = this.renderView(view, stack.enter(value, binds, false));
3894
- this.pushEachEntry(r, nid, attrName, key, dom);
3895
- this.cache.set(cachePath, cacheKey, dom);
3896
- }
3897
- }
3898
- }, start, end);
3899
- return r;
3900
- }
3901
- renderView(view, stack) {
3902
- let n = stack.binds[1];
3903
- while (n !== null) {
3904
- const b = n[0];
3905
- if (b.isFrame) {
3906
- if (stack.it !== b.it)
3907
- break;
3908
- console.error("recursion detected", stack.it, b.it);
3909
- return new VComment("RECURSION AVOIDED");
3910
- }
3911
- n = n[1];
3912
- }
3913
- return view.render(stack, this);
3914
- }
3915
- _renderMetadata(info) {
3916
- return new VComment(`§${JSON.stringify(info)}§`);
3917
- }
3918
- }
3919
- var getSeqInfo = (seq) => isIndexed(seq) ? imIndexedIter : isKeyed(seq) ? imKeyedIter : seq?.[SEQ_INFO] ?? unkIter;
3920
- var normalizeRange = (start, end, size) => {
3921
- let s = start == null ? 0 : start < 0 ? size + start : start;
3922
- let e = end == null ? size : end < 0 ? size + end : end;
3923
- s = s < 0 ? 0 : s > size ? size : s;
3924
- e = e < 0 ? 0 : e > size ? size : e;
3925
- return [s, e < s ? s : e];
3926
- };
3927
- var unpackLoopResult = (result, seq) => {
3928
- const r = result ?? {};
3929
- return { iterData: r.iterData ?? { seq }, start: r.start, end: r.end };
3930
- };
3931
- var imIndexedIter = (seq, visit, start, end) => {
3932
- const [s, e] = normalizeRange(start, end, seq.size);
3933
- for (let i = s;i < e; i++)
3934
- visit(i, seq.get(i), "si");
3935
- };
3936
- var imKeyedIter = (seq, visit, start, end) => {
3937
- const [s, e] = normalizeRange(start, end, seq.size);
3938
- let i = 0;
3939
- for (const [k, v] of seq.toSeq().entries()) {
3940
- if (i >= e)
3941
- break;
3942
- if (i >= s)
3943
- visit(k, v, "sk");
3944
- i++;
3945
- }
3946
- };
3947
- var unkIter = () => {};
3948
- var SEQ_INFO = Symbol.for("tutuca.seqInfo");
3949
-
3950
- // extra/klist.js
3951
- class KList {
3952
- constructor(items = IMap2(), order = List2()) {
3953
- this.items = items;
3954
- this.order = order;
3955
- this.$ = 0;
3956
- }
3957
- _clonish(items, order) {
3958
- return new KList(items, order, this.$);
3959
- }
3960
- toJS() {
3961
- return this.order.toArray().map((k) => this.items.get(k));
3962
- }
3963
- set(k, v) {
3964
- const newOrder = this.items.has(k) ? this.order : this.order.push(k);
3965
- return this._clonish(this.items.set(k, v), newOrder, this.$);
3966
- }
3967
- get(k, dval = null) {
3968
- return this.items.get(k, dval);
3969
- }
3970
- _nextFreeKey() {
3971
- let cur = this.$;
3972
- while (true) {
3973
- const key = `§${cur}§`;
3974
- if (!this.items.has(key)) {
3975
- return [key, cur];
3976
- }
3977
- cur += 1;
3978
- }
3979
- }
3980
- push(v) {
3981
- const [key, next$] = this._nextFreeKey();
3982
- const newKList = this.set(key, v);
3983
- newKList.$ = next$;
3984
- return newKList;
3985
- }
3986
- get size() {
3987
- return this.items.size;
3988
- }
3989
- delete(k) {
3990
- if (this.items.has(k)) {
3991
- const newOrder = this.order.delete(this.order.indexOf(k));
3992
- return this._clonish(this.items.delete(k), newOrder);
3993
- }
3994
- return this;
3995
- }
3996
- moveKeyBeforeKey(k1, k2) {
3997
- const { order } = this;
3998
- return this.moveKeyIndexToIndex(order.indexOf(k1), order.indexOf(k2), 0);
3999
- }
4000
- moveKeyAfterKey(k1, k2) {
4001
- const { order } = this;
4002
- return this.moveKeyIndexToIndex(order.indexOf(k1), order.indexOf(k2), 1);
4003
- }
4004
- moveKeyIndexToIndex(source, target, offset) {
4005
- if (source === -1 || target === -1 || source === target) {
4006
- return this;
4007
- }
4008
- const { order } = this;
4009
- const newPos = target + offset;
4010
- const oldPos = newPos < source ? source + 1 : source;
4011
- const newOrder = order.insert(newPos, order.get(source)).delete(oldPos);
4012
- return this._clonish(this.items, newOrder);
4013
- }
4014
- }
4015
- var klistCoercer = (_) => null;
4016
-
4017
- class CheckTypeKList {
4018
- isValid(v) {
4019
- return v instanceof KList;
4020
- }
4021
- getMessage(_v) {
4022
- return "KList expected";
4023
- }
4024
- }
4025
- var CHECK_TYPE_KLIST = new CheckTypeKList;
4026
-
4027
- class FieldKList extends Field {
4028
- constructor(name, defaultValue = new KList) {
4029
- super("KList", name, CHECK_TYPE_KLIST, klistCoercer, defaultValue);
4030
- }
4031
- extendProtoForType(proto, uname) {
4032
- extendProtoForKeyed(proto, this.name, uname);
4033
- const { name } = this;
4034
- extendProtoForKeyed(proto, name, uname);
4035
- proto[`pushIn${uname}`] = function(v) {
4036
- return this.set(name, this.get(name).push(v));
4037
- };
4038
- }
4039
- }
4040
- KList.prototype[FIELD_CLASS] = FieldKList;
4041
- KList.prototype[SEQ_INFO] = (seq, visit) => {
4042
- for (const k of seq.order)
4043
- visit(k, seq.items.get(k), "data-sk");
4044
- };
4045
4008
  // index.js
4046
- import {
4047
- Collection,
4048
- List as List3,
4049
- Map as Map2,
4050
- OrderedMap as OrderedMap2,
4051
- OrderedSet,
4052
- PairSorting,
4053
- Range,
4054
- Record as Record2,
4055
- Repeat,
4056
- Seq,
4057
- Set as Set2,
4058
- Stack as Stack2,
4059
- fromJS,
4060
- get,
4061
- getIn,
4062
- has,
4063
- hasIn,
4064
- hash,
4065
- is as is2,
4066
- isAssociative,
4067
- isCollection,
4068
- isImmutable,
4069
- isIndexed as isIndexed2,
4070
- isKeyed as isKeyed2,
4071
- isList,
4072
- isMap,
4073
- isOrdered,
4074
- isOrderedMap,
4075
- isOrderedSet,
4076
- isPlainObject,
4077
- isRecord,
4078
- isSeq,
4079
- isSet,
4080
- isStack,
4081
- isValueObject,
4082
- merge,
4083
- mergeDeep,
4084
- mergeDeepWith,
4085
- mergeWith,
4086
- remove,
4087
- removeIn,
4088
- set,
4089
- setIn,
4090
- update,
4091
- updateIn,
4092
- version,
4093
- isMap as isMap2,
4094
- isOrderedMap as isOrderedMap2,
4095
- Map as Map3,
4096
- OrderedMap as OrderedMap3,
4097
- Set as Set3
4098
- } from "immutable";
4099
4009
  var css = String.raw;
4100
4010
  var html = String.raw;
4101
4011
  var macro = (defaults, rawView) => new Macro(defaults, rawView);
@@ -4127,15 +4037,7 @@ async function compileClassesToStyle(app, compileClasses, styleId = "margaui-css
4127
4037
  async function compileClassesToStyleText(app, compileClasses, Ctx = ParseCtxClassSetCollector) {
4128
4038
  app.ParseContext = Ctx;
4129
4039
  app.compile();
4130
- const classes = new Set;
4131
- for (const Comp of app.comps.byId.values()) {
4132
- for (const key in Comp.views) {
4133
- const view = Comp.views[key];
4134
- for (const name of view.ctx.classes)
4135
- classes.add(name);
4136
- }
4137
- }
4138
- return await compileClasses(Array.from(classes));
4040
+ return await compileClasses(Array.from(collectAppClassesInSet(app)));
4139
4041
  }
4140
4042
  export {
4141
4043
  version,
@@ -4198,8 +4100,7 @@ export {
4198
4100
  OrderedMap2 as OrderedMap,
4199
4101
  OrderedMap3 as OMap,
4200
4102
  Map2 as Map,
4201
- List3 as List,
4202
- KList,
4103
+ List2 as List,
4203
4104
  Set3 as ISet,
4204
4105
  Map3 as IMap,
4205
4106
  FIELD_CLASS,