@vuu-ui/vuu-data-test 0.8.18-debug → 0.8.19-debug

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/esm/index.js CHANGED
@@ -879,4658 +879,132 @@ var getSchema = (tableName) => {
879
879
  throw Error(`getSchema no schema for table ${tableName}`);
880
880
  };
881
881
 
882
- // ../../node_modules/@lezer/common/dist/index.js
883
- var DefaultBufferLength = 1024;
884
- var nextPropID = 0;
885
- var Range = class {
886
- constructor(from, to) {
887
- this.from = from;
888
- this.to = to;
889
- }
890
- };
891
- var NodeProp = class {
892
- /// Create a new node prop type.
893
- constructor(config = {}) {
894
- this.id = nextPropID++;
895
- this.perNode = !!config.perNode;
896
- this.deserialize = config.deserialize || (() => {
897
- throw new Error("This node type doesn't define a deserialize function");
898
- });
899
- }
900
- /// This is meant to be used with
901
- /// [`NodeSet.extend`](#common.NodeSet.extend) or
902
- /// [`LRParser.configure`](#lr.ParserConfig.props) to compute
903
- /// prop values for each node type in the set. Takes a [match
904
- /// object](#common.NodeType^match) or function that returns undefined
905
- /// if the node type doesn't get this prop, and the prop's value if
906
- /// it does.
907
- add(match) {
908
- if (this.perNode)
909
- throw new RangeError("Can't add per-node props to node types");
910
- if (typeof match != "function")
911
- match = NodeType.match(match);
912
- return (type) => {
913
- let result = match(type);
914
- return result === void 0 ? null : [this, result];
915
- };
916
- }
917
- };
918
- NodeProp.closedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
919
- NodeProp.openedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
920
- NodeProp.group = new NodeProp({ deserialize: (str) => str.split(" ") });
921
- NodeProp.contextHash = new NodeProp({ perNode: true });
922
- NodeProp.lookAhead = new NodeProp({ perNode: true });
923
- NodeProp.mounted = new NodeProp({ perNode: true });
924
- var noProps = /* @__PURE__ */ Object.create(null);
925
- var NodeType = class _NodeType {
926
- /// @internal
927
- constructor(name, props, id, flags = 0) {
928
- this.name = name;
929
- this.props = props;
930
- this.id = id;
931
- this.flags = flags;
932
- }
933
- /// Define a node type.
934
- static define(spec) {
935
- let props = spec.props && spec.props.length ? /* @__PURE__ */ Object.create(null) : noProps;
936
- let flags = (spec.top ? 1 : 0) | (spec.skipped ? 2 : 0) | (spec.error ? 4 : 0) | (spec.name == null ? 8 : 0);
937
- let type = new _NodeType(spec.name || "", props, spec.id, flags);
938
- if (spec.props)
939
- for (let src of spec.props) {
940
- if (!Array.isArray(src))
941
- src = src(type);
942
- if (src) {
943
- if (src[0].perNode)
944
- throw new RangeError("Can't store a per-node prop on a node type");
945
- props[src[0].id] = src[1];
946
- }
947
- }
948
- return type;
949
- }
950
- /// Retrieves a node prop for this type. Will return `undefined` if
951
- /// the prop isn't present on this node.
952
- prop(prop) {
953
- return this.props[prop.id];
954
- }
955
- /// True when this is the top node of a grammar.
956
- get isTop() {
957
- return (this.flags & 1) > 0;
958
- }
959
- /// True when this node is produced by a skip rule.
960
- get isSkipped() {
961
- return (this.flags & 2) > 0;
962
- }
963
- /// Indicates whether this is an error node.
964
- get isError() {
965
- return (this.flags & 4) > 0;
966
- }
967
- /// When true, this node type doesn't correspond to a user-declared
968
- /// named node, for example because it is used to cache repetition.
969
- get isAnonymous() {
970
- return (this.flags & 8) > 0;
971
- }
972
- /// Returns true when this node's name or one of its
973
- /// [groups](#common.NodeProp^group) matches the given string.
974
- is(name) {
975
- if (typeof name == "string") {
976
- if (this.name == name)
977
- return true;
978
- let group = this.prop(NodeProp.group);
979
- return group ? group.indexOf(name) > -1 : false;
980
- }
981
- return this.id == name;
982
- }
983
- /// Create a function from node types to arbitrary values by
984
- /// specifying an object whose property names are node or
985
- /// [group](#common.NodeProp^group) names. Often useful with
986
- /// [`NodeProp.add`](#common.NodeProp.add). You can put multiple
987
- /// names, separated by spaces, in a single property name to map
988
- /// multiple node names to a single value.
989
- static match(map) {
990
- let direct = /* @__PURE__ */ Object.create(null);
991
- for (let prop in map)
992
- for (let name of prop.split(" "))
993
- direct[name] = map[prop];
994
- return (node) => {
995
- for (let groups = node.prop(NodeProp.group), i = -1; i < (groups ? groups.length : 0); i++) {
996
- let found = direct[i < 0 ? node.name : groups[i]];
997
- if (found)
998
- return found;
999
- }
1000
- };
1001
- }
1002
- };
1003
- NodeType.none = new NodeType(
1004
- "",
1005
- /* @__PURE__ */ Object.create(null),
1006
- 0,
1007
- 8
1008
- /* NodeFlag.Anonymous */
1009
- );
1010
- var NodeSet = class _NodeSet {
1011
- /// Create a set with the given types. The `id` property of each
1012
- /// type should correspond to its position within the array.
1013
- constructor(types) {
1014
- this.types = types;
1015
- for (let i = 0; i < types.length; i++)
1016
- if (types[i].id != i)
1017
- throw new RangeError("Node type ids should correspond to array positions when creating a node set");
1018
- }
1019
- /// Create a copy of this set with some node properties added. The
1020
- /// arguments to this method can be created with
1021
- /// [`NodeProp.add`](#common.NodeProp.add).
1022
- extend(...props) {
1023
- let newTypes = [];
1024
- for (let type of this.types) {
1025
- let newProps = null;
1026
- for (let source of props) {
1027
- let add = source(type);
1028
- if (add) {
1029
- if (!newProps)
1030
- newProps = Object.assign({}, type.props);
1031
- newProps[add[0].id] = add[1];
1032
- }
1033
- }
1034
- newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
1035
- }
1036
- return new _NodeSet(newTypes);
1037
- }
1038
- };
1039
- var CachedNode = /* @__PURE__ */ new WeakMap();
1040
- var CachedInnerNode = /* @__PURE__ */ new WeakMap();
1041
- var IterMode;
1042
- (function(IterMode2) {
1043
- IterMode2[IterMode2["ExcludeBuffers"] = 1] = "ExcludeBuffers";
1044
- IterMode2[IterMode2["IncludeAnonymous"] = 2] = "IncludeAnonymous";
1045
- IterMode2[IterMode2["IgnoreMounts"] = 4] = "IgnoreMounts";
1046
- IterMode2[IterMode2["IgnoreOverlays"] = 8] = "IgnoreOverlays";
1047
- })(IterMode || (IterMode = {}));
1048
- var Tree = class _Tree {
1049
- /// Construct a new tree. See also [`Tree.build`](#common.Tree^build).
1050
- constructor(type, children, positions, length2, props) {
1051
- this.type = type;
1052
- this.children = children;
1053
- this.positions = positions;
1054
- this.length = length2;
1055
- this.props = null;
1056
- if (props && props.length) {
1057
- this.props = /* @__PURE__ */ Object.create(null);
1058
- for (let [prop, value] of props)
1059
- this.props[typeof prop == "number" ? prop : prop.id] = value;
1060
- }
1061
- }
1062
- /// @internal
1063
- toString() {
1064
- let mounted = this.prop(NodeProp.mounted);
1065
- if (mounted && !mounted.overlay)
1066
- return mounted.tree.toString();
1067
- let children = "";
1068
- for (let ch of this.children) {
1069
- let str = ch.toString();
1070
- if (str) {
1071
- if (children)
1072
- children += ",";
1073
- children += str;
1074
- }
1075
- }
1076
- return !this.type.name ? children : (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) + (children.length ? "(" + children + ")" : "");
1077
- }
1078
- /// Get a [tree cursor](#common.TreeCursor) positioned at the top of
1079
- /// the tree. Mode can be used to [control](#common.IterMode) which
1080
- /// nodes the cursor visits.
1081
- cursor(mode = 0) {
1082
- return new TreeCursor(this.topNode, mode);
1083
- }
1084
- /// Get a [tree cursor](#common.TreeCursor) pointing into this tree
1085
- /// at the given position and side (see
1086
- /// [`moveTo`](#common.TreeCursor.moveTo).
1087
- cursorAt(pos, side = 0, mode = 0) {
1088
- let scope = CachedNode.get(this) || this.topNode;
1089
- let cursor = new TreeCursor(scope);
1090
- cursor.moveTo(pos, side);
1091
- CachedNode.set(this, cursor._tree);
1092
- return cursor;
1093
- }
1094
- /// Get a [syntax node](#common.SyntaxNode) object for the top of the
1095
- /// tree.
1096
- get topNode() {
1097
- return new TreeNode(this, 0, 0, null);
1098
- }
1099
- /// Get the [syntax node](#common.SyntaxNode) at the given position.
1100
- /// If `side` is -1, this will move into nodes that end at the
1101
- /// position. If 1, it'll move into nodes that start at the
1102
- /// position. With 0, it'll only enter nodes that cover the position
1103
- /// from both sides.
1104
- ///
1105
- /// Note that this will not enter
1106
- /// [overlays](#common.MountedTree.overlay), and you often want
1107
- /// [`resolveInner`](#common.Tree.resolveInner) instead.
1108
- resolve(pos, side = 0) {
1109
- let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
1110
- CachedNode.set(this, node);
1111
- return node;
1112
- }
1113
- /// Like [`resolve`](#common.Tree.resolve), but will enter
1114
- /// [overlaid](#common.MountedTree.overlay) nodes, producing a syntax node
1115
- /// pointing into the innermost overlaid tree at the given position
1116
- /// (with parent links going through all parent structure, including
1117
- /// the host trees).
1118
- resolveInner(pos, side = 0) {
1119
- let node = resolveNode(CachedInnerNode.get(this) || this.topNode, pos, side, true);
1120
- CachedInnerNode.set(this, node);
1121
- return node;
1122
- }
1123
- /// Iterate over the tree and its children, calling `enter` for any
1124
- /// node that touches the `from`/`to` region (if given) before
1125
- /// running over such a node's children, and `leave` (if given) when
1126
- /// leaving the node. When `enter` returns `false`, that node will
1127
- /// not have its children iterated over (or `leave` called).
1128
- iterate(spec) {
1129
- let { enter, leave, from = 0, to = this.length } = spec;
1130
- let mode = spec.mode || 0, anon = (mode & IterMode.IncludeAnonymous) > 0;
1131
- for (let c = this.cursor(mode | IterMode.IncludeAnonymous); ; ) {
1132
- let entered = false;
1133
- if (c.from <= to && c.to >= from && (!anon && c.type.isAnonymous || enter(c) !== false)) {
1134
- if (c.firstChild())
1135
- continue;
1136
- entered = true;
1137
- }
1138
- for (; ; ) {
1139
- if (entered && leave && (anon || !c.type.isAnonymous))
1140
- leave(c);
1141
- if (c.nextSibling())
1142
- break;
1143
- if (!c.parent())
1144
- return;
1145
- entered = true;
1146
- }
1147
- }
1148
- }
1149
- /// Get the value of the given [node prop](#common.NodeProp) for this
1150
- /// node. Works with both per-node and per-type props.
1151
- prop(prop) {
1152
- return !prop.perNode ? this.type.prop(prop) : this.props ? this.props[prop.id] : void 0;
1153
- }
1154
- /// Returns the node's [per-node props](#common.NodeProp.perNode) in a
1155
- /// format that can be passed to the [`Tree`](#common.Tree)
1156
- /// constructor.
1157
- get propValues() {
1158
- let result = [];
1159
- if (this.props)
1160
- for (let id in this.props)
1161
- result.push([+id, this.props[id]]);
1162
- return result;
1163
- }
1164
- /// Balance the direct children of this tree, producing a copy of
1165
- /// which may have children grouped into subtrees with type
1166
- /// [`NodeType.none`](#common.NodeType^none).
1167
- balance(config = {}) {
1168
- return this.children.length <= 8 ? this : balanceRange(NodeType.none, this.children, this.positions, 0, this.children.length, 0, this.length, (children, positions, length2) => new _Tree(this.type, children, positions, length2, this.propValues), config.makeTree || ((children, positions, length2) => new _Tree(NodeType.none, children, positions, length2)));
1169
- }
1170
- /// Build a tree from a postfix-ordered buffer of node information,
1171
- /// or a cursor over such a buffer.
1172
- static build(data) {
1173
- return buildTree(data);
1174
- }
1175
- };
1176
- Tree.empty = new Tree(NodeType.none, [], [], 0);
1177
- var FlatBufferCursor = class _FlatBufferCursor {
1178
- constructor(buffer, index) {
1179
- this.buffer = buffer;
1180
- this.index = index;
1181
- }
1182
- get id() {
1183
- return this.buffer[this.index - 4];
1184
- }
1185
- get start() {
1186
- return this.buffer[this.index - 3];
1187
- }
1188
- get end() {
1189
- return this.buffer[this.index - 2];
1190
- }
1191
- get size() {
1192
- return this.buffer[this.index - 1];
1193
- }
1194
- get pos() {
1195
- return this.index;
1196
- }
1197
- next() {
1198
- this.index -= 4;
1199
- }
1200
- fork() {
1201
- return new _FlatBufferCursor(this.buffer, this.index);
1202
- }
1203
- };
1204
- var TreeBuffer = class _TreeBuffer {
1205
- /// Create a tree buffer.
1206
- constructor(buffer, length2, set) {
1207
- this.buffer = buffer;
1208
- this.length = length2;
1209
- this.set = set;
1210
- }
1211
- /// @internal
1212
- get type() {
1213
- return NodeType.none;
1214
- }
1215
- /// @internal
1216
- toString() {
1217
- let result = [];
1218
- for (let index = 0; index < this.buffer.length; ) {
1219
- result.push(this.childString(index));
1220
- index = this.buffer[index + 3];
1221
- }
1222
- return result.join(",");
1223
- }
1224
- /// @internal
1225
- childString(index) {
1226
- let id = this.buffer[index], endIndex = this.buffer[index + 3];
1227
- let type = this.set.types[id], result = type.name;
1228
- if (/\W/.test(result) && !type.isError)
1229
- result = JSON.stringify(result);
1230
- index += 4;
1231
- if (endIndex == index)
1232
- return result;
1233
- let children = [];
1234
- while (index < endIndex) {
1235
- children.push(this.childString(index));
1236
- index = this.buffer[index + 3];
1237
- }
1238
- return result + "(" + children.join(",") + ")";
1239
- }
1240
- /// @internal
1241
- findChild(startIndex, endIndex, dir, pos, side) {
1242
- let { buffer } = this, pick = -1;
1243
- for (let i = startIndex; i != endIndex; i = buffer[i + 3]) {
1244
- if (checkSide(side, pos, buffer[i + 1], buffer[i + 2])) {
1245
- pick = i;
1246
- if (dir > 0)
1247
- break;
1248
- }
1249
- }
1250
- return pick;
1251
- }
1252
- /// @internal
1253
- slice(startI, endI, from) {
1254
- let b = this.buffer;
1255
- let copy = new Uint16Array(endI - startI), len = 0;
1256
- for (let i = startI, j = 0; i < endI; ) {
1257
- copy[j++] = b[i++];
1258
- copy[j++] = b[i++] - from;
1259
- let to = copy[j++] = b[i++] - from;
1260
- copy[j++] = b[i++] - startI;
1261
- len = Math.max(len, to);
1262
- }
1263
- return new _TreeBuffer(copy, len, this.set);
1264
- }
1265
- };
1266
- function checkSide(side, pos, from, to) {
1267
- switch (side) {
1268
- case -2:
1269
- return from < pos;
1270
- case -1:
1271
- return to >= pos && from < pos;
1272
- case 0:
1273
- return from < pos && to > pos;
1274
- case 1:
1275
- return from <= pos && to > pos;
1276
- case 2:
1277
- return to > pos;
1278
- case 4:
1279
- return true;
1280
- }
1281
- }
1282
- function enterUnfinishedNodesBefore(node, pos) {
1283
- let scan = node.childBefore(pos);
1284
- while (scan) {
1285
- let last2 = scan.lastChild;
1286
- if (!last2 || last2.to != scan.to)
1287
- break;
1288
- if (last2.type.isError && last2.from == last2.to) {
1289
- node = scan;
1290
- scan = last2.prevSibling;
1291
- } else {
1292
- scan = last2;
1293
- }
1294
- }
1295
- return node;
1296
- }
1297
- function resolveNode(node, pos, side, overlays) {
1298
- var _a;
1299
- while (node.from == node.to || (side < 1 ? node.from >= pos : node.from > pos) || (side > -1 ? node.to <= pos : node.to < pos)) {
1300
- let parent = !overlays && node instanceof TreeNode && node.index < 0 ? null : node.parent;
1301
- if (!parent)
1302
- return node;
1303
- node = parent;
1304
- }
1305
- let mode = overlays ? 0 : IterMode.IgnoreOverlays;
1306
- if (overlays)
1307
- for (let scan = node, parent = scan.parent; parent; scan = parent, parent = scan.parent) {
1308
- if (scan instanceof TreeNode && scan.index < 0 && ((_a = parent.enter(pos, side, mode)) === null || _a === void 0 ? void 0 : _a.from) != scan.from)
1309
- node = parent;
1310
- }
1311
- for (; ; ) {
1312
- let inner = node.enter(pos, side, mode);
1313
- if (!inner)
1314
- return node;
1315
- node = inner;
1316
- }
1317
- }
1318
- var TreeNode = class _TreeNode {
1319
- constructor(_tree, from, index, _parent) {
1320
- this._tree = _tree;
1321
- this.from = from;
1322
- this.index = index;
1323
- this._parent = _parent;
1324
- }
1325
- get type() {
1326
- return this._tree.type;
1327
- }
1328
- get name() {
1329
- return this._tree.type.name;
1330
- }
1331
- get to() {
1332
- return this.from + this._tree.length;
1333
- }
1334
- nextChild(i, dir, pos, side, mode = 0) {
1335
- for (let parent = this; ; ) {
1336
- for (let { children, positions } = parent._tree, e = dir > 0 ? children.length : -1; i != e; i += dir) {
1337
- let next = children[i], start = positions[i] + parent.from;
1338
- if (!checkSide(side, pos, start, start + next.length))
1339
- continue;
1340
- if (next instanceof TreeBuffer) {
1341
- if (mode & IterMode.ExcludeBuffers)
1342
- continue;
1343
- let index = next.findChild(0, next.buffer.length, dir, pos - start, side);
1344
- if (index > -1)
1345
- return new BufferNode(new BufferContext(parent, next, i, start), null, index);
1346
- } else if (mode & IterMode.IncludeAnonymous || (!next.type.isAnonymous || hasChild(next))) {
1347
- let mounted;
1348
- if (!(mode & IterMode.IgnoreMounts) && next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay)
1349
- return new _TreeNode(mounted.tree, start, i, parent);
1350
- let inner = new _TreeNode(next, start, i, parent);
1351
- return mode & IterMode.IncludeAnonymous || !inner.type.isAnonymous ? inner : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side);
1352
- }
1353
- }
1354
- if (mode & IterMode.IncludeAnonymous || !parent.type.isAnonymous)
1355
- return null;
1356
- if (parent.index >= 0)
1357
- i = parent.index + dir;
1358
- else
1359
- i = dir < 0 ? -1 : parent._parent._tree.children.length;
1360
- parent = parent._parent;
1361
- if (!parent)
1362
- return null;
1363
- }
1364
- }
1365
- get firstChild() {
1366
- return this.nextChild(
1367
- 0,
1368
- 1,
1369
- 0,
1370
- 4
1371
- /* Side.DontCare */
1372
- );
1373
- }
1374
- get lastChild() {
1375
- return this.nextChild(
1376
- this._tree.children.length - 1,
1377
- -1,
1378
- 0,
1379
- 4
1380
- /* Side.DontCare */
1381
- );
1382
- }
1383
- childAfter(pos) {
1384
- return this.nextChild(
1385
- 0,
1386
- 1,
1387
- pos,
1388
- 2
1389
- /* Side.After */
1390
- );
1391
- }
1392
- childBefore(pos) {
1393
- return this.nextChild(
1394
- this._tree.children.length - 1,
1395
- -1,
1396
- pos,
1397
- -2
1398
- /* Side.Before */
1399
- );
1400
- }
1401
- enter(pos, side, mode = 0) {
1402
- let mounted;
1403
- if (!(mode & IterMode.IgnoreOverlays) && (mounted = this._tree.prop(NodeProp.mounted)) && mounted.overlay) {
1404
- let rPos = pos - this.from;
1405
- for (let { from, to } of mounted.overlay) {
1406
- if ((side > 0 ? from <= rPos : from < rPos) && (side < 0 ? to >= rPos : to > rPos))
1407
- return new _TreeNode(mounted.tree, mounted.overlay[0].from + this.from, -1, this);
1408
- }
1409
- }
1410
- return this.nextChild(0, 1, pos, side, mode);
1411
- }
1412
- nextSignificantParent() {
1413
- let val = this;
1414
- while (val.type.isAnonymous && val._parent)
1415
- val = val._parent;
1416
- return val;
1417
- }
1418
- get parent() {
1419
- return this._parent ? this._parent.nextSignificantParent() : null;
1420
- }
1421
- get nextSibling() {
1422
- return this._parent && this.index >= 0 ? this._parent.nextChild(
1423
- this.index + 1,
1424
- 1,
1425
- 0,
1426
- 4
1427
- /* Side.DontCare */
1428
- ) : null;
1429
- }
1430
- get prevSibling() {
1431
- return this._parent && this.index >= 0 ? this._parent.nextChild(
1432
- this.index - 1,
1433
- -1,
1434
- 0,
1435
- 4
1436
- /* Side.DontCare */
1437
- ) : null;
1438
- }
1439
- cursor(mode = 0) {
1440
- return new TreeCursor(this, mode);
1441
- }
1442
- get tree() {
1443
- return this._tree;
1444
- }
1445
- toTree() {
1446
- return this._tree;
1447
- }
1448
- resolve(pos, side = 0) {
1449
- return resolveNode(this, pos, side, false);
1450
- }
1451
- resolveInner(pos, side = 0) {
1452
- return resolveNode(this, pos, side, true);
1453
- }
1454
- enterUnfinishedNodesBefore(pos) {
1455
- return enterUnfinishedNodesBefore(this, pos);
1456
- }
1457
- getChild(type, before = null, after = null) {
1458
- let r = getChildren(this, type, before, after);
1459
- return r.length ? r[0] : null;
1460
- }
1461
- getChildren(type, before = null, after = null) {
1462
- return getChildren(this, type, before, after);
1463
- }
1464
- /// @internal
1465
- toString() {
1466
- return this._tree.toString();
1467
- }
1468
- get node() {
1469
- return this;
1470
- }
1471
- matchContext(context) {
1472
- return matchNodeContext(this, context);
1473
- }
1474
- };
1475
- function getChildren(node, type, before, after) {
1476
- let cur = node.cursor(), result = [];
1477
- if (!cur.firstChild())
1478
- return result;
1479
- if (before != null) {
1480
- while (!cur.type.is(before))
1481
- if (!cur.nextSibling())
1482
- return result;
1483
- }
1484
- for (; ; ) {
1485
- if (after != null && cur.type.is(after))
1486
- return result;
1487
- if (cur.type.is(type))
1488
- result.push(cur.node);
1489
- if (!cur.nextSibling())
1490
- return after == null ? result : [];
1491
- }
1492
- }
1493
- function matchNodeContext(node, context, i = context.length - 1) {
1494
- for (let p = node.parent; i >= 0; p = p.parent) {
1495
- if (!p)
1496
- return false;
1497
- if (!p.type.isAnonymous) {
1498
- if (context[i] && context[i] != p.name)
1499
- return false;
1500
- i--;
1501
- }
1502
- }
1503
- return true;
1504
- }
1505
- var BufferContext = class {
1506
- constructor(parent, buffer, index, start) {
1507
- this.parent = parent;
1508
- this.buffer = buffer;
1509
- this.index = index;
1510
- this.start = start;
1511
- }
1512
- };
1513
- var BufferNode = class _BufferNode {
1514
- get name() {
1515
- return this.type.name;
1516
- }
1517
- get from() {
1518
- return this.context.start + this.context.buffer.buffer[this.index + 1];
1519
- }
1520
- get to() {
1521
- return this.context.start + this.context.buffer.buffer[this.index + 2];
1522
- }
1523
- constructor(context, _parent, index) {
1524
- this.context = context;
1525
- this._parent = _parent;
1526
- this.index = index;
1527
- this.type = context.buffer.set.types[context.buffer.buffer[index]];
1528
- }
1529
- child(dir, pos, side) {
1530
- let { buffer } = this.context;
1531
- let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side);
1532
- return index < 0 ? null : new _BufferNode(this.context, this, index);
1533
- }
1534
- get firstChild() {
1535
- return this.child(
1536
- 1,
1537
- 0,
1538
- 4
1539
- /* Side.DontCare */
1540
- );
1541
- }
1542
- get lastChild() {
1543
- return this.child(
1544
- -1,
1545
- 0,
1546
- 4
1547
- /* Side.DontCare */
1548
- );
1549
- }
1550
- childAfter(pos) {
1551
- return this.child(
1552
- 1,
1553
- pos,
1554
- 2
1555
- /* Side.After */
1556
- );
1557
- }
1558
- childBefore(pos) {
1559
- return this.child(
1560
- -1,
1561
- pos,
1562
- -2
1563
- /* Side.Before */
1564
- );
1565
- }
1566
- enter(pos, side, mode = 0) {
1567
- if (mode & IterMode.ExcludeBuffers)
1568
- return null;
1569
- let { buffer } = this.context;
1570
- let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], side > 0 ? 1 : -1, pos - this.context.start, side);
1571
- return index < 0 ? null : new _BufferNode(this.context, this, index);
1572
- }
1573
- get parent() {
1574
- return this._parent || this.context.parent.nextSignificantParent();
1575
- }
1576
- externalSibling(dir) {
1577
- return this._parent ? null : this.context.parent.nextChild(
1578
- this.context.index + dir,
1579
- dir,
1580
- 0,
1581
- 4
1582
- /* Side.DontCare */
1583
- );
1584
- }
1585
- get nextSibling() {
1586
- let { buffer } = this.context;
1587
- let after = buffer.buffer[this.index + 3];
1588
- if (after < (this._parent ? buffer.buffer[this._parent.index + 3] : buffer.buffer.length))
1589
- return new _BufferNode(this.context, this._parent, after);
1590
- return this.externalSibling(1);
1591
- }
1592
- get prevSibling() {
1593
- let { buffer } = this.context;
1594
- let parentStart = this._parent ? this._parent.index + 4 : 0;
1595
- if (this.index == parentStart)
1596
- return this.externalSibling(-1);
1597
- return new _BufferNode(this.context, this._parent, buffer.findChild(
1598
- parentStart,
1599
- this.index,
1600
- -1,
1601
- 0,
1602
- 4
1603
- /* Side.DontCare */
1604
- ));
1605
- }
1606
- cursor(mode = 0) {
1607
- return new TreeCursor(this, mode);
1608
- }
1609
- get tree() {
1610
- return null;
1611
- }
1612
- toTree() {
1613
- let children = [], positions = [];
1614
- let { buffer } = this.context;
1615
- let startI = this.index + 4, endI = buffer.buffer[this.index + 3];
1616
- if (endI > startI) {
1617
- let from = buffer.buffer[this.index + 1];
1618
- children.push(buffer.slice(startI, endI, from));
1619
- positions.push(0);
1620
- }
1621
- return new Tree(this.type, children, positions, this.to - this.from);
1622
- }
1623
- resolve(pos, side = 0) {
1624
- return resolveNode(this, pos, side, false);
1625
- }
1626
- resolveInner(pos, side = 0) {
1627
- return resolveNode(this, pos, side, true);
1628
- }
1629
- enterUnfinishedNodesBefore(pos) {
1630
- return enterUnfinishedNodesBefore(this, pos);
1631
- }
1632
- /// @internal
1633
- toString() {
1634
- return this.context.buffer.childString(this.index);
1635
- }
1636
- getChild(type, before = null, after = null) {
1637
- let r = getChildren(this, type, before, after);
1638
- return r.length ? r[0] : null;
1639
- }
1640
- getChildren(type, before = null, after = null) {
1641
- return getChildren(this, type, before, after);
1642
- }
1643
- get node() {
1644
- return this;
1645
- }
1646
- matchContext(context) {
1647
- return matchNodeContext(this, context);
1648
- }
1649
- };
1650
- var TreeCursor = class {
1651
- /// Shorthand for `.type.name`.
1652
- get name() {
1653
- return this.type.name;
1654
- }
1655
- /// @internal
1656
- constructor(node, mode = 0) {
1657
- this.mode = mode;
1658
- this.buffer = null;
1659
- this.stack = [];
1660
- this.index = 0;
1661
- this.bufferNode = null;
1662
- if (node instanceof TreeNode) {
1663
- this.yieldNode(node);
1664
- } else {
1665
- this._tree = node.context.parent;
1666
- this.buffer = node.context;
1667
- for (let n = node._parent; n; n = n._parent)
1668
- this.stack.unshift(n.index);
1669
- this.bufferNode = node;
1670
- this.yieldBuf(node.index);
1671
- }
1672
- }
1673
- yieldNode(node) {
1674
- if (!node)
1675
- return false;
1676
- this._tree = node;
1677
- this.type = node.type;
1678
- this.from = node.from;
1679
- this.to = node.to;
1680
- return true;
1681
- }
1682
- yieldBuf(index, type) {
1683
- this.index = index;
1684
- let { start, buffer } = this.buffer;
1685
- this.type = type || buffer.set.types[buffer.buffer[index]];
1686
- this.from = start + buffer.buffer[index + 1];
1687
- this.to = start + buffer.buffer[index + 2];
1688
- return true;
1689
- }
1690
- yield(node) {
1691
- if (!node)
1692
- return false;
1693
- if (node instanceof TreeNode) {
1694
- this.buffer = null;
1695
- return this.yieldNode(node);
1696
- }
1697
- this.buffer = node.context;
1698
- return this.yieldBuf(node.index, node.type);
1699
- }
1700
- /// @internal
1701
- toString() {
1702
- return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
1703
- }
1704
- /// @internal
1705
- enterChild(dir, pos, side) {
1706
- if (!this.buffer)
1707
- return this.yield(this._tree.nextChild(dir < 0 ? this._tree._tree.children.length - 1 : 0, dir, pos, side, this.mode));
1708
- let { buffer } = this.buffer;
1709
- let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.buffer.start, side);
1710
- if (index < 0)
1711
- return false;
1712
- this.stack.push(this.index);
1713
- return this.yieldBuf(index);
1714
- }
1715
- /// Move the cursor to this node's first child. When this returns
1716
- /// false, the node has no child, and the cursor has not been moved.
1717
- firstChild() {
1718
- return this.enterChild(
1719
- 1,
1720
- 0,
1721
- 4
1722
- /* Side.DontCare */
1723
- );
1724
- }
1725
- /// Move the cursor to this node's last child.
1726
- lastChild() {
1727
- return this.enterChild(
1728
- -1,
1729
- 0,
1730
- 4
1731
- /* Side.DontCare */
1732
- );
1733
- }
1734
- /// Move the cursor to the first child that ends after `pos`.
1735
- childAfter(pos) {
1736
- return this.enterChild(
1737
- 1,
1738
- pos,
1739
- 2
1740
- /* Side.After */
1741
- );
1742
- }
1743
- /// Move to the last child that starts before `pos`.
1744
- childBefore(pos) {
1745
- return this.enterChild(
1746
- -1,
1747
- pos,
1748
- -2
1749
- /* Side.Before */
1750
- );
1751
- }
1752
- /// Move the cursor to the child around `pos`. If side is -1 the
1753
- /// child may end at that position, when 1 it may start there. This
1754
- /// will also enter [overlaid](#common.MountedTree.overlay)
1755
- /// [mounted](#common.NodeProp^mounted) trees unless `overlays` is
1756
- /// set to false.
1757
- enter(pos, side, mode = this.mode) {
1758
- if (!this.buffer)
1759
- return this.yield(this._tree.enter(pos, side, mode));
1760
- return mode & IterMode.ExcludeBuffers ? false : this.enterChild(1, pos, side);
1761
- }
1762
- /// Move to the node's parent node, if this isn't the top node.
1763
- parent() {
1764
- if (!this.buffer)
1765
- return this.yieldNode(this.mode & IterMode.IncludeAnonymous ? this._tree._parent : this._tree.parent);
1766
- if (this.stack.length)
1767
- return this.yieldBuf(this.stack.pop());
1768
- let parent = this.mode & IterMode.IncludeAnonymous ? this.buffer.parent : this.buffer.parent.nextSignificantParent();
1769
- this.buffer = null;
1770
- return this.yieldNode(parent);
1771
- }
1772
- /// @internal
1773
- sibling(dir) {
1774
- if (!this.buffer)
1775
- return !this._tree._parent ? false : this.yield(this._tree.index < 0 ? null : this._tree._parent.nextChild(this._tree.index + dir, dir, 0, 4, this.mode));
1776
- let { buffer } = this.buffer, d = this.stack.length - 1;
1777
- if (dir < 0) {
1778
- let parentStart = d < 0 ? 0 : this.stack[d] + 4;
1779
- if (this.index != parentStart)
1780
- return this.yieldBuf(buffer.findChild(
1781
- parentStart,
1782
- this.index,
1783
- -1,
1784
- 0,
1785
- 4
1786
- /* Side.DontCare */
1787
- ));
1788
- } else {
1789
- let after = buffer.buffer[this.index + 3];
1790
- if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3]))
1791
- return this.yieldBuf(after);
1792
- }
1793
- return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4, this.mode)) : false;
1794
- }
1795
- /// Move to this node's next sibling, if any.
1796
- nextSibling() {
1797
- return this.sibling(1);
1798
- }
1799
- /// Move to this node's previous sibling, if any.
1800
- prevSibling() {
1801
- return this.sibling(-1);
1802
- }
1803
- atLastNode(dir) {
1804
- let index, parent, { buffer } = this;
1805
- if (buffer) {
1806
- if (dir > 0) {
1807
- if (this.index < buffer.buffer.buffer.length)
1808
- return false;
1809
- } else {
1810
- for (let i = 0; i < this.index; i++)
1811
- if (buffer.buffer.buffer[i + 3] < this.index)
1812
- return false;
1813
- }
1814
- ({ index, parent } = buffer);
1815
- } else {
1816
- ({ index, _parent: parent } = this._tree);
1817
- }
1818
- for (; parent; { index, _parent: parent } = parent) {
1819
- if (index > -1)
1820
- for (let i = index + dir, e = dir < 0 ? -1 : parent._tree.children.length; i != e; i += dir) {
1821
- let child = parent._tree.children[i];
1822
- if (this.mode & IterMode.IncludeAnonymous || child instanceof TreeBuffer || !child.type.isAnonymous || hasChild(child))
1823
- return false;
1824
- }
1825
- }
1826
- return true;
1827
- }
1828
- move(dir, enter) {
1829
- if (enter && this.enterChild(
1830
- dir,
1831
- 0,
1832
- 4
1833
- /* Side.DontCare */
1834
- ))
1835
- return true;
1836
- for (; ; ) {
1837
- if (this.sibling(dir))
1838
- return true;
1839
- if (this.atLastNode(dir) || !this.parent())
1840
- return false;
1841
- }
1842
- }
1843
- /// Move to the next node in a
1844
- /// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
1845
- /// traversal, going from a node to its first child or, if the
1846
- /// current node is empty or `enter` is false, its next sibling or
1847
- /// the next sibling of the first parent node that has one.
1848
- next(enter = true) {
1849
- return this.move(1, enter);
1850
- }
1851
- /// Move to the next node in a last-to-first pre-order traveral. A
1852
- /// node is followed by its last child or, if it has none, its
1853
- /// previous sibling or the previous sibling of the first parent
1854
- /// node that has one.
1855
- prev(enter = true) {
1856
- return this.move(-1, enter);
1857
- }
1858
- /// Move the cursor to the innermost node that covers `pos`. If
1859
- /// `side` is -1, it will enter nodes that end at `pos`. If it is 1,
1860
- /// it will enter nodes that start at `pos`.
1861
- moveTo(pos, side = 0) {
1862
- while (this.from == this.to || (side < 1 ? this.from >= pos : this.from > pos) || (side > -1 ? this.to <= pos : this.to < pos))
1863
- if (!this.parent())
1864
- break;
1865
- while (this.enterChild(1, pos, side)) {
1866
- }
1867
- return this;
1868
- }
1869
- /// Get a [syntax node](#common.SyntaxNode) at the cursor's current
1870
- /// position.
1871
- get node() {
1872
- if (!this.buffer)
1873
- return this._tree;
1874
- let cache = this.bufferNode, result = null, depth = 0;
1875
- if (cache && cache.context == this.buffer) {
1876
- scan:
1877
- for (let index = this.index, d = this.stack.length; d >= 0; ) {
1878
- for (let c = cache; c; c = c._parent)
1879
- if (c.index == index) {
1880
- if (index == this.index)
1881
- return c;
1882
- result = c;
1883
- depth = d + 1;
1884
- break scan;
1885
- }
1886
- index = this.stack[--d];
1887
- }
1888
- }
1889
- for (let i = depth; i < this.stack.length; i++)
1890
- result = new BufferNode(this.buffer, result, this.stack[i]);
1891
- return this.bufferNode = new BufferNode(this.buffer, result, this.index);
1892
- }
1893
- /// Get the [tree](#common.Tree) that represents the current node, if
1894
- /// any. Will return null when the node is in a [tree
1895
- /// buffer](#common.TreeBuffer).
1896
- get tree() {
1897
- return this.buffer ? null : this._tree._tree;
1898
- }
1899
- /// Iterate over the current node and all its descendants, calling
1900
- /// `enter` when entering a node and `leave`, if given, when leaving
1901
- /// one. When `enter` returns `false`, any children of that node are
1902
- /// skipped, and `leave` isn't called for it.
1903
- iterate(enter, leave) {
1904
- for (let depth = 0; ; ) {
1905
- let mustLeave = false;
1906
- if (this.type.isAnonymous || enter(this) !== false) {
1907
- if (this.firstChild()) {
1908
- depth++;
1909
- continue;
1910
- }
1911
- if (!this.type.isAnonymous)
1912
- mustLeave = true;
1913
- }
1914
- for (; ; ) {
1915
- if (mustLeave && leave)
1916
- leave(this);
1917
- mustLeave = this.type.isAnonymous;
1918
- if (this.nextSibling())
1919
- break;
1920
- if (!depth)
1921
- return;
1922
- this.parent();
1923
- depth--;
1924
- mustLeave = true;
1925
- }
1926
- }
1927
- }
1928
- /// Test whether the current node matches a given context—a sequence
1929
- /// of direct parent node names. Empty strings in the context array
1930
- /// are treated as wildcards.
1931
- matchContext(context) {
1932
- if (!this.buffer)
1933
- return matchNodeContext(this.node, context);
1934
- let { buffer } = this.buffer, { types } = buffer.set;
1935
- for (let i = context.length - 1, d = this.stack.length - 1; i >= 0; d--) {
1936
- if (d < 0)
1937
- return matchNodeContext(this.node, context, i);
1938
- let type = types[buffer.buffer[this.stack[d]]];
1939
- if (!type.isAnonymous) {
1940
- if (context[i] && context[i] != type.name)
1941
- return false;
1942
- i--;
1943
- }
1944
- }
1945
- return true;
1946
- }
1947
- };
1948
- function hasChild(tree) {
1949
- return tree.children.some((ch) => ch instanceof TreeBuffer || !ch.type.isAnonymous || hasChild(ch));
1950
- }
1951
- function buildTree(data) {
1952
- var _a;
1953
- let { buffer, nodeSet, maxBufferLength = DefaultBufferLength, reused = [], minRepeatType = nodeSet.types.length } = data;
1954
- let cursor = Array.isArray(buffer) ? new FlatBufferCursor(buffer, buffer.length) : buffer;
1955
- let types = nodeSet.types;
1956
- let contextHash = 0, lookAhead = 0;
1957
- function takeNode(parentStart, minPos, children2, positions2, inRepeat) {
1958
- let { id, start, end, size } = cursor;
1959
- let lookAheadAtStart = lookAhead;
1960
- while (size < 0) {
1961
- cursor.next();
1962
- if (size == -1) {
1963
- let node2 = reused[id];
1964
- children2.push(node2);
1965
- positions2.push(start - parentStart);
1966
- return;
1967
- } else if (size == -3) {
1968
- contextHash = id;
1969
- return;
1970
- } else if (size == -4) {
1971
- lookAhead = id;
1972
- return;
1973
- } else {
1974
- throw new RangeError(`Unrecognized record size: ${size}`);
1975
- }
1976
- }
1977
- let type = types[id], node, buffer2;
1978
- let startPos = start - parentStart;
1979
- if (end - start <= maxBufferLength && (buffer2 = findBufferSize(cursor.pos - minPos, inRepeat))) {
1980
- let data2 = new Uint16Array(buffer2.size - buffer2.skip);
1981
- let endPos = cursor.pos - buffer2.size, index = data2.length;
1982
- while (cursor.pos > endPos)
1983
- index = copyToBuffer(buffer2.start, data2, index);
1984
- node = new TreeBuffer(data2, end - buffer2.start, nodeSet);
1985
- startPos = buffer2.start - parentStart;
1986
- } else {
1987
- let endPos = cursor.pos - size;
1988
- cursor.next();
1989
- let localChildren = [], localPositions = [];
1990
- let localInRepeat = id >= minRepeatType ? id : -1;
1991
- let lastGroup = 0, lastEnd = end;
1992
- while (cursor.pos > endPos) {
1993
- if (localInRepeat >= 0 && cursor.id == localInRepeat && cursor.size >= 0) {
1994
- if (cursor.end <= lastEnd - maxBufferLength) {
1995
- makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart);
1996
- lastGroup = localChildren.length;
1997
- lastEnd = cursor.end;
1998
- }
1999
- cursor.next();
2000
- } else {
2001
- takeNode(start, endPos, localChildren, localPositions, localInRepeat);
2002
- }
2003
- }
2004
- if (localInRepeat >= 0 && lastGroup > 0 && lastGroup < localChildren.length)
2005
- makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart);
2006
- localChildren.reverse();
2007
- localPositions.reverse();
2008
- if (localInRepeat > -1 && lastGroup > 0) {
2009
- let make = makeBalanced(type);
2010
- node = balanceRange(type, localChildren, localPositions, 0, localChildren.length, 0, end - start, make, make);
2011
- } else {
2012
- node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end);
2013
- }
2014
- }
2015
- children2.push(node);
2016
- positions2.push(startPos);
2017
- }
2018
- function makeBalanced(type) {
2019
- return (children2, positions2, length3) => {
2020
- let lookAhead2 = 0, lastI = children2.length - 1, last2, lookAheadProp;
2021
- if (lastI >= 0 && (last2 = children2[lastI]) instanceof Tree) {
2022
- if (!lastI && last2.type == type && last2.length == length3)
2023
- return last2;
2024
- if (lookAheadProp = last2.prop(NodeProp.lookAhead))
2025
- lookAhead2 = positions2[lastI] + last2.length + lookAheadProp;
2026
- }
2027
- return makeTree(type, children2, positions2, length3, lookAhead2);
2028
- };
2029
- }
2030
- function makeRepeatLeaf(children2, positions2, base, i, from, to, type, lookAhead2) {
2031
- let localChildren = [], localPositions = [];
2032
- while (children2.length > i) {
2033
- localChildren.push(children2.pop());
2034
- localPositions.push(positions2.pop() + base - from);
2035
- }
2036
- children2.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead2 - to));
2037
- positions2.push(from - base);
2038
- }
2039
- function makeTree(type, children2, positions2, length3, lookAhead2 = 0, props) {
2040
- if (contextHash) {
2041
- let pair2 = [NodeProp.contextHash, contextHash];
2042
- props = props ? [pair2].concat(props) : [pair2];
2043
- }
2044
- if (lookAhead2 > 25) {
2045
- let pair2 = [NodeProp.lookAhead, lookAhead2];
2046
- props = props ? [pair2].concat(props) : [pair2];
2047
- }
2048
- return new Tree(type, children2, positions2, length3, props);
2049
- }
2050
- function findBufferSize(maxSize, inRepeat) {
2051
- let fork = cursor.fork();
2052
- let size = 0, start = 0, skip = 0, minStart = fork.end - maxBufferLength;
2053
- let result = { size: 0, start: 0, skip: 0 };
2054
- scan:
2055
- for (let minPos = fork.pos - maxSize; fork.pos > minPos; ) {
2056
- let nodeSize2 = fork.size;
2057
- if (fork.id == inRepeat && nodeSize2 >= 0) {
2058
- result.size = size;
2059
- result.start = start;
2060
- result.skip = skip;
2061
- skip += 4;
2062
- size += 4;
2063
- fork.next();
2064
- continue;
2065
- }
2066
- let startPos = fork.pos - nodeSize2;
2067
- if (nodeSize2 < 0 || startPos < minPos || fork.start < minStart)
2068
- break;
2069
- let localSkipped = fork.id >= minRepeatType ? 4 : 0;
2070
- let nodeStart = fork.start;
2071
- fork.next();
2072
- while (fork.pos > startPos) {
2073
- if (fork.size < 0) {
2074
- if (fork.size == -3)
2075
- localSkipped += 4;
2076
- else
2077
- break scan;
2078
- } else if (fork.id >= minRepeatType) {
2079
- localSkipped += 4;
2080
- }
2081
- fork.next();
2082
- }
2083
- start = nodeStart;
2084
- size += nodeSize2;
2085
- skip += localSkipped;
2086
- }
2087
- if (inRepeat < 0 || size == maxSize) {
2088
- result.size = size;
2089
- result.start = start;
2090
- result.skip = skip;
2091
- }
2092
- return result.size > 4 ? result : void 0;
2093
- }
2094
- function copyToBuffer(bufferStart, buffer2, index) {
2095
- let { id, start, end, size } = cursor;
2096
- cursor.next();
2097
- if (size >= 0 && id < minRepeatType) {
2098
- let startIndex = index;
2099
- if (size > 4) {
2100
- let endPos = cursor.pos - (size - 4);
2101
- while (cursor.pos > endPos)
2102
- index = copyToBuffer(bufferStart, buffer2, index);
2103
- }
2104
- buffer2[--index] = startIndex;
2105
- buffer2[--index] = end - bufferStart;
2106
- buffer2[--index] = start - bufferStart;
2107
- buffer2[--index] = id;
2108
- } else if (size == -3) {
2109
- contextHash = id;
2110
- } else if (size == -4) {
2111
- lookAhead = id;
2112
- }
2113
- return index;
2114
- }
2115
- let children = [], positions = [];
2116
- while (cursor.pos > 0)
2117
- takeNode(data.start || 0, data.bufferStart || 0, children, positions, -1);
2118
- let length2 = (_a = data.length) !== null && _a !== void 0 ? _a : children.length ? positions[0] + children[0].length : 0;
2119
- return new Tree(types[data.topID], children.reverse(), positions.reverse(), length2);
2120
- }
2121
- var nodeSizeCache = /* @__PURE__ */ new WeakMap();
2122
- function nodeSize(balanceType, node) {
2123
- if (!balanceType.isAnonymous || node instanceof TreeBuffer || node.type != balanceType)
2124
- return 1;
2125
- let size = nodeSizeCache.get(node);
2126
- if (size == null) {
2127
- size = 1;
2128
- for (let child of node.children) {
2129
- if (child.type != balanceType || !(child instanceof Tree)) {
2130
- size = 1;
2131
- break;
2132
- }
2133
- size += nodeSize(balanceType, child);
2134
- }
2135
- nodeSizeCache.set(node, size);
2136
- }
2137
- return size;
2138
- }
2139
- function balanceRange(balanceType, children, positions, from, to, start, length2, mkTop, mkTree) {
2140
- let total = 0;
2141
- for (let i = from; i < to; i++)
2142
- total += nodeSize(balanceType, children[i]);
2143
- let maxChild = Math.ceil(
2144
- total * 1.5 / 8
2145
- /* Balance.BranchFactor */
2146
- );
2147
- let localChildren = [], localPositions = [];
2148
- function divide(children2, positions2, from2, to2, offset) {
2149
- for (let i = from2; i < to2; ) {
2150
- let groupFrom = i, groupStart = positions2[i], groupSize = nodeSize(balanceType, children2[i]);
2151
- i++;
2152
- for (; i < to2; i++) {
2153
- let nextSize = nodeSize(balanceType, children2[i]);
2154
- if (groupSize + nextSize >= maxChild)
2155
- break;
2156
- groupSize += nextSize;
2157
- }
2158
- if (i == groupFrom + 1) {
2159
- if (groupSize > maxChild) {
2160
- let only = children2[groupFrom];
2161
- divide(only.children, only.positions, 0, only.children.length, positions2[groupFrom] + offset);
2162
- continue;
2163
- }
2164
- localChildren.push(children2[groupFrom]);
2165
- } else {
2166
- let length3 = positions2[i - 1] + children2[i - 1].length - groupStart;
2167
- localChildren.push(balanceRange(balanceType, children2, positions2, groupFrom, i, groupStart, length3, null, mkTree));
2168
- }
2169
- localPositions.push(groupStart + offset - start);
2170
- }
2171
- }
2172
- divide(children, positions, from, to, 0);
2173
- return (mkTop || mkTree)(localChildren, localPositions, length2);
2174
- }
2175
- var Parser = class {
2176
- /// Start a parse, returning a [partial parse](#common.PartialParse)
2177
- /// object. [`fragments`](#common.TreeFragment) can be passed in to
2178
- /// make the parse incremental.
2179
- ///
2180
- /// By default, the entire input is parsed. You can pass `ranges`,
2181
- /// which should be a sorted array of non-empty, non-overlapping
2182
- /// ranges, to parse only those ranges. The tree returned in that
2183
- /// case will start at `ranges[0].from`.
2184
- startParse(input, fragments, ranges) {
2185
- if (typeof input == "string")
2186
- input = new StringInput(input);
2187
- ranges = !ranges ? [new Range(0, input.length)] : ranges.length ? ranges.map((r) => new Range(r.from, r.to)) : [new Range(0, 0)];
2188
- return this.createParse(input, fragments || [], ranges);
2189
- }
2190
- /// Run a full parse, returning the resulting tree.
2191
- parse(input, fragments, ranges) {
2192
- let parse = this.startParse(input, fragments, ranges);
2193
- for (; ; ) {
2194
- let done = parse.advance();
2195
- if (done)
2196
- return done;
2197
- }
2198
- }
2199
- };
2200
- var StringInput = class {
2201
- constructor(string) {
2202
- this.string = string;
2203
- }
2204
- get length() {
2205
- return this.string.length;
2206
- }
2207
- chunk(from) {
2208
- return this.string.slice(from);
2209
- }
2210
- get lineChunks() {
2211
- return false;
2212
- }
2213
- read(from, to) {
2214
- return this.string.slice(from, to);
2215
- }
2216
- };
2217
- var stoppedInner = new NodeProp({ perNode: true });
2218
-
2219
- // ../../node_modules/@lezer/lr/dist/index.js
2220
- var Stack = class _Stack {
2221
- /// @internal
2222
- constructor(p, stack, state, reducePos, pos, score, buffer, bufferBase, curContext, lookAhead = 0, parent) {
2223
- this.p = p;
2224
- this.stack = stack;
2225
- this.state = state;
2226
- this.reducePos = reducePos;
2227
- this.pos = pos;
2228
- this.score = score;
2229
- this.buffer = buffer;
2230
- this.bufferBase = bufferBase;
2231
- this.curContext = curContext;
2232
- this.lookAhead = lookAhead;
2233
- this.parent = parent;
2234
- }
2235
- /// @internal
2236
- toString() {
2237
- return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
2238
- }
2239
- // Start an empty stack
2240
- /// @internal
2241
- static start(p, state, pos = 0) {
2242
- let cx = p.parser.context;
2243
- return new _Stack(p, [], state, pos, pos, 0, [], 0, cx ? new StackContext(cx, cx.start) : null, 0, null);
2244
- }
2245
- /// The stack's current [context](#lr.ContextTracker) value, if
2246
- /// any. Its type will depend on the context tracker's type
2247
- /// parameter, or it will be `null` if there is no context
2248
- /// tracker.
2249
- get context() {
2250
- return this.curContext ? this.curContext.context : null;
2251
- }
2252
- // Push a state onto the stack, tracking its start position as well
2253
- // as the buffer base at that point.
2254
- /// @internal
2255
- pushState(state, start) {
2256
- this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
2257
- this.state = state;
2258
- }
2259
- // Apply a reduce action
2260
- /// @internal
2261
- reduce(action) {
2262
- var _a;
2263
- let depth = action >> 19, type = action & 65535;
2264
- let { parser: parser2 } = this.p;
2265
- let dPrec = parser2.dynamicPrecedence(type);
2266
- if (dPrec)
2267
- this.score += dPrec;
2268
- if (depth == 0) {
2269
- this.pushState(parser2.getGoto(this.state, type, true), this.reducePos);
2270
- if (type < parser2.minRepeatTerm)
2271
- this.storeNode(type, this.reducePos, this.reducePos, 4, true);
2272
- this.reduceContext(type, this.reducePos);
2273
- return;
2274
- }
2275
- let base = this.stack.length - (depth - 1) * 3 - (action & 262144 ? 6 : 0);
2276
- let start = base ? this.stack[base - 2] : this.p.ranges[0].from, size = this.reducePos - start;
2277
- if (size >= 2e3 && !((_a = this.p.parser.nodeSet.types[type]) === null || _a === void 0 ? void 0 : _a.isAnonymous)) {
2278
- if (start == this.p.lastBigReductionStart) {
2279
- this.p.bigReductionCount++;
2280
- this.p.lastBigReductionSize = size;
2281
- } else if (this.p.lastBigReductionSize < size) {
2282
- this.p.bigReductionCount = 1;
2283
- this.p.lastBigReductionStart = start;
2284
- this.p.lastBigReductionSize = size;
2285
- }
2286
- }
2287
- let bufferBase = base ? this.stack[base - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase;
2288
- if (type < parser2.minRepeatTerm || action & 131072) {
2289
- let pos = parser2.stateFlag(
2290
- this.state,
2291
- 1
2292
- /* StateFlag.Skipped */
2293
- ) ? this.pos : this.reducePos;
2294
- this.storeNode(type, start, pos, count + 4, true);
2295
- }
2296
- if (action & 262144) {
2297
- this.state = this.stack[base];
2298
- } else {
2299
- let baseStateID = this.stack[base - 3];
2300
- this.state = parser2.getGoto(baseStateID, type, true);
2301
- }
2302
- while (this.stack.length > base)
2303
- this.stack.pop();
2304
- this.reduceContext(type, start);
2305
- }
2306
- // Shift a value into the buffer
2307
- /// @internal
2308
- storeNode(term, start, end, size = 4, isReduce = false) {
2309
- if (term == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
2310
- let cur = this, top = this.buffer.length;
2311
- if (top == 0 && cur.parent) {
2312
- top = cur.bufferBase - cur.parent.bufferBase;
2313
- cur = cur.parent;
2314
- }
2315
- if (top > 0 && cur.buffer[top - 4] == 0 && cur.buffer[top - 1] > -1) {
2316
- if (start == end)
2317
- return;
2318
- if (cur.buffer[top - 2] >= start) {
2319
- cur.buffer[top - 2] = end;
2320
- return;
2321
- }
2322
- }
2323
- }
2324
- if (!isReduce || this.pos == end) {
2325
- this.buffer.push(term, start, end, size);
2326
- } else {
2327
- let index = this.buffer.length;
2328
- if (index > 0 && this.buffer[index - 4] != 0)
2329
- while (index > 0 && this.buffer[index - 2] > end) {
2330
- this.buffer[index] = this.buffer[index - 4];
2331
- this.buffer[index + 1] = this.buffer[index - 3];
2332
- this.buffer[index + 2] = this.buffer[index - 2];
2333
- this.buffer[index + 3] = this.buffer[index - 1];
2334
- index -= 4;
2335
- if (size > 4)
2336
- size -= 4;
2337
- }
2338
- this.buffer[index] = term;
2339
- this.buffer[index + 1] = start;
2340
- this.buffer[index + 2] = end;
2341
- this.buffer[index + 3] = size;
2342
- }
2343
- }
2344
- // Apply a shift action
2345
- /// @internal
2346
- shift(action, next, nextEnd) {
2347
- let start = this.pos;
2348
- if (action & 131072) {
2349
- this.pushState(action & 65535, this.pos);
2350
- } else if ((action & 262144) == 0) {
2351
- let nextState = action, { parser: parser2 } = this.p;
2352
- if (nextEnd > this.pos || next <= parser2.maxNode) {
2353
- this.pos = nextEnd;
2354
- if (!parser2.stateFlag(
2355
- nextState,
2356
- 1
2357
- /* StateFlag.Skipped */
2358
- ))
2359
- this.reducePos = nextEnd;
2360
- }
2361
- this.pushState(nextState, start);
2362
- this.shiftContext(next, start);
2363
- if (next <= parser2.maxNode)
2364
- this.buffer.push(next, start, nextEnd, 4);
2365
- } else {
2366
- this.pos = nextEnd;
2367
- this.shiftContext(next, start);
2368
- if (next <= this.p.parser.maxNode)
2369
- this.buffer.push(next, start, nextEnd, 4);
2370
- }
2371
- }
2372
- // Apply an action
2373
- /// @internal
2374
- apply(action, next, nextEnd) {
2375
- if (action & 65536)
2376
- this.reduce(action);
2377
- else
2378
- this.shift(action, next, nextEnd);
2379
- }
2380
- // Add a prebuilt (reused) node into the buffer.
2381
- /// @internal
2382
- useNode(value, next) {
2383
- let index = this.p.reused.length - 1;
2384
- if (index < 0 || this.p.reused[index] != value) {
2385
- this.p.reused.push(value);
2386
- index++;
2387
- }
2388
- let start = this.pos;
2389
- this.reducePos = this.pos = start + value.length;
2390
- this.pushState(next, start);
2391
- this.buffer.push(
2392
- index,
2393
- start,
2394
- this.reducePos,
2395
- -1
2396
- /* size == -1 means this is a reused value */
2397
- );
2398
- if (this.curContext)
2399
- this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length)));
2400
- }
2401
- // Split the stack. Due to the buffer sharing and the fact
2402
- // that `this.stack` tends to stay quite shallow, this isn't very
2403
- // expensive.
2404
- /// @internal
2405
- split() {
2406
- let parent = this;
2407
- let off = parent.buffer.length;
2408
- while (off > 0 && parent.buffer[off - 2] > parent.reducePos)
2409
- off -= 4;
2410
- let buffer = parent.buffer.slice(off), base = parent.bufferBase + off;
2411
- while (parent && base == parent.bufferBase)
2412
- parent = parent.parent;
2413
- return new _Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
2414
- }
2415
- // Try to recover from an error by 'deleting' (ignoring) one token.
2416
- /// @internal
2417
- recoverByDelete(next, nextEnd) {
2418
- let isNode = next <= this.p.parser.maxNode;
2419
- if (isNode)
2420
- this.storeNode(next, this.pos, nextEnd, 4);
2421
- this.storeNode(0, this.pos, nextEnd, isNode ? 8 : 4);
2422
- this.pos = this.reducePos = nextEnd;
2423
- this.score -= 190;
2424
- }
2425
- /// Check if the given term would be able to be shifted (optionally
2426
- /// after some reductions) on this stack. This can be useful for
2427
- /// external tokenizers that want to make sure they only provide a
2428
- /// given token when it applies.
2429
- canShift(term) {
2430
- for (let sim = new SimulatedStack(this); ; ) {
2431
- let action = this.p.parser.stateSlot(
2432
- sim.state,
2433
- 4
2434
- /* ParseState.DefaultReduce */
2435
- ) || this.p.parser.hasAction(sim.state, term);
2436
- if (action == 0)
2437
- return false;
2438
- if ((action & 65536) == 0)
2439
- return true;
2440
- sim.reduce(action);
2441
- }
2442
- }
2443
- // Apply up to Recover.MaxNext recovery actions that conceptually
2444
- // inserts some missing token or rule.
2445
- /// @internal
2446
- recoverByInsert(next) {
2447
- if (this.stack.length >= 300)
2448
- return [];
2449
- let nextStates = this.p.parser.nextStates(this.state);
2450
- if (nextStates.length > 4 << 1 || this.stack.length >= 120) {
2451
- let best = [];
2452
- for (let i = 0, s; i < nextStates.length; i += 2) {
2453
- if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next))
2454
- best.push(nextStates[i], s);
2455
- }
2456
- if (this.stack.length < 120)
2457
- for (let i = 0; best.length < 4 << 1 && i < nextStates.length; i += 2) {
2458
- let s = nextStates[i + 1];
2459
- if (!best.some((v, i2) => i2 & 1 && v == s))
2460
- best.push(nextStates[i], s);
2461
- }
2462
- nextStates = best;
2463
- }
2464
- let result = [];
2465
- for (let i = 0; i < nextStates.length && result.length < 4; i += 2) {
2466
- let s = nextStates[i + 1];
2467
- if (s == this.state)
2468
- continue;
2469
- let stack = this.split();
2470
- stack.pushState(s, this.pos);
2471
- stack.storeNode(0, stack.pos, stack.pos, 4, true);
2472
- stack.shiftContext(nextStates[i], this.pos);
2473
- stack.score -= 200;
2474
- result.push(stack);
2475
- }
2476
- return result;
2477
- }
2478
- // Force a reduce, if possible. Return false if that can't
2479
- // be done.
2480
- /// @internal
2481
- forceReduce() {
2482
- let { parser: parser2 } = this.p;
2483
- let reduce = parser2.stateSlot(
2484
- this.state,
2485
- 5
2486
- /* ParseState.ForcedReduce */
2487
- );
2488
- if ((reduce & 65536) == 0)
2489
- return false;
2490
- if (!parser2.validAction(this.state, reduce)) {
2491
- let depth = reduce >> 19, term = reduce & 65535;
2492
- let target = this.stack.length - depth * 3;
2493
- if (target < 0 || parser2.getGoto(this.stack[target], term, false) < 0) {
2494
- let backup = this.findForcedReduction();
2495
- if (backup == null)
2496
- return false;
2497
- reduce = backup;
2498
- }
2499
- this.storeNode(0, this.pos, this.pos, 4, true);
2500
- this.score -= 100;
2501
- }
2502
- this.reducePos = this.pos;
2503
- this.reduce(reduce);
2504
- return true;
2505
- }
2506
- /// Try to scan through the automaton to find some kind of reduction
2507
- /// that can be applied. Used when the regular ForcedReduce field
2508
- /// isn't a valid action. @internal
2509
- findForcedReduction() {
2510
- let { parser: parser2 } = this.p, seen = [];
2511
- let explore = (state, depth) => {
2512
- if (seen.includes(state))
2513
- return;
2514
- seen.push(state);
2515
- return parser2.allActions(state, (action) => {
2516
- if (action & (262144 | 131072))
2517
- ;
2518
- else if (action & 65536) {
2519
- let rDepth = (action >> 19) - depth;
2520
- if (rDepth > 1) {
2521
- let term = action & 65535, target = this.stack.length - rDepth * 3;
2522
- if (target >= 0 && parser2.getGoto(this.stack[target], term, false) >= 0)
2523
- return rDepth << 19 | 65536 | term;
2524
- }
2525
- } else {
2526
- let found = explore(action, depth + 1);
2527
- if (found != null)
2528
- return found;
2529
- }
2530
- });
2531
- };
2532
- return explore(this.state, 0);
2533
- }
2534
- /// @internal
2535
- forceAll() {
2536
- while (!this.p.parser.stateFlag(
2537
- this.state,
2538
- 2
2539
- /* StateFlag.Accepting */
2540
- )) {
2541
- if (!this.forceReduce()) {
2542
- this.storeNode(0, this.pos, this.pos, 4, true);
2543
- break;
2544
- }
2545
- }
2546
- return this;
2547
- }
2548
- /// Check whether this state has no further actions (assumed to be a direct descendant of the
2549
- /// top state, since any other states must be able to continue
2550
- /// somehow). @internal
2551
- get deadEnd() {
2552
- if (this.stack.length != 3)
2553
- return false;
2554
- let { parser: parser2 } = this.p;
2555
- return parser2.data[parser2.stateSlot(
2556
- this.state,
2557
- 1
2558
- /* ParseState.Actions */
2559
- )] == 65535 && !parser2.stateSlot(
2560
- this.state,
2561
- 4
2562
- /* ParseState.DefaultReduce */
2563
- );
2564
- }
2565
- /// Restart the stack (put it back in its start state). Only safe
2566
- /// when this.stack.length == 3 (state is directly below the top
2567
- /// state). @internal
2568
- restart() {
2569
- this.state = this.stack[0];
2570
- this.stack.length = 0;
2571
- }
2572
- /// @internal
2573
- sameState(other) {
2574
- if (this.state != other.state || this.stack.length != other.stack.length)
2575
- return false;
2576
- for (let i = 0; i < this.stack.length; i += 3)
2577
- if (this.stack[i] != other.stack[i])
2578
- return false;
2579
- return true;
2580
- }
2581
- /// Get the parser used by this stack.
2582
- get parser() {
2583
- return this.p.parser;
2584
- }
2585
- /// Test whether a given dialect (by numeric ID, as exported from
2586
- /// the terms file) is enabled.
2587
- dialectEnabled(dialectID) {
2588
- return this.p.parser.dialect.flags[dialectID];
2589
- }
2590
- shiftContext(term, start) {
2591
- if (this.curContext)
2592
- this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start)));
2593
- }
2594
- reduceContext(term, start) {
2595
- if (this.curContext)
2596
- this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start)));
2597
- }
2598
- /// @internal
2599
- emitContext() {
2600
- let last2 = this.buffer.length - 1;
2601
- if (last2 < 0 || this.buffer[last2] != -3)
2602
- this.buffer.push(this.curContext.hash, this.pos, this.pos, -3);
2603
- }
2604
- /// @internal
2605
- emitLookAhead() {
2606
- let last2 = this.buffer.length - 1;
2607
- if (last2 < 0 || this.buffer[last2] != -4)
2608
- this.buffer.push(this.lookAhead, this.pos, this.pos, -4);
2609
- }
2610
- updateContext(context) {
2611
- if (context != this.curContext.context) {
2612
- let newCx = new StackContext(this.curContext.tracker, context);
2613
- if (newCx.hash != this.curContext.hash)
2614
- this.emitContext();
2615
- this.curContext = newCx;
2616
- }
2617
- }
2618
- /// @internal
2619
- setLookAhead(lookAhead) {
2620
- if (lookAhead > this.lookAhead) {
2621
- this.emitLookAhead();
2622
- this.lookAhead = lookAhead;
2623
- }
2624
- }
2625
- /// @internal
2626
- close() {
2627
- if (this.curContext && this.curContext.tracker.strict)
2628
- this.emitContext();
2629
- if (this.lookAhead > 0)
2630
- this.emitLookAhead();
2631
- }
2632
- };
2633
- var StackContext = class {
2634
- constructor(tracker, context) {
2635
- this.tracker = tracker;
2636
- this.context = context;
2637
- this.hash = tracker.strict ? tracker.hash(context) : 0;
2638
- }
2639
- };
2640
- var Recover;
2641
- (function(Recover2) {
2642
- Recover2[Recover2["Insert"] = 200] = "Insert";
2643
- Recover2[Recover2["Delete"] = 190] = "Delete";
2644
- Recover2[Recover2["Reduce"] = 100] = "Reduce";
2645
- Recover2[Recover2["MaxNext"] = 4] = "MaxNext";
2646
- Recover2[Recover2["MaxInsertStackDepth"] = 300] = "MaxInsertStackDepth";
2647
- Recover2[Recover2["DampenInsertStackDepth"] = 120] = "DampenInsertStackDepth";
2648
- Recover2[Recover2["MinBigReduction"] = 2e3] = "MinBigReduction";
2649
- })(Recover || (Recover = {}));
2650
- var SimulatedStack = class {
2651
- constructor(start) {
2652
- this.start = start;
2653
- this.state = start.state;
2654
- this.stack = start.stack;
2655
- this.base = this.stack.length;
2656
- }
2657
- reduce(action) {
2658
- let term = action & 65535, depth = action >> 19;
2659
- if (depth == 0) {
2660
- if (this.stack == this.start.stack)
2661
- this.stack = this.stack.slice();
2662
- this.stack.push(this.state, 0, 0);
2663
- this.base += 3;
2664
- } else {
2665
- this.base -= (depth - 1) * 3;
2666
- }
2667
- let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true);
2668
- this.state = goto;
2669
- }
2670
- };
2671
- var StackBufferCursor = class _StackBufferCursor {
2672
- constructor(stack, pos, index) {
2673
- this.stack = stack;
2674
- this.pos = pos;
2675
- this.index = index;
2676
- this.buffer = stack.buffer;
2677
- if (this.index == 0)
2678
- this.maybeNext();
2679
- }
2680
- static create(stack, pos = stack.bufferBase + stack.buffer.length) {
2681
- return new _StackBufferCursor(stack, pos, pos - stack.bufferBase);
2682
- }
2683
- maybeNext() {
2684
- let next = this.stack.parent;
2685
- if (next != null) {
2686
- this.index = this.stack.bufferBase - next.bufferBase;
2687
- this.stack = next;
2688
- this.buffer = next.buffer;
2689
- }
2690
- }
2691
- get id() {
2692
- return this.buffer[this.index - 4];
2693
- }
2694
- get start() {
2695
- return this.buffer[this.index - 3];
2696
- }
2697
- get end() {
2698
- return this.buffer[this.index - 2];
2699
- }
2700
- get size() {
2701
- return this.buffer[this.index - 1];
2702
- }
2703
- next() {
2704
- this.index -= 4;
2705
- this.pos -= 4;
2706
- if (this.index == 0)
2707
- this.maybeNext();
2708
- }
2709
- fork() {
2710
- return new _StackBufferCursor(this.stack, this.pos, this.index);
2711
- }
2712
- };
2713
- function decodeArray(input, Type = Uint16Array) {
2714
- if (typeof input != "string")
2715
- return input;
2716
- let array = null;
2717
- for (let pos = 0, out = 0; pos < input.length; ) {
2718
- let value = 0;
2719
- for (; ; ) {
2720
- let next = input.charCodeAt(pos++), stop = false;
2721
- if (next == 126) {
2722
- value = 65535;
2723
- break;
2724
- }
2725
- if (next >= 92)
2726
- next--;
2727
- if (next >= 34)
2728
- next--;
2729
- let digit = next - 32;
2730
- if (digit >= 46) {
2731
- digit -= 46;
2732
- stop = true;
2733
- }
2734
- value += digit;
2735
- if (stop)
2736
- break;
2737
- value *= 46;
2738
- }
2739
- if (array)
2740
- array[out++] = value;
2741
- else
2742
- array = new Type(value);
2743
- }
2744
- return array;
2745
- }
2746
- var CachedToken = class {
2747
- constructor() {
2748
- this.start = -1;
2749
- this.value = -1;
2750
- this.end = -1;
2751
- this.extended = -1;
2752
- this.lookAhead = 0;
2753
- this.mask = 0;
2754
- this.context = 0;
2755
- }
2756
- };
2757
- var nullToken = new CachedToken();
2758
- var InputStream = class {
2759
- /// @internal
2760
- constructor(input, ranges) {
2761
- this.input = input;
2762
- this.ranges = ranges;
2763
- this.chunk = "";
2764
- this.chunkOff = 0;
2765
- this.chunk2 = "";
2766
- this.chunk2Pos = 0;
2767
- this.next = -1;
2768
- this.token = nullToken;
2769
- this.rangeIndex = 0;
2770
- this.pos = this.chunkPos = ranges[0].from;
2771
- this.range = ranges[0];
2772
- this.end = ranges[ranges.length - 1].to;
2773
- this.readNext();
2774
- }
2775
- /// @internal
2776
- resolveOffset(offset, assoc) {
2777
- let range = this.range, index = this.rangeIndex;
2778
- let pos = this.pos + offset;
2779
- while (pos < range.from) {
2780
- if (!index)
2781
- return null;
2782
- let next = this.ranges[--index];
2783
- pos -= range.from - next.to;
2784
- range = next;
2785
- }
2786
- while (assoc < 0 ? pos > range.to : pos >= range.to) {
2787
- if (index == this.ranges.length - 1)
2788
- return null;
2789
- let next = this.ranges[++index];
2790
- pos += next.from - range.to;
2791
- range = next;
2792
- }
2793
- return pos;
2794
- }
2795
- /// @internal
2796
- clipPos(pos) {
2797
- if (pos >= this.range.from && pos < this.range.to)
2798
- return pos;
2799
- for (let range of this.ranges)
2800
- if (range.to > pos)
2801
- return Math.max(pos, range.from);
2802
- return this.end;
2803
- }
2804
- /// Look at a code unit near the stream position. `.peek(0)` equals
2805
- /// `.next`, `.peek(-1)` gives you the previous character, and so
2806
- /// on.
2807
- ///
2808
- /// Note that looking around during tokenizing creates dependencies
2809
- /// on potentially far-away content, which may reduce the
2810
- /// effectiveness incremental parsing—when looking forward—or even
2811
- /// cause invalid reparses when looking backward more than 25 code
2812
- /// units, since the library does not track lookbehind.
2813
- peek(offset) {
2814
- let idx = this.chunkOff + offset, pos, result;
2815
- if (idx >= 0 && idx < this.chunk.length) {
2816
- pos = this.pos + offset;
2817
- result = this.chunk.charCodeAt(idx);
2818
- } else {
2819
- let resolved = this.resolveOffset(offset, 1);
2820
- if (resolved == null)
2821
- return -1;
2822
- pos = resolved;
2823
- if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) {
2824
- result = this.chunk2.charCodeAt(pos - this.chunk2Pos);
2825
- } else {
2826
- let i = this.rangeIndex, range = this.range;
2827
- while (range.to <= pos)
2828
- range = this.ranges[++i];
2829
- this.chunk2 = this.input.chunk(this.chunk2Pos = pos);
2830
- if (pos + this.chunk2.length > range.to)
2831
- this.chunk2 = this.chunk2.slice(0, range.to - pos);
2832
- result = this.chunk2.charCodeAt(0);
2833
- }
2834
- }
2835
- if (pos >= this.token.lookAhead)
2836
- this.token.lookAhead = pos + 1;
2837
- return result;
2838
- }
2839
- /// Accept a token. By default, the end of the token is set to the
2840
- /// current stream position, but you can pass an offset (relative to
2841
- /// the stream position) to change that.
2842
- acceptToken(token, endOffset = 0) {
2843
- let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos;
2844
- if (end == null || end < this.token.start)
2845
- throw new RangeError("Token end out of bounds");
2846
- this.token.value = token;
2847
- this.token.end = end;
2848
- }
2849
- getChunk() {
2850
- if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
2851
- let { chunk, chunkPos } = this;
2852
- this.chunk = this.chunk2;
2853
- this.chunkPos = this.chunk2Pos;
2854
- this.chunk2 = chunk;
2855
- this.chunk2Pos = chunkPos;
2856
- this.chunkOff = this.pos - this.chunkPos;
2857
- } else {
2858
- this.chunk2 = this.chunk;
2859
- this.chunk2Pos = this.chunkPos;
2860
- let nextChunk = this.input.chunk(this.pos);
2861
- let end = this.pos + nextChunk.length;
2862
- this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk;
2863
- this.chunkPos = this.pos;
2864
- this.chunkOff = 0;
2865
- }
2866
- }
2867
- readNext() {
2868
- if (this.chunkOff >= this.chunk.length) {
2869
- this.getChunk();
2870
- if (this.chunkOff == this.chunk.length)
2871
- return this.next = -1;
2872
- }
2873
- return this.next = this.chunk.charCodeAt(this.chunkOff);
2874
- }
2875
- /// Move the stream forward N (defaults to 1) code units. Returns
2876
- /// the new value of [`next`](#lr.InputStream.next).
2877
- advance(n = 1) {
2878
- this.chunkOff += n;
2879
- while (this.pos + n >= this.range.to) {
2880
- if (this.rangeIndex == this.ranges.length - 1)
2881
- return this.setDone();
2882
- n -= this.range.to - this.pos;
2883
- this.range = this.ranges[++this.rangeIndex];
2884
- this.pos = this.range.from;
2885
- }
2886
- this.pos += n;
2887
- if (this.pos >= this.token.lookAhead)
2888
- this.token.lookAhead = this.pos + 1;
2889
- return this.readNext();
2890
- }
2891
- setDone() {
2892
- this.pos = this.chunkPos = this.end;
2893
- this.range = this.ranges[this.rangeIndex = this.ranges.length - 1];
2894
- this.chunk = "";
2895
- return this.next = -1;
2896
- }
2897
- /// @internal
2898
- reset(pos, token) {
2899
- if (token) {
2900
- this.token = token;
2901
- token.start = pos;
2902
- token.lookAhead = pos + 1;
2903
- token.value = token.extended = -1;
2904
- } else {
2905
- this.token = nullToken;
2906
- }
2907
- if (this.pos != pos) {
2908
- this.pos = pos;
2909
- if (pos == this.end) {
2910
- this.setDone();
2911
- return this;
2912
- }
2913
- while (pos < this.range.from)
2914
- this.range = this.ranges[--this.rangeIndex];
2915
- while (pos >= this.range.to)
2916
- this.range = this.ranges[++this.rangeIndex];
2917
- if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) {
2918
- this.chunkOff = pos - this.chunkPos;
2919
- } else {
2920
- this.chunk = "";
2921
- this.chunkOff = 0;
2922
- }
2923
- this.readNext();
2924
- }
2925
- return this;
2926
- }
2927
- /// @internal
2928
- read(from, to) {
2929
- if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length)
2930
- return this.chunk.slice(from - this.chunkPos, to - this.chunkPos);
2931
- if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length)
2932
- return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos);
2933
- if (from >= this.range.from && to <= this.range.to)
2934
- return this.input.read(from, to);
2935
- let result = "";
2936
- for (let r of this.ranges) {
2937
- if (r.from >= to)
2938
- break;
2939
- if (r.to > from)
2940
- result += this.input.read(Math.max(r.from, from), Math.min(r.to, to));
2941
- }
2942
- return result;
2943
- }
2944
- };
2945
- var TokenGroup = class {
2946
- constructor(data, id) {
2947
- this.data = data;
2948
- this.id = id;
2949
- }
2950
- token(input, stack) {
2951
- let { parser: parser2 } = stack.p;
2952
- readToken(this.data, input, stack, this.id, parser2.data, parser2.tokenPrecTable);
2953
- }
2954
- };
2955
- TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
2956
- var LocalTokenGroup = class {
2957
- constructor(data, precTable, elseToken) {
2958
- this.precTable = precTable;
2959
- this.elseToken = elseToken;
2960
- this.data = typeof data == "string" ? decodeArray(data) : data;
2961
- }
2962
- token(input, stack) {
2963
- let start = input.pos, skipped = 0;
2964
- for (; ; ) {
2965
- let atEof = input.next < 0, nextPos = input.resolveOffset(1, 1);
2966
- readToken(this.data, input, stack, 0, this.data, this.precTable);
2967
- if (input.token.value > -1)
2968
- break;
2969
- if (this.elseToken == null)
2970
- return;
2971
- if (!atEof)
2972
- skipped++;
2973
- if (nextPos == null)
2974
- break;
2975
- input.reset(nextPos, input.token);
2976
- }
2977
- if (skipped) {
2978
- input.reset(start, input.token);
2979
- input.acceptToken(this.elseToken, skipped);
2980
- }
2981
- }
2982
- };
2983
- LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
2984
- function readToken(data, input, stack, group, precTable, precOffset) {
2985
- let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser;
2986
- scan:
2987
- for (; ; ) {
2988
- if ((groupMask & data[state]) == 0)
2989
- break;
2990
- let accEnd = data[state + 1];
2991
- for (let i = state + 3; i < accEnd; i += 2)
2992
- if ((data[i + 1] & groupMask) > 0) {
2993
- let term = data[i];
2994
- if (dialect.allows(term) && (input.token.value == -1 || input.token.value == term || overrides(term, input.token.value, precTable, precOffset))) {
2995
- input.acceptToken(term);
2996
- break;
2997
- }
2998
- }
2999
- let next = input.next, low = 0, high = data[state + 2];
3000
- if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535 && data[accEnd + high * 3 - 3] == 65535) {
3001
- state = data[accEnd + high * 3 - 1];
3002
- continue scan;
3003
- }
3004
- for (; low < high; ) {
3005
- let mid = low + high >> 1;
3006
- let index = accEnd + mid + (mid << 1);
3007
- let from = data[index], to = data[index + 1] || 65536;
3008
- if (next < from)
3009
- high = mid;
3010
- else if (next >= to)
3011
- low = mid + 1;
3012
- else {
3013
- state = data[index + 2];
3014
- input.advance();
3015
- continue scan;
3016
- }
3017
- }
3018
- break;
3019
- }
3020
- }
3021
- function findOffset(data, start, term) {
3022
- for (let i = start, next; (next = data[i]) != 65535; i++)
3023
- if (next == term)
3024
- return i - start;
3025
- return -1;
3026
- }
3027
- function overrides(token, prev, tableData, tableOffset) {
3028
- let iPrev = findOffset(tableData, tableOffset, prev);
3029
- return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
3030
- }
3031
- var verbose = typeof process != "undefined" && process.env && /\bparse\b/.test(process.env.LOG);
3032
- var stackIDs = null;
3033
- var Safety;
3034
- (function(Safety2) {
3035
- Safety2[Safety2["Margin"] = 25] = "Margin";
3036
- })(Safety || (Safety = {}));
3037
- function cutAt(tree, pos, side) {
3038
- let cursor = tree.cursor(IterMode.IncludeAnonymous);
3039
- cursor.moveTo(pos);
3040
- for (; ; ) {
3041
- if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos)))
3042
- for (; ; ) {
3043
- if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError)
3044
- return side < 0 ? Math.max(0, Math.min(
3045
- cursor.to - 1,
3046
- pos - 25
3047
- /* Safety.Margin */
3048
- )) : Math.min(tree.length, Math.max(
3049
- cursor.from + 1,
3050
- pos + 25
3051
- /* Safety.Margin */
3052
- ));
3053
- if (side < 0 ? cursor.prevSibling() : cursor.nextSibling())
3054
- break;
3055
- if (!cursor.parent())
3056
- return side < 0 ? 0 : tree.length;
3057
- }
3058
- }
3059
- }
3060
- var FragmentCursor = class {
3061
- constructor(fragments, nodeSet) {
3062
- this.fragments = fragments;
3063
- this.nodeSet = nodeSet;
3064
- this.i = 0;
3065
- this.fragment = null;
3066
- this.safeFrom = -1;
3067
- this.safeTo = -1;
3068
- this.trees = [];
3069
- this.start = [];
3070
- this.index = [];
3071
- this.nextFragment();
3072
- }
3073
- nextFragment() {
3074
- let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
3075
- if (fr) {
3076
- this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
3077
- this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
3078
- while (this.trees.length) {
3079
- this.trees.pop();
3080
- this.start.pop();
3081
- this.index.pop();
3082
- }
3083
- this.trees.push(fr.tree);
3084
- this.start.push(-fr.offset);
3085
- this.index.push(0);
3086
- this.nextStart = this.safeFrom;
3087
- } else {
3088
- this.nextStart = 1e9;
3089
- }
3090
- }
3091
- // `pos` must be >= any previously given `pos` for this cursor
3092
- nodeAt(pos) {
3093
- if (pos < this.nextStart)
3094
- return null;
3095
- while (this.fragment && this.safeTo <= pos)
3096
- this.nextFragment();
3097
- if (!this.fragment)
3098
- return null;
3099
- for (; ; ) {
3100
- let last2 = this.trees.length - 1;
3101
- if (last2 < 0) {
3102
- this.nextFragment();
3103
- return null;
3104
- }
3105
- let top = this.trees[last2], index = this.index[last2];
3106
- if (index == top.children.length) {
3107
- this.trees.pop();
3108
- this.start.pop();
3109
- this.index.pop();
3110
- continue;
3111
- }
3112
- let next = top.children[index];
3113
- let start = this.start[last2] + top.positions[index];
3114
- if (start > pos) {
3115
- this.nextStart = start;
3116
- return null;
3117
- }
3118
- if (next instanceof Tree) {
3119
- if (start == pos) {
3120
- if (start < this.safeFrom)
3121
- return null;
3122
- let end = start + next.length;
3123
- if (end <= this.safeTo) {
3124
- let lookAhead = next.prop(NodeProp.lookAhead);
3125
- if (!lookAhead || end + lookAhead < this.fragment.to)
3126
- return next;
3127
- }
3128
- }
3129
- this.index[last2]++;
3130
- if (start + next.length >= Math.max(this.safeFrom, pos)) {
3131
- this.trees.push(next);
3132
- this.start.push(start);
3133
- this.index.push(0);
3134
- }
3135
- } else {
3136
- this.index[last2]++;
3137
- this.nextStart = start + next.length;
3138
- }
3139
- }
3140
- }
3141
- };
3142
- var TokenCache = class {
3143
- constructor(parser2, stream) {
3144
- this.stream = stream;
3145
- this.tokens = [];
3146
- this.mainToken = null;
3147
- this.actions = [];
3148
- this.tokens = parser2.tokenizers.map((_) => new CachedToken());
3149
- }
3150
- getActions(stack) {
3151
- let actionIndex = 0;
3152
- let main = null;
3153
- let { parser: parser2 } = stack.p, { tokenizers } = parser2;
3154
- let mask = parser2.stateSlot(
3155
- stack.state,
3156
- 3
3157
- /* ParseState.TokenizerMask */
3158
- );
3159
- let context = stack.curContext ? stack.curContext.hash : 0;
3160
- let lookAhead = 0;
3161
- for (let i = 0; i < tokenizers.length; i++) {
3162
- if ((1 << i & mask) == 0)
3163
- continue;
3164
- let tokenizer = tokenizers[i], token = this.tokens[i];
3165
- if (main && !tokenizer.fallback)
3166
- continue;
3167
- if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
3168
- this.updateCachedToken(token, tokenizer, stack);
3169
- token.mask = mask;
3170
- token.context = context;
3171
- }
3172
- if (token.lookAhead > token.end + 25)
3173
- lookAhead = Math.max(token.lookAhead, lookAhead);
3174
- if (token.value != 0) {
3175
- let startIndex = actionIndex;
3176
- if (token.extended > -1)
3177
- actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
3178
- actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
3179
- if (!tokenizer.extend) {
3180
- main = token;
3181
- if (actionIndex > startIndex)
3182
- break;
3183
- }
3184
- }
3185
- }
3186
- while (this.actions.length > actionIndex)
3187
- this.actions.pop();
3188
- if (lookAhead)
3189
- stack.setLookAhead(lookAhead);
3190
- if (!main && stack.pos == this.stream.end) {
3191
- main = new CachedToken();
3192
- main.value = stack.p.parser.eofTerm;
3193
- main.start = main.end = stack.pos;
3194
- actionIndex = this.addActions(stack, main.value, main.end, actionIndex);
3195
- }
3196
- this.mainToken = main;
3197
- return this.actions;
3198
- }
3199
- getMainToken(stack) {
3200
- if (this.mainToken)
3201
- return this.mainToken;
3202
- let main = new CachedToken(), { pos, p } = stack;
3203
- main.start = pos;
3204
- main.end = Math.min(pos + 1, p.stream.end);
3205
- main.value = pos == p.stream.end ? p.parser.eofTerm : 0;
3206
- return main;
3207
- }
3208
- updateCachedToken(token, tokenizer, stack) {
3209
- let start = this.stream.clipPos(stack.pos);
3210
- tokenizer.token(this.stream.reset(start, token), stack);
3211
- if (token.value > -1) {
3212
- let { parser: parser2 } = stack.p;
3213
- for (let i = 0; i < parser2.specialized.length; i++)
3214
- if (parser2.specialized[i] == token.value) {
3215
- let result = parser2.specializers[i](this.stream.read(token.start, token.end), stack);
3216
- if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) {
3217
- if ((result & 1) == 0)
3218
- token.value = result >> 1;
3219
- else
3220
- token.extended = result >> 1;
3221
- break;
3222
- }
3223
- }
3224
- } else {
3225
- token.value = 0;
3226
- token.end = this.stream.clipPos(start + 1);
3227
- }
3228
- }
3229
- putAction(action, token, end, index) {
3230
- for (let i = 0; i < index; i += 3)
3231
- if (this.actions[i] == action)
3232
- return index;
3233
- this.actions[index++] = action;
3234
- this.actions[index++] = token;
3235
- this.actions[index++] = end;
3236
- return index;
3237
- }
3238
- addActions(stack, token, end, index) {
3239
- let { state } = stack, { parser: parser2 } = stack.p, { data } = parser2;
3240
- for (let set = 0; set < 2; set++) {
3241
- for (let i = parser2.stateSlot(
3242
- state,
3243
- set ? 2 : 1
3244
- /* ParseState.Actions */
3245
- ); ; i += 3) {
3246
- if (data[i] == 65535) {
3247
- if (data[i + 1] == 1) {
3248
- i = pair(data, i + 2);
3249
- } else {
3250
- if (index == 0 && data[i + 1] == 2)
3251
- index = this.putAction(pair(data, i + 2), token, end, index);
3252
- break;
3253
- }
3254
- }
3255
- if (data[i] == token)
3256
- index = this.putAction(pair(data, i + 1), token, end, index);
3257
- }
3258
- }
3259
- return index;
3260
- }
3261
- };
3262
- var Rec;
3263
- (function(Rec2) {
3264
- Rec2[Rec2["Distance"] = 5] = "Distance";
3265
- Rec2[Rec2["MaxRemainingPerStep"] = 3] = "MaxRemainingPerStep";
3266
- Rec2[Rec2["MinBufferLengthPrune"] = 500] = "MinBufferLengthPrune";
3267
- Rec2[Rec2["ForceReduceLimit"] = 10] = "ForceReduceLimit";
3268
- Rec2[Rec2["CutDepth"] = 15e3] = "CutDepth";
3269
- Rec2[Rec2["CutTo"] = 9e3] = "CutTo";
3270
- Rec2[Rec2["MaxLeftAssociativeReductionCount"] = 300] = "MaxLeftAssociativeReductionCount";
3271
- Rec2[Rec2["MaxStackCount"] = 12] = "MaxStackCount";
3272
- })(Rec || (Rec = {}));
3273
- var Parse = class {
3274
- constructor(parser2, input, fragments, ranges) {
3275
- this.parser = parser2;
3276
- this.input = input;
3277
- this.ranges = ranges;
3278
- this.recovering = 0;
3279
- this.nextStackID = 9812;
3280
- this.minStackPos = 0;
3281
- this.reused = [];
3282
- this.stoppedAt = null;
3283
- this.lastBigReductionStart = -1;
3284
- this.lastBigReductionSize = 0;
3285
- this.bigReductionCount = 0;
3286
- this.stream = new InputStream(input, ranges);
3287
- this.tokens = new TokenCache(parser2, this.stream);
3288
- this.topTerm = parser2.top[1];
3289
- let { from } = ranges[0];
3290
- this.stacks = [Stack.start(this, parser2.top[0], from)];
3291
- this.fragments = fragments.length && this.stream.end - from > parser2.bufferLength * 4 ? new FragmentCursor(fragments, parser2.nodeSet) : null;
3292
- }
3293
- get parsedPos() {
3294
- return this.minStackPos;
3295
- }
3296
- // Move the parser forward. This will process all parse stacks at
3297
- // `this.pos` and try to advance them to a further position. If no
3298
- // stack for such a position is found, it'll start error-recovery.
3299
- //
3300
- // When the parse is finished, this will return a syntax tree. When
3301
- // not, it returns `null`.
3302
- advance() {
3303
- let stacks = this.stacks, pos = this.minStackPos;
3304
- let newStacks = this.stacks = [];
3305
- let stopped, stoppedTokens;
3306
- if (this.bigReductionCount > 300 && stacks.length == 1) {
3307
- let [s] = stacks;
3308
- while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart) {
3309
- }
3310
- this.bigReductionCount = this.lastBigReductionSize = 0;
3311
- }
3312
- for (let i = 0; i < stacks.length; i++) {
3313
- let stack = stacks[i];
3314
- for (; ; ) {
3315
- this.tokens.mainToken = null;
3316
- if (stack.pos > pos) {
3317
- newStacks.push(stack);
3318
- } else if (this.advanceStack(stack, newStacks, stacks)) {
3319
- continue;
3320
- } else {
3321
- if (!stopped) {
3322
- stopped = [];
3323
- stoppedTokens = [];
3324
- }
3325
- stopped.push(stack);
3326
- let tok = this.tokens.getMainToken(stack);
3327
- stoppedTokens.push(tok.value, tok.end);
3328
- }
3329
- break;
3330
- }
3331
- }
3332
- if (!newStacks.length) {
3333
- let finished = stopped && findFinished(stopped);
3334
- if (finished)
3335
- return this.stackToTree(finished);
3336
- if (this.parser.strict) {
3337
- if (verbose && stopped)
3338
- console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none"));
3339
- throw new SyntaxError("No parse at " + pos);
3340
- }
3341
- if (!this.recovering)
3342
- this.recovering = 5;
3343
- }
3344
- if (this.recovering && stopped) {
3345
- let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] : this.runRecovery(stopped, stoppedTokens, newStacks);
3346
- if (finished)
3347
- return this.stackToTree(finished.forceAll());
3348
- }
3349
- if (this.recovering) {
3350
- let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3;
3351
- if (newStacks.length > maxRemaining) {
3352
- newStacks.sort((a, b) => b.score - a.score);
3353
- while (newStacks.length > maxRemaining)
3354
- newStacks.pop();
3355
- }
3356
- if (newStacks.some((s) => s.reducePos > pos))
3357
- this.recovering--;
3358
- } else if (newStacks.length > 1) {
3359
- outer:
3360
- for (let i = 0; i < newStacks.length - 1; i++) {
3361
- let stack = newStacks[i];
3362
- for (let j = i + 1; j < newStacks.length; j++) {
3363
- let other = newStacks[j];
3364
- if (stack.sameState(other) || stack.buffer.length > 500 && other.buffer.length > 500) {
3365
- if ((stack.score - other.score || stack.buffer.length - other.buffer.length) > 0) {
3366
- newStacks.splice(j--, 1);
3367
- } else {
3368
- newStacks.splice(i--, 1);
3369
- continue outer;
3370
- }
3371
- }
3372
- }
3373
- }
3374
- if (newStacks.length > 12)
3375
- newStacks.splice(
3376
- 12,
3377
- newStacks.length - 12
3378
- /* Rec.MaxStackCount */
3379
- );
3380
- }
3381
- this.minStackPos = newStacks[0].pos;
3382
- for (let i = 1; i < newStacks.length; i++)
3383
- if (newStacks[i].pos < this.minStackPos)
3384
- this.minStackPos = newStacks[i].pos;
3385
- return null;
3386
- }
3387
- stopAt(pos) {
3388
- if (this.stoppedAt != null && this.stoppedAt < pos)
3389
- throw new RangeError("Can't move stoppedAt forward");
3390
- this.stoppedAt = pos;
3391
- }
3392
- // Returns an updated version of the given stack, or null if the
3393
- // stack can't advance normally. When `split` and `stacks` are
3394
- // given, stacks split off by ambiguous operations will be pushed to
3395
- // `split`, or added to `stacks` if they move `pos` forward.
3396
- advanceStack(stack, stacks, split) {
3397
- let start = stack.pos, { parser: parser2 } = this;
3398
- let base = verbose ? this.stackID(stack) + " -> " : "";
3399
- if (this.stoppedAt != null && start > this.stoppedAt)
3400
- return stack.forceReduce() ? stack : null;
3401
- if (this.fragments) {
3402
- let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
3403
- for (let cached = this.fragments.nodeAt(start); cached; ) {
3404
- let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser2.getGoto(stack.state, cached.type.id) : -1;
3405
- if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) {
3406
- stack.useNode(cached, match);
3407
- if (verbose)
3408
- console.log(base + this.stackID(stack) + ` (via reuse of ${parser2.getName(cached.type.id)})`);
3409
- return true;
3410
- }
3411
- if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0)
3412
- break;
3413
- let inner = cached.children[0];
3414
- if (inner instanceof Tree && cached.positions[0] == 0)
3415
- cached = inner;
3416
- else
3417
- break;
3418
- }
3419
- }
3420
- let defaultReduce = parser2.stateSlot(
3421
- stack.state,
3422
- 4
3423
- /* ParseState.DefaultReduce */
3424
- );
3425
- if (defaultReduce > 0) {
3426
- stack.reduce(defaultReduce);
3427
- if (verbose)
3428
- console.log(base + this.stackID(stack) + ` (via always-reduce ${parser2.getName(
3429
- defaultReduce & 65535
3430
- /* Action.ValueMask */
3431
- )})`);
3432
- return true;
3433
- }
3434
- if (stack.stack.length >= 15e3) {
3435
- while (stack.stack.length > 9e3 && stack.forceReduce()) {
3436
- }
3437
- }
3438
- let actions = this.tokens.getActions(stack);
3439
- for (let i = 0; i < actions.length; ) {
3440
- let action = actions[i++], term = actions[i++], end = actions[i++];
3441
- let last2 = i == actions.length || !split;
3442
- let localStack = last2 ? stack : stack.split();
3443
- localStack.apply(action, term, end);
3444
- if (verbose)
3445
- console.log(base + this.stackID(localStack) + ` (via ${(action & 65536) == 0 ? "shift" : `reduce of ${parser2.getName(
3446
- action & 65535
3447
- /* Action.ValueMask */
3448
- )}`} for ${parser2.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
3449
- if (last2)
3450
- return true;
3451
- else if (localStack.pos > start)
3452
- stacks.push(localStack);
3453
- else
3454
- split.push(localStack);
3455
- }
3456
- return false;
3457
- }
3458
- // Advance a given stack forward as far as it will go. Returns the
3459
- // (possibly updated) stack if it got stuck, or null if it moved
3460
- // forward and was given to `pushStackDedup`.
3461
- advanceFully(stack, newStacks) {
3462
- let pos = stack.pos;
3463
- for (; ; ) {
3464
- if (!this.advanceStack(stack, null, null))
3465
- return false;
3466
- if (stack.pos > pos) {
3467
- pushStackDedup(stack, newStacks);
3468
- return true;
3469
- }
3470
- }
3471
- }
3472
- runRecovery(stacks, tokens, newStacks) {
3473
- let finished = null, restarted = false;
3474
- for (let i = 0; i < stacks.length; i++) {
3475
- let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1];
3476
- let base = verbose ? this.stackID(stack) + " -> " : "";
3477
- if (stack.deadEnd) {
3478
- if (restarted)
3479
- continue;
3480
- restarted = true;
3481
- stack.restart();
3482
- if (verbose)
3483
- console.log(base + this.stackID(stack) + " (restarted)");
3484
- let done = this.advanceFully(stack, newStacks);
3485
- if (done)
3486
- continue;
3487
- }
3488
- let force = stack.split(), forceBase = base;
3489
- for (let j = 0; force.forceReduce() && j < 10; j++) {
3490
- if (verbose)
3491
- console.log(forceBase + this.stackID(force) + " (via force-reduce)");
3492
- let done = this.advanceFully(force, newStacks);
3493
- if (done)
3494
- break;
3495
- if (verbose)
3496
- forceBase = this.stackID(force) + " -> ";
3497
- }
3498
- for (let insert of stack.recoverByInsert(token)) {
3499
- if (verbose)
3500
- console.log(base + this.stackID(insert) + " (via recover-insert)");
3501
- this.advanceFully(insert, newStacks);
3502
- }
3503
- if (this.stream.end > stack.pos) {
3504
- if (tokenEnd == stack.pos) {
3505
- tokenEnd++;
3506
- token = 0;
3507
- }
3508
- stack.recoverByDelete(token, tokenEnd);
3509
- if (verbose)
3510
- console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
3511
- pushStackDedup(stack, newStacks);
3512
- } else if (!finished || finished.score < stack.score) {
3513
- finished = stack;
3514
- }
3515
- }
3516
- return finished;
3517
- }
3518
- // Convert the stack's buffer to a syntax tree.
3519
- stackToTree(stack) {
3520
- stack.close();
3521
- return Tree.build({
3522
- buffer: StackBufferCursor.create(stack),
3523
- nodeSet: this.parser.nodeSet,
3524
- topID: this.topTerm,
3525
- maxBufferLength: this.parser.bufferLength,
3526
- reused: this.reused,
3527
- start: this.ranges[0].from,
3528
- length: stack.pos - this.ranges[0].from,
3529
- minRepeatType: this.parser.minRepeatTerm
3530
- });
3531
- }
3532
- stackID(stack) {
3533
- let id = (stackIDs || (stackIDs = /* @__PURE__ */ new WeakMap())).get(stack);
3534
- if (!id)
3535
- stackIDs.set(stack, id = String.fromCodePoint(this.nextStackID++));
3536
- return id + stack;
3537
- }
3538
- };
3539
- function pushStackDedup(stack, newStacks) {
3540
- for (let i = 0; i < newStacks.length; i++) {
3541
- let other = newStacks[i];
3542
- if (other.pos == stack.pos && other.sameState(stack)) {
3543
- if (newStacks[i].score < stack.score)
3544
- newStacks[i] = stack;
3545
- return;
3546
- }
3547
- }
3548
- newStacks.push(stack);
3549
- }
3550
- var Dialect = class {
3551
- constructor(source, flags, disabled) {
3552
- this.source = source;
3553
- this.flags = flags;
3554
- this.disabled = disabled;
3555
- }
3556
- allows(term) {
3557
- return !this.disabled || this.disabled[term] == 0;
3558
- }
3559
- };
3560
- var LRParser = class _LRParser extends Parser {
3561
- /// @internal
3562
- constructor(spec) {
3563
- super();
3564
- this.wrappers = [];
3565
- if (spec.version != 14)
3566
- throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14})`);
3567
- let nodeNames = spec.nodeNames.split(" ");
3568
- this.minRepeatTerm = nodeNames.length;
3569
- for (let i = 0; i < spec.repeatNodeCount; i++)
3570
- nodeNames.push("");
3571
- let topTerms = Object.keys(spec.topRules).map((r) => spec.topRules[r][1]);
3572
- let nodeProps = [];
3573
- for (let i = 0; i < nodeNames.length; i++)
3574
- nodeProps.push([]);
3575
- function setProp(nodeID, prop, value) {
3576
- nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
3577
- }
3578
- if (spec.nodeProps)
3579
- for (let propSpec of spec.nodeProps) {
3580
- let prop = propSpec[0];
3581
- if (typeof prop == "string")
3582
- prop = NodeProp[prop];
3583
- for (let i = 1; i < propSpec.length; ) {
3584
- let next = propSpec[i++];
3585
- if (next >= 0) {
3586
- setProp(next, prop, propSpec[i++]);
3587
- } else {
3588
- let value = propSpec[i + -next];
3589
- for (let j = -next; j > 0; j--)
3590
- setProp(propSpec[i++], prop, value);
3591
- i++;
3592
- }
3593
- }
3594
- }
3595
- this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({
3596
- name: i >= this.minRepeatTerm ? void 0 : name,
3597
- id: i,
3598
- props: nodeProps[i],
3599
- top: topTerms.indexOf(i) > -1,
3600
- error: i == 0,
3601
- skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1
3602
- })));
3603
- if (spec.propSources)
3604
- this.nodeSet = this.nodeSet.extend(...spec.propSources);
3605
- this.strict = false;
3606
- this.bufferLength = DefaultBufferLength;
3607
- let tokenArray = decodeArray(spec.tokenData);
3608
- this.context = spec.context;
3609
- this.specializerSpecs = spec.specialized || [];
3610
- this.specialized = new Uint16Array(this.specializerSpecs.length);
3611
- for (let i = 0; i < this.specializerSpecs.length; i++)
3612
- this.specialized[i] = this.specializerSpecs[i].term;
3613
- this.specializers = this.specializerSpecs.map(getSpecializer);
3614
- this.states = decodeArray(spec.states, Uint32Array);
3615
- this.data = decodeArray(spec.stateData);
3616
- this.goto = decodeArray(spec.goto);
3617
- this.maxTerm = spec.maxTerm;
3618
- this.tokenizers = spec.tokenizers.map((value) => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
3619
- this.topRules = spec.topRules;
3620
- this.dialects = spec.dialects || {};
3621
- this.dynamicPrecedences = spec.dynamicPrecedences || null;
3622
- this.tokenPrecTable = spec.tokenPrec;
3623
- this.termNames = spec.termNames || null;
3624
- this.maxNode = this.nodeSet.types.length - 1;
3625
- this.dialect = this.parseDialect();
3626
- this.top = this.topRules[Object.keys(this.topRules)[0]];
3627
- }
3628
- createParse(input, fragments, ranges) {
3629
- let parse = new Parse(this, input, fragments, ranges);
3630
- for (let w of this.wrappers)
3631
- parse = w(parse, input, fragments, ranges);
3632
- return parse;
3633
- }
3634
- /// Get a goto table entry @internal
3635
- getGoto(state, term, loose = false) {
3636
- let table = this.goto;
3637
- if (term >= table[0])
3638
- return -1;
3639
- for (let pos = table[term + 1]; ; ) {
3640
- let groupTag = table[pos++], last2 = groupTag & 1;
3641
- let target = table[pos++];
3642
- if (last2 && loose)
3643
- return target;
3644
- for (let end = pos + (groupTag >> 1); pos < end; pos++)
3645
- if (table[pos] == state)
3646
- return target;
3647
- if (last2)
3648
- return -1;
3649
- }
3650
- }
3651
- /// Check if this state has an action for a given terminal @internal
3652
- hasAction(state, terminal) {
3653
- let data = this.data;
3654
- for (let set = 0; set < 2; set++) {
3655
- for (let i = this.stateSlot(
3656
- state,
3657
- set ? 2 : 1
3658
- /* ParseState.Actions */
3659
- ), next; ; i += 3) {
3660
- if ((next = data[i]) == 65535) {
3661
- if (data[i + 1] == 1)
3662
- next = data[i = pair(data, i + 2)];
3663
- else if (data[i + 1] == 2)
3664
- return pair(data, i + 2);
3665
- else
3666
- break;
3667
- }
3668
- if (next == terminal || next == 0)
3669
- return pair(data, i + 1);
3670
- }
3671
- }
3672
- return 0;
3673
- }
3674
- /// @internal
3675
- stateSlot(state, slot) {
3676
- return this.states[state * 6 + slot];
3677
- }
3678
- /// @internal
3679
- stateFlag(state, flag) {
3680
- return (this.stateSlot(
3681
- state,
3682
- 0
3683
- /* ParseState.Flags */
3684
- ) & flag) > 0;
3685
- }
3686
- /// @internal
3687
- validAction(state, action) {
3688
- return !!this.allActions(state, (a) => a == action ? true : null);
3689
- }
3690
- /// @internal
3691
- allActions(state, action) {
3692
- let deflt = this.stateSlot(
3693
- state,
3694
- 4
3695
- /* ParseState.DefaultReduce */
3696
- );
3697
- let result = deflt ? action(deflt) : void 0;
3698
- for (let i = this.stateSlot(
3699
- state,
3700
- 1
3701
- /* ParseState.Actions */
3702
- ); result == null; i += 3) {
3703
- if (this.data[i] == 65535) {
3704
- if (this.data[i + 1] == 1)
3705
- i = pair(this.data, i + 2);
3706
- else
3707
- break;
3708
- }
3709
- result = action(pair(this.data, i + 1));
3710
- }
3711
- return result;
3712
- }
3713
- /// Get the states that can follow this one through shift actions or
3714
- /// goto jumps. @internal
3715
- nextStates(state) {
3716
- let result = [];
3717
- for (let i = this.stateSlot(
3718
- state,
3719
- 1
3720
- /* ParseState.Actions */
3721
- ); ; i += 3) {
3722
- if (this.data[i] == 65535) {
3723
- if (this.data[i + 1] == 1)
3724
- i = pair(this.data, i + 2);
3725
- else
3726
- break;
3727
- }
3728
- if ((this.data[i + 2] & 65536 >> 16) == 0) {
3729
- let value = this.data[i + 1];
3730
- if (!result.some((v, i2) => i2 & 1 && v == value))
3731
- result.push(this.data[i], value);
3732
- }
3733
- }
3734
- return result;
3735
- }
3736
- /// Configure the parser. Returns a new parser instance that has the
3737
- /// given settings modified. Settings not provided in `config` are
3738
- /// kept from the original parser.
3739
- configure(config) {
3740
- let copy = Object.assign(Object.create(_LRParser.prototype), this);
3741
- if (config.props)
3742
- copy.nodeSet = this.nodeSet.extend(...config.props);
3743
- if (config.top) {
3744
- let info = this.topRules[config.top];
3745
- if (!info)
3746
- throw new RangeError(`Invalid top rule name ${config.top}`);
3747
- copy.top = info;
3748
- }
3749
- if (config.tokenizers)
3750
- copy.tokenizers = this.tokenizers.map((t) => {
3751
- let found = config.tokenizers.find((r) => r.from == t);
3752
- return found ? found.to : t;
3753
- });
3754
- if (config.specializers) {
3755
- copy.specializers = this.specializers.slice();
3756
- copy.specializerSpecs = this.specializerSpecs.map((s, i) => {
3757
- let found = config.specializers.find((r) => r.from == s.external);
3758
- if (!found)
3759
- return s;
3760
- let spec = Object.assign(Object.assign({}, s), { external: found.to });
3761
- copy.specializers[i] = getSpecializer(spec);
3762
- return spec;
3763
- });
3764
- }
3765
- if (config.contextTracker)
3766
- copy.context = config.contextTracker;
3767
- if (config.dialect)
3768
- copy.dialect = this.parseDialect(config.dialect);
3769
- if (config.strict != null)
3770
- copy.strict = config.strict;
3771
- if (config.wrap)
3772
- copy.wrappers = copy.wrappers.concat(config.wrap);
3773
- if (config.bufferLength != null)
3774
- copy.bufferLength = config.bufferLength;
3775
- return copy;
3776
- }
3777
- /// Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
3778
- /// are registered for this parser.
3779
- hasWrappers() {
3780
- return this.wrappers.length > 0;
3781
- }
3782
- /// Returns the name associated with a given term. This will only
3783
- /// work for all terms when the parser was generated with the
3784
- /// `--names` option. By default, only the names of tagged terms are
3785
- /// stored.
3786
- getName(term) {
3787
- return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
3788
- }
3789
- /// The eof term id is always allocated directly after the node
3790
- /// types. @internal
3791
- get eofTerm() {
3792
- return this.maxNode + 1;
3793
- }
3794
- /// The type of top node produced by the parser.
3795
- get topNode() {
3796
- return this.nodeSet.types[this.top[1]];
3797
- }
3798
- /// @internal
3799
- dynamicPrecedence(term) {
3800
- let prec = this.dynamicPrecedences;
3801
- return prec == null ? 0 : prec[term] || 0;
3802
- }
3803
- /// @internal
3804
- parseDialect(dialect) {
3805
- let values = Object.keys(this.dialects), flags = values.map(() => false);
3806
- if (dialect)
3807
- for (let part of dialect.split(" ")) {
3808
- let id = values.indexOf(part);
3809
- if (id >= 0)
3810
- flags[id] = true;
3811
- }
3812
- let disabled = null;
3813
- for (let i = 0; i < values.length; i++)
3814
- if (!flags[i]) {
3815
- for (let j = this.dialects[values[i]], id; (id = this.data[j++]) != 65535; )
3816
- (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id] = 1;
3817
- }
3818
- return new Dialect(dialect, flags, disabled);
3819
- }
3820
- /// Used by the output of the parser generator. Not available to
3821
- /// user code. @hide
3822
- static deserialize(spec) {
3823
- return new _LRParser(spec);
3824
- }
3825
- };
3826
- function pair(data, off) {
3827
- return data[off] | data[off + 1] << 16;
3828
- }
3829
- function findFinished(stacks) {
3830
- let best = null;
3831
- for (let stack of stacks) {
3832
- let stopped = stack.p.stoppedAt;
3833
- if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && stack.p.parser.stateFlag(
3834
- stack.state,
3835
- 2
3836
- /* StateFlag.Accepting */
3837
- ) && (!best || best.score < stack.score))
3838
- best = stack;
3839
- }
3840
- return best;
3841
- }
3842
- function getSpecializer(spec) {
3843
- if (spec.external) {
3844
- let mask = spec.extend ? 1 : 0;
3845
- return (value, stack) => spec.external(value, stack) << 1 | mask;
3846
- }
3847
- return spec.get;
3848
- }
3849
-
3850
- // ../vuu-filter-parser/src/generated/filter-parser.js
3851
- var parser = LRParser.deserialize({
3852
- version: 14,
3853
- states: "%QOVQPOOOOQO'#C_'#C_O_QQO'#C^OOQO'#DO'#DOOvQQO'#C|OOQO'#DR'#DROVQPO'#CuOOQO'#C}'#C}QOQPOOOOQO'#C`'#C`O!UQQO,58xO!dQPO,59VOVQPO,59]OVQPO,59_O!iQPO,59hO!nQQO,59aOOQO'#DQ'#DQOOQO1G.d1G.dO!UQQO1G.qO!yQQO1G.wOOQO1G.y1G.yOOQO'#Cw'#CwOOQO1G/S1G/SOOQO1G.{1G.{O#[QPO'#CnO#dQPO7+$]O!UQQO'#CxO#iQPO,59YOOQO<<Gw<<GwOOQO,59d,59dOOQO-E6v-E6v",
3854
- stateData: "#q~OoOS~OsPOvUO~OTXOUXOVXOWXOXXOYXO`ZO~Of[Oh]Oj^OmpX~OZ`O[`O]`O^`O~OabO~OseO~Of[Oh]OwgO~Oh]Ofeijeimeiwei~OcjOdbX~OdlO~OcjOdba~O",
3855
- goto: "#YvPPw}!TPPPPPPPPPPwPP!WPP!ZP!ZP!aP!g!jPPP!p!s!aP#P!aXROU[]XQOU[]RYQRibXTOU[]XVOU[]Rf^QkhRnkRWOQSOQ_UQc[Rd]QaYQhbRmj",
3856
- nodeNames: "\u26A0 Filter ColumnValueExpression Column Operator Eq NotEq Gt Lt Starts Ends Number String True False ColumnSetExpression In LBrack Values Comma RBrack AndExpression And OrExpression Or ParenthesizedExpression As FilterName",
3857
- maxTerm: 39,
3858
- skippedNodes: [0],
3859
- repeatNodeCount: 1,
3860
- tokenData: "6p~RnXY#PYZ#P]^#Ppq#Pqr#brs#mxy$eyz$j|}$o!O!P$t!Q![%S!^!_%_!_!`%d!`!a%i!c!}%n!}#O&V#P#Q&[#R#S%n#T#U&a#U#X%n#X#Y(w#Y#Z+]#Z#]%n#]#^.]#^#c%n#c#d/e#d#g%n#g#h0m#h#i4[#i#o%n~#USo~XY#PYZ#P]^#Ppq#P~#eP!_!`#h~#mOU~~#pWOX#mZ]#m^r#mrs$Ys#O#m#P;'S#m;'S;=`$_<%lO#m~$_O[~~$bP;=`<%l#m~$jOv~~$oOw~~$tOc~~$wP!Q![$z~%PPZ~!Q![$z~%XQZ~!O!P$t!Q![%S~%dOW~~%iOT~~%nOV~P%sUsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n~&[Oa~~&aOd~R&fYsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c'U#c#g%n#g#h(^#h#o%nR'ZWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X's#X#o%nR'zUfQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(eUjQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR(|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c)f#c#o%nR)kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#W%n#W#X*T#X#o%nR*YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h*r#h#o%nR*yUYQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR+bVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U+w#U#o%nR+|WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#`%n#`#a,f#a#o%nR,kWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h-T#h#o%nR-YWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y-r#Y#o%nR-yU^QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR.bWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#b%n#b#c.z#c#o%nR/RU`QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR/jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g0S#g#o%nR0ZUhQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR0rWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i1[#i#o%nR1aVsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#U1v#U#o%nR1{WsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g2e#g#o%nR2jWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#h%n#h#i3S#i#o%nR3XWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#g%n#g#h3q#h#o%nR3xUXQsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%nR4aWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#f%n#f#g4y#g#o%nR5OWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#i%n#i#j5h#j#o%nR5mWsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#X%n#X#Y6V#Y#o%nR6^U]QsP}!O%n!O!P%n!Q![%n!c!}%n#R#S%n#T#o%n",
3861
- tokenizers: [0, 1],
3862
- topRules: { "Filter": [0, 1] },
3863
- tokenPrec: 0
3864
- });
3865
-
3866
- // ../vuu-utils/src/array-utils.ts
3867
- var getAddedItems = (values, newValues) => {
3868
- const isNew = (v) => !(values == null ? void 0 : values.includes(v));
3869
- if (values === void 0) {
3870
- return newValues;
3871
- } else if (newValues.some(isNew)) {
3872
- return newValues.filter(isNew);
3873
- } else {
3874
- return [];
3875
- }
3876
- };
3877
- var getMissingItems = (sourceItems, items, identity) => items.filter((i) => sourceItems.findIndex((s) => identity(s) === i) === -1);
3878
-
3879
- // ../vuu-utils/src/filter-utils.ts
3880
- var singleValueFilterOps = /* @__PURE__ */ new Set([
3881
- "=",
3882
- "!=",
3883
- ">",
3884
- ">=",
3885
- "<",
3886
- "<=",
3887
- "starts",
3888
- "ends"
3889
- ]);
3890
- var isSingleValueFilter = (f) => f !== void 0 && singleValueFilterOps.has(f.op);
3891
- var isMultiValueFilter = (f) => f !== void 0 && f.op === "in";
3892
- function isMultiClauseFilter(f) {
3893
- return f !== void 0 && (f.op === "and" || f.op === "or");
3894
- }
3895
-
3896
- // ../vuu-utils/src/column-utils.ts
3897
- var isKeyedColumn = (column) => {
3898
- return typeof column.key === "number";
3899
- };
3900
- var EMPTY_COLUMN_MAP = {};
3901
- function buildColumnMap(columns) {
3902
- const start = metadataKeys.count;
3903
- if (columns) {
3904
- return columns.reduce((map, column, i) => {
3905
- if (typeof column === "string") {
3906
- map[column] = start + i;
3907
- } else if (isKeyedColumn(column)) {
3908
- map[column.name] = column.key;
3909
- } else {
3910
- map[column.name] = start + i;
3911
- }
3912
- return map;
3913
- }, {});
3914
- } else {
3915
- return EMPTY_COLUMN_MAP;
3916
- }
3917
- }
3918
- var metadataKeys = {
3919
- IDX: 0,
3920
- RENDER_IDX: 1,
3921
- IS_LEAF: 2,
3922
- IS_EXPANDED: 3,
3923
- DEPTH: 4,
3924
- COUNT: 5,
3925
- KEY: 6,
3926
- SELECTED: 7,
3927
- count: 8,
3928
- // TODO following only used in datamodel
3929
- PARENT_IDX: "parent_idx",
3930
- IDX_POINTER: "idx_pointer",
3931
- FILTER_COUNT: "filter_count",
3932
- NEXT_FILTER_IDX: "next_filter_idx"
3933
- };
3934
- var { DEPTH, IS_LEAF } = metadataKeys;
3935
-
3936
- // ../vuu-utils/src/cookie-utils.ts
3937
- var getCookieValue = (name) => {
3938
- var _a, _b;
3939
- if (((_a = globalThis.document) == null ? void 0 : _a.cookie) !== void 0) {
3940
- return (_b = globalThis.document.cookie.split("; ").find((row) => row.startsWith(`${name}=`))) == null ? void 0 : _b.split("=")[1];
3941
- }
3942
- };
3943
-
3944
- // ../vuu-utils/src/range-utils.ts
3945
- var NULL_RANGE = { from: 0, to: 0 };
3946
- function resetRange({ from, to, bufferSize = 0 }) {
3947
- return {
3948
- from: 0,
3949
- to: to - from,
3950
- bufferSize,
3951
- reset: true
3952
- };
3953
- }
3954
- var rangeNewItems = ({ from: from1, to: to1 }, newRange) => {
3955
- const { from: from2, to: to2 } = newRange;
3956
- const noOverlap = from2 >= to1 || to2 <= from1;
3957
- const newFullySubsumesOld = from2 < from1 && to2 > to1;
3958
- return noOverlap || newFullySubsumesOld ? newRange : to2 > to1 ? { from: to1, to: to2 } : { from: from2, to: from1 };
3959
- };
3960
-
3961
- // ../vuu-utils/src/datasource-utils.ts
3962
- var NoFilter = { filter: "" };
3963
- var NoSort = { sortDefs: [] };
3964
- var vanillaConfig = {
3965
- aggregations: [],
3966
- columns: [],
3967
- filter: NoFilter,
3968
- groupBy: [],
3969
- sort: NoSort
3970
- };
3971
- var equivalentAggregations = ({ aggregations: agg1 }, { aggregations: agg2 }) => agg1 === void 0 && (agg2 == null ? void 0 : agg2.length) === 0 || agg2 === void 0 && (agg1 == null ? void 0 : agg1.length) === 0;
3972
- var equivalentColumns = ({ columns: cols1 }, { columns: cols2 }) => cols1 === void 0 && (cols2 == null ? void 0 : cols2.length) === 0 || cols2 === void 0 && (cols1 == null ? void 0 : cols1.length) === 0;
3973
- var equivalentFilter = ({ filter: f1 }, { filter: f2 }) => f1 === void 0 && (f2 == null ? void 0 : f2.filter) === "" || f2 === void 0 && (f1 == null ? void 0 : f1.filter) === "";
3974
- var equivalentGroupBy = ({ groupBy: val1 }, { groupBy: val2 }) => val1 === void 0 && (val2 == null ? void 0 : val2.length) === 0 || val2 === void 0 && (val1 == null ? void 0 : val1.length) === 0;
3975
- var equivalentSort = ({ sort: s1 }, { sort: s2 }) => s1 === void 0 && (s2 == null ? void 0 : s2.sortDefs.length) === 0 || s2 === void 0 && (s1 == null ? void 0 : s1.sortDefs.length) === 0;
3976
- var exactlyTheSame = (a, b) => {
3977
- if (a === b) {
3978
- return true;
3979
- } else if (a === void 0 && b === void 0) {
3980
- return true;
3981
- } else {
3982
- return false;
3983
- }
3984
- };
3985
- var aggregationsChanged = (config, newConfig) => {
3986
- const { aggregations: agg1 } = config;
3987
- const { aggregations: agg2 } = newConfig;
3988
- if (exactlyTheSame(agg1, agg2) || equivalentAggregations(config, newConfig)) {
3989
- return false;
3990
- } else if (agg1 === void 0 || agg2 === void 0) {
3991
- return true;
3992
- } else if (agg1.length !== agg2.length) {
3993
- return true;
3994
- }
3995
- return agg1.some(
3996
- ({ column, aggType }, i) => column !== agg2[i].column || aggType !== agg2[i].aggType
3997
- );
3998
- };
3999
- var columnsChanged = (config, newConfig) => {
4000
- const { columns: cols1 } = config;
4001
- const { columns: cols2 } = newConfig;
4002
- if (exactlyTheSame(cols1, cols2) || equivalentColumns(config, newConfig)) {
4003
- return false;
4004
- } else if (cols1 === void 0 || cols2 === void 0) {
4005
- return true;
4006
- } else if ((cols1 == null ? void 0 : cols1.length) !== (cols2 == null ? void 0 : cols2.length)) {
4007
- return true;
4008
- }
4009
- return cols1.some((column, i) => column !== (cols2 == null ? void 0 : cols2[i]));
4010
- };
4011
- var filterChanged = (c1, c2) => {
4012
- var _a, _b;
4013
- if (equivalentFilter(c1, c2)) {
4014
- return false;
4015
- } else {
4016
- return ((_a = c1.filter) == null ? void 0 : _a.filter) !== ((_b = c2.filter) == null ? void 0 : _b.filter);
4017
- }
4018
- };
4019
- var groupByChanged = (config, newConfig) => {
4020
- const { groupBy: g1 } = config;
4021
- const { groupBy: g2 } = newConfig;
4022
- if (exactlyTheSame(g1, g2) || equivalentGroupBy(config, newConfig)) {
4023
- return false;
4024
- } else if (g1 === void 0 || g2 === void 0) {
4025
- return true;
4026
- } else if ((g1 == null ? void 0 : g1.length) !== (g2 == null ? void 0 : g2.length)) {
4027
- return true;
4028
- }
4029
- return g1.some((column, i) => column !== (g2 == null ? void 0 : g2[i]));
4030
- };
4031
- var sortChanged = (config, newConfig) => {
4032
- const { sort: s1 } = config;
4033
- const { sort: s2 } = newConfig;
4034
- if (exactlyTheSame(s1, s2) || equivalentSort(config, newConfig)) {
4035
- return false;
4036
- } else if (s1 === void 0 || s2 === void 0) {
4037
- return true;
4038
- } else if ((s1 == null ? void 0 : s1.sortDefs.length) !== (s2 == null ? void 0 : s2.sortDefs.length)) {
4039
- return true;
4040
- }
4041
- return s1.sortDefs.some(
4042
- ({ column, sortType }, i) => column !== s2.sortDefs[i].column || sortType !== s2.sortDefs[i].sortType
4043
- );
4044
- };
4045
- var visualLinkChanged = () => {
4046
- return false;
4047
- };
4048
- var configChanged = (config, newConfig) => {
4049
- if (exactlyTheSame(config, newConfig)) {
4050
- return false;
4051
- }
4052
- if (config === void 0 || newConfig === void 0) {
4053
- return true;
4054
- }
4055
- return aggregationsChanged(config, newConfig) || columnsChanged(config, newConfig) || filterChanged(config, newConfig) || groupByChanged(config, newConfig) || sortChanged(config, newConfig) || visualLinkChanged(config, newConfig);
4056
- };
4057
- var hasGroupBy = (config) => config !== void 0 && config.groupBy !== void 0 && config.groupBy.length > 0;
4058
- var hasFilter = (config) => (config == null ? void 0 : config.filter) !== void 0 && config.filter.filter.length > 0;
4059
- var hasSort = (config) => {
4060
- var _a;
4061
- return (config == null ? void 0 : config.sort) !== void 0 && Array.isArray((_a = config.sort) == null ? void 0 : _a.sortDefs) && config.sort.sortDefs.length > 0;
4062
- };
4063
- var withConfigDefaults = (config) => {
4064
- if (config.aggregations && config.columns && config.filter && config.groupBy && config.sort) {
4065
- return config;
4066
- } else {
4067
- const {
4068
- aggregations = [],
4069
- columns = [],
4070
- filter = { filter: "" },
4071
- groupBy = [],
4072
- sort = { sortDefs: [] },
4073
- visualLink
4074
- } = config;
4075
- return {
4076
- aggregations,
4077
- columns,
4078
- filter,
4079
- groupBy,
4080
- sort,
4081
- visualLink
4082
- };
4083
- }
4084
- };
4085
-
4086
- // ../vuu-utils/src/logging-utils.ts
4087
- var logLevels = ["error", "warn", "info", "debug"];
4088
- var isValidLogLevel = (value) => typeof value === "string" && logLevels.includes(value);
4089
- var DEFAULT_LOG_LEVEL = "error";
4090
- var NO_OP = () => void 0;
4091
- var DEFAULT_DEBUG_LEVEL = false ? "error" : "info";
4092
- var { loggingLevel = DEFAULT_DEBUG_LEVEL } = getLoggingSettings();
4093
- var logger = (category) => {
4094
- const debugEnabled = loggingLevel === "debug";
4095
- const infoEnabled = debugEnabled || loggingLevel === "info";
4096
- const warnEnabled = infoEnabled || loggingLevel === "warn";
4097
- const errorEnabled = warnEnabled || loggingLevel === "error";
4098
- const info = infoEnabled ? (message) => console.info(`[${category}] ${message}`) : NO_OP;
4099
- const warn = warnEnabled ? (message) => console.warn(`[${category}] ${message}`) : NO_OP;
4100
- const debug2 = debugEnabled ? (message) => console.debug(`[${category}] ${message}`) : NO_OP;
4101
- const error = errorEnabled ? (message) => console.error(`[${category}] ${message}`) : NO_OP;
4102
- if (false) {
4103
- return {
4104
- errorEnabled,
4105
- error
4106
- };
4107
- } else {
4108
- return {
4109
- debugEnabled,
4110
- infoEnabled,
4111
- warnEnabled,
4112
- errorEnabled,
4113
- info,
4114
- warn,
4115
- debug: debug2,
4116
- error
4117
- };
4118
- }
4119
- };
4120
- function getLoggingSettings() {
4121
- if (typeof loggingSettings !== "undefined") {
4122
- return loggingSettings;
4123
- } else {
4124
- return {
4125
- loggingLevel: getLoggingLevelFromCookie()
4126
- };
4127
- }
4128
- }
4129
- function getLoggingLevelFromCookie() {
4130
- const value = getCookieValue("vuu-logging-level");
4131
- if (isValidLogLevel(value)) {
4132
- return value;
4133
- } else {
4134
- return DEFAULT_LOG_LEVEL;
4135
- }
4136
- }
4137
-
4138
- // ../vuu-utils/src/event-emitter.ts
4139
- function isArrayOfListeners(listeners) {
4140
- return Array.isArray(listeners);
4141
- }
4142
- function isOnlyListener(listeners) {
4143
- return !Array.isArray(listeners);
4144
- }
4145
- var _events;
4146
- var EventEmitter = class {
4147
- constructor() {
4148
- __privateAdd(this, _events, /* @__PURE__ */ new Map());
4149
- }
4150
- addListener(event, listener) {
4151
- const listeners = __privateGet(this, _events).get(event);
4152
- if (!listeners) {
4153
- __privateGet(this, _events).set(event, listener);
4154
- } else if (isArrayOfListeners(listeners)) {
4155
- listeners.push(listener);
4156
- } else if (isOnlyListener(listeners)) {
4157
- __privateGet(this, _events).set(event, [listeners, listener]);
4158
- }
4159
- }
4160
- removeListener(event, listener) {
4161
- if (!__privateGet(this, _events).has(event)) {
4162
- return;
4163
- }
4164
- const listenerOrListeners = __privateGet(this, _events).get(event);
4165
- let position = -1;
4166
- if (listenerOrListeners === listener) {
4167
- __privateGet(this, _events).delete(event);
4168
- } else if (Array.isArray(listenerOrListeners)) {
4169
- for (let i = length; i-- > 0; ) {
4170
- if (listenerOrListeners[i] === listener) {
4171
- position = i;
4172
- break;
4173
- }
4174
- }
4175
- if (position < 0) {
4176
- return;
4177
- }
4178
- if (listenerOrListeners.length === 1) {
4179
- listenerOrListeners.length = 0;
4180
- __privateGet(this, _events).delete(event);
4181
- } else {
4182
- listenerOrListeners.splice(position, 1);
4183
- }
4184
- }
4185
- }
4186
- removeAllListeners(event) {
4187
- if (event && __privateGet(this, _events).has(event)) {
4188
- __privateGet(this, _events).delete(event);
4189
- } else if (event === void 0) {
4190
- __privateGet(this, _events).clear();
4191
- }
4192
- }
4193
- emit(event, ...args) {
4194
- if (__privateGet(this, _events)) {
4195
- const handler = __privateGet(this, _events).get(event);
4196
- if (handler) {
4197
- this.invokeHandler(handler, args);
4198
- }
4199
- }
4200
- }
4201
- once(event, listener) {
4202
- const handler = (...args) => {
4203
- this.removeListener(event, handler);
4204
- listener(...args);
4205
- };
4206
- this.on(event, handler);
4207
- }
4208
- on(event, listener) {
4209
- this.addListener(event, listener);
4210
- }
4211
- hasListener(event, listener) {
4212
- const listeners = __privateGet(this, _events).get(event);
4213
- if (Array.isArray(listeners)) {
4214
- return listeners.includes(listener);
4215
- } else {
4216
- return listeners === listener;
4217
- }
4218
- }
4219
- invokeHandler(handler, args) {
4220
- if (isArrayOfListeners(handler)) {
4221
- handler.slice().forEach((listener) => this.invokeHandler(listener, args));
4222
- } else {
4223
- switch (args.length) {
4224
- case 0:
4225
- handler();
4226
- break;
4227
- case 1:
4228
- handler(args[0]);
4229
- break;
4230
- case 2:
4231
- handler(args[0], args[1]);
4232
- break;
4233
- default:
4234
- handler.call(null, ...args);
4235
- }
4236
- }
4237
- }
4238
- };
4239
- _events = new WeakMap();
4240
-
4241
- // ../vuu-utils/src/keyset.ts
4242
- var KeySet = class {
4243
- constructor(range) {
4244
- this.keys = /* @__PURE__ */ new Map();
4245
- this.free = [];
4246
- this.nextKeyValue = 0;
4247
- this.reset(range);
4248
- }
4249
- next() {
4250
- if (this.free.length > 0) {
4251
- return this.free.pop();
4252
- } else {
4253
- return this.nextKeyValue++;
4254
- }
4255
- }
4256
- reset({ from, to }) {
4257
- this.keys.forEach((keyValue, rowIndex) => {
4258
- if (rowIndex < from || rowIndex >= to) {
4259
- this.free.push(keyValue);
4260
- this.keys.delete(rowIndex);
4261
- }
4262
- });
4263
- const size = to - from;
4264
- if (this.keys.size + this.free.length > size) {
4265
- this.free.length = Math.max(0, size - this.keys.size);
4266
- }
4267
- for (let rowIndex = from; rowIndex < to; rowIndex++) {
4268
- if (!this.keys.has(rowIndex)) {
4269
- const nextKeyValue = this.next();
4270
- this.keys.set(rowIndex, nextKeyValue);
4271
- }
4272
- }
4273
- if (this.nextKeyValue > this.keys.size) {
4274
- this.nextKeyValue = this.keys.size;
4275
- }
4276
- }
4277
- keyFor(rowIndex) {
4278
- const key = this.keys.get(rowIndex);
4279
- if (key === void 0) {
4280
- console.log(`key not found
4281
- keys: ${this.toDebugString()}
4282
- free : ${this.free.join(",")}
4283
- `);
4284
- throw Error(`KeySet, no key found for rowIndex ${rowIndex}`);
4285
- }
4286
- return key;
4287
- }
4288
- toDebugString() {
4289
- return Array.from(this.keys.entries()).map((k, v) => `${k}=>${v}`).join(",");
4290
- }
4291
- };
4292
-
4293
- // ../vuu-utils/src/nanoid/index.ts
4294
- var uuid = (size = 21) => {
4295
- let id = "";
4296
- const bytes = crypto.getRandomValues(new Uint8Array(size));
4297
- while (size--) {
4298
- const byte = bytes[size] & 63;
4299
- if (byte < 36) {
4300
- id += byte.toString(36);
4301
- } else if (byte < 62) {
4302
- id += (byte - 26).toString(36).toUpperCase();
4303
- } else if (byte < 63) {
4304
- id += "_";
4305
- } else {
4306
- id += "-";
4307
- }
4308
- }
4309
- return id;
4310
- };
4311
-
4312
- // ../vuu-utils/src/selection-utils.ts
4313
- var { SELECTED } = metadataKeys;
4314
- var RowSelected = {
4315
- False: 0,
4316
- True: 1,
4317
- First: 2,
4318
- Last: 4
4319
- };
4320
- var rangeIncludes = (range, index) => index >= range[0] && index <= range[1];
4321
- var SINGLE_SELECTED_ROW = RowSelected.True + RowSelected.First + RowSelected.Last;
4322
- var FIRST_SELECTED_ROW_OF_BLOCK = RowSelected.True + RowSelected.First;
4323
- var LAST_SELECTED_ROW_OF_BLOCK = RowSelected.True + RowSelected.Last;
4324
- var getSelectionStatus = (selected, itemIndex) => {
4325
- for (const item of selected) {
4326
- if (typeof item === "number") {
4327
- if (item === itemIndex) {
4328
- return SINGLE_SELECTED_ROW;
4329
- }
4330
- } else if (rangeIncludes(item, itemIndex)) {
4331
- if (itemIndex === item[0]) {
4332
- return FIRST_SELECTED_ROW_OF_BLOCK;
4333
- } else if (itemIndex === item[1]) {
4334
- return LAST_SELECTED_ROW_OF_BLOCK;
4335
- } else {
4336
- return RowSelected.True;
4337
- }
4338
- }
4339
- }
4340
- return RowSelected.False;
4341
- };
4342
-
4343
- // ../vuu-filter-parser/src/FilterTreeWalker.ts
4344
- var _filter;
4345
- var FilterExpression = class {
4346
- constructor() {
4347
- __privateAdd(this, _filter, void 0);
4348
- }
4349
- setFilterCombinatorOp(op, filter = __privateGet(this, _filter)) {
4350
- if (isMultiClauseFilter(filter) && filter.op === op) {
4351
- return;
4352
- } else {
4353
- __privateSet(this, _filter, {
4354
- op,
4355
- filters: [__privateGet(this, _filter)]
4356
- });
4357
- }
4358
- }
4359
- add(filter) {
4360
- if (__privateGet(this, _filter) === void 0) {
4361
- __privateSet(this, _filter, filter);
4362
- } else if (isMultiClauseFilter(__privateGet(this, _filter))) {
4363
- __privateGet(this, _filter).filters.push(filter);
4364
- } else {
4365
- throw Error(`Invalid filter passed to FilterExpression`);
4366
- }
4367
- }
4368
- setColumn(column, filter = __privateGet(this, _filter)) {
4369
- if (isMultiClauseFilter(filter)) {
4370
- const target = filter.filters.at(-1);
4371
- if (target) {
4372
- this.setColumn(column, target);
4373
- }
4374
- } else if (filter) {
4375
- filter.column = column;
4376
- }
4377
- }
4378
- setOp(value, filter = __privateGet(this, _filter)) {
4379
- if (isMultiClauseFilter(filter)) {
4380
- const target = filter.filters.at(-1);
4381
- if (target) {
4382
- this.setOp(value, target);
4383
- }
4384
- } else if (filter) {
4385
- filter.op = value;
4386
- }
4387
- }
4388
- setValue(value, filter = __privateGet(this, _filter)) {
4389
- var _a;
4390
- if (isMultiClauseFilter(filter)) {
4391
- const target = filter.filters.at(-1);
4392
- if (target) {
4393
- this.setValue(value, target);
4394
- }
4395
- } else if (isMultiValueFilter(filter)) {
4396
- (_a = filter.values) != null ? _a : filter.values = [];
4397
- filter.values.push(value);
4398
- } else if (isSingleValueFilter(filter)) {
4399
- filter.value = value;
4400
- }
4401
- }
4402
- toJSON(filter = __privateGet(this, _filter)) {
4403
- if (this.name) {
4404
- return {
4405
- ...filter,
4406
- name: this.name
4407
- };
4408
- } else {
4409
- return filter;
4410
- }
4411
- }
4412
- };
4413
- _filter = new WeakMap();
4414
- var walkTree = (tree, source) => {
4415
- const filterExpression = new FilterExpression();
4416
- const cursor = tree.cursor();
4417
- do {
4418
- const { name, from, to } = cursor;
4419
- switch (name) {
4420
- case "ColumnValueExpression":
4421
- filterExpression.add({});
4422
- break;
4423
- case "ColumnSetExpression":
4424
- filterExpression.add({ op: "in" });
4425
- break;
4426
- case "Or":
4427
- case "And":
4428
- filterExpression.setFilterCombinatorOp(source.substring(from, to));
4429
- break;
4430
- case "Column":
4431
- filterExpression.setColumn(source.substring(from, to));
4432
- break;
4433
- case "Operator":
4434
- filterExpression.setOp(source.substring(from, to));
4435
- break;
4436
- case "String":
4437
- filterExpression.setValue(source.substring(from + 1, to - 1));
4438
- break;
4439
- case "Number":
4440
- filterExpression.setValue(parseFloat(source.substring(from, to)));
4441
- break;
4442
- case "True":
4443
- filterExpression.setValue(true);
4444
- break;
4445
- case "False":
4446
- filterExpression.setValue(false);
4447
- break;
4448
- case "FilterName":
4449
- filterExpression.name = source.substring(from, to);
4450
- break;
4451
- default:
4452
- }
4453
- } while (cursor.next());
4454
- return filterExpression.toJSON();
4455
- };
4456
-
4457
- // ../vuu-filter-parser/src/FilterParser.ts
4458
- var strictParser = parser.configure({ strict: true });
4459
- var parseFilter = (filterQuery) => {
4460
- const parseTree = strictParser.parse(filterQuery);
4461
- const filter = walkTree(parseTree, filterQuery);
4462
- return filter;
4463
- };
4464
-
4465
- // ../vuu-filter-parser/src/filter-evaluation-utils.ts
4466
- function filterPredicate(columnMap, filter) {
4467
- switch (filter.op) {
4468
- case "in":
4469
- return testInclude(columnMap, filter);
4470
- case "=":
4471
- return testEQ(columnMap, filter);
4472
- case ">":
4473
- return testGT(columnMap, filter);
4474
- case ">=":
4475
- return testGE(columnMap, filter);
4476
- case "<":
4477
- return testLT(columnMap, filter);
4478
- case "<=":
4479
- return testLE(columnMap, filter);
4480
- case "starts":
4481
- return testSW(columnMap, filter);
4482
- case "and":
4483
- return testAND(columnMap, filter);
4484
- case "or":
4485
- return testOR(columnMap, filter);
4486
- default:
4487
- console.log(`unrecognized filter type ${filter.op}`);
4488
- return () => true;
4489
- }
4490
- }
4491
- var testInclude = (columnMap, filter) => {
4492
- return (row) => filter.values.indexOf(row[columnMap[filter.column]]) !== -1;
4493
- };
4494
- var testEQ = (columnMap, filter) => {
4495
- return (row) => row[columnMap[filter.column]] === filter.value;
4496
- };
4497
- var testGT = (columnMap, filter) => {
4498
- return (row) => row[columnMap[filter.column]] > filter.value;
4499
- };
4500
- var testGE = (columnMap, filter) => {
4501
- return (row) => row[columnMap[filter.column]] >= filter.value;
4502
- };
4503
- var testLT = (columnMap, filter) => {
4504
- return (row) => row[columnMap[filter.column]] < filter.value;
4505
- };
4506
- var testLE = (columnMap, filter) => {
4507
- return (row) => row[columnMap[filter.column]] <= filter.value;
4508
- };
4509
- var testSW = (columnMap, filter) => {
4510
- const filterValue = filter.value;
4511
- if (typeof filterValue !== "string") {
4512
- throw Error("string filter applied to value of wrong type");
4513
- }
4514
- return (row) => {
4515
- const rowValue = row[columnMap[filter.column]];
4516
- if (typeof rowValue !== "string") {
4517
- throw Error("string filter applied to value of wrong type");
4518
- }
4519
- return rowValue.toLowerCase().startsWith(filterValue.toLowerCase());
4520
- };
4521
- };
4522
- var testAND = (columnMap, filter) => {
4523
- const filters = filter.filters.map((f1) => filterPredicate(columnMap, f1));
4524
- return (row) => filters.every((fn) => fn(row));
4525
- };
4526
- function testOR(columnMap, filter) {
4527
- const filters = filter.filters.map((f1) => filterPredicate(columnMap, f1));
4528
- return (row) => filters.some((fn) => fn(row));
4529
- }
4530
-
4531
- // ../vuu-data-local/src/array-data-source/aggregate-utils.ts
4532
- var aggregateData = (aggregations, targetData, groupBy, leafData, columnMap, groupMap) => {
4533
- const aggColumn = getAggColumn(columnMap, aggregations);
4534
- const aggType = aggregations[aggregations.length - 1].aggType;
4535
- const groupIndices = groupBy.map((column) => columnMap[column]);
4536
- switch (aggType) {
4537
- case 1:
4538
- return aggregateSum(
4539
- groupMap,
4540
- leafData,
4541
- columnMap,
4542
- aggregations,
4543
- targetData,
4544
- groupIndices
4545
- );
4546
- case 2:
4547
- return aggregateAverage(
4548
- groupMap,
4549
- leafData,
4550
- columnMap,
4551
- aggregations,
4552
- targetData,
4553
- groupIndices
4554
- );
4555
- case 3:
4556
- return aggregateCount(
4557
- groupMap,
4558
- columnMap,
4559
- aggregations,
4560
- targetData,
4561
- groupIndices
4562
- );
4563
- case 4:
4564
- return aggregateHigh(
4565
- groupMap,
4566
- leafData,
4567
- columnMap,
4568
- aggregations,
4569
- targetData,
4570
- groupIndices
4571
- );
4572
- case 5:
4573
- return aggregateLow(
4574
- groupMap,
4575
- leafData,
4576
- columnMap,
4577
- aggregations,
4578
- targetData,
4579
- groupIndices
4580
- );
4581
- case 6:
4582
- return aggregateDistinct(
4583
- groupMap,
4584
- leafData,
4585
- columnMap,
4586
- aggregations,
4587
- targetData,
4588
- groupIndices
4589
- );
4590
- }
4591
- };
4592
- function aggregateCount(groupMap, columnMap, aggregations, targetData, groupIndices) {
4593
- const counts = {};
4594
- const aggColumn = getAggColumn(columnMap, aggregations);
4595
- function countRecursive(map) {
4596
- if (Array.isArray(map)) {
4597
- return map.length;
4598
- } else {
4599
- let count = 0;
4600
- for (const key in map) {
4601
- count += 1 + countRecursive(map[key]);
4602
- }
4603
- return count;
4604
- }
4605
- }
4606
- for (const key in groupMap) {
4607
- const count = countRecursive(groupMap[key]);
4608
- counts[key] = count;
4609
- }
4610
- for (let index = 0; index < targetData.length; index++) {
4611
- for (const key in counts) {
4612
- if (targetData[index][groupIndices[0]] === key) {
4613
- targetData[index][aggColumn] = counts[key];
4614
- }
4615
- }
4616
- }
4617
- console.log("!!!! targetData", targetData);
4618
- console.log("!!!! counts", counts);
4619
- return counts;
4620
- }
4621
- function getAggColumn(columnMap, aggregations) {
4622
- console.log("!!!! aggregation length", aggregations.length);
4623
- const columnName = aggregations[aggregations.length - 1].column;
4624
- const columnNumber = columnMap[columnName];
4625
- return columnNumber;
4626
- }
4627
- function aggregateSum(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
4628
- const sums = {};
4629
- const aggColumn = getAggColumn(columnMap, aggregations);
4630
- function sumRecursive(map, leafData2, aggColumn2) {
4631
- if (Array.isArray(map)) {
4632
- let sum = 0;
4633
- for (const key of map) {
4634
- sum += Number(leafData2[key][aggColumn2]);
4635
- }
4636
- return sum;
4637
- } else {
4638
- let sum = 0;
4639
- for (const key in map) {
4640
- sum += sumRecursive(map[key], leafData2, aggColumn2);
4641
- }
4642
- return sum;
4643
- }
4644
- }
4645
- for (const key in groupMap) {
4646
- console.log(key);
4647
- const sum = Number(sumRecursive(groupMap[key], leafData, aggColumn));
4648
- sums[key] = sum;
4649
- }
4650
- for (let index = 0; index < targetData.length; index++) {
4651
- for (const key in sums) {
4652
- if (targetData[index][groupIndices[0]] === key) {
4653
- targetData[index][aggColumn] = sums[key];
4654
- }
4655
- }
4656
- }
4657
- console.log("!!!! targetData", targetData);
4658
- console.log("!!!! sums", sums);
4659
- return sums;
4660
- }
4661
- function aggregateAverage(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
4662
- const averages = {};
4663
- const aggColumn = getAggColumn(columnMap, aggregations);
4664
- const count = aggregateCount(
4665
- groupMap,
4666
- columnMap,
4667
- aggregations,
4668
- targetData,
4669
- groupIndices
4670
- );
4671
- const sum = aggregateSum(
4672
- groupMap,
4673
- leafData,
4674
- columnMap,
4675
- aggregations,
4676
- targetData,
4677
- groupIndices
4678
- );
4679
- for (const key in count) {
4680
- let average = 0;
4681
- average = sum[key] / count[key];
4682
- averages[key] = average;
4683
- }
4684
- for (let index = 0; index < targetData.length; index++) {
4685
- for (const key in averages) {
4686
- if (targetData[index][groupIndices[0]] === key) {
4687
- targetData[index][aggColumn] = averages[key];
4688
- }
4689
- }
4690
- }
4691
- console.log("!!!! targetData", targetData);
4692
- console.log("!!!! averages", averages);
4693
- return averages;
4694
- }
4695
- function getLeafColumnData(map, leafData, aggColumn) {
4696
- const data = [];
4697
- if (Array.isArray(map)) {
4698
- for (const key of map) {
4699
- data.push(leafData[key][aggColumn]);
4700
- }
4701
- } else {
4702
- for (const key in map) {
4703
- data.push(...getLeafColumnData(map[key], leafData, aggColumn));
4704
- }
4705
- }
4706
- return data;
4707
- }
4708
- function aggregateDistinct(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
4709
- const distincts = {};
4710
- const aggColumn = getAggColumn(columnMap, aggregations);
4711
- for (const key in groupMap) {
4712
- const leafColumnData = getLeafColumnData(
4713
- groupMap[key],
4714
- leafData,
4715
- aggColumn
4716
- );
4717
- const distinct = [...new Set(leafColumnData)];
4718
- distincts[key] = distinct;
4719
- }
4720
- for (let index = 0; index < targetData.length; index++) {
4721
- for (const key in distincts) {
4722
- if (targetData[index][groupIndices[0]] === key) {
4723
- targetData[index][aggColumn] = distincts[key];
4724
- }
4725
- }
4726
- }
4727
- return distincts;
4728
- }
4729
- function aggregateHigh(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
4730
- const highs = {};
4731
- const aggColumn = getAggColumn(columnMap, aggregations);
4732
- for (const key in groupMap) {
4733
- const leafColumnData = getLeafColumnData(
4734
- groupMap[key],
4735
- leafData,
4736
- aggColumn
4737
- );
4738
- const maxNumber = Math.max(...leafColumnData);
4739
- highs[key] = maxNumber;
4740
- }
4741
- for (let index = 0; index < targetData.length; index++) {
4742
- for (const key in highs) {
4743
- if (targetData[index][groupIndices[0]] === key) {
4744
- targetData[index][aggColumn] = highs[key];
4745
- }
4746
- }
4747
- }
4748
- return highs;
4749
- }
4750
- function aggregateLow(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
4751
- const mins = {};
4752
- const aggColumn = getAggColumn(columnMap, aggregations);
4753
- for (const key in groupMap) {
4754
- const leafColumnData = getLeafColumnData(
4755
- groupMap[key],
4756
- leafData,
4757
- aggColumn
4758
- );
4759
- const minNumber = Math.min(...leafColumnData);
4760
- mins[key] = minNumber;
4761
- }
4762
- for (let index = 0; index < targetData.length; index++) {
4763
- for (const key in mins) {
4764
- if (targetData[index][groupIndices[0]] === key) {
4765
- targetData[index][aggColumn] = mins[key];
4766
- }
4767
- }
4768
- }
4769
- return mins;
4770
- }
882
+ // src/TickingArrayDataSource.ts
883
+ import {
884
+ ArrayDataSource
885
+ } from "@vuu-ui/vuu-data-local";
4771
886
 
4772
- // ../vuu-data-local/src/array-data-source/array-data-utils.ts
4773
- var { RENDER_IDX, SELECTED: SELECTED2 } = metadataKeys;
4774
- var toClientRow = (row, keys, selection, dataIndices) => {
4775
- const [rowIndex] = row;
4776
- let clientRow;
4777
- if (dataIndices) {
4778
- const { count } = metadataKeys;
4779
- clientRow = row.slice(0, count).concat(dataIndices.map((idx) => row[idx]));
4780
- } else {
4781
- clientRow = row.slice();
4782
- }
4783
- clientRow[RENDER_IDX] = keys.keyFor(rowIndex);
4784
- clientRow[SELECTED2] = getSelectionStatus(selection, rowIndex);
4785
- return clientRow;
4786
- };
4787
- var divergentMaps = (columnMap, dataMap) => {
4788
- if (dataMap) {
4789
- const { count: mapOffset } = metadataKeys;
4790
- for (const [columnName, index] of Object.entries(columnMap)) {
4791
- const dataIdx = dataMap[columnName];
4792
- if (dataIdx === void 0) {
4793
- throw Error(
4794
- `ArrayDataSource column ${columnName} is not in underlying data set`
4795
- );
4796
- } else if (dataIdx !== index - mapOffset) {
4797
- return true;
4798
- }
4799
- }
4800
- }
4801
- return false;
4802
- };
4803
- var getDataIndices = (columnMap, dataMap) => {
4804
- const { count: mapOffset } = metadataKeys;
4805
- const result = [];
4806
- Object.entries(columnMap).forEach(([columnName]) => {
4807
- result.push(dataMap[columnName] + mapOffset);
4808
- });
4809
- return result;
4810
- };
4811
- var buildDataToClientMap = (columnMap, dataMap) => {
4812
- if (dataMap && divergentMaps(columnMap, dataMap)) {
4813
- return getDataIndices(columnMap, dataMap);
4814
- }
4815
- return void 0;
887
+ // ../vuu-utils/src/column-utils.ts
888
+ var metadataKeys = {
889
+ IDX: 0,
890
+ RENDER_IDX: 1,
891
+ IS_LEAF: 2,
892
+ IS_EXPANDED: 3,
893
+ DEPTH: 4,
894
+ COUNT: 5,
895
+ KEY: 6,
896
+ SELECTED: 7,
897
+ count: 8,
898
+ // TODO following only used in datamodel
899
+ PARENT_IDX: "parent_idx",
900
+ IDX_POINTER: "idx_pointer",
901
+ FILTER_COUNT: "filter_count",
902
+ NEXT_FILTER_IDX: "next_filter_idx"
4816
903
  };
904
+ var { DEPTH, IS_LEAF } = metadataKeys;
4817
905
 
4818
- // ../vuu-data-local/src/array-data-source/group-utils.ts
4819
- var { DEPTH: DEPTH2, IS_EXPANDED, KEY } = metadataKeys;
4820
- var collapseGroup = (key, groupedRows) => {
4821
- const rows = [];
4822
- for (let i = 0, idx = 0, collapsed = false, len = groupedRows.length; i < len; i++) {
4823
- const row = groupedRows[i];
4824
- const { [DEPTH2]: depth, [KEY]: rowKey } = row;
4825
- if (rowKey === key) {
4826
- const collapsedRow = row.slice();
4827
- collapsedRow[IS_EXPANDED] = false;
4828
- rows.push(collapsedRow);
4829
- idx += 1;
4830
- collapsed = true;
4831
- while (i < len - 1 && groupedRows[i + 1][DEPTH2] > depth) {
4832
- i += 1;
4833
- }
4834
- } else if (collapsed) {
4835
- const newRow = row.slice();
4836
- newRow[0] = idx;
4837
- newRow[1] = idx;
4838
- rows.push(newRow);
4839
- idx += 1;
4840
- } else {
4841
- rows.push(row);
4842
- idx += 1;
4843
- }
4844
- }
4845
- return rows;
4846
- };
4847
- var expandGroup = (keys, sourceRows, groupBy, columnMap, groupMap, processedData) => {
4848
- const groupIndices = groupBy.map((column) => columnMap[column]);
4849
- return dataRowsFromGroups2(
4850
- groupMap,
4851
- groupIndices,
4852
- keys,
4853
- sourceRows,
4854
- void 0,
4855
- void 0,
4856
- void 0,
4857
- processedData
4858
- );
4859
- };
4860
- var dataRowsFromGroups2 = (groupMap, groupIndices, openKeys, sourceRows = [], root = "$root", depth = 1, rows = [], processedData) => {
4861
- console.log(`dataRowsFromGroups2 1)`);
4862
- const keys = Object.keys(groupMap).sort();
4863
- for (const key of keys) {
4864
- const idx = rows.length;
4865
- const groupKey = `${root}|${key}`;
4866
- const row = [idx, idx, false, false, depth, 0, groupKey, 0];
4867
- row[groupIndices[depth - 1]] = key;
4868
- rows.push(row);
4869
- if (openKeys.includes(groupKey)) {
4870
- row[IS_EXPANDED] = true;
4871
- if (Array.isArray(groupMap[key])) {
4872
- pushChildren(
4873
- rows,
4874
- groupMap[key],
4875
- sourceRows,
4876
- groupKey,
4877
- depth + 1
4878
- );
4879
- } else {
4880
- dataRowsFromGroups2(
4881
- groupMap[key],
4882
- groupIndices,
4883
- openKeys,
4884
- sourceRows,
4885
- groupKey,
4886
- depth + 1,
4887
- rows,
4888
- processedData
4889
- );
4890
- }
4891
- }
4892
- }
4893
- console.log(`dataRowsFromGroups2 2)`);
4894
- for (const key in rows) {
4895
- for (const index in rows) {
4896
- if (rows[key][2] === false && processedData[index] != void 0) {
4897
- if (rows[key][groupIndices[0]] === processedData[index][groupIndices[0]]) {
4898
- rows[key] = rows[key].splice(0, 8).concat(
4899
- processedData[index].slice(
4900
- 8,
4901
- // groupIndices[0] + 1,
4902
- processedData[index].length
4903
- )
4904
- );
4905
- break;
4906
- }
4907
- }
4908
- }
4909
- }
4910
- console.log(`dataRowsFromGroups2 3)`);
4911
- return rows;
4912
- };
4913
- var pushChildren = (rows, tree, sourceRows, parentKey, depth) => {
4914
- for (const rowIdx of tree) {
4915
- const idx = rows.length;
4916
- const sourceRow = sourceRows[rowIdx].slice();
4917
- sourceRow[0] = idx;
4918
- sourceRow[1] = idx;
4919
- sourceRow[DEPTH2] = depth;
4920
- sourceRow[KEY] = `${parentKey}|${sourceRow[KEY]}`;
4921
- rows.push(sourceRow);
4922
- }
4923
- };
4924
- var groupRows = (rows, groupBy, columnMap) => {
4925
- const groupIndices = groupBy.map((column) => columnMap[column]);
4926
- const groupTree = groupLeafRows(rows, groupIndices);
4927
- const groupedDataRows = dataRowsFromGroups(groupTree, groupIndices);
4928
- return [groupedDataRows, groupTree];
4929
- };
4930
- var dataRowsFromGroups = (groupTree, groupIndices) => {
4931
- const depth = 0;
4932
- const rows = [];
4933
- let idx = 0;
4934
- const keys = Object.keys(groupTree).sort();
4935
- for (const key of keys) {
4936
- const row = [
4937
- idx,
4938
- idx,
4939
- false,
4940
- false,
4941
- 1,
4942
- 0,
4943
- `$root|${key}`,
4944
- 0
4945
- ];
4946
- row[groupIndices[depth]] = key;
4947
- rows.push(row);
4948
- idx += 1;
4949
- }
4950
- return rows;
4951
- };
4952
- function groupLeafRows(leafRows, groupby) {
4953
- const groups = {};
4954
- const levels = groupby.length;
4955
- const lastLevel = levels - 1;
4956
- for (let i = 0, len = leafRows.length; i < len; i++) {
4957
- const leafRow = leafRows[i];
4958
- let target = groups;
4959
- let targetNode;
4960
- let key;
4961
- for (let level = 0; level < levels; level++) {
4962
- const colIdx = groupby[level];
4963
- key = leafRow[colIdx].toString();
4964
- targetNode = target[key];
4965
- if (targetNode && level === lastLevel) {
4966
- targetNode.push(i);
4967
- } else if (targetNode) {
4968
- target = targetNode;
4969
- } else if (!targetNode && level < lastLevel) {
4970
- target = target[key] = {};
4971
- } else if (!targetNode) {
4972
- target[key] = [i];
4973
- }
4974
- }
4975
- }
4976
- console.log("!! groups", groups);
4977
- return groups;
906
+ // ../vuu-utils/src/event-emitter.ts
907
+ function isArrayOfListeners(listeners) {
908
+ return Array.isArray(listeners);
4978
909
  }
4979
-
4980
- // ../vuu-data-local/src/array-data-source/sort-utils.ts
4981
- var defaultSortPredicate = (r1, r2, [i, direction]) => {
4982
- const val1 = direction === "D" ? r2[i] : r1[i];
4983
- const val2 = direction === "D" ? r1[i] : r2[i];
4984
- if (val1 === val2) {
4985
- return 0;
4986
- } else if (val2 === null || val1 > val2) {
4987
- return 1;
4988
- } else {
4989
- return -1;
4990
- }
4991
- };
4992
- var sortComparator = (sortDefs) => {
4993
- if (sortDefs.length === 1) {
4994
- return singleColComparator(sortDefs);
4995
- } else if (sortDefs.length === 2) {
4996
- return twoColComparator(sortDefs);
4997
- } else {
4998
- return multiColComparator(sortDefs);
910
+ function isOnlyListener(listeners) {
911
+ return !Array.isArray(listeners);
912
+ }
913
+ var _events;
914
+ var EventEmitter = class {
915
+ constructor() {
916
+ __privateAdd(this, _events, /* @__PURE__ */ new Map());
4999
917
  }
5000
- };
5001
- var singleColComparator = ([[i, direction]]) => (r1, r2) => {
5002
- const v1 = direction === "D" ? r2[i] : r1[i];
5003
- const v2 = direction === "D" ? r1[i] : r2[i];
5004
- return v1 > v2 ? 1 : v2 > v1 ? -1 : 0;
5005
- };
5006
- var twoColComparator = ([[idx1, direction1], [idx2, direction2]]) => (r1, r2) => {
5007
- const v1 = direction1 === "D" ? r2[idx1] : r1[idx1];
5008
- const v2 = direction1 === "D" ? r1[idx1] : r2[idx1];
5009
- const v3 = direction2 === "D" ? r2[idx2] : r1[idx2];
5010
- const v4 = direction2 === "D" ? r1[idx2] : r2[idx2];
5011
- return v1 > v2 ? 1 : v2 > v1 ? -1 : v3 > v4 ? 1 : v4 > v3 ? -1 : 0;
5012
- };
5013
- var multiColComparator = (sortDefs, test = defaultSortPredicate) => (r1, r2) => {
5014
- for (const sortDef of sortDefs) {
5015
- const result = test(r1, r2, sortDef);
5016
- if (result !== 0) {
5017
- return result;
918
+ addListener(event, listener) {
919
+ const listeners = __privateGet(this, _events).get(event);
920
+ if (!listeners) {
921
+ __privateGet(this, _events).set(event, listener);
922
+ } else if (isArrayOfListeners(listeners)) {
923
+ listeners.push(listener);
924
+ } else if (isOnlyListener(listeners)) {
925
+ __privateGet(this, _events).set(event, [listeners, listener]);
5018
926
  }
5019
927
  }
5020
- return 0;
5021
- };
5022
- var sortRows = (rows, { sortDefs }, columnMap) => {
5023
- const indexedSortDefs = sortDefs.map(({ column, sortType }) => [
5024
- columnMap[column],
5025
- sortType
5026
- ]);
5027
- const comparator = sortComparator(indexedSortDefs);
5028
- return rows.slice().sort(comparator);
5029
- };
5030
-
5031
- // ../vuu-data-local/src/array-data-source/array-data-source.ts
5032
- var { KEY: KEY2 } = metadataKeys;
5033
- var { debug } = logger("ArrayDataSource");
5034
- var toDataSourceRow = (key) => (data, index) => {
5035
- return [index, index, true, false, 1, 0, String(data[key]), 0, ...data];
5036
- };
5037
- var buildTableSchema = (columns, keyColumn) => {
5038
- const schema = {
5039
- columns: columns.map(({ name, serverDataType = "string" }) => ({
5040
- name,
5041
- serverDataType
5042
- })),
5043
- key: keyColumn != null ? keyColumn : columns[0].name,
5044
- table: { module: "", table: "Array" }
5045
- };
5046
- return schema;
5047
- };
5048
- var _columnMap, _config, _data, _links, _range, _selectedRowsCount, _size, _status, _title;
5049
- var ArrayDataSource = class extends EventEmitter {
5050
- constructor({
5051
- aggregations,
5052
- // different from RemoteDataSource
5053
- columnDescriptors,
5054
- data,
5055
- dataMap,
5056
- filter,
5057
- groupBy,
5058
- keyColumn,
5059
- rangeChangeRowset = "delta",
5060
- sort,
5061
- title,
5062
- viewport
5063
- }) {
5064
- super();
5065
- this.lastRangeServed = { from: 0, to: 0 };
5066
- this.openTreeNodes = [];
5067
- /** Map reflecting positions of columns in client data sent to user */
5068
- __privateAdd(this, _columnMap, void 0);
5069
- __privateAdd(this, _config, vanillaConfig);
5070
- __privateAdd(this, _data, void 0);
5071
- __privateAdd(this, _links, void 0);
5072
- __privateAdd(this, _range, NULL_RANGE);
5073
- __privateAdd(this, _selectedRowsCount, 0);
5074
- __privateAdd(this, _size, 0);
5075
- __privateAdd(this, _status, "initialising");
5076
- __privateAdd(this, _title, void 0);
5077
- this.selectedRows = [];
5078
- this.keys = new KeySet(__privateGet(this, _range));
5079
- this.processedData = void 0;
5080
- this.insert = (row) => {
5081
- const dataSourceRow = toDataSourceRow(this.key)(row, this.size);
5082
- __privateGet(this, _data).push(dataSourceRow);
5083
- const { from, to } = __privateGet(this, _range);
5084
- const [rowIdx] = dataSourceRow;
5085
- if (rowIdx >= from && rowIdx < to) {
5086
- this.sendRowsToClient();
5087
- }
5088
- };
5089
- this.update = (row, columnName) => {
5090
- var _a;
5091
- const keyValue = row[this.key];
5092
- const colIndex = __privateGet(this, _columnMap)[columnName];
5093
- const dataColIndex = (_a = this.dataMap) == null ? void 0 : _a[columnName];
5094
- const dataIndex = __privateGet(this, _data).findIndex((row2) => row2[KEY2] === keyValue);
5095
- if (dataIndex !== -1 && dataColIndex !== void 0) {
5096
- const dataSourceRow = __privateGet(this, _data)[dataIndex];
5097
- dataSourceRow[colIndex] = row[dataColIndex];
5098
- const { from, to } = __privateGet(this, _range);
5099
- const [rowIdx] = dataSourceRow;
5100
- if (rowIdx >= from && rowIdx < to) {
5101
- this.sendRowsToClient(false, dataSourceRow);
5102
- }
5103
- }
5104
- };
5105
- this.updateRow = (row) => {
5106
- const keyValue = row[this.key];
5107
- const dataIndex = __privateGet(this, _data).findIndex((row2) => row2[KEY2] === keyValue);
5108
- if (dataIndex !== -1) {
5109
- const dataSourceRow = toDataSourceRow(this.key)(row, dataIndex);
5110
- __privateGet(this, _data)[dataIndex] = dataSourceRow;
5111
- const { from, to } = __privateGet(this, _range);
5112
- if (dataIndex >= from && dataIndex < to) {
5113
- this.sendRowsToClient(false, dataSourceRow);
928
+ removeListener(event, listener) {
929
+ if (!__privateGet(this, _events).has(event)) {
930
+ return;
931
+ }
932
+ const listenerOrListeners = __privateGet(this, _events).get(event);
933
+ let position = -1;
934
+ if (listenerOrListeners === listener) {
935
+ __privateGet(this, _events).delete(event);
936
+ } else if (Array.isArray(listenerOrListeners)) {
937
+ for (let i = length; i-- > 0; ) {
938
+ if (listenerOrListeners[i] === listener) {
939
+ position = i;
940
+ break;
5114
941
  }
5115
942
  }
5116
- };
5117
- if (!data || !columnDescriptors) {
5118
- throw Error(
5119
- "ArrayDataSource constructor called without data or without columnDescriptors"
5120
- );
5121
- }
5122
- this.columnDescriptors = columnDescriptors;
5123
- this.dataMap = dataMap;
5124
- this.key = keyColumn ? this.columnDescriptors.findIndex((col) => col.name === keyColumn) : 0;
5125
- this.rangeChangeRowset = rangeChangeRowset;
5126
- this.tableSchema = buildTableSchema(columnDescriptors, keyColumn);
5127
- this.viewport = viewport || uuid();
5128
- __privateSet(this, _size, data.length);
5129
- __privateSet(this, _title, title);
5130
- const columns = columnDescriptors.map((col) => col.name);
5131
- __privateSet(this, _columnMap, buildColumnMap(columns));
5132
- this.dataIndices = buildDataToClientMap(__privateGet(this, _columnMap), this.dataMap);
5133
- __privateSet(this, _data, data.map(toDataSourceRow(this.key)));
5134
- this.config = {
5135
- ...__privateGet(this, _config),
5136
- aggregations: aggregations || __privateGet(this, _config).aggregations,
5137
- columns,
5138
- filter: filter || __privateGet(this, _config).filter,
5139
- groupBy: groupBy || __privateGet(this, _config).groupBy,
5140
- sort: sort || __privateGet(this, _config).sort
5141
- };
5142
- debug == null ? void 0 : debug(`columnMap: ${JSON.stringify(__privateGet(this, _columnMap))}`);
5143
- }
5144
- async subscribe({
5145
- viewport = ((_a) => (_a = this.viewport) != null ? _a : uuid())(),
5146
- columns,
5147
- aggregations,
5148
- range,
5149
- sort,
5150
- groupBy,
5151
- filter
5152
- }, callback) {
5153
- var _a2;
5154
- this.clientCallback = callback;
5155
- this.viewport = viewport;
5156
- __privateSet(this, _status, "subscribed");
5157
- this.lastRangeServed = { from: 0, to: 0 };
5158
- let config = __privateGet(this, _config);
5159
- const hasConfigProps = aggregations || columns || filter || groupBy || sort;
5160
- if (hasConfigProps) {
5161
- if (range) {
5162
- __privateSet(this, _range, range);
943
+ if (position < 0) {
944
+ return;
5163
945
  }
5164
- config = {
5165
- ...config,
5166
- aggregations: aggregations || __privateGet(this, _config).aggregations,
5167
- columns: columns || __privateGet(this, _config).columns,
5168
- filter: filter || __privateGet(this, _config).filter,
5169
- groupBy: groupBy || __privateGet(this, _config).groupBy,
5170
- sort: sort || __privateGet(this, _config).sort
5171
- };
5172
- }
5173
- (_a2 = this.clientCallback) == null ? void 0 : _a2.call(this, {
5174
- ...config,
5175
- type: "subscribed",
5176
- clientViewportId: this.viewport,
5177
- range: __privateGet(this, _range),
5178
- tableSchema: this.tableSchema
5179
- });
5180
- if (hasConfigProps) {
5181
- this.config = config;
5182
- } else {
5183
- this.clientCallback({
5184
- clientViewportId: this.viewport,
5185
- mode: "size-only",
5186
- type: "viewport-update",
5187
- size: __privateGet(this, _data).length
5188
- });
5189
- if (range) {
5190
- this.range = range;
5191
- } else if (__privateGet(this, _range) !== NULL_RANGE) {
5192
- this.sendRowsToClient();
946
+ if (listenerOrListeners.length === 1) {
947
+ listenerOrListeners.length = 0;
948
+ __privateGet(this, _events).delete(event);
949
+ } else {
950
+ listenerOrListeners.splice(position, 1);
5193
951
  }
5194
952
  }
5195
953
  }
5196
- unsubscribe() {
5197
- console.log("unsubscribe noop");
5198
- }
5199
- suspend() {
5200
- return this;
5201
- }
5202
- resume() {
5203
- return this;
5204
- }
5205
- disable() {
5206
- return this;
5207
- }
5208
- enable() {
5209
- return this;
5210
- }
5211
- select(selected) {
5212
- __privateSet(this, _selectedRowsCount, selected.length);
5213
- debug == null ? void 0 : debug(`select ${JSON.stringify(selected)}`);
5214
- this.selectedRows = selected;
5215
- this.setRange(resetRange(__privateGet(this, _range)), true);
5216
- }
5217
- openTreeNode(key) {
5218
- this.openTreeNodes.push(key);
5219
- this.processedData = expandGroup(
5220
- this.openTreeNodes,
5221
- __privateGet(this, _data),
5222
- __privateGet(this, _config).groupBy,
5223
- __privateGet(this, _columnMap),
5224
- this.groupMap,
5225
- this.processedData
5226
- );
5227
- this.setRange(resetRange(__privateGet(this, _range)), true);
5228
- }
5229
- closeTreeNode(key) {
5230
- this.openTreeNodes = this.openTreeNodes.filter((value) => value !== key);
5231
- if (this.processedData) {
5232
- this.processedData = collapseGroup(key, this.processedData);
5233
- this.setRange(resetRange(__privateGet(this, _range)), true);
5234
- }
5235
- }
5236
- get links() {
5237
- return __privateGet(this, _links);
5238
- }
5239
- get menu() {
5240
- return this._menu;
5241
- }
5242
- get status() {
5243
- return __privateGet(this, _status);
5244
- }
5245
- get data() {
5246
- return __privateGet(this, _data);
5247
- }
5248
- // Only used by the UpdateGenerator
5249
- get currentData() {
5250
- var _a;
5251
- return (_a = this.processedData) != null ? _a : __privateGet(this, _data);
5252
- }
5253
- get table() {
5254
- return this.tableSchema.table;
5255
- }
5256
- get config() {
5257
- return __privateGet(this, _config);
5258
- }
5259
- set config(config) {
5260
- var _a;
5261
- if (this.applyConfig(config)) {
5262
- if (config) {
5263
- const originalConfig = __privateGet(this, _config);
5264
- const newConfig = ((_a = config == null ? void 0 : config.filter) == null ? void 0 : _a.filter) && (config == null ? void 0 : config.filter.filterStruct) === void 0 ? {
5265
- ...config,
5266
- filter: {
5267
- filter: config.filter.filter,
5268
- filterStruct: parseFilter(config.filter.filter)
5269
- }
5270
- } : config;
5271
- __privateSet(this, _config, withConfigDefaults(newConfig));
5272
- let processedData;
5273
- if (hasFilter(config)) {
5274
- const { filter, filterStruct = parseFilter(filter) } = config.filter;
5275
- if (filterStruct) {
5276
- const fn = filterPredicate(__privateGet(this, _columnMap), filterStruct);
5277
- processedData = __privateGet(this, _data).filter(fn);
5278
- } else {
5279
- throw Error("filter must include filterStruct");
5280
- }
5281
- }
5282
- if (hasSort(config)) {
5283
- processedData = sortRows(
5284
- processedData != null ? processedData : __privateGet(this, _data),
5285
- config.sort,
5286
- __privateGet(this, _columnMap)
5287
- );
5288
- }
5289
- if (this.openTreeNodes.length > 0 && groupByChanged(originalConfig, config)) {
5290
- if (__privateGet(this, _config).groupBy.length === 0) {
5291
- this.openTreeNodes.length = 0;
5292
- } else {
5293
- console.log("adjust the openTReeNodes groupBy changed ", {
5294
- originalGroupBy: originalConfig.groupBy,
5295
- newGroupBy: newConfig.groupBy
5296
- });
5297
- }
5298
- }
5299
- if (hasGroupBy(config)) {
5300
- const [groupedData, groupMap] = groupRows(
5301
- processedData != null ? processedData : __privateGet(this, _data),
5302
- config.groupBy,
5303
- __privateGet(this, _columnMap)
5304
- );
5305
- this.groupMap = groupMap;
5306
- processedData = groupedData;
5307
- if (this.openTreeNodes.length > 0) {
5308
- processedData = expandGroup(
5309
- this.openTreeNodes,
5310
- __privateGet(this, _data),
5311
- __privateGet(this, _config).groupBy,
5312
- __privateGet(this, _columnMap),
5313
- this.groupMap,
5314
- processedData
5315
- );
5316
- }
5317
- }
5318
- this.processedData = processedData == null ? void 0 : processedData.map((row, i) => {
5319
- const dolly = row.slice();
5320
- dolly[0] = i;
5321
- dolly[1] = i;
5322
- return dolly;
5323
- });
5324
- }
5325
- this.setRange(resetRange(__privateGet(this, _range)), true);
5326
- this.emit("config", __privateGet(this, _config));
954
+ removeAllListeners(event) {
955
+ if (event && __privateGet(this, _events).has(event)) {
956
+ __privateGet(this, _events).delete(event);
957
+ } else if (event === void 0) {
958
+ __privateGet(this, _events).clear();
5327
959
  }
5328
960
  }
5329
- applyConfig(config) {
5330
- var _a;
5331
- if (configChanged(__privateGet(this, _config), config)) {
5332
- if (config) {
5333
- const newConfig = ((_a = config == null ? void 0 : config.filter) == null ? void 0 : _a.filter) && (config == null ? void 0 : config.filter.filterStruct) === void 0 ? {
5334
- ...config,
5335
- filter: {
5336
- filter: config.filter.filter,
5337
- filterStruct: parseFilter(config.filter.filter)
5338
- }
5339
- } : config;
5340
- __privateSet(this, _config, withConfigDefaults(newConfig));
5341
- return true;
961
+ emit(event, ...args) {
962
+ if (__privateGet(this, _events)) {
963
+ const handler = __privateGet(this, _events).get(event);
964
+ if (handler) {
965
+ this.invokeHandler(handler, args);
5342
966
  }
5343
967
  }
5344
968
  }
5345
- get selectedRowsCount() {
5346
- return __privateGet(this, _selectedRowsCount);
5347
- }
5348
- get size() {
5349
- var _a, _b;
5350
- return (_b = (_a = this.processedData) == null ? void 0 : _a.length) != null ? _b : __privateGet(this, _data).length;
5351
- }
5352
- get range() {
5353
- return __privateGet(this, _range);
5354
- }
5355
- set range(range) {
5356
- if (range.from !== __privateGet(this, _range).from || range.to !== __privateGet(this, _range).to) {
5357
- this.setRange(range);
5358
- }
5359
- }
5360
- delete(row) {
5361
- console.log(`delete row ${row.join(",")}`);
5362
- }
5363
- setRange(range, forceFullRefresh = false) {
5364
- __privateSet(this, _range, range);
5365
- this.keys.reset(range);
5366
- this.sendRowsToClient(forceFullRefresh);
5367
- }
5368
- sendRowsToClient(forceFullRefresh = false, row) {
5369
- var _a, _b, _c;
5370
- if (row) {
5371
- (_a = this.clientCallback) == null ? void 0 : _a.call(this, {
5372
- clientViewportId: this.viewport,
5373
- mode: "update",
5374
- rows: [
5375
- toClientRow(row, this.keys, this.selectedRows, this.dataIndices)
5376
- ],
5377
- type: "viewport-update"
5378
- });
5379
- } else {
5380
- const rowRange = this.rangeChangeRowset === "delta" && !forceFullRefresh ? rangeNewItems(this.lastRangeServed, __privateGet(this, _range)) : __privateGet(this, _range);
5381
- const data = (_b = this.processedData) != null ? _b : __privateGet(this, _data);
5382
- const rowsWithinViewport = data.slice(rowRange.from, rowRange.to).map(
5383
- (row2) => toClientRow(row2, this.keys, this.selectedRows, this.dataIndices)
5384
- );
5385
- (_c = this.clientCallback) == null ? void 0 : _c.call(this, {
5386
- clientViewportId: this.viewport,
5387
- mode: "batch",
5388
- rows: rowsWithinViewport,
5389
- size: data.length,
5390
- type: "viewport-update"
5391
- });
5392
- this.lastRangeServed = {
5393
- from: __privateGet(this, _range).from,
5394
- to: Math.min(
5395
- __privateGet(this, _range).to,
5396
- __privateGet(this, _range).from + rowsWithinViewport.length
5397
- )
5398
- };
5399
- }
5400
- }
5401
- get columns() {
5402
- return __privateGet(this, _config).columns;
5403
- }
5404
- set columns(columns) {
5405
- const addedColumns = getAddedItems(this.config.columns, columns);
5406
- if (addedColumns.length > 0) {
5407
- const columnsWithoutDescriptors = getMissingItems(
5408
- this.columnDescriptors,
5409
- addedColumns,
5410
- (col) => col.name
5411
- );
5412
- console.log(`columnsWithoutDescriptors`, {
5413
- columnsWithoutDescriptors
5414
- });
5415
- }
5416
- __privateSet(this, _columnMap, buildColumnMap(columns));
5417
- this.dataIndices = buildDataToClientMap(__privateGet(this, _columnMap), this.dataMap);
5418
- this.config = {
5419
- ...__privateGet(this, _config),
5420
- columns
5421
- };
5422
- }
5423
- get aggregations() {
5424
- return __privateGet(this, _config).aggregations;
5425
- }
5426
- set aggregations(aggregations) {
5427
- var _a;
5428
- __privateSet(this, _config, {
5429
- ...__privateGet(this, _config),
5430
- aggregations
5431
- });
5432
- const targetData = (_a = this.processedData) != null ? _a : __privateGet(this, _data);
5433
- const leafData = __privateGet(this, _data);
5434
- aggregateData(
5435
- aggregations,
5436
- targetData,
5437
- __privateGet(this, _config).groupBy,
5438
- leafData,
5439
- __privateGet(this, _columnMap),
5440
- this.groupMap
5441
- );
5442
- this.setRange(resetRange(__privateGet(this, _range)), true);
5443
- this.emit("config", __privateGet(this, _config));
5444
- }
5445
- get sort() {
5446
- return __privateGet(this, _config).sort;
5447
- }
5448
- set sort(sort) {
5449
- debug == null ? void 0 : debug(`sort ${JSON.stringify(sort)}`);
5450
- this.config = {
5451
- ...__privateGet(this, _config),
5452
- sort
5453
- };
5454
- }
5455
- get filter() {
5456
- return __privateGet(this, _config).filter;
5457
- }
5458
- set filter(filter) {
5459
- debug == null ? void 0 : debug(`filter ${JSON.stringify(filter)}`);
5460
- this.config = {
5461
- ...__privateGet(this, _config),
5462
- filter
5463
- };
5464
- }
5465
- get groupBy() {
5466
- return __privateGet(this, _config).groupBy;
5467
- }
5468
- set groupBy(groupBy) {
5469
- this.config = {
5470
- ...__privateGet(this, _config),
5471
- groupBy
969
+ once(event, listener) {
970
+ const handler = (...args) => {
971
+ this.removeListener(event, handler);
972
+ listener(...args);
5472
973
  };
974
+ this.on(event, handler);
5473
975
  }
5474
- get title() {
5475
- return __privateGet(this, _title);
5476
- }
5477
- set title(title) {
5478
- __privateSet(this, _title, title);
5479
- }
5480
- get _clientCallback() {
5481
- return this.clientCallback;
5482
- }
5483
- createLink({
5484
- parentVpId,
5485
- link: { fromColumn, toColumn }
5486
- }) {
5487
- console.log("create link", {
5488
- parentVpId,
5489
- fromColumn,
5490
- toColumn
5491
- });
5492
- }
5493
- removeLink() {
5494
- console.log("remove link");
976
+ on(event, listener) {
977
+ this.addListener(event, listener);
5495
978
  }
5496
- findRow(rowKey) {
5497
- const row = __privateGet(this, _data)[rowKey];
5498
- if (row) {
5499
- return row;
979
+ hasListener(event, listener) {
980
+ const listeners = __privateGet(this, _events).get(event);
981
+ if (Array.isArray(listeners)) {
982
+ return listeners.includes(listener);
5500
983
  } else {
5501
- throw `no row found for key ${rowKey}`;
984
+ return listeners === listener;
5502
985
  }
5503
986
  }
5504
- applyEdit(row, columnName, value) {
5505
- console.log(`ArrayDataSource applyEdit ${row[0]} ${columnName} ${value}`);
5506
- return Promise.resolve(true);
5507
- }
5508
- async menuRpcCall(rpcRequest) {
5509
- return new Promise((resolve) => {
5510
- const { type } = rpcRequest;
5511
- switch (type) {
5512
- case "VP_EDIT_CELL_RPC":
5513
- {
5514
- }
987
+ invokeHandler(handler, args) {
988
+ if (isArrayOfListeners(handler)) {
989
+ handler.slice().forEach((listener) => this.invokeHandler(listener, args));
990
+ } else {
991
+ switch (args.length) {
992
+ case 0:
993
+ handler();
994
+ break;
995
+ case 1:
996
+ handler(args[0]);
997
+ break;
998
+ case 2:
999
+ handler(args[0], args[1]);
5515
1000
  break;
5516
1001
  default:
5517
- resolve(void 0);
1002
+ handler.call(null, ...args);
5518
1003
  }
5519
- });
1004
+ }
5520
1005
  }
5521
1006
  };
5522
- _columnMap = new WeakMap();
5523
- _config = new WeakMap();
5524
- _data = new WeakMap();
5525
- _links = new WeakMap();
5526
- _range = new WeakMap();
5527
- _selectedRowsCount = new WeakMap();
5528
- _size = new WeakMap();
5529
- _status = new WeakMap();
5530
- _title = new WeakMap();
5531
-
5532
- // ../vuu-data-local/src/json-data-source/json-data-source.ts
5533
- var { DEPTH: DEPTH3, IDX, IS_EXPANDED: IS_EXPANDED2, IS_LEAF: IS_LEAF2, KEY: KEY3, SELECTED: SELECTED3 } = metadataKeys;
1007
+ _events = new WeakMap();
5534
1008
 
5535
1009
  // src/makeSuggestions.ts
5536
1010
  var cachedValues = /* @__PURE__ */ new Map();
@@ -5751,16 +1225,16 @@ var populateArray = (count, colGen, rowGen, columns) => {
5751
1225
  };
5752
1226
 
5753
1227
  // src/Table.ts
5754
- var _data2, _dataMap, _indexOfKey, _index, _schema;
1228
+ var _data, _dataMap, _indexOfKey, _index, _schema;
5755
1229
  var Table = class extends EventEmitter {
5756
1230
  constructor(schema, data, dataMap, updateGenerator) {
5757
1231
  super();
5758
- __privateAdd(this, _data2, void 0);
1232
+ __privateAdd(this, _data, void 0);
5759
1233
  __privateAdd(this, _dataMap, void 0);
5760
1234
  __privateAdd(this, _indexOfKey, void 0);
5761
1235
  __privateAdd(this, _index, /* @__PURE__ */ new Map());
5762
1236
  __privateAdd(this, _schema, void 0);
5763
- __privateSet(this, _data2, data);
1237
+ __privateSet(this, _data, data);
5764
1238
  __privateSet(this, _dataMap, dataMap);
5765
1239
  __privateSet(this, _schema, schema);
5766
1240
  __privateSet(this, _indexOfKey, dataMap[schema.key]);
@@ -5769,13 +1243,13 @@ var Table = class extends EventEmitter {
5769
1243
  updateGenerator == null ? void 0 : updateGenerator.setRange({ from: 0, to: 100 });
5770
1244
  }
5771
1245
  buildIndex() {
5772
- for (let i = 0; i < __privateGet(this, _data2).length; i++) {
5773
- const key = __privateGet(this, _data2)[i][__privateGet(this, _indexOfKey)];
1246
+ for (let i = 0; i < __privateGet(this, _data).length; i++) {
1247
+ const key = __privateGet(this, _data)[i][__privateGet(this, _indexOfKey)];
5774
1248
  __privateGet(this, _index).set(key, i);
5775
1249
  }
5776
1250
  }
5777
1251
  get data() {
5778
- return __privateGet(this, _data2);
1252
+ return __privateGet(this, _data);
5779
1253
  }
5780
1254
  get map() {
5781
1255
  return __privateGet(this, _dataMap);
@@ -5784,8 +1258,8 @@ var Table = class extends EventEmitter {
5784
1258
  return __privateGet(this, _schema);
5785
1259
  }
5786
1260
  insert(row) {
5787
- const index = __privateGet(this, _data2).length;
5788
- __privateGet(this, _data2).push(row);
1261
+ const index = __privateGet(this, _data).length;
1262
+ __privateGet(this, _data).push(row);
5789
1263
  const key = row[__privateGet(this, _indexOfKey)];
5790
1264
  __privateGet(this, _index).set(key, index);
5791
1265
  this.emit("insert", row);
@@ -5793,33 +1267,33 @@ var Table = class extends EventEmitter {
5793
1267
  findByKey(key) {
5794
1268
  var _a;
5795
1269
  const index = (_a = __privateGet(this, _index).get(key)) != null ? _a : -1;
5796
- return __privateGet(this, _data2)[index];
1270
+ return __privateGet(this, _data)[index];
5797
1271
  }
5798
1272
  update(key, columnName, value) {
5799
- const rowIndex = __privateGet(this, _data2).findIndex(
1273
+ const rowIndex = __privateGet(this, _data).findIndex(
5800
1274
  (row) => row[__privateGet(this, _indexOfKey)] === key
5801
1275
  );
5802
1276
  const colIndex = __privateGet(this, _dataMap)[columnName];
5803
1277
  if (rowIndex !== -1) {
5804
- const row = __privateGet(this, _data2)[rowIndex];
1278
+ const row = __privateGet(this, _data)[rowIndex];
5805
1279
  const newRow = row.slice();
5806
1280
  newRow[colIndex] = value;
5807
- __privateGet(this, _data2)[rowIndex] = newRow;
1281
+ __privateGet(this, _data)[rowIndex] = newRow;
5808
1282
  this.emit("update", newRow, columnName);
5809
1283
  }
5810
1284
  }
5811
1285
  updateRow(row) {
5812
1286
  const key = row[__privateGet(this, _indexOfKey)];
5813
- const rowIndex = __privateGet(this, _data2).findIndex(
1287
+ const rowIndex = __privateGet(this, _data).findIndex(
5814
1288
  (row2) => row2[__privateGet(this, _indexOfKey)] === key
5815
1289
  );
5816
1290
  if (rowIndex !== -1) {
5817
- __privateGet(this, _data2)[rowIndex] = row;
1291
+ __privateGet(this, _data)[rowIndex] = row;
5818
1292
  this.emit("update", row);
5819
1293
  }
5820
1294
  }
5821
1295
  };
5822
- _data2 = new WeakMap();
1296
+ _data = new WeakMap();
5823
1297
  _dataMap = new WeakMap();
5824
1298
  _indexOfKey = new WeakMap();
5825
1299
  _index = new WeakMap();