@netfoundry/docusaurus-shared 0.0.168

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.
Files changed (112) hide show
  1. package/dist/components/Alert/Alert.d.ts +8 -0
  2. package/dist/components/Alert/index.d.ts +2 -0
  3. package/dist/components/CodeBlock/CodeBlock.d.ts +9 -0
  4. package/dist/components/CodeBlock/index.d.ts +2 -0
  5. package/dist/components/Common/Common.d.ts +23 -0
  6. package/dist/components/Common/index.d.ts +1 -0
  7. package/dist/components/NetFoundry/Divider/Divider.d.ts +2 -0
  8. package/dist/components/NetFoundry/Divider/index.d.ts +1 -0
  9. package/dist/components/NetFoundry/index.d.ts +1 -0
  10. package/dist/components/NetFoundryFooter/NetFoundryFooter.d.ts +22 -0
  11. package/dist/components/NetFoundryFooter/index.d.ts +1 -0
  12. package/dist/components/NetFoundryHighlight/NetFoundryHighlight.d.ts +6 -0
  13. package/dist/components/NetFoundryHighlight/index.d.ts +2 -0
  14. package/dist/components/NetFoundryHorizontalSection/NetFoundryHorizontalSection.d.ts +8 -0
  15. package/dist/components/NetFoundryHorizontalSection/index.d.ts +2 -0
  16. package/dist/components/NetFoundryLayout/NetFoundryLayout.d.ts +29 -0
  17. package/dist/components/NetFoundryLayout/index.d.ts +1 -0
  18. package/dist/components/NetFoundryNavbarItems/NetFoundryNavbarItems.d.ts +9 -0
  19. package/dist/components/NetFoundryNavbarItems/index.d.ts +2 -0
  20. package/dist/components/OsTabs/OsTabs.d.ts +5 -0
  21. package/dist/components/OsTabs/index.d.ts +2 -0
  22. package/dist/components/StarUs/StarUs.d.ts +6 -0
  23. package/dist/components/StarUs/index.d.ts +2 -0
  24. package/dist/components/index.d.ts +11 -0
  25. package/dist/docusaurus-envhelper.d.ts +15 -0
  26. package/dist/docusaurus-plugins/index.d.ts +7 -0
  27. package/dist/docusaurus-plugins/logger.d.ts +12 -0
  28. package/dist/docusaurus-plugins/remarkCodeSections.d.ts +7 -0
  29. package/dist/docusaurus-plugins/remarkReplaceMetaUrl.d.ts +10 -0
  30. package/dist/docusaurus-plugins/remarkScopedPath.d.ts +12 -0
  31. package/dist/docusaurus-plugins/remarkYamlTable.d.ts +7 -0
  32. package/dist/docusaurus-plugins/remarkYouTube.d.ts +7 -0
  33. package/dist/docusaurus-plugins/timedPlugin.d.ts +5 -0
  34. package/dist/index.cjs +8 -0
  35. package/dist/index.cjs.map +1 -0
  36. package/dist/index.css +1 -0
  37. package/dist/index.d.ts +1 -0
  38. package/dist/index.esm.js +6 -0
  39. package/dist/index.esm.js.map +1 -0
  40. package/dist/node.cjs +80 -0
  41. package/dist/node.cjs.map +1 -0
  42. package/dist/node.d.ts +1 -0
  43. package/dist/node.esm.js +68 -0
  44. package/dist/node.esm.js.map +1 -0
  45. package/dist/plugins.cjs +4643 -0
  46. package/dist/plugins.cjs.map +1 -0
  47. package/dist/plugins.d.ts +1 -0
  48. package/dist/plugins.esm.js +4634 -0
  49. package/dist/plugins.esm.js.map +1 -0
  50. package/dist/ui.cjs +1312 -0
  51. package/dist/ui.cjs.map +1 -0
  52. package/dist/ui.d.ts +2 -0
  53. package/dist/ui.esm.js +1284 -0
  54. package/dist/ui.esm.js.map +1 -0
  55. package/dist/version.cjs +6 -0
  56. package/dist/version.cjs.map +1 -0
  57. package/dist/version.d.ts +1 -0
  58. package/dist/version.esm.js +4 -0
  59. package/dist/version.esm.js.map +1 -0
  60. package/package.json +82 -0
  61. package/src/components/Alert/Alert.module.css +39 -0
  62. package/src/components/Alert/Alert.tsx +24 -0
  63. package/src/components/Alert/index.ts +2 -0
  64. package/src/components/CodeBlock/CodeBlock.module.css +27 -0
  65. package/src/components/CodeBlock/CodeBlock.tsx +32 -0
  66. package/src/components/CodeBlock/index.ts +2 -0
  67. package/src/components/Common/Common.module.css +0 -0
  68. package/src/components/Common/Common.tsx +53 -0
  69. package/src/components/Common/index.ts +1 -0
  70. package/src/components/NetFoundry/Divider/Divider.module.css +23 -0
  71. package/src/components/NetFoundry/Divider/Divider.tsx +20 -0
  72. package/src/components/NetFoundry/Divider/index.ts +1 -0
  73. package/src/components/NetFoundry/index.ts +1 -0
  74. package/src/components/NetFoundryFooter/NetFoundryFooter.tsx +164 -0
  75. package/src/components/NetFoundryFooter/index.ts +1 -0
  76. package/src/components/NetFoundryFooter/styles.module.css +99 -0
  77. package/src/components/NetFoundryHighlight/NetFoundryHighlight.tsx +15 -0
  78. package/src/components/NetFoundryHighlight/index.ts +2 -0
  79. package/src/components/NetFoundryHighlight/styles.module.css +26 -0
  80. package/src/components/NetFoundryHorizontalSection/NetFoundryHorizontalSection.tsx +23 -0
  81. package/src/components/NetFoundryHorizontalSection/index.ts +2 -0
  82. package/src/components/NetFoundryHorizontalSection/styles.module.css +23 -0
  83. package/src/components/NetFoundryLayout/NetFoundryLayout.module.css +6 -0
  84. package/src/components/NetFoundryLayout/NetFoundryLayout.tsx +110 -0
  85. package/src/components/NetFoundryLayout/index.ts +1 -0
  86. package/src/components/NetFoundryNavbarItems/NetFoundryNavbarItems.tsx +22 -0
  87. package/src/components/NetFoundryNavbarItems/index.ts +2 -0
  88. package/src/components/OsTabs/OsTabs.tsx +30 -0
  89. package/src/components/OsTabs/index.ts +2 -0
  90. package/src/components/StarUs/StarUs.tsx +19 -0
  91. package/src/components/StarUs/index.ts +2 -0
  92. package/src/components/StarUs/styles.module.css +6 -0
  93. package/src/components/index.ts +11 -0
  94. package/src/css/layout.css +14 -0
  95. package/src/css/legacy.css +2348 -0
  96. package/src/css/vars-dark.css +7 -0
  97. package/src/css/vars.css +8 -0
  98. package/src/docusaurus-envhelper.ts +105 -0
  99. package/src/docusaurus-plugins/index.ts +7 -0
  100. package/src/docusaurus-plugins/logger.ts +38 -0
  101. package/src/docusaurus-plugins/remarkCodeSections.ts +115 -0
  102. package/src/docusaurus-plugins/remarkReplaceMetaUrl.ts +35 -0
  103. package/src/docusaurus-plugins/remarkScopedPath.ts +70 -0
  104. package/src/docusaurus-plugins/remarkYamlTable.ts +83 -0
  105. package/src/docusaurus-plugins/remarkYouTube.ts +56 -0
  106. package/src/docusaurus-plugins/timedPlugin.ts +22 -0
  107. package/src/global.d.ts +1 -0
  108. package/src/index.ts +3 -0
  109. package/src/node.ts +1 -0
  110. package/src/plugins.ts +1 -0
  111. package/src/ui.ts +2 -0
  112. package/src/version.ts +1 -0
@@ -0,0 +1,4634 @@
1
+ import { existsSync, writeFileSync, appendFileSync } from 'fs';
2
+ import { join } from 'path';
3
+ import { __spreadArray } from 'tslib';
4
+
5
+ var LogLevel;
6
+ (function (LogLevel) {
7
+ LogLevel[LogLevel["Silent"] = 0] = "Silent";
8
+ LogLevel[LogLevel["Info"] = 1] = "Info";
9
+ LogLevel[LogLevel["Debug"] = 2] = "Debug";
10
+ })(LogLevel || (LogLevel = {}));
11
+ var LOG = join(process.cwd(), 'remark-plugins.log');
12
+ var Logger = /** @class */ (function () {
13
+ function Logger(level, name) {
14
+ this.level = level;
15
+ this.name = name;
16
+ }
17
+ Logger.prototype.log = function (msg, level) {
18
+ if (level === void 0) { level = LogLevel.Info; }
19
+ if (this.level === LogLevel.Silent)
20
+ return;
21
+ if (level > this.level)
22
+ return;
23
+ var text = String(msg);
24
+ if (!text.trim())
25
+ return;
26
+ var line = "[".concat(this.name, "] ").concat(LogLevel[level], " ").concat(text);
27
+ if (!existsSync(LOG))
28
+ writeFileSync(LOG, '');
29
+ appendFileSync(LOG, "[".concat(new Date().toISOString(), "] ").concat(line, "\n"));
30
+ };
31
+ return Logger;
32
+ }());
33
+ function resolveLogLevel(val) {
34
+ if (typeof val === "number" && LogLevel[val] !== undefined) {
35
+ return val;
36
+ }
37
+ if (typeof val === "string") {
38
+ var key = val[0].toUpperCase() + val.slice(1).toLowerCase();
39
+ if (key in LogLevel) {
40
+ return LogLevel[key];
41
+ }
42
+ }
43
+ return LogLevel.Silent;
44
+ }
45
+
46
+ /**
47
+ * @typedef {import('unist').Node} Node
48
+ * @typedef {import('unist').Parent} Parent
49
+ */
50
+
51
+
52
+ /**
53
+ * Generate an assertion from a test.
54
+ *
55
+ * Useful if you’re going to test many nodes, for example when creating a
56
+ * utility where something else passes a compatible test.
57
+ *
58
+ * The created function is a bit faster because it expects valid input only:
59
+ * a `node`, `index`, and `parent`.
60
+ *
61
+ * @param {Test} test
62
+ * * when nullish, checks if `node` is a `Node`.
63
+ * * when `string`, works like passing `(node) => node.type === test`.
64
+ * * when `function` checks if function passed the node is true.
65
+ * * when `object`, checks that all keys in test are in node, and that they have (strictly) equal values.
66
+ * * when `array`, checks if any one of the subtests pass.
67
+ * @returns {Check}
68
+ * An assertion.
69
+ */
70
+ const convert =
71
+ // Note: overloads in JSDoc can’t yet use different `@template`s.
72
+ /**
73
+ * @type {(
74
+ * (<Condition extends string>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & {type: Condition}) &
75
+ * (<Condition extends Props>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Condition) &
76
+ * (<Condition extends TestFunction>(test: Condition) => (node: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node & Predicate<Condition, Node>) &
77
+ * ((test?: null | undefined) => (node?: unknown, index?: number | null | undefined, parent?: Parent | null | undefined, context?: unknown) => node is Node) &
78
+ * ((test?: Test) => Check)
79
+ * )}
80
+ */
81
+ (
82
+ /**
83
+ * @param {Test} [test]
84
+ * @returns {Check}
85
+ */
86
+ function (test) {
87
+ if (test === null || test === undefined) {
88
+ return ok
89
+ }
90
+
91
+ if (typeof test === 'function') {
92
+ return castFactory(test)
93
+ }
94
+
95
+ if (typeof test === 'object') {
96
+ return Array.isArray(test) ? anyFactory(test) : propsFactory(test)
97
+ }
98
+
99
+ if (typeof test === 'string') {
100
+ return typeFactory(test)
101
+ }
102
+
103
+ throw new Error('Expected function, string, or object as test')
104
+ }
105
+ );
106
+
107
+ /**
108
+ * @param {Array<Props | TestFunction | string>} tests
109
+ * @returns {Check}
110
+ */
111
+ function anyFactory(tests) {
112
+ /** @type {Array<Check>} */
113
+ const checks = [];
114
+ let index = -1;
115
+
116
+ while (++index < tests.length) {
117
+ checks[index] = convert(tests[index]);
118
+ }
119
+
120
+ return castFactory(any)
121
+
122
+ /**
123
+ * @this {unknown}
124
+ * @type {TestFunction}
125
+ */
126
+ function any(...parameters) {
127
+ let index = -1;
128
+
129
+ while (++index < checks.length) {
130
+ if (checks[index].apply(this, parameters)) return true
131
+ }
132
+
133
+ return false
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Turn an object into a test for a node with a certain fields.
139
+ *
140
+ * @param {Props} check
141
+ * @returns {Check}
142
+ */
143
+ function propsFactory(check) {
144
+ const checkAsRecord = /** @type {Record<string, unknown>} */ (check);
145
+
146
+ return castFactory(all)
147
+
148
+ /**
149
+ * @param {Node} node
150
+ * @returns {boolean}
151
+ */
152
+ function all(node) {
153
+ const nodeAsRecord = /** @type {Record<string, unknown>} */ (
154
+ /** @type {unknown} */ (node)
155
+ );
156
+
157
+ /** @type {string} */
158
+ let key;
159
+
160
+ for (key in check) {
161
+ if (nodeAsRecord[key] !== checkAsRecord[key]) return false
162
+ }
163
+
164
+ return true
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Turn a string into a test for a node with a certain type.
170
+ *
171
+ * @param {string} check
172
+ * @returns {Check}
173
+ */
174
+ function typeFactory(check) {
175
+ return castFactory(type)
176
+
177
+ /**
178
+ * @param {Node} node
179
+ */
180
+ function type(node) {
181
+ return node && node.type === check
182
+ }
183
+ }
184
+
185
+ /**
186
+ * Turn a custom test into a test for a node that passes that test.
187
+ *
188
+ * @param {TestFunction} testFunction
189
+ * @returns {Check}
190
+ */
191
+ function castFactory(testFunction) {
192
+ return check
193
+
194
+ /**
195
+ * @this {unknown}
196
+ * @type {Check}
197
+ */
198
+ function check(value, index, parent) {
199
+ return Boolean(
200
+ looksLikeANode(value) &&
201
+ testFunction.call(
202
+ this,
203
+ value,
204
+ typeof index === 'number' ? index : undefined,
205
+ parent || undefined
206
+ )
207
+ )
208
+ }
209
+ }
210
+
211
+ function ok() {
212
+ return true
213
+ }
214
+
215
+ /**
216
+ * @param {unknown} value
217
+ * @returns {value is Node}
218
+ */
219
+ function looksLikeANode(value) {
220
+ return value !== null && typeof value === 'object' && 'type' in value
221
+ }
222
+
223
+ /**
224
+ * @param {string} d
225
+ * @returns {string}
226
+ */
227
+ function color(d) {
228
+ return d
229
+ }
230
+
231
+ /**
232
+ * @typedef {import('unist').Node} UnistNode
233
+ * @typedef {import('unist').Parent} UnistParent
234
+ */
235
+
236
+
237
+ /** @type {Readonly<ActionTuple>} */
238
+ const empty = [];
239
+
240
+ /**
241
+ * Continue traversing as normal.
242
+ */
243
+ const CONTINUE = true;
244
+
245
+ /**
246
+ * Stop traversing immediately.
247
+ */
248
+ const EXIT = false;
249
+
250
+ /**
251
+ * Do not traverse this node’s children.
252
+ */
253
+ const SKIP = 'skip';
254
+
255
+ /**
256
+ * Visit nodes, with ancestral information.
257
+ *
258
+ * This algorithm performs *depth-first* *tree traversal* in *preorder*
259
+ * (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).
260
+ *
261
+ * You can choose for which nodes `visitor` is called by passing a `test`.
262
+ * For complex tests, you should test yourself in `visitor`, as it will be
263
+ * faster and will have improved type information.
264
+ *
265
+ * Walking the tree is an intensive task.
266
+ * Make use of the return values of the visitor when possible.
267
+ * Instead of walking a tree multiple times, walk it once, use `unist-util-is`
268
+ * to check if a node matches, and then perform different operations.
269
+ *
270
+ * You can change the tree.
271
+ * See `Visitor` for more info.
272
+ *
273
+ * @overload
274
+ * @param {Tree} tree
275
+ * @param {Check} check
276
+ * @param {BuildVisitor<Tree, Check>} visitor
277
+ * @param {boolean | null | undefined} [reverse]
278
+ * @returns {undefined}
279
+ *
280
+ * @overload
281
+ * @param {Tree} tree
282
+ * @param {BuildVisitor<Tree>} visitor
283
+ * @param {boolean | null | undefined} [reverse]
284
+ * @returns {undefined}
285
+ *
286
+ * @param {UnistNode} tree
287
+ * Tree to traverse.
288
+ * @param {Visitor | Test} test
289
+ * `unist-util-is`-compatible test
290
+ * @param {Visitor | boolean | null | undefined} [visitor]
291
+ * Handle each node.
292
+ * @param {boolean | null | undefined} [reverse]
293
+ * Traverse in reverse preorder (NRL) instead of the default preorder (NLR).
294
+ * @returns {undefined}
295
+ * Nothing.
296
+ *
297
+ * @template {UnistNode} Tree
298
+ * Node type.
299
+ * @template {Test} Check
300
+ * `unist-util-is`-compatible test.
301
+ */
302
+ function visitParents(tree, test, visitor, reverse) {
303
+ /** @type {Test} */
304
+ let check;
305
+
306
+ if (typeof test === 'function' && typeof visitor !== 'function') {
307
+ reverse = visitor;
308
+ // @ts-expect-error no visitor given, so `visitor` is test.
309
+ visitor = test;
310
+ } else {
311
+ // @ts-expect-error visitor given, so `test` isn’t a visitor.
312
+ check = test;
313
+ }
314
+
315
+ const is = convert(check);
316
+ const step = reverse ? -1 : 1;
317
+
318
+ factory(tree, undefined, [])();
319
+
320
+ /**
321
+ * @param {UnistNode} node
322
+ * @param {number | undefined} index
323
+ * @param {Array<UnistParent>} parents
324
+ */
325
+ function factory(node, index, parents) {
326
+ const value = /** @type {Record<string, unknown>} */ (
327
+ node && typeof node === 'object' ? node : {}
328
+ );
329
+
330
+ if (typeof value.type === 'string') {
331
+ const name =
332
+ // `hast`
333
+ typeof value.tagName === 'string'
334
+ ? value.tagName
335
+ : // `xast`
336
+ typeof value.name === 'string'
337
+ ? value.name
338
+ : undefined;
339
+
340
+ Object.defineProperty(visit, 'name', {
341
+ value:
342
+ 'node (' + color(node.type + (name ? '<' + name + '>' : '')) + ')'
343
+ });
344
+ }
345
+
346
+ return visit
347
+
348
+ function visit() {
349
+ /** @type {Readonly<ActionTuple>} */
350
+ let result = empty;
351
+ /** @type {Readonly<ActionTuple>} */
352
+ let subresult;
353
+ /** @type {number} */
354
+ let offset;
355
+ /** @type {Array<UnistParent>} */
356
+ let grandparents;
357
+
358
+ if (!test || is(node, index, parents[parents.length - 1] || undefined)) {
359
+ // @ts-expect-error: `visitor` is now a visitor.
360
+ result = toResult(visitor(node, parents));
361
+
362
+ if (result[0] === EXIT) {
363
+ return result
364
+ }
365
+ }
366
+
367
+ if ('children' in node && node.children) {
368
+ const nodeAsParent = /** @type {UnistParent} */ (node);
369
+
370
+ if (nodeAsParent.children && result[0] !== SKIP) {
371
+ offset = (reverse ? nodeAsParent.children.length : -1) + step;
372
+ grandparents = parents.concat(nodeAsParent);
373
+
374
+ while (offset > -1 && offset < nodeAsParent.children.length) {
375
+ const child = nodeAsParent.children[offset];
376
+
377
+ subresult = factory(child, offset, grandparents)();
378
+
379
+ if (subresult[0] === EXIT) {
380
+ return subresult
381
+ }
382
+
383
+ offset =
384
+ typeof subresult[1] === 'number' ? subresult[1] : offset + step;
385
+ }
386
+ }
387
+ }
388
+
389
+ return result
390
+ }
391
+ }
392
+ }
393
+
394
+ /**
395
+ * Turn a return value into a clean result.
396
+ *
397
+ * @param {VisitorResult} value
398
+ * Valid return values from visitors.
399
+ * @returns {Readonly<ActionTuple>}
400
+ * Clean result.
401
+ */
402
+ function toResult(value) {
403
+ if (Array.isArray(value)) {
404
+ return value
405
+ }
406
+
407
+ if (typeof value === 'number') {
408
+ return [CONTINUE, value]
409
+ }
410
+
411
+ return value === null || value === undefined ? empty : [value]
412
+ }
413
+
414
+ /**
415
+ * @typedef {import('unist').Node} UnistNode
416
+ * @typedef {import('unist').Parent} UnistParent
417
+ * @typedef {import('unist-util-visit-parents').VisitorResult} VisitorResult
418
+ */
419
+
420
+
421
+ /**
422
+ * Visit nodes.
423
+ *
424
+ * This algorithm performs *depth-first* *tree traversal* in *preorder*
425
+ * (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).
426
+ *
427
+ * You can choose for which nodes `visitor` is called by passing a `test`.
428
+ * For complex tests, you should test yourself in `visitor`, as it will be
429
+ * faster and will have improved type information.
430
+ *
431
+ * Walking the tree is an intensive task.
432
+ * Make use of the return values of the visitor when possible.
433
+ * Instead of walking a tree multiple times, walk it once, use `unist-util-is`
434
+ * to check if a node matches, and then perform different operations.
435
+ *
436
+ * You can change the tree.
437
+ * See `Visitor` for more info.
438
+ *
439
+ * @overload
440
+ * @param {Tree} tree
441
+ * @param {Check} check
442
+ * @param {BuildVisitor<Tree, Check>} visitor
443
+ * @param {boolean | null | undefined} [reverse]
444
+ * @returns {undefined}
445
+ *
446
+ * @overload
447
+ * @param {Tree} tree
448
+ * @param {BuildVisitor<Tree>} visitor
449
+ * @param {boolean | null | undefined} [reverse]
450
+ * @returns {undefined}
451
+ *
452
+ * @param {UnistNode} tree
453
+ * Tree to traverse.
454
+ * @param {Visitor | Test} testOrVisitor
455
+ * `unist-util-is`-compatible test (optional, omit to pass a visitor).
456
+ * @param {Visitor | boolean | null | undefined} [visitorOrReverse]
457
+ * Handle each node (when test is omitted, pass `reverse`).
458
+ * @param {boolean | null | undefined} [maybeReverse=false]
459
+ * Traverse in reverse preorder (NRL) instead of the default preorder (NLR).
460
+ * @returns {undefined}
461
+ * Nothing.
462
+ *
463
+ * @template {UnistNode} Tree
464
+ * Node type.
465
+ * @template {Test} Check
466
+ * `unist-util-is`-compatible test.
467
+ */
468
+ function visit(tree, testOrVisitor, visitorOrReverse, maybeReverse) {
469
+ /** @type {boolean | null | undefined} */
470
+ let reverse;
471
+ /** @type {Test} */
472
+ let test;
473
+ /** @type {Visitor} */
474
+ let visitor;
475
+
476
+ if (
477
+ typeof testOrVisitor === 'function' &&
478
+ typeof visitorOrReverse !== 'function'
479
+ ) {
480
+ test = undefined;
481
+ visitor = testOrVisitor;
482
+ reverse = visitorOrReverse;
483
+ } else {
484
+ // @ts-expect-error: assume the overload with test was given.
485
+ test = testOrVisitor;
486
+ // @ts-expect-error: assume the overload with test was given.
487
+ visitor = visitorOrReverse;
488
+ reverse = maybeReverse;
489
+ }
490
+
491
+ visitParents(tree, test, overload, reverse);
492
+
493
+ /**
494
+ * @param {UnistNode} node
495
+ * @param {Array<UnistParent>} parents
496
+ */
497
+ function overload(node, parents) {
498
+ const parent = parents[parents.length - 1];
499
+ const index = parent ? parent.children.indexOf(node) : undefined;
500
+ return visitor(node, index, parent)
501
+ }
502
+ }
503
+
504
+ console.log("🦖 remarkYouTube plugin module loaded");
505
+ var remarkYouTube = function (options) {
506
+ var _a = (options !== null && options !== void 0 ? options : {}).logLevel; _a === void 0 ? LogLevel.Silent : _a;
507
+ var logger = new Logger(resolveLogLevel(options === null || options === void 0 ? void 0 : options.logLevel), 'remarkYouTube');
508
+ logger.log('initialized');
509
+ return function (tree) {
510
+ visit(tree, ['link', 'text'], function (node, index, parent) {
511
+ if (!parent || typeof index !== 'number')
512
+ return;
513
+ var raw = node.url || node.value || '';
514
+ var ytUrl = raw.trim();
515
+ var hashnodeMatch = ytUrl.match(/^%\[(.+)\]$/);
516
+ if (hashnodeMatch) {
517
+ ytUrl = hashnodeMatch[1];
518
+ logger.log("hashnode-style embed detected: ".concat(ytUrl), LogLevel.Info);
519
+ }
520
+ var m = ytUrl.match(/youtube\.com\/watch\?v=([A-Za-z0-9_-]+)/) ||
521
+ ytUrl.match(/youtu\.be\/([A-Za-z0-9_-]+)/) ||
522
+ ytUrl.match(/youtube-nocookie\.com\/watch\?v=([A-Za-z0-9_-]+)/);
523
+ if (m) {
524
+ logger.log("rewriting YouTube URL: ".concat(ytUrl, " \u2192 videoId=").concat(m[1]), LogLevel.Debug);
525
+ parent.children.splice(index, 1, {
526
+ type: 'mdxJsxFlowElement',
527
+ name: 'LiteYouTubeEmbed',
528
+ attributes: [
529
+ { type: 'mdxJsxAttribute', name: 'id', value: m[1] },
530
+ { type: 'mdxJsxAttribute', name: 'title', value: 'YouTube video' },
531
+ ],
532
+ });
533
+ }
534
+ });
535
+ visit(tree, 'text', function (node, index, parent) {
536
+ if (!parent || typeof index !== 'number')
537
+ return;
538
+ if (node.value.trim() === '%[' || node.value.trim() === ']') {
539
+ logger.log("stripping hashnode bracket artifact: ".concat(node.value), LogLevel.Debug);
540
+ parent.children.splice(index, 1);
541
+ }
542
+ });
543
+ };
544
+ };
545
+
546
+ console.log("🦖 remarkScopedPath plugin module loaded");
547
+ var remarkScopedPath = function (options) {
548
+ var _a = options !== null && options !== void 0 ? options : {}, _b = _a.mappings, mappings = _b === void 0 ? [] : _b, _c = _a.logLevel; _c === void 0 ? LogLevel.Silent : _c;
549
+ var logger = new Logger(resolveLogLevel(options === null || options === void 0 ? void 0 : options.logLevel), 'remarkScopedPath');
550
+ logger.log("initialized with ".concat(mappings.length, " mappings"));
551
+ return function (tree, file) {
552
+ var _a;
553
+ var filePath = (file === null || file === void 0 ? void 0 : file.path) || ((_a = file === null || file === void 0 ? void 0 : file.history) === null || _a === void 0 ? void 0 : _a.slice(-1)[0]) || 'unknown';
554
+ logger.log("processing file: ".concat(filePath), LogLevel.Debug);
555
+ var rewrite = function (val, from, to, ctx) {
556
+ if (val.startsWith(from)) {
557
+ var newVal = val.replace(from, to);
558
+ logger.log("\uD83D\uDD04 ".concat(ctx, " ").concat(val, " \u2192 ").concat(newVal), LogLevel.Info);
559
+ return newVal;
560
+ }
561
+ return val;
562
+ };
563
+ visit(tree, 'image', function (node) {
564
+ for (var _i = 0, mappings_1 = mappings; _i < mappings_1.length; _i++) {
565
+ var _a = mappings_1[_i], from = _a.from, to = _a.to;
566
+ node.url = rewrite(node.url, from, to, 'img');
567
+ }
568
+ });
569
+ visit(tree, 'link', function (node) {
570
+ for (var _i = 0, mappings_2 = mappings; _i < mappings_2.length; _i++) {
571
+ var _a = mappings_2[_i], from = _a.from, to = _a.to;
572
+ node.url = rewrite(node.url, from, to, 'link');
573
+ }
574
+ });
575
+ visit(tree, 'mdxJsxFlowElement', function (node) {
576
+ var _a;
577
+ (_a = node.attributes) === null || _a === void 0 ? void 0 : _a.forEach(function (attr) {
578
+ if (attr.type === 'mdxJsxAttribute' && typeof attr.value === 'string') {
579
+ for (var _i = 0, mappings_3 = mappings; _i < mappings_3.length; _i++) {
580
+ var _a = mappings_3[_i], from = _a.from, to = _a.to;
581
+ attr.value = rewrite(attr.value, from, to, "jsx <".concat(node.name, "> ").concat(attr.name, ":"));
582
+ }
583
+ }
584
+ });
585
+ });
586
+ visit(tree, 'mdxjsEsm', function (node) {
587
+ for (var _i = 0, mappings_4 = mappings; _i < mappings_4.length; _i++) {
588
+ var _a = mappings_4[_i], from = _a.from, to = _a.to;
589
+ var re = new RegExp("(['\"])".concat(from, "/"), 'g');
590
+ var newVal = node.value.replace(re, "$1".concat(to, "/"));
591
+ if (newVal !== node.value) {
592
+ logger.log("esm rewrite (".concat(from, " \u2192 ").concat(to, "):\n--- before ---\n").concat(node.value, "\n--- after ---\n").concat(newVal), LogLevel.Info);
593
+ node.value = newVal;
594
+ }
595
+ }
596
+ });
597
+ logger.log(" ", LogLevel.Debug);
598
+ };
599
+ };
600
+
601
+ console.log("🦖 remarkReplaceMetaUrl plugin loaded");
602
+ var remarkReplaceMetaUrl = function (options) {
603
+ var _a = options !== null && options !== void 0 ? options : {}, _b = _a.from, from = _b === void 0 ? '' : _b, _c = _a.to, to = _c === void 0 ? '' : _c, _d = _a.logLevel; _d === void 0 ? LogLevel.Silent : _d;
604
+ var logger = new Logger(resolveLogLevel(options === null || options === void 0 ? void 0 : options.logLevel), 'remarkReplaceMetaUrl');
605
+ logger.log("initialized: replacing \"".concat(from, "\" \u2192 \"").concat(to, "\""));
606
+ return function (tree) {
607
+ visit(tree, 'mdxJsxFlowElement', function (node) {
608
+ if (node.name === 'meta' && Array.isArray(node.attributes)) {
609
+ for (var _i = 0, _a = node.attributes; _i < _a.length; _i++) {
610
+ var attr = _a[_i];
611
+ if (attr.name === 'content' && typeof attr.value === 'string' && attr.value.includes(from)) {
612
+ var newVal = attr.value.replace(from, to);
613
+ logger.log("rewriting: \"".concat(attr.value, "\" \u2192 \"").concat(newVal, "\""), LogLevel.Info);
614
+ attr.value = newVal;
615
+ }
616
+ }
617
+ }
618
+ });
619
+ };
620
+ };
621
+
622
+ var remarkCodeSections = function (options) {
623
+ var logger = new Logger(resolveLogLevel(options === null || options === void 0 ? void 0 : options.logLevel), "remarkCodeSections");
624
+ var desc_text = "@desc:";
625
+ var command_text = "@command:";
626
+ var code_text = "@code:";
627
+ var results_text = "@results:";
628
+ return function (tree) {
629
+ visit(tree, "code", function (node, index, parent) {
630
+ if (!(node === null || node === void 0 ? void 0 : node.value))
631
+ return;
632
+ var hasActivator = /@desc:|@command:|@code:|@results:/.test(node.value);
633
+ if (!hasActivator)
634
+ return;
635
+ logger.log(node, LogLevel.Debug);
636
+ if (node.lang && node.lang.startsWith("example")) {
637
+ var lang = node.lang.replace("example-", "").trim();
638
+ var lines = node.value.split("\n");
639
+ var description_1 = "", command_1 = "", code_1 = "", results_1 = "", codeTitle_1 = "";
640
+ var currentSection_1 = "";
641
+ lines.forEach(function (line) {
642
+ if (line.startsWith(desc_text)) {
643
+ currentSection_1 = "description";
644
+ description_1 = line.replace(desc_text, "").trim();
645
+ }
646
+ else if (line.startsWith(command_text)) {
647
+ currentSection_1 = "command";
648
+ command_1 = line.replace(command_text, "").trim();
649
+ }
650
+ else if (line.startsWith(code_text)) {
651
+ currentSection_1 = "code";
652
+ codeTitle_1 = line.replace(code_text, "").trim();
653
+ }
654
+ else if (line.startsWith(results_text)) {
655
+ currentSection_1 = "results";
656
+ results_1 = line.replace(results_text, "").trim();
657
+ }
658
+ else {
659
+ if (currentSection_1 === "description")
660
+ description_1 += "\n".concat(line);
661
+ else if (currentSection_1 === "command")
662
+ command_1 += "\n".concat(line);
663
+ else if (currentSection_1 === "code")
664
+ code_1 += "\n".concat(line);
665
+ else if (currentSection_1 === "results")
666
+ results_1 += "\n".concat(line);
667
+ }
668
+ });
669
+ var divWrapper = {
670
+ type: "div",
671
+ data: { hName: "div", hProperties: { className: "code-section" } },
672
+ children: [],
673
+ };
674
+ if (description_1) {
675
+ var descDiv = {
676
+ type: "div",
677
+ data: { hName: "div", hProperties: { className: "code-section-desc" } },
678
+ children: [],
679
+ };
680
+ descDiv.children.push({ type: "paragraph", children: [{ type: "strong", children: [{ type: "text", value: "Description:" }] }] }, { type: "paragraph", children: [{ type: "text", value: description_1.trim() }], data: { hProperties: { style: "padding-bottom: 10px;" } } });
681
+ divWrapper.children.push(descDiv);
682
+ }
683
+ if (command_1) {
684
+ var cmdDiv = {
685
+ type: "div",
686
+ data: { hName: "div", hProperties: { className: "code-section-command" } },
687
+ children: [],
688
+ };
689
+ cmdDiv.children.push({ type: "paragraph", children: [{ type: "strong", children: [{ type: "text", value: "Command:" }] }] }, { type: "code", lang: "sh", value: command_1.trim() });
690
+ divWrapper.children.push(cmdDiv);
691
+ }
692
+ if (code_1) {
693
+ var codeDiv = {
694
+ type: "div",
695
+ data: { hName: "div", hProperties: { className: "code-section-code" } },
696
+ children: [],
697
+ };
698
+ codeDiv.children.push({ type: "paragraph", children: [{ type: "strong", children: [{ type: "text", value: codeTitle_1 }] }] }, { type: "code", lang: lang, value: code_1.trim() });
699
+ divWrapper.children.push(codeDiv);
700
+ }
701
+ if (results_1) {
702
+ var resultsDiv = {
703
+ type: "div",
704
+ data: { hName: "div", hProperties: { className: "code-section-results" } },
705
+ children: [],
706
+ };
707
+ resultsDiv.children.push({ type: "paragraph", children: [{ type: "strong", children: [{ type: "text", value: "Results:" }] }] }, { type: "code", lang: "buttonless", value: results_1.trim() });
708
+ divWrapper.children.push(resultsDiv);
709
+ }
710
+ parent.children.splice(index, 1, divWrapper);
711
+ }
712
+ });
713
+ };
714
+ };
715
+
716
+ /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */
717
+ function isNothing(subject) {
718
+ return (typeof subject === 'undefined') || (subject === null);
719
+ }
720
+
721
+
722
+ function isObject(subject) {
723
+ return (typeof subject === 'object') && (subject !== null);
724
+ }
725
+
726
+
727
+ function toArray(sequence) {
728
+ if (Array.isArray(sequence)) return sequence;
729
+ else if (isNothing(sequence)) return [];
730
+
731
+ return [ sequence ];
732
+ }
733
+
734
+
735
+ function extend(target, source) {
736
+ var index, length, key, sourceKeys;
737
+
738
+ if (source) {
739
+ sourceKeys = Object.keys(source);
740
+
741
+ for (index = 0, length = sourceKeys.length; index < length; index += 1) {
742
+ key = sourceKeys[index];
743
+ target[key] = source[key];
744
+ }
745
+ }
746
+
747
+ return target;
748
+ }
749
+
750
+
751
+ function repeat(string, count) {
752
+ var result = '', cycle;
753
+
754
+ for (cycle = 0; cycle < count; cycle += 1) {
755
+ result += string;
756
+ }
757
+
758
+ return result;
759
+ }
760
+
761
+
762
+ function isNegativeZero(number) {
763
+ return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
764
+ }
765
+
766
+
767
+ var isNothing_1 = isNothing;
768
+ var isObject_1 = isObject;
769
+ var toArray_1 = toArray;
770
+ var repeat_1 = repeat;
771
+ var isNegativeZero_1 = isNegativeZero;
772
+ var extend_1 = extend;
773
+
774
+ var common = {
775
+ isNothing: isNothing_1,
776
+ isObject: isObject_1,
777
+ toArray: toArray_1,
778
+ repeat: repeat_1,
779
+ isNegativeZero: isNegativeZero_1,
780
+ extend: extend_1
781
+ };
782
+
783
+ // YAML error class. http://stackoverflow.com/questions/8458984
784
+
785
+
786
+ function formatError(exception, compact) {
787
+ var where = '', message = exception.reason || '(unknown reason)';
788
+
789
+ if (!exception.mark) return message;
790
+
791
+ if (exception.mark.name) {
792
+ where += 'in "' + exception.mark.name + '" ';
793
+ }
794
+
795
+ where += '(' + (exception.mark.line + 1) + ':' + (exception.mark.column + 1) + ')';
796
+
797
+ if (!compact && exception.mark.snippet) {
798
+ where += '\n\n' + exception.mark.snippet;
799
+ }
800
+
801
+ return message + ' ' + where;
802
+ }
803
+
804
+
805
+ function YAMLException$1(reason, mark) {
806
+ // Super constructor
807
+ Error.call(this);
808
+
809
+ this.name = 'YAMLException';
810
+ this.reason = reason;
811
+ this.mark = mark;
812
+ this.message = formatError(this, false);
813
+
814
+ // Include stack trace in error object
815
+ if (Error.captureStackTrace) {
816
+ // Chrome and NodeJS
817
+ Error.captureStackTrace(this, this.constructor);
818
+ } else {
819
+ // FF, IE 10+ and Safari 6+. Fallback for others
820
+ this.stack = (new Error()).stack || '';
821
+ }
822
+ }
823
+
824
+
825
+ // Inherit from Error
826
+ YAMLException$1.prototype = Object.create(Error.prototype);
827
+ YAMLException$1.prototype.constructor = YAMLException$1;
828
+
829
+
830
+ YAMLException$1.prototype.toString = function toString(compact) {
831
+ return this.name + ': ' + formatError(this, compact);
832
+ };
833
+
834
+
835
+ var exception = YAMLException$1;
836
+
837
+ // get snippet for a single line, respecting maxLength
838
+ function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
839
+ var head = '';
840
+ var tail = '';
841
+ var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
842
+
843
+ if (position - lineStart > maxHalfLength) {
844
+ head = ' ... ';
845
+ lineStart = position - maxHalfLength + head.length;
846
+ }
847
+
848
+ if (lineEnd - position > maxHalfLength) {
849
+ tail = ' ...';
850
+ lineEnd = position + maxHalfLength - tail.length;
851
+ }
852
+
853
+ return {
854
+ str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, '→') + tail,
855
+ pos: position - lineStart + head.length // relative position
856
+ };
857
+ }
858
+
859
+
860
+ function padStart(string, max) {
861
+ return common.repeat(' ', max - string.length) + string;
862
+ }
863
+
864
+
865
+ function makeSnippet(mark, options) {
866
+ options = Object.create(options || null);
867
+
868
+ if (!mark.buffer) return null;
869
+
870
+ if (!options.maxLength) options.maxLength = 79;
871
+ if (typeof options.indent !== 'number') options.indent = 1;
872
+ if (typeof options.linesBefore !== 'number') options.linesBefore = 3;
873
+ if (typeof options.linesAfter !== 'number') options.linesAfter = 2;
874
+
875
+ var re = /\r?\n|\r|\0/g;
876
+ var lineStarts = [ 0 ];
877
+ var lineEnds = [];
878
+ var match;
879
+ var foundLineNo = -1;
880
+
881
+ while ((match = re.exec(mark.buffer))) {
882
+ lineEnds.push(match.index);
883
+ lineStarts.push(match.index + match[0].length);
884
+
885
+ if (mark.position <= match.index && foundLineNo < 0) {
886
+ foundLineNo = lineStarts.length - 2;
887
+ }
888
+ }
889
+
890
+ if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
891
+
892
+ var result = '', i, line;
893
+ var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
894
+ var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
895
+
896
+ for (i = 1; i <= options.linesBefore; i++) {
897
+ if (foundLineNo - i < 0) break;
898
+ line = getLine(
899
+ mark.buffer,
900
+ lineStarts[foundLineNo - i],
901
+ lineEnds[foundLineNo - i],
902
+ mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]),
903
+ maxLineLength
904
+ );
905
+ result = common.repeat(' ', options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) +
906
+ ' | ' + line.str + '\n' + result;
907
+ }
908
+
909
+ line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
910
+ result += common.repeat(' ', options.indent) + padStart((mark.line + 1).toString(), lineNoLength) +
911
+ ' | ' + line.str + '\n';
912
+ result += common.repeat('-', options.indent + lineNoLength + 3 + line.pos) + '^' + '\n';
913
+
914
+ for (i = 1; i <= options.linesAfter; i++) {
915
+ if (foundLineNo + i >= lineEnds.length) break;
916
+ line = getLine(
917
+ mark.buffer,
918
+ lineStarts[foundLineNo + i],
919
+ lineEnds[foundLineNo + i],
920
+ mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]),
921
+ maxLineLength
922
+ );
923
+ result += common.repeat(' ', options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) +
924
+ ' | ' + line.str + '\n';
925
+ }
926
+
927
+ return result.replace(/\n$/, '');
928
+ }
929
+
930
+
931
+ var snippet = makeSnippet;
932
+
933
+ var TYPE_CONSTRUCTOR_OPTIONS = [
934
+ 'kind',
935
+ 'multi',
936
+ 'resolve',
937
+ 'construct',
938
+ 'instanceOf',
939
+ 'predicate',
940
+ 'represent',
941
+ 'representName',
942
+ 'defaultStyle',
943
+ 'styleAliases'
944
+ ];
945
+
946
+ var YAML_NODE_KINDS = [
947
+ 'scalar',
948
+ 'sequence',
949
+ 'mapping'
950
+ ];
951
+
952
+ function compileStyleAliases(map) {
953
+ var result = {};
954
+
955
+ if (map !== null) {
956
+ Object.keys(map).forEach(function (style) {
957
+ map[style].forEach(function (alias) {
958
+ result[String(alias)] = style;
959
+ });
960
+ });
961
+ }
962
+
963
+ return result;
964
+ }
965
+
966
+ function Type$1(tag, options) {
967
+ options = options || {};
968
+
969
+ Object.keys(options).forEach(function (name) {
970
+ if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
971
+ throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
972
+ }
973
+ });
974
+
975
+ // TODO: Add tag format check.
976
+ this.options = options; // keep original options in case user wants to extend this type later
977
+ this.tag = tag;
978
+ this.kind = options['kind'] || null;
979
+ this.resolve = options['resolve'] || function () { return true; };
980
+ this.construct = options['construct'] || function (data) { return data; };
981
+ this.instanceOf = options['instanceOf'] || null;
982
+ this.predicate = options['predicate'] || null;
983
+ this.represent = options['represent'] || null;
984
+ this.representName = options['representName'] || null;
985
+ this.defaultStyle = options['defaultStyle'] || null;
986
+ this.multi = options['multi'] || false;
987
+ this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
988
+
989
+ if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
990
+ throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
991
+ }
992
+ }
993
+
994
+ var type = Type$1;
995
+
996
+ /*eslint-disable max-len*/
997
+
998
+
999
+
1000
+
1001
+
1002
+ function compileList(schema, name) {
1003
+ var result = [];
1004
+
1005
+ schema[name].forEach(function (currentType) {
1006
+ var newIndex = result.length;
1007
+
1008
+ result.forEach(function (previousType, previousIndex) {
1009
+ if (previousType.tag === currentType.tag &&
1010
+ previousType.kind === currentType.kind &&
1011
+ previousType.multi === currentType.multi) {
1012
+
1013
+ newIndex = previousIndex;
1014
+ }
1015
+ });
1016
+
1017
+ result[newIndex] = currentType;
1018
+ });
1019
+
1020
+ return result;
1021
+ }
1022
+
1023
+
1024
+ function compileMap(/* lists... */) {
1025
+ var result = {
1026
+ scalar: {},
1027
+ sequence: {},
1028
+ mapping: {},
1029
+ fallback: {},
1030
+ multi: {
1031
+ scalar: [],
1032
+ sequence: [],
1033
+ mapping: [],
1034
+ fallback: []
1035
+ }
1036
+ }, index, length;
1037
+
1038
+ function collectType(type) {
1039
+ if (type.multi) {
1040
+ result.multi[type.kind].push(type);
1041
+ result.multi['fallback'].push(type);
1042
+ } else {
1043
+ result[type.kind][type.tag] = result['fallback'][type.tag] = type;
1044
+ }
1045
+ }
1046
+
1047
+ for (index = 0, length = arguments.length; index < length; index += 1) {
1048
+ arguments[index].forEach(collectType);
1049
+ }
1050
+ return result;
1051
+ }
1052
+
1053
+
1054
+ function Schema$1(definition) {
1055
+ return this.extend(definition);
1056
+ }
1057
+
1058
+
1059
+ Schema$1.prototype.extend = function extend(definition) {
1060
+ var implicit = [];
1061
+ var explicit = [];
1062
+
1063
+ if (definition instanceof type) {
1064
+ // Schema.extend(type)
1065
+ explicit.push(definition);
1066
+
1067
+ } else if (Array.isArray(definition)) {
1068
+ // Schema.extend([ type1, type2, ... ])
1069
+ explicit = explicit.concat(definition);
1070
+
1071
+ } else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
1072
+ // Schema.extend({ explicit: [ type1, type2, ... ], implicit: [ type1, type2, ... ] })
1073
+ if (definition.implicit) implicit = implicit.concat(definition.implicit);
1074
+ if (definition.explicit) explicit = explicit.concat(definition.explicit);
1075
+
1076
+ } else {
1077
+ throw new exception('Schema.extend argument should be a Type, [ Type ], ' +
1078
+ 'or a schema definition ({ implicit: [...], explicit: [...] })');
1079
+ }
1080
+
1081
+ implicit.forEach(function (type$1) {
1082
+ if (!(type$1 instanceof type)) {
1083
+ throw new exception('Specified list of YAML types (or a single Type object) contains a non-Type object.');
1084
+ }
1085
+
1086
+ if (type$1.loadKind && type$1.loadKind !== 'scalar') {
1087
+ throw new exception('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
1088
+ }
1089
+
1090
+ if (type$1.multi) {
1091
+ throw new exception('There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.');
1092
+ }
1093
+ });
1094
+
1095
+ explicit.forEach(function (type$1) {
1096
+ if (!(type$1 instanceof type)) {
1097
+ throw new exception('Specified list of YAML types (or a single Type object) contains a non-Type object.');
1098
+ }
1099
+ });
1100
+
1101
+ var result = Object.create(Schema$1.prototype);
1102
+
1103
+ result.implicit = (this.implicit || []).concat(implicit);
1104
+ result.explicit = (this.explicit || []).concat(explicit);
1105
+
1106
+ result.compiledImplicit = compileList(result, 'implicit');
1107
+ result.compiledExplicit = compileList(result, 'explicit');
1108
+ result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
1109
+
1110
+ return result;
1111
+ };
1112
+
1113
+
1114
+ var schema = Schema$1;
1115
+
1116
+ var str = new type('tag:yaml.org,2002:str', {
1117
+ kind: 'scalar',
1118
+ construct: function (data) { return data !== null ? data : ''; }
1119
+ });
1120
+
1121
+ var seq = new type('tag:yaml.org,2002:seq', {
1122
+ kind: 'sequence',
1123
+ construct: function (data) { return data !== null ? data : []; }
1124
+ });
1125
+
1126
+ var map = new type('tag:yaml.org,2002:map', {
1127
+ kind: 'mapping',
1128
+ construct: function (data) { return data !== null ? data : {}; }
1129
+ });
1130
+
1131
+ var failsafe = new schema({
1132
+ explicit: [
1133
+ str,
1134
+ seq,
1135
+ map
1136
+ ]
1137
+ });
1138
+
1139
+ function resolveYamlNull(data) {
1140
+ if (data === null) return true;
1141
+
1142
+ var max = data.length;
1143
+
1144
+ return (max === 1 && data === '~') ||
1145
+ (max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'));
1146
+ }
1147
+
1148
+ function constructYamlNull() {
1149
+ return null;
1150
+ }
1151
+
1152
+ function isNull(object) {
1153
+ return object === null;
1154
+ }
1155
+
1156
+ var _null = new type('tag:yaml.org,2002:null', {
1157
+ kind: 'scalar',
1158
+ resolve: resolveYamlNull,
1159
+ construct: constructYamlNull,
1160
+ predicate: isNull,
1161
+ represent: {
1162
+ canonical: function () { return '~'; },
1163
+ lowercase: function () { return 'null'; },
1164
+ uppercase: function () { return 'NULL'; },
1165
+ camelcase: function () { return 'Null'; },
1166
+ empty: function () { return ''; }
1167
+ },
1168
+ defaultStyle: 'lowercase'
1169
+ });
1170
+
1171
+ function resolveYamlBoolean(data) {
1172
+ if (data === null) return false;
1173
+
1174
+ var max = data.length;
1175
+
1176
+ return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
1177
+ (max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
1178
+ }
1179
+
1180
+ function constructYamlBoolean(data) {
1181
+ return data === 'true' ||
1182
+ data === 'True' ||
1183
+ data === 'TRUE';
1184
+ }
1185
+
1186
+ function isBoolean(object) {
1187
+ return Object.prototype.toString.call(object) === '[object Boolean]';
1188
+ }
1189
+
1190
+ var bool = new type('tag:yaml.org,2002:bool', {
1191
+ kind: 'scalar',
1192
+ resolve: resolveYamlBoolean,
1193
+ construct: constructYamlBoolean,
1194
+ predicate: isBoolean,
1195
+ represent: {
1196
+ lowercase: function (object) { return object ? 'true' : 'false'; },
1197
+ uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
1198
+ camelcase: function (object) { return object ? 'True' : 'False'; }
1199
+ },
1200
+ defaultStyle: 'lowercase'
1201
+ });
1202
+
1203
+ function isHexCode(c) {
1204
+ return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) ||
1205
+ ((0x41/* A */ <= c) && (c <= 0x46/* F */)) ||
1206
+ ((0x61/* a */ <= c) && (c <= 0x66/* f */));
1207
+ }
1208
+
1209
+ function isOctCode(c) {
1210
+ return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */));
1211
+ }
1212
+
1213
+ function isDecCode(c) {
1214
+ return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */));
1215
+ }
1216
+
1217
+ function resolveYamlInteger(data) {
1218
+ if (data === null) return false;
1219
+
1220
+ var max = data.length,
1221
+ index = 0,
1222
+ hasDigits = false,
1223
+ ch;
1224
+
1225
+ if (!max) return false;
1226
+
1227
+ ch = data[index];
1228
+
1229
+ // sign
1230
+ if (ch === '-' || ch === '+') {
1231
+ ch = data[++index];
1232
+ }
1233
+
1234
+ if (ch === '0') {
1235
+ // 0
1236
+ if (index + 1 === max) return true;
1237
+ ch = data[++index];
1238
+
1239
+ // base 2, base 8, base 16
1240
+
1241
+ if (ch === 'b') {
1242
+ // base 2
1243
+ index++;
1244
+
1245
+ for (; index < max; index++) {
1246
+ ch = data[index];
1247
+ if (ch === '_') continue;
1248
+ if (ch !== '0' && ch !== '1') return false;
1249
+ hasDigits = true;
1250
+ }
1251
+ return hasDigits && ch !== '_';
1252
+ }
1253
+
1254
+
1255
+ if (ch === 'x') {
1256
+ // base 16
1257
+ index++;
1258
+
1259
+ for (; index < max; index++) {
1260
+ ch = data[index];
1261
+ if (ch === '_') continue;
1262
+ if (!isHexCode(data.charCodeAt(index))) return false;
1263
+ hasDigits = true;
1264
+ }
1265
+ return hasDigits && ch !== '_';
1266
+ }
1267
+
1268
+
1269
+ if (ch === 'o') {
1270
+ // base 8
1271
+ index++;
1272
+
1273
+ for (; index < max; index++) {
1274
+ ch = data[index];
1275
+ if (ch === '_') continue;
1276
+ if (!isOctCode(data.charCodeAt(index))) return false;
1277
+ hasDigits = true;
1278
+ }
1279
+ return hasDigits && ch !== '_';
1280
+ }
1281
+ }
1282
+
1283
+ // base 10 (except 0)
1284
+
1285
+ // value should not start with `_`;
1286
+ if (ch === '_') return false;
1287
+
1288
+ for (; index < max; index++) {
1289
+ ch = data[index];
1290
+ if (ch === '_') continue;
1291
+ if (!isDecCode(data.charCodeAt(index))) {
1292
+ return false;
1293
+ }
1294
+ hasDigits = true;
1295
+ }
1296
+
1297
+ // Should have digits and should not end with `_`
1298
+ if (!hasDigits || ch === '_') return false;
1299
+
1300
+ return true;
1301
+ }
1302
+
1303
+ function constructYamlInteger(data) {
1304
+ var value = data, sign = 1, ch;
1305
+
1306
+ if (value.indexOf('_') !== -1) {
1307
+ value = value.replace(/_/g, '');
1308
+ }
1309
+
1310
+ ch = value[0];
1311
+
1312
+ if (ch === '-' || ch === '+') {
1313
+ if (ch === '-') sign = -1;
1314
+ value = value.slice(1);
1315
+ ch = value[0];
1316
+ }
1317
+
1318
+ if (value === '0') return 0;
1319
+
1320
+ if (ch === '0') {
1321
+ if (value[1] === 'b') return sign * parseInt(value.slice(2), 2);
1322
+ if (value[1] === 'x') return sign * parseInt(value.slice(2), 16);
1323
+ if (value[1] === 'o') return sign * parseInt(value.slice(2), 8);
1324
+ }
1325
+
1326
+ return sign * parseInt(value, 10);
1327
+ }
1328
+
1329
+ function isInteger(object) {
1330
+ return (Object.prototype.toString.call(object)) === '[object Number]' &&
1331
+ (object % 1 === 0 && !common.isNegativeZero(object));
1332
+ }
1333
+
1334
+ var int = new type('tag:yaml.org,2002:int', {
1335
+ kind: 'scalar',
1336
+ resolve: resolveYamlInteger,
1337
+ construct: constructYamlInteger,
1338
+ predicate: isInteger,
1339
+ represent: {
1340
+ binary: function (obj) { return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1); },
1341
+ octal: function (obj) { return obj >= 0 ? '0o' + obj.toString(8) : '-0o' + obj.toString(8).slice(1); },
1342
+ decimal: function (obj) { return obj.toString(10); },
1343
+ /* eslint-disable max-len */
1344
+ hexadecimal: function (obj) { return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1); }
1345
+ },
1346
+ defaultStyle: 'decimal',
1347
+ styleAliases: {
1348
+ binary: [ 2, 'bin' ],
1349
+ octal: [ 8, 'oct' ],
1350
+ decimal: [ 10, 'dec' ],
1351
+ hexadecimal: [ 16, 'hex' ]
1352
+ }
1353
+ });
1354
+
1355
+ var YAML_FLOAT_PATTERN = new RegExp(
1356
+ // 2.5e4, 2.5 and integers
1357
+ '^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' +
1358
+ // .2e4, .2
1359
+ // special case, seems not from spec
1360
+ '|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' +
1361
+ // .inf
1362
+ '|[-+]?\\.(?:inf|Inf|INF)' +
1363
+ // .nan
1364
+ '|\\.(?:nan|NaN|NAN))$');
1365
+
1366
+ function resolveYamlFloat(data) {
1367
+ if (data === null) return false;
1368
+
1369
+ if (!YAML_FLOAT_PATTERN.test(data) ||
1370
+ // Quick hack to not allow integers end with `_`
1371
+ // Probably should update regexp & check speed
1372
+ data[data.length - 1] === '_') {
1373
+ return false;
1374
+ }
1375
+
1376
+ return true;
1377
+ }
1378
+
1379
+ function constructYamlFloat(data) {
1380
+ var value, sign;
1381
+
1382
+ value = data.replace(/_/g, '').toLowerCase();
1383
+ sign = value[0] === '-' ? -1 : 1;
1384
+
1385
+ if ('+-'.indexOf(value[0]) >= 0) {
1386
+ value = value.slice(1);
1387
+ }
1388
+
1389
+ if (value === '.inf') {
1390
+ return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
1391
+
1392
+ } else if (value === '.nan') {
1393
+ return NaN;
1394
+ }
1395
+ return sign * parseFloat(value, 10);
1396
+ }
1397
+
1398
+
1399
+ var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
1400
+
1401
+ function representYamlFloat(object, style) {
1402
+ var res;
1403
+
1404
+ if (isNaN(object)) {
1405
+ switch (style) {
1406
+ case 'lowercase': return '.nan';
1407
+ case 'uppercase': return '.NAN';
1408
+ case 'camelcase': return '.NaN';
1409
+ }
1410
+ } else if (Number.POSITIVE_INFINITY === object) {
1411
+ switch (style) {
1412
+ case 'lowercase': return '.inf';
1413
+ case 'uppercase': return '.INF';
1414
+ case 'camelcase': return '.Inf';
1415
+ }
1416
+ } else if (Number.NEGATIVE_INFINITY === object) {
1417
+ switch (style) {
1418
+ case 'lowercase': return '-.inf';
1419
+ case 'uppercase': return '-.INF';
1420
+ case 'camelcase': return '-.Inf';
1421
+ }
1422
+ } else if (common.isNegativeZero(object)) {
1423
+ return '-0.0';
1424
+ }
1425
+
1426
+ res = object.toString(10);
1427
+
1428
+ // JS stringifier can build scientific format without dots: 5e-100,
1429
+ // while YAML requres dot: 5.e-100. Fix it with simple hack
1430
+
1431
+ return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
1432
+ }
1433
+
1434
+ function isFloat(object) {
1435
+ return (Object.prototype.toString.call(object) === '[object Number]') &&
1436
+ (object % 1 !== 0 || common.isNegativeZero(object));
1437
+ }
1438
+
1439
+ var float = new type('tag:yaml.org,2002:float', {
1440
+ kind: 'scalar',
1441
+ resolve: resolveYamlFloat,
1442
+ construct: constructYamlFloat,
1443
+ predicate: isFloat,
1444
+ represent: representYamlFloat,
1445
+ defaultStyle: 'lowercase'
1446
+ });
1447
+
1448
+ var json = failsafe.extend({
1449
+ implicit: [
1450
+ _null,
1451
+ bool,
1452
+ int,
1453
+ float
1454
+ ]
1455
+ });
1456
+
1457
+ var core = json;
1458
+
1459
+ var YAML_DATE_REGEXP = new RegExp(
1460
+ '^([0-9][0-9][0-9][0-9])' + // [1] year
1461
+ '-([0-9][0-9])' + // [2] month
1462
+ '-([0-9][0-9])$'); // [3] day
1463
+
1464
+ var YAML_TIMESTAMP_REGEXP = new RegExp(
1465
+ '^([0-9][0-9][0-9][0-9])' + // [1] year
1466
+ '-([0-9][0-9]?)' + // [2] month
1467
+ '-([0-9][0-9]?)' + // [3] day
1468
+ '(?:[Tt]|[ \\t]+)' + // ...
1469
+ '([0-9][0-9]?)' + // [4] hour
1470
+ ':([0-9][0-9])' + // [5] minute
1471
+ ':([0-9][0-9])' + // [6] second
1472
+ '(?:\\.([0-9]*))?' + // [7] fraction
1473
+ '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
1474
+ '(?::([0-9][0-9]))?))?$'); // [11] tz_minute
1475
+
1476
+ function resolveYamlTimestamp(data) {
1477
+ if (data === null) return false;
1478
+ if (YAML_DATE_REGEXP.exec(data) !== null) return true;
1479
+ if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
1480
+ return false;
1481
+ }
1482
+
1483
+ function constructYamlTimestamp(data) {
1484
+ var match, year, month, day, hour, minute, second, fraction = 0,
1485
+ delta = null, tz_hour, tz_minute, date;
1486
+
1487
+ match = YAML_DATE_REGEXP.exec(data);
1488
+ if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
1489
+
1490
+ if (match === null) throw new Error('Date resolve error');
1491
+
1492
+ // match: [1] year [2] month [3] day
1493
+
1494
+ year = +(match[1]);
1495
+ month = +(match[2]) - 1; // JS month starts with 0
1496
+ day = +(match[3]);
1497
+
1498
+ if (!match[4]) { // no hour
1499
+ return new Date(Date.UTC(year, month, day));
1500
+ }
1501
+
1502
+ // match: [4] hour [5] minute [6] second [7] fraction
1503
+
1504
+ hour = +(match[4]);
1505
+ minute = +(match[5]);
1506
+ second = +(match[6]);
1507
+
1508
+ if (match[7]) {
1509
+ fraction = match[7].slice(0, 3);
1510
+ while (fraction.length < 3) { // milli-seconds
1511
+ fraction += '0';
1512
+ }
1513
+ fraction = +fraction;
1514
+ }
1515
+
1516
+ // match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
1517
+
1518
+ if (match[9]) {
1519
+ tz_hour = +(match[10]);
1520
+ tz_minute = +(match[11] || 0);
1521
+ delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
1522
+ if (match[9] === '-') delta = -delta;
1523
+ }
1524
+
1525
+ date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
1526
+
1527
+ if (delta) date.setTime(date.getTime() - delta);
1528
+
1529
+ return date;
1530
+ }
1531
+
1532
+ function representYamlTimestamp(object /*, style*/) {
1533
+ return object.toISOString();
1534
+ }
1535
+
1536
+ var timestamp = new type('tag:yaml.org,2002:timestamp', {
1537
+ kind: 'scalar',
1538
+ resolve: resolveYamlTimestamp,
1539
+ construct: constructYamlTimestamp,
1540
+ instanceOf: Date,
1541
+ represent: representYamlTimestamp
1542
+ });
1543
+
1544
+ function resolveYamlMerge(data) {
1545
+ return data === '<<' || data === null;
1546
+ }
1547
+
1548
+ var merge = new type('tag:yaml.org,2002:merge', {
1549
+ kind: 'scalar',
1550
+ resolve: resolveYamlMerge
1551
+ });
1552
+
1553
+ /*eslint-disable no-bitwise*/
1554
+
1555
+
1556
+
1557
+
1558
+
1559
+ // [ 64, 65, 66 ] -> [ padding, CR, LF ]
1560
+ var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
1561
+
1562
+
1563
+ function resolveYamlBinary(data) {
1564
+ if (data === null) return false;
1565
+
1566
+ var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
1567
+
1568
+ // Convert one by one.
1569
+ for (idx = 0; idx < max; idx++) {
1570
+ code = map.indexOf(data.charAt(idx));
1571
+
1572
+ // Skip CR/LF
1573
+ if (code > 64) continue;
1574
+
1575
+ // Fail on illegal characters
1576
+ if (code < 0) return false;
1577
+
1578
+ bitlen += 6;
1579
+ }
1580
+
1581
+ // If there are any bits left, source was corrupted
1582
+ return (bitlen % 8) === 0;
1583
+ }
1584
+
1585
+ function constructYamlBinary(data) {
1586
+ var idx, tailbits,
1587
+ input = data.replace(/[\r\n=]/g, ''), // remove CR/LF & padding to simplify scan
1588
+ max = input.length,
1589
+ map = BASE64_MAP,
1590
+ bits = 0,
1591
+ result = [];
1592
+
1593
+ // Collect by 6*4 bits (3 bytes)
1594
+
1595
+ for (idx = 0; idx < max; idx++) {
1596
+ if ((idx % 4 === 0) && idx) {
1597
+ result.push((bits >> 16) & 0xFF);
1598
+ result.push((bits >> 8) & 0xFF);
1599
+ result.push(bits & 0xFF);
1600
+ }
1601
+
1602
+ bits = (bits << 6) | map.indexOf(input.charAt(idx));
1603
+ }
1604
+
1605
+ // Dump tail
1606
+
1607
+ tailbits = (max % 4) * 6;
1608
+
1609
+ if (tailbits === 0) {
1610
+ result.push((bits >> 16) & 0xFF);
1611
+ result.push((bits >> 8) & 0xFF);
1612
+ result.push(bits & 0xFF);
1613
+ } else if (tailbits === 18) {
1614
+ result.push((bits >> 10) & 0xFF);
1615
+ result.push((bits >> 2) & 0xFF);
1616
+ } else if (tailbits === 12) {
1617
+ result.push((bits >> 4) & 0xFF);
1618
+ }
1619
+
1620
+ return new Uint8Array(result);
1621
+ }
1622
+
1623
+ function representYamlBinary(object /*, style*/) {
1624
+ var result = '', bits = 0, idx, tail,
1625
+ max = object.length,
1626
+ map = BASE64_MAP;
1627
+
1628
+ // Convert every three bytes to 4 ASCII characters.
1629
+
1630
+ for (idx = 0; idx < max; idx++) {
1631
+ if ((idx % 3 === 0) && idx) {
1632
+ result += map[(bits >> 18) & 0x3F];
1633
+ result += map[(bits >> 12) & 0x3F];
1634
+ result += map[(bits >> 6) & 0x3F];
1635
+ result += map[bits & 0x3F];
1636
+ }
1637
+
1638
+ bits = (bits << 8) + object[idx];
1639
+ }
1640
+
1641
+ // Dump tail
1642
+
1643
+ tail = max % 3;
1644
+
1645
+ if (tail === 0) {
1646
+ result += map[(bits >> 18) & 0x3F];
1647
+ result += map[(bits >> 12) & 0x3F];
1648
+ result += map[(bits >> 6) & 0x3F];
1649
+ result += map[bits & 0x3F];
1650
+ } else if (tail === 2) {
1651
+ result += map[(bits >> 10) & 0x3F];
1652
+ result += map[(bits >> 4) & 0x3F];
1653
+ result += map[(bits << 2) & 0x3F];
1654
+ result += map[64];
1655
+ } else if (tail === 1) {
1656
+ result += map[(bits >> 2) & 0x3F];
1657
+ result += map[(bits << 4) & 0x3F];
1658
+ result += map[64];
1659
+ result += map[64];
1660
+ }
1661
+
1662
+ return result;
1663
+ }
1664
+
1665
+ function isBinary(obj) {
1666
+ return Object.prototype.toString.call(obj) === '[object Uint8Array]';
1667
+ }
1668
+
1669
+ var binary = new type('tag:yaml.org,2002:binary', {
1670
+ kind: 'scalar',
1671
+ resolve: resolveYamlBinary,
1672
+ construct: constructYamlBinary,
1673
+ predicate: isBinary,
1674
+ represent: representYamlBinary
1675
+ });
1676
+
1677
+ var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
1678
+ var _toString$2 = Object.prototype.toString;
1679
+
1680
+ function resolveYamlOmap(data) {
1681
+ if (data === null) return true;
1682
+
1683
+ var objectKeys = [], index, length, pair, pairKey, pairHasKey,
1684
+ object = data;
1685
+
1686
+ for (index = 0, length = object.length; index < length; index += 1) {
1687
+ pair = object[index];
1688
+ pairHasKey = false;
1689
+
1690
+ if (_toString$2.call(pair) !== '[object Object]') return false;
1691
+
1692
+ for (pairKey in pair) {
1693
+ if (_hasOwnProperty$3.call(pair, pairKey)) {
1694
+ if (!pairHasKey) pairHasKey = true;
1695
+ else return false;
1696
+ }
1697
+ }
1698
+
1699
+ if (!pairHasKey) return false;
1700
+
1701
+ if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
1702
+ else return false;
1703
+ }
1704
+
1705
+ return true;
1706
+ }
1707
+
1708
+ function constructYamlOmap(data) {
1709
+ return data !== null ? data : [];
1710
+ }
1711
+
1712
+ var omap = new type('tag:yaml.org,2002:omap', {
1713
+ kind: 'sequence',
1714
+ resolve: resolveYamlOmap,
1715
+ construct: constructYamlOmap
1716
+ });
1717
+
1718
+ var _toString$1 = Object.prototype.toString;
1719
+
1720
+ function resolveYamlPairs(data) {
1721
+ if (data === null) return true;
1722
+
1723
+ var index, length, pair, keys, result,
1724
+ object = data;
1725
+
1726
+ result = new Array(object.length);
1727
+
1728
+ for (index = 0, length = object.length; index < length; index += 1) {
1729
+ pair = object[index];
1730
+
1731
+ if (_toString$1.call(pair) !== '[object Object]') return false;
1732
+
1733
+ keys = Object.keys(pair);
1734
+
1735
+ if (keys.length !== 1) return false;
1736
+
1737
+ result[index] = [ keys[0], pair[keys[0]] ];
1738
+ }
1739
+
1740
+ return true;
1741
+ }
1742
+
1743
+ function constructYamlPairs(data) {
1744
+ if (data === null) return [];
1745
+
1746
+ var index, length, pair, keys, result,
1747
+ object = data;
1748
+
1749
+ result = new Array(object.length);
1750
+
1751
+ for (index = 0, length = object.length; index < length; index += 1) {
1752
+ pair = object[index];
1753
+
1754
+ keys = Object.keys(pair);
1755
+
1756
+ result[index] = [ keys[0], pair[keys[0]] ];
1757
+ }
1758
+
1759
+ return result;
1760
+ }
1761
+
1762
+ var pairs = new type('tag:yaml.org,2002:pairs', {
1763
+ kind: 'sequence',
1764
+ resolve: resolveYamlPairs,
1765
+ construct: constructYamlPairs
1766
+ });
1767
+
1768
+ var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
1769
+
1770
+ function resolveYamlSet(data) {
1771
+ if (data === null) return true;
1772
+
1773
+ var key, object = data;
1774
+
1775
+ for (key in object) {
1776
+ if (_hasOwnProperty$2.call(object, key)) {
1777
+ if (object[key] !== null) return false;
1778
+ }
1779
+ }
1780
+
1781
+ return true;
1782
+ }
1783
+
1784
+ function constructYamlSet(data) {
1785
+ return data !== null ? data : {};
1786
+ }
1787
+
1788
+ var set = new type('tag:yaml.org,2002:set', {
1789
+ kind: 'mapping',
1790
+ resolve: resolveYamlSet,
1791
+ construct: constructYamlSet
1792
+ });
1793
+
1794
+ var _default = core.extend({
1795
+ implicit: [
1796
+ timestamp,
1797
+ merge
1798
+ ],
1799
+ explicit: [
1800
+ binary,
1801
+ omap,
1802
+ pairs,
1803
+ set
1804
+ ]
1805
+ });
1806
+
1807
+ /*eslint-disable max-len,no-use-before-define*/
1808
+
1809
+
1810
+
1811
+
1812
+
1813
+
1814
+
1815
+ var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
1816
+
1817
+
1818
+ var CONTEXT_FLOW_IN = 1;
1819
+ var CONTEXT_FLOW_OUT = 2;
1820
+ var CONTEXT_BLOCK_IN = 3;
1821
+ var CONTEXT_BLOCK_OUT = 4;
1822
+
1823
+
1824
+ var CHOMPING_CLIP = 1;
1825
+ var CHOMPING_STRIP = 2;
1826
+ var CHOMPING_KEEP = 3;
1827
+
1828
+
1829
+ var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
1830
+ var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
1831
+ var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
1832
+ var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
1833
+ var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
1834
+
1835
+
1836
+ function _class(obj) { return Object.prototype.toString.call(obj); }
1837
+
1838
+ function is_EOL(c) {
1839
+ return (c === 0x0A/* LF */) || (c === 0x0D/* CR */);
1840
+ }
1841
+
1842
+ function is_WHITE_SPACE(c) {
1843
+ return (c === 0x09/* Tab */) || (c === 0x20/* Space */);
1844
+ }
1845
+
1846
+ function is_WS_OR_EOL(c) {
1847
+ return (c === 0x09/* Tab */) ||
1848
+ (c === 0x20/* Space */) ||
1849
+ (c === 0x0A/* LF */) ||
1850
+ (c === 0x0D/* CR */);
1851
+ }
1852
+
1853
+ function is_FLOW_INDICATOR(c) {
1854
+ return c === 0x2C/* , */ ||
1855
+ c === 0x5B/* [ */ ||
1856
+ c === 0x5D/* ] */ ||
1857
+ c === 0x7B/* { */ ||
1858
+ c === 0x7D/* } */;
1859
+ }
1860
+
1861
+ function fromHexCode(c) {
1862
+ var lc;
1863
+
1864
+ if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
1865
+ return c - 0x30;
1866
+ }
1867
+
1868
+ /*eslint-disable no-bitwise*/
1869
+ lc = c | 0x20;
1870
+
1871
+ if ((0x61/* a */ <= lc) && (lc <= 0x66/* f */)) {
1872
+ return lc - 0x61 + 10;
1873
+ }
1874
+
1875
+ return -1;
1876
+ }
1877
+
1878
+ function escapedHexLen(c) {
1879
+ if (c === 0x78/* x */) { return 2; }
1880
+ if (c === 0x75/* u */) { return 4; }
1881
+ if (c === 0x55/* U */) { return 8; }
1882
+ return 0;
1883
+ }
1884
+
1885
+ function fromDecimalCode(c) {
1886
+ if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
1887
+ return c - 0x30;
1888
+ }
1889
+
1890
+ return -1;
1891
+ }
1892
+
1893
+ function simpleEscapeSequence(c) {
1894
+ /* eslint-disable indent */
1895
+ return (c === 0x30/* 0 */) ? '\x00' :
1896
+ (c === 0x61/* a */) ? '\x07' :
1897
+ (c === 0x62/* b */) ? '\x08' :
1898
+ (c === 0x74/* t */) ? '\x09' :
1899
+ (c === 0x09/* Tab */) ? '\x09' :
1900
+ (c === 0x6E/* n */) ? '\x0A' :
1901
+ (c === 0x76/* v */) ? '\x0B' :
1902
+ (c === 0x66/* f */) ? '\x0C' :
1903
+ (c === 0x72/* r */) ? '\x0D' :
1904
+ (c === 0x65/* e */) ? '\x1B' :
1905
+ (c === 0x20/* Space */) ? ' ' :
1906
+ (c === 0x22/* " */) ? '\x22' :
1907
+ (c === 0x2F/* / */) ? '/' :
1908
+ (c === 0x5C/* \ */) ? '\x5C' :
1909
+ (c === 0x4E/* N */) ? '\x85' :
1910
+ (c === 0x5F/* _ */) ? '\xA0' :
1911
+ (c === 0x4C/* L */) ? '\u2028' :
1912
+ (c === 0x50/* P */) ? '\u2029' : '';
1913
+ }
1914
+
1915
+ function charFromCodepoint(c) {
1916
+ if (c <= 0xFFFF) {
1917
+ return String.fromCharCode(c);
1918
+ }
1919
+ // Encode UTF-16 surrogate pair
1920
+ // https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
1921
+ return String.fromCharCode(
1922
+ ((c - 0x010000) >> 10) + 0xD800,
1923
+ ((c - 0x010000) & 0x03FF) + 0xDC00
1924
+ );
1925
+ }
1926
+
1927
+ var simpleEscapeCheck = new Array(256); // integer, for fast access
1928
+ var simpleEscapeMap = new Array(256);
1929
+ for (var i = 0; i < 256; i++) {
1930
+ simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
1931
+ simpleEscapeMap[i] = simpleEscapeSequence(i);
1932
+ }
1933
+
1934
+
1935
+ function State$1(input, options) {
1936
+ this.input = input;
1937
+
1938
+ this.filename = options['filename'] || null;
1939
+ this.schema = options['schema'] || _default;
1940
+ this.onWarning = options['onWarning'] || null;
1941
+ // (Hidden) Remove? makes the loader to expect YAML 1.1 documents
1942
+ // if such documents have no explicit %YAML directive
1943
+ this.legacy = options['legacy'] || false;
1944
+
1945
+ this.json = options['json'] || false;
1946
+ this.listener = options['listener'] || null;
1947
+
1948
+ this.implicitTypes = this.schema.compiledImplicit;
1949
+ this.typeMap = this.schema.compiledTypeMap;
1950
+
1951
+ this.length = input.length;
1952
+ this.position = 0;
1953
+ this.line = 0;
1954
+ this.lineStart = 0;
1955
+ this.lineIndent = 0;
1956
+
1957
+ // position of first leading tab in the current line,
1958
+ // used to make sure there are no tabs in the indentation
1959
+ this.firstTabInLine = -1;
1960
+
1961
+ this.documents = [];
1962
+
1963
+ /*
1964
+ this.version;
1965
+ this.checkLineBreaks;
1966
+ this.tagMap;
1967
+ this.anchorMap;
1968
+ this.tag;
1969
+ this.anchor;
1970
+ this.kind;
1971
+ this.result;*/
1972
+
1973
+ }
1974
+
1975
+
1976
+ function generateError(state, message) {
1977
+ var mark = {
1978
+ name: state.filename,
1979
+ buffer: state.input.slice(0, -1), // omit trailing \0
1980
+ position: state.position,
1981
+ line: state.line,
1982
+ column: state.position - state.lineStart
1983
+ };
1984
+
1985
+ mark.snippet = snippet(mark);
1986
+
1987
+ return new exception(message, mark);
1988
+ }
1989
+
1990
+ function throwError(state, message) {
1991
+ throw generateError(state, message);
1992
+ }
1993
+
1994
+ function throwWarning(state, message) {
1995
+ if (state.onWarning) {
1996
+ state.onWarning.call(null, generateError(state, message));
1997
+ }
1998
+ }
1999
+
2000
+
2001
+ var directiveHandlers = {
2002
+
2003
+ YAML: function handleYamlDirective(state, name, args) {
2004
+
2005
+ var match, major, minor;
2006
+
2007
+ if (state.version !== null) {
2008
+ throwError(state, 'duplication of %YAML directive');
2009
+ }
2010
+
2011
+ if (args.length !== 1) {
2012
+ throwError(state, 'YAML directive accepts exactly one argument');
2013
+ }
2014
+
2015
+ match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
2016
+
2017
+ if (match === null) {
2018
+ throwError(state, 'ill-formed argument of the YAML directive');
2019
+ }
2020
+
2021
+ major = parseInt(match[1], 10);
2022
+ minor = parseInt(match[2], 10);
2023
+
2024
+ if (major !== 1) {
2025
+ throwError(state, 'unacceptable YAML version of the document');
2026
+ }
2027
+
2028
+ state.version = args[0];
2029
+ state.checkLineBreaks = (minor < 2);
2030
+
2031
+ if (minor !== 1 && minor !== 2) {
2032
+ throwWarning(state, 'unsupported YAML version of the document');
2033
+ }
2034
+ },
2035
+
2036
+ TAG: function handleTagDirective(state, name, args) {
2037
+
2038
+ var handle, prefix;
2039
+
2040
+ if (args.length !== 2) {
2041
+ throwError(state, 'TAG directive accepts exactly two arguments');
2042
+ }
2043
+
2044
+ handle = args[0];
2045
+ prefix = args[1];
2046
+
2047
+ if (!PATTERN_TAG_HANDLE.test(handle)) {
2048
+ throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
2049
+ }
2050
+
2051
+ if (_hasOwnProperty$1.call(state.tagMap, handle)) {
2052
+ throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
2053
+ }
2054
+
2055
+ if (!PATTERN_TAG_URI.test(prefix)) {
2056
+ throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
2057
+ }
2058
+
2059
+ try {
2060
+ prefix = decodeURIComponent(prefix);
2061
+ } catch (err) {
2062
+ throwError(state, 'tag prefix is malformed: ' + prefix);
2063
+ }
2064
+
2065
+ state.tagMap[handle] = prefix;
2066
+ }
2067
+ };
2068
+
2069
+
2070
+ function captureSegment(state, start, end, checkJson) {
2071
+ var _position, _length, _character, _result;
2072
+
2073
+ if (start < end) {
2074
+ _result = state.input.slice(start, end);
2075
+
2076
+ if (checkJson) {
2077
+ for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
2078
+ _character = _result.charCodeAt(_position);
2079
+ if (!(_character === 0x09 ||
2080
+ (0x20 <= _character && _character <= 0x10FFFF))) {
2081
+ throwError(state, 'expected valid JSON character');
2082
+ }
2083
+ }
2084
+ } else if (PATTERN_NON_PRINTABLE.test(_result)) {
2085
+ throwError(state, 'the stream contains non-printable characters');
2086
+ }
2087
+
2088
+ state.result += _result;
2089
+ }
2090
+ }
2091
+
2092
+ function mergeMappings(state, destination, source, overridableKeys) {
2093
+ var sourceKeys, key, index, quantity;
2094
+
2095
+ if (!common.isObject(source)) {
2096
+ throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
2097
+ }
2098
+
2099
+ sourceKeys = Object.keys(source);
2100
+
2101
+ for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
2102
+ key = sourceKeys[index];
2103
+
2104
+ if (!_hasOwnProperty$1.call(destination, key)) {
2105
+ destination[key] = source[key];
2106
+ overridableKeys[key] = true;
2107
+ }
2108
+ }
2109
+ }
2110
+
2111
+ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode,
2112
+ startLine, startLineStart, startPos) {
2113
+
2114
+ var index, quantity;
2115
+
2116
+ // The output is a plain object here, so keys can only be strings.
2117
+ // We need to convert keyNode to a string, but doing so can hang the process
2118
+ // (deeply nested arrays that explode exponentially using aliases).
2119
+ if (Array.isArray(keyNode)) {
2120
+ keyNode = Array.prototype.slice.call(keyNode);
2121
+
2122
+ for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
2123
+ if (Array.isArray(keyNode[index])) {
2124
+ throwError(state, 'nested arrays are not supported inside keys');
2125
+ }
2126
+
2127
+ if (typeof keyNode === 'object' && _class(keyNode[index]) === '[object Object]') {
2128
+ keyNode[index] = '[object Object]';
2129
+ }
2130
+ }
2131
+ }
2132
+
2133
+ // Avoid code execution in load() via toString property
2134
+ // (still use its own toString for arrays, timestamps,
2135
+ // and whatever user schema extensions happen to have @@toStringTag)
2136
+ if (typeof keyNode === 'object' && _class(keyNode) === '[object Object]') {
2137
+ keyNode = '[object Object]';
2138
+ }
2139
+
2140
+
2141
+ keyNode = String(keyNode);
2142
+
2143
+ if (_result === null) {
2144
+ _result = {};
2145
+ }
2146
+
2147
+ if (keyTag === 'tag:yaml.org,2002:merge') {
2148
+ if (Array.isArray(valueNode)) {
2149
+ for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
2150
+ mergeMappings(state, _result, valueNode[index], overridableKeys);
2151
+ }
2152
+ } else {
2153
+ mergeMappings(state, _result, valueNode, overridableKeys);
2154
+ }
2155
+ } else {
2156
+ if (!state.json &&
2157
+ !_hasOwnProperty$1.call(overridableKeys, keyNode) &&
2158
+ _hasOwnProperty$1.call(_result, keyNode)) {
2159
+ state.line = startLine || state.line;
2160
+ state.lineStart = startLineStart || state.lineStart;
2161
+ state.position = startPos || state.position;
2162
+ throwError(state, 'duplicated mapping key');
2163
+ }
2164
+
2165
+ // used for this specific key only because Object.defineProperty is slow
2166
+ if (keyNode === '__proto__') {
2167
+ Object.defineProperty(_result, keyNode, {
2168
+ configurable: true,
2169
+ enumerable: true,
2170
+ writable: true,
2171
+ value: valueNode
2172
+ });
2173
+ } else {
2174
+ _result[keyNode] = valueNode;
2175
+ }
2176
+ delete overridableKeys[keyNode];
2177
+ }
2178
+
2179
+ return _result;
2180
+ }
2181
+
2182
+ function readLineBreak(state) {
2183
+ var ch;
2184
+
2185
+ ch = state.input.charCodeAt(state.position);
2186
+
2187
+ if (ch === 0x0A/* LF */) {
2188
+ state.position++;
2189
+ } else if (ch === 0x0D/* CR */) {
2190
+ state.position++;
2191
+ if (state.input.charCodeAt(state.position) === 0x0A/* LF */) {
2192
+ state.position++;
2193
+ }
2194
+ } else {
2195
+ throwError(state, 'a line break is expected');
2196
+ }
2197
+
2198
+ state.line += 1;
2199
+ state.lineStart = state.position;
2200
+ state.firstTabInLine = -1;
2201
+ }
2202
+
2203
+ function skipSeparationSpace(state, allowComments, checkIndent) {
2204
+ var lineBreaks = 0,
2205
+ ch = state.input.charCodeAt(state.position);
2206
+
2207
+ while (ch !== 0) {
2208
+ while (is_WHITE_SPACE(ch)) {
2209
+ if (ch === 0x09/* Tab */ && state.firstTabInLine === -1) {
2210
+ state.firstTabInLine = state.position;
2211
+ }
2212
+ ch = state.input.charCodeAt(++state.position);
2213
+ }
2214
+
2215
+ if (allowComments && ch === 0x23/* # */) {
2216
+ do {
2217
+ ch = state.input.charCodeAt(++state.position);
2218
+ } while (ch !== 0x0A/* LF */ && ch !== 0x0D/* CR */ && ch !== 0);
2219
+ }
2220
+
2221
+ if (is_EOL(ch)) {
2222
+ readLineBreak(state);
2223
+
2224
+ ch = state.input.charCodeAt(state.position);
2225
+ lineBreaks++;
2226
+ state.lineIndent = 0;
2227
+
2228
+ while (ch === 0x20/* Space */) {
2229
+ state.lineIndent++;
2230
+ ch = state.input.charCodeAt(++state.position);
2231
+ }
2232
+ } else {
2233
+ break;
2234
+ }
2235
+ }
2236
+
2237
+ if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
2238
+ throwWarning(state, 'deficient indentation');
2239
+ }
2240
+
2241
+ return lineBreaks;
2242
+ }
2243
+
2244
+ function testDocumentSeparator(state) {
2245
+ var _position = state.position,
2246
+ ch;
2247
+
2248
+ ch = state.input.charCodeAt(_position);
2249
+
2250
+ // Condition state.position === state.lineStart is tested
2251
+ // in parent on each call, for efficiency. No needs to test here again.
2252
+ if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) &&
2253
+ ch === state.input.charCodeAt(_position + 1) &&
2254
+ ch === state.input.charCodeAt(_position + 2)) {
2255
+
2256
+ _position += 3;
2257
+
2258
+ ch = state.input.charCodeAt(_position);
2259
+
2260
+ if (ch === 0 || is_WS_OR_EOL(ch)) {
2261
+ return true;
2262
+ }
2263
+ }
2264
+
2265
+ return false;
2266
+ }
2267
+
2268
+ function writeFoldedLines(state, count) {
2269
+ if (count === 1) {
2270
+ state.result += ' ';
2271
+ } else if (count > 1) {
2272
+ state.result += common.repeat('\n', count - 1);
2273
+ }
2274
+ }
2275
+
2276
+
2277
+ function readPlainScalar(state, nodeIndent, withinFlowCollection) {
2278
+ var preceding,
2279
+ following,
2280
+ captureStart,
2281
+ captureEnd,
2282
+ hasPendingContent,
2283
+ _line,
2284
+ _lineStart,
2285
+ _lineIndent,
2286
+ _kind = state.kind,
2287
+ _result = state.result,
2288
+ ch;
2289
+
2290
+ ch = state.input.charCodeAt(state.position);
2291
+
2292
+ if (is_WS_OR_EOL(ch) ||
2293
+ is_FLOW_INDICATOR(ch) ||
2294
+ ch === 0x23/* # */ ||
2295
+ ch === 0x26/* & */ ||
2296
+ ch === 0x2A/* * */ ||
2297
+ ch === 0x21/* ! */ ||
2298
+ ch === 0x7C/* | */ ||
2299
+ ch === 0x3E/* > */ ||
2300
+ ch === 0x27/* ' */ ||
2301
+ ch === 0x22/* " */ ||
2302
+ ch === 0x25/* % */ ||
2303
+ ch === 0x40/* @ */ ||
2304
+ ch === 0x60/* ` */) {
2305
+ return false;
2306
+ }
2307
+
2308
+ if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) {
2309
+ following = state.input.charCodeAt(state.position + 1);
2310
+
2311
+ if (is_WS_OR_EOL(following) ||
2312
+ withinFlowCollection && is_FLOW_INDICATOR(following)) {
2313
+ return false;
2314
+ }
2315
+ }
2316
+
2317
+ state.kind = 'scalar';
2318
+ state.result = '';
2319
+ captureStart = captureEnd = state.position;
2320
+ hasPendingContent = false;
2321
+
2322
+ while (ch !== 0) {
2323
+ if (ch === 0x3A/* : */) {
2324
+ following = state.input.charCodeAt(state.position + 1);
2325
+
2326
+ if (is_WS_OR_EOL(following) ||
2327
+ withinFlowCollection && is_FLOW_INDICATOR(following)) {
2328
+ break;
2329
+ }
2330
+
2331
+ } else if (ch === 0x23/* # */) {
2332
+ preceding = state.input.charCodeAt(state.position - 1);
2333
+
2334
+ if (is_WS_OR_EOL(preceding)) {
2335
+ break;
2336
+ }
2337
+
2338
+ } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
2339
+ withinFlowCollection && is_FLOW_INDICATOR(ch)) {
2340
+ break;
2341
+
2342
+ } else if (is_EOL(ch)) {
2343
+ _line = state.line;
2344
+ _lineStart = state.lineStart;
2345
+ _lineIndent = state.lineIndent;
2346
+ skipSeparationSpace(state, false, -1);
2347
+
2348
+ if (state.lineIndent >= nodeIndent) {
2349
+ hasPendingContent = true;
2350
+ ch = state.input.charCodeAt(state.position);
2351
+ continue;
2352
+ } else {
2353
+ state.position = captureEnd;
2354
+ state.line = _line;
2355
+ state.lineStart = _lineStart;
2356
+ state.lineIndent = _lineIndent;
2357
+ break;
2358
+ }
2359
+ }
2360
+
2361
+ if (hasPendingContent) {
2362
+ captureSegment(state, captureStart, captureEnd, false);
2363
+ writeFoldedLines(state, state.line - _line);
2364
+ captureStart = captureEnd = state.position;
2365
+ hasPendingContent = false;
2366
+ }
2367
+
2368
+ if (!is_WHITE_SPACE(ch)) {
2369
+ captureEnd = state.position + 1;
2370
+ }
2371
+
2372
+ ch = state.input.charCodeAt(++state.position);
2373
+ }
2374
+
2375
+ captureSegment(state, captureStart, captureEnd, false);
2376
+
2377
+ if (state.result) {
2378
+ return true;
2379
+ }
2380
+
2381
+ state.kind = _kind;
2382
+ state.result = _result;
2383
+ return false;
2384
+ }
2385
+
2386
+ function readSingleQuotedScalar(state, nodeIndent) {
2387
+ var ch,
2388
+ captureStart, captureEnd;
2389
+
2390
+ ch = state.input.charCodeAt(state.position);
2391
+
2392
+ if (ch !== 0x27/* ' */) {
2393
+ return false;
2394
+ }
2395
+
2396
+ state.kind = 'scalar';
2397
+ state.result = '';
2398
+ state.position++;
2399
+ captureStart = captureEnd = state.position;
2400
+
2401
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
2402
+ if (ch === 0x27/* ' */) {
2403
+ captureSegment(state, captureStart, state.position, true);
2404
+ ch = state.input.charCodeAt(++state.position);
2405
+
2406
+ if (ch === 0x27/* ' */) {
2407
+ captureStart = state.position;
2408
+ state.position++;
2409
+ captureEnd = state.position;
2410
+ } else {
2411
+ return true;
2412
+ }
2413
+
2414
+ } else if (is_EOL(ch)) {
2415
+ captureSegment(state, captureStart, captureEnd, true);
2416
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
2417
+ captureStart = captureEnd = state.position;
2418
+
2419
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
2420
+ throwError(state, 'unexpected end of the document within a single quoted scalar');
2421
+
2422
+ } else {
2423
+ state.position++;
2424
+ captureEnd = state.position;
2425
+ }
2426
+ }
2427
+
2428
+ throwError(state, 'unexpected end of the stream within a single quoted scalar');
2429
+ }
2430
+
2431
+ function readDoubleQuotedScalar(state, nodeIndent) {
2432
+ var captureStart,
2433
+ captureEnd,
2434
+ hexLength,
2435
+ hexResult,
2436
+ tmp,
2437
+ ch;
2438
+
2439
+ ch = state.input.charCodeAt(state.position);
2440
+
2441
+ if (ch !== 0x22/* " */) {
2442
+ return false;
2443
+ }
2444
+
2445
+ state.kind = 'scalar';
2446
+ state.result = '';
2447
+ state.position++;
2448
+ captureStart = captureEnd = state.position;
2449
+
2450
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
2451
+ if (ch === 0x22/* " */) {
2452
+ captureSegment(state, captureStart, state.position, true);
2453
+ state.position++;
2454
+ return true;
2455
+
2456
+ } else if (ch === 0x5C/* \ */) {
2457
+ captureSegment(state, captureStart, state.position, true);
2458
+ ch = state.input.charCodeAt(++state.position);
2459
+
2460
+ if (is_EOL(ch)) {
2461
+ skipSeparationSpace(state, false, nodeIndent);
2462
+
2463
+ // TODO: rework to inline fn with no type cast?
2464
+ } else if (ch < 256 && simpleEscapeCheck[ch]) {
2465
+ state.result += simpleEscapeMap[ch];
2466
+ state.position++;
2467
+
2468
+ } else if ((tmp = escapedHexLen(ch)) > 0) {
2469
+ hexLength = tmp;
2470
+ hexResult = 0;
2471
+
2472
+ for (; hexLength > 0; hexLength--) {
2473
+ ch = state.input.charCodeAt(++state.position);
2474
+
2475
+ if ((tmp = fromHexCode(ch)) >= 0) {
2476
+ hexResult = (hexResult << 4) + tmp;
2477
+
2478
+ } else {
2479
+ throwError(state, 'expected hexadecimal character');
2480
+ }
2481
+ }
2482
+
2483
+ state.result += charFromCodepoint(hexResult);
2484
+
2485
+ state.position++;
2486
+
2487
+ } else {
2488
+ throwError(state, 'unknown escape sequence');
2489
+ }
2490
+
2491
+ captureStart = captureEnd = state.position;
2492
+
2493
+ } else if (is_EOL(ch)) {
2494
+ captureSegment(state, captureStart, captureEnd, true);
2495
+ writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
2496
+ captureStart = captureEnd = state.position;
2497
+
2498
+ } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
2499
+ throwError(state, 'unexpected end of the document within a double quoted scalar');
2500
+
2501
+ } else {
2502
+ state.position++;
2503
+ captureEnd = state.position;
2504
+ }
2505
+ }
2506
+
2507
+ throwError(state, 'unexpected end of the stream within a double quoted scalar');
2508
+ }
2509
+
2510
+ function readFlowCollection(state, nodeIndent) {
2511
+ var readNext = true,
2512
+ _line,
2513
+ _lineStart,
2514
+ _pos,
2515
+ _tag = state.tag,
2516
+ _result,
2517
+ _anchor = state.anchor,
2518
+ following,
2519
+ terminator,
2520
+ isPair,
2521
+ isExplicitPair,
2522
+ isMapping,
2523
+ overridableKeys = Object.create(null),
2524
+ keyNode,
2525
+ keyTag,
2526
+ valueNode,
2527
+ ch;
2528
+
2529
+ ch = state.input.charCodeAt(state.position);
2530
+
2531
+ if (ch === 0x5B/* [ */) {
2532
+ terminator = 0x5D;/* ] */
2533
+ isMapping = false;
2534
+ _result = [];
2535
+ } else if (ch === 0x7B/* { */) {
2536
+ terminator = 0x7D;/* } */
2537
+ isMapping = true;
2538
+ _result = {};
2539
+ } else {
2540
+ return false;
2541
+ }
2542
+
2543
+ if (state.anchor !== null) {
2544
+ state.anchorMap[state.anchor] = _result;
2545
+ }
2546
+
2547
+ ch = state.input.charCodeAt(++state.position);
2548
+
2549
+ while (ch !== 0) {
2550
+ skipSeparationSpace(state, true, nodeIndent);
2551
+
2552
+ ch = state.input.charCodeAt(state.position);
2553
+
2554
+ if (ch === terminator) {
2555
+ state.position++;
2556
+ state.tag = _tag;
2557
+ state.anchor = _anchor;
2558
+ state.kind = isMapping ? 'mapping' : 'sequence';
2559
+ state.result = _result;
2560
+ return true;
2561
+ } else if (!readNext) {
2562
+ throwError(state, 'missed comma between flow collection entries');
2563
+ } else if (ch === 0x2C/* , */) {
2564
+ // "flow collection entries can never be completely empty", as per YAML 1.2, section 7.4
2565
+ throwError(state, "expected the node content, but found ','");
2566
+ }
2567
+
2568
+ keyTag = keyNode = valueNode = null;
2569
+ isPair = isExplicitPair = false;
2570
+
2571
+ if (ch === 0x3F/* ? */) {
2572
+ following = state.input.charCodeAt(state.position + 1);
2573
+
2574
+ if (is_WS_OR_EOL(following)) {
2575
+ isPair = isExplicitPair = true;
2576
+ state.position++;
2577
+ skipSeparationSpace(state, true, nodeIndent);
2578
+ }
2579
+ }
2580
+
2581
+ _line = state.line; // Save the current line.
2582
+ _lineStart = state.lineStart;
2583
+ _pos = state.position;
2584
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
2585
+ keyTag = state.tag;
2586
+ keyNode = state.result;
2587
+ skipSeparationSpace(state, true, nodeIndent);
2588
+
2589
+ ch = state.input.charCodeAt(state.position);
2590
+
2591
+ if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {
2592
+ isPair = true;
2593
+ ch = state.input.charCodeAt(++state.position);
2594
+ skipSeparationSpace(state, true, nodeIndent);
2595
+ composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
2596
+ valueNode = state.result;
2597
+ }
2598
+
2599
+ if (isMapping) {
2600
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos);
2601
+ } else if (isPair) {
2602
+ _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode, _line, _lineStart, _pos));
2603
+ } else {
2604
+ _result.push(keyNode);
2605
+ }
2606
+
2607
+ skipSeparationSpace(state, true, nodeIndent);
2608
+
2609
+ ch = state.input.charCodeAt(state.position);
2610
+
2611
+ if (ch === 0x2C/* , */) {
2612
+ readNext = true;
2613
+ ch = state.input.charCodeAt(++state.position);
2614
+ } else {
2615
+ readNext = false;
2616
+ }
2617
+ }
2618
+
2619
+ throwError(state, 'unexpected end of the stream within a flow collection');
2620
+ }
2621
+
2622
+ function readBlockScalar(state, nodeIndent) {
2623
+ var captureStart,
2624
+ folding,
2625
+ chomping = CHOMPING_CLIP,
2626
+ didReadContent = false,
2627
+ detectedIndent = false,
2628
+ textIndent = nodeIndent,
2629
+ emptyLines = 0,
2630
+ atMoreIndented = false,
2631
+ tmp,
2632
+ ch;
2633
+
2634
+ ch = state.input.charCodeAt(state.position);
2635
+
2636
+ if (ch === 0x7C/* | */) {
2637
+ folding = false;
2638
+ } else if (ch === 0x3E/* > */) {
2639
+ folding = true;
2640
+ } else {
2641
+ return false;
2642
+ }
2643
+
2644
+ state.kind = 'scalar';
2645
+ state.result = '';
2646
+
2647
+ while (ch !== 0) {
2648
+ ch = state.input.charCodeAt(++state.position);
2649
+
2650
+ if (ch === 0x2B/* + */ || ch === 0x2D/* - */) {
2651
+ if (CHOMPING_CLIP === chomping) {
2652
+ chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP;
2653
+ } else {
2654
+ throwError(state, 'repeat of a chomping mode identifier');
2655
+ }
2656
+
2657
+ } else if ((tmp = fromDecimalCode(ch)) >= 0) {
2658
+ if (tmp === 0) {
2659
+ throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
2660
+ } else if (!detectedIndent) {
2661
+ textIndent = nodeIndent + tmp - 1;
2662
+ detectedIndent = true;
2663
+ } else {
2664
+ throwError(state, 'repeat of an indentation width identifier');
2665
+ }
2666
+
2667
+ } else {
2668
+ break;
2669
+ }
2670
+ }
2671
+
2672
+ if (is_WHITE_SPACE(ch)) {
2673
+ do { ch = state.input.charCodeAt(++state.position); }
2674
+ while (is_WHITE_SPACE(ch));
2675
+
2676
+ if (ch === 0x23/* # */) {
2677
+ do { ch = state.input.charCodeAt(++state.position); }
2678
+ while (!is_EOL(ch) && (ch !== 0));
2679
+ }
2680
+ }
2681
+
2682
+ while (ch !== 0) {
2683
+ readLineBreak(state);
2684
+ state.lineIndent = 0;
2685
+
2686
+ ch = state.input.charCodeAt(state.position);
2687
+
2688
+ while ((!detectedIndent || state.lineIndent < textIndent) &&
2689
+ (ch === 0x20/* Space */)) {
2690
+ state.lineIndent++;
2691
+ ch = state.input.charCodeAt(++state.position);
2692
+ }
2693
+
2694
+ if (!detectedIndent && state.lineIndent > textIndent) {
2695
+ textIndent = state.lineIndent;
2696
+ }
2697
+
2698
+ if (is_EOL(ch)) {
2699
+ emptyLines++;
2700
+ continue;
2701
+ }
2702
+
2703
+ // End of the scalar.
2704
+ if (state.lineIndent < textIndent) {
2705
+
2706
+ // Perform the chomping.
2707
+ if (chomping === CHOMPING_KEEP) {
2708
+ state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
2709
+ } else if (chomping === CHOMPING_CLIP) {
2710
+ if (didReadContent) { // i.e. only if the scalar is not empty.
2711
+ state.result += '\n';
2712
+ }
2713
+ }
2714
+
2715
+ // Break this `while` cycle and go to the funciton's epilogue.
2716
+ break;
2717
+ }
2718
+
2719
+ // Folded style: use fancy rules to handle line breaks.
2720
+ if (folding) {
2721
+
2722
+ // Lines starting with white space characters (more-indented lines) are not folded.
2723
+ if (is_WHITE_SPACE(ch)) {
2724
+ atMoreIndented = true;
2725
+ // except for the first content line (cf. Example 8.1)
2726
+ state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
2727
+
2728
+ // End of more-indented block.
2729
+ } else if (atMoreIndented) {
2730
+ atMoreIndented = false;
2731
+ state.result += common.repeat('\n', emptyLines + 1);
2732
+
2733
+ // Just one line break - perceive as the same line.
2734
+ } else if (emptyLines === 0) {
2735
+ if (didReadContent) { // i.e. only if we have already read some scalar content.
2736
+ state.result += ' ';
2737
+ }
2738
+
2739
+ // Several line breaks - perceive as different lines.
2740
+ } else {
2741
+ state.result += common.repeat('\n', emptyLines);
2742
+ }
2743
+
2744
+ // Literal style: just add exact number of line breaks between content lines.
2745
+ } else {
2746
+ // Keep all line breaks except the header line break.
2747
+ state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
2748
+ }
2749
+
2750
+ didReadContent = true;
2751
+ detectedIndent = true;
2752
+ emptyLines = 0;
2753
+ captureStart = state.position;
2754
+
2755
+ while (!is_EOL(ch) && (ch !== 0)) {
2756
+ ch = state.input.charCodeAt(++state.position);
2757
+ }
2758
+
2759
+ captureSegment(state, captureStart, state.position, false);
2760
+ }
2761
+
2762
+ return true;
2763
+ }
2764
+
2765
+ function readBlockSequence(state, nodeIndent) {
2766
+ var _line,
2767
+ _tag = state.tag,
2768
+ _anchor = state.anchor,
2769
+ _result = [],
2770
+ following,
2771
+ detected = false,
2772
+ ch;
2773
+
2774
+ // there is a leading tab before this token, so it can't be a block sequence/mapping;
2775
+ // it can still be flow sequence/mapping or a scalar
2776
+ if (state.firstTabInLine !== -1) return false;
2777
+
2778
+ if (state.anchor !== null) {
2779
+ state.anchorMap[state.anchor] = _result;
2780
+ }
2781
+
2782
+ ch = state.input.charCodeAt(state.position);
2783
+
2784
+ while (ch !== 0) {
2785
+ if (state.firstTabInLine !== -1) {
2786
+ state.position = state.firstTabInLine;
2787
+ throwError(state, 'tab characters must not be used in indentation');
2788
+ }
2789
+
2790
+ if (ch !== 0x2D/* - */) {
2791
+ break;
2792
+ }
2793
+
2794
+ following = state.input.charCodeAt(state.position + 1);
2795
+
2796
+ if (!is_WS_OR_EOL(following)) {
2797
+ break;
2798
+ }
2799
+
2800
+ detected = true;
2801
+ state.position++;
2802
+
2803
+ if (skipSeparationSpace(state, true, -1)) {
2804
+ if (state.lineIndent <= nodeIndent) {
2805
+ _result.push(null);
2806
+ ch = state.input.charCodeAt(state.position);
2807
+ continue;
2808
+ }
2809
+ }
2810
+
2811
+ _line = state.line;
2812
+ composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
2813
+ _result.push(state.result);
2814
+ skipSeparationSpace(state, true, -1);
2815
+
2816
+ ch = state.input.charCodeAt(state.position);
2817
+
2818
+ if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
2819
+ throwError(state, 'bad indentation of a sequence entry');
2820
+ } else if (state.lineIndent < nodeIndent) {
2821
+ break;
2822
+ }
2823
+ }
2824
+
2825
+ if (detected) {
2826
+ state.tag = _tag;
2827
+ state.anchor = _anchor;
2828
+ state.kind = 'sequence';
2829
+ state.result = _result;
2830
+ return true;
2831
+ }
2832
+ return false;
2833
+ }
2834
+
2835
+ function readBlockMapping(state, nodeIndent, flowIndent) {
2836
+ var following,
2837
+ allowCompact,
2838
+ _line,
2839
+ _keyLine,
2840
+ _keyLineStart,
2841
+ _keyPos,
2842
+ _tag = state.tag,
2843
+ _anchor = state.anchor,
2844
+ _result = {},
2845
+ overridableKeys = Object.create(null),
2846
+ keyTag = null,
2847
+ keyNode = null,
2848
+ valueNode = null,
2849
+ atExplicitKey = false,
2850
+ detected = false,
2851
+ ch;
2852
+
2853
+ // there is a leading tab before this token, so it can't be a block sequence/mapping;
2854
+ // it can still be flow sequence/mapping or a scalar
2855
+ if (state.firstTabInLine !== -1) return false;
2856
+
2857
+ if (state.anchor !== null) {
2858
+ state.anchorMap[state.anchor] = _result;
2859
+ }
2860
+
2861
+ ch = state.input.charCodeAt(state.position);
2862
+
2863
+ while (ch !== 0) {
2864
+ if (!atExplicitKey && state.firstTabInLine !== -1) {
2865
+ state.position = state.firstTabInLine;
2866
+ throwError(state, 'tab characters must not be used in indentation');
2867
+ }
2868
+
2869
+ following = state.input.charCodeAt(state.position + 1);
2870
+ _line = state.line; // Save the current line.
2871
+
2872
+ //
2873
+ // Explicit notation case. There are two separate blocks:
2874
+ // first for the key (denoted by "?") and second for the value (denoted by ":")
2875
+ //
2876
+ if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && is_WS_OR_EOL(following)) {
2877
+
2878
+ if (ch === 0x3F/* ? */) {
2879
+ if (atExplicitKey) {
2880
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
2881
+ keyTag = keyNode = valueNode = null;
2882
+ }
2883
+
2884
+ detected = true;
2885
+ atExplicitKey = true;
2886
+ allowCompact = true;
2887
+
2888
+ } else if (atExplicitKey) {
2889
+ // i.e. 0x3A/* : */ === character after the explicit key.
2890
+ atExplicitKey = false;
2891
+ allowCompact = true;
2892
+
2893
+ } else {
2894
+ throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line');
2895
+ }
2896
+
2897
+ state.position += 1;
2898
+ ch = following;
2899
+
2900
+ //
2901
+ // Implicit notation case. Flow-style node as the key first, then ":", and the value.
2902
+ //
2903
+ } else {
2904
+ _keyLine = state.line;
2905
+ _keyLineStart = state.lineStart;
2906
+ _keyPos = state.position;
2907
+
2908
+ if (!composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
2909
+ // Neither implicit nor explicit notation.
2910
+ // Reading is done. Go to the epilogue.
2911
+ break;
2912
+ }
2913
+
2914
+ if (state.line === _line) {
2915
+ ch = state.input.charCodeAt(state.position);
2916
+
2917
+ while (is_WHITE_SPACE(ch)) {
2918
+ ch = state.input.charCodeAt(++state.position);
2919
+ }
2920
+
2921
+ if (ch === 0x3A/* : */) {
2922
+ ch = state.input.charCodeAt(++state.position);
2923
+
2924
+ if (!is_WS_OR_EOL(ch)) {
2925
+ throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
2926
+ }
2927
+
2928
+ if (atExplicitKey) {
2929
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
2930
+ keyTag = keyNode = valueNode = null;
2931
+ }
2932
+
2933
+ detected = true;
2934
+ atExplicitKey = false;
2935
+ allowCompact = false;
2936
+ keyTag = state.tag;
2937
+ keyNode = state.result;
2938
+
2939
+ } else if (detected) {
2940
+ throwError(state, 'can not read an implicit mapping pair; a colon is missed');
2941
+
2942
+ } else {
2943
+ state.tag = _tag;
2944
+ state.anchor = _anchor;
2945
+ return true; // Keep the result of `composeNode`.
2946
+ }
2947
+
2948
+ } else if (detected) {
2949
+ throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
2950
+
2951
+ } else {
2952
+ state.tag = _tag;
2953
+ state.anchor = _anchor;
2954
+ return true; // Keep the result of `composeNode`.
2955
+ }
2956
+ }
2957
+
2958
+ //
2959
+ // Common reading code for both explicit and implicit notations.
2960
+ //
2961
+ if (state.line === _line || state.lineIndent > nodeIndent) {
2962
+ if (atExplicitKey) {
2963
+ _keyLine = state.line;
2964
+ _keyLineStart = state.lineStart;
2965
+ _keyPos = state.position;
2966
+ }
2967
+
2968
+ if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
2969
+ if (atExplicitKey) {
2970
+ keyNode = state.result;
2971
+ } else {
2972
+ valueNode = state.result;
2973
+ }
2974
+ }
2975
+
2976
+ if (!atExplicitKey) {
2977
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _keyLine, _keyLineStart, _keyPos);
2978
+ keyTag = keyNode = valueNode = null;
2979
+ }
2980
+
2981
+ skipSeparationSpace(state, true, -1);
2982
+ ch = state.input.charCodeAt(state.position);
2983
+ }
2984
+
2985
+ if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
2986
+ throwError(state, 'bad indentation of a mapping entry');
2987
+ } else if (state.lineIndent < nodeIndent) {
2988
+ break;
2989
+ }
2990
+ }
2991
+
2992
+ //
2993
+ // Epilogue.
2994
+ //
2995
+
2996
+ // Special case: last mapping's node contains only the key in explicit notation.
2997
+ if (atExplicitKey) {
2998
+ storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
2999
+ }
3000
+
3001
+ // Expose the resulting mapping.
3002
+ if (detected) {
3003
+ state.tag = _tag;
3004
+ state.anchor = _anchor;
3005
+ state.kind = 'mapping';
3006
+ state.result = _result;
3007
+ }
3008
+
3009
+ return detected;
3010
+ }
3011
+
3012
+ function readTagProperty(state) {
3013
+ var _position,
3014
+ isVerbatim = false,
3015
+ isNamed = false,
3016
+ tagHandle,
3017
+ tagName,
3018
+ ch;
3019
+
3020
+ ch = state.input.charCodeAt(state.position);
3021
+
3022
+ if (ch !== 0x21/* ! */) return false;
3023
+
3024
+ if (state.tag !== null) {
3025
+ throwError(state, 'duplication of a tag property');
3026
+ }
3027
+
3028
+ ch = state.input.charCodeAt(++state.position);
3029
+
3030
+ if (ch === 0x3C/* < */) {
3031
+ isVerbatim = true;
3032
+ ch = state.input.charCodeAt(++state.position);
3033
+
3034
+ } else if (ch === 0x21/* ! */) {
3035
+ isNamed = true;
3036
+ tagHandle = '!!';
3037
+ ch = state.input.charCodeAt(++state.position);
3038
+
3039
+ } else {
3040
+ tagHandle = '!';
3041
+ }
3042
+
3043
+ _position = state.position;
3044
+
3045
+ if (isVerbatim) {
3046
+ do { ch = state.input.charCodeAt(++state.position); }
3047
+ while (ch !== 0 && ch !== 0x3E/* > */);
3048
+
3049
+ if (state.position < state.length) {
3050
+ tagName = state.input.slice(_position, state.position);
3051
+ ch = state.input.charCodeAt(++state.position);
3052
+ } else {
3053
+ throwError(state, 'unexpected end of the stream within a verbatim tag');
3054
+ }
3055
+ } else {
3056
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
3057
+
3058
+ if (ch === 0x21/* ! */) {
3059
+ if (!isNamed) {
3060
+ tagHandle = state.input.slice(_position - 1, state.position + 1);
3061
+
3062
+ if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
3063
+ throwError(state, 'named tag handle cannot contain such characters');
3064
+ }
3065
+
3066
+ isNamed = true;
3067
+ _position = state.position + 1;
3068
+ } else {
3069
+ throwError(state, 'tag suffix cannot contain exclamation marks');
3070
+ }
3071
+ }
3072
+
3073
+ ch = state.input.charCodeAt(++state.position);
3074
+ }
3075
+
3076
+ tagName = state.input.slice(_position, state.position);
3077
+
3078
+ if (PATTERN_FLOW_INDICATORS.test(tagName)) {
3079
+ throwError(state, 'tag suffix cannot contain flow indicator characters');
3080
+ }
3081
+ }
3082
+
3083
+ if (tagName && !PATTERN_TAG_URI.test(tagName)) {
3084
+ throwError(state, 'tag name cannot contain such characters: ' + tagName);
3085
+ }
3086
+
3087
+ try {
3088
+ tagName = decodeURIComponent(tagName);
3089
+ } catch (err) {
3090
+ throwError(state, 'tag name is malformed: ' + tagName);
3091
+ }
3092
+
3093
+ if (isVerbatim) {
3094
+ state.tag = tagName;
3095
+
3096
+ } else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
3097
+ state.tag = state.tagMap[tagHandle] + tagName;
3098
+
3099
+ } else if (tagHandle === '!') {
3100
+ state.tag = '!' + tagName;
3101
+
3102
+ } else if (tagHandle === '!!') {
3103
+ state.tag = 'tag:yaml.org,2002:' + tagName;
3104
+
3105
+ } else {
3106
+ throwError(state, 'undeclared tag handle "' + tagHandle + '"');
3107
+ }
3108
+
3109
+ return true;
3110
+ }
3111
+
3112
+ function readAnchorProperty(state) {
3113
+ var _position,
3114
+ ch;
3115
+
3116
+ ch = state.input.charCodeAt(state.position);
3117
+
3118
+ if (ch !== 0x26/* & */) return false;
3119
+
3120
+ if (state.anchor !== null) {
3121
+ throwError(state, 'duplication of an anchor property');
3122
+ }
3123
+
3124
+ ch = state.input.charCodeAt(++state.position);
3125
+ _position = state.position;
3126
+
3127
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
3128
+ ch = state.input.charCodeAt(++state.position);
3129
+ }
3130
+
3131
+ if (state.position === _position) {
3132
+ throwError(state, 'name of an anchor node must contain at least one character');
3133
+ }
3134
+
3135
+ state.anchor = state.input.slice(_position, state.position);
3136
+ return true;
3137
+ }
3138
+
3139
+ function readAlias(state) {
3140
+ var _position, alias,
3141
+ ch;
3142
+
3143
+ ch = state.input.charCodeAt(state.position);
3144
+
3145
+ if (ch !== 0x2A/* * */) return false;
3146
+
3147
+ ch = state.input.charCodeAt(++state.position);
3148
+ _position = state.position;
3149
+
3150
+ while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
3151
+ ch = state.input.charCodeAt(++state.position);
3152
+ }
3153
+
3154
+ if (state.position === _position) {
3155
+ throwError(state, 'name of an alias node must contain at least one character');
3156
+ }
3157
+
3158
+ alias = state.input.slice(_position, state.position);
3159
+
3160
+ if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
3161
+ throwError(state, 'unidentified alias "' + alias + '"');
3162
+ }
3163
+
3164
+ state.result = state.anchorMap[alias];
3165
+ skipSeparationSpace(state, true, -1);
3166
+ return true;
3167
+ }
3168
+
3169
+ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
3170
+ var allowBlockStyles,
3171
+ allowBlockScalars,
3172
+ allowBlockCollections,
3173
+ indentStatus = 1, // 1: this>parent, 0: this=parent, -1: this<parent
3174
+ atNewLine = false,
3175
+ hasContent = false,
3176
+ typeIndex,
3177
+ typeQuantity,
3178
+ typeList,
3179
+ type,
3180
+ flowIndent,
3181
+ blockIndent;
3182
+
3183
+ if (state.listener !== null) {
3184
+ state.listener('open', state);
3185
+ }
3186
+
3187
+ state.tag = null;
3188
+ state.anchor = null;
3189
+ state.kind = null;
3190
+ state.result = null;
3191
+
3192
+ allowBlockStyles = allowBlockScalars = allowBlockCollections =
3193
+ CONTEXT_BLOCK_OUT === nodeContext ||
3194
+ CONTEXT_BLOCK_IN === nodeContext;
3195
+
3196
+ if (allowToSeek) {
3197
+ if (skipSeparationSpace(state, true, -1)) {
3198
+ atNewLine = true;
3199
+
3200
+ if (state.lineIndent > parentIndent) {
3201
+ indentStatus = 1;
3202
+ } else if (state.lineIndent === parentIndent) {
3203
+ indentStatus = 0;
3204
+ } else if (state.lineIndent < parentIndent) {
3205
+ indentStatus = -1;
3206
+ }
3207
+ }
3208
+ }
3209
+
3210
+ if (indentStatus === 1) {
3211
+ while (readTagProperty(state) || readAnchorProperty(state)) {
3212
+ if (skipSeparationSpace(state, true, -1)) {
3213
+ atNewLine = true;
3214
+ allowBlockCollections = allowBlockStyles;
3215
+
3216
+ if (state.lineIndent > parentIndent) {
3217
+ indentStatus = 1;
3218
+ } else if (state.lineIndent === parentIndent) {
3219
+ indentStatus = 0;
3220
+ } else if (state.lineIndent < parentIndent) {
3221
+ indentStatus = -1;
3222
+ }
3223
+ } else {
3224
+ allowBlockCollections = false;
3225
+ }
3226
+ }
3227
+ }
3228
+
3229
+ if (allowBlockCollections) {
3230
+ allowBlockCollections = atNewLine || allowCompact;
3231
+ }
3232
+
3233
+ if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
3234
+ if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
3235
+ flowIndent = parentIndent;
3236
+ } else {
3237
+ flowIndent = parentIndent + 1;
3238
+ }
3239
+
3240
+ blockIndent = state.position - state.lineStart;
3241
+
3242
+ if (indentStatus === 1) {
3243
+ if (allowBlockCollections &&
3244
+ (readBlockSequence(state, blockIndent) ||
3245
+ readBlockMapping(state, blockIndent, flowIndent)) ||
3246
+ readFlowCollection(state, flowIndent)) {
3247
+ hasContent = true;
3248
+ } else {
3249
+ if ((allowBlockScalars && readBlockScalar(state, flowIndent)) ||
3250
+ readSingleQuotedScalar(state, flowIndent) ||
3251
+ readDoubleQuotedScalar(state, flowIndent)) {
3252
+ hasContent = true;
3253
+
3254
+ } else if (readAlias(state)) {
3255
+ hasContent = true;
3256
+
3257
+ if (state.tag !== null || state.anchor !== null) {
3258
+ throwError(state, 'alias node should not have any properties');
3259
+ }
3260
+
3261
+ } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
3262
+ hasContent = true;
3263
+
3264
+ if (state.tag === null) {
3265
+ state.tag = '?';
3266
+ }
3267
+ }
3268
+
3269
+ if (state.anchor !== null) {
3270
+ state.anchorMap[state.anchor] = state.result;
3271
+ }
3272
+ }
3273
+ } else if (indentStatus === 0) {
3274
+ // Special case: block sequences are allowed to have same indentation level as the parent.
3275
+ // http://www.yaml.org/spec/1.2/spec.html#id2799784
3276
+ hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
3277
+ }
3278
+ }
3279
+
3280
+ if (state.tag === null) {
3281
+ if (state.anchor !== null) {
3282
+ state.anchorMap[state.anchor] = state.result;
3283
+ }
3284
+
3285
+ } else if (state.tag === '?') {
3286
+ // Implicit resolving is not allowed for non-scalar types, and '?'
3287
+ // non-specific tag is only automatically assigned to plain scalars.
3288
+ //
3289
+ // We only need to check kind conformity in case user explicitly assigns '?'
3290
+ // tag, for example like this: "!<?> [0]"
3291
+ //
3292
+ if (state.result !== null && state.kind !== 'scalar') {
3293
+ throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
3294
+ }
3295
+
3296
+ for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
3297
+ type = state.implicitTypes[typeIndex];
3298
+
3299
+ if (type.resolve(state.result)) { // `state.result` updated in resolver if matched
3300
+ state.result = type.construct(state.result);
3301
+ state.tag = type.tag;
3302
+ if (state.anchor !== null) {
3303
+ state.anchorMap[state.anchor] = state.result;
3304
+ }
3305
+ break;
3306
+ }
3307
+ }
3308
+ } else if (state.tag !== '!') {
3309
+ if (_hasOwnProperty$1.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
3310
+ type = state.typeMap[state.kind || 'fallback'][state.tag];
3311
+ } else {
3312
+ // looking for multi type
3313
+ type = null;
3314
+ typeList = state.typeMap.multi[state.kind || 'fallback'];
3315
+
3316
+ for (typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1) {
3317
+ if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
3318
+ type = typeList[typeIndex];
3319
+ break;
3320
+ }
3321
+ }
3322
+ }
3323
+
3324
+ if (!type) {
3325
+ throwError(state, 'unknown tag !<' + state.tag + '>');
3326
+ }
3327
+
3328
+ if (state.result !== null && type.kind !== state.kind) {
3329
+ throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
3330
+ }
3331
+
3332
+ if (!type.resolve(state.result, state.tag)) { // `state.result` updated in resolver if matched
3333
+ throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
3334
+ } else {
3335
+ state.result = type.construct(state.result, state.tag);
3336
+ if (state.anchor !== null) {
3337
+ state.anchorMap[state.anchor] = state.result;
3338
+ }
3339
+ }
3340
+ }
3341
+
3342
+ if (state.listener !== null) {
3343
+ state.listener('close', state);
3344
+ }
3345
+ return state.tag !== null || state.anchor !== null || hasContent;
3346
+ }
3347
+
3348
+ function readDocument(state) {
3349
+ var documentStart = state.position,
3350
+ _position,
3351
+ directiveName,
3352
+ directiveArgs,
3353
+ hasDirectives = false,
3354
+ ch;
3355
+
3356
+ state.version = null;
3357
+ state.checkLineBreaks = state.legacy;
3358
+ state.tagMap = Object.create(null);
3359
+ state.anchorMap = Object.create(null);
3360
+
3361
+ while ((ch = state.input.charCodeAt(state.position)) !== 0) {
3362
+ skipSeparationSpace(state, true, -1);
3363
+
3364
+ ch = state.input.charCodeAt(state.position);
3365
+
3366
+ if (state.lineIndent > 0 || ch !== 0x25/* % */) {
3367
+ break;
3368
+ }
3369
+
3370
+ hasDirectives = true;
3371
+ ch = state.input.charCodeAt(++state.position);
3372
+ _position = state.position;
3373
+
3374
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
3375
+ ch = state.input.charCodeAt(++state.position);
3376
+ }
3377
+
3378
+ directiveName = state.input.slice(_position, state.position);
3379
+ directiveArgs = [];
3380
+
3381
+ if (directiveName.length < 1) {
3382
+ throwError(state, 'directive name must not be less than one character in length');
3383
+ }
3384
+
3385
+ while (ch !== 0) {
3386
+ while (is_WHITE_SPACE(ch)) {
3387
+ ch = state.input.charCodeAt(++state.position);
3388
+ }
3389
+
3390
+ if (ch === 0x23/* # */) {
3391
+ do { ch = state.input.charCodeAt(++state.position); }
3392
+ while (ch !== 0 && !is_EOL(ch));
3393
+ break;
3394
+ }
3395
+
3396
+ if (is_EOL(ch)) break;
3397
+
3398
+ _position = state.position;
3399
+
3400
+ while (ch !== 0 && !is_WS_OR_EOL(ch)) {
3401
+ ch = state.input.charCodeAt(++state.position);
3402
+ }
3403
+
3404
+ directiveArgs.push(state.input.slice(_position, state.position));
3405
+ }
3406
+
3407
+ if (ch !== 0) readLineBreak(state);
3408
+
3409
+ if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
3410
+ directiveHandlers[directiveName](state, directiveName, directiveArgs);
3411
+ } else {
3412
+ throwWarning(state, 'unknown document directive "' + directiveName + '"');
3413
+ }
3414
+ }
3415
+
3416
+ skipSeparationSpace(state, true, -1);
3417
+
3418
+ if (state.lineIndent === 0 &&
3419
+ state.input.charCodeAt(state.position) === 0x2D/* - */ &&
3420
+ state.input.charCodeAt(state.position + 1) === 0x2D/* - */ &&
3421
+ state.input.charCodeAt(state.position + 2) === 0x2D/* - */) {
3422
+ state.position += 3;
3423
+ skipSeparationSpace(state, true, -1);
3424
+
3425
+ } else if (hasDirectives) {
3426
+ throwError(state, 'directives end mark is expected');
3427
+ }
3428
+
3429
+ composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
3430
+ skipSeparationSpace(state, true, -1);
3431
+
3432
+ if (state.checkLineBreaks &&
3433
+ PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
3434
+ throwWarning(state, 'non-ASCII line breaks are interpreted as content');
3435
+ }
3436
+
3437
+ state.documents.push(state.result);
3438
+
3439
+ if (state.position === state.lineStart && testDocumentSeparator(state)) {
3440
+
3441
+ if (state.input.charCodeAt(state.position) === 0x2E/* . */) {
3442
+ state.position += 3;
3443
+ skipSeparationSpace(state, true, -1);
3444
+ }
3445
+ return;
3446
+ }
3447
+
3448
+ if (state.position < (state.length - 1)) {
3449
+ throwError(state, 'end of the stream or a document separator is expected');
3450
+ } else {
3451
+ return;
3452
+ }
3453
+ }
3454
+
3455
+
3456
+ function loadDocuments(input, options) {
3457
+ input = String(input);
3458
+ options = options || {};
3459
+
3460
+ if (input.length !== 0) {
3461
+
3462
+ // Add tailing `\n` if not exists
3463
+ if (input.charCodeAt(input.length - 1) !== 0x0A/* LF */ &&
3464
+ input.charCodeAt(input.length - 1) !== 0x0D/* CR */) {
3465
+ input += '\n';
3466
+ }
3467
+
3468
+ // Strip BOM
3469
+ if (input.charCodeAt(0) === 0xFEFF) {
3470
+ input = input.slice(1);
3471
+ }
3472
+ }
3473
+
3474
+ var state = new State$1(input, options);
3475
+
3476
+ var nullpos = input.indexOf('\0');
3477
+
3478
+ if (nullpos !== -1) {
3479
+ state.position = nullpos;
3480
+ throwError(state, 'null byte is not allowed in input');
3481
+ }
3482
+
3483
+ // Use 0 as string terminator. That significantly simplifies bounds check.
3484
+ state.input += '\0';
3485
+
3486
+ while (state.input.charCodeAt(state.position) === 0x20/* Space */) {
3487
+ state.lineIndent += 1;
3488
+ state.position += 1;
3489
+ }
3490
+
3491
+ while (state.position < (state.length - 1)) {
3492
+ readDocument(state);
3493
+ }
3494
+
3495
+ return state.documents;
3496
+ }
3497
+
3498
+
3499
+ function loadAll$1(input, iterator, options) {
3500
+ if (iterator !== null && typeof iterator === 'object' && typeof options === 'undefined') {
3501
+ options = iterator;
3502
+ iterator = null;
3503
+ }
3504
+
3505
+ var documents = loadDocuments(input, options);
3506
+
3507
+ if (typeof iterator !== 'function') {
3508
+ return documents;
3509
+ }
3510
+
3511
+ for (var index = 0, length = documents.length; index < length; index += 1) {
3512
+ iterator(documents[index]);
3513
+ }
3514
+ }
3515
+
3516
+
3517
+ function load$1(input, options) {
3518
+ var documents = loadDocuments(input, options);
3519
+
3520
+ if (documents.length === 0) {
3521
+ /*eslint-disable no-undefined*/
3522
+ return undefined;
3523
+ } else if (documents.length === 1) {
3524
+ return documents[0];
3525
+ }
3526
+ throw new exception('expected a single document in the stream, but found more');
3527
+ }
3528
+
3529
+
3530
+ var loadAll_1 = loadAll$1;
3531
+ var load_1 = load$1;
3532
+
3533
+ var loader = {
3534
+ loadAll: loadAll_1,
3535
+ load: load_1
3536
+ };
3537
+
3538
+ /*eslint-disable no-use-before-define*/
3539
+
3540
+
3541
+
3542
+
3543
+
3544
+ var _toString = Object.prototype.toString;
3545
+ var _hasOwnProperty = Object.prototype.hasOwnProperty;
3546
+
3547
+ var CHAR_BOM = 0xFEFF;
3548
+ var CHAR_TAB = 0x09; /* Tab */
3549
+ var CHAR_LINE_FEED = 0x0A; /* LF */
3550
+ var CHAR_CARRIAGE_RETURN = 0x0D; /* CR */
3551
+ var CHAR_SPACE = 0x20; /* Space */
3552
+ var CHAR_EXCLAMATION = 0x21; /* ! */
3553
+ var CHAR_DOUBLE_QUOTE = 0x22; /* " */
3554
+ var CHAR_SHARP = 0x23; /* # */
3555
+ var CHAR_PERCENT = 0x25; /* % */
3556
+ var CHAR_AMPERSAND = 0x26; /* & */
3557
+ var CHAR_SINGLE_QUOTE = 0x27; /* ' */
3558
+ var CHAR_ASTERISK = 0x2A; /* * */
3559
+ var CHAR_COMMA = 0x2C; /* , */
3560
+ var CHAR_MINUS = 0x2D; /* - */
3561
+ var CHAR_COLON = 0x3A; /* : */
3562
+ var CHAR_EQUALS = 0x3D; /* = */
3563
+ var CHAR_GREATER_THAN = 0x3E; /* > */
3564
+ var CHAR_QUESTION = 0x3F; /* ? */
3565
+ var CHAR_COMMERCIAL_AT = 0x40; /* @ */
3566
+ var CHAR_LEFT_SQUARE_BRACKET = 0x5B; /* [ */
3567
+ var CHAR_RIGHT_SQUARE_BRACKET = 0x5D; /* ] */
3568
+ var CHAR_GRAVE_ACCENT = 0x60; /* ` */
3569
+ var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */
3570
+ var CHAR_VERTICAL_LINE = 0x7C; /* | */
3571
+ var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */
3572
+
3573
+ var ESCAPE_SEQUENCES = {};
3574
+
3575
+ ESCAPE_SEQUENCES[0x00] = '\\0';
3576
+ ESCAPE_SEQUENCES[0x07] = '\\a';
3577
+ ESCAPE_SEQUENCES[0x08] = '\\b';
3578
+ ESCAPE_SEQUENCES[0x09] = '\\t';
3579
+ ESCAPE_SEQUENCES[0x0A] = '\\n';
3580
+ ESCAPE_SEQUENCES[0x0B] = '\\v';
3581
+ ESCAPE_SEQUENCES[0x0C] = '\\f';
3582
+ ESCAPE_SEQUENCES[0x0D] = '\\r';
3583
+ ESCAPE_SEQUENCES[0x1B] = '\\e';
3584
+ ESCAPE_SEQUENCES[0x22] = '\\"';
3585
+ ESCAPE_SEQUENCES[0x5C] = '\\\\';
3586
+ ESCAPE_SEQUENCES[0x85] = '\\N';
3587
+ ESCAPE_SEQUENCES[0xA0] = '\\_';
3588
+ ESCAPE_SEQUENCES[0x2028] = '\\L';
3589
+ ESCAPE_SEQUENCES[0x2029] = '\\P';
3590
+
3591
+ var DEPRECATED_BOOLEANS_SYNTAX = [
3592
+ 'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON',
3593
+ 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'
3594
+ ];
3595
+
3596
+ var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
3597
+
3598
+ function compileStyleMap(schema, map) {
3599
+ var result, keys, index, length, tag, style, type;
3600
+
3601
+ if (map === null) return {};
3602
+
3603
+ result = {};
3604
+ keys = Object.keys(map);
3605
+
3606
+ for (index = 0, length = keys.length; index < length; index += 1) {
3607
+ tag = keys[index];
3608
+ style = String(map[tag]);
3609
+
3610
+ if (tag.slice(0, 2) === '!!') {
3611
+ tag = 'tag:yaml.org,2002:' + tag.slice(2);
3612
+ }
3613
+ type = schema.compiledTypeMap['fallback'][tag];
3614
+
3615
+ if (type && _hasOwnProperty.call(type.styleAliases, style)) {
3616
+ style = type.styleAliases[style];
3617
+ }
3618
+
3619
+ result[tag] = style;
3620
+ }
3621
+
3622
+ return result;
3623
+ }
3624
+
3625
+ function encodeHex(character) {
3626
+ var string, handle, length;
3627
+
3628
+ string = character.toString(16).toUpperCase();
3629
+
3630
+ if (character <= 0xFF) {
3631
+ handle = 'x';
3632
+ length = 2;
3633
+ } else if (character <= 0xFFFF) {
3634
+ handle = 'u';
3635
+ length = 4;
3636
+ } else if (character <= 0xFFFFFFFF) {
3637
+ handle = 'U';
3638
+ length = 8;
3639
+ } else {
3640
+ throw new exception('code point within a string may not be greater than 0xFFFFFFFF');
3641
+ }
3642
+
3643
+ return '\\' + handle + common.repeat('0', length - string.length) + string;
3644
+ }
3645
+
3646
+
3647
+ var QUOTING_TYPE_SINGLE = 1,
3648
+ QUOTING_TYPE_DOUBLE = 2;
3649
+
3650
+ function State(options) {
3651
+ this.schema = options['schema'] || _default;
3652
+ this.indent = Math.max(1, (options['indent'] || 2));
3653
+ this.noArrayIndent = options['noArrayIndent'] || false;
3654
+ this.skipInvalid = options['skipInvalid'] || false;
3655
+ this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
3656
+ this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
3657
+ this.sortKeys = options['sortKeys'] || false;
3658
+ this.lineWidth = options['lineWidth'] || 80;
3659
+ this.noRefs = options['noRefs'] || false;
3660
+ this.noCompatMode = options['noCompatMode'] || false;
3661
+ this.condenseFlow = options['condenseFlow'] || false;
3662
+ this.quotingType = options['quotingType'] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
3663
+ this.forceQuotes = options['forceQuotes'] || false;
3664
+ this.replacer = typeof options['replacer'] === 'function' ? options['replacer'] : null;
3665
+
3666
+ this.implicitTypes = this.schema.compiledImplicit;
3667
+ this.explicitTypes = this.schema.compiledExplicit;
3668
+
3669
+ this.tag = null;
3670
+ this.result = '';
3671
+
3672
+ this.duplicates = [];
3673
+ this.usedDuplicates = null;
3674
+ }
3675
+
3676
+ // Indents every line in a string. Empty lines (\n only) are not indented.
3677
+ function indentString(string, spaces) {
3678
+ var ind = common.repeat(' ', spaces),
3679
+ position = 0,
3680
+ next = -1,
3681
+ result = '',
3682
+ line,
3683
+ length = string.length;
3684
+
3685
+ while (position < length) {
3686
+ next = string.indexOf('\n', position);
3687
+ if (next === -1) {
3688
+ line = string.slice(position);
3689
+ position = length;
3690
+ } else {
3691
+ line = string.slice(position, next + 1);
3692
+ position = next + 1;
3693
+ }
3694
+
3695
+ if (line.length && line !== '\n') result += ind;
3696
+
3697
+ result += line;
3698
+ }
3699
+
3700
+ return result;
3701
+ }
3702
+
3703
+ function generateNextLine(state, level) {
3704
+ return '\n' + common.repeat(' ', state.indent * level);
3705
+ }
3706
+
3707
+ function testImplicitResolving(state, str) {
3708
+ var index, length, type;
3709
+
3710
+ for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
3711
+ type = state.implicitTypes[index];
3712
+
3713
+ if (type.resolve(str)) {
3714
+ return true;
3715
+ }
3716
+ }
3717
+
3718
+ return false;
3719
+ }
3720
+
3721
+ // [33] s-white ::= s-space | s-tab
3722
+ function isWhitespace(c) {
3723
+ return c === CHAR_SPACE || c === CHAR_TAB;
3724
+ }
3725
+
3726
+ // Returns true if the character can be printed without escaping.
3727
+ // From YAML 1.2: "any allowed characters known to be non-printable
3728
+ // should also be escaped. [However,] This isn’t mandatory"
3729
+ // Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029.
3730
+ function isPrintable(c) {
3731
+ return (0x00020 <= c && c <= 0x00007E)
3732
+ || ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029)
3733
+ || ((0x0E000 <= c && c <= 0x00FFFD) && c !== CHAR_BOM)
3734
+ || (0x10000 <= c && c <= 0x10FFFF);
3735
+ }
3736
+
3737
+ // [34] ns-char ::= nb-char - s-white
3738
+ // [27] nb-char ::= c-printable - b-char - c-byte-order-mark
3739
+ // [26] b-char ::= b-line-feed | b-carriage-return
3740
+ // Including s-white (for some reason, examples doesn't match specs in this aspect)
3741
+ // ns-char ::= c-printable - b-line-feed - b-carriage-return - c-byte-order-mark
3742
+ function isNsCharOrWhitespace(c) {
3743
+ return isPrintable(c)
3744
+ && c !== CHAR_BOM
3745
+ // - b-char
3746
+ && c !== CHAR_CARRIAGE_RETURN
3747
+ && c !== CHAR_LINE_FEED;
3748
+ }
3749
+
3750
+ // [127] ns-plain-safe(c) ::= c = flow-out ⇒ ns-plain-safe-out
3751
+ // c = flow-in ⇒ ns-plain-safe-in
3752
+ // c = block-key ⇒ ns-plain-safe-out
3753
+ // c = flow-key ⇒ ns-plain-safe-in
3754
+ // [128] ns-plain-safe-out ::= ns-char
3755
+ // [129] ns-plain-safe-in ::= ns-char - c-flow-indicator
3756
+ // [130] ns-plain-char(c) ::= ( ns-plain-safe(c) - “:” - “#” )
3757
+ // | ( /* An ns-char preceding */ “#” )
3758
+ // | ( “:” /* Followed by an ns-plain-safe(c) */ )
3759
+ function isPlainSafe(c, prev, inblock) {
3760
+ var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
3761
+ var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
3762
+ return (
3763
+ // ns-plain-safe
3764
+ inblock ? // c = flow-in
3765
+ cIsNsCharOrWhitespace
3766
+ : cIsNsCharOrWhitespace
3767
+ // - c-flow-indicator
3768
+ && c !== CHAR_COMMA
3769
+ && c !== CHAR_LEFT_SQUARE_BRACKET
3770
+ && c !== CHAR_RIGHT_SQUARE_BRACKET
3771
+ && c !== CHAR_LEFT_CURLY_BRACKET
3772
+ && c !== CHAR_RIGHT_CURLY_BRACKET
3773
+ )
3774
+ // ns-plain-char
3775
+ && c !== CHAR_SHARP // false on '#'
3776
+ && !(prev === CHAR_COLON && !cIsNsChar) // false on ': '
3777
+ || (isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP) // change to true on '[^ ]#'
3778
+ || (prev === CHAR_COLON && cIsNsChar); // change to true on ':[^ ]'
3779
+ }
3780
+
3781
+ // Simplified test for values allowed as the first character in plain style.
3782
+ function isPlainSafeFirst(c) {
3783
+ // Uses a subset of ns-char - c-indicator
3784
+ // where ns-char = nb-char - s-white.
3785
+ // No support of ( ( “?” | “:” | “-” ) /* Followed by an ns-plain-safe(c)) */ ) part
3786
+ return isPrintable(c) && c !== CHAR_BOM
3787
+ && !isWhitespace(c) // - s-white
3788
+ // - (c-indicator ::=
3789
+ // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}”
3790
+ && c !== CHAR_MINUS
3791
+ && c !== CHAR_QUESTION
3792
+ && c !== CHAR_COLON
3793
+ && c !== CHAR_COMMA
3794
+ && c !== CHAR_LEFT_SQUARE_BRACKET
3795
+ && c !== CHAR_RIGHT_SQUARE_BRACKET
3796
+ && c !== CHAR_LEFT_CURLY_BRACKET
3797
+ && c !== CHAR_RIGHT_CURLY_BRACKET
3798
+ // | “#” | “&” | “*” | “!” | “|” | “=” | “>” | “'” | “"”
3799
+ && c !== CHAR_SHARP
3800
+ && c !== CHAR_AMPERSAND
3801
+ && c !== CHAR_ASTERISK
3802
+ && c !== CHAR_EXCLAMATION
3803
+ && c !== CHAR_VERTICAL_LINE
3804
+ && c !== CHAR_EQUALS
3805
+ && c !== CHAR_GREATER_THAN
3806
+ && c !== CHAR_SINGLE_QUOTE
3807
+ && c !== CHAR_DOUBLE_QUOTE
3808
+ // | “%” | “@” | “`”)
3809
+ && c !== CHAR_PERCENT
3810
+ && c !== CHAR_COMMERCIAL_AT
3811
+ && c !== CHAR_GRAVE_ACCENT;
3812
+ }
3813
+
3814
+ // Simplified test for values allowed as the last character in plain style.
3815
+ function isPlainSafeLast(c) {
3816
+ // just not whitespace or colon, it will be checked to be plain character later
3817
+ return !isWhitespace(c) && c !== CHAR_COLON;
3818
+ }
3819
+
3820
+ // Same as 'string'.codePointAt(pos), but works in older browsers.
3821
+ function codePointAt(string, pos) {
3822
+ var first = string.charCodeAt(pos), second;
3823
+ if (first >= 0xD800 && first <= 0xDBFF && pos + 1 < string.length) {
3824
+ second = string.charCodeAt(pos + 1);
3825
+ if (second >= 0xDC00 && second <= 0xDFFF) {
3826
+ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
3827
+ return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
3828
+ }
3829
+ }
3830
+ return first;
3831
+ }
3832
+
3833
+ // Determines whether block indentation indicator is required.
3834
+ function needIndentIndicator(string) {
3835
+ var leadingSpaceRe = /^\n* /;
3836
+ return leadingSpaceRe.test(string);
3837
+ }
3838
+
3839
+ var STYLE_PLAIN = 1,
3840
+ STYLE_SINGLE = 2,
3841
+ STYLE_LITERAL = 3,
3842
+ STYLE_FOLDED = 4,
3843
+ STYLE_DOUBLE = 5;
3844
+
3845
+ // Determines which scalar styles are possible and returns the preferred style.
3846
+ // lineWidth = -1 => no limit.
3847
+ // Pre-conditions: str.length > 0.
3848
+ // Post-conditions:
3849
+ // STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
3850
+ // STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
3851
+ // STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1).
3852
+ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth,
3853
+ testAmbiguousType, quotingType, forceQuotes, inblock) {
3854
+
3855
+ var i;
3856
+ var char = 0;
3857
+ var prevChar = null;
3858
+ var hasLineBreak = false;
3859
+ var hasFoldableLine = false; // only checked if shouldTrackWidth
3860
+ var shouldTrackWidth = lineWidth !== -1;
3861
+ var previousLineBreak = -1; // count the first line correctly
3862
+ var plain = isPlainSafeFirst(codePointAt(string, 0))
3863
+ && isPlainSafeLast(codePointAt(string, string.length - 1));
3864
+
3865
+ if (singleLineOnly || forceQuotes) {
3866
+ // Case: no block styles.
3867
+ // Check for disallowed characters to rule out plain and single.
3868
+ for (i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++) {
3869
+ char = codePointAt(string, i);
3870
+ if (!isPrintable(char)) {
3871
+ return STYLE_DOUBLE;
3872
+ }
3873
+ plain = plain && isPlainSafe(char, prevChar, inblock);
3874
+ prevChar = char;
3875
+ }
3876
+ } else {
3877
+ // Case: block styles permitted.
3878
+ for (i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++) {
3879
+ char = codePointAt(string, i);
3880
+ if (char === CHAR_LINE_FEED) {
3881
+ hasLineBreak = true;
3882
+ // Check if any line can be folded.
3883
+ if (shouldTrackWidth) {
3884
+ hasFoldableLine = hasFoldableLine ||
3885
+ // Foldable line = too long, and not more-indented.
3886
+ (i - previousLineBreak - 1 > lineWidth &&
3887
+ string[previousLineBreak + 1] !== ' ');
3888
+ previousLineBreak = i;
3889
+ }
3890
+ } else if (!isPrintable(char)) {
3891
+ return STYLE_DOUBLE;
3892
+ }
3893
+ plain = plain && isPlainSafe(char, prevChar, inblock);
3894
+ prevChar = char;
3895
+ }
3896
+ // in case the end is missing a \n
3897
+ hasFoldableLine = hasFoldableLine || (shouldTrackWidth &&
3898
+ (i - previousLineBreak - 1 > lineWidth &&
3899
+ string[previousLineBreak + 1] !== ' '));
3900
+ }
3901
+ // Although every style can represent \n without escaping, prefer block styles
3902
+ // for multiline, since they're more readable and they don't add empty lines.
3903
+ // Also prefer folding a super-long line.
3904
+ if (!hasLineBreak && !hasFoldableLine) {
3905
+ // Strings interpretable as another type have to be quoted;
3906
+ // e.g. the string 'true' vs. the boolean true.
3907
+ if (plain && !forceQuotes && !testAmbiguousType(string)) {
3908
+ return STYLE_PLAIN;
3909
+ }
3910
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
3911
+ }
3912
+ // Edge case: block indentation indicator can only have one digit.
3913
+ if (indentPerLevel > 9 && needIndentIndicator(string)) {
3914
+ return STYLE_DOUBLE;
3915
+ }
3916
+ // At this point we know block styles are valid.
3917
+ // Prefer literal style unless we want to fold.
3918
+ if (!forceQuotes) {
3919
+ return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
3920
+ }
3921
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
3922
+ }
3923
+
3924
+ // Note: line breaking/folding is implemented for only the folded style.
3925
+ // NB. We drop the last trailing newline (if any) of a returned block scalar
3926
+ // since the dumper adds its own newline. This always works:
3927
+ // • No ending newline => unaffected; already using strip "-" chomping.
3928
+ // • Ending newline => removed then restored.
3929
+ // Importantly, this keeps the "+" chomp indicator from gaining an extra line.
3930
+ function writeScalar(state, string, level, iskey, inblock) {
3931
+ state.dump = (function () {
3932
+ if (string.length === 0) {
3933
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
3934
+ }
3935
+ if (!state.noCompatMode) {
3936
+ if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
3937
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? ('"' + string + '"') : ("'" + string + "'");
3938
+ }
3939
+ }
3940
+
3941
+ var indent = state.indent * Math.max(1, level); // no 0-indent scalars
3942
+ // As indentation gets deeper, let the width decrease monotonically
3943
+ // to the lower bound min(state.lineWidth, 40).
3944
+ // Note that this implies
3945
+ // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
3946
+ // state.lineWidth > 40 + state.indent: width decreases until the lower bound.
3947
+ // This behaves better than a constant minimum width which disallows narrower options,
3948
+ // or an indent threshold which causes the width to suddenly increase.
3949
+ var lineWidth = state.lineWidth === -1
3950
+ ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
3951
+
3952
+ // Without knowing if keys are implicit/explicit, assume implicit for safety.
3953
+ var singleLineOnly = iskey
3954
+ // No block styles in flow mode.
3955
+ || (state.flowLevel > -1 && level >= state.flowLevel);
3956
+ function testAmbiguity(string) {
3957
+ return testImplicitResolving(state, string);
3958
+ }
3959
+
3960
+ switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth,
3961
+ testAmbiguity, state.quotingType, state.forceQuotes && !iskey, inblock)) {
3962
+
3963
+ case STYLE_PLAIN:
3964
+ return string;
3965
+ case STYLE_SINGLE:
3966
+ return "'" + string.replace(/'/g, "''") + "'";
3967
+ case STYLE_LITERAL:
3968
+ return '|' + blockHeader(string, state.indent)
3969
+ + dropEndingNewline(indentString(string, indent));
3970
+ case STYLE_FOLDED:
3971
+ return '>' + blockHeader(string, state.indent)
3972
+ + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
3973
+ case STYLE_DOUBLE:
3974
+ return '"' + escapeString(string) + '"';
3975
+ default:
3976
+ throw new exception('impossible error: invalid scalar style');
3977
+ }
3978
+ }());
3979
+ }
3980
+
3981
+ // Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
3982
+ function blockHeader(string, indentPerLevel) {
3983
+ var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : '';
3984
+
3985
+ // note the special case: the string '\n' counts as a "trailing" empty line.
3986
+ var clip = string[string.length - 1] === '\n';
3987
+ var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
3988
+ var chomp = keep ? '+' : (clip ? '' : '-');
3989
+
3990
+ return indentIndicator + chomp + '\n';
3991
+ }
3992
+
3993
+ // (See the note for writeScalar.)
3994
+ function dropEndingNewline(string) {
3995
+ return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
3996
+ }
3997
+
3998
+ // Note: a long line without a suitable break point will exceed the width limit.
3999
+ // Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
4000
+ function foldString(string, width) {
4001
+ // In folded style, $k$ consecutive newlines output as $k+1$ newlines—
4002
+ // unless they're before or after a more-indented line, or at the very
4003
+ // beginning or end, in which case $k$ maps to $k$.
4004
+ // Therefore, parse each chunk as newline(s) followed by a content line.
4005
+ var lineRe = /(\n+)([^\n]*)/g;
4006
+
4007
+ // first line (possibly an empty line)
4008
+ var result = (function () {
4009
+ var nextLF = string.indexOf('\n');
4010
+ nextLF = nextLF !== -1 ? nextLF : string.length;
4011
+ lineRe.lastIndex = nextLF;
4012
+ return foldLine(string.slice(0, nextLF), width);
4013
+ }());
4014
+ // If we haven't reached the first content line yet, don't add an extra \n.
4015
+ var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
4016
+ var moreIndented;
4017
+
4018
+ // rest of the lines
4019
+ var match;
4020
+ while ((match = lineRe.exec(string))) {
4021
+ var prefix = match[1], line = match[2];
4022
+ moreIndented = (line[0] === ' ');
4023
+ result += prefix
4024
+ + (!prevMoreIndented && !moreIndented && line !== ''
4025
+ ? '\n' : '')
4026
+ + foldLine(line, width);
4027
+ prevMoreIndented = moreIndented;
4028
+ }
4029
+
4030
+ return result;
4031
+ }
4032
+
4033
+ // Greedy line breaking.
4034
+ // Picks the longest line under the limit each time,
4035
+ // otherwise settles for the shortest line over the limit.
4036
+ // NB. More-indented lines *cannot* be folded, as that would add an extra \n.
4037
+ function foldLine(line, width) {
4038
+ if (line === '' || line[0] === ' ') return line;
4039
+
4040
+ // Since a more-indented line adds a \n, breaks can't be followed by a space.
4041
+ var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
4042
+ var match;
4043
+ // start is an inclusive index. end, curr, and next are exclusive.
4044
+ var start = 0, end, curr = 0, next = 0;
4045
+ var result = '';
4046
+
4047
+ // Invariants: 0 <= start <= length-1.
4048
+ // 0 <= curr <= next <= max(0, length-2). curr - start <= width.
4049
+ // Inside the loop:
4050
+ // A match implies length >= 2, so curr and next are <= length-2.
4051
+ while ((match = breakRe.exec(line))) {
4052
+ next = match.index;
4053
+ // maintain invariant: curr - start <= width
4054
+ if (next - start > width) {
4055
+ end = (curr > start) ? curr : next; // derive end <= length-2
4056
+ result += '\n' + line.slice(start, end);
4057
+ // skip the space that was output as \n
4058
+ start = end + 1; // derive start <= length-1
4059
+ }
4060
+ curr = next;
4061
+ }
4062
+
4063
+ // By the invariants, start <= length-1, so there is something left over.
4064
+ // It is either the whole string or a part starting from non-whitespace.
4065
+ result += '\n';
4066
+ // Insert a break if the remainder is too long and there is a break available.
4067
+ if (line.length - start > width && curr > start) {
4068
+ result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
4069
+ } else {
4070
+ result += line.slice(start);
4071
+ }
4072
+
4073
+ return result.slice(1); // drop extra \n joiner
4074
+ }
4075
+
4076
+ // Escapes a double-quoted string.
4077
+ function escapeString(string) {
4078
+ var result = '';
4079
+ var char = 0;
4080
+ var escapeSeq;
4081
+
4082
+ for (var i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++) {
4083
+ char = codePointAt(string, i);
4084
+ escapeSeq = ESCAPE_SEQUENCES[char];
4085
+
4086
+ if (!escapeSeq && isPrintable(char)) {
4087
+ result += string[i];
4088
+ if (char >= 0x10000) result += string[i + 1];
4089
+ } else {
4090
+ result += escapeSeq || encodeHex(char);
4091
+ }
4092
+ }
4093
+
4094
+ return result;
4095
+ }
4096
+
4097
+ function writeFlowSequence(state, level, object) {
4098
+ var _result = '',
4099
+ _tag = state.tag,
4100
+ index,
4101
+ length,
4102
+ value;
4103
+
4104
+ for (index = 0, length = object.length; index < length; index += 1) {
4105
+ value = object[index];
4106
+
4107
+ if (state.replacer) {
4108
+ value = state.replacer.call(object, String(index), value);
4109
+ }
4110
+
4111
+ // Write only valid elements, put null instead of invalid elements.
4112
+ if (writeNode(state, level, value, false, false) ||
4113
+ (typeof value === 'undefined' &&
4114
+ writeNode(state, level, null, false, false))) {
4115
+
4116
+ if (_result !== '') _result += ',' + (!state.condenseFlow ? ' ' : '');
4117
+ _result += state.dump;
4118
+ }
4119
+ }
4120
+
4121
+ state.tag = _tag;
4122
+ state.dump = '[' + _result + ']';
4123
+ }
4124
+
4125
+ function writeBlockSequence(state, level, object, compact) {
4126
+ var _result = '',
4127
+ _tag = state.tag,
4128
+ index,
4129
+ length,
4130
+ value;
4131
+
4132
+ for (index = 0, length = object.length; index < length; index += 1) {
4133
+ value = object[index];
4134
+
4135
+ if (state.replacer) {
4136
+ value = state.replacer.call(object, String(index), value);
4137
+ }
4138
+
4139
+ // Write only valid elements, put null instead of invalid elements.
4140
+ if (writeNode(state, level + 1, value, true, true, false, true) ||
4141
+ (typeof value === 'undefined' &&
4142
+ writeNode(state, level + 1, null, true, true, false, true))) {
4143
+
4144
+ if (!compact || _result !== '') {
4145
+ _result += generateNextLine(state, level);
4146
+ }
4147
+
4148
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
4149
+ _result += '-';
4150
+ } else {
4151
+ _result += '- ';
4152
+ }
4153
+
4154
+ _result += state.dump;
4155
+ }
4156
+ }
4157
+
4158
+ state.tag = _tag;
4159
+ state.dump = _result || '[]'; // Empty sequence if no valid values.
4160
+ }
4161
+
4162
+ function writeFlowMapping(state, level, object) {
4163
+ var _result = '',
4164
+ _tag = state.tag,
4165
+ objectKeyList = Object.keys(object),
4166
+ index,
4167
+ length,
4168
+ objectKey,
4169
+ objectValue,
4170
+ pairBuffer;
4171
+
4172
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
4173
+
4174
+ pairBuffer = '';
4175
+ if (_result !== '') pairBuffer += ', ';
4176
+
4177
+ if (state.condenseFlow) pairBuffer += '"';
4178
+
4179
+ objectKey = objectKeyList[index];
4180
+ objectValue = object[objectKey];
4181
+
4182
+ if (state.replacer) {
4183
+ objectValue = state.replacer.call(object, objectKey, objectValue);
4184
+ }
4185
+
4186
+ if (!writeNode(state, level, objectKey, false, false)) {
4187
+ continue; // Skip this pair because of invalid key;
4188
+ }
4189
+
4190
+ if (state.dump.length > 1024) pairBuffer += '? ';
4191
+
4192
+ pairBuffer += state.dump + (state.condenseFlow ? '"' : '') + ':' + (state.condenseFlow ? '' : ' ');
4193
+
4194
+ if (!writeNode(state, level, objectValue, false, false)) {
4195
+ continue; // Skip this pair because of invalid value.
4196
+ }
4197
+
4198
+ pairBuffer += state.dump;
4199
+
4200
+ // Both key and value are valid.
4201
+ _result += pairBuffer;
4202
+ }
4203
+
4204
+ state.tag = _tag;
4205
+ state.dump = '{' + _result + '}';
4206
+ }
4207
+
4208
+ function writeBlockMapping(state, level, object, compact) {
4209
+ var _result = '',
4210
+ _tag = state.tag,
4211
+ objectKeyList = Object.keys(object),
4212
+ index,
4213
+ length,
4214
+ objectKey,
4215
+ objectValue,
4216
+ explicitPair,
4217
+ pairBuffer;
4218
+
4219
+ // Allow sorting keys so that the output file is deterministic
4220
+ if (state.sortKeys === true) {
4221
+ // Default sorting
4222
+ objectKeyList.sort();
4223
+ } else if (typeof state.sortKeys === 'function') {
4224
+ // Custom sort function
4225
+ objectKeyList.sort(state.sortKeys);
4226
+ } else if (state.sortKeys) {
4227
+ // Something is wrong
4228
+ throw new exception('sortKeys must be a boolean or a function');
4229
+ }
4230
+
4231
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
4232
+ pairBuffer = '';
4233
+
4234
+ if (!compact || _result !== '') {
4235
+ pairBuffer += generateNextLine(state, level);
4236
+ }
4237
+
4238
+ objectKey = objectKeyList[index];
4239
+ objectValue = object[objectKey];
4240
+
4241
+ if (state.replacer) {
4242
+ objectValue = state.replacer.call(object, objectKey, objectValue);
4243
+ }
4244
+
4245
+ if (!writeNode(state, level + 1, objectKey, true, true, true)) {
4246
+ continue; // Skip this pair because of invalid key.
4247
+ }
4248
+
4249
+ explicitPair = (state.tag !== null && state.tag !== '?') ||
4250
+ (state.dump && state.dump.length > 1024);
4251
+
4252
+ if (explicitPair) {
4253
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
4254
+ pairBuffer += '?';
4255
+ } else {
4256
+ pairBuffer += '? ';
4257
+ }
4258
+ }
4259
+
4260
+ pairBuffer += state.dump;
4261
+
4262
+ if (explicitPair) {
4263
+ pairBuffer += generateNextLine(state, level);
4264
+ }
4265
+
4266
+ if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
4267
+ continue; // Skip this pair because of invalid value.
4268
+ }
4269
+
4270
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
4271
+ pairBuffer += ':';
4272
+ } else {
4273
+ pairBuffer += ': ';
4274
+ }
4275
+
4276
+ pairBuffer += state.dump;
4277
+
4278
+ // Both key and value are valid.
4279
+ _result += pairBuffer;
4280
+ }
4281
+
4282
+ state.tag = _tag;
4283
+ state.dump = _result || '{}'; // Empty mapping if no valid pairs.
4284
+ }
4285
+
4286
+ function detectType(state, object, explicit) {
4287
+ var _result, typeList, index, length, type, style;
4288
+
4289
+ typeList = explicit ? state.explicitTypes : state.implicitTypes;
4290
+
4291
+ for (index = 0, length = typeList.length; index < length; index += 1) {
4292
+ type = typeList[index];
4293
+
4294
+ if ((type.instanceOf || type.predicate) &&
4295
+ (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) &&
4296
+ (!type.predicate || type.predicate(object))) {
4297
+
4298
+ if (explicit) {
4299
+ if (type.multi && type.representName) {
4300
+ state.tag = type.representName(object);
4301
+ } else {
4302
+ state.tag = type.tag;
4303
+ }
4304
+ } else {
4305
+ state.tag = '?';
4306
+ }
4307
+
4308
+ if (type.represent) {
4309
+ style = state.styleMap[type.tag] || type.defaultStyle;
4310
+
4311
+ if (_toString.call(type.represent) === '[object Function]') {
4312
+ _result = type.represent(object, style);
4313
+ } else if (_hasOwnProperty.call(type.represent, style)) {
4314
+ _result = type.represent[style](object, style);
4315
+ } else {
4316
+ throw new exception('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
4317
+ }
4318
+
4319
+ state.dump = _result;
4320
+ }
4321
+
4322
+ return true;
4323
+ }
4324
+ }
4325
+
4326
+ return false;
4327
+ }
4328
+
4329
+ // Serializes `object` and writes it to global `result`.
4330
+ // Returns true on success, or false on invalid object.
4331
+ //
4332
+ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
4333
+ state.tag = null;
4334
+ state.dump = object;
4335
+
4336
+ if (!detectType(state, object, false)) {
4337
+ detectType(state, object, true);
4338
+ }
4339
+
4340
+ var type = _toString.call(state.dump);
4341
+ var inblock = block;
4342
+ var tagStr;
4343
+
4344
+ if (block) {
4345
+ block = (state.flowLevel < 0 || state.flowLevel > level);
4346
+ }
4347
+
4348
+ var objectOrArray = type === '[object Object]' || type === '[object Array]',
4349
+ duplicateIndex,
4350
+ duplicate;
4351
+
4352
+ if (objectOrArray) {
4353
+ duplicateIndex = state.duplicates.indexOf(object);
4354
+ duplicate = duplicateIndex !== -1;
4355
+ }
4356
+
4357
+ if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
4358
+ compact = false;
4359
+ }
4360
+
4361
+ if (duplicate && state.usedDuplicates[duplicateIndex]) {
4362
+ state.dump = '*ref_' + duplicateIndex;
4363
+ } else {
4364
+ if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
4365
+ state.usedDuplicates[duplicateIndex] = true;
4366
+ }
4367
+ if (type === '[object Object]') {
4368
+ if (block && (Object.keys(state.dump).length !== 0)) {
4369
+ writeBlockMapping(state, level, state.dump, compact);
4370
+ if (duplicate) {
4371
+ state.dump = '&ref_' + duplicateIndex + state.dump;
4372
+ }
4373
+ } else {
4374
+ writeFlowMapping(state, level, state.dump);
4375
+ if (duplicate) {
4376
+ state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
4377
+ }
4378
+ }
4379
+ } else if (type === '[object Array]') {
4380
+ if (block && (state.dump.length !== 0)) {
4381
+ if (state.noArrayIndent && !isblockseq && level > 0) {
4382
+ writeBlockSequence(state, level - 1, state.dump, compact);
4383
+ } else {
4384
+ writeBlockSequence(state, level, state.dump, compact);
4385
+ }
4386
+ if (duplicate) {
4387
+ state.dump = '&ref_' + duplicateIndex + state.dump;
4388
+ }
4389
+ } else {
4390
+ writeFlowSequence(state, level, state.dump);
4391
+ if (duplicate) {
4392
+ state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
4393
+ }
4394
+ }
4395
+ } else if (type === '[object String]') {
4396
+ if (state.tag !== '?') {
4397
+ writeScalar(state, state.dump, level, iskey, inblock);
4398
+ }
4399
+ } else if (type === '[object Undefined]') {
4400
+ return false;
4401
+ } else {
4402
+ if (state.skipInvalid) return false;
4403
+ throw new exception('unacceptable kind of an object to dump ' + type);
4404
+ }
4405
+
4406
+ if (state.tag !== null && state.tag !== '?') {
4407
+ // Need to encode all characters except those allowed by the spec:
4408
+ //
4409
+ // [35] ns-dec-digit ::= [#x30-#x39] /* 0-9 */
4410
+ // [36] ns-hex-digit ::= ns-dec-digit
4411
+ // | [#x41-#x46] /* A-F */ | [#x61-#x66] /* a-f */
4412
+ // [37] ns-ascii-letter ::= [#x41-#x5A] /* A-Z */ | [#x61-#x7A] /* a-z */
4413
+ // [38] ns-word-char ::= ns-dec-digit | ns-ascii-letter | “-”
4414
+ // [39] ns-uri-char ::= “%” ns-hex-digit ns-hex-digit | ns-word-char | “#”
4415
+ // | “;” | “/” | “?” | “:” | “@” | “&” | “=” | “+” | “$” | “,”
4416
+ // | “_” | “.” | “!” | “~” | “*” | “'” | “(” | “)” | “[” | “]”
4417
+ //
4418
+ // Also need to encode '!' because it has special meaning (end of tag prefix).
4419
+ //
4420
+ tagStr = encodeURI(
4421
+ state.tag[0] === '!' ? state.tag.slice(1) : state.tag
4422
+ ).replace(/!/g, '%21');
4423
+
4424
+ if (state.tag[0] === '!') {
4425
+ tagStr = '!' + tagStr;
4426
+ } else if (tagStr.slice(0, 18) === 'tag:yaml.org,2002:') {
4427
+ tagStr = '!!' + tagStr.slice(18);
4428
+ } else {
4429
+ tagStr = '!<' + tagStr + '>';
4430
+ }
4431
+
4432
+ state.dump = tagStr + ' ' + state.dump;
4433
+ }
4434
+ }
4435
+
4436
+ return true;
4437
+ }
4438
+
4439
+ function getDuplicateReferences(object, state) {
4440
+ var objects = [],
4441
+ duplicatesIndexes = [],
4442
+ index,
4443
+ length;
4444
+
4445
+ inspectNode(object, objects, duplicatesIndexes);
4446
+
4447
+ for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
4448
+ state.duplicates.push(objects[duplicatesIndexes[index]]);
4449
+ }
4450
+ state.usedDuplicates = new Array(length);
4451
+ }
4452
+
4453
+ function inspectNode(object, objects, duplicatesIndexes) {
4454
+ var objectKeyList,
4455
+ index,
4456
+ length;
4457
+
4458
+ if (object !== null && typeof object === 'object') {
4459
+ index = objects.indexOf(object);
4460
+ if (index !== -1) {
4461
+ if (duplicatesIndexes.indexOf(index) === -1) {
4462
+ duplicatesIndexes.push(index);
4463
+ }
4464
+ } else {
4465
+ objects.push(object);
4466
+
4467
+ if (Array.isArray(object)) {
4468
+ for (index = 0, length = object.length; index < length; index += 1) {
4469
+ inspectNode(object[index], objects, duplicatesIndexes);
4470
+ }
4471
+ } else {
4472
+ objectKeyList = Object.keys(object);
4473
+
4474
+ for (index = 0, length = objectKeyList.length; index < length; index += 1) {
4475
+ inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
4476
+ }
4477
+ }
4478
+ }
4479
+ }
4480
+ }
4481
+
4482
+ function dump$1(input, options) {
4483
+ options = options || {};
4484
+
4485
+ var state = new State(options);
4486
+
4487
+ if (!state.noRefs) getDuplicateReferences(input, state);
4488
+
4489
+ var value = input;
4490
+
4491
+ if (state.replacer) {
4492
+ value = state.replacer.call({ '': value }, '', value);
4493
+ }
4494
+
4495
+ if (writeNode(state, 0, value, true, true)) return state.dump + '\n';
4496
+
4497
+ return '';
4498
+ }
4499
+
4500
+ var dump_1 = dump$1;
4501
+
4502
+ var dumper = {
4503
+ dump: dump_1
4504
+ };
4505
+
4506
+ function renamed(from, to) {
4507
+ return function () {
4508
+ throw new Error('Function yaml.' + from + ' is removed in js-yaml 4. ' +
4509
+ 'Use yaml.' + to + ' instead, which is now safe by default.');
4510
+ };
4511
+ }
4512
+
4513
+
4514
+ var Type = type;
4515
+ var Schema = schema;
4516
+ var FAILSAFE_SCHEMA = failsafe;
4517
+ var JSON_SCHEMA = json;
4518
+ var CORE_SCHEMA = core;
4519
+ var DEFAULT_SCHEMA = _default;
4520
+ var load = loader.load;
4521
+ var loadAll = loader.loadAll;
4522
+ var dump = dumper.dump;
4523
+ var YAMLException = exception;
4524
+
4525
+ // Re-export all types in case user wants to create custom schema
4526
+ var types = {
4527
+ binary: binary,
4528
+ float: float,
4529
+ map: map,
4530
+ null: _null,
4531
+ pairs: pairs,
4532
+ set: set,
4533
+ timestamp: timestamp,
4534
+ bool: bool,
4535
+ int: int,
4536
+ merge: merge,
4537
+ omap: omap,
4538
+ seq: seq,
4539
+ str: str
4540
+ };
4541
+
4542
+ // Removed functions from JS-YAML 3.0.x
4543
+ var safeLoad = renamed('safeLoad', 'load');
4544
+ var safeLoadAll = renamed('safeLoadAll', 'loadAll');
4545
+ var safeDump = renamed('safeDump', 'dump');
4546
+
4547
+ var jsYaml = {
4548
+ Type: Type,
4549
+ Schema: Schema,
4550
+ FAILSAFE_SCHEMA: FAILSAFE_SCHEMA,
4551
+ JSON_SCHEMA: JSON_SCHEMA,
4552
+ CORE_SCHEMA: CORE_SCHEMA,
4553
+ DEFAULT_SCHEMA: DEFAULT_SCHEMA,
4554
+ load: load,
4555
+ loadAll: loadAll,
4556
+ dump: dump,
4557
+ YAMLException: YAMLException,
4558
+ types: types,
4559
+ safeLoad: safeLoad,
4560
+ safeLoadAll: safeLoadAll,
4561
+ safeDump: safeDump
4562
+ };
4563
+
4564
+ console.log("🦖 remarkYamlTable plugin module loaded");
4565
+ var remarkYamlTable = function (options) {
4566
+ var _a = (options !== null && options !== void 0 ? options : {}).logLevel; _a === void 0 ? LogLevel.Silent : _a;
4567
+ var logger = new Logger(resolveLogLevel(options === null || options === void 0 ? void 0 : options.logLevel), 'remarkYamlTable');
4568
+ logger.log('initialized');
4569
+ return function (tree) {
4570
+ visit(tree, 'code', function (node, index, parent) {
4571
+ if (!parent || index === undefined)
4572
+ return;
4573
+ if (node.lang === 'yaml-table') {
4574
+ try {
4575
+ var data = jsYaml.load(node.value);
4576
+ if (Array.isArray(data) && data.length > 0 && typeof data[0] === 'object') {
4577
+ var headers_1 = Object.keys(data[0]);
4578
+ var tableRows = data.map(function (row) { return ({
4579
+ type: 'tableRow',
4580
+ children: headers_1.map(function (header) {
4581
+ var _a;
4582
+ return ({
4583
+ type: 'tableCell',
4584
+ children: [{ type: 'text', value: String((_a = row[header]) !== null && _a !== void 0 ? _a : '') }],
4585
+ });
4586
+ }),
4587
+ }); });
4588
+ var tableNode = {
4589
+ type: 'table',
4590
+ align: headers_1.map(function () { return null; }),
4591
+ children: __spreadArray([
4592
+ {
4593
+ type: 'tableRow',
4594
+ children: headers_1.map(function (header) { return ({
4595
+ type: 'tableCell',
4596
+ children: [{ type: 'text', value: header }],
4597
+ }); }),
4598
+ }
4599
+ ], tableRows, true),
4600
+ };
4601
+ parent.children[index] = tableNode;
4602
+ logger.log("generated table with ".concat(headers_1.length, " columns and ").concat(data.length, " rows"), LogLevel.Info);
4603
+ }
4604
+ }
4605
+ catch (error) {
4606
+ logger.log("YAML parsing error: ".concat(error.message), LogLevel.Info);
4607
+ }
4608
+ }
4609
+ });
4610
+ };
4611
+ };
4612
+
4613
+ function timedPlugin(name, plugin, opts) {
4614
+ if (opts === void 0) { opts = {}; }
4615
+ var _a = opts.logLevel; _a === void 0 ? LogLevel.Info : _a;
4616
+ var logger = new Logger(resolveLogLevel(opts === null || opts === void 0 ? void 0 : opts.logLevel), name);
4617
+ return (function () {
4618
+ var args = [];
4619
+ for (var _i = 0; _i < arguments.length; _i++) {
4620
+ args[_i] = arguments[_i];
4621
+ }
4622
+ var instance = plugin.apply(void 0, args);
4623
+ return function (tree, file) {
4624
+ var start = Date.now();
4625
+ var res = instance(tree, file);
4626
+ var dur = Date.now() - start;
4627
+ logger.log("\u23F1 finished in ".concat(dur, "ms"));
4628
+ return res;
4629
+ };
4630
+ });
4631
+ }
4632
+
4633
+ export { LogLevel, Logger, remarkCodeSections, remarkReplaceMetaUrl, remarkScopedPath, remarkYamlTable, remarkYouTube, resolveLogLevel, timedPlugin };
4634
+ //# sourceMappingURL=plugins.esm.js.map