react-dsl-editor 0.3.0 → 0.3.2

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.
@@ -1,15 +1,15 @@
1
1
  import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
2
- import { jsx, jsxs } from "react/jsx-runtime";
3
- var __create = Object.create, __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __getOwnPropNames = Object.getOwnPropertyNames, __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty, __commonJSMin = (o, _) => () => (_ || o((_ = { exports: {} }).exports, _), _.exports), __copyProps = (o, _, v, y) => {
4
- if (_ && typeof _ == "object" || typeof _ == "function") for (var b = __getOwnPropNames(_), x = 0, S = b.length, C; x < S; x++) C = b[x], !__hasOwnProp.call(o, C) && C !== v && __defProp(o, C, {
5
- get: ((o) => _[o]).bind(null, C),
6
- enumerable: !(y = __getOwnPropDesc(_, C)) || y.enumerable
2
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
+ var __create = Object.create, __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __getOwnPropNames = Object.getOwnPropertyNames, __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty, __commonJSMin = (o, h) => () => (h || o((h = { exports: {} }).exports, h), h.exports), __copyProps = (o, h, g, _) => {
4
+ if (h && typeof h == "object" || typeof h == "function") for (var v = __getOwnPropNames(h), y = 0, b = v.length, x; y < b; y++) x = v[y], !__hasOwnProp.call(o, x) && x !== g && __defProp(o, x, {
5
+ get: ((o) => h[o]).bind(null, x),
6
+ enumerable: !(_ = __getOwnPropDesc(h, x)) || _.enumerable
7
7
  });
8
8
  return o;
9
- }, __toESM = (o, _, v) => (v = o == null ? {} : __create(__getProtoOf(o)), __copyProps(_ || !o || !o.__esModule ? __defProp(v, "default", {
9
+ }, __toESM = (o, h, g) => (g = o == null ? {} : __create(__getProtoOf(o)), __copyProps(h || !o || !o.__esModule ? __defProp(g, "default", {
10
10
  value: o,
11
11
  enumerable: !0
12
- }) : v, o));
12
+ }) : g, o));
13
13
  const textStyle = {
14
14
  position: "absolute",
15
15
  inset: 0,
@@ -18,84 +18,84 @@ const textStyle = {
18
18
  fontSize: "1em",
19
19
  lineHeight: "1.3em",
20
20
  fontFamily: "monospace"
21
- }, ReadOnlyTextarea = forwardRef(function({ wrap: o, children: _, style: v = {} }, y) {
21
+ }, ReadOnlyTextarea = forwardRef(function({ wrap: o, children: h, style: g = {} }, _) {
22
22
  return /* @__PURE__ */ jsx("pre", {
23
- ref: y,
23
+ ref: _,
24
24
  style: {
25
25
  ...textStyle,
26
26
  pointerEvents: "none",
27
27
  margin: 0,
28
28
  overflow: "auto",
29
29
  whiteSpace: o ? "pre-wrap" : "pre",
30
- ...v
30
+ ...g
31
31
  },
32
- children: _
32
+ children: h
33
33
  });
34
34
  });
35
- function e$4(o, _, v) {
36
- let y = (v) => o(v, ..._);
37
- return v === void 0 ? y : Object.assign(y, {
38
- lazy: v,
39
- lazyArgs: _
35
+ function e$4(o, h, g) {
36
+ let _ = (g) => o(g, ...h);
37
+ return g === void 0 ? _ : Object.assign(_, {
38
+ lazy: g,
39
+ lazyArgs: h
40
40
  });
41
41
  }
42
- function t$10(o, _, v) {
43
- let y = o.length - _.length;
44
- if (y === 0) return o(..._);
45
- if (y === 1) return e$4(o, _, v);
42
+ function t$10(o, h, g) {
43
+ let _ = o.length - h.length;
44
+ if (_ === 0) return o(...h);
45
+ if (_ === 1) return e$4(o, h, g);
46
46
  throw Error("Wrong number of arguments");
47
47
  }
48
48
  function t$5(...o) {
49
49
  return t$10(n$13, o);
50
50
  }
51
- var n$13 = (o, _) => o ?? _, e$3 = {
51
+ var n$13 = (o, h) => o ?? h, e$3 = {
52
52
  done: !0,
53
53
  hasNext: !1
54
54
  }, t$8 = {
55
55
  done: !1,
56
56
  hasNext: !1
57
57
  }, n$5 = () => e$3;
58
- function t(o, ..._) {
59
- let v = o, y = _.map((o) => "lazy" in o ? r$8(o) : void 0), b = 0;
60
- for (; b < _.length;) {
61
- if (y[b] === void 0 || !i$4(v)) {
62
- let o = _[b];
63
- v = o(v), b += 1;
58
+ function t(o, ...h) {
59
+ let g = o, _ = h.map((o) => "lazy" in o ? r$8(o) : void 0), v = 0;
60
+ for (; v < h.length;) {
61
+ if (_[v] === void 0 || !i$4(g)) {
62
+ let o = h[v];
63
+ g = o(g), v += 1;
64
64
  continue;
65
65
  }
66
66
  let o = [];
67
- for (let v = b; v < _.length; v++) {
68
- let _ = y[v];
69
- if (_ === void 0 || (o.push(_), _.isSingle)) break;
67
+ for (let g = v; g < h.length; g++) {
68
+ let h = _[g];
69
+ if (h === void 0 || (o.push(h), h.isSingle)) break;
70
70
  }
71
- let x = [];
72
- for (let _ of v) if (n$12(_, x, o)) break;
73
- let { isSingle: S } = o.at(-1);
74
- v = S ? x[0] : x, b += o.length;
71
+ let y = [];
72
+ for (let h of g) if (n$12(h, y, o)) break;
73
+ let { isSingle: b } = o.at(-1);
74
+ g = b ? y[0] : y, v += o.length;
75
75
  }
76
- return v;
76
+ return g;
77
77
  }
78
- function n$12(o, _, v) {
79
- if (v.length === 0) return _.push(o), !1;
80
- let y = o, b = t$8, x = !1;
81
- for (let [o, S] of v.entries()) {
82
- let { index: C, items: w } = S;
83
- if (w.push(y), b = S(y, C, w), S.index += 1, b.hasNext) {
84
- if (b.hasMany ?? !1) {
85
- for (let y of b.next) if (n$12(y, _, v.slice(o + 1))) return !0;
86
- return x;
78
+ function n$12(o, h, g) {
79
+ if (g.length === 0) return h.push(o), !1;
80
+ let _ = o, v = t$8, y = !1;
81
+ for (let [o, b] of g.entries()) {
82
+ let { index: x, items: S } = b;
83
+ if (S.push(_), v = b(_, x, S), b.index += 1, v.hasNext) {
84
+ if (v.hasMany ?? !1) {
85
+ for (let _ of v.next) if (n$12(_, h, g.slice(o + 1))) return !0;
86
+ return y;
87
87
  }
88
- y = b.next;
88
+ _ = v.next;
89
89
  }
90
- if (!b.hasNext) break;
91
- b.done && (x = !0);
90
+ if (!v.hasNext) break;
91
+ v.done && (y = !0);
92
92
  }
93
- return b.hasNext && _.push(y), x;
93
+ return v.hasNext && h.push(_), y;
94
94
  }
95
95
  function r$8(o) {
96
- let { lazy: _, lazyArgs: v } = o, y = _(...v);
97
- return Object.assign(y, {
98
- isSingle: _.single ?? !1,
96
+ let { lazy: h, lazyArgs: g } = o, _ = h(...g);
97
+ return Object.assign(_, {
98
+ isSingle: h.single ?? !1,
99
99
  index: 0,
100
100
  items: []
101
101
  });
@@ -103,58 +103,58 @@ function r$8(o) {
103
103
  function i$4(o) {
104
104
  return typeof o == "string" || typeof o == "object" && !!o && Symbol.iterator in o;
105
105
  }
106
- function t$9(o, _) {
107
- let v = _.length - o.length;
108
- if (v === 1) {
109
- let [v, ...y] = _;
110
- return t(v, {
106
+ function t$9(o, h) {
107
+ let g = h.length - o.length;
108
+ if (g === 1) {
109
+ let [g, ..._] = h;
110
+ return t(g, {
111
111
  lazy: o,
112
- lazyArgs: y
112
+ lazyArgs: _
113
113
  });
114
114
  }
115
- if (v === 0) {
116
- let v = {
115
+ if (g === 0) {
116
+ let g = {
117
117
  lazy: o,
118
- lazyArgs: _
118
+ lazyArgs: h
119
119
  };
120
- return Object.assign((o) => t(o, v), v);
120
+ return Object.assign((o) => t(o, g), g);
121
121
  }
122
122
  throw Error("Wrong number of arguments");
123
123
  }
124
124
  var e$2 = {
125
- asc: (o, _) => o > _,
126
- desc: (o, _) => o < _
125
+ asc: (o, h) => o > h,
126
+ desc: (o, h) => o < h
127
127
  };
128
- function t$11(o, _) {
129
- let [v, ...y] = _;
130
- if (!i$3(v)) {
131
- let _ = r$7(...y);
132
- return o(v, _);
128
+ function t$11(o, h) {
129
+ let [g, ..._] = h;
130
+ if (!i$3(g)) {
131
+ let h = r$7(..._);
132
+ return o(g, h);
133
133
  }
134
- let b = r$7(v, ...y);
135
- return (_) => o(_, b);
134
+ let v = r$7(g, ..._);
135
+ return (h) => o(h, v);
136
136
  }
137
- function r$7(o, _, ...v) {
138
- let y = typeof o == "function" ? o : o[0], b = typeof o == "function" ? "asc" : o[1], { [b]: x } = e$2, S = _ === void 0 ? void 0 : r$7(_, ...v);
139
- return (o, _) => {
140
- let v = y(o), b = y(_);
141
- return x(v, b) ? 1 : x(b, v) ? -1 : S?.(o, _) ?? 0;
137
+ function r$7(o, h, ...g) {
138
+ let _ = typeof o == "function" ? o : o[0], v = typeof o == "function" ? "asc" : o[1], { [v]: y } = e$2, b = h === void 0 ? void 0 : r$7(h, ...g);
139
+ return (o, h) => {
140
+ let g = _(o), v = _(h);
141
+ return y(g, v) ? 1 : y(v, g) ? -1 : b?.(o, h) ?? 0;
142
142
  };
143
143
  }
144
144
  function i$3(o) {
145
145
  if (a$1(o)) return !0;
146
146
  if (typeof o != "object" || !Array.isArray(o)) return !1;
147
- let [_, v, ...y] = o;
148
- return a$1(_) && typeof v == "string" && v in e$2 && y.length === 0;
147
+ let [h, g, ..._] = o;
148
+ return a$1(h) && typeof g == "string" && g in e$2 && _.length === 0;
149
149
  }
150
150
  var a$1 = (o) => typeof o == "function" && o.length === 1;
151
151
  function n(...o) {
152
152
  return t$10(r$6, o, i$2);
153
153
  }
154
- var r$6 = (o, _) => o.filter(_), i$2 = (o) => (_, v, y) => o(_, v, y) ? {
154
+ var r$6 = (o, h) => o.filter(h), i$2 = (o) => (h, g, _) => o(h, g, _) ? {
155
155
  done: !1,
156
156
  hasNext: !0,
157
- next: _
157
+ next: h
158
158
  } : t$8, e$1 = (o) => Object.assign(o, { single: !0 });
159
159
  function n$1(...o) {
160
160
  return t$10(r$5, o, e$1(i$1));
@@ -167,17 +167,17 @@ var r$5 = ([o]) => o, i$1 = () => a, a = (o) => ({
167
167
  function t$7(...o) {
168
168
  return t$10(n$11, o, r$4);
169
169
  }
170
- var n$11 = (o, _) => o.flatMap(_), r$4 = (o) => (_, v, y) => {
171
- let b = o(_, v, y);
172
- return Array.isArray(b) ? {
170
+ var n$11 = (o, h) => o.flatMap(h), r$4 = (o) => (h, g, _) => {
171
+ let v = o(h, g, _);
172
+ return Array.isArray(v) ? {
173
173
  done: !1,
174
174
  hasNext: !0,
175
175
  hasMany: !0,
176
- next: b
176
+ next: v
177
177
  } : {
178
178
  done: !1,
179
179
  hasNext: !0,
180
- next: b
180
+ next: v
181
181
  };
182
182
  };
183
183
  function e(o) {
@@ -190,10 +190,10 @@ var n$10 = (o) => o.at(-1);
190
190
  function t$3(...o) {
191
191
  return t$10(n$9, o, r$3);
192
192
  }
193
- var n$9 = (o, _) => o.map(_), r$3 = (o) => (_, v, y) => ({
193
+ var n$9 = (o, h) => o.map(h), r$3 = (o) => (h, g, _) => ({
194
194
  done: !1,
195
195
  hasNext: !0,
196
- next: o(_, v, y)
196
+ next: o(h, g, _)
197
197
  });
198
198
  function t$6(...o) {
199
199
  return t$10(n$8, o);
@@ -202,24 +202,24 @@ var n$8 = (o) => o.length === 1 ? o[0] : void 0;
202
202
  function t$4(...o) {
203
203
  return t$10(n$7, o);
204
204
  }
205
- function n$7(o, _) {
206
- let v = [];
207
- for (let y = o; y < _; y++) v.push(y);
208
- return v;
205
+ function n$7(o, h) {
206
+ let g = [];
207
+ for (let _ = o; _ < h; _++) g.push(_);
208
+ return g;
209
209
  }
210
210
  function t$1(...o) {
211
211
  return t$11(n$6, o);
212
212
  }
213
- var n$6 = (o, _) => [...o].sort(_);
213
+ var n$6 = (o, h) => [...o].sort(h);
214
214
  function n$3(...o) {
215
215
  return t$10(r$2, o, i);
216
216
  }
217
- var r$2 = (o, _) => _ < 0 ? [] : o.slice(0, _);
217
+ var r$2 = (o, h) => h < 0 ? [] : o.slice(0, h);
218
218
  function i(o) {
219
219
  if (o <= 0) return n$5;
220
- let _ = o;
221
- return (o) => (--_, {
222
- done: _ <= 0,
220
+ let h = o;
221
+ return (o) => (--h, {
222
+ done: h <= 0,
223
223
  hasNext: !0,
224
224
  next: o
225
225
  });
@@ -229,121 +229,120 @@ function n$2(...o) {
229
229
  }
230
230
  function r$1() {
231
231
  let o = /* @__PURE__ */ new Set();
232
- return (_) => o.has(_) ? t$8 : (o.add(_), {
232
+ return (h) => o.has(h) ? t$8 : (o.add(h), {
233
233
  done: !1,
234
234
  hasNext: !0,
235
- next: _
235
+ next: h
236
236
  });
237
237
  }
238
238
  function n$4(...o) {
239
239
  return t$9(r, o);
240
240
  }
241
241
  function r(o) {
242
- let _ = o, v = /* @__PURE__ */ new Set();
243
- return (o, y, b) => {
244
- let x = _(o, y, b);
245
- return v.has(x) ? t$8 : (v.add(x), {
242
+ let h = o, g = /* @__PURE__ */ new Set();
243
+ return (o, _, v) => {
244
+ let y = h(o, _, v);
245
+ return g.has(y) ? t$8 : (g.add(y), {
246
246
  done: !1,
247
247
  hasNext: !0,
248
248
  next: o
249
249
  });
250
250
  };
251
251
  }
252
- var colors = [
253
- "#FF0000",
254
- "#0000FF",
255
- "#FF00FF",
256
- "#800000",
257
- "#008000",
258
- "#000080",
259
- "#808000",
260
- "#800080",
261
- "#008080",
262
- "#808080",
263
- "#993366",
264
- "#336699"
265
- ], colorAssignments = /* @__PURE__ */ new Map();
266
- function getColorAssigment(o) {
267
- let _ = String(o), v = colorAssignments.get(_);
268
- if (v) return v;
269
- let y = colors[colorAssignments.size % colors.length];
270
- return colorAssignments.set(_, y), console.log(colorAssignments), y;
271
- }
272
- function defaultStyleFor(o) {
273
- let { name: _, regex: v } = o.grammar.meta ?? {}, y = _ ?? v;
274
- if (y) return { color: getColorAssigment(y) };
275
- }
276
- function SyntaxHighlighter({ cstRoot: o, ref: _, wrap: v }) {
252
+ var squiggly = {
253
+ textDecorationLine: "underline",
254
+ textDecorationStyle: "wavy",
255
+ textDecorationColor: "red"
256
+ };
257
+ function SyntaxHighlighter({ cstRoot: o, ref: h, wrap: g, syntaxColors: _ }) {
277
258
  return /* @__PURE__ */ jsx(ReadOnlyTextarea, {
278
- ref: _,
279
- wrap: v,
259
+ ref: h,
260
+ wrap: g,
280
261
  children: /* @__PURE__ */ jsx(StyledNode, {
281
262
  node: o,
282
- styleFor: defaultStyleFor
263
+ styleFor: _
283
264
  })
284
265
  });
285
266
  }
267
+ function ErrorHighlighter({ ref: o, wrap: h, errors: g, children: _ }) {
268
+ let v = `${_} `, [y] = g;
269
+ return y ? /* @__PURE__ */ jsxs(ReadOnlyTextarea, {
270
+ ref: o,
271
+ wrap: h,
272
+ "data-id": "ErrorHighlighter",
273
+ style: { color: "transparent" },
274
+ children: [
275
+ v.substring(0, y.start),
276
+ /* @__PURE__ */ jsx("span", {
277
+ style: squiggly,
278
+ title: y.message,
279
+ children: v.substring(y.start, y.end)
280
+ }),
281
+ v.substring(y.end)
282
+ ]
283
+ }) : /* @__PURE__ */ jsx(Fragment, {});
284
+ }
286
285
  function StyledNode(o) {
287
- let _ = o.styleFor(o.node);
286
+ let h = o.styleFor(o.node);
288
287
  return /* @__PURE__ */ jsx("span", {
289
- style: _,
290
- children: e(o.node.children ?? []) ? o.node.text : o.node.children.map((_, v) => /* @__PURE__ */ jsx(StyledNode, {
291
- node: _,
288
+ style: h,
289
+ children: e(o.node.children ?? []) ? o.node.text : o.node.children.map((h, g) => /* @__PURE__ */ jsx(StyledNode, {
290
+ node: h,
292
291
  styleFor: o.styleFor
293
- }, v))
292
+ }, g))
294
293
  });
295
294
  }
296
- function cstPathAt(o, _) {
297
- return _cstPathAt(o, _, []);
295
+ function cstPathAt(o, h) {
296
+ return _cstPathAt(o, h, []);
298
297
  }
299
- function _cstPathAt(o, _, v = []) {
300
- return o.offset <= _ && _ <= o.end ? (v.push(o), o.children?.forEach((o) => _cstPathAt(o, _, v)), v) : [];
298
+ function _cstPathAt(o, h, g = []) {
299
+ return o.offset <= h && h <= o.end ? (g.push(o), o.children?.forEach((o) => _cstPathAt(o, h, g)), g) : [];
301
300
  }
302
- function getSuggestions(o, _, v = () => void 0) {
303
- let y = cstPathAt(o, _), b = t(y, t$7((o) => {
301
+ function getSuggestions(o, h, g = () => void 0) {
302
+ let _ = cstPathAt(o, h), v = t(_, t$7((o) => {
304
303
  if (o.grammar.meta?.name !== void 0) {
305
- let _ = v(o);
306
- if (_) return _.map((_) => ({
304
+ let h = g(o);
305
+ if (h) return h.map((h) => ({
307
306
  node: o,
308
- suggestion: _
307
+ suggestion: h
309
308
  }));
310
309
  }
311
- return o.grammar.suggestions().map((_) => ({
310
+ return o.grammar.suggestions().map((h) => ({
312
311
  node: o,
313
- suggestion: _
312
+ suggestion: h
314
313
  }));
315
314
  }));
316
- return t(b, t$7((o) => {
317
- let v = o.node.text.substring(0, _ - o.node.offset);
318
- return o.suggestion.startsWith(v) ? [{
315
+ return t(v, t$7((o) => {
316
+ let g = o.node.text.substring(0, h - o.node.offset);
317
+ return o.suggestion.startsWith(g) ? [{
319
318
  suggestion: o.suggestion,
320
- prefix: v
319
+ prefix: g
321
320
  }] : [];
322
321
  }), n$4((o) => o.suggestion));
323
322
  }
324
- const CursorPosition = forwardRef(function(o, _) {
325
- let v = useRef(null), b = useRef(null);
326
- return useImperativeHandle(_, () => ({ getCursorPosition() {
327
- if (!v.current || !b.current) return {
323
+ const CursorPosition = forwardRef(function(o, h) {
324
+ let g = useRef(null), v = useRef(null);
325
+ return useImperativeHandle(h, () => ({ getCursorPosition() {
326
+ if (!g.current || !v.current) return {
328
327
  top: 0,
329
328
  left: 0
330
329
  };
331
- let { offsetTop: o, offsetLeft: _ } = v.current, { scrollTop: y, scrollLeft: x } = b.current, S = window.getComputedStyle(b.current), C = parseInt(S.lineHeight);
330
+ let { offsetTop: o, offsetLeft: h } = g.current, { scrollTop: _, scrollLeft: y } = v.current, b = window.getComputedStyle(v.current), x = parseInt(b.lineHeight);
332
331
  return {
333
- top: o - y + C,
334
- left: _ - x
332
+ top: o - _ + x,
333
+ left: h - y
335
334
  };
336
335
  } }), []), /* @__PURE__ */ jsxs(ReadOnlyTextarea, {
337
- ref: b,
336
+ ref: v,
338
337
  wrap: o.wrap,
339
338
  style: { visibility: "hidden" },
340
339
  children: [o.text, /* @__PURE__ */ jsx("span", {
341
- ref: v,
340
+ ref: g,
342
341
  children: "\xA0"
343
342
  })]
344
343
  });
345
344
  });
346
- function SuggestionsView({ suggestions: o, onSelect: _ }) {
345
+ function SuggestionsView({ suggestions: o, onSelect: h }) {
347
346
  return /* @__PURE__ */ jsx("div", {
348
347
  style: {
349
348
  display: "flex",
@@ -351,26 +350,28 @@ function SuggestionsView({ suggestions: o, onSelect: _ }) {
351
350
  padding: "4px 0",
352
351
  overflowY: "auto"
353
352
  },
354
- children: o.map((o, v) => /* @__PURE__ */ jsxs("button", {
355
- onClick: () => _(o),
353
+ children: o.map((o, g) => /* @__PURE__ */ jsxs("button", {
354
+ onClick: () => h(o),
356
355
  children: [
357
356
  "\xA0",
358
357
  o,
359
358
  "\xA0"
360
359
  ]
361
- }, v))
360
+ }, g))
362
361
  });
363
362
  }
364
363
  function shortcutName(o) {
365
- let _ = "";
366
- o.ctrlKey && (_ = "Ctrl");
367
- let { key: v } = o;
368
- return v === " " && (v = "Space"), `${_}${v}`;
364
+ let h = "";
365
+ o.ctrlKey && (h = "Ctrl");
366
+ let { key: g } = o;
367
+ return g === " " && (g = "Space"), `${h}${g}`;
369
368
  }
370
- function useSyncScroll(o) {
371
- return useCallback((_) => {
372
- let v = _.currentTarget;
373
- o.current && v && (o.current.scrollTop = v.scrollTop, o.current.scrollLeft = v.scrollLeft);
369
+ function useSyncScroll(...o) {
370
+ return useCallback((h) => {
371
+ let g = h.currentTarget;
372
+ o.forEach((o) => {
373
+ o.current && g && (o.current.scrollTop = g.scrollTop, o.current.scrollLeft = g.scrollLeft);
374
+ });
374
375
  }, [o]);
375
376
  }
376
377
  var ParsingError = class extends Error {
@@ -382,7 +383,10 @@ function success(o) {
382
383
  return o;
383
384
  }
384
385
  function error(o) {
385
- return o;
386
+ return {
387
+ ...o,
388
+ offset: 0
389
+ };
386
390
  }
387
391
  function isParserError(o) {
388
392
  return "expected" in o;
@@ -394,30 +398,39 @@ function asException(o) {
394
398
  return new ParsingError(`[${o.grammar.type}]: Expected ${o.expected.map((o) => `'${o}'`).join(" | ")}, but got '${o.got}'`);
395
399
  }
396
400
  function sequence(...o) {
397
- let _ = {
401
+ let h = {
398
402
  children: o,
399
403
  type: "sequence",
400
404
  suggestions() {
401
405
  return t(o, t$3((o) => o.suggestions()), n$3(1), t$6(), t$5([]));
402
406
  },
403
- parse(v, y) {
404
- let b = 0, x = [];
405
- for (let S of o) {
406
- let o = v.substring(b), C = y.faultCorrection(S.parse(o, y), _);
407
- if (isParserError(C)) {
408
- if (y.faultTolerant) continue;
409
- return C;
407
+ parse(g, _) {
408
+ let v = 0, y = [], b = !1;
409
+ for (let x of o) {
410
+ let o = g.substring(v), S = _.faultCorrection(x.parse(o, _), h);
411
+ if (isParserError(S)) {
412
+ if (_.faultTolerant) {
413
+ b = !0;
414
+ continue;
415
+ }
416
+ return {
417
+ ...S,
418
+ offset: v
419
+ };
410
420
  }
411
- b += C.text.length, x.push(C);
421
+ v += S.text.length, y.push({
422
+ ...S,
423
+ recoverableError: b
424
+ }), b = !1;
412
425
  }
413
426
  return success({
414
- grammar: _,
415
- text: v.substring(0, b),
416
- children: x
427
+ grammar: h,
428
+ text: g.substring(0, v),
429
+ children: y
417
430
  });
418
431
  }
419
432
  };
420
- return _;
433
+ return h;
421
434
  }
422
435
  const eof = {
423
436
  type: "eof",
@@ -435,17 +448,18 @@ const eof = {
435
448
  });
436
449
  }
437
450
  };
438
- function withOffset(o, _ = 0) {
439
- let v = _;
451
+ function withOffset(o, h = 0) {
452
+ let g = h;
440
453
  return {
441
454
  text: o.text,
442
- offset: _,
443
- end: _ + o.text.length,
444
- children: o.children?.map((o, _, y) => {
445
- let { text: b } = y[_ - 1] ?? { text: "" };
446
- return v += b.length, withOffset(o, v);
455
+ offset: h,
456
+ end: h + o.text.length,
457
+ children: o.children?.map((o, h, _) => {
458
+ let { text: v } = _[h - 1] ?? { text: "" };
459
+ return g += v.length, withOffset(o, g);
447
460
  }),
448
- grammar: o.grammar
461
+ grammar: o.grammar,
462
+ recoverableError: o.recoverableError ?? !1
449
463
  };
450
464
  }
451
465
  function _flatCST(o) {
@@ -454,37 +468,85 @@ function _flatCST(o) {
454
468
  function flatCST(o) {
455
469
  return _flatCST(o).filter((o) => o.text !== "");
456
470
  }
471
+ function getErrors(o) {
472
+ let h = o.children?.flatMap((o) => getErrors(o)) ?? [];
473
+ return o.recoverableError ? [{
474
+ start: o.offset,
475
+ end: Math.max(o.end, o.offset + 1),
476
+ message: o.grammar.type
477
+ }, ...h] : h;
478
+ }
457
479
  var DSLParser = class {
458
480
  grammar;
459
481
  constructor(o) {
460
482
  this.grammar = sequence(o, eof);
461
483
  }
462
- _parse(o) {
463
- let _ = this.grammar.parse(o, {
484
+ parse(o) {
485
+ let h = this.grammar.parse(o, {
464
486
  faultTolerant: !1,
465
487
  faultCorrection: (o) => o
466
- });
467
- return isParserError(_) ? this.grammar.parse(o, {
488
+ }), g = isParserError(h) ? this.grammar.parse(o, {
468
489
  faultTolerant: !0,
469
490
  faultCorrection: (o) => o
470
- }) : _;
471
- }
472
- parse(o) {
473
- let _ = this._parse(o);
474
- if (isParserError(_)) throw asException(_);
475
- let v = withOffset(_), y = flatCST(v);
491
+ }) : h;
492
+ if (isParserError(g)) throw asException(g);
493
+ let _ = withOffset(g), v = flatCST(_);
476
494
  return {
477
- cst: v,
478
- terminals: y,
479
- result: _
495
+ cst: _,
496
+ terminals: v,
497
+ result: g,
498
+ strictResult: isParserSuccess(h) ? h : void 0,
499
+ errors: getErrors(_)
480
500
  };
481
501
  }
482
- };
483
- function SuggestionsMenu({ suggestions: o, onSelect: _, style: v, selectedIndex: y, onHover: b }) {
502
+ }, themes = {
503
+ light: [
504
+ "#FF0000",
505
+ "#0000FF",
506
+ "#FF00FF",
507
+ "#800000",
508
+ "#008000",
509
+ "#000080",
510
+ "#808000",
511
+ "#800080",
512
+ "#008080",
513
+ "#808080",
514
+ "#993366",
515
+ "#336699"
516
+ ],
517
+ dark: [
518
+ "#FF5555",
519
+ "#5555FF",
520
+ "#FF55FF",
521
+ "#FF5555",
522
+ "#55FF55",
523
+ "#5555FF",
524
+ "#FFFF55",
525
+ "#FF55FF",
526
+ "#55FFFF",
527
+ "#AAAAAA",
528
+ "#CC99FF",
529
+ "#99CCFF"
530
+ ]
531
+ }, colorAssignments = /* @__PURE__ */ new Map();
532
+ function getColorAssigment(o, h) {
533
+ let g = String(o), _ = colorAssignments.get(g);
534
+ if (_) return _;
535
+ let v = h[colorAssignments.size % h.length];
536
+ return colorAssignments.set(g, v), console.log(colorAssignments), v;
537
+ }
538
+ function defaultStyleFor(o, h) {
539
+ let { name: g, regex: _ } = o.grammar.meta ?? {}, v = g ?? _;
540
+ if (v) return { color: getColorAssigment(v, h) };
541
+ }
542
+ function defaultSyntaxColors(o) {
543
+ return (h) => defaultStyleFor(h, themes[o]);
544
+ }
545
+ function SuggestionsMenu({ suggestions: o, onSelect: h, style: g, selectedIndex: _, onHover: v }) {
484
546
  return /* @__PURE__ */ jsx("div", {
485
547
  style: {
486
548
  position: "absolute",
487
- ...v,
549
+ ...g,
488
550
  background: "#252526",
489
551
  border: "1px solid #454545",
490
552
  boxShadow: "0 2px 8px rgba(0,0,0,0.3)",
@@ -494,89 +556,89 @@ function SuggestionsMenu({ suggestions: o, onSelect: _, style: v, selectedIndex:
494
556
  minWidth: 200,
495
557
  zIndex: 100
496
558
  },
497
- children: o.map((o, v) => /* @__PURE__ */ jsx("div", {
498
- onClick: () => _(o),
499
- onMouseOver: () => b(v),
559
+ children: o.map((o, g) => /* @__PURE__ */ jsx("div", {
560
+ onClick: () => h(o),
561
+ onMouseOver: () => v(g),
500
562
  style: {
501
563
  cursor: "pointer",
502
564
  padding: "4px 8px",
503
- backgroundColor: y === v ? "#094771" : "transparent"
565
+ backgroundColor: _ === g ? "#094771" : "transparent"
504
566
  },
505
567
  children: o
506
- }, v))
568
+ }, g))
507
569
  });
508
570
  }
509
- function DslEditor({ code: o, onChange: y, onParsed: T, grammar: E, wrap: D = !1, suggestions: O, className: k = DslEditor.name,...A }) {
510
- let [j, M] = useState([]), [N, F] = useState(), [I, L] = useState({
571
+ function DslEditor({ code: o, onChange: _, onParsed: x, grammar: w, wrap: T = !1, suggestions: E, className: D = DslEditor.name, syntaxColors: O = defaultSyntaxColors("light"),...k }) {
572
+ let [A, j] = useState([]), [M, P] = useState(), [F, I] = useState({
511
573
  top: 0,
512
574
  left: 0,
513
575
  visible: !1
514
- }), [R, z] = useState(0), [B, V] = useState(""), H = useRef(null), U = useRef(null), W = useRef(null), G = useRef(null), K = useCallback((o) => {
515
- let _ = U.current?.selectionStart ?? 0, v = getSuggestions(o, _, O);
516
- M(v);
517
- }, [O]), q = useCallback(() => {
518
- N && (K(N.cst), V(U.current?.value?.substring(0, U.current?.selectionStart ?? 0) ?? ""));
519
- }, [N, K]);
576
+ }), [L, R] = useState(0), [z, B] = useState(""), V = useRef(null), H = useRef(null), U = useRef(null), W = useRef(null), G = useRef(null), K = useCallback((o) => {
577
+ let h = H.current?.selectionStart ?? 0, g = getSuggestions(o, h, E);
578
+ j(g);
579
+ }, [E]), q = useCallback(() => {
580
+ M && (K(M.cst), B(H.current?.value?.substring(0, H.current?.selectionStart ?? 0) ?? ""));
581
+ }, [M, K]);
520
582
  useEffect(() => {
521
- H.current = new DSLParser(E);
522
- }, [E]), useEffect(() => {
523
- if (!H.current) return;
524
- let _ = H.current.parse(o);
525
- F(_), T?.(_.result), K(_.cst), V(o.substring(0, U.current?.selectionStart ?? 0));
583
+ V.current = new DSLParser(w);
584
+ }, [w]), useEffect(() => {
585
+ if (!V.current) return;
586
+ let h = V.current.parse(o);
587
+ P(h), x?.(h), K(h.cst), B(o.substring(0, H.current?.selectionStart ?? 0));
526
588
  }, [
527
589
  o,
528
- T,
590
+ x,
529
591
  K
530
592
  ]);
531
- let J = useCallback(() => W.current?.getCursorPosition?.() ?? {
593
+ let J = useCallback(() => U.current?.getCursorPosition?.() ?? {
532
594
  top: 0,
533
595
  left: 0
534
596
  }, []), Y = useCallback((o) => {
535
- U.current && console.log(o);
597
+ H.current && console.log(o);
536
598
  }, [
537
599
  o,
538
- y,
539
- j
600
+ _,
601
+ A
540
602
  ]), X = useMemo(() => ({
541
603
  ArrowDown() {
542
- z((o) => (o + 1) % j.length);
604
+ R((o) => (o + 1) % A.length);
543
605
  },
544
606
  ArrowUp() {
545
- z((o) => (o - 1 + j.length) % j.length);
607
+ R((o) => (o - 1 + A.length) % A.length);
546
608
  },
547
609
  Enter() {
548
- j[R] && Y(j[R].suggestion);
610
+ A[L] && Y(A[L].suggestion);
549
611
  },
550
612
  Escape() {
551
- L((o) => ({
613
+ I((o) => ({
552
614
  ...o,
553
615
  visible: !1
554
616
  }));
555
617
  }
556
618
  }), [
557
619
  Y,
558
- R,
559
- j
620
+ L,
621
+ A
560
622
  ]), Z = useMemo(() => ({ CtrlSpace() {
561
- let { top: o, left: _ } = J();
562
- z(0), L({
623
+ let { top: o, left: h } = J();
624
+ R(0), I({
563
625
  visible: !0,
564
626
  top: o,
565
- left: _
627
+ left: h
566
628
  });
567
629
  } }), [J]), Q = useCallback((o) => {
568
- let _ = (I.visible ? X : Z)[shortcutName(o)];
569
- _ && (o.preventDefault(), _());
630
+ let h = (F.visible ? X : Z)[shortcutName(o)];
631
+ h && (o.preventDefault(), h());
570
632
  }, [
571
- I.visible,
633
+ F.visible,
572
634
  X,
573
635
  Z
574
636
  ]), $ = useCallback((o) => {
575
- y(o.target.value), L((o) => ({
637
+ _(o.target.value), I((o) => ({
576
638
  ...o,
577
639
  visible: !1
578
- })), V(o.target.value.substring(0, o.target.selectionStart));
579
- }, [y]);
640
+ })), B(o.target.value.substring(0, o.target.selectionStart));
641
+ }, [_]);
580
642
  return /* @__PURE__ */ jsxs("div", {
581
643
  style: {
582
644
  display: "grid",
@@ -585,7 +647,7 @@ function DslEditor({ code: o, onChange: y, onParsed: T, grammar: E, wrap: D = !1
585
647
  width: "100%",
586
648
  height: "100%"
587
649
  },
588
- className: k,
650
+ className: D,
589
651
  children: [
590
652
  /* @__PURE__ */ jsxs("div", {
591
653
  style: {
@@ -595,9 +657,9 @@ function DslEditor({ code: o, onChange: y, onParsed: T, grammar: E, wrap: D = !1
595
657
  },
596
658
  children: [
597
659
  /* @__PURE__ */ jsx("textarea", {
598
- ref: U,
660
+ ref: H,
599
661
  spellCheck: !1,
600
- wrap: D ? "soft" : "off",
662
+ wrap: T ? "soft" : "off",
601
663
  style: {
602
664
  ...textStyle,
603
665
  color: "transparent",
@@ -609,45 +671,52 @@ function DslEditor({ code: o, onChange: y, onParsed: T, grammar: E, wrap: D = !1
609
671
  value: o,
610
672
  onSelect: q,
611
673
  onChange: $,
612
- onScroll: useSyncScroll(G),
674
+ onScroll: useSyncScroll(W, G),
613
675
  onKeyDown: Q,
614
- ...A
676
+ ...k
615
677
  }),
616
- N && /* @__PURE__ */ jsx(SyntaxHighlighter, {
617
- cstRoot: N.cst,
678
+ M && /* @__PURE__ */ jsx(SyntaxHighlighter, {
679
+ cstRoot: M.cst,
680
+ ref: W,
681
+ wrap: T,
682
+ syntaxColors: O
683
+ }),
684
+ !e(M?.errors ?? []) && /* @__PURE__ */ jsx(ErrorHighlighter, {
618
685
  ref: G,
619
- wrap: D
686
+ errors: M?.errors ?? [],
687
+ wrap: T,
688
+ children: o
620
689
  }),
621
690
  /* @__PURE__ */ jsx(CursorPosition, {
622
- ref: W,
623
- text: B,
624
- wrap: D
691
+ ref: U,
692
+ text: z,
693
+ wrap: T
625
694
  }),
626
- I.visible && j.length > 0 && /* @__PURE__ */ jsx(SuggestionsMenu, {
627
- suggestions: j.map((o) => o.suggestion),
695
+ F.visible && A.length > 0 && /* @__PURE__ */ jsx(SuggestionsMenu, {
696
+ suggestions: A.map((o) => o.suggestion),
628
697
  onSelect: Y,
629
698
  style: {
630
- top: I.top,
631
- left: I.left
699
+ top: F.top,
700
+ left: F.left
632
701
  },
633
- selectedIndex: R,
634
- onHover: z
702
+ selectedIndex: L,
703
+ onHover: R
635
704
  })
636
705
  ]
637
706
  }),
638
- JSON.stringify(j),
707
+ JSON.stringify(M?.errors ?? []),
639
708
  /* @__PURE__ */ jsx(SuggestionsView, {
640
- suggestions: j.map((o) => o.suggestion),
709
+ suggestions: A.map((o) => o.suggestion),
641
710
  onSelect: Y
642
711
  })
643
712
  ]
644
713
  });
645
714
  }
646
- function visit(o, _, v = (o) => o.text) {
647
- return isParserError(o) ? [] : (((o) => o.grammar.meta?.name === _)(o) ? [v(o)] : []).concat(...o.children?.flatMap((o) => visit(o, _, v)) ?? []);
715
+ function visit(o, h, g = (o) => o.text) {
716
+ return isParserError(o) ? [] : (((o) => o.grammar.meta?.name !== void 0 && h.includes(o.grammar.meta?.name))(o) ? [g(o)] : []).concat(...o.children?.flatMap((o) => visit(o, h, g)) ?? []);
648
717
  }
649
- var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
650
- _.exports = {
718
+ var require_types = /* @__PURE__ */ __commonJSMin(((o, h) => {
719
+ h.exports = {
651
720
  ROOT: 0,
652
721
  GROUP: 1,
653
722
  POSITION: 2,
@@ -658,136 +727,136 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
658
727
  CHAR: 7
659
728
  };
660
729
  })), require_sets = /* @__PURE__ */ __commonJSMin(((o) => {
661
- var _ = require_types(), v = () => [{
662
- type: _.RANGE,
730
+ var h = require_types(), g = () => [{
731
+ type: h.RANGE,
663
732
  from: 48,
664
733
  to: 57
665
- }], y = () => [
734
+ }], _ = () => [
666
735
  {
667
- type: _.CHAR,
736
+ type: h.CHAR,
668
737
  value: 95
669
738
  },
670
739
  {
671
- type: _.RANGE,
740
+ type: h.RANGE,
672
741
  from: 97,
673
742
  to: 122
674
743
  },
675
744
  {
676
- type: _.RANGE,
745
+ type: h.RANGE,
677
746
  from: 65,
678
747
  to: 90
679
748
  }
680
- ].concat(v()), b = () => [
749
+ ].concat(g()), v = () => [
681
750
  {
682
- type: _.CHAR,
751
+ type: h.CHAR,
683
752
  value: 9
684
753
  },
685
754
  {
686
- type: _.CHAR,
755
+ type: h.CHAR,
687
756
  value: 10
688
757
  },
689
758
  {
690
- type: _.CHAR,
759
+ type: h.CHAR,
691
760
  value: 11
692
761
  },
693
762
  {
694
- type: _.CHAR,
763
+ type: h.CHAR,
695
764
  value: 12
696
765
  },
697
766
  {
698
- type: _.CHAR,
767
+ type: h.CHAR,
699
768
  value: 13
700
769
  },
701
770
  {
702
- type: _.CHAR,
771
+ type: h.CHAR,
703
772
  value: 32
704
773
  },
705
774
  {
706
- type: _.CHAR,
775
+ type: h.CHAR,
707
776
  value: 160
708
777
  },
709
778
  {
710
- type: _.CHAR,
779
+ type: h.CHAR,
711
780
  value: 5760
712
781
  },
713
782
  {
714
- type: _.RANGE,
783
+ type: h.RANGE,
715
784
  from: 8192,
716
785
  to: 8202
717
786
  },
718
787
  {
719
- type: _.CHAR,
788
+ type: h.CHAR,
720
789
  value: 8232
721
790
  },
722
791
  {
723
- type: _.CHAR,
792
+ type: h.CHAR,
724
793
  value: 8233
725
794
  },
726
795
  {
727
- type: _.CHAR,
796
+ type: h.CHAR,
728
797
  value: 8239
729
798
  },
730
799
  {
731
- type: _.CHAR,
800
+ type: h.CHAR,
732
801
  value: 8287
733
802
  },
734
803
  {
735
- type: _.CHAR,
804
+ type: h.CHAR,
736
805
  value: 12288
737
806
  },
738
807
  {
739
- type: _.CHAR,
808
+ type: h.CHAR,
740
809
  value: 65279
741
810
  }
742
- ], x = () => [
811
+ ], y = () => [
743
812
  {
744
- type: _.CHAR,
813
+ type: h.CHAR,
745
814
  value: 10
746
815
  },
747
816
  {
748
- type: _.CHAR,
817
+ type: h.CHAR,
749
818
  value: 13
750
819
  },
751
820
  {
752
- type: _.CHAR,
821
+ type: h.CHAR,
753
822
  value: 8232
754
823
  },
755
824
  {
756
- type: _.CHAR,
825
+ type: h.CHAR,
757
826
  value: 8233
758
827
  }
759
828
  ];
760
829
  o.words = () => ({
761
- type: _.SET,
762
- set: y(),
830
+ type: h.SET,
831
+ set: _(),
763
832
  not: !1
764
833
  }), o.notWords = () => ({
765
- type: _.SET,
766
- set: y(),
834
+ type: h.SET,
835
+ set: _(),
767
836
  not: !0
768
837
  }), o.ints = () => ({
769
- type: _.SET,
770
- set: v(),
838
+ type: h.SET,
839
+ set: g(),
771
840
  not: !1
772
841
  }), o.notInts = () => ({
773
- type: _.SET,
774
- set: v(),
842
+ type: h.SET,
843
+ set: g(),
775
844
  not: !0
776
845
  }), o.whitespace = () => ({
777
- type: _.SET,
778
- set: b(),
846
+ type: h.SET,
847
+ set: v(),
779
848
  not: !1
780
849
  }), o.notWhitespace = () => ({
781
- type: _.SET,
782
- set: b(),
850
+ type: h.SET,
851
+ set: v(),
783
852
  not: !0
784
853
  }), o.anyChar = () => ({
785
- type: _.SET,
786
- set: x(),
854
+ type: h.SET,
855
+ set: y(),
787
856
  not: !0
788
857
  });
789
858
  })), require_util = /* @__PURE__ */ __commonJSMin(((o) => {
790
- var _ = require_types(), v = require_sets(), y = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?", b = {
859
+ var h = require_types(), g = require_sets(), _ = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^ ?", v = {
791
860
  0: 0,
792
861
  t: 9,
793
862
  n: 10,
@@ -796,174 +865,174 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
796
865
  r: 13
797
866
  };
798
867
  o.strToChars = function(o) {
799
- return o = o.replace(/(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g, function(o, _, v, x, S, C, w, T) {
800
- if (v) return o;
801
- var E = _ ? 8 : x ? parseInt(x, 16) : S ? parseInt(S, 16) : C ? parseInt(C, 8) : w ? y.indexOf(w) : b[T], D = String.fromCharCode(E);
802
- return /[[\]{}^$.|?*+()]/.test(D) && (D = "\\" + D), D;
868
+ return o = o.replace(/(\[\\b\])|(\\)?\\(?:u([A-F0-9]{4})|x([A-F0-9]{2})|(0?[0-7]{2})|c([@A-Z[\\\]^?])|([0tnvfr]))/g, function(o, h, g, y, b, x, S, C) {
869
+ if (g) return o;
870
+ var w = h ? 8 : y ? parseInt(y, 16) : b ? parseInt(b, 16) : x ? parseInt(x, 8) : S ? _.indexOf(S) : v[C], T = String.fromCharCode(w);
871
+ return /[[\]{}^$.|?*+()]/.test(T) && (T = "\\" + T), T;
803
872
  }), o;
804
- }, o.tokenizeClass = (y, b) => {
805
- for (var x = [], S = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(?:\\)?([^\]]))|(\])|(?:\\)?([^])/g, C, w; (C = S.exec(y)) != null;) if (C[1]) x.push(v.words());
806
- else if (C[2]) x.push(v.ints());
807
- else if (C[3]) x.push(v.whitespace());
808
- else if (C[4]) x.push(v.notWords());
809
- else if (C[5]) x.push(v.notInts());
810
- else if (C[6]) x.push(v.notWhitespace());
811
- else if (C[7]) x.push({
812
- type: _.RANGE,
813
- from: (C[8] || C[9]).charCodeAt(0),
814
- to: C[10].charCodeAt(0)
873
+ }, o.tokenizeClass = (_, v) => {
874
+ for (var y = [], b = /\\(?:(w)|(d)|(s)|(W)|(D)|(S))|((?:(?:\\)(.)|([^\]\\]))-(?:\\)?([^\]]))|(\])|(?:\\)?([^])/g, x, S; (x = b.exec(_)) != null;) if (x[1]) y.push(g.words());
875
+ else if (x[2]) y.push(g.ints());
876
+ else if (x[3]) y.push(g.whitespace());
877
+ else if (x[4]) y.push(g.notWords());
878
+ else if (x[5]) y.push(g.notInts());
879
+ else if (x[6]) y.push(g.notWhitespace());
880
+ else if (x[7]) y.push({
881
+ type: h.RANGE,
882
+ from: (x[8] || x[9]).charCodeAt(0),
883
+ to: x[10].charCodeAt(0)
815
884
  });
816
- else if (w = C[12]) x.push({
817
- type: _.CHAR,
818
- value: w.charCodeAt(0)
885
+ else if (S = x[12]) y.push({
886
+ type: h.CHAR,
887
+ value: S.charCodeAt(0)
819
888
  });
820
- else return [x, S.lastIndex];
821
- o.error(b, "Unterminated character class");
822
- }, o.error = (o, _) => {
823
- throw SyntaxError("Invalid regular expression: /" + o + "/: " + _);
889
+ else return [y, b.lastIndex];
890
+ o.error(v, "Unterminated character class");
891
+ }, o.error = (o, h) => {
892
+ throw SyntaxError("Invalid regular expression: /" + o + "/: " + h);
824
893
  };
825
894
  })), require_positions = /* @__PURE__ */ __commonJSMin(((o) => {
826
- var _ = require_types();
895
+ var h = require_types();
827
896
  o.wordBoundary = () => ({
828
- type: _.POSITION,
897
+ type: h.POSITION,
829
898
  value: "b"
830
899
  }), o.nonWordBoundary = () => ({
831
- type: _.POSITION,
900
+ type: h.POSITION,
832
901
  value: "B"
833
902
  }), o.begin = () => ({
834
- type: _.POSITION,
903
+ type: h.POSITION,
835
904
  value: "^"
836
905
  }), o.end = () => ({
837
- type: _.POSITION,
906
+ type: h.POSITION,
838
907
  value: "$"
839
908
  });
840
- })), require_lib$1 = /* @__PURE__ */ __commonJSMin(((o, _) => {
841
- var v = require_util(), y = require_types(), b = require_sets(), x = require_positions();
842
- _.exports = (o) => {
843
- var _ = 0, S, C, w = {
844
- type: y.ROOT,
909
+ })), require_lib$1 = /* @__PURE__ */ __commonJSMin(((o, h) => {
910
+ var g = require_util(), _ = require_types(), v = require_sets(), y = require_positions();
911
+ h.exports = (o) => {
912
+ var h = 0, b, x, S = {
913
+ type: _.ROOT,
845
914
  stack: []
846
- }, T = w, E = w.stack, D = [], O = (_) => {
847
- v.error(o, `Nothing to repeat at column ${_ - 1}`);
848
- }, k = v.strToChars(o);
849
- for (S = k.length; _ < S;) switch (C = k[_++], C) {
915
+ }, C = S, w = S.stack, T = [], E = (h) => {
916
+ g.error(o, `Nothing to repeat at column ${h - 1}`);
917
+ }, D = g.strToChars(o);
918
+ for (b = D.length; h < b;) switch (x = D[h++], x) {
850
919
  case "\\":
851
- switch (C = k[_++], C) {
920
+ switch (x = D[h++], x) {
852
921
  case "b":
853
- E.push(x.wordBoundary());
922
+ w.push(y.wordBoundary());
854
923
  break;
855
924
  case "B":
856
- E.push(x.nonWordBoundary());
925
+ w.push(y.nonWordBoundary());
857
926
  break;
858
927
  case "w":
859
- E.push(b.words());
928
+ w.push(v.words());
860
929
  break;
861
930
  case "W":
862
- E.push(b.notWords());
931
+ w.push(v.notWords());
863
932
  break;
864
933
  case "d":
865
- E.push(b.ints());
934
+ w.push(v.ints());
866
935
  break;
867
936
  case "D":
868
- E.push(b.notInts());
937
+ w.push(v.notInts());
869
938
  break;
870
939
  case "s":
871
- E.push(b.whitespace());
940
+ w.push(v.whitespace());
872
941
  break;
873
942
  case "S":
874
- E.push(b.notWhitespace());
943
+ w.push(v.notWhitespace());
875
944
  break;
876
- default: /\d/.test(C) ? E.push({
877
- type: y.REFERENCE,
878
- value: parseInt(C, 10)
879
- }) : E.push({
880
- type: y.CHAR,
881
- value: C.charCodeAt(0)
945
+ default: /\d/.test(x) ? w.push({
946
+ type: _.REFERENCE,
947
+ value: parseInt(x, 10)
948
+ }) : w.push({
949
+ type: _.CHAR,
950
+ value: x.charCodeAt(0)
882
951
  });
883
952
  }
884
953
  break;
885
954
  case "^":
886
- E.push(x.begin());
955
+ w.push(y.begin());
887
956
  break;
888
957
  case "$":
889
- E.push(x.end());
958
+ w.push(y.end());
890
959
  break;
891
960
  case "[":
892
- var A;
893
- k[_] === "^" ? (A = !0, _++) : A = !1;
894
- var j = v.tokenizeClass(k.slice(_), o);
895
- _ += j[1], E.push({
896
- type: y.SET,
897
- set: j[0],
898
- not: A
961
+ var O;
962
+ D[h] === "^" ? (O = !0, h++) : O = !1;
963
+ var k = g.tokenizeClass(D.slice(h), o);
964
+ h += k[1], w.push({
965
+ type: _.SET,
966
+ set: k[0],
967
+ not: O
899
968
  });
900
969
  break;
901
970
  case ".":
902
- E.push(b.anyChar());
971
+ w.push(v.anyChar());
903
972
  break;
904
973
  case "(":
905
- var M = {
906
- type: y.GROUP,
974
+ var A = {
975
+ type: _.GROUP,
907
976
  stack: [],
908
977
  remember: !0
909
978
  };
910
- C = k[_], C === "?" && (C = k[_ + 1], _ += 2, C === "=" ? M.followedBy = !0 : C === "!" ? M.notFollowedBy = !0 : C !== ":" && v.error(o, `Invalid group, character '${C}' after '?' at column ${_ - 1}`), M.remember = !1), E.push(M), D.push(T), T = M, E = M.stack;
979
+ x = D[h], x === "?" && (x = D[h + 1], h += 2, x === "=" ? A.followedBy = !0 : x === "!" ? A.notFollowedBy = !0 : x !== ":" && g.error(o, `Invalid group, character '${x}' after '?' at column ${h - 1}`), A.remember = !1), w.push(A), T.push(C), C = A, w = A.stack;
911
980
  break;
912
981
  case ")":
913
- D.length === 0 && v.error(o, `Unmatched ) at column ${_ - 1}`), T = D.pop(), E = T.options ? T.options[T.options.length - 1] : T.stack;
982
+ T.length === 0 && g.error(o, `Unmatched ) at column ${h - 1}`), C = T.pop(), w = C.options ? C.options[C.options.length - 1] : C.stack;
914
983
  break;
915
984
  case "|":
916
- T.options || (T.options = [T.stack], delete T.stack);
917
- var N = [];
918
- T.options.push(N), E = N;
985
+ C.options || (C.options = [C.stack], delete C.stack);
986
+ var j = [];
987
+ C.options.push(j), w = j;
919
988
  break;
920
989
  case "{":
921
- var P = /^(\d+)(,(\d+)?)?\}/.exec(k.slice(_)), F, I;
922
- P === null ? E.push({
923
- type: y.CHAR,
990
+ var M = /^(\d+)(,(\d+)?)?\}/.exec(D.slice(h)), N, P;
991
+ M === null ? w.push({
992
+ type: _.CHAR,
924
993
  value: 123
925
- }) : (E.length === 0 && O(_), F = parseInt(P[1], 10), I = P[2] ? P[3] ? parseInt(P[3], 10) : Infinity : F, _ += P[0].length, E.push({
926
- type: y.REPETITION,
927
- min: F,
928
- max: I,
929
- value: E.pop()
994
+ }) : (w.length === 0 && E(h), N = parseInt(M[1], 10), P = M[2] ? M[3] ? parseInt(M[3], 10) : Infinity : N, h += M[0].length, w.push({
995
+ type: _.REPETITION,
996
+ min: N,
997
+ max: P,
998
+ value: w.pop()
930
999
  }));
931
1000
  break;
932
1001
  case "?":
933
- E.length === 0 && O(_), E.push({
934
- type: y.REPETITION,
1002
+ w.length === 0 && E(h), w.push({
1003
+ type: _.REPETITION,
935
1004
  min: 0,
936
1005
  max: 1,
937
- value: E.pop()
1006
+ value: w.pop()
938
1007
  });
939
1008
  break;
940
1009
  case "+":
941
- E.length === 0 && O(_), E.push({
942
- type: y.REPETITION,
1010
+ w.length === 0 && E(h), w.push({
1011
+ type: _.REPETITION,
943
1012
  min: 1,
944
1013
  max: Infinity,
945
- value: E.pop()
1014
+ value: w.pop()
946
1015
  });
947
1016
  break;
948
1017
  case "*":
949
- E.length === 0 && O(_), E.push({
950
- type: y.REPETITION,
1018
+ w.length === 0 && E(h), w.push({
1019
+ type: _.REPETITION,
951
1020
  min: 0,
952
1021
  max: Infinity,
953
- value: E.pop()
1022
+ value: w.pop()
954
1023
  });
955
1024
  break;
956
- default: E.push({
957
- type: y.CHAR,
958
- value: C.charCodeAt(0)
1025
+ default: w.push({
1026
+ type: _.CHAR,
1027
+ value: x.charCodeAt(0)
959
1028
  });
960
1029
  }
961
- return D.length !== 0 && v.error(o, "Unterminated group"), w;
962
- }, _.exports.types = y;
963
- })), require_lib = /* @__PURE__ */ __commonJSMin(((o, _) => {
964
- var v = class o {
965
- constructor(o, _) {
966
- this.low = o, this.high = _, this.length = 1 + _ - o;
1030
+ return T.length !== 0 && g.error(o, "Unterminated group"), S;
1031
+ }, h.exports.types = _;
1032
+ })), require_lib = /* @__PURE__ */ __commonJSMin(((o, h) => {
1033
+ var g = class o {
1034
+ constructor(o, h) {
1035
+ this.low = o, this.high = h, this.length = 1 + h - o;
967
1036
  }
968
1037
  overlaps(o) {
969
1038
  return !(this.high < o.low || this.low > o.high);
@@ -971,52 +1040,52 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
971
1040
  touches(o) {
972
1041
  return !(this.high + 1 < o.low || this.low - 1 > o.high);
973
1042
  }
974
- add(_) {
975
- return new o(Math.min(this.low, _.low), Math.max(this.high, _.high));
1043
+ add(h) {
1044
+ return new o(Math.min(this.low, h.low), Math.max(this.high, h.high));
976
1045
  }
977
- subtract(_) {
978
- return _.low <= this.low && _.high >= this.high ? [] : _.low > this.low && _.high < this.high ? [new o(this.low, _.low - 1), new o(_.high + 1, this.high)] : _.low <= this.low ? [new o(_.high + 1, this.high)] : [new o(this.low, _.low - 1)];
1046
+ subtract(h) {
1047
+ return h.low <= this.low && h.high >= this.high ? [] : h.low > this.low && h.high < this.high ? [new o(this.low, h.low - 1), new o(h.high + 1, this.high)] : h.low <= this.low ? [new o(h.high + 1, this.high)] : [new o(this.low, h.low - 1)];
979
1048
  }
980
1049
  toString() {
981
1050
  return this.low == this.high ? this.low.toString() : this.low + "-" + this.high;
982
1051
  }
983
1052
  };
984
- _.exports = class o {
985
- constructor(o, _) {
986
- this.ranges = [], this.length = 0, o != null && this.add(o, _);
1053
+ h.exports = class o {
1054
+ constructor(o, h) {
1055
+ this.ranges = [], this.length = 0, o != null && this.add(o, h);
987
1056
  }
988
1057
  _update_length() {
989
- this.length = this.ranges.reduce((o, _) => o + _.length, 0);
1058
+ this.length = this.ranges.reduce((o, h) => o + h.length, 0);
990
1059
  }
991
- add(_, y) {
992
- var b = (o) => {
993
- for (var _ = 0; _ < this.ranges.length && !o.touches(this.ranges[_]);) _++;
994
- for (var v = this.ranges.slice(0, _); _ < this.ranges.length && o.touches(this.ranges[_]);) o = o.add(this.ranges[_]), _++;
995
- v.push(o), this.ranges = v.concat(this.ranges.slice(_)), this._update_length();
1060
+ add(h, _) {
1061
+ var v = (o) => {
1062
+ for (var h = 0; h < this.ranges.length && !o.touches(this.ranges[h]);) h++;
1063
+ for (var g = this.ranges.slice(0, h); h < this.ranges.length && o.touches(this.ranges[h]);) o = o.add(this.ranges[h]), h++;
1064
+ g.push(o), this.ranges = g.concat(this.ranges.slice(h)), this._update_length();
996
1065
  };
997
- return _ instanceof o ? _.ranges.forEach(b) : (y ??= _, b(new v(_, y))), this;
1066
+ return h instanceof o ? h.ranges.forEach(v) : (_ ??= h, v(new g(h, _))), this;
998
1067
  }
999
- subtract(_, y) {
1000
- var b = (o) => {
1001
- for (var _ = 0; _ < this.ranges.length && !o.overlaps(this.ranges[_]);) _++;
1002
- for (var v = this.ranges.slice(0, _); _ < this.ranges.length && o.overlaps(this.ranges[_]);) v = v.concat(this.ranges[_].subtract(o)), _++;
1003
- this.ranges = v.concat(this.ranges.slice(_)), this._update_length();
1068
+ subtract(h, _) {
1069
+ var v = (o) => {
1070
+ for (var h = 0; h < this.ranges.length && !o.overlaps(this.ranges[h]);) h++;
1071
+ for (var g = this.ranges.slice(0, h); h < this.ranges.length && o.overlaps(this.ranges[h]);) g = g.concat(this.ranges[h].subtract(o)), h++;
1072
+ this.ranges = g.concat(this.ranges.slice(h)), this._update_length();
1004
1073
  };
1005
- return _ instanceof o ? _.ranges.forEach(b) : (y ??= _, b(new v(_, y))), this;
1074
+ return h instanceof o ? h.ranges.forEach(v) : (_ ??= h, v(new g(h, _))), this;
1006
1075
  }
1007
- intersect(_, y) {
1008
- var b = [], x = (o) => {
1009
- for (var _ = 0; _ < this.ranges.length && !o.overlaps(this.ranges[_]);) _++;
1010
- for (; _ < this.ranges.length && o.overlaps(this.ranges[_]);) {
1011
- var y = Math.max(this.ranges[_].low, o.low), x = Math.min(this.ranges[_].high, o.high);
1012
- b.push(new v(y, x)), _++;
1076
+ intersect(h, _) {
1077
+ var v = [], y = (o) => {
1078
+ for (var h = 0; h < this.ranges.length && !o.overlaps(this.ranges[h]);) h++;
1079
+ for (; h < this.ranges.length && o.overlaps(this.ranges[h]);) {
1080
+ var _ = Math.max(this.ranges[h].low, o.low), y = Math.min(this.ranges[h].high, o.high);
1081
+ v.push(new g(_, y)), h++;
1013
1082
  }
1014
1083
  };
1015
- return _ instanceof o ? _.ranges.forEach(x) : (y ??= _, x(new v(_, y))), this.ranges = b, this._update_length(), this;
1084
+ return h instanceof o ? h.ranges.forEach(y) : (_ ??= h, y(new g(h, _))), this.ranges = v, this._update_length(), this;
1016
1085
  }
1017
1086
  index(o) {
1018
- for (var _ = 0; _ < this.ranges.length && this.ranges[_].length <= o;) o -= this.ranges[_].length, _++;
1019
- return this.ranges[_].low + o;
1087
+ for (var h = 0; h < this.ranges.length && this.ranges[h].length <= o;) o -= this.ranges[h].length, h++;
1088
+ return this.ranges[h].low + o;
1020
1089
  }
1021
1090
  toString() {
1022
1091
  return "[ " + this.ranges.join(", ") + " ]";
@@ -1025,8 +1094,8 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
1025
1094
  return new o(this);
1026
1095
  }
1027
1096
  numbers() {
1028
- return this.ranges.reduce((o, _) => {
1029
- for (var v = _.low; v <= _.high;) o.push(v), v++;
1097
+ return this.ranges.reduce((o, h) => {
1098
+ for (var g = h.low; g <= h.high;) o.push(g), g++;
1030
1099
  return o;
1031
1100
  }, []);
1032
1101
  }
@@ -1038,40 +1107,40 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
1038
1107
  }));
1039
1108
  }
1040
1109
  };
1041
- })), import_randexp = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((o, _) => {
1042
- var v = require_lib$1(), y = require_lib(), b = v.types;
1043
- _.exports = class o {
1044
- constructor(o, _) {
1110
+ })), import_randexp = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((o, h) => {
1111
+ var g = require_lib$1(), _ = require_lib(), v = g.types;
1112
+ h.exports = class o {
1113
+ constructor(o, h) {
1045
1114
  if (this._setDefaults(o), o instanceof RegExp) this.ignoreCase = o.ignoreCase, this.multiline = o.multiline, o = o.source;
1046
- else if (typeof o == "string") this.ignoreCase = _ && _.indexOf("i") !== -1, this.multiline = _ && _.indexOf("m") !== -1;
1115
+ else if (typeof o == "string") this.ignoreCase = h && h.indexOf("i") !== -1, this.multiline = h && h.indexOf("m") !== -1;
1047
1116
  else throw Error("Expected a regexp or string");
1048
- this.tokens = v(o);
1117
+ this.tokens = g(o);
1049
1118
  }
1050
- _setDefaults(_) {
1051
- this.max = _.max == null ? o.prototype.max == null ? 100 : o.prototype.max : _.max, this.defaultRange = _.defaultRange ? _.defaultRange : this.defaultRange.clone(), _.randInt && (this.randInt = _.randInt);
1119
+ _setDefaults(h) {
1120
+ this.max = h.max == null ? o.prototype.max == null ? 100 : o.prototype.max : h.max, this.defaultRange = h.defaultRange ? h.defaultRange : this.defaultRange.clone(), h.randInt && (this.randInt = h.randInt);
1052
1121
  }
1053
1122
  gen() {
1054
1123
  return this._gen(this.tokens, []);
1055
1124
  }
1056
- _gen(o, _) {
1057
- var v, y, x, S, C;
1125
+ _gen(o, h) {
1126
+ var g, _, y, b, x;
1058
1127
  switch (o.type) {
1059
- case b.ROOT:
1060
- case b.GROUP:
1128
+ case v.ROOT:
1129
+ case v.GROUP:
1061
1130
  if (o.followedBy || o.notFollowedBy) return "";
1062
- for (o.remember && o.groupNumber === void 0 && (o.groupNumber = _.push(null) - 1), v = o.options ? this._randSelect(o.options) : o.stack, y = "", S = 0, C = v.length; S < C; S++) y += this._gen(v[S], _);
1063
- return o.remember && (_[o.groupNumber] = y), y;
1064
- case b.POSITION: return "";
1065
- case b.SET:
1066
- var w = this._expand(o);
1067
- return w.length ? String.fromCharCode(this._randSelect(w)) : "";
1068
- case b.REPETITION:
1069
- for (x = this.randInt(o.min, o.max === Infinity ? o.min + this.max : o.max), y = "", S = 0; S < x; S++) y += this._gen(o.value, _);
1070
- return y;
1071
- case b.REFERENCE: return _[o.value - 1] || "";
1072
- case b.CHAR:
1073
- var T = this.ignoreCase && this._randBool() ? this._toOtherCase(o.value) : o.value;
1074
- return String.fromCharCode(T);
1131
+ for (o.remember && o.groupNumber === void 0 && (o.groupNumber = h.push(null) - 1), g = o.options ? this._randSelect(o.options) : o.stack, _ = "", b = 0, x = g.length; b < x; b++) _ += this._gen(g[b], h);
1132
+ return o.remember && (h[o.groupNumber] = _), _;
1133
+ case v.POSITION: return "";
1134
+ case v.SET:
1135
+ var S = this._expand(o);
1136
+ return S.length ? String.fromCharCode(this._randSelect(S)) : "";
1137
+ case v.REPETITION:
1138
+ for (y = this.randInt(o.min, o.max === Infinity ? o.min + this.max : o.max), _ = "", b = 0; b < y; b++) _ += this._gen(o.value, h);
1139
+ return _;
1140
+ case v.REFERENCE: return h[o.value - 1] || "";
1141
+ case v.CHAR:
1142
+ var C = this.ignoreCase && this._randBool() ? this._toOtherCase(o.value) : o.value;
1143
+ return String.fromCharCode(C);
1075
1144
  }
1076
1145
  }
1077
1146
  _toOtherCase(o) {
@@ -1081,35 +1150,35 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
1081
1150
  return !this.randInt(0, 1);
1082
1151
  }
1083
1152
  _randSelect(o) {
1084
- return o instanceof y ? o.index(this.randInt(0, o.length - 1)) : o[this.randInt(0, o.length - 1)];
1153
+ return o instanceof _ ? o.index(this.randInt(0, o.length - 1)) : o[this.randInt(0, o.length - 1)];
1085
1154
  }
1086
1155
  _expand(o) {
1087
- if (o.type === v.types.CHAR) return new y(o.value);
1088
- if (o.type === v.types.RANGE) return new y(o.from, o.to);
1156
+ if (o.type === g.types.CHAR) return new _(o.value);
1157
+ if (o.type === g.types.RANGE) return new _(o.from, o.to);
1089
1158
  {
1090
- let _ = new y();
1091
- for (let v = 0; v < o.set.length; v++) {
1092
- let y = this._expand(o.set[v]);
1093
- if (_.add(y), this.ignoreCase) for (let o = 0; o < y.length; o++) {
1094
- let v = y.index(o), b = this._toOtherCase(v);
1095
- v !== b && _.add(b);
1159
+ let h = new _();
1160
+ for (let g = 0; g < o.set.length; g++) {
1161
+ let _ = this._expand(o.set[g]);
1162
+ if (h.add(_), this.ignoreCase) for (let o = 0; o < _.length; o++) {
1163
+ let g = _.index(o), v = this._toOtherCase(g);
1164
+ g !== v && h.add(v);
1096
1165
  }
1097
1166
  }
1098
- return o.not ? this.defaultRange.clone().subtract(_) : this.defaultRange.clone().intersect(_);
1167
+ return o.not ? this.defaultRange.clone().subtract(h) : this.defaultRange.clone().intersect(h);
1099
1168
  }
1100
1169
  }
1101
- randInt(o, _) {
1102
- return o + Math.floor(Math.random() * (1 + _ - o));
1170
+ randInt(o, h) {
1171
+ return o + Math.floor(Math.random() * (1 + h - o));
1103
1172
  }
1104
1173
  get defaultRange() {
1105
- return this._range = this._range || new y(32, 126);
1174
+ return this._range = this._range || new _(32, 126);
1106
1175
  }
1107
1176
  set defaultRange(o) {
1108
1177
  this._range = o;
1109
1178
  }
1110
- static randexp(_, v) {
1111
- var y;
1112
- return typeof _ == "string" && (_ = new RegExp(_, v)), _._randexp === void 0 ? (y = new o(_, v), _._randexp = y) : (y = _._randexp, y._setDefaults(_)), y.gen();
1179
+ static randexp(h, g) {
1180
+ var _;
1181
+ return typeof h == "string" && (h = new RegExp(h, g)), h._randexp === void 0 ? (_ = new o(h, g), h._randexp = _) : (_ = h._randexp, _._setDefaults(h)), _.gen();
1113
1182
  }
1114
1183
  static sugar() {
1115
1184
  RegExp.prototype.gen = function() {
@@ -1118,81 +1187,82 @@ var require_types = /* @__PURE__ */ __commonJSMin(((o, _) => {
1118
1187
  }
1119
1188
  };
1120
1189
  })))()), array = [], characterCodeCache = [];
1121
- function leven(o, _, v) {
1122
- if (o === _) return 0;
1123
- let y = v?.maxDistance, b = o;
1124
- o.length > _.length && (o = _, _ = b);
1125
- let x = o.length, S = _.length;
1126
- for (; x > 0 && o.charCodeAt(~-x) === _.charCodeAt(~-S);) x--, S--;
1127
- let C = 0;
1128
- for (; C < x && o.charCodeAt(C) === _.charCodeAt(C);) C++;
1129
- if (x -= C, S -= C, y !== void 0 && S - x > y) return y;
1130
- if (x === 0) return y !== void 0 && S > y ? y : S;
1131
- let w, T, E, D, O = 0, k = 0;
1132
- for (; O < x;) characterCodeCache[O] = o.charCodeAt(C + O), array[O] = ++O;
1133
- for (; k < S;) {
1134
- for (w = _.charCodeAt(C + k), E = k++, T = k, O = 0; O < x; O++) D = w === characterCodeCache[O] ? E : E + 1, E = array[O], T = array[O] = E > T ? D > T ? T + 1 : D : D > E ? E + 1 : D;
1135
- if (y !== void 0) {
1136
- let o = T;
1137
- for (O = 0; O < x; O++) array[O] < o && (o = array[O]);
1138
- if (o > y) return y;
1190
+ function leven(o, h, g) {
1191
+ if (o === h) return 0;
1192
+ let _ = g?.maxDistance, v = o;
1193
+ o.length > h.length && (o = h, h = v);
1194
+ let y = o.length, b = h.length;
1195
+ for (; y > 0 && o.charCodeAt(~-y) === h.charCodeAt(~-b);) y--, b--;
1196
+ let x = 0;
1197
+ for (; x < y && o.charCodeAt(x) === h.charCodeAt(x);) x++;
1198
+ if (y -= x, b -= x, _ !== void 0 && b - y > _) return _;
1199
+ if (y === 0) return _ !== void 0 && b > _ ? _ : b;
1200
+ let S, C, w, T, E = 0, D = 0;
1201
+ for (; E < y;) characterCodeCache[E] = o.charCodeAt(x + E), array[E] = ++E;
1202
+ for (; D < b;) {
1203
+ for (S = h.charCodeAt(x + D), w = D++, C = D, E = 0; E < y; E++) T = S === characterCodeCache[E] ? w : w + 1, w = array[E], C = array[E] = w > C ? T > C ? C + 1 : T : T > w ? w + 1 : T;
1204
+ if (_ !== void 0) {
1205
+ let o = C;
1206
+ for (E = 0; E < y; E++) array[E] < o && (o = array[E]);
1207
+ if (o > _) return _;
1139
1208
  }
1140
1209
  }
1141
- return array.length = x, characterCodeCache.length = x, y !== void 0 && T > y ? y : T;
1210
+ return array.length = y, characterCodeCache.length = y, _ !== void 0 && C > _ ? _ : C;
1142
1211
  }
1143
1212
  function pattern(o) {
1144
- let _ = new import_randexp.default(o);
1145
- _.randInt = () => 0, _.defaultRange.subtract(-Infinity, Infinity);
1146
- function v() {
1147
- return t(t$4(0, 10), t$3(() => _.gen()), n$2());
1213
+ let h = new import_randexp.default(o);
1214
+ h.randInt = () => 0, h.defaultRange.subtract(-Infinity, Infinity);
1215
+ function g() {
1216
+ return t(t$4(0, 10), t$3(() => h.gen()), n$2());
1148
1217
  }
1149
- let y = {
1218
+ let _ = {
1150
1219
  type: "pattern",
1151
1220
  children: [],
1152
1221
  meta: { regex: o },
1153
- suggestions: v,
1154
- parse(_, b) {
1155
- let x = new RegExp(o, "yu");
1156
- x.lastIndex = 0;
1157
- let S = x.exec(_);
1158
- if (S) return success({
1159
- text: S[0],
1160
- grammar: y,
1222
+ suggestions: g,
1223
+ parse(h, v) {
1224
+ let y = new RegExp(o, "yu");
1225
+ y.lastIndex = 0;
1226
+ let b = y.exec(h);
1227
+ if (b) return success({
1228
+ text: b[0],
1229
+ grammar: _,
1161
1230
  children: []
1162
1231
  });
1163
- if (b.faultTolerant) {
1164
- let o = t(v(), n((o) => leven(o, _) <= 2), n$1());
1232
+ if (v.faultTolerant) {
1233
+ let o = t(g(), n((o) => leven(o, h) <= 2), n$1());
1165
1234
  if (o !== void 0) return success({
1166
- text: _.substring(0, o.length),
1167
- grammar: y,
1168
- children: []
1235
+ text: h.substring(0, o.length),
1236
+ grammar: _,
1237
+ children: [],
1238
+ recoverableError: !0
1169
1239
  });
1170
1240
  }
1171
1241
  return error({
1172
- grammar: y,
1173
- got: _,
1174
- expected: y.suggestions()
1242
+ grammar: _,
1243
+ got: h,
1244
+ expected: _.suggestions()
1175
1245
  });
1176
1246
  }
1177
1247
  };
1178
- return y;
1248
+ return _;
1179
1249
  }
1180
1250
  const rational = pattern(/\d+(:?.\d+)?/);
1181
1251
  function optional(o) {
1182
- let _ = {
1252
+ let h = {
1183
1253
  type: "optional",
1184
1254
  suggestions: () => o.suggestions(),
1185
1255
  children: [o],
1186
- parse(v, y) {
1187
- let b = o.parse(v, y);
1188
- return isParserError(b) ? success({
1256
+ parse(g, _) {
1257
+ let v = o.parse(g, _);
1258
+ return isParserError(v) ? success({
1189
1259
  text: "",
1190
- grammar: _,
1260
+ grammar: h,
1191
1261
  children: []
1192
- }) : b;
1262
+ }) : v;
1193
1263
  }
1194
1264
  };
1195
- return _;
1265
+ return h;
1196
1266
  }
1197
1267
  const ws = optional(pattern(/\s+/));
1198
1268
  function seq(...o) {
@@ -1205,94 +1275,104 @@ function regexEscape(o) {
1205
1275
  return o.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1206
1276
  }
1207
1277
  function alternative(...o) {
1208
- let _ = {
1278
+ let h = {
1209
1279
  type: "alternative",
1210
1280
  children: o,
1211
- parse(v, y) {
1212
- let b = [];
1213
- if (y.faultTolerant) {
1214
- for (let _ of o) {
1215
- let o = _.parse(v, {
1216
- ...y,
1281
+ parse(g, _) {
1282
+ let v = [];
1283
+ if (_.faultTolerant) {
1284
+ for (let h of o) {
1285
+ let o = h.parse(g, {
1286
+ ..._,
1217
1287
  faultTolerant: !1
1218
1288
  });
1219
1289
  if (isParserSuccess(o)) return o;
1220
1290
  }
1221
- let _ = o.map((o) => o.parse(v, {
1222
- ...y,
1291
+ let h = o.map((o) => o.parse(g, {
1292
+ ..._,
1223
1293
  faultTolerant: !0
1224
- })), b = t(_, n(isParserSuccess), t$1((o) => o.text.length), t$2());
1225
- if (b) return b;
1226
- } else for (let _ of o) {
1227
- let o = _.parse(v, y);
1294
+ })), v = t(h, n(isParserSuccess), t$1((o) => o.text.length), t$2());
1295
+ if (v) return {
1296
+ ...v,
1297
+ recoverableError: !0
1298
+ };
1299
+ } else for (let h of o) {
1300
+ let o = h.parse(g, _);
1228
1301
  if (isParserError(o)) {
1229
- b.push(o);
1302
+ v.push(o);
1230
1303
  continue;
1231
1304
  }
1232
1305
  return o;
1233
1306
  }
1234
1307
  return error({
1235
- got: v,
1236
- expected: b.flatMap((o) => o.expected),
1237
- grammar: _
1308
+ got: g,
1309
+ expected: v.flatMap((o) => o.expected),
1310
+ grammar: h
1238
1311
  });
1239
1312
  },
1240
1313
  suggestions() {
1241
1314
  return o.flatMap((o) => o.suggestions());
1242
1315
  }
1243
1316
  };
1244
- return _;
1317
+ return h;
1245
1318
  }
1246
- function named(o, _) {
1247
- let v = {
1319
+ function named(o, h) {
1320
+ let g = {
1248
1321
  meta: { name: o },
1249
1322
  type: "named",
1250
1323
  suggestions() {
1251
- return _.suggestions();
1324
+ return h.suggestions();
1252
1325
  },
1253
- children: [_],
1254
- parse(o, y) {
1255
- let b = _.parse(o, y);
1256
- return isParserError(b) ? b : success({
1257
- text: b.text,
1258
- grammar: v,
1259
- children: [b]
1326
+ children: [h],
1327
+ parse(o, _) {
1328
+ let v = h.parse(o, _);
1329
+ return isParserError(v) ? v : success({
1330
+ text: v.text,
1331
+ grammar: g,
1332
+ children: [v]
1260
1333
  });
1261
1334
  }
1262
1335
  };
1263
- return v;
1336
+ return g;
1264
1337
  }
1265
- function repeat(o, _ = 1, v = 1e3) {
1266
- let y = {
1338
+ function repeat(o, h = 1, g = 1e3) {
1339
+ let _ = {
1267
1340
  type: "repeat",
1268
1341
  children: [o],
1269
1342
  suggestions: () => o.suggestions(),
1270
- parse(b, x) {
1271
- let S = 0, C = !1, w = [];
1272
- for (let y = 0; y < v && S < b.length; y++) {
1273
- let v = b.substring(S), T = o.parse(v, {
1274
- ...x,
1275
- faultTolerant: x.faultTolerant && !C
1343
+ parse(v, y) {
1344
+ let b = 0, x = !1, S = [];
1345
+ for (let _ = 0; _ < g && b < v.length; _++) {
1346
+ let g = v.substring(b), C = o.parse(g, {
1347
+ ...y,
1348
+ faultTolerant: y.faultTolerant && !x
1276
1349
  });
1277
- if (isParserError(T)) {
1278
- if (y >= _) break;
1279
- if (x.faultTolerant) {
1280
- if (!C) {
1281
- C = !0;
1350
+ if (isParserError(C)) {
1351
+ let o = {
1352
+ ...C,
1353
+ offset: b
1354
+ };
1355
+ if (_ >= h) break;
1356
+ if (y.faultTolerant) {
1357
+ if (!x) {
1358
+ x = !0;
1282
1359
  continue;
1283
1360
  }
1284
- return T;
1285
- } else return T;
1361
+ return o;
1362
+ } else return o;
1286
1363
  }
1287
- S += T.text.length, w.push(T);
1364
+ b += C.text.length, S.push({
1365
+ ...C,
1366
+ recoverableError: x
1367
+ });
1288
1368
  }
1289
1369
  return success({
1290
- grammar: y,
1291
- children: w,
1292
- text: b.substring(0, S)
1370
+ grammar: _,
1371
+ children: S,
1372
+ text: v.substring(0, b)
1293
1373
  });
1294
1374
  }
1295
1375
  };
1296
- return y;
1376
+ return _;
1297
1377
  }
1298
1378
  export { DSLParser, DslEditor, ParsingError, alternative, asException, eof, error, isParserError, isParserSuccess, named, optional, pattern, rational, repeat, seq, sequence, success, term, visit, ws };