@caiquecamargo/vite-plugin-netlify-cms 0.0.14 → 0.0.15

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