fumadocs-openapi 10.6.8 → 10.7.1

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