@mcpc-tech/plugin-markdown-loader 0.0.11 → 0.0.12

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 (3) hide show
  1. package/index.cjs +197 -161
  2. package/index.mjs +200 -161
  3. package/package.json +1 -1
package/index.mjs CHANGED
@@ -1,3 +1,6 @@
1
+ import { createRequire } from 'node:module';
2
+ const require = createRequire(import.meta.url);
3
+
1
4
  // __mcpc__plugin-markdown-loader_latest/node_modules/@mcpc/plugin-markdown-loader/src/markdown-loader.js
2
5
  import { readdir, readFile, stat } from "node:fs/promises";
3
6
 
@@ -839,12 +842,29 @@ function writeFoldedLines(count) {
839
842
  if (count > 1) return "\n".repeat(count - 1);
840
843
  return "";
841
844
  }
845
+ var Scanner = class {
846
+ source;
847
+ #length;
848
+ position = 0;
849
+ constructor(source) {
850
+ source += "\0";
851
+ this.source = source;
852
+ this.#length = source.length;
853
+ }
854
+ peek(offset = 0) {
855
+ return this.source.charCodeAt(this.position + offset);
856
+ }
857
+ next() {
858
+ this.position += 1;
859
+ }
860
+ eof() {
861
+ return this.position >= this.#length - 1;
862
+ }
863
+ };
842
864
  var LoaderState = class {
843
- input;
844
- length;
865
+ #scanner;
845
866
  lineIndent = 0;
846
867
  lineStart = 0;
847
- position = 0;
848
868
  line = 0;
849
869
  onWarning;
850
870
  allowDuplicateKeys;
@@ -854,44 +874,40 @@ var LoaderState = class {
854
874
  tagMap = /* @__PURE__ */ new Map();
855
875
  anchorMap = /* @__PURE__ */ new Map();
856
876
  constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
857
- this.input = input;
877
+ this.#scanner = new Scanner(input);
858
878
  this.onWarning = onWarning;
859
879
  this.allowDuplicateKeys = allowDuplicateKeys;
860
880
  this.implicitTypes = schema.implicitTypes;
861
881
  this.typeMap = schema.typeMap;
862
- this.length = input.length;
863
882
  this.readIndent();
864
883
  }
865
884
  skipWhitespaces() {
866
- let ch = this.peek();
885
+ let ch = this.#scanner.peek();
867
886
  while (isWhiteSpace(ch)) {
868
- ch = this.next();
887
+ this.#scanner.next();
888
+ ch = this.#scanner.peek();
869
889
  }
870
890
  }
871
891
  skipComment() {
872
- let ch = this.peek();
892
+ let ch = this.#scanner.peek();
873
893
  if (ch !== SHARP) return;
874
- ch = this.next();
894
+ this.#scanner.next();
895
+ ch = this.#scanner.peek();
875
896
  while (ch !== 0 && !isEOL(ch)) {
876
- ch = this.next();
897
+ this.#scanner.next();
898
+ ch = this.#scanner.peek();
877
899
  }
878
900
  }
879
901
  readIndent() {
880
- let char = this.peek();
881
- while (char === SPACE) {
902
+ let ch = this.#scanner.peek();
903
+ while (ch === SPACE) {
882
904
  this.lineIndent += 1;
883
- char = this.next();
905
+ this.#scanner.next();
906
+ ch = this.#scanner.peek();
884
907
  }
885
908
  }
886
- peek(offset = 0) {
887
- return this.input.charCodeAt(this.position + offset);
888
- }
889
- next() {
890
- this.position += 1;
891
- return this.peek();
892
- }
893
909
  #createError(message) {
894
- const mark = markToString(this.input, this.position, this.line, this.position - this.lineStart);
910
+ const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
895
911
  return new SyntaxError(`${message} ${mark}`);
896
912
  }
897
913
  dispatchWarning(message) {
@@ -936,7 +952,7 @@ var LoaderState = class {
936
952
  }
937
953
  captureSegment(start, end, checkJson) {
938
954
  if (start < end) {
939
- const result = this.input.slice(start, end);
955
+ const result = this.#scanner.source.slice(start, end);
940
956
  if (checkJson) {
941
957
  for (let position = 0; position < result.length; position++) {
942
958
  const character = result.charCodeAt(position);
@@ -954,21 +970,21 @@ var LoaderState = class {
954
970
  let detected = false;
955
971
  const result = [];
956
972
  if (anchor !== null) this.anchorMap.set(anchor, result);
957
- let ch = this.peek();
973
+ let ch = this.#scanner.peek();
958
974
  while (ch !== 0) {
959
975
  if (ch !== MINUS) {
960
976
  break;
961
977
  }
962
- const following = this.peek(1);
978
+ const following = this.#scanner.peek(1);
963
979
  if (!isWhiteSpaceOrEOL(following)) {
964
980
  break;
965
981
  }
966
982
  detected = true;
967
- this.position++;
983
+ this.#scanner.next();
968
984
  if (this.skipSeparationSpace(true, -1)) {
969
985
  if (this.lineIndent <= nodeIndent) {
970
986
  result.push(null);
971
- ch = this.peek();
987
+ ch = this.#scanner.peek();
972
988
  continue;
973
989
  }
974
990
  }
@@ -981,7 +997,7 @@ var LoaderState = class {
981
997
  });
982
998
  if (newState) result.push(newState.result);
983
999
  this.skipSeparationSpace(true, -1);
984
- ch = this.peek();
1000
+ ch = this.#scanner.peek();
985
1001
  if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
986
1002
  throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
987
1003
  } else if (this.lineIndent < nodeIndent) {
@@ -1037,7 +1053,7 @@ var LoaderState = class {
1037
1053
  } else {
1038
1054
  if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
1039
1055
  this.line = startLine || this.line;
1040
- this.position = startPos || this.position;
1056
+ this.#scanner.position = startPos || this.#scanner.position;
1041
1057
  throw this.#createError("Cannot store mapping pair: duplicated key");
1042
1058
  }
1043
1059
  Object.defineProperty(result, keyNode, {
@@ -1051,37 +1067,37 @@ var LoaderState = class {
1051
1067
  return result;
1052
1068
  }
1053
1069
  readLineBreak() {
1054
- const ch = this.peek();
1070
+ const ch = this.#scanner.peek();
1055
1071
  if (ch === LINE_FEED) {
1056
- this.position++;
1072
+ this.#scanner.next();
1057
1073
  } else if (ch === CARRIAGE_RETURN) {
1058
- this.position++;
1059
- if (this.peek() === LINE_FEED) {
1060
- this.position++;
1074
+ this.#scanner.next();
1075
+ if (this.#scanner.peek() === LINE_FEED) {
1076
+ this.#scanner.next();
1061
1077
  }
1062
1078
  } else {
1063
1079
  throw this.#createError("Cannot read line: line break not found");
1064
1080
  }
1065
1081
  this.line += 1;
1066
- this.lineStart = this.position;
1082
+ this.lineStart = this.#scanner.position;
1067
1083
  }
1068
1084
  skipSeparationSpace(allowComments, checkIndent) {
1069
1085
  let lineBreaks = 0;
1070
- let ch = this.peek();
1086
+ let ch = this.#scanner.peek();
1071
1087
  while (ch !== 0) {
1072
1088
  this.skipWhitespaces();
1073
- ch = this.peek();
1089
+ ch = this.#scanner.peek();
1074
1090
  if (allowComments) {
1075
1091
  this.skipComment();
1076
- ch = this.peek();
1092
+ ch = this.#scanner.peek();
1077
1093
  }
1078
1094
  if (isEOL(ch)) {
1079
1095
  this.readLineBreak();
1080
- ch = this.peek();
1096
+ ch = this.#scanner.peek();
1081
1097
  lineBreaks++;
1082
1098
  this.lineIndent = 0;
1083
1099
  this.readIndent();
1084
- ch = this.peek();
1100
+ ch = this.#scanner.peek();
1085
1101
  } else {
1086
1102
  break;
1087
1103
  }
@@ -1092,9 +1108,9 @@ var LoaderState = class {
1092
1108
  return lineBreaks;
1093
1109
  }
1094
1110
  testDocumentSeparator() {
1095
- let ch = this.peek();
1096
- if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
1097
- ch = this.peek(3);
1111
+ let ch = this.#scanner.peek();
1112
+ if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
1113
+ ch = this.#scanner.peek(3);
1098
1114
  if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
1099
1115
  return true;
1100
1116
  }
@@ -1102,34 +1118,34 @@ var LoaderState = class {
1102
1118
  return false;
1103
1119
  }
1104
1120
  readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
1105
- let ch = this.peek();
1121
+ let ch = this.#scanner.peek();
1106
1122
  if (isWhiteSpaceOrEOL(ch) || isFlowIndicator(ch) || ch === SHARP || ch === AMPERSAND || ch === ASTERISK || ch === EXCLAMATION || ch === VERTICAL_LINE || ch === GREATER_THAN || ch === SINGLE_QUOTE || ch === DOUBLE_QUOTE || ch === PERCENT || ch === COMMERCIAL_AT || ch === GRAVE_ACCENT) {
1107
1123
  return;
1108
1124
  }
1109
1125
  let following;
1110
1126
  if (ch === QUESTION || ch === MINUS) {
1111
- following = this.peek(1);
1127
+ following = this.#scanner.peek(1);
1112
1128
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
1113
1129
  return;
1114
1130
  }
1115
1131
  }
1116
1132
  let result = "";
1117
- let captureEnd = this.position;
1118
- let captureStart = this.position;
1133
+ let captureEnd = this.#scanner.position;
1134
+ let captureStart = this.#scanner.position;
1119
1135
  let hasPendingContent = false;
1120
1136
  let line = 0;
1121
1137
  while (ch !== 0) {
1122
1138
  if (ch === COLON) {
1123
- following = this.peek(1);
1139
+ following = this.#scanner.peek(1);
1124
1140
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
1125
1141
  break;
1126
1142
  }
1127
1143
  } else if (ch === SHARP) {
1128
- const preceding = this.peek(-1);
1144
+ const preceding = this.#scanner.peek(-1);
1129
1145
  if (isWhiteSpaceOrEOL(preceding)) {
1130
1146
  break;
1131
1147
  }
1132
- } else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
1148
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
1133
1149
  break;
1134
1150
  } else if (isEOL(ch)) {
1135
1151
  line = this.line;
@@ -1138,10 +1154,10 @@ var LoaderState = class {
1138
1154
  this.skipSeparationSpace(false, -1);
1139
1155
  if (this.lineIndent >= nodeIndent) {
1140
1156
  hasPendingContent = true;
1141
- ch = this.peek();
1157
+ ch = this.#scanner.peek();
1142
1158
  continue;
1143
1159
  } else {
1144
- this.position = captureEnd;
1160
+ this.#scanner.position = captureEnd;
1145
1161
  this.line = line;
1146
1162
  this.lineStart = lineStart;
1147
1163
  this.lineIndent = lineIndent;
@@ -1152,13 +1168,14 @@ var LoaderState = class {
1152
1168
  const segment2 = this.captureSegment(captureStart, captureEnd, false);
1153
1169
  if (segment2) result += segment2;
1154
1170
  result += writeFoldedLines(this.line - line);
1155
- captureStart = captureEnd = this.position;
1171
+ captureStart = captureEnd = this.#scanner.position;
1156
1172
  hasPendingContent = false;
1157
1173
  }
1158
1174
  if (!isWhiteSpace(ch)) {
1159
- captureEnd = this.position + 1;
1175
+ captureEnd = this.#scanner.position + 1;
1160
1176
  }
1161
- ch = this.next();
1177
+ this.#scanner.next();
1178
+ ch = this.#scanner.peek();
1162
1179
  }
1163
1180
  const segment = this.captureSegment(captureStart, captureEnd, false);
1164
1181
  if (segment) result += segment;
@@ -1171,22 +1188,23 @@ var LoaderState = class {
1171
1188
  };
1172
1189
  }
1173
1190
  readSingleQuotedScalar(tag, anchor, nodeIndent) {
1174
- let ch = this.peek();
1191
+ let ch = this.#scanner.peek();
1175
1192
  if (ch !== SINGLE_QUOTE) return;
1176
1193
  let result = "";
1177
- this.position++;
1178
- let captureStart = this.position;
1179
- let captureEnd = this.position;
1180
- ch = this.peek();
1194
+ this.#scanner.next();
1195
+ let captureStart = this.#scanner.position;
1196
+ let captureEnd = this.#scanner.position;
1197
+ ch = this.#scanner.peek();
1181
1198
  while (ch !== 0) {
1182
1199
  if (ch === SINGLE_QUOTE) {
1183
- const segment = this.captureSegment(captureStart, this.position, true);
1200
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
1184
1201
  if (segment) result += segment;
1185
- ch = this.next();
1202
+ this.#scanner.next();
1203
+ ch = this.#scanner.peek();
1186
1204
  if (ch === SINGLE_QUOTE) {
1187
- captureStart = this.position;
1188
- this.position++;
1189
- captureEnd = this.position;
1205
+ captureStart = this.#scanner.position;
1206
+ this.#scanner.next();
1207
+ captureEnd = this.#scanner.position;
1190
1208
  } else {
1191
1209
  if (anchor !== null) this.anchorMap.set(anchor, result);
1192
1210
  return {
@@ -1200,31 +1218,31 @@ var LoaderState = class {
1200
1218
  const segment = this.captureSegment(captureStart, captureEnd, true);
1201
1219
  if (segment) result += segment;
1202
1220
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
1203
- captureStart = captureEnd = this.position;
1204
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
1221
+ captureStart = captureEnd = this.#scanner.position;
1222
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
1205
1223
  throw this.#createError("Unexpected end of the document within a single quoted scalar");
1206
1224
  } else {
1207
- this.position++;
1208
- captureEnd = this.position;
1225
+ this.#scanner.next();
1226
+ captureEnd = this.#scanner.position;
1209
1227
  }
1210
- ch = this.peek();
1228
+ ch = this.#scanner.peek();
1211
1229
  }
1212
1230
  throw this.#createError("Unexpected end of the stream within a single quoted scalar");
1213
1231
  }
1214
1232
  readDoubleQuotedScalar(tag, anchor, nodeIndent) {
1215
- let ch = this.peek();
1233
+ let ch = this.#scanner.peek();
1216
1234
  if (ch !== DOUBLE_QUOTE) return;
1217
1235
  let result = "";
1218
- this.position++;
1219
- let captureEnd = this.position;
1220
- let captureStart = this.position;
1236
+ this.#scanner.next();
1237
+ let captureEnd = this.#scanner.position;
1238
+ let captureStart = this.#scanner.position;
1221
1239
  let tmp;
1222
- ch = this.peek();
1240
+ ch = this.#scanner.peek();
1223
1241
  while (ch !== 0) {
1224
1242
  if (ch === DOUBLE_QUOTE) {
1225
- const segment = this.captureSegment(captureStart, this.position, true);
1243
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
1226
1244
  if (segment) result += segment;
1227
- this.position++;
1245
+ this.#scanner.next();
1228
1246
  if (anchor !== null) this.anchorMap.set(anchor, result);
1229
1247
  return {
1230
1248
  tag,
@@ -1234,19 +1252,21 @@ var LoaderState = class {
1234
1252
  };
1235
1253
  }
1236
1254
  if (ch === BACKSLASH) {
1237
- const segment = this.captureSegment(captureStart, this.position, true);
1255
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
1238
1256
  if (segment) result += segment;
1239
- ch = this.next();
1257
+ this.#scanner.next();
1258
+ ch = this.#scanner.peek();
1240
1259
  if (isEOL(ch)) {
1241
1260
  this.skipSeparationSpace(false, nodeIndent);
1242
1261
  } else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
1243
1262
  result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
1244
- this.position++;
1263
+ this.#scanner.next();
1245
1264
  } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
1246
1265
  let hexLength = tmp;
1247
1266
  let hexResult = 0;
1248
1267
  for (; hexLength > 0; hexLength--) {
1249
- ch = this.next();
1268
+ this.#scanner.next();
1269
+ ch = this.#scanner.peek();
1250
1270
  if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
1251
1271
  hexResult = (hexResult << 4) + tmp;
1252
1272
  } else {
@@ -1254,28 +1274,28 @@ var LoaderState = class {
1254
1274
  }
1255
1275
  }
1256
1276
  result += codepointToChar(hexResult);
1257
- this.position++;
1277
+ this.#scanner.next();
1258
1278
  } else {
1259
1279
  throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
1260
1280
  }
1261
- captureStart = captureEnd = this.position;
1281
+ captureStart = captureEnd = this.#scanner.position;
1262
1282
  } else if (isEOL(ch)) {
1263
1283
  const segment = this.captureSegment(captureStart, captureEnd, true);
1264
1284
  if (segment) result += segment;
1265
1285
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
1266
- captureStart = captureEnd = this.position;
1267
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
1286
+ captureStart = captureEnd = this.#scanner.position;
1287
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
1268
1288
  throw this.#createError("Unexpected end of the document within a double quoted scalar");
1269
1289
  } else {
1270
- this.position++;
1271
- captureEnd = this.position;
1290
+ this.#scanner.next();
1291
+ captureEnd = this.#scanner.position;
1272
1292
  }
1273
- ch = this.peek();
1293
+ ch = this.#scanner.peek();
1274
1294
  }
1275
1295
  throw this.#createError("Unexpected end of the stream within a double quoted scalar");
1276
1296
  }
1277
1297
  readFlowCollection(tag, anchor, nodeIndent) {
1278
- let ch = this.peek();
1298
+ let ch = this.#scanner.peek();
1279
1299
  let terminator;
1280
1300
  let isMapping = true;
1281
1301
  let result = {};
@@ -1289,7 +1309,8 @@ var LoaderState = class {
1289
1309
  return;
1290
1310
  }
1291
1311
  if (anchor !== null) this.anchorMap.set(anchor, result);
1292
- ch = this.next();
1312
+ this.#scanner.next();
1313
+ ch = this.#scanner.peek();
1293
1314
  let readNext = true;
1294
1315
  let valueNode = null;
1295
1316
  let keyNode = null;
@@ -1301,9 +1322,9 @@ var LoaderState = class {
1301
1322
  const overridableKeys = /* @__PURE__ */ new Set();
1302
1323
  while (ch !== 0) {
1303
1324
  this.skipSeparationSpace(true, nodeIndent);
1304
- ch = this.peek();
1325
+ ch = this.#scanner.peek();
1305
1326
  if (ch === terminator) {
1306
- this.position++;
1327
+ this.#scanner.next();
1307
1328
  const kind = isMapping ? "mapping" : "sequence";
1308
1329
  return {
1309
1330
  tag,
@@ -1318,10 +1339,10 @@ var LoaderState = class {
1318
1339
  keyTag = keyNode = valueNode = null;
1319
1340
  isPair = isExplicitPair = false;
1320
1341
  if (ch === QUESTION) {
1321
- following = this.peek(1);
1342
+ following = this.#scanner.peek(1);
1322
1343
  if (isWhiteSpaceOrEOL(following)) {
1323
1344
  isPair = isExplicitPair = true;
1324
- this.position++;
1345
+ this.#scanner.next();
1325
1346
  this.skipSeparationSpace(true, nodeIndent);
1326
1347
  }
1327
1348
  }
@@ -1337,10 +1358,11 @@ var LoaderState = class {
1337
1358
  keyNode = newState.result;
1338
1359
  }
1339
1360
  this.skipSeparationSpace(true, nodeIndent);
1340
- ch = this.peek();
1361
+ ch = this.#scanner.peek();
1341
1362
  if ((isExplicitPair || this.line === line) && ch === COLON) {
1342
1363
  isPair = true;
1343
- ch = this.next();
1364
+ this.#scanner.next();
1365
+ ch = this.#scanner.peek();
1344
1366
  this.skipSeparationSpace(true, nodeIndent);
1345
1367
  const newState2 = this.composeNode({
1346
1368
  parentIndent: nodeIndent,
@@ -1358,10 +1380,11 @@ var LoaderState = class {
1358
1380
  result.push(keyNode);
1359
1381
  }
1360
1382
  this.skipSeparationSpace(true, nodeIndent);
1361
- ch = this.peek();
1383
+ ch = this.#scanner.peek();
1362
1384
  if (ch === COMMA) {
1363
1385
  readNext = true;
1364
- ch = this.next();
1386
+ this.#scanner.next();
1387
+ ch = this.#scanner.peek();
1365
1388
  } else {
1366
1389
  readNext = false;
1367
1390
  }
@@ -1377,7 +1400,7 @@ var LoaderState = class {
1377
1400
  let textIndent = nodeIndent;
1378
1401
  let emptyLines = 0;
1379
1402
  let atMoreIndented = false;
1380
- let ch = this.peek();
1403
+ let ch = this.#scanner.peek();
1381
1404
  let folding = false;
1382
1405
  if (ch === VERTICAL_LINE) {
1383
1406
  folding = false;
@@ -1389,7 +1412,8 @@ var LoaderState = class {
1389
1412
  let result = "";
1390
1413
  let tmp = 0;
1391
1414
  while (ch !== 0) {
1392
- ch = this.next();
1415
+ this.#scanner.next();
1416
+ ch = this.#scanner.peek();
1393
1417
  if (ch === PLUS || ch === MINUS) {
1394
1418
  if (CHOMPING_CLIP === chomping) {
1395
1419
  chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
@@ -1412,15 +1436,16 @@ var LoaderState = class {
1412
1436
  if (isWhiteSpace(ch)) {
1413
1437
  this.skipWhitespaces();
1414
1438
  this.skipComment();
1415
- ch = this.peek();
1439
+ ch = this.#scanner.peek();
1416
1440
  }
1417
1441
  while (ch !== 0) {
1418
1442
  this.readLineBreak();
1419
1443
  this.lineIndent = 0;
1420
- ch = this.peek();
1444
+ ch = this.#scanner.peek();
1421
1445
  while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
1422
1446
  this.lineIndent++;
1423
- ch = this.next();
1447
+ this.#scanner.next();
1448
+ ch = this.#scanner.peek();
1424
1449
  }
1425
1450
  if (!detectedIndent && this.lineIndent > textIndent) {
1426
1451
  textIndent = this.lineIndent;
@@ -1459,11 +1484,12 @@ var LoaderState = class {
1459
1484
  didReadContent = true;
1460
1485
  detectedIndent = true;
1461
1486
  emptyLines = 0;
1462
- const captureStart = this.position;
1487
+ const captureStart = this.#scanner.position;
1463
1488
  while (!isEOL(ch) && ch !== 0) {
1464
- ch = this.next();
1489
+ this.#scanner.next();
1490
+ ch = this.#scanner.peek();
1465
1491
  }
1466
- const segment = this.captureSegment(captureStart, this.position, false);
1492
+ const segment = this.captureSegment(captureStart, this.#scanner.position, false);
1467
1493
  if (segment) result += segment;
1468
1494
  }
1469
1495
  if (anchor !== null) this.anchorMap.set(anchor, result);
@@ -1486,11 +1512,11 @@ var LoaderState = class {
1486
1512
  let atExplicitKey = false;
1487
1513
  let detected = false;
1488
1514
  if (anchor !== null) this.anchorMap.set(anchor, result);
1489
- let ch = this.peek();
1515
+ let ch = this.#scanner.peek();
1490
1516
  while (ch !== 0) {
1491
- const following = this.peek(1);
1517
+ const following = this.#scanner.peek(1);
1492
1518
  line = this.line;
1493
- pos = this.position;
1519
+ pos = this.#scanner.position;
1494
1520
  if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
1495
1521
  if (ch === QUESTION) {
1496
1522
  if (atExplicitKey) {
@@ -1508,7 +1534,7 @@ var LoaderState = class {
1508
1534
  } else {
1509
1535
  throw this.#createError("Cannot read block as explicit mapping pair is incomplete: a key node is missed or followed by a non-tabulated empty line");
1510
1536
  }
1511
- this.position += 1;
1537
+ this.#scanner.next();
1512
1538
  ch = following;
1513
1539
  } else {
1514
1540
  const newState = this.composeNode({
@@ -1519,11 +1545,12 @@ var LoaderState = class {
1519
1545
  });
1520
1546
  if (!newState) break;
1521
1547
  if (this.line === line) {
1522
- ch = this.peek();
1548
+ ch = this.#scanner.peek();
1523
1549
  this.skipWhitespaces();
1524
- ch = this.peek();
1550
+ ch = this.#scanner.peek();
1525
1551
  if (ch === COLON) {
1526
- ch = this.next();
1552
+ this.#scanner.next();
1553
+ ch = this.#scanner.peek();
1527
1554
  if (!isWhiteSpaceOrEOL(ch)) {
1528
1555
  throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
1529
1556
  }
@@ -1580,7 +1607,7 @@ var LoaderState = class {
1580
1607
  keyTag = keyNode = valueNode = null;
1581
1608
  }
1582
1609
  this.skipSeparationSpace(true, -1);
1583
- ch = this.peek();
1610
+ ch = this.#scanner.peek();
1584
1611
  }
1585
1612
  if (this.lineIndent > nodeIndent && ch !== 0) {
1586
1613
  throw this.#createError("Cannot read block: bad indentation of a mapping entry");
@@ -1603,30 +1630,35 @@ var LoaderState = class {
1603
1630
  let isNamed = false;
1604
1631
  let tagHandle = "";
1605
1632
  let tagName;
1606
- let ch = this.peek();
1633
+ let ch = this.#scanner.peek();
1607
1634
  if (ch !== EXCLAMATION) return;
1608
1635
  if (tag !== null) {
1609
1636
  throw this.#createError("Cannot read tag property: duplication of a tag property");
1610
1637
  }
1611
- ch = this.next();
1638
+ this.#scanner.next();
1639
+ ch = this.#scanner.peek();
1612
1640
  if (ch === SMALLER_THAN) {
1613
1641
  isVerbatim = true;
1614
- ch = this.next();
1642
+ this.#scanner.next();
1643
+ ch = this.#scanner.peek();
1615
1644
  } else if (ch === EXCLAMATION) {
1616
1645
  isNamed = true;
1617
1646
  tagHandle = "!!";
1618
- ch = this.next();
1647
+ this.#scanner.next();
1648
+ ch = this.#scanner.peek();
1619
1649
  } else {
1620
1650
  tagHandle = "!";
1621
1651
  }
1622
- let position = this.position;
1652
+ let position = this.#scanner.position;
1623
1653
  if (isVerbatim) {
1624
1654
  do {
1625
- ch = this.next();
1655
+ this.#scanner.next();
1656
+ ch = this.#scanner.peek();
1626
1657
  } while (ch !== 0 && ch !== GREATER_THAN);
1627
- if (this.position < this.length) {
1628
- tagName = this.input.slice(position, this.position);
1629
- ch = this.next();
1658
+ if (!this.#scanner.eof()) {
1659
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
1660
+ this.#scanner.next();
1661
+ ch = this.#scanner.peek();
1630
1662
  } else {
1631
1663
  throw this.#createError("Cannot read tag property: unexpected end of stream");
1632
1664
  }
@@ -1634,19 +1666,20 @@ var LoaderState = class {
1634
1666
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
1635
1667
  if (ch === EXCLAMATION) {
1636
1668
  if (!isNamed) {
1637
- tagHandle = this.input.slice(position - 1, this.position + 1);
1669
+ tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
1638
1670
  if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
1639
1671
  throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
1640
1672
  }
1641
1673
  isNamed = true;
1642
- position = this.position + 1;
1674
+ position = this.#scanner.position + 1;
1643
1675
  } else {
1644
1676
  throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
1645
1677
  }
1646
1678
  }
1647
- ch = this.next();
1679
+ this.#scanner.next();
1680
+ ch = this.#scanner.peek();
1648
1681
  }
1649
- tagName = this.input.slice(position, this.position);
1682
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
1650
1683
  if (PATTERN_FLOW_INDICATORS.test(tagName)) {
1651
1684
  throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
1652
1685
  }
@@ -1666,32 +1699,36 @@ var LoaderState = class {
1666
1699
  throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
1667
1700
  }
1668
1701
  readAnchorProperty(anchor) {
1669
- let ch = this.peek();
1702
+ let ch = this.#scanner.peek();
1670
1703
  if (ch !== AMPERSAND) return;
1671
1704
  if (anchor !== null) {
1672
1705
  throw this.#createError("Cannot read anchor property: duplicate anchor property");
1673
1706
  }
1674
- ch = this.next();
1675
- const position = this.position;
1707
+ this.#scanner.next();
1708
+ ch = this.#scanner.peek();
1709
+ const position = this.#scanner.position;
1676
1710
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
1677
- ch = this.next();
1711
+ this.#scanner.next();
1712
+ ch = this.#scanner.peek();
1678
1713
  }
1679
- if (this.position === position) {
1714
+ if (this.#scanner.position === position) {
1680
1715
  throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
1681
1716
  }
1682
- return this.input.slice(position, this.position);
1717
+ return this.#scanner.source.slice(position, this.#scanner.position);
1683
1718
  }
1684
1719
  readAlias() {
1685
- if (this.peek() !== ASTERISK) return;
1686
- let ch = this.next();
1687
- const position = this.position;
1720
+ if (this.#scanner.peek() !== ASTERISK) return;
1721
+ this.#scanner.next();
1722
+ let ch = this.#scanner.peek();
1723
+ const position = this.#scanner.position;
1688
1724
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
1689
- ch = this.next();
1725
+ this.#scanner.next();
1726
+ ch = this.#scanner.peek();
1690
1727
  }
1691
- if (this.position === position) {
1728
+ if (this.#scanner.position === position) {
1692
1729
  throw this.#createError("Cannot read alias: alias name must contain at least one character");
1693
1730
  }
1694
- const alias = this.input.slice(position, this.position);
1731
+ const alias = this.#scanner.source.slice(position, this.#scanner.position);
1695
1732
  if (!this.anchorMap.has(alias)) {
1696
1733
  throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
1697
1734
  }
@@ -1774,7 +1811,7 @@ var LoaderState = class {
1774
1811
  const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
1775
1812
  const flowIndent = cond ? parentIndent : parentIndent + 1;
1776
1813
  if (allowBlockCollections) {
1777
- const blockIndent = this.position - this.lineStart;
1814
+ const blockIndent = this.#scanner.position - this.lineStart;
1778
1815
  const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
1779
1816
  if (blockSequenceState) return this.resolveTag(blockSequenceState);
1780
1817
  const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
@@ -1808,7 +1845,7 @@ var LoaderState = class {
1808
1845
  return this.resolveTag(plainScalarState);
1809
1846
  }
1810
1847
  } else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
1811
- const blockIndent = this.position - this.lineStart;
1848
+ const blockIndent = this.#scanner.position - this.lineStart;
1812
1849
  const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
1813
1850
  if (newState2) return this.resolveTag(newState2);
1814
1851
  }
@@ -1823,20 +1860,22 @@ var LoaderState = class {
1823
1860
  readDirectives() {
1824
1861
  let hasDirectives = false;
1825
1862
  let version = null;
1826
- let ch = this.peek();
1863
+ let ch = this.#scanner.peek();
1827
1864
  while (ch !== 0) {
1828
1865
  this.skipSeparationSpace(true, -1);
1829
- ch = this.peek();
1866
+ ch = this.#scanner.peek();
1830
1867
  if (this.lineIndent > 0 || ch !== PERCENT) {
1831
1868
  break;
1832
1869
  }
1833
1870
  hasDirectives = true;
1834
- ch = this.next();
1835
- let position = this.position;
1871
+ this.#scanner.next();
1872
+ ch = this.#scanner.peek();
1873
+ let position = this.#scanner.position;
1836
1874
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
1837
- ch = this.next();
1875
+ this.#scanner.next();
1876
+ ch = this.#scanner.peek();
1838
1877
  }
1839
- const directiveName = this.input.slice(position, this.position);
1878
+ const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
1840
1879
  const directiveArgs = [];
1841
1880
  if (directiveName.length < 1) {
1842
1881
  throw this.#createError("Cannot read document: directive name length must be greater than zero");
@@ -1844,13 +1883,14 @@ var LoaderState = class {
1844
1883
  while (ch !== 0) {
1845
1884
  this.skipWhitespaces();
1846
1885
  this.skipComment();
1847
- ch = this.peek();
1886
+ ch = this.#scanner.peek();
1848
1887
  if (isEOL(ch)) break;
1849
- position = this.position;
1888
+ position = this.#scanner.position;
1850
1889
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
1851
- ch = this.next();
1890
+ this.#scanner.next();
1891
+ ch = this.#scanner.peek();
1852
1892
  }
1853
- directiveArgs.push(this.input.slice(position, this.position));
1893
+ directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
1854
1894
  }
1855
1895
  if (ch !== 0) this.readLineBreak();
1856
1896
  switch (directiveName) {
@@ -1867,20 +1907,20 @@ var LoaderState = class {
1867
1907
  this.dispatchWarning(`unknown document directive "${directiveName}"`);
1868
1908
  break;
1869
1909
  }
1870
- ch = this.peek();
1910
+ ch = this.#scanner.peek();
1871
1911
  }
1872
1912
  return hasDirectives;
1873
1913
  }
1874
1914
  readDocument() {
1875
- const documentStart = this.position;
1915
+ const documentStart = this.#scanner.position;
1876
1916
  this.checkLineBreaks = false;
1877
1917
  this.tagMap = /* @__PURE__ */ new Map();
1878
1918
  this.anchorMap = /* @__PURE__ */ new Map();
1879
1919
  const hasDirectives = this.readDirectives();
1880
1920
  this.skipSeparationSpace(true, -1);
1881
1921
  let result = null;
1882
- if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
1883
- this.position += 3;
1922
+ if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
1923
+ this.#scanner.position += 3;
1884
1924
  this.skipSeparationSpace(true, -1);
1885
1925
  } else if (hasDirectives) {
1886
1926
  throw this.#createError("Cannot read document: directives end mark is expected");
@@ -1893,21 +1933,21 @@ var LoaderState = class {
1893
1933
  });
1894
1934
  if (newState) result = newState.result;
1895
1935
  this.skipSeparationSpace(true, -1);
1896
- if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.input.slice(documentStart, this.position))) {
1936
+ if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
1897
1937
  this.dispatchWarning("non-ASCII line breaks are interpreted as content");
1898
1938
  }
1899
- if (this.position === this.lineStart && this.testDocumentSeparator()) {
1900
- if (this.peek() === DOT) {
1901
- this.position += 3;
1939
+ if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
1940
+ if (this.#scanner.peek() === DOT) {
1941
+ this.#scanner.position += 3;
1902
1942
  this.skipSeparationSpace(true, -1);
1903
1943
  }
1904
- } else if (this.position < this.length - 1) {
1944
+ } else if (!this.#scanner.eof()) {
1905
1945
  throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
1906
1946
  }
1907
1947
  return result;
1908
1948
  }
1909
1949
  *readDocuments() {
1910
- while (this.position < this.length - 1) {
1950
+ while (!this.#scanner.eof()) {
1911
1951
  yield this.readDocument();
1912
1952
  }
1913
1953
  }
@@ -1920,7 +1960,6 @@ function sanitizeInput(input) {
1920
1960
  if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
1921
1961
  if (input.charCodeAt(0) === 65279) input = input.slice(1);
1922
1962
  }
1923
- input += "\0";
1924
1963
  return input;
1925
1964
  }
1926
1965
  function parse(content, options = {}) {