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