fumadocs-openapi 10.6.8 → 10.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/css/generated/shared.css +0 -1
  2. package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/general/create-limiter.js +43 -0
  3. package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/object/is-object.js +26 -0
  4. package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/object/prevent-pollution.js +33 -0
  5. package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/queue/queue.js +106 -0
  6. package/dist/node_modules/.pnpm/@scalar_helpers@0.4.3/node_modules/@scalar/helpers/dist/string/generate-hash.js +120 -0
  7. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/bundle.js +346 -0
  8. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/fetch-urls/index.js +73 -0
  9. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/node.js +3 -0
  10. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/parse-yaml/index.js +1 -0
  11. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/plugins/read-files/index.js +51 -0
  12. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/bundle/value-generator.js +88 -0
  13. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/convert-to-local-ref.js +24 -0
  14. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/escape-json-pointer.js +11 -0
  15. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/get-schemas.js +44 -0
  16. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/get-segments-from-path.js +10 -0
  17. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/get-value-by-path.js +42 -0
  18. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-file-path.js +23 -0
  19. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-http-url.js +23 -0
  20. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-json-object.js +28 -0
  21. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/is-yaml.js +21 -0
  22. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/normalize.js +26 -0
  23. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/resolve-reference-path.js +30 -0
  24. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/set-value-at-path.js +70 -0
  25. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/to-relative-path.js +33 -0
  26. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.5/node_modules/@scalar/json-magic/dist/helpers/unescape-json-pointer.js +12 -0
  27. package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/2.0-to-3.0/upgrade-from-two-to-three.js +487 -0
  28. package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js +95 -0
  29. package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.js +59 -0
  30. package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/helpers/traverse.js +25 -0
  31. package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.4/node_modules/@scalar/openapi-upgrader/dist/upgrade.js +15 -0
  32. package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/index.js +19 -0
  33. package/dist/node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.js +430 -0
  34. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/compose-collection.js +50 -0
  35. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/compose-doc.js +39 -0
  36. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/compose-node.js +85 -0
  37. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/compose-scalar.js +57 -0
  38. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/composer.js +193 -0
  39. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-block-map.js +82 -0
  40. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +173 -0
  41. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +40 -0
  42. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-end.js +36 -0
  43. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +153 -0
  44. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +204 -0
  45. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/resolve-props.js +105 -0
  46. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/util-contains-newline.js +27 -0
  47. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +25 -0
  48. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +10 -0
  49. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/compose/util-map-includes.js +10 -0
  50. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/Document.js +277 -0
  51. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/anchors.js +57 -0
  52. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/applyReviver.js +38 -0
  53. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/createNode.js +61 -0
  54. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/doc/directives.js +163 -0
  55. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/errors.js +48 -0
  56. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/index.js +16 -0
  57. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/log.js +6 -0
  58. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Alias.js +91 -0
  59. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Collection.js +117 -0
  60. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Node.js +32 -0
  61. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Pair.js +29 -0
  62. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/Scalar.js +24 -0
  63. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/YAMLMap.js +106 -0
  64. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +104 -0
  65. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +49 -0
  66. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/identity.js +33 -0
  67. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/nodes/toJS.js +35 -0
  68. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/cst-scalar.js +3 -0
  69. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/cst-visit.js +89 -0
  70. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/cst.js +40 -0
  71. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/lexer.js +517 -0
  72. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/line-counter.js +45 -0
  73. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/parser.js +852 -0
  74. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/public-api.js +44 -0
  75. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/Schema.js +27 -0
  76. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/common/map.js +16 -0
  77. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/common/null.js +13 -0
  78. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/common/seq.js +16 -0
  79. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/common/string.js +14 -0
  80. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/core/bool.js +17 -0
  81. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/core/float.js +38 -0
  82. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/core/int.js +37 -0
  83. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/core/schema.js +23 -0
  84. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/json/schema.js +61 -0
  85. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/tags.js +81 -0
  86. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/binary.js +44 -0
  87. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/bool.js +24 -0
  88. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +41 -0
  89. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/int.js +70 -0
  90. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/merge.js +36 -0
  91. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +60 -0
  92. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +56 -0
  93. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/schema.js +39 -0
  94. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +65 -0
  95. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/schema/yaml-1.1/timestamp.js +79 -0
  96. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +111 -0
  97. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringify.js +105 -0
  98. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +116 -0
  99. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyComment.js +16 -0
  100. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +59 -0
  101. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyNumber.js +19 -0
  102. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyPair.js +95 -0
  103. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/stringify/stringifyString.js +222 -0
  104. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/visit.js +187 -0
  105. package/dist/node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/index.js +16 -0
  106. package/dist/scalar/client.js +1 -1
  107. package/dist/utils/document/process.js +5 -3
  108. package/package.json +16 -16
@@ -0,0 +1,852 @@
1
+ import { tokenType } from "./cst.js";
2
+ import { Lexer } from "./lexer.js";
3
+ //#region ../../node_modules/.pnpm/yaml@2.8.3/node_modules/yaml/browser/dist/parse/parser.js
4
+ function includesToken(list, type) {
5
+ for (let i = 0; i < list.length; ++i) if (list[i].type === type) return true;
6
+ return false;
7
+ }
8
+ function findNonEmptyIndex(list) {
9
+ for (let i = 0; i < list.length; ++i) switch (list[i].type) {
10
+ case "space":
11
+ case "comment":
12
+ case "newline": break;
13
+ default: return i;
14
+ }
15
+ return -1;
16
+ }
17
+ function isFlowToken(token) {
18
+ switch (token?.type) {
19
+ case "alias":
20
+ case "scalar":
21
+ case "single-quoted-scalar":
22
+ case "double-quoted-scalar":
23
+ case "flow-collection": return true;
24
+ default: return false;
25
+ }
26
+ }
27
+ function getPrevProps(parent) {
28
+ switch (parent.type) {
29
+ case "document": return parent.start;
30
+ case "block-map": {
31
+ const it = parent.items[parent.items.length - 1];
32
+ return it.sep ?? it.start;
33
+ }
34
+ case "block-seq": return parent.items[parent.items.length - 1].start;
35
+ default: return [];
36
+ }
37
+ }
38
+ /** Note: May modify input array */
39
+ function getFirstKeyStartProps(prev) {
40
+ if (prev.length === 0) return [];
41
+ let i = prev.length;
42
+ loop: while (--i >= 0) switch (prev[i].type) {
43
+ case "doc-start":
44
+ case "explicit-key-ind":
45
+ case "map-value-ind":
46
+ case "seq-item-ind":
47
+ case "newline": break loop;
48
+ }
49
+ while (prev[++i]?.type === "space");
50
+ return prev.splice(i, prev.length);
51
+ }
52
+ function fixFlowSeqItems(fc) {
53
+ if (fc.start.type === "flow-seq-start") {
54
+ for (const it of fc.items) if (it.sep && !it.value && !includesToken(it.start, "explicit-key-ind") && !includesToken(it.sep, "map-value-ind")) {
55
+ if (it.key) it.value = it.key;
56
+ delete it.key;
57
+ if (isFlowToken(it.value)) if (it.value.end) Array.prototype.push.apply(it.value.end, it.sep);
58
+ else it.value.end = it.sep;
59
+ else Array.prototype.push.apply(it.start, it.sep);
60
+ delete it.sep;
61
+ }
62
+ }
63
+ }
64
+ /**
65
+ * A YAML concrete syntax tree (CST) parser
66
+ *
67
+ * ```ts
68
+ * const src: string = ...
69
+ * for (const token of new Parser().parse(src)) {
70
+ * // token: Token
71
+ * }
72
+ * ```
73
+ *
74
+ * To use the parser with a user-provided lexer:
75
+ *
76
+ * ```ts
77
+ * function* parse(source: string, lexer: Lexer) {
78
+ * const parser = new Parser()
79
+ * for (const lexeme of lexer.lex(source))
80
+ * yield* parser.next(lexeme)
81
+ * yield* parser.end()
82
+ * }
83
+ *
84
+ * const src: string = ...
85
+ * const lexer = new Lexer()
86
+ * for (const token of parse(src, lexer)) {
87
+ * // token: Token
88
+ * }
89
+ * ```
90
+ */
91
+ var Parser = class {
92
+ /**
93
+ * @param onNewLine - If defined, called separately with the start position of
94
+ * each new line (in `parse()`, including the start of input).
95
+ */
96
+ constructor(onNewLine) {
97
+ /** If true, space and sequence indicators count as indentation */
98
+ this.atNewLine = true;
99
+ /** If true, next token is a scalar value */
100
+ this.atScalar = false;
101
+ /** Current indentation level */
102
+ this.indent = 0;
103
+ /** Current offset since the start of parsing */
104
+ this.offset = 0;
105
+ /** On the same line with a block map key */
106
+ this.onKeyLine = false;
107
+ /** Top indicates the node that's currently being built */
108
+ this.stack = [];
109
+ /** The source of the current token, set in parse() */
110
+ this.source = "";
111
+ /** The type of the current token, set in parse() */
112
+ this.type = "";
113
+ this.lexer = new Lexer();
114
+ this.onNewLine = onNewLine;
115
+ }
116
+ /**
117
+ * Parse `source` as a YAML stream.
118
+ * If `incomplete`, a part of the last line may be left as a buffer for the next call.
119
+ *
120
+ * Errors are not thrown, but yielded as `{ type: 'error', message }` tokens.
121
+ *
122
+ * @returns A generator of tokens representing each directive, document, and other structure.
123
+ */
124
+ *parse(source, incomplete = false) {
125
+ if (this.onNewLine && this.offset === 0) this.onNewLine(0);
126
+ for (const lexeme of this.lexer.lex(source, incomplete)) yield* this.next(lexeme);
127
+ if (!incomplete) yield* this.end();
128
+ }
129
+ /**
130
+ * Advance the parser by the `source` of one lexical token.
131
+ */
132
+ *next(source) {
133
+ this.source = source;
134
+ if (this.atScalar) {
135
+ this.atScalar = false;
136
+ yield* this.step();
137
+ this.offset += source.length;
138
+ return;
139
+ }
140
+ const type = tokenType(source);
141
+ if (!type) {
142
+ const message = `Not a YAML token: ${source}`;
143
+ yield* this.pop({
144
+ type: "error",
145
+ offset: this.offset,
146
+ message,
147
+ source
148
+ });
149
+ this.offset += source.length;
150
+ } else if (type === "scalar") {
151
+ this.atNewLine = false;
152
+ this.atScalar = true;
153
+ this.type = "scalar";
154
+ } else {
155
+ this.type = type;
156
+ yield* this.step();
157
+ switch (type) {
158
+ case "newline":
159
+ this.atNewLine = true;
160
+ this.indent = 0;
161
+ if (this.onNewLine) this.onNewLine(this.offset + source.length);
162
+ break;
163
+ case "space":
164
+ if (this.atNewLine && source[0] === " ") this.indent += source.length;
165
+ break;
166
+ case "explicit-key-ind":
167
+ case "map-value-ind":
168
+ case "seq-item-ind":
169
+ if (this.atNewLine) this.indent += source.length;
170
+ break;
171
+ case "doc-mode":
172
+ case "flow-error-end": return;
173
+ default: this.atNewLine = false;
174
+ }
175
+ this.offset += source.length;
176
+ }
177
+ }
178
+ /** Call at end of input to push out any remaining constructions */
179
+ *end() {
180
+ while (this.stack.length > 0) yield* this.pop();
181
+ }
182
+ get sourceToken() {
183
+ return {
184
+ type: this.type,
185
+ offset: this.offset,
186
+ indent: this.indent,
187
+ source: this.source
188
+ };
189
+ }
190
+ *step() {
191
+ const top = this.peek(1);
192
+ if (this.type === "doc-end" && top?.type !== "doc-end") {
193
+ while (this.stack.length > 0) yield* this.pop();
194
+ this.stack.push({
195
+ type: "doc-end",
196
+ offset: this.offset,
197
+ source: this.source
198
+ });
199
+ return;
200
+ }
201
+ if (!top) return yield* this.stream();
202
+ switch (top.type) {
203
+ case "document": return yield* this.document(top);
204
+ case "alias":
205
+ case "scalar":
206
+ case "single-quoted-scalar":
207
+ case "double-quoted-scalar": return yield* this.scalar(top);
208
+ case "block-scalar": return yield* this.blockScalar(top);
209
+ case "block-map": return yield* this.blockMap(top);
210
+ case "block-seq": return yield* this.blockSequence(top);
211
+ case "flow-collection": return yield* this.flowCollection(top);
212
+ case "doc-end": return yield* this.documentEnd(top);
213
+ }
214
+ /* istanbul ignore next should not happen */
215
+ yield* this.pop();
216
+ }
217
+ peek(n) {
218
+ return this.stack[this.stack.length - n];
219
+ }
220
+ *pop(error) {
221
+ const token = error ?? this.stack.pop();
222
+ /* istanbul ignore if should not happen */
223
+ if (!token) yield {
224
+ type: "error",
225
+ offset: this.offset,
226
+ source: "",
227
+ message: "Tried to pop an empty stack"
228
+ };
229
+ else if (this.stack.length === 0) yield token;
230
+ else {
231
+ const top = this.peek(1);
232
+ if (token.type === "block-scalar") token.indent = "indent" in top ? top.indent : 0;
233
+ else if (token.type === "flow-collection" && top.type === "document") token.indent = 0;
234
+ if (token.type === "flow-collection") fixFlowSeqItems(token);
235
+ switch (top.type) {
236
+ case "document":
237
+ top.value = token;
238
+ break;
239
+ case "block-scalar":
240
+ top.props.push(token);
241
+ break;
242
+ case "block-map": {
243
+ const it = top.items[top.items.length - 1];
244
+ if (it.value) {
245
+ top.items.push({
246
+ start: [],
247
+ key: token,
248
+ sep: []
249
+ });
250
+ this.onKeyLine = true;
251
+ return;
252
+ } else if (it.sep) it.value = token;
253
+ else {
254
+ Object.assign(it, {
255
+ key: token,
256
+ sep: []
257
+ });
258
+ this.onKeyLine = !it.explicitKey;
259
+ return;
260
+ }
261
+ break;
262
+ }
263
+ case "block-seq": {
264
+ const it = top.items[top.items.length - 1];
265
+ if (it.value) top.items.push({
266
+ start: [],
267
+ value: token
268
+ });
269
+ else it.value = token;
270
+ break;
271
+ }
272
+ case "flow-collection": {
273
+ const it = top.items[top.items.length - 1];
274
+ if (!it || it.value) top.items.push({
275
+ start: [],
276
+ key: token,
277
+ sep: []
278
+ });
279
+ else if (it.sep) it.value = token;
280
+ else Object.assign(it, {
281
+ key: token,
282
+ sep: []
283
+ });
284
+ return;
285
+ }
286
+ default:
287
+ yield* this.pop();
288
+ yield* this.pop(token);
289
+ }
290
+ if ((top.type === "document" || top.type === "block-map" || top.type === "block-seq") && (token.type === "block-map" || token.type === "block-seq")) {
291
+ const last = token.items[token.items.length - 1];
292
+ if (last && !last.sep && !last.value && last.start.length > 0 && findNonEmptyIndex(last.start) === -1 && (token.indent === 0 || last.start.every((st) => st.type !== "comment" || st.indent < token.indent))) {
293
+ if (top.type === "document") top.end = last.start;
294
+ else top.items.push({ start: last.start });
295
+ token.items.splice(-1, 1);
296
+ }
297
+ }
298
+ }
299
+ }
300
+ *stream() {
301
+ switch (this.type) {
302
+ case "directive-line":
303
+ yield {
304
+ type: "directive",
305
+ offset: this.offset,
306
+ source: this.source
307
+ };
308
+ return;
309
+ case "byte-order-mark":
310
+ case "space":
311
+ case "comment":
312
+ case "newline":
313
+ yield this.sourceToken;
314
+ return;
315
+ case "doc-mode":
316
+ case "doc-start": {
317
+ const doc = {
318
+ type: "document",
319
+ offset: this.offset,
320
+ start: []
321
+ };
322
+ if (this.type === "doc-start") doc.start.push(this.sourceToken);
323
+ this.stack.push(doc);
324
+ return;
325
+ }
326
+ }
327
+ yield {
328
+ type: "error",
329
+ offset: this.offset,
330
+ message: `Unexpected ${this.type} token in YAML stream`,
331
+ source: this.source
332
+ };
333
+ }
334
+ *document(doc) {
335
+ if (doc.value) return yield* this.lineEnd(doc);
336
+ switch (this.type) {
337
+ case "doc-start":
338
+ if (findNonEmptyIndex(doc.start) !== -1) {
339
+ yield* this.pop();
340
+ yield* this.step();
341
+ } else doc.start.push(this.sourceToken);
342
+ return;
343
+ case "anchor":
344
+ case "tag":
345
+ case "space":
346
+ case "comment":
347
+ case "newline":
348
+ doc.start.push(this.sourceToken);
349
+ return;
350
+ }
351
+ const bv = this.startBlockValue(doc);
352
+ if (bv) this.stack.push(bv);
353
+ else yield {
354
+ type: "error",
355
+ offset: this.offset,
356
+ message: `Unexpected ${this.type} token in YAML document`,
357
+ source: this.source
358
+ };
359
+ }
360
+ *scalar(scalar) {
361
+ if (this.type === "map-value-ind") {
362
+ const start = getFirstKeyStartProps(getPrevProps(this.peek(2)));
363
+ let sep;
364
+ if (scalar.end) {
365
+ sep = scalar.end;
366
+ sep.push(this.sourceToken);
367
+ delete scalar.end;
368
+ } else sep = [this.sourceToken];
369
+ const map = {
370
+ type: "block-map",
371
+ offset: scalar.offset,
372
+ indent: scalar.indent,
373
+ items: [{
374
+ start,
375
+ key: scalar,
376
+ sep
377
+ }]
378
+ };
379
+ this.onKeyLine = true;
380
+ this.stack[this.stack.length - 1] = map;
381
+ } else yield* this.lineEnd(scalar);
382
+ }
383
+ *blockScalar(scalar) {
384
+ switch (this.type) {
385
+ case "space":
386
+ case "comment":
387
+ case "newline":
388
+ scalar.props.push(this.sourceToken);
389
+ return;
390
+ case "scalar":
391
+ scalar.source = this.source;
392
+ this.atNewLine = true;
393
+ this.indent = 0;
394
+ if (this.onNewLine) {
395
+ let nl = this.source.indexOf("\n") + 1;
396
+ while (nl !== 0) {
397
+ this.onNewLine(this.offset + nl);
398
+ nl = this.source.indexOf("\n", nl) + 1;
399
+ }
400
+ }
401
+ yield* this.pop();
402
+ break;
403
+ default:
404
+ yield* this.pop();
405
+ yield* this.step();
406
+ }
407
+ }
408
+ *blockMap(map) {
409
+ const it = map.items[map.items.length - 1];
410
+ switch (this.type) {
411
+ case "newline":
412
+ this.onKeyLine = false;
413
+ if (it.value) {
414
+ const end = "end" in it.value ? it.value.end : void 0;
415
+ if ((Array.isArray(end) ? end[end.length - 1] : void 0)?.type === "comment") end?.push(this.sourceToken);
416
+ else map.items.push({ start: [this.sourceToken] });
417
+ } else if (it.sep) it.sep.push(this.sourceToken);
418
+ else it.start.push(this.sourceToken);
419
+ return;
420
+ case "space":
421
+ case "comment":
422
+ if (it.value) map.items.push({ start: [this.sourceToken] });
423
+ else if (it.sep) it.sep.push(this.sourceToken);
424
+ else {
425
+ if (this.atIndentedComment(it.start, map.indent)) {
426
+ const end = map.items[map.items.length - 2]?.value?.end;
427
+ if (Array.isArray(end)) {
428
+ Array.prototype.push.apply(end, it.start);
429
+ end.push(this.sourceToken);
430
+ map.items.pop();
431
+ return;
432
+ }
433
+ }
434
+ it.start.push(this.sourceToken);
435
+ }
436
+ return;
437
+ }
438
+ if (this.indent >= map.indent) {
439
+ const atMapIndent = !this.onKeyLine && this.indent === map.indent;
440
+ const atNextItem = atMapIndent && (it.sep || it.explicitKey) && this.type !== "seq-item-ind";
441
+ let start = [];
442
+ if (atNextItem && it.sep && !it.value) {
443
+ const nl = [];
444
+ for (let i = 0; i < it.sep.length; ++i) {
445
+ const st = it.sep[i];
446
+ switch (st.type) {
447
+ case "newline":
448
+ nl.push(i);
449
+ break;
450
+ case "space": break;
451
+ case "comment":
452
+ if (st.indent > map.indent) nl.length = 0;
453
+ break;
454
+ default: nl.length = 0;
455
+ }
456
+ }
457
+ if (nl.length >= 2) start = it.sep.splice(nl[1]);
458
+ }
459
+ switch (this.type) {
460
+ case "anchor":
461
+ case "tag":
462
+ if (atNextItem || it.value) {
463
+ start.push(this.sourceToken);
464
+ map.items.push({ start });
465
+ this.onKeyLine = true;
466
+ } else if (it.sep) it.sep.push(this.sourceToken);
467
+ else it.start.push(this.sourceToken);
468
+ return;
469
+ case "explicit-key-ind":
470
+ if (!it.sep && !it.explicitKey) {
471
+ it.start.push(this.sourceToken);
472
+ it.explicitKey = true;
473
+ } else if (atNextItem || it.value) {
474
+ start.push(this.sourceToken);
475
+ map.items.push({
476
+ start,
477
+ explicitKey: true
478
+ });
479
+ } else this.stack.push({
480
+ type: "block-map",
481
+ offset: this.offset,
482
+ indent: this.indent,
483
+ items: [{
484
+ start: [this.sourceToken],
485
+ explicitKey: true
486
+ }]
487
+ });
488
+ this.onKeyLine = true;
489
+ return;
490
+ case "map-value-ind":
491
+ if (it.explicitKey) if (!it.sep) if (includesToken(it.start, "newline")) Object.assign(it, {
492
+ key: null,
493
+ sep: [this.sourceToken]
494
+ });
495
+ else {
496
+ const start = getFirstKeyStartProps(it.start);
497
+ this.stack.push({
498
+ type: "block-map",
499
+ offset: this.offset,
500
+ indent: this.indent,
501
+ items: [{
502
+ start,
503
+ key: null,
504
+ sep: [this.sourceToken]
505
+ }]
506
+ });
507
+ }
508
+ else if (it.value) map.items.push({
509
+ start: [],
510
+ key: null,
511
+ sep: [this.sourceToken]
512
+ });
513
+ else if (includesToken(it.sep, "map-value-ind")) this.stack.push({
514
+ type: "block-map",
515
+ offset: this.offset,
516
+ indent: this.indent,
517
+ items: [{
518
+ start,
519
+ key: null,
520
+ sep: [this.sourceToken]
521
+ }]
522
+ });
523
+ else if (isFlowToken(it.key) && !includesToken(it.sep, "newline")) {
524
+ const start = getFirstKeyStartProps(it.start);
525
+ const key = it.key;
526
+ const sep = it.sep;
527
+ sep.push(this.sourceToken);
528
+ delete it.key;
529
+ delete it.sep;
530
+ this.stack.push({
531
+ type: "block-map",
532
+ offset: this.offset,
533
+ indent: this.indent,
534
+ items: [{
535
+ start,
536
+ key,
537
+ sep
538
+ }]
539
+ });
540
+ } else if (start.length > 0) it.sep = it.sep.concat(start, this.sourceToken);
541
+ else it.sep.push(this.sourceToken);
542
+ else if (!it.sep) Object.assign(it, {
543
+ key: null,
544
+ sep: [this.sourceToken]
545
+ });
546
+ else if (it.value || atNextItem) map.items.push({
547
+ start,
548
+ key: null,
549
+ sep: [this.sourceToken]
550
+ });
551
+ else if (includesToken(it.sep, "map-value-ind")) this.stack.push({
552
+ type: "block-map",
553
+ offset: this.offset,
554
+ indent: this.indent,
555
+ items: [{
556
+ start: [],
557
+ key: null,
558
+ sep: [this.sourceToken]
559
+ }]
560
+ });
561
+ else it.sep.push(this.sourceToken);
562
+ this.onKeyLine = true;
563
+ return;
564
+ case "alias":
565
+ case "scalar":
566
+ case "single-quoted-scalar":
567
+ case "double-quoted-scalar": {
568
+ const fs = this.flowScalar(this.type);
569
+ if (atNextItem || it.value) {
570
+ map.items.push({
571
+ start,
572
+ key: fs,
573
+ sep: []
574
+ });
575
+ this.onKeyLine = true;
576
+ } else if (it.sep) this.stack.push(fs);
577
+ else {
578
+ Object.assign(it, {
579
+ key: fs,
580
+ sep: []
581
+ });
582
+ this.onKeyLine = true;
583
+ }
584
+ return;
585
+ }
586
+ default: {
587
+ const bv = this.startBlockValue(map);
588
+ if (bv) {
589
+ if (bv.type === "block-seq") {
590
+ if (!it.explicitKey && it.sep && !includesToken(it.sep, "newline")) {
591
+ yield* this.pop({
592
+ type: "error",
593
+ offset: this.offset,
594
+ message: "Unexpected block-seq-ind on same line with key",
595
+ source: this.source
596
+ });
597
+ return;
598
+ }
599
+ } else if (atMapIndent) map.items.push({ start });
600
+ this.stack.push(bv);
601
+ return;
602
+ }
603
+ }
604
+ }
605
+ }
606
+ yield* this.pop();
607
+ yield* this.step();
608
+ }
609
+ *blockSequence(seq) {
610
+ const it = seq.items[seq.items.length - 1];
611
+ switch (this.type) {
612
+ case "newline":
613
+ if (it.value) {
614
+ const end = "end" in it.value ? it.value.end : void 0;
615
+ if ((Array.isArray(end) ? end[end.length - 1] : void 0)?.type === "comment") end?.push(this.sourceToken);
616
+ else seq.items.push({ start: [this.sourceToken] });
617
+ } else it.start.push(this.sourceToken);
618
+ return;
619
+ case "space":
620
+ case "comment":
621
+ if (it.value) seq.items.push({ start: [this.sourceToken] });
622
+ else {
623
+ if (this.atIndentedComment(it.start, seq.indent)) {
624
+ const end = seq.items[seq.items.length - 2]?.value?.end;
625
+ if (Array.isArray(end)) {
626
+ Array.prototype.push.apply(end, it.start);
627
+ end.push(this.sourceToken);
628
+ seq.items.pop();
629
+ return;
630
+ }
631
+ }
632
+ it.start.push(this.sourceToken);
633
+ }
634
+ return;
635
+ case "anchor":
636
+ case "tag":
637
+ if (it.value || this.indent <= seq.indent) break;
638
+ it.start.push(this.sourceToken);
639
+ return;
640
+ case "seq-item-ind":
641
+ if (this.indent !== seq.indent) break;
642
+ if (it.value || includesToken(it.start, "seq-item-ind")) seq.items.push({ start: [this.sourceToken] });
643
+ else it.start.push(this.sourceToken);
644
+ return;
645
+ }
646
+ if (this.indent > seq.indent) {
647
+ const bv = this.startBlockValue(seq);
648
+ if (bv) {
649
+ this.stack.push(bv);
650
+ return;
651
+ }
652
+ }
653
+ yield* this.pop();
654
+ yield* this.step();
655
+ }
656
+ *flowCollection(fc) {
657
+ const it = fc.items[fc.items.length - 1];
658
+ if (this.type === "flow-error-end") {
659
+ let top;
660
+ do {
661
+ yield* this.pop();
662
+ top = this.peek(1);
663
+ } while (top?.type === "flow-collection");
664
+ } else if (fc.end.length === 0) {
665
+ switch (this.type) {
666
+ case "comma":
667
+ case "explicit-key-ind":
668
+ if (!it || it.sep) fc.items.push({ start: [this.sourceToken] });
669
+ else it.start.push(this.sourceToken);
670
+ return;
671
+ case "map-value-ind":
672
+ if (!it || it.value) fc.items.push({
673
+ start: [],
674
+ key: null,
675
+ sep: [this.sourceToken]
676
+ });
677
+ else if (it.sep) it.sep.push(this.sourceToken);
678
+ else Object.assign(it, {
679
+ key: null,
680
+ sep: [this.sourceToken]
681
+ });
682
+ return;
683
+ case "space":
684
+ case "comment":
685
+ case "newline":
686
+ case "anchor":
687
+ case "tag":
688
+ if (!it || it.value) fc.items.push({ start: [this.sourceToken] });
689
+ else if (it.sep) it.sep.push(this.sourceToken);
690
+ else it.start.push(this.sourceToken);
691
+ return;
692
+ case "alias":
693
+ case "scalar":
694
+ case "single-quoted-scalar":
695
+ case "double-quoted-scalar": {
696
+ const fs = this.flowScalar(this.type);
697
+ if (!it || it.value) fc.items.push({
698
+ start: [],
699
+ key: fs,
700
+ sep: []
701
+ });
702
+ else if (it.sep) this.stack.push(fs);
703
+ else Object.assign(it, {
704
+ key: fs,
705
+ sep: []
706
+ });
707
+ return;
708
+ }
709
+ case "flow-map-end":
710
+ case "flow-seq-end":
711
+ fc.end.push(this.sourceToken);
712
+ return;
713
+ }
714
+ const bv = this.startBlockValue(fc);
715
+ /* istanbul ignore else should not happen */
716
+ if (bv) this.stack.push(bv);
717
+ else {
718
+ yield* this.pop();
719
+ yield* this.step();
720
+ }
721
+ } else {
722
+ const parent = this.peek(2);
723
+ if (parent.type === "block-map" && (this.type === "map-value-ind" && parent.indent === fc.indent || this.type === "newline" && !parent.items[parent.items.length - 1].sep)) {
724
+ yield* this.pop();
725
+ yield* this.step();
726
+ } else if (this.type === "map-value-ind" && parent.type !== "flow-collection") {
727
+ const start = getFirstKeyStartProps(getPrevProps(parent));
728
+ fixFlowSeqItems(fc);
729
+ const sep = fc.end.splice(1, fc.end.length);
730
+ sep.push(this.sourceToken);
731
+ const map = {
732
+ type: "block-map",
733
+ offset: fc.offset,
734
+ indent: fc.indent,
735
+ items: [{
736
+ start,
737
+ key: fc,
738
+ sep
739
+ }]
740
+ };
741
+ this.onKeyLine = true;
742
+ this.stack[this.stack.length - 1] = map;
743
+ } else yield* this.lineEnd(fc);
744
+ }
745
+ }
746
+ flowScalar(type) {
747
+ if (this.onNewLine) {
748
+ let nl = this.source.indexOf("\n") + 1;
749
+ while (nl !== 0) {
750
+ this.onNewLine(this.offset + nl);
751
+ nl = this.source.indexOf("\n", nl) + 1;
752
+ }
753
+ }
754
+ return {
755
+ type,
756
+ offset: this.offset,
757
+ indent: this.indent,
758
+ source: this.source
759
+ };
760
+ }
761
+ startBlockValue(parent) {
762
+ switch (this.type) {
763
+ case "alias":
764
+ case "scalar":
765
+ case "single-quoted-scalar":
766
+ case "double-quoted-scalar": return this.flowScalar(this.type);
767
+ case "block-scalar-header": return {
768
+ type: "block-scalar",
769
+ offset: this.offset,
770
+ indent: this.indent,
771
+ props: [this.sourceToken],
772
+ source: ""
773
+ };
774
+ case "flow-map-start":
775
+ case "flow-seq-start": return {
776
+ type: "flow-collection",
777
+ offset: this.offset,
778
+ indent: this.indent,
779
+ start: this.sourceToken,
780
+ items: [],
781
+ end: []
782
+ };
783
+ case "seq-item-ind": return {
784
+ type: "block-seq",
785
+ offset: this.offset,
786
+ indent: this.indent,
787
+ items: [{ start: [this.sourceToken] }]
788
+ };
789
+ case "explicit-key-ind": {
790
+ this.onKeyLine = true;
791
+ const start = getFirstKeyStartProps(getPrevProps(parent));
792
+ start.push(this.sourceToken);
793
+ return {
794
+ type: "block-map",
795
+ offset: this.offset,
796
+ indent: this.indent,
797
+ items: [{
798
+ start,
799
+ explicitKey: true
800
+ }]
801
+ };
802
+ }
803
+ case "map-value-ind": {
804
+ this.onKeyLine = true;
805
+ const start = getFirstKeyStartProps(getPrevProps(parent));
806
+ return {
807
+ type: "block-map",
808
+ offset: this.offset,
809
+ indent: this.indent,
810
+ items: [{
811
+ start,
812
+ key: null,
813
+ sep: [this.sourceToken]
814
+ }]
815
+ };
816
+ }
817
+ }
818
+ return null;
819
+ }
820
+ atIndentedComment(start, indent) {
821
+ if (this.type !== "comment") return false;
822
+ if (this.indent <= indent) return false;
823
+ return start.every((st) => st.type === "newline" || st.type === "space");
824
+ }
825
+ *documentEnd(docEnd) {
826
+ if (this.type !== "doc-mode") {
827
+ if (docEnd.end) docEnd.end.push(this.sourceToken);
828
+ else docEnd.end = [this.sourceToken];
829
+ if (this.type === "newline") yield* this.pop();
830
+ }
831
+ }
832
+ *lineEnd(token) {
833
+ switch (this.type) {
834
+ case "comma":
835
+ case "doc-start":
836
+ case "doc-end":
837
+ case "flow-seq-end":
838
+ case "flow-map-end":
839
+ case "map-value-ind":
840
+ yield* this.pop();
841
+ yield* this.step();
842
+ break;
843
+ case "newline": this.onKeyLine = false;
844
+ default:
845
+ if (token.end) token.end.push(this.sourceToken);
846
+ else token.end = [this.sourceToken];
847
+ if (this.type === "newline") yield* this.pop();
848
+ }
849
+ }
850
+ };
851
+ //#endregion
852
+ export { Parser };