@cloud-cli/on 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/on.js ADDED
@@ -0,0 +1,4621 @@
1
+ #!/usr/bin/env node
2
+ import { createServer as ms } from "node:http";
3
+ import { parseArgs as gs } from "node:util";
4
+ import { spawn as ys } from "node:child_process";
5
+ import { readFile as et } from "node:fs/promises";
6
+ import bt from "node:path";
7
+ const tt = /* @__PURE__ */ Symbol.for("yaml.alias"), We = /* @__PURE__ */ Symbol.for("yaml.document"), J = /* @__PURE__ */ Symbol.for("yaml.map"), vt = /* @__PURE__ */ Symbol.for("yaml.pair"), q = /* @__PURE__ */ Symbol.for("yaml.scalar"), oe = /* @__PURE__ */ Symbol.for("yaml.seq"), j = /* @__PURE__ */ Symbol.for("yaml.node.type"), Q = (s) => !!s && typeof s == "object" && s[j] === tt, Ce = (s) => !!s && typeof s == "object" && s[j] === We, ye = (s) => !!s && typeof s == "object" && s[j] === J, $ = (s) => !!s && typeof s == "object" && s[j] === vt, E = (s) => !!s && typeof s == "object" && s[j] === q, be = (s) => !!s && typeof s == "object" && s[j] === oe;
8
+ function I(s) {
9
+ if (s && typeof s == "object")
10
+ switch (s[j]) {
11
+ case J:
12
+ case oe:
13
+ return !0;
14
+ }
15
+ return !1;
16
+ }
17
+ function L(s) {
18
+ if (s && typeof s == "object")
19
+ switch (s[j]) {
20
+ case tt:
21
+ case J:
22
+ case q:
23
+ case oe:
24
+ return !0;
25
+ }
26
+ return !1;
27
+ }
28
+ const Ct = (s) => (E(s) || I(s)) && !!s.anchor, Y = /* @__PURE__ */ Symbol("break visit"), bs = /* @__PURE__ */ Symbol("skip children"), de = /* @__PURE__ */ Symbol("remove node");
29
+ function le(s, e) {
30
+ const t = ws(e);
31
+ Ce(s) ? Z(null, s.contents, t, Object.freeze([s])) === de && (s.contents = null) : Z(null, s, t, Object.freeze([]));
32
+ }
33
+ le.BREAK = Y;
34
+ le.SKIP = bs;
35
+ le.REMOVE = de;
36
+ function Z(s, e, t, n) {
37
+ const i = ks(s, e, t, n);
38
+ if (L(i) || $(i))
39
+ return Ss(s, n, i), Z(s, i, t, n);
40
+ if (typeof i != "symbol") {
41
+ if (I(e)) {
42
+ n = Object.freeze(n.concat(e));
43
+ for (let r = 0; r < e.items.length; ++r) {
44
+ const o = Z(r, e.items[r], t, n);
45
+ if (typeof o == "number")
46
+ r = o - 1;
47
+ else {
48
+ if (o === Y)
49
+ return Y;
50
+ o === de && (e.items.splice(r, 1), r -= 1);
51
+ }
52
+ }
53
+ } else if ($(e)) {
54
+ n = Object.freeze(n.concat(e));
55
+ const r = Z("key", e.key, t, n);
56
+ if (r === Y)
57
+ return Y;
58
+ r === de && (e.key = null);
59
+ const o = Z("value", e.value, t, n);
60
+ if (o === Y)
61
+ return Y;
62
+ o === de && (e.value = null);
63
+ }
64
+ }
65
+ return i;
66
+ }
67
+ function ws(s) {
68
+ return typeof s == "object" && (s.Collection || s.Node || s.Value) ? Object.assign({
69
+ Alias: s.Node,
70
+ Map: s.Node,
71
+ Scalar: s.Node,
72
+ Seq: s.Node
73
+ }, s.Value && {
74
+ Map: s.Value,
75
+ Scalar: s.Value,
76
+ Seq: s.Value
77
+ }, s.Collection && {
78
+ Map: s.Collection,
79
+ Seq: s.Collection
80
+ }, s) : s;
81
+ }
82
+ function ks(s, e, t, n) {
83
+ if (typeof t == "function")
84
+ return t(s, e, n);
85
+ if (ye(e))
86
+ return t.Map?.(s, e, n);
87
+ if (be(e))
88
+ return t.Seq?.(s, e, n);
89
+ if ($(e))
90
+ return t.Pair?.(s, e, n);
91
+ if (E(e))
92
+ return t.Scalar?.(s, e, n);
93
+ if (Q(e))
94
+ return t.Alias?.(s, e, n);
95
+ }
96
+ function Ss(s, e, t) {
97
+ const n = e[e.length - 1];
98
+ if (I(n))
99
+ n.items[s] = t;
100
+ else if ($(n))
101
+ s === "key" ? n.key = t : n.value = t;
102
+ else if (Ce(n))
103
+ n.contents = t;
104
+ else {
105
+ const i = Q(n) ? "alias" : "scalar";
106
+ throw new Error(`Cannot replace node with ${i} parent`);
107
+ }
108
+ }
109
+ const Ns = {
110
+ "!": "%21",
111
+ ",": "%2C",
112
+ "[": "%5B",
113
+ "]": "%5D",
114
+ "{": "%7B",
115
+ "}": "%7D"
116
+ }, Os = (s) => s.replace(/[!,[\]{}]/g, (e) => Ns[e]);
117
+ class _ {
118
+ constructor(e, t) {
119
+ this.docStart = null, this.docEnd = !1, this.yaml = Object.assign({}, _.defaultYaml, e), this.tags = Object.assign({}, _.defaultTags, t);
120
+ }
121
+ clone() {
122
+ const e = new _(this.yaml, this.tags);
123
+ return e.docStart = this.docStart, e;
124
+ }
125
+ /**
126
+ * During parsing, get a Directives instance for the current document and
127
+ * update the stream state according to the current version's spec.
128
+ */
129
+ atDocument() {
130
+ const e = new _(this.yaml, this.tags);
131
+ switch (this.yaml.version) {
132
+ case "1.1":
133
+ this.atNextDocument = !0;
134
+ break;
135
+ case "1.2":
136
+ this.atNextDocument = !1, this.yaml = {
137
+ explicit: _.defaultYaml.explicit,
138
+ version: "1.2"
139
+ }, this.tags = Object.assign({}, _.defaultTags);
140
+ break;
141
+ }
142
+ return e;
143
+ }
144
+ /**
145
+ * @param onError - May be called even if the action was successful
146
+ * @returns `true` on success
147
+ */
148
+ add(e, t) {
149
+ this.atNextDocument && (this.yaml = { explicit: _.defaultYaml.explicit, version: "1.1" }, this.tags = Object.assign({}, _.defaultTags), this.atNextDocument = !1);
150
+ const n = e.trim().split(/[ \t]+/), i = n.shift();
151
+ switch (i) {
152
+ case "%TAG": {
153
+ if (n.length !== 2 && (t(0, "%TAG directive should contain exactly two parts"), n.length < 2))
154
+ return !1;
155
+ const [r, o] = n;
156
+ return this.tags[r] = o, !0;
157
+ }
158
+ case "%YAML": {
159
+ if (this.yaml.explicit = !0, n.length !== 1)
160
+ return t(0, "%YAML directive should contain exactly one part"), !1;
161
+ const [r] = n;
162
+ if (r === "1.1" || r === "1.2")
163
+ return this.yaml.version = r, !0;
164
+ {
165
+ const o = /^\d+\.\d+$/.test(r);
166
+ return t(6, `Unsupported YAML version ${r}`, o), !1;
167
+ }
168
+ }
169
+ default:
170
+ return t(0, `Unknown directive ${i}`, !0), !1;
171
+ }
172
+ }
173
+ /**
174
+ * Resolves a tag, matching handles to those defined in %TAG directives.
175
+ *
176
+ * @returns Resolved tag, which may also be the non-specific tag `'!'` or a
177
+ * `'!local'` tag, or `null` if unresolvable.
178
+ */
179
+ tagName(e, t) {
180
+ if (e === "!")
181
+ return "!";
182
+ if (e[0] !== "!")
183
+ return t(`Not a valid tag: ${e}`), null;
184
+ if (e[1] === "<") {
185
+ const o = e.slice(2, -1);
186
+ return o === "!" || o === "!!" ? (t(`Verbatim tags aren't resolved, so ${e} is invalid.`), null) : (e[e.length - 1] !== ">" && t("Verbatim tags must end with a >"), o);
187
+ }
188
+ const [, n, i] = e.match(/^(.*!)([^!]*)$/s);
189
+ i || t(`The ${e} tag has no suffix`);
190
+ const r = this.tags[n];
191
+ if (r)
192
+ try {
193
+ return r + decodeURIComponent(i);
194
+ } catch (o) {
195
+ return t(String(o)), null;
196
+ }
197
+ return n === "!" ? e : (t(`Could not resolve tag: ${e}`), null);
198
+ }
199
+ /**
200
+ * Given a fully resolved tag, returns its printable string form,
201
+ * taking into account current tag prefixes and defaults.
202
+ */
203
+ tagString(e) {
204
+ for (const [t, n] of Object.entries(this.tags))
205
+ if (e.startsWith(n))
206
+ return t + Os(e.substring(n.length));
207
+ return e[0] === "!" ? e : `!<${e}>`;
208
+ }
209
+ toString(e) {
210
+ const t = this.yaml.explicit ? [`%YAML ${this.yaml.version || "1.2"}`] : [], n = Object.entries(this.tags);
211
+ let i;
212
+ if (e && n.length > 0 && L(e.contents)) {
213
+ const r = {};
214
+ le(e.contents, (o, l) => {
215
+ L(l) && l.tag && (r[l.tag] = !0);
216
+ }), i = Object.keys(r);
217
+ } else
218
+ i = [];
219
+ for (const [r, o] of n)
220
+ r === "!!" && o === "tag:yaml.org,2002:" || (!e || i.some((l) => l.startsWith(o))) && t.push(`%TAG ${r} ${o}`);
221
+ return t.join(`
222
+ `);
223
+ }
224
+ }
225
+ _.defaultYaml = { explicit: !1, version: "1.2" };
226
+ _.defaultTags = { "!!": "tag:yaml.org,2002:" };
227
+ function _t(s) {
228
+ if (/[\x00-\x19\s,[\]{}]/.test(s)) {
229
+ const t = `Anchor must not contain whitespace or control characters: ${JSON.stringify(s)}`;
230
+ throw new Error(t);
231
+ }
232
+ return !0;
233
+ }
234
+ function Bt(s) {
235
+ const e = /* @__PURE__ */ new Set();
236
+ return le(s, {
237
+ Value(t, n) {
238
+ n.anchor && e.add(n.anchor);
239
+ }
240
+ }), e;
241
+ }
242
+ function Mt(s, e) {
243
+ for (let t = 1; ; ++t) {
244
+ const n = `${s}${t}`;
245
+ if (!e.has(n))
246
+ return n;
247
+ }
248
+ }
249
+ function As(s, e) {
250
+ const t = [], n = /* @__PURE__ */ new Map();
251
+ let i = null;
252
+ return {
253
+ onAnchor: (r) => {
254
+ t.push(r), i ?? (i = Bt(s));
255
+ const o = Mt(e, i);
256
+ return i.add(o), o;
257
+ },
258
+ /**
259
+ * With circular references, the source node is only resolved after all
260
+ * of its child nodes are. This is why anchors are set only after all of
261
+ * the nodes have been created.
262
+ */
263
+ setAnchors: () => {
264
+ for (const r of t) {
265
+ const o = n.get(r);
266
+ if (typeof o == "object" && o.anchor && (E(o.node) || I(o.node)))
267
+ o.node.anchor = o.anchor;
268
+ else {
269
+ const l = new Error("Failed to resolve repeated object (this should not happen)");
270
+ throw l.source = r, l;
271
+ }
272
+ }
273
+ },
274
+ sourceObjects: n
275
+ };
276
+ }
277
+ function ee(s, e, t, n) {
278
+ if (n && typeof n == "object")
279
+ if (Array.isArray(n))
280
+ for (let i = 0, r = n.length; i < r; ++i) {
281
+ const o = n[i], l = ee(s, n, String(i), o);
282
+ l === void 0 ? delete n[i] : l !== o && (n[i] = l);
283
+ }
284
+ else if (n instanceof Map)
285
+ for (const i of Array.from(n.keys())) {
286
+ const r = n.get(i), o = ee(s, n, i, r);
287
+ o === void 0 ? n.delete(i) : o !== r && n.set(i, o);
288
+ }
289
+ else if (n instanceof Set)
290
+ for (const i of Array.from(n)) {
291
+ const r = ee(s, n, i, i);
292
+ r === void 0 ? n.delete(i) : r !== i && (n.delete(i), n.add(r));
293
+ }
294
+ else
295
+ for (const [i, r] of Object.entries(n)) {
296
+ const o = ee(s, n, i, r);
297
+ o === void 0 ? delete n[i] : o !== r && (n[i] = o);
298
+ }
299
+ return s.call(e, t, n);
300
+ }
301
+ function P(s, e, t) {
302
+ if (Array.isArray(s))
303
+ return s.map((n, i) => P(n, String(i), t));
304
+ if (s && typeof s.toJSON == "function") {
305
+ if (!t || !Ct(s))
306
+ return s.toJSON(e, t);
307
+ const n = { aliasCount: 0, count: 1, res: void 0 };
308
+ t.anchors.set(s, n), t.onCreate = (r) => {
309
+ n.res = r, delete t.onCreate;
310
+ };
311
+ const i = s.toJSON(e, t);
312
+ return t.onCreate && t.onCreate(i), i;
313
+ }
314
+ return typeof s == "bigint" && !t?.keep ? Number(s) : s;
315
+ }
316
+ class st {
317
+ constructor(e) {
318
+ Object.defineProperty(this, j, { value: e });
319
+ }
320
+ /** Create a copy of this node. */
321
+ clone() {
322
+ const e = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
323
+ return this.range && (e.range = this.range.slice()), e;
324
+ }
325
+ /** A plain JavaScript representation of this node. */
326
+ toJS(e, { mapAsMap: t, maxAliasCount: n, onAnchor: i, reviver: r } = {}) {
327
+ if (!Ce(e))
328
+ throw new TypeError("A document argument is required");
329
+ const o = {
330
+ anchors: /* @__PURE__ */ new Map(),
331
+ doc: e,
332
+ keep: !0,
333
+ mapAsMap: t === !0,
334
+ mapKeyWarned: !1,
335
+ maxAliasCount: typeof n == "number" ? n : 100
336
+ }, l = P(this, "", o);
337
+ if (typeof i == "function")
338
+ for (const { count: a, res: c } of o.anchors.values())
339
+ i(c, a);
340
+ return typeof r == "function" ? ee(r, { "": l }, "", l) : l;
341
+ }
342
+ }
343
+ class nt extends st {
344
+ constructor(e) {
345
+ super(tt), this.source = e, Object.defineProperty(this, "tag", {
346
+ set() {
347
+ throw new Error("Alias nodes cannot have tags");
348
+ }
349
+ });
350
+ }
351
+ /**
352
+ * Resolve the value of this alias within `doc`, finding the last
353
+ * instance of the `source` anchor before this node.
354
+ */
355
+ resolve(e, t) {
356
+ let n;
357
+ t?.aliasResolveCache ? n = t.aliasResolveCache : (n = [], le(e, {
358
+ Node: (r, o) => {
359
+ (Q(o) || Ct(o)) && n.push(o);
360
+ }
361
+ }), t && (t.aliasResolveCache = n));
362
+ let i;
363
+ for (const r of n) {
364
+ if (r === this)
365
+ break;
366
+ r.anchor === this.source && (i = r);
367
+ }
368
+ return i;
369
+ }
370
+ toJSON(e, t) {
371
+ if (!t)
372
+ return { source: this.source };
373
+ const { anchors: n, doc: i, maxAliasCount: r } = t, o = this.resolve(i, t);
374
+ if (!o) {
375
+ const a = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
376
+ throw new ReferenceError(a);
377
+ }
378
+ let l = n.get(o);
379
+ if (l || (P(o, null, t), l = n.get(o)), l?.res === void 0) {
380
+ const a = "This should not happen: Alias anchor was not resolved?";
381
+ throw new ReferenceError(a);
382
+ }
383
+ if (r >= 0 && (l.count += 1, l.aliasCount === 0 && (l.aliasCount = Ee(i, o, n)), l.count * l.aliasCount > r)) {
384
+ const a = "Excessive alias count indicates a resource exhaustion attack";
385
+ throw new ReferenceError(a);
386
+ }
387
+ return l.res;
388
+ }
389
+ toString(e, t, n) {
390
+ const i = `*${this.source}`;
391
+ if (e) {
392
+ if (_t(this.source), e.options.verifyAliasOrder && !e.anchors.has(this.source)) {
393
+ const r = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
394
+ throw new Error(r);
395
+ }
396
+ if (e.implicitKey)
397
+ return `${i} `;
398
+ }
399
+ return i;
400
+ }
401
+ }
402
+ function Ee(s, e, t) {
403
+ if (Q(e)) {
404
+ const n = e.resolve(s), i = t && n && t.get(n);
405
+ return i ? i.count * i.aliasCount : 0;
406
+ } else if (I(e)) {
407
+ let n = 0;
408
+ for (const i of e.items) {
409
+ const r = Ee(s, i, t);
410
+ r > n && (n = r);
411
+ }
412
+ return n;
413
+ } else if ($(e)) {
414
+ const n = Ee(s, e.key, t), i = Ee(s, e.value, t);
415
+ return Math.max(n, i);
416
+ }
417
+ return 1;
418
+ }
419
+ const Pt = (s) => !s || typeof s != "function" && typeof s != "object";
420
+ class O extends st {
421
+ constructor(e) {
422
+ super(q), this.value = e;
423
+ }
424
+ toJSON(e, t) {
425
+ return t?.keep ? this.value : P(this.value, e, t);
426
+ }
427
+ toString() {
428
+ return String(this.value);
429
+ }
430
+ }
431
+ O.BLOCK_FOLDED = "BLOCK_FOLDED";
432
+ O.BLOCK_LITERAL = "BLOCK_LITERAL";
433
+ O.PLAIN = "PLAIN";
434
+ O.QUOTE_DOUBLE = "QUOTE_DOUBLE";
435
+ O.QUOTE_SINGLE = "QUOTE_SINGLE";
436
+ const Ts = "tag:yaml.org,2002:";
437
+ function Es(s, e, t) {
438
+ if (e) {
439
+ const n = t.filter((r) => r.tag === e), i = n.find((r) => !r.format) ?? n[0];
440
+ if (!i)
441
+ throw new Error(`Tag ${e} not found`);
442
+ return i;
443
+ }
444
+ return t.find((n) => n.identify?.(s) && !n.format);
445
+ }
446
+ function me(s, e, t) {
447
+ if (Ce(s) && (s = s.contents), L(s))
448
+ return s;
449
+ if ($(s)) {
450
+ const f = t.schema[J].createNode?.(t.schema, null, t);
451
+ return f.items.push(s), f;
452
+ }
453
+ (s instanceof String || s instanceof Number || s instanceof Boolean || typeof BigInt < "u" && s instanceof BigInt) && (s = s.valueOf());
454
+ const { aliasDuplicateObjects: n, onAnchor: i, onTagObj: r, schema: o, sourceObjects: l } = t;
455
+ let a;
456
+ if (n && s && typeof s == "object") {
457
+ if (a = l.get(s), a)
458
+ return a.anchor ?? (a.anchor = i(s)), new nt(a.anchor);
459
+ a = { anchor: null, node: null }, l.set(s, a);
460
+ }
461
+ e?.startsWith("!!") && (e = Ts + e.slice(2));
462
+ let c = Es(s, e, o.tags);
463
+ if (!c) {
464
+ if (s && typeof s.toJSON == "function" && (s = s.toJSON()), !s || typeof s != "object") {
465
+ const f = new O(s);
466
+ return a && (a.node = f), f;
467
+ }
468
+ c = s instanceof Map ? o[J] : Symbol.iterator in Object(s) ? o[oe] : o[J];
469
+ }
470
+ r && (r(c), delete t.onTagObj);
471
+ const d = c?.createNode ? c.createNode(t.schema, s, t) : typeof c?.nodeClass?.from == "function" ? c.nodeClass.from(t.schema, s, t) : new O(s);
472
+ return e ? d.tag = e : c.default || (d.tag = c.tag), a && (a.node = d), d;
473
+ }
474
+ function $e(s, e, t) {
475
+ let n = t;
476
+ for (let i = e.length - 1; i >= 0; --i) {
477
+ const r = e[i];
478
+ if (typeof r == "number" && Number.isInteger(r) && r >= 0) {
479
+ const o = [];
480
+ o[r] = n, n = o;
481
+ } else
482
+ n = /* @__PURE__ */ new Map([[r, n]]);
483
+ }
484
+ return me(n, void 0, {
485
+ aliasDuplicateObjects: !1,
486
+ keepUndefined: !1,
487
+ onAnchor: () => {
488
+ throw new Error("This should not happen, please report a bug.");
489
+ },
490
+ schema: s,
491
+ sourceObjects: /* @__PURE__ */ new Map()
492
+ });
493
+ }
494
+ const ue = (s) => s == null || typeof s == "object" && !!s[Symbol.iterator]().next().done;
495
+ class jt extends st {
496
+ constructor(e, t) {
497
+ super(e), Object.defineProperty(this, "schema", {
498
+ value: t,
499
+ configurable: !0,
500
+ enumerable: !1,
501
+ writable: !0
502
+ });
503
+ }
504
+ /**
505
+ * Create a copy of this collection.
506
+ *
507
+ * @param schema - If defined, overwrites the original's schema
508
+ */
509
+ clone(e) {
510
+ const t = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
511
+ return e && (t.schema = e), t.items = t.items.map((n) => L(n) || $(n) ? n.clone(e) : n), this.range && (t.range = this.range.slice()), t;
512
+ }
513
+ /**
514
+ * Adds a value to the collection. For `!!map` and `!!omap` the value must
515
+ * be a Pair instance or a `{ key, value }` object, which may not have a key
516
+ * that already exists in the map.
517
+ */
518
+ addIn(e, t) {
519
+ if (ue(e))
520
+ this.add(t);
521
+ else {
522
+ const [n, ...i] = e, r = this.get(n, !0);
523
+ if (I(r))
524
+ r.addIn(i, t);
525
+ else if (r === void 0 && this.schema)
526
+ this.set(n, $e(this.schema, i, t));
527
+ else
528
+ throw new Error(`Expected YAML collection at ${n}. Remaining path: ${i}`);
529
+ }
530
+ }
531
+ /**
532
+ * Removes a value from the collection.
533
+ * @returns `true` if the item was found and removed.
534
+ */
535
+ deleteIn(e) {
536
+ const [t, ...n] = e;
537
+ if (n.length === 0)
538
+ return this.delete(t);
539
+ const i = this.get(t, !0);
540
+ if (I(i))
541
+ return i.deleteIn(n);
542
+ throw new Error(`Expected YAML collection at ${t}. Remaining path: ${n}`);
543
+ }
544
+ /**
545
+ * Returns item at `key`, or `undefined` if not found. By default unwraps
546
+ * scalar values from their surrounding node; to disable set `keepScalar` to
547
+ * `true` (collections are always returned intact).
548
+ */
549
+ getIn(e, t) {
550
+ const [n, ...i] = e, r = this.get(n, !0);
551
+ return i.length === 0 ? !t && E(r) ? r.value : r : I(r) ? r.getIn(i, t) : void 0;
552
+ }
553
+ hasAllNullValues(e) {
554
+ return this.items.every((t) => {
555
+ if (!$(t))
556
+ return !1;
557
+ const n = t.value;
558
+ return n == null || e && E(n) && n.value == null && !n.commentBefore && !n.comment && !n.tag;
559
+ });
560
+ }
561
+ /**
562
+ * Checks if the collection includes a value with the key `key`.
563
+ */
564
+ hasIn(e) {
565
+ const [t, ...n] = e;
566
+ if (n.length === 0)
567
+ return this.has(t);
568
+ const i = this.get(t, !0);
569
+ return I(i) ? i.hasIn(n) : !1;
570
+ }
571
+ /**
572
+ * Sets a value in this collection. For `!!set`, `value` needs to be a
573
+ * boolean to add/remove the item from the set.
574
+ */
575
+ setIn(e, t) {
576
+ const [n, ...i] = e;
577
+ if (i.length === 0)
578
+ this.set(n, t);
579
+ else {
580
+ const r = this.get(n, !0);
581
+ if (I(r))
582
+ r.setIn(i, t);
583
+ else if (r === void 0 && this.schema)
584
+ this.set(n, $e(this.schema, i, t));
585
+ else
586
+ throw new Error(`Expected YAML collection at ${n}. Remaining path: ${i}`);
587
+ }
588
+ }
589
+ }
590
+ const Is = (s) => s.replace(/^(?!$)(?: $)?/gm, "#");
591
+ function U(s, e) {
592
+ return /^\n+$/.test(s) ? s.substring(1) : e ? s.replace(/^(?! *$)/gm, e) : s;
593
+ }
594
+ const G = (s, e, t) => s.endsWith(`
595
+ `) ? U(t, e) : t.includes(`
596
+ `) ? `
597
+ ` + U(t, e) : (s.endsWith(" ") ? "" : " ") + t, Kt = "flow", Qe = "block", Ie = "quoted";
598
+ function _e(s, e, t = "flow", { indentAtStart: n, lineWidth: i = 80, minContentWidth: r = 20, onFold: o, onOverflow: l } = {}) {
599
+ if (!i || i < 0)
600
+ return s;
601
+ i < r && (r = 0);
602
+ const a = Math.max(1 + r, 1 + i - e.length);
603
+ if (s.length <= a)
604
+ return s;
605
+ const c = [], d = {};
606
+ let f = i - e.length;
607
+ typeof n == "number" && (n > i - Math.max(2, r) ? c.push(0) : f = i - n);
608
+ let u, m, g = !1, h = -1, p = -1, b = -1;
609
+ t === Qe && (h = wt(s, h, e.length), h !== -1 && (f = h + a));
610
+ for (let k; k = s[h += 1]; ) {
611
+ if (t === Ie && k === "\\") {
612
+ switch (p = h, s[h + 1]) {
613
+ case "x":
614
+ h += 3;
615
+ break;
616
+ case "u":
617
+ h += 5;
618
+ break;
619
+ case "U":
620
+ h += 9;
621
+ break;
622
+ default:
623
+ h += 1;
624
+ }
625
+ b = h;
626
+ }
627
+ if (k === `
628
+ `)
629
+ t === Qe && (h = wt(s, h, e.length)), f = h + e.length + a, u = void 0;
630
+ else {
631
+ if (k === " " && m && m !== " " && m !== `
632
+ ` && m !== " ") {
633
+ const S = s[h + 1];
634
+ S && S !== " " && S !== `
635
+ ` && S !== " " && (u = h);
636
+ }
637
+ if (h >= f)
638
+ if (u)
639
+ c.push(u), f = u + a, u = void 0;
640
+ else if (t === Ie) {
641
+ for (; m === " " || m === " "; )
642
+ m = k, k = s[h += 1], g = !0;
643
+ const S = h > b + 1 ? h - 2 : p - 1;
644
+ if (d[S])
645
+ return s;
646
+ c.push(S), d[S] = !0, f = S + a, u = void 0;
647
+ } else
648
+ g = !0;
649
+ }
650
+ m = k;
651
+ }
652
+ if (g && l && l(), c.length === 0)
653
+ return s;
654
+ o && o();
655
+ let w = s.slice(0, c[0]);
656
+ for (let k = 0; k < c.length; ++k) {
657
+ const S = c[k], N = c[k + 1] || s.length;
658
+ S === 0 ? w = `
659
+ ${e}${s.slice(0, N)}` : (t === Ie && d[S] && (w += `${s[S]}\\`), w += `
660
+ ${e}${s.slice(S + 1, N)}`);
661
+ }
662
+ return w;
663
+ }
664
+ function wt(s, e, t) {
665
+ let n = e, i = e + 1, r = s[i];
666
+ for (; r === " " || r === " "; )
667
+ if (e < i + t)
668
+ r = s[++e];
669
+ else {
670
+ do
671
+ r = s[++e];
672
+ while (r && r !== `
673
+ `);
674
+ n = e, i = e + 1, r = s[i];
675
+ }
676
+ return n;
677
+ }
678
+ const Be = (s, e) => ({
679
+ indentAtStart: e ? s.indent.length : s.indentAtStart,
680
+ lineWidth: s.options.lineWidth,
681
+ minContentWidth: s.options.minContentWidth
682
+ }), Me = (s) => /^(%|---|\.\.\.)/m.test(s);
683
+ function Ls(s, e, t) {
684
+ if (!e || e < 0)
685
+ return !1;
686
+ const n = e - t, i = s.length;
687
+ if (i <= n)
688
+ return !1;
689
+ for (let r = 0, o = 0; r < i; ++r)
690
+ if (s[r] === `
691
+ `) {
692
+ if (r - o > n)
693
+ return !0;
694
+ if (o = r + 1, i - o <= n)
695
+ return !1;
696
+ }
697
+ return !0;
698
+ }
699
+ function pe(s, e) {
700
+ const t = JSON.stringify(s);
701
+ if (e.options.doubleQuotedAsJSON)
702
+ return t;
703
+ const { implicitKey: n } = e, i = e.options.doubleQuotedMinMultiLineLength, r = e.indent || (Me(s) ? " " : "");
704
+ let o = "", l = 0;
705
+ for (let a = 0, c = t[a]; c; c = t[++a])
706
+ if (c === " " && t[a + 1] === "\\" && t[a + 2] === "n" && (o += t.slice(l, a) + "\\ ", a += 1, l = a, c = "\\"), c === "\\")
707
+ switch (t[a + 1]) {
708
+ case "u":
709
+ {
710
+ o += t.slice(l, a);
711
+ const d = t.substr(a + 2, 4);
712
+ switch (d) {
713
+ case "0000":
714
+ o += "\\0";
715
+ break;
716
+ case "0007":
717
+ o += "\\a";
718
+ break;
719
+ case "000b":
720
+ o += "\\v";
721
+ break;
722
+ case "001b":
723
+ o += "\\e";
724
+ break;
725
+ case "0085":
726
+ o += "\\N";
727
+ break;
728
+ case "00a0":
729
+ o += "\\_";
730
+ break;
731
+ case "2028":
732
+ o += "\\L";
733
+ break;
734
+ case "2029":
735
+ o += "\\P";
736
+ break;
737
+ default:
738
+ d.substr(0, 2) === "00" ? o += "\\x" + d.substr(2) : o += t.substr(a, 6);
739
+ }
740
+ a += 5, l = a + 1;
741
+ }
742
+ break;
743
+ case "n":
744
+ if (n || t[a + 2] === '"' || t.length < i)
745
+ a += 1;
746
+ else {
747
+ for (o += t.slice(l, a) + `
748
+
749
+ `; t[a + 2] === "\\" && t[a + 3] === "n" && t[a + 4] !== '"'; )
750
+ o += `
751
+ `, a += 2;
752
+ o += r, t[a + 2] === " " && (o += "\\"), a += 1, l = a + 1;
753
+ }
754
+ break;
755
+ default:
756
+ a += 1;
757
+ }
758
+ return o = l ? o + t.slice(l) : t, n ? o : _e(o, r, Ie, Be(e, !1));
759
+ }
760
+ function Xe(s, e) {
761
+ if (e.options.singleQuote === !1 || e.implicitKey && s.includes(`
762
+ `) || /[ \t]\n|\n[ \t]/.test(s))
763
+ return pe(s, e);
764
+ const t = e.indent || (Me(s) ? " " : ""), n = "'" + s.replace(/'/g, "''").replace(/\n+/g, `$&
765
+ ${t}`) + "'";
766
+ return e.implicitKey ? n : _e(n, t, Kt, Be(e, !1));
767
+ }
768
+ function te(s, e) {
769
+ const { singleQuote: t } = e.options;
770
+ let n;
771
+ if (t === !1)
772
+ n = pe;
773
+ else {
774
+ const i = s.includes('"'), r = s.includes("'");
775
+ i && !r ? n = Xe : r && !i ? n = pe : n = t ? Xe : pe;
776
+ }
777
+ return n(s, e);
778
+ }
779
+ let xe;
780
+ try {
781
+ xe = new RegExp(`(^|(?<!
782
+ ))
783
+ +(?!
784
+ |$)`, "g");
785
+ } catch {
786
+ xe = /\n+(?!\n|$)/g;
787
+ }
788
+ function Le({ comment: s, type: e, value: t }, n, i, r) {
789
+ const { blockQuote: o, commentString: l, lineWidth: a } = n.options;
790
+ if (!o || /\n[\t ]+$/.test(t))
791
+ return te(t, n);
792
+ const c = n.indent || (n.forceBlockIndent || Me(t) ? " " : ""), d = o === "literal" ? !0 : o === "folded" || e === O.BLOCK_FOLDED ? !1 : e === O.BLOCK_LITERAL ? !0 : !Ls(t, a, c.length);
793
+ if (!t)
794
+ return d ? `|
795
+ ` : `>
796
+ `;
797
+ let f, u;
798
+ for (u = t.length; u > 0; --u) {
799
+ const N = t[u - 1];
800
+ if (N !== `
801
+ ` && N !== " " && N !== " ")
802
+ break;
803
+ }
804
+ let m = t.substring(u);
805
+ const g = m.indexOf(`
806
+ `);
807
+ g === -1 ? f = "-" : t === m || g !== m.length - 1 ? (f = "+", r && r()) : f = "", m && (t = t.slice(0, -m.length), m[m.length - 1] === `
808
+ ` && (m = m.slice(0, -1)), m = m.replace(xe, `$&${c}`));
809
+ let h = !1, p, b = -1;
810
+ for (p = 0; p < t.length; ++p) {
811
+ const N = t[p];
812
+ if (N === " ")
813
+ h = !0;
814
+ else if (N === `
815
+ `)
816
+ b = p;
817
+ else
818
+ break;
819
+ }
820
+ let w = t.substring(0, b < p ? b + 1 : p);
821
+ w && (t = t.substring(w.length), w = w.replace(/\n+/g, `$&${c}`));
822
+ let S = (h ? c ? "2" : "1" : "") + f;
823
+ if (s && (S += " " + l(s.replace(/ ?[\r\n]+/g, " ")), i && i()), !d) {
824
+ const N = t.replace(/\n+/g, `
825
+ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, "$1$2").replace(/\n+/g, `$&${c}`);
826
+ let A = !1;
827
+ const T = Be(n, !0);
828
+ o !== "folded" && e !== O.BLOCK_FOLDED && (T.onOverflow = () => {
829
+ A = !0;
830
+ });
831
+ const y = _e(`${w}${N}${m}`, c, Qe, T);
832
+ if (!A)
833
+ return `>${S}
834
+ ${c}${y}`;
835
+ }
836
+ return t = t.replace(/\n+/g, `$&${c}`), `|${S}
837
+ ${c}${w}${t}${m}`;
838
+ }
839
+ function $s(s, e, t, n) {
840
+ const { type: i, value: r } = s, { actualString: o, implicitKey: l, indent: a, indentStep: c, inFlow: d } = e;
841
+ if (l && r.includes(`
842
+ `) || d && /[[\]{},]/.test(r))
843
+ return te(r, e);
844
+ if (/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(r))
845
+ return l || d || !r.includes(`
846
+ `) ? te(r, e) : Le(s, e, t, n);
847
+ if (!l && !d && i !== O.PLAIN && r.includes(`
848
+ `))
849
+ return Le(s, e, t, n);
850
+ if (Me(r)) {
851
+ if (a === "")
852
+ return e.forceBlockIndent = !0, Le(s, e, t, n);
853
+ if (l && a === c)
854
+ return te(r, e);
855
+ }
856
+ const f = r.replace(/\n+/g, `$&
857
+ ${a}`);
858
+ if (o) {
859
+ const u = (h) => h.default && h.tag !== "tag:yaml.org,2002:str" && h.test?.test(f), { compat: m, tags: g } = e.doc.schema;
860
+ if (g.some(u) || m?.some(u))
861
+ return te(r, e);
862
+ }
863
+ return l ? f : _e(f, a, Kt, Be(e, !1));
864
+ }
865
+ function it(s, e, t, n) {
866
+ const { implicitKey: i, inFlow: r } = e, o = typeof s.value == "string" ? s : Object.assign({}, s, { value: String(s.value) });
867
+ let { type: l } = s;
868
+ l !== O.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(o.value) && (l = O.QUOTE_DOUBLE);
869
+ const a = (d) => {
870
+ switch (d) {
871
+ case O.BLOCK_FOLDED:
872
+ case O.BLOCK_LITERAL:
873
+ return i || r ? te(o.value, e) : Le(o, e, t, n);
874
+ case O.QUOTE_DOUBLE:
875
+ return pe(o.value, e);
876
+ case O.QUOTE_SINGLE:
877
+ return Xe(o.value, e);
878
+ case O.PLAIN:
879
+ return $s(o, e, t, n);
880
+ default:
881
+ return null;
882
+ }
883
+ };
884
+ let c = a(l);
885
+ if (c === null) {
886
+ const { defaultKeyType: d, defaultStringType: f } = e.options, u = i && d || f;
887
+ if (c = a(u), c === null)
888
+ throw new Error(`Unsupported default string type ${u}`);
889
+ }
890
+ return c;
891
+ }
892
+ function Dt(s, e) {
893
+ const t = Object.assign({
894
+ blockQuote: !0,
895
+ commentString: Is,
896
+ defaultKeyType: null,
897
+ defaultStringType: "PLAIN",
898
+ directives: null,
899
+ doubleQuotedAsJSON: !1,
900
+ doubleQuotedMinMultiLineLength: 40,
901
+ falseStr: "false",
902
+ flowCollectionPadding: !0,
903
+ indentSeq: !0,
904
+ lineWidth: 80,
905
+ minContentWidth: 20,
906
+ nullStr: "null",
907
+ simpleKeys: !1,
908
+ singleQuote: null,
909
+ trueStr: "true",
910
+ verifyAliasOrder: !0
911
+ }, s.schema.toStringOptions, e);
912
+ let n;
913
+ switch (t.collectionStyle) {
914
+ case "block":
915
+ n = !1;
916
+ break;
917
+ case "flow":
918
+ n = !0;
919
+ break;
920
+ default:
921
+ n = null;
922
+ }
923
+ return {
924
+ anchors: /* @__PURE__ */ new Set(),
925
+ doc: s,
926
+ flowCollectionPadding: t.flowCollectionPadding ? " " : "",
927
+ indent: "",
928
+ indentStep: typeof t.indent == "number" ? " ".repeat(t.indent) : " ",
929
+ inFlow: n,
930
+ options: t
931
+ };
932
+ }
933
+ function vs(s, e) {
934
+ if (e.tag) {
935
+ const i = s.filter((r) => r.tag === e.tag);
936
+ if (i.length > 0)
937
+ return i.find((r) => r.format === e.format) ?? i[0];
938
+ }
939
+ let t, n;
940
+ if (E(e)) {
941
+ n = e.value;
942
+ let i = s.filter((r) => r.identify?.(n));
943
+ if (i.length > 1) {
944
+ const r = i.filter((o) => o.test);
945
+ r.length > 0 && (i = r);
946
+ }
947
+ t = i.find((r) => r.format === e.format) ?? i.find((r) => !r.format);
948
+ } else
949
+ n = e, t = s.find((i) => i.nodeClass && n instanceof i.nodeClass);
950
+ if (!t) {
951
+ const i = n?.constructor?.name ?? (n === null ? "null" : typeof n);
952
+ throw new Error(`Tag not resolved for ${i} value`);
953
+ }
954
+ return t;
955
+ }
956
+ function Cs(s, e, { anchors: t, doc: n }) {
957
+ if (!n.directives)
958
+ return "";
959
+ const i = [], r = (E(s) || I(s)) && s.anchor;
960
+ r && _t(r) && (t.add(r), i.push(`&${r}`));
961
+ const o = s.tag ?? (e.default ? null : e.tag);
962
+ return o && i.push(n.directives.tagString(o)), i.join(" ");
963
+ }
964
+ function ie(s, e, t, n) {
965
+ if ($(s))
966
+ return s.toString(e, t, n);
967
+ if (Q(s)) {
968
+ if (e.doc.directives)
969
+ return s.toString(e);
970
+ if (e.resolvedAliases?.has(s))
971
+ throw new TypeError("Cannot stringify circular structure without alias nodes");
972
+ e.resolvedAliases ? e.resolvedAliases.add(s) : e.resolvedAliases = /* @__PURE__ */ new Set([s]), s = s.resolve(e.doc);
973
+ }
974
+ let i;
975
+ const r = L(s) ? s : e.doc.createNode(s, { onTagObj: (a) => i = a });
976
+ i ?? (i = vs(e.doc.schema.tags, r));
977
+ const o = Cs(r, i, e);
978
+ o.length > 0 && (e.indentAtStart = (e.indentAtStart ?? 0) + o.length + 1);
979
+ const l = typeof i.stringify == "function" ? i.stringify(r, e, t, n) : E(r) ? it(r, e, t, n) : r.toString(e, t, n);
980
+ return o ? E(r) || l[0] === "{" || l[0] === "[" ? `${o} ${l}` : `${o}
981
+ ${e.indent}${l}` : l;
982
+ }
983
+ function _s({ key: s, value: e }, t, n, i) {
984
+ const { allNullValues: r, doc: o, indent: l, indentStep: a, options: { commentString: c, indentSeq: d, simpleKeys: f } } = t;
985
+ let u = L(s) && s.comment || null;
986
+ if (f) {
987
+ if (u)
988
+ throw new Error("With simple keys, key nodes cannot have comments");
989
+ if (I(s) || !L(s) && typeof s == "object") {
990
+ const T = "With simple keys, collection cannot be used as a key value";
991
+ throw new Error(T);
992
+ }
993
+ }
994
+ let m = !f && (!s || u && e == null && !t.inFlow || I(s) || (E(s) ? s.type === O.BLOCK_FOLDED || s.type === O.BLOCK_LITERAL : typeof s == "object"));
995
+ t = Object.assign({}, t, {
996
+ allNullValues: !1,
997
+ implicitKey: !m && (f || !r),
998
+ indent: l + a
999
+ });
1000
+ let g = !1, h = !1, p = ie(s, t, () => g = !0, () => h = !0);
1001
+ if (!m && !t.inFlow && p.length > 1024) {
1002
+ if (f)
1003
+ throw new Error("With simple keys, single line scalar must not span more than 1024 characters");
1004
+ m = !0;
1005
+ }
1006
+ if (t.inFlow) {
1007
+ if (r || e == null)
1008
+ return g && n && n(), p === "" ? "?" : m ? `? ${p}` : p;
1009
+ } else if (r && !f || e == null && m)
1010
+ return p = `? ${p}`, u && !g ? p += G(p, t.indent, c(u)) : h && i && i(), p;
1011
+ g && (u = null), m ? (u && (p += G(p, t.indent, c(u))), p = `? ${p}
1012
+ ${l}:`) : (p = `${p}:`, u && (p += G(p, t.indent, c(u))));
1013
+ let b, w, k;
1014
+ L(e) ? (b = !!e.spaceBefore, w = e.commentBefore, k = e.comment) : (b = !1, w = null, k = null, e && typeof e == "object" && (e = o.createNode(e))), t.implicitKey = !1, !m && !u && E(e) && (t.indentAtStart = p.length + 1), h = !1, !d && a.length >= 2 && !t.inFlow && !m && be(e) && !e.flow && !e.tag && !e.anchor && (t.indent = t.indent.substring(2));
1015
+ let S = !1;
1016
+ const N = ie(e, t, () => S = !0, () => h = !0);
1017
+ let A = " ";
1018
+ if (u || b || w) {
1019
+ if (A = b ? `
1020
+ ` : "", w) {
1021
+ const T = c(w);
1022
+ A += `
1023
+ ${U(T, t.indent)}`;
1024
+ }
1025
+ N === "" && !t.inFlow ? A === `
1026
+ ` && k && (A = `
1027
+
1028
+ `) : A += `
1029
+ ${t.indent}`;
1030
+ } else if (!m && I(e)) {
1031
+ const T = N[0], y = N.indexOf(`
1032
+ `), v = y !== -1, R = t.inFlow ?? e.flow ?? e.items.length === 0;
1033
+ if (v || !R) {
1034
+ let X = !1;
1035
+ if (v && (T === "&" || T === "!")) {
1036
+ let C = N.indexOf(" ");
1037
+ T === "&" && C !== -1 && C < y && N[C + 1] === "!" && (C = N.indexOf(" ", C + 1)), (C === -1 || y < C) && (X = !0);
1038
+ }
1039
+ X || (A = `
1040
+ ${t.indent}`);
1041
+ }
1042
+ } else (N === "" || N[0] === `
1043
+ `) && (A = "");
1044
+ return p += A + N, t.inFlow ? S && n && n() : k && !S ? p += G(p, t.indent, c(k)) : h && i && i(), p;
1045
+ }
1046
+ function qt(s, e) {
1047
+ (s === "debug" || s === "warn") && console.warn(e);
1048
+ }
1049
+ const Se = "<<", F = {
1050
+ identify: (s) => s === Se || typeof s == "symbol" && s.description === Se,
1051
+ default: "key",
1052
+ tag: "tag:yaml.org,2002:merge",
1053
+ test: /^<<$/,
1054
+ resolve: () => Object.assign(new O(Symbol(Se)), {
1055
+ addToJSMap: Ut
1056
+ }),
1057
+ stringify: () => Se
1058
+ }, Bs = (s, e) => (F.identify(e) || E(e) && (!e.type || e.type === O.PLAIN) && F.identify(e.value)) && s?.doc.schema.tags.some((t) => t.tag === F.tag && t.default);
1059
+ function Ut(s, e, t) {
1060
+ if (t = s && Q(t) ? t.resolve(s.doc) : t, be(t))
1061
+ for (const n of t.items)
1062
+ Fe(s, e, n);
1063
+ else if (Array.isArray(t))
1064
+ for (const n of t)
1065
+ Fe(s, e, n);
1066
+ else
1067
+ Fe(s, e, t);
1068
+ }
1069
+ function Fe(s, e, t) {
1070
+ const n = s && Q(t) ? t.resolve(s.doc) : t;
1071
+ if (!ye(n))
1072
+ throw new Error("Merge sources must be maps or map aliases");
1073
+ const i = n.toJSON(null, s, Map);
1074
+ for (const [r, o] of i)
1075
+ e instanceof Map ? e.has(r) || e.set(r, o) : e instanceof Set ? e.add(r) : Object.prototype.hasOwnProperty.call(e, r) || Object.defineProperty(e, r, {
1076
+ value: o,
1077
+ writable: !0,
1078
+ enumerable: !0,
1079
+ configurable: !0
1080
+ });
1081
+ return e;
1082
+ }
1083
+ function Ft(s, e, { key: t, value: n }) {
1084
+ if (L(t) && t.addToJSMap)
1085
+ t.addToJSMap(s, e, n);
1086
+ else if (Bs(s, t))
1087
+ Ut(s, e, n);
1088
+ else {
1089
+ const i = P(t, "", s);
1090
+ if (e instanceof Map)
1091
+ e.set(i, P(n, i, s));
1092
+ else if (e instanceof Set)
1093
+ e.add(i);
1094
+ else {
1095
+ const r = Ms(t, i, s), o = P(n, r, s);
1096
+ r in e ? Object.defineProperty(e, r, {
1097
+ value: o,
1098
+ writable: !0,
1099
+ enumerable: !0,
1100
+ configurable: !0
1101
+ }) : e[r] = o;
1102
+ }
1103
+ }
1104
+ return e;
1105
+ }
1106
+ function Ms(s, e, t) {
1107
+ if (e === null)
1108
+ return "";
1109
+ if (typeof e != "object")
1110
+ return String(e);
1111
+ if (L(s) && t?.doc) {
1112
+ const n = Dt(t.doc, {});
1113
+ n.anchors = /* @__PURE__ */ new Set();
1114
+ for (const r of t.anchors.keys())
1115
+ n.anchors.add(r.anchor);
1116
+ n.inFlow = !0, n.inStringifyKey = !0;
1117
+ const i = s.toString(n);
1118
+ if (!t.mapKeyWarned) {
1119
+ let r = JSON.stringify(i);
1120
+ r.length > 40 && (r = r.substring(0, 36) + '..."'), qt(t.doc.options.logLevel, `Keys with collection values will be stringified due to JS Object restrictions: ${r}. Set mapAsMap: true to use object keys.`), t.mapKeyWarned = !0;
1121
+ }
1122
+ return i;
1123
+ }
1124
+ return JSON.stringify(e);
1125
+ }
1126
+ function rt(s, e, t) {
1127
+ const n = me(s, void 0, t), i = me(e, void 0, t);
1128
+ return new B(n, i);
1129
+ }
1130
+ class B {
1131
+ constructor(e, t = null) {
1132
+ Object.defineProperty(this, j, { value: vt }), this.key = e, this.value = t;
1133
+ }
1134
+ clone(e) {
1135
+ let { key: t, value: n } = this;
1136
+ return L(t) && (t = t.clone(e)), L(n) && (n = n.clone(e)), new B(t, n);
1137
+ }
1138
+ toJSON(e, t) {
1139
+ const n = t?.mapAsMap ? /* @__PURE__ */ new Map() : {};
1140
+ return Ft(t, n, this);
1141
+ }
1142
+ toString(e, t, n) {
1143
+ return e?.doc ? _s(this, e, t, n) : JSON.stringify(this);
1144
+ }
1145
+ }
1146
+ function Rt(s, e, t) {
1147
+ return (e.inFlow ?? s.flow ? js : Ps)(s, e, t);
1148
+ }
1149
+ function Ps({ comment: s, items: e }, t, { blockItemPrefix: n, flowChars: i, itemIndent: r, onChompKeep: o, onComment: l }) {
1150
+ const { indent: a, options: { commentString: c } } = t, d = Object.assign({}, t, { indent: r, type: null });
1151
+ let f = !1;
1152
+ const u = [];
1153
+ for (let g = 0; g < e.length; ++g) {
1154
+ const h = e[g];
1155
+ let p = null;
1156
+ if (L(h))
1157
+ !f && h.spaceBefore && u.push(""), ve(t, u, h.commentBefore, f), h.comment && (p = h.comment);
1158
+ else if ($(h)) {
1159
+ const w = L(h.key) ? h.key : null;
1160
+ w && (!f && w.spaceBefore && u.push(""), ve(t, u, w.commentBefore, f));
1161
+ }
1162
+ f = !1;
1163
+ let b = ie(h, d, () => p = null, () => f = !0);
1164
+ p && (b += G(b, r, c(p))), f && p && (f = !1), u.push(n + b);
1165
+ }
1166
+ let m;
1167
+ if (u.length === 0)
1168
+ m = i.start + i.end;
1169
+ else {
1170
+ m = u[0];
1171
+ for (let g = 1; g < u.length; ++g) {
1172
+ const h = u[g];
1173
+ m += h ? `
1174
+ ${a}${h}` : `
1175
+ `;
1176
+ }
1177
+ }
1178
+ return s ? (m += `
1179
+ ` + U(c(s), a), l && l()) : f && o && o(), m;
1180
+ }
1181
+ function js({ items: s }, e, { flowChars: t, itemIndent: n }) {
1182
+ const { indent: i, indentStep: r, flowCollectionPadding: o, options: { commentString: l } } = e;
1183
+ n += r;
1184
+ const a = Object.assign({}, e, {
1185
+ indent: n,
1186
+ inFlow: !0,
1187
+ type: null
1188
+ });
1189
+ let c = !1, d = 0;
1190
+ const f = [];
1191
+ for (let g = 0; g < s.length; ++g) {
1192
+ const h = s[g];
1193
+ let p = null;
1194
+ if (L(h))
1195
+ h.spaceBefore && f.push(""), ve(e, f, h.commentBefore, !1), h.comment && (p = h.comment);
1196
+ else if ($(h)) {
1197
+ const w = L(h.key) ? h.key : null;
1198
+ w && (w.spaceBefore && f.push(""), ve(e, f, w.commentBefore, !1), w.comment && (c = !0));
1199
+ const k = L(h.value) ? h.value : null;
1200
+ k ? (k.comment && (p = k.comment), k.commentBefore && (c = !0)) : h.value == null && w?.comment && (p = w.comment);
1201
+ }
1202
+ p && (c = !0);
1203
+ let b = ie(h, a, () => p = null);
1204
+ g < s.length - 1 && (b += ","), p && (b += G(b, n, l(p))), !c && (f.length > d || b.includes(`
1205
+ `)) && (c = !0), f.push(b), d = f.length;
1206
+ }
1207
+ const { start: u, end: m } = t;
1208
+ if (f.length === 0)
1209
+ return u + m;
1210
+ if (!c) {
1211
+ const g = f.reduce((h, p) => h + p.length + 2, 2);
1212
+ c = e.options.lineWidth > 0 && g > e.options.lineWidth;
1213
+ }
1214
+ if (c) {
1215
+ let g = u;
1216
+ for (const h of f)
1217
+ g += h ? `
1218
+ ${r}${i}${h}` : `
1219
+ `;
1220
+ return `${g}
1221
+ ${i}${m}`;
1222
+ } else
1223
+ return `${u}${o}${f.join(" ")}${o}${m}`;
1224
+ }
1225
+ function ve({ indent: s, options: { commentString: e } }, t, n, i) {
1226
+ if (n && i && (n = n.replace(/^\n+/, "")), n) {
1227
+ const r = U(e(n), s);
1228
+ t.push(r.trimStart());
1229
+ }
1230
+ }
1231
+ function H(s, e) {
1232
+ const t = E(e) ? e.value : e;
1233
+ for (const n of s)
1234
+ if ($(n) && (n.key === e || n.key === t || E(n.key) && n.key.value === t))
1235
+ return n;
1236
+ }
1237
+ class M extends jt {
1238
+ static get tagName() {
1239
+ return "tag:yaml.org,2002:map";
1240
+ }
1241
+ constructor(e) {
1242
+ super(J, e), this.items = [];
1243
+ }
1244
+ /**
1245
+ * A generic collection parsing method that can be extended
1246
+ * to other node classes that inherit from YAMLMap
1247
+ */
1248
+ static from(e, t, n) {
1249
+ const { keepUndefined: i, replacer: r } = n, o = new this(e), l = (a, c) => {
1250
+ if (typeof r == "function")
1251
+ c = r.call(t, a, c);
1252
+ else if (Array.isArray(r) && !r.includes(a))
1253
+ return;
1254
+ (c !== void 0 || i) && o.items.push(rt(a, c, n));
1255
+ };
1256
+ if (t instanceof Map)
1257
+ for (const [a, c] of t)
1258
+ l(a, c);
1259
+ else if (t && typeof t == "object")
1260
+ for (const a of Object.keys(t))
1261
+ l(a, t[a]);
1262
+ return typeof e.sortMapEntries == "function" && o.items.sort(e.sortMapEntries), o;
1263
+ }
1264
+ /**
1265
+ * Adds a value to the collection.
1266
+ *
1267
+ * @param overwrite - If not set `true`, using a key that is already in the
1268
+ * collection will throw. Otherwise, overwrites the previous value.
1269
+ */
1270
+ add(e, t) {
1271
+ let n;
1272
+ $(e) ? n = e : !e || typeof e != "object" || !("key" in e) ? n = new B(e, e?.value) : n = new B(e.key, e.value);
1273
+ const i = H(this.items, n.key), r = this.schema?.sortMapEntries;
1274
+ if (i) {
1275
+ if (!t)
1276
+ throw new Error(`Key ${n.key} already set`);
1277
+ E(i.value) && Pt(n.value) ? i.value.value = n.value : i.value = n.value;
1278
+ } else if (r) {
1279
+ const o = this.items.findIndex((l) => r(n, l) < 0);
1280
+ o === -1 ? this.items.push(n) : this.items.splice(o, 0, n);
1281
+ } else
1282
+ this.items.push(n);
1283
+ }
1284
+ delete(e) {
1285
+ const t = H(this.items, e);
1286
+ return t ? this.items.splice(this.items.indexOf(t), 1).length > 0 : !1;
1287
+ }
1288
+ get(e, t) {
1289
+ const i = H(this.items, e)?.value;
1290
+ return (!t && E(i) ? i.value : i) ?? void 0;
1291
+ }
1292
+ has(e) {
1293
+ return !!H(this.items, e);
1294
+ }
1295
+ set(e, t) {
1296
+ this.add(new B(e, t), !0);
1297
+ }
1298
+ /**
1299
+ * @param ctx - Conversion context, originally set in Document#toJS()
1300
+ * @param {Class} Type - If set, forces the returned collection type
1301
+ * @returns Instance of Type, Map, or Object
1302
+ */
1303
+ toJSON(e, t, n) {
1304
+ const i = n ? new n() : t?.mapAsMap ? /* @__PURE__ */ new Map() : {};
1305
+ t?.onCreate && t.onCreate(i);
1306
+ for (const r of this.items)
1307
+ Ft(t, i, r);
1308
+ return i;
1309
+ }
1310
+ toString(e, t, n) {
1311
+ if (!e)
1312
+ return JSON.stringify(this);
1313
+ for (const i of this.items)
1314
+ if (!$(i))
1315
+ throw new Error(`Map items must all be pairs; found ${JSON.stringify(i)} instead`);
1316
+ return !e.allNullValues && this.hasAllNullValues(!1) && (e = Object.assign({}, e, { allNullValues: !0 })), Rt(this, e, {
1317
+ blockItemPrefix: "",
1318
+ flowChars: { start: "{", end: "}" },
1319
+ itemIndent: e.indent || "",
1320
+ onChompKeep: n,
1321
+ onComment: t
1322
+ });
1323
+ }
1324
+ }
1325
+ const ae = {
1326
+ collection: "map",
1327
+ default: !0,
1328
+ nodeClass: M,
1329
+ tag: "tag:yaml.org,2002:map",
1330
+ resolve(s, e) {
1331
+ return ye(s) || e("Expected a mapping for this tag"), s;
1332
+ },
1333
+ createNode: (s, e, t) => M.from(s, e, t)
1334
+ };
1335
+ class W extends jt {
1336
+ static get tagName() {
1337
+ return "tag:yaml.org,2002:seq";
1338
+ }
1339
+ constructor(e) {
1340
+ super(oe, e), this.items = [];
1341
+ }
1342
+ add(e) {
1343
+ this.items.push(e);
1344
+ }
1345
+ /**
1346
+ * Removes a value from the collection.
1347
+ *
1348
+ * `key` must contain a representation of an integer for this to succeed.
1349
+ * It may be wrapped in a `Scalar`.
1350
+ *
1351
+ * @returns `true` if the item was found and removed.
1352
+ */
1353
+ delete(e) {
1354
+ const t = Ne(e);
1355
+ return typeof t != "number" ? !1 : this.items.splice(t, 1).length > 0;
1356
+ }
1357
+ get(e, t) {
1358
+ const n = Ne(e);
1359
+ if (typeof n != "number")
1360
+ return;
1361
+ const i = this.items[n];
1362
+ return !t && E(i) ? i.value : i;
1363
+ }
1364
+ /**
1365
+ * Checks if the collection includes a value with the key `key`.
1366
+ *
1367
+ * `key` must contain a representation of an integer for this to succeed.
1368
+ * It may be wrapped in a `Scalar`.
1369
+ */
1370
+ has(e) {
1371
+ const t = Ne(e);
1372
+ return typeof t == "number" && t < this.items.length;
1373
+ }
1374
+ /**
1375
+ * Sets a value in this collection. For `!!set`, `value` needs to be a
1376
+ * boolean to add/remove the item from the set.
1377
+ *
1378
+ * If `key` does not contain a representation of an integer, this will throw.
1379
+ * It may be wrapped in a `Scalar`.
1380
+ */
1381
+ set(e, t) {
1382
+ const n = Ne(e);
1383
+ if (typeof n != "number")
1384
+ throw new Error(`Expected a valid index, not ${e}.`);
1385
+ const i = this.items[n];
1386
+ E(i) && Pt(t) ? i.value = t : this.items[n] = t;
1387
+ }
1388
+ toJSON(e, t) {
1389
+ const n = [];
1390
+ t?.onCreate && t.onCreate(n);
1391
+ let i = 0;
1392
+ for (const r of this.items)
1393
+ n.push(P(r, String(i++), t));
1394
+ return n;
1395
+ }
1396
+ toString(e, t, n) {
1397
+ return e ? Rt(this, e, {
1398
+ blockItemPrefix: "- ",
1399
+ flowChars: { start: "[", end: "]" },
1400
+ itemIndent: (e.indent || "") + " ",
1401
+ onChompKeep: n,
1402
+ onComment: t
1403
+ }) : JSON.stringify(this);
1404
+ }
1405
+ static from(e, t, n) {
1406
+ const { replacer: i } = n, r = new this(e);
1407
+ if (t && Symbol.iterator in Object(t)) {
1408
+ let o = 0;
1409
+ for (let l of t) {
1410
+ if (typeof i == "function") {
1411
+ const a = t instanceof Set ? l : String(o++);
1412
+ l = i.call(t, a, l);
1413
+ }
1414
+ r.items.push(me(l, void 0, n));
1415
+ }
1416
+ }
1417
+ return r;
1418
+ }
1419
+ }
1420
+ function Ne(s) {
1421
+ let e = E(s) ? s.value : s;
1422
+ return e && typeof e == "string" && (e = Number(e)), typeof e == "number" && Number.isInteger(e) && e >= 0 ? e : null;
1423
+ }
1424
+ const ce = {
1425
+ collection: "seq",
1426
+ default: !0,
1427
+ nodeClass: W,
1428
+ tag: "tag:yaml.org,2002:seq",
1429
+ resolve(s, e) {
1430
+ return be(s) || e("Expected a sequence for this tag"), s;
1431
+ },
1432
+ createNode: (s, e, t) => W.from(s, e, t)
1433
+ }, Pe = {
1434
+ identify: (s) => typeof s == "string",
1435
+ default: !0,
1436
+ tag: "tag:yaml.org,2002:str",
1437
+ resolve: (s) => s,
1438
+ stringify(s, e, t, n) {
1439
+ return e = Object.assign({ actualString: !0 }, e), it(s, e, t, n);
1440
+ }
1441
+ }, je = {
1442
+ identify: (s) => s == null,
1443
+ createNode: () => new O(null),
1444
+ default: !0,
1445
+ tag: "tag:yaml.org,2002:null",
1446
+ test: /^(?:~|[Nn]ull|NULL)?$/,
1447
+ resolve: () => new O(null),
1448
+ stringify: ({ source: s }, e) => typeof s == "string" && je.test.test(s) ? s : e.options.nullStr
1449
+ }, ot = {
1450
+ identify: (s) => typeof s == "boolean",
1451
+ default: !0,
1452
+ tag: "tag:yaml.org,2002:bool",
1453
+ test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
1454
+ resolve: (s) => new O(s[0] === "t" || s[0] === "T"),
1455
+ stringify({ source: s, value: e }, t) {
1456
+ if (s && ot.test.test(s)) {
1457
+ const n = s[0] === "t" || s[0] === "T";
1458
+ if (e === n)
1459
+ return s;
1460
+ }
1461
+ return e ? t.options.trueStr : t.options.falseStr;
1462
+ }
1463
+ };
1464
+ function D({ format: s, minFractionDigits: e, tag: t, value: n }) {
1465
+ if (typeof n == "bigint")
1466
+ return String(n);
1467
+ const i = typeof n == "number" ? n : Number(n);
1468
+ if (!isFinite(i))
1469
+ return isNaN(i) ? ".nan" : i < 0 ? "-.inf" : ".inf";
1470
+ let r = Object.is(n, -0) ? "-0" : JSON.stringify(n);
1471
+ if (!s && e && (!t || t === "tag:yaml.org,2002:float") && /^\d/.test(r)) {
1472
+ let o = r.indexOf(".");
1473
+ o < 0 && (o = r.length, r += ".");
1474
+ let l = e - (r.length - o - 1);
1475
+ for (; l-- > 0; )
1476
+ r += "0";
1477
+ }
1478
+ return r;
1479
+ }
1480
+ const Vt = {
1481
+ identify: (s) => typeof s == "number",
1482
+ default: !0,
1483
+ tag: "tag:yaml.org,2002:float",
1484
+ test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
1485
+ resolve: (s) => s.slice(-3).toLowerCase() === "nan" ? NaN : s[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
1486
+ stringify: D
1487
+ }, Jt = {
1488
+ identify: (s) => typeof s == "number",
1489
+ default: !0,
1490
+ tag: "tag:yaml.org,2002:float",
1491
+ format: "EXP",
1492
+ test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
1493
+ resolve: (s) => parseFloat(s),
1494
+ stringify(s) {
1495
+ const e = Number(s.value);
1496
+ return isFinite(e) ? e.toExponential() : D(s);
1497
+ }
1498
+ }, Yt = {
1499
+ identify: (s) => typeof s == "number",
1500
+ default: !0,
1501
+ tag: "tag:yaml.org,2002:float",
1502
+ test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
1503
+ resolve(s) {
1504
+ const e = new O(parseFloat(s)), t = s.indexOf(".");
1505
+ return t !== -1 && s[s.length - 1] === "0" && (e.minFractionDigits = s.length - t - 1), e;
1506
+ },
1507
+ stringify: D
1508
+ }, Ke = (s) => typeof s == "bigint" || Number.isInteger(s), lt = (s, e, t, { intAsBigInt: n }) => n ? BigInt(s) : parseInt(s.substring(e), t);
1509
+ function Gt(s, e, t) {
1510
+ const { value: n } = s;
1511
+ return Ke(n) && n >= 0 ? t + n.toString(e) : D(s);
1512
+ }
1513
+ const Ht = {
1514
+ identify: (s) => Ke(s) && s >= 0,
1515
+ default: !0,
1516
+ tag: "tag:yaml.org,2002:int",
1517
+ format: "OCT",
1518
+ test: /^0o[0-7]+$/,
1519
+ resolve: (s, e, t) => lt(s, 2, 8, t),
1520
+ stringify: (s) => Gt(s, 8, "0o")
1521
+ }, Wt = {
1522
+ identify: Ke,
1523
+ default: !0,
1524
+ tag: "tag:yaml.org,2002:int",
1525
+ test: /^[-+]?[0-9]+$/,
1526
+ resolve: (s, e, t) => lt(s, 0, 10, t),
1527
+ stringify: D
1528
+ }, Qt = {
1529
+ identify: (s) => Ke(s) && s >= 0,
1530
+ default: !0,
1531
+ tag: "tag:yaml.org,2002:int",
1532
+ format: "HEX",
1533
+ test: /^0x[0-9a-fA-F]+$/,
1534
+ resolve: (s, e, t) => lt(s, 2, 16, t),
1535
+ stringify: (s) => Gt(s, 16, "0x")
1536
+ }, Ks = [
1537
+ ae,
1538
+ ce,
1539
+ Pe,
1540
+ je,
1541
+ ot,
1542
+ Ht,
1543
+ Wt,
1544
+ Qt,
1545
+ Vt,
1546
+ Jt,
1547
+ Yt
1548
+ ];
1549
+ function kt(s) {
1550
+ return typeof s == "bigint" || Number.isInteger(s);
1551
+ }
1552
+ const Oe = ({ value: s }) => JSON.stringify(s), Ds = [
1553
+ {
1554
+ identify: (s) => typeof s == "string",
1555
+ default: !0,
1556
+ tag: "tag:yaml.org,2002:str",
1557
+ resolve: (s) => s,
1558
+ stringify: Oe
1559
+ },
1560
+ {
1561
+ identify: (s) => s == null,
1562
+ createNode: () => new O(null),
1563
+ default: !0,
1564
+ tag: "tag:yaml.org,2002:null",
1565
+ test: /^null$/,
1566
+ resolve: () => null,
1567
+ stringify: Oe
1568
+ },
1569
+ {
1570
+ identify: (s) => typeof s == "boolean",
1571
+ default: !0,
1572
+ tag: "tag:yaml.org,2002:bool",
1573
+ test: /^true$|^false$/,
1574
+ resolve: (s) => s === "true",
1575
+ stringify: Oe
1576
+ },
1577
+ {
1578
+ identify: kt,
1579
+ default: !0,
1580
+ tag: "tag:yaml.org,2002:int",
1581
+ test: /^-?(?:0|[1-9][0-9]*)$/,
1582
+ resolve: (s, e, { intAsBigInt: t }) => t ? BigInt(s) : parseInt(s, 10),
1583
+ stringify: ({ value: s }) => kt(s) ? s.toString() : JSON.stringify(s)
1584
+ },
1585
+ {
1586
+ identify: (s) => typeof s == "number",
1587
+ default: !0,
1588
+ tag: "tag:yaml.org,2002:float",
1589
+ test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
1590
+ resolve: (s) => parseFloat(s),
1591
+ stringify: Oe
1592
+ }
1593
+ ], qs = {
1594
+ default: !0,
1595
+ tag: "",
1596
+ test: /^/,
1597
+ resolve(s, e) {
1598
+ return e(`Unresolved plain scalar ${JSON.stringify(s)}`), s;
1599
+ }
1600
+ }, Us = [ae, ce].concat(Ds, qs), at = {
1601
+ identify: (s) => s instanceof Uint8Array,
1602
+ // Buffer inherits from Uint8Array
1603
+ default: !1,
1604
+ tag: "tag:yaml.org,2002:binary",
1605
+ /**
1606
+ * Returns a Buffer in node and an Uint8Array in browsers
1607
+ *
1608
+ * To use the resulting buffer as an image, you'll want to do something like:
1609
+ *
1610
+ * const blob = new Blob([buffer], { type: 'image/jpeg' })
1611
+ * document.querySelector('#photo').src = URL.createObjectURL(blob)
1612
+ */
1613
+ resolve(s, e) {
1614
+ if (typeof atob == "function") {
1615
+ const t = atob(s.replace(/[\n\r]/g, "")), n = new Uint8Array(t.length);
1616
+ for (let i = 0; i < t.length; ++i)
1617
+ n[i] = t.charCodeAt(i);
1618
+ return n;
1619
+ } else
1620
+ return e("This environment does not support reading binary tags; either Buffer or atob is required"), s;
1621
+ },
1622
+ stringify({ comment: s, type: e, value: t }, n, i, r) {
1623
+ if (!t)
1624
+ return "";
1625
+ const o = t;
1626
+ let l;
1627
+ if (typeof btoa == "function") {
1628
+ let a = "";
1629
+ for (let c = 0; c < o.length; ++c)
1630
+ a += String.fromCharCode(o[c]);
1631
+ l = btoa(a);
1632
+ } else
1633
+ throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");
1634
+ if (e ?? (e = O.BLOCK_LITERAL), e !== O.QUOTE_DOUBLE) {
1635
+ const a = Math.max(n.options.lineWidth - n.indent.length, n.options.minContentWidth), c = Math.ceil(l.length / a), d = new Array(c);
1636
+ for (let f = 0, u = 0; f < c; ++f, u += a)
1637
+ d[f] = l.substr(u, a);
1638
+ l = d.join(e === O.BLOCK_LITERAL ? `
1639
+ ` : " ");
1640
+ }
1641
+ return it({ comment: s, type: e, value: l }, n, i, r);
1642
+ }
1643
+ };
1644
+ function Xt(s, e) {
1645
+ if (be(s))
1646
+ for (let t = 0; t < s.items.length; ++t) {
1647
+ let n = s.items[t];
1648
+ if (!$(n)) {
1649
+ if (ye(n)) {
1650
+ n.items.length > 1 && e("Each pair must have its own sequence indicator");
1651
+ const i = n.items[0] || new B(new O(null));
1652
+ if (n.commentBefore && (i.key.commentBefore = i.key.commentBefore ? `${n.commentBefore}
1653
+ ${i.key.commentBefore}` : n.commentBefore), n.comment) {
1654
+ const r = i.value ?? i.key;
1655
+ r.comment = r.comment ? `${n.comment}
1656
+ ${r.comment}` : n.comment;
1657
+ }
1658
+ n = i;
1659
+ }
1660
+ s.items[t] = $(n) ? n : new B(n);
1661
+ }
1662
+ }
1663
+ else
1664
+ e("Expected a sequence for this tag");
1665
+ return s;
1666
+ }
1667
+ function xt(s, e, t) {
1668
+ const { replacer: n } = t, i = new W(s);
1669
+ i.tag = "tag:yaml.org,2002:pairs";
1670
+ let r = 0;
1671
+ if (e && Symbol.iterator in Object(e))
1672
+ for (let o of e) {
1673
+ typeof n == "function" && (o = n.call(e, String(r++), o));
1674
+ let l, a;
1675
+ if (Array.isArray(o))
1676
+ if (o.length === 2)
1677
+ l = o[0], a = o[1];
1678
+ else
1679
+ throw new TypeError(`Expected [key, value] tuple: ${o}`);
1680
+ else if (o && o instanceof Object) {
1681
+ const c = Object.keys(o);
1682
+ if (c.length === 1)
1683
+ l = c[0], a = o[l];
1684
+ else
1685
+ throw new TypeError(`Expected tuple with one key, not ${c.length} keys`);
1686
+ } else
1687
+ l = o;
1688
+ i.items.push(rt(l, a, t));
1689
+ }
1690
+ return i;
1691
+ }
1692
+ const ct = {
1693
+ collection: "seq",
1694
+ default: !1,
1695
+ tag: "tag:yaml.org,2002:pairs",
1696
+ resolve: Xt,
1697
+ createNode: xt
1698
+ };
1699
+ class se extends W {
1700
+ constructor() {
1701
+ super(), this.add = M.prototype.add.bind(this), this.delete = M.prototype.delete.bind(this), this.get = M.prototype.get.bind(this), this.has = M.prototype.has.bind(this), this.set = M.prototype.set.bind(this), this.tag = se.tag;
1702
+ }
1703
+ /**
1704
+ * If `ctx` is given, the return type is actually `Map<unknown, unknown>`,
1705
+ * but TypeScript won't allow widening the signature of a child method.
1706
+ */
1707
+ toJSON(e, t) {
1708
+ if (!t)
1709
+ return super.toJSON(e);
1710
+ const n = /* @__PURE__ */ new Map();
1711
+ t?.onCreate && t.onCreate(n);
1712
+ for (const i of this.items) {
1713
+ let r, o;
1714
+ if ($(i) ? (r = P(i.key, "", t), o = P(i.value, r, t)) : r = P(i, "", t), n.has(r))
1715
+ throw new Error("Ordered maps must not include duplicate keys");
1716
+ n.set(r, o);
1717
+ }
1718
+ return n;
1719
+ }
1720
+ static from(e, t, n) {
1721
+ const i = xt(e, t, n), r = new this();
1722
+ return r.items = i.items, r;
1723
+ }
1724
+ }
1725
+ se.tag = "tag:yaml.org,2002:omap";
1726
+ const ft = {
1727
+ collection: "seq",
1728
+ identify: (s) => s instanceof Map,
1729
+ nodeClass: se,
1730
+ default: !1,
1731
+ tag: "tag:yaml.org,2002:omap",
1732
+ resolve(s, e) {
1733
+ const t = Xt(s, e), n = [];
1734
+ for (const { key: i } of t.items)
1735
+ E(i) && (n.includes(i.value) ? e(`Ordered maps must not include duplicate keys: ${i.value}`) : n.push(i.value));
1736
+ return Object.assign(new se(), t);
1737
+ },
1738
+ createNode: (s, e, t) => se.from(s, e, t)
1739
+ };
1740
+ function zt({ value: s, source: e }, t) {
1741
+ return e && (s ? Zt : es).test.test(e) ? e : s ? t.options.trueStr : t.options.falseStr;
1742
+ }
1743
+ const Zt = {
1744
+ identify: (s) => s === !0,
1745
+ default: !0,
1746
+ tag: "tag:yaml.org,2002:bool",
1747
+ test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
1748
+ resolve: () => new O(!0),
1749
+ stringify: zt
1750
+ }, es = {
1751
+ identify: (s) => s === !1,
1752
+ default: !0,
1753
+ tag: "tag:yaml.org,2002:bool",
1754
+ test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
1755
+ resolve: () => new O(!1),
1756
+ stringify: zt
1757
+ }, Fs = {
1758
+ identify: (s) => typeof s == "number",
1759
+ default: !0,
1760
+ tag: "tag:yaml.org,2002:float",
1761
+ test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
1762
+ resolve: (s) => s.slice(-3).toLowerCase() === "nan" ? NaN : s[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
1763
+ stringify: D
1764
+ }, Rs = {
1765
+ identify: (s) => typeof s == "number",
1766
+ default: !0,
1767
+ tag: "tag:yaml.org,2002:float",
1768
+ format: "EXP",
1769
+ test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
1770
+ resolve: (s) => parseFloat(s.replace(/_/g, "")),
1771
+ stringify(s) {
1772
+ const e = Number(s.value);
1773
+ return isFinite(e) ? e.toExponential() : D(s);
1774
+ }
1775
+ }, Vs = {
1776
+ identify: (s) => typeof s == "number",
1777
+ default: !0,
1778
+ tag: "tag:yaml.org,2002:float",
1779
+ test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
1780
+ resolve(s) {
1781
+ const e = new O(parseFloat(s.replace(/_/g, ""))), t = s.indexOf(".");
1782
+ if (t !== -1) {
1783
+ const n = s.substring(t + 1).replace(/_/g, "");
1784
+ n[n.length - 1] === "0" && (e.minFractionDigits = n.length);
1785
+ }
1786
+ return e;
1787
+ },
1788
+ stringify: D
1789
+ }, we = (s) => typeof s == "bigint" || Number.isInteger(s);
1790
+ function De(s, e, t, { intAsBigInt: n }) {
1791
+ const i = s[0];
1792
+ if ((i === "-" || i === "+") && (e += 1), s = s.substring(e).replace(/_/g, ""), n) {
1793
+ switch (t) {
1794
+ case 2:
1795
+ s = `0b${s}`;
1796
+ break;
1797
+ case 8:
1798
+ s = `0o${s}`;
1799
+ break;
1800
+ case 16:
1801
+ s = `0x${s}`;
1802
+ break;
1803
+ }
1804
+ const o = BigInt(s);
1805
+ return i === "-" ? BigInt(-1) * o : o;
1806
+ }
1807
+ const r = parseInt(s, t);
1808
+ return i === "-" ? -1 * r : r;
1809
+ }
1810
+ function ut(s, e, t) {
1811
+ const { value: n } = s;
1812
+ if (we(n)) {
1813
+ const i = n.toString(e);
1814
+ return n < 0 ? "-" + t + i.substr(1) : t + i;
1815
+ }
1816
+ return D(s);
1817
+ }
1818
+ const Js = {
1819
+ identify: we,
1820
+ default: !0,
1821
+ tag: "tag:yaml.org,2002:int",
1822
+ format: "BIN",
1823
+ test: /^[-+]?0b[0-1_]+$/,
1824
+ resolve: (s, e, t) => De(s, 2, 2, t),
1825
+ stringify: (s) => ut(s, 2, "0b")
1826
+ }, Ys = {
1827
+ identify: we,
1828
+ default: !0,
1829
+ tag: "tag:yaml.org,2002:int",
1830
+ format: "OCT",
1831
+ test: /^[-+]?0[0-7_]+$/,
1832
+ resolve: (s, e, t) => De(s, 1, 8, t),
1833
+ stringify: (s) => ut(s, 8, "0")
1834
+ }, Gs = {
1835
+ identify: we,
1836
+ default: !0,
1837
+ tag: "tag:yaml.org,2002:int",
1838
+ test: /^[-+]?[0-9][0-9_]*$/,
1839
+ resolve: (s, e, t) => De(s, 0, 10, t),
1840
+ stringify: D
1841
+ }, Hs = {
1842
+ identify: we,
1843
+ default: !0,
1844
+ tag: "tag:yaml.org,2002:int",
1845
+ format: "HEX",
1846
+ test: /^[-+]?0x[0-9a-fA-F_]+$/,
1847
+ resolve: (s, e, t) => De(s, 2, 16, t),
1848
+ stringify: (s) => ut(s, 16, "0x")
1849
+ };
1850
+ class ne extends M {
1851
+ constructor(e) {
1852
+ super(e), this.tag = ne.tag;
1853
+ }
1854
+ add(e) {
1855
+ let t;
1856
+ $(e) ? t = e : e && typeof e == "object" && "key" in e && "value" in e && e.value === null ? t = new B(e.key, null) : t = new B(e, null), H(this.items, t.key) || this.items.push(t);
1857
+ }
1858
+ /**
1859
+ * If `keepPair` is `true`, returns the Pair matching `key`.
1860
+ * Otherwise, returns the value of that Pair's key.
1861
+ */
1862
+ get(e, t) {
1863
+ const n = H(this.items, e);
1864
+ return !t && $(n) ? E(n.key) ? n.key.value : n.key : n;
1865
+ }
1866
+ set(e, t) {
1867
+ if (typeof t != "boolean")
1868
+ throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof t}`);
1869
+ const n = H(this.items, e);
1870
+ n && !t ? this.items.splice(this.items.indexOf(n), 1) : !n && t && this.items.push(new B(e));
1871
+ }
1872
+ toJSON(e, t) {
1873
+ return super.toJSON(e, t, Set);
1874
+ }
1875
+ toString(e, t, n) {
1876
+ if (!e)
1877
+ return JSON.stringify(this);
1878
+ if (this.hasAllNullValues(!0))
1879
+ return super.toString(Object.assign({}, e, { allNullValues: !0 }), t, n);
1880
+ throw new Error("Set items must all have null values");
1881
+ }
1882
+ static from(e, t, n) {
1883
+ const { replacer: i } = n, r = new this(e);
1884
+ if (t && Symbol.iterator in Object(t))
1885
+ for (let o of t)
1886
+ typeof i == "function" && (o = i.call(t, o, o)), r.items.push(rt(o, null, n));
1887
+ return r;
1888
+ }
1889
+ }
1890
+ ne.tag = "tag:yaml.org,2002:set";
1891
+ const ht = {
1892
+ collection: "map",
1893
+ identify: (s) => s instanceof Set,
1894
+ nodeClass: ne,
1895
+ default: !1,
1896
+ tag: "tag:yaml.org,2002:set",
1897
+ createNode: (s, e, t) => ne.from(s, e, t),
1898
+ resolve(s, e) {
1899
+ if (ye(s)) {
1900
+ if (s.hasAllNullValues(!0))
1901
+ return Object.assign(new ne(), s);
1902
+ e("Set items must all have null values");
1903
+ } else
1904
+ e("Expected a mapping for this tag");
1905
+ return s;
1906
+ }
1907
+ };
1908
+ function dt(s, e) {
1909
+ const t = s[0], n = t === "-" || t === "+" ? s.substring(1) : s, i = (o) => e ? BigInt(o) : Number(o), r = n.replace(/_/g, "").split(":").reduce((o, l) => o * i(60) + i(l), i(0));
1910
+ return t === "-" ? i(-1) * r : r;
1911
+ }
1912
+ function ts(s) {
1913
+ let { value: e } = s, t = (o) => o;
1914
+ if (typeof e == "bigint")
1915
+ t = (o) => BigInt(o);
1916
+ else if (isNaN(e) || !isFinite(e))
1917
+ return D(s);
1918
+ let n = "";
1919
+ e < 0 && (n = "-", e *= t(-1));
1920
+ const i = t(60), r = [e % i];
1921
+ return e < 60 ? r.unshift(0) : (e = (e - r[0]) / i, r.unshift(e % i), e >= 60 && (e = (e - r[0]) / i, r.unshift(e))), n + r.map((o) => String(o).padStart(2, "0")).join(":").replace(/000000\d*$/, "");
1922
+ }
1923
+ const ss = {
1924
+ identify: (s) => typeof s == "bigint" || Number.isInteger(s),
1925
+ default: !0,
1926
+ tag: "tag:yaml.org,2002:int",
1927
+ format: "TIME",
1928
+ test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,
1929
+ resolve: (s, e, { intAsBigInt: t }) => dt(s, t),
1930
+ stringify: ts
1931
+ }, ns = {
1932
+ identify: (s) => typeof s == "number",
1933
+ default: !0,
1934
+ tag: "tag:yaml.org,2002:float",
1935
+ format: "TIME",
1936
+ test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,
1937
+ resolve: (s) => dt(s, !1),
1938
+ stringify: ts
1939
+ }, qe = {
1940
+ identify: (s) => s instanceof Date,
1941
+ default: !0,
1942
+ tag: "tag:yaml.org,2002:timestamp",
1943
+ // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
1944
+ // may be omitted altogether, resulting in a date format. In such a case, the time part is
1945
+ // assumed to be 00:00:00Z (start of day, UTC).
1946
+ test: RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),
1947
+ resolve(s) {
1948
+ const e = s.match(qe.test);
1949
+ if (!e)
1950
+ throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");
1951
+ const [, t, n, i, r, o, l] = e.map(Number), a = e[7] ? Number((e[7] + "00").substr(1, 3)) : 0;
1952
+ let c = Date.UTC(t, n - 1, i, r || 0, o || 0, l || 0, a);
1953
+ const d = e[8];
1954
+ if (d && d !== "Z") {
1955
+ let f = dt(d, !1);
1956
+ Math.abs(f) < 30 && (f *= 60), c -= 6e4 * f;
1957
+ }
1958
+ return new Date(c);
1959
+ },
1960
+ stringify: ({ value: s }) => s?.toISOString().replace(/(T00:00:00)?\.000Z$/, "") ?? ""
1961
+ }, St = [
1962
+ ae,
1963
+ ce,
1964
+ Pe,
1965
+ je,
1966
+ Zt,
1967
+ es,
1968
+ Js,
1969
+ Ys,
1970
+ Gs,
1971
+ Hs,
1972
+ Fs,
1973
+ Rs,
1974
+ Vs,
1975
+ at,
1976
+ F,
1977
+ ft,
1978
+ ct,
1979
+ ht,
1980
+ ss,
1981
+ ns,
1982
+ qe
1983
+ ], Nt = /* @__PURE__ */ new Map([
1984
+ ["core", Ks],
1985
+ ["failsafe", [ae, ce, Pe]],
1986
+ ["json", Us],
1987
+ ["yaml11", St],
1988
+ ["yaml-1.1", St]
1989
+ ]), Ot = {
1990
+ binary: at,
1991
+ bool: ot,
1992
+ float: Yt,
1993
+ floatExp: Jt,
1994
+ floatNaN: Vt,
1995
+ floatTime: ns,
1996
+ int: Wt,
1997
+ intHex: Qt,
1998
+ intOct: Ht,
1999
+ intTime: ss,
2000
+ map: ae,
2001
+ merge: F,
2002
+ null: je,
2003
+ omap: ft,
2004
+ pairs: ct,
2005
+ seq: ce,
2006
+ set: ht,
2007
+ timestamp: qe
2008
+ }, Ws = {
2009
+ "tag:yaml.org,2002:binary": at,
2010
+ "tag:yaml.org,2002:merge": F,
2011
+ "tag:yaml.org,2002:omap": ft,
2012
+ "tag:yaml.org,2002:pairs": ct,
2013
+ "tag:yaml.org,2002:set": ht,
2014
+ "tag:yaml.org,2002:timestamp": qe
2015
+ };
2016
+ function Re(s, e, t) {
2017
+ const n = Nt.get(e);
2018
+ if (n && !s)
2019
+ return t && !n.includes(F) ? n.concat(F) : n.slice();
2020
+ let i = n;
2021
+ if (!i)
2022
+ if (Array.isArray(s))
2023
+ i = [];
2024
+ else {
2025
+ const r = Array.from(Nt.keys()).filter((o) => o !== "yaml11").map((o) => JSON.stringify(o)).join(", ");
2026
+ throw new Error(`Unknown schema "${e}"; use one of ${r} or define customTags array`);
2027
+ }
2028
+ if (Array.isArray(s))
2029
+ for (const r of s)
2030
+ i = i.concat(r);
2031
+ else typeof s == "function" && (i = s(i.slice()));
2032
+ return t && (i = i.concat(F)), i.reduce((r, o) => {
2033
+ const l = typeof o == "string" ? Ot[o] : o;
2034
+ if (!l) {
2035
+ const a = JSON.stringify(o), c = Object.keys(Ot).map((d) => JSON.stringify(d)).join(", ");
2036
+ throw new Error(`Unknown custom tag ${a}; use one of ${c}`);
2037
+ }
2038
+ return r.includes(l) || r.push(l), r;
2039
+ }, []);
2040
+ }
2041
+ const Qs = (s, e) => s.key < e.key ? -1 : s.key > e.key ? 1 : 0;
2042
+ class pt {
2043
+ constructor({ compat: e, customTags: t, merge: n, resolveKnownTags: i, schema: r, sortMapEntries: o, toStringDefaults: l }) {
2044
+ this.compat = Array.isArray(e) ? Re(e, "compat") : e ? Re(null, e) : null, this.name = typeof r == "string" && r || "core", this.knownTags = i ? Ws : {}, this.tags = Re(t, this.name, n), this.toStringOptions = l ?? null, Object.defineProperty(this, J, { value: ae }), Object.defineProperty(this, q, { value: Pe }), Object.defineProperty(this, oe, { value: ce }), this.sortMapEntries = typeof o == "function" ? o : o === !0 ? Qs : null;
2045
+ }
2046
+ clone() {
2047
+ const e = Object.create(pt.prototype, Object.getOwnPropertyDescriptors(this));
2048
+ return e.tags = this.tags.slice(), e;
2049
+ }
2050
+ }
2051
+ function Xs(s, e) {
2052
+ const t = [];
2053
+ let n = e.directives === !0;
2054
+ if (e.directives !== !1 && s.directives) {
2055
+ const a = s.directives.toString(s);
2056
+ a ? (t.push(a), n = !0) : s.directives.docStart && (n = !0);
2057
+ }
2058
+ n && t.push("---");
2059
+ const i = Dt(s, e), { commentString: r } = i.options;
2060
+ if (s.commentBefore) {
2061
+ t.length !== 1 && t.unshift("");
2062
+ const a = r(s.commentBefore);
2063
+ t.unshift(U(a, ""));
2064
+ }
2065
+ let o = !1, l = null;
2066
+ if (s.contents) {
2067
+ if (L(s.contents)) {
2068
+ if (s.contents.spaceBefore && n && t.push(""), s.contents.commentBefore) {
2069
+ const d = r(s.contents.commentBefore);
2070
+ t.push(U(d, ""));
2071
+ }
2072
+ i.forceBlockIndent = !!s.comment, l = s.contents.comment;
2073
+ }
2074
+ const a = l ? void 0 : () => o = !0;
2075
+ let c = ie(s.contents, i, () => l = null, a);
2076
+ l && (c += G(c, "", r(l))), (c[0] === "|" || c[0] === ">") && t[t.length - 1] === "---" ? t[t.length - 1] = `--- ${c}` : t.push(c);
2077
+ } else
2078
+ t.push(ie(s.contents, i));
2079
+ if (s.directives?.docEnd)
2080
+ if (s.comment) {
2081
+ const a = r(s.comment);
2082
+ a.includes(`
2083
+ `) ? (t.push("..."), t.push(U(a, ""))) : t.push(`... ${a}`);
2084
+ } else
2085
+ t.push("...");
2086
+ else {
2087
+ let a = s.comment;
2088
+ a && o && (a = a.replace(/^\n+/, "")), a && ((!o || l) && t[t.length - 1] !== "" && t.push(""), t.push(U(r(a), "")));
2089
+ }
2090
+ return t.join(`
2091
+ `) + `
2092
+ `;
2093
+ }
2094
+ class Ue {
2095
+ constructor(e, t, n) {
2096
+ this.commentBefore = null, this.comment = null, this.errors = [], this.warnings = [], Object.defineProperty(this, j, { value: We });
2097
+ let i = null;
2098
+ typeof t == "function" || Array.isArray(t) ? i = t : n === void 0 && t && (n = t, t = void 0);
2099
+ const r = Object.assign({
2100
+ intAsBigInt: !1,
2101
+ keepSourceTokens: !1,
2102
+ logLevel: "warn",
2103
+ prettyErrors: !0,
2104
+ strict: !0,
2105
+ stringKeys: !1,
2106
+ uniqueKeys: !0,
2107
+ version: "1.2"
2108
+ }, n);
2109
+ this.options = r;
2110
+ let { version: o } = r;
2111
+ n?._directives ? (this.directives = n._directives.atDocument(), this.directives.yaml.explicit && (o = this.directives.yaml.version)) : this.directives = new _({ version: o }), this.setSchema(o, n), this.contents = e === void 0 ? null : this.createNode(e, i, n);
2112
+ }
2113
+ /**
2114
+ * Create a deep copy of this Document and its contents.
2115
+ *
2116
+ * Custom Node values that inherit from `Object` still refer to their original instances.
2117
+ */
2118
+ clone() {
2119
+ const e = Object.create(Ue.prototype, {
2120
+ [j]: { value: We }
2121
+ });
2122
+ return e.commentBefore = this.commentBefore, e.comment = this.comment, e.errors = this.errors.slice(), e.warnings = this.warnings.slice(), e.options = Object.assign({}, this.options), this.directives && (e.directives = this.directives.clone()), e.schema = this.schema.clone(), e.contents = L(this.contents) ? this.contents.clone(e.schema) : this.contents, this.range && (e.range = this.range.slice()), e;
2123
+ }
2124
+ /** Adds a value to the document. */
2125
+ add(e) {
2126
+ x(this.contents) && this.contents.add(e);
2127
+ }
2128
+ /** Adds a value to the document. */
2129
+ addIn(e, t) {
2130
+ x(this.contents) && this.contents.addIn(e, t);
2131
+ }
2132
+ /**
2133
+ * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
2134
+ *
2135
+ * If `node` already has an anchor, `name` is ignored.
2136
+ * Otherwise, the `node.anchor` value will be set to `name`,
2137
+ * or if an anchor with that name is already present in the document,
2138
+ * `name` will be used as a prefix for a new unique anchor.
2139
+ * If `name` is undefined, the generated anchor will use 'a' as a prefix.
2140
+ */
2141
+ createAlias(e, t) {
2142
+ if (!e.anchor) {
2143
+ const n = Bt(this);
2144
+ e.anchor = // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
2145
+ !t || n.has(t) ? Mt(t || "a", n) : t;
2146
+ }
2147
+ return new nt(e.anchor);
2148
+ }
2149
+ createNode(e, t, n) {
2150
+ let i;
2151
+ if (typeof t == "function")
2152
+ e = t.call({ "": e }, "", e), i = t;
2153
+ else if (Array.isArray(t)) {
2154
+ const p = (w) => typeof w == "number" || w instanceof String || w instanceof Number, b = t.filter(p).map(String);
2155
+ b.length > 0 && (t = t.concat(b)), i = t;
2156
+ } else n === void 0 && t && (n = t, t = void 0);
2157
+ const { aliasDuplicateObjects: r, anchorPrefix: o, flow: l, keepUndefined: a, onTagObj: c, tag: d } = n ?? {}, { onAnchor: f, setAnchors: u, sourceObjects: m } = As(
2158
+ this,
2159
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
2160
+ o || "a"
2161
+ ), g = {
2162
+ aliasDuplicateObjects: r ?? !0,
2163
+ keepUndefined: a ?? !1,
2164
+ onAnchor: f,
2165
+ onTagObj: c,
2166
+ replacer: i,
2167
+ schema: this.schema,
2168
+ sourceObjects: m
2169
+ }, h = me(e, d, g);
2170
+ return l && I(h) && (h.flow = !0), u(), h;
2171
+ }
2172
+ /**
2173
+ * Convert a key and a value into a `Pair` using the current schema,
2174
+ * recursively wrapping all values as `Scalar` or `Collection` nodes.
2175
+ */
2176
+ createPair(e, t, n = {}) {
2177
+ const i = this.createNode(e, null, n), r = this.createNode(t, null, n);
2178
+ return new B(i, r);
2179
+ }
2180
+ /**
2181
+ * Removes a value from the document.
2182
+ * @returns `true` if the item was found and removed.
2183
+ */
2184
+ delete(e) {
2185
+ return x(this.contents) ? this.contents.delete(e) : !1;
2186
+ }
2187
+ /**
2188
+ * Removes a value from the document.
2189
+ * @returns `true` if the item was found and removed.
2190
+ */
2191
+ deleteIn(e) {
2192
+ return ue(e) ? this.contents == null ? !1 : (this.contents = null, !0) : x(this.contents) ? this.contents.deleteIn(e) : !1;
2193
+ }
2194
+ /**
2195
+ * Returns item at `key`, or `undefined` if not found. By default unwraps
2196
+ * scalar values from their surrounding node; to disable set `keepScalar` to
2197
+ * `true` (collections are always returned intact).
2198
+ */
2199
+ get(e, t) {
2200
+ return I(this.contents) ? this.contents.get(e, t) : void 0;
2201
+ }
2202
+ /**
2203
+ * Returns item at `path`, or `undefined` if not found. By default unwraps
2204
+ * scalar values from their surrounding node; to disable set `keepScalar` to
2205
+ * `true` (collections are always returned intact).
2206
+ */
2207
+ getIn(e, t) {
2208
+ return ue(e) ? !t && E(this.contents) ? this.contents.value : this.contents : I(this.contents) ? this.contents.getIn(e, t) : void 0;
2209
+ }
2210
+ /**
2211
+ * Checks if the document includes a value with the key `key`.
2212
+ */
2213
+ has(e) {
2214
+ return I(this.contents) ? this.contents.has(e) : !1;
2215
+ }
2216
+ /**
2217
+ * Checks if the document includes a value at `path`.
2218
+ */
2219
+ hasIn(e) {
2220
+ return ue(e) ? this.contents !== void 0 : I(this.contents) ? this.contents.hasIn(e) : !1;
2221
+ }
2222
+ /**
2223
+ * Sets a value in this document. For `!!set`, `value` needs to be a
2224
+ * boolean to add/remove the item from the set.
2225
+ */
2226
+ set(e, t) {
2227
+ this.contents == null ? this.contents = $e(this.schema, [e], t) : x(this.contents) && this.contents.set(e, t);
2228
+ }
2229
+ /**
2230
+ * Sets a value in this document. For `!!set`, `value` needs to be a
2231
+ * boolean to add/remove the item from the set.
2232
+ */
2233
+ setIn(e, t) {
2234
+ ue(e) ? this.contents = t : this.contents == null ? this.contents = $e(this.schema, Array.from(e), t) : x(this.contents) && this.contents.setIn(e, t);
2235
+ }
2236
+ /**
2237
+ * Change the YAML version and schema used by the document.
2238
+ * A `null` version disables support for directives, explicit tags, anchors, and aliases.
2239
+ * It also requires the `schema` option to be given as a `Schema` instance value.
2240
+ *
2241
+ * Overrides all previously set schema options.
2242
+ */
2243
+ setSchema(e, t = {}) {
2244
+ typeof e == "number" && (e = String(e));
2245
+ let n;
2246
+ switch (e) {
2247
+ case "1.1":
2248
+ this.directives ? this.directives.yaml.version = "1.1" : this.directives = new _({ version: "1.1" }), n = { resolveKnownTags: !1, schema: "yaml-1.1" };
2249
+ break;
2250
+ case "1.2":
2251
+ case "next":
2252
+ this.directives ? this.directives.yaml.version = e : this.directives = new _({ version: e }), n = { resolveKnownTags: !0, schema: "core" };
2253
+ break;
2254
+ case null:
2255
+ this.directives && delete this.directives, n = null;
2256
+ break;
2257
+ default: {
2258
+ const i = JSON.stringify(e);
2259
+ throw new Error(`Expected '1.1', '1.2' or null as first argument, but found: ${i}`);
2260
+ }
2261
+ }
2262
+ if (t.schema instanceof Object)
2263
+ this.schema = t.schema;
2264
+ else if (n)
2265
+ this.schema = new pt(Object.assign(n, t));
2266
+ else
2267
+ throw new Error("With a null YAML version, the { schema: Schema } option is required");
2268
+ }
2269
+ // json & jsonArg are only used from toJSON()
2270
+ toJS({ json: e, jsonArg: t, mapAsMap: n, maxAliasCount: i, onAnchor: r, reviver: o } = {}) {
2271
+ const l = {
2272
+ anchors: /* @__PURE__ */ new Map(),
2273
+ doc: this,
2274
+ keep: !e,
2275
+ mapAsMap: n === !0,
2276
+ mapKeyWarned: !1,
2277
+ maxAliasCount: typeof i == "number" ? i : 100
2278
+ }, a = P(this.contents, t ?? "", l);
2279
+ if (typeof r == "function")
2280
+ for (const { count: c, res: d } of l.anchors.values())
2281
+ r(d, c);
2282
+ return typeof o == "function" ? ee(o, { "": a }, "", a) : a;
2283
+ }
2284
+ /**
2285
+ * A JSON representation of the document `contents`.
2286
+ *
2287
+ * @param jsonArg Used by `JSON.stringify` to indicate the array index or
2288
+ * property name.
2289
+ */
2290
+ toJSON(e, t) {
2291
+ return this.toJS({ json: !0, jsonArg: e, mapAsMap: !1, onAnchor: t });
2292
+ }
2293
+ /** A YAML representation of the document. */
2294
+ toString(e = {}) {
2295
+ if (this.errors.length > 0)
2296
+ throw new Error("Document with errors cannot be stringified");
2297
+ if ("indent" in e && (!Number.isInteger(e.indent) || Number(e.indent) <= 0)) {
2298
+ const t = JSON.stringify(e.indent);
2299
+ throw new Error(`"indent" option must be a positive integer, not ${t}`);
2300
+ }
2301
+ return Xs(this, e);
2302
+ }
2303
+ }
2304
+ function x(s) {
2305
+ if (I(s))
2306
+ return !0;
2307
+ throw new Error("Expected a YAML collection as document contents");
2308
+ }
2309
+ class is extends Error {
2310
+ constructor(e, t, n, i) {
2311
+ super(), this.name = e, this.code = n, this.message = i, this.pos = t;
2312
+ }
2313
+ }
2314
+ class he extends is {
2315
+ constructor(e, t, n) {
2316
+ super("YAMLParseError", e, t, n);
2317
+ }
2318
+ }
2319
+ class xs extends is {
2320
+ constructor(e, t, n) {
2321
+ super("YAMLWarning", e, t, n);
2322
+ }
2323
+ }
2324
+ const At = (s, e) => (t) => {
2325
+ if (t.pos[0] === -1)
2326
+ return;
2327
+ t.linePos = t.pos.map((l) => e.linePos(l));
2328
+ const { line: n, col: i } = t.linePos[0];
2329
+ t.message += ` at line ${n}, column ${i}`;
2330
+ let r = i - 1, o = s.substring(e.lineStarts[n - 1], e.lineStarts[n]).replace(/[\n\r]+$/, "");
2331
+ if (r >= 60 && o.length > 80) {
2332
+ const l = Math.min(r - 39, o.length - 79);
2333
+ o = "…" + o.substring(l), r -= l - 1;
2334
+ }
2335
+ if (o.length > 80 && (o = o.substring(0, 79) + "…"), n > 1 && /^ *$/.test(o.substring(0, r))) {
2336
+ let l = s.substring(e.lineStarts[n - 2], e.lineStarts[n - 1]);
2337
+ l.length > 80 && (l = l.substring(0, 79) + `…
2338
+ `), o = l + o;
2339
+ }
2340
+ if (/[^ ]/.test(o)) {
2341
+ let l = 1;
2342
+ const a = t.linePos[1];
2343
+ a?.line === n && a.col > i && (l = Math.max(1, Math.min(a.col - i, 80 - r)));
2344
+ const c = " ".repeat(r) + "^".repeat(l);
2345
+ t.message += `:
2346
+
2347
+ ${o}
2348
+ ${c}
2349
+ `;
2350
+ }
2351
+ };
2352
+ function re(s, { flow: e, indicator: t, next: n, offset: i, onError: r, parentIndent: o, startOnNewline: l }) {
2353
+ let a = !1, c = l, d = l, f = "", u = "", m = !1, g = !1, h = null, p = null, b = null, w = null, k = null, S = null, N = null;
2354
+ for (const y of s)
2355
+ switch (g && (y.type !== "space" && y.type !== "newline" && y.type !== "comma" && r(y.offset, "MISSING_CHAR", "Tags and anchors must be separated from the next token by white space"), g = !1), h && (c && y.type !== "comment" && y.type !== "newline" && r(h, "TAB_AS_INDENT", "Tabs are not allowed as indentation"), h = null), y.type) {
2356
+ case "space":
2357
+ !e && (t !== "doc-start" || n?.type !== "flow-collection") && y.source.includes(" ") && (h = y), d = !0;
2358
+ break;
2359
+ case "comment": {
2360
+ d || r(y, "MISSING_CHAR", "Comments must be separated from other tokens by white space characters");
2361
+ const v = y.source.substring(1) || " ";
2362
+ f ? f += u + v : f = v, u = "", c = !1;
2363
+ break;
2364
+ }
2365
+ case "newline":
2366
+ c ? f ? f += y.source : (!S || t !== "seq-item-ind") && (a = !0) : u += y.source, c = !0, m = !0, (p || b) && (w = y), d = !0;
2367
+ break;
2368
+ case "anchor":
2369
+ p && r(y, "MULTIPLE_ANCHORS", "A node can have at most one anchor"), y.source.endsWith(":") && r(y.offset + y.source.length - 1, "BAD_ALIAS", "Anchor ending in : is ambiguous", !0), p = y, N ?? (N = y.offset), c = !1, d = !1, g = !0;
2370
+ break;
2371
+ case "tag": {
2372
+ b && r(y, "MULTIPLE_TAGS", "A node can have at most one tag"), b = y, N ?? (N = y.offset), c = !1, d = !1, g = !0;
2373
+ break;
2374
+ }
2375
+ case t:
2376
+ (p || b) && r(y, "BAD_PROP_ORDER", `Anchors and tags must be after the ${y.source} indicator`), S && r(y, "UNEXPECTED_TOKEN", `Unexpected ${y.source} in ${e ?? "collection"}`), S = y, c = t === "seq-item-ind" || t === "explicit-key-ind", d = !1;
2377
+ break;
2378
+ case "comma":
2379
+ if (e) {
2380
+ k && r(y, "UNEXPECTED_TOKEN", `Unexpected , in ${e}`), k = y, c = !1, d = !1;
2381
+ break;
2382
+ }
2383
+ // else fallthrough
2384
+ default:
2385
+ r(y, "UNEXPECTED_TOKEN", `Unexpected ${y.type} token`), c = !1, d = !1;
2386
+ }
2387
+ const A = s[s.length - 1], T = A ? A.offset + A.source.length : i;
2388
+ return g && n && n.type !== "space" && n.type !== "newline" && n.type !== "comma" && (n.type !== "scalar" || n.source !== "") && r(n.offset, "MISSING_CHAR", "Tags and anchors must be separated from the next token by white space"), h && (c && h.indent <= o || n?.type === "block-map" || n?.type === "block-seq") && r(h, "TAB_AS_INDENT", "Tabs are not allowed as indentation"), {
2389
+ comma: k,
2390
+ found: S,
2391
+ spaceBefore: a,
2392
+ comment: f,
2393
+ hasNewline: m,
2394
+ anchor: p,
2395
+ tag: b,
2396
+ newlineAfterProp: w,
2397
+ end: T,
2398
+ start: N ?? T
2399
+ };
2400
+ }
2401
+ function ge(s) {
2402
+ if (!s)
2403
+ return null;
2404
+ switch (s.type) {
2405
+ case "alias":
2406
+ case "scalar":
2407
+ case "double-quoted-scalar":
2408
+ case "single-quoted-scalar":
2409
+ if (s.source.includes(`
2410
+ `))
2411
+ return !0;
2412
+ if (s.end) {
2413
+ for (const e of s.end)
2414
+ if (e.type === "newline")
2415
+ return !0;
2416
+ }
2417
+ return !1;
2418
+ case "flow-collection":
2419
+ for (const e of s.items) {
2420
+ for (const t of e.start)
2421
+ if (t.type === "newline")
2422
+ return !0;
2423
+ if (e.sep) {
2424
+ for (const t of e.sep)
2425
+ if (t.type === "newline")
2426
+ return !0;
2427
+ }
2428
+ if (ge(e.key) || ge(e.value))
2429
+ return !0;
2430
+ }
2431
+ return !1;
2432
+ default:
2433
+ return !0;
2434
+ }
2435
+ }
2436
+ function ze(s, e, t) {
2437
+ if (e?.type === "flow-collection") {
2438
+ const n = e.end[0];
2439
+ n.indent === s && (n.source === "]" || n.source === "}") && ge(e) && t(n, "BAD_INDENT", "Flow end indicator should be more indented than parent", !0);
2440
+ }
2441
+ }
2442
+ function rs(s, e, t) {
2443
+ const { uniqueKeys: n } = s.options;
2444
+ if (n === !1)
2445
+ return !1;
2446
+ const i = typeof n == "function" ? n : (r, o) => r === o || E(r) && E(o) && r.value === o.value;
2447
+ return e.some((r) => i(r.key, t));
2448
+ }
2449
+ const Tt = "All mapping items must start at the same column";
2450
+ function zs({ composeNode: s, composeEmptyNode: e }, t, n, i, r) {
2451
+ const o = r?.nodeClass ?? M, l = new o(t.schema);
2452
+ t.atRoot && (t.atRoot = !1);
2453
+ let a = n.offset, c = null;
2454
+ for (const d of n.items) {
2455
+ const { start: f, key: u, sep: m, value: g } = d, h = re(f, {
2456
+ indicator: "explicit-key-ind",
2457
+ next: u ?? m?.[0],
2458
+ offset: a,
2459
+ onError: i,
2460
+ parentIndent: n.indent,
2461
+ startOnNewline: !0
2462
+ }), p = !h.found;
2463
+ if (p) {
2464
+ if (u && (u.type === "block-seq" ? i(a, "BLOCK_AS_IMPLICIT_KEY", "A block sequence may not be used as an implicit map key") : "indent" in u && u.indent !== n.indent && i(a, "BAD_INDENT", Tt)), !h.anchor && !h.tag && !m) {
2465
+ c = h.end, h.comment && (l.comment ? l.comment += `
2466
+ ` + h.comment : l.comment = h.comment);
2467
+ continue;
2468
+ }
2469
+ (h.newlineAfterProp || ge(u)) && i(u ?? f[f.length - 1], "MULTILINE_IMPLICIT_KEY", "Implicit keys need to be on a single line");
2470
+ } else h.found?.indent !== n.indent && i(a, "BAD_INDENT", Tt);
2471
+ t.atKey = !0;
2472
+ const b = h.end, w = u ? s(t, u, h, i) : e(t, b, f, null, h, i);
2473
+ t.schema.compat && ze(n.indent, u, i), t.atKey = !1, rs(t, l.items, w) && i(b, "DUPLICATE_KEY", "Map keys must be unique");
2474
+ const k = re(m ?? [], {
2475
+ indicator: "map-value-ind",
2476
+ next: g,
2477
+ offset: w.range[2],
2478
+ onError: i,
2479
+ parentIndent: n.indent,
2480
+ startOnNewline: !u || u.type === "block-scalar"
2481
+ });
2482
+ if (a = k.end, k.found) {
2483
+ p && (g?.type === "block-map" && !k.hasNewline && i(a, "BLOCK_AS_IMPLICIT_KEY", "Nested mappings are not allowed in compact mappings"), t.options.strict && h.start < k.found.offset - 1024 && i(w.range, "KEY_OVER_1024_CHARS", "The : indicator must be at most 1024 chars after the start of an implicit block mapping key"));
2484
+ const S = g ? s(t, g, k, i) : e(t, a, m, null, k, i);
2485
+ t.schema.compat && ze(n.indent, g, i), a = S.range[2];
2486
+ const N = new B(w, S);
2487
+ t.options.keepSourceTokens && (N.srcToken = d), l.items.push(N);
2488
+ } else {
2489
+ p && i(w.range, "MISSING_CHAR", "Implicit map keys need to be followed by map values"), k.comment && (w.comment ? w.comment += `
2490
+ ` + k.comment : w.comment = k.comment);
2491
+ const S = new B(w);
2492
+ t.options.keepSourceTokens && (S.srcToken = d), l.items.push(S);
2493
+ }
2494
+ }
2495
+ return c && c < a && i(c, "IMPOSSIBLE", "Map comment with trailing content"), l.range = [n.offset, a, c ?? a], l;
2496
+ }
2497
+ function Zs({ composeNode: s, composeEmptyNode: e }, t, n, i, r) {
2498
+ const o = r?.nodeClass ?? W, l = new o(t.schema);
2499
+ t.atRoot && (t.atRoot = !1), t.atKey && (t.atKey = !1);
2500
+ let a = n.offset, c = null;
2501
+ for (const { start: d, value: f } of n.items) {
2502
+ const u = re(d, {
2503
+ indicator: "seq-item-ind",
2504
+ next: f,
2505
+ offset: a,
2506
+ onError: i,
2507
+ parentIndent: n.indent,
2508
+ startOnNewline: !0
2509
+ });
2510
+ if (!u.found)
2511
+ if (u.anchor || u.tag || f)
2512
+ f?.type === "block-seq" ? i(u.end, "BAD_INDENT", "All sequence items must start at the same column") : i(a, "MISSING_CHAR", "Sequence item without - indicator");
2513
+ else {
2514
+ c = u.end, u.comment && (l.comment = u.comment);
2515
+ continue;
2516
+ }
2517
+ const m = f ? s(t, f, u, i) : e(t, u.end, d, null, u, i);
2518
+ t.schema.compat && ze(n.indent, f, i), a = m.range[2], l.items.push(m);
2519
+ }
2520
+ return l.range = [n.offset, a, c ?? a], l;
2521
+ }
2522
+ function ke(s, e, t, n) {
2523
+ let i = "";
2524
+ if (s) {
2525
+ let r = !1, o = "";
2526
+ for (const l of s) {
2527
+ const { source: a, type: c } = l;
2528
+ switch (c) {
2529
+ case "space":
2530
+ r = !0;
2531
+ break;
2532
+ case "comment": {
2533
+ t && !r && n(l, "MISSING_CHAR", "Comments must be separated from other tokens by white space characters");
2534
+ const d = a.substring(1) || " ";
2535
+ i ? i += o + d : i = d, o = "";
2536
+ break;
2537
+ }
2538
+ case "newline":
2539
+ i && (o += a), r = !0;
2540
+ break;
2541
+ default:
2542
+ n(l, "UNEXPECTED_TOKEN", `Unexpected ${c} at node end`);
2543
+ }
2544
+ e += a.length;
2545
+ }
2546
+ }
2547
+ return { comment: i, offset: e };
2548
+ }
2549
+ const Ve = "Block collections are not allowed within flow collections", Je = (s) => s && (s.type === "block-map" || s.type === "block-seq");
2550
+ function en({ composeNode: s, composeEmptyNode: e }, t, n, i, r) {
2551
+ const o = n.start.source === "{", l = o ? "flow map" : "flow sequence", a = r?.nodeClass ?? (o ? M : W), c = new a(t.schema);
2552
+ c.flow = !0;
2553
+ const d = t.atRoot;
2554
+ d && (t.atRoot = !1), t.atKey && (t.atKey = !1);
2555
+ let f = n.offset + n.start.source.length;
2556
+ for (let p = 0; p < n.items.length; ++p) {
2557
+ const b = n.items[p], { start: w, key: k, sep: S, value: N } = b, A = re(w, {
2558
+ flow: l,
2559
+ indicator: "explicit-key-ind",
2560
+ next: k ?? S?.[0],
2561
+ offset: f,
2562
+ onError: i,
2563
+ parentIndent: n.indent,
2564
+ startOnNewline: !1
2565
+ });
2566
+ if (!A.found) {
2567
+ if (!A.anchor && !A.tag && !S && !N) {
2568
+ p === 0 && A.comma ? i(A.comma, "UNEXPECTED_TOKEN", `Unexpected , in ${l}`) : p < n.items.length - 1 && i(A.start, "UNEXPECTED_TOKEN", `Unexpected empty item in ${l}`), A.comment && (c.comment ? c.comment += `
2569
+ ` + A.comment : c.comment = A.comment), f = A.end;
2570
+ continue;
2571
+ }
2572
+ !o && t.options.strict && ge(k) && i(
2573
+ k,
2574
+ // checked by containsNewline()
2575
+ "MULTILINE_IMPLICIT_KEY",
2576
+ "Implicit keys of flow sequence pairs need to be on a single line"
2577
+ );
2578
+ }
2579
+ if (p === 0)
2580
+ A.comma && i(A.comma, "UNEXPECTED_TOKEN", `Unexpected , in ${l}`);
2581
+ else if (A.comma || i(A.start, "MISSING_CHAR", `Missing , between ${l} items`), A.comment) {
2582
+ let T = "";
2583
+ e: for (const y of w)
2584
+ switch (y.type) {
2585
+ case "comma":
2586
+ case "space":
2587
+ break;
2588
+ case "comment":
2589
+ T = y.source.substring(1);
2590
+ break e;
2591
+ default:
2592
+ break e;
2593
+ }
2594
+ if (T) {
2595
+ let y = c.items[c.items.length - 1];
2596
+ $(y) && (y = y.value ?? y.key), y.comment ? y.comment += `
2597
+ ` + T : y.comment = T, A.comment = A.comment.substring(T.length + 1);
2598
+ }
2599
+ }
2600
+ if (!o && !S && !A.found) {
2601
+ const T = N ? s(t, N, A, i) : e(t, A.end, S, null, A, i);
2602
+ c.items.push(T), f = T.range[2], Je(N) && i(T.range, "BLOCK_IN_FLOW", Ve);
2603
+ } else {
2604
+ t.atKey = !0;
2605
+ const T = A.end, y = k ? s(t, k, A, i) : e(t, T, w, null, A, i);
2606
+ Je(k) && i(y.range, "BLOCK_IN_FLOW", Ve), t.atKey = !1;
2607
+ const v = re(S ?? [], {
2608
+ flow: l,
2609
+ indicator: "map-value-ind",
2610
+ next: N,
2611
+ offset: y.range[2],
2612
+ onError: i,
2613
+ parentIndent: n.indent,
2614
+ startOnNewline: !1
2615
+ });
2616
+ if (v.found) {
2617
+ if (!o && !A.found && t.options.strict) {
2618
+ if (S)
2619
+ for (const C of S) {
2620
+ if (C === v.found)
2621
+ break;
2622
+ if (C.type === "newline") {
2623
+ i(C, "MULTILINE_IMPLICIT_KEY", "Implicit keys of flow sequence pairs need to be on a single line");
2624
+ break;
2625
+ }
2626
+ }
2627
+ A.start < v.found.offset - 1024 && i(v.found, "KEY_OVER_1024_CHARS", "The : indicator must be at most 1024 chars after the start of an implicit flow sequence key");
2628
+ }
2629
+ } else N && ("source" in N && N.source?.[0] === ":" ? i(N, "MISSING_CHAR", `Missing space after : in ${l}`) : i(v.start, "MISSING_CHAR", `Missing , or : between ${l} items`));
2630
+ const R = N ? s(t, N, v, i) : v.found ? e(t, v.end, S, null, v, i) : null;
2631
+ R ? Je(N) && i(R.range, "BLOCK_IN_FLOW", Ve) : v.comment && (y.comment ? y.comment += `
2632
+ ` + v.comment : y.comment = v.comment);
2633
+ const X = new B(y, R);
2634
+ if (t.options.keepSourceTokens && (X.srcToken = b), o) {
2635
+ const C = c;
2636
+ rs(t, C.items, y) && i(T, "DUPLICATE_KEY", "Map keys must be unique"), C.items.push(X);
2637
+ } else {
2638
+ const C = new M(t.schema);
2639
+ C.flow = !0, C.items.push(X);
2640
+ const yt = (R ?? y).range;
2641
+ C.range = [y.range[0], yt[1], yt[2]], c.items.push(C);
2642
+ }
2643
+ f = R ? R.range[2] : v.end;
2644
+ }
2645
+ }
2646
+ const u = o ? "}" : "]", [m, ...g] = n.end;
2647
+ let h = f;
2648
+ if (m?.source === u)
2649
+ h = m.offset + m.source.length;
2650
+ else {
2651
+ const p = l[0].toUpperCase() + l.substring(1), b = d ? `${p} must end with a ${u}` : `${p} in block collection must be sufficiently indented and end with a ${u}`;
2652
+ i(f, d ? "MISSING_CHAR" : "BAD_INDENT", b), m && m.source.length !== 1 && g.unshift(m);
2653
+ }
2654
+ if (g.length > 0) {
2655
+ const p = ke(g, h, t.options.strict, i);
2656
+ p.comment && (c.comment ? c.comment += `
2657
+ ` + p.comment : c.comment = p.comment), c.range = [n.offset, h, p.offset];
2658
+ } else
2659
+ c.range = [n.offset, h, h];
2660
+ return c;
2661
+ }
2662
+ function Ye(s, e, t, n, i, r) {
2663
+ const o = t.type === "block-map" ? zs(s, e, t, n, r) : t.type === "block-seq" ? Zs(s, e, t, n, r) : en(s, e, t, n, r), l = o.constructor;
2664
+ return i === "!" || i === l.tagName ? (o.tag = l.tagName, o) : (i && (o.tag = i), o);
2665
+ }
2666
+ function tn(s, e, t, n, i) {
2667
+ const r = n.tag, o = r ? e.directives.tagName(r.source, (u) => i(r, "TAG_RESOLVE_FAILED", u)) : null;
2668
+ if (t.type === "block-seq") {
2669
+ const { anchor: u, newlineAfterProp: m } = n, g = u && r ? u.offset > r.offset ? u : r : u ?? r;
2670
+ g && (!m || m.offset < g.offset) && i(g, "MISSING_CHAR", "Missing newline after block sequence props");
2671
+ }
2672
+ const l = t.type === "block-map" ? "map" : t.type === "block-seq" ? "seq" : t.start.source === "{" ? "map" : "seq";
2673
+ if (!r || !o || o === "!" || o === M.tagName && l === "map" || o === W.tagName && l === "seq")
2674
+ return Ye(s, e, t, i, o);
2675
+ let a = e.schema.tags.find((u) => u.tag === o && u.collection === l);
2676
+ if (!a) {
2677
+ const u = e.schema.knownTags[o];
2678
+ if (u?.collection === l)
2679
+ e.schema.tags.push(Object.assign({}, u, { default: !1 })), a = u;
2680
+ else
2681
+ return u ? i(r, "BAD_COLLECTION_TYPE", `${u.tag} used for ${l} collection, but expects ${u.collection ?? "scalar"}`, !0) : i(r, "TAG_RESOLVE_FAILED", `Unresolved tag: ${o}`, !0), Ye(s, e, t, i, o);
2682
+ }
2683
+ const c = Ye(s, e, t, i, o, a), d = a.resolve?.(c, (u) => i(r, "TAG_RESOLVE_FAILED", u), e.options) ?? c, f = L(d) ? d : new O(d);
2684
+ return f.range = c.range, f.tag = o, a?.format && (f.format = a.format), f;
2685
+ }
2686
+ function sn(s, e, t) {
2687
+ const n = e.offset, i = nn(e, s.options.strict, t);
2688
+ if (!i)
2689
+ return { value: "", type: null, comment: "", range: [n, n, n] };
2690
+ const r = i.mode === ">" ? O.BLOCK_FOLDED : O.BLOCK_LITERAL, o = e.source ? rn(e.source) : [];
2691
+ let l = o.length;
2692
+ for (let h = o.length - 1; h >= 0; --h) {
2693
+ const p = o[h][1];
2694
+ if (p === "" || p === "\r")
2695
+ l = h;
2696
+ else
2697
+ break;
2698
+ }
2699
+ if (l === 0) {
2700
+ const h = i.chomp === "+" && o.length > 0 ? `
2701
+ `.repeat(Math.max(1, o.length - 1)) : "";
2702
+ let p = n + i.length;
2703
+ return e.source && (p += e.source.length), { value: h, type: r, comment: i.comment, range: [n, p, p] };
2704
+ }
2705
+ let a = e.indent + i.indent, c = e.offset + i.length, d = 0;
2706
+ for (let h = 0; h < l; ++h) {
2707
+ const [p, b] = o[h];
2708
+ if (b === "" || b === "\r")
2709
+ i.indent === 0 && p.length > a && (a = p.length);
2710
+ else {
2711
+ p.length < a && t(c + p.length, "MISSING_CHAR", "Block scalars with more-indented leading empty lines must use an explicit indentation indicator"), i.indent === 0 && (a = p.length), d = h, a === 0 && !s.atRoot && t(c, "BAD_INDENT", "Block scalar values in collections must be indented");
2712
+ break;
2713
+ }
2714
+ c += p.length + b.length + 1;
2715
+ }
2716
+ for (let h = o.length - 1; h >= l; --h)
2717
+ o[h][0].length > a && (l = h + 1);
2718
+ let f = "", u = "", m = !1;
2719
+ for (let h = 0; h < d; ++h)
2720
+ f += o[h][0].slice(a) + `
2721
+ `;
2722
+ for (let h = d; h < l; ++h) {
2723
+ let [p, b] = o[h];
2724
+ c += p.length + b.length + 1;
2725
+ const w = b[b.length - 1] === "\r";
2726
+ if (w && (b = b.slice(0, -1)), b && p.length < a) {
2727
+ const S = `Block scalar lines must not be less indented than their ${i.indent ? "explicit indentation indicator" : "first line"}`;
2728
+ t(c - b.length - (w ? 2 : 1), "BAD_INDENT", S), p = "";
2729
+ }
2730
+ r === O.BLOCK_LITERAL ? (f += u + p.slice(a) + b, u = `
2731
+ `) : p.length > a || b[0] === " " ? (u === " " ? u = `
2732
+ ` : !m && u === `
2733
+ ` && (u = `
2734
+
2735
+ `), f += u + p.slice(a) + b, u = `
2736
+ `, m = !0) : b === "" ? u === `
2737
+ ` ? f += `
2738
+ ` : u = `
2739
+ ` : (f += u + b, u = " ", m = !1);
2740
+ }
2741
+ switch (i.chomp) {
2742
+ case "-":
2743
+ break;
2744
+ case "+":
2745
+ for (let h = l; h < o.length; ++h)
2746
+ f += `
2747
+ ` + o[h][0].slice(a);
2748
+ f[f.length - 1] !== `
2749
+ ` && (f += `
2750
+ `);
2751
+ break;
2752
+ default:
2753
+ f += `
2754
+ `;
2755
+ }
2756
+ const g = n + i.length + e.source.length;
2757
+ return { value: f, type: r, comment: i.comment, range: [n, g, g] };
2758
+ }
2759
+ function nn({ offset: s, props: e }, t, n) {
2760
+ if (e[0].type !== "block-scalar-header")
2761
+ return n(e[0], "IMPOSSIBLE", "Block scalar header not found"), null;
2762
+ const { source: i } = e[0], r = i[0];
2763
+ let o = 0, l = "", a = -1;
2764
+ for (let u = 1; u < i.length; ++u) {
2765
+ const m = i[u];
2766
+ if (!l && (m === "-" || m === "+"))
2767
+ l = m;
2768
+ else {
2769
+ const g = Number(m);
2770
+ !o && g ? o = g : a === -1 && (a = s + u);
2771
+ }
2772
+ }
2773
+ a !== -1 && n(a, "UNEXPECTED_TOKEN", `Block scalar header includes extra characters: ${i}`);
2774
+ let c = !1, d = "", f = i.length;
2775
+ for (let u = 1; u < e.length; ++u) {
2776
+ const m = e[u];
2777
+ switch (m.type) {
2778
+ case "space":
2779
+ c = !0;
2780
+ // fallthrough
2781
+ case "newline":
2782
+ f += m.source.length;
2783
+ break;
2784
+ case "comment":
2785
+ t && !c && n(m, "MISSING_CHAR", "Comments must be separated from other tokens by white space characters"), f += m.source.length, d = m.source.substring(1);
2786
+ break;
2787
+ case "error":
2788
+ n(m, "UNEXPECTED_TOKEN", m.message), f += m.source.length;
2789
+ break;
2790
+ /* istanbul ignore next should not happen */
2791
+ default: {
2792
+ const g = `Unexpected token in block scalar header: ${m.type}`;
2793
+ n(m, "UNEXPECTED_TOKEN", g);
2794
+ const h = m.source;
2795
+ h && typeof h == "string" && (f += h.length);
2796
+ }
2797
+ }
2798
+ }
2799
+ return { mode: r, indent: o, chomp: l, comment: d, length: f };
2800
+ }
2801
+ function rn(s) {
2802
+ const e = s.split(/\n( *)/), t = e[0], n = t.match(/^( *)/), r = [n?.[1] ? [n[1], t.slice(n[1].length)] : ["", t]];
2803
+ for (let o = 1; o < e.length; o += 2)
2804
+ r.push([e[o], e[o + 1]]);
2805
+ return r;
2806
+ }
2807
+ function on(s, e, t) {
2808
+ const { offset: n, type: i, source: r, end: o } = s;
2809
+ let l, a;
2810
+ const c = (u, m, g) => t(n + u, m, g);
2811
+ switch (i) {
2812
+ case "scalar":
2813
+ l = O.PLAIN, a = ln(r, c);
2814
+ break;
2815
+ case "single-quoted-scalar":
2816
+ l = O.QUOTE_SINGLE, a = an(r, c);
2817
+ break;
2818
+ case "double-quoted-scalar":
2819
+ l = O.QUOTE_DOUBLE, a = cn(r, c);
2820
+ break;
2821
+ /* istanbul ignore next should not happen */
2822
+ default:
2823
+ return t(s, "UNEXPECTED_TOKEN", `Expected a flow scalar value, but found: ${i}`), {
2824
+ value: "",
2825
+ type: null,
2826
+ comment: "",
2827
+ range: [n, n + r.length, n + r.length]
2828
+ };
2829
+ }
2830
+ const d = n + r.length, f = ke(o, d, e, t);
2831
+ return {
2832
+ value: a,
2833
+ type: l,
2834
+ comment: f.comment,
2835
+ range: [n, d, f.offset]
2836
+ };
2837
+ }
2838
+ function ln(s, e) {
2839
+ let t = "";
2840
+ switch (s[0]) {
2841
+ /* istanbul ignore next should not happen */
2842
+ case " ":
2843
+ t = "a tab character";
2844
+ break;
2845
+ case ",":
2846
+ t = "flow indicator character ,";
2847
+ break;
2848
+ case "%":
2849
+ t = "directive indicator character %";
2850
+ break;
2851
+ case "|":
2852
+ case ">": {
2853
+ t = `block scalar indicator ${s[0]}`;
2854
+ break;
2855
+ }
2856
+ case "@":
2857
+ case "`": {
2858
+ t = `reserved character ${s[0]}`;
2859
+ break;
2860
+ }
2861
+ }
2862
+ return t && e(0, "BAD_SCALAR_START", `Plain value cannot start with ${t}`), os(s);
2863
+ }
2864
+ function an(s, e) {
2865
+ return (s[s.length - 1] !== "'" || s.length === 1) && e(s.length, "MISSING_CHAR", "Missing closing 'quote"), os(s.slice(1, -1)).replace(/''/g, "'");
2866
+ }
2867
+ function os(s) {
2868
+ let e, t;
2869
+ try {
2870
+ e = new RegExp(`(.*?)(?<![ ])[ ]*\r?
2871
+ `, "sy"), t = new RegExp(`[ ]*(.*?)(?:(?<![ ])[ ]*)?\r?
2872
+ `, "sy");
2873
+ } catch {
2874
+ e = /(.*?)[ \t]*\r?\n/sy, t = /[ \t]*(.*?)[ \t]*\r?\n/sy;
2875
+ }
2876
+ let n = e.exec(s);
2877
+ if (!n)
2878
+ return s;
2879
+ let i = n[1], r = " ", o = e.lastIndex;
2880
+ for (t.lastIndex = o; n = t.exec(s); )
2881
+ n[1] === "" ? r === `
2882
+ ` ? i += r : r = `
2883
+ ` : (i += r + n[1], r = " "), o = t.lastIndex;
2884
+ const l = /[ \t]*(.*)/sy;
2885
+ return l.lastIndex = o, n = l.exec(s), i + r + (n?.[1] ?? "");
2886
+ }
2887
+ function cn(s, e) {
2888
+ let t = "";
2889
+ for (let n = 1; n < s.length - 1; ++n) {
2890
+ const i = s[n];
2891
+ if (!(i === "\r" && s[n + 1] === `
2892
+ `))
2893
+ if (i === `
2894
+ `) {
2895
+ const { fold: r, offset: o } = fn(s, n);
2896
+ t += r, n = o;
2897
+ } else if (i === "\\") {
2898
+ let r = s[++n];
2899
+ const o = un[r];
2900
+ if (o)
2901
+ t += o;
2902
+ else if (r === `
2903
+ `)
2904
+ for (r = s[n + 1]; r === " " || r === " "; )
2905
+ r = s[++n + 1];
2906
+ else if (r === "\r" && s[n + 1] === `
2907
+ `)
2908
+ for (r = s[++n + 1]; r === " " || r === " "; )
2909
+ r = s[++n + 1];
2910
+ else if (r === "x" || r === "u" || r === "U") {
2911
+ const l = { x: 2, u: 4, U: 8 }[r];
2912
+ t += hn(s, n + 1, l, e), n += l;
2913
+ } else {
2914
+ const l = s.substr(n - 1, 2);
2915
+ e(n - 1, "BAD_DQ_ESCAPE", `Invalid escape sequence ${l}`), t += l;
2916
+ }
2917
+ } else if (i === " " || i === " ") {
2918
+ const r = n;
2919
+ let o = s[n + 1];
2920
+ for (; o === " " || o === " "; )
2921
+ o = s[++n + 1];
2922
+ o !== `
2923
+ ` && !(o === "\r" && s[n + 2] === `
2924
+ `) && (t += n > r ? s.slice(r, n + 1) : i);
2925
+ } else
2926
+ t += i;
2927
+ }
2928
+ return (s[s.length - 1] !== '"' || s.length === 1) && e(s.length, "MISSING_CHAR", 'Missing closing "quote'), t;
2929
+ }
2930
+ function fn(s, e) {
2931
+ let t = "", n = s[e + 1];
2932
+ for (; (n === " " || n === " " || n === `
2933
+ ` || n === "\r") && !(n === "\r" && s[e + 2] !== `
2934
+ `); )
2935
+ n === `
2936
+ ` && (t += `
2937
+ `), e += 1, n = s[e + 1];
2938
+ return t || (t = " "), { fold: t, offset: e };
2939
+ }
2940
+ const un = {
2941
+ 0: "\0",
2942
+ // null character
2943
+ a: "\x07",
2944
+ // bell character
2945
+ b: "\b",
2946
+ // backspace
2947
+ e: "\x1B",
2948
+ // escape character
2949
+ f: "\f",
2950
+ // form feed
2951
+ n: `
2952
+ `,
2953
+ // line feed
2954
+ r: "\r",
2955
+ // carriage return
2956
+ t: " ",
2957
+ // horizontal tab
2958
+ v: "\v",
2959
+ // vertical tab
2960
+ N: "…",
2961
+ // Unicode next line
2962
+ _: " ",
2963
+ // Unicode non-breaking space
2964
+ L: "\u2028",
2965
+ // Unicode line separator
2966
+ P: "\u2029",
2967
+ // Unicode paragraph separator
2968
+ " ": " ",
2969
+ '"': '"',
2970
+ "/": "/",
2971
+ "\\": "\\",
2972
+ " ": " "
2973
+ };
2974
+ function hn(s, e, t, n) {
2975
+ const i = s.substr(e, t), o = i.length === t && /^[0-9a-fA-F]+$/.test(i) ? parseInt(i, 16) : NaN;
2976
+ if (isNaN(o)) {
2977
+ const l = s.substr(e - 2, t + 2);
2978
+ return n(e - 2, "BAD_DQ_ESCAPE", `Invalid escape sequence ${l}`), l;
2979
+ }
2980
+ return String.fromCodePoint(o);
2981
+ }
2982
+ function ls(s, e, t, n) {
2983
+ const { value: i, type: r, comment: o, range: l } = e.type === "block-scalar" ? sn(s, e, n) : on(e, s.options.strict, n), a = t ? s.directives.tagName(t.source, (f) => n(t, "TAG_RESOLVE_FAILED", f)) : null;
2984
+ let c;
2985
+ s.options.stringKeys && s.atKey ? c = s.schema[q] : a ? c = dn(s.schema, i, a, t, n) : e.type === "scalar" ? c = pn(s, i, e, n) : c = s.schema[q];
2986
+ let d;
2987
+ try {
2988
+ const f = c.resolve(i, (u) => n(t ?? e, "TAG_RESOLVE_FAILED", u), s.options);
2989
+ d = E(f) ? f : new O(f);
2990
+ } catch (f) {
2991
+ const u = f instanceof Error ? f.message : String(f);
2992
+ n(t ?? e, "TAG_RESOLVE_FAILED", u), d = new O(i);
2993
+ }
2994
+ return d.range = l, d.source = i, r && (d.type = r), a && (d.tag = a), c.format && (d.format = c.format), o && (d.comment = o), d;
2995
+ }
2996
+ function dn(s, e, t, n, i) {
2997
+ if (t === "!")
2998
+ return s[q];
2999
+ const r = [];
3000
+ for (const l of s.tags)
3001
+ if (!l.collection && l.tag === t)
3002
+ if (l.default && l.test)
3003
+ r.push(l);
3004
+ else
3005
+ return l;
3006
+ for (const l of r)
3007
+ if (l.test?.test(e))
3008
+ return l;
3009
+ const o = s.knownTags[t];
3010
+ return o && !o.collection ? (s.tags.push(Object.assign({}, o, { default: !1, test: void 0 })), o) : (i(n, "TAG_RESOLVE_FAILED", `Unresolved tag: ${t}`, t !== "tag:yaml.org,2002:str"), s[q]);
3011
+ }
3012
+ function pn({ atKey: s, directives: e, schema: t }, n, i, r) {
3013
+ const o = t.tags.find((l) => (l.default === !0 || s && l.default === "key") && l.test?.test(n)) || t[q];
3014
+ if (t.compat) {
3015
+ const l = t.compat.find((a) => a.default && a.test?.test(n)) ?? t[q];
3016
+ if (o.tag !== l.tag) {
3017
+ const a = e.tagString(o.tag), c = e.tagString(l.tag), d = `Value may be parsed as either ${a} or ${c}`;
3018
+ r(i, "TAG_RESOLVE_FAILED", d, !0);
3019
+ }
3020
+ }
3021
+ return o;
3022
+ }
3023
+ function mn(s, e, t) {
3024
+ if (e) {
3025
+ t ?? (t = e.length);
3026
+ for (let n = t - 1; n >= 0; --n) {
3027
+ let i = e[n];
3028
+ switch (i.type) {
3029
+ case "space":
3030
+ case "comment":
3031
+ case "newline":
3032
+ s -= i.source.length;
3033
+ continue;
3034
+ }
3035
+ for (i = e[++n]; i?.type === "space"; )
3036
+ s += i.source.length, i = e[++n];
3037
+ break;
3038
+ }
3039
+ }
3040
+ return s;
3041
+ }
3042
+ const gn = { composeNode: as, composeEmptyNode: mt };
3043
+ function as(s, e, t, n) {
3044
+ const i = s.atKey, { spaceBefore: r, comment: o, anchor: l, tag: a } = t;
3045
+ let c, d = !0;
3046
+ switch (e.type) {
3047
+ case "alias":
3048
+ c = yn(s, e, n), (l || a) && n(e, "ALIAS_PROPS", "An alias node must not specify any properties");
3049
+ break;
3050
+ case "scalar":
3051
+ case "single-quoted-scalar":
3052
+ case "double-quoted-scalar":
3053
+ case "block-scalar":
3054
+ c = ls(s, e, a, n), l && (c.anchor = l.source.substring(1));
3055
+ break;
3056
+ case "block-map":
3057
+ case "block-seq":
3058
+ case "flow-collection":
3059
+ c = tn(gn, s, e, t, n), l && (c.anchor = l.source.substring(1));
3060
+ break;
3061
+ default: {
3062
+ const f = e.type === "error" ? e.message : `Unsupported token (type: ${e.type})`;
3063
+ n(e, "UNEXPECTED_TOKEN", f), c = mt(s, e.offset, void 0, null, t, n), d = !1;
3064
+ }
3065
+ }
3066
+ return l && c.anchor === "" && n(l, "BAD_ALIAS", "Anchor cannot be an empty string"), i && s.options.stringKeys && (!E(c) || typeof c.value != "string" || c.tag && c.tag !== "tag:yaml.org,2002:str") && n(a ?? e, "NON_STRING_KEY", "With stringKeys, all keys must be strings"), r && (c.spaceBefore = !0), o && (e.type === "scalar" && e.source === "" ? c.comment = o : c.commentBefore = o), s.options.keepSourceTokens && d && (c.srcToken = e), c;
3067
+ }
3068
+ function mt(s, e, t, n, { spaceBefore: i, comment: r, anchor: o, tag: l, end: a }, c) {
3069
+ const d = {
3070
+ type: "scalar",
3071
+ offset: mn(e, t, n),
3072
+ indent: -1,
3073
+ source: ""
3074
+ }, f = ls(s, d, l, c);
3075
+ return o && (f.anchor = o.source.substring(1), f.anchor === "" && c(o, "BAD_ALIAS", "Anchor cannot be an empty string")), i && (f.spaceBefore = !0), r && (f.comment = r, f.range[2] = a), f;
3076
+ }
3077
+ function yn({ options: s }, { offset: e, source: t, end: n }, i) {
3078
+ const r = new nt(t.substring(1));
3079
+ r.source === "" && i(e, "BAD_ALIAS", "Alias cannot be an empty string"), r.source.endsWith(":") && i(e + t.length - 1, "BAD_ALIAS", "Alias ending in : is ambiguous", !0);
3080
+ const o = e + t.length, l = ke(n, o, s.strict, i);
3081
+ return r.range = [e, o, l.offset], l.comment && (r.comment = l.comment), r;
3082
+ }
3083
+ function bn(s, e, { offset: t, start: n, value: i, end: r }, o) {
3084
+ const l = Object.assign({ _directives: e }, s), a = new Ue(void 0, l), c = {
3085
+ atKey: !1,
3086
+ atRoot: !0,
3087
+ directives: a.directives,
3088
+ options: a.options,
3089
+ schema: a.schema
3090
+ }, d = re(n, {
3091
+ indicator: "doc-start",
3092
+ next: i ?? r?.[0],
3093
+ offset: t,
3094
+ onError: o,
3095
+ parentIndent: 0,
3096
+ startOnNewline: !0
3097
+ });
3098
+ d.found && (a.directives.docStart = !0, i && (i.type === "block-map" || i.type === "block-seq") && !d.hasNewline && o(d.end, "MISSING_CHAR", "Block collection cannot start on same line with directives-end marker")), a.contents = i ? as(c, i, d, o) : mt(c, d.end, n, null, d, o);
3099
+ const f = a.contents.range[2], u = ke(r, f, !1, o);
3100
+ return u.comment && (a.comment = u.comment), a.range = [t, f, u.offset], a;
3101
+ }
3102
+ function fe(s) {
3103
+ if (typeof s == "number")
3104
+ return [s, s + 1];
3105
+ if (Array.isArray(s))
3106
+ return s.length === 2 ? s : [s[0], s[1]];
3107
+ const { offset: e, source: t } = s;
3108
+ return [e, e + (typeof t == "string" ? t.length : 1)];
3109
+ }
3110
+ function Et(s) {
3111
+ let e = "", t = !1, n = !1;
3112
+ for (let i = 0; i < s.length; ++i) {
3113
+ const r = s[i];
3114
+ switch (r[0]) {
3115
+ case "#":
3116
+ e += (e === "" ? "" : n ? `
3117
+
3118
+ ` : `
3119
+ `) + (r.substring(1) || " "), t = !0, n = !1;
3120
+ break;
3121
+ case "%":
3122
+ s[i + 1]?.[0] !== "#" && (i += 1), t = !1;
3123
+ break;
3124
+ default:
3125
+ t || (n = !0), t = !1;
3126
+ }
3127
+ }
3128
+ return { comment: e, afterEmptyLine: n };
3129
+ }
3130
+ class wn {
3131
+ constructor(e = {}) {
3132
+ this.doc = null, this.atDirectives = !1, this.prelude = [], this.errors = [], this.warnings = [], this.onError = (t, n, i, r) => {
3133
+ const o = fe(t);
3134
+ r ? this.warnings.push(new xs(o, n, i)) : this.errors.push(new he(o, n, i));
3135
+ }, this.directives = new _({ version: e.version || "1.2" }), this.options = e;
3136
+ }
3137
+ decorate(e, t) {
3138
+ const { comment: n, afterEmptyLine: i } = Et(this.prelude);
3139
+ if (n) {
3140
+ const r = e.contents;
3141
+ if (t)
3142
+ e.comment = e.comment ? `${e.comment}
3143
+ ${n}` : n;
3144
+ else if (i || e.directives.docStart || !r)
3145
+ e.commentBefore = n;
3146
+ else if (I(r) && !r.flow && r.items.length > 0) {
3147
+ let o = r.items[0];
3148
+ $(o) && (o = o.key);
3149
+ const l = o.commentBefore;
3150
+ o.commentBefore = l ? `${n}
3151
+ ${l}` : n;
3152
+ } else {
3153
+ const o = r.commentBefore;
3154
+ r.commentBefore = o ? `${n}
3155
+ ${o}` : n;
3156
+ }
3157
+ }
3158
+ t ? (Array.prototype.push.apply(e.errors, this.errors), Array.prototype.push.apply(e.warnings, this.warnings)) : (e.errors = this.errors, e.warnings = this.warnings), this.prelude = [], this.errors = [], this.warnings = [];
3159
+ }
3160
+ /**
3161
+ * Current stream status information.
3162
+ *
3163
+ * Mostly useful at the end of input for an empty stream.
3164
+ */
3165
+ streamInfo() {
3166
+ return {
3167
+ comment: Et(this.prelude).comment,
3168
+ directives: this.directives,
3169
+ errors: this.errors,
3170
+ warnings: this.warnings
3171
+ };
3172
+ }
3173
+ /**
3174
+ * Compose tokens into documents.
3175
+ *
3176
+ * @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
3177
+ * @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
3178
+ */
3179
+ *compose(e, t = !1, n = -1) {
3180
+ for (const i of e)
3181
+ yield* this.next(i);
3182
+ yield* this.end(t, n);
3183
+ }
3184
+ /** Advance the composer by one CST token. */
3185
+ *next(e) {
3186
+ switch (e.type) {
3187
+ case "directive":
3188
+ this.directives.add(e.source, (t, n, i) => {
3189
+ const r = fe(e);
3190
+ r[0] += t, this.onError(r, "BAD_DIRECTIVE", n, i);
3191
+ }), this.prelude.push(e.source), this.atDirectives = !0;
3192
+ break;
3193
+ case "document": {
3194
+ const t = bn(this.options, this.directives, e, this.onError);
3195
+ this.atDirectives && !t.directives.docStart && this.onError(e, "MISSING_CHAR", "Missing directives-end/doc-start indicator line"), this.decorate(t, !1), this.doc && (yield this.doc), this.doc = t, this.atDirectives = !1;
3196
+ break;
3197
+ }
3198
+ case "byte-order-mark":
3199
+ case "space":
3200
+ break;
3201
+ case "comment":
3202
+ case "newline":
3203
+ this.prelude.push(e.source);
3204
+ break;
3205
+ case "error": {
3206
+ const t = e.source ? `${e.message}: ${JSON.stringify(e.source)}` : e.message, n = new he(fe(e), "UNEXPECTED_TOKEN", t);
3207
+ this.atDirectives || !this.doc ? this.errors.push(n) : this.doc.errors.push(n);
3208
+ break;
3209
+ }
3210
+ case "doc-end": {
3211
+ if (!this.doc) {
3212
+ const n = "Unexpected doc-end without preceding document";
3213
+ this.errors.push(new he(fe(e), "UNEXPECTED_TOKEN", n));
3214
+ break;
3215
+ }
3216
+ this.doc.directives.docEnd = !0;
3217
+ const t = ke(e.end, e.offset + e.source.length, this.doc.options.strict, this.onError);
3218
+ if (this.decorate(this.doc, !0), t.comment) {
3219
+ const n = this.doc.comment;
3220
+ this.doc.comment = n ? `${n}
3221
+ ${t.comment}` : t.comment;
3222
+ }
3223
+ this.doc.range[2] = t.offset;
3224
+ break;
3225
+ }
3226
+ default:
3227
+ this.errors.push(new he(fe(e), "UNEXPECTED_TOKEN", `Unsupported token ${e.type}`));
3228
+ }
3229
+ }
3230
+ /**
3231
+ * Call at end of input to yield any remaining document.
3232
+ *
3233
+ * @param forceDoc - If the stream contains no document, still emit a final document including any comments and directives that would be applied to a subsequent document.
3234
+ * @param endOffset - Should be set if `forceDoc` is also set, to set the document range end and to indicate errors correctly.
3235
+ */
3236
+ *end(e = !1, t = -1) {
3237
+ if (this.doc)
3238
+ this.decorate(this.doc, !0), yield this.doc, this.doc = null;
3239
+ else if (e) {
3240
+ const n = Object.assign({ _directives: this.directives }, this.options), i = new Ue(void 0, n);
3241
+ this.atDirectives && this.onError(t, "MISSING_CHAR", "Missing directives-end indicator line"), i.range = [0, t, t], this.decorate(i, !1), yield i;
3242
+ }
3243
+ }
3244
+ }
3245
+ const cs = "\uFEFF", fs = "", us = "", Ze = "";
3246
+ function kn(s) {
3247
+ switch (s) {
3248
+ case cs:
3249
+ return "byte-order-mark";
3250
+ case fs:
3251
+ return "doc-mode";
3252
+ case us:
3253
+ return "flow-error-end";
3254
+ case Ze:
3255
+ return "scalar";
3256
+ case "---":
3257
+ return "doc-start";
3258
+ case "...":
3259
+ return "doc-end";
3260
+ case "":
3261
+ case `
3262
+ `:
3263
+ case `\r
3264
+ `:
3265
+ return "newline";
3266
+ case "-":
3267
+ return "seq-item-ind";
3268
+ case "?":
3269
+ return "explicit-key-ind";
3270
+ case ":":
3271
+ return "map-value-ind";
3272
+ case "{":
3273
+ return "flow-map-start";
3274
+ case "}":
3275
+ return "flow-map-end";
3276
+ case "[":
3277
+ return "flow-seq-start";
3278
+ case "]":
3279
+ return "flow-seq-end";
3280
+ case ",":
3281
+ return "comma";
3282
+ }
3283
+ switch (s[0]) {
3284
+ case " ":
3285
+ case " ":
3286
+ return "space";
3287
+ case "#":
3288
+ return "comment";
3289
+ case "%":
3290
+ return "directive-line";
3291
+ case "*":
3292
+ return "alias";
3293
+ case "&":
3294
+ return "anchor";
3295
+ case "!":
3296
+ return "tag";
3297
+ case "'":
3298
+ return "single-quoted-scalar";
3299
+ case '"':
3300
+ return "double-quoted-scalar";
3301
+ case "|":
3302
+ case ">":
3303
+ return "block-scalar-header";
3304
+ }
3305
+ return null;
3306
+ }
3307
+ function K(s) {
3308
+ switch (s) {
3309
+ case void 0:
3310
+ case " ":
3311
+ case `
3312
+ `:
3313
+ case "\r":
3314
+ case " ":
3315
+ return !0;
3316
+ default:
3317
+ return !1;
3318
+ }
3319
+ }
3320
+ const It = new Set("0123456789ABCDEFabcdef"), Sn = new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()"), Ae = new Set(",[]{}"), Nn = new Set(` ,[]{}
3321
+ \r `), Ge = (s) => !s || Nn.has(s);
3322
+ class On {
3323
+ constructor() {
3324
+ this.atEnd = !1, this.blockScalarIndent = -1, this.blockScalarKeep = !1, this.buffer = "", this.flowKey = !1, this.flowLevel = 0, this.indentNext = 0, this.indentValue = 0, this.lineEndPos = null, this.next = null, this.pos = 0;
3325
+ }
3326
+ /**
3327
+ * Generate YAML tokens from the `source` string. If `incomplete`,
3328
+ * a part of the last line may be left as a buffer for the next call.
3329
+ *
3330
+ * @returns A generator of lexical tokens
3331
+ */
3332
+ *lex(e, t = !1) {
3333
+ if (e) {
3334
+ if (typeof e != "string")
3335
+ throw TypeError("source is not a string");
3336
+ this.buffer = this.buffer ? this.buffer + e : e, this.lineEndPos = null;
3337
+ }
3338
+ this.atEnd = !t;
3339
+ let n = this.next ?? "stream";
3340
+ for (; n && (t || this.hasChars(1)); )
3341
+ n = yield* this.parseNext(n);
3342
+ }
3343
+ atLineEnd() {
3344
+ let e = this.pos, t = this.buffer[e];
3345
+ for (; t === " " || t === " "; )
3346
+ t = this.buffer[++e];
3347
+ return !t || t === "#" || t === `
3348
+ ` ? !0 : t === "\r" ? this.buffer[e + 1] === `
3349
+ ` : !1;
3350
+ }
3351
+ charAt(e) {
3352
+ return this.buffer[this.pos + e];
3353
+ }
3354
+ continueScalar(e) {
3355
+ let t = this.buffer[e];
3356
+ if (this.indentNext > 0) {
3357
+ let n = 0;
3358
+ for (; t === " "; )
3359
+ t = this.buffer[++n + e];
3360
+ if (t === "\r") {
3361
+ const i = this.buffer[n + e + 1];
3362
+ if (i === `
3363
+ ` || !i && !this.atEnd)
3364
+ return e + n + 1;
3365
+ }
3366
+ return t === `
3367
+ ` || n >= this.indentNext || !t && !this.atEnd ? e + n : -1;
3368
+ }
3369
+ if (t === "-" || t === ".") {
3370
+ const n = this.buffer.substr(e, 3);
3371
+ if ((n === "---" || n === "...") && K(this.buffer[e + 3]))
3372
+ return -1;
3373
+ }
3374
+ return e;
3375
+ }
3376
+ getLine() {
3377
+ let e = this.lineEndPos;
3378
+ return (typeof e != "number" || e !== -1 && e < this.pos) && (e = this.buffer.indexOf(`
3379
+ `, this.pos), this.lineEndPos = e), e === -1 ? this.atEnd ? this.buffer.substring(this.pos) : null : (this.buffer[e - 1] === "\r" && (e -= 1), this.buffer.substring(this.pos, e));
3380
+ }
3381
+ hasChars(e) {
3382
+ return this.pos + e <= this.buffer.length;
3383
+ }
3384
+ setNext(e) {
3385
+ return this.buffer = this.buffer.substring(this.pos), this.pos = 0, this.lineEndPos = null, this.next = e, null;
3386
+ }
3387
+ peek(e) {
3388
+ return this.buffer.substr(this.pos, e);
3389
+ }
3390
+ *parseNext(e) {
3391
+ switch (e) {
3392
+ case "stream":
3393
+ return yield* this.parseStream();
3394
+ case "line-start":
3395
+ return yield* this.parseLineStart();
3396
+ case "block-start":
3397
+ return yield* this.parseBlockStart();
3398
+ case "doc":
3399
+ return yield* this.parseDocument();
3400
+ case "flow":
3401
+ return yield* this.parseFlowCollection();
3402
+ case "quoted-scalar":
3403
+ return yield* this.parseQuotedScalar();
3404
+ case "block-scalar":
3405
+ return yield* this.parseBlockScalar();
3406
+ case "plain-scalar":
3407
+ return yield* this.parsePlainScalar();
3408
+ }
3409
+ }
3410
+ *parseStream() {
3411
+ let e = this.getLine();
3412
+ if (e === null)
3413
+ return this.setNext("stream");
3414
+ if (e[0] === cs && (yield* this.pushCount(1), e = e.substring(1)), e[0] === "%") {
3415
+ let t = e.length, n = e.indexOf("#");
3416
+ for (; n !== -1; ) {
3417
+ const r = e[n - 1];
3418
+ if (r === " " || r === " ") {
3419
+ t = n - 1;
3420
+ break;
3421
+ } else
3422
+ n = e.indexOf("#", n + 1);
3423
+ }
3424
+ for (; ; ) {
3425
+ const r = e[t - 1];
3426
+ if (r === " " || r === " ")
3427
+ t -= 1;
3428
+ else
3429
+ break;
3430
+ }
3431
+ const i = (yield* this.pushCount(t)) + (yield* this.pushSpaces(!0));
3432
+ return yield* this.pushCount(e.length - i), this.pushNewline(), "stream";
3433
+ }
3434
+ if (this.atLineEnd()) {
3435
+ const t = yield* this.pushSpaces(!0);
3436
+ return yield* this.pushCount(e.length - t), yield* this.pushNewline(), "stream";
3437
+ }
3438
+ return yield fs, yield* this.parseLineStart();
3439
+ }
3440
+ *parseLineStart() {
3441
+ const e = this.charAt(0);
3442
+ if (!e && !this.atEnd)
3443
+ return this.setNext("line-start");
3444
+ if (e === "-" || e === ".") {
3445
+ if (!this.atEnd && !this.hasChars(4))
3446
+ return this.setNext("line-start");
3447
+ const t = this.peek(3);
3448
+ if ((t === "---" || t === "...") && K(this.charAt(3)))
3449
+ return yield* this.pushCount(3), this.indentValue = 0, this.indentNext = 0, t === "---" ? "doc" : "stream";
3450
+ }
3451
+ return this.indentValue = yield* this.pushSpaces(!1), this.indentNext > this.indentValue && !K(this.charAt(1)) && (this.indentNext = this.indentValue), yield* this.parseBlockStart();
3452
+ }
3453
+ *parseBlockStart() {
3454
+ const [e, t] = this.peek(2);
3455
+ if (!t && !this.atEnd)
3456
+ return this.setNext("block-start");
3457
+ if ((e === "-" || e === "?" || e === ":") && K(t)) {
3458
+ const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(!0));
3459
+ return this.indentNext = this.indentValue + 1, this.indentValue += n, yield* this.parseBlockStart();
3460
+ }
3461
+ return "doc";
3462
+ }
3463
+ *parseDocument() {
3464
+ yield* this.pushSpaces(!0);
3465
+ const e = this.getLine();
3466
+ if (e === null)
3467
+ return this.setNext("doc");
3468
+ let t = yield* this.pushIndicators();
3469
+ switch (e[t]) {
3470
+ case "#":
3471
+ yield* this.pushCount(e.length - t);
3472
+ // fallthrough
3473
+ case void 0:
3474
+ return yield* this.pushNewline(), yield* this.parseLineStart();
3475
+ case "{":
3476
+ case "[":
3477
+ return yield* this.pushCount(1), this.flowKey = !1, this.flowLevel = 1, "flow";
3478
+ case "}":
3479
+ case "]":
3480
+ return yield* this.pushCount(1), "doc";
3481
+ case "*":
3482
+ return yield* this.pushUntil(Ge), "doc";
3483
+ case '"':
3484
+ case "'":
3485
+ return yield* this.parseQuotedScalar();
3486
+ case "|":
3487
+ case ">":
3488
+ return t += yield* this.parseBlockScalarHeader(), t += yield* this.pushSpaces(!0), yield* this.pushCount(e.length - t), yield* this.pushNewline(), yield* this.parseBlockScalar();
3489
+ default:
3490
+ return yield* this.parsePlainScalar();
3491
+ }
3492
+ }
3493
+ *parseFlowCollection() {
3494
+ let e, t, n = -1;
3495
+ do
3496
+ e = yield* this.pushNewline(), e > 0 ? (t = yield* this.pushSpaces(!1), this.indentValue = n = t) : t = 0, t += yield* this.pushSpaces(!0);
3497
+ while (e + t > 0);
3498
+ const i = this.getLine();
3499
+ if (i === null)
3500
+ return this.setNext("flow");
3501
+ if ((n !== -1 && n < this.indentNext && i[0] !== "#" || n === 0 && (i.startsWith("---") || i.startsWith("...")) && K(i[3])) && !(n === this.indentNext - 1 && this.flowLevel === 1 && (i[0] === "]" || i[0] === "}")))
3502
+ return this.flowLevel = 0, yield us, yield* this.parseLineStart();
3503
+ let r = 0;
3504
+ for (; i[r] === ","; )
3505
+ r += yield* this.pushCount(1), r += yield* this.pushSpaces(!0), this.flowKey = !1;
3506
+ switch (r += yield* this.pushIndicators(), i[r]) {
3507
+ case void 0:
3508
+ return "flow";
3509
+ case "#":
3510
+ return yield* this.pushCount(i.length - r), "flow";
3511
+ case "{":
3512
+ case "[":
3513
+ return yield* this.pushCount(1), this.flowKey = !1, this.flowLevel += 1, "flow";
3514
+ case "}":
3515
+ case "]":
3516
+ return yield* this.pushCount(1), this.flowKey = !0, this.flowLevel -= 1, this.flowLevel ? "flow" : "doc";
3517
+ case "*":
3518
+ return yield* this.pushUntil(Ge), "flow";
3519
+ case '"':
3520
+ case "'":
3521
+ return this.flowKey = !0, yield* this.parseQuotedScalar();
3522
+ case ":": {
3523
+ const o = this.charAt(1);
3524
+ if (this.flowKey || K(o) || o === ",")
3525
+ return this.flowKey = !1, yield* this.pushCount(1), yield* this.pushSpaces(!0), "flow";
3526
+ }
3527
+ // fallthrough
3528
+ default:
3529
+ return this.flowKey = !1, yield* this.parsePlainScalar();
3530
+ }
3531
+ }
3532
+ *parseQuotedScalar() {
3533
+ const e = this.charAt(0);
3534
+ let t = this.buffer.indexOf(e, this.pos + 1);
3535
+ if (e === "'")
3536
+ for (; t !== -1 && this.buffer[t + 1] === "'"; )
3537
+ t = this.buffer.indexOf("'", t + 2);
3538
+ else
3539
+ for (; t !== -1; ) {
3540
+ let r = 0;
3541
+ for (; this.buffer[t - 1 - r] === "\\"; )
3542
+ r += 1;
3543
+ if (r % 2 === 0)
3544
+ break;
3545
+ t = this.buffer.indexOf('"', t + 1);
3546
+ }
3547
+ const n = this.buffer.substring(0, t);
3548
+ let i = n.indexOf(`
3549
+ `, this.pos);
3550
+ if (i !== -1) {
3551
+ for (; i !== -1; ) {
3552
+ const r = this.continueScalar(i + 1);
3553
+ if (r === -1)
3554
+ break;
3555
+ i = n.indexOf(`
3556
+ `, r);
3557
+ }
3558
+ i !== -1 && (t = i - (n[i - 1] === "\r" ? 2 : 1));
3559
+ }
3560
+ if (t === -1) {
3561
+ if (!this.atEnd)
3562
+ return this.setNext("quoted-scalar");
3563
+ t = this.buffer.length;
3564
+ }
3565
+ return yield* this.pushToIndex(t + 1, !1), this.flowLevel ? "flow" : "doc";
3566
+ }
3567
+ *parseBlockScalarHeader() {
3568
+ this.blockScalarIndent = -1, this.blockScalarKeep = !1;
3569
+ let e = this.pos;
3570
+ for (; ; ) {
3571
+ const t = this.buffer[++e];
3572
+ if (t === "+")
3573
+ this.blockScalarKeep = !0;
3574
+ else if (t > "0" && t <= "9")
3575
+ this.blockScalarIndent = Number(t) - 1;
3576
+ else if (t !== "-")
3577
+ break;
3578
+ }
3579
+ return yield* this.pushUntil((t) => K(t) || t === "#");
3580
+ }
3581
+ *parseBlockScalar() {
3582
+ let e = this.pos - 1, t = 0, n;
3583
+ e: for (let r = this.pos; n = this.buffer[r]; ++r)
3584
+ switch (n) {
3585
+ case " ":
3586
+ t += 1;
3587
+ break;
3588
+ case `
3589
+ `:
3590
+ e = r, t = 0;
3591
+ break;
3592
+ case "\r": {
3593
+ const o = this.buffer[r + 1];
3594
+ if (!o && !this.atEnd)
3595
+ return this.setNext("block-scalar");
3596
+ if (o === `
3597
+ `)
3598
+ break;
3599
+ }
3600
+ // fallthrough
3601
+ default:
3602
+ break e;
3603
+ }
3604
+ if (!n && !this.atEnd)
3605
+ return this.setNext("block-scalar");
3606
+ if (t >= this.indentNext) {
3607
+ this.blockScalarIndent === -1 ? this.indentNext = t : this.indentNext = this.blockScalarIndent + (this.indentNext === 0 ? 1 : this.indentNext);
3608
+ do {
3609
+ const r = this.continueScalar(e + 1);
3610
+ if (r === -1)
3611
+ break;
3612
+ e = this.buffer.indexOf(`
3613
+ `, r);
3614
+ } while (e !== -1);
3615
+ if (e === -1) {
3616
+ if (!this.atEnd)
3617
+ return this.setNext("block-scalar");
3618
+ e = this.buffer.length;
3619
+ }
3620
+ }
3621
+ let i = e + 1;
3622
+ for (n = this.buffer[i]; n === " "; )
3623
+ n = this.buffer[++i];
3624
+ if (n === " ") {
3625
+ for (; n === " " || n === " " || n === "\r" || n === `
3626
+ `; )
3627
+ n = this.buffer[++i];
3628
+ e = i - 1;
3629
+ } else if (!this.blockScalarKeep)
3630
+ do {
3631
+ let r = e - 1, o = this.buffer[r];
3632
+ o === "\r" && (o = this.buffer[--r]);
3633
+ const l = r;
3634
+ for (; o === " "; )
3635
+ o = this.buffer[--r];
3636
+ if (o === `
3637
+ ` && r >= this.pos && r + 1 + t > l)
3638
+ e = r;
3639
+ else
3640
+ break;
3641
+ } while (!0);
3642
+ return yield Ze, yield* this.pushToIndex(e + 1, !0), yield* this.parseLineStart();
3643
+ }
3644
+ *parsePlainScalar() {
3645
+ const e = this.flowLevel > 0;
3646
+ let t = this.pos - 1, n = this.pos - 1, i;
3647
+ for (; i = this.buffer[++n]; )
3648
+ if (i === ":") {
3649
+ const r = this.buffer[n + 1];
3650
+ if (K(r) || e && Ae.has(r))
3651
+ break;
3652
+ t = n;
3653
+ } else if (K(i)) {
3654
+ let r = this.buffer[n + 1];
3655
+ if (i === "\r" && (r === `
3656
+ ` ? (n += 1, i = `
3657
+ `, r = this.buffer[n + 1]) : t = n), r === "#" || e && Ae.has(r))
3658
+ break;
3659
+ if (i === `
3660
+ `) {
3661
+ const o = this.continueScalar(n + 1);
3662
+ if (o === -1)
3663
+ break;
3664
+ n = Math.max(n, o - 2);
3665
+ }
3666
+ } else {
3667
+ if (e && Ae.has(i))
3668
+ break;
3669
+ t = n;
3670
+ }
3671
+ return !i && !this.atEnd ? this.setNext("plain-scalar") : (yield Ze, yield* this.pushToIndex(t + 1, !0), e ? "flow" : "doc");
3672
+ }
3673
+ *pushCount(e) {
3674
+ return e > 0 ? (yield this.buffer.substr(this.pos, e), this.pos += e, e) : 0;
3675
+ }
3676
+ *pushToIndex(e, t) {
3677
+ const n = this.buffer.slice(this.pos, e);
3678
+ return n ? (yield n, this.pos += n.length, n.length) : (t && (yield ""), 0);
3679
+ }
3680
+ *pushIndicators() {
3681
+ switch (this.charAt(0)) {
3682
+ case "!":
3683
+ return (yield* this.pushTag()) + (yield* this.pushSpaces(!0)) + (yield* this.pushIndicators());
3684
+ case "&":
3685
+ return (yield* this.pushUntil(Ge)) + (yield* this.pushSpaces(!0)) + (yield* this.pushIndicators());
3686
+ case "-":
3687
+ // this is an error
3688
+ case "?":
3689
+ // this is an error outside flow collections
3690
+ case ":": {
3691
+ const e = this.flowLevel > 0, t = this.charAt(1);
3692
+ if (K(t) || e && Ae.has(t))
3693
+ return e ? this.flowKey && (this.flowKey = !1) : this.indentNext = this.indentValue + 1, (yield* this.pushCount(1)) + (yield* this.pushSpaces(!0)) + (yield* this.pushIndicators());
3694
+ }
3695
+ }
3696
+ return 0;
3697
+ }
3698
+ *pushTag() {
3699
+ if (this.charAt(1) === "<") {
3700
+ let e = this.pos + 2, t = this.buffer[e];
3701
+ for (; !K(t) && t !== ">"; )
3702
+ t = this.buffer[++e];
3703
+ return yield* this.pushToIndex(t === ">" ? e + 1 : e, !1);
3704
+ } else {
3705
+ let e = this.pos + 1, t = this.buffer[e];
3706
+ for (; t; )
3707
+ if (Sn.has(t))
3708
+ t = this.buffer[++e];
3709
+ else if (t === "%" && It.has(this.buffer[e + 1]) && It.has(this.buffer[e + 2]))
3710
+ t = this.buffer[e += 3];
3711
+ else
3712
+ break;
3713
+ return yield* this.pushToIndex(e, !1);
3714
+ }
3715
+ }
3716
+ *pushNewline() {
3717
+ const e = this.buffer[this.pos];
3718
+ return e === `
3719
+ ` ? yield* this.pushCount(1) : e === "\r" && this.charAt(1) === `
3720
+ ` ? yield* this.pushCount(2) : 0;
3721
+ }
3722
+ *pushSpaces(e) {
3723
+ let t = this.pos - 1, n;
3724
+ do
3725
+ n = this.buffer[++t];
3726
+ while (n === " " || e && n === " ");
3727
+ const i = t - this.pos;
3728
+ return i > 0 && (yield this.buffer.substr(this.pos, i), this.pos = t), i;
3729
+ }
3730
+ *pushUntil(e) {
3731
+ let t = this.pos, n = this.buffer[t];
3732
+ for (; !e(n); )
3733
+ n = this.buffer[++t];
3734
+ return yield* this.pushToIndex(t, !1);
3735
+ }
3736
+ }
3737
+ class An {
3738
+ constructor() {
3739
+ this.lineStarts = [], this.addNewLine = (e) => this.lineStarts.push(e), this.linePos = (e) => {
3740
+ let t = 0, n = this.lineStarts.length;
3741
+ for (; t < n; ) {
3742
+ const r = t + n >> 1;
3743
+ this.lineStarts[r] < e ? t = r + 1 : n = r;
3744
+ }
3745
+ if (this.lineStarts[t] === e)
3746
+ return { line: t + 1, col: 1 };
3747
+ if (t === 0)
3748
+ return { line: 0, col: e };
3749
+ const i = this.lineStarts[t - 1];
3750
+ return { line: t, col: e - i + 1 };
3751
+ };
3752
+ }
3753
+ }
3754
+ function V(s, e) {
3755
+ for (let t = 0; t < s.length; ++t)
3756
+ if (s[t].type === e)
3757
+ return !0;
3758
+ return !1;
3759
+ }
3760
+ function Lt(s) {
3761
+ for (let e = 0; e < s.length; ++e)
3762
+ switch (s[e].type) {
3763
+ case "space":
3764
+ case "comment":
3765
+ case "newline":
3766
+ break;
3767
+ default:
3768
+ return e;
3769
+ }
3770
+ return -1;
3771
+ }
3772
+ function hs(s) {
3773
+ switch (s?.type) {
3774
+ case "alias":
3775
+ case "scalar":
3776
+ case "single-quoted-scalar":
3777
+ case "double-quoted-scalar":
3778
+ case "flow-collection":
3779
+ return !0;
3780
+ default:
3781
+ return !1;
3782
+ }
3783
+ }
3784
+ function Te(s) {
3785
+ switch (s.type) {
3786
+ case "document":
3787
+ return s.start;
3788
+ case "block-map": {
3789
+ const e = s.items[s.items.length - 1];
3790
+ return e.sep ?? e.start;
3791
+ }
3792
+ case "block-seq":
3793
+ return s.items[s.items.length - 1].start;
3794
+ /* istanbul ignore next should not happen */
3795
+ default:
3796
+ return [];
3797
+ }
3798
+ }
3799
+ function z(s) {
3800
+ if (s.length === 0)
3801
+ return [];
3802
+ let e = s.length;
3803
+ e: for (; --e >= 0; )
3804
+ switch (s[e].type) {
3805
+ case "doc-start":
3806
+ case "explicit-key-ind":
3807
+ case "map-value-ind":
3808
+ case "seq-item-ind":
3809
+ case "newline":
3810
+ break e;
3811
+ }
3812
+ for (; s[++e]?.type === "space"; )
3813
+ ;
3814
+ return s.splice(e, s.length);
3815
+ }
3816
+ function $t(s) {
3817
+ if (s.start.type === "flow-seq-start")
3818
+ for (const e of s.items)
3819
+ e.sep && !e.value && !V(e.start, "explicit-key-ind") && !V(e.sep, "map-value-ind") && (e.key && (e.value = e.key), delete e.key, hs(e.value) ? e.value.end ? Array.prototype.push.apply(e.value.end, e.sep) : e.value.end = e.sep : Array.prototype.push.apply(e.start, e.sep), delete e.sep);
3820
+ }
3821
+ class Tn {
3822
+ /**
3823
+ * @param onNewLine - If defined, called separately with the start position of
3824
+ * each new line (in `parse()`, including the start of input).
3825
+ */
3826
+ constructor(e) {
3827
+ this.atNewLine = !0, this.atScalar = !1, this.indent = 0, this.offset = 0, this.onKeyLine = !1, this.stack = [], this.source = "", this.type = "", this.lexer = new On(), this.onNewLine = e;
3828
+ }
3829
+ /**
3830
+ * Parse `source` as a YAML stream.
3831
+ * If `incomplete`, a part of the last line may be left as a buffer for the next call.
3832
+ *
3833
+ * Errors are not thrown, but yielded as `{ type: 'error', message }` tokens.
3834
+ *
3835
+ * @returns A generator of tokens representing each directive, document, and other structure.
3836
+ */
3837
+ *parse(e, t = !1) {
3838
+ this.onNewLine && this.offset === 0 && this.onNewLine(0);
3839
+ for (const n of this.lexer.lex(e, t))
3840
+ yield* this.next(n);
3841
+ t || (yield* this.end());
3842
+ }
3843
+ /**
3844
+ * Advance the parser by the `source` of one lexical token.
3845
+ */
3846
+ *next(e) {
3847
+ if (this.source = e, this.atScalar) {
3848
+ this.atScalar = !1, yield* this.step(), this.offset += e.length;
3849
+ return;
3850
+ }
3851
+ const t = kn(e);
3852
+ if (t)
3853
+ if (t === "scalar")
3854
+ this.atNewLine = !1, this.atScalar = !0, this.type = "scalar";
3855
+ else {
3856
+ switch (this.type = t, yield* this.step(), t) {
3857
+ case "newline":
3858
+ this.atNewLine = !0, this.indent = 0, this.onNewLine && this.onNewLine(this.offset + e.length);
3859
+ break;
3860
+ case "space":
3861
+ this.atNewLine && e[0] === " " && (this.indent += e.length);
3862
+ break;
3863
+ case "explicit-key-ind":
3864
+ case "map-value-ind":
3865
+ case "seq-item-ind":
3866
+ this.atNewLine && (this.indent += e.length);
3867
+ break;
3868
+ case "doc-mode":
3869
+ case "flow-error-end":
3870
+ return;
3871
+ default:
3872
+ this.atNewLine = !1;
3873
+ }
3874
+ this.offset += e.length;
3875
+ }
3876
+ else {
3877
+ const n = `Not a YAML token: ${e}`;
3878
+ yield* this.pop({ type: "error", offset: this.offset, message: n, source: e }), this.offset += e.length;
3879
+ }
3880
+ }
3881
+ /** Call at end of input to push out any remaining constructions */
3882
+ *end() {
3883
+ for (; this.stack.length > 0; )
3884
+ yield* this.pop();
3885
+ }
3886
+ get sourceToken() {
3887
+ return {
3888
+ type: this.type,
3889
+ offset: this.offset,
3890
+ indent: this.indent,
3891
+ source: this.source
3892
+ };
3893
+ }
3894
+ *step() {
3895
+ const e = this.peek(1);
3896
+ if (this.type === "doc-end" && e?.type !== "doc-end") {
3897
+ for (; this.stack.length > 0; )
3898
+ yield* this.pop();
3899
+ this.stack.push({
3900
+ type: "doc-end",
3901
+ offset: this.offset,
3902
+ source: this.source
3903
+ });
3904
+ return;
3905
+ }
3906
+ if (!e)
3907
+ return yield* this.stream();
3908
+ switch (e.type) {
3909
+ case "document":
3910
+ return yield* this.document(e);
3911
+ case "alias":
3912
+ case "scalar":
3913
+ case "single-quoted-scalar":
3914
+ case "double-quoted-scalar":
3915
+ return yield* this.scalar(e);
3916
+ case "block-scalar":
3917
+ return yield* this.blockScalar(e);
3918
+ case "block-map":
3919
+ return yield* this.blockMap(e);
3920
+ case "block-seq":
3921
+ return yield* this.blockSequence(e);
3922
+ case "flow-collection":
3923
+ return yield* this.flowCollection(e);
3924
+ case "doc-end":
3925
+ return yield* this.documentEnd(e);
3926
+ }
3927
+ yield* this.pop();
3928
+ }
3929
+ peek(e) {
3930
+ return this.stack[this.stack.length - e];
3931
+ }
3932
+ *pop(e) {
3933
+ const t = e ?? this.stack.pop();
3934
+ if (!t)
3935
+ yield { type: "error", offset: this.offset, source: "", message: "Tried to pop an empty stack" };
3936
+ else if (this.stack.length === 0)
3937
+ yield t;
3938
+ else {
3939
+ const n = this.peek(1);
3940
+ switch (t.type === "block-scalar" ? t.indent = "indent" in n ? n.indent : 0 : t.type === "flow-collection" && n.type === "document" && (t.indent = 0), t.type === "flow-collection" && $t(t), n.type) {
3941
+ case "document":
3942
+ n.value = t;
3943
+ break;
3944
+ case "block-scalar":
3945
+ n.props.push(t);
3946
+ break;
3947
+ case "block-map": {
3948
+ const i = n.items[n.items.length - 1];
3949
+ if (i.value) {
3950
+ n.items.push({ start: [], key: t, sep: [] }), this.onKeyLine = !0;
3951
+ return;
3952
+ } else if (i.sep)
3953
+ i.value = t;
3954
+ else {
3955
+ Object.assign(i, { key: t, sep: [] }), this.onKeyLine = !i.explicitKey;
3956
+ return;
3957
+ }
3958
+ break;
3959
+ }
3960
+ case "block-seq": {
3961
+ const i = n.items[n.items.length - 1];
3962
+ i.value ? n.items.push({ start: [], value: t }) : i.value = t;
3963
+ break;
3964
+ }
3965
+ case "flow-collection": {
3966
+ const i = n.items[n.items.length - 1];
3967
+ !i || i.value ? n.items.push({ start: [], key: t, sep: [] }) : i.sep ? i.value = t : Object.assign(i, { key: t, sep: [] });
3968
+ return;
3969
+ }
3970
+ /* istanbul ignore next should not happen */
3971
+ default:
3972
+ yield* this.pop(), yield* this.pop(t);
3973
+ }
3974
+ if ((n.type === "document" || n.type === "block-map" || n.type === "block-seq") && (t.type === "block-map" || t.type === "block-seq")) {
3975
+ const i = t.items[t.items.length - 1];
3976
+ i && !i.sep && !i.value && i.start.length > 0 && Lt(i.start) === -1 && (t.indent === 0 || i.start.every((r) => r.type !== "comment" || r.indent < t.indent)) && (n.type === "document" ? n.end = i.start : n.items.push({ start: i.start }), t.items.splice(-1, 1));
3977
+ }
3978
+ }
3979
+ }
3980
+ *stream() {
3981
+ switch (this.type) {
3982
+ case "directive-line":
3983
+ yield { type: "directive", offset: this.offset, source: this.source };
3984
+ return;
3985
+ case "byte-order-mark":
3986
+ case "space":
3987
+ case "comment":
3988
+ case "newline":
3989
+ yield this.sourceToken;
3990
+ return;
3991
+ case "doc-mode":
3992
+ case "doc-start": {
3993
+ const e = {
3994
+ type: "document",
3995
+ offset: this.offset,
3996
+ start: []
3997
+ };
3998
+ this.type === "doc-start" && e.start.push(this.sourceToken), this.stack.push(e);
3999
+ return;
4000
+ }
4001
+ }
4002
+ yield {
4003
+ type: "error",
4004
+ offset: this.offset,
4005
+ message: `Unexpected ${this.type} token in YAML stream`,
4006
+ source: this.source
4007
+ };
4008
+ }
4009
+ *document(e) {
4010
+ if (e.value)
4011
+ return yield* this.lineEnd(e);
4012
+ switch (this.type) {
4013
+ case "doc-start": {
4014
+ Lt(e.start) !== -1 ? (yield* this.pop(), yield* this.step()) : e.start.push(this.sourceToken);
4015
+ return;
4016
+ }
4017
+ case "anchor":
4018
+ case "tag":
4019
+ case "space":
4020
+ case "comment":
4021
+ case "newline":
4022
+ e.start.push(this.sourceToken);
4023
+ return;
4024
+ }
4025
+ const t = this.startBlockValue(e);
4026
+ t ? this.stack.push(t) : yield {
4027
+ type: "error",
4028
+ offset: this.offset,
4029
+ message: `Unexpected ${this.type} token in YAML document`,
4030
+ source: this.source
4031
+ };
4032
+ }
4033
+ *scalar(e) {
4034
+ if (this.type === "map-value-ind") {
4035
+ const t = Te(this.peek(2)), n = z(t);
4036
+ let i;
4037
+ e.end ? (i = e.end, i.push(this.sourceToken), delete e.end) : i = [this.sourceToken];
4038
+ const r = {
4039
+ type: "block-map",
4040
+ offset: e.offset,
4041
+ indent: e.indent,
4042
+ items: [{ start: n, key: e, sep: i }]
4043
+ };
4044
+ this.onKeyLine = !0, this.stack[this.stack.length - 1] = r;
4045
+ } else
4046
+ yield* this.lineEnd(e);
4047
+ }
4048
+ *blockScalar(e) {
4049
+ switch (this.type) {
4050
+ case "space":
4051
+ case "comment":
4052
+ case "newline":
4053
+ e.props.push(this.sourceToken);
4054
+ return;
4055
+ case "scalar":
4056
+ if (e.source = this.source, this.atNewLine = !0, this.indent = 0, this.onNewLine) {
4057
+ let t = this.source.indexOf(`
4058
+ `) + 1;
4059
+ for (; t !== 0; )
4060
+ this.onNewLine(this.offset + t), t = this.source.indexOf(`
4061
+ `, t) + 1;
4062
+ }
4063
+ yield* this.pop();
4064
+ break;
4065
+ /* istanbul ignore next should not happen */
4066
+ default:
4067
+ yield* this.pop(), yield* this.step();
4068
+ }
4069
+ }
4070
+ *blockMap(e) {
4071
+ const t = e.items[e.items.length - 1];
4072
+ switch (this.type) {
4073
+ case "newline":
4074
+ if (this.onKeyLine = !1, t.value) {
4075
+ const n = "end" in t.value ? t.value.end : void 0;
4076
+ (Array.isArray(n) ? n[n.length - 1] : void 0)?.type === "comment" ? n?.push(this.sourceToken) : e.items.push({ start: [this.sourceToken] });
4077
+ } else t.sep ? t.sep.push(this.sourceToken) : t.start.push(this.sourceToken);
4078
+ return;
4079
+ case "space":
4080
+ case "comment":
4081
+ if (t.value)
4082
+ e.items.push({ start: [this.sourceToken] });
4083
+ else if (t.sep)
4084
+ t.sep.push(this.sourceToken);
4085
+ else {
4086
+ if (this.atIndentedComment(t.start, e.indent)) {
4087
+ const i = e.items[e.items.length - 2]?.value?.end;
4088
+ if (Array.isArray(i)) {
4089
+ Array.prototype.push.apply(i, t.start), i.push(this.sourceToken), e.items.pop();
4090
+ return;
4091
+ }
4092
+ }
4093
+ t.start.push(this.sourceToken);
4094
+ }
4095
+ return;
4096
+ }
4097
+ if (this.indent >= e.indent) {
4098
+ const n = !this.onKeyLine && this.indent === e.indent, i = n && (t.sep || t.explicitKey) && this.type !== "seq-item-ind";
4099
+ let r = [];
4100
+ if (i && t.sep && !t.value) {
4101
+ const o = [];
4102
+ for (let l = 0; l < t.sep.length; ++l) {
4103
+ const a = t.sep[l];
4104
+ switch (a.type) {
4105
+ case "newline":
4106
+ o.push(l);
4107
+ break;
4108
+ case "space":
4109
+ break;
4110
+ case "comment":
4111
+ a.indent > e.indent && (o.length = 0);
4112
+ break;
4113
+ default:
4114
+ o.length = 0;
4115
+ }
4116
+ }
4117
+ o.length >= 2 && (r = t.sep.splice(o[1]));
4118
+ }
4119
+ switch (this.type) {
4120
+ case "anchor":
4121
+ case "tag":
4122
+ i || t.value ? (r.push(this.sourceToken), e.items.push({ start: r }), this.onKeyLine = !0) : t.sep ? t.sep.push(this.sourceToken) : t.start.push(this.sourceToken);
4123
+ return;
4124
+ case "explicit-key-ind":
4125
+ !t.sep && !t.explicitKey ? (t.start.push(this.sourceToken), t.explicitKey = !0) : i || t.value ? (r.push(this.sourceToken), e.items.push({ start: r, explicitKey: !0 })) : this.stack.push({
4126
+ type: "block-map",
4127
+ offset: this.offset,
4128
+ indent: this.indent,
4129
+ items: [{ start: [this.sourceToken], explicitKey: !0 }]
4130
+ }), this.onKeyLine = !0;
4131
+ return;
4132
+ case "map-value-ind":
4133
+ if (t.explicitKey)
4134
+ if (t.sep)
4135
+ if (t.value)
4136
+ e.items.push({ start: [], key: null, sep: [this.sourceToken] });
4137
+ else if (V(t.sep, "map-value-ind"))
4138
+ this.stack.push({
4139
+ type: "block-map",
4140
+ offset: this.offset,
4141
+ indent: this.indent,
4142
+ items: [{ start: r, key: null, sep: [this.sourceToken] }]
4143
+ });
4144
+ else if (hs(t.key) && !V(t.sep, "newline")) {
4145
+ const o = z(t.start), l = t.key, a = t.sep;
4146
+ a.push(this.sourceToken), delete t.key, delete t.sep, this.stack.push({
4147
+ type: "block-map",
4148
+ offset: this.offset,
4149
+ indent: this.indent,
4150
+ items: [{ start: o, key: l, sep: a }]
4151
+ });
4152
+ } else r.length > 0 ? t.sep = t.sep.concat(r, this.sourceToken) : t.sep.push(this.sourceToken);
4153
+ else if (V(t.start, "newline"))
4154
+ Object.assign(t, { key: null, sep: [this.sourceToken] });
4155
+ else {
4156
+ const o = z(t.start);
4157
+ this.stack.push({
4158
+ type: "block-map",
4159
+ offset: this.offset,
4160
+ indent: this.indent,
4161
+ items: [{ start: o, key: null, sep: [this.sourceToken] }]
4162
+ });
4163
+ }
4164
+ else
4165
+ t.sep ? t.value || i ? e.items.push({ start: r, key: null, sep: [this.sourceToken] }) : V(t.sep, "map-value-ind") ? this.stack.push({
4166
+ type: "block-map",
4167
+ offset: this.offset,
4168
+ indent: this.indent,
4169
+ items: [{ start: [], key: null, sep: [this.sourceToken] }]
4170
+ }) : t.sep.push(this.sourceToken) : Object.assign(t, { key: null, sep: [this.sourceToken] });
4171
+ this.onKeyLine = !0;
4172
+ return;
4173
+ case "alias":
4174
+ case "scalar":
4175
+ case "single-quoted-scalar":
4176
+ case "double-quoted-scalar": {
4177
+ const o = this.flowScalar(this.type);
4178
+ i || t.value ? (e.items.push({ start: r, key: o, sep: [] }), this.onKeyLine = !0) : t.sep ? this.stack.push(o) : (Object.assign(t, { key: o, sep: [] }), this.onKeyLine = !0);
4179
+ return;
4180
+ }
4181
+ default: {
4182
+ const o = this.startBlockValue(e);
4183
+ if (o) {
4184
+ if (o.type === "block-seq") {
4185
+ if (!t.explicitKey && t.sep && !V(t.sep, "newline")) {
4186
+ yield* this.pop({
4187
+ type: "error",
4188
+ offset: this.offset,
4189
+ message: "Unexpected block-seq-ind on same line with key",
4190
+ source: this.source
4191
+ });
4192
+ return;
4193
+ }
4194
+ } else n && e.items.push({ start: r });
4195
+ this.stack.push(o);
4196
+ return;
4197
+ }
4198
+ }
4199
+ }
4200
+ }
4201
+ yield* this.pop(), yield* this.step();
4202
+ }
4203
+ *blockSequence(e) {
4204
+ const t = e.items[e.items.length - 1];
4205
+ switch (this.type) {
4206
+ case "newline":
4207
+ if (t.value) {
4208
+ const n = "end" in t.value ? t.value.end : void 0;
4209
+ (Array.isArray(n) ? n[n.length - 1] : void 0)?.type === "comment" ? n?.push(this.sourceToken) : e.items.push({ start: [this.sourceToken] });
4210
+ } else
4211
+ t.start.push(this.sourceToken);
4212
+ return;
4213
+ case "space":
4214
+ case "comment":
4215
+ if (t.value)
4216
+ e.items.push({ start: [this.sourceToken] });
4217
+ else {
4218
+ if (this.atIndentedComment(t.start, e.indent)) {
4219
+ const i = e.items[e.items.length - 2]?.value?.end;
4220
+ if (Array.isArray(i)) {
4221
+ Array.prototype.push.apply(i, t.start), i.push(this.sourceToken), e.items.pop();
4222
+ return;
4223
+ }
4224
+ }
4225
+ t.start.push(this.sourceToken);
4226
+ }
4227
+ return;
4228
+ case "anchor":
4229
+ case "tag":
4230
+ if (t.value || this.indent <= e.indent)
4231
+ break;
4232
+ t.start.push(this.sourceToken);
4233
+ return;
4234
+ case "seq-item-ind":
4235
+ if (this.indent !== e.indent)
4236
+ break;
4237
+ t.value || V(t.start, "seq-item-ind") ? e.items.push({ start: [this.sourceToken] }) : t.start.push(this.sourceToken);
4238
+ return;
4239
+ }
4240
+ if (this.indent > e.indent) {
4241
+ const n = this.startBlockValue(e);
4242
+ if (n) {
4243
+ this.stack.push(n);
4244
+ return;
4245
+ }
4246
+ }
4247
+ yield* this.pop(), yield* this.step();
4248
+ }
4249
+ *flowCollection(e) {
4250
+ const t = e.items[e.items.length - 1];
4251
+ if (this.type === "flow-error-end") {
4252
+ let n;
4253
+ do
4254
+ yield* this.pop(), n = this.peek(1);
4255
+ while (n?.type === "flow-collection");
4256
+ } else if (e.end.length === 0) {
4257
+ switch (this.type) {
4258
+ case "comma":
4259
+ case "explicit-key-ind":
4260
+ !t || t.sep ? e.items.push({ start: [this.sourceToken] }) : t.start.push(this.sourceToken);
4261
+ return;
4262
+ case "map-value-ind":
4263
+ !t || t.value ? e.items.push({ start: [], key: null, sep: [this.sourceToken] }) : t.sep ? t.sep.push(this.sourceToken) : Object.assign(t, { key: null, sep: [this.sourceToken] });
4264
+ return;
4265
+ case "space":
4266
+ case "comment":
4267
+ case "newline":
4268
+ case "anchor":
4269
+ case "tag":
4270
+ !t || t.value ? e.items.push({ start: [this.sourceToken] }) : t.sep ? t.sep.push(this.sourceToken) : t.start.push(this.sourceToken);
4271
+ return;
4272
+ case "alias":
4273
+ case "scalar":
4274
+ case "single-quoted-scalar":
4275
+ case "double-quoted-scalar": {
4276
+ const i = this.flowScalar(this.type);
4277
+ !t || t.value ? e.items.push({ start: [], key: i, sep: [] }) : t.sep ? this.stack.push(i) : Object.assign(t, { key: i, sep: [] });
4278
+ return;
4279
+ }
4280
+ case "flow-map-end":
4281
+ case "flow-seq-end":
4282
+ e.end.push(this.sourceToken);
4283
+ return;
4284
+ }
4285
+ const n = this.startBlockValue(e);
4286
+ n ? this.stack.push(n) : (yield* this.pop(), yield* this.step());
4287
+ } else {
4288
+ const n = this.peek(2);
4289
+ if (n.type === "block-map" && (this.type === "map-value-ind" && n.indent === e.indent || this.type === "newline" && !n.items[n.items.length - 1].sep))
4290
+ yield* this.pop(), yield* this.step();
4291
+ else if (this.type === "map-value-ind" && n.type !== "flow-collection") {
4292
+ const i = Te(n), r = z(i);
4293
+ $t(e);
4294
+ const o = e.end.splice(1, e.end.length);
4295
+ o.push(this.sourceToken);
4296
+ const l = {
4297
+ type: "block-map",
4298
+ offset: e.offset,
4299
+ indent: e.indent,
4300
+ items: [{ start: r, key: e, sep: o }]
4301
+ };
4302
+ this.onKeyLine = !0, this.stack[this.stack.length - 1] = l;
4303
+ } else
4304
+ yield* this.lineEnd(e);
4305
+ }
4306
+ }
4307
+ flowScalar(e) {
4308
+ if (this.onNewLine) {
4309
+ let t = this.source.indexOf(`
4310
+ `) + 1;
4311
+ for (; t !== 0; )
4312
+ this.onNewLine(this.offset + t), t = this.source.indexOf(`
4313
+ `, t) + 1;
4314
+ }
4315
+ return {
4316
+ type: e,
4317
+ offset: this.offset,
4318
+ indent: this.indent,
4319
+ source: this.source
4320
+ };
4321
+ }
4322
+ startBlockValue(e) {
4323
+ switch (this.type) {
4324
+ case "alias":
4325
+ case "scalar":
4326
+ case "single-quoted-scalar":
4327
+ case "double-quoted-scalar":
4328
+ return this.flowScalar(this.type);
4329
+ case "block-scalar-header":
4330
+ return {
4331
+ type: "block-scalar",
4332
+ offset: this.offset,
4333
+ indent: this.indent,
4334
+ props: [this.sourceToken],
4335
+ source: ""
4336
+ };
4337
+ case "flow-map-start":
4338
+ case "flow-seq-start":
4339
+ return {
4340
+ type: "flow-collection",
4341
+ offset: this.offset,
4342
+ indent: this.indent,
4343
+ start: this.sourceToken,
4344
+ items: [],
4345
+ end: []
4346
+ };
4347
+ case "seq-item-ind":
4348
+ return {
4349
+ type: "block-seq",
4350
+ offset: this.offset,
4351
+ indent: this.indent,
4352
+ items: [{ start: [this.sourceToken] }]
4353
+ };
4354
+ case "explicit-key-ind": {
4355
+ this.onKeyLine = !0;
4356
+ const t = Te(e), n = z(t);
4357
+ return n.push(this.sourceToken), {
4358
+ type: "block-map",
4359
+ offset: this.offset,
4360
+ indent: this.indent,
4361
+ items: [{ start: n, explicitKey: !0 }]
4362
+ };
4363
+ }
4364
+ case "map-value-ind": {
4365
+ this.onKeyLine = !0;
4366
+ const t = Te(e), n = z(t);
4367
+ return {
4368
+ type: "block-map",
4369
+ offset: this.offset,
4370
+ indent: this.indent,
4371
+ items: [{ start: n, key: null, sep: [this.sourceToken] }]
4372
+ };
4373
+ }
4374
+ }
4375
+ return null;
4376
+ }
4377
+ atIndentedComment(e, t) {
4378
+ return this.type !== "comment" || this.indent <= t ? !1 : e.every((n) => n.type === "newline" || n.type === "space");
4379
+ }
4380
+ *documentEnd(e) {
4381
+ this.type !== "doc-mode" && (e.end ? e.end.push(this.sourceToken) : e.end = [this.sourceToken], this.type === "newline" && (yield* this.pop()));
4382
+ }
4383
+ *lineEnd(e) {
4384
+ switch (this.type) {
4385
+ case "comma":
4386
+ case "doc-start":
4387
+ case "doc-end":
4388
+ case "flow-seq-end":
4389
+ case "flow-map-end":
4390
+ case "map-value-ind":
4391
+ yield* this.pop(), yield* this.step();
4392
+ break;
4393
+ case "newline":
4394
+ this.onKeyLine = !1;
4395
+ default:
4396
+ e.end ? e.end.push(this.sourceToken) : e.end = [this.sourceToken], this.type === "newline" && (yield* this.pop());
4397
+ }
4398
+ }
4399
+ }
4400
+ function En(s) {
4401
+ const e = s.prettyErrors !== !1;
4402
+ return { lineCounter: s.lineCounter || e && new An() || null, prettyErrors: e };
4403
+ }
4404
+ function In(s, e = {}) {
4405
+ const { lineCounter: t, prettyErrors: n } = En(e), i = new Tn(t?.addNewLine), r = new wn(e);
4406
+ let o = null;
4407
+ for (const l of r.compose(i.parse(s), !0, s.length))
4408
+ if (!o)
4409
+ o = l;
4410
+ else if (o.options.logLevel !== "silent") {
4411
+ o.errors.push(new he(l.range.slice(0, 2), "MULTIPLE_DOCS", "Source contains multiple documents; please use YAML.parseAllDocuments()"));
4412
+ break;
4413
+ }
4414
+ return n && t && (o.errors.forEach(At(s, t)), o.warnings.forEach(At(s, t))), o;
4415
+ }
4416
+ function Ln(s, e, t) {
4417
+ let n;
4418
+ const i = In(s, t);
4419
+ if (!i)
4420
+ return null;
4421
+ if (i.warnings.forEach((r) => qt(i.options.logLevel, r)), i.errors.length > 0) {
4422
+ if (i.options.logLevel !== "silent")
4423
+ throw i.errors[0];
4424
+ i.errors = [];
4425
+ }
4426
+ return i.toJS(Object.assign({ reviver: n }, t));
4427
+ }
4428
+ const $n = `on - daemonized webhook runner
4429
+
4430
+ Usage:
4431
+ on --port <port> [--host <host>] [--config <path>]
4432
+
4433
+ Options:
4434
+ --port, -p HTTP port for incoming webhooks (required)
4435
+ --host, -H Host binding for the HTTP server (default: 127.0.0.1)
4436
+ --config, -c Path to a YAML/JSON config file
4437
+ --help, -h Show this help message
4438
+ `;
4439
+ async function vn(s) {
4440
+ const e = [];
4441
+ for await (const t of s)
4442
+ e.push(Buffer.isBuffer(t) ? t : Buffer.from(t));
4443
+ return Buffer.concat(e).toString("utf8");
4444
+ }
4445
+ function He(s, e, t) {
4446
+ s.statusCode = e, s.setHeader("content-type", "application/json"), s.end(JSON.stringify(t));
4447
+ }
4448
+ function Cn(s) {
4449
+ return bt.isAbsolute(s) ? s : bt.resolve(process.cwd(), s);
4450
+ }
4451
+ async function _n(s) {
4452
+ if (!s)
4453
+ return {};
4454
+ const e = Cn(s), t = await et(e, "utf8");
4455
+ return e.endsWith(".yaml") || e.endsWith(".yml") ? Ln(t) ?? {} : JSON.parse(t);
4456
+ }
4457
+ function Bn(s) {
4458
+ const e = Number.parseInt(s, 10);
4459
+ if (!Number.isInteger(e) || e < 0 || e > 65535)
4460
+ throw new Error(`Invalid --port value '${s}'. Expected an integer from 0 to 65535.`);
4461
+ return e;
4462
+ }
4463
+ function gt(s) {
4464
+ if (!s || typeof s != "object" || Array.isArray(s))
4465
+ throw new Error("Incoming webhook payload must be a JSON object.");
4466
+ return s;
4467
+ }
4468
+ function ds(s, e) {
4469
+ const n = e.trim().replace(/^\$\{/, "").replace(/}$/, "").split(".").filter(Boolean);
4470
+ let i = s;
4471
+ for (const r of n) {
4472
+ if (typeof i != "object" || i === null || !(r in i))
4473
+ return;
4474
+ i = i[r];
4475
+ }
4476
+ return i;
4477
+ }
4478
+ function Mn(s, e) {
4479
+ return s.replace(/\$\{([^}]+)}/g, (t, n) => {
4480
+ const i = ds(e, n);
4481
+ return i == null ? "" : String(i);
4482
+ });
4483
+ }
4484
+ function Pn(s) {
4485
+ return s.split(/\r?\n/u).map((e) => e.trim()).filter((e) => e.length > 0 && !e.startsWith("#")).reduce((e, t) => {
4486
+ const n = t.indexOf("=");
4487
+ if (n <= 0)
4488
+ return e;
4489
+ const i = t.slice(0, n).trim(), r = t.slice(n + 1).trim();
4490
+ return e[i] = r, e;
4491
+ }, {});
4492
+ }
4493
+ async function jn(s) {
4494
+ const e = {};
4495
+ for (const [t, n] of Object.entries(process.env))
4496
+ typeof n == "string" && (e[t] = n);
4497
+ for (const t of s ?? []) {
4498
+ const n = await et(t, "utf8");
4499
+ if (t.endsWith(".json")) {
4500
+ const i = gt(JSON.parse(n));
4501
+ for (const [r, o] of Object.entries(i))
4502
+ o != null && (e[r] = String(o));
4503
+ continue;
4504
+ }
4505
+ Object.assign(e, Pn(n));
4506
+ }
4507
+ return e;
4508
+ }
4509
+ function Kn(s, e) {
4510
+ if (!e)
4511
+ return { ...s };
4512
+ const t = { ...s };
4513
+ for (const [n, i] of Object.entries(e)) {
4514
+ const r = i.startsWith("${") ? i : `\${${i}}`;
4515
+ t[n] = ds({ inputs: t }, r);
4516
+ }
4517
+ return t;
4518
+ }
4519
+ async function Dn(s, e) {
4520
+ await new Promise((t, n) => {
4521
+ const i = ys(s, {
4522
+ env: e,
4523
+ shell: !0,
4524
+ stdio: "inherit"
4525
+ });
4526
+ i.once("error", n), i.once("exit", (r) => {
4527
+ if (r === 0) {
4528
+ t();
4529
+ return;
4530
+ }
4531
+ n(new Error(`Step failed with exit code ${r}: ${s}`));
4532
+ });
4533
+ });
4534
+ }
4535
+ async function ps(s, e) {
4536
+ if (typeof s.source != "string" || typeof s.event != "string")
4537
+ throw new Error("Incoming payload must include string fields 'source' and 'event'.");
4538
+ const t = e.on?.[s.source]?.[s.event];
4539
+ if (!t)
4540
+ throw new Error(`No workflow configured for source '${s.source}' and event '${s.event}'.`);
4541
+ const n = Kn({ ...s }, t.mappings), i = await jn(t.secrets), r = {
4542
+ ...process.env,
4543
+ ...Object.fromEntries(Object.entries(i).map(([l, a]) => [l, String(a)]))
4544
+ }, o = {
4545
+ inputs: n,
4546
+ secrets: i
4547
+ };
4548
+ for (const [l, a] of Object.entries(t.env ?? {}))
4549
+ r[l] = Mn(a, o);
4550
+ t.defaults?.image && (r.ON_DEFAULT_IMAGE = t.defaults.image), t.defaults?.volumes && (r.ON_DEFAULT_VOLUMES = JSON.stringify(t.defaults.volumes)), t.defaults?.args && (r.ON_DEFAULT_ARGS = JSON.stringify(t.defaults.args));
4551
+ for (const l of t.steps ?? [])
4552
+ await Dn(l, r);
4553
+ for (const l of t.dispatch ?? []) {
4554
+ const a = await et(l, "utf8"), c = gt(JSON.parse(a));
4555
+ await ps(c, e);
4556
+ }
4557
+ }
4558
+ function qn(s) {
4559
+ const { values: e } = gs({
4560
+ args: s,
4561
+ options: {
4562
+ port: { type: "string", short: "p" },
4563
+ host: { type: "string", short: "H", default: "127.0.0.1" },
4564
+ config: { type: "string", short: "c" },
4565
+ help: { type: "boolean", short: "h", default: !1 }
4566
+ },
4567
+ allowPositionals: !1
4568
+ });
4569
+ if (e.help)
4570
+ return console.log($n), null;
4571
+ if (!e.port)
4572
+ throw new Error("Missing required option --port.");
4573
+ return {
4574
+ port: Bn(e.port),
4575
+ host: e.host,
4576
+ configPath: e.config
4577
+ };
4578
+ }
4579
+ async function Un(s) {
4580
+ const e = await _n(s.configPath), t = ms(async (i, r) => {
4581
+ if (i.method !== "POST") {
4582
+ He(r, 405, { error: "Only POST webhooks are supported." });
4583
+ return;
4584
+ }
4585
+ try {
4586
+ const o = await vn(i), l = gt(o.length > 0 ? JSON.parse(o) : {});
4587
+ await ps(l, e), He(r, 202, {
4588
+ status: "accepted",
4589
+ source: l.source,
4590
+ event: l.event
4591
+ });
4592
+ } catch (o) {
4593
+ const l = o instanceof Error ? o.message : "Unknown error";
4594
+ He(r, 400, { error: l });
4595
+ }
4596
+ });
4597
+ await new Promise((i, r) => {
4598
+ t.once("error", r), t.listen(s.port, s.host, () => i());
4599
+ });
4600
+ const n = t.address();
4601
+ return n && typeof n == "object" && console.log(`on daemon listening on http://${n.address}:${n.port}`), t;
4602
+ }
4603
+ async function Fn() {
4604
+ try {
4605
+ const s = qn(process.argv.slice(2));
4606
+ if (!s) {
4607
+ process.exitCode = 0;
4608
+ return;
4609
+ }
4610
+ await Un(s);
4611
+ } catch (s) {
4612
+ const e = s instanceof Error ? s.message : String(s);
4613
+ console.error(`on: ${e}`), process.exitCode = 1;
4614
+ }
4615
+ }
4616
+ import.meta.url === `file://${process.argv[1]}` && Fn();
4617
+ export {
4618
+ Fn as main,
4619
+ qn as parseCliOptions,
4620
+ Un as startDaemon
4621
+ };