var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/pisellUrl/utils/urlValidator.ts
var urlValidator_exports = {};
__export(urlValidator_exports, {
  parseUrl: () => parseUrl,
  validateUrl: () => validateUrl,
  validateUrlByRegex: () => validateUrlByRegex,
  validateUrlProtocol: () => validateUrlProtocol
});
module.exports = __toCommonJS(urlValidator_exports);
function validateUrl(url) {
  if (!url) return true;
  try {
    new URL(url);
    return true;
  } catch (error) {
    return false;
  }
}
function validateUrlByRegex(url) {
  if (!url) return true;
  const STRICT_URL_REGEX = /^(https?:\/\/)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)$/;
  return STRICT_URL_REGEX.test(url);
}
function parseUrl(url) {
  try {
    const urlObj = new URL(url);
    return {
      protocol: urlObj.protocol.replace(":", ""),
      host: urlObj.hostname,
      port: urlObj.port,
      pathname: urlObj.pathname,
      search: urlObj.search,
      hash: urlObj.hash
    };
  } catch {
    return null;
  }
}
function validateUrlProtocol(url, allowedProtocols) {
  const errors = [];
  const parts = parseUrl(url);
  if (!parts) {
    return { isValid: true, errors };
  }
  if (parts.protocol && !allowedProtocols.includes(parts.protocol)) {
    errors.push(`只允许以下协议：${allowedProtocols.join(", ")}`);
  }
  return {
    isValid: errors.length === 0,
    errors
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  parseUrl,
  validateUrl,
  validateUrlByRegex,
  validateUrlProtocol
});
