@dataverse-to-code/test 0.0.0-stage → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/sim.js ADDED
@@ -0,0 +1,4713 @@
1
+ "use strict";
2
+ (() => {
3
+ // ../../node_modules/yaml/browser/dist/nodes/identity.js
4
+ var ALIAS = /* @__PURE__ */ Symbol.for("yaml.alias");
5
+ var DOC = /* @__PURE__ */ Symbol.for("yaml.document");
6
+ var MAP = /* @__PURE__ */ Symbol.for("yaml.map");
7
+ var PAIR = /* @__PURE__ */ Symbol.for("yaml.pair");
8
+ var SCALAR = /* @__PURE__ */ Symbol.for("yaml.scalar");
9
+ var SEQ = /* @__PURE__ */ Symbol.for("yaml.seq");
10
+ var NODE_TYPE = /* @__PURE__ */ Symbol.for("yaml.node.type");
11
+ var isAlias = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === ALIAS;
12
+ var isDocument = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === DOC;
13
+ var isMap = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === MAP;
14
+ var isPair = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === PAIR;
15
+ var isScalar = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SCALAR;
16
+ var isSeq = (node) => !!node && typeof node === "object" && node[NODE_TYPE] === SEQ;
17
+ function isCollection(node) {
18
+ if (node && typeof node === "object")
19
+ switch (node[NODE_TYPE]) {
20
+ case MAP:
21
+ case SEQ:
22
+ return true;
23
+ }
24
+ return false;
25
+ }
26
+ function isNode(node) {
27
+ if (node && typeof node === "object")
28
+ switch (node[NODE_TYPE]) {
29
+ case ALIAS:
30
+ case MAP:
31
+ case SCALAR:
32
+ case SEQ:
33
+ return true;
34
+ }
35
+ return false;
36
+ }
37
+ var hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
38
+
39
+ // ../../node_modules/yaml/browser/dist/visit.js
40
+ var BREAK = /* @__PURE__ */ Symbol("break visit");
41
+ var SKIP = /* @__PURE__ */ Symbol("skip children");
42
+ var REMOVE = /* @__PURE__ */ Symbol("remove node");
43
+ function visit(node, visitor) {
44
+ const visitor_ = initVisitor(visitor);
45
+ if (isDocument(node)) {
46
+ const cd = visit_(null, node.contents, visitor_, Object.freeze([node]));
47
+ if (cd === REMOVE)
48
+ node.contents = null;
49
+ } else
50
+ visit_(null, node, visitor_, Object.freeze([]));
51
+ }
52
+ visit.BREAK = BREAK;
53
+ visit.SKIP = SKIP;
54
+ visit.REMOVE = REMOVE;
55
+ function visit_(key2, node, visitor, path) {
56
+ const ctrl = callVisitor(key2, node, visitor, path);
57
+ if (isNode(ctrl) || isPair(ctrl)) {
58
+ replaceNode(key2, path, ctrl);
59
+ return visit_(key2, ctrl, visitor, path);
60
+ }
61
+ if (typeof ctrl !== "symbol") {
62
+ if (isCollection(node)) {
63
+ path = Object.freeze(path.concat(node));
64
+ for (let i = 0; i < node.items.length; ++i) {
65
+ const ci = visit_(i, node.items[i], visitor, path);
66
+ if (typeof ci === "number")
67
+ i = ci - 1;
68
+ else if (ci === BREAK)
69
+ return BREAK;
70
+ else if (ci === REMOVE) {
71
+ node.items.splice(i, 1);
72
+ i -= 1;
73
+ }
74
+ }
75
+ } else if (isPair(node)) {
76
+ path = Object.freeze(path.concat(node));
77
+ const ck = visit_("key", node.key, visitor, path);
78
+ if (ck === BREAK)
79
+ return BREAK;
80
+ else if (ck === REMOVE)
81
+ node.key = null;
82
+ const cv = visit_("value", node.value, visitor, path);
83
+ if (cv === BREAK)
84
+ return BREAK;
85
+ else if (cv === REMOVE)
86
+ node.value = null;
87
+ }
88
+ }
89
+ return ctrl;
90
+ }
91
+ async function visitAsync(node, visitor) {
92
+ const visitor_ = initVisitor(visitor);
93
+ if (isDocument(node)) {
94
+ const cd = await visitAsync_(null, node.contents, visitor_, Object.freeze([node]));
95
+ if (cd === REMOVE)
96
+ node.contents = null;
97
+ } else
98
+ await visitAsync_(null, node, visitor_, Object.freeze([]));
99
+ }
100
+ visitAsync.BREAK = BREAK;
101
+ visitAsync.SKIP = SKIP;
102
+ visitAsync.REMOVE = REMOVE;
103
+ async function visitAsync_(key2, node, visitor, path) {
104
+ const ctrl = await callVisitor(key2, node, visitor, path);
105
+ if (isNode(ctrl) || isPair(ctrl)) {
106
+ replaceNode(key2, path, ctrl);
107
+ return visitAsync_(key2, ctrl, visitor, path);
108
+ }
109
+ if (typeof ctrl !== "symbol") {
110
+ if (isCollection(node)) {
111
+ path = Object.freeze(path.concat(node));
112
+ for (let i = 0; i < node.items.length; ++i) {
113
+ const ci = await visitAsync_(i, node.items[i], visitor, path);
114
+ if (typeof ci === "number")
115
+ i = ci - 1;
116
+ else if (ci === BREAK)
117
+ return BREAK;
118
+ else if (ci === REMOVE) {
119
+ node.items.splice(i, 1);
120
+ i -= 1;
121
+ }
122
+ }
123
+ } else if (isPair(node)) {
124
+ path = Object.freeze(path.concat(node));
125
+ const ck = await visitAsync_("key", node.key, visitor, path);
126
+ if (ck === BREAK)
127
+ return BREAK;
128
+ else if (ck === REMOVE)
129
+ node.key = null;
130
+ const cv = await visitAsync_("value", node.value, visitor, path);
131
+ if (cv === BREAK)
132
+ return BREAK;
133
+ else if (cv === REMOVE)
134
+ node.value = null;
135
+ }
136
+ }
137
+ return ctrl;
138
+ }
139
+ function initVisitor(visitor) {
140
+ if (typeof visitor === "object" && (visitor.Collection || visitor.Node || visitor.Value)) {
141
+ return Object.assign({
142
+ Alias: visitor.Node,
143
+ Map: visitor.Node,
144
+ Scalar: visitor.Node,
145
+ Seq: visitor.Node
146
+ }, visitor.Value && {
147
+ Map: visitor.Value,
148
+ Scalar: visitor.Value,
149
+ Seq: visitor.Value
150
+ }, visitor.Collection && {
151
+ Map: visitor.Collection,
152
+ Seq: visitor.Collection
153
+ }, visitor);
154
+ }
155
+ return visitor;
156
+ }
157
+ function callVisitor(key2, node, visitor, path) {
158
+ if (typeof visitor === "function")
159
+ return visitor(key2, node, path);
160
+ if (isMap(node))
161
+ return visitor.Map?.(key2, node, path);
162
+ if (isSeq(node))
163
+ return visitor.Seq?.(key2, node, path);
164
+ if (isPair(node))
165
+ return visitor.Pair?.(key2, node, path);
166
+ if (isScalar(node))
167
+ return visitor.Scalar?.(key2, node, path);
168
+ if (isAlias(node))
169
+ return visitor.Alias?.(key2, node, path);
170
+ return void 0;
171
+ }
172
+ function replaceNode(key2, path, node) {
173
+ const parent = path[path.length - 1];
174
+ if (isCollection(parent)) {
175
+ parent.items[key2] = node;
176
+ } else if (isPair(parent)) {
177
+ if (key2 === "key")
178
+ parent.key = node;
179
+ else
180
+ parent.value = node;
181
+ } else if (isDocument(parent)) {
182
+ parent.contents = node;
183
+ } else {
184
+ const pt = isAlias(parent) ? "alias" : "scalar";
185
+ throw new Error(`Cannot replace node with ${pt} parent`);
186
+ }
187
+ }
188
+
189
+ // ../../node_modules/yaml/browser/dist/doc/directives.js
190
+ var escapeChars = {
191
+ "!": "%21",
192
+ ",": "%2C",
193
+ "[": "%5B",
194
+ "]": "%5D",
195
+ "{": "%7B",
196
+ "}": "%7D"
197
+ };
198
+ var escapeTagName = (tn) => tn.replace(/[!,[\]{}]/g, (ch) => escapeChars[ch]);
199
+ var Directives = class _Directives {
200
+ constructor(yaml, tags) {
201
+ this.docStart = null;
202
+ this.docEnd = false;
203
+ this.yaml = Object.assign({}, _Directives.defaultYaml, yaml);
204
+ this.tags = Object.assign({}, _Directives.defaultTags, tags);
205
+ }
206
+ clone() {
207
+ const copy = new _Directives(this.yaml, this.tags);
208
+ copy.docStart = this.docStart;
209
+ return copy;
210
+ }
211
+ /**
212
+ * During parsing, get a Directives instance for the current document and
213
+ * update the stream state according to the current version's spec.
214
+ */
215
+ atDocument() {
216
+ const res = new _Directives(this.yaml, this.tags);
217
+ switch (this.yaml.version) {
218
+ case "1.1":
219
+ this.atNextDocument = true;
220
+ break;
221
+ case "1.2":
222
+ this.atNextDocument = false;
223
+ this.yaml = {
224
+ explicit: _Directives.defaultYaml.explicit,
225
+ version: "1.2"
226
+ };
227
+ this.tags = Object.assign({}, _Directives.defaultTags);
228
+ break;
229
+ }
230
+ return res;
231
+ }
232
+ /**
233
+ * @param onError - May be called even if the action was successful
234
+ * @returns `true` on success
235
+ */
236
+ add(line, onError) {
237
+ if (this.atNextDocument) {
238
+ this.yaml = { explicit: _Directives.defaultYaml.explicit, version: "1.1" };
239
+ this.tags = Object.assign({}, _Directives.defaultTags);
240
+ this.atNextDocument = false;
241
+ }
242
+ const parts = line.trim().split(/[ \t]+/);
243
+ const name = parts.shift();
244
+ switch (name) {
245
+ case "%TAG": {
246
+ if (parts.length !== 2) {
247
+ onError(0, "%TAG directive should contain exactly two parts");
248
+ if (parts.length < 2)
249
+ return false;
250
+ }
251
+ const [handle, prefix] = parts;
252
+ this.tags[handle] = prefix;
253
+ return true;
254
+ }
255
+ case "%YAML": {
256
+ this.yaml.explicit = true;
257
+ if (parts.length !== 1) {
258
+ onError(0, "%YAML directive should contain exactly one part");
259
+ return false;
260
+ }
261
+ const [version] = parts;
262
+ if (version === "1.1" || version === "1.2") {
263
+ this.yaml.version = version;
264
+ return true;
265
+ } else {
266
+ const isValid = /^\d+\.\d+$/.test(version);
267
+ onError(6, `Unsupported YAML version ${version}`, isValid);
268
+ return false;
269
+ }
270
+ }
271
+ default:
272
+ onError(0, `Unknown directive ${name}`, true);
273
+ return false;
274
+ }
275
+ }
276
+ /**
277
+ * Resolves a tag, matching handles to those defined in %TAG directives.
278
+ *
279
+ * @returns Resolved tag, which may also be the non-specific tag `'!'` or a
280
+ * `'!local'` tag, or `null` if unresolvable.
281
+ */
282
+ tagName(source, onError) {
283
+ if (source === "!")
284
+ return "!";
285
+ if (source[0] !== "!") {
286
+ onError(`Not a valid tag: ${source}`);
287
+ return null;
288
+ }
289
+ if (source[1] === "<") {
290
+ const verbatim = source.slice(2, -1);
291
+ if (verbatim === "!" || verbatim === "!!") {
292
+ onError(`Verbatim tags aren't resolved, so ${source} is invalid.`);
293
+ return null;
294
+ }
295
+ if (source[source.length - 1] !== ">")
296
+ onError("Verbatim tags must end with a >");
297
+ return verbatim;
298
+ }
299
+ const [, handle, suffix] = source.match(/^(.*!)([^!]*)$/s);
300
+ if (!suffix)
301
+ onError(`The ${source} tag has no suffix`);
302
+ const prefix = this.tags[handle];
303
+ if (prefix) {
304
+ try {
305
+ return prefix + decodeURIComponent(suffix);
306
+ } catch (error) {
307
+ onError(String(error));
308
+ return null;
309
+ }
310
+ }
311
+ if (handle === "!")
312
+ return source;
313
+ onError(`Could not resolve tag: ${source}`);
314
+ return null;
315
+ }
316
+ /**
317
+ * Given a fully resolved tag, returns its printable string form,
318
+ * taking into account current tag prefixes and defaults.
319
+ */
320
+ tagString(tag) {
321
+ for (const [handle, prefix] of Object.entries(this.tags)) {
322
+ if (tag.startsWith(prefix))
323
+ return handle + escapeTagName(tag.substring(prefix.length));
324
+ }
325
+ return tag[0] === "!" ? tag : `!<${tag}>`;
326
+ }
327
+ toString(doc) {
328
+ const lines = this.yaml.explicit ? [`%YAML ${this.yaml.version || "1.2"}`] : [];
329
+ const tagEntries = Object.entries(this.tags);
330
+ let tagNames;
331
+ if (doc && tagEntries.length > 0 && isNode(doc.contents)) {
332
+ const tags = {};
333
+ visit(doc.contents, (_key, node) => {
334
+ if (isNode(node) && node.tag)
335
+ tags[node.tag] = true;
336
+ });
337
+ tagNames = Object.keys(tags);
338
+ } else
339
+ tagNames = [];
340
+ for (const [handle, prefix] of tagEntries) {
341
+ if (handle === "!!" && prefix === "tag:yaml.org,2002:")
342
+ continue;
343
+ if (!doc || tagNames.some((tn) => tn.startsWith(prefix)))
344
+ lines.push(`%TAG ${handle} ${prefix}`);
345
+ }
346
+ return lines.join("\n");
347
+ }
348
+ };
349
+ Directives.defaultYaml = { explicit: false, version: "1.2" };
350
+ Directives.defaultTags = { "!!": "tag:yaml.org,2002:" };
351
+
352
+ // ../../node_modules/yaml/browser/dist/doc/anchors.js
353
+ function anchorIsValid(anchor) {
354
+ if (/[\x00-\x19\s,[\]{}]/.test(anchor)) {
355
+ const sa = JSON.stringify(anchor);
356
+ const msg = `Anchor must not contain whitespace or control characters: ${sa}`;
357
+ throw new Error(msg);
358
+ }
359
+ return true;
360
+ }
361
+ function anchorNames(root) {
362
+ const anchors = /* @__PURE__ */ new Set();
363
+ visit(root, {
364
+ Value(_key, node) {
365
+ if (node.anchor)
366
+ anchors.add(node.anchor);
367
+ }
368
+ });
369
+ return anchors;
370
+ }
371
+ function findNewAnchor(prefix, exclude) {
372
+ for (let i = 1; true; ++i) {
373
+ const name = `${prefix}${i}`;
374
+ if (!exclude.has(name))
375
+ return name;
376
+ }
377
+ }
378
+ function createNodeAnchors(doc, prefix) {
379
+ const aliasObjects = [];
380
+ const sourceObjects = /* @__PURE__ */ new Map();
381
+ let prevAnchors = null;
382
+ return {
383
+ onAnchor: (source) => {
384
+ aliasObjects.push(source);
385
+ prevAnchors ?? (prevAnchors = anchorNames(doc));
386
+ const anchor = findNewAnchor(prefix, prevAnchors);
387
+ prevAnchors.add(anchor);
388
+ return anchor;
389
+ },
390
+ /**
391
+ * With circular references, the source node is only resolved after all
392
+ * of its child nodes are. This is why anchors are set only after all of
393
+ * the nodes have been created.
394
+ */
395
+ setAnchors: () => {
396
+ for (const source of aliasObjects) {
397
+ const ref = sourceObjects.get(source);
398
+ if (typeof ref === "object" && ref.anchor && (isScalar(ref.node) || isCollection(ref.node))) {
399
+ ref.node.anchor = ref.anchor;
400
+ } else {
401
+ const error = new Error("Failed to resolve repeated object (this should not happen)");
402
+ error.source = source;
403
+ throw error;
404
+ }
405
+ }
406
+ },
407
+ sourceObjects
408
+ };
409
+ }
410
+
411
+ // ../../node_modules/yaml/browser/dist/doc/applyReviver.js
412
+ function applyReviver(reviver, obj, key2, val) {
413
+ if (val && typeof val === "object") {
414
+ if (Array.isArray(val)) {
415
+ for (let i = 0, len = val.length; i < len; ++i) {
416
+ const v0 = val[i];
417
+ const v1 = applyReviver(reviver, val, String(i), v0);
418
+ if (v1 === void 0)
419
+ delete val[i];
420
+ else if (v1 !== v0)
421
+ val[i] = v1;
422
+ }
423
+ } else if (val instanceof Map) {
424
+ for (const k of Array.from(val.keys())) {
425
+ const v0 = val.get(k);
426
+ const v1 = applyReviver(reviver, val, k, v0);
427
+ if (v1 === void 0)
428
+ val.delete(k);
429
+ else if (v1 !== v0)
430
+ val.set(k, v1);
431
+ }
432
+ } else if (val instanceof Set) {
433
+ for (const v0 of Array.from(val)) {
434
+ const v1 = applyReviver(reviver, val, v0, v0);
435
+ if (v1 === void 0)
436
+ val.delete(v0);
437
+ else if (v1 !== v0) {
438
+ val.delete(v0);
439
+ val.add(v1);
440
+ }
441
+ }
442
+ } else {
443
+ for (const [k, v0] of Object.entries(val)) {
444
+ const v1 = applyReviver(reviver, val, k, v0);
445
+ if (v1 === void 0)
446
+ delete val[k];
447
+ else if (v1 !== v0)
448
+ val[k] = v1;
449
+ }
450
+ }
451
+ }
452
+ return reviver.call(obj, key2, val);
453
+ }
454
+
455
+ // ../../node_modules/yaml/browser/dist/nodes/toJS.js
456
+ function toJS(value, arg, ctx) {
457
+ if (Array.isArray(value))
458
+ return value.map((v, i) => toJS(v, String(i), ctx));
459
+ if (value && typeof value.toJSON === "function") {
460
+ if (!ctx || !hasAnchor(value))
461
+ return value.toJSON(arg, ctx);
462
+ const data = { aliasCount: 0, count: 1, res: void 0 };
463
+ ctx.anchors.set(value, data);
464
+ ctx.onCreate = (res2) => {
465
+ data.res = res2;
466
+ delete ctx.onCreate;
467
+ };
468
+ const res = value.toJSON(arg, ctx);
469
+ if (ctx.onCreate)
470
+ ctx.onCreate(res);
471
+ return res;
472
+ }
473
+ if (typeof value === "bigint" && !ctx?.keep)
474
+ return Number(value);
475
+ return value;
476
+ }
477
+
478
+ // ../../node_modules/yaml/browser/dist/nodes/Node.js
479
+ var NodeBase = class {
480
+ constructor(type) {
481
+ Object.defineProperty(this, NODE_TYPE, { value: type });
482
+ }
483
+ /** Create a copy of this node. */
484
+ clone() {
485
+ const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
486
+ if (this.range)
487
+ copy.range = this.range.slice();
488
+ return copy;
489
+ }
490
+ /** A plain JavaScript representation of this node. */
491
+ toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
492
+ if (!isDocument(doc))
493
+ throw new TypeError("A document argument is required");
494
+ const ctx = {
495
+ anchors: /* @__PURE__ */ new Map(),
496
+ doc,
497
+ keep: true,
498
+ mapAsMap: mapAsMap === true,
499
+ mapKeyWarned: false,
500
+ maxAliasCount: typeof maxAliasCount === "number" ? maxAliasCount : 100
501
+ };
502
+ const res = toJS(this, "", ctx);
503
+ if (typeof onAnchor === "function")
504
+ for (const { count, res: res2 } of ctx.anchors.values())
505
+ onAnchor(res2, count);
506
+ return typeof reviver === "function" ? applyReviver(reviver, { "": res }, "", res) : res;
507
+ }
508
+ };
509
+
510
+ // ../../node_modules/yaml/browser/dist/nodes/Alias.js
511
+ var Alias = class extends NodeBase {
512
+ constructor(source) {
513
+ super(ALIAS);
514
+ this.source = source;
515
+ Object.defineProperty(this, "tag", {
516
+ set() {
517
+ throw new Error("Alias nodes cannot have tags");
518
+ }
519
+ });
520
+ }
521
+ /**
522
+ * Resolve the value of this alias within `doc`, finding the last
523
+ * instance of the `source` anchor before this node.
524
+ */
525
+ resolve(doc, ctx) {
526
+ if (ctx?.maxAliasCount === 0)
527
+ throw new ReferenceError("Alias resolution is disabled");
528
+ let nodes;
529
+ if (ctx?.aliasResolveCache) {
530
+ nodes = ctx.aliasResolveCache;
531
+ } else {
532
+ nodes = [];
533
+ visit(doc, {
534
+ Node: (_key, node) => {
535
+ if (isAlias(node) || hasAnchor(node))
536
+ nodes.push(node);
537
+ }
538
+ });
539
+ if (ctx)
540
+ ctx.aliasResolveCache = nodes;
541
+ }
542
+ let found = void 0;
543
+ for (const node of nodes) {
544
+ if (node === this)
545
+ break;
546
+ if (node.anchor === this.source)
547
+ found = node;
548
+ }
549
+ if (found && ctx) {
550
+ const { anchors, doc: doc2, maxAliasCount } = ctx;
551
+ let data = anchors.get(found);
552
+ if (!data) {
553
+ toJS(found, null, ctx);
554
+ data = anchors.get(found);
555
+ }
556
+ if (data?.res === void 0) {
557
+ const msg = "This should not happen: Alias anchor was not resolved?";
558
+ throw new ReferenceError(msg);
559
+ }
560
+ if (maxAliasCount >= 0) {
561
+ data.count += 1;
562
+ if (data.aliasCount === 0)
563
+ data.aliasCount = getAliasCount(doc2, found, anchors);
564
+ if (data.count * data.aliasCount > maxAliasCount) {
565
+ const msg = "Excessive alias count indicates a resource exhaustion attack";
566
+ throw new ReferenceError(msg);
567
+ }
568
+ }
569
+ }
570
+ return found;
571
+ }
572
+ toJSON(_arg, ctx) {
573
+ if (!ctx)
574
+ return { source: this.source };
575
+ const source = this.resolve(ctx.doc, ctx);
576
+ if (!source) {
577
+ const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
578
+ throw new ReferenceError(msg);
579
+ }
580
+ return ctx.anchors.get(source).res;
581
+ }
582
+ toString(ctx, _onComment, _onChompKeep) {
583
+ const src = `*${this.source}`;
584
+ if (ctx) {
585
+ anchorIsValid(this.source);
586
+ if (ctx.options.verifyAliasOrder && !ctx.anchors.has(this.source)) {
587
+ const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
588
+ throw new Error(msg);
589
+ }
590
+ if (ctx.implicitKey)
591
+ return `${src} `;
592
+ }
593
+ return src;
594
+ }
595
+ };
596
+ function getAliasCount(doc, node, anchors) {
597
+ if (isAlias(node)) {
598
+ const source = node.resolve(doc);
599
+ const anchor = anchors && source && anchors.get(source);
600
+ return anchor ? anchor.count * anchor.aliasCount : 0;
601
+ } else if (isCollection(node)) {
602
+ let count = 0;
603
+ for (const item of node.items) {
604
+ const c = getAliasCount(doc, item, anchors);
605
+ if (c > count)
606
+ count = c;
607
+ }
608
+ return count;
609
+ } else if (isPair(node)) {
610
+ const kc = getAliasCount(doc, node.key, anchors);
611
+ const vc = getAliasCount(doc, node.value, anchors);
612
+ return Math.max(kc, vc);
613
+ }
614
+ return 1;
615
+ }
616
+
617
+ // ../../node_modules/yaml/browser/dist/nodes/Scalar.js
618
+ var isScalarValue = (value) => !value || typeof value !== "function" && typeof value !== "object";
619
+ var Scalar = class extends NodeBase {
620
+ constructor(value) {
621
+ super(SCALAR);
622
+ this.value = value;
623
+ }
624
+ toJSON(arg, ctx) {
625
+ return ctx?.keep ? this.value : toJS(this.value, arg, ctx);
626
+ }
627
+ toString() {
628
+ return String(this.value);
629
+ }
630
+ };
631
+ Scalar.BLOCK_FOLDED = "BLOCK_FOLDED";
632
+ Scalar.BLOCK_LITERAL = "BLOCK_LITERAL";
633
+ Scalar.PLAIN = "PLAIN";
634
+ Scalar.QUOTE_DOUBLE = "QUOTE_DOUBLE";
635
+ Scalar.QUOTE_SINGLE = "QUOTE_SINGLE";
636
+
637
+ // ../../node_modules/yaml/browser/dist/doc/createNode.js
638
+ var defaultTagPrefix = "tag:yaml.org,2002:";
639
+ function findTagObject(value, tagName, tags) {
640
+ if (tagName) {
641
+ const match = tags.filter((t) => t.tag === tagName);
642
+ const tagObj = match.find((t) => !t.format) ?? match[0];
643
+ if (!tagObj)
644
+ throw new Error(`Tag ${tagName} not found`);
645
+ return tagObj;
646
+ }
647
+ return tags.find((t) => t.identify?.(value) && !t.format);
648
+ }
649
+ function createNode(value, tagName, ctx) {
650
+ if (isDocument(value))
651
+ value = value.contents;
652
+ if (isNode(value))
653
+ return value;
654
+ if (isPair(value)) {
655
+ const map2 = ctx.schema[MAP].createNode?.(ctx.schema, null, ctx);
656
+ map2.items.push(value);
657
+ return map2;
658
+ }
659
+ if (value instanceof String || value instanceof Number || value instanceof Boolean || typeof BigInt !== "undefined" && value instanceof BigInt) {
660
+ value = value.valueOf();
661
+ }
662
+ const { aliasDuplicateObjects, onAnchor, onTagObj, schema: schema4, sourceObjects } = ctx;
663
+ let ref = void 0;
664
+ if (aliasDuplicateObjects && value && typeof value === "object") {
665
+ ref = sourceObjects.get(value);
666
+ if (ref) {
667
+ ref.anchor ?? (ref.anchor = onAnchor(value));
668
+ return new Alias(ref.anchor);
669
+ } else {
670
+ ref = { anchor: null, node: null };
671
+ sourceObjects.set(value, ref);
672
+ }
673
+ }
674
+ if (tagName?.startsWith("!!"))
675
+ tagName = defaultTagPrefix + tagName.slice(2);
676
+ let tagObj = findTagObject(value, tagName, schema4.tags);
677
+ if (!tagObj) {
678
+ if (value && typeof value.toJSON === "function") {
679
+ value = value.toJSON();
680
+ }
681
+ if (!value || typeof value !== "object") {
682
+ const node2 = new Scalar(value);
683
+ if (ref)
684
+ ref.node = node2;
685
+ return node2;
686
+ }
687
+ tagObj = value instanceof Map ? schema4[MAP] : Symbol.iterator in Object(value) ? schema4[SEQ] : schema4[MAP];
688
+ }
689
+ if (onTagObj) {
690
+ onTagObj(tagObj);
691
+ delete ctx.onTagObj;
692
+ }
693
+ const node = tagObj?.createNode ? tagObj.createNode(ctx.schema, value, ctx) : typeof tagObj?.nodeClass?.from === "function" ? tagObj.nodeClass.from(ctx.schema, value, ctx) : new Scalar(value);
694
+ if (tagName)
695
+ node.tag = tagName;
696
+ else if (!tagObj.default)
697
+ node.tag = tagObj.tag;
698
+ if (ref)
699
+ ref.node = node;
700
+ return node;
701
+ }
702
+
703
+ // ../../node_modules/yaml/browser/dist/nodes/Collection.js
704
+ function collectionFromPath(schema4, path, value) {
705
+ let v = value;
706
+ for (let i = path.length - 1; i >= 0; --i) {
707
+ const k = path[i];
708
+ if (typeof k === "number" && Number.isInteger(k) && k >= 0) {
709
+ const a = [];
710
+ a[k] = v;
711
+ v = a;
712
+ } else {
713
+ v = /* @__PURE__ */ new Map([[k, v]]);
714
+ }
715
+ }
716
+ return createNode(v, void 0, {
717
+ aliasDuplicateObjects: false,
718
+ keepUndefined: false,
719
+ onAnchor: () => {
720
+ throw new Error("This should not happen, please report a bug.");
721
+ },
722
+ schema: schema4,
723
+ sourceObjects: /* @__PURE__ */ new Map()
724
+ });
725
+ }
726
+ var isEmptyPath = (path) => path == null || typeof path === "object" && !!path[Symbol.iterator]().next().done;
727
+ var Collection = class extends NodeBase {
728
+ constructor(type, schema4) {
729
+ super(type);
730
+ Object.defineProperty(this, "schema", {
731
+ value: schema4,
732
+ configurable: true,
733
+ enumerable: false,
734
+ writable: true
735
+ });
736
+ }
737
+ /**
738
+ * Create a copy of this collection.
739
+ *
740
+ * @param schema - If defined, overwrites the original's schema
741
+ */
742
+ clone(schema4) {
743
+ const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
744
+ if (schema4)
745
+ copy.schema = schema4;
746
+ copy.items = copy.items.map((it) => isNode(it) || isPair(it) ? it.clone(schema4) : it);
747
+ if (this.range)
748
+ copy.range = this.range.slice();
749
+ return copy;
750
+ }
751
+ /**
752
+ * Adds a value to the collection. For `!!map` and `!!omap` the value must
753
+ * be a Pair instance or a `{ key, value }` object, which may not have a key
754
+ * that already exists in the map.
755
+ */
756
+ addIn(path, value) {
757
+ if (isEmptyPath(path))
758
+ this.add(value);
759
+ else {
760
+ const [key2, ...rest] = path;
761
+ const node = this.get(key2, true);
762
+ if (isCollection(node))
763
+ node.addIn(rest, value);
764
+ else if (node === void 0 && this.schema)
765
+ this.set(key2, collectionFromPath(this.schema, rest, value));
766
+ else
767
+ throw new Error(`Expected YAML collection at ${key2}. Remaining path: ${rest}`);
768
+ }
769
+ }
770
+ /**
771
+ * Removes a value from the collection.
772
+ * @returns `true` if the item was found and removed.
773
+ */
774
+ deleteIn(path) {
775
+ const [key2, ...rest] = path;
776
+ if (rest.length === 0)
777
+ return this.delete(key2);
778
+ const node = this.get(key2, true);
779
+ if (isCollection(node))
780
+ return node.deleteIn(rest);
781
+ else
782
+ throw new Error(`Expected YAML collection at ${key2}. Remaining path: ${rest}`);
783
+ }
784
+ /**
785
+ * Returns item at `key`, or `undefined` if not found. By default unwraps
786
+ * scalar values from their surrounding node; to disable set `keepScalar` to
787
+ * `true` (collections are always returned intact).
788
+ */
789
+ getIn(path, keepScalar) {
790
+ const [key2, ...rest] = path;
791
+ const node = this.get(key2, true);
792
+ if (rest.length === 0)
793
+ return !keepScalar && isScalar(node) ? node.value : node;
794
+ else
795
+ return isCollection(node) ? node.getIn(rest, keepScalar) : void 0;
796
+ }
797
+ hasAllNullValues(allowScalar) {
798
+ return this.items.every((node) => {
799
+ if (!isPair(node))
800
+ return false;
801
+ const n = node.value;
802
+ return n == null || allowScalar && isScalar(n) && n.value == null && !n.commentBefore && !n.comment && !n.tag;
803
+ });
804
+ }
805
+ /**
806
+ * Checks if the collection includes a value with the key `key`.
807
+ */
808
+ hasIn(path) {
809
+ const [key2, ...rest] = path;
810
+ if (rest.length === 0)
811
+ return this.has(key2);
812
+ const node = this.get(key2, true);
813
+ return isCollection(node) ? node.hasIn(rest) : false;
814
+ }
815
+ /**
816
+ * Sets a value in this collection. For `!!set`, `value` needs to be a
817
+ * boolean to add/remove the item from the set.
818
+ */
819
+ setIn(path, value) {
820
+ const [key2, ...rest] = path;
821
+ if (rest.length === 0) {
822
+ this.set(key2, value);
823
+ } else {
824
+ const node = this.get(key2, true);
825
+ if (isCollection(node))
826
+ node.setIn(rest, value);
827
+ else if (node === void 0 && this.schema)
828
+ this.set(key2, collectionFromPath(this.schema, rest, value));
829
+ else
830
+ throw new Error(`Expected YAML collection at ${key2}. Remaining path: ${rest}`);
831
+ }
832
+ }
833
+ };
834
+
835
+ // ../../node_modules/yaml/browser/dist/stringify/stringifyComment.js
836
+ var stringifyComment = (str) => str.replace(/^(?!$)(?: $)?/gm, "#");
837
+ function indentComment(comment, indent) {
838
+ if (/^\n+$/.test(comment))
839
+ return comment.substring(1);
840
+ return indent ? comment.replace(/^(?! *$)/gm, indent) : comment;
841
+ }
842
+ var lineComment = (str, indent, comment) => str.endsWith("\n") ? indentComment(comment, indent) : comment.includes("\n") ? "\n" + indentComment(comment, indent) : (str.endsWith(" ") ? "" : " ") + comment;
843
+
844
+ // ../../node_modules/yaml/browser/dist/stringify/foldFlowLines.js
845
+ var FOLD_FLOW = "flow";
846
+ var FOLD_BLOCK = "block";
847
+ var FOLD_QUOTED = "quoted";
848
+ function foldFlowLines(text, indent, mode = "flow", { indentAtStart, lineWidth = 80, minContentWidth = 20, onFold, onOverflow } = {}) {
849
+ if (!lineWidth || lineWidth < 0)
850
+ return text;
851
+ if (lineWidth < minContentWidth)
852
+ minContentWidth = 0;
853
+ const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);
854
+ if (text.length <= endStep)
855
+ return text;
856
+ const folds = [];
857
+ const escapedFolds = {};
858
+ let end = lineWidth - indent.length;
859
+ if (typeof indentAtStart === "number") {
860
+ if (indentAtStart > lineWidth - Math.max(2, minContentWidth))
861
+ folds.push(0);
862
+ else
863
+ end = lineWidth - indentAtStart;
864
+ }
865
+ let split = void 0;
866
+ let prev = void 0;
867
+ let overflow = false;
868
+ let i = -1;
869
+ let escStart = -1;
870
+ let escEnd = -1;
871
+ if (mode === FOLD_BLOCK) {
872
+ i = consumeMoreIndentedLines(text, i, indent.length);
873
+ if (i !== -1)
874
+ end = i + endStep;
875
+ }
876
+ for (let ch; ch = text[i += 1]; ) {
877
+ if (mode === FOLD_QUOTED && ch === "\\") {
878
+ escStart = i;
879
+ switch (text[i + 1]) {
880
+ case "x":
881
+ i += 3;
882
+ break;
883
+ case "u":
884
+ i += 5;
885
+ break;
886
+ case "U":
887
+ i += 9;
888
+ break;
889
+ default:
890
+ i += 1;
891
+ }
892
+ escEnd = i;
893
+ }
894
+ if (ch === "\n") {
895
+ if (mode === FOLD_BLOCK)
896
+ i = consumeMoreIndentedLines(text, i, indent.length);
897
+ end = i + indent.length + endStep;
898
+ split = void 0;
899
+ } else {
900
+ if (ch === " " && prev && prev !== " " && prev !== "\n" && prev !== " ") {
901
+ const next = text[i + 1];
902
+ if (next && next !== " " && next !== "\n" && next !== " ")
903
+ split = i;
904
+ }
905
+ if (i >= end) {
906
+ if (split) {
907
+ folds.push(split);
908
+ end = split + endStep;
909
+ split = void 0;
910
+ } else if (mode === FOLD_QUOTED) {
911
+ while (prev === " " || prev === " ") {
912
+ prev = ch;
913
+ ch = text[i += 1];
914
+ overflow = true;
915
+ }
916
+ const j = i > escEnd + 1 ? i - 2 : escStart - 1;
917
+ if (escapedFolds[j])
918
+ return text;
919
+ folds.push(j);
920
+ escapedFolds[j] = true;
921
+ end = j + endStep;
922
+ split = void 0;
923
+ } else {
924
+ overflow = true;
925
+ }
926
+ }
927
+ }
928
+ prev = ch;
929
+ }
930
+ if (overflow && onOverflow)
931
+ onOverflow();
932
+ if (folds.length === 0)
933
+ return text;
934
+ if (onFold)
935
+ onFold();
936
+ let res = text.slice(0, folds[0]);
937
+ for (let i2 = 0; i2 < folds.length; ++i2) {
938
+ const fold = folds[i2];
939
+ const end2 = folds[i2 + 1] || text.length;
940
+ if (fold === 0)
941
+ res = `
942
+ ${indent}${text.slice(0, end2)}`;
943
+ else {
944
+ if (mode === FOLD_QUOTED && escapedFolds[fold])
945
+ res += `${text[fold]}\\`;
946
+ res += `
947
+ ${indent}${text.slice(fold + 1, end2)}`;
948
+ }
949
+ }
950
+ return res;
951
+ }
952
+ function consumeMoreIndentedLines(text, i, indent) {
953
+ let end = i;
954
+ let start = i + 1;
955
+ let ch = text[start];
956
+ while (ch === " " || ch === " ") {
957
+ if (i < start + indent) {
958
+ ch = text[++i];
959
+ } else {
960
+ do {
961
+ ch = text[++i];
962
+ } while (ch && ch !== "\n");
963
+ end = i;
964
+ start = i + 1;
965
+ ch = text[start];
966
+ }
967
+ }
968
+ return end;
969
+ }
970
+
971
+ // ../../node_modules/yaml/browser/dist/stringify/stringifyString.js
972
+ var getFoldOptions = (ctx, isBlock) => ({
973
+ indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
974
+ lineWidth: ctx.options.lineWidth,
975
+ minContentWidth: ctx.options.minContentWidth
976
+ });
977
+ var containsDocumentMarker = (str) => /^(%|---|\.\.\.)/m.test(str);
978
+ function lineLengthOverLimit(str, lineWidth, indentLength) {
979
+ if (!lineWidth || lineWidth < 0)
980
+ return false;
981
+ const limit = lineWidth - indentLength;
982
+ const strLen = str.length;
983
+ if (strLen <= limit)
984
+ return false;
985
+ for (let i = 0, start = 0; i < strLen; ++i) {
986
+ if (str[i] === "\n") {
987
+ if (i - start > limit)
988
+ return true;
989
+ start = i + 1;
990
+ if (strLen - start <= limit)
991
+ return false;
992
+ }
993
+ }
994
+ return true;
995
+ }
996
+ function doubleQuotedString(value, ctx) {
997
+ const json = JSON.stringify(value);
998
+ if (ctx.options.doubleQuotedAsJSON)
999
+ return json;
1000
+ const { implicitKey } = ctx;
1001
+ const minMultiLineLength = ctx.options.doubleQuotedMinMultiLineLength;
1002
+ const indent = ctx.indent || (containsDocumentMarker(value) ? " " : "");
1003
+ let str = "";
1004
+ let start = 0;
1005
+ for (let i = 0, ch = json[i]; ch; ch = json[++i]) {
1006
+ if (ch === " " && json[i + 1] === "\\" && json[i + 2] === "n") {
1007
+ str += json.slice(start, i) + "\\ ";
1008
+ i += 1;
1009
+ start = i;
1010
+ ch = "\\";
1011
+ }
1012
+ if (ch === "\\")
1013
+ switch (json[i + 1]) {
1014
+ case "u":
1015
+ {
1016
+ str += json.slice(start, i);
1017
+ const code = json.substr(i + 2, 4);
1018
+ switch (code) {
1019
+ case "0000":
1020
+ str += "\\0";
1021
+ break;
1022
+ case "0007":
1023
+ str += "\\a";
1024
+ break;
1025
+ case "000b":
1026
+ str += "\\v";
1027
+ break;
1028
+ case "001b":
1029
+ str += "\\e";
1030
+ break;
1031
+ case "0085":
1032
+ str += "\\N";
1033
+ break;
1034
+ case "00a0":
1035
+ str += "\\_";
1036
+ break;
1037
+ case "2028":
1038
+ str += "\\L";
1039
+ break;
1040
+ case "2029":
1041
+ str += "\\P";
1042
+ break;
1043
+ default:
1044
+ if (code.substr(0, 2) === "00")
1045
+ str += "\\x" + code.substr(2);
1046
+ else
1047
+ str += json.substr(i, 6);
1048
+ }
1049
+ i += 5;
1050
+ start = i + 1;
1051
+ }
1052
+ break;
1053
+ case "n":
1054
+ if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) {
1055
+ i += 1;
1056
+ } else {
1057
+ str += json.slice(start, i) + "\n\n";
1058
+ while (json[i + 2] === "\\" && json[i + 3] === "n" && json[i + 4] !== '"') {
1059
+ str += "\n";
1060
+ i += 2;
1061
+ }
1062
+ str += indent;
1063
+ if (json[i + 2] === " ")
1064
+ str += "\\";
1065
+ i += 1;
1066
+ start = i + 1;
1067
+ }
1068
+ break;
1069
+ default:
1070
+ i += 1;
1071
+ }
1072
+ }
1073
+ str = start ? str + json.slice(start) : json;
1074
+ return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx, false));
1075
+ }
1076
+ function singleQuotedString(value, ctx) {
1077
+ if (ctx.options.singleQuote === false || ctx.implicitKey && value.includes("\n") || /[ \t]\n|\n[ \t]/.test(value))
1078
+ return doubleQuotedString(value, ctx);
1079
+ const indent = ctx.indent || (containsDocumentMarker(value) ? " " : "");
1080
+ const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&
1081
+ ${indent}`) + "'";
1082
+ return ctx.implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx, false));
1083
+ }
1084
+ function quotedString(value, ctx) {
1085
+ const { singleQuote } = ctx.options;
1086
+ let qs;
1087
+ if (singleQuote === false)
1088
+ qs = doubleQuotedString;
1089
+ else {
1090
+ const hasDouble = value.includes('"');
1091
+ const hasSingle = value.includes("'");
1092
+ if (hasDouble && !hasSingle)
1093
+ qs = singleQuotedString;
1094
+ else if (hasSingle && !hasDouble)
1095
+ qs = doubleQuotedString;
1096
+ else
1097
+ qs = singleQuote ? singleQuotedString : doubleQuotedString;
1098
+ }
1099
+ return qs(value, ctx);
1100
+ }
1101
+ var blockEndNewlines;
1102
+ try {
1103
+ blockEndNewlines = new RegExp("(^|(?<!\n))\n+(?!\n|$)", "g");
1104
+ } catch {
1105
+ blockEndNewlines = /\n+(?!\n|$)/g;
1106
+ }
1107
+ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
1108
+ const { blockQuote, commentString, lineWidth } = ctx.options;
1109
+ if (!blockQuote || /\n[\t ]+$/.test(value)) {
1110
+ return quotedString(value, ctx);
1111
+ }
1112
+ const indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? " " : "");
1113
+ const literal2 = blockQuote === "literal" ? true : blockQuote === "folded" || type === Scalar.BLOCK_FOLDED ? false : type === Scalar.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, lineWidth, indent.length);
1114
+ if (!value)
1115
+ return literal2 ? "|\n" : ">\n";
1116
+ let chomp;
1117
+ let endStart;
1118
+ for (endStart = value.length; endStart > 0; --endStart) {
1119
+ const ch = value[endStart - 1];
1120
+ if (ch !== "\n" && ch !== " " && ch !== " ")
1121
+ break;
1122
+ }
1123
+ let end = value.substring(endStart);
1124
+ const endNlPos = end.indexOf("\n");
1125
+ if (endNlPos === -1) {
1126
+ chomp = "-";
1127
+ } else if (value === end || endNlPos !== end.length - 1) {
1128
+ chomp = "+";
1129
+ if (onChompKeep)
1130
+ onChompKeep();
1131
+ } else {
1132
+ chomp = "";
1133
+ }
1134
+ if (end) {
1135
+ value = value.slice(0, -end.length);
1136
+ if (end[end.length - 1] === "\n")
1137
+ end = end.slice(0, -1);
1138
+ end = end.replace(blockEndNewlines, `$&${indent}`);
1139
+ }
1140
+ let startWithSpace = false;
1141
+ let startEnd;
1142
+ let startNlPos = -1;
1143
+ for (startEnd = 0; startEnd < value.length; ++startEnd) {
1144
+ const ch = value[startEnd];
1145
+ if (ch === " ")
1146
+ startWithSpace = true;
1147
+ else if (ch === "\n")
1148
+ startNlPos = startEnd;
1149
+ else
1150
+ break;
1151
+ }
1152
+ let start = value.substring(0, startNlPos < startEnd ? startNlPos + 1 : startEnd);
1153
+ if (start) {
1154
+ value = value.substring(start.length);
1155
+ start = start.replace(/\n+/g, `$&${indent}`);
1156
+ }
1157
+ const indentSize = indent ? "2" : "1";
1158
+ let header = (startWithSpace ? indentSize : "") + chomp;
1159
+ if (comment) {
1160
+ header += " " + commentString(comment.replace(/ ?[\r\n]+/g, " "));
1161
+ if (onComment)
1162
+ onComment();
1163
+ }
1164
+ if (!literal2) {
1165
+ const foldedValue = value.replace(/\n+/g, "\n$&").replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, "$1$2").replace(/\n+/g, `$&${indent}`);
1166
+ let literalFallback = false;
1167
+ const foldOptions = getFoldOptions(ctx, true);
1168
+ if (blockQuote !== "folded" && type !== Scalar.BLOCK_FOLDED) {
1169
+ foldOptions.onOverflow = () => {
1170
+ literalFallback = true;
1171
+ };
1172
+ }
1173
+ const body = foldFlowLines(`${start}${foldedValue}${end}`, indent, FOLD_BLOCK, foldOptions);
1174
+ if (!literalFallback)
1175
+ return `>${header}
1176
+ ${indent}${body}`;
1177
+ }
1178
+ value = value.replace(/\n+/g, `$&${indent}`);
1179
+ return `|${header}
1180
+ ${indent}${start}${value}${end}`;
1181
+ }
1182
+ function plainString(item, ctx, onComment, onChompKeep) {
1183
+ const { type, value } = item;
1184
+ const { actualString, implicitKey, indent, indentStep, inFlow } = ctx;
1185
+ if (implicitKey && value.includes("\n") || inFlow && /[[\]{},]/.test(value)) {
1186
+ return quotedString(value, ctx);
1187
+ }
1188
+ if (/^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
1189
+ return implicitKey || inFlow || !value.includes("\n") ? quotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
1190
+ }
1191
+ if (!implicitKey && !inFlow && type !== Scalar.PLAIN && value.includes("\n")) {
1192
+ return blockString(item, ctx, onComment, onChompKeep);
1193
+ }
1194
+ if (containsDocumentMarker(value)) {
1195
+ if (indent === "") {
1196
+ ctx.forceBlockIndent = true;
1197
+ return blockString(item, ctx, onComment, onChompKeep);
1198
+ } else if (implicitKey && indent === indentStep) {
1199
+ return quotedString(value, ctx);
1200
+ }
1201
+ }
1202
+ const str = value.replace(/\n+/g, `$&
1203
+ ${indent}`);
1204
+ if (actualString) {
1205
+ const test = (tag) => tag.default && tag.tag !== "tag:yaml.org,2002:str" && tag.test?.test(str);
1206
+ const { compat, tags } = ctx.doc.schema;
1207
+ if (tags.some(test) || compat?.some(test))
1208
+ return quotedString(value, ctx);
1209
+ }
1210
+ return implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx, false));
1211
+ }
1212
+ function stringifyString(item, ctx, onComment, onChompKeep) {
1213
+ const { implicitKey, inFlow } = ctx;
1214
+ const ss = typeof item.value === "string" ? item : Object.assign({}, item, { value: String(item.value) });
1215
+ let { type } = item;
1216
+ if (type !== Scalar.QUOTE_DOUBLE) {
1217
+ if (/[\x00-\x08\x0b-\x1f\x7f-\x9f\u{D800}-\u{DFFF}]/u.test(ss.value))
1218
+ type = Scalar.QUOTE_DOUBLE;
1219
+ }
1220
+ const _stringify = (_type) => {
1221
+ switch (_type) {
1222
+ case Scalar.BLOCK_FOLDED:
1223
+ case Scalar.BLOCK_LITERAL:
1224
+ return implicitKey || inFlow ? quotedString(ss.value, ctx) : blockString(ss, ctx, onComment, onChompKeep);
1225
+ case Scalar.QUOTE_DOUBLE:
1226
+ return doubleQuotedString(ss.value, ctx);
1227
+ case Scalar.QUOTE_SINGLE:
1228
+ return singleQuotedString(ss.value, ctx);
1229
+ case Scalar.PLAIN:
1230
+ return plainString(ss, ctx, onComment, onChompKeep);
1231
+ default:
1232
+ return null;
1233
+ }
1234
+ };
1235
+ let res = _stringify(type);
1236
+ if (res === null) {
1237
+ const { defaultKeyType, defaultStringType } = ctx.options;
1238
+ const t = implicitKey && defaultKeyType || defaultStringType;
1239
+ res = _stringify(t);
1240
+ if (res === null)
1241
+ throw new Error(`Unsupported default string type ${t}`);
1242
+ }
1243
+ return res;
1244
+ }
1245
+
1246
+ // ../../node_modules/yaml/browser/dist/stringify/stringify.js
1247
+ function createStringifyContext(doc, options) {
1248
+ const opt = Object.assign({
1249
+ blockQuote: true,
1250
+ commentString: stringifyComment,
1251
+ defaultKeyType: null,
1252
+ defaultStringType: "PLAIN",
1253
+ directives: null,
1254
+ doubleQuotedAsJSON: false,
1255
+ doubleQuotedMinMultiLineLength: 40,
1256
+ falseStr: "false",
1257
+ flowCollectionPadding: true,
1258
+ indentSeq: true,
1259
+ lineWidth: 80,
1260
+ minContentWidth: 20,
1261
+ nullStr: "null",
1262
+ simpleKeys: false,
1263
+ singleQuote: null,
1264
+ trailingComma: false,
1265
+ trueStr: "true",
1266
+ verifyAliasOrder: true
1267
+ }, doc.schema.toStringOptions, options);
1268
+ let inFlow;
1269
+ switch (opt.collectionStyle) {
1270
+ case "block":
1271
+ inFlow = false;
1272
+ break;
1273
+ case "flow":
1274
+ inFlow = true;
1275
+ break;
1276
+ default:
1277
+ inFlow = null;
1278
+ }
1279
+ return {
1280
+ anchors: /* @__PURE__ */ new Set(),
1281
+ doc,
1282
+ flowCollectionPadding: opt.flowCollectionPadding ? " " : "",
1283
+ indent: "",
1284
+ indentStep: typeof opt.indent === "number" ? " ".repeat(opt.indent) : " ",
1285
+ inFlow,
1286
+ options: opt
1287
+ };
1288
+ }
1289
+ function getTagObject(tags, item) {
1290
+ if (item.tag) {
1291
+ const match = tags.filter((t) => t.tag === item.tag);
1292
+ if (match.length > 0)
1293
+ return match.find((t) => t.format === item.format) ?? match[0];
1294
+ }
1295
+ let tagObj = void 0;
1296
+ let obj;
1297
+ if (isScalar(item)) {
1298
+ obj = item.value;
1299
+ let match = tags.filter((t) => t.identify?.(obj));
1300
+ if (match.length > 1) {
1301
+ const testMatch = match.filter((t) => t.test);
1302
+ if (testMatch.length > 0)
1303
+ match = testMatch;
1304
+ }
1305
+ tagObj = match.find((t) => t.format === item.format) ?? match.find((t) => !t.format);
1306
+ } else {
1307
+ obj = item;
1308
+ tagObj = tags.find((t) => t.nodeClass && obj instanceof t.nodeClass);
1309
+ }
1310
+ if (!tagObj) {
1311
+ const name = obj?.constructor?.name ?? (obj === null ? "null" : typeof obj);
1312
+ throw new Error(`Tag not resolved for ${name} value`);
1313
+ }
1314
+ return tagObj;
1315
+ }
1316
+ function stringifyProps(node, tagObj, { anchors, doc }) {
1317
+ if (!doc.directives)
1318
+ return "";
1319
+ const props = [];
1320
+ const anchor = (isScalar(node) || isCollection(node)) && node.anchor;
1321
+ if (anchor && anchorIsValid(anchor)) {
1322
+ anchors.add(anchor);
1323
+ props.push(`&${anchor}`);
1324
+ }
1325
+ const tag = node.tag ?? (tagObj.default ? null : tagObj.tag);
1326
+ if (tag)
1327
+ props.push(doc.directives.tagString(tag));
1328
+ return props.join(" ");
1329
+ }
1330
+ function stringify(item, ctx, onComment, onChompKeep) {
1331
+ if (isPair(item))
1332
+ return item.toString(ctx, onComment, onChompKeep);
1333
+ if (isAlias(item)) {
1334
+ if (ctx.doc.directives)
1335
+ return item.toString(ctx);
1336
+ if (ctx.resolvedAliases?.has(item)) {
1337
+ throw new TypeError(`Cannot stringify circular structure without alias nodes`);
1338
+ } else {
1339
+ if (ctx.resolvedAliases)
1340
+ ctx.resolvedAliases.add(item);
1341
+ else
1342
+ ctx.resolvedAliases = /* @__PURE__ */ new Set([item]);
1343
+ item = item.resolve(ctx.doc);
1344
+ }
1345
+ }
1346
+ let tagObj = void 0;
1347
+ const node = isNode(item) ? item : ctx.doc.createNode(item, { onTagObj: (o) => tagObj = o });
1348
+ tagObj ?? (tagObj = getTagObject(ctx.doc.schema.tags, node));
1349
+ const props = stringifyProps(node, tagObj, ctx);
1350
+ if (props.length > 0)
1351
+ ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
1352
+ const str = typeof tagObj.stringify === "function" ? tagObj.stringify(node, ctx, onComment, onChompKeep) : isScalar(node) ? stringifyString(node, ctx, onComment, onChompKeep) : node.toString(ctx, onComment, onChompKeep);
1353
+ if (!props)
1354
+ return str;
1355
+ return isScalar(node) || str[0] === "{" || str[0] === "[" ? `${props} ${str}` : `${props}
1356
+ ${ctx.indent}${str}`;
1357
+ }
1358
+
1359
+ // ../../node_modules/yaml/browser/dist/stringify/stringifyPair.js
1360
+ function stringifyPair({ key: key2, value }, ctx, onComment, onChompKeep) {
1361
+ const { allNullValues, doc, indent, indentStep, options: { commentString, indentSeq, simpleKeys } } = ctx;
1362
+ let keyComment = isNode(key2) && key2.comment || null;
1363
+ if (simpleKeys) {
1364
+ if (keyComment) {
1365
+ throw new Error("With simple keys, key nodes cannot have comments");
1366
+ }
1367
+ if (isCollection(key2) || !isNode(key2) && typeof key2 === "object") {
1368
+ const msg = "With simple keys, collection cannot be used as a key value";
1369
+ throw new Error(msg);
1370
+ }
1371
+ }
1372
+ let explicitKey = !simpleKeys && (!key2 || keyComment && value == null && !ctx.inFlow || isCollection(key2) || (isScalar(key2) ? key2.type === Scalar.BLOCK_FOLDED || key2.type === Scalar.BLOCK_LITERAL : typeof key2 === "object"));
1373
+ ctx = Object.assign({}, ctx, {
1374
+ allNullValues: false,
1375
+ implicitKey: !explicitKey && (simpleKeys || !allNullValues),
1376
+ indent: indent + indentStep
1377
+ });
1378
+ let keyCommentDone = false;
1379
+ let chompKeep = false;
1380
+ let str = stringify(key2, ctx, () => keyCommentDone = true, () => chompKeep = true);
1381
+ if (!explicitKey && !ctx.inFlow && str.length > 1024) {
1382
+ if (simpleKeys)
1383
+ throw new Error("With simple keys, single line scalar must not span more than 1024 characters");
1384
+ explicitKey = true;
1385
+ }
1386
+ if (ctx.inFlow) {
1387
+ if (allNullValues || value == null) {
1388
+ if (keyCommentDone && onComment)
1389
+ onComment();
1390
+ return str === "" ? "?" : explicitKey ? `? ${str}` : str;
1391
+ }
1392
+ } else if (allNullValues && !simpleKeys || value == null && explicitKey) {
1393
+ str = `? ${str}`;
1394
+ if (keyComment && !keyCommentDone) {
1395
+ str += lineComment(str, ctx.indent, commentString(keyComment));
1396
+ } else if (chompKeep && onChompKeep)
1397
+ onChompKeep();
1398
+ return str;
1399
+ }
1400
+ if (keyCommentDone)
1401
+ keyComment = null;
1402
+ if (explicitKey) {
1403
+ if (keyComment)
1404
+ str += lineComment(str, ctx.indent, commentString(keyComment));
1405
+ str = `? ${str}
1406
+ ${indent}:`;
1407
+ } else {
1408
+ str = `${str}:`;
1409
+ if (keyComment)
1410
+ str += lineComment(str, ctx.indent, commentString(keyComment));
1411
+ }
1412
+ let vsb, vcb, valueComment;
1413
+ if (isNode(value)) {
1414
+ vsb = !!value.spaceBefore;
1415
+ vcb = value.commentBefore;
1416
+ valueComment = value.comment;
1417
+ } else {
1418
+ vsb = false;
1419
+ vcb = null;
1420
+ valueComment = null;
1421
+ if (value && typeof value === "object")
1422
+ value = doc.createNode(value);
1423
+ }
1424
+ ctx.implicitKey = false;
1425
+ if (!explicitKey && !keyComment && isScalar(value))
1426
+ ctx.indentAtStart = str.length + 1;
1427
+ chompKeep = false;
1428
+ if (!indentSeq && indentStep.length >= 2 && !ctx.inFlow && !explicitKey && isSeq(value) && !value.flow && !value.tag && !value.anchor) {
1429
+ ctx.indent = ctx.indent.substring(2);
1430
+ }
1431
+ let valueCommentDone = false;
1432
+ const valueStr = stringify(value, ctx, () => valueCommentDone = true, () => chompKeep = true);
1433
+ let ws = " ";
1434
+ if (keyComment || vsb || vcb) {
1435
+ ws = vsb ? "\n" : "";
1436
+ if (vcb) {
1437
+ const cs = commentString(vcb);
1438
+ ws += `
1439
+ ${indentComment(cs, ctx.indent)}`;
1440
+ }
1441
+ if (valueStr === "" && !ctx.inFlow) {
1442
+ if (ws === "\n" && valueComment)
1443
+ ws = "\n\n";
1444
+ } else {
1445
+ ws += `
1446
+ ${ctx.indent}`;
1447
+ }
1448
+ } else if (!explicitKey && isCollection(value)) {
1449
+ const vs0 = valueStr[0];
1450
+ const nl0 = valueStr.indexOf("\n");
1451
+ const hasNewline = nl0 !== -1;
1452
+ const flow = ctx.inFlow ?? value.flow ?? value.items.length === 0;
1453
+ if (hasNewline || !flow) {
1454
+ let hasPropsLine = false;
1455
+ if (hasNewline && (vs0 === "&" || vs0 === "!")) {
1456
+ let sp0 = valueStr.indexOf(" ");
1457
+ if (vs0 === "&" && sp0 !== -1 && sp0 < nl0 && valueStr[sp0 + 1] === "!") {
1458
+ sp0 = valueStr.indexOf(" ", sp0 + 1);
1459
+ }
1460
+ if (sp0 === -1 || nl0 < sp0)
1461
+ hasPropsLine = true;
1462
+ }
1463
+ if (!hasPropsLine)
1464
+ ws = `
1465
+ ${ctx.indent}`;
1466
+ }
1467
+ } else if (valueStr === "" || valueStr[0] === "\n") {
1468
+ ws = "";
1469
+ }
1470
+ str += ws + valueStr;
1471
+ if (ctx.inFlow) {
1472
+ if (valueCommentDone && onComment)
1473
+ onComment();
1474
+ } else if (valueComment && !valueCommentDone) {
1475
+ str += lineComment(str, ctx.indent, commentString(valueComment));
1476
+ } else if (chompKeep && onChompKeep) {
1477
+ onChompKeep();
1478
+ }
1479
+ return str;
1480
+ }
1481
+
1482
+ // ../../node_modules/yaml/browser/dist/log.js
1483
+ function warn(logLevel, warning) {
1484
+ if (logLevel === "debug" || logLevel === "warn") {
1485
+ console.warn(warning);
1486
+ }
1487
+ }
1488
+
1489
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js
1490
+ var MERGE_KEY = "<<";
1491
+ var merge = {
1492
+ identify: (value) => value === MERGE_KEY || typeof value === "symbol" && value.description === MERGE_KEY,
1493
+ default: "key",
1494
+ tag: "tag:yaml.org,2002:merge",
1495
+ test: /^<<$/,
1496
+ resolve: () => Object.assign(new Scalar(Symbol(MERGE_KEY)), {
1497
+ addToJSMap: addMergeToJSMap
1498
+ }),
1499
+ stringify: () => MERGE_KEY
1500
+ };
1501
+ var isMergeKey = (ctx, key2) => (merge.identify(key2) || isScalar(key2) && (!key2.type || key2.type === Scalar.PLAIN) && merge.identify(key2.value)) && ctx?.doc.schema.tags.some((tag) => tag.tag === merge.tag && tag.default);
1502
+ function addMergeToJSMap(ctx, map2, value) {
1503
+ const source = resolveAliasValue(ctx, value);
1504
+ if (isSeq(source))
1505
+ for (const it of source.items)
1506
+ mergeValue(ctx, map2, it);
1507
+ else if (Array.isArray(source))
1508
+ for (const it of source)
1509
+ mergeValue(ctx, map2, it);
1510
+ else
1511
+ mergeValue(ctx, map2, source);
1512
+ }
1513
+ function mergeValue(ctx, map2, value) {
1514
+ const source = resolveAliasValue(ctx, value);
1515
+ if (!isMap(source))
1516
+ throw new Error("Merge sources must be maps or map aliases");
1517
+ const srcMap = source.toJSON(null, ctx, Map);
1518
+ for (const [key2, value2] of srcMap) {
1519
+ if (map2 instanceof Map) {
1520
+ if (!map2.has(key2))
1521
+ map2.set(key2, value2);
1522
+ } else if (map2 instanceof Set) {
1523
+ map2.add(key2);
1524
+ } else if (!Object.prototype.hasOwnProperty.call(map2, key2)) {
1525
+ Object.defineProperty(map2, key2, {
1526
+ value: value2,
1527
+ writable: true,
1528
+ enumerable: true,
1529
+ configurable: true
1530
+ });
1531
+ }
1532
+ }
1533
+ return map2;
1534
+ }
1535
+ function resolveAliasValue(ctx, value) {
1536
+ return ctx && isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
1537
+ }
1538
+
1539
+ // ../../node_modules/yaml/browser/dist/nodes/addPairToJSMap.js
1540
+ function addPairToJSMap(ctx, map2, { key: key2, value }) {
1541
+ if (isNode(key2) && key2.addToJSMap)
1542
+ key2.addToJSMap(ctx, map2, value);
1543
+ else if (isMergeKey(ctx, key2))
1544
+ addMergeToJSMap(ctx, map2, value);
1545
+ else {
1546
+ const jsKey = toJS(key2, "", ctx);
1547
+ if (map2 instanceof Map) {
1548
+ map2.set(jsKey, toJS(value, jsKey, ctx));
1549
+ } else if (map2 instanceof Set) {
1550
+ map2.add(jsKey);
1551
+ } else {
1552
+ const stringKey = stringifyKey(key2, jsKey, ctx);
1553
+ const jsValue = toJS(value, stringKey, ctx);
1554
+ if (stringKey in map2)
1555
+ Object.defineProperty(map2, stringKey, {
1556
+ value: jsValue,
1557
+ writable: true,
1558
+ enumerable: true,
1559
+ configurable: true
1560
+ });
1561
+ else
1562
+ map2[stringKey] = jsValue;
1563
+ }
1564
+ }
1565
+ return map2;
1566
+ }
1567
+ function stringifyKey(key2, jsKey, ctx) {
1568
+ if (jsKey === null)
1569
+ return "";
1570
+ if (typeof jsKey !== "object")
1571
+ return String(jsKey);
1572
+ if (isNode(key2) && ctx?.doc) {
1573
+ const strCtx = createStringifyContext(ctx.doc, {});
1574
+ strCtx.anchors = /* @__PURE__ */ new Set();
1575
+ for (const node of ctx.anchors.keys())
1576
+ strCtx.anchors.add(node.anchor);
1577
+ strCtx.inFlow = true;
1578
+ strCtx.inStringifyKey = true;
1579
+ const strKey = key2.toString(strCtx);
1580
+ if (!ctx.mapKeyWarned) {
1581
+ let jsonStr = JSON.stringify(strKey);
1582
+ if (jsonStr.length > 40)
1583
+ jsonStr = jsonStr.substring(0, 36) + '..."';
1584
+ warn(ctx.doc.options.logLevel, `Keys with collection values will be stringified due to JS Object restrictions: ${jsonStr}. Set mapAsMap: true to use object keys.`);
1585
+ ctx.mapKeyWarned = true;
1586
+ }
1587
+ return strKey;
1588
+ }
1589
+ return JSON.stringify(jsKey);
1590
+ }
1591
+
1592
+ // ../../node_modules/yaml/browser/dist/nodes/Pair.js
1593
+ function createPair(key2, value, ctx) {
1594
+ const k = createNode(key2, void 0, ctx);
1595
+ const v = createNode(value, void 0, ctx);
1596
+ return new Pair(k, v);
1597
+ }
1598
+ var Pair = class _Pair {
1599
+ constructor(key2, value = null) {
1600
+ Object.defineProperty(this, NODE_TYPE, { value: PAIR });
1601
+ this.key = key2;
1602
+ this.value = value;
1603
+ }
1604
+ clone(schema4) {
1605
+ let { key: key2, value } = this;
1606
+ if (isNode(key2))
1607
+ key2 = key2.clone(schema4);
1608
+ if (isNode(value))
1609
+ value = value.clone(schema4);
1610
+ return new _Pair(key2, value);
1611
+ }
1612
+ toJSON(_, ctx) {
1613
+ const pair = ctx?.mapAsMap ? /* @__PURE__ */ new Map() : {};
1614
+ return addPairToJSMap(ctx, pair, this);
1615
+ }
1616
+ toString(ctx, onComment, onChompKeep) {
1617
+ return ctx?.doc ? stringifyPair(this, ctx, onComment, onChompKeep) : JSON.stringify(this);
1618
+ }
1619
+ };
1620
+
1621
+ // ../../node_modules/yaml/browser/dist/stringify/stringifyCollection.js
1622
+ function stringifyCollection(collection, ctx, options) {
1623
+ const flow = ctx.inFlow ?? collection.flow;
1624
+ const stringify4 = flow ? stringifyFlowCollection : stringifyBlockCollection;
1625
+ return stringify4(collection, ctx, options);
1626
+ }
1627
+ function stringifyBlockCollection({ comment, items }, ctx, { blockItemPrefix, flowChars, itemIndent, onChompKeep, onComment }) {
1628
+ const { indent, options: { commentString } } = ctx;
1629
+ const itemCtx = Object.assign({}, ctx, { indent: itemIndent, type: null });
1630
+ let chompKeep = false;
1631
+ const lines = [];
1632
+ for (let i = 0; i < items.length; ++i) {
1633
+ const item = items[i];
1634
+ let comment2 = null;
1635
+ if (isNode(item)) {
1636
+ if (!chompKeep && item.spaceBefore)
1637
+ lines.push("");
1638
+ addCommentBefore(ctx, lines, item.commentBefore, chompKeep);
1639
+ if (item.comment)
1640
+ comment2 = item.comment;
1641
+ } else if (isPair(item)) {
1642
+ const ik = isNode(item.key) ? item.key : null;
1643
+ if (ik) {
1644
+ if (!chompKeep && ik.spaceBefore)
1645
+ lines.push("");
1646
+ addCommentBefore(ctx, lines, ik.commentBefore, chompKeep);
1647
+ }
1648
+ }
1649
+ chompKeep = false;
1650
+ let str2 = stringify(item, itemCtx, () => comment2 = null, () => chompKeep = true);
1651
+ if (comment2)
1652
+ str2 += lineComment(str2, itemIndent, commentString(comment2));
1653
+ if (chompKeep && comment2)
1654
+ chompKeep = false;
1655
+ lines.push(blockItemPrefix + str2);
1656
+ }
1657
+ let str;
1658
+ if (lines.length === 0) {
1659
+ str = flowChars.start + flowChars.end;
1660
+ } else {
1661
+ str = lines[0];
1662
+ for (let i = 1; i < lines.length; ++i) {
1663
+ const line = lines[i];
1664
+ str += line ? `
1665
+ ${indent}${line}` : "\n";
1666
+ }
1667
+ }
1668
+ if (comment) {
1669
+ str += "\n" + indentComment(commentString(comment), indent);
1670
+ if (onComment)
1671
+ onComment();
1672
+ } else if (chompKeep && onChompKeep)
1673
+ onChompKeep();
1674
+ return str;
1675
+ }
1676
+ function stringifyFlowCollection({ items }, ctx, { flowChars, itemIndent }) {
1677
+ const { indent, indentStep, flowCollectionPadding: fcPadding, options: { commentString } } = ctx;
1678
+ itemIndent += indentStep;
1679
+ const itemCtx = Object.assign({}, ctx, {
1680
+ indent: itemIndent,
1681
+ inFlow: true,
1682
+ type: null
1683
+ });
1684
+ let reqNewline = false;
1685
+ let linesAtValue = 0;
1686
+ const lines = [];
1687
+ for (let i = 0; i < items.length; ++i) {
1688
+ const item = items[i];
1689
+ let comment = null;
1690
+ if (isNode(item)) {
1691
+ if (item.spaceBefore)
1692
+ lines.push("");
1693
+ addCommentBefore(ctx, lines, item.commentBefore, false);
1694
+ if (item.comment)
1695
+ comment = item.comment;
1696
+ } else if (isPair(item)) {
1697
+ const ik = isNode(item.key) ? item.key : null;
1698
+ if (ik) {
1699
+ if (ik.spaceBefore)
1700
+ lines.push("");
1701
+ addCommentBefore(ctx, lines, ik.commentBefore, false);
1702
+ if (ik.comment)
1703
+ reqNewline = true;
1704
+ }
1705
+ const iv = isNode(item.value) ? item.value : null;
1706
+ if (iv) {
1707
+ if (iv.comment)
1708
+ comment = iv.comment;
1709
+ if (iv.commentBefore)
1710
+ reqNewline = true;
1711
+ } else if (item.value == null && ik?.comment) {
1712
+ comment = ik.comment;
1713
+ }
1714
+ }
1715
+ if (comment)
1716
+ reqNewline = true;
1717
+ let str = stringify(item, itemCtx, () => comment = null);
1718
+ reqNewline || (reqNewline = lines.length > linesAtValue || str.includes("\n"));
1719
+ if (i < items.length - 1) {
1720
+ str += ",";
1721
+ } else if (ctx.options.trailingComma) {
1722
+ if (ctx.options.lineWidth > 0) {
1723
+ reqNewline || (reqNewline = lines.reduce((sum, line) => sum + line.length + 2, 2) + (str.length + 2) > ctx.options.lineWidth);
1724
+ }
1725
+ if (reqNewline) {
1726
+ str += ",";
1727
+ }
1728
+ }
1729
+ if (comment)
1730
+ str += lineComment(str, itemIndent, commentString(comment));
1731
+ lines.push(str);
1732
+ linesAtValue = lines.length;
1733
+ }
1734
+ const { start, end } = flowChars;
1735
+ if (lines.length === 0) {
1736
+ return start + end;
1737
+ } else {
1738
+ if (!reqNewline) {
1739
+ const len = lines.reduce((sum, line) => sum + line.length + 2, 2);
1740
+ reqNewline = ctx.options.lineWidth > 0 && len > ctx.options.lineWidth;
1741
+ }
1742
+ if (reqNewline) {
1743
+ let str = start;
1744
+ for (const line of lines)
1745
+ str += line ? `
1746
+ ${indentStep}${indent}${line}` : "\n";
1747
+ return `${str}
1748
+ ${indent}${end}`;
1749
+ } else {
1750
+ return `${start}${fcPadding}${lines.join(" ")}${fcPadding}${end}`;
1751
+ }
1752
+ }
1753
+ }
1754
+ function addCommentBefore({ indent, options: { commentString } }, lines, comment, chompKeep) {
1755
+ if (comment && chompKeep)
1756
+ comment = comment.replace(/^\n+/, "");
1757
+ if (comment) {
1758
+ const ic = indentComment(commentString(comment), indent);
1759
+ lines.push(ic.trimStart());
1760
+ }
1761
+ }
1762
+
1763
+ // ../../node_modules/yaml/browser/dist/nodes/YAMLMap.js
1764
+ function findPair(items, key2) {
1765
+ const k = isScalar(key2) ? key2.value : key2;
1766
+ for (const it of items) {
1767
+ if (isPair(it)) {
1768
+ if (it.key === key2 || it.key === k)
1769
+ return it;
1770
+ if (isScalar(it.key) && it.key.value === k)
1771
+ return it;
1772
+ }
1773
+ }
1774
+ return void 0;
1775
+ }
1776
+ var YAMLMap = class extends Collection {
1777
+ static get tagName() {
1778
+ return "tag:yaml.org,2002:map";
1779
+ }
1780
+ constructor(schema4) {
1781
+ super(MAP, schema4);
1782
+ this.items = [];
1783
+ }
1784
+ /**
1785
+ * A generic collection parsing method that can be extended
1786
+ * to other node classes that inherit from YAMLMap
1787
+ */
1788
+ static from(schema4, obj, ctx) {
1789
+ const { keepUndefined, replacer } = ctx;
1790
+ const map2 = new this(schema4);
1791
+ const add = (key2, value) => {
1792
+ if (typeof replacer === "function")
1793
+ value = replacer.call(obj, key2, value);
1794
+ else if (Array.isArray(replacer) && !replacer.includes(key2))
1795
+ return;
1796
+ if (value !== void 0 || keepUndefined)
1797
+ map2.items.push(createPair(key2, value, ctx));
1798
+ };
1799
+ if (obj instanceof Map) {
1800
+ for (const [key2, value] of obj)
1801
+ add(key2, value);
1802
+ } else if (obj && typeof obj === "object") {
1803
+ for (const key2 of Object.keys(obj))
1804
+ add(key2, obj[key2]);
1805
+ }
1806
+ if (typeof schema4.sortMapEntries === "function") {
1807
+ map2.items.sort(schema4.sortMapEntries);
1808
+ }
1809
+ return map2;
1810
+ }
1811
+ /**
1812
+ * Adds a value to the collection.
1813
+ *
1814
+ * @param overwrite - If not set `true`, using a key that is already in the
1815
+ * collection will throw. Otherwise, overwrites the previous value.
1816
+ */
1817
+ add(pair, overwrite) {
1818
+ let _pair;
1819
+ if (isPair(pair))
1820
+ _pair = pair;
1821
+ else if (!pair || typeof pair !== "object" || !("key" in pair)) {
1822
+ _pair = new Pair(pair, pair?.value);
1823
+ } else
1824
+ _pair = new Pair(pair.key, pair.value);
1825
+ const prev = findPair(this.items, _pair.key);
1826
+ const sortEntries = this.schema?.sortMapEntries;
1827
+ if (prev) {
1828
+ if (!overwrite)
1829
+ throw new Error(`Key ${_pair.key} already set`);
1830
+ if (isScalar(prev.value) && isScalarValue(_pair.value))
1831
+ prev.value.value = _pair.value;
1832
+ else
1833
+ prev.value = _pair.value;
1834
+ } else if (sortEntries) {
1835
+ const i = this.items.findIndex((item) => sortEntries(_pair, item) < 0);
1836
+ if (i === -1)
1837
+ this.items.push(_pair);
1838
+ else
1839
+ this.items.splice(i, 0, _pair);
1840
+ } else {
1841
+ this.items.push(_pair);
1842
+ }
1843
+ }
1844
+ delete(key2) {
1845
+ const it = findPair(this.items, key2);
1846
+ if (!it)
1847
+ return false;
1848
+ const del = this.items.splice(this.items.indexOf(it), 1);
1849
+ return del.length > 0;
1850
+ }
1851
+ get(key2, keepScalar) {
1852
+ const it = findPair(this.items, key2);
1853
+ const node = it?.value;
1854
+ return (!keepScalar && isScalar(node) ? node.value : node) ?? void 0;
1855
+ }
1856
+ has(key2) {
1857
+ return !!findPair(this.items, key2);
1858
+ }
1859
+ set(key2, value) {
1860
+ this.add(new Pair(key2, value), true);
1861
+ }
1862
+ /**
1863
+ * @param ctx - Conversion context, originally set in Document#toJS()
1864
+ * @param {Class} Type - If set, forces the returned collection type
1865
+ * @returns Instance of Type, Map, or Object
1866
+ */
1867
+ toJSON(_, ctx, Type) {
1868
+ const map2 = Type ? new Type() : ctx?.mapAsMap ? /* @__PURE__ */ new Map() : {};
1869
+ if (ctx?.onCreate)
1870
+ ctx.onCreate(map2);
1871
+ for (const item of this.items)
1872
+ addPairToJSMap(ctx, map2, item);
1873
+ return map2;
1874
+ }
1875
+ toString(ctx, onComment, onChompKeep) {
1876
+ if (!ctx)
1877
+ return JSON.stringify(this);
1878
+ for (const item of this.items) {
1879
+ if (!isPair(item))
1880
+ throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
1881
+ }
1882
+ if (!ctx.allNullValues && this.hasAllNullValues(false))
1883
+ ctx = Object.assign({}, ctx, { allNullValues: true });
1884
+ return stringifyCollection(this, ctx, {
1885
+ blockItemPrefix: "",
1886
+ flowChars: { start: "{", end: "}" },
1887
+ itemIndent: ctx.indent || "",
1888
+ onChompKeep,
1889
+ onComment
1890
+ });
1891
+ }
1892
+ };
1893
+
1894
+ // ../../node_modules/yaml/browser/dist/schema/common/map.js
1895
+ var map = {
1896
+ collection: "map",
1897
+ default: true,
1898
+ nodeClass: YAMLMap,
1899
+ tag: "tag:yaml.org,2002:map",
1900
+ resolve(map2, onError) {
1901
+ if (!isMap(map2))
1902
+ onError("Expected a mapping for this tag");
1903
+ return map2;
1904
+ },
1905
+ createNode: (schema4, obj, ctx) => YAMLMap.from(schema4, obj, ctx)
1906
+ };
1907
+
1908
+ // ../../node_modules/yaml/browser/dist/nodes/YAMLSeq.js
1909
+ var YAMLSeq = class extends Collection {
1910
+ static get tagName() {
1911
+ return "tag:yaml.org,2002:seq";
1912
+ }
1913
+ constructor(schema4) {
1914
+ super(SEQ, schema4);
1915
+ this.items = [];
1916
+ }
1917
+ add(value) {
1918
+ this.items.push(value);
1919
+ }
1920
+ /**
1921
+ * Removes a value from the collection.
1922
+ *
1923
+ * `key` must contain a representation of an integer for this to succeed.
1924
+ * It may be wrapped in a `Scalar`.
1925
+ *
1926
+ * @returns `true` if the item was found and removed.
1927
+ */
1928
+ delete(key2) {
1929
+ const idx = asItemIndex(key2);
1930
+ if (typeof idx !== "number")
1931
+ return false;
1932
+ const del = this.items.splice(idx, 1);
1933
+ return del.length > 0;
1934
+ }
1935
+ get(key2, keepScalar) {
1936
+ const idx = asItemIndex(key2);
1937
+ if (typeof idx !== "number")
1938
+ return void 0;
1939
+ const it = this.items[idx];
1940
+ return !keepScalar && isScalar(it) ? it.value : it;
1941
+ }
1942
+ /**
1943
+ * Checks if the collection includes a value with the key `key`.
1944
+ *
1945
+ * `key` must contain a representation of an integer for this to succeed.
1946
+ * It may be wrapped in a `Scalar`.
1947
+ */
1948
+ has(key2) {
1949
+ const idx = asItemIndex(key2);
1950
+ return typeof idx === "number" && idx < this.items.length;
1951
+ }
1952
+ /**
1953
+ * Sets a value in this collection. For `!!set`, `value` needs to be a
1954
+ * boolean to add/remove the item from the set.
1955
+ *
1956
+ * If `key` does not contain a representation of an integer, this will throw.
1957
+ * It may be wrapped in a `Scalar`.
1958
+ */
1959
+ set(key2, value) {
1960
+ const idx = asItemIndex(key2);
1961
+ if (typeof idx !== "number")
1962
+ throw new Error(`Expected a valid index, not ${key2}.`);
1963
+ const prev = this.items[idx];
1964
+ if (isScalar(prev) && isScalarValue(value))
1965
+ prev.value = value;
1966
+ else
1967
+ this.items[idx] = value;
1968
+ }
1969
+ toJSON(_, ctx) {
1970
+ const seq2 = [];
1971
+ if (ctx?.onCreate)
1972
+ ctx.onCreate(seq2);
1973
+ let i = 0;
1974
+ for (const item of this.items)
1975
+ seq2.push(toJS(item, String(i++), ctx));
1976
+ return seq2;
1977
+ }
1978
+ toString(ctx, onComment, onChompKeep) {
1979
+ if (!ctx)
1980
+ return JSON.stringify(this);
1981
+ return stringifyCollection(this, ctx, {
1982
+ blockItemPrefix: "- ",
1983
+ flowChars: { start: "[", end: "]" },
1984
+ itemIndent: (ctx.indent || "") + " ",
1985
+ onChompKeep,
1986
+ onComment
1987
+ });
1988
+ }
1989
+ static from(schema4, obj, ctx) {
1990
+ const { replacer } = ctx;
1991
+ const seq2 = new this(schema4);
1992
+ if (obj && Symbol.iterator in Object(obj)) {
1993
+ let i = 0;
1994
+ for (let it of obj) {
1995
+ if (typeof replacer === "function") {
1996
+ const key2 = obj instanceof Set ? it : String(i++);
1997
+ it = replacer.call(obj, key2, it);
1998
+ }
1999
+ seq2.items.push(createNode(it, void 0, ctx));
2000
+ }
2001
+ }
2002
+ return seq2;
2003
+ }
2004
+ };
2005
+ function asItemIndex(key2) {
2006
+ let idx = isScalar(key2) ? key2.value : key2;
2007
+ if (idx && typeof idx === "string")
2008
+ idx = Number(idx);
2009
+ return typeof idx === "number" && Number.isInteger(idx) && idx >= 0 ? idx : null;
2010
+ }
2011
+
2012
+ // ../../node_modules/yaml/browser/dist/schema/common/seq.js
2013
+ var seq = {
2014
+ collection: "seq",
2015
+ default: true,
2016
+ nodeClass: YAMLSeq,
2017
+ tag: "tag:yaml.org,2002:seq",
2018
+ resolve(seq2, onError) {
2019
+ if (!isSeq(seq2))
2020
+ onError("Expected a sequence for this tag");
2021
+ return seq2;
2022
+ },
2023
+ createNode: (schema4, obj, ctx) => YAMLSeq.from(schema4, obj, ctx)
2024
+ };
2025
+
2026
+ // ../../node_modules/yaml/browser/dist/schema/common/string.js
2027
+ var string = {
2028
+ identify: (value) => typeof value === "string",
2029
+ default: true,
2030
+ tag: "tag:yaml.org,2002:str",
2031
+ resolve: (str) => str,
2032
+ stringify(item, ctx, onComment, onChompKeep) {
2033
+ ctx = Object.assign({ actualString: true }, ctx);
2034
+ return stringifyString(item, ctx, onComment, onChompKeep);
2035
+ }
2036
+ };
2037
+
2038
+ // ../../node_modules/yaml/browser/dist/schema/common/null.js
2039
+ var nullTag = {
2040
+ identify: (value) => value == null,
2041
+ createNode: () => new Scalar(null),
2042
+ default: true,
2043
+ tag: "tag:yaml.org,2002:null",
2044
+ test: /^(?:~|[Nn]ull|NULL)?$/,
2045
+ resolve: () => new Scalar(null),
2046
+ stringify: ({ source }, ctx) => typeof source === "string" && nullTag.test.test(source) ? source : ctx.options.nullStr
2047
+ };
2048
+
2049
+ // ../../node_modules/yaml/browser/dist/schema/core/bool.js
2050
+ var boolTag = {
2051
+ identify: (value) => typeof value === "boolean",
2052
+ default: true,
2053
+ tag: "tag:yaml.org,2002:bool",
2054
+ test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
2055
+ resolve: (str) => new Scalar(str[0] === "t" || str[0] === "T"),
2056
+ stringify({ source, value }, ctx) {
2057
+ if (source && boolTag.test.test(source)) {
2058
+ const sv = source[0] === "t" || source[0] === "T";
2059
+ if (value === sv)
2060
+ return source;
2061
+ }
2062
+ return value ? ctx.options.trueStr : ctx.options.falseStr;
2063
+ }
2064
+ };
2065
+
2066
+ // ../../node_modules/yaml/browser/dist/stringify/stringifyNumber.js
2067
+ function stringifyNumber({ format, minFractionDigits, tag, value }) {
2068
+ if (typeof value === "bigint")
2069
+ return String(value);
2070
+ const num = typeof value === "number" ? value : Number(value);
2071
+ if (!isFinite(num))
2072
+ return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
2073
+ let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
2074
+ if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
2075
+ let i = n.indexOf(".");
2076
+ if (i < 0) {
2077
+ i = n.length;
2078
+ n += ".";
2079
+ }
2080
+ let d = minFractionDigits - (n.length - i - 1);
2081
+ while (d-- > 0)
2082
+ n += "0";
2083
+ }
2084
+ return n;
2085
+ }
2086
+
2087
+ // ../../node_modules/yaml/browser/dist/schema/core/float.js
2088
+ var floatNaN = {
2089
+ identify: (value) => typeof value === "number",
2090
+ default: true,
2091
+ tag: "tag:yaml.org,2002:float",
2092
+ test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
2093
+ resolve: (str) => str.slice(-3).toLowerCase() === "nan" ? NaN : str[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
2094
+ stringify: stringifyNumber
2095
+ };
2096
+ var floatExp = {
2097
+ identify: (value) => typeof value === "number",
2098
+ default: true,
2099
+ tag: "tag:yaml.org,2002:float",
2100
+ format: "EXP",
2101
+ test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
2102
+ resolve: (str) => parseFloat(str),
2103
+ stringify(node) {
2104
+ const num = Number(node.value);
2105
+ return isFinite(num) ? num.toExponential() : stringifyNumber(node);
2106
+ }
2107
+ };
2108
+ var float = {
2109
+ identify: (value) => typeof value === "number",
2110
+ default: true,
2111
+ tag: "tag:yaml.org,2002:float",
2112
+ test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
2113
+ resolve(str) {
2114
+ const node = new Scalar(parseFloat(str));
2115
+ const dot = str.indexOf(".");
2116
+ if (dot !== -1 && str[str.length - 1] === "0")
2117
+ node.minFractionDigits = str.length - dot - 1;
2118
+ return node;
2119
+ },
2120
+ stringify: stringifyNumber
2121
+ };
2122
+
2123
+ // ../../node_modules/yaml/browser/dist/schema/core/int.js
2124
+ var intIdentify = (value) => typeof value === "bigint" || Number.isInteger(value);
2125
+ var intResolve = (str, offset, radix, { intAsBigInt }) => intAsBigInt ? BigInt(str) : parseInt(str.substring(offset), radix);
2126
+ function intStringify(node, radix, prefix) {
2127
+ const { value } = node;
2128
+ if (intIdentify(value) && value >= 0)
2129
+ return prefix + value.toString(radix);
2130
+ return stringifyNumber(node);
2131
+ }
2132
+ var intOct = {
2133
+ identify: (value) => intIdentify(value) && value >= 0,
2134
+ default: true,
2135
+ tag: "tag:yaml.org,2002:int",
2136
+ format: "OCT",
2137
+ test: /^0o[0-7]+$/,
2138
+ resolve: (str, _onError, opt) => intResolve(str, 2, 8, opt),
2139
+ stringify: (node) => intStringify(node, 8, "0o")
2140
+ };
2141
+ var int = {
2142
+ identify: intIdentify,
2143
+ default: true,
2144
+ tag: "tag:yaml.org,2002:int",
2145
+ test: /^[-+]?[0-9]+$/,
2146
+ resolve: (str, _onError, opt) => intResolve(str, 0, 10, opt),
2147
+ stringify: stringifyNumber
2148
+ };
2149
+ var intHex = {
2150
+ identify: (value) => intIdentify(value) && value >= 0,
2151
+ default: true,
2152
+ tag: "tag:yaml.org,2002:int",
2153
+ format: "HEX",
2154
+ test: /^0x[0-9a-fA-F]+$/,
2155
+ resolve: (str, _onError, opt) => intResolve(str, 2, 16, opt),
2156
+ stringify: (node) => intStringify(node, 16, "0x")
2157
+ };
2158
+
2159
+ // ../../node_modules/yaml/browser/dist/schema/core/schema.js
2160
+ var schema = [
2161
+ map,
2162
+ seq,
2163
+ string,
2164
+ nullTag,
2165
+ boolTag,
2166
+ intOct,
2167
+ int,
2168
+ intHex,
2169
+ floatNaN,
2170
+ floatExp,
2171
+ float
2172
+ ];
2173
+
2174
+ // ../../node_modules/yaml/browser/dist/schema/json/schema.js
2175
+ function intIdentify2(value) {
2176
+ return typeof value === "bigint" || Number.isInteger(value);
2177
+ }
2178
+ var stringifyJSON = ({ value }) => JSON.stringify(value);
2179
+ var jsonScalars = [
2180
+ {
2181
+ identify: (value) => typeof value === "string",
2182
+ default: true,
2183
+ tag: "tag:yaml.org,2002:str",
2184
+ resolve: (str) => str,
2185
+ stringify: stringifyJSON
2186
+ },
2187
+ {
2188
+ identify: (value) => value == null,
2189
+ createNode: () => new Scalar(null),
2190
+ default: true,
2191
+ tag: "tag:yaml.org,2002:null",
2192
+ test: /^null$/,
2193
+ resolve: () => null,
2194
+ stringify: stringifyJSON
2195
+ },
2196
+ {
2197
+ identify: (value) => typeof value === "boolean",
2198
+ default: true,
2199
+ tag: "tag:yaml.org,2002:bool",
2200
+ test: /^true$|^false$/,
2201
+ resolve: (str) => str === "true",
2202
+ stringify: stringifyJSON
2203
+ },
2204
+ {
2205
+ identify: intIdentify2,
2206
+ default: true,
2207
+ tag: "tag:yaml.org,2002:int",
2208
+ test: /^-?(?:0|[1-9][0-9]*)$/,
2209
+ resolve: (str, _onError, { intAsBigInt }) => intAsBigInt ? BigInt(str) : parseInt(str, 10),
2210
+ stringify: ({ value }) => intIdentify2(value) ? value.toString() : JSON.stringify(value)
2211
+ },
2212
+ {
2213
+ identify: (value) => typeof value === "number",
2214
+ default: true,
2215
+ tag: "tag:yaml.org,2002:float",
2216
+ test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
2217
+ resolve: (str) => parseFloat(str),
2218
+ stringify: stringifyJSON
2219
+ }
2220
+ ];
2221
+ var jsonError = {
2222
+ default: true,
2223
+ tag: "",
2224
+ test: /^/,
2225
+ resolve(str, onError) {
2226
+ onError(`Unresolved plain scalar ${JSON.stringify(str)}`);
2227
+ return str;
2228
+ }
2229
+ };
2230
+ var schema2 = [map, seq].concat(jsonScalars, jsonError);
2231
+
2232
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js
2233
+ var binary = {
2234
+ identify: (value) => value instanceof Uint8Array,
2235
+ // Buffer inherits from Uint8Array
2236
+ default: false,
2237
+ tag: "tag:yaml.org,2002:binary",
2238
+ /**
2239
+ * Returns a Buffer in node and an Uint8Array in browsers
2240
+ *
2241
+ * To use the resulting buffer as an image, you'll want to do something like:
2242
+ *
2243
+ * const blob = new Blob([buffer], { type: 'image/jpeg' })
2244
+ * document.querySelector('#photo').src = URL.createObjectURL(blob)
2245
+ */
2246
+ resolve(src, onError) {
2247
+ if (typeof atob === "function") {
2248
+ const str = atob(src.replace(/[\n\r]/g, ""));
2249
+ const buffer = new Uint8Array(str.length);
2250
+ for (let i = 0; i < str.length; ++i)
2251
+ buffer[i] = str.charCodeAt(i);
2252
+ return buffer;
2253
+ } else {
2254
+ onError("This environment does not support reading binary tags; either Buffer or atob is required");
2255
+ return src;
2256
+ }
2257
+ },
2258
+ stringify({ comment, type, value }, ctx, onComment, onChompKeep) {
2259
+ if (!value)
2260
+ return "";
2261
+ const buf = value;
2262
+ let str;
2263
+ if (typeof btoa === "function") {
2264
+ let s = "";
2265
+ for (let i = 0; i < buf.length; ++i)
2266
+ s += String.fromCharCode(buf[i]);
2267
+ str = btoa(s);
2268
+ } else {
2269
+ throw new Error("This environment does not support writing binary tags; either Buffer or btoa is required");
2270
+ }
2271
+ type ?? (type = Scalar.BLOCK_LITERAL);
2272
+ if (type !== Scalar.QUOTE_DOUBLE) {
2273
+ const lineWidth = Math.max(ctx.options.lineWidth - ctx.indent.length, ctx.options.minContentWidth);
2274
+ const n = Math.ceil(str.length / lineWidth);
2275
+ const lines = new Array(n);
2276
+ for (let i = 0, o = 0; i < n; ++i, o += lineWidth) {
2277
+ lines[i] = str.substr(o, lineWidth);
2278
+ }
2279
+ str = lines.join(type === Scalar.BLOCK_LITERAL ? "\n" : " ");
2280
+ }
2281
+ return stringifyString({ comment, type, value: str }, ctx, onComment, onChompKeep);
2282
+ }
2283
+ };
2284
+
2285
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js
2286
+ function resolvePairs(seq2, onError) {
2287
+ if (isSeq(seq2)) {
2288
+ for (let i = 0; i < seq2.items.length; ++i) {
2289
+ let item = seq2.items[i];
2290
+ if (isPair(item))
2291
+ continue;
2292
+ else if (isMap(item)) {
2293
+ if (item.items.length > 1)
2294
+ onError("Each pair must have its own sequence indicator");
2295
+ const pair = item.items[0] || new Pair(new Scalar(null));
2296
+ if (item.commentBefore)
2297
+ pair.key.commentBefore = pair.key.commentBefore ? `${item.commentBefore}
2298
+ ${pair.key.commentBefore}` : item.commentBefore;
2299
+ if (item.comment) {
2300
+ const cn = pair.value ?? pair.key;
2301
+ cn.comment = cn.comment ? `${item.comment}
2302
+ ${cn.comment}` : item.comment;
2303
+ }
2304
+ item = pair;
2305
+ }
2306
+ seq2.items[i] = isPair(item) ? item : new Pair(item);
2307
+ }
2308
+ } else
2309
+ onError("Expected a sequence for this tag");
2310
+ return seq2;
2311
+ }
2312
+ function createPairs(schema4, iterable, ctx) {
2313
+ const { replacer } = ctx;
2314
+ const pairs2 = new YAMLSeq(schema4);
2315
+ pairs2.tag = "tag:yaml.org,2002:pairs";
2316
+ let i = 0;
2317
+ if (iterable && Symbol.iterator in Object(iterable))
2318
+ for (let it of iterable) {
2319
+ if (typeof replacer === "function")
2320
+ it = replacer.call(iterable, String(i++), it);
2321
+ let key2, value;
2322
+ if (Array.isArray(it)) {
2323
+ if (it.length === 2) {
2324
+ key2 = it[0];
2325
+ value = it[1];
2326
+ } else
2327
+ throw new TypeError(`Expected [key, value] tuple: ${it}`);
2328
+ } else if (it && it instanceof Object) {
2329
+ const keys = Object.keys(it);
2330
+ if (keys.length === 1) {
2331
+ key2 = keys[0];
2332
+ value = it[key2];
2333
+ } else {
2334
+ throw new TypeError(`Expected tuple with one key, not ${keys.length} keys`);
2335
+ }
2336
+ } else {
2337
+ key2 = it;
2338
+ }
2339
+ pairs2.items.push(createPair(key2, value, ctx));
2340
+ }
2341
+ return pairs2;
2342
+ }
2343
+ var pairs = {
2344
+ collection: "seq",
2345
+ default: false,
2346
+ tag: "tag:yaml.org,2002:pairs",
2347
+ resolve: resolvePairs,
2348
+ createNode: createPairs
2349
+ };
2350
+
2351
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js
2352
+ var YAMLOMap = class _YAMLOMap extends YAMLSeq {
2353
+ constructor() {
2354
+ super();
2355
+ this.add = YAMLMap.prototype.add.bind(this);
2356
+ this.delete = YAMLMap.prototype.delete.bind(this);
2357
+ this.get = YAMLMap.prototype.get.bind(this);
2358
+ this.has = YAMLMap.prototype.has.bind(this);
2359
+ this.set = YAMLMap.prototype.set.bind(this);
2360
+ this.tag = _YAMLOMap.tag;
2361
+ }
2362
+ /**
2363
+ * If `ctx` is given, the return type is actually `Map<unknown, unknown>`,
2364
+ * but TypeScript won't allow widening the signature of a child method.
2365
+ */
2366
+ toJSON(_, ctx) {
2367
+ if (!ctx)
2368
+ return super.toJSON(_);
2369
+ const map2 = /* @__PURE__ */ new Map();
2370
+ if (ctx?.onCreate)
2371
+ ctx.onCreate(map2);
2372
+ for (const pair of this.items) {
2373
+ let key2, value;
2374
+ if (isPair(pair)) {
2375
+ key2 = toJS(pair.key, "", ctx);
2376
+ value = toJS(pair.value, key2, ctx);
2377
+ } else {
2378
+ key2 = toJS(pair, "", ctx);
2379
+ }
2380
+ if (map2.has(key2))
2381
+ throw new Error("Ordered maps must not include duplicate keys");
2382
+ map2.set(key2, value);
2383
+ }
2384
+ return map2;
2385
+ }
2386
+ static from(schema4, iterable, ctx) {
2387
+ const pairs2 = createPairs(schema4, iterable, ctx);
2388
+ const omap2 = new this();
2389
+ omap2.items = pairs2.items;
2390
+ return omap2;
2391
+ }
2392
+ };
2393
+ YAMLOMap.tag = "tag:yaml.org,2002:omap";
2394
+ var omap = {
2395
+ collection: "seq",
2396
+ identify: (value) => value instanceof Map,
2397
+ nodeClass: YAMLOMap,
2398
+ default: false,
2399
+ tag: "tag:yaml.org,2002:omap",
2400
+ resolve(seq2, onError) {
2401
+ const pairs2 = resolvePairs(seq2, onError);
2402
+ const seenKeys = [];
2403
+ for (const { key: key2 } of pairs2.items) {
2404
+ if (isScalar(key2)) {
2405
+ if (seenKeys.includes(key2.value)) {
2406
+ onError(`Ordered maps must not include duplicate keys: ${key2.value}`);
2407
+ } else {
2408
+ seenKeys.push(key2.value);
2409
+ }
2410
+ }
2411
+ }
2412
+ return Object.assign(new YAMLOMap(), pairs2);
2413
+ },
2414
+ createNode: (schema4, iterable, ctx) => YAMLOMap.from(schema4, iterable, ctx)
2415
+ };
2416
+
2417
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js
2418
+ function boolStringify({ value, source }, ctx) {
2419
+ const boolObj = value ? trueTag : falseTag;
2420
+ if (source && boolObj.test.test(source))
2421
+ return source;
2422
+ return value ? ctx.options.trueStr : ctx.options.falseStr;
2423
+ }
2424
+ var trueTag = {
2425
+ identify: (value) => value === true,
2426
+ default: true,
2427
+ tag: "tag:yaml.org,2002:bool",
2428
+ test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
2429
+ resolve: () => new Scalar(true),
2430
+ stringify: boolStringify
2431
+ };
2432
+ var falseTag = {
2433
+ identify: (value) => value === false,
2434
+ default: true,
2435
+ tag: "tag:yaml.org,2002:bool",
2436
+ test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
2437
+ resolve: () => new Scalar(false),
2438
+ stringify: boolStringify
2439
+ };
2440
+
2441
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/float.js
2442
+ var floatNaN2 = {
2443
+ identify: (value) => typeof value === "number",
2444
+ default: true,
2445
+ tag: "tag:yaml.org,2002:float",
2446
+ test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
2447
+ resolve: (str) => str.slice(-3).toLowerCase() === "nan" ? NaN : str[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
2448
+ stringify: stringifyNumber
2449
+ };
2450
+ var floatExp2 = {
2451
+ identify: (value) => typeof value === "number",
2452
+ default: true,
2453
+ tag: "tag:yaml.org,2002:float",
2454
+ format: "EXP",
2455
+ test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
2456
+ resolve: (str) => parseFloat(str.replace(/_/g, "")),
2457
+ stringify(node) {
2458
+ const num = Number(node.value);
2459
+ return isFinite(num) ? num.toExponential() : stringifyNumber(node);
2460
+ }
2461
+ };
2462
+ var float2 = {
2463
+ identify: (value) => typeof value === "number",
2464
+ default: true,
2465
+ tag: "tag:yaml.org,2002:float",
2466
+ test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
2467
+ resolve(str) {
2468
+ const node = new Scalar(parseFloat(str.replace(/_/g, "")));
2469
+ const dot = str.indexOf(".");
2470
+ if (dot !== -1) {
2471
+ const f = str.substring(dot + 1).replace(/_/g, "");
2472
+ if (f[f.length - 1] === "0")
2473
+ node.minFractionDigits = f.length;
2474
+ }
2475
+ return node;
2476
+ },
2477
+ stringify: stringifyNumber
2478
+ };
2479
+
2480
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/int.js
2481
+ var intIdentify3 = (value) => typeof value === "bigint" || Number.isInteger(value);
2482
+ function intResolve2(str, offset, radix, { intAsBigInt }) {
2483
+ const sign = str[0];
2484
+ if (sign === "-" || sign === "+")
2485
+ offset += 1;
2486
+ str = str.substring(offset).replace(/_/g, "");
2487
+ if (intAsBigInt) {
2488
+ switch (radix) {
2489
+ case 2:
2490
+ str = `0b${str}`;
2491
+ break;
2492
+ case 8:
2493
+ str = `0o${str}`;
2494
+ break;
2495
+ case 16:
2496
+ str = `0x${str}`;
2497
+ break;
2498
+ }
2499
+ const n2 = BigInt(str);
2500
+ return sign === "-" ? BigInt(-1) * n2 : n2;
2501
+ }
2502
+ const n = parseInt(str, radix);
2503
+ return sign === "-" ? -1 * n : n;
2504
+ }
2505
+ function intStringify2(node, radix, prefix) {
2506
+ const { value } = node;
2507
+ if (intIdentify3(value)) {
2508
+ const str = value.toString(radix);
2509
+ return value < 0 ? "-" + prefix + str.substr(1) : prefix + str;
2510
+ }
2511
+ return stringifyNumber(node);
2512
+ }
2513
+ var intBin = {
2514
+ identify: intIdentify3,
2515
+ default: true,
2516
+ tag: "tag:yaml.org,2002:int",
2517
+ format: "BIN",
2518
+ test: /^[-+]?0b[0-1_]+$/,
2519
+ resolve: (str, _onError, opt) => intResolve2(str, 2, 2, opt),
2520
+ stringify: (node) => intStringify2(node, 2, "0b")
2521
+ };
2522
+ var intOct2 = {
2523
+ identify: intIdentify3,
2524
+ default: true,
2525
+ tag: "tag:yaml.org,2002:int",
2526
+ format: "OCT",
2527
+ test: /^[-+]?0[0-7_]+$/,
2528
+ resolve: (str, _onError, opt) => intResolve2(str, 1, 8, opt),
2529
+ stringify: (node) => intStringify2(node, 8, "0")
2530
+ };
2531
+ var int2 = {
2532
+ identify: intIdentify3,
2533
+ default: true,
2534
+ tag: "tag:yaml.org,2002:int",
2535
+ test: /^[-+]?[0-9][0-9_]*$/,
2536
+ resolve: (str, _onError, opt) => intResolve2(str, 0, 10, opt),
2537
+ stringify: stringifyNumber
2538
+ };
2539
+ var intHex2 = {
2540
+ identify: intIdentify3,
2541
+ default: true,
2542
+ tag: "tag:yaml.org,2002:int",
2543
+ format: "HEX",
2544
+ test: /^[-+]?0x[0-9a-fA-F_]+$/,
2545
+ resolve: (str, _onError, opt) => intResolve2(str, 2, 16, opt),
2546
+ stringify: (node) => intStringify2(node, 16, "0x")
2547
+ };
2548
+
2549
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/set.js
2550
+ var YAMLSet = class _YAMLSet extends YAMLMap {
2551
+ constructor(schema4) {
2552
+ super(schema4);
2553
+ this.tag = _YAMLSet.tag;
2554
+ }
2555
+ add(key2) {
2556
+ let pair;
2557
+ if (isPair(key2))
2558
+ pair = key2;
2559
+ else if (key2 && typeof key2 === "object" && "key" in key2 && "value" in key2 && key2.value === null)
2560
+ pair = new Pair(key2.key, null);
2561
+ else
2562
+ pair = new Pair(key2, null);
2563
+ const prev = findPair(this.items, pair.key);
2564
+ if (!prev)
2565
+ this.items.push(pair);
2566
+ }
2567
+ /**
2568
+ * If `keepPair` is `true`, returns the Pair matching `key`.
2569
+ * Otherwise, returns the value of that Pair's key.
2570
+ */
2571
+ get(key2, keepPair) {
2572
+ const pair = findPair(this.items, key2);
2573
+ return !keepPair && isPair(pair) ? isScalar(pair.key) ? pair.key.value : pair.key : pair;
2574
+ }
2575
+ set(key2, value) {
2576
+ if (typeof value !== "boolean")
2577
+ throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);
2578
+ const prev = findPair(this.items, key2);
2579
+ if (prev && !value) {
2580
+ this.items.splice(this.items.indexOf(prev), 1);
2581
+ } else if (!prev && value) {
2582
+ this.items.push(new Pair(key2));
2583
+ }
2584
+ }
2585
+ toJSON(_, ctx) {
2586
+ return super.toJSON(_, ctx, Set);
2587
+ }
2588
+ toString(ctx, onComment, onChompKeep) {
2589
+ if (!ctx)
2590
+ return JSON.stringify(this);
2591
+ if (this.hasAllNullValues(true))
2592
+ return super.toString(Object.assign({}, ctx, { allNullValues: true }), onComment, onChompKeep);
2593
+ else
2594
+ throw new Error("Set items must all have null values");
2595
+ }
2596
+ static from(schema4, iterable, ctx) {
2597
+ const { replacer } = ctx;
2598
+ const set2 = new this(schema4);
2599
+ if (iterable && Symbol.iterator in Object(iterable))
2600
+ for (let value of iterable) {
2601
+ if (typeof replacer === "function")
2602
+ value = replacer.call(iterable, value, value);
2603
+ set2.items.push(createPair(value, null, ctx));
2604
+ }
2605
+ return set2;
2606
+ }
2607
+ };
2608
+ YAMLSet.tag = "tag:yaml.org,2002:set";
2609
+ var set = {
2610
+ collection: "map",
2611
+ identify: (value) => value instanceof Set,
2612
+ nodeClass: YAMLSet,
2613
+ default: false,
2614
+ tag: "tag:yaml.org,2002:set",
2615
+ createNode: (schema4, iterable, ctx) => YAMLSet.from(schema4, iterable, ctx),
2616
+ resolve(map2, onError) {
2617
+ if (isMap(map2)) {
2618
+ if (map2.hasAllNullValues(true))
2619
+ return Object.assign(new YAMLSet(), map2);
2620
+ else
2621
+ onError("Set items must all have null values");
2622
+ } else
2623
+ onError("Expected a mapping for this tag");
2624
+ return map2;
2625
+ }
2626
+ };
2627
+
2628
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js
2629
+ function parseSexagesimal(str, asBigInt) {
2630
+ const sign = str[0];
2631
+ const parts = sign === "-" || sign === "+" ? str.substring(1) : str;
2632
+ const num = (n) => asBigInt ? BigInt(n) : Number(n);
2633
+ const res = parts.replace(/_/g, "").split(":").reduce((res2, p) => res2 * num(60) + num(p), num(0));
2634
+ return sign === "-" ? num(-1) * res : res;
2635
+ }
2636
+ function stringifySexagesimal(node) {
2637
+ let { value } = node;
2638
+ let num = (n) => n;
2639
+ if (typeof value === "bigint")
2640
+ num = (n) => BigInt(n);
2641
+ else if (isNaN(value) || !isFinite(value))
2642
+ return stringifyNumber(node);
2643
+ let sign = "";
2644
+ if (value < 0) {
2645
+ sign = "-";
2646
+ value *= num(-1);
2647
+ }
2648
+ const _60 = num(60);
2649
+ const parts = [value % _60];
2650
+ if (value < 60) {
2651
+ parts.unshift(0);
2652
+ } else {
2653
+ value = (value - parts[0]) / _60;
2654
+ parts.unshift(value % _60);
2655
+ if (value >= 60) {
2656
+ value = (value - parts[0]) / _60;
2657
+ parts.unshift(value);
2658
+ }
2659
+ }
2660
+ return sign + parts.map((n) => String(n).padStart(2, "0")).join(":").replace(/000000\d*$/, "");
2661
+ }
2662
+ var intTime = {
2663
+ identify: (value) => typeof value === "bigint" || Number.isInteger(value),
2664
+ default: true,
2665
+ tag: "tag:yaml.org,2002:int",
2666
+ format: "TIME",
2667
+ test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,
2668
+ resolve: (str, _onError, { intAsBigInt }) => parseSexagesimal(str, intAsBigInt),
2669
+ stringify: stringifySexagesimal
2670
+ };
2671
+ var floatTime = {
2672
+ identify: (value) => typeof value === "number",
2673
+ default: true,
2674
+ tag: "tag:yaml.org,2002:float",
2675
+ format: "TIME",
2676
+ test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,
2677
+ resolve: (str) => parseSexagesimal(str, false),
2678
+ stringify: stringifySexagesimal
2679
+ };
2680
+ var timestamp = {
2681
+ identify: (value) => value instanceof Date,
2682
+ default: true,
2683
+ tag: "tag:yaml.org,2002:timestamp",
2684
+ // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
2685
+ // may be omitted altogether, resulting in a date format. In such a case, the time part is
2686
+ // assumed to be 00:00:00Z (start of day, UTC).
2687
+ 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})?))?)?$"),
2688
+ resolve(str) {
2689
+ const match = str.match(timestamp.test);
2690
+ if (!match)
2691
+ throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");
2692
+ const [, year, month, day2, hour, minute, second] = match.map(Number);
2693
+ const millisec = match[7] ? Number((match[7] + "00").substr(1, 3)) : 0;
2694
+ let date = Date.UTC(year, month - 1, day2, hour || 0, minute || 0, second || 0, millisec);
2695
+ const tz = match[8];
2696
+ if (tz && tz !== "Z") {
2697
+ let d = parseSexagesimal(tz, false);
2698
+ if (Math.abs(d) < 30)
2699
+ d *= 60;
2700
+ date -= 6e4 * d;
2701
+ }
2702
+ return new Date(date);
2703
+ },
2704
+ stringify: ({ value }) => value?.toISOString().replace(/(T00:00:00)?\.000Z$/, "") ?? ""
2705
+ };
2706
+
2707
+ // ../../node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js
2708
+ var schema3 = [
2709
+ map,
2710
+ seq,
2711
+ string,
2712
+ nullTag,
2713
+ trueTag,
2714
+ falseTag,
2715
+ intBin,
2716
+ intOct2,
2717
+ int2,
2718
+ intHex2,
2719
+ floatNaN2,
2720
+ floatExp2,
2721
+ float2,
2722
+ binary,
2723
+ merge,
2724
+ omap,
2725
+ pairs,
2726
+ set,
2727
+ intTime,
2728
+ floatTime,
2729
+ timestamp
2730
+ ];
2731
+
2732
+ // ../../node_modules/yaml/browser/dist/schema/tags.js
2733
+ var schemas = /* @__PURE__ */ new Map([
2734
+ ["core", schema],
2735
+ ["failsafe", [map, seq, string]],
2736
+ ["json", schema2],
2737
+ ["yaml11", schema3],
2738
+ ["yaml-1.1", schema3]
2739
+ ]);
2740
+ var tagsByName = {
2741
+ binary,
2742
+ bool: boolTag,
2743
+ float,
2744
+ floatExp,
2745
+ floatNaN,
2746
+ floatTime,
2747
+ int,
2748
+ intHex,
2749
+ intOct,
2750
+ intTime,
2751
+ map,
2752
+ merge,
2753
+ null: nullTag,
2754
+ omap,
2755
+ pairs,
2756
+ seq,
2757
+ set,
2758
+ timestamp
2759
+ };
2760
+ var coreKnownTags = {
2761
+ "tag:yaml.org,2002:binary": binary,
2762
+ "tag:yaml.org,2002:merge": merge,
2763
+ "tag:yaml.org,2002:omap": omap,
2764
+ "tag:yaml.org,2002:pairs": pairs,
2765
+ "tag:yaml.org,2002:set": set,
2766
+ "tag:yaml.org,2002:timestamp": timestamp
2767
+ };
2768
+ function getTags(customTags, schemaName, addMergeTag) {
2769
+ const schemaTags = schemas.get(schemaName);
2770
+ if (schemaTags && !customTags) {
2771
+ return addMergeTag && !schemaTags.includes(merge) ? schemaTags.concat(merge) : schemaTags.slice();
2772
+ }
2773
+ let tags = schemaTags;
2774
+ if (!tags) {
2775
+ if (Array.isArray(customTags))
2776
+ tags = [];
2777
+ else {
2778
+ const keys = Array.from(schemas.keys()).filter((key2) => key2 !== "yaml11").map((key2) => JSON.stringify(key2)).join(", ");
2779
+ throw new Error(`Unknown schema "${schemaName}"; use one of ${keys} or define customTags array`);
2780
+ }
2781
+ }
2782
+ if (Array.isArray(customTags)) {
2783
+ for (const tag of customTags)
2784
+ tags = tags.concat(tag);
2785
+ } else if (typeof customTags === "function") {
2786
+ tags = customTags(tags.slice());
2787
+ }
2788
+ if (addMergeTag)
2789
+ tags = tags.concat(merge);
2790
+ return tags.reduce((tags2, tag) => {
2791
+ const tagObj = typeof tag === "string" ? tagsByName[tag] : tag;
2792
+ if (!tagObj) {
2793
+ const tagName = JSON.stringify(tag);
2794
+ const keys = Object.keys(tagsByName).map((key2) => JSON.stringify(key2)).join(", ");
2795
+ throw new Error(`Unknown custom tag ${tagName}; use one of ${keys}`);
2796
+ }
2797
+ if (!tags2.includes(tagObj))
2798
+ tags2.push(tagObj);
2799
+ return tags2;
2800
+ }, []);
2801
+ }
2802
+
2803
+ // ../../node_modules/yaml/browser/dist/schema/Schema.js
2804
+ var sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
2805
+ var Schema = class _Schema {
2806
+ constructor({ compat, customTags, merge: merge2, resolveKnownTags, schema: schema4, sortMapEntries, toStringDefaults }) {
2807
+ this.compat = Array.isArray(compat) ? getTags(compat, "compat") : compat ? getTags(null, compat) : null;
2808
+ this.name = typeof schema4 === "string" && schema4 || "core";
2809
+ this.knownTags = resolveKnownTags ? coreKnownTags : {};
2810
+ this.tags = getTags(customTags, this.name, merge2);
2811
+ this.toStringOptions = toStringDefaults ?? null;
2812
+ Object.defineProperty(this, MAP, { value: map });
2813
+ Object.defineProperty(this, SCALAR, { value: string });
2814
+ Object.defineProperty(this, SEQ, { value: seq });
2815
+ this.sortMapEntries = typeof sortMapEntries === "function" ? sortMapEntries : sortMapEntries === true ? sortMapEntriesByKey : null;
2816
+ }
2817
+ clone() {
2818
+ const copy = Object.create(_Schema.prototype, Object.getOwnPropertyDescriptors(this));
2819
+ copy.tags = this.tags.slice();
2820
+ return copy;
2821
+ }
2822
+ };
2823
+
2824
+ // ../../node_modules/yaml/browser/dist/stringify/stringifyDocument.js
2825
+ function stringifyDocument(doc, options) {
2826
+ const lines = [];
2827
+ let hasDirectives = options.directives === true;
2828
+ if (options.directives !== false && doc.directives) {
2829
+ const dir = doc.directives.toString(doc);
2830
+ if (dir) {
2831
+ lines.push(dir);
2832
+ hasDirectives = true;
2833
+ } else if (doc.directives.docStart)
2834
+ hasDirectives = true;
2835
+ }
2836
+ if (hasDirectives)
2837
+ lines.push("---");
2838
+ const ctx = createStringifyContext(doc, options);
2839
+ const { commentString } = ctx.options;
2840
+ if (doc.commentBefore) {
2841
+ if (lines.length !== 1)
2842
+ lines.unshift("");
2843
+ const cs = commentString(doc.commentBefore);
2844
+ lines.unshift(indentComment(cs, ""));
2845
+ }
2846
+ let chompKeep = false;
2847
+ let contentComment = null;
2848
+ if (doc.contents) {
2849
+ if (isNode(doc.contents)) {
2850
+ if (doc.contents.spaceBefore && hasDirectives)
2851
+ lines.push("");
2852
+ if (doc.contents.commentBefore) {
2853
+ const cs = commentString(doc.contents.commentBefore);
2854
+ lines.push(indentComment(cs, ""));
2855
+ }
2856
+ ctx.forceBlockIndent = !!doc.comment;
2857
+ contentComment = doc.contents.comment;
2858
+ }
2859
+ const onChompKeep = contentComment ? void 0 : () => chompKeep = true;
2860
+ let body = stringify(doc.contents, ctx, () => contentComment = null, onChompKeep);
2861
+ if (contentComment)
2862
+ body += lineComment(body, "", commentString(contentComment));
2863
+ if ((body[0] === "|" || body[0] === ">") && lines[lines.length - 1] === "---") {
2864
+ lines[lines.length - 1] = `--- ${body}`;
2865
+ } else
2866
+ lines.push(body);
2867
+ } else {
2868
+ lines.push(stringify(doc.contents, ctx));
2869
+ }
2870
+ if (doc.directives?.docEnd) {
2871
+ if (doc.comment) {
2872
+ const cs = commentString(doc.comment);
2873
+ if (cs.includes("\n")) {
2874
+ lines.push("...");
2875
+ lines.push(indentComment(cs, ""));
2876
+ } else {
2877
+ lines.push(`... ${cs}`);
2878
+ }
2879
+ } else {
2880
+ lines.push("...");
2881
+ }
2882
+ } else {
2883
+ let dc = doc.comment;
2884
+ if (dc && chompKeep)
2885
+ dc = dc.replace(/^\n+/, "");
2886
+ if (dc) {
2887
+ if ((!chompKeep || contentComment) && lines[lines.length - 1] !== "")
2888
+ lines.push("");
2889
+ lines.push(indentComment(commentString(dc), ""));
2890
+ }
2891
+ }
2892
+ return lines.join("\n") + "\n";
2893
+ }
2894
+
2895
+ // ../../node_modules/yaml/browser/dist/doc/Document.js
2896
+ var Document = class _Document {
2897
+ constructor(value, replacer, options) {
2898
+ this.commentBefore = null;
2899
+ this.comment = null;
2900
+ this.errors = [];
2901
+ this.warnings = [];
2902
+ Object.defineProperty(this, NODE_TYPE, { value: DOC });
2903
+ let _replacer = null;
2904
+ if (typeof replacer === "function" || Array.isArray(replacer)) {
2905
+ _replacer = replacer;
2906
+ } else if (options === void 0 && replacer) {
2907
+ options = replacer;
2908
+ replacer = void 0;
2909
+ }
2910
+ const opt = Object.assign({
2911
+ intAsBigInt: false,
2912
+ keepSourceTokens: false,
2913
+ logLevel: "warn",
2914
+ prettyErrors: true,
2915
+ strict: true,
2916
+ stringKeys: false,
2917
+ uniqueKeys: true,
2918
+ version: "1.2"
2919
+ }, options);
2920
+ this.options = opt;
2921
+ let { version } = opt;
2922
+ if (options?._directives) {
2923
+ this.directives = options._directives.atDocument();
2924
+ if (this.directives.yaml.explicit)
2925
+ version = this.directives.yaml.version;
2926
+ } else
2927
+ this.directives = new Directives({ version });
2928
+ this.setSchema(version, options);
2929
+ this.contents = value === void 0 ? null : this.createNode(value, _replacer, options);
2930
+ }
2931
+ /**
2932
+ * Create a deep copy of this Document and its contents.
2933
+ *
2934
+ * Custom Node values that inherit from `Object` still refer to their original instances.
2935
+ */
2936
+ clone() {
2937
+ const copy = Object.create(_Document.prototype, {
2938
+ [NODE_TYPE]: { value: DOC }
2939
+ });
2940
+ copy.commentBefore = this.commentBefore;
2941
+ copy.comment = this.comment;
2942
+ copy.errors = this.errors.slice();
2943
+ copy.warnings = this.warnings.slice();
2944
+ copy.options = Object.assign({}, this.options);
2945
+ if (this.directives)
2946
+ copy.directives = this.directives.clone();
2947
+ copy.schema = this.schema.clone();
2948
+ copy.contents = isNode(this.contents) ? this.contents.clone(copy.schema) : this.contents;
2949
+ if (this.range)
2950
+ copy.range = this.range.slice();
2951
+ return copy;
2952
+ }
2953
+ /** Adds a value to the document. */
2954
+ add(value) {
2955
+ if (assertCollection(this.contents))
2956
+ this.contents.add(value);
2957
+ }
2958
+ /** Adds a value to the document. */
2959
+ addIn(path, value) {
2960
+ if (assertCollection(this.contents))
2961
+ this.contents.addIn(path, value);
2962
+ }
2963
+ /**
2964
+ * Create a new `Alias` node, ensuring that the target `node` has the required anchor.
2965
+ *
2966
+ * If `node` already has an anchor, `name` is ignored.
2967
+ * Otherwise, the `node.anchor` value will be set to `name`,
2968
+ * or if an anchor with that name is already present in the document,
2969
+ * `name` will be used as a prefix for a new unique anchor.
2970
+ * If `name` is undefined, the generated anchor will use 'a' as a prefix.
2971
+ */
2972
+ createAlias(node, name) {
2973
+ if (!node.anchor) {
2974
+ const prev = anchorNames(this);
2975
+ node.anchor = // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
2976
+ !name || prev.has(name) ? findNewAnchor(name || "a", prev) : name;
2977
+ }
2978
+ return new Alias(node.anchor);
2979
+ }
2980
+ createNode(value, replacer, options) {
2981
+ let _replacer = void 0;
2982
+ if (typeof replacer === "function") {
2983
+ value = replacer.call({ "": value }, "", value);
2984
+ _replacer = replacer;
2985
+ } else if (Array.isArray(replacer)) {
2986
+ const keyToStr = (v) => typeof v === "number" || v instanceof String || v instanceof Number;
2987
+ const asStr = replacer.filter(keyToStr).map(String);
2988
+ if (asStr.length > 0)
2989
+ replacer = replacer.concat(asStr);
2990
+ _replacer = replacer;
2991
+ } else if (options === void 0 && replacer) {
2992
+ options = replacer;
2993
+ replacer = void 0;
2994
+ }
2995
+ const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options ?? {};
2996
+ const { onAnchor, setAnchors, sourceObjects } = createNodeAnchors(
2997
+ this,
2998
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
2999
+ anchorPrefix || "a"
3000
+ );
3001
+ const ctx = {
3002
+ aliasDuplicateObjects: aliasDuplicateObjects ?? true,
3003
+ keepUndefined: keepUndefined ?? false,
3004
+ onAnchor,
3005
+ onTagObj,
3006
+ replacer: _replacer,
3007
+ schema: this.schema,
3008
+ sourceObjects
3009
+ };
3010
+ const node = createNode(value, tag, ctx);
3011
+ if (flow && isCollection(node))
3012
+ node.flow = true;
3013
+ setAnchors();
3014
+ return node;
3015
+ }
3016
+ /**
3017
+ * Convert a key and a value into a `Pair` using the current schema,
3018
+ * recursively wrapping all values as `Scalar` or `Collection` nodes.
3019
+ */
3020
+ createPair(key2, value, options = {}) {
3021
+ const k = this.createNode(key2, null, options);
3022
+ const v = this.createNode(value, null, options);
3023
+ return new Pair(k, v);
3024
+ }
3025
+ /**
3026
+ * Removes a value from the document.
3027
+ * @returns `true` if the item was found and removed.
3028
+ */
3029
+ delete(key2) {
3030
+ return assertCollection(this.contents) ? this.contents.delete(key2) : false;
3031
+ }
3032
+ /**
3033
+ * Removes a value from the document.
3034
+ * @returns `true` if the item was found and removed.
3035
+ */
3036
+ deleteIn(path) {
3037
+ if (isEmptyPath(path)) {
3038
+ if (this.contents == null)
3039
+ return false;
3040
+ this.contents = null;
3041
+ return true;
3042
+ }
3043
+ return assertCollection(this.contents) ? this.contents.deleteIn(path) : false;
3044
+ }
3045
+ /**
3046
+ * Returns item at `key`, or `undefined` if not found. By default unwraps
3047
+ * scalar values from their surrounding node; to disable set `keepScalar` to
3048
+ * `true` (collections are always returned intact).
3049
+ */
3050
+ get(key2, keepScalar) {
3051
+ return isCollection(this.contents) ? this.contents.get(key2, keepScalar) : void 0;
3052
+ }
3053
+ /**
3054
+ * Returns item at `path`, or `undefined` if not found. By default unwraps
3055
+ * scalar values from their surrounding node; to disable set `keepScalar` to
3056
+ * `true` (collections are always returned intact).
3057
+ */
3058
+ getIn(path, keepScalar) {
3059
+ if (isEmptyPath(path))
3060
+ return !keepScalar && isScalar(this.contents) ? this.contents.value : this.contents;
3061
+ return isCollection(this.contents) ? this.contents.getIn(path, keepScalar) : void 0;
3062
+ }
3063
+ /**
3064
+ * Checks if the document includes a value with the key `key`.
3065
+ */
3066
+ has(key2) {
3067
+ return isCollection(this.contents) ? this.contents.has(key2) : false;
3068
+ }
3069
+ /**
3070
+ * Checks if the document includes a value at `path`.
3071
+ */
3072
+ hasIn(path) {
3073
+ if (isEmptyPath(path))
3074
+ return this.contents !== void 0;
3075
+ return isCollection(this.contents) ? this.contents.hasIn(path) : false;
3076
+ }
3077
+ /**
3078
+ * Sets a value in this document. For `!!set`, `value` needs to be a
3079
+ * boolean to add/remove the item from the set.
3080
+ */
3081
+ set(key2, value) {
3082
+ if (this.contents == null) {
3083
+ this.contents = collectionFromPath(this.schema, [key2], value);
3084
+ } else if (assertCollection(this.contents)) {
3085
+ this.contents.set(key2, value);
3086
+ }
3087
+ }
3088
+ /**
3089
+ * Sets a value in this document. For `!!set`, `value` needs to be a
3090
+ * boolean to add/remove the item from the set.
3091
+ */
3092
+ setIn(path, value) {
3093
+ if (isEmptyPath(path)) {
3094
+ this.contents = value;
3095
+ } else if (this.contents == null) {
3096
+ this.contents = collectionFromPath(this.schema, Array.from(path), value);
3097
+ } else if (assertCollection(this.contents)) {
3098
+ this.contents.setIn(path, value);
3099
+ }
3100
+ }
3101
+ /**
3102
+ * Change the YAML version and schema used by the document.
3103
+ * A `null` version disables support for directives, explicit tags, anchors, and aliases.
3104
+ * It also requires the `schema` option to be given as a `Schema` instance value.
3105
+ *
3106
+ * Overrides all previously set schema options.
3107
+ */
3108
+ setSchema(version, options = {}) {
3109
+ if (typeof version === "number")
3110
+ version = String(version);
3111
+ let opt;
3112
+ switch (version) {
3113
+ case "1.1":
3114
+ if (this.directives)
3115
+ this.directives.yaml.version = "1.1";
3116
+ else
3117
+ this.directives = new Directives({ version: "1.1" });
3118
+ opt = { resolveKnownTags: false, schema: "yaml-1.1" };
3119
+ break;
3120
+ case "1.2":
3121
+ case "next":
3122
+ if (this.directives)
3123
+ this.directives.yaml.version = version;
3124
+ else
3125
+ this.directives = new Directives({ version });
3126
+ opt = { resolveKnownTags: true, schema: "core" };
3127
+ break;
3128
+ case null:
3129
+ if (this.directives)
3130
+ delete this.directives;
3131
+ opt = null;
3132
+ break;
3133
+ default: {
3134
+ const sv = JSON.stringify(version);
3135
+ throw new Error(`Expected '1.1', '1.2' or null as first argument, but found: ${sv}`);
3136
+ }
3137
+ }
3138
+ if (options.schema instanceof Object)
3139
+ this.schema = options.schema;
3140
+ else if (opt)
3141
+ this.schema = new Schema(Object.assign(opt, options));
3142
+ else
3143
+ throw new Error(`With a null YAML version, the { schema: Schema } option is required`);
3144
+ }
3145
+ // json & jsonArg are only used from toJSON()
3146
+ toJS({ json, jsonArg, mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
3147
+ const ctx = {
3148
+ anchors: /* @__PURE__ */ new Map(),
3149
+ doc: this,
3150
+ keep: !json,
3151
+ mapAsMap: mapAsMap === true,
3152
+ mapKeyWarned: false,
3153
+ maxAliasCount: typeof maxAliasCount === "number" ? maxAliasCount : 100
3154
+ };
3155
+ const res = toJS(this.contents, jsonArg ?? "", ctx);
3156
+ if (typeof onAnchor === "function")
3157
+ for (const { count, res: res2 } of ctx.anchors.values())
3158
+ onAnchor(res2, count);
3159
+ return typeof reviver === "function" ? applyReviver(reviver, { "": res }, "", res) : res;
3160
+ }
3161
+ /**
3162
+ * A JSON representation of the document `contents`.
3163
+ *
3164
+ * @param jsonArg Used by `JSON.stringify` to indicate the array index or
3165
+ * property name.
3166
+ */
3167
+ toJSON(jsonArg, onAnchor) {
3168
+ return this.toJS({ json: true, jsonArg, mapAsMap: false, onAnchor });
3169
+ }
3170
+ /** A YAML representation of the document. */
3171
+ toString(options = {}) {
3172
+ if (this.errors.length > 0)
3173
+ throw new Error("Document with errors cannot be stringified");
3174
+ if ("indent" in options && (!Number.isInteger(options.indent) || Number(options.indent) <= 0)) {
3175
+ const s = JSON.stringify(options.indent);
3176
+ throw new Error(`"indent" option must be a positive integer, not ${s}`);
3177
+ }
3178
+ return stringifyDocument(this, options);
3179
+ }
3180
+ };
3181
+ function assertCollection(contents) {
3182
+ if (isCollection(contents))
3183
+ return true;
3184
+ throw new Error("Expected a YAML collection as document contents");
3185
+ }
3186
+
3187
+ // ../../node_modules/yaml/browser/dist/parse/cst-visit.js
3188
+ var BREAK2 = /* @__PURE__ */ Symbol("break visit");
3189
+ var SKIP2 = /* @__PURE__ */ Symbol("skip children");
3190
+ var REMOVE2 = /* @__PURE__ */ Symbol("remove item");
3191
+ function visit2(cst, visitor) {
3192
+ if ("type" in cst && cst.type === "document")
3193
+ cst = { start: cst.start, value: cst.value };
3194
+ _visit(Object.freeze([]), cst, visitor);
3195
+ }
3196
+ visit2.BREAK = BREAK2;
3197
+ visit2.SKIP = SKIP2;
3198
+ visit2.REMOVE = REMOVE2;
3199
+ visit2.itemAtPath = (cst, path) => {
3200
+ let item = cst;
3201
+ for (const [field, index] of path) {
3202
+ const tok = item?.[field];
3203
+ if (tok && "items" in tok) {
3204
+ item = tok.items[index];
3205
+ } else
3206
+ return void 0;
3207
+ }
3208
+ return item;
3209
+ };
3210
+ visit2.parentCollection = (cst, path) => {
3211
+ const parent = visit2.itemAtPath(cst, path.slice(0, -1));
3212
+ const field = path[path.length - 1][0];
3213
+ const coll = parent?.[field];
3214
+ if (coll && "items" in coll)
3215
+ return coll;
3216
+ throw new Error("Parent collection not found");
3217
+ };
3218
+ function _visit(path, item, visitor) {
3219
+ let ctrl = visitor(item, path);
3220
+ if (typeof ctrl === "symbol")
3221
+ return ctrl;
3222
+ for (const field of ["key", "value"]) {
3223
+ const token = item[field];
3224
+ if (token && "items" in token) {
3225
+ for (let i = 0; i < token.items.length; ++i) {
3226
+ const ci = _visit(Object.freeze(path.concat([[field, i]])), token.items[i], visitor);
3227
+ if (typeof ci === "number")
3228
+ i = ci - 1;
3229
+ else if (ci === BREAK2)
3230
+ return BREAK2;
3231
+ else if (ci === REMOVE2) {
3232
+ token.items.splice(i, 1);
3233
+ i -= 1;
3234
+ }
3235
+ }
3236
+ if (typeof ctrl === "function" && field === "key")
3237
+ ctrl = ctrl(item, path);
3238
+ }
3239
+ }
3240
+ return typeof ctrl === "function" ? ctrl(item, path) : ctrl;
3241
+ }
3242
+
3243
+ // ../../node_modules/yaml/browser/dist/parse/lexer.js
3244
+ var hexDigits = new Set("0123456789ABCDEFabcdef");
3245
+ var tagChars = new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()");
3246
+ var flowIndicatorChars = new Set(",[]{}");
3247
+ var invalidAnchorChars = new Set(" ,[]{}\n\r ");
3248
+
3249
+ // ../../node_modules/yaml/browser/dist/public-api.js
3250
+ function stringify3(value, replacer, options) {
3251
+ let _replacer = null;
3252
+ if (typeof replacer === "function" || Array.isArray(replacer)) {
3253
+ _replacer = replacer;
3254
+ } else if (options === void 0 && replacer) {
3255
+ options = replacer;
3256
+ }
3257
+ if (typeof options === "string")
3258
+ options = options.length;
3259
+ if (typeof options === "number") {
3260
+ const indent = Math.round(options);
3261
+ options = indent < 1 ? void 0 : indent > 8 ? { indent: 8 } : { indent };
3262
+ }
3263
+ if (value === void 0) {
3264
+ const { keepUndefined } = options ?? replacer ?? {};
3265
+ if (!keepUndefined)
3266
+ return void 0;
3267
+ }
3268
+ if (isDocument(value) && !_replacer)
3269
+ return value.toString(options);
3270
+ return new Document(value, _replacer, options).toString(options);
3271
+ }
3272
+
3273
+ // ../../extension/src/sim/notSimulated.ts
3274
+ var NotSimulated = class extends Error {
3275
+ constructor(what) {
3276
+ super(`${what} isn't simulated offline; run this test online`);
3277
+ this.what = what;
3278
+ this.name = "NotSimulated";
3279
+ }
3280
+ what;
3281
+ /** Already in the event log (the guard logs as it throws); the simulator logs the others. */
3282
+ logged = false;
3283
+ };
3284
+ function guard(target, path, onMiss) {
3285
+ return new Proxy(target, {
3286
+ get(t, name, receiver) {
3287
+ if (typeof name === "symbol" || name in t) return Reflect.get(t, name, receiver);
3288
+ if (name === "then" || name === "toJSON") return void 0;
3289
+ const what = `${path}.${name}`;
3290
+ onMiss(what);
3291
+ return () => {
3292
+ const e = new NotSimulated(what);
3293
+ e.logged = true;
3294
+ throw e;
3295
+ };
3296
+ }
3297
+ });
3298
+ }
3299
+
3300
+ // ../../extension/src/sim/values.ts
3301
+ var NUMBER = /* @__PURE__ */ new Set(["wholeNumber", "decimal", "float", "currency", "bigInteger"]);
3302
+ var LOOKUP = /* @__PURE__ */ new Set(["lookup", "customer", "owner"]);
3303
+ var DATE = /* @__PURE__ */ new Set(["date", "dateTime"]);
3304
+ var TYPES = {
3305
+ text: "string",
3306
+ multiline: "memo",
3307
+ wholeNumber: "integer",
3308
+ decimal: "decimal",
3309
+ float: "double",
3310
+ currency: "money",
3311
+ bigInteger: "bigint",
3312
+ date: "datetime",
3313
+ dateTime: "datetime",
3314
+ choice: "optionset",
3315
+ choices: "multiselectoptionset",
3316
+ yesNo: "boolean",
3317
+ lookup: "lookup",
3318
+ customer: "lookup",
3319
+ owner: "lookup"
3320
+ };
3321
+ var attributeType = (type) => TYPES[type] ?? "string";
3322
+ var isLookup = (col) => LOOKUP.has(col.type);
3323
+ var bare = (id) => id.replace(/[{}]/g, "").toLowerCase();
3324
+ var dateOnly = (col) => col.type === "date" || col.behavior === "dateOnly";
3325
+ var day = (d) => Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate());
3326
+ var asDate = (s) => new Date(s.length === 10 ? `${s}T00:00:00Z` : /(Z|[+-]\d\d:?\d\d)$/.test(s) ? s : `${s}Z`);
3327
+ function fromRecord(col, record, nameOf) {
3328
+ if (LOOKUP.has(col.type)) {
3329
+ const id = record[`_${col.name}_value`];
3330
+ if (typeof id !== "string") return null;
3331
+ const table = String(record[`_${col.name}_value@Microsoft.Dynamics.CRM.lookuplogicalname`] ?? col.target ?? "");
3332
+ return [{ id, name: nameOf(table, id), entityType: table }];
3333
+ }
3334
+ const v = record[col.name];
3335
+ if (v === void 0 || v === null || v === "") return null;
3336
+ if (NUMBER.has(col.type) || col.type === "choice") return Number(v);
3337
+ if (col.type === "choices") return String(v).split(",").filter(Boolean).map(Number);
3338
+ if (col.type === "yesNo") return v === true || v === "true" || v === 1;
3339
+ if (DATE.has(col.type)) return asDate(String(v));
3340
+ return String(v);
3341
+ }
3342
+ function toRecord(col, value) {
3343
+ if (LOOKUP.has(col.type)) return { [`_${col.name}_value`]: Array.isArray(value) && value.length > 0 ? value[0].id : null };
3344
+ if (value === null) return { [col.name]: null };
3345
+ if (col.type === "choices") return { [col.name]: value.join(",") };
3346
+ if (value instanceof Date) return { [col.name]: dateOnly(col) ? value.toISOString().slice(0, 10) : value.toISOString() };
3347
+ return { [col.name]: value };
3348
+ }
3349
+ function fromUser(col, text) {
3350
+ if (text.trim() === "") return null;
3351
+ if (col.type === "choices") return text.split(",").map((t) => t.trim()).filter(Boolean).map(Number);
3352
+ if (NUMBER.has(col.type) || col.type === "choice") return Number(text);
3353
+ if (col.type === "yesNo") return text === "true";
3354
+ if (DATE.has(col.type)) return asDate(text);
3355
+ return text;
3356
+ }
3357
+ function literal(col, text) {
3358
+ if (NUMBER.has(col.type)) return Number(text);
3359
+ if (col.type === "yesNo") return text === "true" || text === "1";
3360
+ if (DATE.has(col.type)) return asDate(text);
3361
+ if (col.type === "choice" || col.type === "choices") {
3362
+ if (/^-?\d+$/.test(text)) return Number(text);
3363
+ const matches = col.options.filter((o) => o.label.toLowerCase() === text.toLowerCase());
3364
+ if (matches.length !== 1) throw new NotSimulated(`the choice label "${text}" on ${col.name} (${matches.length === 0 ? "no option has it" : "two options share it"})`);
3365
+ return matches[0].value;
3366
+ }
3367
+ if (LOOKUP.has(col.type)) return [{ id: bare(text), name: "", entityType: col.target ?? "" }];
3368
+ return text;
3369
+ }
3370
+ var isEmpty = (v) => v === null || v === "" || Array.isArray(v) && v.length === 0;
3371
+ function compare(col, a, b) {
3372
+ if (isEmpty(a) || isEmpty(b)) return void 0;
3373
+ if (LOOKUP.has(col.type)) return bare(a[0].id) === bare(b[0].id) ? 0 : 1;
3374
+ if (a instanceof Date && b instanceof Date) return dateOnly(col) ? day(a) - day(b) : a.getTime() - b.getTime();
3375
+ if (typeof a === "number" && typeof b === "number") return a - b;
3376
+ if (typeof a === "boolean" && typeof b === "boolean") return a === b ? 0 : 1;
3377
+ if (Array.isArray(a) && Array.isArray(b)) return [...a].sort().join(",") === [...b].sort().join(",") ? 0 : 1;
3378
+ const x = String(a).toLowerCase();
3379
+ const y = String(b).toLowerCase();
3380
+ return x < y ? -1 : x > y ? 1 : 0;
3381
+ }
3382
+ var textOf = (v) => (v === null ? "" : Array.isArray(v) ? v.map((x) => typeof x === "object" ? x.name : String(x)).join(",") : v instanceof Date ? v.toISOString() : String(v)).toLowerCase();
3383
+ function display(col, v) {
3384
+ if (v === null) return "";
3385
+ if (col.type === "choice") return col.options.find((o) => o.value === v)?.label ?? String(v);
3386
+ if (col.type === "choices") return (Array.isArray(v) ? v : [Number(v)]).map((x) => col.options.find((o) => o.value === x)?.label ?? String(x)).join("; ");
3387
+ if (LOOKUP.has(col.type)) return v[0]?.name ?? "";
3388
+ if (v instanceof Date) return dateOnly(col) ? v.toISOString().slice(0, 10) : v.toISOString();
3389
+ if (typeof v === "boolean") return col.options.find((o) => o.value === (v ? 1 : 0))?.label ?? (v ? "Yes" : "No");
3390
+ return String(v);
3391
+ }
3392
+
3393
+ // ../../extension/src/sim/recorder.ts
3394
+ var Recorder = class {
3395
+ constructor(sim, formRef) {
3396
+ this.sim = sim;
3397
+ this.formRef = formRef;
3398
+ this.start = this.snapshot();
3399
+ this.startedAt = sim.log.entries.length;
3400
+ }
3401
+ sim;
3402
+ formRef;
3403
+ steps = [];
3404
+ start;
3405
+ startedAt;
3406
+ saved;
3407
+ snapshot() {
3408
+ const s = /* @__PURE__ */ new Map();
3409
+ for (const [field, value] of this.sim.state.values) {
3410
+ const c = this.sim.state.controls.get(field);
3411
+ s.set(field, { value: display(this.sim.state.columns.get(field), value), visible: c?.visible ?? true, disabled: c?.disabled ?? false, required: this.sim.state.required.get(field) ?? "none" });
3412
+ }
3413
+ return s;
3414
+ }
3415
+ /** A value as a test writes it: a choice by its label when only one option has it, a lookup by id, a date as text. */
3416
+ written(field, value) {
3417
+ const col = this.sim.state.columns.get(field);
3418
+ if (col.type === "choice" && typeof value === "number") {
3419
+ const option = col.options.find((o) => o.value === value);
3420
+ return option && col.options.filter((o) => o.label === option.label).length === 1 ? option.label : value;
3421
+ }
3422
+ if (Array.isArray(value) && value.length > 0 && typeof value[0] === "object") return value[0].id;
3423
+ if (value instanceof Date) return display(col, value);
3424
+ return value;
3425
+ }
3426
+ async set(field, value) {
3427
+ await this.sim.userSet(field, value);
3428
+ const last = this.steps.at(-1);
3429
+ if (last && "set" in last) last.set[field] = this.written(field, value);
3430
+ else this.steps.push({ set: { [field]: this.written(field, value) } });
3431
+ }
3432
+ async save() {
3433
+ this.saved = await this.sim.save();
3434
+ this.steps.push({ save: true });
3435
+ return this.saved;
3436
+ }
3437
+ testYaml(caseName = "Recorded in Try form") {
3438
+ const end = this.snapshot();
3439
+ const setFields = new Set(this.steps.flatMap((s) => "set" in s ? Object.keys(s.set) : []));
3440
+ const expect = {};
3441
+ for (const [field, after] of end) {
3442
+ const before = this.start.get(field);
3443
+ const changed = {};
3444
+ if (after.value !== before.value && !setFields.has(field)) changed.value = this.written(field, this.sim.state.values.get(field) ?? null);
3445
+ if (after.visible !== before.visible) changed.visible = after.visible;
3446
+ if (after.disabled !== before.disabled) changed.disabled = after.disabled;
3447
+ if (after.required !== before.required) changed.required = after.required === "required";
3448
+ if (Object.keys(changed).length > 0) expect[field] = changed;
3449
+ }
3450
+ if (this.saved !== void 0) expect.saved = this.saved;
3451
+ const acted = new Set(this.sim.log.entries.slice(this.startedAt).filter((e) => e.kind === "rule").map((e) => /^rule "([^"]+)" →/.exec(e.message)?.[1]).filter((n) => !!n));
3452
+ const covers = [...acted].map((n) => `rule:${this.sim.pkg.table}/${(this.sim.pkg.rules.find((r) => r.name === n)?.file ?? n).replace(/\.rule\.yaml$/, "")}`);
3453
+ const given = this.sim.pkg.open ? { given: { record: this.sim.pkg.open } } : {};
3454
+ return stringify3({ kind: "Test", form: this.formRef, ...covers.length > 0 ? { covers } : {}, ...given, cases: [{ name: caseName, steps: this.steps, expect }] });
3455
+ }
3456
+ };
3457
+
3458
+ // ../../extension/src/sim/formState.ts
3459
+ var FormState = class {
3460
+ columns = /* @__PURE__ */ new Map();
3461
+ values = /* @__PURE__ */ new Map();
3462
+ dirty = /* @__PURE__ */ new Set();
3463
+ required = /* @__PURE__ */ new Map();
3464
+ /** Body controls are named by their field; header and footer ones header_<field> and footer_<field>. */
3465
+ controls = /* @__PURE__ */ new Map();
3466
+ /** By tab name, or tab_<n> when the layout has none. */
3467
+ tabs = /* @__PURE__ */ new Map();
3468
+ formNotifications = /* @__PURE__ */ new Map();
3469
+ formType = 1;
3470
+ recordId;
3471
+ /** Handlers scripts added with addOnChange. */
3472
+ onChange = /* @__PURE__ */ new Map();
3473
+ listeners = [];
3474
+ constructor(pkg) {
3475
+ for (const c of pkg.columns) this.columns.set(c.name, c);
3476
+ const add = (name, cell) => {
3477
+ if (this.controls.has(name)) return;
3478
+ const column = cell.field ? this.columns.get(cell.field) : void 0;
3479
+ this.controls.set(name, {
3480
+ field: cell.field,
3481
+ visible: cell.visible !== false,
3482
+ disabled: cell.readOnly === true,
3483
+ label: cell.label ?? column?.label ?? cell.field ?? name,
3484
+ notifications: /* @__PURE__ */ new Map()
3485
+ });
3486
+ if (cell.field && column && !this.values.has(cell.field)) {
3487
+ this.values.set(cell.field, null);
3488
+ this.required.set(cell.field, column.requiredLevel);
3489
+ }
3490
+ };
3491
+ for (const cell of (pkg.form.header?.rows ?? []).flat()) if (cell.field) add(`header_${cell.field}`, cell);
3492
+ pkg.form.tabs.forEach((tab, t) => {
3493
+ const sections = /* @__PURE__ */ new Map();
3494
+ tab.sections.forEach((s, i) => {
3495
+ const name2 = s.name ?? `section_${i + 1}`;
3496
+ sections.set(name2, { name: name2, label: s.label ?? "", visible: s.visible !== false });
3497
+ for (const cell of s.rows.flat()) if (cell.field) add(cell.field, cell);
3498
+ });
3499
+ const name = tab.name ?? `tab_${t + 1}`;
3500
+ this.tabs.set(name, { name, label: tab.label ?? "", visible: tab.visible !== false, expanded: tab.expanded !== false, sections });
3501
+ });
3502
+ for (const cell of (pkg.form.footer?.rows ?? []).flat()) if (cell.field) add(`footer_${cell.field}`, cell);
3503
+ }
3504
+ changed() {
3505
+ for (const l of this.listeners) l();
3506
+ }
3507
+ };
3508
+
3509
+ // ../../extension/src/sim/log.ts
3510
+ var EventLog = class {
3511
+ entries = [];
3512
+ listeners = [];
3513
+ add(kind, message) {
3514
+ const entry = { seq: this.entries.length + 1, kind, message };
3515
+ this.entries.push(entry);
3516
+ for (const l of this.listeners) l(entry);
3517
+ }
3518
+ onAdd(listener) {
3519
+ this.listeners.push(listener);
3520
+ }
3521
+ };
3522
+
3523
+ // ../../extension/src/sim/formula.ts
3524
+ function evaluateFormula(text, valueOf, target) {
3525
+ const toks = text.match(/\d+(?:\.\d+)?|[A-Za-z_]\w*|[-+*/()]|\S/g) ?? [];
3526
+ const fail = () => {
3527
+ throw new NotSimulated(`the formula "${text}"`);
3528
+ };
3529
+ let p = 0;
3530
+ const atom = () => {
3531
+ const t = toks[p++];
3532
+ if (t === "(") {
3533
+ const v = sum();
3534
+ if (toks[p++] !== ")") fail();
3535
+ return v;
3536
+ }
3537
+ if (t === "-") {
3538
+ const v = atom();
3539
+ return typeof v === "number" ? -v : null;
3540
+ }
3541
+ if (t !== void 0 && /^\d/.test(t)) return Number(t);
3542
+ if (t !== void 0 && /^[A-Za-z_]/.test(t)) {
3543
+ if (toks[p] === "(") throw new NotSimulated(`the formula function ${t}`);
3544
+ const v = valueOf(t);
3545
+ if (v === null) return null;
3546
+ if (typeof v === "number" || v instanceof Date) return v;
3547
+ throw new NotSimulated(`the formula "${text}" (${t} isn't a number or a date)`);
3548
+ }
3549
+ return fail();
3550
+ };
3551
+ const product = () => {
3552
+ let v = atom();
3553
+ while (toks[p] === "*" || toks[p] === "/") {
3554
+ const op = toks[p++];
3555
+ const r = atom();
3556
+ v = typeof v === "number" && typeof r === "number" ? op === "*" ? v * r : v / r : null;
3557
+ }
3558
+ return v;
3559
+ };
3560
+ const sum = () => {
3561
+ let v = product();
3562
+ while (toks[p] === "+" || toks[p] === "-") {
3563
+ const op = toks[p++];
3564
+ const r = product();
3565
+ if (v instanceof Date && typeof r === "number") v = new Date(v.getTime() + (op === "+" ? r : -r) * 864e5);
3566
+ else if (typeof v === "number" && typeof r === "number") v = op === "+" ? v + r : v - r;
3567
+ else v = null;
3568
+ }
3569
+ return v;
3570
+ };
3571
+ if (toks.length === 0) fail();
3572
+ const result = sum();
3573
+ if (p !== toks.length) fail();
3574
+ return typeof result === "number" && target.type === "wholeNumber" ? Math.round(result) : result;
3575
+ }
3576
+
3577
+ // ../../extension/src/sim/rules.ts
3578
+ var MAX_DEPTH = 10;
3579
+ var errorId = (rule) => `rule:${rule}`;
3580
+ var TEXT_OPS = {
3581
+ contains: (a, b) => a.includes(b),
3582
+ notContains: (a, b) => !a.includes(b),
3583
+ beginsWith: (a, b) => a.startsWith(b),
3584
+ notBeginsWith: (a, b) => !a.startsWith(b),
3585
+ endsWith: (a, b) => a.endsWith(b),
3586
+ notEndsWith: (a, b) => !a.endsWith(b)
3587
+ };
3588
+ var RuleEngine = class {
3589
+ constructor(rules, state, log, effects) {
3590
+ this.rules = rules;
3591
+ this.state = state;
3592
+ this.log = log;
3593
+ this.effects = effects;
3594
+ this.simulated = rules.filter((r) => r.logic);
3595
+ for (const r of this.simulated) {
3596
+ this.watched.set(r, new Set(r.logic.branches.flatMap((b) => b.conditions.flatMap((c) => [c.column, ...c.value?.column ? [c.value.column] : []]))));
3597
+ }
3598
+ }
3599
+ rules;
3600
+ state;
3601
+ log;
3602
+ effects;
3603
+ simulated;
3604
+ watched = /* @__PURE__ */ new Map();
3605
+ depth = 0;
3606
+ chain = [];
3607
+ stopped = false;
3608
+ watches(field) {
3609
+ return this.simulated.some((r) => this.watched.get(r).has(field));
3610
+ }
3611
+ onLoad() {
3612
+ for (const r of this.rules.filter((x) => x.notSimulated)) this.log.add("notSimulated", `rule "${r.name}": ${r.notSimulated}`);
3613
+ this.stopped = false;
3614
+ for (const r of this.simulated) this.run(r);
3615
+ }
3616
+ onChange(field) {
3617
+ if (this.depth === 0) this.stopped = false;
3618
+ for (const r of this.simulated.filter((x) => this.watched.get(x).has(field))) this.run(r);
3619
+ }
3620
+ /** A rule's error is showing on the form (it blocks save). */
3621
+ hasErrors() {
3622
+ return [...this.state.controls.values()].some((c) => [...c.notifications.keys()].some((k) => k.startsWith("rule:")));
3623
+ }
3624
+ /** Entity-scope rules at save, as Dataverse runs them on the server: set and default apply; errors stop the save. */
3625
+ onSave() {
3626
+ const errors = [];
3627
+ for (const r of this.simulated.filter((x) => x.scope === "entity")) {
3628
+ try {
3629
+ for (const a of this.pick(r)?.actions ?? []) {
3630
+ if (a.kind === "error") errors.push(a.message ?? "");
3631
+ else if (a.kind === "set" || a.kind === "default") this.apply(r, a, true);
3632
+ }
3633
+ } catch (e) {
3634
+ this.report(r, e);
3635
+ }
3636
+ }
3637
+ for (const e of errors) this.log.add("save", `rule error stops the save: ${e}`);
3638
+ return errors;
3639
+ }
3640
+ value(rule, column, v) {
3641
+ const col = this.state.columns.get(column);
3642
+ if (!col) throw new NotSimulated(`rule "${rule.name}" using ${column}, which isn't a column of this table`);
3643
+ if (v.column !== void 0) return this.state.values.get(v.column) ?? null;
3644
+ if (v.formula !== void 0) return evaluateFormula(v.formula, (c) => this.state.values.get(c) ?? null, col);
3645
+ return literal(col, v.literal ?? "");
3646
+ }
3647
+ holds(rule, c) {
3648
+ const col = this.state.columns.get(c.column);
3649
+ if (!col) throw new NotSimulated(`rule "${rule.name}" using ${c.column}, which isn't a column of this table`);
3650
+ const current = this.state.values.get(c.column) ?? null;
3651
+ if (c.operator === "isEmpty") return isEmpty(current);
3652
+ if (c.operator === "hasData") return !isEmpty(current);
3653
+ const other = this.value(rule, c.column, c.value ?? {});
3654
+ if (TEXT_OPS[c.operator]) return !isEmpty(current) && TEXT_OPS[c.operator](textOf(current), textOf(other));
3655
+ const cmp = compare(col, current, other);
3656
+ if (cmp === void 0) return false;
3657
+ switch (c.operator) {
3658
+ case "equals":
3659
+ return cmp === 0;
3660
+ case "notEquals":
3661
+ return cmp !== 0;
3662
+ case "greaterThan":
3663
+ return cmp > 0;
3664
+ case "greaterOrEqual":
3665
+ return cmp >= 0;
3666
+ case "lessThan":
3667
+ return cmp < 0;
3668
+ case "lessOrEqual":
3669
+ return cmp <= 0;
3670
+ default:
3671
+ throw new NotSimulated(`the operator ${c.operator}`);
3672
+ }
3673
+ }
3674
+ pick(rule) {
3675
+ for (const b of rule.logic.branches) {
3676
+ if (b.kind === "always" || b.kind === "else") return b;
3677
+ const results = b.conditions.map((c) => this.holds(rule, c));
3678
+ if (b.match === "all" ? results.every(Boolean) : results.some(Boolean)) return b;
3679
+ }
3680
+ return void 0;
3681
+ }
3682
+ report(rule, e) {
3683
+ if (e instanceof NotSimulated) this.log.add("notSimulated", `rule "${rule.name}": ${e.what}`);
3684
+ else this.log.add("error", `rule "${rule.name}": ${e instanceof Error ? e.message : String(e)}`);
3685
+ }
3686
+ run(rule) {
3687
+ if (this.stopped) return;
3688
+ if (this.depth >= MAX_DEPTH) {
3689
+ this.stopped = true;
3690
+ this.log.add("error", `rule loop: ${[...new Set(this.chain)].join(" \u2192 ")} kept changing each other's fields; stopped after ${MAX_DEPTH} levels`);
3691
+ return;
3692
+ }
3693
+ this.depth++;
3694
+ this.chain.push(rule.name);
3695
+ try {
3696
+ for (const c of this.state.controls.values()) c.notifications.delete(errorId(rule.name));
3697
+ const branch = this.pick(rule);
3698
+ if (!branch) this.log.add("rule", `rule "${rule.name}": no branch taken`);
3699
+ else for (const a of branch.actions) this.apply(rule, a, false);
3700
+ } catch (e) {
3701
+ this.report(rule, e);
3702
+ } finally {
3703
+ this.depth--;
3704
+ this.chain.pop();
3705
+ this.state.changed();
3706
+ }
3707
+ }
3708
+ apply(rule, a, onSave) {
3709
+ const control = this.state.controls.get(a.column);
3710
+ const say = (what) => this.log.add("rule", `rule "${rule.name}" \u2192 ${what}`);
3711
+ switch (a.kind) {
3712
+ case "show":
3713
+ case "hide":
3714
+ if (control) control.visible = a.kind === "show";
3715
+ return say(`${a.kind} ${a.column}`);
3716
+ case "lock":
3717
+ case "unlock":
3718
+ if (control) control.disabled = a.kind === "lock";
3719
+ return say(`${a.kind} ${a.column}`);
3720
+ case "require":
3721
+ case "unrequire":
3722
+ this.state.required.set(a.column, a.kind === "require" ? "required" : "none");
3723
+ return say(`${a.kind} ${a.column}`);
3724
+ case "error":
3725
+ control?.notifications.set(errorId(rule.name), a.message ?? "");
3726
+ return say(`error on ${a.column}: ${a.message ?? ""}`);
3727
+ case "clear":
3728
+ case "set":
3729
+ case "default": {
3730
+ if (a.kind === "default" && (this.state.formType !== 1 || !isEmpty(this.state.values.get(a.column) ?? null))) return;
3731
+ const col = this.state.columns.get(a.column);
3732
+ if (!col) throw new NotSimulated(`rule "${rule.name}" setting ${a.column}, which isn't a column of this table`);
3733
+ const v = a.kind === "clear" ? null : this.value(rule, a.column, a.value ?? {});
3734
+ say(`${a.kind} ${a.column}${a.kind === "clear" ? "" : ` = ${display(col, v) || "(empty)"}`}`);
3735
+ if (onSave) {
3736
+ this.state.values.set(a.column, v);
3737
+ this.state.dirty.add(a.column);
3738
+ } else this.effects.setValue(a.column, v, rule.name);
3739
+ return;
3740
+ }
3741
+ default:
3742
+ throw new NotSimulated(`the action ${a.kind}`);
3743
+ }
3744
+ }
3745
+ };
3746
+
3747
+ // ../../extension/src/sim/odata.ts
3748
+ var SUPPORTED = /* @__PURE__ */ new Set(["$select", "$filter", "$orderby", "$top"]);
3749
+ var OPS = /* @__PURE__ */ new Set(["eq", "ne", "gt", "ge", "lt", "le", "and", "or", "not"]);
3750
+ function parseQuery(options) {
3751
+ const q = {};
3752
+ const text = options.replace(/^\?/, "");
3753
+ if (!text) return q;
3754
+ for (const part of text.split("&")) {
3755
+ const eq = part.indexOf("=");
3756
+ const key2 = decodeURIComponent(eq < 0 ? part : part.slice(0, eq));
3757
+ const value = decodeURIComponent(eq < 0 ? "" : part.slice(eq + 1));
3758
+ if (!SUPPORTED.has(key2)) throw new NotSimulated(key2);
3759
+ if (key2 === "$select") q.select = value.split(",").map((s) => s.trim()).filter(Boolean);
3760
+ else if (key2 === "$top") q.top = Number(value);
3761
+ else if (key2 === "$orderby") q.orderBy = value.split(",").map((s) => s.trim().split(/\s+/)).map(([field, dir]) => ({ field, desc: dir === "desc" }));
3762
+ else q.filter = parseFilter(value);
3763
+ }
3764
+ return q;
3765
+ }
3766
+ function tokens(s) {
3767
+ const out = [];
3768
+ const re = /\s*(?:(\()|(\))|(,)|'((?:[^']|'')*)'|([0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12})(?![\w-])|(-?\d+(?:\.\d+)?)(?![\w-])|([A-Za-z_][\w.@-]*))\s*/y;
3769
+ let i = 0;
3770
+ while (i < s.length) {
3771
+ re.lastIndex = i;
3772
+ const m = re.exec(s);
3773
+ if (!m || re.lastIndex === i) throw new NotSimulated(`the $filter "${s}"`);
3774
+ i = re.lastIndex;
3775
+ if (m[1]) out.push({ t: "(", v: "(" });
3776
+ else if (m[2]) out.push({ t: ")", v: ")" });
3777
+ else if (m[3]) out.push({ t: ",", v: "," });
3778
+ else if (m[4] !== void 0) out.push({ t: "str", v: m[4].replace(/''/g, "'") });
3779
+ else if (m[5]) out.push({ t: "id", v: m[5] });
3780
+ else if (m[6]) out.push({ t: "num", v: m[6] });
3781
+ else if (m[7]) out.push({ t: OPS.has(m[7]) ? "op" : "id", v: m[7] });
3782
+ }
3783
+ return out;
3784
+ }
3785
+ function parseFilter(s) {
3786
+ const toks = tokens(s);
3787
+ let p = 0;
3788
+ const fail = () => {
3789
+ throw new NotSimulated(`the $filter "${s}"`);
3790
+ };
3791
+ const take = (t) => {
3792
+ const tok = toks[p++];
3793
+ if (!tok || t && tok.t !== t) fail();
3794
+ return tok;
3795
+ };
3796
+ const value = () => {
3797
+ const tok = take();
3798
+ if (tok.t === "str") return tok.v;
3799
+ if (tok.t === "num") return Number(tok.v);
3800
+ if (tok.t !== "id") return fail();
3801
+ if (tok.v === "null") return null;
3802
+ if (tok.v === "true" || tok.v === "false") return tok.v === "true";
3803
+ if (/^[\w-]+$/.test(tok.v)) return tok.v;
3804
+ return fail();
3805
+ };
3806
+ const cmp = (a, b) => typeof a === "number" && typeof b === "number" ? a - b : String(a).toLowerCase() < String(b).toLowerCase() ? -1 : String(a).toLowerCase() > String(b).toLowerCase() ? 1 : 0;
3807
+ const primary = () => {
3808
+ const tok = toks[p];
3809
+ if (!tok) return fail();
3810
+ if (tok.t === "(") {
3811
+ take("(");
3812
+ const inner = or();
3813
+ take(")");
3814
+ return inner;
3815
+ }
3816
+ if (tok.t === "op" && tok.v === "not") {
3817
+ take();
3818
+ const inner = primary();
3819
+ return (r) => !inner(r);
3820
+ }
3821
+ if (tok.t === "id" && toks[p + 1]?.t === "(") {
3822
+ if (!["contains", "startswith", "endswith"].includes(tok.v)) throw new NotSimulated(`the $filter function ${tok.v}`);
3823
+ const fn = take().v;
3824
+ take("(");
3825
+ const field2 = take("id").v;
3826
+ take(",");
3827
+ const text = String(value()).toLowerCase();
3828
+ take(")");
3829
+ return (r) => {
3830
+ const v2 = String(r[field2] ?? "").toLowerCase();
3831
+ return fn === "contains" ? v2.includes(text) : fn === "startswith" ? v2.startsWith(text) : v2.endsWith(text);
3832
+ };
3833
+ }
3834
+ const field = take("id").v;
3835
+ const op = take("op").v;
3836
+ if (!["eq", "ne", "gt", "ge", "lt", "le"].includes(op)) fail();
3837
+ const v = value();
3838
+ return (r) => {
3839
+ const x = r[field] ?? null;
3840
+ if (op === "eq") return v === null ? x === null : x !== null && cmp(x, v) === 0;
3841
+ if (op === "ne") return v === null ? x !== null : x === null || cmp(x, v) !== 0;
3842
+ if (x === null || v === null) return false;
3843
+ const c = cmp(x, v);
3844
+ return op === "gt" ? c > 0 : op === "ge" ? c >= 0 : op === "lt" ? c < 0 : c <= 0;
3845
+ };
3846
+ };
3847
+ const and = () => {
3848
+ let left = primary();
3849
+ while (toks[p]?.v === "and") {
3850
+ take();
3851
+ const l = left;
3852
+ const r = primary();
3853
+ left = (x) => l(x) && r(x);
3854
+ }
3855
+ return left;
3856
+ };
3857
+ const or = () => {
3858
+ let left = and();
3859
+ while (toks[p]?.v === "or") {
3860
+ take();
3861
+ const l = left;
3862
+ const r = and();
3863
+ left = (x) => l(x) || r(x);
3864
+ }
3865
+ return left;
3866
+ };
3867
+ const pred = or();
3868
+ if (p < toks.length) fail();
3869
+ return pred;
3870
+ }
3871
+
3872
+ // ../../extension/src/sim/store.ts
3873
+ var key = (id) => id.replace(/[{}]/g, "").toLowerCase();
3874
+ var Store = class {
3875
+ constructor(tables, records, newId, lookupColumns = {}) {
3876
+ this.tables = tables;
3877
+ this.newId = newId;
3878
+ this.lookupColumns = lookupColumns;
3879
+ for (const r of records) this.put({ table: r.table, id: r.id, values: this.normalise(r.table, r.values) });
3880
+ }
3881
+ tables;
3882
+ newId;
3883
+ lookupColumns;
3884
+ records = /* @__PURE__ */ new Map();
3885
+ /** Lookups given as col: id (seed output, hand-written records) are held as the Web API holds them: _col_value. */
3886
+ normalise(table, values) {
3887
+ const lookups = new Set(this.lookupColumns[table] ?? []);
3888
+ return Object.fromEntries(Object.entries(values).map(([k, v]) => {
3889
+ const bind = /^(.+)@odata\.bind$/.exec(k);
3890
+ if (bind && typeof v === "string") return [`_${bind[1].toLowerCase()}_value`, (/\(([^)]+)\)\s*$/.exec(v)?.[1] ?? v).replace(/[{}]/g, "").toLowerCase()];
3891
+ return lookups.has(k) ? [`_${k}_value`, v] : [k, v];
3892
+ }));
3893
+ }
3894
+ put(r) {
3895
+ if (!this.records.has(r.table)) this.records.set(r.table, /* @__PURE__ */ new Map());
3896
+ this.records.get(r.table).set(key(r.id), r);
3897
+ }
3898
+ primaryId(table) {
3899
+ return this.tables[table]?.primaryId ?? `${table}id`;
3900
+ }
3901
+ all(table) {
3902
+ return [...this.records.get(table)?.values() ?? []];
3903
+ }
3904
+ get(table, id) {
3905
+ return this.records.get(table)?.get(key(id));
3906
+ }
3907
+ create(table, values) {
3908
+ const id = this.newId();
3909
+ this.put({ table, id, values: this.normalise(table, { ...values }) });
3910
+ return id;
3911
+ }
3912
+ update(table, id, values) {
3913
+ const r = this.get(table, id);
3914
+ if (!r) throw new Error(`No ${table} record ${id} in the offline data.`);
3915
+ r.values = { ...r.values, ...this.normalise(table, values) };
3916
+ }
3917
+ delete(table, id) {
3918
+ this.records.get(table)?.delete(key(id));
3919
+ }
3920
+ nameOf(table, id) {
3921
+ const name = this.tables[table]?.primaryName;
3922
+ const r = this.get(table, id);
3923
+ return name && r ? String(r.values[name] ?? "") : "";
3924
+ }
3925
+ /** The record as the Web API returns it: its id under the primary id name, then the values ($select keeps those named). */
3926
+ webApi(table, record, select) {
3927
+ const out = { [this.primaryId(table)]: record.id };
3928
+ for (const [k, v] of Object.entries(record.values)) {
3929
+ const name = k.startsWith("_") && k.endsWith("_value") ? k.slice(1, -6) : k;
3930
+ if (!select || select.includes(k) || select.includes(name)) out[k] = v;
3931
+ }
3932
+ return out;
3933
+ }
3934
+ query(table, options) {
3935
+ const q = parseQuery(options);
3936
+ let rows = this.all(table).map((r) => this.webApi(table, r));
3937
+ if (q.filter) rows = rows.filter(q.filter);
3938
+ for (const o of [...q.orderBy ?? []].reverse()) {
3939
+ rows.sort((a, b) => {
3940
+ const x = a[o.field];
3941
+ const y = b[o.field];
3942
+ const c = typeof x === "number" && typeof y === "number" ? x - y : String(x ?? "").localeCompare(String(y ?? ""));
3943
+ return o.desc ? -c : c;
3944
+ });
3945
+ }
3946
+ if (q.top !== void 0) rows = rows.slice(0, q.top);
3947
+ if (!q.select) return rows;
3948
+ const id = this.primaryId(table);
3949
+ return rows.map((r) => Object.fromEntries(Object.entries(r).filter(([k]) => k === id || q.select.includes(k) || q.select.includes(k.replace(/^_(.*)_value$/, "$1")))));
3950
+ }
3951
+ };
3952
+
3953
+ // ../../extension/src/sim/xrm.ts
3954
+ function createXrm(state, store, log, pkg, hooks, user) {
3955
+ const miss = (what) => log.add("notSimulated", what);
3956
+ const g = (o, path) => guard(o, path, miss);
3957
+ const touch = () => state.changed();
3958
+ const collection = (items, wrap) => ({
3959
+ get: (arg) => {
3960
+ const names = items();
3961
+ if (arg === void 0) return names.map(wrap);
3962
+ if (typeof arg === "function") return names.map(wrap).filter(arg);
3963
+ if (typeof arg === "number") return names[arg] !== void 0 ? wrap(names[arg]) : null;
3964
+ return names.includes(arg) ? wrap(arg) : null;
3965
+ },
3966
+ forEach: (f) => items().forEach((n, i) => f(wrap(n), i)),
3967
+ getLength: () => items().length
3968
+ });
3969
+ const control = (name) => {
3970
+ const c = state.controls.get(name);
3971
+ if (!c) return null;
3972
+ return g({
3973
+ getName: () => name,
3974
+ getControlType: () => "standard",
3975
+ getAttribute: () => c.field ? attribute(c.field) : null,
3976
+ getVisible: () => c.visible,
3977
+ setVisible: (v) => {
3978
+ c.visible = v;
3979
+ log.add("xrm", `${name} ${v ? "shown" : "hidden"}`);
3980
+ touch();
3981
+ },
3982
+ getDisabled: () => c.disabled,
3983
+ setDisabled: (v) => {
3984
+ c.disabled = v;
3985
+ log.add("xrm", `${name} ${v ? "locked" : "unlocked"}`);
3986
+ touch();
3987
+ },
3988
+ getLabel: () => c.label,
3989
+ setLabel: (l) => {
3990
+ c.label = l;
3991
+ touch();
3992
+ },
3993
+ setNotification: (message, id = "default") => {
3994
+ c.notifications.set(id, message);
3995
+ log.add("xrm", `${name} notification: ${message}`);
3996
+ touch();
3997
+ return true;
3998
+ },
3999
+ clearNotification: (id) => {
4000
+ if (id === void 0) c.notifications.clear();
4001
+ else c.notifications.delete(id);
4002
+ touch();
4003
+ return true;
4004
+ },
4005
+ addNotification: (n) => {
4006
+ c.notifications.set(n.uniqueId ?? "default", (n.messages ?? []).join(" "));
4007
+ touch();
4008
+ },
4009
+ setFocus: () => {
4010
+ }
4011
+ }, `formContext.getControl("${name}")`);
4012
+ };
4013
+ const controlsOf = (field) => () => [...state.controls.entries()].filter(([, c]) => c.field === field).map(([n]) => n);
4014
+ const attribute = (name) => {
4015
+ const col = state.columns.get(name);
4016
+ if (!col || !state.values.has(name)) return null;
4017
+ return g({
4018
+ getName: () => name,
4019
+ getValue: () => state.values.get(name) ?? null,
4020
+ setValue: (v) => {
4021
+ state.values.set(name, v ?? null);
4022
+ state.dirty.add(name);
4023
+ log.add("value", `${name} = ${display(col, v ?? null) || "(empty)"} (script)`);
4024
+ touch();
4025
+ },
4026
+ getText: () => display(col, state.values.get(name) ?? null) || null,
4027
+ getAttributeType: () => attributeType(col.type),
4028
+ getFormat: () => col.type === "date" || col.behavior === "dateOnly" ? "date" : col.type === "dateTime" ? "datetime" : col.type === "multiline" ? "textarea" : col.type === "currency" ? "money" : "text",
4029
+ getOptions: () => col.options.map((o) => ({ text: o.label, value: o.value })),
4030
+ getOption: (v) => {
4031
+ const o = col.options.find((x) => x.value === v || x.label === v);
4032
+ return o ? { text: o.label, value: o.value } : null;
4033
+ },
4034
+ getSelectedOption: () => {
4035
+ const v = state.values.get(name);
4036
+ const o = col.options.find((x) => x.value === v);
4037
+ return o ? { text: o.label, value: o.value } : null;
4038
+ },
4039
+ getMaxLength: () => col.maxLength ?? null,
4040
+ getMin: () => col.minValue ?? null,
4041
+ getMax: () => col.maxValue ?? null,
4042
+ getRequiredLevel: () => state.required.get(name) ?? "none",
4043
+ setRequiredLevel: (level) => {
4044
+ state.required.set(name, level);
4045
+ log.add("xrm", `${name} required level ${level}`);
4046
+ touch();
4047
+ },
4048
+ getIsDirty: () => state.dirty.has(name),
4049
+ addOnChange: (fn) => {
4050
+ state.onChange.set(name, [...state.onChange.get(name) ?? [], fn]);
4051
+ },
4052
+ removeOnChange: (fn) => {
4053
+ state.onChange.set(name, (state.onChange.get(name) ?? []).filter((f) => f !== fn));
4054
+ },
4055
+ fireOnChange: () => hooks.fireOnChange(name),
4056
+ controls: collection(controlsOf(name), control)
4057
+ }, `formContext.getAttribute("${name}")`);
4058
+ };
4059
+ const tab = (name) => {
4060
+ const t = state.tabs.get(name);
4061
+ return g({
4062
+ getName: () => name,
4063
+ getLabel: () => t.label,
4064
+ setLabel: (l) => {
4065
+ t.label = l;
4066
+ touch();
4067
+ },
4068
+ getVisible: () => t.visible,
4069
+ setVisible: (v) => {
4070
+ t.visible = v;
4071
+ log.add("xrm", `tab ${name} ${v ? "shown" : "hidden"}`);
4072
+ touch();
4073
+ },
4074
+ getDisplayState: () => t.expanded ? "expanded" : "collapsed",
4075
+ setDisplayState: (s) => {
4076
+ t.expanded = s === "expanded";
4077
+ log.add("xrm", `tab ${name} ${s}`);
4078
+ touch();
4079
+ },
4080
+ setFocus: () => {
4081
+ },
4082
+ sections: collection(() => [...t.sections.keys()], (n) => {
4083
+ const s = t.sections.get(n);
4084
+ return g({
4085
+ getName: () => n,
4086
+ getLabel: () => s.label,
4087
+ setLabel: (l) => {
4088
+ s.label = l;
4089
+ touch();
4090
+ },
4091
+ getVisible: () => s.visible,
4092
+ setVisible: (v) => {
4093
+ s.visible = v;
4094
+ log.add("xrm", `section ${n} ${v ? "shown" : "hidden"}`);
4095
+ touch();
4096
+ }
4097
+ }, `section("${n}")`);
4098
+ })
4099
+ }, `formContext.ui.tabs.get("${name}")`);
4100
+ };
4101
+ const formContext = g({
4102
+ getAttribute: (name) => name === void 0 ? [...state.values.keys()].map(attribute) : attribute(name),
4103
+ getControl: (name) => name === void 0 ? [...state.controls.keys()].map(control) : control(name),
4104
+ data: g({
4105
+ entity: g({
4106
+ getId: () => state.recordId ? `{${state.recordId.toUpperCase()}}` : "",
4107
+ getEntityName: () => pkg.table,
4108
+ getIsDirty: () => state.dirty.size > 0,
4109
+ getPrimaryAttributeValue: () => state.values.get(pkg.tables[pkg.table]?.primaryName ?? "") ?? null,
4110
+ save: () => {
4111
+ void hooks.save();
4112
+ },
4113
+ attributes: collection(() => [...state.values.keys()], attribute)
4114
+ }, "formContext.data.entity"),
4115
+ save: () => hooks.save().then((ok) => {
4116
+ if (!ok) throw new Error("The record wasn't saved.");
4117
+ }),
4118
+ refresh: () => Promise.resolve(),
4119
+ getIsDirty: () => state.dirty.size > 0
4120
+ }, "formContext.data"),
4121
+ ui: g({
4122
+ getFormType: () => state.formType,
4123
+ setFormNotification: (message, level, id) => {
4124
+ state.formNotifications.set(id, { message, level });
4125
+ log.add("xrm", `form notification (${level}): ${message}`);
4126
+ touch();
4127
+ return true;
4128
+ },
4129
+ clearFormNotification: (id) => {
4130
+ state.formNotifications.delete(id);
4131
+ touch();
4132
+ return true;
4133
+ },
4134
+ tabs: collection(() => [...state.tabs.keys()], tab),
4135
+ controls: collection(() => [...state.controls.keys()], control),
4136
+ formSelector: {
4137
+ getCurrentItem: () => ({
4138
+ getId: () => typeof pkg.form.head.id === "string" ? pkg.form.head.id.replace(/[{}]/g, "").toLowerCase() : null,
4139
+ getLabel: () => pkg.formName
4140
+ })
4141
+ }
4142
+ }, "formContext.ui")
4143
+ }, "formContext");
4144
+ const webApi = (name, fn) => (async (...a) => {
4145
+ try {
4146
+ return await fn(...a);
4147
+ } catch (e) {
4148
+ if (e instanceof NotSimulated && !e.logged) {
4149
+ log.add("notSimulated", `Xrm.WebApi.${name}: ${e.what}`);
4150
+ e.logged = true;
4151
+ }
4152
+ throw e;
4153
+ }
4154
+ });
4155
+ const notFound = (table, id) => Object.assign(new Error(`${table} with id ${id} was not found in the offline data`), { errorCode: -2147220969 });
4156
+ const xrm = g({
4157
+ WebApi: g({
4158
+ retrieveRecord: webApi("retrieveRecord", async (table, id, options = "") => {
4159
+ if (/\$expand/.test(options)) throw new NotSimulated("$expand");
4160
+ const r = store.get(table, id);
4161
+ if (!r) throw notFound(table, id);
4162
+ log.add("xrm", `WebApi.retrieveRecord ${table} ${id}`);
4163
+ const select = /\$select=([^&]*)/.exec(options)?.[1]?.split(",");
4164
+ return store.webApi(table, r, select);
4165
+ }),
4166
+ retrieveMultipleRecords: webApi("retrieveMultipleRecords", async (table, options = "") => {
4167
+ log.add("xrm", `WebApi.retrieveMultipleRecords ${table} ${options}`);
4168
+ return { entities: store.query(table, options) };
4169
+ }),
4170
+ createRecord: async (table, data) => {
4171
+ const id = store.create(table, data);
4172
+ log.add("xrm", `WebApi.createRecord ${table} \u2192 ${id}`);
4173
+ return { entityType: table, id };
4174
+ },
4175
+ updateRecord: async (table, id, data) => {
4176
+ if (!store.get(table, id)) throw notFound(table, id);
4177
+ store.update(table, id, data);
4178
+ log.add("xrm", `WebApi.updateRecord ${table} ${id}`);
4179
+ return { entityType: table, id };
4180
+ },
4181
+ deleteRecord: async (table, id) => {
4182
+ if (!store.get(table, id)) throw notFound(table, id);
4183
+ store.delete(table, id);
4184
+ log.add("xrm", `WebApi.deleteRecord ${table} ${id}`);
4185
+ return { entityType: table, id };
4186
+ }
4187
+ }, "Xrm.WebApi"),
4188
+ Navigation: g({
4189
+ openAlertDialog: async (a) => {
4190
+ log.add("dialog", `alert: ${a?.text ?? ""}`);
4191
+ hooks.alert(a?.text ?? "");
4192
+ return {};
4193
+ },
4194
+ openConfirmDialog: async (c) => {
4195
+ const confirmed = hooks.confirm(c?.text ?? "");
4196
+ log.add("dialog", `confirm: ${c?.text ?? ""} \u2192 ${confirmed ? "OK" : "Cancel"}`);
4197
+ return { confirmed };
4198
+ }
4199
+ }, "Xrm.Navigation"),
4200
+ Utility: g({
4201
+ getGlobalContext: () => g({
4202
+ userSettings: g({ userId: `{${user.id.toUpperCase()}}`, userName: user.name, languageId: 1033 }, "Xrm.Utility.getGlobalContext().userSettings"),
4203
+ getClientUrl: () => "https://offline.invalid",
4204
+ getVersion: () => "9.2.0.0"
4205
+ }, "Xrm.Utility.getGlobalContext()")
4206
+ }, "Xrm.Utility"),
4207
+ Page: formContext
4208
+ // older scripts use Xrm.Page
4209
+ }, "Xrm");
4210
+ const executionContext = (eventSource, onSave) => {
4211
+ let prevented = false;
4212
+ const args = onSave ? g({ preventDefault: () => {
4213
+ prevented = true;
4214
+ onSave.cancel();
4215
+ }, isDefaultPrevented: () => prevented, getSaveMode: () => 1 }, "executionContext.getEventArgs()") : null;
4216
+ return g({
4217
+ getFormContext: () => formContext,
4218
+ getEventSource: () => eventSource ?? formContext,
4219
+ getDepth: () => 0,
4220
+ getEventArgs: () => args
4221
+ }, "executionContext");
4222
+ };
4223
+ return { Xrm: xrm, formContext, executionContext, attribute };
4224
+ }
4225
+
4226
+ // ../../extension/src/sim/simulator.ts
4227
+ function parseParameters(text) {
4228
+ if (!text?.trim()) return [];
4229
+ try {
4230
+ return JSON.parse(`[${text.replace(/'((?:[^'\\]|\\.)*)'/g, (_, s) => JSON.stringify(s.replace(/\\'/g, "'")))}]`);
4231
+ } catch {
4232
+ throw new NotSimulated(`the handler parameters ${text}`);
4233
+ }
4234
+ }
4235
+ var messageOf = (e) => e && typeof e === "object" && typeof e.message === "string" ? e.message : String(e);
4236
+ var isPromise = (v) => !!v && typeof v.then === "function";
4237
+ var Simulator = class {
4238
+ constructor(pkg, host) {
4239
+ this.pkg = pkg;
4240
+ this.host = host;
4241
+ const lookups = { [pkg.table]: pkg.columns.filter(isLookup).map((c) => c.name) };
4242
+ this.store = new Store(pkg.tables, pkg.records, host.newId, lookups);
4243
+ this.state = new FormState(pkg);
4244
+ const rules = new RuleEngine(pkg.rules, this.state, this.log, {
4245
+ setValue: (field, value) => {
4246
+ const col = this.state.columns.get(field);
4247
+ const before = this.state.values.get(field) ?? null;
4248
+ const same = isEmpty(before) && isEmpty(value) || col !== void 0 && compare(col, before, value) === 0;
4249
+ this.state.values.set(field, value);
4250
+ this.state.dirty.add(field);
4251
+ if (!same) rules.onChange(field);
4252
+ }
4253
+ });
4254
+ this.rules = rules;
4255
+ const made = createXrm(this.state, this.store, this.log, pkg, {
4256
+ fireOnChange: (field) => this.change(field),
4257
+ save: () => this.save(),
4258
+ alert: () => {
4259
+ },
4260
+ confirm: (text) => host.confirm ? host.confirm(text) : true
4261
+ }, host.user ?? { id: "00000000-0000-0000-0000-000000000001", name: "Offline User" });
4262
+ this.Xrm = made.Xrm;
4263
+ this.formContext = made.formContext;
4264
+ this.context = made.executionContext;
4265
+ this.attribute = made.attribute;
4266
+ }
4267
+ pkg;
4268
+ host;
4269
+ log = new EventLog();
4270
+ store;
4271
+ state;
4272
+ rules;
4273
+ Xrm;
4274
+ formContext;
4275
+ context;
4276
+ attribute;
4277
+ pending = [];
4278
+ /** Waits for the promises handlers returned (WebApi calls), including ones those started. */
4279
+ async settle() {
4280
+ while (this.pending.length > 0) {
4281
+ const now = this.pending;
4282
+ this.pending = [];
4283
+ await Promise.allSettled(now);
4284
+ }
4285
+ }
4286
+ failed(event, name, e) {
4287
+ if (e instanceof NotSimulated) {
4288
+ if (!e.logged) this.log.add("notSimulated", `${event}: ${name}: ${e.what}`);
4289
+ e.logged = true;
4290
+ return;
4291
+ }
4292
+ this.log.add("error", `${event}: ${name} threw ${messageOf(e)}`);
4293
+ }
4294
+ invoke(event, name, run) {
4295
+ try {
4296
+ const result = run();
4297
+ if (isPromise(result)) this.pending.push(result.catch((e) => this.failed(event, name, e)));
4298
+ } catch (e) {
4299
+ this.failed(event, name, e);
4300
+ }
4301
+ }
4302
+ call(event, h2, onSave, eventSource) {
4303
+ if (h2.enabled === false) return;
4304
+ if (!this.host.loaded(h2.library)) {
4305
+ this.log.add("error", `${event}: ${h2.function} not run; its library ${h2.library} isn't loaded`);
4306
+ return;
4307
+ }
4308
+ const fn = this.host.resolve(h2.function);
4309
+ if (!fn) {
4310
+ this.log.add("error", `${event}: ${h2.function} isn't defined by ${h2.library}`);
4311
+ return;
4312
+ }
4313
+ this.log.add("handler", `${event}: ${h2.function}`);
4314
+ this.invoke(event, h2.function, () => fn(...h2.passContext ? [this.context(eventSource, onSave)] : [], ...parseParameters(h2.parameters)));
4315
+ }
4316
+ /** A change the form reacts to: the field's OnChange handlers (scripts:, then addOnChange ones), then the rules that watch it. */
4317
+ change(field) {
4318
+ const source = this.attribute(field);
4319
+ for (const h2 of this.pkg.form.scripts?.onChange?.[field] ?? []) this.call(`OnChange ${field}`, h2, void 0, source);
4320
+ for (const fn of this.state.onChange.get(field) ?? []) {
4321
+ this.log.add("handler", `OnChange ${field}: (added by a script)`);
4322
+ this.invoke(`OnChange ${field}`, "a handler added by a script", () => fn(this.context(source)));
4323
+ }
4324
+ this.rules.onChange(field);
4325
+ this.state.changed();
4326
+ }
4327
+ async open(recordId) {
4328
+ for (const lib of this.pkg.libraries) {
4329
+ if (!lib.src) this.log.add("error", `library ${lib.name} isn't in the project (webresources/${lib.name})`);
4330
+ }
4331
+ if ((this.pkg.form.scripts?.events ?? []).length > 0) this.log.add("notSimulated", "handlers kept in scripts.events (tab state changes and other events) aren't run offline");
4332
+ for (const s of this.pkg.skipped) this.log.add("skipped", `rule "${s.rule}" skipped: ${s.missing.join(", ")} ${s.missing.length === 1 ? "isn't" : "aren't"} on this form`);
4333
+ for (const w of this.pkg.warnings) this.log.add("warning", w);
4334
+ const id = recordId ?? this.pkg.open;
4335
+ if (id) {
4336
+ const record = this.store.get(this.pkg.table, id);
4337
+ if (!record) throw new Error(`No ${this.pkg.table} record ${id} in the offline data.`);
4338
+ for (const field of this.state.values.keys()) {
4339
+ this.state.values.set(field, fromRecord(this.state.columns.get(field), record.values, (t, i) => this.store.nameOf(t, i)));
4340
+ }
4341
+ this.state.formType = 2;
4342
+ this.state.recordId = record.id;
4343
+ }
4344
+ this.log.add("value", id ? `opened ${this.pkg.table} ${id}` : `new ${this.pkg.table}`);
4345
+ this.rules.onLoad();
4346
+ for (const h2 of this.pkg.form.scripts?.onLoad ?? []) this.call("OnLoad", h2);
4347
+ await this.settle();
4348
+ this.state.changed();
4349
+ }
4350
+ /** As a person changes a field: the value, its OnChange handlers, then rules; resolves once handlers' promises settle. */
4351
+ async userSet(field, value) {
4352
+ const col = this.state.columns.get(field);
4353
+ if (!col || !this.state.values.has(field)) throw new Error(`${field} isn't on this form.`);
4354
+ this.state.values.set(field, value);
4355
+ this.state.dirty.add(field);
4356
+ this.log.add("value", `${field} = ${display(col, value) || "(empty)"}`);
4357
+ this.change(field);
4358
+ await this.settle();
4359
+ }
4360
+ /** A person expanding or collapsing a tab (TabStateChange handlers are kept raw and not run offline). */
4361
+ setTabExpanded(tab, expanded) {
4362
+ const t = this.state.tabs.get(tab);
4363
+ if (!t) throw new Error(`Tab ${tab} isn't on this form.`);
4364
+ t.expanded = expanded;
4365
+ this.log.add("value", `tab ${tab} ${expanded ? "expanded" : "collapsed"}`);
4366
+ this.state.changed();
4367
+ }
4368
+ async save() {
4369
+ let cancelled = false;
4370
+ for (const h2 of this.pkg.form.scripts?.onSave ?? []) this.call("OnSave", h2, { cancel: () => {
4371
+ cancelled = true;
4372
+ } });
4373
+ await this.settle();
4374
+ if (cancelled) {
4375
+ this.log.add("save", "save cancelled by an OnSave handler");
4376
+ return false;
4377
+ }
4378
+ const missing = [...this.state.required.entries()].filter(([f, level]) => level === "required" && isEmpty(this.state.values.get(f) ?? null)).map(([f]) => this.state.controls.get(f)?.label ?? f);
4379
+ if (missing.length > 0) {
4380
+ this.state.formNotifications.set("required", { message: `Required fields must be filled in: ${missing.join(", ")}.`, level: "ERROR" });
4381
+ this.log.add("save", `save refused: ${missing.join(", ")} required`);
4382
+ this.state.changed();
4383
+ return false;
4384
+ }
4385
+ this.state.formNotifications.delete("required");
4386
+ const limits = [];
4387
+ for (const [field, v] of this.state.values) {
4388
+ const col = this.state.columns.get(field);
4389
+ const label = this.state.controls.get(field)?.label ?? col.label;
4390
+ if (typeof v === "string" && col.maxLength !== void 0 && v.length > col.maxLength) limits.push(`${label} is longer than ${col.maxLength} characters.`);
4391
+ if (typeof v === "number" && col.minValue !== void 0 && v < col.minValue) limits.push(`${label} must be at least ${col.minValue}.`);
4392
+ if (typeof v === "number" && col.maxValue !== void 0 && v > col.maxValue) limits.push(`${label} must be at most ${col.maxValue}.`);
4393
+ }
4394
+ if (limits.length > 0) {
4395
+ this.state.formNotifications.set("limits", { message: limits.join(" "), level: "ERROR" });
4396
+ this.log.add("save", `save refused: ${limits.join(" ")}`);
4397
+ this.state.changed();
4398
+ return false;
4399
+ }
4400
+ this.state.formNotifications.delete("limits");
4401
+ const noted = [...this.state.controls.entries()].filter(([, c]) => c.notifications.size > 0 && ![...c.notifications.keys()].every((k) => k.startsWith("rule:"))).map(([n]) => n);
4402
+ if (noted.length > 0) {
4403
+ this.log.add("save", `save refused: a notification is showing on ${noted.join(", ")}`);
4404
+ this.state.changed();
4405
+ return false;
4406
+ }
4407
+ if (this.rules.hasErrors()) {
4408
+ this.log.add("save", "save refused: a business rule error is showing");
4409
+ this.state.changed();
4410
+ return false;
4411
+ }
4412
+ const ruleErrors = this.rules.onSave();
4413
+ if (ruleErrors.length > 0) {
4414
+ this.state.formNotifications.set("rules", { message: ruleErrors.join(" "), level: "ERROR" });
4415
+ this.state.changed();
4416
+ return false;
4417
+ }
4418
+ this.state.formNotifications.delete("rules");
4419
+ const values = {};
4420
+ for (const [field, v] of this.state.values) Object.assign(values, toRecord(this.state.columns.get(field), v));
4421
+ if (this.state.recordId) this.store.update(this.pkg.table, this.state.recordId, values);
4422
+ else {
4423
+ this.state.recordId = this.store.create(this.pkg.table, values);
4424
+ this.state.formType = 2;
4425
+ }
4426
+ this.state.dirty.clear();
4427
+ this.log.add("save", `saved ${this.pkg.table} ${this.state.recordId}`);
4428
+ this.state.changed();
4429
+ return true;
4430
+ }
4431
+ };
4432
+
4433
+ // ../../extension/src/sim/page.ts
4434
+ var h = (tag, attrs = {}, ...children) => {
4435
+ const el = document.createElement(tag);
4436
+ for (const [k, v] of Object.entries(attrs)) el.setAttribute(k, v);
4437
+ el.append(...children);
4438
+ return el;
4439
+ };
4440
+ var NUMBER2 = /* @__PURE__ */ new Set(["wholeNumber", "decimal", "float", "currency", "bigInteger"]);
4441
+ function inputFor(col, value, sim) {
4442
+ const attrs = { "data-sim-field": col.name, id: `f_${col.name}` };
4443
+ if (col.type === "choices") {
4444
+ const chosen = new Set(Array.isArray(value) ? value.map(String) : []);
4445
+ const select = h("select", { ...attrs, multiple: "" }, ...col.options.map((o) => h("option", { value: String(o.value) }, o.label)));
4446
+ for (const o of Array.from(select.options)) o.selected = chosen.has(o.value);
4447
+ return select;
4448
+ }
4449
+ if (col.type === "choice" || col.type === "yesNo" || isLookup(col)) {
4450
+ const target = col.target ?? "";
4451
+ const options = col.type === "choice" ? col.options.map((o) => ({ label: o.label, value: String(o.value) })) : col.type === "yesNo" ? [{ label: col.options.find((o) => o.value === 0)?.label ?? "No", value: "false" }, { label: col.options.find((o) => o.value === 1)?.label ?? "Yes", value: "true" }] : sim.store.all(target).map((r) => ({ label: sim.store.nameOf(target, r.id) || r.id, value: r.id }));
4452
+ const select = h("select", attrs, h("option", { value: "" }, ""), ...options.map((o) => h("option", { value: o.value }, o.label)));
4453
+ select.value = value === null ? "" : Array.isArray(value) && value.length > 0 && typeof value[0] === "object" ? value[0].id : String(value);
4454
+ return select;
4455
+ }
4456
+ if (col.type === "multiline") {
4457
+ const t = h("textarea", attrs);
4458
+ t.value = value === null ? "" : String(value);
4459
+ return t;
4460
+ }
4461
+ const type = NUMBER2.has(col.type) ? "number" : col.type === "date" || col.behavior === "dateOnly" ? "date" : col.type === "dateTime" ? "datetime-local" : "text";
4462
+ const input = h("input", { ...attrs, type });
4463
+ input.value = value instanceof Date ? type === "date" ? value.toISOString().slice(0, 10) : value.toISOString().slice(0, 16) : value === null ? "" : String(value);
4464
+ return input;
4465
+ }
4466
+ function readInput(col, el, sim) {
4467
+ if (isLookup(col)) {
4468
+ const target = col.target ?? "";
4469
+ return el.value ? [{ id: el.value, name: sim.store.nameOf(target, el.value), entityType: target }] : null;
4470
+ }
4471
+ if (col.type === "choices" && el instanceof HTMLSelectElement) return fromUser(col, Array.from(el.selectedOptions).map((o) => o.value).join(","));
4472
+ return fromUser(col, el.value);
4473
+ }
4474
+ var testsText = "";
4475
+ var listening = false;
4476
+ function listenForTestStatus() {
4477
+ if (listening || typeof window === "undefined") return;
4478
+ listening = true;
4479
+ window.addEventListener("message", (e) => {
4480
+ const m = e.data;
4481
+ if (m?.type !== "tests") return;
4482
+ testsText = m.text ?? "";
4483
+ for (const el of Array.from(document.querySelectorAll("[data-tests-status]"))) el.textContent = testsText;
4484
+ });
4485
+ }
4486
+ function startPage(root, pkg, host, post) {
4487
+ listenForTestStatus();
4488
+ const sim = new Simulator(pkg, host);
4489
+ if (typeof window !== "undefined") {
4490
+ const w = window;
4491
+ w.__simXrm = sim.Xrm;
4492
+ w.__simBlocked = (what) => sim.log.add("notSimulated", what);
4493
+ }
4494
+ const formRef = `${pkg.table}/${pkg.formType}/${pkg.formName.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "")}`;
4495
+ const page = { sim, recorder: new Recorder(sim, formRef), ready: Promise.resolve() };
4496
+ let currentTab = [...sim.state.tabs.keys()][0];
4497
+ const formPane = h("div", { class: "sim-form" });
4498
+ const dataPane = h("div", { class: "sim-data" });
4499
+ const logPane = h("ol", { class: "sim-log" });
4500
+ const button = (action, label) => h("button", { "data-sim-action": action, type: "button" }, label);
4501
+ const toolbar = h(
4502
+ "div",
4503
+ { class: "sim-bar" },
4504
+ button("new", "New record"),
4505
+ button("save", "Save"),
4506
+ button("reset", "Reset"),
4507
+ button("copyTest", "Copy as test"),
4508
+ button("loadSeed", "Load from seed"),
4509
+ h("span", { class: "sim-tests", "data-tests-status": "" }, testsText),
4510
+ h("span", { class: "sim-note" }, "Offline: nothing is sent to Dataverse.")
4511
+ );
4512
+ root.replaceChildren(toolbar, h(
4513
+ "div",
4514
+ { class: "sim-panes" },
4515
+ formPane,
4516
+ h("div", { class: "sim-side" }, h("h3", {}, "Data"), dataPane, h("h3", {}, "Event log"), logPane)
4517
+ ));
4518
+ const drawLog = () => {
4519
+ logPane.replaceChildren(...sim.log.entries.map((e) => h("li", { "data-sim-log": e.kind, class: `log-${e.kind}` }, h("span", { class: "kind" }, e.kind), ` ${e.message}`)));
4520
+ logPane.scrollTop = logPane.scrollHeight;
4521
+ };
4522
+ const cell = (field, controlName, kind, label) => {
4523
+ if (!field) return h("div", { class: "sim-cell sim-placeholder" });
4524
+ const col = sim.state.columns.get(field);
4525
+ const control = sim.state.controls.get(controlName);
4526
+ if (kind && ["subgrid", "quickView", "timeline", "webResource", "iframe", "map", "other"].includes(kind)) {
4527
+ return h("div", { class: "sim-cell sim-placeholder" }, `${label ?? field} (${kind}; shown as a placeholder offline)`);
4528
+ }
4529
+ if (!col || !control) return h("div", { class: "sim-cell sim-placeholder" }, `${field} (a column the project doesn't describe; shown as a placeholder)`);
4530
+ const input = inputFor(col, sim.state.values.get(field) ?? null, sim);
4531
+ input.disabled = control.disabled;
4532
+ input.addEventListener("change", () => void page.recorder.set(field, readInput(col, input, sim)));
4533
+ const required = (sim.state.required.get(field) ?? "none") === "required";
4534
+ return h(
4535
+ "div",
4536
+ {
4537
+ class: `sim-cell${control.visible ? "" : " sim-hidden"}`,
4538
+ "data-sim-control": controlName,
4539
+ "data-sim-visible": String(control.visible),
4540
+ "data-sim-disabled": String(control.disabled),
4541
+ "data-sim-required": String(required)
4542
+ },
4543
+ h("label", { for: input.id }, control.label, required ? h("span", { class: "sim-req" }, " *") : ""),
4544
+ input,
4545
+ ...[...control.notifications.values()].map((n) => h("div", { class: "sim-notification", "data-sim-notification": controlName }, n))
4546
+ );
4547
+ };
4548
+ const draw = () => {
4549
+ const notes = [...sim.state.formNotifications.entries()].map(([id, n]) => h("div", { class: `sim-form-note level-${n.level.toLowerCase()}`, "data-sim-form-notification": id }, n.message));
4550
+ const strip = h("div", { class: "sim-tabs" }, ...[...sim.state.tabs.values()].map((t) => {
4551
+ const b = h("button", { type: "button", "data-sim-tab": t.name, class: `${t.name === currentTab ? "on" : ""}${t.visible ? "" : " sim-hidden"}` }, t.label || t.name);
4552
+ b.addEventListener("click", () => {
4553
+ currentTab = t.name;
4554
+ draw();
4555
+ });
4556
+ return b;
4557
+ }));
4558
+ const tabIndex = [...sim.state.tabs.keys()].indexOf(currentTab);
4559
+ const tab = pkg.form.tabs[tabIndex];
4560
+ const columns = tab ? tab.columns.map((_, i) => h("div", { class: "sim-column" }, ...tab.sections.map((s, j) => ({ s, j })).filter(({ s }) => (s.column ?? 1) === i + 1).map(({ s, j }) => {
4561
+ const state = sim.state.tabs.get(currentTab).sections.get(s.name ?? `section_${j + 1}`);
4562
+ return h(
4563
+ "fieldset",
4564
+ { class: `sim-section${state.visible ? "" : " sim-hidden"}`, "data-sim-section": state.name },
4565
+ h("legend", {}, state.label || state.name),
4566
+ ...s.rows.map((row) => h("div", { class: `sim-row cols-${Math.min(row.length, 4)}` }, ...row.map((c) => cell(c.field, c.field ?? "", c.kind, c.label))))
4567
+ );
4568
+ }))) : [];
4569
+ const header = (pkg.form.header?.rows ?? []).flat().map((c) => cell(c.field, `header_${c.field}`, c.kind, c.label));
4570
+ formPane.replaceChildren(
4571
+ ...notes,
4572
+ ...header.length > 0 ? [h("div", { class: "sim-header" }, ...header)] : [],
4573
+ strip,
4574
+ h("div", { class: `sim-columns cols-${Math.min(tab?.columns.length ?? 1, 4)}` }, ...columns)
4575
+ );
4576
+ dataPane.replaceChildren(...Object.keys(pkg.tables).map((t) => {
4577
+ const add = h("form", { "data-sim-add": t, class: "sim-add" }, h("input", { type: "text", placeholder: `New ${t}: ${pkg.tables[t].primaryName}` }), h("button", { type: "submit" }, "Add"));
4578
+ add.addEventListener("submit", (e) => {
4579
+ e.preventDefault();
4580
+ const name = add.querySelector("input").value.trim();
4581
+ if (!name) return;
4582
+ const id = sim.store.create(t, { [pkg.tables[t].primaryName]: name });
4583
+ sim.log.add("value", `offline data: added ${t} ${name} (${id})`);
4584
+ draw();
4585
+ });
4586
+ return h(
4587
+ "details",
4588
+ { "data-sim-table": t, ...sim.store.all(t).length > 0 || t !== pkg.table ? { open: "" } : {} },
4589
+ h("summary", {}, `${t} (${sim.store.all(t).length})`),
4590
+ h("ul", {}, ...sim.store.all(t).map((r) => {
4591
+ const li = h("li", { "data-sim-record": r.id }, sim.store.nameOf(t, r.id) || r.id);
4592
+ if (t === pkg.table) {
4593
+ const open = h("button", { type: "button", "data-sim-open": r.id, class: "link" }, "Open");
4594
+ open.addEventListener("click", () => restart(r.id));
4595
+ li.append(" ", open);
4596
+ }
4597
+ if (!(t === pkg.table && r.id === sim.state.recordId)) {
4598
+ const remove = h("button", { type: "button", "data-sim-delete": r.id, class: "link" }, "Delete");
4599
+ remove.addEventListener("click", () => {
4600
+ sim.store.delete(t, r.id);
4601
+ sim.log.add("value", `offline data: deleted ${t} ${r.id}`);
4602
+ draw();
4603
+ });
4604
+ li.append(" ", remove);
4605
+ }
4606
+ return li;
4607
+ })),
4608
+ add
4609
+ );
4610
+ }));
4611
+ drawLog();
4612
+ };
4613
+ const restart = (id) => {
4614
+ const records = Object.keys(pkg.tables).flatMap((t) => sim.store.all(t));
4615
+ const next = startPage(root, { ...pkg, records, open: id }, host, post);
4616
+ page.sim = next.sim;
4617
+ page.recorder = next.recorder;
4618
+ };
4619
+ sim.state.listeners.push(draw);
4620
+ sim.log.onAdd(drawLog);
4621
+ toolbar.addEventListener("click", (e) => {
4622
+ const action = e.target.getAttribute("data-sim-action");
4623
+ if (action === "save") void page.recorder.save();
4624
+ else if (action === "new") restart();
4625
+ else if (action === "reset") restart(sim.state.recordId);
4626
+ else if (action === "copyTest") post({ type: "copyTest", yaml: page.recorder.testYaml() });
4627
+ else if (action === "loadSeed") post({ type: "loadSeed" });
4628
+ });
4629
+ draw();
4630
+ page.ready = sim.open().then(() => {
4631
+ page.recorder = new Recorder(sim, formRef);
4632
+ draw();
4633
+ }, (e) => sim.log.add("error", e instanceof Error ? e.message : String(e)));
4634
+ return page;
4635
+ }
4636
+ var toWire = (v) => v instanceof Date ? { $date: v.toISOString() } : Array.isArray(v) ? v.map(toWire) : v;
4637
+ var fromWire = (v) => v && typeof v === "object" && "$date" in v ? new Date(v.$date) : Array.isArray(v) ? v.map(fromWire) : v;
4638
+ function api(current) {
4639
+ let saved;
4640
+ return {
4641
+ ready: () => current().ready,
4642
+ async set(field, wire) {
4643
+ const { sim } = current();
4644
+ const col = sim.state.columns.get(field);
4645
+ if (!col || !sim.state.values.has(field)) throw new Error(`${field} isn't on the form.`);
4646
+ let value = fromWire(wire);
4647
+ if (isLookup(col) && Array.isArray(value) && value.length > 0) {
4648
+ const v = value[0];
4649
+ value = [{ ...v, name: sim.store.nameOf(v.entityType, v.id) }];
4650
+ }
4651
+ await sim.userSet(field, value);
4652
+ },
4653
+ async save() {
4654
+ saved = await current().sim.save();
4655
+ return saved;
4656
+ },
4657
+ expand: (tab, expanded) => current().sim.setTabExpanded(tab, expanded),
4658
+ snapshot() {
4659
+ const { sim } = current();
4660
+ const fields = {};
4661
+ for (const [name, value] of sim.state.values) {
4662
+ const col = sim.state.columns.get(name);
4663
+ const control = sim.state.controls.get(name) ?? sim.state.controls.get(`header_${name}`) ?? sim.state.controls.get(`footer_${name}`);
4664
+ if (!control) continue;
4665
+ fields[name] = {
4666
+ value: toWire(value),
4667
+ text: display(col, value),
4668
+ required: sim.state.required.get(name) === "required",
4669
+ visible: control.visible,
4670
+ disabled: control.disabled,
4671
+ label: control.label,
4672
+ notifications: [...control.notifications.values()],
4673
+ options: col.options.map((o) => o.label)
4674
+ };
4675
+ }
4676
+ return {
4677
+ fields,
4678
+ form: { saved, notifications: [...sim.state.formNotifications.values()].map((n) => n.message), dialogs: sim.log.entries.filter((e) => e.kind === "dialog").map((e) => e.message), log: [...sim.log.entries] }
4679
+ };
4680
+ }
4681
+ };
4682
+ }
4683
+ function boot() {
4684
+ const root = document.getElementById("sim");
4685
+ if (!root || !window.__simPackage) return;
4686
+ const vscode = window.acquireVsCodeApi?.();
4687
+ const post = (m) => vscode ? vscode.postMessage(m) : window.dispatchEvent(new CustomEvent("sim-post", { detail: m }));
4688
+ let n = 0;
4689
+ const host = {
4690
+ resolve: (name) => {
4691
+ let v = window;
4692
+ for (const part of name.split(".")) v = v?.[part];
4693
+ return typeof v === "function" ? v : void 0;
4694
+ },
4695
+ loaded: (lib) => window.__simLoaded?.[lib] === true,
4696
+ newId: () => typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `00000000-0000-4000-8000-${String(++n).padStart(12, "0")}`,
4697
+ confirm: () => window.__simAnswers?.shift() ?? true
4698
+ };
4699
+ let current = startPage(root, window.__simPackage, host, post);
4700
+ post({ type: "ready" });
4701
+ window.addEventListener("message", (e) => {
4702
+ const m = e.data;
4703
+ if (m.type === "package" && m.pkg) current = startPage(root, m.pkg, host, post);
4704
+ else if (m.type === "records" && m.records) current = startPage(root, { ...current.sim.pkg, records: m.records, open: void 0 }, host, post);
4705
+ });
4706
+ window.__sim = () => current;
4707
+ window.__simAnswers ??= [];
4708
+ window.__simApi = api(() => current);
4709
+ }
4710
+
4711
+ // ../../extension/src/sim/main.ts
4712
+ boot();
4713
+ })();