const VISIBLE_TEXT_THRESHOLD = 200;
const SCRIPT_RATIO_THRESHOLD = 0.8;
const SUBSTANTIVE_BODY_THRESHOLD = 500;
function stripScriptsAndStyles(html) {
  return html.replace(/<script[\s\S]*?<\/script>/gi, "").replace(/<style[\s\S]*?<\/style>/gi, "");
}
function extractVisibleText(html) {
  const stripped = stripScriptsAndStyles(html);
  const noTags = stripped.replace(/<[^>]+>/g, " ");
  return noTags.replace(/\s+/g, " ").trim();
}
function extractVisibleTextExcludingNoscript(html) {
  const withoutNoscript = html.replace(/<noscript[\s\S]*?<\/noscript>/gi, "");
  return extractVisibleText(withoutNoscript);
}
function hasSpaShellIndicator(html) {
  const emptyShell = [
    /<div[^>]+id=["']root["'][^>]*>\s*<\/div>/i,
    /<div[^>]+id=["']app["'][^>]*>\s*<\/div>/i,
    /<div[^>]+id=["']__next["'][^>]*>\s*<\/div>/i
  ];
  if (emptyShell.some((pattern) => pattern.test(html))) return true;
  const hasShellId = /<div[^>]+id=["'](?:root|app|__next)["']/i.test(html);
  if (!hasShellId) return false;
  const hasSemanticContent = /<main[\s>]|<article[\s>]/i.test(html);
  if (hasSemanticContent) return false;
  const visibleText = extractVisibleTextExcludingNoscript(html);
  return visibleText.length < SUBSTANTIVE_BODY_THRESHOLD;
}
function hasNextData(html) {
  if (!/__NEXT_DATA__/.test(html)) return false;
  const withoutScripts = stripScriptsAndStyles(html);
  const visibleText = withoutScripts.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
  return visibleText.length < VISIBLE_TEXT_THRESHOLD;
}
function hasNoscriptRequired(html) {
  const noscriptMatches = html.match(/<noscript[^>]*>([\s\S]*?)<\/noscript>/gi);
  if (!noscriptMatches) return false;
  const looksLikeJsWarning = noscriptMatches.some((tag) => {
    const inner = tag.replace(/<[^>]+>/g, "").toLowerCase();
    return inner.includes("javascript") || inner.includes("enable");
  });
  if (!looksLikeJsWarning) return false;
  const bodyText = extractVisibleTextExcludingNoscript(html);
  return bodyText.length < SUBSTANTIVE_BODY_THRESHOLD;
}
function hasHighScriptRatio(html) {
  const bodyMatch = html.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
  const bodyContent = bodyMatch ? bodyMatch[1] : html;
  const scriptMatches = bodyContent.match(/<script[\s\S]*?<\/script>/gi) ?? [];
  const scriptText = scriptMatches.join("");
  const scriptLen = scriptText.length;
  const totalLen = bodyContent.length;
  if (totalLen === 0) return false;
  return scriptLen / totalLen > SCRIPT_RATIO_THRESHOLD;
}
function contentAppearsEmpty(html) {
  const visibleText = extractVisibleText(html);
  if (visibleText.length < VISIBLE_TEXT_THRESHOLD) return true;
  if (hasSpaShellIndicator(html)) return true;
  if (hasNextData(html)) return true;
  if (hasNoscriptRequired(html)) return true;
  if (hasHighScriptRatio(html)) return true;
  return false;
}
export {
  contentAppearsEmpty
};
//# sourceMappingURL=content-check.js.map