@vuu-ui/vuu-table 0.7.6-debug → 0.8.0-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
@@ -1,3 +1,76 @@
1
+ var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
4
+ };
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
8
+ };
9
+ var __privateAdd = (obj, member, value) => {
10
+ if (member.has(obj))
11
+ throw TypeError("Cannot add the same private member more than once");
12
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
+ };
14
+ var __privateSet = (obj, member, value, setter) => {
15
+ __accessCheck(obj, member, "write to private field");
16
+ setter ? setter.call(obj, value) : member.set(obj, value);
17
+ return value;
18
+ };
19
+
20
+ // src/ColumnResizer.tsx
21
+ import { useCallback, useRef } from "react";
22
+ import { jsx } from "react/jsx-runtime";
23
+ var NOOP = () => void 0;
24
+ var baseClass = "vuuColumnResizer";
25
+ var ColumnResizer = ({
26
+ onDrag,
27
+ onDragEnd = NOOP,
28
+ onDragStart = NOOP
29
+ }) => {
30
+ const position = useRef(0);
31
+ const onMouseMove = useCallback(
32
+ (e) => {
33
+ if (e.stopPropagation) {
34
+ e.stopPropagation();
35
+ }
36
+ if (e.preventDefault) {
37
+ e.preventDefault();
38
+ }
39
+ const x = Math.round(e.clientX);
40
+ const moveBy = x - position.current;
41
+ position.current = x;
42
+ if (moveBy !== 0) {
43
+ onDrag(e, moveBy);
44
+ }
45
+ },
46
+ [onDrag]
47
+ );
48
+ const onMouseUp = useCallback(
49
+ (e) => {
50
+ window.removeEventListener("mouseup", onMouseUp);
51
+ window.removeEventListener("mousemove", onMouseMove);
52
+ onDragEnd(e);
53
+ },
54
+ [onDragEnd, onMouseMove]
55
+ );
56
+ const handleMouseDown = useCallback(
57
+ (e) => {
58
+ onDragStart(e);
59
+ position.current = Math.round(e.clientX);
60
+ window.addEventListener("mouseup", onMouseUp);
61
+ window.addEventListener("mousemove", onMouseMove);
62
+ if (e.stopPropagation) {
63
+ e.stopPropagation();
64
+ }
65
+ if (e.preventDefault) {
66
+ e.preventDefault();
67
+ }
68
+ },
69
+ [onDragStart, onMouseMove, onMouseUp]
70
+ );
71
+ return /* @__PURE__ */ jsx("div", { className: baseClass, "data-align": "end", onMouseDown: handleMouseDown });
72
+ };
73
+
1
74
  // src/context-menu/buildContextMenuDescriptors.ts
2
75
  import { isNumericColumn } from "@vuu-ui/vuu-utils";
3
76
  var buildContextMenuDescriptors = (dataSource) => (location, options) => {
@@ -16,6 +89,12 @@ var buildContextMenuDescriptors = (dataSource) => (location, options) => {
16
89
  ...buildAggregationMenuItems(options, dataSource)
17
90
  );
18
91
  descriptors.push(...buildColumnDisplayMenuItems(options));
92
+ descriptors.push({
93
+ action: "column-settings",
94
+ icon: "cog",
95
+ label: `Column Settings`,
96
+ options
97
+ });
19
98
  } else if (location === "filter") {
20
99
  const { column, filter } = options;
21
100
  const colIsOnlyFilter = (filter == null ? void 0 : filter.column) === (column == null ? void 0 : column.name);
@@ -217,7 +296,7 @@ function buildGroupMenuItems(options, { groupBy }) {
217
296
  }
218
297
 
219
298
  // src/context-menu/useTableContextMenu.ts
220
- import { removeColumnFromFilter } from "@vuu-ui/vuu-filters";
299
+ import { removeColumnFromFilter } from "@vuu-ui/vuu-utils";
221
300
  import {
222
301
  addGroupColumn,
223
302
  addSortColumn,
@@ -289,6 +368,8 @@ var useTableContextMenu = ({
289
368
  return onPersistentColumnOperation({ type: "pinColumn", column, pin: "right" }), true;
290
369
  case "column-unpin":
291
370
  return onPersistentColumnOperation({ type: "pinColumn", column, pin: void 0 }), true;
371
+ case "column-settings":
372
+ return onPersistentColumnOperation({ type: "columnSettings", column }), true;
292
373
  default:
293
374
  }
294
375
  }
@@ -321,7 +402,7 @@ import {
321
402
  notHidden
322
403
  } from "@vuu-ui/vuu-utils";
323
404
  import cx2 from "classnames";
324
- import { memo as memo2, useCallback as useCallback3 } from "react";
405
+ import { memo as memo2, useCallback as useCallback4 } from "react";
325
406
 
326
407
  // src/TableCell.tsx
327
408
  import { getColumnStyle, metadataKeys } from "@vuu-ui/vuu-utils";
@@ -329,11 +410,11 @@ import { EditableLabel } from "@heswell/salt-lab";
329
410
  import cx from "classnames";
330
411
  import {
331
412
  memo,
332
- useCallback,
333
- useRef,
413
+ useCallback as useCallback2,
414
+ useRef as useRef2,
334
415
  useState
335
416
  } from "react";
336
- import { jsx } from "react/jsx-runtime";
417
+ import { jsx as jsx2 } from "react/jsx-runtime";
337
418
  var { KEY } = metadataKeys;
338
419
  var TableCell = memo(
339
420
  ({
@@ -343,7 +424,7 @@ var TableCell = memo(
343
424
  onClick,
344
425
  row
345
426
  }) => {
346
- const labelFieldRef = useRef(null);
427
+ const labelFieldRef = useRef2(null);
347
428
  const {
348
429
  align,
349
430
  CellRenderer,
@@ -365,7 +446,7 @@ var TableCell = memo(
365
446
  setEditing(true);
366
447
  }
367
448
  };
368
- const handleClick = useCallback(
449
+ const handleClick = useCallback2(
369
450
  (evt) => {
370
451
  onClick == null ? void 0 : onClick(evt, column);
371
452
  },
@@ -394,7 +475,7 @@ var TableCell = memo(
394
475
  "vuuTableCell-resizing": resizing
395
476
  }) || void 0;
396
477
  const style = getColumnStyle(column);
397
- return editable ? /* @__PURE__ */ jsx(
478
+ return editable ? /* @__PURE__ */ jsx2(
398
479
  "div",
399
480
  {
400
481
  className,
@@ -402,7 +483,7 @@ var TableCell = memo(
402
483
  role: "cell",
403
484
  style,
404
485
  onKeyDown: handleTitleKeyDown,
405
- children: /* @__PURE__ */ jsx(
486
+ children: /* @__PURE__ */ jsx2(
406
487
  EditableLabel,
407
488
  {
408
489
  editing,
@@ -418,14 +499,14 @@ var TableCell = memo(
418
499
  "title"
419
500
  )
420
501
  }
421
- ) : /* @__PURE__ */ jsx(
502
+ ) : /* @__PURE__ */ jsx2(
422
503
  "div",
423
504
  {
424
505
  className,
425
506
  role: "cell",
426
507
  style,
427
508
  onClick: handleClick,
428
- children: CellRenderer ? /* @__PURE__ */ jsx(CellRenderer, { column, columnMap, row }) : value
509
+ children: CellRenderer ? /* @__PURE__ */ jsx2(CellRenderer, { column, columnMap, row }) : value
429
510
  }
430
511
  );
431
512
  },
@@ -437,26 +518,18 @@ function cellValuesAreEqual(prev, next) {
437
518
  }
438
519
 
439
520
  // src/TableGroupCell.tsx
440
- import { getColumnStyle as getColumnStyle2, metadataKeys as metadataKeys2 } from "@vuu-ui/vuu-utils";
441
- import { useCallback as useCallback2 } from "react";
442
- import { jsx as jsx2, jsxs } from "react/jsx-runtime";
443
- var { DEPTH, IS_LEAF } = metadataKeys2;
444
- var getGroupValueAndOffset = (columns, row) => {
445
- const { [DEPTH]: depth, [IS_LEAF]: isLeaf } = row;
446
- if (isLeaf || depth > columns.length) {
447
- return [null, depth === null ? 0 : Math.max(0, depth - 1)];
448
- } else if (depth === 0) {
449
- return ["$root", 0];
450
- } else {
451
- const { key, valueFormatter } = columns[depth - 1];
452
- const value = valueFormatter(row[key]);
453
- return [value, depth - 1];
454
- }
455
- };
521
+ import {
522
+ getColumnStyle as getColumnStyle2,
523
+ getGroupValueAndOffset,
524
+ metadataKeys as metadataKeys2
525
+ } from "@vuu-ui/vuu-utils";
526
+ import { useCallback as useCallback3 } from "react";
527
+ import { jsx as jsx3, jsxs } from "react/jsx-runtime";
528
+ var { IS_LEAF } = metadataKeys2;
456
529
  var TableGroupCell = ({ column, onClick, row }) => {
457
530
  const { columns } = column;
458
531
  const [value, offset] = getGroupValueAndOffset(columns, row);
459
- const handleClick = useCallback2(
532
+ const handleClick = useCallback3(
460
533
  (evt) => {
461
534
  onClick == null ? void 0 : onClick(evt, column);
462
535
  },
@@ -464,7 +537,7 @@ var TableGroupCell = ({ column, onClick, row }) => {
464
537
  );
465
538
  const style = getColumnStyle2(column);
466
539
  const isLeaf = row[IS_LEAF];
467
- const spacers = Array(offset).fill(0).map((n, i) => /* @__PURE__ */ jsx2("span", { className: "vuuTableGroupCell-spacer" }, i));
540
+ const spacers = Array(offset).fill(0).map((n, i) => /* @__PURE__ */ jsx3("span", { className: "vuuTableGroupCell-spacer" }, i));
468
541
  return /* @__PURE__ */ jsxs(
469
542
  "div",
470
543
  {
@@ -474,15 +547,15 @@ var TableGroupCell = ({ column, onClick, row }) => {
474
547
  style,
475
548
  children: [
476
549
  spacers,
477
- isLeaf ? null : /* @__PURE__ */ jsx2("span", { className: "vuuTableGroupCell-toggle", "data-icon": "triangle-right" }),
478
- /* @__PURE__ */ jsx2("span", { children: value })
550
+ isLeaf ? null : /* @__PURE__ */ jsx3("span", { className: "vuuTableGroupCell-toggle", "data-icon": "triangle-right" }),
551
+ /* @__PURE__ */ jsx3("span", { children: value })
479
552
  ]
480
553
  }
481
554
  );
482
555
  };
483
556
 
484
557
  // src/TableRow.tsx
485
- import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
558
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
486
559
  var { IDX, IS_EXPANDED, SELECTED } = metadataKeys3;
487
560
  var classBase = "vuuTableRow";
488
561
  var TableRow = memo2(function Row({
@@ -504,7 +577,7 @@ var TableRow = memo2(function Row({
504
577
  [`${classBase}-expanded`]: isExpanded,
505
578
  [`${classBase}-preSelected`]: isSelected === 2
506
579
  });
507
- const handleRowClick = useCallback3(
580
+ const handleRowClick = useCallback4(
508
581
  (evt) => {
509
582
  const rangeSelect = evt.shiftKey;
510
583
  const keepExistingSelection = evt.ctrlKey || evt.metaKey;
@@ -512,7 +585,7 @@ var TableRow = memo2(function Row({
512
585
  },
513
586
  [onClick, row]
514
587
  );
515
- const handleGroupCellClick = useCallback3(
588
+ const handleGroupCellClick = useCallback4(
516
589
  (evt, column) => {
517
590
  if (isGroupColumn(column) || isJsonGroup(column, row)) {
518
591
  evt.stopPropagation();
@@ -533,12 +606,12 @@ var TableRow = memo2(function Row({
533
606
  transform: `translate3d(0px, ${offset}px, 0px)`
534
607
  },
535
608
  children: [
536
- virtualColSpan > 0 ? /* @__PURE__ */ jsx3("div", { role: "cell", style: { width: virtualColSpan } }) : null,
609
+ virtualColSpan > 0 ? /* @__PURE__ */ jsx4("div", { role: "cell", style: { width: virtualColSpan } }) : null,
537
610
  columns.filter(notHidden).map((column) => {
538
611
  const isGroup = isGroupColumn(column);
539
612
  const isJsonCell = isJsonColumn(column);
540
613
  const Cell = isGroup ? TableGroupCell : TableCell;
541
- return /* @__PURE__ */ jsx3(
614
+ return /* @__PURE__ */ jsx4(
542
615
  Cell,
543
616
  {
544
617
  column,
@@ -558,60 +631,6 @@ var TableRow = memo2(function Row({
558
631
  import cx3 from "classnames";
559
632
  import { useRef as useRef4 } from "react";
560
633
 
561
- // src/ColumnResizer.tsx
562
- import { useCallback as useCallback4, useRef as useRef2 } from "react";
563
- import { jsx as jsx4 } from "react/jsx-runtime";
564
- var NOOP = () => void 0;
565
- var baseClass = "vuuColumnResizer";
566
- var ColumnResizer = ({
567
- onDrag,
568
- onDragEnd = NOOP,
569
- onDragStart = NOOP
570
- }) => {
571
- const position = useRef2(0);
572
- const onMouseMove = useCallback4(
573
- (e) => {
574
- if (e.stopPropagation) {
575
- e.stopPropagation();
576
- }
577
- if (e.preventDefault) {
578
- e.preventDefault();
579
- }
580
- const x = Math.round(e.clientX);
581
- const moveBy = x - position.current;
582
- position.current = x;
583
- if (moveBy !== 0) {
584
- onDrag(e, moveBy);
585
- }
586
- },
587
- [onDrag]
588
- );
589
- const onMouseUp = useCallback4(
590
- (e) => {
591
- window.removeEventListener("mouseup", onMouseUp);
592
- window.removeEventListener("mousemove", onMouseMove);
593
- onDragEnd(e);
594
- },
595
- [onDragEnd, onMouseMove]
596
- );
597
- const handleMouseDown = useCallback4(
598
- (e) => {
599
- onDragStart(e);
600
- position.current = Math.round(e.clientX);
601
- window.addEventListener("mouseup", onMouseUp);
602
- window.addEventListener("mousemove", onMouseMove);
603
- if (e.stopPropagation) {
604
- e.stopPropagation();
605
- }
606
- if (e.preventDefault) {
607
- e.preventDefault();
608
- }
609
- },
610
- [onDragStart, onMouseMove, onMouseUp]
611
- );
612
- return /* @__PURE__ */ jsx4("div", { className: baseClass, "data-align": "end", onMouseDown: handleMouseDown });
613
- };
614
-
615
634
  // src/useTableColumnResize.tsx
616
635
  import { useCallback as useCallback5, useRef as useRef3 } from "react";
617
636
  var useTableColumnResize = ({
@@ -624,6 +643,7 @@ var useTableColumnResize = ({
624
643
  const { name } = column;
625
644
  const handleResizeStart = useCallback5(() => {
626
645
  if (onResize && rootRef.current) {
646
+ console.log("handleResizeStart");
627
647
  const { width } = rootRef.current.getBoundingClientRect();
628
648
  widthRef.current = Math.round(width);
629
649
  isResizing.current = true;
@@ -759,204 +779,3261 @@ var FilterIndicator = ({ column, filter }) => {
759
779
  "data-icon": "filter",
760
780
  onClick: handleClick
761
781
  }
762
- );
782
+ );
783
+ };
784
+
785
+ // src/TableHeaderCell.tsx
786
+ import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
787
+ var classBase4 = "vuuTable-headerCell";
788
+ var TableHeaderCell = ({
789
+ column,
790
+ className: classNameProp,
791
+ onClick,
792
+ onDragStart,
793
+ onResize,
794
+ ...props
795
+ }) => {
796
+ const rootRef = useRef5(null);
797
+ const { isResizing, ...resizeProps } = useTableColumnResize({
798
+ column,
799
+ onResize,
800
+ rootRef
801
+ });
802
+ const showContextMenu = useContextMenu2();
803
+ const dragTimerRef = useRef5(null);
804
+ const handleContextMenu = (e) => {
805
+ showContextMenu(e, "header", { column });
806
+ };
807
+ const handleClick = useCallback7(
808
+ (evt) => !isResizing && (onClick == null ? void 0 : onClick(evt)),
809
+ [isResizing, onClick]
810
+ );
811
+ const handleMouseDown = useCallback7(
812
+ (evt) => {
813
+ dragTimerRef.current = window.setTimeout(() => {
814
+ onDragStart == null ? void 0 : onDragStart(evt);
815
+ dragTimerRef.current = null;
816
+ }, 500);
817
+ },
818
+ [onDragStart]
819
+ );
820
+ const handleMouseUp = useCallback7(() => {
821
+ if (dragTimerRef.current !== null) {
822
+ window.clearTimeout(dragTimerRef.current);
823
+ dragTimerRef.current = null;
824
+ }
825
+ }, []);
826
+ const className = cx6(classBase4, classNameProp, {
827
+ vuuPinFloating: column.pin === "floating",
828
+ vuuPinLeft: column.pin === "left",
829
+ vuuPinRight: column.pin === "right",
830
+ vuuEndPin: column.endPin,
831
+ [`${classBase4}-resizing`]: column.resizing,
832
+ [`${classBase4}-right`]: column.align === "right"
833
+ });
834
+ return /* @__PURE__ */ jsx8(
835
+ "div",
836
+ {
837
+ className,
838
+ ...props,
839
+ onClick: handleClick,
840
+ onContextMenu: handleContextMenu,
841
+ onMouseDown: handleMouseDown,
842
+ onMouseUp: handleMouseUp,
843
+ ref: rootRef,
844
+ children: /* @__PURE__ */ jsxs5("div", { className: `${classBase4}-inner`, children: [
845
+ /* @__PURE__ */ jsx8(FilterIndicator, { column }),
846
+ /* @__PURE__ */ jsx8("div", { className: `${classBase4}-label`, children: column.label }),
847
+ /* @__PURE__ */ jsx8(SortIndicator, { sorted: column.sorted }),
848
+ column.resizeable !== false ? /* @__PURE__ */ jsx8(ColumnResizer, { ...resizeProps }) : null
849
+ ] })
850
+ }
851
+ );
852
+ };
853
+
854
+ // src/RowBasedTable.tsx
855
+ import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
856
+ var classBase5 = "vuuTable";
857
+ var { RENDER_IDX } = metadataKeys4;
858
+ var RowBasedTable = ({
859
+ columns,
860
+ columnsWithinViewport,
861
+ data,
862
+ getRowOffset,
863
+ headings,
864
+ onColumnResize,
865
+ onHeaderCellDragStart,
866
+ onContextMenu,
867
+ onRemoveColumnFromGroupBy,
868
+ onRowClick,
869
+ onSort,
870
+ onToggleGroup,
871
+ tableId,
872
+ virtualColSpan = 0,
873
+ rowCount
874
+ }) => {
875
+ const handleDragStart = useCallback8(
876
+ (evt) => {
877
+ onHeaderCellDragStart == null ? void 0 : onHeaderCellDragStart(evt);
878
+ },
879
+ [onHeaderCellDragStart]
880
+ );
881
+ const visibleColumns = useMemo(() => {
882
+ return columns.filter(notHidden2);
883
+ }, [columns]);
884
+ const columnMap = useMemo(() => buildColumnMap(columns), [columns]);
885
+ const handleHeaderClick = useCallback8(
886
+ (evt) => {
887
+ var _a;
888
+ const targetElement = evt.target;
889
+ const headerCell = targetElement.closest(
890
+ ".vuuTable-headerCell"
891
+ );
892
+ const colIdx = parseInt((_a = headerCell == null ? void 0 : headerCell.dataset.idx) != null ? _a : "-1");
893
+ const column = visibleColumnAtIndex(columns, colIdx);
894
+ const isAdditive = evt.shiftKey;
895
+ column && onSort(column, isAdditive);
896
+ },
897
+ [columns, onSort]
898
+ );
899
+ return /* @__PURE__ */ jsxs6("div", { "aria-rowcount": rowCount, className: `${classBase5}-table`, role: "table", children: [
900
+ /* @__PURE__ */ jsxs6("div", { className: `${classBase5}-headers`, role: "rowGroup", children: [
901
+ headings.map((colHeaders, i) => /* @__PURE__ */ jsx9("div", { className: "vuuTable-heading", children: colHeaders.map(({ label, width }, j) => /* @__PURE__ */ jsx9("div", { className: "vuuTable-headingCell", style: { width }, children: label }, j)) }, i)),
902
+ /* @__PURE__ */ jsx9("div", { role: "row", children: visibleColumns.map((column, i) => {
903
+ const style = getColumnStyle3(column);
904
+ return isGroupColumn2(column) ? /* @__PURE__ */ jsx9(
905
+ TableGroupHeaderCell,
906
+ {
907
+ column,
908
+ "data-idx": i,
909
+ onRemoveColumn: onRemoveColumnFromGroupBy,
910
+ onResize: onColumnResize,
911
+ role: "columnHeader",
912
+ style
913
+ },
914
+ i
915
+ ) : /* @__PURE__ */ jsx9(
916
+ TableHeaderCell,
917
+ {
918
+ column,
919
+ "data-idx": i,
920
+ id: `${tableId}-${i}`,
921
+ onClick: handleHeaderClick,
922
+ onDragStart: handleDragStart,
923
+ onResize: onColumnResize,
924
+ role: "columnHeader",
925
+ style
926
+ },
927
+ i
928
+ );
929
+ }) })
930
+ ] }),
931
+ /* @__PURE__ */ jsx9(
932
+ "div",
933
+ {
934
+ className: `${classBase5}-body`,
935
+ onContextMenu,
936
+ role: "rowGroup",
937
+ children: data == null ? void 0 : data.map((row) => /* @__PURE__ */ jsx9(
938
+ TableRow,
939
+ {
940
+ columnMap,
941
+ columns: columnsWithinViewport,
942
+ offset: getRowOffset(row),
943
+ onClick: onRowClick,
944
+ virtualColSpan,
945
+ onToggleGroup,
946
+ row
947
+ },
948
+ row[RENDER_IDX]
949
+ ))
950
+ }
951
+ )
952
+ ] });
953
+ };
954
+
955
+ // src/useTable.ts
956
+ import { useContextMenu as usePopupContextMenu } from "@vuu-ui/vuu-popups";
957
+ import {
958
+ applySort,
959
+ buildColumnMap as buildColumnMap2,
960
+ isJsonGroup as isJsonGroup2,
961
+ metadataKeys as metadataKeys10,
962
+ moveItem as moveItem2
963
+ } from "@vuu-ui/vuu-utils";
964
+ import {
965
+ useCallback as useCallback24,
966
+ useEffect as useEffect9,
967
+ useMemo as useMemo8,
968
+ useRef as useRef16,
969
+ useState as useState9
970
+ } from "react";
971
+
972
+ // ../vuu-data-react/src/hooks/useDataSource.ts
973
+ import { getFullRange, metadataKeys as metadataKeys5, WindowRange } from "@vuu-ui/vuu-utils";
974
+ import { useCallback as useCallback9, useEffect, useMemo as useMemo2, useRef as useRef6, useState as useState2 } from "react";
975
+ var { SELECTED: SELECTED2 } = metadataKeys5;
976
+
977
+ // ../vuu-data-react/src/hooks/useServerConnectionStatus.ts
978
+ import { useCallback as useCallback10, useEffect as useEffect2, useState as useState3 } from "react";
979
+ import { ConnectionManager } from "@vuu-ui/vuu-data";
980
+
981
+ // ../vuu-data-react/src/hooks/useServerConnectionQuality.ts
982
+ import { useCallback as useCallback11, useEffect as useEffect3, useState as useState4 } from "react";
983
+ import { ConnectionManager as ConnectionManager2 } from "@vuu-ui/vuu-data";
984
+
985
+ // ../vuu-data-react/src/hooks/useTypeaheadSuggestions.ts
986
+ import { useCallback as useCallback12 } from "react";
987
+ import { makeRpcCall } from "@vuu-ui/vuu-data";
988
+
989
+ // ../../node_modules/@lezer/common/dist/index.js
990
+ var DefaultBufferLength = 1024;
991
+ var nextPropID = 0;
992
+ var Range = class {
993
+ constructor(from, to) {
994
+ this.from = from;
995
+ this.to = to;
996
+ }
997
+ };
998
+ var NodeProp = class {
999
+ /// Create a new node prop type.
1000
+ constructor(config = {}) {
1001
+ this.id = nextPropID++;
1002
+ this.perNode = !!config.perNode;
1003
+ this.deserialize = config.deserialize || (() => {
1004
+ throw new Error("This node type doesn't define a deserialize function");
1005
+ });
1006
+ }
1007
+ /// This is meant to be used with
1008
+ /// [`NodeSet.extend`](#common.NodeSet.extend) or
1009
+ /// [`LRParser.configure`](#lr.ParserConfig.props) to compute
1010
+ /// prop values for each node type in the set. Takes a [match
1011
+ /// object](#common.NodeType^match) or function that returns undefined
1012
+ /// if the node type doesn't get this prop, and the prop's value if
1013
+ /// it does.
1014
+ add(match) {
1015
+ if (this.perNode)
1016
+ throw new RangeError("Can't add per-node props to node types");
1017
+ if (typeof match != "function")
1018
+ match = NodeType.match(match);
1019
+ return (type) => {
1020
+ let result = match(type);
1021
+ return result === void 0 ? null : [this, result];
1022
+ };
1023
+ }
1024
+ };
1025
+ NodeProp.closedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
1026
+ NodeProp.openedBy = new NodeProp({ deserialize: (str) => str.split(" ") });
1027
+ NodeProp.group = new NodeProp({ deserialize: (str) => str.split(" ") });
1028
+ NodeProp.contextHash = new NodeProp({ perNode: true });
1029
+ NodeProp.lookAhead = new NodeProp({ perNode: true });
1030
+ NodeProp.mounted = new NodeProp({ perNode: true });
1031
+ var noProps = /* @__PURE__ */ Object.create(null);
1032
+ var NodeType = class {
1033
+ /// @internal
1034
+ constructor(name, props, id, flags = 0) {
1035
+ this.name = name;
1036
+ this.props = props;
1037
+ this.id = id;
1038
+ this.flags = flags;
1039
+ }
1040
+ /// Define a node type.
1041
+ static define(spec) {
1042
+ let props = spec.props && spec.props.length ? /* @__PURE__ */ Object.create(null) : noProps;
1043
+ let flags = (spec.top ? 1 : 0) | (spec.skipped ? 2 : 0) | (spec.error ? 4 : 0) | (spec.name == null ? 8 : 0);
1044
+ let type = new NodeType(spec.name || "", props, spec.id, flags);
1045
+ if (spec.props)
1046
+ for (let src of spec.props) {
1047
+ if (!Array.isArray(src))
1048
+ src = src(type);
1049
+ if (src) {
1050
+ if (src[0].perNode)
1051
+ throw new RangeError("Can't store a per-node prop on a node type");
1052
+ props[src[0].id] = src[1];
1053
+ }
1054
+ }
1055
+ return type;
1056
+ }
1057
+ /// Retrieves a node prop for this type. Will return `undefined` if
1058
+ /// the prop isn't present on this node.
1059
+ prop(prop) {
1060
+ return this.props[prop.id];
1061
+ }
1062
+ /// True when this is the top node of a grammar.
1063
+ get isTop() {
1064
+ return (this.flags & 1) > 0;
1065
+ }
1066
+ /// True when this node is produced by a skip rule.
1067
+ get isSkipped() {
1068
+ return (this.flags & 2) > 0;
1069
+ }
1070
+ /// Indicates whether this is an error node.
1071
+ get isError() {
1072
+ return (this.flags & 4) > 0;
1073
+ }
1074
+ /// When true, this node type doesn't correspond to a user-declared
1075
+ /// named node, for example because it is used to cache repetition.
1076
+ get isAnonymous() {
1077
+ return (this.flags & 8) > 0;
1078
+ }
1079
+ /// Returns true when this node's name or one of its
1080
+ /// [groups](#common.NodeProp^group) matches the given string.
1081
+ is(name) {
1082
+ if (typeof name == "string") {
1083
+ if (this.name == name)
1084
+ return true;
1085
+ let group = this.prop(NodeProp.group);
1086
+ return group ? group.indexOf(name) > -1 : false;
1087
+ }
1088
+ return this.id == name;
1089
+ }
1090
+ /// Create a function from node types to arbitrary values by
1091
+ /// specifying an object whose property names are node or
1092
+ /// [group](#common.NodeProp^group) names. Often useful with
1093
+ /// [`NodeProp.add`](#common.NodeProp.add). You can put multiple
1094
+ /// names, separated by spaces, in a single property name to map
1095
+ /// multiple node names to a single value.
1096
+ static match(map) {
1097
+ let direct = /* @__PURE__ */ Object.create(null);
1098
+ for (let prop in map)
1099
+ for (let name of prop.split(" "))
1100
+ direct[name] = map[prop];
1101
+ return (node) => {
1102
+ for (let groups = node.prop(NodeProp.group), i = -1; i < (groups ? groups.length : 0); i++) {
1103
+ let found = direct[i < 0 ? node.name : groups[i]];
1104
+ if (found)
1105
+ return found;
1106
+ }
1107
+ };
1108
+ }
1109
+ };
1110
+ NodeType.none = new NodeType(
1111
+ "",
1112
+ /* @__PURE__ */ Object.create(null),
1113
+ 0,
1114
+ 8
1115
+ /* NodeFlag.Anonymous */
1116
+ );
1117
+ var NodeSet = class {
1118
+ /// Create a set with the given types. The `id` property of each
1119
+ /// type should correspond to its position within the array.
1120
+ constructor(types) {
1121
+ this.types = types;
1122
+ for (let i = 0; i < types.length; i++)
1123
+ if (types[i].id != i)
1124
+ throw new RangeError("Node type ids should correspond to array positions when creating a node set");
1125
+ }
1126
+ /// Create a copy of this set with some node properties added. The
1127
+ /// arguments to this method can be created with
1128
+ /// [`NodeProp.add`](#common.NodeProp.add).
1129
+ extend(...props) {
1130
+ let newTypes = [];
1131
+ for (let type of this.types) {
1132
+ let newProps = null;
1133
+ for (let source of props) {
1134
+ let add = source(type);
1135
+ if (add) {
1136
+ if (!newProps)
1137
+ newProps = Object.assign({}, type.props);
1138
+ newProps[add[0].id] = add[1];
1139
+ }
1140
+ }
1141
+ newTypes.push(newProps ? new NodeType(type.name, newProps, type.id, type.flags) : type);
1142
+ }
1143
+ return new NodeSet(newTypes);
1144
+ }
1145
+ };
1146
+ var CachedNode = /* @__PURE__ */ new WeakMap();
1147
+ var CachedInnerNode = /* @__PURE__ */ new WeakMap();
1148
+ var IterMode;
1149
+ (function(IterMode2) {
1150
+ IterMode2[IterMode2["ExcludeBuffers"] = 1] = "ExcludeBuffers";
1151
+ IterMode2[IterMode2["IncludeAnonymous"] = 2] = "IncludeAnonymous";
1152
+ IterMode2[IterMode2["IgnoreMounts"] = 4] = "IgnoreMounts";
1153
+ IterMode2[IterMode2["IgnoreOverlays"] = 8] = "IgnoreOverlays";
1154
+ })(IterMode || (IterMode = {}));
1155
+ var Tree = class {
1156
+ /// Construct a new tree. See also [`Tree.build`](#common.Tree^build).
1157
+ constructor(type, children, positions, length, props) {
1158
+ this.type = type;
1159
+ this.children = children;
1160
+ this.positions = positions;
1161
+ this.length = length;
1162
+ this.props = null;
1163
+ if (props && props.length) {
1164
+ this.props = /* @__PURE__ */ Object.create(null);
1165
+ for (let [prop, value] of props)
1166
+ this.props[typeof prop == "number" ? prop : prop.id] = value;
1167
+ }
1168
+ }
1169
+ /// @internal
1170
+ toString() {
1171
+ let mounted = this.prop(NodeProp.mounted);
1172
+ if (mounted && !mounted.overlay)
1173
+ return mounted.tree.toString();
1174
+ let children = "";
1175
+ for (let ch of this.children) {
1176
+ let str = ch.toString();
1177
+ if (str) {
1178
+ if (children)
1179
+ children += ",";
1180
+ children += str;
1181
+ }
1182
+ }
1183
+ return !this.type.name ? children : (/\W/.test(this.type.name) && !this.type.isError ? JSON.stringify(this.type.name) : this.type.name) + (children.length ? "(" + children + ")" : "");
1184
+ }
1185
+ /// Get a [tree cursor](#common.TreeCursor) positioned at the top of
1186
+ /// the tree. Mode can be used to [control](#common.IterMode) which
1187
+ /// nodes the cursor visits.
1188
+ cursor(mode = 0) {
1189
+ return new TreeCursor(this.topNode, mode);
1190
+ }
1191
+ /// Get a [tree cursor](#common.TreeCursor) pointing into this tree
1192
+ /// at the given position and side (see
1193
+ /// [`moveTo`](#common.TreeCursor.moveTo).
1194
+ cursorAt(pos, side = 0, mode = 0) {
1195
+ let scope = CachedNode.get(this) || this.topNode;
1196
+ let cursor = new TreeCursor(scope);
1197
+ cursor.moveTo(pos, side);
1198
+ CachedNode.set(this, cursor._tree);
1199
+ return cursor;
1200
+ }
1201
+ /// Get a [syntax node](#common.SyntaxNode) object for the top of the
1202
+ /// tree.
1203
+ get topNode() {
1204
+ return new TreeNode(this, 0, 0, null);
1205
+ }
1206
+ /// Get the [syntax node](#common.SyntaxNode) at the given position.
1207
+ /// If `side` is -1, this will move into nodes that end at the
1208
+ /// position. If 1, it'll move into nodes that start at the
1209
+ /// position. With 0, it'll only enter nodes that cover the position
1210
+ /// from both sides.
1211
+ ///
1212
+ /// Note that this will not enter
1213
+ /// [overlays](#common.MountedTree.overlay), and you often want
1214
+ /// [`resolveInner`](#common.Tree.resolveInner) instead.
1215
+ resolve(pos, side = 0) {
1216
+ let node = resolveNode(CachedNode.get(this) || this.topNode, pos, side, false);
1217
+ CachedNode.set(this, node);
1218
+ return node;
1219
+ }
1220
+ /// Like [`resolve`](#common.Tree.resolve), but will enter
1221
+ /// [overlaid](#common.MountedTree.overlay) nodes, producing a syntax node
1222
+ /// pointing into the innermost overlaid tree at the given position
1223
+ /// (with parent links going through all parent structure, including
1224
+ /// the host trees).
1225
+ resolveInner(pos, side = 0) {
1226
+ let node = resolveNode(CachedInnerNode.get(this) || this.topNode, pos, side, true);
1227
+ CachedInnerNode.set(this, node);
1228
+ return node;
1229
+ }
1230
+ /// Iterate over the tree and its children, calling `enter` for any
1231
+ /// node that touches the `from`/`to` region (if given) before
1232
+ /// running over such a node's children, and `leave` (if given) when
1233
+ /// leaving the node. When `enter` returns `false`, that node will
1234
+ /// not have its children iterated over (or `leave` called).
1235
+ iterate(spec) {
1236
+ let { enter, leave, from = 0, to = this.length } = spec;
1237
+ let mode = spec.mode || 0, anon = (mode & IterMode.IncludeAnonymous) > 0;
1238
+ for (let c = this.cursor(mode | IterMode.IncludeAnonymous); ; ) {
1239
+ let entered = false;
1240
+ if (c.from <= to && c.to >= from && (!anon && c.type.isAnonymous || enter(c) !== false)) {
1241
+ if (c.firstChild())
1242
+ continue;
1243
+ entered = true;
1244
+ }
1245
+ for (; ; ) {
1246
+ if (entered && leave && (anon || !c.type.isAnonymous))
1247
+ leave(c);
1248
+ if (c.nextSibling())
1249
+ break;
1250
+ if (!c.parent())
1251
+ return;
1252
+ entered = true;
1253
+ }
1254
+ }
1255
+ }
1256
+ /// Get the value of the given [node prop](#common.NodeProp) for this
1257
+ /// node. Works with both per-node and per-type props.
1258
+ prop(prop) {
1259
+ return !prop.perNode ? this.type.prop(prop) : this.props ? this.props[prop.id] : void 0;
1260
+ }
1261
+ /// Returns the node's [per-node props](#common.NodeProp.perNode) in a
1262
+ /// format that can be passed to the [`Tree`](#common.Tree)
1263
+ /// constructor.
1264
+ get propValues() {
1265
+ let result = [];
1266
+ if (this.props)
1267
+ for (let id in this.props)
1268
+ result.push([+id, this.props[id]]);
1269
+ return result;
1270
+ }
1271
+ /// Balance the direct children of this tree, producing a copy of
1272
+ /// which may have children grouped into subtrees with type
1273
+ /// [`NodeType.none`](#common.NodeType^none).
1274
+ balance(config = {}) {
1275
+ return this.children.length <= 8 ? this : balanceRange(NodeType.none, this.children, this.positions, 0, this.children.length, 0, this.length, (children, positions, length) => new Tree(this.type, children, positions, length, this.propValues), config.makeTree || ((children, positions, length) => new Tree(NodeType.none, children, positions, length)));
1276
+ }
1277
+ /// Build a tree from a postfix-ordered buffer of node information,
1278
+ /// or a cursor over such a buffer.
1279
+ static build(data) {
1280
+ return buildTree(data);
1281
+ }
1282
+ };
1283
+ Tree.empty = new Tree(NodeType.none, [], [], 0);
1284
+ var FlatBufferCursor = class {
1285
+ constructor(buffer, index) {
1286
+ this.buffer = buffer;
1287
+ this.index = index;
1288
+ }
1289
+ get id() {
1290
+ return this.buffer[this.index - 4];
1291
+ }
1292
+ get start() {
1293
+ return this.buffer[this.index - 3];
1294
+ }
1295
+ get end() {
1296
+ return this.buffer[this.index - 2];
1297
+ }
1298
+ get size() {
1299
+ return this.buffer[this.index - 1];
1300
+ }
1301
+ get pos() {
1302
+ return this.index;
1303
+ }
1304
+ next() {
1305
+ this.index -= 4;
1306
+ }
1307
+ fork() {
1308
+ return new FlatBufferCursor(this.buffer, this.index);
1309
+ }
1310
+ };
1311
+ var TreeBuffer = class {
1312
+ /// Create a tree buffer.
1313
+ constructor(buffer, length, set) {
1314
+ this.buffer = buffer;
1315
+ this.length = length;
1316
+ this.set = set;
1317
+ }
1318
+ /// @internal
1319
+ get type() {
1320
+ return NodeType.none;
1321
+ }
1322
+ /// @internal
1323
+ toString() {
1324
+ let result = [];
1325
+ for (let index = 0; index < this.buffer.length; ) {
1326
+ result.push(this.childString(index));
1327
+ index = this.buffer[index + 3];
1328
+ }
1329
+ return result.join(",");
1330
+ }
1331
+ /// @internal
1332
+ childString(index) {
1333
+ let id = this.buffer[index], endIndex = this.buffer[index + 3];
1334
+ let type = this.set.types[id], result = type.name;
1335
+ if (/\W/.test(result) && !type.isError)
1336
+ result = JSON.stringify(result);
1337
+ index += 4;
1338
+ if (endIndex == index)
1339
+ return result;
1340
+ let children = [];
1341
+ while (index < endIndex) {
1342
+ children.push(this.childString(index));
1343
+ index = this.buffer[index + 3];
1344
+ }
1345
+ return result + "(" + children.join(",") + ")";
1346
+ }
1347
+ /// @internal
1348
+ findChild(startIndex, endIndex, dir, pos, side) {
1349
+ let { buffer } = this, pick = -1;
1350
+ for (let i = startIndex; i != endIndex; i = buffer[i + 3]) {
1351
+ if (checkSide(side, pos, buffer[i + 1], buffer[i + 2])) {
1352
+ pick = i;
1353
+ if (dir > 0)
1354
+ break;
1355
+ }
1356
+ }
1357
+ return pick;
1358
+ }
1359
+ /// @internal
1360
+ slice(startI, endI, from) {
1361
+ let b = this.buffer;
1362
+ let copy = new Uint16Array(endI - startI), len = 0;
1363
+ for (let i = startI, j = 0; i < endI; ) {
1364
+ copy[j++] = b[i++];
1365
+ copy[j++] = b[i++] - from;
1366
+ let to = copy[j++] = b[i++] - from;
1367
+ copy[j++] = b[i++] - startI;
1368
+ len = Math.max(len, to);
1369
+ }
1370
+ return new TreeBuffer(copy, len, this.set);
1371
+ }
1372
+ };
1373
+ function checkSide(side, pos, from, to) {
1374
+ switch (side) {
1375
+ case -2:
1376
+ return from < pos;
1377
+ case -1:
1378
+ return to >= pos && from < pos;
1379
+ case 0:
1380
+ return from < pos && to > pos;
1381
+ case 1:
1382
+ return from <= pos && to > pos;
1383
+ case 2:
1384
+ return to > pos;
1385
+ case 4:
1386
+ return true;
1387
+ }
1388
+ }
1389
+ function enterUnfinishedNodesBefore(node, pos) {
1390
+ let scan = node.childBefore(pos);
1391
+ while (scan) {
1392
+ let last = scan.lastChild;
1393
+ if (!last || last.to != scan.to)
1394
+ break;
1395
+ if (last.type.isError && last.from == last.to) {
1396
+ node = scan;
1397
+ scan = last.prevSibling;
1398
+ } else {
1399
+ scan = last;
1400
+ }
1401
+ }
1402
+ return node;
1403
+ }
1404
+ function resolveNode(node, pos, side, overlays) {
1405
+ var _a;
1406
+ while (node.from == node.to || (side < 1 ? node.from >= pos : node.from > pos) || (side > -1 ? node.to <= pos : node.to < pos)) {
1407
+ let parent = !overlays && node instanceof TreeNode && node.index < 0 ? null : node.parent;
1408
+ if (!parent)
1409
+ return node;
1410
+ node = parent;
1411
+ }
1412
+ let mode = overlays ? 0 : IterMode.IgnoreOverlays;
1413
+ if (overlays)
1414
+ for (let scan = node, parent = scan.parent; parent; scan = parent, parent = scan.parent) {
1415
+ if (scan instanceof TreeNode && scan.index < 0 && ((_a = parent.enter(pos, side, mode)) === null || _a === void 0 ? void 0 : _a.from) != scan.from)
1416
+ node = parent;
1417
+ }
1418
+ for (; ; ) {
1419
+ let inner = node.enter(pos, side, mode);
1420
+ if (!inner)
1421
+ return node;
1422
+ node = inner;
1423
+ }
1424
+ }
1425
+ var TreeNode = class {
1426
+ constructor(_tree, from, index, _parent) {
1427
+ this._tree = _tree;
1428
+ this.from = from;
1429
+ this.index = index;
1430
+ this._parent = _parent;
1431
+ }
1432
+ get type() {
1433
+ return this._tree.type;
1434
+ }
1435
+ get name() {
1436
+ return this._tree.type.name;
1437
+ }
1438
+ get to() {
1439
+ return this.from + this._tree.length;
1440
+ }
1441
+ nextChild(i, dir, pos, side, mode = 0) {
1442
+ for (let parent = this; ; ) {
1443
+ for (let { children, positions } = parent._tree, e = dir > 0 ? children.length : -1; i != e; i += dir) {
1444
+ let next = children[i], start = positions[i] + parent.from;
1445
+ if (!checkSide(side, pos, start, start + next.length))
1446
+ continue;
1447
+ if (next instanceof TreeBuffer) {
1448
+ if (mode & IterMode.ExcludeBuffers)
1449
+ continue;
1450
+ let index = next.findChild(0, next.buffer.length, dir, pos - start, side);
1451
+ if (index > -1)
1452
+ return new BufferNode(new BufferContext(parent, next, i, start), null, index);
1453
+ } else if (mode & IterMode.IncludeAnonymous || (!next.type.isAnonymous || hasChild(next))) {
1454
+ let mounted;
1455
+ if (!(mode & IterMode.IgnoreMounts) && next.props && (mounted = next.prop(NodeProp.mounted)) && !mounted.overlay)
1456
+ return new TreeNode(mounted.tree, start, i, parent);
1457
+ let inner = new TreeNode(next, start, i, parent);
1458
+ return mode & IterMode.IncludeAnonymous || !inner.type.isAnonymous ? inner : inner.nextChild(dir < 0 ? next.children.length - 1 : 0, dir, pos, side);
1459
+ }
1460
+ }
1461
+ if (mode & IterMode.IncludeAnonymous || !parent.type.isAnonymous)
1462
+ return null;
1463
+ if (parent.index >= 0)
1464
+ i = parent.index + dir;
1465
+ else
1466
+ i = dir < 0 ? -1 : parent._parent._tree.children.length;
1467
+ parent = parent._parent;
1468
+ if (!parent)
1469
+ return null;
1470
+ }
1471
+ }
1472
+ get firstChild() {
1473
+ return this.nextChild(
1474
+ 0,
1475
+ 1,
1476
+ 0,
1477
+ 4
1478
+ /* Side.DontCare */
1479
+ );
1480
+ }
1481
+ get lastChild() {
1482
+ return this.nextChild(
1483
+ this._tree.children.length - 1,
1484
+ -1,
1485
+ 0,
1486
+ 4
1487
+ /* Side.DontCare */
1488
+ );
1489
+ }
1490
+ childAfter(pos) {
1491
+ return this.nextChild(
1492
+ 0,
1493
+ 1,
1494
+ pos,
1495
+ 2
1496
+ /* Side.After */
1497
+ );
1498
+ }
1499
+ childBefore(pos) {
1500
+ return this.nextChild(
1501
+ this._tree.children.length - 1,
1502
+ -1,
1503
+ pos,
1504
+ -2
1505
+ /* Side.Before */
1506
+ );
1507
+ }
1508
+ enter(pos, side, mode = 0) {
1509
+ let mounted;
1510
+ if (!(mode & IterMode.IgnoreOverlays) && (mounted = this._tree.prop(NodeProp.mounted)) && mounted.overlay) {
1511
+ let rPos = pos - this.from;
1512
+ for (let { from, to } of mounted.overlay) {
1513
+ if ((side > 0 ? from <= rPos : from < rPos) && (side < 0 ? to >= rPos : to > rPos))
1514
+ return new TreeNode(mounted.tree, mounted.overlay[0].from + this.from, -1, this);
1515
+ }
1516
+ }
1517
+ return this.nextChild(0, 1, pos, side, mode);
1518
+ }
1519
+ nextSignificantParent() {
1520
+ let val = this;
1521
+ while (val.type.isAnonymous && val._parent)
1522
+ val = val._parent;
1523
+ return val;
1524
+ }
1525
+ get parent() {
1526
+ return this._parent ? this._parent.nextSignificantParent() : null;
1527
+ }
1528
+ get nextSibling() {
1529
+ return this._parent && this.index >= 0 ? this._parent.nextChild(
1530
+ this.index + 1,
1531
+ 1,
1532
+ 0,
1533
+ 4
1534
+ /* Side.DontCare */
1535
+ ) : null;
1536
+ }
1537
+ get prevSibling() {
1538
+ return this._parent && this.index >= 0 ? this._parent.nextChild(
1539
+ this.index - 1,
1540
+ -1,
1541
+ 0,
1542
+ 4
1543
+ /* Side.DontCare */
1544
+ ) : null;
1545
+ }
1546
+ cursor(mode = 0) {
1547
+ return new TreeCursor(this, mode);
1548
+ }
1549
+ get tree() {
1550
+ return this._tree;
1551
+ }
1552
+ toTree() {
1553
+ return this._tree;
1554
+ }
1555
+ resolve(pos, side = 0) {
1556
+ return resolveNode(this, pos, side, false);
1557
+ }
1558
+ resolveInner(pos, side = 0) {
1559
+ return resolveNode(this, pos, side, true);
1560
+ }
1561
+ enterUnfinishedNodesBefore(pos) {
1562
+ return enterUnfinishedNodesBefore(this, pos);
1563
+ }
1564
+ getChild(type, before = null, after = null) {
1565
+ let r = getChildren(this, type, before, after);
1566
+ return r.length ? r[0] : null;
1567
+ }
1568
+ getChildren(type, before = null, after = null) {
1569
+ return getChildren(this, type, before, after);
1570
+ }
1571
+ /// @internal
1572
+ toString() {
1573
+ return this._tree.toString();
1574
+ }
1575
+ get node() {
1576
+ return this;
1577
+ }
1578
+ matchContext(context) {
1579
+ return matchNodeContext(this, context);
1580
+ }
1581
+ };
1582
+ function getChildren(node, type, before, after) {
1583
+ let cur = node.cursor(), result = [];
1584
+ if (!cur.firstChild())
1585
+ return result;
1586
+ if (before != null) {
1587
+ while (!cur.type.is(before))
1588
+ if (!cur.nextSibling())
1589
+ return result;
1590
+ }
1591
+ for (; ; ) {
1592
+ if (after != null && cur.type.is(after))
1593
+ return result;
1594
+ if (cur.type.is(type))
1595
+ result.push(cur.node);
1596
+ if (!cur.nextSibling())
1597
+ return after == null ? result : [];
1598
+ }
1599
+ }
1600
+ function matchNodeContext(node, context, i = context.length - 1) {
1601
+ for (let p = node.parent; i >= 0; p = p.parent) {
1602
+ if (!p)
1603
+ return false;
1604
+ if (!p.type.isAnonymous) {
1605
+ if (context[i] && context[i] != p.name)
1606
+ return false;
1607
+ i--;
1608
+ }
1609
+ }
1610
+ return true;
1611
+ }
1612
+ var BufferContext = class {
1613
+ constructor(parent, buffer, index, start) {
1614
+ this.parent = parent;
1615
+ this.buffer = buffer;
1616
+ this.index = index;
1617
+ this.start = start;
1618
+ }
1619
+ };
1620
+ var BufferNode = class {
1621
+ get name() {
1622
+ return this.type.name;
1623
+ }
1624
+ get from() {
1625
+ return this.context.start + this.context.buffer.buffer[this.index + 1];
1626
+ }
1627
+ get to() {
1628
+ return this.context.start + this.context.buffer.buffer[this.index + 2];
1629
+ }
1630
+ constructor(context, _parent, index) {
1631
+ this.context = context;
1632
+ this._parent = _parent;
1633
+ this.index = index;
1634
+ this.type = context.buffer.set.types[context.buffer.buffer[index]];
1635
+ }
1636
+ child(dir, pos, side) {
1637
+ let { buffer } = this.context;
1638
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.context.start, side);
1639
+ return index < 0 ? null : new BufferNode(this.context, this, index);
1640
+ }
1641
+ get firstChild() {
1642
+ return this.child(
1643
+ 1,
1644
+ 0,
1645
+ 4
1646
+ /* Side.DontCare */
1647
+ );
1648
+ }
1649
+ get lastChild() {
1650
+ return this.child(
1651
+ -1,
1652
+ 0,
1653
+ 4
1654
+ /* Side.DontCare */
1655
+ );
1656
+ }
1657
+ childAfter(pos) {
1658
+ return this.child(
1659
+ 1,
1660
+ pos,
1661
+ 2
1662
+ /* Side.After */
1663
+ );
1664
+ }
1665
+ childBefore(pos) {
1666
+ return this.child(
1667
+ -1,
1668
+ pos,
1669
+ -2
1670
+ /* Side.Before */
1671
+ );
1672
+ }
1673
+ enter(pos, side, mode = 0) {
1674
+ if (mode & IterMode.ExcludeBuffers)
1675
+ return null;
1676
+ let { buffer } = this.context;
1677
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], side > 0 ? 1 : -1, pos - this.context.start, side);
1678
+ return index < 0 ? null : new BufferNode(this.context, this, index);
1679
+ }
1680
+ get parent() {
1681
+ return this._parent || this.context.parent.nextSignificantParent();
1682
+ }
1683
+ externalSibling(dir) {
1684
+ return this._parent ? null : this.context.parent.nextChild(
1685
+ this.context.index + dir,
1686
+ dir,
1687
+ 0,
1688
+ 4
1689
+ /* Side.DontCare */
1690
+ );
1691
+ }
1692
+ get nextSibling() {
1693
+ let { buffer } = this.context;
1694
+ let after = buffer.buffer[this.index + 3];
1695
+ if (after < (this._parent ? buffer.buffer[this._parent.index + 3] : buffer.buffer.length))
1696
+ return new BufferNode(this.context, this._parent, after);
1697
+ return this.externalSibling(1);
1698
+ }
1699
+ get prevSibling() {
1700
+ let { buffer } = this.context;
1701
+ let parentStart = this._parent ? this._parent.index + 4 : 0;
1702
+ if (this.index == parentStart)
1703
+ return this.externalSibling(-1);
1704
+ return new BufferNode(this.context, this._parent, buffer.findChild(
1705
+ parentStart,
1706
+ this.index,
1707
+ -1,
1708
+ 0,
1709
+ 4
1710
+ /* Side.DontCare */
1711
+ ));
1712
+ }
1713
+ cursor(mode = 0) {
1714
+ return new TreeCursor(this, mode);
1715
+ }
1716
+ get tree() {
1717
+ return null;
1718
+ }
1719
+ toTree() {
1720
+ let children = [], positions = [];
1721
+ let { buffer } = this.context;
1722
+ let startI = this.index + 4, endI = buffer.buffer[this.index + 3];
1723
+ if (endI > startI) {
1724
+ let from = buffer.buffer[this.index + 1];
1725
+ children.push(buffer.slice(startI, endI, from));
1726
+ positions.push(0);
1727
+ }
1728
+ return new Tree(this.type, children, positions, this.to - this.from);
1729
+ }
1730
+ resolve(pos, side = 0) {
1731
+ return resolveNode(this, pos, side, false);
1732
+ }
1733
+ resolveInner(pos, side = 0) {
1734
+ return resolveNode(this, pos, side, true);
1735
+ }
1736
+ enterUnfinishedNodesBefore(pos) {
1737
+ return enterUnfinishedNodesBefore(this, pos);
1738
+ }
1739
+ /// @internal
1740
+ toString() {
1741
+ return this.context.buffer.childString(this.index);
1742
+ }
1743
+ getChild(type, before = null, after = null) {
1744
+ let r = getChildren(this, type, before, after);
1745
+ return r.length ? r[0] : null;
1746
+ }
1747
+ getChildren(type, before = null, after = null) {
1748
+ return getChildren(this, type, before, after);
1749
+ }
1750
+ get node() {
1751
+ return this;
1752
+ }
1753
+ matchContext(context) {
1754
+ return matchNodeContext(this, context);
1755
+ }
1756
+ };
1757
+ var TreeCursor = class {
1758
+ /// Shorthand for `.type.name`.
1759
+ get name() {
1760
+ return this.type.name;
1761
+ }
1762
+ /// @internal
1763
+ constructor(node, mode = 0) {
1764
+ this.mode = mode;
1765
+ this.buffer = null;
1766
+ this.stack = [];
1767
+ this.index = 0;
1768
+ this.bufferNode = null;
1769
+ if (node instanceof TreeNode) {
1770
+ this.yieldNode(node);
1771
+ } else {
1772
+ this._tree = node.context.parent;
1773
+ this.buffer = node.context;
1774
+ for (let n = node._parent; n; n = n._parent)
1775
+ this.stack.unshift(n.index);
1776
+ this.bufferNode = node;
1777
+ this.yieldBuf(node.index);
1778
+ }
1779
+ }
1780
+ yieldNode(node) {
1781
+ if (!node)
1782
+ return false;
1783
+ this._tree = node;
1784
+ this.type = node.type;
1785
+ this.from = node.from;
1786
+ this.to = node.to;
1787
+ return true;
1788
+ }
1789
+ yieldBuf(index, type) {
1790
+ this.index = index;
1791
+ let { start, buffer } = this.buffer;
1792
+ this.type = type || buffer.set.types[buffer.buffer[index]];
1793
+ this.from = start + buffer.buffer[index + 1];
1794
+ this.to = start + buffer.buffer[index + 2];
1795
+ return true;
1796
+ }
1797
+ yield(node) {
1798
+ if (!node)
1799
+ return false;
1800
+ if (node instanceof TreeNode) {
1801
+ this.buffer = null;
1802
+ return this.yieldNode(node);
1803
+ }
1804
+ this.buffer = node.context;
1805
+ return this.yieldBuf(node.index, node.type);
1806
+ }
1807
+ /// @internal
1808
+ toString() {
1809
+ return this.buffer ? this.buffer.buffer.childString(this.index) : this._tree.toString();
1810
+ }
1811
+ /// @internal
1812
+ enterChild(dir, pos, side) {
1813
+ if (!this.buffer)
1814
+ return this.yield(this._tree.nextChild(dir < 0 ? this._tree._tree.children.length - 1 : 0, dir, pos, side, this.mode));
1815
+ let { buffer } = this.buffer;
1816
+ let index = buffer.findChild(this.index + 4, buffer.buffer[this.index + 3], dir, pos - this.buffer.start, side);
1817
+ if (index < 0)
1818
+ return false;
1819
+ this.stack.push(this.index);
1820
+ return this.yieldBuf(index);
1821
+ }
1822
+ /// Move the cursor to this node's first child. When this returns
1823
+ /// false, the node has no child, and the cursor has not been moved.
1824
+ firstChild() {
1825
+ return this.enterChild(
1826
+ 1,
1827
+ 0,
1828
+ 4
1829
+ /* Side.DontCare */
1830
+ );
1831
+ }
1832
+ /// Move the cursor to this node's last child.
1833
+ lastChild() {
1834
+ return this.enterChild(
1835
+ -1,
1836
+ 0,
1837
+ 4
1838
+ /* Side.DontCare */
1839
+ );
1840
+ }
1841
+ /// Move the cursor to the first child that ends after `pos`.
1842
+ childAfter(pos) {
1843
+ return this.enterChild(
1844
+ 1,
1845
+ pos,
1846
+ 2
1847
+ /* Side.After */
1848
+ );
1849
+ }
1850
+ /// Move to the last child that starts before `pos`.
1851
+ childBefore(pos) {
1852
+ return this.enterChild(
1853
+ -1,
1854
+ pos,
1855
+ -2
1856
+ /* Side.Before */
1857
+ );
1858
+ }
1859
+ /// Move the cursor to the child around `pos`. If side is -1 the
1860
+ /// child may end at that position, when 1 it may start there. This
1861
+ /// will also enter [overlaid](#common.MountedTree.overlay)
1862
+ /// [mounted](#common.NodeProp^mounted) trees unless `overlays` is
1863
+ /// set to false.
1864
+ enter(pos, side, mode = this.mode) {
1865
+ if (!this.buffer)
1866
+ return this.yield(this._tree.enter(pos, side, mode));
1867
+ return mode & IterMode.ExcludeBuffers ? false : this.enterChild(1, pos, side);
1868
+ }
1869
+ /// Move to the node's parent node, if this isn't the top node.
1870
+ parent() {
1871
+ if (!this.buffer)
1872
+ return this.yieldNode(this.mode & IterMode.IncludeAnonymous ? this._tree._parent : this._tree.parent);
1873
+ if (this.stack.length)
1874
+ return this.yieldBuf(this.stack.pop());
1875
+ let parent = this.mode & IterMode.IncludeAnonymous ? this.buffer.parent : this.buffer.parent.nextSignificantParent();
1876
+ this.buffer = null;
1877
+ return this.yieldNode(parent);
1878
+ }
1879
+ /// @internal
1880
+ sibling(dir) {
1881
+ if (!this.buffer)
1882
+ 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));
1883
+ let { buffer } = this.buffer, d = this.stack.length - 1;
1884
+ if (dir < 0) {
1885
+ let parentStart = d < 0 ? 0 : this.stack[d] + 4;
1886
+ if (this.index != parentStart)
1887
+ return this.yieldBuf(buffer.findChild(
1888
+ parentStart,
1889
+ this.index,
1890
+ -1,
1891
+ 0,
1892
+ 4
1893
+ /* Side.DontCare */
1894
+ ));
1895
+ } else {
1896
+ let after = buffer.buffer[this.index + 3];
1897
+ if (after < (d < 0 ? buffer.buffer.length : buffer.buffer[this.stack[d] + 3]))
1898
+ return this.yieldBuf(after);
1899
+ }
1900
+ return d < 0 ? this.yield(this.buffer.parent.nextChild(this.buffer.index + dir, dir, 0, 4, this.mode)) : false;
1901
+ }
1902
+ /// Move to this node's next sibling, if any.
1903
+ nextSibling() {
1904
+ return this.sibling(1);
1905
+ }
1906
+ /// Move to this node's previous sibling, if any.
1907
+ prevSibling() {
1908
+ return this.sibling(-1);
1909
+ }
1910
+ atLastNode(dir) {
1911
+ let index, parent, { buffer } = this;
1912
+ if (buffer) {
1913
+ if (dir > 0) {
1914
+ if (this.index < buffer.buffer.buffer.length)
1915
+ return false;
1916
+ } else {
1917
+ for (let i = 0; i < this.index; i++)
1918
+ if (buffer.buffer.buffer[i + 3] < this.index)
1919
+ return false;
1920
+ }
1921
+ ({ index, parent } = buffer);
1922
+ } else {
1923
+ ({ index, _parent: parent } = this._tree);
1924
+ }
1925
+ for (; parent; { index, _parent: parent } = parent) {
1926
+ if (index > -1)
1927
+ for (let i = index + dir, e = dir < 0 ? -1 : parent._tree.children.length; i != e; i += dir) {
1928
+ let child = parent._tree.children[i];
1929
+ if (this.mode & IterMode.IncludeAnonymous || child instanceof TreeBuffer || !child.type.isAnonymous || hasChild(child))
1930
+ return false;
1931
+ }
1932
+ }
1933
+ return true;
1934
+ }
1935
+ move(dir, enter) {
1936
+ if (enter && this.enterChild(
1937
+ dir,
1938
+ 0,
1939
+ 4
1940
+ /* Side.DontCare */
1941
+ ))
1942
+ return true;
1943
+ for (; ; ) {
1944
+ if (this.sibling(dir))
1945
+ return true;
1946
+ if (this.atLastNode(dir) || !this.parent())
1947
+ return false;
1948
+ }
1949
+ }
1950
+ /// Move to the next node in a
1951
+ /// [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
1952
+ /// traversal, going from a node to its first child or, if the
1953
+ /// current node is empty or `enter` is false, its next sibling or
1954
+ /// the next sibling of the first parent node that has one.
1955
+ next(enter = true) {
1956
+ return this.move(1, enter);
1957
+ }
1958
+ /// Move to the next node in a last-to-first pre-order traveral. A
1959
+ /// node is followed by its last child or, if it has none, its
1960
+ /// previous sibling or the previous sibling of the first parent
1961
+ /// node that has one.
1962
+ prev(enter = true) {
1963
+ return this.move(-1, enter);
1964
+ }
1965
+ /// Move the cursor to the innermost node that covers `pos`. If
1966
+ /// `side` is -1, it will enter nodes that end at `pos`. If it is 1,
1967
+ /// it will enter nodes that start at `pos`.
1968
+ moveTo(pos, side = 0) {
1969
+ while (this.from == this.to || (side < 1 ? this.from >= pos : this.from > pos) || (side > -1 ? this.to <= pos : this.to < pos))
1970
+ if (!this.parent())
1971
+ break;
1972
+ while (this.enterChild(1, pos, side)) {
1973
+ }
1974
+ return this;
1975
+ }
1976
+ /// Get a [syntax node](#common.SyntaxNode) at the cursor's current
1977
+ /// position.
1978
+ get node() {
1979
+ if (!this.buffer)
1980
+ return this._tree;
1981
+ let cache = this.bufferNode, result = null, depth = 0;
1982
+ if (cache && cache.context == this.buffer) {
1983
+ scan:
1984
+ for (let index = this.index, d = this.stack.length; d >= 0; ) {
1985
+ for (let c = cache; c; c = c._parent)
1986
+ if (c.index == index) {
1987
+ if (index == this.index)
1988
+ return c;
1989
+ result = c;
1990
+ depth = d + 1;
1991
+ break scan;
1992
+ }
1993
+ index = this.stack[--d];
1994
+ }
1995
+ }
1996
+ for (let i = depth; i < this.stack.length; i++)
1997
+ result = new BufferNode(this.buffer, result, this.stack[i]);
1998
+ return this.bufferNode = new BufferNode(this.buffer, result, this.index);
1999
+ }
2000
+ /// Get the [tree](#common.Tree) that represents the current node, if
2001
+ /// any. Will return null when the node is in a [tree
2002
+ /// buffer](#common.TreeBuffer).
2003
+ get tree() {
2004
+ return this.buffer ? null : this._tree._tree;
2005
+ }
2006
+ /// Iterate over the current node and all its descendants, calling
2007
+ /// `enter` when entering a node and `leave`, if given, when leaving
2008
+ /// one. When `enter` returns `false`, any children of that node are
2009
+ /// skipped, and `leave` isn't called for it.
2010
+ iterate(enter, leave) {
2011
+ for (let depth = 0; ; ) {
2012
+ let mustLeave = false;
2013
+ if (this.type.isAnonymous || enter(this) !== false) {
2014
+ if (this.firstChild()) {
2015
+ depth++;
2016
+ continue;
2017
+ }
2018
+ if (!this.type.isAnonymous)
2019
+ mustLeave = true;
2020
+ }
2021
+ for (; ; ) {
2022
+ if (mustLeave && leave)
2023
+ leave(this);
2024
+ mustLeave = this.type.isAnonymous;
2025
+ if (this.nextSibling())
2026
+ break;
2027
+ if (!depth)
2028
+ return;
2029
+ this.parent();
2030
+ depth--;
2031
+ mustLeave = true;
2032
+ }
2033
+ }
2034
+ }
2035
+ /// Test whether the current node matches a given context—a sequence
2036
+ /// of direct parent node names. Empty strings in the context array
2037
+ /// are treated as wildcards.
2038
+ matchContext(context) {
2039
+ if (!this.buffer)
2040
+ return matchNodeContext(this.node, context);
2041
+ let { buffer } = this.buffer, { types } = buffer.set;
2042
+ for (let i = context.length - 1, d = this.stack.length - 1; i >= 0; d--) {
2043
+ if (d < 0)
2044
+ return matchNodeContext(this.node, context, i);
2045
+ let type = types[buffer.buffer[this.stack[d]]];
2046
+ if (!type.isAnonymous) {
2047
+ if (context[i] && context[i] != type.name)
2048
+ return false;
2049
+ i--;
2050
+ }
2051
+ }
2052
+ return true;
2053
+ }
2054
+ };
2055
+ function hasChild(tree) {
2056
+ return tree.children.some((ch) => ch instanceof TreeBuffer || !ch.type.isAnonymous || hasChild(ch));
2057
+ }
2058
+ function buildTree(data) {
2059
+ var _a;
2060
+ let { buffer, nodeSet, maxBufferLength = DefaultBufferLength, reused = [], minRepeatType = nodeSet.types.length } = data;
2061
+ let cursor = Array.isArray(buffer) ? new FlatBufferCursor(buffer, buffer.length) : buffer;
2062
+ let types = nodeSet.types;
2063
+ let contextHash = 0, lookAhead = 0;
2064
+ function takeNode(parentStart, minPos, children2, positions2, inRepeat) {
2065
+ let { id, start, end, size } = cursor;
2066
+ let lookAheadAtStart = lookAhead;
2067
+ while (size < 0) {
2068
+ cursor.next();
2069
+ if (size == -1) {
2070
+ let node2 = reused[id];
2071
+ children2.push(node2);
2072
+ positions2.push(start - parentStart);
2073
+ return;
2074
+ } else if (size == -3) {
2075
+ contextHash = id;
2076
+ return;
2077
+ } else if (size == -4) {
2078
+ lookAhead = id;
2079
+ return;
2080
+ } else {
2081
+ throw new RangeError(`Unrecognized record size: ${size}`);
2082
+ }
2083
+ }
2084
+ let type = types[id], node, buffer2;
2085
+ let startPos = start - parentStart;
2086
+ if (end - start <= maxBufferLength && (buffer2 = findBufferSize(cursor.pos - minPos, inRepeat))) {
2087
+ let data2 = new Uint16Array(buffer2.size - buffer2.skip);
2088
+ let endPos = cursor.pos - buffer2.size, index = data2.length;
2089
+ while (cursor.pos > endPos)
2090
+ index = copyToBuffer(buffer2.start, data2, index);
2091
+ node = new TreeBuffer(data2, end - buffer2.start, nodeSet);
2092
+ startPos = buffer2.start - parentStart;
2093
+ } else {
2094
+ let endPos = cursor.pos - size;
2095
+ cursor.next();
2096
+ let localChildren = [], localPositions = [];
2097
+ let localInRepeat = id >= minRepeatType ? id : -1;
2098
+ let lastGroup = 0, lastEnd = end;
2099
+ while (cursor.pos > endPos) {
2100
+ if (localInRepeat >= 0 && cursor.id == localInRepeat && cursor.size >= 0) {
2101
+ if (cursor.end <= lastEnd - maxBufferLength) {
2102
+ makeRepeatLeaf(localChildren, localPositions, start, lastGroup, cursor.end, lastEnd, localInRepeat, lookAheadAtStart);
2103
+ lastGroup = localChildren.length;
2104
+ lastEnd = cursor.end;
2105
+ }
2106
+ cursor.next();
2107
+ } else {
2108
+ takeNode(start, endPos, localChildren, localPositions, localInRepeat);
2109
+ }
2110
+ }
2111
+ if (localInRepeat >= 0 && lastGroup > 0 && lastGroup < localChildren.length)
2112
+ makeRepeatLeaf(localChildren, localPositions, start, lastGroup, start, lastEnd, localInRepeat, lookAheadAtStart);
2113
+ localChildren.reverse();
2114
+ localPositions.reverse();
2115
+ if (localInRepeat > -1 && lastGroup > 0) {
2116
+ let make = makeBalanced(type);
2117
+ node = balanceRange(type, localChildren, localPositions, 0, localChildren.length, 0, end - start, make, make);
2118
+ } else {
2119
+ node = makeTree(type, localChildren, localPositions, end - start, lookAheadAtStart - end);
2120
+ }
2121
+ }
2122
+ children2.push(node);
2123
+ positions2.push(startPos);
2124
+ }
2125
+ function makeBalanced(type) {
2126
+ return (children2, positions2, length2) => {
2127
+ let lookAhead2 = 0, lastI = children2.length - 1, last, lookAheadProp;
2128
+ if (lastI >= 0 && (last = children2[lastI]) instanceof Tree) {
2129
+ if (!lastI && last.type == type && last.length == length2)
2130
+ return last;
2131
+ if (lookAheadProp = last.prop(NodeProp.lookAhead))
2132
+ lookAhead2 = positions2[lastI] + last.length + lookAheadProp;
2133
+ }
2134
+ return makeTree(type, children2, positions2, length2, lookAhead2);
2135
+ };
2136
+ }
2137
+ function makeRepeatLeaf(children2, positions2, base, i, from, to, type, lookAhead2) {
2138
+ let localChildren = [], localPositions = [];
2139
+ while (children2.length > i) {
2140
+ localChildren.push(children2.pop());
2141
+ localPositions.push(positions2.pop() + base - from);
2142
+ }
2143
+ children2.push(makeTree(nodeSet.types[type], localChildren, localPositions, to - from, lookAhead2 - to));
2144
+ positions2.push(from - base);
2145
+ }
2146
+ function makeTree(type, children2, positions2, length2, lookAhead2 = 0, props) {
2147
+ if (contextHash) {
2148
+ let pair2 = [NodeProp.contextHash, contextHash];
2149
+ props = props ? [pair2].concat(props) : [pair2];
2150
+ }
2151
+ if (lookAhead2 > 25) {
2152
+ let pair2 = [NodeProp.lookAhead, lookAhead2];
2153
+ props = props ? [pair2].concat(props) : [pair2];
2154
+ }
2155
+ return new Tree(type, children2, positions2, length2, props);
2156
+ }
2157
+ function findBufferSize(maxSize, inRepeat) {
2158
+ let fork = cursor.fork();
2159
+ let size = 0, start = 0, skip = 0, minStart = fork.end - maxBufferLength;
2160
+ let result = { size: 0, start: 0, skip: 0 };
2161
+ scan:
2162
+ for (let minPos = fork.pos - maxSize; fork.pos > minPos; ) {
2163
+ let nodeSize2 = fork.size;
2164
+ if (fork.id == inRepeat && nodeSize2 >= 0) {
2165
+ result.size = size;
2166
+ result.start = start;
2167
+ result.skip = skip;
2168
+ skip += 4;
2169
+ size += 4;
2170
+ fork.next();
2171
+ continue;
2172
+ }
2173
+ let startPos = fork.pos - nodeSize2;
2174
+ if (nodeSize2 < 0 || startPos < minPos || fork.start < minStart)
2175
+ break;
2176
+ let localSkipped = fork.id >= minRepeatType ? 4 : 0;
2177
+ let nodeStart = fork.start;
2178
+ fork.next();
2179
+ while (fork.pos > startPos) {
2180
+ if (fork.size < 0) {
2181
+ if (fork.size == -3)
2182
+ localSkipped += 4;
2183
+ else
2184
+ break scan;
2185
+ } else if (fork.id >= minRepeatType) {
2186
+ localSkipped += 4;
2187
+ }
2188
+ fork.next();
2189
+ }
2190
+ start = nodeStart;
2191
+ size += nodeSize2;
2192
+ skip += localSkipped;
2193
+ }
2194
+ if (inRepeat < 0 || size == maxSize) {
2195
+ result.size = size;
2196
+ result.start = start;
2197
+ result.skip = skip;
2198
+ }
2199
+ return result.size > 4 ? result : void 0;
2200
+ }
2201
+ function copyToBuffer(bufferStart, buffer2, index) {
2202
+ let { id, start, end, size } = cursor;
2203
+ cursor.next();
2204
+ if (size >= 0 && id < minRepeatType) {
2205
+ let startIndex = index;
2206
+ if (size > 4) {
2207
+ let endPos = cursor.pos - (size - 4);
2208
+ while (cursor.pos > endPos)
2209
+ index = copyToBuffer(bufferStart, buffer2, index);
2210
+ }
2211
+ buffer2[--index] = startIndex;
2212
+ buffer2[--index] = end - bufferStart;
2213
+ buffer2[--index] = start - bufferStart;
2214
+ buffer2[--index] = id;
2215
+ } else if (size == -3) {
2216
+ contextHash = id;
2217
+ } else if (size == -4) {
2218
+ lookAhead = id;
2219
+ }
2220
+ return index;
2221
+ }
2222
+ let children = [], positions = [];
2223
+ while (cursor.pos > 0)
2224
+ takeNode(data.start || 0, data.bufferStart || 0, children, positions, -1);
2225
+ let length = (_a = data.length) !== null && _a !== void 0 ? _a : children.length ? positions[0] + children[0].length : 0;
2226
+ return new Tree(types[data.topID], children.reverse(), positions.reverse(), length);
2227
+ }
2228
+ var nodeSizeCache = /* @__PURE__ */ new WeakMap();
2229
+ function nodeSize(balanceType, node) {
2230
+ if (!balanceType.isAnonymous || node instanceof TreeBuffer || node.type != balanceType)
2231
+ return 1;
2232
+ let size = nodeSizeCache.get(node);
2233
+ if (size == null) {
2234
+ size = 1;
2235
+ for (let child of node.children) {
2236
+ if (child.type != balanceType || !(child instanceof Tree)) {
2237
+ size = 1;
2238
+ break;
2239
+ }
2240
+ size += nodeSize(balanceType, child);
2241
+ }
2242
+ nodeSizeCache.set(node, size);
2243
+ }
2244
+ return size;
2245
+ }
2246
+ function balanceRange(balanceType, children, positions, from, to, start, length, mkTop, mkTree) {
2247
+ let total = 0;
2248
+ for (let i = from; i < to; i++)
2249
+ total += nodeSize(balanceType, children[i]);
2250
+ let maxChild = Math.ceil(
2251
+ total * 1.5 / 8
2252
+ /* Balance.BranchFactor */
2253
+ );
2254
+ let localChildren = [], localPositions = [];
2255
+ function divide(children2, positions2, from2, to2, offset) {
2256
+ for (let i = from2; i < to2; ) {
2257
+ let groupFrom = i, groupStart = positions2[i], groupSize = nodeSize(balanceType, children2[i]);
2258
+ i++;
2259
+ for (; i < to2; i++) {
2260
+ let nextSize = nodeSize(balanceType, children2[i]);
2261
+ if (groupSize + nextSize >= maxChild)
2262
+ break;
2263
+ groupSize += nextSize;
2264
+ }
2265
+ if (i == groupFrom + 1) {
2266
+ if (groupSize > maxChild) {
2267
+ let only = children2[groupFrom];
2268
+ divide(only.children, only.positions, 0, only.children.length, positions2[groupFrom] + offset);
2269
+ continue;
2270
+ }
2271
+ localChildren.push(children2[groupFrom]);
2272
+ } else {
2273
+ let length2 = positions2[i - 1] + children2[i - 1].length - groupStart;
2274
+ localChildren.push(balanceRange(balanceType, children2, positions2, groupFrom, i, groupStart, length2, null, mkTree));
2275
+ }
2276
+ localPositions.push(groupStart + offset - start);
2277
+ }
2278
+ }
2279
+ divide(children, positions, from, to, 0);
2280
+ return (mkTop || mkTree)(localChildren, localPositions, length);
2281
+ }
2282
+ var Parser = class {
2283
+ /// Start a parse, returning a [partial parse](#common.PartialParse)
2284
+ /// object. [`fragments`](#common.TreeFragment) can be passed in to
2285
+ /// make the parse incremental.
2286
+ ///
2287
+ /// By default, the entire input is parsed. You can pass `ranges`,
2288
+ /// which should be a sorted array of non-empty, non-overlapping
2289
+ /// ranges, to parse only those ranges. The tree returned in that
2290
+ /// case will start at `ranges[0].from`.
2291
+ startParse(input, fragments, ranges) {
2292
+ if (typeof input == "string")
2293
+ input = new StringInput(input);
2294
+ ranges = !ranges ? [new Range(0, input.length)] : ranges.length ? ranges.map((r) => new Range(r.from, r.to)) : [new Range(0, 0)];
2295
+ return this.createParse(input, fragments || [], ranges);
2296
+ }
2297
+ /// Run a full parse, returning the resulting tree.
2298
+ parse(input, fragments, ranges) {
2299
+ let parse = this.startParse(input, fragments, ranges);
2300
+ for (; ; ) {
2301
+ let done = parse.advance();
2302
+ if (done)
2303
+ return done;
2304
+ }
2305
+ }
2306
+ };
2307
+ var StringInput = class {
2308
+ constructor(string) {
2309
+ this.string = string;
2310
+ }
2311
+ get length() {
2312
+ return this.string.length;
2313
+ }
2314
+ chunk(from) {
2315
+ return this.string.slice(from);
2316
+ }
2317
+ get lineChunks() {
2318
+ return false;
2319
+ }
2320
+ read(from, to) {
2321
+ return this.string.slice(from, to);
2322
+ }
2323
+ };
2324
+ var stoppedInner = new NodeProp({ perNode: true });
2325
+
2326
+ // ../../node_modules/@lezer/lr/dist/index.js
2327
+ var Stack = class {
2328
+ /// @internal
2329
+ constructor(p, stack, state, reducePos, pos, score, buffer, bufferBase, curContext, lookAhead = 0, parent) {
2330
+ this.p = p;
2331
+ this.stack = stack;
2332
+ this.state = state;
2333
+ this.reducePos = reducePos;
2334
+ this.pos = pos;
2335
+ this.score = score;
2336
+ this.buffer = buffer;
2337
+ this.bufferBase = bufferBase;
2338
+ this.curContext = curContext;
2339
+ this.lookAhead = lookAhead;
2340
+ this.parent = parent;
2341
+ }
2342
+ /// @internal
2343
+ toString() {
2344
+ return `[${this.stack.filter((_, i) => i % 3 == 0).concat(this.state)}]@${this.pos}${this.score ? "!" + this.score : ""}`;
2345
+ }
2346
+ // Start an empty stack
2347
+ /// @internal
2348
+ static start(p, state, pos = 0) {
2349
+ let cx9 = p.parser.context;
2350
+ return new Stack(p, [], state, pos, pos, 0, [], 0, cx9 ? new StackContext(cx9, cx9.start) : null, 0, null);
2351
+ }
2352
+ /// The stack's current [context](#lr.ContextTracker) value, if
2353
+ /// any. Its type will depend on the context tracker's type
2354
+ /// parameter, or it will be `null` if there is no context
2355
+ /// tracker.
2356
+ get context() {
2357
+ return this.curContext ? this.curContext.context : null;
2358
+ }
2359
+ // Push a state onto the stack, tracking its start position as well
2360
+ // as the buffer base at that point.
2361
+ /// @internal
2362
+ pushState(state, start) {
2363
+ this.stack.push(this.state, start, this.bufferBase + this.buffer.length);
2364
+ this.state = state;
2365
+ }
2366
+ // Apply a reduce action
2367
+ /// @internal
2368
+ reduce(action) {
2369
+ var _a;
2370
+ let depth = action >> 19, type = action & 65535;
2371
+ let { parser: parser2 } = this.p;
2372
+ let dPrec = parser2.dynamicPrecedence(type);
2373
+ if (dPrec)
2374
+ this.score += dPrec;
2375
+ if (depth == 0) {
2376
+ this.pushState(parser2.getGoto(this.state, type, true), this.reducePos);
2377
+ if (type < parser2.minRepeatTerm)
2378
+ this.storeNode(type, this.reducePos, this.reducePos, 4, true);
2379
+ this.reduceContext(type, this.reducePos);
2380
+ return;
2381
+ }
2382
+ let base = this.stack.length - (depth - 1) * 3 - (action & 262144 ? 6 : 0);
2383
+ let start = base ? this.stack[base - 2] : this.p.ranges[0].from, size = this.reducePos - start;
2384
+ if (size >= 2e3 && !((_a = this.p.parser.nodeSet.types[type]) === null || _a === void 0 ? void 0 : _a.isAnonymous)) {
2385
+ if (start == this.p.lastBigReductionStart) {
2386
+ this.p.bigReductionCount++;
2387
+ this.p.lastBigReductionSize = size;
2388
+ } else if (this.p.lastBigReductionSize < size) {
2389
+ this.p.bigReductionCount = 1;
2390
+ this.p.lastBigReductionStart = start;
2391
+ this.p.lastBigReductionSize = size;
2392
+ }
2393
+ }
2394
+ let bufferBase = base ? this.stack[base - 1] : 0, count = this.bufferBase + this.buffer.length - bufferBase;
2395
+ if (type < parser2.minRepeatTerm || action & 131072) {
2396
+ let pos = parser2.stateFlag(
2397
+ this.state,
2398
+ 1
2399
+ /* StateFlag.Skipped */
2400
+ ) ? this.pos : this.reducePos;
2401
+ this.storeNode(type, start, pos, count + 4, true);
2402
+ }
2403
+ if (action & 262144) {
2404
+ this.state = this.stack[base];
2405
+ } else {
2406
+ let baseStateID = this.stack[base - 3];
2407
+ this.state = parser2.getGoto(baseStateID, type, true);
2408
+ }
2409
+ while (this.stack.length > base)
2410
+ this.stack.pop();
2411
+ this.reduceContext(type, start);
2412
+ }
2413
+ // Shift a value into the buffer
2414
+ /// @internal
2415
+ storeNode(term, start, end, size = 4, isReduce = false) {
2416
+ if (term == 0 && (!this.stack.length || this.stack[this.stack.length - 1] < this.buffer.length + this.bufferBase)) {
2417
+ let cur = this, top = this.buffer.length;
2418
+ if (top == 0 && cur.parent) {
2419
+ top = cur.bufferBase - cur.parent.bufferBase;
2420
+ cur = cur.parent;
2421
+ }
2422
+ if (top > 0 && cur.buffer[top - 4] == 0 && cur.buffer[top - 1] > -1) {
2423
+ if (start == end)
2424
+ return;
2425
+ if (cur.buffer[top - 2] >= start) {
2426
+ cur.buffer[top - 2] = end;
2427
+ return;
2428
+ }
2429
+ }
2430
+ }
2431
+ if (!isReduce || this.pos == end) {
2432
+ this.buffer.push(term, start, end, size);
2433
+ } else {
2434
+ let index = this.buffer.length;
2435
+ if (index > 0 && this.buffer[index - 4] != 0)
2436
+ while (index > 0 && this.buffer[index - 2] > end) {
2437
+ this.buffer[index] = this.buffer[index - 4];
2438
+ this.buffer[index + 1] = this.buffer[index - 3];
2439
+ this.buffer[index + 2] = this.buffer[index - 2];
2440
+ this.buffer[index + 3] = this.buffer[index - 1];
2441
+ index -= 4;
2442
+ if (size > 4)
2443
+ size -= 4;
2444
+ }
2445
+ this.buffer[index] = term;
2446
+ this.buffer[index + 1] = start;
2447
+ this.buffer[index + 2] = end;
2448
+ this.buffer[index + 3] = size;
2449
+ }
2450
+ }
2451
+ // Apply a shift action
2452
+ /// @internal
2453
+ shift(action, next, nextEnd) {
2454
+ let start = this.pos;
2455
+ if (action & 131072) {
2456
+ this.pushState(action & 65535, this.pos);
2457
+ } else if ((action & 262144) == 0) {
2458
+ let nextState = action, { parser: parser2 } = this.p;
2459
+ if (nextEnd > this.pos || next <= parser2.maxNode) {
2460
+ this.pos = nextEnd;
2461
+ if (!parser2.stateFlag(
2462
+ nextState,
2463
+ 1
2464
+ /* StateFlag.Skipped */
2465
+ ))
2466
+ this.reducePos = nextEnd;
2467
+ }
2468
+ this.pushState(nextState, start);
2469
+ this.shiftContext(next, start);
2470
+ if (next <= parser2.maxNode)
2471
+ this.buffer.push(next, start, nextEnd, 4);
2472
+ } else {
2473
+ this.pos = nextEnd;
2474
+ this.shiftContext(next, start);
2475
+ if (next <= this.p.parser.maxNode)
2476
+ this.buffer.push(next, start, nextEnd, 4);
2477
+ }
2478
+ }
2479
+ // Apply an action
2480
+ /// @internal
2481
+ apply(action, next, nextEnd) {
2482
+ if (action & 65536)
2483
+ this.reduce(action);
2484
+ else
2485
+ this.shift(action, next, nextEnd);
2486
+ }
2487
+ // Add a prebuilt (reused) node into the buffer.
2488
+ /// @internal
2489
+ useNode(value, next) {
2490
+ let index = this.p.reused.length - 1;
2491
+ if (index < 0 || this.p.reused[index] != value) {
2492
+ this.p.reused.push(value);
2493
+ index++;
2494
+ }
2495
+ let start = this.pos;
2496
+ this.reducePos = this.pos = start + value.length;
2497
+ this.pushState(next, start);
2498
+ this.buffer.push(
2499
+ index,
2500
+ start,
2501
+ this.reducePos,
2502
+ -1
2503
+ /* size == -1 means this is a reused value */
2504
+ );
2505
+ if (this.curContext)
2506
+ this.updateContext(this.curContext.tracker.reuse(this.curContext.context, value, this, this.p.stream.reset(this.pos - value.length)));
2507
+ }
2508
+ // Split the stack. Due to the buffer sharing and the fact
2509
+ // that `this.stack` tends to stay quite shallow, this isn't very
2510
+ // expensive.
2511
+ /// @internal
2512
+ split() {
2513
+ let parent = this;
2514
+ let off = parent.buffer.length;
2515
+ while (off > 0 && parent.buffer[off - 2] > parent.reducePos)
2516
+ off -= 4;
2517
+ let buffer = parent.buffer.slice(off), base = parent.bufferBase + off;
2518
+ while (parent && base == parent.bufferBase)
2519
+ parent = parent.parent;
2520
+ return new Stack(this.p, this.stack.slice(), this.state, this.reducePos, this.pos, this.score, buffer, base, this.curContext, this.lookAhead, parent);
2521
+ }
2522
+ // Try to recover from an error by 'deleting' (ignoring) one token.
2523
+ /// @internal
2524
+ recoverByDelete(next, nextEnd) {
2525
+ let isNode = next <= this.p.parser.maxNode;
2526
+ if (isNode)
2527
+ this.storeNode(next, this.pos, nextEnd, 4);
2528
+ this.storeNode(0, this.pos, nextEnd, isNode ? 8 : 4);
2529
+ this.pos = this.reducePos = nextEnd;
2530
+ this.score -= 190;
2531
+ }
2532
+ /// Check if the given term would be able to be shifted (optionally
2533
+ /// after some reductions) on this stack. This can be useful for
2534
+ /// external tokenizers that want to make sure they only provide a
2535
+ /// given token when it applies.
2536
+ canShift(term) {
2537
+ for (let sim = new SimulatedStack(this); ; ) {
2538
+ let action = this.p.parser.stateSlot(
2539
+ sim.state,
2540
+ 4
2541
+ /* ParseState.DefaultReduce */
2542
+ ) || this.p.parser.hasAction(sim.state, term);
2543
+ if (action == 0)
2544
+ return false;
2545
+ if ((action & 65536) == 0)
2546
+ return true;
2547
+ sim.reduce(action);
2548
+ }
2549
+ }
2550
+ // Apply up to Recover.MaxNext recovery actions that conceptually
2551
+ // inserts some missing token or rule.
2552
+ /// @internal
2553
+ recoverByInsert(next) {
2554
+ if (this.stack.length >= 300)
2555
+ return [];
2556
+ let nextStates = this.p.parser.nextStates(this.state);
2557
+ if (nextStates.length > 4 << 1 || this.stack.length >= 120) {
2558
+ let best = [];
2559
+ for (let i = 0, s; i < nextStates.length; i += 2) {
2560
+ if ((s = nextStates[i + 1]) != this.state && this.p.parser.hasAction(s, next))
2561
+ best.push(nextStates[i], s);
2562
+ }
2563
+ if (this.stack.length < 120)
2564
+ for (let i = 0; best.length < 4 << 1 && i < nextStates.length; i += 2) {
2565
+ let s = nextStates[i + 1];
2566
+ if (!best.some((v, i2) => i2 & 1 && v == s))
2567
+ best.push(nextStates[i], s);
2568
+ }
2569
+ nextStates = best;
2570
+ }
2571
+ let result = [];
2572
+ for (let i = 0; i < nextStates.length && result.length < 4; i += 2) {
2573
+ let s = nextStates[i + 1];
2574
+ if (s == this.state)
2575
+ continue;
2576
+ let stack = this.split();
2577
+ stack.pushState(s, this.pos);
2578
+ stack.storeNode(0, stack.pos, stack.pos, 4, true);
2579
+ stack.shiftContext(nextStates[i], this.pos);
2580
+ stack.score -= 200;
2581
+ result.push(stack);
2582
+ }
2583
+ return result;
2584
+ }
2585
+ // Force a reduce, if possible. Return false if that can't
2586
+ // be done.
2587
+ /// @internal
2588
+ forceReduce() {
2589
+ let reduce = this.p.parser.stateSlot(
2590
+ this.state,
2591
+ 5
2592
+ /* ParseState.ForcedReduce */
2593
+ );
2594
+ if ((reduce & 65536) == 0)
2595
+ return false;
2596
+ let { parser: parser2 } = this.p;
2597
+ if (!parser2.validAction(this.state, reduce)) {
2598
+ let depth = reduce >> 19, term = reduce & 65535;
2599
+ let target = this.stack.length - depth * 3;
2600
+ if (target < 0 || parser2.getGoto(this.stack[target], term, false) < 0)
2601
+ return false;
2602
+ this.storeNode(0, this.reducePos, this.reducePos, 4, true);
2603
+ this.score -= 100;
2604
+ }
2605
+ this.reducePos = this.pos;
2606
+ this.reduce(reduce);
2607
+ return true;
2608
+ }
2609
+ /// @internal
2610
+ forceAll() {
2611
+ while (!this.p.parser.stateFlag(
2612
+ this.state,
2613
+ 2
2614
+ /* StateFlag.Accepting */
2615
+ )) {
2616
+ if (!this.forceReduce()) {
2617
+ this.storeNode(0, this.pos, this.pos, 4, true);
2618
+ break;
2619
+ }
2620
+ }
2621
+ return this;
2622
+ }
2623
+ /// Check whether this state has no further actions (assumed to be a direct descendant of the
2624
+ /// top state, since any other states must be able to continue
2625
+ /// somehow). @internal
2626
+ get deadEnd() {
2627
+ if (this.stack.length != 3)
2628
+ return false;
2629
+ let { parser: parser2 } = this.p;
2630
+ return parser2.data[parser2.stateSlot(
2631
+ this.state,
2632
+ 1
2633
+ /* ParseState.Actions */
2634
+ )] == 65535 && !parser2.stateSlot(
2635
+ this.state,
2636
+ 4
2637
+ /* ParseState.DefaultReduce */
2638
+ );
2639
+ }
2640
+ /// Restart the stack (put it back in its start state). Only safe
2641
+ /// when this.stack.length == 3 (state is directly below the top
2642
+ /// state). @internal
2643
+ restart() {
2644
+ this.state = this.stack[0];
2645
+ this.stack.length = 0;
2646
+ }
2647
+ /// @internal
2648
+ sameState(other) {
2649
+ if (this.state != other.state || this.stack.length != other.stack.length)
2650
+ return false;
2651
+ for (let i = 0; i < this.stack.length; i += 3)
2652
+ if (this.stack[i] != other.stack[i])
2653
+ return false;
2654
+ return true;
2655
+ }
2656
+ /// Get the parser used by this stack.
2657
+ get parser() {
2658
+ return this.p.parser;
2659
+ }
2660
+ /// Test whether a given dialect (by numeric ID, as exported from
2661
+ /// the terms file) is enabled.
2662
+ dialectEnabled(dialectID) {
2663
+ return this.p.parser.dialect.flags[dialectID];
2664
+ }
2665
+ shiftContext(term, start) {
2666
+ if (this.curContext)
2667
+ this.updateContext(this.curContext.tracker.shift(this.curContext.context, term, this, this.p.stream.reset(start)));
2668
+ }
2669
+ reduceContext(term, start) {
2670
+ if (this.curContext)
2671
+ this.updateContext(this.curContext.tracker.reduce(this.curContext.context, term, this, this.p.stream.reset(start)));
2672
+ }
2673
+ /// @internal
2674
+ emitContext() {
2675
+ let last = this.buffer.length - 1;
2676
+ if (last < 0 || this.buffer[last] != -3)
2677
+ this.buffer.push(this.curContext.hash, this.reducePos, this.reducePos, -3);
2678
+ }
2679
+ /// @internal
2680
+ emitLookAhead() {
2681
+ let last = this.buffer.length - 1;
2682
+ if (last < 0 || this.buffer[last] != -4)
2683
+ this.buffer.push(this.lookAhead, this.reducePos, this.reducePos, -4);
2684
+ }
2685
+ updateContext(context) {
2686
+ if (context != this.curContext.context) {
2687
+ let newCx = new StackContext(this.curContext.tracker, context);
2688
+ if (newCx.hash != this.curContext.hash)
2689
+ this.emitContext();
2690
+ this.curContext = newCx;
2691
+ }
2692
+ }
2693
+ /// @internal
2694
+ setLookAhead(lookAhead) {
2695
+ if (lookAhead > this.lookAhead) {
2696
+ this.emitLookAhead();
2697
+ this.lookAhead = lookAhead;
2698
+ }
2699
+ }
2700
+ /// @internal
2701
+ close() {
2702
+ if (this.curContext && this.curContext.tracker.strict)
2703
+ this.emitContext();
2704
+ if (this.lookAhead > 0)
2705
+ this.emitLookAhead();
2706
+ }
2707
+ };
2708
+ var StackContext = class {
2709
+ constructor(tracker, context) {
2710
+ this.tracker = tracker;
2711
+ this.context = context;
2712
+ this.hash = tracker.strict ? tracker.hash(context) : 0;
2713
+ }
2714
+ };
2715
+ var Recover;
2716
+ (function(Recover2) {
2717
+ Recover2[Recover2["Insert"] = 200] = "Insert";
2718
+ Recover2[Recover2["Delete"] = 190] = "Delete";
2719
+ Recover2[Recover2["Reduce"] = 100] = "Reduce";
2720
+ Recover2[Recover2["MaxNext"] = 4] = "MaxNext";
2721
+ Recover2[Recover2["MaxInsertStackDepth"] = 300] = "MaxInsertStackDepth";
2722
+ Recover2[Recover2["DampenInsertStackDepth"] = 120] = "DampenInsertStackDepth";
2723
+ Recover2[Recover2["MinBigReduction"] = 2e3] = "MinBigReduction";
2724
+ })(Recover || (Recover = {}));
2725
+ var SimulatedStack = class {
2726
+ constructor(start) {
2727
+ this.start = start;
2728
+ this.state = start.state;
2729
+ this.stack = start.stack;
2730
+ this.base = this.stack.length;
2731
+ }
2732
+ reduce(action) {
2733
+ let term = action & 65535, depth = action >> 19;
2734
+ if (depth == 0) {
2735
+ if (this.stack == this.start.stack)
2736
+ this.stack = this.stack.slice();
2737
+ this.stack.push(this.state, 0, 0);
2738
+ this.base += 3;
2739
+ } else {
2740
+ this.base -= (depth - 1) * 3;
2741
+ }
2742
+ let goto = this.start.p.parser.getGoto(this.stack[this.base - 3], term, true);
2743
+ this.state = goto;
2744
+ }
2745
+ };
2746
+ var StackBufferCursor = class {
2747
+ constructor(stack, pos, index) {
2748
+ this.stack = stack;
2749
+ this.pos = pos;
2750
+ this.index = index;
2751
+ this.buffer = stack.buffer;
2752
+ if (this.index == 0)
2753
+ this.maybeNext();
2754
+ }
2755
+ static create(stack, pos = stack.bufferBase + stack.buffer.length) {
2756
+ return new StackBufferCursor(stack, pos, pos - stack.bufferBase);
2757
+ }
2758
+ maybeNext() {
2759
+ let next = this.stack.parent;
2760
+ if (next != null) {
2761
+ this.index = this.stack.bufferBase - next.bufferBase;
2762
+ this.stack = next;
2763
+ this.buffer = next.buffer;
2764
+ }
2765
+ }
2766
+ get id() {
2767
+ return this.buffer[this.index - 4];
2768
+ }
2769
+ get start() {
2770
+ return this.buffer[this.index - 3];
2771
+ }
2772
+ get end() {
2773
+ return this.buffer[this.index - 2];
2774
+ }
2775
+ get size() {
2776
+ return this.buffer[this.index - 1];
2777
+ }
2778
+ next() {
2779
+ this.index -= 4;
2780
+ this.pos -= 4;
2781
+ if (this.index == 0)
2782
+ this.maybeNext();
2783
+ }
2784
+ fork() {
2785
+ return new StackBufferCursor(this.stack, this.pos, this.index);
2786
+ }
2787
+ };
2788
+ function decodeArray(input, Type = Uint16Array) {
2789
+ if (typeof input != "string")
2790
+ return input;
2791
+ let array = null;
2792
+ for (let pos = 0, out = 0; pos < input.length; ) {
2793
+ let value = 0;
2794
+ for (; ; ) {
2795
+ let next = input.charCodeAt(pos++), stop = false;
2796
+ if (next == 126) {
2797
+ value = 65535;
2798
+ break;
2799
+ }
2800
+ if (next >= 92)
2801
+ next--;
2802
+ if (next >= 34)
2803
+ next--;
2804
+ let digit = next - 32;
2805
+ if (digit >= 46) {
2806
+ digit -= 46;
2807
+ stop = true;
2808
+ }
2809
+ value += digit;
2810
+ if (stop)
2811
+ break;
2812
+ value *= 46;
2813
+ }
2814
+ if (array)
2815
+ array[out++] = value;
2816
+ else
2817
+ array = new Type(value);
2818
+ }
2819
+ return array;
2820
+ }
2821
+ var CachedToken = class {
2822
+ constructor() {
2823
+ this.start = -1;
2824
+ this.value = -1;
2825
+ this.end = -1;
2826
+ this.extended = -1;
2827
+ this.lookAhead = 0;
2828
+ this.mask = 0;
2829
+ this.context = 0;
2830
+ }
2831
+ };
2832
+ var nullToken = new CachedToken();
2833
+ var InputStream = class {
2834
+ /// @internal
2835
+ constructor(input, ranges) {
2836
+ this.input = input;
2837
+ this.ranges = ranges;
2838
+ this.chunk = "";
2839
+ this.chunkOff = 0;
2840
+ this.chunk2 = "";
2841
+ this.chunk2Pos = 0;
2842
+ this.next = -1;
2843
+ this.token = nullToken;
2844
+ this.rangeIndex = 0;
2845
+ this.pos = this.chunkPos = ranges[0].from;
2846
+ this.range = ranges[0];
2847
+ this.end = ranges[ranges.length - 1].to;
2848
+ this.readNext();
2849
+ }
2850
+ /// @internal
2851
+ resolveOffset(offset, assoc) {
2852
+ let range = this.range, index = this.rangeIndex;
2853
+ let pos = this.pos + offset;
2854
+ while (pos < range.from) {
2855
+ if (!index)
2856
+ return null;
2857
+ let next = this.ranges[--index];
2858
+ pos -= range.from - next.to;
2859
+ range = next;
2860
+ }
2861
+ while (assoc < 0 ? pos > range.to : pos >= range.to) {
2862
+ if (index == this.ranges.length - 1)
2863
+ return null;
2864
+ let next = this.ranges[++index];
2865
+ pos += next.from - range.to;
2866
+ range = next;
2867
+ }
2868
+ return pos;
2869
+ }
2870
+ /// @internal
2871
+ clipPos(pos) {
2872
+ if (pos >= this.range.from && pos < this.range.to)
2873
+ return pos;
2874
+ for (let range of this.ranges)
2875
+ if (range.to > pos)
2876
+ return Math.max(pos, range.from);
2877
+ return this.end;
2878
+ }
2879
+ /// Look at a code unit near the stream position. `.peek(0)` equals
2880
+ /// `.next`, `.peek(-1)` gives you the previous character, and so
2881
+ /// on.
2882
+ ///
2883
+ /// Note that looking around during tokenizing creates dependencies
2884
+ /// on potentially far-away content, which may reduce the
2885
+ /// effectiveness incremental parsing—when looking forward—or even
2886
+ /// cause invalid reparses when looking backward more than 25 code
2887
+ /// units, since the library does not track lookbehind.
2888
+ peek(offset) {
2889
+ let idx = this.chunkOff + offset, pos, result;
2890
+ if (idx >= 0 && idx < this.chunk.length) {
2891
+ pos = this.pos + offset;
2892
+ result = this.chunk.charCodeAt(idx);
2893
+ } else {
2894
+ let resolved = this.resolveOffset(offset, 1);
2895
+ if (resolved == null)
2896
+ return -1;
2897
+ pos = resolved;
2898
+ if (pos >= this.chunk2Pos && pos < this.chunk2Pos + this.chunk2.length) {
2899
+ result = this.chunk2.charCodeAt(pos - this.chunk2Pos);
2900
+ } else {
2901
+ let i = this.rangeIndex, range = this.range;
2902
+ while (range.to <= pos)
2903
+ range = this.ranges[++i];
2904
+ this.chunk2 = this.input.chunk(this.chunk2Pos = pos);
2905
+ if (pos + this.chunk2.length > range.to)
2906
+ this.chunk2 = this.chunk2.slice(0, range.to - pos);
2907
+ result = this.chunk2.charCodeAt(0);
2908
+ }
2909
+ }
2910
+ if (pos >= this.token.lookAhead)
2911
+ this.token.lookAhead = pos + 1;
2912
+ return result;
2913
+ }
2914
+ /// Accept a token. By default, the end of the token is set to the
2915
+ /// current stream position, but you can pass an offset (relative to
2916
+ /// the stream position) to change that.
2917
+ acceptToken(token, endOffset = 0) {
2918
+ let end = endOffset ? this.resolveOffset(endOffset, -1) : this.pos;
2919
+ if (end == null || end < this.token.start)
2920
+ throw new RangeError("Token end out of bounds");
2921
+ this.token.value = token;
2922
+ this.token.end = end;
2923
+ }
2924
+ getChunk() {
2925
+ if (this.pos >= this.chunk2Pos && this.pos < this.chunk2Pos + this.chunk2.length) {
2926
+ let { chunk, chunkPos } = this;
2927
+ this.chunk = this.chunk2;
2928
+ this.chunkPos = this.chunk2Pos;
2929
+ this.chunk2 = chunk;
2930
+ this.chunk2Pos = chunkPos;
2931
+ this.chunkOff = this.pos - this.chunkPos;
2932
+ } else {
2933
+ this.chunk2 = this.chunk;
2934
+ this.chunk2Pos = this.chunkPos;
2935
+ let nextChunk = this.input.chunk(this.pos);
2936
+ let end = this.pos + nextChunk.length;
2937
+ this.chunk = end > this.range.to ? nextChunk.slice(0, this.range.to - this.pos) : nextChunk;
2938
+ this.chunkPos = this.pos;
2939
+ this.chunkOff = 0;
2940
+ }
2941
+ }
2942
+ readNext() {
2943
+ if (this.chunkOff >= this.chunk.length) {
2944
+ this.getChunk();
2945
+ if (this.chunkOff == this.chunk.length)
2946
+ return this.next = -1;
2947
+ }
2948
+ return this.next = this.chunk.charCodeAt(this.chunkOff);
2949
+ }
2950
+ /// Move the stream forward N (defaults to 1) code units. Returns
2951
+ /// the new value of [`next`](#lr.InputStream.next).
2952
+ advance(n = 1) {
2953
+ this.chunkOff += n;
2954
+ while (this.pos + n >= this.range.to) {
2955
+ if (this.rangeIndex == this.ranges.length - 1)
2956
+ return this.setDone();
2957
+ n -= this.range.to - this.pos;
2958
+ this.range = this.ranges[++this.rangeIndex];
2959
+ this.pos = this.range.from;
2960
+ }
2961
+ this.pos += n;
2962
+ if (this.pos >= this.token.lookAhead)
2963
+ this.token.lookAhead = this.pos + 1;
2964
+ return this.readNext();
2965
+ }
2966
+ setDone() {
2967
+ this.pos = this.chunkPos = this.end;
2968
+ this.range = this.ranges[this.rangeIndex = this.ranges.length - 1];
2969
+ this.chunk = "";
2970
+ return this.next = -1;
2971
+ }
2972
+ /// @internal
2973
+ reset(pos, token) {
2974
+ if (token) {
2975
+ this.token = token;
2976
+ token.start = pos;
2977
+ token.lookAhead = pos + 1;
2978
+ token.value = token.extended = -1;
2979
+ } else {
2980
+ this.token = nullToken;
2981
+ }
2982
+ if (this.pos != pos) {
2983
+ this.pos = pos;
2984
+ if (pos == this.end) {
2985
+ this.setDone();
2986
+ return this;
2987
+ }
2988
+ while (pos < this.range.from)
2989
+ this.range = this.ranges[--this.rangeIndex];
2990
+ while (pos >= this.range.to)
2991
+ this.range = this.ranges[++this.rangeIndex];
2992
+ if (pos >= this.chunkPos && pos < this.chunkPos + this.chunk.length) {
2993
+ this.chunkOff = pos - this.chunkPos;
2994
+ } else {
2995
+ this.chunk = "";
2996
+ this.chunkOff = 0;
2997
+ }
2998
+ this.readNext();
2999
+ }
3000
+ return this;
3001
+ }
3002
+ /// @internal
3003
+ read(from, to) {
3004
+ if (from >= this.chunkPos && to <= this.chunkPos + this.chunk.length)
3005
+ return this.chunk.slice(from - this.chunkPos, to - this.chunkPos);
3006
+ if (from >= this.chunk2Pos && to <= this.chunk2Pos + this.chunk2.length)
3007
+ return this.chunk2.slice(from - this.chunk2Pos, to - this.chunk2Pos);
3008
+ if (from >= this.range.from && to <= this.range.to)
3009
+ return this.input.read(from, to);
3010
+ let result = "";
3011
+ for (let r of this.ranges) {
3012
+ if (r.from >= to)
3013
+ break;
3014
+ if (r.to > from)
3015
+ result += this.input.read(Math.max(r.from, from), Math.min(r.to, to));
3016
+ }
3017
+ return result;
3018
+ }
3019
+ };
3020
+ var TokenGroup = class {
3021
+ constructor(data, id) {
3022
+ this.data = data;
3023
+ this.id = id;
3024
+ }
3025
+ token(input, stack) {
3026
+ let { parser: parser2 } = stack.p;
3027
+ readToken(this.data, input, stack, this.id, parser2.data, parser2.tokenPrecTable);
3028
+ }
3029
+ };
3030
+ TokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
3031
+ var LocalTokenGroup = class {
3032
+ constructor(data, precTable, elseToken) {
3033
+ this.precTable = precTable;
3034
+ this.elseToken = elseToken;
3035
+ this.data = typeof data == "string" ? decodeArray(data) : data;
3036
+ }
3037
+ token(input, stack) {
3038
+ let start = input.pos, skipped = 0;
3039
+ for (; ; ) {
3040
+ readToken(this.data, input, stack, 0, this.data, this.precTable);
3041
+ if (input.token.value > -1)
3042
+ break;
3043
+ if (this.elseToken == null)
3044
+ return;
3045
+ if (input.next < 0)
3046
+ break;
3047
+ input.advance();
3048
+ input.reset(input.pos, input.token);
3049
+ skipped++;
3050
+ }
3051
+ if (skipped) {
3052
+ input.reset(start, input.token);
3053
+ input.acceptToken(this.elseToken, skipped);
3054
+ }
3055
+ }
3056
+ };
3057
+ LocalTokenGroup.prototype.contextual = TokenGroup.prototype.fallback = TokenGroup.prototype.extend = false;
3058
+ function readToken(data, input, stack, group, precTable, precOffset) {
3059
+ let state = 0, groupMask = 1 << group, { dialect } = stack.p.parser;
3060
+ scan:
3061
+ for (; ; ) {
3062
+ if ((groupMask & data[state]) == 0)
3063
+ break;
3064
+ let accEnd = data[state + 1];
3065
+ for (let i = state + 3; i < accEnd; i += 2)
3066
+ if ((data[i + 1] & groupMask) > 0) {
3067
+ let term = data[i];
3068
+ if (dialect.allows(term) && (input.token.value == -1 || input.token.value == term || overrides(term, input.token.value, precTable, precOffset))) {
3069
+ input.acceptToken(term);
3070
+ break;
3071
+ }
3072
+ }
3073
+ let next = input.next, low = 0, high = data[state + 2];
3074
+ if (input.next < 0 && high > low && data[accEnd + high * 3 - 3] == 65535 && data[accEnd + high * 3 - 3] == 65535) {
3075
+ state = data[accEnd + high * 3 - 1];
3076
+ continue scan;
3077
+ }
3078
+ for (; low < high; ) {
3079
+ let mid = low + high >> 1;
3080
+ let index = accEnd + mid + (mid << 1);
3081
+ let from = data[index], to = data[index + 1] || 65536;
3082
+ if (next < from)
3083
+ high = mid;
3084
+ else if (next >= to)
3085
+ low = mid + 1;
3086
+ else {
3087
+ state = data[index + 2];
3088
+ input.advance();
3089
+ continue scan;
3090
+ }
3091
+ }
3092
+ break;
3093
+ }
3094
+ }
3095
+ function findOffset(data, start, term) {
3096
+ for (let i = start, next; (next = data[i]) != 65535; i++)
3097
+ if (next == term)
3098
+ return i - start;
3099
+ return -1;
3100
+ }
3101
+ function overrides(token, prev, tableData, tableOffset) {
3102
+ let iPrev = findOffset(tableData, tableOffset, prev);
3103
+ return iPrev < 0 || findOffset(tableData, tableOffset, token) < iPrev;
3104
+ }
3105
+ var verbose = typeof process != "undefined" && process.env && /\bparse\b/.test(process.env.LOG);
3106
+ var stackIDs = null;
3107
+ var Safety;
3108
+ (function(Safety2) {
3109
+ Safety2[Safety2["Margin"] = 25] = "Margin";
3110
+ })(Safety || (Safety = {}));
3111
+ function cutAt(tree, pos, side) {
3112
+ let cursor = tree.cursor(IterMode.IncludeAnonymous);
3113
+ cursor.moveTo(pos);
3114
+ for (; ; ) {
3115
+ if (!(side < 0 ? cursor.childBefore(pos) : cursor.childAfter(pos)))
3116
+ for (; ; ) {
3117
+ if ((side < 0 ? cursor.to < pos : cursor.from > pos) && !cursor.type.isError)
3118
+ return side < 0 ? Math.max(0, Math.min(
3119
+ cursor.to - 1,
3120
+ pos - 25
3121
+ /* Safety.Margin */
3122
+ )) : Math.min(tree.length, Math.max(
3123
+ cursor.from + 1,
3124
+ pos + 25
3125
+ /* Safety.Margin */
3126
+ ));
3127
+ if (side < 0 ? cursor.prevSibling() : cursor.nextSibling())
3128
+ break;
3129
+ if (!cursor.parent())
3130
+ return side < 0 ? 0 : tree.length;
3131
+ }
3132
+ }
3133
+ }
3134
+ var FragmentCursor = class {
3135
+ constructor(fragments, nodeSet) {
3136
+ this.fragments = fragments;
3137
+ this.nodeSet = nodeSet;
3138
+ this.i = 0;
3139
+ this.fragment = null;
3140
+ this.safeFrom = -1;
3141
+ this.safeTo = -1;
3142
+ this.trees = [];
3143
+ this.start = [];
3144
+ this.index = [];
3145
+ this.nextFragment();
3146
+ }
3147
+ nextFragment() {
3148
+ let fr = this.fragment = this.i == this.fragments.length ? null : this.fragments[this.i++];
3149
+ if (fr) {
3150
+ this.safeFrom = fr.openStart ? cutAt(fr.tree, fr.from + fr.offset, 1) - fr.offset : fr.from;
3151
+ this.safeTo = fr.openEnd ? cutAt(fr.tree, fr.to + fr.offset, -1) - fr.offset : fr.to;
3152
+ while (this.trees.length) {
3153
+ this.trees.pop();
3154
+ this.start.pop();
3155
+ this.index.pop();
3156
+ }
3157
+ this.trees.push(fr.tree);
3158
+ this.start.push(-fr.offset);
3159
+ this.index.push(0);
3160
+ this.nextStart = this.safeFrom;
3161
+ } else {
3162
+ this.nextStart = 1e9;
3163
+ }
3164
+ }
3165
+ // `pos` must be >= any previously given `pos` for this cursor
3166
+ nodeAt(pos) {
3167
+ if (pos < this.nextStart)
3168
+ return null;
3169
+ while (this.fragment && this.safeTo <= pos)
3170
+ this.nextFragment();
3171
+ if (!this.fragment)
3172
+ return null;
3173
+ for (; ; ) {
3174
+ let last = this.trees.length - 1;
3175
+ if (last < 0) {
3176
+ this.nextFragment();
3177
+ return null;
3178
+ }
3179
+ let top = this.trees[last], index = this.index[last];
3180
+ if (index == top.children.length) {
3181
+ this.trees.pop();
3182
+ this.start.pop();
3183
+ this.index.pop();
3184
+ continue;
3185
+ }
3186
+ let next = top.children[index];
3187
+ let start = this.start[last] + top.positions[index];
3188
+ if (start > pos) {
3189
+ this.nextStart = start;
3190
+ return null;
3191
+ }
3192
+ if (next instanceof Tree) {
3193
+ if (start == pos) {
3194
+ if (start < this.safeFrom)
3195
+ return null;
3196
+ let end = start + next.length;
3197
+ if (end <= this.safeTo) {
3198
+ let lookAhead = next.prop(NodeProp.lookAhead);
3199
+ if (!lookAhead || end + lookAhead < this.fragment.to)
3200
+ return next;
3201
+ }
3202
+ }
3203
+ this.index[last]++;
3204
+ if (start + next.length >= Math.max(this.safeFrom, pos)) {
3205
+ this.trees.push(next);
3206
+ this.start.push(start);
3207
+ this.index.push(0);
3208
+ }
3209
+ } else {
3210
+ this.index[last]++;
3211
+ this.nextStart = start + next.length;
3212
+ }
3213
+ }
3214
+ }
3215
+ };
3216
+ var TokenCache = class {
3217
+ constructor(parser2, stream) {
3218
+ this.stream = stream;
3219
+ this.tokens = [];
3220
+ this.mainToken = null;
3221
+ this.actions = [];
3222
+ this.tokens = parser2.tokenizers.map((_) => new CachedToken());
3223
+ }
3224
+ getActions(stack) {
3225
+ let actionIndex = 0;
3226
+ let main = null;
3227
+ let { parser: parser2 } = stack.p, { tokenizers } = parser2;
3228
+ let mask = parser2.stateSlot(
3229
+ stack.state,
3230
+ 3
3231
+ /* ParseState.TokenizerMask */
3232
+ );
3233
+ let context = stack.curContext ? stack.curContext.hash : 0;
3234
+ let lookAhead = 0;
3235
+ for (let i = 0; i < tokenizers.length; i++) {
3236
+ if ((1 << i & mask) == 0)
3237
+ continue;
3238
+ let tokenizer = tokenizers[i], token = this.tokens[i];
3239
+ if (main && !tokenizer.fallback)
3240
+ continue;
3241
+ if (tokenizer.contextual || token.start != stack.pos || token.mask != mask || token.context != context) {
3242
+ this.updateCachedToken(token, tokenizer, stack);
3243
+ token.mask = mask;
3244
+ token.context = context;
3245
+ }
3246
+ if (token.lookAhead > token.end + 25)
3247
+ lookAhead = Math.max(token.lookAhead, lookAhead);
3248
+ if (token.value != 0) {
3249
+ let startIndex = actionIndex;
3250
+ if (token.extended > -1)
3251
+ actionIndex = this.addActions(stack, token.extended, token.end, actionIndex);
3252
+ actionIndex = this.addActions(stack, token.value, token.end, actionIndex);
3253
+ if (!tokenizer.extend) {
3254
+ main = token;
3255
+ if (actionIndex > startIndex)
3256
+ break;
3257
+ }
3258
+ }
3259
+ }
3260
+ while (this.actions.length > actionIndex)
3261
+ this.actions.pop();
3262
+ if (lookAhead)
3263
+ stack.setLookAhead(lookAhead);
3264
+ if (!main && stack.pos == this.stream.end) {
3265
+ main = new CachedToken();
3266
+ main.value = stack.p.parser.eofTerm;
3267
+ main.start = main.end = stack.pos;
3268
+ actionIndex = this.addActions(stack, main.value, main.end, actionIndex);
3269
+ }
3270
+ this.mainToken = main;
3271
+ return this.actions;
3272
+ }
3273
+ getMainToken(stack) {
3274
+ if (this.mainToken)
3275
+ return this.mainToken;
3276
+ let main = new CachedToken(), { pos, p } = stack;
3277
+ main.start = pos;
3278
+ main.end = Math.min(pos + 1, p.stream.end);
3279
+ main.value = pos == p.stream.end ? p.parser.eofTerm : 0;
3280
+ return main;
3281
+ }
3282
+ updateCachedToken(token, tokenizer, stack) {
3283
+ let start = this.stream.clipPos(stack.pos);
3284
+ tokenizer.token(this.stream.reset(start, token), stack);
3285
+ if (token.value > -1) {
3286
+ let { parser: parser2 } = stack.p;
3287
+ for (let i = 0; i < parser2.specialized.length; i++)
3288
+ if (parser2.specialized[i] == token.value) {
3289
+ let result = parser2.specializers[i](this.stream.read(token.start, token.end), stack);
3290
+ if (result >= 0 && stack.p.parser.dialect.allows(result >> 1)) {
3291
+ if ((result & 1) == 0)
3292
+ token.value = result >> 1;
3293
+ else
3294
+ token.extended = result >> 1;
3295
+ break;
3296
+ }
3297
+ }
3298
+ } else {
3299
+ token.value = 0;
3300
+ token.end = this.stream.clipPos(start + 1);
3301
+ }
3302
+ }
3303
+ putAction(action, token, end, index) {
3304
+ for (let i = 0; i < index; i += 3)
3305
+ if (this.actions[i] == action)
3306
+ return index;
3307
+ this.actions[index++] = action;
3308
+ this.actions[index++] = token;
3309
+ this.actions[index++] = end;
3310
+ return index;
3311
+ }
3312
+ addActions(stack, token, end, index) {
3313
+ let { state } = stack, { parser: parser2 } = stack.p, { data } = parser2;
3314
+ for (let set = 0; set < 2; set++) {
3315
+ for (let i = parser2.stateSlot(
3316
+ state,
3317
+ set ? 2 : 1
3318
+ /* ParseState.Actions */
3319
+ ); ; i += 3) {
3320
+ if (data[i] == 65535) {
3321
+ if (data[i + 1] == 1) {
3322
+ i = pair(data, i + 2);
3323
+ } else {
3324
+ if (index == 0 && data[i + 1] == 2)
3325
+ index = this.putAction(pair(data, i + 2), token, end, index);
3326
+ break;
3327
+ }
3328
+ }
3329
+ if (data[i] == token)
3330
+ index = this.putAction(pair(data, i + 1), token, end, index);
3331
+ }
3332
+ }
3333
+ return index;
3334
+ }
3335
+ };
3336
+ var Rec;
3337
+ (function(Rec2) {
3338
+ Rec2[Rec2["Distance"] = 5] = "Distance";
3339
+ Rec2[Rec2["MaxRemainingPerStep"] = 3] = "MaxRemainingPerStep";
3340
+ Rec2[Rec2["MinBufferLengthPrune"] = 500] = "MinBufferLengthPrune";
3341
+ Rec2[Rec2["ForceReduceLimit"] = 10] = "ForceReduceLimit";
3342
+ Rec2[Rec2["CutDepth"] = 15e3] = "CutDepth";
3343
+ Rec2[Rec2["CutTo"] = 9e3] = "CutTo";
3344
+ Rec2[Rec2["MaxLeftAssociativeReductionCount"] = 300] = "MaxLeftAssociativeReductionCount";
3345
+ Rec2[Rec2["MaxStackCount"] = 12] = "MaxStackCount";
3346
+ })(Rec || (Rec = {}));
3347
+ var Parse = class {
3348
+ constructor(parser2, input, fragments, ranges) {
3349
+ this.parser = parser2;
3350
+ this.input = input;
3351
+ this.ranges = ranges;
3352
+ this.recovering = 0;
3353
+ this.nextStackID = 9812;
3354
+ this.minStackPos = 0;
3355
+ this.reused = [];
3356
+ this.stoppedAt = null;
3357
+ this.lastBigReductionStart = -1;
3358
+ this.lastBigReductionSize = 0;
3359
+ this.bigReductionCount = 0;
3360
+ this.stream = new InputStream(input, ranges);
3361
+ this.tokens = new TokenCache(parser2, this.stream);
3362
+ this.topTerm = parser2.top[1];
3363
+ let { from } = ranges[0];
3364
+ this.stacks = [Stack.start(this, parser2.top[0], from)];
3365
+ this.fragments = fragments.length && this.stream.end - from > parser2.bufferLength * 4 ? new FragmentCursor(fragments, parser2.nodeSet) : null;
3366
+ }
3367
+ get parsedPos() {
3368
+ return this.minStackPos;
3369
+ }
3370
+ // Move the parser forward. This will process all parse stacks at
3371
+ // `this.pos` and try to advance them to a further position. If no
3372
+ // stack for such a position is found, it'll start error-recovery.
3373
+ //
3374
+ // When the parse is finished, this will return a syntax tree. When
3375
+ // not, it returns `null`.
3376
+ advance() {
3377
+ let stacks = this.stacks, pos = this.minStackPos;
3378
+ let newStacks = this.stacks = [];
3379
+ let stopped, stoppedTokens;
3380
+ if (this.bigReductionCount > 300 && stacks.length == 1) {
3381
+ let [s] = stacks;
3382
+ while (s.forceReduce() && s.stack.length && s.stack[s.stack.length - 2] >= this.lastBigReductionStart) {
3383
+ }
3384
+ this.bigReductionCount = this.lastBigReductionSize = 0;
3385
+ }
3386
+ for (let i = 0; i < stacks.length; i++) {
3387
+ let stack = stacks[i];
3388
+ for (; ; ) {
3389
+ this.tokens.mainToken = null;
3390
+ if (stack.pos > pos) {
3391
+ newStacks.push(stack);
3392
+ } else if (this.advanceStack(stack, newStacks, stacks)) {
3393
+ continue;
3394
+ } else {
3395
+ if (!stopped) {
3396
+ stopped = [];
3397
+ stoppedTokens = [];
3398
+ }
3399
+ stopped.push(stack);
3400
+ let tok = this.tokens.getMainToken(stack);
3401
+ stoppedTokens.push(tok.value, tok.end);
3402
+ }
3403
+ break;
3404
+ }
3405
+ }
3406
+ if (!newStacks.length) {
3407
+ let finished = stopped && findFinished(stopped);
3408
+ if (finished)
3409
+ return this.stackToTree(finished);
3410
+ if (this.parser.strict) {
3411
+ if (verbose && stopped)
3412
+ console.log("Stuck with token " + (this.tokens.mainToken ? this.parser.getName(this.tokens.mainToken.value) : "none"));
3413
+ throw new SyntaxError("No parse at " + pos);
3414
+ }
3415
+ if (!this.recovering)
3416
+ this.recovering = 5;
3417
+ }
3418
+ if (this.recovering && stopped) {
3419
+ let finished = this.stoppedAt != null && stopped[0].pos > this.stoppedAt ? stopped[0] : this.runRecovery(stopped, stoppedTokens, newStacks);
3420
+ if (finished)
3421
+ return this.stackToTree(finished.forceAll());
3422
+ }
3423
+ if (this.recovering) {
3424
+ let maxRemaining = this.recovering == 1 ? 1 : this.recovering * 3;
3425
+ if (newStacks.length > maxRemaining) {
3426
+ newStacks.sort((a, b) => b.score - a.score);
3427
+ while (newStacks.length > maxRemaining)
3428
+ newStacks.pop();
3429
+ }
3430
+ if (newStacks.some((s) => s.reducePos > pos))
3431
+ this.recovering--;
3432
+ } else if (newStacks.length > 1) {
3433
+ outer:
3434
+ for (let i = 0; i < newStacks.length - 1; i++) {
3435
+ let stack = newStacks[i];
3436
+ for (let j = i + 1; j < newStacks.length; j++) {
3437
+ let other = newStacks[j];
3438
+ if (stack.sameState(other) || stack.buffer.length > 500 && other.buffer.length > 500) {
3439
+ if ((stack.score - other.score || stack.buffer.length - other.buffer.length) > 0) {
3440
+ newStacks.splice(j--, 1);
3441
+ } else {
3442
+ newStacks.splice(i--, 1);
3443
+ continue outer;
3444
+ }
3445
+ }
3446
+ }
3447
+ }
3448
+ if (newStacks.length > 12)
3449
+ newStacks.splice(
3450
+ 12,
3451
+ newStacks.length - 12
3452
+ /* Rec.MaxStackCount */
3453
+ );
3454
+ }
3455
+ this.minStackPos = newStacks[0].pos;
3456
+ for (let i = 1; i < newStacks.length; i++)
3457
+ if (newStacks[i].pos < this.minStackPos)
3458
+ this.minStackPos = newStacks[i].pos;
3459
+ return null;
3460
+ }
3461
+ stopAt(pos) {
3462
+ if (this.stoppedAt != null && this.stoppedAt < pos)
3463
+ throw new RangeError("Can't move stoppedAt forward");
3464
+ this.stoppedAt = pos;
3465
+ }
3466
+ // Returns an updated version of the given stack, or null if the
3467
+ // stack can't advance normally. When `split` and `stacks` are
3468
+ // given, stacks split off by ambiguous operations will be pushed to
3469
+ // `split`, or added to `stacks` if they move `pos` forward.
3470
+ advanceStack(stack, stacks, split) {
3471
+ let start = stack.pos, { parser: parser2 } = this;
3472
+ let base = verbose ? this.stackID(stack) + " -> " : "";
3473
+ if (this.stoppedAt != null && start > this.stoppedAt)
3474
+ return stack.forceReduce() ? stack : null;
3475
+ if (this.fragments) {
3476
+ let strictCx = stack.curContext && stack.curContext.tracker.strict, cxHash = strictCx ? stack.curContext.hash : 0;
3477
+ for (let cached = this.fragments.nodeAt(start); cached; ) {
3478
+ let match = this.parser.nodeSet.types[cached.type.id] == cached.type ? parser2.getGoto(stack.state, cached.type.id) : -1;
3479
+ if (match > -1 && cached.length && (!strictCx || (cached.prop(NodeProp.contextHash) || 0) == cxHash)) {
3480
+ stack.useNode(cached, match);
3481
+ if (verbose)
3482
+ console.log(base + this.stackID(stack) + ` (via reuse of ${parser2.getName(cached.type.id)})`);
3483
+ return true;
3484
+ }
3485
+ if (!(cached instanceof Tree) || cached.children.length == 0 || cached.positions[0] > 0)
3486
+ break;
3487
+ let inner = cached.children[0];
3488
+ if (inner instanceof Tree && cached.positions[0] == 0)
3489
+ cached = inner;
3490
+ else
3491
+ break;
3492
+ }
3493
+ }
3494
+ let defaultReduce = parser2.stateSlot(
3495
+ stack.state,
3496
+ 4
3497
+ /* ParseState.DefaultReduce */
3498
+ );
3499
+ if (defaultReduce > 0) {
3500
+ stack.reduce(defaultReduce);
3501
+ if (verbose)
3502
+ console.log(base + this.stackID(stack) + ` (via always-reduce ${parser2.getName(
3503
+ defaultReduce & 65535
3504
+ /* Action.ValueMask */
3505
+ )})`);
3506
+ return true;
3507
+ }
3508
+ if (stack.stack.length >= 15e3) {
3509
+ while (stack.stack.length > 9e3 && stack.forceReduce()) {
3510
+ }
3511
+ }
3512
+ let actions = this.tokens.getActions(stack);
3513
+ for (let i = 0; i < actions.length; ) {
3514
+ let action = actions[i++], term = actions[i++], end = actions[i++];
3515
+ let last = i == actions.length || !split;
3516
+ let localStack = last ? stack : stack.split();
3517
+ localStack.apply(action, term, end);
3518
+ if (verbose)
3519
+ console.log(base + this.stackID(localStack) + ` (via ${(action & 65536) == 0 ? "shift" : `reduce of ${parser2.getName(
3520
+ action & 65535
3521
+ /* Action.ValueMask */
3522
+ )}`} for ${parser2.getName(term)} @ ${start}${localStack == stack ? "" : ", split"})`);
3523
+ if (last)
3524
+ return true;
3525
+ else if (localStack.pos > start)
3526
+ stacks.push(localStack);
3527
+ else
3528
+ split.push(localStack);
3529
+ }
3530
+ return false;
3531
+ }
3532
+ // Advance a given stack forward as far as it will go. Returns the
3533
+ // (possibly updated) stack if it got stuck, or null if it moved
3534
+ // forward and was given to `pushStackDedup`.
3535
+ advanceFully(stack, newStacks) {
3536
+ let pos = stack.pos;
3537
+ for (; ; ) {
3538
+ if (!this.advanceStack(stack, null, null))
3539
+ return false;
3540
+ if (stack.pos > pos) {
3541
+ pushStackDedup(stack, newStacks);
3542
+ return true;
3543
+ }
3544
+ }
3545
+ }
3546
+ runRecovery(stacks, tokens, newStacks) {
3547
+ let finished = null, restarted = false;
3548
+ for (let i = 0; i < stacks.length; i++) {
3549
+ let stack = stacks[i], token = tokens[i << 1], tokenEnd = tokens[(i << 1) + 1];
3550
+ let base = verbose ? this.stackID(stack) + " -> " : "";
3551
+ if (stack.deadEnd) {
3552
+ if (restarted)
3553
+ continue;
3554
+ restarted = true;
3555
+ stack.restart();
3556
+ if (verbose)
3557
+ console.log(base + this.stackID(stack) + " (restarted)");
3558
+ let done = this.advanceFully(stack, newStacks);
3559
+ if (done)
3560
+ continue;
3561
+ }
3562
+ let force = stack.split(), forceBase = base;
3563
+ for (let j = 0; force.forceReduce() && j < 10; j++) {
3564
+ if (verbose)
3565
+ console.log(forceBase + this.stackID(force) + " (via force-reduce)");
3566
+ let done = this.advanceFully(force, newStacks);
3567
+ if (done)
3568
+ break;
3569
+ if (verbose)
3570
+ forceBase = this.stackID(force) + " -> ";
3571
+ }
3572
+ for (let insert of stack.recoverByInsert(token)) {
3573
+ if (verbose)
3574
+ console.log(base + this.stackID(insert) + " (via recover-insert)");
3575
+ this.advanceFully(insert, newStacks);
3576
+ }
3577
+ if (this.stream.end > stack.pos) {
3578
+ if (tokenEnd == stack.pos) {
3579
+ tokenEnd++;
3580
+ token = 0;
3581
+ }
3582
+ stack.recoverByDelete(token, tokenEnd);
3583
+ if (verbose)
3584
+ console.log(base + this.stackID(stack) + ` (via recover-delete ${this.parser.getName(token)})`);
3585
+ pushStackDedup(stack, newStacks);
3586
+ } else if (!finished || finished.score < stack.score) {
3587
+ finished = stack;
3588
+ }
3589
+ }
3590
+ return finished;
3591
+ }
3592
+ // Convert the stack's buffer to a syntax tree.
3593
+ stackToTree(stack) {
3594
+ stack.close();
3595
+ return Tree.build({
3596
+ buffer: StackBufferCursor.create(stack),
3597
+ nodeSet: this.parser.nodeSet,
3598
+ topID: this.topTerm,
3599
+ maxBufferLength: this.parser.bufferLength,
3600
+ reused: this.reused,
3601
+ start: this.ranges[0].from,
3602
+ length: stack.pos - this.ranges[0].from,
3603
+ minRepeatType: this.parser.minRepeatTerm
3604
+ });
3605
+ }
3606
+ stackID(stack) {
3607
+ let id = (stackIDs || (stackIDs = /* @__PURE__ */ new WeakMap())).get(stack);
3608
+ if (!id)
3609
+ stackIDs.set(stack, id = String.fromCodePoint(this.nextStackID++));
3610
+ return id + stack;
3611
+ }
3612
+ };
3613
+ function pushStackDedup(stack, newStacks) {
3614
+ for (let i = 0; i < newStacks.length; i++) {
3615
+ let other = newStacks[i];
3616
+ if (other.pos == stack.pos && other.sameState(stack)) {
3617
+ if (newStacks[i].score < stack.score)
3618
+ newStacks[i] = stack;
3619
+ return;
3620
+ }
3621
+ }
3622
+ newStacks.push(stack);
3623
+ }
3624
+ var Dialect = class {
3625
+ constructor(source, flags, disabled) {
3626
+ this.source = source;
3627
+ this.flags = flags;
3628
+ this.disabled = disabled;
3629
+ }
3630
+ allows(term) {
3631
+ return !this.disabled || this.disabled[term] == 0;
3632
+ }
3633
+ };
3634
+ var LRParser = class extends Parser {
3635
+ /// @internal
3636
+ constructor(spec) {
3637
+ super();
3638
+ this.wrappers = [];
3639
+ if (spec.version != 14)
3640
+ throw new RangeError(`Parser version (${spec.version}) doesn't match runtime version (${14})`);
3641
+ let nodeNames = spec.nodeNames.split(" ");
3642
+ this.minRepeatTerm = nodeNames.length;
3643
+ for (let i = 0; i < spec.repeatNodeCount; i++)
3644
+ nodeNames.push("");
3645
+ let topTerms = Object.keys(spec.topRules).map((r) => spec.topRules[r][1]);
3646
+ let nodeProps = [];
3647
+ for (let i = 0; i < nodeNames.length; i++)
3648
+ nodeProps.push([]);
3649
+ function setProp(nodeID, prop, value) {
3650
+ nodeProps[nodeID].push([prop, prop.deserialize(String(value))]);
3651
+ }
3652
+ if (spec.nodeProps)
3653
+ for (let propSpec of spec.nodeProps) {
3654
+ let prop = propSpec[0];
3655
+ if (typeof prop == "string")
3656
+ prop = NodeProp[prop];
3657
+ for (let i = 1; i < propSpec.length; ) {
3658
+ let next = propSpec[i++];
3659
+ if (next >= 0) {
3660
+ setProp(next, prop, propSpec[i++]);
3661
+ } else {
3662
+ let value = propSpec[i + -next];
3663
+ for (let j = -next; j > 0; j--)
3664
+ setProp(propSpec[i++], prop, value);
3665
+ i++;
3666
+ }
3667
+ }
3668
+ }
3669
+ this.nodeSet = new NodeSet(nodeNames.map((name, i) => NodeType.define({
3670
+ name: i >= this.minRepeatTerm ? void 0 : name,
3671
+ id: i,
3672
+ props: nodeProps[i],
3673
+ top: topTerms.indexOf(i) > -1,
3674
+ error: i == 0,
3675
+ skipped: spec.skippedNodes && spec.skippedNodes.indexOf(i) > -1
3676
+ })));
3677
+ if (spec.propSources)
3678
+ this.nodeSet = this.nodeSet.extend(...spec.propSources);
3679
+ this.strict = false;
3680
+ this.bufferLength = DefaultBufferLength;
3681
+ let tokenArray = decodeArray(spec.tokenData);
3682
+ this.context = spec.context;
3683
+ this.specializerSpecs = spec.specialized || [];
3684
+ this.specialized = new Uint16Array(this.specializerSpecs.length);
3685
+ for (let i = 0; i < this.specializerSpecs.length; i++)
3686
+ this.specialized[i] = this.specializerSpecs[i].term;
3687
+ this.specializers = this.specializerSpecs.map(getSpecializer);
3688
+ this.states = decodeArray(spec.states, Uint32Array);
3689
+ this.data = decodeArray(spec.stateData);
3690
+ this.goto = decodeArray(spec.goto);
3691
+ this.maxTerm = spec.maxTerm;
3692
+ this.tokenizers = spec.tokenizers.map((value) => typeof value == "number" ? new TokenGroup(tokenArray, value) : value);
3693
+ this.topRules = spec.topRules;
3694
+ this.dialects = spec.dialects || {};
3695
+ this.dynamicPrecedences = spec.dynamicPrecedences || null;
3696
+ this.tokenPrecTable = spec.tokenPrec;
3697
+ this.termNames = spec.termNames || null;
3698
+ this.maxNode = this.nodeSet.types.length - 1;
3699
+ this.dialect = this.parseDialect();
3700
+ this.top = this.topRules[Object.keys(this.topRules)[0]];
3701
+ }
3702
+ createParse(input, fragments, ranges) {
3703
+ let parse = new Parse(this, input, fragments, ranges);
3704
+ for (let w of this.wrappers)
3705
+ parse = w(parse, input, fragments, ranges);
3706
+ return parse;
3707
+ }
3708
+ /// Get a goto table entry @internal
3709
+ getGoto(state, term, loose = false) {
3710
+ let table = this.goto;
3711
+ if (term >= table[0])
3712
+ return -1;
3713
+ for (let pos = table[term + 1]; ; ) {
3714
+ let groupTag = table[pos++], last = groupTag & 1;
3715
+ let target = table[pos++];
3716
+ if (last && loose)
3717
+ return target;
3718
+ for (let end = pos + (groupTag >> 1); pos < end; pos++)
3719
+ if (table[pos] == state)
3720
+ return target;
3721
+ if (last)
3722
+ return -1;
3723
+ }
3724
+ }
3725
+ /// Check if this state has an action for a given terminal @internal
3726
+ hasAction(state, terminal) {
3727
+ let data = this.data;
3728
+ for (let set = 0; set < 2; set++) {
3729
+ for (let i = this.stateSlot(
3730
+ state,
3731
+ set ? 2 : 1
3732
+ /* ParseState.Actions */
3733
+ ), next; ; i += 3) {
3734
+ if ((next = data[i]) == 65535) {
3735
+ if (data[i + 1] == 1)
3736
+ next = data[i = pair(data, i + 2)];
3737
+ else if (data[i + 1] == 2)
3738
+ return pair(data, i + 2);
3739
+ else
3740
+ break;
3741
+ }
3742
+ if (next == terminal || next == 0)
3743
+ return pair(data, i + 1);
3744
+ }
3745
+ }
3746
+ return 0;
3747
+ }
3748
+ /// @internal
3749
+ stateSlot(state, slot) {
3750
+ return this.states[state * 6 + slot];
3751
+ }
3752
+ /// @internal
3753
+ stateFlag(state, flag) {
3754
+ return (this.stateSlot(
3755
+ state,
3756
+ 0
3757
+ /* ParseState.Flags */
3758
+ ) & flag) > 0;
3759
+ }
3760
+ /// @internal
3761
+ validAction(state, action) {
3762
+ if (action == this.stateSlot(
3763
+ state,
3764
+ 4
3765
+ /* ParseState.DefaultReduce */
3766
+ ))
3767
+ return true;
3768
+ for (let i = this.stateSlot(
3769
+ state,
3770
+ 1
3771
+ /* ParseState.Actions */
3772
+ ); ; i += 3) {
3773
+ if (this.data[i] == 65535) {
3774
+ if (this.data[i + 1] == 1)
3775
+ i = pair(this.data, i + 2);
3776
+ else
3777
+ return false;
3778
+ }
3779
+ if (action == pair(this.data, i + 1))
3780
+ return true;
3781
+ }
3782
+ }
3783
+ /// Get the states that can follow this one through shift actions or
3784
+ /// goto jumps. @internal
3785
+ nextStates(state) {
3786
+ let result = [];
3787
+ for (let i = this.stateSlot(
3788
+ state,
3789
+ 1
3790
+ /* ParseState.Actions */
3791
+ ); ; i += 3) {
3792
+ if (this.data[i] == 65535) {
3793
+ if (this.data[i + 1] == 1)
3794
+ i = pair(this.data, i + 2);
3795
+ else
3796
+ break;
3797
+ }
3798
+ if ((this.data[i + 2] & 65536 >> 16) == 0) {
3799
+ let value = this.data[i + 1];
3800
+ if (!result.some((v, i2) => i2 & 1 && v == value))
3801
+ result.push(this.data[i], value);
3802
+ }
3803
+ }
3804
+ return result;
3805
+ }
3806
+ /// Configure the parser. Returns a new parser instance that has the
3807
+ /// given settings modified. Settings not provided in `config` are
3808
+ /// kept from the original parser.
3809
+ configure(config) {
3810
+ let copy = Object.assign(Object.create(LRParser.prototype), this);
3811
+ if (config.props)
3812
+ copy.nodeSet = this.nodeSet.extend(...config.props);
3813
+ if (config.top) {
3814
+ let info2 = this.topRules[config.top];
3815
+ if (!info2)
3816
+ throw new RangeError(`Invalid top rule name ${config.top}`);
3817
+ copy.top = info2;
3818
+ }
3819
+ if (config.tokenizers)
3820
+ copy.tokenizers = this.tokenizers.map((t) => {
3821
+ let found = config.tokenizers.find((r) => r.from == t);
3822
+ return found ? found.to : t;
3823
+ });
3824
+ if (config.specializers) {
3825
+ copy.specializers = this.specializers.slice();
3826
+ copy.specializerSpecs = this.specializerSpecs.map((s, i) => {
3827
+ let found = config.specializers.find((r) => r.from == s.external);
3828
+ if (!found)
3829
+ return s;
3830
+ let spec = Object.assign(Object.assign({}, s), { external: found.to });
3831
+ copy.specializers[i] = getSpecializer(spec);
3832
+ return spec;
3833
+ });
3834
+ }
3835
+ if (config.contextTracker)
3836
+ copy.context = config.contextTracker;
3837
+ if (config.dialect)
3838
+ copy.dialect = this.parseDialect(config.dialect);
3839
+ if (config.strict != null)
3840
+ copy.strict = config.strict;
3841
+ if (config.wrap)
3842
+ copy.wrappers = copy.wrappers.concat(config.wrap);
3843
+ if (config.bufferLength != null)
3844
+ copy.bufferLength = config.bufferLength;
3845
+ return copy;
3846
+ }
3847
+ /// Tells you whether any [parse wrappers](#lr.ParserConfig.wrap)
3848
+ /// are registered for this parser.
3849
+ hasWrappers() {
3850
+ return this.wrappers.length > 0;
3851
+ }
3852
+ /// Returns the name associated with a given term. This will only
3853
+ /// work for all terms when the parser was generated with the
3854
+ /// `--names` option. By default, only the names of tagged terms are
3855
+ /// stored.
3856
+ getName(term) {
3857
+ return this.termNames ? this.termNames[term] : String(term <= this.maxNode && this.nodeSet.types[term].name || term);
3858
+ }
3859
+ /// The eof term id is always allocated directly after the node
3860
+ /// types. @internal
3861
+ get eofTerm() {
3862
+ return this.maxNode + 1;
3863
+ }
3864
+ /// The type of top node produced by the parser.
3865
+ get topNode() {
3866
+ return this.nodeSet.types[this.top[1]];
3867
+ }
3868
+ /// @internal
3869
+ dynamicPrecedence(term) {
3870
+ let prec = this.dynamicPrecedences;
3871
+ return prec == null ? 0 : prec[term] || 0;
3872
+ }
3873
+ /// @internal
3874
+ parseDialect(dialect) {
3875
+ let values = Object.keys(this.dialects), flags = values.map(() => false);
3876
+ if (dialect)
3877
+ for (let part of dialect.split(" ")) {
3878
+ let id = values.indexOf(part);
3879
+ if (id >= 0)
3880
+ flags[id] = true;
3881
+ }
3882
+ let disabled = null;
3883
+ for (let i = 0; i < values.length; i++)
3884
+ if (!flags[i]) {
3885
+ for (let j = this.dialects[values[i]], id; (id = this.data[j++]) != 65535; )
3886
+ (disabled || (disabled = new Uint8Array(this.maxTerm + 1)))[id] = 1;
3887
+ }
3888
+ return new Dialect(dialect, flags, disabled);
3889
+ }
3890
+ /// Used by the output of the parser generator. Not available to
3891
+ /// user code. @hide
3892
+ static deserialize(spec) {
3893
+ return new LRParser(spec);
3894
+ }
763
3895
  };
3896
+ function pair(data, off) {
3897
+ return data[off] | data[off + 1] << 16;
3898
+ }
3899
+ function findFinished(stacks) {
3900
+ let best = null;
3901
+ for (let stack of stacks) {
3902
+ let stopped = stack.p.stoppedAt;
3903
+ if ((stack.pos == stack.p.stream.end || stopped != null && stack.pos > stopped) && stack.p.parser.stateFlag(
3904
+ stack.state,
3905
+ 2
3906
+ /* StateFlag.Accepting */
3907
+ ) && (!best || best.score < stack.score))
3908
+ best = stack;
3909
+ }
3910
+ return best;
3911
+ }
3912
+ function getSpecializer(spec) {
3913
+ if (spec.external) {
3914
+ let mask = spec.extend ? 1 : 0;
3915
+ return (value, stack) => spec.external(value, stack) << 1 | mask;
3916
+ }
3917
+ return spec.get;
3918
+ }
764
3919
 
765
- // src/TableHeaderCell.tsx
766
- import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
767
- var classBase4 = "vuuTable-headerCell";
768
- var TableHeaderCell = ({
769
- column,
770
- className: classNameProp,
771
- onClick,
772
- onDragStart,
773
- onResize,
774
- ...props
775
- }) => {
776
- const rootRef = useRef5(null);
777
- const { isResizing, ...resizeProps } = useTableColumnResize({
778
- column,
779
- onResize,
780
- rootRef
781
- });
782
- const showContextMenu = useContextMenu2();
783
- const dragTimerRef = useRef5(null);
784
- const handleContextMenu = (e) => {
785
- showContextMenu(e, "header", { column });
786
- };
787
- const handleClick = useCallback7(
788
- (evt) => !isResizing && (onClick == null ? void 0 : onClick(evt)),
789
- [isResizing, onClick]
790
- );
791
- const handleMouseDown = useCallback7(
792
- (evt) => {
793
- dragTimerRef.current = window.setTimeout(() => {
794
- onDragStart == null ? void 0 : onDragStart(evt);
795
- dragTimerRef.current = null;
796
- }, 500);
797
- },
798
- [onDragStart]
799
- );
800
- const handleMouseUp = useCallback7(() => {
801
- if (dragTimerRef.current !== null) {
802
- window.clearTimeout(dragTimerRef.current);
803
- dragTimerRef.current = null;
3920
+ // ../vuu-filter-parser/src/generated/filter-parser.js
3921
+ var parser = LRParser.deserialize({
3922
+ version: 14,
3923
+ 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",
3924
+ 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",
3925
+ goto: "#YvPPw}!TPPPPPPPPPPwPP!WPP!ZP!ZP!aP!g!jPPP!p!s!aP#P!aXROU[]XQOU[]RYQRibXTOU[]XVOU[]Rf^QkhRnkRWOQSOQ_UQc[Rd]QaYQhbRmj",
3926
+ 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",
3927
+ maxTerm: 39,
3928
+ skippedNodes: [0],
3929
+ repeatNodeCount: 1,
3930
+ 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",
3931
+ tokenizers: [0, 1],
3932
+ topRules: { "Filter": [0, 1] },
3933
+ tokenPrec: 0
3934
+ });
3935
+
3936
+ // ../vuu-filter-parser/src/FilterTreeWalker.ts
3937
+ import {
3938
+ isMultiClauseFilter,
3939
+ isMultiValueFilter,
3940
+ isSingleValueFilter
3941
+ } from "@vuu-ui/vuu-utils";
3942
+ var _filter;
3943
+ var FilterExpression = class {
3944
+ constructor() {
3945
+ __privateAdd(this, _filter, void 0);
3946
+ }
3947
+ setFilterCombinatorOp(op, filter = __privateGet(this, _filter)) {
3948
+ if (isMultiClauseFilter(filter) && filter.op === op) {
3949
+ return;
3950
+ } else {
3951
+ __privateSet(this, _filter, {
3952
+ op,
3953
+ filters: [__privateGet(this, _filter)]
3954
+ });
804
3955
  }
805
- }, []);
806
- const className = cx6(classBase4, classNameProp, {
807
- vuuPinFloating: column.pin === "floating",
808
- vuuPinLeft: column.pin === "left",
809
- vuuPinRight: column.pin === "right",
810
- vuuEndPin: column.endPin,
811
- [`${classBase4}-resizing`]: column.resizing,
812
- [`${classBase4}-right`]: column.align === "right"
813
- });
814
- return /* @__PURE__ */ jsx8(
815
- "div",
816
- {
817
- className,
818
- ...props,
819
- onClick: handleClick,
820
- onContextMenu: handleContextMenu,
821
- onMouseDown: handleMouseDown,
822
- onMouseUp: handleMouseUp,
823
- ref: rootRef,
824
- children: /* @__PURE__ */ jsxs5("div", { className: `${classBase4}-inner`, children: [
825
- /* @__PURE__ */ jsx8(FilterIndicator, { column }),
826
- /* @__PURE__ */ jsx8("div", { className: `${classBase4}-label`, children: column.label }),
827
- /* @__PURE__ */ jsx8(SortIndicator, { sorted: column.sorted }),
828
- column.resizeable !== false ? /* @__PURE__ */ jsx8(ColumnResizer, { ...resizeProps }) : null
829
- ] })
3956
+ }
3957
+ add(filter) {
3958
+ if (__privateGet(this, _filter) === void 0) {
3959
+ __privateSet(this, _filter, filter);
3960
+ } else if (isMultiClauseFilter(__privateGet(this, _filter))) {
3961
+ __privateGet(this, _filter).filters.push(filter);
3962
+ } else {
3963
+ throw Error(`Invalid filter passed to FilterExpression`);
830
3964
  }
831
- );
832
- };
833
-
834
- // src/RowBasedTable.tsx
835
- import { jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
836
- var classBase5 = "vuuTable";
837
- var { RENDER_IDX } = metadataKeys4;
838
- var RowBasedTable = ({
839
- columns,
840
- columnsWithinViewport,
841
- data,
842
- getRowOffset,
843
- headings,
844
- onColumnResize,
845
- onHeaderCellDragStart,
846
- onContextMenu,
847
- onRemoveColumnFromGroupBy,
848
- onRowClick,
849
- onSort,
850
- onToggleGroup,
851
- tableId,
852
- virtualColSpan = 0,
853
- rowCount
854
- }) => {
855
- const handleDragStart = useCallback8(
856
- (evt) => {
857
- onHeaderCellDragStart == null ? void 0 : onHeaderCellDragStart(evt);
858
- },
859
- [onHeaderCellDragStart]
860
- );
861
- const visibleColumns = useMemo(() => {
862
- return columns.filter(notHidden2);
863
- }, [columns]);
864
- const columnMap = useMemo(() => buildColumnMap(columns), [columns]);
865
- const handleHeaderClick = useCallback8(
866
- (evt) => {
867
- var _a;
868
- const targetElement = evt.target;
869
- const headerCell = targetElement.closest(
870
- ".vuuTable-headerCell"
871
- );
872
- const colIdx = parseInt((_a = headerCell == null ? void 0 : headerCell.dataset.idx) != null ? _a : "-1");
873
- const column = visibleColumnAtIndex(columns, colIdx);
874
- const isAdditive = evt.shiftKey;
875
- column && onSort(column, isAdditive);
876
- },
877
- [columns, onSort]
878
- );
879
- return /* @__PURE__ */ jsxs6("div", { "aria-rowcount": rowCount, className: `${classBase5}-table`, role: "table", children: [
880
- /* @__PURE__ */ jsxs6("div", { className: `${classBase5}-headers`, role: "rowGroup", children: [
881
- headings.map((colHeaders, i) => /* @__PURE__ */ jsx9("div", { className: "vuuTable-heading", children: colHeaders.map(({ label, width }, j) => /* @__PURE__ */ jsx9("div", { className: "vuuTable-headingCell", style: { width }, children: label }, j)) }, i)),
882
- /* @__PURE__ */ jsx9("div", { role: "row", children: visibleColumns.map((column, i) => {
883
- const style = getColumnStyle3(column);
884
- return isGroupColumn2(column) ? /* @__PURE__ */ jsx9(
885
- TableGroupHeaderCell,
886
- {
887
- column,
888
- "data-idx": i,
889
- onRemoveColumn: onRemoveColumnFromGroupBy,
890
- onResize: onColumnResize,
891
- role: "columnHeader",
892
- style
893
- },
894
- i
895
- ) : /* @__PURE__ */ jsx9(
896
- TableHeaderCell,
897
- {
898
- column,
899
- "data-idx": i,
900
- id: `${tableId}-${i}`,
901
- onClick: handleHeaderClick,
902
- onDragStart: handleDragStart,
903
- onResize: onColumnResize,
904
- role: "columnHeader",
905
- style
906
- },
907
- i
908
- );
909
- }) })
910
- ] }),
911
- /* @__PURE__ */ jsx9(
912
- "div",
913
- {
914
- className: `${classBase5}-body`,
915
- onContextMenu,
916
- role: "rowGroup",
917
- children: data == null ? void 0 : data.map((row) => /* @__PURE__ */ jsx9(
918
- TableRow,
919
- {
920
- columnMap,
921
- columns: columnsWithinViewport,
922
- offset: getRowOffset(row),
923
- onClick: onRowClick,
924
- virtualColSpan,
925
- onToggleGroup,
926
- row
927
- },
928
- row[RENDER_IDX]
929
- ))
3965
+ }
3966
+ setColumn(column, filter = __privateGet(this, _filter)) {
3967
+ if (isMultiClauseFilter(filter)) {
3968
+ const target = filter.filters.at(-1);
3969
+ if (target) {
3970
+ this.setColumn(column, target);
930
3971
  }
931
- )
932
- ] });
3972
+ } else if (filter) {
3973
+ filter.column = column;
3974
+ }
3975
+ }
3976
+ setOp(value, filter = __privateGet(this, _filter)) {
3977
+ if (isMultiClauseFilter(filter)) {
3978
+ const target = filter.filters.at(-1);
3979
+ if (target) {
3980
+ this.setOp(value, target);
3981
+ }
3982
+ } else if (filter) {
3983
+ filter.op = value;
3984
+ }
3985
+ }
3986
+ setValue(value, filter = __privateGet(this, _filter)) {
3987
+ var _a;
3988
+ if (isMultiClauseFilter(filter)) {
3989
+ const target = filter.filters.at(-1);
3990
+ if (target) {
3991
+ this.setValue(value, target);
3992
+ }
3993
+ } else if (isMultiValueFilter(filter)) {
3994
+ (_a = filter.values) != null ? _a : filter.values = [];
3995
+ filter.values.push(value);
3996
+ } else if (isSingleValueFilter(filter)) {
3997
+ filter.value = value;
3998
+ }
3999
+ }
4000
+ toJSON(filter = __privateGet(this, _filter)) {
4001
+ if (this.name) {
4002
+ return {
4003
+ ...filter,
4004
+ name: this.name
4005
+ };
4006
+ } else {
4007
+ return filter;
4008
+ }
4009
+ }
933
4010
  };
4011
+ _filter = new WeakMap();
934
4012
 
935
- // src/useTable.ts
936
- import { useContextMenu as usePopupContextMenu } from "@vuu-ui/vuu-popups";
4013
+ // ../vuu-filter-parser/src/FilterParser.ts
4014
+ var strictParser = parser.configure({ strict: true });
4015
+
4016
+ // ../vuu-data-react/src/hooks/useVuuMenuActions.ts
937
4017
  import {
938
- applySort,
939
- buildColumnMap as buildColumnMap2,
940
- isJsonGroup as isJsonGroup2,
941
- metadataKeys as metadataKeys8,
942
- moveItem as moveItem2
4018
+ getRowRecord,
4019
+ isGroupMenuItemDescriptor,
4020
+ metadataKeys as metadataKeys6
943
4021
  } from "@vuu-ui/vuu-utils";
944
- import {
945
- useCallback as useCallback18,
946
- useEffect as useEffect5,
947
- useMemo as useMemo7,
948
- useRef as useRef15,
949
- useState as useState5
950
- } from "react";
4022
+ import { useCallback as useCallback13 } from "react";
4023
+ var { KEY: KEY2 } = metadataKeys6;
4024
+ var isVisualLinksAction = (action) => action.type === "vuu-links";
4025
+ var isViewportMenusAction = (action) => action.type === "vuu-menu";
4026
+ var isVuuFeatureAction = (action) => isViewportMenusAction(action) || isVisualLinksAction(action);
4027
+ var isVuuFeatureInvocation = (action) => action.type === "vuu-link-created" || action.type === "vuu-link-removed";
4028
+
4029
+ // ../vuu-data-react/src/hooks/useVuuTables.ts
4030
+ import { useCallback as useCallback14, useEffect as useEffect4, useState as useState5 } from "react";
4031
+ import { getServerAPI } from "@vuu-ui/vuu-data";
951
4032
 
952
4033
  // src/useDataSource.ts
953
- import {
954
- isVuuFeatureAction,
955
- isVuuFeatureInvocation
956
- } from "@vuu-ui/vuu-data";
957
- import { getFullRange, metadataKeys as metadataKeys5, WindowRange } from "@vuu-ui/vuu-utils";
958
- import { useCallback as useCallback9, useEffect, useMemo as useMemo2, useRef as useRef6, useState as useState2 } from "react";
959
- var { SELECTED: SELECTED2 } = metadataKeys5;
4034
+ import { getFullRange as getFullRange2, metadataKeys as metadataKeys7, WindowRange as WindowRange2 } from "@vuu-ui/vuu-utils";
4035
+ import { useCallback as useCallback15, useEffect as useEffect5, useMemo as useMemo3, useRef as useRef7, useState as useState6 } from "react";
4036
+ var { SELECTED: SELECTED3 } = metadataKeys7;
960
4037
  function useDataSource({
961
4038
  dataSource,
962
4039
  onConfigChange,
@@ -968,18 +4045,18 @@ function useDataSource({
968
4045
  renderBufferSize = 0,
969
4046
  viewportRowCount
970
4047
  }) {
971
- const [, forceUpdate] = useState2(null);
972
- const isMounted = useRef6(true);
973
- const hasUpdated = useRef6(false);
974
- const rangeRef = useRef6({ from: 0, to: 0 });
975
- const rafHandle = useRef6(null);
976
- const data = useRef6([]);
977
- const dataWindow = useMemo2(
978
- () => new MovingWindow(getFullRange(range)),
4048
+ const [, forceUpdate] = useState6(null);
4049
+ const isMounted = useRef7(true);
4050
+ const hasUpdated = useRef7(false);
4051
+ const rangeRef = useRef7({ from: 0, to: 0 });
4052
+ const rafHandle = useRef7(null);
4053
+ const data = useRef7([]);
4054
+ const dataWindow = useMemo3(
4055
+ () => new MovingWindow(getFullRange2(range)),
979
4056
  // eslint-disable-next-line react-hooks/exhaustive-deps
980
4057
  []
981
4058
  );
982
- const setData = useCallback9(
4059
+ const setData = useCallback15(
983
4060
  (updates) => {
984
4061
  for (const row of updates) {
985
4062
  dataWindow.add(row);
@@ -989,7 +4066,7 @@ function useDataSource({
989
4066
  },
990
4067
  [dataWindow]
991
4068
  );
992
- const datasourceMessageHandler = useCallback9(
4069
+ const datasourceMessageHandler = useCallback15(
993
4070
  (message) => {
994
4071
  if (message.type === "subscribed") {
995
4072
  onSubscribed == null ? void 0 : onSubscribed(message);
@@ -1021,7 +4098,7 @@ function useDataSource({
1021
4098
  setData
1022
4099
  ]
1023
4100
  );
1024
- useEffect(
4101
+ useEffect5(
1025
4102
  () => () => {
1026
4103
  if (rafHandle.current) {
1027
4104
  cancelAnimationFrame(rafHandle.current);
@@ -1031,7 +4108,7 @@ function useDataSource({
1031
4108
  },
1032
4109
  []
1033
4110
  );
1034
- const refreshIfUpdated = useCallback9(() => {
4111
+ const refreshIfUpdated = useCallback15(() => {
1035
4112
  if (isMounted.current) {
1036
4113
  if (hasUpdated.current) {
1037
4114
  forceUpdate({});
@@ -1040,33 +4117,33 @@ function useDataSource({
1040
4117
  rafHandle.current = requestAnimationFrame(refreshIfUpdated);
1041
4118
  }
1042
4119
  }, [forceUpdate]);
1043
- useEffect(() => {
4120
+ useEffect5(() => {
1044
4121
  rafHandle.current = requestAnimationFrame(refreshIfUpdated);
1045
4122
  }, [refreshIfUpdated]);
1046
- const adjustRange = useCallback9(
4123
+ const adjustRange = useCallback15(
1047
4124
  (rowCount) => {
1048
4125
  const { from } = dataSource.range;
1049
4126
  const rowRange = { from, to: from + rowCount };
1050
- const fullRange = getFullRange(rowRange, renderBufferSize);
4127
+ const fullRange = getFullRange2(rowRange, renderBufferSize);
1051
4128
  dataWindow.setRange(fullRange);
1052
4129
  dataSource.range = rangeRef.current = fullRange;
1053
4130
  dataSource.emit("range", rowRange);
1054
4131
  },
1055
4132
  [dataSource, dataWindow, renderBufferSize]
1056
4133
  );
1057
- const setRange = useCallback9(
4134
+ const setRange = useCallback15(
1058
4135
  (range2) => {
1059
- const fullRange = getFullRange(range2, renderBufferSize);
4136
+ const fullRange = getFullRange2(range2, renderBufferSize);
1060
4137
  dataWindow.setRange(fullRange);
1061
4138
  dataSource.range = rangeRef.current = fullRange;
1062
4139
  dataSource.emit("range", range2);
1063
4140
  },
1064
4141
  [dataSource, dataWindow, renderBufferSize]
1065
4142
  );
1066
- const getSelectedRows = useCallback9(() => {
4143
+ const getSelectedRows = useCallback15(() => {
1067
4144
  return dataWindow.getSelectedRows();
1068
4145
  }, [dataWindow]);
1069
- useEffect(() => {
4146
+ useEffect5(() => {
1070
4147
  dataSource == null ? void 0 : dataSource.subscribe(
1071
4148
  {
1072
4149
  range: rangeRef.current
@@ -1074,7 +4151,7 @@ function useDataSource({
1074
4151
  datasourceMessageHandler
1075
4152
  );
1076
4153
  }, [dataSource, datasourceMessageHandler, onConfigChange]);
1077
- useEffect(() => {
4154
+ useEffect5(() => {
1078
4155
  adjustRange(viewportRowCount);
1079
4156
  }, [adjustRange, viewportRowCount]);
1080
4157
  return {
@@ -1094,7 +4171,7 @@ var MovingWindow = class {
1094
4171
  }
1095
4172
  this.rowCount = rowCount;
1096
4173
  };
1097
- this.range = new WindowRange(from, to);
4174
+ this.range = new WindowRange2(from, to);
1098
4175
  this.data = new Array(to - from);
1099
4176
  this.rowCount = 0;
1100
4177
  }
@@ -1104,12 +4181,12 @@ var MovingWindow = class {
1104
4181
  if (this.isWithinRange(index)) {
1105
4182
  const internalIndex = index - this.range.from;
1106
4183
  this.data[internalIndex] = data;
1107
- const isSelected = data[SELECTED2];
1108
- const preSelected = (_a = this.data[internalIndex - 1]) == null ? void 0 : _a[SELECTED2];
4184
+ const isSelected = data[SELECTED3];
4185
+ const preSelected = (_a = this.data[internalIndex - 1]) == null ? void 0 : _a[SELECTED3];
1109
4186
  if (preSelected === 0 && isSelected) {
1110
- this.data[internalIndex - 1][SELECTED2] = 2;
4187
+ this.data[internalIndex - 1][SELECTED3] = 2;
1111
4188
  } else if (preSelected === 2 && !isSelected) {
1112
- this.data[internalIndex - 1][SELECTED2] = 0;
4189
+ this.data[internalIndex - 1][SELECTED3] = 0;
1113
4190
  }
1114
4191
  }
1115
4192
  }
@@ -1136,17 +4213,17 @@ var MovingWindow = class {
1136
4213
  }
1137
4214
  }
1138
4215
  getSelectedRows() {
1139
- return this.data.filter((row) => row[SELECTED2] === 1);
4216
+ return this.data.filter((row) => row[SELECTED3] === 1);
1140
4217
  }
1141
4218
  };
1142
4219
 
1143
4220
  // src/useDraggableColumn.ts
1144
4221
  import { useDragDrop } from "@heswell/salt-lab";
1145
- import { useCallback as useCallback10, useRef as useRef7 } from "react";
4222
+ import { useCallback as useCallback16, useRef as useRef8 } from "react";
1146
4223
  var useDraggableColumn = ({ onDrop }) => {
1147
- const mousePosRef = useRef7();
1148
- const containerRef = useRef7(null);
1149
- const handleDropSettle = useCallback10(() => {
4224
+ const mousePosRef = useRef8();
4225
+ const containerRef = useRef8(null);
4226
+ const handleDropSettle = useCallback16(() => {
1150
4227
  console.log(`handleDropSettle`);
1151
4228
  mousePosRef.current = void 0;
1152
4229
  containerRef.current = null;
@@ -1161,7 +4238,7 @@ var useDraggableColumn = ({ onDrop }) => {
1161
4238
  onDrop,
1162
4239
  onDropSettle: handleDropSettle
1163
4240
  });
1164
- const onHeaderCellDragStart = useCallback10(
4241
+ const onHeaderCellDragStart = useCallback16(
1165
4242
  (evt) => {
1166
4243
  const { clientX, clientY } = evt;
1167
4244
  console.log(
@@ -1194,11 +4271,11 @@ var useDraggableColumn = ({ onDrop }) => {
1194
4271
  // src/useKeyboardNavigation.ts
1195
4272
  import { withinRange } from "@vuu-ui/vuu-utils";
1196
4273
  import {
1197
- useCallback as useCallback11,
1198
- useEffect as useEffect2,
4274
+ useCallback as useCallback17,
4275
+ useEffect as useEffect6,
1199
4276
  useLayoutEffect,
1200
- useMemo as useMemo3,
1201
- useRef as useRef8
4277
+ useMemo as useMemo4,
4278
+ useRef as useRef9
1202
4279
  } from "react";
1203
4280
 
1204
4281
  // src/keyUtils.ts
@@ -1304,10 +4381,10 @@ var useKeyboardNavigation = ({
1304
4381
  }) => {
1305
4382
  var _a;
1306
4383
  const { from: viewportFirstRow, to: viewportLastRow } = viewportRange;
1307
- const focusedCellPos = useRef8([-1, -1]);
1308
- const focusableCell = useRef8();
1309
- const activeCellPos = useRef8([-1, 0]);
1310
- const getTableCell = useCallback11(
4384
+ const focusedCellPos = useRef9([-1, -1]);
4385
+ const focusableCell = useRef9();
4386
+ const activeCellPos = useRef9([-1, 0]);
4387
+ const getTableCell = useCallback17(
1311
4388
  ([rowIdx, colIdx]) => {
1312
4389
  var _a2;
1313
4390
  const cssQuery = rowIdx === -1 ? headerCellQuery(colIdx) : dataCellQuery(rowIdx, colIdx);
@@ -1335,7 +4412,7 @@ var useKeyboardNavigation = ({
1335
4412
  }
1336
4413
  return NULL_CELL_POS;
1337
4414
  };
1338
- const focusCell = useCallback11(
4415
+ const focusCell = useCallback17(
1339
4416
  (cellPos) => {
1340
4417
  var _a2;
1341
4418
  if (containerRef.current) {
@@ -1357,7 +4434,7 @@ var useKeyboardNavigation = ({
1357
4434
  // be often whilst scrolling - store range in a a ref ?
1358
4435
  [containerRef, getTableCell, requestScroll, viewportRange]
1359
4436
  );
1360
- const setActiveCell = useCallback11(
4437
+ const setActiveCell = useCallback17(
1361
4438
  (rowIdx, colIdx, fromKeyboard = false) => {
1362
4439
  const pos = [rowIdx, colIdx];
1363
4440
  activeCellPos.current = pos;
@@ -1368,12 +4445,12 @@ var useKeyboardNavigation = ({
1368
4445
  },
1369
4446
  [focusCell]
1370
4447
  );
1371
- const virtualizeActiveCell = useCallback11(() => {
4448
+ const virtualizeActiveCell = useCallback17(() => {
1372
4449
  var _a2;
1373
4450
  (_a2 = focusableCell.current) == null ? void 0 : _a2.setAttribute("tabindex", "");
1374
4451
  focusableCell.current = void 0;
1375
4452
  }, []);
1376
- const nextPageItemIdx = useCallback11(
4453
+ const nextPageItemIdx = useCallback17(
1377
4454
  async (key, cellPos) => {
1378
4455
  switch (key) {
1379
4456
  case PageDown:
@@ -1393,7 +4470,7 @@ var useKeyboardNavigation = ({
1393
4470
  },
1394
4471
  [requestScroll]
1395
4472
  );
1396
- const handleFocus = useCallback11(() => {
4473
+ const handleFocus = useCallback17(() => {
1397
4474
  var _a2;
1398
4475
  if (disableHighlightOnFocus !== true) {
1399
4476
  if ((_a2 = containerRef.current) == null ? void 0 : _a2.contains(document.activeElement)) {
@@ -1404,7 +4481,7 @@ var useKeyboardNavigation = ({
1404
4481
  }
1405
4482
  }
1406
4483
  }, [disableHighlightOnFocus, containerRef]);
1407
- const navigateChildItems = useCallback11(
4484
+ const navigateChildItems = useCallback17(
1408
4485
  async (key) => {
1409
4486
  const [nextRowIdx, nextColIdx] = isPagingKey(key) ? await nextPageItemIdx(key, activeCellPos.current) : nextCellPos(key, activeCellPos.current, columnCount, rowCount);
1410
4487
  const [rowIdx, colIdx] = activeCellPos.current;
@@ -1414,7 +4491,7 @@ var useKeyboardNavigation = ({
1414
4491
  },
1415
4492
  [columnCount, nextPageItemIdx, rowCount, setActiveCell]
1416
4493
  );
1417
- const handleKeyDown = useCallback11(
4494
+ const handleKeyDown = useCallback17(
1418
4495
  (e) => {
1419
4496
  if (data.length > 0 && isNavigationKey(e.key)) {
1420
4497
  e.preventDefault();
@@ -1424,7 +4501,7 @@ var useKeyboardNavigation = ({
1424
4501
  },
1425
4502
  [data, navigateChildItems]
1426
4503
  );
1427
- const handleClick = useCallback11(
4504
+ const handleClick = useCallback17(
1428
4505
  // Might not be a cell e.g the Settings button
1429
4506
  (evt) => {
1430
4507
  const target = evt.target;
@@ -1436,7 +4513,7 @@ var useKeyboardNavigation = ({
1436
4513
  },
1437
4514
  [setActiveCell]
1438
4515
  );
1439
- const containerProps = useMemo3(() => {
4516
+ const containerProps = useMemo4(() => {
1440
4517
  return {
1441
4518
  onClick: handleClick,
1442
4519
  onFocus: handleFocus,
@@ -1453,7 +4530,7 @@ var useKeyboardNavigation = ({
1453
4530
  }
1454
4531
  }, [focusCell, viewportFirstRow, viewportLastRow, virtualizeActiveCell]);
1455
4532
  const fullyRendered = ((_a = containerRef.current) == null ? void 0 : _a.firstChild) != null;
1456
- useEffect2(() => {
4533
+ useEffect6(() => {
1457
4534
  var _a2;
1458
4535
  if (fullyRendered && focusableCell.current === void 0) {
1459
4536
  const headerCell = (_a2 = containerRef.current) == null ? void 0 : _a2.querySelector(
@@ -1470,10 +4547,10 @@ var useKeyboardNavigation = ({
1470
4547
 
1471
4548
  // src/useMeasuredContainer.ts
1472
4549
  import { isValidNumber } from "@vuu-ui/vuu-utils";
1473
- import { useCallback as useCallback13, useMemo as useMemo4, useRef as useRef10, useState as useState3 } from "react";
4550
+ import { useCallback as useCallback19, useMemo as useMemo5, useRef as useRef11, useState as useState7 } from "react";
1474
4551
 
1475
4552
  // src/useResizeObserver.ts
1476
- import { useCallback as useCallback12, useEffect as useEffect3, useRef as useRef9 } from "react";
4553
+ import { useCallback as useCallback18, useEffect as useEffect7, useRef as useRef10 } from "react";
1477
4554
  var observedMap = /* @__PURE__ */ new Map();
1478
4555
  var getTargetSize = (element, size, dimension) => {
1479
4556
  switch (dimension) {
@@ -1524,8 +4601,8 @@ var resizeObserver = new ResizeObserver((entries) => {
1524
4601
  }
1525
4602
  });
1526
4603
  function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false) {
1527
- const dimensionsRef = useRef9(dimensions);
1528
- const measure = useCallback12((target) => {
4604
+ const dimensionsRef = useRef10(dimensions);
4605
+ const measure = useCallback18((target) => {
1529
4606
  const { width, height } = target.getBoundingClientRect();
1530
4607
  const { clientWidth: contentWidth, clientHeight: contentHeight } = target;
1531
4608
  return dimensionsRef.current.reduce(
@@ -1540,7 +4617,7 @@ function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false)
1540
4617
  {}
1541
4618
  );
1542
4619
  }, []);
1543
- useEffect3(() => {
4620
+ useEffect7(() => {
1544
4621
  const target = ref.current;
1545
4622
  async function registerObserver() {
1546
4623
  observedMap.set(target, { measurements: {} });
@@ -1575,7 +4652,7 @@ function useResizeObserver(ref, dimensions, onResize, reportInitialSize = false)
1575
4652
  }
1576
4653
  };
1577
4654
  }, [measure, ref]);
1578
- useEffect3(() => {
4655
+ useEffect7(() => {
1579
4656
  const target = ref.current;
1580
4657
  const record = observedMap.get(target);
1581
4658
  if (record) {
@@ -1617,8 +4694,8 @@ var useMeasuredContainer = ({
1617
4694
  height,
1618
4695
  width
1619
4696
  }) => {
1620
- const containerRef = useRef10(null);
1621
- const [size, setSize] = useState3({
4697
+ const containerRef = useRef11(null);
4698
+ const [size, setSize] = useState7({
1622
4699
  css: getInitialCssSize(height, width),
1623
4700
  inner: getInitialInnerSize(height, width),
1624
4701
  outer: {
@@ -1626,7 +4703,7 @@ var useMeasuredContainer = ({
1626
4703
  width: width != null ? width : "100%"
1627
4704
  }
1628
4705
  });
1629
- useMemo4(() => {
4706
+ useMemo5(() => {
1630
4707
  setSize((currentSize) => {
1631
4708
  const { inner, outer } = currentSize;
1632
4709
  if (isValidNumber(height) && isValidNumber(width) && inner && outer) {
@@ -1645,7 +4722,7 @@ var useMeasuredContainer = ({
1645
4722
  return currentSize;
1646
4723
  });
1647
4724
  }, [height, width]);
1648
- const onResize = useCallback13(
4725
+ const onResize = useCallback19(
1649
4726
  ({ clientWidth, clientHeight }) => {
1650
4727
  setSize((currentSize) => {
1651
4728
  const { css, inner, outer } = currentSize;
@@ -1671,23 +4748,28 @@ var useMeasuredContainer = ({
1671
4748
  };
1672
4749
 
1673
4750
  // src/useSelection.ts
1674
- import { deselectItem, metadataKeys as metadataKeys6, selectItem } from "@vuu-ui/vuu-utils";
1675
- import { useCallback as useCallback14, useRef as useRef11 } from "react";
1676
- var { IDX: IDX2, SELECTED: SELECTED3 } = metadataKeys6;
4751
+ import {
4752
+ deselectItem,
4753
+ isRowSelected,
4754
+ metadataKeys as metadataKeys8,
4755
+ selectItem
4756
+ } from "@vuu-ui/vuu-utils";
4757
+ import { useCallback as useCallback20, useRef as useRef12 } from "react";
4758
+ var { IDX: IDX2 } = metadataKeys8;
1677
4759
  var NO_SELECTION = [];
1678
4760
  var useSelection = ({
1679
4761
  selectionModel,
1680
4762
  onSelectionChange
1681
4763
  }) => {
1682
4764
  selectionModel === "extended" || selectionModel === "checkbox";
1683
- const lastActiveRef = useRef11(-1);
1684
- const selectedRef = useRef11(NO_SELECTION);
1685
- const handleSelectionChange = useCallback14(
4765
+ const lastActiveRef = useRef12(-1);
4766
+ const selectedRef = useRef12(NO_SELECTION);
4767
+ const handleSelectionChange = useCallback20(
1686
4768
  (row, rangeSelect, keepExistingSelection) => {
1687
- const { [IDX2]: idx, [SELECTED3]: isSelected } = row;
4769
+ const { [IDX2]: idx } = row;
1688
4770
  const { current: active } = lastActiveRef;
1689
4771
  const { current: selected } = selectedRef;
1690
- const selectOperation = isSelected ? deselectItem : selectItem;
4772
+ const selectOperation = isRowSelected(row) ? deselectItem : selectItem;
1691
4773
  const newSelected = selectOperation(
1692
4774
  selectionModel,
1693
4775
  selected,
@@ -1723,14 +4805,15 @@ import {
1723
4805
  isPinned,
1724
4806
  isTypeDescriptor,
1725
4807
  logger,
1726
- metadataKeys as metadataKeys7,
4808
+ metadataKeys as metadataKeys9,
4809
+ updateColumn,
1727
4810
  sortPinnedColumns,
1728
4811
  stripFilterFromColumns
1729
4812
  } from "@vuu-ui/vuu-utils";
1730
4813
  import { useReducer } from "react";
1731
4814
  var { info } = logger("useTableModel");
1732
4815
  var DEFAULT_COLUMN_WIDTH = 100;
1733
- var KEY_OFFSET = metadataKeys7.count;
4816
+ var KEY_OFFSET = metadataKeys9.count;
1734
4817
  var columnWithoutDataType = ({ serverDataType }) => serverDataType === void 0;
1735
4818
  var getCellRendererForColumn = (column) => {
1736
4819
  var _a;
@@ -1753,8 +4836,8 @@ var getServerDataTypeForColumn = (column, tableSchema) => {
1753
4836
  };
1754
4837
  var numericTypes = ["int", "long", "double"];
1755
4838
  var getDefaultAlignment = (serverDataType) => serverDataType === void 0 ? void 0 : numericTypes.includes(serverDataType) ? "right" : "left";
4839
+ var isShowSettings = (action) => action.type === "columnSettings";
1756
4840
  var columnReducer = (state, action) => {
1757
- info == null ? void 0 : info(`GridModelReducer ${action.type}`);
1758
4841
  switch (action.type) {
1759
4842
  case "init":
1760
4843
  return init(action);
@@ -1906,8 +4989,9 @@ function resizeColumn(state, { column, phase, width }) {
1906
4989
  const resizing = phase !== "end";
1907
4990
  switch (phase) {
1908
4991
  case "begin":
1909
- case "end":
1910
4992
  return updateColumnProp(state, { type, column, resizing });
4993
+ case "end":
4994
+ return updateColumnProp(state, { type, column, resizing, width });
1911
4995
  case "resize":
1912
4996
  return updateColumnProp(state, { type, column, width });
1913
4997
  default:
@@ -1941,39 +5025,34 @@ function setTableSchema(state, { tableSchema }) {
1941
5025
  function pinColumn2(state, action) {
1942
5026
  let { columns } = state;
1943
5027
  const { column, pin } = action;
1944
- const targetColumn = columns.find((col) => col.name === column.name);
1945
- if (targetColumn) {
1946
- columns = replaceColumn(columns, { ...targetColumn, pin });
1947
- columns = sortPinnedColumns(columns);
1948
- return {
1949
- ...state,
1950
- columns
1951
- };
1952
- } else {
1953
- return state;
1954
- }
5028
+ columns = updateColumn(columns, column.name, { pin });
5029
+ columns = sortPinnedColumns(columns);
5030
+ console.log({ withPins: columns });
5031
+ return {
5032
+ ...state,
5033
+ columns
5034
+ };
1955
5035
  }
1956
5036
  function updateColumnProp(state, action) {
1957
5037
  let { columns } = state;
1958
5038
  const { align, column, hidden, label, resizing, width } = action;
1959
- const targetColumn = columns.find((col) => col.name === column.name);
1960
- if (targetColumn) {
1961
- if (align === "left" || align === "right") {
1962
- columns = replaceColumn(columns, { ...targetColumn, align });
1963
- }
1964
- if (typeof label === "string") {
1965
- columns = replaceColumn(columns, { ...targetColumn, label });
1966
- }
1967
- if (typeof resizing === "boolean") {
1968
- columns = replaceColumn(columns, { ...targetColumn, resizing });
1969
- }
1970
- if (typeof hidden === "boolean") {
1971
- columns = replaceColumn(columns, { ...targetColumn, hidden });
1972
- }
1973
- if (typeof width === "number") {
1974
- columns = replaceColumn(columns, { ...targetColumn, width });
1975
- }
5039
+ const options = {};
5040
+ if (align === "left" || align === "right") {
5041
+ options.align = align;
5042
+ }
5043
+ if (typeof label === "string") {
5044
+ options.label = label;
5045
+ }
5046
+ if (typeof resizing === "boolean") {
5047
+ options.resizing = resizing;
5048
+ }
5049
+ if (typeof hidden === "boolean") {
5050
+ options.hidden = hidden;
5051
+ }
5052
+ if (typeof width === "number") {
5053
+ options.width = width;
1976
5054
  }
5055
+ columns = updateColumn(columns, column.name, options);
1977
5056
  return {
1978
5057
  ...state,
1979
5058
  columns
@@ -2038,12 +5117,9 @@ function updateTableConfig(state, { columns, confirmed, filter, groupBy, sort })
2038
5117
  }
2039
5118
  return result;
2040
5119
  }
2041
- function replaceColumn(state, column) {
2042
- return state.map((col) => col.name === column.name ? column : col);
2043
- }
2044
5120
 
2045
5121
  // src/useTableScroll.ts
2046
- import { useCallback as useCallback15, useRef as useRef12 } from "react";
5122
+ import { useCallback as useCallback21, useRef as useRef13 } from "react";
2047
5123
  var getPctScroll = (container) => {
2048
5124
  const { scrollLeft, scrollTop } = container;
2049
5125
  const { clientHeight, clientWidth, scrollHeight, scrollWidth } = container;
@@ -2059,8 +5135,8 @@ var useCallbackRef = ({
2059
5135
  onAttach,
2060
5136
  onDetach
2061
5137
  }) => {
2062
- const ref = useRef12(null);
2063
- const callbackRef = useCallback15(
5138
+ const ref = useRef13(null);
5139
+ const callbackRef = useCallback21(
2064
5140
  (el) => {
2065
5141
  if (el) {
2066
5142
  ref.current = el;
@@ -2080,15 +5156,15 @@ var useTableScroll = ({
2080
5156
  onVerticalScroll,
2081
5157
  viewport
2082
5158
  }) => {
2083
- const contentContainerScrolledRef = useRef12(false);
2084
- const scrollPosRef = useRef12({ scrollTop: 0, scrollLeft: 0 });
2085
- const scrollbarContainerRef = useRef12(null);
2086
- const contentContainerRef = useRef12(null);
5159
+ const contentContainerScrolledRef = useRef13(false);
5160
+ const scrollPosRef = useRef13({ scrollTop: 0, scrollLeft: 0 });
5161
+ const scrollbarContainerRef = useRef13(null);
5162
+ const contentContainerRef = useRef13(null);
2087
5163
  const {
2088
5164
  maxScrollContainerScrollHorizontal: maxScrollLeft,
2089
5165
  maxScrollContainerScrollVertical: maxScrollTop
2090
5166
  } = viewport;
2091
- const handleScrollbarContainerScroll = useCallback15(() => {
5167
+ const handleScrollbarContainerScroll = useCallback21(() => {
2092
5168
  const { current: contentContainer } = contentContainerRef;
2093
5169
  const { current: scrollbarContainer } = scrollbarContainerRef;
2094
5170
  const { current: contentContainerScrolled } = contentContainerScrolledRef;
@@ -2099,6 +5175,9 @@ var useTableScroll = ({
2099
5175
  const [maxScrollLeft2, maxScrollTop2] = getMaxScroll(contentContainer);
2100
5176
  const rootScrollLeft = Math.round(pctScrollLeft * maxScrollLeft2);
2101
5177
  const rootScrollTop = Math.round(pctScrollTop * maxScrollTop2);
5178
+ console.log(
5179
+ `pctScrollTop ${pctScrollTop}, maxScrollTop ${maxScrollTop2} rootScrollTop ${rootScrollTop}`
5180
+ );
2102
5181
  contentContainer.scrollTo({
2103
5182
  left: rootScrollLeft,
2104
5183
  top: rootScrollTop,
@@ -2106,7 +5185,7 @@ var useTableScroll = ({
2106
5185
  });
2107
5186
  }
2108
5187
  }, []);
2109
- const handleContentContainerScroll = useCallback15(() => {
5188
+ const handleContentContainerScroll = useCallback21(() => {
2110
5189
  const { current: contentContainer } = contentContainerRef;
2111
5190
  const { current: scrollbarContainer } = scrollbarContainerRef;
2112
5191
  const { current: scrollPos } = scrollPosRef;
@@ -2126,7 +5205,7 @@ var useTableScroll = ({
2126
5205
  }
2127
5206
  }
2128
5207
  }, [maxScrollLeft, maxScrollTop, onHorizontalScroll, onVerticalScroll]);
2129
- const handleAttachScrollbarContainer = useCallback15(
5208
+ const handleAttachScrollbarContainer = useCallback21(
2130
5209
  (el) => {
2131
5210
  scrollbarContainerRef.current = el;
2132
5211
  el.addEventListener("scroll", handleScrollbarContainerScroll, {
@@ -2135,14 +5214,14 @@ var useTableScroll = ({
2135
5214
  },
2136
5215
  [handleScrollbarContainerScroll]
2137
5216
  );
2138
- const handleDetachScrollbarContainer = useCallback15(
5217
+ const handleDetachScrollbarContainer = useCallback21(
2139
5218
  (el) => {
2140
5219
  scrollbarContainerRef.current = null;
2141
5220
  el.removeEventListener("scroll", handleScrollbarContainerScroll);
2142
5221
  },
2143
5222
  [handleScrollbarContainerScroll]
2144
5223
  );
2145
- const handleAttachContentContainer = useCallback15(
5224
+ const handleAttachContentContainer = useCallback21(
2146
5225
  (el) => {
2147
5226
  contentContainerRef.current = el;
2148
5227
  el.addEventListener("scroll", handleContentContainerScroll, {
@@ -2151,7 +5230,7 @@ var useTableScroll = ({
2151
5230
  },
2152
5231
  [handleContentContainerScroll]
2153
5232
  );
2154
- const handleDetachContentContainer = useCallback15(
5233
+ const handleDetachContentContainer = useCallback21(
2155
5234
  (el) => {
2156
5235
  contentContainerRef.current = null;
2157
5236
  el.removeEventListener("scroll", handleContentContainerScroll);
@@ -2166,7 +5245,7 @@ var useTableScroll = ({
2166
5245
  onAttach: handleAttachScrollbarContainer,
2167
5246
  onDetach: handleDetachScrollbarContainer
2168
5247
  });
2169
- const requestScroll = useCallback15(
5248
+ const requestScroll = useCallback21(
2170
5249
  (scrollRequest) => {
2171
5250
  const { current: scrollbarContainer } = contentContainerRef;
2172
5251
  if (scrollbarContainer) {
@@ -2208,7 +5287,7 @@ var useTableScroll = ({
2208
5287
  };
2209
5288
 
2210
5289
  // src/useTableViewport.ts
2211
- import { useCallback as useCallback16, useMemo as useMemo5, useRef as useRef13 } from "react";
5290
+ import { useCallback as useCallback22, useMemo as useMemo6, useRef as useRef14 } from "react";
2212
5291
  import {
2213
5292
  actualRowPositioning,
2214
5293
  virtualRowPositioning
@@ -2245,7 +5324,11 @@ var measurePinnedColumns = (columns) => {
2245
5324
  unpinnedWidth += visibleWidth;
2246
5325
  }
2247
5326
  }
2248
- return { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth };
5327
+ return {
5328
+ pinnedWidthLeft: pinnedWidthLeft + 4,
5329
+ pinnedWidthRight: pinnedWidthRight + 4,
5330
+ unpinnedWidth
5331
+ };
2249
5332
  };
2250
5333
  var useTableViewport = ({
2251
5334
  columns,
@@ -2255,20 +5338,20 @@ var useTableViewport = ({
2255
5338
  rowHeight,
2256
5339
  size
2257
5340
  }) => {
2258
- const pctScrollTopRef = useRef13(0);
5341
+ const pctScrollTopRef = useRef14(0);
2259
5342
  const appliedRowCount = Math.min(rowCount, MAX_RAW_ROWS);
2260
5343
  const appliedContentHeight = appliedRowCount * rowHeight;
2261
5344
  const virtualContentHeight = rowCount * rowHeight;
2262
5345
  const virtualisedExtent = virtualContentHeight - appliedContentHeight;
2263
- const { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth } = useMemo5(
5346
+ const { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth } = useMemo6(
2264
5347
  () => measurePinnedColumns(columns),
2265
5348
  [columns]
2266
5349
  );
2267
- const [actualRowOffset, actualRowAtPosition] = useMemo5(
5350
+ const [actualRowOffset, actualRowAtPosition] = useMemo6(
2268
5351
  () => actualRowPositioning(rowHeight),
2269
5352
  [rowHeight]
2270
5353
  );
2271
- const [getRowOffset, getRowAtPosition] = useMemo5(() => {
5354
+ const [getRowOffset, getRowAtPosition] = useMemo6(() => {
2272
5355
  if (virtualisedExtent) {
2273
5356
  return virtualRowPositioning(
2274
5357
  rowHeight,
@@ -2279,10 +5362,10 @@ var useTableViewport = ({
2279
5362
  return [actualRowOffset, actualRowAtPosition];
2280
5363
  }
2281
5364
  }, [actualRowAtPosition, actualRowOffset, virtualisedExtent, rowHeight]);
2282
- const setPctScrollTop = useCallback16((scrollPct) => {
5365
+ const setPctScrollTop = useCallback22((scrollPct) => {
2283
5366
  pctScrollTopRef.current = scrollPct;
2284
5367
  }, []);
2285
- return useMemo5(() => {
5368
+ return useMemo6(() => {
2286
5369
  var _a;
2287
5370
  if (size) {
2288
5371
  const headingsDepth = headings.length;
@@ -2335,22 +5418,22 @@ import {
2335
5418
  getColumnsInViewport,
2336
5419
  itemsChanged
2337
5420
  } from "@vuu-ui/vuu-utils";
2338
- import { useCallback as useCallback17, useEffect as useEffect4, useMemo as useMemo6, useRef as useRef14, useState as useState4 } from "react";
5421
+ import { useCallback as useCallback23, useEffect as useEffect8, useMemo as useMemo7, useRef as useRef15, useState as useState8 } from "react";
2339
5422
  var useVirtualViewport = ({
2340
5423
  columns,
2341
5424
  getRowAtPosition,
2342
5425
  setRange,
2343
5426
  viewportMeasurements
2344
5427
  }) => {
2345
- const firstRowRef = useRef14(-1);
5428
+ const firstRowRef = useRef15(-1);
2346
5429
  const {
2347
5430
  rowCount: viewportRowCount,
2348
5431
  contentWidth,
2349
5432
  maxScrollContainerScrollHorizontal
2350
5433
  } = viewportMeasurements;
2351
5434
  const availableWidth = contentWidth - maxScrollContainerScrollHorizontal;
2352
- const scrollLeftRef = useRef14(0);
2353
- const [visibleColumns, preSpan] = useMemo6(
5435
+ const scrollLeftRef = useRef15(0);
5436
+ const [visibleColumns, preSpan] = useMemo7(
2354
5437
  () => getColumnsInViewport(
2355
5438
  columns,
2356
5439
  scrollLeftRef.current,
@@ -2358,12 +5441,12 @@ var useVirtualViewport = ({
2358
5441
  ),
2359
5442
  [availableWidth, columns]
2360
5443
  );
2361
- const preSpanRef = useRef14(preSpan);
2362
- useEffect4(() => {
5444
+ const preSpanRef = useRef15(preSpan);
5445
+ useEffect8(() => {
2363
5446
  setColumnsWithinViewport(visibleColumns);
2364
5447
  }, [visibleColumns]);
2365
- const [columnsWithinViewport, setColumnsWithinViewport] = useState4(visibleColumns);
2366
- const handleHorizontalScroll = useCallback17(
5448
+ const [columnsWithinViewport, setColumnsWithinViewport] = useState8(visibleColumns);
5449
+ const handleHorizontalScroll = useCallback23(
2367
5450
  (scrollLeft) => {
2368
5451
  scrollLeftRef.current = scrollLeft;
2369
5452
  const [visibleColumns2, pre] = getColumnsInViewport(
@@ -2378,7 +5461,7 @@ var useVirtualViewport = ({
2378
5461
  },
2379
5462
  [availableWidth, columns, columnsWithinViewport]
2380
5463
  );
2381
- const handleVerticalScroll = useCallback17(
5464
+ const handleVerticalScroll = useCallback23(
2382
5465
  (scrollTop) => {
2383
5466
  const firstRow = getRowAtPosition(scrollTop);
2384
5467
  if (firstRow !== firstRowRef.current) {
@@ -2399,7 +5482,7 @@ var useVirtualViewport = ({
2399
5482
 
2400
5483
  // src/useTable.ts
2401
5484
  var NO_ROWS = [];
2402
- var { KEY: KEY2, IS_EXPANDED: IS_EXPANDED2, IS_LEAF: IS_LEAF2 } = metadataKeys8;
5485
+ var { KEY: KEY3, IS_EXPANDED: IS_EXPANDED2, IS_LEAF: IS_LEAF2 } = metadataKeys10;
2403
5486
  var useTable = ({
2404
5487
  config,
2405
5488
  dataSource,
@@ -2414,15 +5497,15 @@ var useTable = ({
2414
5497
  ...measuredProps
2415
5498
  }) => {
2416
5499
  var _a, _b;
2417
- const [rowCount, setRowCount] = useState5(dataSource.size);
2418
- const expectConfigChangeRef = useRef15(false);
2419
- const dataSourceRef = useRef15();
5500
+ const [rowCount, setRowCount] = useState9(dataSource.size);
5501
+ const expectConfigChangeRef = useRef16(false);
5502
+ const dataSourceRef = useRef16();
2420
5503
  dataSourceRef.current = dataSource;
2421
5504
  if (dataSource === void 0) {
2422
5505
  throw Error("no data source provided to Vuu Table");
2423
5506
  }
2424
5507
  const containerMeasurements = useMeasuredContainer(measuredProps);
2425
- const onDataRowcountChange = useCallback18((size) => {
5508
+ const onDataRowcountChange = useCallback24((size) => {
2426
5509
  setRowCount(size);
2427
5510
  }, []);
2428
5511
  const { columns, dispatchColumnAction, headings } = useTableModel(
@@ -2442,7 +5525,7 @@ var useTable = ({
2442
5525
  rowHeight,
2443
5526
  size: containerMeasurements.innerSize
2444
5527
  });
2445
- const onSubscribed = useCallback18(
5528
+ const onSubscribed = useCallback24(
2446
5529
  ({ tableSchema }) => {
2447
5530
  if (tableSchema) {
2448
5531
  expectConfigChangeRef.current = true;
@@ -2456,7 +5539,7 @@ var useTable = ({
2456
5539
  },
2457
5540
  [dispatchColumnAction]
2458
5541
  );
2459
- const handleSelectionChange = useCallback18(
5542
+ const handleSelectionChange = useCallback24(
2460
5543
  (selected) => {
2461
5544
  dataSource.select(selected);
2462
5545
  onSelectionChange == null ? void 0 : onSelectionChange(selected);
@@ -2476,9 +5559,9 @@ var useTable = ({
2476
5559
  renderBufferSize,
2477
5560
  viewportRowCount: viewportMeasurements.rowCount
2478
5561
  });
2479
- const dataRef = useRef15();
5562
+ const dataRef = useRef16();
2480
5563
  dataRef.current = data;
2481
- const onPersistentColumnOperation = useCallback18(
5564
+ const onPersistentColumnOperation = useCallback24(
2482
5565
  (action) => {
2483
5566
  expectConfigChangeRef.current = true;
2484
5567
  dispatchColumnAction(action);
@@ -2489,7 +5572,7 @@ var useTable = ({
2489
5572
  dataSource,
2490
5573
  onPersistentColumnOperation
2491
5574
  });
2492
- const handleSort = useCallback18(
5575
+ const handleSort = useCallback24(
2493
5576
  (column, extendSort = false, sortType) => {
2494
5577
  if (dataSource) {
2495
5578
  dataSource.sort = applySort(
@@ -2502,7 +5585,7 @@ var useTable = ({
2502
5585
  },
2503
5586
  [dataSource]
2504
5587
  );
2505
- const handleColumnResize = useCallback18(
5588
+ const handleColumnResize = useCallback24(
2506
5589
  (phase, columnName, width) => {
2507
5590
  const column = columns.find((column2) => column2.name === columnName);
2508
5591
  if (column) {
@@ -2523,10 +5606,10 @@ var useTable = ({
2523
5606
  },
2524
5607
  [columns, dispatchColumnAction]
2525
5608
  );
2526
- const handleToggleGroup = useCallback18(
5609
+ const handleToggleGroup = useCallback24(
2527
5610
  (row, column) => {
2528
5611
  const isJson = isJsonGroup2(column, row);
2529
- const key = row[KEY2];
5612
+ const key = row[KEY3];
2530
5613
  if (row[IS_EXPANDED2]) {
2531
5614
  dataSource.closeTreeNode(key, true);
2532
5615
  if (isJson) {
@@ -2570,7 +5653,7 @@ var useTable = ({
2570
5653
  setRange,
2571
5654
  viewportMeasurements
2572
5655
  });
2573
- const handleVerticalScroll = useCallback18(
5656
+ const handleVerticalScroll = useCallback24(
2574
5657
  (scrollTop, pctScrollTop) => {
2575
5658
  setPctScrollTop(pctScrollTop);
2576
5659
  onVerticalScroll(scrollTop);
@@ -2591,7 +5674,7 @@ var useTable = ({
2591
5674
  rowCount: dataSource == null ? void 0 : dataSource.size,
2592
5675
  viewportRange: range
2593
5676
  });
2594
- const handleRemoveColumnFromGroupBy = useCallback18(
5677
+ const handleRemoveColumnFromGroupBy = useCallback24(
2595
5678
  (column) => {
2596
5679
  if (column) {
2597
5680
  if (dataSource && dataSource.groupBy.includes(column.name)) {
@@ -2605,7 +5688,7 @@ var useTable = ({
2605
5688
  },
2606
5689
  [dataSource]
2607
5690
  );
2608
- const handleDropColumn = useCallback18(
5691
+ const handleDropColumn = useCallback24(
2609
5692
  (fromIndex, toIndex) => {
2610
5693
  const column = dataSource.columns[fromIndex];
2611
5694
  const columns2 = moveItem2(dataSource.columns, column, toIndex);
@@ -2619,7 +5702,7 @@ var useTable = ({
2619
5702
  const draggableHook = useDraggableColumn({
2620
5703
  onDrop: handleDropColumn
2621
5704
  });
2622
- useEffect5(() => {
5705
+ useEffect9(() => {
2623
5706
  if (dataSourceRef.current) {
2624
5707
  expectConfigChangeRef.current = true;
2625
5708
  dispatchColumnAction({
@@ -2629,7 +5712,7 @@ var useTable = ({
2629
5712
  });
2630
5713
  }
2631
5714
  }, [config, dispatchColumnAction]);
2632
- useEffect5(() => {
5715
+ useEffect9(() => {
2633
5716
  dataSource.on("config", (config2, confirmed) => {
2634
5717
  expectConfigChangeRef.current = true;
2635
5718
  dispatchColumnAction({
@@ -2639,7 +5722,7 @@ var useTable = ({
2639
5722
  });
2640
5723
  });
2641
5724
  }, [dataSource, dispatchColumnAction]);
2642
- useMemo7(() => {
5725
+ useMemo8(() => {
2643
5726
  if (expectConfigChangeRef.current) {
2644
5727
  onConfigChange == null ? void 0 : onConfigChange({
2645
5728
  ...config,
@@ -2649,7 +5732,7 @@ var useTable = ({
2649
5732
  }
2650
5733
  }, [columns, config, onConfigChange]);
2651
5734
  const showContextMenu = usePopupContextMenu();
2652
- const onContextMenu = useCallback18(
5735
+ const onContextMenu = useCallback24(
2653
5736
  (evt) => {
2654
5737
  var _a2;
2655
5738
  const { current: currentData } = dataRef;
@@ -2831,12 +5914,12 @@ var Table = ({
2831
5914
  import cx8 from "classnames";
2832
5915
  import {
2833
5916
  isJsonAttribute,
2834
- metadataKeys as metadataKeys9,
5917
+ metadataKeys as metadataKeys11,
2835
5918
  registerComponent
2836
5919
  } from "@vuu-ui/vuu-utils";
2837
5920
  import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
2838
5921
  var classBase7 = "vuuJsonCell";
2839
- var { IS_EXPANDED: IS_EXPANDED3, KEY: KEY3 } = metadataKeys9;
5922
+ var { IS_EXPANDED: IS_EXPANDED3, KEY: KEY4 } = metadataKeys11;
2840
5923
  var localKey = (key) => {
2841
5924
  const pos = key.lastIndexOf("|");
2842
5925
  if (pos === -1) {
@@ -2856,7 +5939,7 @@ var JsonCell = ({ column, row }) => {
2856
5939
  value = value.slice(0, -1);
2857
5940
  isToggle = true;
2858
5941
  }
2859
- const rowKey = localKey(row[KEY3]);
5942
+ const rowKey = localKey(row[KEY4]);
2860
5943
  const className = cx8({
2861
5944
  [`${classBase7}-name`]: rowKey === value,
2862
5945
  [`${classBase7}-value`]: rowKey !== value,
@@ -2876,9 +5959,13 @@ var JsonCell = ({ column, row }) => {
2876
5959
  };
2877
5960
  registerComponent("json", JsonCell, "cell-renderer", {});
2878
5961
  export {
5962
+ ColumnResizer,
2879
5963
  Table,
2880
5964
  buildContextMenuDescriptors,
5965
+ isShowSettings,
2881
5966
  useMeasuredContainer,
5967
+ useSelection,
5968
+ useTableColumnResize,
2882
5969
  useTableContextMenu,
2883
5970
  useTableModel,
2884
5971
  useTableViewport