(() => {
  var __create = Object.create;
  var __defProp = Object.defineProperty;
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  var __getOwnPropNames = Object.getOwnPropertyNames;
  var __getProtoOf = Object.getPrototypeOf;
  var __hasOwnProp = Object.prototype.hasOwnProperty;
  var __commonJS = (cb, mod) => function __require() {
    return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  };
  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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
    // If the importer is in node compatibility mode or this is not an ESM
    // file that has been converted to a CommonJS file using a Babel-
    // compatible transform (i.e. "__esModule" has not been set), then set
    // "default" to the CommonJS "module.exports" for node compatibility.
    isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
    mod
  ));

  // src/shared/version.js
  var require_version = __commonJS({
    "src/shared/version.js"(exports, module) {
      (function attachBuildIdentity(root, factory) {
        const api = factory();
        if (typeof module === "object" && module.exports) module.exports = api;
        root.TfaBuildIdentity = api;
      })(typeof globalThis === "object" ? globalThis : exports, function createBuildIdentity() {
        "use strict";
        const EXTENSION_VERSION = "1.25.34";
        const injectedFingerprint = true ? "ad6e691b8aca11ed33afdee80003f6267e631e774c668aa45122b2917e7c7890" : "";
        const fingerprint = injectedFingerprint || `source:${EXTENSION_VERSION}`;
        return Object.freeze({ version: EXTENSION_VERSION, fingerprint });
      });
    }
  });

  // src/shared/shortcut-logic.js
  var require_shortcut_logic = __commonJS({
    "src/shared/shortcut-logic.js"(exports, module) {
      (function(global) {
        const MOD_KEYS = ["Alt", "Control", "Shift", "Meta"];
        const KEY_TO_CODE = {
          q: "KeyQ",
          w: "KeyW",
          e: "KeyE",
          r: "KeyR",
          t: "KeyT",
          y: "KeyY",
          u: "KeyU",
          i: "KeyI",
          o: "KeyO",
          p: "KeyP",
          a: "KeyA",
          s: "KeyS",
          d: "KeyD",
          f: "KeyF",
          g: "KeyG",
          h: "KeyH",
          j: "KeyJ",
          k: "KeyK",
          l: "KeyL",
          z: "KeyZ",
          x: "KeyX",
          c: "KeyC",
          v: "KeyV",
          b: "KeyB",
          n: "KeyN",
          m: "KeyM",
          " ": "Space",
          "`": "Backquote",
          "1": "Digit1",
          "2": "Digit2",
          "3": "Digit3",
          "4": "Digit4",
          "5": "Digit5",
          "6": "Digit6",
          "7": "Digit7",
          "8": "Digit8",
          "9": "Digit9",
          "0": "Digit0",
          "-": "Minus",
          "=": "Equal",
          "[": "BracketLeft",
          "]": "BracketRight",
          "\\": "Backslash",
          ";": "Semicolon",
          "'": "Quote",
          ",": "Comma",
          ".": "Period",
          "/": "Slash",
          Tab: "Tab",
          Escape: "Escape"
        };
        function keyLabel(key) {
          if (key === " ") return "Space";
          if (key === "Control") return "Ctrl";
          if (key === "Meta") return "Meta";
          if (key === "`") return "`";
          if (key === "-") return "-";
          if (key === "=") return "=";
          return key && key.length === 1 ? key.toUpperCase() : key;
        }
        function makeLabel(config) {
          if (config.type === "combo") {
            return (config.modifiers || []).map(keyLabel).join("+") + "+" + keyLabel(config.key);
          }
          return keyLabel(config.key);
        }
        function normalizeTriggerConfig(value) {
          if (value.type === "combo") {
            return {
              type: "combo",
              key: value.key,
              modifiers: value.modifiers || [],
              label: value.label || makeLabel(value),
              code: value.code || KEY_TO_CODE[(value.key || "").toLowerCase()] || ""
            };
          }
          return {
            type: "single",
            key: value.key,
            modifiers: [],
            label: value.label || keyLabel(value.key),
            code: value.code || KEY_TO_CODE[(value.key || "").toLowerCase()] || ""
          };
        }
        function buildTriggerConfigFromPreset(preset) {
          if (typeof preset !== "string") return null;
          if (preset.startsWith("combo:")) {
            const parts = preset.slice(6).split("+");
            const mainKey = parts.pop();
            if (!mainKey) return null;
            return normalizeTriggerConfig({ type: "combo", key: mainKey, modifiers: parts });
          }
          if (preset.startsWith("single:")) {
            return normalizeTriggerConfig({ type: "single", key: preset.slice(7) });
          }
          return null;
        }
        function matchesTriggerPreset(config, preset) {
          if (!config || !config.type || typeof config.key === "undefined") return false;
          const presetConfig = buildTriggerConfigFromPreset(preset);
          if (!presetConfig) return false;
          const cfg = normalizeTriggerConfig(config);
          if (cfg.type !== presetConfig.type) return false;
          if (String(cfg.key).toLowerCase() !== String(presetConfig.key).toLowerCase()) return false;
          const cfgMods = [...cfg.modifiers || []].sort().join(",");
          const presetMods = [...presetConfig.modifiers || []].sort().join(",");
          return cfgMods === presetMods;
        }
        function isModifier(key) {
          return MOD_KEYS.includes(key);
        }
        function hasExactModifiers(config, payload) {
          const configuredModifiers = config.modifiers || [];
          const mainModifier = config.type === "single" && isModifier(config.key) ? config.key : null;
          const modifierFlags = {
            Alt: payload.altKey,
            Control: payload.ctrlKey,
            Shift: payload.shiftKey,
            Meta: payload.metaKey
          };
          for (const mod of MOD_KEYS) {
            const expected = mod === mainModifier || configuredModifiers.includes(mod);
            if (Boolean(modifierFlags[mod]) !== expected) return false;
          }
          return true;
        }
        function matchesConfiguredMainKey(config, eventLike) {
          const cfg = normalizeTriggerConfig(config);
          const isIme = eventLike.key === "Process" || eventLike.keyCode === 229;
          const expectedCode = cfg.code || KEY_TO_CODE[(cfg.key || "").toLowerCase()];
          if (expectedCode && eventLike.code === expectedCode) return true;
          return !isIme && String(eventLike.key).toLowerCase() === String(cfg.key).toLowerCase();
        }
        function isEventPartOfTrigger(config, eventLike) {
          const cfg = normalizeTriggerConfig(config);
          if (matchesConfiguredMainKey(cfg, eventLike)) return true;
          return cfg.type === "combo" && (cfg.modifiers || []).includes(eventLike.key);
        }
        function matchesTriggerFromKeyboardEvent(config, eventLike, toggles) {
          const cfg = normalizeTriggerConfig(config);
          const singleEnabled = toggles.singleEnabled !== false;
          const comboEnabled = toggles.comboEnabled !== false;
          if (cfg.type === "combo") {
            return comboEnabled && hasExactModifiers(cfg, eventLike) && matchesConfiguredMainKey(cfg, eventLike);
          }
          return singleEnabled && hasExactModifiers(cfg, eventLike) && matchesConfiguredMainKey(cfg, eventLike);
        }
        function matchesTriggerFromForwardedEvent(config, payload, toggles) {
          return matchesTriggerFromKeyboardEvent(config, payload, toggles);
        }
        function createShortcutSession() {
          const pressed = /* @__PURE__ */ new Map();
          const triggerTokens = /* @__PURE__ */ new Set();
          let active = false;
          let canceled = false;
          let activeConfig = null;
          function physicalKeyToken(eventLike) {
            return eventLike.code || `${eventLike.key}:${eventLike.location || 0}`;
          }
          function keyDown(config, eventLike, toggles) {
            if (eventLike.repeat === true) {
              return { trigger: false, cancel: false };
            }
            const token = physicalKeyToken(eventLike);
            pressed.set(token, eventLike);
            if (active) {
              if (!canceled && !isEventPartOfTrigger(activeConfig, eventLike)) {
                canceled = true;
                return { trigger: false, cancel: true };
              }
              return { trigger: false, cancel: false };
            }
            const cfg = normalizeTriggerConfig(config);
            const expectedCount = cfg.type === "combo" ? new Set(cfg.modifiers || []).size + 1 : 1;
            const exactPressedKeys = pressed.size === expectedCount && [...pressed.values()].every((pressedEvent) => isEventPartOfTrigger(cfg, pressedEvent));
            if (exactPressedKeys && matchesTriggerFromKeyboardEvent(cfg, eventLike, toggles)) {
              active = true;
              activeConfig = cfg;
              for (const pressedToken of pressed.keys()) triggerTokens.add(pressedToken);
              return { trigger: true, cancel: false };
            }
            return { trigger: false, cancel: false };
          }
          function keyUp(eventLike) {
            const token = physicalKeyToken(eventLike);
            const triggerReleased = triggerTokens.delete(token);
            pressed.delete(token);
            const ended = active && triggerTokens.size === 0;
            const wasCanceled = canceled;
            if (ended) {
              active = false;
              canceled = false;
              activeConfig = null;
            }
            return {
              triggerReleased,
              ended,
              canceled: ended ? wasCanceled : canceled
            };
          }
          function reset() {
            pressed.clear();
            triggerTokens.clear();
            active = false;
            canceled = false;
            activeConfig = null;
          }
          function getState() {
            return {
              active,
              canceled,
              pressedCount: pressed.size,
              triggerCount: triggerTokens.size
            };
          }
          return { keyDown, keyUp, reset, getState };
        }
        function buildFullKey(config) {
          const cfg = normalizeTriggerConfig(config);
          const modifiers = (cfg.modifiers || []).map(keyLabel).sort().join("+");
          return modifiers ? `${modifiers}+${keyLabel(cfg.key)}` : keyLabel(cfg.key);
        }
        function checkShortcutConflict(config, platform) {
          const cfg = normalizeTriggerConfig(config);
          const fullKey = buildFullKey(cfg);
          const warnings = [];
          const errors = [];
          if (platform.isMac && cfg.key === "Meta") {
            errors.push("Mac \u4E0A Command \u952E\u4F1A\u88AB\u7CFB\u7EDF\u5360\u7528\uFF0C\u4E0D\u80FD\u53EF\u9760\u5730\u7528\u4F5C\u5355\u952E\u89E6\u53D1\u3002");
          }
          if (platform.isMac && cfg.modifiers && cfg.modifiers.includes("Meta")) {
            warnings.push("Mac \u4E0A Cmd \u7EC4\u5408\u952E\u5E38\u88AB\u7CFB\u7EDF\u6216\u6D4F\u89C8\u5668\u62E6\u622A\u3002");
          }
          if (cfg.type === "single" && cfg.key === "Shift") {
            warnings.push("Shift \u5355\u952E\u5E38\u4E0E\u8F93\u5165\u6CD5\u5207\u6362\u51B2\u7A81\u3002");
          }
          if (cfg.type === "single" && cfg.key === " ") {
            warnings.push("Space \u5355\u952E\u4F1A\u5F71\u54CD\u9875\u9762\u6EDA\u52A8\u3002");
          }
          if (cfg.type === "single" && cfg.key === "Control") {
            warnings.push("Ctrl \u5355\u952E\u5728\u90E8\u5206\u573A\u666F\u4E0B\u4F1A\u88AB\u6D4F\u89C8\u5668\u6216\u7CFB\u7EDF\u62E6\u622A\u3002");
          }
          if (cfg.type === "single" && cfg.key === "Alt") {
            warnings.push("Alt \u5355\u952E\u53EF\u80FD\u89E6\u53D1\u6D4F\u89C8\u5668\u83DC\u5355\u6216\u6743\u9650\u6C14\u6CE1\uFF0C\u7A33\u5B9A\u6027\u901A\u5E38\u4E0D\u5982 Alt+Q\u3002");
          }
          if (platform.browserShortcuts && platform.browserShortcuts[fullKey]) {
            warnings.push(`\u4E0E\u6D4F\u89C8\u5668\u5FEB\u6377\u952E\u51B2\u7A81\uFF1A${platform.browserShortcuts[fullKey]}\uFF08${fullKey}\uFF09`);
          }
          if (platform.winShortcuts && platform.isWin && platform.winShortcuts[fullKey]) {
            warnings.push(`\u4E0E Windows \u7CFB\u7EDF\u70ED\u952E\u51B2\u7A81\uFF1A${platform.winShortcuts[fullKey]}\uFF08${fullKey}\uFF09`);
          }
          if (platform.macShortcuts && platform.isMac && platform.macShortcuts[fullKey]) {
            warnings.push(`\u4E0E macOS \u7CFB\u7EDF\u70ED\u952E\u51B2\u7A81\uFF1A${platform.macShortcuts[fullKey]}\uFF08${fullKey}\uFF09`);
          }
          if (platform.imeShortcuts) {
            const singleKey = keyLabel(cfg.key);
            if (cfg.type === "single" && platform.imeShortcuts[singleKey]) {
              warnings.push(`\u4E0E\u8F93\u5165\u6CD5\u70ED\u952E\u51B2\u7A81\uFF1A${platform.imeShortcuts[singleKey]}`);
            }
            if (platform.imeShortcuts[fullKey]) {
              warnings.push(`\u4E0E\u8F93\u5165\u6CD5\u70ED\u952E\u51B2\u7A81\uFF1A${platform.imeShortcuts[fullKey]}`);
            }
          }
          return { warnings, errors, fullKey };
        }
        const api = {
          MOD_KEYS,
          KEY_TO_CODE,
          keyLabel,
          makeLabel,
          normalizeTriggerConfig,
          buildTriggerConfigFromPreset,
          matchesTriggerPreset,
          isModifier,
          matchesConfiguredMainKey,
          isEventPartOfTrigger,
          matchesTriggerFromKeyboardEvent,
          matchesTriggerFromForwardedEvent,
          createShortcutSession,
          checkShortcutConflict
        };
        if (typeof module !== "undefined" && module.exports) module.exports = api;
        global.TfaShortcutLogic = api;
      })(typeof globalThis !== "undefined" ? globalThis : exports);
    }
  });

  // src/content/content-feature-host.js
  var require_content_feature_host = __commonJS({
    "src/content/content-feature-host.js"(exports, module) {
      (function attachContentFeatureHost(root, factory) {
        const api = factory();
        if (typeof module === "object" && module.exports) module.exports = api;
        root.TfaContentFeatureHost = api;
      })(typeof globalThis === "object" ? globalThis : exports, function createContentFeatureHostModule() {
        "use strict";
        const FEATURE_NAMES = Object.freeze(["web_dock", "workspace", "guidance"]);
        const LOAD_MESSAGE = "TFA_LOAD_CONTENT_FEATURE";
        function createContentFeatureHost(options = {}) {
          const fingerprint = String(options.fingerprint || "");
          const send = options.send;
          const features = /* @__PURE__ */ new Map();
          const loads = /* @__PURE__ */ new Map();
          const pendingIntents = /* @__PURE__ */ new Map();
          const featureEpochs = /* @__PURE__ */ new Map();
          let destroyed = false;
          const validName = (name) => FEATURE_NAMES.includes(String(name || ""));
          function featureRecord(name) {
            return features.get(String(name || "")) || null;
          }
          function featureEpoch(name) {
            return featureEpochs.get(String(name || "")) || 0;
          }
          function invalidateFeature(name) {
            const feature = String(name || "");
            const next = featureEpoch(feature) + 1;
            featureEpochs.set(feature, next);
            return next;
          }
          async function invoke(record, intent, epoch = featureEpoch(record?.definition?.name)) {
            const name = String(record?.definition?.name || "");
            if (!record || destroyed || features.get(name) !== record || featureEpoch(name) !== epoch) return false;
            let result = false;
            try {
              result = await record.start(intent);
            } catch (_error) {
              result = false;
            }
            if (destroyed || features.get(name) !== record || featureEpoch(name) !== epoch) return false;
            record.started = result !== false;
            return record.started;
          }
          function registerFeature(definition = {}) {
            const name = String(definition.name || "");
            if (destroyed || !validName(name) || typeof definition.start !== "function" || typeof definition.destroy !== "function") return false;
            if (String(definition.fingerprint || "") !== fingerprint) return false;
            const current = features.get(name);
            if (current?.definition === definition) return true;
            if (current) return false;
            const record = { definition, start: definition.start, destroy: definition.destroy, started: false, ready: null, queue: Promise.resolve(false) };
            features.set(name, record);
            const intent = pendingIntents.get(name);
            if (pendingIntents.has(name)) {
              pendingIntents.delete(name);
              const epoch = featureEpoch(name);
              record.ready = record.queue = record.queue.then(() => invoke(record, intent, epoch)).catch(() => false);
            }
            return true;
          }
          async function requestFeature(name, intent) {
            const feature = String(name || "");
            if (destroyed || !validName(feature)) return false;
            pendingIntents.set(feature, intent);
            const registered = featureRecord(feature);
            if (registered) {
              pendingIntents.delete(feature);
              const epoch2 = featureEpoch(feature);
              registered.queue = registered.queue.catch(() => false).then(() => invoke(registered, intent, epoch2));
              return registered.queue;
            }
            if (loads.has(feature)) return loads.get(feature);
            if (typeof send !== "function") return false;
            const epoch = featureEpoch(feature);
            let load;
            load = Promise.resolve(send({ type: LOAD_MESSAGE, feature, intent })).then(async (response) => {
              if (!response?.ok || destroyed || featureEpoch(feature) !== epoch) return false;
              const loaded = featureRecord(feature);
              if (!loaded) return false;
              const latest = pendingIntents.get(feature);
              if (pendingIntents.has(feature)) {
                pendingIntents.delete(feature);
                return invoke(loaded, latest, epoch);
              }
              return loaded.ready ? loaded.ready : loaded.started;
            }).catch(() => false).finally(() => {
              if (loads.get(feature) === load) loads.delete(feature);
            });
            loads.set(feature, load);
            return load;
          }
          function hasFeature(name) {
            return Boolean(featureRecord(name));
          }
          function cacheIntent(name, intent) {
            if (destroyed || !validName(name)) return false;
            pendingIntents.set(String(name), intent);
            return true;
          }
          function destroyFeature(name) {
            const feature = String(name || "");
            if (!validName(feature)) return false;
            invalidateFeature(feature);
            pendingIntents.delete(feature);
            loads.delete(feature);
            const record = featureRecord(feature);
            if (record) {
              features.delete(feature);
              try {
                record.destroy();
              } catch (_error) {
              }
            }
            return true;
          }
          function destroy() {
            if (destroyed) return false;
            destroyed = true;
            [...FEATURE_NAMES].forEach(destroyFeature);
            loads.clear();
            pendingIntents.clear();
            return true;
          }
          function inspect() {
            return { destroyed, fingerprint, registered: [...features.keys()], loading: [...loads.keys()], pending: [...pendingIntents.keys()] };
          }
          return Object.freeze({ registerFeature, requestFeature, hasFeature, cacheIntent, destroyFeature, destroy, inspect });
        }
        return Object.freeze({ FEATURE_NAMES, LOAD_MESSAGE, createContentFeatureHost });
      });
    }
  });

  // src/content/content-bootstrap-runtime.js
  var require_content_bootstrap_runtime = __commonJS({
    "src/content/content-bootstrap-runtime.js"(exports, module) {
      (function attachContentBootstrapRuntime(root, factory) {
        const api = factory();
        if (typeof module === "object" && module.exports) module.exports = api;
        root.TfaContentBootstrapRuntime = api;
      })(typeof globalThis === "object" ? globalThis : exports, function createContentBootstrapRuntimeModule() {
        "use strict";
        const OWNER_KEY = "__TFA_OWNER__";
        const FEATURE_HOST_KEY = "__TFA_FEATURE_HOST__";
        const SEARCH_PERMISSIONS_CHANGED_EVENT = "tfa:web-dock-search-permissions-changed";
        const DOCK_BROADCASTS = /* @__PURE__ */ new Set([
          "WEB_DOCK_CONFIG_CHANGED",
          "WEB_DOCK_RECENTLY_CLOSED_CHANGED",
          "WEB_DOCK_SEARCH_PERMISSIONS_CHANGED",
          "WEB_DOCK_ZOOM_CHANGED"
        ]);
        const GUIDANCE_PROMPT_KEY = "tfa_active_guidance_prompt";
        const ACTIVE_GUIDANCE_CLAIM_MESSAGE = "ACTIVE_GUIDANCE_CLAIM";
        const ACTIVE_GUIDANCE_CONFIRM_MESSAGE = "ACTIVE_GUIDANCE_CONFIRM";
        const ACTIVE_GUIDANCE_RELEASE_MESSAGE = "ACTIVE_GUIDANCE_RELEASE";
        const ACTIVE_GUIDANCE_DISMISS_MESSAGE = "ACTIVE_GUIDANCE_DISMISS";
        const ACTIVE_GUIDANCE_SHORTCUT_EVENT = "tfa:active-guidance-shortcut";
        const DEFAULT_DOCK_BOOTSTRAP_CONFIG = Object.freeze({ enabled: true, autoHide: false });
        function createContentBootstrapRuntime(options = {}) {
          const windowRef = options.window || globalThis.window;
          const documentRef = options.document || globalThis.document;
          const chromeApi = options.chrome || globalThis.chrome;
          const identity = options.identity || globalThis.TfaBuildIdentity || {};
          const featureHostModule = options.featureHost || globalThis.TfaContentFeatureHost;
          const shortcutLogic = options.shortcutLogic || globalThis.TfaShortcutLogic;
          const captureSurfaceLeaseMs = Math.max(100, Number(options.captureSurfaceLeaseMs) || 2500);
          const workspaceRevealPollMs = Math.max(10, Number(options.workspaceRevealPollMs) || 25);
          const guidanceReleaseMessageTimeoutMs = Math.max(
            25,
            Number(options.guidanceReleaseMessageTimeoutMs) || 500
          );
          const guidanceReleaseRetryDelays = Array.isArray(options.guidanceReleaseRetryDelays) ? options.guidanceReleaseRetryDelays.map((value) => Math.max(0, Number(value) || 0)) : [40, 120, 300, 700];
          const guidanceReleaseContinuationDelayMs = Math.max(
            25,
            Number(options.guidanceReleaseContinuationDelayMs) || 5e3
          );
          if (!windowRef || !documentRef || !chromeApi?.runtime?.onMessage || !featureHostModule || !shortcutLogic) throw new Error("content bootstrap dependencies unavailable");
          const version = String(identity.version || "unknown");
          const fingerprint = String(identity.fingerprint || `legacy:${version}`);
          const previous = windowRef[OWNER_KEY];
          if (previous?.state === "active" && previous.fingerprint === fingerprint && previous.featureHost) return previous.bootstrap;
          previous?.dispose?.();
          const lastGeneration = Math.max(0, Number(previous?.generation) || 0, Number(windowRef.__TFA_GENERATION__) || 0);
          const generation = lastGeneration + 1;
          const instanceId = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
          const send = (message) => new Promise((resolve) => {
            try {
              chromeApi.runtime.sendMessage(message, (response) => resolve(response || {}));
            } catch (_error) {
              resolve({ ok: false });
            }
          });
          const featureHost = featureHostModule.createContentFeatureHost({ fingerprint, send });
          const listeners = [];
          const latestBroadcasts = /* @__PURE__ */ new Map();
          let destroyed = false;
          let dockConfig = null;
          let guidanceRevision = 0;
          let desiredGuidancePromptId = "";
          let claimedGuidancePromptId = "";
          let guidanceVisible = false;
          const releasedGuidancePromptIds = /* @__PURE__ */ new Set();
          const guidanceReleaseCompensations = /* @__PURE__ */ new Map();
          const workspaceDockSuppressions = /* @__PURE__ */ new Set();
          let captureSurfaceStates = [];
          const captureSurfaceNodes = /* @__PURE__ */ new Set();
          let captureSurfaceObserver = null;
          const captureSurfaceLeases = /* @__PURE__ */ new Map();
          let anonymousCaptureLeaseSequence = 0;
          const owner = { version, fingerprint, generation, instanceId, state: "active", featureHost: true, featureHostApi: featureHost, bootstrap: null, dispose: null };
          Object.assign(windowRef, {
            [OWNER_KEY]: owner,
            [FEATURE_HOST_KEY]: featureHost,
            __TFA_INJECTED__: true,
            __TFA_VERSION__: version,
            __TFA_FINGERPRINT__: fingerprint,
            __TFA_GENERATION__: generation,
            __TFA_INSTANCE__: instanceId
          });
          function listen(target, type, handler, capture) {
            target.addEventListener(type, handler, capture);
            listeners.push([target, type, handler, capture]);
          }
          function requestWorkspace(intent) {
            return featureHost.requestFeature("workspace", intent);
          }
          function hideDockForWorkspaceOpen() {
            const saved = [];
            const suppressed = /* @__PURE__ */ new Set();
            const observedRoots = /* @__PURE__ */ new Map();
            const MutationObserverConstructor = options.MutationObserver || windowRef?.MutationObserver;
            let restored = false;
            const observe = (root) => {
              if (!root || typeof MutationObserverConstructor !== "function" || observedRoots.has(root)) return;
              const observer = new MutationObserverConstructor(() => suppress2());
              try {
                observer.observe(root, { childList: true, subtree: true });
                observedRoots.set(root, observer);
              } catch (_error) {
                observer.disconnect?.();
              }
            };
            function suppress2() {
              if (restored) return false;
              observe(documentRef.documentElement);
              for (const host of documentRef.querySelectorAll?.('[data-tfa-host="true"]') || []) {
                const root = host?.shadowRoot;
                observe(root);
                const matches = root?.querySelectorAll?.(".web-dock-shell") || [];
                for (const dock of matches) {
                  if (!dock?.style || suppressed.has(dock)) continue;
                  suppressed.add(dock);
                  saved.push([
                    dock,
                    dock.style.getPropertyValue?.("visibility") || "",
                    dock.style.getPropertyPriority?.("visibility") || ""
                  ]);
                  dock.style.setProperty?.("visibility", "hidden", "important");
                }
              }
              return true;
            }
            suppress2();
            const restore = () => {
              if (restored) return false;
              restored = true;
              for (const observer of observedRoots.values()) observer.disconnect?.();
              observedRoots.clear();
              for (const [dock, value, priority] of saved) {
                if (!dock?.style) continue;
                if (value) dock.style.setProperty?.("visibility", value, priority);
                else dock.style.removeProperty?.("visibility");
              }
              workspaceDockSuppressions.delete(restore);
              return true;
            };
            restore.suppress = suppress2;
            workspaceDockSuppressions.add(restore);
            return restore;
          }
          function workspaceRevealed() {
            if (owner.workspaceVisible === true) return true;
            for (const host of documentRef.querySelectorAll?.('[data-tfa-host="true"]') || []) {
              const overlay = host?.shadowRoot?.querySelector?.("#overlay.show");
              if (overlay && overlay.hidden !== true && overlay.getAttribute?.("aria-hidden") !== "true") return true;
            }
            return false;
          }
          function requestWorkspaceFromShortcut(intent) {
            const restoreDock = hideDockForWorkspaceOpen();
            let revealTimer = null;
            const stop = () => {
              if (revealTimer != null) windowRef.clearTimeout?.(revealTimer);
              revealTimer = null;
              return restoreDock();
            };
            const poll = () => {
              if (destroyed || workspaceRevealed()) {
                stop();
                return;
              }
              restoreDock.suppress?.();
              revealTimer = windowRef.setTimeout?.(poll, workspaceRevealPollMs) || null;
              revealTimer?.unref?.();
            };
            poll();
            let result;
            try {
              result = requestWorkspace(intent);
            } catch (error) {
              stop();
              throw error;
            }
            void Promise.resolve(result).then((opened) => {
              if (opened === false || opened == null || workspaceRevealed()) stop();
            }, stop);
            return result;
          }
          function releaseGuidanceClaim(promptId, options2 = {}) {
            if (!promptId || releasedGuidancePromptIds.has(promptId)) {
              return Promise.resolve({ ok: true, released: false });
            }
            let compensation = guidanceReleaseCompensations.get(promptId);
            if (!compensation) {
              compensation = {
                discard: options2.discard === true,
                work: null,
                lastResponse: null,
                retryTimer: null
              };
              guidanceReleaseCompensations.set(promptId, compensation);
            } else if (options2.discard === true) {
              compensation.discard = true;
            }
            if (compensation.work) return compensation.work;
            const wait = (delay) => new Promise((resolve) => windowRef.setTimeout?.(resolve, delay));
            const sendRelease = (message) => new Promise((resolve) => {
              let settled = false;
              const finish = (response) => {
                if (settled) return;
                settled = true;
                windowRef.clearTimeout?.(timer);
                resolve(response || { ok: false });
              };
              const timer = windowRef.setTimeout?.(
                () => finish({ ok: false, timeout: true }),
                guidanceReleaseMessageTimeoutMs
              );
              void send(message).then(finish, () => finish({ ok: false }));
            });
            compensation.work = (async () => {
              const attempts = guidanceReleaseRetryDelays.length + 1;
              for (let index = 0; index < attempts; index += 1) {
                if (index > 0) await wait(guidanceReleaseRetryDelays[index - 1]);
                const response = await sendRelease({
                  type: ACTIVE_GUIDANCE_RELEASE_MESSAGE,
                  promptId,
                  discard: compensation.discard
                });
                compensation.lastResponse = response;
                const semanticallyReleased = response?.ok === true && (compensation.discard ? response.released === true && response.discarded === true : true);
                if (semanticallyReleased) {
                  if (compensation.retryTimer != null) {
                    windowRef.clearTimeout?.(compensation.retryTimer);
                    compensation.retryTimer = null;
                  }
                  releasedGuidancePromptIds.add(promptId);
                  guidanceReleaseCompensations.delete(promptId);
                  return response;
                }
              }
              if (compensation.retryTimer == null) {
                compensation.retryTimer = windowRef.setTimeout?.(() => {
                  compensation.retryTimer = null;
                  if (!releasedGuidancePromptIds.has(promptId)) {
                    void releaseGuidanceClaim(promptId, { discard: compensation.discard });
                  }
                }, guidanceReleaseContinuationDelayMs) || null;
                compensation.retryTimer?.unref?.();
              }
              return compensation.lastResponse || { ok: false };
            })().finally(() => {
              compensation.work = null;
            });
            return compensation.work;
          }
          function cancelPendingGuidanceForWorkspaceOpen() {
            const promptId = desiredGuidancePromptId || claimedGuidancePromptId;
            if (!promptId) return false;
            guidanceRevision += 1;
            desiredGuidancePromptId = "";
            claimedGuidancePromptId = "";
            guidanceVisible = false;
            featureHost.destroyFeature("guidance");
            void releaseGuidanceClaim(promptId, { discard: true });
            return true;
          }
          async function syncGuidance(prompt) {
            if (owner.surfaceMode === "newtab" || /\/newtab\.html$/i.test(String(windowRef.location?.pathname || ""))) return false;
            const revision = ++guidanceRevision;
            const promptId = typeof prompt?.id === "string" ? prompt.id : "";
            desiredGuidancePromptId = promptId;
            if (!promptId) {
              const previousId = claimedGuidancePromptId;
              claimedGuidancePromptId = "";
              guidanceVisible = false;
              featureHost.destroyFeature("guidance");
              if (previousId) void releaseGuidanceClaim(previousId);
              return false;
            }
            const claim = await send({ type: ACTIVE_GUIDANCE_CLAIM_MESSAGE, promptId });
            if (destroyed || revision !== guidanceRevision || desiredGuidancePromptId !== promptId) {
              if (desiredGuidancePromptId !== promptId && claim?.claimed) {
                void releaseGuidanceClaim(promptId);
              }
              return false;
            }
            if (!claim?.claimed || claim?.prompt?.id !== promptId) {
              if (claimedGuidancePromptId === promptId) claimedGuidancePromptId = "";
              guidanceVisible = false;
              featureHost.destroyFeature("guidance");
              return false;
            }
            releasedGuidancePromptIds.delete(promptId);
            claimedGuidancePromptId = promptId;
            const rendered = await featureHost.requestFeature("guidance", {
              type: "prompt",
              prompt: claim.prompt
            });
            if (destroyed || revision !== guidanceRevision || desiredGuidancePromptId !== promptId || rendered !== true) {
              if (!destroyed && revision !== guidanceRevision && desiredGuidancePromptId === promptId) {
                return false;
              }
              featureHost.destroyFeature("guidance");
              guidanceVisible = false;
              if (claimedGuidancePromptId === promptId) claimedGuidancePromptId = "";
              await releaseGuidanceClaim(promptId);
              return false;
            }
            const confirmed = await send({ type: ACTIVE_GUIDANCE_CONFIRM_MESSAGE, promptId });
            if (destroyed || desiredGuidancePromptId !== promptId || confirmed?.ok !== true || confirmed?.confirmed === false) {
              featureHost.destroyFeature("guidance");
              guidanceVisible = false;
              if (claimedGuidancePromptId === promptId) claimedGuidancePromptId = "";
              await releaseGuidanceClaim(promptId);
              return false;
            }
            guidanceVisible = true;
            return true;
          }
          function scheduleDock(intent) {
            const run = () => featureHost.requestFeature("web_dock", intent);
            if (typeof windowRef.requestIdleCallback === "function") windowRef.requestIdleCallback(run, { timeout: 1200 });
            else windowRef.setTimeout(run, 120);
          }
          function applyDockConfig(config, intent) {
            const input = config && typeof config === "object" ? config : {};
            const legacyDisabled = input.enabled === false && input.enabledUserSet !== true;
            dockConfig = {
              ...input,
              enabled: legacyDisabled ? true : input.enabled !== false,
              enabledUserSet: input.enabledUserSet === true,
              autoHide: input.autoHide === true
            };
            if (dockConfig?.enabled === false) {
              featureHost.destroyFeature("web_dock");
              return false;
            }
            if (dockConfig?.enabled === true) scheduleDock(intent || { type: "dock-enabled", config: dockConfig });
            return dockConfig?.enabled === true;
          }
          const session = shortcutLogic.createShortcutSession();
          let triggerConfig = shortcutLogic.normalizeTriggerConfig({ type: "single", key: "Alt" });
          let singleEnabled = true, comboEnabled = true, middleEnabled = true, middleStart = null, holdThreshold = 2e3, shortcutPressedAt = null;
          const now = options.now || Date.now;
          async function loadSettings() {
            try {
              const values = await chromeApi.storage.sync.get(["tfa_settings", "tfa_single_enabled", "tfa_combo_enabled", "tfa_middle_trigger", "tfa_hold_threshold", "tfa_web_dock"]);
              if (values.tfa_settings?.key) triggerConfig = shortcutLogic.normalizeTriggerConfig(values.tfa_settings);
              singleEnabled = values.tfa_single_enabled !== false;
              comboEnabled = values.tfa_combo_enabled !== false;
              const threshold = Number(values.tfa_hold_threshold);
              if (threshold >= 500 && threshold <= 5e3) holdThreshold = threshold;
              middleEnabled = values.tfa_middle_trigger !== false;
              const storedDock = values.tfa_web_dock || DEFAULT_DOCK_BOOTSTRAP_CONFIG;
              const migratedLegacyDisabled = storedDock.enabled === false && storedDock.enabledUserSet !== true;
              applyDockConfig(storedDock);
              if (migratedLegacyDisabled) {
                await chromeApi.storage.sync.set({ tfa_web_dock: { ...storedDock, enabled: true, enabledUserSet: false, autoHide: storedDock.autoHide === true } });
              }
            } catch (_error) {
            }
          }
          async function loadGuidance() {
            try {
              const values = await chromeApi.storage.local.get(GUIDANCE_PROMPT_KEY);
              await syncGuidance(values?.[GUIDANCE_PROMPT_KEY]);
            } catch (_error) {
            }
          }
          function onStorageChanged(changes, area) {
            if (area === "local" && changes?.[GUIDANCE_PROMPT_KEY]) void syncGuidance(changes[GUIDANCE_PROMPT_KEY].newValue);
          }
          function suppress(event) {
            event.preventDefault?.();
            event.stopPropagation?.();
            event.stopImmediatePropagation?.();
          }
          let guidanceShortcutActive = false;
          function guidanceConsumesShortcut(event) {
            if (triggerConfig.type !== "single" || triggerConfig.key !== "Alt" || event?.key !== "Alt") return false;
            const CustomEventConstructor = windowRef.CustomEvent || globalThis.CustomEvent;
            if (typeof windowRef.dispatchEvent !== "function" || typeof CustomEventConstructor !== "function") return false;
            const detail = { handled: false };
            const guidanceEvent = new CustomEventConstructor(ACTIVE_GUIDANCE_SHORTCUT_EVENT, {
              cancelable: true,
              detail
            });
            const dispatched = windowRef.dispatchEvent(guidanceEvent);
            return detail.handled === true || dispatched === false || guidanceEvent.defaultPrevented === true;
          }
          function handleKey(type, event) {
            const result = type === "keydown" ? session.keyDown(triggerConfig, event, { singleEnabled, comboEnabled }) : session.keyUp(event);
            if (result.cancel) return false;
            if (result.trigger) {
              suppress(event);
              shortcutPressedAt = now();
              if (guidanceConsumesShortcut(event)) {
                guidanceShortcutActive = true;
                return true;
              }
              if (cancelPendingGuidanceForWorkspaceOpen()) guidanceShortcutActive = true;
              requestWorkspaceFromShortcut({
                type: "shortcut-press",
                key: event.key,
                repeat: event.repeat === true,
                pressedAt: shortcutPressedAt,
                holdThreshold
              });
              return true;
            }
            if (result.triggerReleased) {
              suppress(event);
              if (guidanceShortcutActive) {
                guidanceShortcutActive = false;
                shortcutPressedAt = null;
                return true;
              }
              requestWorkspace({ type: "shortcut-release", key: event.key, releasedAt: now(), pressedAt: shortcutPressedAt, holdThreshold });
              shortcutPressedAt = null;
            }
            return false;
          }
          function onMessageEvent(event) {
            const data = event.data;
            if (!data?.__tfa_fwd) return;
            if (data.type === "keydown" || data.type === "keyup") handleKey(data.type, data);
            else if (data.type === "mouseup" && data.button === 1 && middleEnabled) requestWorkspace({ type: "middle-click" });
          }
          function onMouseDown(event) {
            if (event.button === 1 && middleEnabled) middleStart = { x: event.clientX, y: event.clientY };
          }
          function onMouseUp(event) {
            if (event.button !== 1 || !middleStart) return;
            const dx = event.clientX - middleStart.x, dy = event.clientY - middleStart.y;
            middleStart = null;
            if (dx * dx + dy * dy <= 36) {
              event.preventDefault?.();
              requestWorkspace({ type: "middle-click" });
            }
          }
          function onVisibilityChange() {
            const hidden = documentRef.hidden === true || documentRef.visibilityState === "hidden";
            if (hidden && featureHost.hasFeature("workspace")) void requestWorkspace({ type: "tab-hidden", source: "visibility-change" });
          }
          function restoreCaptureSurfacesIfIdle() {
            if (captureSurfaceLeases.size) return false;
            captureSurfaceObserver?.disconnect?.();
            captureSurfaceObserver = null;
            captureSurfaceStates.splice(0).forEach(([surface, value, priority]) => {
              if (!surface?.style) return;
              if (value) surface.style.setProperty("visibility", value, priority);
              else surface.style.removeProperty?.("visibility");
            });
            captureSurfaceNodes.clear();
            return true;
          }
          function releaseCaptureSurfaceLease(leaseId) {
            let token = typeof leaseId === "string" && leaseId ? leaseId : "";
            if (!token) {
              token = [...captureSurfaceLeases.keys()].find((candidate) => candidate.startsWith("anonymous:")) || "";
            }
            if (token && captureSurfaceLeases.has(token)) {
              windowRef.clearTimeout?.(captureSurfaceLeases.get(token));
              captureSurfaceLeases.delete(token);
            }
            restoreCaptureSurfacesIfIdle();
            return true;
          }
          function suppressCurrentCaptureSurfaces() {
            if (!captureSurfaceLeases.size) return false;
            const surfaces = documentRef.querySelectorAll?.('[data-tfa-host="true"],#tfa-active-guidance-host') || [];
            for (const surface of surfaces) {
              if (!surface?.style || captureSurfaceNodes.has(surface)) continue;
              captureSurfaceNodes.add(surface);
              captureSurfaceStates.push([
                surface,
                surface.style.getPropertyValue?.("visibility") || "",
                surface.style.getPropertyPriority?.("visibility") || ""
              ]);
              surface.style.setProperty?.("visibility", "hidden", "important");
            }
            return captureSurfaceStates.length > 0;
          }
          function observeCaptureSurfaces() {
            if (captureSurfaceObserver || !captureSurfaceLeases.size) return;
            const MutationObserverConstructor = options.MutationObserver || windowRef?.MutationObserver;
            if (typeof MutationObserverConstructor !== "function" || !documentRef.documentElement) return;
            captureSurfaceObserver = new MutationObserverConstructor(() => suppressCurrentCaptureSurfaces());
            try {
              captureSurfaceObserver.observe(documentRef.documentElement, { childList: true, subtree: true });
            } catch (_error) {
              captureSurfaceObserver.disconnect?.();
              captureSurfaceObserver = null;
            }
          }
          function acquireCaptureSurfaceLease(leaseId) {
            const token = typeof leaseId === "string" && leaseId ? leaseId : `anonymous:${++anonymousCaptureLeaseSequence}`;
            if (captureSurfaceLeases.has(token)) windowRef.clearTimeout?.(captureSurfaceLeases.get(token));
            const timerId = windowRef.setTimeout?.(() => {
              captureSurfaceLeases.delete(token);
              restoreCaptureSurfacesIfIdle();
            }, captureSurfaceLeaseMs) || 0;
            timerId?.unref?.();
            captureSurfaceLeases.set(token, timerId);
            observeCaptureSurfaces();
            return suppressCurrentCaptureSurfaces();
          }
          function setCaptureSurfacesHidden(hidden, leaseId) {
            return hidden ? acquireCaptureSurfaceLease(leaseId) : releaseCaptureSurfaceLease(leaseId);
          }
          function restoreAllCaptureSurfaces() {
            captureSurfaceLeases.forEach((timerId) => windowRef.clearTimeout?.(timerId));
            captureSurfaceLeases.clear();
            restoreCaptureSurfacesIfIdle();
          }
          function afterCapturePaint(callback) {
            let finished = false;
            const finish = () => {
              if (finished) return;
              finished = true;
              callback();
            };
            const frame = typeof windowRef.requestAnimationFrame === "function" ? windowRef.requestAnimationFrame.bind(windowRef) : (fn) => windowRef.setTimeout(fn, 0);
            frame(() => frame(finish));
            windowRef.setTimeout?.(finish, 80);
          }
          function dispatchSearchPermissionsChanged(message) {
            const CustomEventConstructor = windowRef.CustomEvent || globalThis.CustomEvent;
            if (typeof windowRef.dispatchEvent !== "function" || typeof CustomEventConstructor !== "function") return false;
            windowRef.dispatchEvent(new CustomEventConstructor(SEARCH_PERMISSIONS_CHANGED_EVENT, { detail: message }));
            return true;
          }
          function onRuntimeMessage(message, _sender, sendResponse) {
            if (!message || destroyed) return false;
            if (message.type === "PING") {
              sendResponse({ ok: true, version, fingerprint, generation, instanceId, bootstrap: true });
              return false;
            }
            if (message.type === "TFA_QUERY_OVERLAY_VISIBILITY") {
              sendResponse({ ok: true, visible: owner.workspaceVisible === true });
              return false;
            }
            if (message.type === "TFA_SET_CAPTURE_SURFACES_HIDDEN") {
              const surfacesHidden = setCaptureSurfacesHidden(message.hidden === true, message.leaseId);
              if (message.hidden === true) afterCapturePaint(() => sendResponse({ ok: true, hidden: surfacesHidden }));
              else sendResponse({ ok: true, hidden: false });
              return message.hidden === true;
            }
            if (message.type === "TOGGLE_OVERLAY") {
              void requestWorkspace({ type: "toggle-command" });
              sendResponse({ ok: true, loading: !featureHost.hasFeature("workspace") });
              return false;
            }
            if (DOCK_BROADCASTS.has(message.type)) {
              latestBroadcasts.set(message.type, message);
              if (message.type === "WEB_DOCK_CONFIG_CHANGED") applyDockConfig(message.config, message);
              else if (message.type === "WEB_DOCK_SEARCH_PERMISSIONS_CHANGED") {
                dispatchSearchPermissionsChanged(message);
              } else if (featureHost.hasFeature("web_dock")) void featureHost.requestFeature("web_dock", message);
              else featureHost.cacheIntent("web_dock", message);
              sendResponse({ ok: true, cached: !featureHost.hasFeature("web_dock") });
              return false;
            }
            if (message.type === "RELOAD") {
              if (message.expectedInstanceId && message.expectedInstanceId !== instanceId) {
                sendResponse({ ok: false, stale: true, instanceId });
                return false;
              }
              destroy();
              sendResponse({ ok: true, terminated: true, version, fingerprint, generation, instanceId });
              return false;
            }
            return false;
          }
          function destroy() {
            if (destroyed) return false;
            restoreAllCaptureSurfaces();
            for (const restoreDock of [...workspaceDockSuppressions]) restoreDock();
            guidanceRevision += 1;
            desiredGuidancePromptId = "";
            const guidancePromptId = claimedGuidancePromptId;
            claimedGuidancePromptId = "";
            if (guidancePromptId) {
              if (guidanceVisible) {
                void send({ type: ACTIVE_GUIDANCE_DISMISS_MESSAGE, promptId: guidancePromptId });
              } else {
                void releaseGuidanceClaim(guidancePromptId);
              }
            }
            guidanceVisible = false;
            destroyed = true;
            featureHost.destroy();
            listeners.splice(0).forEach(([target, type, handler, capture]) => target.removeEventListener(type, handler, capture));
            chromeApi.runtime.onMessage.removeListener(onRuntimeMessage);
            chromeApi.storage.onChanged?.removeListener?.(onStorageChanged);
            if (windowRef[OWNER_KEY] === owner) Object.assign(windowRef, { [OWNER_KEY]: null, [FEATURE_HOST_KEY]: null, __TFA_INJECTED__: false, __TFA_INSTANCE__: null });
            owner.state = "disposed";
            return true;
          }
          const bootstrap = Object.freeze({
            destroy,
            requestFeature: featureHost.requestFeature,
            hasFeature: featureHost.hasFeature,
            latestBroadcasts: () => new Map(latestBroadcasts)
          });
          owner.bootstrap = bootstrap;
          owner.dispose = destroy;
          listen(windowRef, "keydown", (event) => handleKey("keydown", event), true);
          listen(windowRef, "keyup", (event) => handleKey("keyup", event), true);
          listen(windowRef, "mousedown", onMouseDown, true);
          listen(windowRef, "mouseup", onMouseUp, true);
          listen(windowRef, "message", onMessageEvent);
          listen(documentRef, "visibilitychange", onVisibilityChange);
          chromeApi.runtime.onMessage.addListener(onRuntimeMessage);
          chromeApi.storage.onChanged?.addListener?.(onStorageChanged);
          void loadSettings();
          void loadGuidance();
          return bootstrap;
        }
        return Object.freeze({
          OWNER_KEY,
          FEATURE_HOST_KEY,
          SEARCH_PERMISSIONS_CHANGED_EVENT,
          ACTIVE_GUIDANCE_SHORTCUT_EVENT,
          DEFAULT_DOCK_BOOTSTRAP_CONFIG,
          createContentBootstrapRuntime
        });
      });
    }
  });

  // src/content/content-bootstrap-entry.js
  var require_content_bootstrap_entry = __commonJS({
    "src/content/content-bootstrap-entry.js"() {
      var import_version = __toESM(require_version());
      var import_shortcut_logic = __toESM(require_shortcut_logic());
      var import_content_feature_host = __toESM(require_content_feature_host());
      var import_content_bootstrap_runtime = __toESM(require_content_bootstrap_runtime());
      if (window === window.top) {
        globalThis.TfaContentBootstrapRuntime.createContentBootstrapRuntime({
          window,
          document,
          chrome,
          identity: globalThis.TfaBuildIdentity,
          featureHost: globalThis.TfaContentFeatureHost,
          shortcutLogic: globalThis.TfaShortcutLogic
        });
      }
    }
  });
  require_content_bootstrap_entry();
})();
