@gramlot/gramlot 0.2.11 → 0.2.12

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.
package/dist/gramlot.js CHANGED
@@ -72,13 +72,13 @@ var require_conventions = __commonJS({
72
72
  function hasOwn(object, key) {
73
73
  return Object.prototype.hasOwnProperty.call(object, key);
74
74
  }
75
- function assign(target, source2) {
75
+ function assign(target, source) {
76
76
  if (target === null || typeof target !== "object") {
77
77
  throw new TypeError("target is not an object");
78
78
  }
79
- for (var key in source2) {
80
- if (hasOwn(source2, key)) {
81
- target[key] = source2[key];
79
+ for (var key in source) {
80
+ if (hasOwn(source, key)) {
81
+ target[key] = source[key];
82
82
  }
83
83
  }
84
84
  return target;
@@ -5450,18 +5450,18 @@ var require_sax = __commonJS({
5450
5450
  function XMLReader() {
5451
5451
  }
5452
5452
  XMLReader.prototype = {
5453
- parse: function(source2, defaultNSMap, entityMap) {
5453
+ parse: function(source, defaultNSMap, entityMap) {
5454
5454
  var domBuilder = this.domBuilder;
5455
5455
  domBuilder.startDocument();
5456
5456
  _copy(defaultNSMap, defaultNSMap = /* @__PURE__ */ Object.create(null));
5457
- parse2(source2, defaultNSMap, entityMap, domBuilder, this.errorHandler);
5457
+ parse2(source, defaultNSMap, entityMap, domBuilder, this.errorHandler);
5458
5458
  domBuilder.endDocument();
5459
5459
  }
5460
5460
  };
5461
5461
  var ENTITY_REG = /&#?\w+;?/g;
5462
- function parse2(source2, defaultNSMapCopy, entityMap, domBuilder, errorHandler) {
5462
+ function parse2(source, defaultNSMapCopy, entityMap, domBuilder, errorHandler) {
5463
5463
  var isHTML = isHTMLMimeType(domBuilder.mimeType);
5464
- if (source2.indexOf(g.UNICODE_REPLACEMENT_CHARACTER) >= 0) {
5464
+ if (source.indexOf(g.UNICODE_REPLACEMENT_CHARACTER) >= 0) {
5465
5465
  errorHandler.warning("Unicode replacement character detected, source encoding issues?");
5466
5466
  }
5467
5467
  function fixedFromCharCode(code) {
@@ -5496,7 +5496,7 @@ var require_sax = __commonJS({
5496
5496
  }
5497
5497
  function appendText(end2) {
5498
5498
  if (end2 > start) {
5499
- var xt = source2.substring(start, end2).replace(ENTITY_REG, entityReplacer);
5499
+ var xt = source.substring(start, end2).replace(ENTITY_REG, entityReplacer);
5500
5500
  locator && position(start);
5501
5501
  domBuilder.characters(xt, 0, end2 - start);
5502
5502
  start = end2;
@@ -5507,7 +5507,7 @@ var require_sax = __commonJS({
5507
5507
  var linePattern = /\r\n?|\n|$/g;
5508
5508
  var locator = domBuilder.locator;
5509
5509
  function position(p, m) {
5510
- while (p >= lineEnd && (m = linePattern.exec(source2))) {
5510
+ while (p >= lineEnd && (m = linePattern.exec(source))) {
5511
5511
  lineStart = lineEnd;
5512
5512
  lineEnd = m.index + m[0].length;
5513
5513
  locator.lineNumber++;
@@ -5519,14 +5519,14 @@ var require_sax = __commonJS({
5519
5519
  var start = 0;
5520
5520
  while (true) {
5521
5521
  try {
5522
- var tagStart = source2.indexOf("<", start);
5522
+ var tagStart = source.indexOf("<", start);
5523
5523
  if (tagStart < 0) {
5524
5524
  if (!isHTML && unclosedTags.length > 0) {
5525
5525
  return errorHandler.fatalError("unclosed xml tag(s): " + unclosedTags.join(", "));
5526
5526
  }
5527
- if (!source2.substring(start).match(/^\s*$/)) {
5527
+ if (!source.substring(start).match(/^\s*$/)) {
5528
5528
  var doc = domBuilder.doc;
5529
- var text = doc.createTextNode(source2.substring(start));
5529
+ var text = doc.createTextNode(source.substring(start));
5530
5530
  if (doc.documentElement) {
5531
5531
  return errorHandler.error("Extra content at the end of the document");
5532
5532
  }
@@ -5536,17 +5536,17 @@ var require_sax = __commonJS({
5536
5536
  return;
5537
5537
  }
5538
5538
  if (tagStart > start) {
5539
- var fromSource = source2.substring(start, tagStart);
5539
+ var fromSource = source.substring(start, tagStart);
5540
5540
  if (!isHTML && unclosedTags.length === 0) {
5541
5541
  fromSource = fromSource.replace(new RegExp(g.S_OPT.source, "g"), "");
5542
5542
  fromSource && errorHandler.error("Unexpected content outside root element: '" + fromSource + "'");
5543
5543
  }
5544
5544
  appendText(tagStart);
5545
5545
  }
5546
- switch (source2.charAt(tagStart + 1)) {
5546
+ switch (source.charAt(tagStart + 1)) {
5547
5547
  case "/":
5548
- var end = source2.indexOf(">", tagStart + 2);
5549
- var tagNameRaw = source2.substring(tagStart + 2, end > 0 ? end : void 0);
5548
+ var end = source.indexOf(">", tagStart + 2);
5549
+ var tagNameRaw = source.substring(tagStart + 2, end > 0 ? end : void 0);
5550
5550
  if (!tagNameRaw) {
5551
5551
  return errorHandler.fatalError("end tag name missing");
5552
5552
  }
@@ -5597,17 +5597,17 @@ var require_sax = __commonJS({
5597
5597
  // end element
5598
5598
  case "?":
5599
5599
  locator && position(tagStart);
5600
- end = parseProcessingInstruction(source2, tagStart, domBuilder, errorHandler);
5600
+ end = parseProcessingInstruction(source, tagStart, domBuilder, errorHandler);
5601
5601
  break;
5602
5602
  case "!":
5603
5603
  locator && position(tagStart);
5604
- end = parseDoctypeCommentOrCData(source2, tagStart, domBuilder, errorHandler, isHTML);
5604
+ end = parseDoctypeCommentOrCData(source, tagStart, domBuilder, errorHandler, isHTML);
5605
5605
  break;
5606
5606
  default:
5607
5607
  locator && position(tagStart);
5608
5608
  var el = new ElementAttributes();
5609
5609
  var currentNSMap = parseStack[parseStack.length - 1].currentNSMap;
5610
- var end = parseElementStartPart(source2, tagStart, el, currentNSMap, entityReplacer, errorHandler, isHTML);
5610
+ var end = parseElementStartPart(source, tagStart, el, currentNSMap, entityReplacer, errorHandler, isHTML);
5611
5611
  var len = el.length;
5612
5612
  if (!el.closed) {
5613
5613
  if (isHTML && conventions.isHTMLVoidElement(el.tagName)) {
@@ -5634,7 +5634,7 @@ var require_sax = __commonJS({
5634
5634
  }
5635
5635
  }
5636
5636
  if (isHTML && !el.closed) {
5637
- end = parseHtmlSpecialContent(source2, end, el.tagName, entityReplacer, domBuilder);
5637
+ end = parseHtmlSpecialContent(source, end, el.tagName, entityReplacer, domBuilder);
5638
5638
  } else {
5639
5639
  end++;
5640
5640
  }
@@ -5660,7 +5660,7 @@ var require_sax = __commonJS({
5660
5660
  t.columnNumber = f.columnNumber;
5661
5661
  return t;
5662
5662
  }
5663
- function parseElementStartPart(source2, start, el, currentNSMap, entityReplacer, errorHandler, isHTML) {
5663
+ function parseElementStartPart(source, start, el, currentNSMap, entityReplacer, errorHandler, isHTML) {
5664
5664
  function addAttribute(qname, value2, startIndex) {
5665
5665
  if (hasOwn(el.attributeNames, qname)) {
5666
5666
  return errorHandler.fatalError("Attribute " + qname + " redefined");
@@ -5683,14 +5683,14 @@ var require_sax = __commonJS({
5683
5683
  var p = ++start;
5684
5684
  var s = S_TAG;
5685
5685
  while (true) {
5686
- var c = source2.charAt(p);
5686
+ var c = source.charAt(p);
5687
5687
  if (s === S_TAG && c === "<") {
5688
- throw new Error("unexpected < in tag name: " + source2.slice(start, p));
5688
+ throw new Error("unexpected < in tag name: " + source.slice(start, p));
5689
5689
  }
5690
5690
  switch (c) {
5691
5691
  case "=":
5692
5692
  if (s === S_ATTR) {
5693
- attrName = source2.slice(start, p);
5693
+ attrName = source.slice(start, p);
5694
5694
  s = S_EQ;
5695
5695
  } else if (s === S_ATTR_SPACE) {
5696
5696
  s = S_EQ;
@@ -5703,19 +5703,19 @@ var require_sax = __commonJS({
5703
5703
  if (s === S_EQ || s === S_ATTR) {
5704
5704
  if (s === S_ATTR) {
5705
5705
  errorHandler.warning('attribute value must after "="');
5706
- attrName = source2.slice(start, p);
5706
+ attrName = source.slice(start, p);
5707
5707
  }
5708
5708
  start = p + 1;
5709
- p = source2.indexOf(c, start);
5709
+ p = source.indexOf(c, start);
5710
5710
  if (p > 0) {
5711
- value = source2.slice(start, p);
5711
+ value = source.slice(start, p);
5712
5712
  addAttribute(attrName, value, start - 1);
5713
5713
  s = S_ATTR_END;
5714
5714
  } else {
5715
5715
  throw new Error("attribute value no end '" + c + "' match");
5716
5716
  }
5717
5717
  } else if (s == S_ATTR_NOQUOT_VALUE) {
5718
- value = source2.slice(start, p);
5718
+ value = source.slice(start, p);
5719
5719
  addAttribute(attrName, value, start);
5720
5720
  errorHandler.warning('attribute "' + attrName + '" missed start quot(' + c + ")!!");
5721
5721
  start = p + 1;
@@ -5727,7 +5727,7 @@ var require_sax = __commonJS({
5727
5727
  case "/":
5728
5728
  switch (s) {
5729
5729
  case S_TAG:
5730
- el.setTagName(source2.slice(start, p));
5730
+ el.setTagName(source.slice(start, p));
5731
5731
  case S_ATTR_END:
5732
5732
  case S_TAG_SPACE:
5733
5733
  case S_TAG_CLOSE:
@@ -5747,13 +5747,13 @@ var require_sax = __commonJS({
5747
5747
  case "":
5748
5748
  errorHandler.error("unexpected end of input");
5749
5749
  if (s == S_TAG) {
5750
- el.setTagName(source2.slice(start, p));
5750
+ el.setTagName(source.slice(start, p));
5751
5751
  }
5752
5752
  return p;
5753
5753
  case ">":
5754
5754
  switch (s) {
5755
5755
  case S_TAG:
5756
- el.setTagName(source2.slice(start, p));
5756
+ el.setTagName(source.slice(start, p));
5757
5757
  case S_ATTR_END:
5758
5758
  case S_TAG_SPACE:
5759
5759
  case S_TAG_CLOSE:
@@ -5762,7 +5762,7 @@ var require_sax = __commonJS({
5762
5762
  case S_ATTR_NOQUOT_VALUE:
5763
5763
  //Compatible state
5764
5764
  case S_ATTR:
5765
- value = source2.slice(start, p);
5765
+ value = source.slice(start, p);
5766
5766
  if (value.slice(-1) === "/") {
5767
5767
  el.closed = true;
5768
5768
  value = value.slice(0, -1);
@@ -5794,15 +5794,15 @@ var require_sax = __commonJS({
5794
5794
  if (c <= " ") {
5795
5795
  switch (s) {
5796
5796
  case S_TAG:
5797
- el.setTagName(source2.slice(start, p));
5797
+ el.setTagName(source.slice(start, p));
5798
5798
  s = S_TAG_SPACE;
5799
5799
  break;
5800
5800
  case S_ATTR:
5801
- attrName = source2.slice(start, p);
5801
+ attrName = source.slice(start, p);
5802
5802
  s = S_ATTR_SPACE;
5803
5803
  break;
5804
5804
  case S_ATTR_NOQUOT_VALUE:
5805
- var value = source2.slice(start, p);
5805
+ var value = source.slice(start, p);
5806
5806
  errorHandler.warning('attribute "' + value + '" missed quot(")!!');
5807
5807
  addAttribute(attrName, value, start);
5808
5808
  case S_ATTR_END:
@@ -5906,17 +5906,17 @@ var require_sax = __commonJS({
5906
5906
  return true;
5907
5907
  }
5908
5908
  }
5909
- function parseHtmlSpecialContent(source2, elStartEnd, tagName, entityReplacer, domBuilder) {
5909
+ function parseHtmlSpecialContent(source, elStartEnd, tagName, entityReplacer, domBuilder) {
5910
5910
  var isEscapableRaw = isHTMLEscapableRawTextElement(tagName);
5911
5911
  if (isEscapableRaw || isHTMLRawTextElement(tagName)) {
5912
5912
  var closeTag = new RegExp("</" + tagName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + ">", "ig");
5913
5913
  closeTag.lastIndex = elStartEnd;
5914
- var match = closeTag.exec(source2);
5914
+ var match = closeTag.exec(source);
5915
5915
  var elEndStart = match ? match.index : -1;
5916
5916
  if (elEndStart < 0) {
5917
5917
  return elStartEnd + 1;
5918
5918
  }
5919
- var text = source2.substring(elStartEnd + 1, elEndStart);
5919
+ var text = source.substring(elStartEnd + 1, elEndStart);
5920
5920
  if (isEscapableRaw) {
5921
5921
  text = text.replace(ENTITY_REG, entityReplacer);
5922
5922
  }
@@ -5925,18 +5925,18 @@ var require_sax = __commonJS({
5925
5925
  }
5926
5926
  return elStartEnd + 1;
5927
5927
  }
5928
- function _copy(source2, target) {
5929
- for (var n in source2) {
5930
- if (hasOwn(source2, n)) {
5931
- target[n] = source2[n];
5928
+ function _copy(source, target) {
5929
+ for (var n in source) {
5930
+ if (hasOwn(source, n)) {
5931
+ target[n] = source[n];
5932
5932
  }
5933
5933
  }
5934
5934
  }
5935
- function parseUtils(source2, start) {
5935
+ function parseUtils(source, start) {
5936
5936
  var index = start;
5937
5937
  function char(n) {
5938
5938
  n = n || 0;
5939
- return source2.charAt(index + n);
5939
+ return source.charAt(index + n);
5940
5940
  }
5941
5941
  function skip(n) {
5942
5942
  n = n || 1;
@@ -5944,7 +5944,7 @@ var require_sax = __commonJS({
5944
5944
  }
5945
5945
  function skipBlanks() {
5946
5946
  var blanks = 0;
5947
- while (index < source2.length) {
5947
+ while (index < source.length) {
5948
5948
  var c = char();
5949
5949
  if (c !== " " && c !== "\n" && c !== " " && c !== "\r") {
5950
5950
  return blanks;
@@ -5955,13 +5955,13 @@ var require_sax = __commonJS({
5955
5955
  return -1;
5956
5956
  }
5957
5957
  function substringFromIndex() {
5958
- return source2.substring(index);
5958
+ return source.substring(index);
5959
5959
  }
5960
5960
  function substringStartsWith(text) {
5961
- return source2.substring(index, index + text.length) === text;
5961
+ return source.substring(index, index + text.length) === text;
5962
5962
  }
5963
5963
  function substringStartsWithCaseInsensitive(text) {
5964
- return source2.substring(index, index + text.length).toUpperCase() === text.toUpperCase();
5964
+ return source.substring(index, index + text.length).toUpperCase() === text.toUpperCase();
5965
5965
  }
5966
5966
  function getMatch(args) {
5967
5967
  var expr = g.reg("^", args);
@@ -5979,7 +5979,7 @@ var require_sax = __commonJS({
5979
5979
  },
5980
5980
  getMatch,
5981
5981
  getSource: function() {
5982
- return source2;
5982
+ return source;
5983
5983
  },
5984
5984
  skip,
5985
5985
  skipBlanks,
@@ -6002,14 +6002,14 @@ var require_sax = __commonJS({
6002
6002
  p2.skip(match[0].length);
6003
6003
  return match[0];
6004
6004
  }
6005
- var source2 = p.getSource();
6005
+ var source = p.getSource();
6006
6006
  if (p.char() === "[") {
6007
6007
  p.skip(1);
6008
6008
  var intSubsetStart = p.getIndex();
6009
- while (p.getIndex() < source2.length) {
6009
+ while (p.getIndex() < source.length) {
6010
6010
  p.skipBlanks();
6011
6011
  if (p.char() === "]") {
6012
- var internalSubset = source2.substring(intSubsetStart, p.getIndex());
6012
+ var internalSubset = source.substring(intSubsetStart, p.getIndex());
6013
6013
  p.skip(1);
6014
6014
  return internalSubset;
6015
6015
  }
@@ -6047,8 +6047,8 @@ var require_sax = __commonJS({
6047
6047
  return errorHandler.fatalError("doctype internal subset is not well-formed, missing ]");
6048
6048
  }
6049
6049
  }
6050
- function parseDoctypeCommentOrCData(source2, start, domBuilder, errorHandler, isHTML) {
6051
- var p = parseUtils(source2, start);
6050
+ function parseDoctypeCommentOrCData(source, start, domBuilder, errorHandler, isHTML) {
6051
+ var p = parseUtils(source, start);
6052
6052
  switch (isHTML ? p.char(2).toUpperCase() : p.char(2)) {
6053
6053
  case "-":
6054
6054
  var comment = p.getMatch(g.Comment);
@@ -6139,8 +6139,8 @@ var require_sax = __commonJS({
6139
6139
  return errorHandler.fatalError('Not well-formed XML starting with "<!" at position ' + start);
6140
6140
  }
6141
6141
  }
6142
- function parseProcessingInstruction(source2, start, domBuilder, errorHandler) {
6143
- var match = source2.substring(start).match(g.PI);
6142
+ function parseProcessingInstruction(source, start, domBuilder, errorHandler) {
6143
+ var match = source.substring(start).match(g.PI);
6144
6144
  if (!match) {
6145
6145
  return errorHandler.fatalError("Invalid processing instruction starting at position " + start);
6146
6146
  }
@@ -6150,7 +6150,7 @@ var require_sax = __commonJS({
6150
6150
  "processing instruction at position " + start + " is an xml declaration which is only at the start of the document"
6151
6151
  );
6152
6152
  }
6153
- if (!g.XMLDecl.test(source2.substring(start))) {
6153
+ if (!g.XMLDecl.test(source.substring(start))) {
6154
6154
  return errorHandler.fatalError("xml declaration is not well-formed");
6155
6155
  }
6156
6156
  }
@@ -6244,7 +6244,7 @@ var require_dom_parser = __commonJS({
6244
6244
  this.locator = !!options.locator;
6245
6245
  this.xmlns = this.assign(/* @__PURE__ */ Object.create(null), options.xmlns);
6246
6246
  }
6247
- DOMParser4.prototype.parseFromString = function(source2, mimeType) {
6247
+ DOMParser4.prototype.parseFromString = function(source, mimeType) {
6248
6248
  if (!isValidMimeType(mimeType)) {
6249
6249
  throw new TypeError('DOMParser.parseFromString: the provided mimeType "' + mimeType + '" is not valid.');
6250
6250
  }
@@ -6272,10 +6272,10 @@ var require_dom_parser = __commonJS({
6272
6272
  sax2.errorHandler = domBuilder;
6273
6273
  sax2.domBuilder = domBuilder;
6274
6274
  var isXml = !conventions.isHTMLMimeType(mimeType);
6275
- if (isXml && typeof source2 !== "string") {
6275
+ if (isXml && typeof source !== "string") {
6276
6276
  sax2.errorHandler.fatalError("source is not a string");
6277
6277
  }
6278
- sax2.parse(this.normalizeLineEndings(String(source2)), defaultNSMap, entityMap);
6278
+ sax2.parse(this.normalizeLineEndings(String(source)), defaultNSMap, entityMap);
6279
6279
  if (!domBuilder.doc.documentElement) {
6280
6280
  sax2.errorHandler.fatalError("missing root element");
6281
6281
  }
@@ -12905,7 +12905,7 @@ var Bag = class _Bag {
12905
12905
  *
12906
12906
  * @param {Object} [source=null] - Optional dict to initialize from.
12907
12907
  */
12908
- constructor(source2 = null) {
12908
+ constructor(source = null) {
12909
12909
  this._nodes = new BagNodeContainer();
12910
12910
  this._backref = false;
12911
12911
  this._parent = null;
@@ -12914,8 +12914,8 @@ var Bag = class _Bag {
12914
12914
  this._updSubscribers = {};
12915
12915
  this._insSubscribers = {};
12916
12916
  this._delSubscribers = {};
12917
- if (source2) {
12918
- this._loadSource(source2);
12917
+ if (source) {
12918
+ this._loadSource(source);
12919
12919
  }
12920
12920
  }
12921
12921
  // -------------------------------------------------------------------------
@@ -14272,10 +14272,10 @@ var Bag = class _Bag {
14272
14272
  * @param {boolean} [ignoreNone=false] - Optional extension: preserve existing
14273
14273
  * values when the incoming value is null. It is not the mode argument.
14274
14274
  */
14275
- update(source2, mode = null, reason = null, ignoreNone = false) {
14276
- if (!(source2 instanceof _Bag)) {
14277
- for (const label in source2) {
14278
- const value = source2[label];
14275
+ update(source, mode = null, reason = null, ignoreNone = false) {
14276
+ if (!(source instanceof _Bag)) {
14277
+ for (const label in source) {
14278
+ const value = source[label];
14279
14279
  if (!ignoreNone || value !== null || !this._nodes.has(label)) {
14280
14280
  this.setItem(
14281
14281
  label,
@@ -14292,7 +14292,7 @@ var Bag = class _Bag {
14292
14292
  }
14293
14293
  return;
14294
14294
  }
14295
- for (const incoming of [...source2]) {
14295
+ for (const incoming of [...source]) {
14296
14296
  const label = incoming.label;
14297
14297
  const resolver = mode === "static" ? incoming.resolver : null;
14298
14298
  const value = resolver ? null : incoming.getValue();
@@ -14414,13 +14414,13 @@ var Bag = class _Bag {
14414
14414
  * bag.replace(other);
14415
14415
  * // bag now has only 'x' = 10
14416
14416
  */
14417
- _loadSource(source2) {
14418
- if (source2 == null) return this;
14417
+ _loadSource(source) {
14418
+ if (source == null) return this;
14419
14419
  const prepared = this.createChildBag();
14420
- if (source2 instanceof _Bag) {
14421
- prepared._fillFromBag(source2);
14422
- } else if (typeof source2 === "object" && !Array.isArray(source2)) {
14423
- prepared._fillFromDict(source2);
14420
+ if (source instanceof _Bag) {
14421
+ prepared._fillFromBag(source);
14422
+ } else if (typeof source === "object" && !Array.isArray(source)) {
14423
+ prepared._fillFromDict(source);
14424
14424
  } else {
14425
14425
  return this;
14426
14426
  }
@@ -14770,19 +14770,19 @@ ${" ".repeat(depth)}</${tag2}>`;
14770
14770
  * @param {string} [options.tagAttribute=null] - If set, save XML tag name as this attribute on each node.
14771
14771
  * @returns {Bag} Reconstructed Bag hierarchy.
14772
14772
  */
14773
- static fromXml(source2, options = {}) {
14773
+ static fromXml(source, options = {}) {
14774
14774
  const { tagAttribute = null } = options;
14775
14775
  let doc;
14776
14776
  if (typeof DOMParser !== "undefined") {
14777
14777
  const parser = new DOMParser();
14778
- doc = parser.parseFromString(source2, "application/xml");
14778
+ doc = parser.parseFromString(source, "application/xml");
14779
14779
  const parseError = doc.querySelector("parsererror");
14780
14780
  if (parseError) {
14781
14781
  throw new Error(`XML parse error: ${parseError.textContent}`);
14782
14782
  }
14783
14783
  } else {
14784
14784
  const parser = new import_xmldom2.DOMParser();
14785
- doc = parser.parseFromString(source2, "application/xml");
14785
+ doc = parser.parseFromString(source, "application/xml");
14786
14786
  }
14787
14787
  return this._xmlElementToBag(doc.documentElement, tagAttribute);
14788
14788
  }
@@ -14916,14 +14916,14 @@ ${" ".repeat(depth)}</${tag2}>`;
14916
14916
  * @param {string} [listJoiner=null] - If provided, join string arrays with this separator.
14917
14917
  * @returns {Bag} Deserialized Bag.
14918
14918
  */
14919
- static fromJson(source2, listJoiner = null) {
14920
- if (typeof source2 === "string") {
14921
- source2 = fromTytx(source2);
14919
+ static fromJson(source, listJoiner = null) {
14920
+ if (typeof source === "string") {
14921
+ source = fromTytx(source);
14922
14922
  }
14923
- if (!Array.isArray(source2) && typeof source2 !== "object") {
14924
- source2 = { value: source2 };
14923
+ if (!Array.isArray(source) && typeof source !== "object") {
14924
+ source = { value: source };
14925
14925
  }
14926
- return _Bag._fromJsonRecursive(source2, listJoiner);
14926
+ return _Bag._fromJsonRecursive(source, listJoiner);
14927
14927
  }
14928
14928
  /**
14929
14929
  * Recursively convert JSON data to Bag (internal).
@@ -15385,8 +15385,8 @@ var SourceBagNode = class extends BagNode {
15385
15385
  }
15386
15386
  };
15387
15387
  var SourceBag = class _SourceBag extends Bag {
15388
- constructor(source2 = null, builder = null) {
15389
- super(source2);
15388
+ constructor(source = null, builder = null) {
15389
+ super(source);
15390
15390
  this._builder = builder;
15391
15391
  this._insertingBuilder = null;
15392
15392
  }
@@ -15521,11 +15521,11 @@ function elementCall(builder, target, tag2, onBag) {
15521
15521
  };
15522
15522
  }
15523
15523
  function sourceBagFromTytx(payload, builder, { transport = "json" } = {}) {
15524
- const source2 = fromTytx(payload, transport === "json" ? null : transport);
15525
- if (!(source2 instanceof SourceBag)) {
15524
+ const source = fromTytx(payload, transport === "json" ? null : transport);
15525
+ if (!(source instanceof SourceBag)) {
15526
15526
  throw new TypeError("TYTX payload did not decode to SourceBag");
15527
15527
  }
15528
- return source2.bindBuilder(builder);
15528
+ return source.bindBuilder(builder);
15529
15529
  }
15530
15530
 
15531
15531
  // node_modules/@genrojs/builders/src/grammar-loader.js
@@ -16036,8 +16036,8 @@ var RendererBase = class {
16036
16036
  return this.render(roots[0], expansionOpts);
16037
16037
  }
16038
16038
  /** Normalize the source before the top-level walk. Identity by default. */
16039
- preprocess(source2) {
16040
- return source2;
16039
+ preprocess(source) {
16040
+ return source;
16041
16041
  }
16042
16042
  /** Dialect-specific fragment for `node`. Concrete renderers override. */
16043
16043
  renderedItem(_node, _item, _runtimeAttrs, _opts) {
@@ -16795,8 +16795,8 @@ var BuilderBase = class _BuilderBase {
16795
16795
  if (typeof func !== "string") {
16796
16796
  throw new Error("data-element func must be a name or a function");
16797
16797
  }
16798
- for (const source2 of this.dataLogic) {
16799
- const holder = typeof source2 === "function" ? source2 : source2.constructor;
16798
+ for (const source of this.dataLogic) {
16799
+ const holder = typeof source === "function" ? source : source.constructor;
16800
16800
  const fn = holder[func];
16801
16801
  if (typeof fn === "function") {
16802
16802
  return fn;
@@ -24022,14 +24022,14 @@ var Provider = class {
24022
24022
  * `_triggerpars`, `_reason`, the click arguments (undefined for any other trigger), then the author
24023
24023
  * attributes; a body (`formula`, `script`, or `_else` in their place) has `_kwargs` first, `_if` has not.
24024
24024
  */
24025
- #inline(attr, code, source2, kwargs, body) {
24025
+ #inline(attr, code, source, kwargs, body) {
24026
24026
  const names = [
24027
24027
  ...body ? ["_kwargs"] : [],
24028
24028
  ...TRIGGER_FIELDS,
24029
24029
  ...CLICK_FIELDS,
24030
24030
  ...Object.keys(authorArguments(kwargs))
24031
24031
  ];
24032
- return this.binding.runtime.inlineCompiler.compile(this.node, attr, code, names, source2)({ ...kwargs, _kwargs: kwargs });
24032
+ return this.binding.runtime.inlineCompiler.compile(this.node, attr, code, names, source)({ ...kwargs, _kwargs: kwargs });
24033
24033
  }
24034
24034
  #closeRegistrations() {
24035
24035
  for (const registration of this.#registrations.splice(0)) registration.close();
@@ -24143,8 +24143,8 @@ var InlineCompiler = class {
24143
24143
  * The legacy macros of `source` translated to the node methods, `$n` to `arguments[n-1]`, as in
24144
24144
  * `gnrlang.js`. A translated declaration gets one deprecation warning; `PUBLISH` is an error.
24145
24145
  */
24146
- preprocess(node, attr, source2) {
24147
- const text = source2.trim();
24146
+ preprocess(node, attr, source) {
24147
+ const text = source.trim();
24148
24148
  if (PUBLISH.test(text)) throw new Error(`${declaration2(node, attr)}: the PUBLISH macro is excluded from Gramlot 0.2.0`);
24149
24149
  let result = text.replace(/\$(\d+)/g, (_token, n) => `arguments[${parseInt(n, 10) - 1}]`);
24150
24150
  for (const [separator, macro, target] of MACROS) {
@@ -24166,7 +24166,7 @@ var InlineCompiler = class {
24166
24166
  * compile again; the entry is released when its attribute changes or is removed, and when the
24167
24167
  * node's NodeBinding closes.
24168
24168
  */
24169
- compile(node, attr, code, argNames, source2 = code) {
24169
+ compile(node, attr, code, argNames, source = code) {
24170
24170
  if (node.activatedCode(attr) !== code) {
24171
24171
  throw new Error(`${declaration2(node, attr)}: inline code runs only as received with the Source (main or a remote Source); a text written later is not run: use named logic`);
24172
24172
  }
@@ -24177,8 +24177,8 @@ var InlineCompiler = class {
24177
24177
  this.runtime.bindingFor(node).track(() => this.release(node));
24178
24178
  }
24179
24179
  let entry = entries.get(attr);
24180
- if (entry?.source !== source2) {
24181
- entry = { source: source2, text: this.preprocess(node, attr, source2), key: null, run: null };
24180
+ if (entry?.source !== source) {
24181
+ entry = { source, text: this.preprocess(node, attr, source), key: null, run: null };
24182
24182
  entries.set(attr, entry);
24183
24183
  }
24184
24184
  const params = argNames.filter(isIdentifier);
@@ -24700,19 +24700,19 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
24700
24700
  // The resolved projection that `project` hands to the rebuild of a control whose shape changed.
24701
24701
  #rebuildAttributes = /* @__PURE__ */ new WeakMap();
24702
24702
  /** The live renderer of one Gramlot page: `binding` is the page's BindingRuntime (§4.3). */
24703
- constructor(builder, source2, destination, { binding } = {}) {
24703
+ constructor(builder, source, destination, { binding } = {}) {
24704
24704
  super(builder);
24705
- if (!(builder instanceof BuilderBase) || !(source2 instanceof GramlotBuilderBag) || destination?.nodeType !== 1) {
24705
+ if (!(builder instanceof BuilderBase) || !(source instanceof GramlotBuilderBag) || destination?.nodeType !== 1) {
24706
24706
  throw new TypeError("GramlotRenderer requires a BuilderBase, GramlotBuilderBag and HTML destination");
24707
24707
  }
24708
24708
  if (!(binding instanceof BindingRuntime)) throw new TypeError("GramlotRenderer requires a BindingRuntime");
24709
- if (!(source2._builder instanceof BuilderBase)) throw new TypeError("SourceBag requires builder ownership");
24709
+ if (!(source._builder instanceof BuilderBase)) throw new TypeError("SourceBag requires builder ownership");
24710
24710
  this._binding = binding;
24711
- this.source = source2;
24711
+ this.source = source;
24712
24712
  this.destination = destination;
24713
24713
  this.html = new HtmlElement({ metadataAttributes: ["__ref"] });
24714
24714
  this.records = /* @__PURE__ */ new Map();
24715
- this.references = new References(source2);
24715
+ this.references = new References(source);
24716
24716
  this.pending = [];
24717
24717
  this.building = false;
24718
24718
  this.disposed = false;
@@ -24720,7 +24720,7 @@ var GramlotRenderer = class extends GramlotHtmlRenderer {
24720
24720
  this.instanceId = crypto.randomUUID();
24721
24721
  this.radioGroups = new RadioGroups(this);
24722
24722
  this.subscription = `html-source-renderer-${this.instanceId}`;
24723
- source2.subscribe(this.subscription, { any: (event) => this.receive(event) });
24723
+ source.subscribe(this.subscription, { any: (event) => this.receive(event) });
24724
24724
  }
24725
24725
  get binding() {
24726
24726
  return this._binding;
@@ -25324,10 +25324,10 @@ function regexStarts(previous) {
25324
25324
  if (/^[\w$]/.test(previous)) return REGEX_AFTER_WORDS.has(previous);
25325
25325
  return previous !== ")" && previous !== "]";
25326
25326
  }
25327
- function regexEnd(source2, start) {
25327
+ function regexEnd(source, start) {
25328
25328
  let inClass = false;
25329
- for (let index = start + 1; index < source2.length; index++) {
25330
- const char = source2[index];
25329
+ for (let index = start + 1; index < source.length; index++) {
25330
+ const char = source[index];
25331
25331
  if (char === "\n") return -1;
25332
25332
  if (char === "\\") {
25333
25333
  index++;
@@ -25339,26 +25339,26 @@ function regexEnd(source2, start) {
25339
25339
  }
25340
25340
  return -1;
25341
25341
  }
25342
- function declaresConstructor(source2) {
25342
+ function declaresConstructor(source) {
25343
25343
  let depth = 0;
25344
25344
  let members = "";
25345
25345
  let previous = "";
25346
- for (let index = source2.indexOf("{"); index < source2.length; index++) {
25347
- const char = source2[index];
25348
- if (char === "/" && source2[index + 1] === "/") {
25349
- index = source2.indexOf("\n", index);
25346
+ for (let index = source.indexOf("{"); index < source.length; index++) {
25347
+ const char = source[index];
25348
+ if (char === "/" && source[index + 1] === "/") {
25349
+ index = source.indexOf("\n", index);
25350
25350
  if (index < 0) break;
25351
25351
  continue;
25352
25352
  }
25353
- if (char === "/" && source2[index + 1] === "*") {
25354
- const close = source2.indexOf("*/", index + 2);
25353
+ if (char === "/" && source[index + 1] === "*") {
25354
+ const close = source.indexOf("*/", index + 2);
25355
25355
  if (close >= 0) {
25356
25356
  index = close + 1;
25357
25357
  continue;
25358
25358
  }
25359
25359
  }
25360
25360
  if (char === "/" && regexStarts(previous)) {
25361
- const close = regexEnd(source2, index);
25361
+ const close = regexEnd(source, index);
25362
25362
  if (close >= 0) {
25363
25363
  index = close;
25364
25364
  previous = ")";
@@ -25367,17 +25367,17 @@ function declaresConstructor(source2) {
25367
25367
  }
25368
25368
  if (char === '"' || char === "'" || char === "`") {
25369
25369
  let end = index + 1;
25370
- while (end < source2.length && source2[end] !== char) end += source2[end] === "\\" ? 2 : 1;
25371
- if (depth === 1) members += source2.slice(index + 1, end) === "constructor" ? " constructor" : ' ""';
25370
+ while (end < source.length && source[end] !== char) end += source[end] === "\\" ? 2 : 1;
25371
+ if (depth === 1) members += source.slice(index + 1, end) === "constructor" ? " constructor" : ' ""';
25372
25372
  index = end;
25373
25373
  previous = ")";
25374
25374
  continue;
25375
25375
  }
25376
25376
  if (/[\w$]/.test(char)) {
25377
25377
  let end = index + 1;
25378
- while (end < source2.length && /[\w$]/.test(source2[end])) end++;
25379
- if (depth === 1) members += source2.slice(index, end);
25380
- previous = source2.slice(index, end);
25378
+ while (end < source.length && /[\w$]/.test(source[end])) end++;
25379
+ if (depth === 1) members += source.slice(index, end);
25380
+ previous = source.slice(index, end);
25381
25381
  index = end - 1;
25382
25382
  continue;
25383
25383
  }
@@ -25550,10 +25550,10 @@ var SourceHandler = class extends Handler {
25550
25550
  * NodeBindings (P12, no rollback).
25551
25551
  */
25552
25552
  mountMainSource(wire) {
25553
- const source2 = this.prepareSource(wire);
25554
- this.renderer.validateCandidate(source2);
25553
+ const source = this.prepareSource(wire);
25554
+ this.renderer.validateCandidate(source);
25555
25555
  try {
25556
- this.source.setItem("main", source2);
25556
+ this.source.setItem("main", source);
25557
25557
  } catch (error) {
25558
25558
  if (!this.binding.bindingFor(this.source.getNode("main"))) this.source.popNode("main");
25559
25559
  throw error;
@@ -25572,16 +25572,16 @@ var SourceHandler = class extends Handler {
25572
25572
  if (!(wire instanceof GramlotBuilderBag)) throw new TypeError("Source values must be GramlotBuilderBags");
25573
25573
  return wire.bindBuilder(builder).activateCode();
25574
25574
  }
25575
- const source2 = sourceBagFromTytx(wire, builder);
25576
- if (!(source2 instanceof GramlotBuilderBag)) throw new TypeError("Source values must be GramlotBuilderBags");
25577
- return source2.activateCode();
25575
+ const source = sourceBagFromTytx(wire, builder);
25576
+ if (!(source instanceof GramlotBuilderBag)) throw new TypeError("Source values must be GramlotBuilderBags");
25577
+ return source.activateCode();
25578
25578
  }
25579
25579
  /**
25580
25580
  * Replace one Source node's children only after incoming Source validation.
25581
25581
  * The request lives as long as the target's NodeBinding (P24): a DOM rebuild
25582
25582
  * or a freeze keeps it, the removal of the target cancels it.
25583
25583
  *
25584
- * Source methods (`@source`, `source(...)`, `remoteSource`) are not yet part of the page-writing API:
25584
+ * Source methods (`@source`, `registerSource`, `remoteSource`) are not yet part of the page-writing API:
25585
25585
  * they arrive together with the `remote` grammar attribute and `@endpoint`.
25586
25586
  */
25587
25587
  async remoteSource(target, method, params = {}) {
@@ -25891,13 +25891,8 @@ var PageBootstrap = class {
25891
25891
  }
25892
25892
  };
25893
25893
 
25894
- // src/adapters/page.js
25894
+ // src/server/page.js
25895
25895
  var SOURCE_METHOD = /* @__PURE__ */ Symbol("gramlot.source");
25896
- function source(method) {
25897
- if (typeof method !== "function") throw new TypeError("source requires a method");
25898
- method[SOURCE_METHOD] = true;
25899
- return method;
25900
- }
25901
25896
  var Page = class {
25902
25897
  static title = "Gramlot";
25903
25898
  static css = [];
@@ -25907,6 +25902,21 @@ var Page = class {
25907
25902
  main(root) {
25908
25903
  throw new Error("Page.main(root) must be implemented");
25909
25904
  }
25905
+ /**
25906
+ * Mark the own method `methodName` of this page class as a remote Source method,
25907
+ * equivalent to Python `@source`; call it after the class.
25908
+ *
25909
+ * Source methods (`@source`, `registerSource`, `remoteSource`) are not yet part of the page-writing API:
25910
+ * they arrive together with the `remote` grammar attribute and `@endpoint`.
25911
+ */
25912
+ static registerSource(methodName) {
25913
+ const method = Object.getOwnPropertyDescriptor(this.prototype, methodName)?.value;
25914
+ if (typeof method !== "function") {
25915
+ throw new TypeError(`registerSource requires an own method of ${this.name}: ${String(methodName)}`);
25916
+ }
25917
+ if (method[SOURCE_METHOD]) throw new TypeError(`Source method already registered: ${methodName}`);
25918
+ method[SOURCE_METHOD] = true;
25919
+ }
25910
25920
  };
25911
25921
  export {
25912
25922
  Bag,
@@ -25925,6 +25935,5 @@ export {
25925
25935
  References,
25926
25936
  RpcHandler,
25927
25937
  SourceHandler,
25928
- UtilitiesHandler,
25929
- source
25938
+ UtilitiesHandler
25930
25939
  };