@quanta-intellect/vessel-browser 0.1.125 → 0.1.128

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.
@@ -2123,6 +2123,43 @@ function generateStableSelector(el) {
2123
2123
  }
2124
2124
  return uniqueSelector(document2, parts.join(" > ")) || parts.join(" > ");
2125
2125
  }
2126
+ function getEnvFlag(name) {
2127
+ const globalProcess = typeof globalThis === "object" && "process" in globalThis ? globalThis.process : void 0;
2128
+ return globalProcess?.env?.[name];
2129
+ }
2130
+ function isDebugEnabled() {
2131
+ const value = getEnvFlag("VESSEL_DEBUG")?.trim().toLowerCase();
2132
+ return value === "1" || value === "true" || value === "yes" || value === "on";
2133
+ }
2134
+ function writeLog(level, scope, args) {
2135
+ if (level === "debug" && !isDebugEnabled()) {
2136
+ return;
2137
+ }
2138
+ const prefix = `[Vessel ${scope}]`;
2139
+ switch (level) {
2140
+ case "debug":
2141
+ console.debug(prefix, ...args);
2142
+ return;
2143
+ case "info":
2144
+ console.info(prefix, ...args);
2145
+ return;
2146
+ case "warn":
2147
+ console.warn(prefix, ...args);
2148
+ return;
2149
+ case "error":
2150
+ console.error(prefix, ...args);
2151
+ return;
2152
+ }
2153
+ }
2154
+ function createLogger(scope) {
2155
+ return {
2156
+ debug: (...args) => writeLog("debug", scope, args),
2157
+ info: (...args) => writeLog("info", scope, args),
2158
+ warn: (...args) => writeLog("warn", scope, args),
2159
+ error: (...args) => writeLog("error", scope, args)
2160
+ };
2161
+ }
2162
+ const logger = createLogger("ContentScript");
2126
2163
  function looksLikeCorrectOption(value) {
2127
2164
  const text = getTrimmedText(value);
2128
2165
  if (!text) return void 0;
@@ -2140,7 +2177,7 @@ function looksLikeCorrectOption(value) {
2140
2177
  }
2141
2178
  let elementIndex = 0;
2142
2179
  const elementSelectors = {};
2143
- let indexedElements = /* @__PURE__ */ new WeakMap();
2180
+ const indexedElements = /* @__PURE__ */ new WeakMap();
2144
2181
  const indexedElementRefs = {};
2145
2182
  let activeOverlays = [];
2146
2183
  let pageDiffMutationTimer = null;
@@ -2629,6 +2666,17 @@ function classifyOverlayKind(args) {
2629
2666
  if (/alert|warning|notice|success|error/.test(haystack)) return "alert";
2630
2667
  return "overlay";
2631
2668
  }
2669
+ const MAX_OVERLAY_CANDIDATES = 2e3;
2670
+ function forEachOverlayCandidate(maxCandidates, visitor) {
2671
+ if (!document.body) return;
2672
+ let visited = 0;
2673
+ for (const node of document.body.querySelectorAll("*")) {
2674
+ if (!(node instanceof HTMLElement)) continue;
2675
+ if (visited >= maxCandidates) break;
2676
+ visited++;
2677
+ visitor(node);
2678
+ }
2679
+ }
2632
2680
  function detectOverlays() {
2633
2681
  if (!document.body) return [];
2634
2682
  const viewportWidth = window.innerWidth || document.documentElement?.clientWidth || 0;
@@ -2636,8 +2684,8 @@ function detectOverlays() {
2636
2684
  const viewportArea = Math.max(1, viewportWidth * viewportHeight);
2637
2685
  const overlays = [];
2638
2686
  const seen = /* @__PURE__ */ new Set();
2639
- Array.from(document.body.querySelectorAll("*")).forEach((node) => {
2640
- if (!(node instanceof HTMLElement) || seen.has(node)) return;
2687
+ forEachOverlayCandidate(MAX_OVERLAY_CANDIDATES, (node) => {
2688
+ if (seen.has(node)) return;
2641
2689
  if (!isElementVisible(node)) return;
2642
2690
  const style = window.getComputedStyle(node);
2643
2691
  if (style.pointerEvents === "none") return;
@@ -2709,8 +2757,7 @@ function detectDormantOverlays() {
2709
2757
  if (!document.body) return [];
2710
2758
  const seen = /* @__PURE__ */ new Set();
2711
2759
  const matches = [];
2712
- Array.from(document.body.querySelectorAll("*")).forEach((node) => {
2713
- if (!(node instanceof HTMLElement)) return;
2760
+ forEachOverlayCandidate(MAX_OVERLAY_CANDIDATES, (node) => {
2714
2761
  if (isElementVisible(node)) return;
2715
2762
  if (!isLikelyDormantOverlay(node)) return;
2716
2763
  const selector = generateSelector(node);
@@ -3315,7 +3362,7 @@ function vesselExtractContent() {
3315
3362
  const article = reader.parse();
3316
3363
  return extractStructuredContent(article || void 0);
3317
3364
  } catch (error) {
3318
- console.error("Vessel content extraction error:", error);
3365
+ logger.error("Vessel content extraction error:", error);
3319
3366
  return extractStructuredContent();
3320
3367
  }
3321
3368
  }