"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const index = require("../micromark-util-character/index.cjs");
function normalizeUri(value) {
  const result = [];
  let index$1 = -1;
  let start = 0;
  let skip = 0;
  while (++index$1 < value.length) {
    const code = value.charCodeAt(index$1);
    let replace = "";
    if (code === 37 && index.asciiAlphanumeric(value.charCodeAt(index$1 + 1)) && index.asciiAlphanumeric(value.charCodeAt(index$1 + 2))) {
      skip = 2;
    } else if (code < 128) {
      if (!/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(code))) {
        replace = String.fromCharCode(code);
      }
    } else if (code > 55295 && code < 57344) {
      const next = value.charCodeAt(index$1 + 1);
      if (code < 56320 && next > 56319 && next < 57344) {
        replace = String.fromCharCode(code, next);
        skip = 1;
      } else {
        replace = "�";
      }
    } else {
      replace = String.fromCharCode(code);
    }
    if (replace) {
      result.push(value.slice(start, index$1), encodeURIComponent(replace));
      start = index$1 + skip + 1;
      replace = "";
    }
    if (skip) {
      index$1 += skip;
      skip = 0;
    }
  }
  return result.join("") + value.slice(start);
}
exports.normalizeUri = normalizeUri;
//# sourceMappingURL=index.cjs.map
