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.
@@ -5223,9 +5223,6 @@ class DynVal extends RenderNameVal {
5223
5223
  eval(stack) {
5224
5224
  return stack.lookupDynamic(this.name);
5225
5225
  }
5226
- toPathItem() {
5227
- return null;
5228
- }
5229
5226
  toString() {
5230
5227
  return `*${this.name}`;
5231
5228
  }
@@ -5463,7 +5460,7 @@ class ConstAttrs extends Attributes {
5463
5460
  toMacroVars() {
5464
5461
  const r = {};
5465
5462
  for (const name in this.items)
5466
- r[name] = `'${this.items[name]}'`;
5463
+ r[name] = new ConstVal(`${this.items[name]}`).toString();
5467
5464
  return r;
5468
5465
  }
5469
5466
  isConstant() {
@@ -5569,6 +5566,76 @@ class RequestHandler {
5569
5566
  }
5570
5567
  }
5571
5568
 
5569
+ // src/cache.js
5570
+ class NullDomCache {
5571
+ get(_keys, _cacheKey) {}
5572
+ set(_keys, _cacheKey, _v) {}
5573
+ evict() {
5574
+ return { hit: 0, miss: 0, badKey: 0 };
5575
+ }
5576
+ }
5577
+
5578
+ class WeakMapDomCache {
5579
+ constructor() {
5580
+ this.hit = this.miss = this.badKey = 0;
5581
+ this.keysByLen = new Map;
5582
+ }
5583
+ _returnValue(r) {
5584
+ if (r === undefined)
5585
+ this.miss += 1;
5586
+ else
5587
+ this.hit += 1;
5588
+ return r;
5589
+ }
5590
+ get(keys, cacheKey) {
5591
+ const len = keys.length;
5592
+ let cur = this.keysByLen.get(len);
5593
+ if (!cur)
5594
+ return this._returnValue(undefined);
5595
+ for (let i = 0;i < len - 1; i++) {
5596
+ cur = cur.get(keys[i]);
5597
+ if (!cur)
5598
+ return this._returnValue(undefined);
5599
+ }
5600
+ return this._returnValue(cur.get(keys[len - 1])?.[cacheKey]);
5601
+ }
5602
+ set(keys, cacheKey, v) {
5603
+ const len = keys.length;
5604
+ let cur = this.keysByLen.get(len);
5605
+ if (!cur) {
5606
+ cur = new WeakMap;
5607
+ this.keysByLen.set(len, cur);
5608
+ }
5609
+ for (let i = 0;i < len - 1; i++) {
5610
+ const key = keys[i];
5611
+ let next = cur.get(key);
5612
+ if (!next) {
5613
+ if (typeof key !== "object") {
5614
+ this.badKey += 1;
5615
+ return;
5616
+ }
5617
+ next = new WeakMap;
5618
+ cur.set(key, next);
5619
+ }
5620
+ cur = next;
5621
+ }
5622
+ const lastKey = keys[len - 1];
5623
+ const leaf = cur.get(lastKey);
5624
+ if (leaf)
5625
+ leaf[cacheKey] = v;
5626
+ else if (typeof lastKey === "object")
5627
+ cur.set(lastKey, { [cacheKey]: v });
5628
+ else
5629
+ this.badKey += 1;
5630
+ }
5631
+ evict() {
5632
+ const { hit, miss, badKey } = this;
5633
+ this.hit = this.miss = this.badKey = 0;
5634
+ this.keysByLen = new Map;
5635
+ return { hit, miss, badKey };
5636
+ }
5637
+ }
5638
+
5572
5639
  // src/vdom.js
5573
5640
  var HTML_NS = "http://www.w3.org/1999/xhtml";
5574
5641
  var SVG_NS = "http://www.w3.org/2000/svg";
@@ -5596,6 +5663,7 @@ var NEVER_ASSIGN = new Set([
5596
5663
  "role",
5597
5664
  "popover"
5598
5665
  ]);
5666
+ var PROP_ATTR_NAME = { className: "class", htmlFor: "for" };
5599
5667
  function applyProperties(node, props) {
5600
5668
  const namespaced = isNamespaced(node);
5601
5669
  for (const name in props)
@@ -5614,15 +5682,22 @@ function setProp2(node, name, value, namespaced) {
5614
5682
  }
5615
5683
  if (typeof value === "function")
5616
5684
  return;
5617
- if (!namespaced && !NEVER_ASSIGN.has(name) && name in node) {
5685
+ const usesProp = !namespaced && !NEVER_ASSIGN.has(name) && name in node;
5686
+ if (usesProp && value != null) {
5618
5687
  try {
5619
- node[name] = value == null ? "" : value;
5688
+ node[name] = value;
5620
5689
  return;
5621
5690
  } catch {}
5622
5691
  }
5623
- if (value == null || value === false && name[4] !== "-")
5624
- node.removeAttribute(name);
5625
- else
5692
+ if (value == null || value === false && name[4] !== "-") {
5693
+ if (usesProp) {
5694
+ try {
5695
+ node[name] = "";
5696
+ } catch {}
5697
+ node.removeAttribute(PROP_ATTR_NAME[name] ?? name);
5698
+ } else
5699
+ node.removeAttribute(name);
5700
+ } else
5626
5701
  node.setAttribute(name, value);
5627
5702
  }
5628
5703
  function applyValueLast(node, value) {
@@ -5803,22 +5878,12 @@ function morphNode(domNode, source, target, opts) {
5803
5878
  }
5804
5879
  if (type === 1 && source.isSameKind(target)) {
5805
5880
  const propsDiff = diffProps(source.attrs, target.attrs);
5806
- let pendingValue;
5807
- let pendingChecked;
5808
- let applyValue = false;
5809
- let applyChecked = false;
5881
+ const hasValue = propsDiff != null && "value" in propsDiff;
5882
+ const hasChecked = propsDiff != null && "checked" in propsDiff;
5810
5883
  if (propsDiff) {
5811
- if ("value" in propsDiff || "checked" in propsDiff) {
5812
- const { value, checked, ...rest } = propsDiff;
5884
+ if (hasValue || hasChecked) {
5885
+ const { value: _v, checked: _c, ...rest } = propsDiff;
5813
5886
  applyProperties(domNode, rest);
5814
- if ("value" in propsDiff) {
5815
- pendingValue = value;
5816
- applyValue = true;
5817
- }
5818
- if ("checked" in propsDiff) {
5819
- pendingChecked = checked;
5820
- applyChecked = true;
5821
- }
5822
5887
  } else
5823
5888
  applyProperties(domNode, propsDiff);
5824
5889
  }
@@ -5826,14 +5891,12 @@ function morphNode(domNode, source, target, opts) {
5826
5891
  const ns = effectiveNs(target, opts);
5827
5892
  morphChildren(domNode, source.childs, target.childs, childOpts(target, ns, opts));
5828
5893
  }
5829
- if (!applyValue && source.tag === "SELECT" && target.attrs.value !== undefined) {
5830
- pendingValue = target.attrs.value;
5831
- applyValue = true;
5832
- }
5833
- if (applyValue)
5834
- applyValueLast(domNode, pendingValue);
5835
- if (applyChecked)
5836
- setProp2(domNode, "checked", pendingChecked, false);
5894
+ if (hasValue)
5895
+ applyValueLast(domNode, propsDiff.value);
5896
+ else if (source.tag === "SELECT" && target.attrs.value !== undefined)
5897
+ applyValueLast(domNode, target.attrs.value);
5898
+ if (hasChecked)
5899
+ setProp2(domNode, "checked", propsDiff.checked, false);
5837
5900
  return domNode;
5838
5901
  }
5839
5902
  if (type === 11) {
@@ -5954,6 +6017,161 @@ function h(tagName, properties, children, namespace) {
5954
6017
  return new VNode2(tag, props, normalizedChildren, key, namespace);
5955
6018
  }
5956
6019
 
6020
+ // src/renderer.js
6021
+ var DATASET_ATTRS = ["nid", "cid", "eid", "vid", "si", "sk"];
6022
+
6023
+ class Renderer {
6024
+ constructor(comps) {
6025
+ this.comps = comps;
6026
+ this.cache = new WeakMapDomCache;
6027
+ this.renderTag = h;
6028
+ }
6029
+ renderFragment(childs) {
6030
+ return new VFragment(childs);
6031
+ }
6032
+ renderComment(text) {
6033
+ return new VComment(text);
6034
+ }
6035
+ setNullCache() {
6036
+ this.cache = new NullDomCache;
6037
+ }
6038
+ renderToDOM(stack, val) {
6039
+ const rootNode = document.createElement("div");
6040
+ const rOpts = { document };
6041
+ render(h("DIV", null, [this.renderRoot(stack, val)]), rootNode, rOpts);
6042
+ return rootNode.childNodes[0];
6043
+ }
6044
+ renderToString(stack, val, cleanAttrs = true) {
6045
+ const dom = this.renderToDOM(stack, val);
6046
+ if (cleanAttrs) {
6047
+ const nodes = dom.querySelectorAll("[data-nid],[data-cid],[data-eid]");
6048
+ for (const { dataset } of nodes)
6049
+ for (const name of DATASET_ATTRS)
6050
+ delete dataset[name];
6051
+ }
6052
+ return dom.innerHTML;
6053
+ }
6054
+ renderRoot(stack, val, viewName = null) {
6055
+ const comp = this.comps.getCompFor(val);
6056
+ if (comp === null)
6057
+ return null;
6058
+ return this._rValComp(stack, val, comp, comp.getView(viewName).anode, "ROOT", viewName);
6059
+ }
6060
+ renderIt(stack, node, key, viewName) {
6061
+ const comp = this.comps.getCompFor(stack.it);
6062
+ return comp ? this._rValComp(stack, stack.it, comp, node, key, viewName) : null;
6063
+ }
6064
+ _rValComp(stack, val, comp, node, key, viewName) {
6065
+ const cacheKey = `${viewName ?? stack.viewsId ?? ""}-${key}`;
6066
+ const cachePath = [node, val];
6067
+ stack._pushDynBindValuesToArray(cachePath, comp);
6068
+ const cachedNode = this.cache.get(cachePath, cacheKey);
6069
+ if (cachedNode)
6070
+ return cachedNode;
6071
+ const view = viewName ? comp.getView(viewName) : stack.lookupBestView(comp.views, "main");
6072
+ const meta = this._renderMetadata({
6073
+ $: "Comp",
6074
+ nid: node?.nodeId ?? null,
6075
+ cid: comp.id,
6076
+ vid: view.name
6077
+ });
6078
+ const dom = new VFragment([meta, this.renderView(view, stack)]);
6079
+ this.cache.set(cachePath, cacheKey, dom);
6080
+ return dom;
6081
+ }
6082
+ pushEachEntry(r, nid, attrName, key, dom) {
6083
+ r.push(this._renderMetadata({ $: "Each", nid, [attrName]: key }), dom);
6084
+ }
6085
+ renderEach(stack, iterInfo, node, viewName) {
6086
+ const { seq, filter, loopWith } = iterInfo.eval(stack);
6087
+ const r = [];
6088
+ const { iterData, start, end } = unpackLoopResult(loopWith.call(stack.it, seq), seq);
6089
+ getSeqInfo(seq)(seq, (key, value, attrName) => {
6090
+ if (filter.call(stack.it, key, value, iterData)) {
6091
+ const dom = this.renderIt(stack.enter(value, { key }, true), node, key, viewName);
6092
+ this.pushEachEntry(r, node.nodeId, attrName, key, dom);
6093
+ }
6094
+ }, start, end);
6095
+ return r;
6096
+ }
6097
+ renderEachWhen(stack, iterInfo, view, nid) {
6098
+ const { seq, filter, loopWith, enricher } = iterInfo.eval(stack);
6099
+ const r = [];
6100
+ const it = stack.it;
6101
+ const { iterData, start, end } = unpackLoopResult(loopWith.call(it, seq), seq);
6102
+ getSeqInfo(seq)(seq, (key, value, attrName) => {
6103
+ if (filter.call(it, key, value, iterData)) {
6104
+ const cachePath = enricher ? [view, it, value] : [view, value];
6105
+ const binds = { key, value };
6106
+ const cacheKey = `${nid}-${key}`;
6107
+ if (enricher)
6108
+ enricher.call(it, binds, key, value, iterData);
6109
+ const cachedNode = this.cache.get(cachePath, cacheKey);
6110
+ if (cachedNode)
6111
+ this.pushEachEntry(r, nid, attrName, key, cachedNode);
6112
+ else {
6113
+ const dom = this.renderView(view, stack.enter(value, binds, false));
6114
+ this.pushEachEntry(r, nid, attrName, key, dom);
6115
+ this.cache.set(cachePath, cacheKey, dom);
6116
+ }
6117
+ }
6118
+ }, start, end);
6119
+ return r;
6120
+ }
6121
+ renderView(view, stack) {
6122
+ let n = stack.binds[1];
6123
+ while (n !== null) {
6124
+ const b = n[0];
6125
+ if (b.isFrame) {
6126
+ if (stack.it !== b.it)
6127
+ break;
6128
+ console.error("recursion detected", stack.it, b.it);
6129
+ return new VComment("RECURSION AVOIDED");
6130
+ }
6131
+ n = n[1];
6132
+ }
6133
+ return view.render(stack, this);
6134
+ }
6135
+ _renderMetadata(info) {
6136
+ return new VComment(`§${JSON.stringify(info)}§`);
6137
+ }
6138
+ }
6139
+ var getSeqInfo = (seq) => isIndexed(seq) ? imIndexedIter : isKeyed(seq) ? imKeyedIter : seq?.[SEQ_INFO] ?? unkIter;
6140
+ var normalizeRange = (start, end, size) => {
6141
+ let s = start == null ? 0 : start < 0 ? size + start : start;
6142
+ let e = end == null ? size : end < 0 ? size + end : end;
6143
+ s = s < 0 ? 0 : s > size ? size : s;
6144
+ e = e < 0 ? 0 : e > size ? size : e;
6145
+ return [s, e < s ? s : e];
6146
+ };
6147
+ var filterAlwaysTrue = (_v, _k, _seq) => true;
6148
+ var nullLoopWith = (seq) => ({ iterData: { seq } });
6149
+ var unpackLoopResult = (result, seq) => {
6150
+ const r = result ?? {};
6151
+ return { iterData: r.iterData ?? { seq }, start: r.start, end: r.end };
6152
+ };
6153
+ var imIndexedIter = (seq, visit, start, end) => {
6154
+ const [s, e] = normalizeRange(start, end, seq.size);
6155
+ for (let i = s;i < e; i++)
6156
+ visit(i, seq.get(i), "si");
6157
+ };
6158
+ var imKeyedIter = (seq, visit, start, end) => {
6159
+ const [s, e] = normalizeRange(start, end, seq.size);
6160
+ let i = 0;
6161
+ for (const [k, v] of seq.toSeq().entries()) {
6162
+ if (i >= e)
6163
+ break;
6164
+ if (i >= s)
6165
+ visit(k, v, "sk");
6166
+ i++;
6167
+ }
6168
+ };
6169
+ var unkIter = () => {};
6170
+ var SEQ_INFO = Symbol.for("tutuca.seqInfo");
6171
+
6172
+ // src/util/env.js
6173
+ var isMac = (globalThis.navigator?.userAgent ?? "").toLowerCase().includes("mac");
6174
+
5957
6175
  // src/anode.js
5958
6176
  function resolveDynProducer(comp, name) {
5959
6177
  let producerComp, producerProvide;
@@ -6157,7 +6375,7 @@ class ANode extends BaseNode {
6157
6375
  }
6158
6376
  }
6159
6377
  function parseXOp(attrs, childs, opIdx, px) {
6160
- if (attrs.length === 0)
6378
+ if (attrs.length <= opIdx)
6161
6379
  return maybeFragment(childs);
6162
6380
  const { name, value } = attrs[opIdx];
6163
6381
  const as = attrs.getNamedItem("as")?.value ?? null;
@@ -6478,8 +6696,6 @@ class IterInfo {
6478
6696
  return { seq, filter, loopWith, enricher };
6479
6697
  }
6480
6698
  }
6481
- var filterAlwaysTrue = (_v, _k, _seq) => true;
6482
- var nullLoopWith = (seq) => ({ iterData: { seq } });
6483
6699
  function xOp(consumed = [], { wrappable = false, wrapper = null } = {}) {
6484
6700
  return { consumed: new Set(consumed), wrappable, wrapper };
6485
6701
  }
@@ -6666,7 +6882,6 @@ class NodeEvent {
6666
6882
  return r;
6667
6883
  }
6668
6884
  }
6669
- var isMac = (globalThis.navigator?.userAgent ?? "").toLowerCase().includes("mac");
6670
6885
  var fwdIfCtxPred = (pred) => (w) => (that, f, args, ctx) => pred(ctx) ? w(that, f, args, ctx) : that;
6671
6886
  var fwdIfKey = (keyName) => fwdIfCtxPred((ctx) => ctx.e.key === keyName);
6672
6887
  var fwdCtrl = fwdIfCtxPred(({ e }) => isMac && e.metaKey || e.ctrlKey);
@@ -7174,7 +7389,6 @@ class Transaction {
7174
7389
  return null;
7175
7390
  }
7176
7391
  }
7177
- var isMac2 = (globalThis.navigator?.userAgent ?? "").toLowerCase().includes("mac");
7178
7392
  var toNullIfNaN = (v) => Number.isNaN(v) ? null : v;
7179
7393
  function getValue(e) {
7180
7394
  return e.target.type === "checkbox" ? e.target.checked : (e instanceof CustomEvent ? e.detail : e.target.value) ?? null;
@@ -7228,7 +7442,7 @@ class InputEvent extends Transaction {
7228
7442
  return e.shiftKey;
7229
7443
  case "isCtrl":
7230
7444
  case "isCmd":
7231
- return isMac2 && e.metaKey || e.ctrlKey;
7445
+ return isMac && e.metaKey || e.ctrlKey;
7232
7446
  case "key":
7233
7447
  return e.key;
7234
7448
  case "keyCode":
@@ -7708,7 +7922,18 @@ class ParseCtxClassSetCollector extends ParseContext {
7708
7922
  return false;
7709
7923
  }
7710
7924
  }
7711
-
7925
+ function collectAppClassesInSet(app) {
7926
+ const classes = new Set;
7927
+ for (const Comp of app.comps.byId.values()) {
7928
+ for (const key in Comp.views) {
7929
+ const view = Comp.views[key];
7930
+ for (const name of view.ctx.classes) {
7931
+ classes.add(name);
7932
+ }
7933
+ }
7934
+ }
7935
+ return classes;
7936
+ }
7712
7937
  // src/oo.js
7713
7938
  var BAD_VALUE = Symbol("BadValue");
7714
7939
  var nullCoercer = (v) => v;
@@ -7975,8 +8200,8 @@ class FieldSet extends Field {
7975
8200
  }
7976
8201
  }
7977
8202
  function mkCompField(field, scope, args) {
7978
- const Comp = scope.lookupComponent(field.type);
7979
- console.assert(Comp !== null, "component not found", { field });
8203
+ const Comp = scope?.lookupComponent(field.type) ?? null;
8204
+ console.assert(!scope || Comp !== null, "component not found", { field });
7980
8205
  return Comp?.make({ ...field.args, ...args }, { scope }) ?? null;
7981
8206
  }
7982
8207
 
@@ -8093,321 +8318,6 @@ function classFromData(name, { fields = {}, methods, statics }) {
8093
8318
  Component.fromSpec = (opts) => new Component(classFromData(opts.name, opts), opts);
8094
8319
  var component = (opts) => Component.fromSpec(opts);
8095
8320
 
8096
- // src/cache.js
8097
- class NullDomCache {
8098
- get(_keys, _cacheKey) {}
8099
- set(_keys, _cacheKey, _v) {}
8100
- evict() {
8101
- return { hit: 0, miss: 0, badKey: 0 };
8102
- }
8103
- }
8104
-
8105
- class WeakMapDomCache {
8106
- constructor() {
8107
- this.hit = this.miss = this.badKey = 0;
8108
- this.keysByLen = new Map;
8109
- }
8110
- _returnValue(r) {
8111
- if (r === undefined)
8112
- this.miss += 1;
8113
- else
8114
- this.hit += 1;
8115
- return r;
8116
- }
8117
- get(keys, cacheKey) {
8118
- const len = keys.length;
8119
- let cur = this.keysByLen.get(len);
8120
- if (!cur)
8121
- return this._returnValue(undefined);
8122
- for (let i = 0;i < len - 1; i++) {
8123
- cur = cur.get(keys[i]);
8124
- if (!cur)
8125
- return this._returnValue(undefined);
8126
- }
8127
- return this._returnValue(cur.get(keys[len - 1])?.[cacheKey]);
8128
- }
8129
- set(keys, cacheKey, v) {
8130
- const len = keys.length;
8131
- let cur = this.keysByLen.get(len);
8132
- if (!cur) {
8133
- cur = new WeakMap;
8134
- this.keysByLen.set(len, cur);
8135
- }
8136
- for (let i = 0;i < len - 1; i++) {
8137
- const key = keys[i];
8138
- let next = cur.get(key);
8139
- if (!next) {
8140
- if (typeof key !== "object") {
8141
- this.badKey += 1;
8142
- return;
8143
- }
8144
- next = new WeakMap;
8145
- cur.set(key, next);
8146
- }
8147
- cur = next;
8148
- }
8149
- const lastKey = keys[len - 1];
8150
- const leaf = cur.get(lastKey);
8151
- if (leaf)
8152
- leaf[cacheKey] = v;
8153
- else if (typeof lastKey === "object")
8154
- cur.set(lastKey, { [cacheKey]: v });
8155
- else
8156
- this.badKey += 1;
8157
- }
8158
- evict() {
8159
- const { hit, miss, badKey } = this;
8160
- this.hit = this.miss = this.badKey = 0;
8161
- this.keysByLen = new Map;
8162
- return { hit, miss, badKey };
8163
- }
8164
- }
8165
-
8166
- // src/renderer.js
8167
- var DATASET_ATTRS = ["nid", "cid", "eid", "vid", "si", "sk"];
8168
-
8169
- class Renderer {
8170
- constructor(comps) {
8171
- this.comps = comps;
8172
- this.cache = new WeakMapDomCache;
8173
- this.renderTag = h;
8174
- }
8175
- renderFragment(childs) {
8176
- return new VFragment(childs);
8177
- }
8178
- renderComment(text) {
8179
- return new VComment(text);
8180
- }
8181
- setNullCache() {
8182
- this.cache = new NullDomCache;
8183
- }
8184
- renderToDOM(stack, val) {
8185
- const rootNode = document.createElement("div");
8186
- const rOpts = { document };
8187
- render(h("DIV", null, [this.renderRoot(stack, val)]), rootNode, rOpts);
8188
- return rootNode.childNodes[0];
8189
- }
8190
- renderToString(stack, val, cleanAttrs = true) {
8191
- const dom = this.renderToDOM(stack, val);
8192
- if (cleanAttrs) {
8193
- const nodes = dom.querySelectorAll("[data-nid],[data-cid],[data-eid]");
8194
- for (const { dataset } of nodes)
8195
- for (const name of DATASET_ATTRS)
8196
- delete dataset[name];
8197
- }
8198
- return dom.innerHTML;
8199
- }
8200
- renderRoot(stack, val, viewName = null) {
8201
- const comp = this.comps.getCompFor(val);
8202
- if (comp === null)
8203
- return null;
8204
- return this._rValComp(stack, val, comp, comp.getView(viewName).anode, "ROOT", viewName);
8205
- }
8206
- renderIt(stack, node, key, viewName) {
8207
- const comp = this.comps.getCompFor(stack.it);
8208
- return comp ? this._rValComp(stack, stack.it, comp, node, key, viewName) : null;
8209
- }
8210
- _rValComp(stack, val, comp, node, key, viewName) {
8211
- const cacheKey = `${viewName ?? stack.viewsId ?? ""}-${key}`;
8212
- const cachePath = [node, val];
8213
- stack._pushDynBindValuesToArray(cachePath, comp);
8214
- const cachedNode = this.cache.get(cachePath, cacheKey);
8215
- if (cachedNode)
8216
- return cachedNode;
8217
- const view = viewName ? comp.getView(viewName) : stack.lookupBestView(comp.views, "main");
8218
- const meta = this._renderMetadata({
8219
- $: "Comp",
8220
- nid: node?.nodeId ?? null,
8221
- cid: comp.id,
8222
- vid: view.name
8223
- });
8224
- const dom = new VFragment([meta, this.renderView(view, stack)]);
8225
- this.cache.set(cachePath, cacheKey, dom);
8226
- return dom;
8227
- }
8228
- pushEachEntry(r, nid, attrName, key, dom) {
8229
- r.push(this._renderMetadata({ $: "Each", nid, [attrName]: key }), dom);
8230
- }
8231
- renderEach(stack, iterInfo, node, viewName) {
8232
- const { seq, filter, loopWith } = iterInfo.eval(stack);
8233
- const r = [];
8234
- const { iterData, start, end } = unpackLoopResult(loopWith.call(stack.it, seq), seq);
8235
- getSeqInfo(seq)(seq, (key, value, attrName) => {
8236
- if (filter.call(stack.it, key, value, iterData)) {
8237
- const dom = this.renderIt(stack.enter(value, { key }, true), node, key, viewName);
8238
- this.pushEachEntry(r, node.nodeId, attrName, key, dom);
8239
- }
8240
- }, start, end);
8241
- return r;
8242
- }
8243
- renderEachWhen(stack, iterInfo, view, nid) {
8244
- const { seq, filter, loopWith, enricher } = iterInfo.eval(stack);
8245
- const r = [];
8246
- const it = stack.it;
8247
- const { iterData, start, end } = unpackLoopResult(loopWith.call(it, seq), seq);
8248
- getSeqInfo(seq)(seq, (key, value, attrName) => {
8249
- if (filter.call(it, key, value, iterData)) {
8250
- const cachePath = enricher ? [view, it, value] : [view, value];
8251
- const binds = { key, value };
8252
- const cacheKey = `${nid}-${key}`;
8253
- if (enricher)
8254
- enricher.call(it, binds, key, value, iterData);
8255
- const cachedNode = this.cache.get(cachePath, cacheKey);
8256
- if (cachedNode)
8257
- this.pushEachEntry(r, nid, attrName, key, cachedNode);
8258
- else {
8259
- const dom = this.renderView(view, stack.enter(value, binds, false));
8260
- this.pushEachEntry(r, nid, attrName, key, dom);
8261
- this.cache.set(cachePath, cacheKey, dom);
8262
- }
8263
- }
8264
- }, start, end);
8265
- return r;
8266
- }
8267
- renderView(view, stack) {
8268
- let n = stack.binds[1];
8269
- while (n !== null) {
8270
- const b = n[0];
8271
- if (b.isFrame) {
8272
- if (stack.it !== b.it)
8273
- break;
8274
- console.error("recursion detected", stack.it, b.it);
8275
- return new VComment("RECURSION AVOIDED");
8276
- }
8277
- n = n[1];
8278
- }
8279
- return view.render(stack, this);
8280
- }
8281
- _renderMetadata(info) {
8282
- return new VComment(`§${JSON.stringify(info)}§`);
8283
- }
8284
- }
8285
- var getSeqInfo = (seq) => isIndexed(seq) ? imIndexedIter : isKeyed(seq) ? imKeyedIter : seq?.[SEQ_INFO] ?? unkIter;
8286
- var normalizeRange = (start, end, size) => {
8287
- let s = start == null ? 0 : start < 0 ? size + start : start;
8288
- let e = end == null ? size : end < 0 ? size + end : end;
8289
- s = s < 0 ? 0 : s > size ? size : s;
8290
- e = e < 0 ? 0 : e > size ? size : e;
8291
- return [s, e < s ? s : e];
8292
- };
8293
- var unpackLoopResult = (result, seq) => {
8294
- const r = result ?? {};
8295
- return { iterData: r.iterData ?? { seq }, start: r.start, end: r.end };
8296
- };
8297
- var imIndexedIter = (seq, visit, start, end) => {
8298
- const [s, e] = normalizeRange(start, end, seq.size);
8299
- for (let i = s;i < e; i++)
8300
- visit(i, seq.get(i), "si");
8301
- };
8302
- var imKeyedIter = (seq, visit, start, end) => {
8303
- const [s, e] = normalizeRange(start, end, seq.size);
8304
- let i = 0;
8305
- for (const [k, v] of seq.toSeq().entries()) {
8306
- if (i >= e)
8307
- break;
8308
- if (i >= s)
8309
- visit(k, v, "sk");
8310
- i++;
8311
- }
8312
- };
8313
- var unkIter = () => {};
8314
- var SEQ_INFO = Symbol.for("tutuca.seqInfo");
8315
-
8316
- // extra/klist.js
8317
- class KList {
8318
- constructor(items = Map2(), order = List()) {
8319
- this.items = items;
8320
- this.order = order;
8321
- this.$ = 0;
8322
- }
8323
- _clonish(items, order) {
8324
- return new KList(items, order, this.$);
8325
- }
8326
- toJS() {
8327
- return this.order.toArray().map((k) => this.items.get(k));
8328
- }
8329
- set(k, v) {
8330
- const newOrder = this.items.has(k) ? this.order : this.order.push(k);
8331
- return this._clonish(this.items.set(k, v), newOrder, this.$);
8332
- }
8333
- get(k, dval = null) {
8334
- return this.items.get(k, dval);
8335
- }
8336
- _nextFreeKey() {
8337
- let cur = this.$;
8338
- while (true) {
8339
- const key = `§${cur}§`;
8340
- if (!this.items.has(key)) {
8341
- return [key, cur];
8342
- }
8343
- cur += 1;
8344
- }
8345
- }
8346
- push(v) {
8347
- const [key, next$] = this._nextFreeKey();
8348
- const newKList = this.set(key, v);
8349
- newKList.$ = next$;
8350
- return newKList;
8351
- }
8352
- get size() {
8353
- return this.items.size;
8354
- }
8355
- delete(k) {
8356
- if (this.items.has(k)) {
8357
- const newOrder = this.order.delete(this.order.indexOf(k));
8358
- return this._clonish(this.items.delete(k), newOrder);
8359
- }
8360
- return this;
8361
- }
8362
- moveKeyBeforeKey(k1, k2) {
8363
- const { order } = this;
8364
- return this.moveKeyIndexToIndex(order.indexOf(k1), order.indexOf(k2), 0);
8365
- }
8366
- moveKeyAfterKey(k1, k2) {
8367
- const { order } = this;
8368
- return this.moveKeyIndexToIndex(order.indexOf(k1), order.indexOf(k2), 1);
8369
- }
8370
- moveKeyIndexToIndex(source, target, offset) {
8371
- if (source === -1 || target === -1 || source === target) {
8372
- return this;
8373
- }
8374
- const { order } = this;
8375
- const newPos = target + offset;
8376
- const oldPos = newPos < source ? source + 1 : source;
8377
- const newOrder = order.insert(newPos, order.get(source)).delete(oldPos);
8378
- return this._clonish(this.items, newOrder);
8379
- }
8380
- }
8381
- var klistCoercer = (_) => null;
8382
-
8383
- class CheckTypeKList {
8384
- isValid(v) {
8385
- return v instanceof KList;
8386
- }
8387
- getMessage(_v) {
8388
- return "KList expected";
8389
- }
8390
- }
8391
- var CHECK_TYPE_KLIST = new CheckTypeKList;
8392
-
8393
- class FieldKList extends Field {
8394
- constructor(name, defaultValue = new KList) {
8395
- super("KList", name, CHECK_TYPE_KLIST, klistCoercer, defaultValue);
8396
- }
8397
- extendProtoForType(proto, uname) {
8398
- extendProtoForKeyed(proto, this.name, uname);
8399
- const { name } = this;
8400
- extendProtoForKeyed(proto, name, uname);
8401
- proto[`pushIn${uname}`] = function(v) {
8402
- return this.set(name, this.get(name).push(v));
8403
- };
8404
- }
8405
- }
8406
- KList.prototype[FIELD_CLASS] = FieldKList;
8407
- KList.prototype[SEQ_INFO] = (seq, visit) => {
8408
- for (const k of seq.order)
8409
- visit(k, seq.items.get(k), "data-sk");
8410
- };
8411
8321
  // index.js
8412
8322
  var css = String.raw;
8413
8323
  var html = String.raw;
@@ -8440,15 +8350,7 @@ async function compileClassesToStyle(app, compileClasses, styleId = "margaui-css
8440
8350
  async function compileClassesToStyleText(app, compileClasses, Ctx = ParseCtxClassSetCollector) {
8441
8351
  app.ParseContext = Ctx;
8442
8352
  app.compile();
8443
- const classes = new Set;
8444
- for (const Comp of app.comps.byId.values()) {
8445
- for (const key in Comp.views) {
8446
- const view = Comp.views[key];
8447
- for (const name of view.ctx.classes)
8448
- classes.add(name);
8449
- }
8450
- }
8451
- return await compileClasses(Array.from(classes));
8353
+ return await compileClasses(Array.from(collectAppClassesInSet(app)));
8452
8354
  }
8453
8355
  export {
8454
8356
  version,
@@ -8512,7 +8414,6 @@ export {
8512
8414
  OrderedMap as OMap,
8513
8415
  Map2 as Map,
8514
8416
  List,
8515
- KList,
8516
8417
  Set2 as ISet,
8517
8418
  Map2 as IMap,
8518
8419
  FIELD_CLASS,