@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.cjs CHANGED
@@ -882,12 +882,29 @@ function writeFoldedLines(count) {
882
882
  if (count > 1) return "\n".repeat(count - 1);
883
883
  return "";
884
884
  }
885
+ var Scanner = class {
886
+ source;
887
+ #length;
888
+ position = 0;
889
+ constructor(source) {
890
+ source += "\0";
891
+ this.source = source;
892
+ this.#length = source.length;
893
+ }
894
+ peek(offset = 0) {
895
+ return this.source.charCodeAt(this.position + offset);
896
+ }
897
+ next() {
898
+ this.position += 1;
899
+ }
900
+ eof() {
901
+ return this.position >= this.#length - 1;
902
+ }
903
+ };
885
904
  var LoaderState = class {
886
- input;
887
- length;
905
+ #scanner;
888
906
  lineIndent = 0;
889
907
  lineStart = 0;
890
- position = 0;
891
908
  line = 0;
892
909
  onWarning;
893
910
  allowDuplicateKeys;
@@ -897,44 +914,40 @@ var LoaderState = class {
897
914
  tagMap = /* @__PURE__ */ new Map();
898
915
  anchorMap = /* @__PURE__ */ new Map();
899
916
  constructor(input, { schema = DEFAULT_SCHEMA, onWarning, allowDuplicateKeys = false }) {
900
- this.input = input;
917
+ this.#scanner = new Scanner(input);
901
918
  this.onWarning = onWarning;
902
919
  this.allowDuplicateKeys = allowDuplicateKeys;
903
920
  this.implicitTypes = schema.implicitTypes;
904
921
  this.typeMap = schema.typeMap;
905
- this.length = input.length;
906
922
  this.readIndent();
907
923
  }
908
924
  skipWhitespaces() {
909
- let ch = this.peek();
925
+ let ch = this.#scanner.peek();
910
926
  while (isWhiteSpace(ch)) {
911
- ch = this.next();
927
+ this.#scanner.next();
928
+ ch = this.#scanner.peek();
912
929
  }
913
930
  }
914
931
  skipComment() {
915
- let ch = this.peek();
932
+ let ch = this.#scanner.peek();
916
933
  if (ch !== SHARP) return;
917
- ch = this.next();
934
+ this.#scanner.next();
935
+ ch = this.#scanner.peek();
918
936
  while (ch !== 0 && !isEOL(ch)) {
919
- ch = this.next();
937
+ this.#scanner.next();
938
+ ch = this.#scanner.peek();
920
939
  }
921
940
  }
922
941
  readIndent() {
923
- let char = this.peek();
924
- while (char === SPACE) {
942
+ let ch = this.#scanner.peek();
943
+ while (ch === SPACE) {
925
944
  this.lineIndent += 1;
926
- char = this.next();
945
+ this.#scanner.next();
946
+ ch = this.#scanner.peek();
927
947
  }
928
948
  }
929
- peek(offset = 0) {
930
- return this.input.charCodeAt(this.position + offset);
931
- }
932
- next() {
933
- this.position += 1;
934
- return this.peek();
935
- }
936
949
  #createError(message) {
937
- const mark = markToString(this.input, this.position, this.line, this.position - this.lineStart);
950
+ const mark = markToString(this.#scanner.source, this.#scanner.position, this.line, this.#scanner.position - this.lineStart);
938
951
  return new SyntaxError(`${message} ${mark}`);
939
952
  }
940
953
  dispatchWarning(message) {
@@ -979,7 +992,7 @@ var LoaderState = class {
979
992
  }
980
993
  captureSegment(start, end, checkJson) {
981
994
  if (start < end) {
982
- const result = this.input.slice(start, end);
995
+ const result = this.#scanner.source.slice(start, end);
983
996
  if (checkJson) {
984
997
  for (let position = 0; position < result.length; position++) {
985
998
  const character = result.charCodeAt(position);
@@ -997,21 +1010,21 @@ var LoaderState = class {
997
1010
  let detected = false;
998
1011
  const result = [];
999
1012
  if (anchor !== null) this.anchorMap.set(anchor, result);
1000
- let ch = this.peek();
1013
+ let ch = this.#scanner.peek();
1001
1014
  while (ch !== 0) {
1002
1015
  if (ch !== MINUS) {
1003
1016
  break;
1004
1017
  }
1005
- const following = this.peek(1);
1018
+ const following = this.#scanner.peek(1);
1006
1019
  if (!isWhiteSpaceOrEOL(following)) {
1007
1020
  break;
1008
1021
  }
1009
1022
  detected = true;
1010
- this.position++;
1023
+ this.#scanner.next();
1011
1024
  if (this.skipSeparationSpace(true, -1)) {
1012
1025
  if (this.lineIndent <= nodeIndent) {
1013
1026
  result.push(null);
1014
- ch = this.peek();
1027
+ ch = this.#scanner.peek();
1015
1028
  continue;
1016
1029
  }
1017
1030
  }
@@ -1024,7 +1037,7 @@ var LoaderState = class {
1024
1037
  });
1025
1038
  if (newState) result.push(newState.result);
1026
1039
  this.skipSeparationSpace(true, -1);
1027
- ch = this.peek();
1040
+ ch = this.#scanner.peek();
1028
1041
  if ((this.line === line || this.lineIndent > nodeIndent) && ch !== 0) {
1029
1042
  throw this.#createError("Cannot read block sequence: bad indentation of a sequence entry");
1030
1043
  } else if (this.lineIndent < nodeIndent) {
@@ -1080,7 +1093,7 @@ var LoaderState = class {
1080
1093
  } else {
1081
1094
  if (!this.allowDuplicateKeys && !overridableKeys.has(keyNode) && Object.hasOwn(result, keyNode)) {
1082
1095
  this.line = startLine || this.line;
1083
- this.position = startPos || this.position;
1096
+ this.#scanner.position = startPos || this.#scanner.position;
1084
1097
  throw this.#createError("Cannot store mapping pair: duplicated key");
1085
1098
  }
1086
1099
  Object.defineProperty(result, keyNode, {
@@ -1094,37 +1107,37 @@ var LoaderState = class {
1094
1107
  return result;
1095
1108
  }
1096
1109
  readLineBreak() {
1097
- const ch = this.peek();
1110
+ const ch = this.#scanner.peek();
1098
1111
  if (ch === LINE_FEED) {
1099
- this.position++;
1112
+ this.#scanner.next();
1100
1113
  } else if (ch === CARRIAGE_RETURN) {
1101
- this.position++;
1102
- if (this.peek() === LINE_FEED) {
1103
- this.position++;
1114
+ this.#scanner.next();
1115
+ if (this.#scanner.peek() === LINE_FEED) {
1116
+ this.#scanner.next();
1104
1117
  }
1105
1118
  } else {
1106
1119
  throw this.#createError("Cannot read line: line break not found");
1107
1120
  }
1108
1121
  this.line += 1;
1109
- this.lineStart = this.position;
1122
+ this.lineStart = this.#scanner.position;
1110
1123
  }
1111
1124
  skipSeparationSpace(allowComments, checkIndent) {
1112
1125
  let lineBreaks = 0;
1113
- let ch = this.peek();
1126
+ let ch = this.#scanner.peek();
1114
1127
  while (ch !== 0) {
1115
1128
  this.skipWhitespaces();
1116
- ch = this.peek();
1129
+ ch = this.#scanner.peek();
1117
1130
  if (allowComments) {
1118
1131
  this.skipComment();
1119
- ch = this.peek();
1132
+ ch = this.#scanner.peek();
1120
1133
  }
1121
1134
  if (isEOL(ch)) {
1122
1135
  this.readLineBreak();
1123
- ch = this.peek();
1136
+ ch = this.#scanner.peek();
1124
1137
  lineBreaks++;
1125
1138
  this.lineIndent = 0;
1126
1139
  this.readIndent();
1127
- ch = this.peek();
1140
+ ch = this.#scanner.peek();
1128
1141
  } else {
1129
1142
  break;
1130
1143
  }
@@ -1135,9 +1148,9 @@ var LoaderState = class {
1135
1148
  return lineBreaks;
1136
1149
  }
1137
1150
  testDocumentSeparator() {
1138
- let ch = this.peek();
1139
- if ((ch === MINUS || ch === DOT) && ch === this.peek(1) && ch === this.peek(2)) {
1140
- ch = this.peek(3);
1151
+ let ch = this.#scanner.peek();
1152
+ if ((ch === MINUS || ch === DOT) && ch === this.#scanner.peek(1) && ch === this.#scanner.peek(2)) {
1153
+ ch = this.#scanner.peek(3);
1141
1154
  if (ch === 0 || isWhiteSpaceOrEOL(ch)) {
1142
1155
  return true;
1143
1156
  }
@@ -1145,34 +1158,34 @@ var LoaderState = class {
1145
1158
  return false;
1146
1159
  }
1147
1160
  readPlainScalar(tag, anchor, nodeIndent, withinFlowCollection) {
1148
- let ch = this.peek();
1161
+ let ch = this.#scanner.peek();
1149
1162
  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) {
1150
1163
  return;
1151
1164
  }
1152
1165
  let following;
1153
1166
  if (ch === QUESTION || ch === MINUS) {
1154
- following = this.peek(1);
1167
+ following = this.#scanner.peek(1);
1155
1168
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
1156
1169
  return;
1157
1170
  }
1158
1171
  }
1159
1172
  let result = "";
1160
- let captureEnd = this.position;
1161
- let captureStart = this.position;
1173
+ let captureEnd = this.#scanner.position;
1174
+ let captureStart = this.#scanner.position;
1162
1175
  let hasPendingContent = false;
1163
1176
  let line = 0;
1164
1177
  while (ch !== 0) {
1165
1178
  if (ch === COLON) {
1166
- following = this.peek(1);
1179
+ following = this.#scanner.peek(1);
1167
1180
  if (isWhiteSpaceOrEOL(following) || withinFlowCollection && isFlowIndicator(following)) {
1168
1181
  break;
1169
1182
  }
1170
1183
  } else if (ch === SHARP) {
1171
- const preceding = this.peek(-1);
1184
+ const preceding = this.#scanner.peek(-1);
1172
1185
  if (isWhiteSpaceOrEOL(preceding)) {
1173
1186
  break;
1174
1187
  }
1175
- } else if (this.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
1188
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator() || withinFlowCollection && isFlowIndicator(ch)) {
1176
1189
  break;
1177
1190
  } else if (isEOL(ch)) {
1178
1191
  line = this.line;
@@ -1181,10 +1194,10 @@ var LoaderState = class {
1181
1194
  this.skipSeparationSpace(false, -1);
1182
1195
  if (this.lineIndent >= nodeIndent) {
1183
1196
  hasPendingContent = true;
1184
- ch = this.peek();
1197
+ ch = this.#scanner.peek();
1185
1198
  continue;
1186
1199
  } else {
1187
- this.position = captureEnd;
1200
+ this.#scanner.position = captureEnd;
1188
1201
  this.line = line;
1189
1202
  this.lineStart = lineStart;
1190
1203
  this.lineIndent = lineIndent;
@@ -1195,13 +1208,14 @@ var LoaderState = class {
1195
1208
  const segment2 = this.captureSegment(captureStart, captureEnd, false);
1196
1209
  if (segment2) result += segment2;
1197
1210
  result += writeFoldedLines(this.line - line);
1198
- captureStart = captureEnd = this.position;
1211
+ captureStart = captureEnd = this.#scanner.position;
1199
1212
  hasPendingContent = false;
1200
1213
  }
1201
1214
  if (!isWhiteSpace(ch)) {
1202
- captureEnd = this.position + 1;
1215
+ captureEnd = this.#scanner.position + 1;
1203
1216
  }
1204
- ch = this.next();
1217
+ this.#scanner.next();
1218
+ ch = this.#scanner.peek();
1205
1219
  }
1206
1220
  const segment = this.captureSegment(captureStart, captureEnd, false);
1207
1221
  if (segment) result += segment;
@@ -1214,22 +1228,23 @@ var LoaderState = class {
1214
1228
  };
1215
1229
  }
1216
1230
  readSingleQuotedScalar(tag, anchor, nodeIndent) {
1217
- let ch = this.peek();
1231
+ let ch = this.#scanner.peek();
1218
1232
  if (ch !== SINGLE_QUOTE) return;
1219
1233
  let result = "";
1220
- this.position++;
1221
- let captureStart = this.position;
1222
- let captureEnd = this.position;
1223
- ch = this.peek();
1234
+ this.#scanner.next();
1235
+ let captureStart = this.#scanner.position;
1236
+ let captureEnd = this.#scanner.position;
1237
+ ch = this.#scanner.peek();
1224
1238
  while (ch !== 0) {
1225
1239
  if (ch === SINGLE_QUOTE) {
1226
- const segment = this.captureSegment(captureStart, this.position, true);
1240
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
1227
1241
  if (segment) result += segment;
1228
- ch = this.next();
1242
+ this.#scanner.next();
1243
+ ch = this.#scanner.peek();
1229
1244
  if (ch === SINGLE_QUOTE) {
1230
- captureStart = this.position;
1231
- this.position++;
1232
- captureEnd = this.position;
1245
+ captureStart = this.#scanner.position;
1246
+ this.#scanner.next();
1247
+ captureEnd = this.#scanner.position;
1233
1248
  } else {
1234
1249
  if (anchor !== null) this.anchorMap.set(anchor, result);
1235
1250
  return {
@@ -1243,31 +1258,31 @@ var LoaderState = class {
1243
1258
  const segment = this.captureSegment(captureStart, captureEnd, true);
1244
1259
  if (segment) result += segment;
1245
1260
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
1246
- captureStart = captureEnd = this.position;
1247
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
1261
+ captureStart = captureEnd = this.#scanner.position;
1262
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
1248
1263
  throw this.#createError("Unexpected end of the document within a single quoted scalar");
1249
1264
  } else {
1250
- this.position++;
1251
- captureEnd = this.position;
1265
+ this.#scanner.next();
1266
+ captureEnd = this.#scanner.position;
1252
1267
  }
1253
- ch = this.peek();
1268
+ ch = this.#scanner.peek();
1254
1269
  }
1255
1270
  throw this.#createError("Unexpected end of the stream within a single quoted scalar");
1256
1271
  }
1257
1272
  readDoubleQuotedScalar(tag, anchor, nodeIndent) {
1258
- let ch = this.peek();
1273
+ let ch = this.#scanner.peek();
1259
1274
  if (ch !== DOUBLE_QUOTE) return;
1260
1275
  let result = "";
1261
- this.position++;
1262
- let captureEnd = this.position;
1263
- let captureStart = this.position;
1276
+ this.#scanner.next();
1277
+ let captureEnd = this.#scanner.position;
1278
+ let captureStart = this.#scanner.position;
1264
1279
  let tmp;
1265
- ch = this.peek();
1280
+ ch = this.#scanner.peek();
1266
1281
  while (ch !== 0) {
1267
1282
  if (ch === DOUBLE_QUOTE) {
1268
- const segment = this.captureSegment(captureStart, this.position, true);
1283
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
1269
1284
  if (segment) result += segment;
1270
- this.position++;
1285
+ this.#scanner.next();
1271
1286
  if (anchor !== null) this.anchorMap.set(anchor, result);
1272
1287
  return {
1273
1288
  tag,
@@ -1277,19 +1292,21 @@ var LoaderState = class {
1277
1292
  };
1278
1293
  }
1279
1294
  if (ch === BACKSLASH) {
1280
- const segment = this.captureSegment(captureStart, this.position, true);
1295
+ const segment = this.captureSegment(captureStart, this.#scanner.position, true);
1281
1296
  if (segment) result += segment;
1282
- ch = this.next();
1297
+ this.#scanner.next();
1298
+ ch = this.#scanner.peek();
1283
1299
  if (isEOL(ch)) {
1284
1300
  this.skipSeparationSpace(false, nodeIndent);
1285
1301
  } else if (ch < 256 && SIMPLE_ESCAPE_SEQUENCES.has(ch)) {
1286
1302
  result += SIMPLE_ESCAPE_SEQUENCES.get(ch);
1287
- this.position++;
1303
+ this.#scanner.next();
1288
1304
  } else if ((tmp = ESCAPED_HEX_LENGTHS.get(ch) ?? 0) > 0) {
1289
1305
  let hexLength = tmp;
1290
1306
  let hexResult = 0;
1291
1307
  for (; hexLength > 0; hexLength--) {
1292
- ch = this.next();
1308
+ this.#scanner.next();
1309
+ ch = this.#scanner.peek();
1293
1310
  if ((tmp = hexCharCodeToNumber(ch)) >= 0) {
1294
1311
  hexResult = (hexResult << 4) + tmp;
1295
1312
  } else {
@@ -1297,28 +1314,28 @@ var LoaderState = class {
1297
1314
  }
1298
1315
  }
1299
1316
  result += codepointToChar(hexResult);
1300
- this.position++;
1317
+ this.#scanner.next();
1301
1318
  } else {
1302
1319
  throw this.#createError("Cannot read double quoted scalar: unknown escape sequence");
1303
1320
  }
1304
- captureStart = captureEnd = this.position;
1321
+ captureStart = captureEnd = this.#scanner.position;
1305
1322
  } else if (isEOL(ch)) {
1306
1323
  const segment = this.captureSegment(captureStart, captureEnd, true);
1307
1324
  if (segment) result += segment;
1308
1325
  result += writeFoldedLines(this.skipSeparationSpace(false, nodeIndent));
1309
- captureStart = captureEnd = this.position;
1310
- } else if (this.position === this.lineStart && this.testDocumentSeparator()) {
1326
+ captureStart = captureEnd = this.#scanner.position;
1327
+ } else if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
1311
1328
  throw this.#createError("Unexpected end of the document within a double quoted scalar");
1312
1329
  } else {
1313
- this.position++;
1314
- captureEnd = this.position;
1330
+ this.#scanner.next();
1331
+ captureEnd = this.#scanner.position;
1315
1332
  }
1316
- ch = this.peek();
1333
+ ch = this.#scanner.peek();
1317
1334
  }
1318
1335
  throw this.#createError("Unexpected end of the stream within a double quoted scalar");
1319
1336
  }
1320
1337
  readFlowCollection(tag, anchor, nodeIndent) {
1321
- let ch = this.peek();
1338
+ let ch = this.#scanner.peek();
1322
1339
  let terminator;
1323
1340
  let isMapping = true;
1324
1341
  let result = {};
@@ -1332,7 +1349,8 @@ var LoaderState = class {
1332
1349
  return;
1333
1350
  }
1334
1351
  if (anchor !== null) this.anchorMap.set(anchor, result);
1335
- ch = this.next();
1352
+ this.#scanner.next();
1353
+ ch = this.#scanner.peek();
1336
1354
  let readNext = true;
1337
1355
  let valueNode = null;
1338
1356
  let keyNode = null;
@@ -1344,9 +1362,9 @@ var LoaderState = class {
1344
1362
  const overridableKeys = /* @__PURE__ */ new Set();
1345
1363
  while (ch !== 0) {
1346
1364
  this.skipSeparationSpace(true, nodeIndent);
1347
- ch = this.peek();
1365
+ ch = this.#scanner.peek();
1348
1366
  if (ch === terminator) {
1349
- this.position++;
1367
+ this.#scanner.next();
1350
1368
  const kind = isMapping ? "mapping" : "sequence";
1351
1369
  return {
1352
1370
  tag,
@@ -1361,10 +1379,10 @@ var LoaderState = class {
1361
1379
  keyTag = keyNode = valueNode = null;
1362
1380
  isPair = isExplicitPair = false;
1363
1381
  if (ch === QUESTION) {
1364
- following = this.peek(1);
1382
+ following = this.#scanner.peek(1);
1365
1383
  if (isWhiteSpaceOrEOL(following)) {
1366
1384
  isPair = isExplicitPair = true;
1367
- this.position++;
1385
+ this.#scanner.next();
1368
1386
  this.skipSeparationSpace(true, nodeIndent);
1369
1387
  }
1370
1388
  }
@@ -1380,10 +1398,11 @@ var LoaderState = class {
1380
1398
  keyNode = newState.result;
1381
1399
  }
1382
1400
  this.skipSeparationSpace(true, nodeIndent);
1383
- ch = this.peek();
1401
+ ch = this.#scanner.peek();
1384
1402
  if ((isExplicitPair || this.line === line) && ch === COLON) {
1385
1403
  isPair = true;
1386
- ch = this.next();
1404
+ this.#scanner.next();
1405
+ ch = this.#scanner.peek();
1387
1406
  this.skipSeparationSpace(true, nodeIndent);
1388
1407
  const newState2 = this.composeNode({
1389
1408
  parentIndent: nodeIndent,
@@ -1401,10 +1420,11 @@ var LoaderState = class {
1401
1420
  result.push(keyNode);
1402
1421
  }
1403
1422
  this.skipSeparationSpace(true, nodeIndent);
1404
- ch = this.peek();
1423
+ ch = this.#scanner.peek();
1405
1424
  if (ch === COMMA) {
1406
1425
  readNext = true;
1407
- ch = this.next();
1426
+ this.#scanner.next();
1427
+ ch = this.#scanner.peek();
1408
1428
  } else {
1409
1429
  readNext = false;
1410
1430
  }
@@ -1420,7 +1440,7 @@ var LoaderState = class {
1420
1440
  let textIndent = nodeIndent;
1421
1441
  let emptyLines = 0;
1422
1442
  let atMoreIndented = false;
1423
- let ch = this.peek();
1443
+ let ch = this.#scanner.peek();
1424
1444
  let folding = false;
1425
1445
  if (ch === VERTICAL_LINE) {
1426
1446
  folding = false;
@@ -1432,7 +1452,8 @@ var LoaderState = class {
1432
1452
  let result = "";
1433
1453
  let tmp = 0;
1434
1454
  while (ch !== 0) {
1435
- ch = this.next();
1455
+ this.#scanner.next();
1456
+ ch = this.#scanner.peek();
1436
1457
  if (ch === PLUS || ch === MINUS) {
1437
1458
  if (CHOMPING_CLIP === chomping) {
1438
1459
  chomping = ch === PLUS ? CHOMPING_KEEP : CHOMPING_STRIP;
@@ -1455,15 +1476,16 @@ var LoaderState = class {
1455
1476
  if (isWhiteSpace(ch)) {
1456
1477
  this.skipWhitespaces();
1457
1478
  this.skipComment();
1458
- ch = this.peek();
1479
+ ch = this.#scanner.peek();
1459
1480
  }
1460
1481
  while (ch !== 0) {
1461
1482
  this.readLineBreak();
1462
1483
  this.lineIndent = 0;
1463
- ch = this.peek();
1484
+ ch = this.#scanner.peek();
1464
1485
  while ((!detectedIndent || this.lineIndent < textIndent) && ch === SPACE) {
1465
1486
  this.lineIndent++;
1466
- ch = this.next();
1487
+ this.#scanner.next();
1488
+ ch = this.#scanner.peek();
1467
1489
  }
1468
1490
  if (!detectedIndent && this.lineIndent > textIndent) {
1469
1491
  textIndent = this.lineIndent;
@@ -1502,11 +1524,12 @@ var LoaderState = class {
1502
1524
  didReadContent = true;
1503
1525
  detectedIndent = true;
1504
1526
  emptyLines = 0;
1505
- const captureStart = this.position;
1527
+ const captureStart = this.#scanner.position;
1506
1528
  while (!isEOL(ch) && ch !== 0) {
1507
- ch = this.next();
1529
+ this.#scanner.next();
1530
+ ch = this.#scanner.peek();
1508
1531
  }
1509
- const segment = this.captureSegment(captureStart, this.position, false);
1532
+ const segment = this.captureSegment(captureStart, this.#scanner.position, false);
1510
1533
  if (segment) result += segment;
1511
1534
  }
1512
1535
  if (anchor !== null) this.anchorMap.set(anchor, result);
@@ -1529,11 +1552,11 @@ var LoaderState = class {
1529
1552
  let atExplicitKey = false;
1530
1553
  let detected = false;
1531
1554
  if (anchor !== null) this.anchorMap.set(anchor, result);
1532
- let ch = this.peek();
1555
+ let ch = this.#scanner.peek();
1533
1556
  while (ch !== 0) {
1534
- const following = this.peek(1);
1557
+ const following = this.#scanner.peek(1);
1535
1558
  line = this.line;
1536
- pos = this.position;
1559
+ pos = this.#scanner.position;
1537
1560
  if ((ch === QUESTION || ch === COLON) && isWhiteSpaceOrEOL(following)) {
1538
1561
  if (ch === QUESTION) {
1539
1562
  if (atExplicitKey) {
@@ -1551,7 +1574,7 @@ var LoaderState = class {
1551
1574
  } else {
1552
1575
  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");
1553
1576
  }
1554
- this.position += 1;
1577
+ this.#scanner.next();
1555
1578
  ch = following;
1556
1579
  } else {
1557
1580
  const newState = this.composeNode({
@@ -1562,11 +1585,12 @@ var LoaderState = class {
1562
1585
  });
1563
1586
  if (!newState) break;
1564
1587
  if (this.line === line) {
1565
- ch = this.peek();
1588
+ ch = this.#scanner.peek();
1566
1589
  this.skipWhitespaces();
1567
- ch = this.peek();
1590
+ ch = this.#scanner.peek();
1568
1591
  if (ch === COLON) {
1569
- ch = this.next();
1592
+ this.#scanner.next();
1593
+ ch = this.#scanner.peek();
1570
1594
  if (!isWhiteSpaceOrEOL(ch)) {
1571
1595
  throw this.#createError("Cannot read block: a whitespace character is expected after the key-value separator within a block mapping");
1572
1596
  }
@@ -1623,7 +1647,7 @@ var LoaderState = class {
1623
1647
  keyTag = keyNode = valueNode = null;
1624
1648
  }
1625
1649
  this.skipSeparationSpace(true, -1);
1626
- ch = this.peek();
1650
+ ch = this.#scanner.peek();
1627
1651
  }
1628
1652
  if (this.lineIndent > nodeIndent && ch !== 0) {
1629
1653
  throw this.#createError("Cannot read block: bad indentation of a mapping entry");
@@ -1646,30 +1670,35 @@ var LoaderState = class {
1646
1670
  let isNamed = false;
1647
1671
  let tagHandle = "";
1648
1672
  let tagName;
1649
- let ch = this.peek();
1673
+ let ch = this.#scanner.peek();
1650
1674
  if (ch !== EXCLAMATION) return;
1651
1675
  if (tag !== null) {
1652
1676
  throw this.#createError("Cannot read tag property: duplication of a tag property");
1653
1677
  }
1654
- ch = this.next();
1678
+ this.#scanner.next();
1679
+ ch = this.#scanner.peek();
1655
1680
  if (ch === SMALLER_THAN) {
1656
1681
  isVerbatim = true;
1657
- ch = this.next();
1682
+ this.#scanner.next();
1683
+ ch = this.#scanner.peek();
1658
1684
  } else if (ch === EXCLAMATION) {
1659
1685
  isNamed = true;
1660
1686
  tagHandle = "!!";
1661
- ch = this.next();
1687
+ this.#scanner.next();
1688
+ ch = this.#scanner.peek();
1662
1689
  } else {
1663
1690
  tagHandle = "!";
1664
1691
  }
1665
- let position = this.position;
1692
+ let position = this.#scanner.position;
1666
1693
  if (isVerbatim) {
1667
1694
  do {
1668
- ch = this.next();
1695
+ this.#scanner.next();
1696
+ ch = this.#scanner.peek();
1669
1697
  } while (ch !== 0 && ch !== GREATER_THAN);
1670
- if (this.position < this.length) {
1671
- tagName = this.input.slice(position, this.position);
1672
- ch = this.next();
1698
+ if (!this.#scanner.eof()) {
1699
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
1700
+ this.#scanner.next();
1701
+ ch = this.#scanner.peek();
1673
1702
  } else {
1674
1703
  throw this.#createError("Cannot read tag property: unexpected end of stream");
1675
1704
  }
@@ -1677,19 +1706,20 @@ var LoaderState = class {
1677
1706
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
1678
1707
  if (ch === EXCLAMATION) {
1679
1708
  if (!isNamed) {
1680
- tagHandle = this.input.slice(position - 1, this.position + 1);
1709
+ tagHandle = this.#scanner.source.slice(position - 1, this.#scanner.position + 1);
1681
1710
  if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
1682
1711
  throw this.#createError("Cannot read tag property: named tag handle contains invalid characters");
1683
1712
  }
1684
1713
  isNamed = true;
1685
- position = this.position + 1;
1714
+ position = this.#scanner.position + 1;
1686
1715
  } else {
1687
1716
  throw this.#createError("Cannot read tag property: tag suffix cannot contain an exclamation mark");
1688
1717
  }
1689
1718
  }
1690
- ch = this.next();
1719
+ this.#scanner.next();
1720
+ ch = this.#scanner.peek();
1691
1721
  }
1692
- tagName = this.input.slice(position, this.position);
1722
+ tagName = this.#scanner.source.slice(position, this.#scanner.position);
1693
1723
  if (PATTERN_FLOW_INDICATORS.test(tagName)) {
1694
1724
  throw this.#createError("Cannot read tag property: tag suffix cannot contain flow indicator characters");
1695
1725
  }
@@ -1709,32 +1739,36 @@ var LoaderState = class {
1709
1739
  throw this.#createError(`Cannot read tag property: undeclared tag handle "${tagHandle}"`);
1710
1740
  }
1711
1741
  readAnchorProperty(anchor) {
1712
- let ch = this.peek();
1742
+ let ch = this.#scanner.peek();
1713
1743
  if (ch !== AMPERSAND) return;
1714
1744
  if (anchor !== null) {
1715
1745
  throw this.#createError("Cannot read anchor property: duplicate anchor property");
1716
1746
  }
1717
- ch = this.next();
1718
- const position = this.position;
1747
+ this.#scanner.next();
1748
+ ch = this.#scanner.peek();
1749
+ const position = this.#scanner.position;
1719
1750
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
1720
- ch = this.next();
1751
+ this.#scanner.next();
1752
+ ch = this.#scanner.peek();
1721
1753
  }
1722
- if (this.position === position) {
1754
+ if (this.#scanner.position === position) {
1723
1755
  throw this.#createError("Cannot read anchor property: name of an anchor node must contain at least one character");
1724
1756
  }
1725
- return this.input.slice(position, this.position);
1757
+ return this.#scanner.source.slice(position, this.#scanner.position);
1726
1758
  }
1727
1759
  readAlias() {
1728
- if (this.peek() !== ASTERISK) return;
1729
- let ch = this.next();
1730
- const position = this.position;
1760
+ if (this.#scanner.peek() !== ASTERISK) return;
1761
+ this.#scanner.next();
1762
+ let ch = this.#scanner.peek();
1763
+ const position = this.#scanner.position;
1731
1764
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch) && !isFlowIndicator(ch)) {
1732
- ch = this.next();
1765
+ this.#scanner.next();
1766
+ ch = this.#scanner.peek();
1733
1767
  }
1734
- if (this.position === position) {
1768
+ if (this.#scanner.position === position) {
1735
1769
  throw this.#createError("Cannot read alias: alias name must contain at least one character");
1736
1770
  }
1737
- const alias = this.input.slice(position, this.position);
1771
+ const alias = this.#scanner.source.slice(position, this.#scanner.position);
1738
1772
  if (!this.anchorMap.has(alias)) {
1739
1773
  throw this.#createError(`Cannot read alias: unidentified alias "${alias}"`);
1740
1774
  }
@@ -1817,7 +1851,7 @@ var LoaderState = class {
1817
1851
  const cond = CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext;
1818
1852
  const flowIndent = cond ? parentIndent : parentIndent + 1;
1819
1853
  if (allowBlockCollections) {
1820
- const blockIndent = this.position - this.lineStart;
1854
+ const blockIndent = this.#scanner.position - this.lineStart;
1821
1855
  const blockSequenceState = this.readBlockSequence(tag, anchor, blockIndent);
1822
1856
  if (blockSequenceState) return this.resolveTag(blockSequenceState);
1823
1857
  const blockMappingState = this.readBlockMapping(tag, anchor, blockIndent, flowIndent);
@@ -1851,7 +1885,7 @@ var LoaderState = class {
1851
1885
  return this.resolveTag(plainScalarState);
1852
1886
  }
1853
1887
  } else if (indentStatus === 0 && CONTEXT_BLOCK_OUT === nodeContext && allowBlockCollections) {
1854
- const blockIndent = this.position - this.lineStart;
1888
+ const blockIndent = this.#scanner.position - this.lineStart;
1855
1889
  const newState2 = this.readBlockSequence(tag, anchor, blockIndent);
1856
1890
  if (newState2) return this.resolveTag(newState2);
1857
1891
  }
@@ -1866,20 +1900,22 @@ var LoaderState = class {
1866
1900
  readDirectives() {
1867
1901
  let hasDirectives = false;
1868
1902
  let version = null;
1869
- let ch = this.peek();
1903
+ let ch = this.#scanner.peek();
1870
1904
  while (ch !== 0) {
1871
1905
  this.skipSeparationSpace(true, -1);
1872
- ch = this.peek();
1906
+ ch = this.#scanner.peek();
1873
1907
  if (this.lineIndent > 0 || ch !== PERCENT) {
1874
1908
  break;
1875
1909
  }
1876
1910
  hasDirectives = true;
1877
- ch = this.next();
1878
- let position = this.position;
1911
+ this.#scanner.next();
1912
+ ch = this.#scanner.peek();
1913
+ let position = this.#scanner.position;
1879
1914
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
1880
- ch = this.next();
1915
+ this.#scanner.next();
1916
+ ch = this.#scanner.peek();
1881
1917
  }
1882
- const directiveName = this.input.slice(position, this.position);
1918
+ const directiveName = this.#scanner.source.slice(position, this.#scanner.position);
1883
1919
  const directiveArgs = [];
1884
1920
  if (directiveName.length < 1) {
1885
1921
  throw this.#createError("Cannot read document: directive name length must be greater than zero");
@@ -1887,13 +1923,14 @@ var LoaderState = class {
1887
1923
  while (ch !== 0) {
1888
1924
  this.skipWhitespaces();
1889
1925
  this.skipComment();
1890
- ch = this.peek();
1926
+ ch = this.#scanner.peek();
1891
1927
  if (isEOL(ch)) break;
1892
- position = this.position;
1928
+ position = this.#scanner.position;
1893
1929
  while (ch !== 0 && !isWhiteSpaceOrEOL(ch)) {
1894
- ch = this.next();
1930
+ this.#scanner.next();
1931
+ ch = this.#scanner.peek();
1895
1932
  }
1896
- directiveArgs.push(this.input.slice(position, this.position));
1933
+ directiveArgs.push(this.#scanner.source.slice(position, this.#scanner.position));
1897
1934
  }
1898
1935
  if (ch !== 0) this.readLineBreak();
1899
1936
  switch (directiveName) {
@@ -1910,20 +1947,20 @@ var LoaderState = class {
1910
1947
  this.dispatchWarning(`unknown document directive "${directiveName}"`);
1911
1948
  break;
1912
1949
  }
1913
- ch = this.peek();
1950
+ ch = this.#scanner.peek();
1914
1951
  }
1915
1952
  return hasDirectives;
1916
1953
  }
1917
1954
  readDocument() {
1918
- const documentStart = this.position;
1955
+ const documentStart = this.#scanner.position;
1919
1956
  this.checkLineBreaks = false;
1920
1957
  this.tagMap = /* @__PURE__ */ new Map();
1921
1958
  this.anchorMap = /* @__PURE__ */ new Map();
1922
1959
  const hasDirectives = this.readDirectives();
1923
1960
  this.skipSeparationSpace(true, -1);
1924
1961
  let result = null;
1925
- if (this.lineIndent === 0 && this.peek() === MINUS && this.peek(1) === MINUS && this.peek(2) === MINUS) {
1926
- this.position += 3;
1962
+ if (this.lineIndent === 0 && this.#scanner.peek() === MINUS && this.#scanner.peek(1) === MINUS && this.#scanner.peek(2) === MINUS) {
1963
+ this.#scanner.position += 3;
1927
1964
  this.skipSeparationSpace(true, -1);
1928
1965
  } else if (hasDirectives) {
1929
1966
  throw this.#createError("Cannot read document: directives end mark is expected");
@@ -1936,21 +1973,21 @@ var LoaderState = class {
1936
1973
  });
1937
1974
  if (newState) result = newState.result;
1938
1975
  this.skipSeparationSpace(true, -1);
1939
- if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.input.slice(documentStart, this.position))) {
1976
+ if (this.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(this.#scanner.source.slice(documentStart, this.#scanner.position))) {
1940
1977
  this.dispatchWarning("non-ASCII line breaks are interpreted as content");
1941
1978
  }
1942
- if (this.position === this.lineStart && this.testDocumentSeparator()) {
1943
- if (this.peek() === DOT) {
1944
- this.position += 3;
1979
+ if (this.#scanner.position === this.lineStart && this.testDocumentSeparator()) {
1980
+ if (this.#scanner.peek() === DOT) {
1981
+ this.#scanner.position += 3;
1945
1982
  this.skipSeparationSpace(true, -1);
1946
1983
  }
1947
- } else if (this.position < this.length - 1) {
1984
+ } else if (!this.#scanner.eof()) {
1948
1985
  throw this.#createError("Cannot read document: end of the stream or a document separator is expected");
1949
1986
  }
1950
1987
  return result;
1951
1988
  }
1952
1989
  *readDocuments() {
1953
- while (this.position < this.length - 1) {
1990
+ while (!this.#scanner.eof()) {
1954
1991
  yield this.readDocument();
1955
1992
  }
1956
1993
  }
@@ -1963,7 +2000,6 @@ function sanitizeInput(input) {
1963
2000
  if (!isEOL(input.charCodeAt(input.length - 1))) input += "\n";
1964
2001
  if (input.charCodeAt(0) === 65279) input = input.slice(1);
1965
2002
  }
1966
- input += "\0";
1967
2003
  return input;
1968
2004
  }
1969
2005
  function parse(content, options = {}) {