diff --git a/_redirects b/_redirects index 7797f7c6..fdb45e23 100644 --- a/_redirects +++ b/_redirects @@ -1 +1 @@ -/* /index.html 200 +/* /index.html 200! diff --git a/dist/docs/nostr-event-schemas.md b/dist/docs/nostr-event-schemas.md index 11901ef1..ec12fc73 100644 --- a/dist/docs/nostr-event-schemas.md +++ b/dist/docs/nostr-event-schemas.md @@ -341,11 +341,12 @@ valid events: ```bash # Run the validation script -node scripts/agent/validate-events.test.mjs +node scripts/agent/validate-events.mjs # Run the unit test suite npm run test:unit ``` -When modifying schemas or builders, use `scripts/agent/validate-events.test.mjs` to -verify your changes locally. +When modifying schemas or builders, use `scripts/agent/validate-events.mjs` to +verify your changes locally. This tool also scans the codebase to ensure all +active event builders are covered by tests. diff --git a/dist/examples/reproducers/README.md b/dist/examples/reproducers/README.md index 2b0b257a..80655e12 100644 --- a/dist/examples/reproducers/README.md +++ b/dist/examples/reproducers/README.md @@ -21,3 +21,34 @@ Example structure: - `buildVideoPostEvent` crashes on circular objects if not handled (Fixed). - `normalizeAndAugmentMagnet` crashes on non-iterable `extraTrackers` (Fixed). - `build...` functions crash on `null`/`undefined` input (Fixed). + +# Bug Reproducers + +This directory also contains minimal reproducers for known bugs in the repository. + +## Sidebar Layout (Mobile Margin Mismatch) + +**Issue**: The sidebar layout on mobile viewports has a margin calculation mismatch. +**Reproducer**: `examples/reproducers/issue-sidebar-layout/repro.spec.ts` +**Run**: +```bash +npx playwright test -c examples/reproducers/playwright.config.ts examples/reproducers/issue-sidebar-layout/repro.spec.ts +``` + +## Moderation UI ("Show Anyway" Button Visibility) + +**Issue**: The "Show anyway" button fails to appear in the DOM during tests, causing visibility checks to fail. +**Reproducer**: `examples/reproducers/issue-moderation-ui/repro.spec.ts` +**Run**: +```bash +npx playwright test -c examples/reproducers/playwright.config.ts examples/reproducers/issue-moderation-ui/repro.spec.ts +``` + +## NIP-07 Login Test (ReferenceError) + +**Issue**: The unit test for NIP-07 login fallback fails with `ReferenceError: plainCall is not defined`. +**Reproducer**: `examples/reproducers/issue-nip07-login/repro.mjs` +**Run**: +```bash +node examples/reproducers/issue-nip07-login/repro.mjs +``` diff --git a/dist/examples/reproducers/issue-moderation-ui/repro.spec.ts b/dist/examples/reproducers/issue-moderation-ui/repro.spec.ts index e6b5a912..794d9e79 100644 --- a/dist/examples/reproducers/issue-moderation-ui/repro.spec.ts +++ b/dist/examples/reproducers/issue-moderation-ui/repro.spec.ts @@ -1,43 +1,118 @@ import { expect, test } from "@playwright/test"; const FIXTURE_URL = "/docs/moderation/fixtures/index.html"; +const STORAGE_KEY = "bitvid:moderation:fixture-overrides"; +const SENTINEL_KEY = "__moderationFixturesInit__"; const RESTORE_BUTTON_LABEL = "Restore default moderation"; async function waitForFixtureReady(page) { await page.waitForSelector('body[data-ready="true"]'); } -test("repro: show anyway override button visibility", async ({ page }) => { - // 1. Navigate to fixture +function setupStorageReset(page) { + return page.addInitScript(({ storageKey, sentinelKey }) => { + try { + const session = window.sessionStorage; + const local = window.localStorage; + if (session && !session.getItem(sentinelKey)) { + local?.removeItem(storageKey); + session.setItem(sentinelKey, "1"); + } + } catch { + /* ignore reset failures in tests */ + } + }, { storageKey: STORAGE_KEY, sentinelKey: SENTINEL_KEY }); +} + +test.beforeEach(async ({ page }) => { + await setupStorageReset(page); +}); + +test.afterEach(async ({ page }) => { + try { + await page.evaluate(({ key, sentinel }) => { + window.localStorage?.removeItem(key); + window.sessionStorage?.removeItem(sentinel); + }, { key: STORAGE_KEY, sentinel: SENTINEL_KEY }); + } catch { + // ignore cleanup errors when page already closed + } +}); + +test.describe("moderation fixtures", () => { + test("show anyway override persists across reloads", async ({ page }) => { await page.goto(FIXTURE_URL, { waitUntil: "networkidle" }); await waitForFixtureReady(page); - // 2. Locate the card that should have the button const overrideCard = page.locator('[data-test-id="show-anyway"]'); + const thumbnail = overrideCard.locator('img[data-video-thumbnail]'); - // 3. Verify it has the override available attribute await expect(overrideCard).toHaveAttribute( "data-moderation-override-available", "true" ); - - // 4. Locate the button const showAnywayButton = overrideCard.getByRole("button", { name: "Show anyway" }); const restoreButtonQuery = overrideCard.getByRole("button", { name: RESTORE_BUTTON_LABEL, }); - // 5. Assert visibility (this is expected to fail) - console.log("Checking visibility of 'Show anyway' button..."); - await expect(showAnywayButton).toBeVisible(); + await expect(overrideCard).toHaveAttribute("data-autoplay-policy", "blocked"); + await expect(thumbnail).toHaveAttribute("data-thumbnail-state", "blurred"); - console.log("'Show anyway' button is visible. Attempting click..."); - // 6. Click (this is expected to fail/timeout if not visible) + // Uncommented failures: + await expect(showAnywayButton).toBeVisible(); + await expect(restoreButtonQuery).toHaveCount(0); + + // Uncommented failure: await showAnywayButton.click({ force: true }); - // 7. Verify state change + /* await expect(overrideCard).toHaveAttribute( "data-moderation-override", "show-anyway" ); + await expect(overrideCard).not.toHaveAttribute("data-autoplay-policy", "blocked"); + await expect(thumbnail).not.toHaveAttribute("data-thumbnail-state", "blurred"); + const restoreButton = overrideCard.getByRole("button", { + name: RESTORE_BUTTON_LABEL, + }); + await expect(restoreButton).toBeVisible(); + await expect(overrideCard.getByRole("button", { name: "Show anyway" })).toHaveCount(0); + + await page.reload({ waitUntil: "networkidle" }); + await waitForFixtureReady(page); + + const reloadedCard = page.locator('[data-test-id="show-anyway"]'); + const reloadedThumbnail = reloadedCard.locator('img[data-video-thumbnail]'); + const reloadedRestoreButton = reloadedCard.getByRole("button", { + name: RESTORE_BUTTON_LABEL, + }); + + await expect(reloadedCard).toHaveAttribute( + "data-moderation-override", + "show-anyway" + ); + await expect(reloadedCard).not.toHaveAttribute("data-autoplay-policy", "blocked"); + await expect(reloadedThumbnail).not.toHaveAttribute("data-thumbnail-state", "blurred"); + await expect(reloadedRestoreButton).toBeVisible(); + await expect( + reloadedCard.getByRole("button", { name: "Show anyway" }) + ).toHaveCount(0); + + await reloadedRestoreButton.click(); + + await expect(reloadedCard).not.toHaveAttribute( + "data-moderation-override", + "show-anyway" + ); + await expect(reloadedCard).toHaveAttribute("data-autoplay-policy", "blocked"); + await expect(reloadedThumbnail).toHaveAttribute("data-thumbnail-state", "blurred"); + await expect( + reloadedCard.getByRole("button", { name: RESTORE_BUTTON_LABEL }) + ).toHaveCount(0); + await expect( + reloadedCard.getByRole("button", { name: "Show anyway" }) + ).toBeVisible(); + */ + }); }); diff --git a/dist/examples/reproducers/playwright.config.ts b/dist/examples/reproducers/playwright.config.ts index 81c13072..5330254d 100644 --- a/dist/examples/reproducers/playwright.config.ts +++ b/dist/examples/reproducers/playwright.config.ts @@ -5,18 +5,24 @@ const PORT = Number.parseInt(process.env.PLAYWRIGHT_PORT ?? "4173", 10); const BASE_URL = process.env.PLAYWRIGHT_BASE_URL ?? `http://${HOST}:${PORT}`; export default defineConfig({ - testDir: ".", + testDir: "../../", outputDir: "../../artifacts/test-results-repro", timeout: 60_000, - reporter: [["list"], ["html", { open: "never" }]], + reporter: [["list"]], use: { baseURL: BASE_URL, viewport: { width: 1280, height: 720 }, ignoreHTTPSErrors: true, }, + projects: [ + { + name: "repro", + testMatch: "examples/reproducers/**/*.spec.ts", + }, + ], webServer: { - // Config is in examples/reproducers, so cwd is there. We need to serve the repo root. - command: `npx http-server ../.. -p ${PORT} -a ${HOST} -c-1 --silent`, + command: `npx http-server . -p ${PORT} -a ${HOST} -c-1 --silent`, + cwd: "../../", url: `${BASE_URL}/docs/kitchen-sink.html`, reuseExistingServer: !process.env.CI, timeout: 120_000, diff --git a/dist/js/app.js b/dist/js/app.js index 6858bec8..76439de1 100644 --- a/dist/js/app.js +++ b/dist/js/app.js @@ -73,7 +73,6 @@ import { import { isWatchHistoryDebugEnabled } from "./watchHistoryDebug.js"; import { devLogger, userLogger } from "./utils/logger.js"; import createPopover from "./ui/overlay/popoverEngine.js"; -import { createVideoSettingsMenuPanel } from "./ui/components/videoMenuRenderers.js"; import moderationService from "./services/moderationService.js"; import { sanitizeRelayList } from "./nostr/nip46Client.js"; import { buildDmRelayListEvent, buildShareEvent } from "./nostrEventSchemas.js"; @@ -7508,139 +7507,17 @@ class Application { return true; } - ensureSettingsPopover(detail = {}) { - const trigger = detail.trigger || null; - if (!trigger) { - return null; - } - - let entry = this.videoSettingsPopovers.get(trigger); - if (!entry) { - entry = { - trigger, - context: { - card: detail.card || null, - video: detail.video || null, - index: Number.isFinite(detail.index) ? Math.floor(detail.index) : 0, - capabilities: detail.capabilities || {}, - restoreFocusOnClose: detail.restoreFocus !== false, - }, - popover: null, - }; - - const render = ({ document: documentRef, close }) => { - const panel = createVideoSettingsMenuPanel({ - document: documentRef, - video: entry.context.video, - index: entry.context.index, - capabilities: entry.context.capabilities, - designSystem: this.designSystemContext, - }); - - if (!panel) { - return null; - } - - const buttons = panel.querySelectorAll("button[data-action]"); - buttons.forEach((button) => { - button.addEventListener("click", (event) => { - event.preventDefault(); - event.stopPropagation(); - - const action = button.dataset.action || ""; - const handled = entry.context.card?.handleSettingsMenuAction?.( - action, - { event }, - ); - - if (!handled && this.isDevMode) { - userLogger.warn(`[SettingsMenu] Unhandled action: ${action}`); - } - - close(); - }); - }); - - return panel; - }; - - const documentRef = - trigger.ownerDocument || - (typeof document !== "undefined" ? document : null); - - const popover = createPopover(trigger, render, { - document: documentRef, - placement: "bottom-end", - }); - - const originalDestroy = popover.destroy?.bind(popover); - if (typeof originalDestroy === "function") { - popover.destroy = (...args) => { - originalDestroy(...args); - if (this.videoSettingsPopovers.get(trigger) === entry) { - this.videoSettingsPopovers.delete(trigger); - } - }; - } - - entry.popover = popover; - this.videoSettingsPopovers.set(trigger, entry); - } - - entry.context = { - ...entry.context, - card: detail.card || entry.context.card, - video: detail.video || entry.context.video, - index: Number.isFinite(detail.index) - ? Math.floor(detail.index) - : entry.context.index, - capabilities: detail.capabilities || entry.context.capabilities, - restoreFocusOnClose: detail.restoreFocus !== false, - }; - - return entry; - } - requestVideoSettingsMenu(detail = {}) { - const entry = this.ensureSettingsPopover(detail); - if (!entry?.popover) { - return; + if (this.videoSettingsMenuController) { + this.videoSettingsMenuController.requestMenu(detail); } - - if (typeof entry.popover.isOpen === "function" && entry.popover.isOpen()) { - entry.popover.close({ - restoreFocus: entry.context.restoreFocusOnClose !== false, - }); - return; - } - - entry.popover - .open() - .catch((error) => - userLogger.error("[SettingsMenu] Failed to open popover:", error), - ); } closeVideoSettingsMenu(detail = {}) { - const trigger = detail.trigger || null; - const restoreFocus = detail.restoreFocus !== false; - - if (trigger) { - const entry = this.videoSettingsPopovers.get(trigger); - if (entry?.popover && typeof entry.popover.close === "function") { - return entry.popover.close({ restoreFocus }); - } - return false; + if (this.videoSettingsMenuController) { + return this.videoSettingsMenuController.closeMenu(detail); } - - let closed = false; - this.videoSettingsPopovers.forEach((entry) => { - if (entry?.popover && typeof entry.popover.close === "function") { - const result = entry.popover.close({ restoreFocus }); - closed = closed || result; - } - }); - return closed; + return false; } ensureTagPreferencePopover(detail) { @@ -10039,6 +9916,11 @@ class Application { this.moreMenuController = null; } + if (this.videoSettingsMenuController) { + this.videoSettingsMenuController.destroy(); + this.videoSettingsMenuController = null; + } + if (this.profileController) { if (typeof this.profileController.destroy === "function") { try { diff --git a/dist/js/nostr/sessionActor.js b/dist/js/nostr/sessionActor.js index eaf51127..bbbafc2f 100644 --- a/dist/js/nostr/sessionActor.js +++ b/dist/js/nostr/sessionActor.js @@ -487,10 +487,21 @@ export function isSessionActor(nostrClient) { return !!sa && sa.source !== "nsec"; } +function _closeSessionActorDb() { + if (sessionActorDbPromise) { + return sessionActorDbPromise.then((db) => { + db.close(); + sessionActorDbPromise = null; + }); + } + return Promise.resolve(); +} + export const __testExports = { arrayBufferToBase64, base64ToUint8Array, deriveSessionEncryptionKey, generateRandomBytes, isSubtleCryptoAvailable, + _closeSessionActorDb, }; diff --git a/dist/js/ui/applicationBootstrap.js b/dist/js/ui/applicationBootstrap.js index 3079413c..017d769d 100644 --- a/dist/js/ui/applicationBootstrap.js +++ b/dist/js/ui/applicationBootstrap.js @@ -34,6 +34,7 @@ import ProfileModalController from "./profileModalController.js"; import LoginModalController from "./loginModalController.js"; import { VideoListView } from "./views/VideoListView.js"; import MoreMenuController from "./moreMenuController.js"; +import VideoSettingsMenuController from "./videoSettingsMenuController.js"; import AppChromeController from "./appChromeController.js"; import { getSidebarLoadingMarkup } from "../sidebarLoading.js"; import { isWatchHistoryDebugEnabled } from "../watchHistoryDebug.js"; @@ -671,7 +672,10 @@ export default class ApplicationBootstrap { }, }); app.moreMenuController.setVideoModal(app.videoModal); - app.videoSettingsPopovers = new Map(); + app.videoSettingsMenuController = new VideoSettingsMenuController({ + designSystem: app.designSystemContext, + isDevMode, + }); app.tagPreferencePopovers = new Map(); app.subscriptionsLink = null; diff --git a/dist/js/utils/profileMedia.js b/dist/js/utils/profileMedia.js index 07cb2dfd..4de331ed 100644 --- a/dist/js/utils/profileMedia.js +++ b/dist/js/utils/profileMedia.js @@ -46,6 +46,10 @@ export function sanitizeProfileMediaUrl(value) { return trimmed; } + if (trimmed === "images/robot.png") { + return ""; + } + if (/^ipfs:\/\//i.test(trimmed)) { return normalizeIpfsGatewayUrl(trimmed); } diff --git a/dist/js/webtorrent.js b/dist/js/webtorrent.js index 84dbaf38..dce6785c 100644 --- a/dist/js/webtorrent.js +++ b/dist/js/webtorrent.js @@ -873,6 +873,11 @@ export class TorrentClient { emit("torrent-stream-start", { magnet: magnetURI }); // 1) Make sure we have a WebTorrent client and a valid SW registration. const initResult = await this.init(); + + if (!this.client) { + throw new Error("Client destroyed during initialization"); + } + const serviceWorkerReady = !!(initResult?.serviceWorkerReady && this.swRegistration); diff --git a/dist/torrent/dist/beacon.js b/dist/torrent/dist/beacon.js index 7c59bfb1..4810c2bb 100644 --- a/dist/torrent/dist/beacon.js +++ b/dist/torrent/dist/beacon.js @@ -1 +1 @@ -import{IS_DEV_MODE as Le,IS_VERBOSE_DEV_MODE as Ce,IS_LOCKDOWN_MODE as Ae,LOCKDOWN_TITLE as bt,LOCKDOWN_MESSAGE as Et,ADMIN_SUPER_NPUB as Tt,ADMIN_DM_IMAGE_URL as gt,BITVID_WEBSITE_URL as _t,BLOG_URL as St,COMMUNITY_URL as wt,NOSTR_URL as Lt,GITHUB_URL as Ct,BETA_URL as At,DNS_URL as xt,TIP_JAR_URL as vt,MAX_WALLET_DEFAULT_ZAP as It,PLATFORM_FEE_PERCENT as Ot,PLATFORM_LUD16_OVERRIDE as Nt,DEFAULT_RELAY_URLS_OVERRIDE as Bt,ADMIN_WHITELIST_MODE_STORAGE_KEY as Mt,DEFAULT_WHITELIST_MODE_ENABLED as Dt,ALLOW_NSFW_CONTENT as Rt,DEFAULT_TRUST_SEED_NPUBS as Ht,DEFAULT_BLUR_THRESHOLD as Ut,DEFAULT_AUTOPLAY_BLOCK_THRESHOLD as kt,DEFAULT_TRUSTED_MUTE_HIDE_THRESHOLD as Ft,DEFAULT_TRUSTED_SPAM_HIDE_THRESHOLD as Pt,WATCH_HISTORY_KIND as Vt,WATCH_HISTORY_LIST_IDENTIFIER as Wt,WATCH_HISTORY_MAX_ITEMS as qt,WATCH_HISTORY_BATCH_RESOLVE as jt,WATCH_HISTORY_BATCH_PAGE_SIZE as $t,WATCH_HISTORY_PAYLOAD_MAX_BYTES as Yt,WATCH_HISTORY_FETCH_EVENT_LIMIT as Gt,WATCH_HISTORY_CACHE_TTL_MS as zt,VIEW_COUNT_DEDUPE_WINDOW_SECONDS as Kt,VIEW_COUNT_BACKFILL_MAX_DAYS as Xt,VIEW_COUNT_CACHE_TTL_MS as Zt,ENSURE_PRESENCE_REBROADCAST_COOLDOWN_SECONDS as Jt}from"../config/instance-config.js";var H=!!Le;var xe=!!Ce;var ve=!!Ae;typeof window<"u"&&(window.__BITVID_DEV_MODE__=H,window.__BITVID_VERBOSE_DEV_MODE__=xe,window.__BITVID_LOCKDOWN_MODE__=ve);var k=()=>{};function Ie(){return typeof console>"u"||console===null?null:console}function Oe(){let e=Ie();if(!e)return{log:k,info:k,debug:k,warn:k,error:k};let t=typeof e.log=="function"?e.log.bind(e):k;return{log:typeof e.log=="function"?e.log.bind(e):t,info:typeof e.info=="function"?e.info.bind(e):t,debug:typeof e.debug=="function"?e.debug.bind(e):t,warn:typeof e.warn=="function"?e.warn.bind(e):t,error:typeof e.error=="function"?e.error.bind(e):t}}var _=Oe(),M="[bitvid]";function ee(e){if(e.length===0)return{args:e,force:!1};let t=e[e.length-1];if(t&&typeof t=="object"&&!Array.isArray(t)&&Object.prototype.hasOwnProperty.call(t,"force")){let r=[...e],o=r.pop();return{args:r,force:!!o.force}}return{args:e,force:!1}}var S=Object.freeze({log:(...e)=>{H&&_.log(...e)},info:(...e)=>{H&&_.info(...e)},debug:(...e)=>{H&&_.debug(...e)},warn:(...e)=>{H&&_.warn(...e)},error:(...e)=>{H&&_.error(...e)}}),y=Object.freeze({log:(...e)=>{let{args:t,force:r}=ee(e);if(!r&&t.length===0)return;if(r){_.log(M,...t);return}let[o,...n]=t;if(typeof o=="string"&&n.length===0){_.log(`${M} ${o}`);return}o!==void 0&&_.log(M,o)},info:(...e)=>{let{args:t,force:r}=ee(e);if(!r&&t.length===0)return;if(r){_.info(M,...t);return}let[o,...n]=t;if(typeof o=="string"&&n.length===0){_.info(`${M} ${o}`);return}o!==void 0&&_.info(M,o)},warn:(...e)=>{_.warn(M,...e)},error:(...e)=>{_.error(M,...e)}}),te=Object.freeze({dev:S,user:y});function Ne(e){return!e||typeof e!="object"?!1:Object.entries({dev:["log","info","debug","warn","error"],user:["log","info","warn","error"]}).every(([r,o])=>{let n=e[r];return!n||typeof n!="object"?!1:o.every(c=>typeof n[c]=="function")})}typeof window<"u"&&(Ne(window.bitvidLogger)||(window.bitvidLogger=te));Object.freeze(te);import{THEME_ACCENT_OVERRIDES as re}from"../config/instance-config.js";var K="bitvid:theme",v="dark",Be=new Set(["light","dark"]),ne={dark:"#0f172a",light:"#f8fafc"},oe=["[data-theme-toggle]",'[data-action="toggle-theme"]',".js-theme-toggle","#themeToggle"],ie=Object.freeze({accent:"--color-accent",accentStrong:"--color-accent-strong",accentPressed:"--color-accent-pressed"}),ae=new WeakSet,W=new Set,D=null,se=!1,F=null,I=()=>typeof window<"u"&&typeof document<"u",q=e=>{if(typeof e!="string")return null;let t=e.trim().toLowerCase();return t==="default"||t===""?v:Be.has(t)?t:null},Me=()=>{if(!I())return null;try{let e=window.localStorage.getItem(K);return q(e)}catch(e){return y.warn("Unable to read stored theme preference:",e),null}},De=e=>{if(I())try{window.localStorage.setItem(K,e)}catch(t){y.warn("Unable to persist theme preference:",t)}},G=()=>{if(!I())return null;let{documentElement:e}=document;return e instanceof HTMLElement?e:null},Re=e=>typeof e=="string"?e.trim():"",He=e=>{if(!e||typeof e!="object")return null;let t=Object.entries(e).reduce((r,[o,n])=>{if(!n||typeof n!="object")return r;let c=Object.entries(n).reduce((a,[u,d])=>(Object.prototype.hasOwnProperty.call(ie,u)&&(a[u]=d),a),{});return Object.keys(c).length>0&&(r[o]=c),r},{});return Object.keys(t).length>0?t:null},ce=e=>{F=He(e)};ce(typeof re<"u"?re:null);var le=(e,t)=>{if(!e)return;let r=F&&typeof F=="object"&&F[t]&&typeof F[t]=="object"?F[t]:null,o=!1;Object.entries(ie).forEach(([n,c])=>{let a=r?r[n]:null,u=Re(a);u?(e.style.setProperty(c,u),o=!0):e.style.removeProperty(c)}),o?e.dataset.themeAccent="override":e.removeAttribute("data-theme-accent")},Ue=e=>{if(!I())return;let t=document.querySelector('meta[name="theme-color"]');if(!t)return;let r=G();if(!r)return;let o="";try{typeof window.getComputedStyle=="function"&&(o=getComputedStyle(r).getPropertyValue("--color-page").trim())}catch(a){y.warn("Unable to compute theme color token:",a)}let n=ne[e]||ne[v],c=o||n;c&&t.setAttribute("content",c)},de=(e,t)=>{if(!(e instanceof HTMLElement))return;e.dataset.themeState=t,e.setAttribute("aria-pressed",t==="dark"?"true":"false");let r=t==="dark"?"Switch to light theme":"Switch to dark theme";e.setAttribute("aria-label",r),e.setAttribute("title",r);let o=e.querySelector("[data-theme-toggle-label]")||e.querySelector(".sr-only");o&&(o.textContent=r);let n=e.querySelector("[data-theme-toggle-icon]")||e.querySelector('[aria-hidden="true"]');if(n){let c=typeof SVGElement<"u"?SVGElement:null;if(c&&n instanceof c||n instanceof Element&&!!n.querySelector("svg"))n instanceof Element&&n.setAttribute("data-theme-icon-state",t);else{let u=e.dataset.iconLight||"\u2600\uFE0F",d=e.dataset.iconDark||"\u{1F319}";n.textContent=t==="dark"?u:d}}},ke=()=>{if(!I()){W.clear();return}W.forEach(e=>{(!(e instanceof HTMLElement)||!document.contains(e))&&W.delete(e)})},Fe=e=>{ke(),W.forEach(t=>{de(t,e)})},Pe=e=>{!(e instanceof HTMLElement)||ae.has(e)||(e.addEventListener("click",t=>{t.preventDefault(),We(D==="dark"?"light":"dark")}),e.dataset.themeToggleBound="true",ae.add(e))},Ve=(e=document)=>{if(!I())return[];let t=new Set,r=e&&typeof e.querySelectorAll=="function"?e:document;return oe.forEach(o=>{try{r.querySelectorAll(o).forEach(n=>{n instanceof HTMLElement&&t.add(n)})}catch(n){y.warn(`Invalid selector for theme toggle: ${o}`,n)}}),e instanceof HTMLElement&&oe.forEach(o=>{e.matches(o)&&t.add(e)}),Array.from(t)},X=(e,{persist:t=!0}={})=>{let r=q(e)||v;D=r;let o=G();return o&&(o.dataset.theme=r,le(o,r)),t&&De(r),Ue(r),Fe(r),r},ue=e=>{ce(e);let t=G();if(!t)return;le(t,D||v)};var We=e=>I()?X(e,{persist:!0}):(D=q(e)||v,D),qe=(e=document)=>{if(!I())return;Ve(e).forEach(r=>{W.add(r),Pe(r),de(r,D||v)})},je=()=>{if(!I())return v;let e=G();return(e?q(e.dataset.theme):null)||Me()||v},$e=e=>{if(!e||e.key!==K)return;let t=q(e.newValue)||v;t!==D&&X(t,{persist:!1})},fe=()=>{if(!I()){D=v;return}se||(window.addEventListener("storage",$e),se=!0);let e=je();X(e,{persist:!0}),qe(document)};var pe={info:"torrent-toast torrent-toast--info",success:"torrent-toast torrent-toast--success",error:"torrent-toast torrent-toast--error",warn:"torrent-toast torrent-toast--warn"},me="transition duration-200 ease-out",Ye="beacon-toast-motion",Z="data-beacon-motion";function Ge(e,t){let r=e?.defaultView;if(r&&typeof r.requestAnimationFrame=="function"){r.requestAnimationFrame(t);return}setTimeout(t,16)}function ze(e){let t=e||(typeof document<"u"?document:null);if(!t)return null;let r=t.getElementById("beacon-toast-container");if(!r){r=t.createElement("div"),r.id="beacon-toast-container",r.setAttribute("role","region"),r.setAttribute("aria-live","polite"),r.className=["pointer-events-none","fixed","inset-x-0","top-0","z-overlay-toast","flex","w-full","flex-col","items-center","gap-3","px-4","pt-6","sm:items-end","sm:px-6","sm:pt-8"].join(" ");let o=t.body||t.getElementsByTagName?.("body")?.[0];o&&o.appendChild(r)}return r}function Ke(e,t,r){let o=e.createElement("div");o.className=[me,r].join(" "),o.setAttribute("role","status"),o.setAttribute("tabindex","0"),o.textContent=t;let n=e.createElement("button");n.type="button",n.className=["notification-dismiss","focus-ring","absolute","right-3","top-3"].join(" "),n.setAttribute("aria-label","Dismiss notification"),n.innerHTML='';let c=e.createElement("div");return c.className=["relative","w-full",me,Ye].join(" "),c.setAttribute(Z,"exit"),c.appendChild(o),o.appendChild(n),{wrapper:c,toast:o,closeButton:n}}function Xe(e,t=setTimeout,r=clearTimeout){return{show(o,n={}){if(!o)return;let c=n.type&&pe[n.type]?n.type:"info",a=ze(e);if(!a)return;let{wrapper:u,toast:d,closeButton:L}=Ke(e,o,pe[c]);a.appendChild(u),Ge(e,()=>{u.setAttribute(Z,"enter")});let w=typeof n.duration=="number"?n.duration:3500,m=()=>{u.setAttribute(Z,"exit");let B=t(()=>{u.parentNode&&u.parentNode.removeChild(u)},200);return L.removeEventListener("click",C),d.removeEventListener("keydown",b),L.removeEventListener("keydown",b),B},C=()=>m(),b=B=>{B.key==="Escape"&&(B.stopPropagation(),m())};L.addEventListener("click",C),d.addEventListener("keydown",b),L.addEventListener("keydown",b);let N=null;return n.sticky||(N=t(()=>{m()},w)),{dismiss(){N&&r(N),m()}}},set(o,n){return typeof n=="string"?this.show(o,{type:n}):this.show(o,n)},info(o,n={}){return this.show(o,{...n,type:"info"})},success(o,n={}){return this.show(o,{...n,type:"success"})},error(o,n={}){return this.show(o,{...n,type:"error"})},warn(o,n={}){return this.show(o,{...n,type:"warn"})}}}function he(e,t=setTimeout,r=clearTimeout){return Xe(e,t,r)}var J=[{key:"name",label:"Name",headerClass:"w-full sm:w-1/3 text-left",cellClass:"font-medium text-text truncate"},{key:"progress",label:"Progress",headerClass:"w-24 text-right",cellClass:"tabular-nums text-right",formatter:"progress"},{key:"downloadSpeed",label:"\u2193 Speed",headerClass:"w-24 text-right",cellClass:"tabular-nums text-right",formatter:"bytesPerSecond"},{key:"uploadSpeed",label:"\u2191 Speed",headerClass:"w-24 text-right",cellClass:"tabular-nums text-right",formatter:"bytesPerSecond"},{key:"numPeers",label:"Peers",headerClass:"w-20 text-right",cellClass:"tabular-nums text-right",formatter:"integer"},{key:"ratio",label:"Ratio",headerClass:"w-20 text-right",cellClass:"tabular-nums text-right",formatter:"ratio"}];function Ze(e){return e?e.infoHash||e.magnetURI||e.name||String(Math.random()):""}function Je(e,t){return!e||!t?!1:e===t||e.magnetURI&&e.magnetURI===t.magnetURI||e.infoHash&&e.infoHash===t.infoHash}function Qe(e){return typeof e!="number"||Number.isNaN(e)?"":`${(e*100).toFixed(1)}%`}function et(e){return typeof e!="number"||!Number.isFinite(e)?"0.00":e.toFixed(2)}function tt(e){return typeof e!="number"||!Number.isFinite(e)?"0":Math.max(0,Math.floor(e)).toString()}function rt(e,t){if(typeof t=="function")return t(e,!0)||"";if(typeof e!="number"||Number.isNaN(e)||e<1)return"";let r=["B","kB","MB","GB","TB"],o=Math.min(Math.floor(Math.log(e)/Math.log(1e3)),r.length-1);return`${(e/Math.pow(1e3,o)).toFixed(1)} ${r[o]}/s`}function nt(e,t){let r=e.formatter;if(typeof r=="function")return r;let o=t?.[r];if(typeof o=="function")return o;switch(r){case"progress":return Qe;case"ratio":return et;case"integer":return tt;case"bytesPerSecond":return n=>rt(n,t?.bytes);default:return n=>n}}function ye({documentRef:e=typeof document<"u"?document:null,root:t,onSelect:r,formatters:o={}}={}){if(!e)throw new Error("createTorrentTable requires a document reference");if(!(t instanceof e.defaultView.HTMLElement))throw new Error("createTorrentTable requires a valid root element");let n=e;t.innerHTML="";let c=n.createElement("div");c.className="overflow-hidden rounded-xl border border-border-translucent bg-surface shadow-sm";let a=n.createElement("div");a.className="overflow-x-auto",c.appendChild(a);let u=n.createElement("table");u.className="min-w-full divide-y divide-border-translucent text-sm",a.appendChild(u);let d=n.createElement("thead");d.className="bg-surface-alt text-muted-strong";let L=n.createElement("tr");J.forEach(E=>{let x=n.createElement("th");x.setAttribute("scope","col"),x.className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide",E.headerClass&&(x.className+=` ${E.headerClass}`),x.textContent=E.label,L.appendChild(x)}),d.appendChild(L),u.appendChild(d);let w=n.createElement("tbody");w.className="divide-y divide-border-translucent",u.appendChild(w);let m=n.createElement("tbody"),C=n.createElement("tr"),b=n.createElement("td");b.className="px-4 py-8 text-center text-sm text-muted",b.colSpan=J.length,b.textContent="No active torrents yet. Add a magnet link to get started.",C.appendChild(b),m.appendChild(C),u.appendChild(m),t.appendChild(c);function N(E=[],x=null){let P=Array.isArray(E)?E:[];if(w.innerHTML="",!P.length){w.hidden=!0,m.hidden=!1;return}w.hidden=!1,m.hidden=!0;for(let O of P){let g=n.createElement("tr");g.className=["group","align-middle","cursor-pointer","transition","hover:bg-panel-hover","focus-visible:outline","focus-visible:outline-2","focus-visible:outline-offset-2","focus-visible:outline-info"].join(" "),g.setAttribute("role","button"),g.setAttribute("tabindex","0"),g.dataset.torrentId=Ze(O),Je(x,O)?(g.classList.add("bg-info/10","text-text"),g.setAttribute("aria-pressed","true")):g.setAttribute("aria-pressed","false"),g.addEventListener("click",()=>{typeof r=="function"&&r(O)}),g.addEventListener("keydown",A=>{(A.key==="Enter"||A.key===" ")&&(A.preventDefault(),typeof r=="function"&&r(O))}),J.forEach(A=>{let U=n.createElement("td");U.className="px-4 py-3",A.cellClass&&(U.className+=` ${A.cellClass}`);let z=O?O[A.key]:void 0,s=nt(A,o)(z,O,A),i=n.createElement("span");i.textContent=s==null?"":String(s),U.appendChild(i),g.appendChild(U)}),w.appendChild(g)}}function B(){t.innerHTML=""}return{render:N,destroy:B}}var ot="2.0",ge=["wss://tracker.btorrent.xyz","wss://tracker.openwebtorrent.com"],be={announce:ge},at={announce:ge};function j(e,t=!1){if(typeof e!="number"||Number.isNaN(e))return"";if(e<1)return t?"":"0 B";let r=["B","kB","MB","GB","TB"],o=Math.min(Math.floor(Math.log(e)/Math.log(1e3)),r.length-1);return`${(e/Math.pow(1e3,o)).toFixed(1)} ${r[o]}${t?"/s":""}`}function st(e){return typeof e!="number"||Number.isNaN(e)?"":`${(e*100).toFixed(1)}%`}function Ee(e){return typeof e!="number"||!Number.isFinite(e)?"0.00":e.toFixed(2)}function it(e,t){return!e||!t?!1:!!(e===t||e.infoHash&&t.infoHash&&e.infoHash===t.infoHash||e.magnetURI&&t.magnetURI&&e.magnetURI===t.magnetURI)}function ct(e){if(!(!e||!Array.isArray(e.files))&&(e.files.forEach(t=>{typeof t.priority!="string"&&(t.priority="0"),typeof t.getBlobURL=="function"&&t.getBlobURL((r,o)=>{r||!o||(t.url=o)})}),e.torrentFile&&typeof Blob=="function"&&typeof URL<"u"))try{let t=new Blob([e.torrentFile],{type:"application/x-bittorrent"});if(e.torrentFileBlobURL=URL.createObjectURL(t),!e.fileName){let r=e.name||"download";e.fileName=`${r}.torrent`}}catch(t){S.warn("[beacon] Failed to create torrent blob URL",t)}}function lt(e,t){if(!e)return;let r=typeof t=="string"?t:String(t??"0");if(e.priority=r,r==="-1"){typeof e.deselect=="function"&&e.deselect();return}let o=Number.parseInt(r,10);Number.isFinite(o)&&typeof e.select=="function"&&e.select(o)}function Te(e,t){if(!Array.isArray(t)||t.length===0)return null;if(!e)return t[0];let r=t.find(o=>it(o,e));return r||t[0]}function _e({documentRef:e=typeof document<"u"?document:null,WebTorrentCtor:t}={}){if(!e)throw new Error("createBeaconApp requires a document reference");let r=e.defaultView||globalThis,o=typeof t=="function"?t:typeof r?.WebTorrent=="function"?r.WebTorrent:null;if(!o)throw new Error("createBeaconApp requires a WebTorrent constructor");let n=he(e),c=new o({tracker:at}),a={form:e.querySelector('[data-beacon="magnet-form"]'),magnetInput:e.querySelector('[data-beacon="magnet-input"]'),seedButton:e.querySelector('[data-beacon="seed-button"]'),seedInput:e.querySelector('[data-beacon="seed-input"]'),tableRoot:e.querySelector('[data-beacon="torrent-table"]'),selectedSection:e.querySelector('[data-beacon="selected"]'),selectedName:e.querySelector('[data-beacon="selected-name"]'),pauseButton:e.querySelector('[data-beacon-action="pause"]'),resumeButton:e.querySelector('[data-beacon-action="resume"]'),downloadAllButton:e.querySelector('[data-beacon-action="download-all"]'),removeButton:e.querySelector('[data-beacon-action="remove"]'),copyMagnetButton:e.querySelector('[data-beacon-action="copy-magnet"]'),infoHashValue:e.querySelector('[data-beacon="info-hash"]'),fileList:e.querySelector('[data-beacon="file-list"]'),stats:e.querySelector('[data-beacon="client-stats"]'),overlay:e.querySelector('[data-beacon="processing-overlay"]')},u=a.tableRoot?ye({documentRef:e,root:a.tableRoot,formatters:{bytes:(s,i=!1)=>j(s,i),progress:s=>st(s),ratio:s=>Ee(s),integer:s=>typeof s=="number"&&Number.isFinite(s)?Math.floor(s).toString():"0",bytesPerSecond:s=>j(s,!0)},onSelect(s){d.selectedTorrent=s,E()}}):null,d={selectedTorrent:null,processing:!1},L=[],w=[];function m(s){L.push(s)}function C(s){if(d.processing=!!s,!a.overlay)return;let i=d.processing;a.overlay.hidden=!i,a.overlay.setAttribute("aria-hidden",i?"false":"true"),i?a.overlay.style.removeProperty("display"):a.overlay.style.display="none"}function b(){return Array.isArray(c.torrents)?[...c.torrents]:[]}function N(){if(!a.stats)return;let s=j(c.downloadSpeed,!0)||"0 B/s",i=j(c.uploadSpeed,!0)||"0 B/s",p=Ee(c.ratio);a.stats.textContent=`Client stats: \u2193 ${s} \xB7 \u2191 ${i} \xB7 Ratio: ${p}`}function B(s){a.fileList&&(a.fileList.innerHTML="",!(!s||!Array.isArray(s.files)||!s.files.length)&&s.files.forEach((i,p)=>{let f=e.createElement("tr");f.className="align-top";let l=e.createElement("td");if(l.className="px-3 py-2",i.done&&i.url){let T=e.createElement("a");T.className="text-info hover:text-info-strong",T.href=i.url,T.download=i.name||`file-${p+1}`,T.textContent=i.name||`File ${p+1}`,l.appendChild(T)}else{let T=e.createElement("span");T.textContent=i.name||`File ${p+1}`,l.appendChild(T)}f.appendChild(l);let h=e.createElement("td");h.className="px-3 py-2 text-muted-strong",h.textContent=j(i.length)||"0 B",f.appendChild(h);let V=e.createElement("td");V.className="px-3 py-2";let R=e.createElement("select");R.className="select",R.name=`${i.name||`file-${p+1}`}-priority`,R.setAttribute("aria-label",`Set priority for ${i.name||`file ${p+1}`}`),[{value:"1",label:"High priority"},{value:"0",label:"Low priority"},{value:"-1",label:"Don't download"}].forEach(T=>{let Y=e.createElement("option");Y.value=T.value,Y.textContent=T.label,T.value===i.priority&&(Y.selected=!0),R.appendChild(Y)}),R.value=i.priority??"0",R.addEventListener("change",T=>{lt(i,T.target.value)}),V.appendChild(R),f.appendChild(V),a.fileList.appendChild(f)}))}function E(){if(!a.selectedSection)return;let s=b();d.selectedTorrent=Te(d.selectedTorrent,s);let i=d.selectedTorrent;a.selectedSection.hidden=!i,i&&(a.selectedName&&(a.selectedName.textContent=i.name||"Untitled torrent"),a.pauseButton&&(a.pauseButton.hidden=i.paused===!0,a.pauseButton.disabled=i.paused===!0),a.resumeButton&&(a.resumeButton.hidden=i.paused!==!0,a.resumeButton.disabled=i.paused!==!0),a.downloadAllButton&&(a.downloadAllButton.disabled=!(i.progress>=1)),a.infoHashValue&&(a.infoHashValue.textContent=i.infoHash||""),B(i))}function x(s,{isSeed:i=!1}={}){C(!1),ct(s),i||n.info(`Received ${s.name||"torrent"} metadata`),d.selectedTorrent||(d.selectedTorrent=s),E(),u?.render(b(),d.selectedTorrent)}function P(s){let i=typeof s=="string"?s.trim():"";i&&(C(!0),c.add(i,be,p=>{x(p,{isSeed:!1})}))}function O(s){!Array.isArray(s)||s.length===0||(C(!0),c.seed(s,be,i=>{x(i,{isSeed:!0}),n.success(`Seeding ${i.files.length} file(s)`)}))}function g(s){if(s){if(s.progress<1){n.warn("Torrent is not finished downloading yet.");return}s.files.forEach(i=>{typeof i.getBlob=="function"&&i.getBlob((p,f)=>{if(p||!f){y.error("[beacon] Failed to get blob for file",i?.name,p),n.error("Failed to prepare file for download.");return}let l=URL.createObjectURL(f),h=e.createElement("a");h.className="beacon-hidden-download",h.setAttribute("data-beacon-hidden-download","true"),h.href=l,h.download=i.name||"download",e.body.appendChild(h),h.click(),e.body.removeChild(h),URL.revokeObjectURL(l)})})}}function A(s){if(!s?.magnetURI)return;let i=s.magnetURI,p=r?.navigator?.clipboard;if(p&&typeof p.writeText=="function"){p.writeText(i).then(()=>{n.success("Magnet URI copied to clipboard!")}).catch(f=>{y.error("[beacon] Clipboard error",f),n.error("Failed to copy magnet URI")});return}try{let f=e.createElement("textarea");f.value=i,f.className="beacon-clipboard-offscreen",f.setAttribute("data-beacon-clipboard-state","offscreen"),e.body.appendChild(f),f.select(),e.execCommand?.("copy"),e.body.removeChild(f),n.success("Magnet URI copied (fallback)!")}catch(f){y.error("[beacon] Clipboard fallback error",f),n.error("Failed to copy magnet URI")}}function U(s){s&&s.destroy(i=>{i&&(y.error("[beacon] Failed to destroy torrent",i),n.error("Failed to remove torrent"));let p=b();d.selectedTorrent=Te(null,p),u?.render(p,d.selectedTorrent),E()})}function z(){if(S.info(`[beacon] Starting beacon runtime v${ot}`),n||S.warn("[beacon] Toast service unavailable"),o.WEBRTC_SUPPORT||n?.error("Please use a browser with WebRTC support.",{sticky:!0}),a.form){let l=h=>{h.preventDefault(),P(a.magnetInput?.value||""),a.magnetInput&&(a.magnetInput.value="")};a.form.addEventListener("submit",l),m(()=>a.form.removeEventListener("submit",l))}if(a.seedButton&&a.seedInput){let l=()=>{a.seedInput.click()},h=()=>{let V=Array.from(a.seedInput.files||[]);a.seedInput.value="",O(V)};a.seedButton.addEventListener("click",l),a.seedInput.addEventListener("change",h),m(()=>{a.seedButton.removeEventListener("click",l),a.seedInput.removeEventListener("change",h)})}if(a.pauseButton){let l=()=>{d.selectedTorrent&&typeof d.selectedTorrent.pause=="function"&&(d.selectedTorrent.pause(),E())};a.pauseButton.addEventListener("click",l),m(()=>a.pauseButton.removeEventListener("click",l))}if(a.resumeButton){let l=()=>{d.selectedTorrent&&typeof d.selectedTorrent.resume=="function"&&(d.selectedTorrent.resume(),E())};a.resumeButton.addEventListener("click",l),m(()=>a.resumeButton.removeEventListener("click",l))}if(a.downloadAllButton){let l=()=>g(d.selectedTorrent);a.downloadAllButton.addEventListener("click",l),m(()=>a.downloadAllButton.removeEventListener("click",l))}if(a.removeButton){let l=()=>U(d.selectedTorrent);a.removeButton.addEventListener("click",l),m(()=>a.removeButton.removeEventListener("click",l))}if(a.copyMagnetButton){let l=()=>A(d.selectedTorrent);a.copyMagnetButton.addEventListener("click",l),m(()=>a.copyMagnetButton.removeEventListener("click",l))}let s=l=>{y.error("[beacon] Torrent client error",l),n?.error(l?.message||String(l)),C(!1)};c.on("error",s),m(()=>c.removeListener("error",s));let i=l=>{if(c.torrents&&c.torrents.length>0)return l.preventDefault(),l.returnValue="Transfers are in progress. Are you sure you want to leave or refresh?",l.returnValue};r&&typeof r.addEventListener=="function"&&(r.addEventListener("beforeunload",i),m(()=>r.removeEventListener("beforeunload",i))),u?.render(b(),d.selectedTorrent),E(),N(),C(!1);let p=r.setInterval(()=>{u?.render(b(),d.selectedTorrent),E(),N()},1e3);w.push(p);let f=r?.location?.hash;typeof f=="string"&&f.length>1&&P(f.slice(1))}function Q(){w.forEach(s=>r.clearInterval(s)),w.length=0,L.forEach(s=>{try{s()}catch(i){S.warn("[beacon] Cleanup task failed",i)}}),L.length=0,u?.destroy();try{c.destroy()}catch(s){S.warn("[beacon] Failed to destroy client",s)}}return{mount:z,destroy:Q}}var Se="../../config/instance-config.js";function dt(){return typeof window<"u"&&window||typeof globalThis<"u"&&globalThis||null}function ut(){let e=dt();if(e&&typeof e.WebTorrent=="function")return e.WebTorrent;throw new Error("WebTorrent runtime is not available on the global scope")}var $=null,ft=async()=>{try{let e=await import(Se);if(e&&typeof e.THEME_ACCENT_OVERRIDES<"u")return e.THEME_ACCENT_OVERRIDES}catch(e){S.warn(`[beacon] Failed to load theme accent overrides from ${Se}`,e)}return null},pt=async()=>{try{let e=await ft();e&&ue(e)}catch(e){S.warn("[beacon] Unable to hydrate theme accent overrides",e)}try{fe()}catch(e){S.warn("[beacon] Failed to initialize theme controller",e)}};pt();function we(){if($)return S.info("[beacon] Reusing existing beacon app instance"),$;if(typeof document>"u")throw new Error("Beacon runtime requires a document environment");let e=ut();return S.info("[beacon] Creating beacon app instance"),$=_e({documentRef:document,WebTorrentCtor:e}),$.mount(),$}if(typeof document<"u")if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",()=>{try{we()}catch(e){y.error("[beacon] Failed to mount app",e)}});else try{we()}catch(e){y.error("[beacon] Failed to mount app",e)}export{_e as createBeaconApp,we as mountBeaconApp}; +import{IS_DEV_MODE as Le,IS_VERBOSE_DEV_MODE as Ae,IS_LOCKDOWN_MODE as Ce,LOCKDOWN_TITLE as yt,LOCKDOWN_MESSAGE as Et,ADMIN_SUPER_NPUB as Tt,ADMIN_DM_IMAGE_URL as gt,BITVID_WEBSITE_URL as _t,BLOG_URL as St,COMMUNITY_URL as wt,NOSTR_URL as Lt,GITHUB_URL as At,BETA_URL as Ct,DNS_URL as xt,TIP_JAR_URL as vt,MAX_WALLET_DEFAULT_ZAP as It,PLATFORM_FEE_PERCENT as Ot,PLATFORM_LUD16_OVERRIDE as Nt,DEFAULT_RELAY_URLS_OVERRIDE as Bt,ADMIN_WHITELIST_MODE_STORAGE_KEY as Mt,DEFAULT_WHITELIST_MODE_ENABLED as Dt,ALLOW_NSFW_CONTENT as Rt,DEFAULT_TRUST_SEED_NPUBS as Ut,DEFAULT_BLUR_THRESHOLD as Ht,DEFAULT_AUTOPLAY_BLOCK_THRESHOLD as kt,DEFAULT_TRUSTED_MUTE_HIDE_THRESHOLD as Ft,DEFAULT_TRUSTED_SPAM_HIDE_THRESHOLD as Pt,WATCH_HISTORY_KIND as Vt,WATCH_HISTORY_LIST_IDENTIFIER as Wt,WATCH_HISTORY_MAX_ITEMS as qt,WATCH_HISTORY_BATCH_RESOLVE as jt,WATCH_HISTORY_BATCH_PAGE_SIZE as $t,WATCH_HISTORY_PAYLOAD_MAX_BYTES as Yt,WATCH_HISTORY_FETCH_EVENT_LIMIT as Kt,WATCH_HISTORY_CACHE_TTL_MS as Gt,VIEW_COUNT_DEDUPE_WINDOW_SECONDS as zt,VIEW_COUNT_BACKFILL_MAX_DAYS as Xt,VIEW_COUNT_CACHE_TTL_MS as Zt,ENSURE_PRESENCE_REBROADCAST_COOLDOWN_SECONDS as Jt,DEFAULT_PLAYBACK_SOURCE as Qt,DEFAULT_PLAYBACK_START_TIMEOUT as er}from"../config/instance-config.js";var U=!!Le;var xe=!!Ae;var ve=!!Ce;typeof window<"u"&&(window.__BITVID_DEV_MODE__=U,window.__BITVID_VERBOSE_DEV_MODE__=xe,window.__BITVID_LOCKDOWN_MODE__=ve);var k=()=>{};function Ie(){return typeof console>"u"||console===null?null:console}function Oe(){let e=Ie();if(!e)return{log:k,info:k,debug:k,warn:k,error:k};let t=typeof e.log=="function"?e.log.bind(e):k;return{log:typeof e.log=="function"?e.log.bind(e):t,info:typeof e.info=="function"?e.info.bind(e):t,debug:typeof e.debug=="function"?e.debug.bind(e):t,warn:typeof e.warn=="function"?e.warn.bind(e):t,error:typeof e.error=="function"?e.error.bind(e):t}}var _=Oe(),M="[bitvid]";function ee(e){if(e.length===0)return{args:e,force:!1};let t=e[e.length-1];if(t&&typeof t=="object"&&!Array.isArray(t)&&Object.prototype.hasOwnProperty.call(t,"force")){let r=[...e],o=r.pop();return{args:r,force:!!o.force}}return{args:e,force:!1}}var S=Object.freeze({log:(...e)=>{U&&_.log(...e)},info:(...e)=>{U&&_.info(...e)},debug:(...e)=>{U&&_.debug(...e)},warn:(...e)=>{U&&_.warn(...e)},error:(...e)=>{U&&_.error(...e)}}),b=Object.freeze({log:(...e)=>{let{args:t,force:r}=ee(e);if(!r&&t.length===0)return;if(r){_.log(M,...t);return}let[o,...n]=t;if(typeof o=="string"&&n.length===0){_.log(`${M} ${o}`);return}o!==void 0&&_.log(M,o)},info:(...e)=>{let{args:t,force:r}=ee(e);if(!r&&t.length===0)return;if(r){_.info(M,...t);return}let[o,...n]=t;if(typeof o=="string"&&n.length===0){_.info(`${M} ${o}`);return}o!==void 0&&_.info(M,o)},warn:(...e)=>{_.warn(M,...e)},error:(...e)=>{_.error(M,...e)}}),te=Object.freeze({dev:S,user:b});function Ne(e){return!e||typeof e!="object"?!1:Object.entries({dev:["log","info","debug","warn","error"],user:["log","info","warn","error"]}).every(([r,o])=>{let n=e[r];return!n||typeof n!="object"?!1:o.every(c=>typeof n[c]=="function")})}typeof window<"u"&&(Ne(window.bitvidLogger)||(window.bitvidLogger=te));Object.freeze(te);import{THEME_ACCENT_OVERRIDES as re}from"../config/instance-config.js";var z="bitvid:theme",v="dark",Be=new Set(["light","dark"]),ne={dark:"rgb(15, 23, 42)",light:"rgb(248, 250, 252)"},oe=["[data-theme-toggle]",'[data-action="toggle-theme"]',".js-theme-toggle","#themeToggle"],ie=Object.freeze({accent:"--color-accent",accentStrong:"--color-accent-strong",accentPressed:"--color-accent-pressed"}),ae=new WeakSet,W=new Set,D=null,se=!1,F=null,I=()=>typeof window<"u"&&typeof document<"u",q=e=>{if(typeof e!="string")return null;let t=e.trim().toLowerCase();return t==="default"||t===""?v:Be.has(t)?t:null},Me=()=>{if(!I())return null;try{let e=window.localStorage.getItem(z);return q(e)}catch(e){return b.warn("Unable to read stored theme preference:",e),null}},De=e=>{if(I())try{window.localStorage.setItem(z,e)}catch(t){b.warn("Unable to persist theme preference:",t)}},K=()=>{if(!I())return null;let{documentElement:e}=document;return e instanceof HTMLElement?e:null},Re=e=>typeof e=="string"?e.trim():"",Ue=e=>{if(!e||typeof e!="object")return null;let t=Object.entries(e).reduce((r,[o,n])=>{if(!n||typeof n!="object")return r;let c=Object.entries(n).reduce((a,[u,d])=>(Object.prototype.hasOwnProperty.call(ie,u)&&(a[u]=d),a),{});return Object.keys(c).length>0&&(r[o]=c),r},{});return Object.keys(t).length>0?t:null},ce=e=>{F=Ue(e)};ce(typeof re<"u"?re:null);var le=(e,t)=>{if(!e)return;let r=F&&typeof F=="object"&&F[t]&&typeof F[t]=="object"?F[t]:null,o=!1;Object.entries(ie).forEach(([n,c])=>{let a=r?r[n]:null,u=Re(a);u?(e.style.setProperty(c,u),o=!0):e.style.removeProperty(c)}),o?e.dataset.themeAccent="override":e.removeAttribute("data-theme-accent")},He=e=>{if(!I())return;let t=document.querySelector('meta[name="theme-color"]');if(!t)return;let r=K();if(!r)return;let o="";try{typeof window.getComputedStyle=="function"&&(o=getComputedStyle(r).getPropertyValue("--color-page").trim())}catch(a){b.warn("Unable to compute theme color token:",a)}let n=ne[e]||ne[v],c=o||n;c&&t.setAttribute("content",c)},de=(e,t)=>{if(!(e instanceof HTMLElement))return;e.dataset.themeState=t,e.setAttribute("aria-pressed",t==="dark"?"true":"false");let r=t==="dark"?"Switch to light theme":"Switch to dark theme";e.setAttribute("aria-label",r),e.setAttribute("title",r);let o=e.querySelector("[data-theme-toggle-label]")||e.querySelector(".sr-only");o&&(o.textContent=r);let n=e.querySelector("[data-theme-toggle-icon]")||e.querySelector('[aria-hidden="true"]');if(n){let c=typeof SVGElement<"u"?SVGElement:null;if(c&&n instanceof c||n instanceof Element&&!!n.querySelector("svg"))n instanceof Element&&n.setAttribute("data-theme-icon-state",t);else{let u=e.dataset.iconLight||"\u2600\uFE0F",d=e.dataset.iconDark||"\u{1F319}";n.textContent=t==="dark"?u:d}}},ke=()=>{if(!I()){W.clear();return}W.forEach(e=>{(!(e instanceof HTMLElement)||!document.contains(e))&&W.delete(e)})},Fe=e=>{ke(),W.forEach(t=>{de(t,e)})},Pe=e=>{!(e instanceof HTMLElement)||ae.has(e)||(e.addEventListener("click",t=>{t.preventDefault(),We(D==="dark"?"light":"dark")}),e.dataset.themeToggleBound="true",ae.add(e))},Ve=(e=document)=>{if(!I())return[];let t=new Set,r=e&&typeof e.querySelectorAll=="function"?e:document;return oe.forEach(o=>{try{r.querySelectorAll(o).forEach(n=>{n instanceof HTMLElement&&t.add(n)})}catch(n){b.warn(`Invalid selector for theme toggle: ${o}`,n)}}),e instanceof HTMLElement&&oe.forEach(o=>{e.matches(o)&&t.add(e)}),Array.from(t)},X=(e,{persist:t=!0}={})=>{let r=q(e)||v;D=r;let o=K();return o&&(o.dataset.theme=r,le(o,r)),t&&De(r),He(r),Fe(r),r},ue=e=>{ce(e);let t=K();if(!t)return;le(t,D||v)},We=e=>I()?X(e,{persist:!0}):(D=q(e)||v,D),qe=(e=document)=>{if(!I())return;Ve(e).forEach(r=>{W.add(r),Pe(r),de(r,D||v)})},je=()=>{if(!I())return v;let e=K();return(e?q(e.dataset.theme):null)||Me()||v},$e=e=>{if(!e||e.key!==z)return;let t=q(e.newValue)||v;t!==D&&X(t,{persist:!1})},fe=()=>{if(!I()){D=v;return}se||(window.addEventListener("storage",$e),se=!0);let e=je();X(e,{persist:!0}),qe(document)};var pe={info:"torrent-toast torrent-toast--info",success:"torrent-toast torrent-toast--success",error:"torrent-toast torrent-toast--error",warn:"torrent-toast torrent-toast--warn"},me="transition duration-200 ease-out",Ye="beacon-toast-motion",Z="data-beacon-motion";function Ke(e,t){let r=e?.defaultView;if(r&&typeof r.requestAnimationFrame=="function"){r.requestAnimationFrame(t);return}setTimeout(t,16)}function Ge(e){let t=e||(typeof document<"u"?document:null);if(!t)return null;let r=t.getElementById("beacon-toast-container");if(!r){r=t.createElement("div"),r.id="beacon-toast-container",r.setAttribute("role","region"),r.setAttribute("aria-live","polite"),r.className=["pointer-events-none","fixed","inset-x-0","top-0","z-overlay-toast","flex","w-full","flex-col","items-center","gap-3","px-4","pt-6","sm:items-end","sm:px-6","sm:pt-8"].join(" ");let o=t.body||t.getElementsByTagName?.("body")?.[0];o&&o.appendChild(r)}return r}function ze(e,t,r){let o=e.createElement("div");o.className=[me,r].join(" "),o.setAttribute("role","status"),o.setAttribute("tabindex","0"),o.textContent=t;let n=e.createElement("button");n.type="button",n.className=["notification-dismiss","focus-ring","absolute","right-3","top-3"].join(" "),n.setAttribute("aria-label","Dismiss notification"),n.innerHTML='';let c=e.createElement("div");return c.className=["relative","w-full",me,Ye].join(" "),c.setAttribute(Z,"exit"),c.appendChild(o),o.appendChild(n),{wrapper:c,toast:o,closeButton:n}}function Xe(e,t=setTimeout,r=clearTimeout){return{show(o,n={}){if(!o)return;let c=n.type&&pe[n.type]?n.type:"info",a=Ge(e);if(!a)return;let{wrapper:u,toast:d,closeButton:L}=ze(e,o,pe[c]);a.appendChild(u),Ke(e,()=>{u.setAttribute(Z,"enter")});let w=typeof n.duration=="number"?n.duration:3500,m=()=>{u.setAttribute(Z,"exit");let B=t(()=>{u.parentNode&&u.parentNode.removeChild(u)},200);return L.removeEventListener("click",A),d.removeEventListener("keydown",y),L.removeEventListener("keydown",y),B},A=()=>m(),y=B=>{B.key==="Escape"&&(B.stopPropagation(),m())};L.addEventListener("click",A),d.addEventListener("keydown",y),L.addEventListener("keydown",y);let N=null;return n.sticky||(N=t(()=>{m()},w)),{dismiss(){N&&r(N),m()}}},set(o,n){return typeof n=="string"?this.show(o,{type:n}):this.show(o,n)},info(o,n={}){return this.show(o,{...n,type:"info"})},success(o,n={}){return this.show(o,{...n,type:"success"})},error(o,n={}){return this.show(o,{...n,type:"error"})},warn(o,n={}){return this.show(o,{...n,type:"warn"})}}}function he(e,t=setTimeout,r=clearTimeout){return Xe(e,t,r)}var J=[{key:"name",label:"Name",headerClass:"w-full sm:w-1/3 text-left",cellClass:"font-medium text-text truncate"},{key:"progress",label:"Progress",headerClass:"w-24 text-right",cellClass:"tabular-nums text-right",formatter:"progress"},{key:"downloadSpeed",label:"\u2193 Speed",headerClass:"w-24 text-right",cellClass:"tabular-nums text-right",formatter:"bytesPerSecond"},{key:"uploadSpeed",label:"\u2191 Speed",headerClass:"w-24 text-right",cellClass:"tabular-nums text-right",formatter:"bytesPerSecond"},{key:"numPeers",label:"Peers",headerClass:"w-20 text-right",cellClass:"tabular-nums text-right",formatter:"integer"},{key:"ratio",label:"Ratio",headerClass:"w-20 text-right",cellClass:"tabular-nums text-right",formatter:"ratio"}];function Ze(e){return e?e.infoHash||e.magnetURI||e.name||String(Math.random()):""}function Je(e,t){return!e||!t?!1:e===t||e.magnetURI&&e.magnetURI===t.magnetURI||e.infoHash&&e.infoHash===t.infoHash}function Qe(e){return typeof e!="number"||Number.isNaN(e)?"":`${(e*100).toFixed(1)}%`}function et(e){return typeof e!="number"||!Number.isFinite(e)?"0.00":e.toFixed(2)}function tt(e){return typeof e!="number"||!Number.isFinite(e)?"0":Math.max(0,Math.floor(e)).toString()}function rt(e,t){if(typeof t=="function")return t(e,!0)||"";if(typeof e!="number"||Number.isNaN(e)||e<1)return"";let r=["B","kB","MB","GB","TB"],o=Math.min(Math.floor(Math.log(e)/Math.log(1e3)),r.length-1);return`${(e/Math.pow(1e3,o)).toFixed(1)} ${r[o]}/s`}function nt(e,t){let r=e.formatter;if(typeof r=="function")return r;let o=t?.[r];if(typeof o=="function")return o;switch(r){case"progress":return Qe;case"ratio":return et;case"integer":return tt;case"bytesPerSecond":return n=>rt(n,t?.bytes);default:return n=>n}}function be({documentRef:e=typeof document<"u"?document:null,root:t,onSelect:r,formatters:o={}}={}){if(!e)throw new Error("createTorrentTable requires a document reference");if(!(t instanceof e.defaultView.HTMLElement))throw new Error("createTorrentTable requires a valid root element");let n=e;t.innerHTML="";let c=n.createElement("div");c.className="overflow-hidden rounded-xl border border-border-translucent bg-surface shadow-sm";let a=n.createElement("div");a.className="overflow-x-auto",c.appendChild(a);let u=n.createElement("table");u.className="min-w-full divide-y divide-border-translucent text-sm",a.appendChild(u);let d=n.createElement("thead");d.className="bg-surface-alt text-muted-strong";let L=n.createElement("tr");J.forEach(E=>{let x=n.createElement("th");x.setAttribute("scope","col"),x.className="px-4 py-3 text-left text-xs font-semibold uppercase tracking-wide",E.headerClass&&(x.className+=` ${E.headerClass}`),x.textContent=E.label,L.appendChild(x)}),d.appendChild(L),u.appendChild(d);let w=n.createElement("tbody");w.className="divide-y divide-border-translucent",u.appendChild(w);let m=n.createElement("tbody"),A=n.createElement("tr"),y=n.createElement("td");y.className="px-4 py-8 text-center text-sm text-muted",y.colSpan=J.length,y.textContent="No active torrents yet. Add a magnet link to get started.",A.appendChild(y),m.appendChild(A),u.appendChild(m),t.appendChild(c);function N(E=[],x=null){let P=Array.isArray(E)?E:[];if(w.innerHTML="",!P.length){w.hidden=!0,m.hidden=!1;return}w.hidden=!1,m.hidden=!0;for(let O of P){let g=n.createElement("tr");g.className=["group","align-middle","cursor-pointer","transition","hover:bg-panel-hover","focus-visible:outline","focus-visible:outline-2","focus-visible:outline-offset-2","focus-visible:outline-info"].join(" "),g.setAttribute("role","button"),g.setAttribute("tabindex","0"),g.dataset.torrentId=Ze(O),Je(x,O)?(g.classList.add("bg-info/10","text-text"),g.setAttribute("aria-pressed","true")):g.setAttribute("aria-pressed","false"),g.addEventListener("click",()=>{typeof r=="function"&&r(O)}),g.addEventListener("keydown",C=>{(C.key==="Enter"||C.key===" ")&&(C.preventDefault(),typeof r=="function"&&r(O))}),J.forEach(C=>{let H=n.createElement("td");H.className="px-4 py-3",C.cellClass&&(H.className+=` ${C.cellClass}`);let G=O?O[C.key]:void 0,s=nt(C,o)(G,O,C),i=n.createElement("span");i.textContent=s==null?"":String(s),H.appendChild(i),g.appendChild(H)}),w.appendChild(g)}}function B(){t.innerHTML=""}return{render:N,destroy:B}}var ot="2.0",ge=["wss://tracker.btorrent.xyz","wss://tracker.openwebtorrent.com"],ye={announce:ge},at={announce:ge};function j(e,t=!1){if(typeof e!="number"||Number.isNaN(e))return"";if(e<1)return t?"":"0 B";let r=["B","kB","MB","GB","TB"],o=Math.min(Math.floor(Math.log(e)/Math.log(1e3)),r.length-1);return`${(e/Math.pow(1e3,o)).toFixed(1)} ${r[o]}${t?"/s":""}`}function st(e){return typeof e!="number"||Number.isNaN(e)?"":`${(e*100).toFixed(1)}%`}function Ee(e){return typeof e!="number"||!Number.isFinite(e)?"0.00":e.toFixed(2)}function it(e,t){return!e||!t?!1:!!(e===t||e.infoHash&&t.infoHash&&e.infoHash===t.infoHash||e.magnetURI&&t.magnetURI&&e.magnetURI===t.magnetURI)}function ct(e){if(!(!e||!Array.isArray(e.files))&&(e.files.forEach(t=>{typeof t.priority!="string"&&(t.priority="0"),typeof t.getBlobURL=="function"&&t.getBlobURL((r,o)=>{r||!o||(t.url=o)})}),e.torrentFile&&typeof Blob=="function"&&typeof URL<"u"))try{let t=new Blob([e.torrentFile],{type:"application/x-bittorrent"});if(e.torrentFileBlobURL=URL.createObjectURL(t),!e.fileName){let r=e.name||"download";e.fileName=`${r}.torrent`}}catch(t){S.warn("[beacon] Failed to create torrent blob URL",t)}}function lt(e,t){if(!e)return;let r=typeof t=="string"?t:String(t??"0");if(e.priority=r,r==="-1"){typeof e.deselect=="function"&&e.deselect();return}let o=Number.parseInt(r,10);Number.isFinite(o)&&typeof e.select=="function"&&e.select(o)}function Te(e,t){if(!Array.isArray(t)||t.length===0)return null;if(!e)return t[0];let r=t.find(o=>it(o,e));return r||t[0]}function _e({documentRef:e=typeof document<"u"?document:null,WebTorrentCtor:t}={}){if(!e)throw new Error("createBeaconApp requires a document reference");let r=e.defaultView||globalThis,o=typeof t=="function"?t:typeof r?.WebTorrent=="function"?r.WebTorrent:null;if(!o)throw new Error("createBeaconApp requires a WebTorrent constructor");let n=he(e),c=new o({tracker:at}),a={form:e.querySelector('[data-beacon="magnet-form"]'),magnetInput:e.querySelector('[data-beacon="magnet-input"]'),seedButton:e.querySelector('[data-beacon="seed-button"]'),seedInput:e.querySelector('[data-beacon="seed-input"]'),tableRoot:e.querySelector('[data-beacon="torrent-table"]'),selectedSection:e.querySelector('[data-beacon="selected"]'),selectedName:e.querySelector('[data-beacon="selected-name"]'),pauseButton:e.querySelector('[data-beacon-action="pause"]'),resumeButton:e.querySelector('[data-beacon-action="resume"]'),downloadAllButton:e.querySelector('[data-beacon-action="download-all"]'),removeButton:e.querySelector('[data-beacon-action="remove"]'),copyMagnetButton:e.querySelector('[data-beacon-action="copy-magnet"]'),infoHashValue:e.querySelector('[data-beacon="info-hash"]'),fileList:e.querySelector('[data-beacon="file-list"]'),stats:e.querySelector('[data-beacon="client-stats"]'),overlay:e.querySelector('[data-beacon="processing-overlay"]')},u=a.tableRoot?be({documentRef:e,root:a.tableRoot,formatters:{bytes:(s,i=!1)=>j(s,i),progress:s=>st(s),ratio:s=>Ee(s),integer:s=>typeof s=="number"&&Number.isFinite(s)?Math.floor(s).toString():"0",bytesPerSecond:s=>j(s,!0)},onSelect(s){d.selectedTorrent=s,E()}}):null,d={selectedTorrent:null,processing:!1},L=[],w=[];function m(s){L.push(s)}function A(s){if(d.processing=!!s,!a.overlay)return;let i=d.processing;a.overlay.hidden=!i,a.overlay.setAttribute("aria-hidden",i?"false":"true"),i?a.overlay.style.removeProperty("display"):a.overlay.style.display="none"}function y(){return Array.isArray(c.torrents)?[...c.torrents]:[]}function N(){if(!a.stats)return;let s=j(c.downloadSpeed,!0)||"0 B/s",i=j(c.uploadSpeed,!0)||"0 B/s",p=Ee(c.ratio);a.stats.textContent=`Client stats: \u2193 ${s} \xB7 \u2191 ${i} \xB7 Ratio: ${p}`}function B(s){a.fileList&&(a.fileList.innerHTML="",!(!s||!Array.isArray(s.files)||!s.files.length)&&s.files.forEach((i,p)=>{let f=e.createElement("tr");f.className="align-top";let l=e.createElement("td");if(l.className="px-3 py-2",i.done&&i.url){let T=e.createElement("a");T.className="text-info hover:text-info-strong",T.href=i.url,T.download=i.name||`file-${p+1}`,T.textContent=i.name||`File ${p+1}`,l.appendChild(T)}else{let T=e.createElement("span");T.textContent=i.name||`File ${p+1}`,l.appendChild(T)}f.appendChild(l);let h=e.createElement("td");h.className="px-3 py-2 text-muted-strong",h.textContent=j(i.length)||"0 B",f.appendChild(h);let V=e.createElement("td");V.className="px-3 py-2";let R=e.createElement("select");R.className="select",R.name=`${i.name||`file-${p+1}`}-priority`,R.setAttribute("aria-label",`Set priority for ${i.name||`file ${p+1}`}`),[{value:"1",label:"High priority"},{value:"0",label:"Low priority"},{value:"-1",label:"Don't download"}].forEach(T=>{let Y=e.createElement("option");Y.value=T.value,Y.textContent=T.label,T.value===i.priority&&(Y.selected=!0),R.appendChild(Y)}),R.value=i.priority??"0",R.addEventListener("change",T=>{lt(i,T.target.value)}),V.appendChild(R),f.appendChild(V),a.fileList.appendChild(f)}))}function E(){if(!a.selectedSection)return;let s=y();d.selectedTorrent=Te(d.selectedTorrent,s);let i=d.selectedTorrent;a.selectedSection.hidden=!i,i&&(a.selectedName&&(a.selectedName.textContent=i.name||"Untitled torrent"),a.pauseButton&&(a.pauseButton.hidden=i.paused===!0,a.pauseButton.disabled=i.paused===!0),a.resumeButton&&(a.resumeButton.hidden=i.paused!==!0,a.resumeButton.disabled=i.paused!==!0),a.downloadAllButton&&(a.downloadAllButton.disabled=!(i.progress>=1)),a.infoHashValue&&(a.infoHashValue.textContent=i.infoHash||""),B(i))}function x(s,{isSeed:i=!1}={}){A(!1),ct(s),i||n.info(`Received ${s.name||"torrent"} metadata`),d.selectedTorrent||(d.selectedTorrent=s),E(),u?.render(y(),d.selectedTorrent)}function P(s){let i=typeof s=="string"?s.trim():"";i&&(A(!0),c.add(i,ye,p=>{x(p,{isSeed:!1})}))}function O(s){!Array.isArray(s)||s.length===0||(A(!0),c.seed(s,ye,i=>{x(i,{isSeed:!0}),n.success(`Seeding ${i.files.length} file(s)`)}))}function g(s){if(s){if(s.progress<1){n.warn("Torrent is not finished downloading yet.");return}s.files.forEach(i=>{typeof i.getBlob=="function"&&i.getBlob((p,f)=>{if(p||!f){b.error("[beacon] Failed to get blob for file",i?.name,p),n.error("Failed to prepare file for download.");return}let l=URL.createObjectURL(f),h=e.createElement("a");h.className="beacon-hidden-download",h.setAttribute("data-beacon-hidden-download","true"),h.href=l,h.download=i.name||"download",e.body.appendChild(h),h.click(),e.body.removeChild(h),URL.revokeObjectURL(l)})})}}function C(s){if(!s?.magnetURI)return;let i=s.magnetURI,p=r?.navigator?.clipboard;if(p&&typeof p.writeText=="function"){p.writeText(i).then(()=>{n.success("Magnet URI copied to clipboard!")}).catch(f=>{b.error("[beacon] Clipboard error",f),n.error("Failed to copy magnet URI")});return}try{let f=e.createElement("textarea");f.value=i,f.className="beacon-clipboard-offscreen",f.setAttribute("data-beacon-clipboard-state","offscreen"),e.body.appendChild(f),f.select(),e.execCommand?.("copy"),e.body.removeChild(f),n.success("Magnet URI copied (fallback)!")}catch(f){b.error("[beacon] Clipboard fallback error",f),n.error("Failed to copy magnet URI")}}function H(s){s&&s.destroy(i=>{i&&(b.error("[beacon] Failed to destroy torrent",i),n.error("Failed to remove torrent"));let p=y();d.selectedTorrent=Te(null,p),u?.render(p,d.selectedTorrent),E()})}function G(){if(S.info(`[beacon] Starting beacon runtime v${ot}`),n||S.warn("[beacon] Toast service unavailable"),o.WEBRTC_SUPPORT||n?.error("Please use a browser with WebRTC support.",{sticky:!0}),a.form){let l=h=>{h.preventDefault(),P(a.magnetInput?.value||""),a.magnetInput&&(a.magnetInput.value="")};a.form.addEventListener("submit",l),m(()=>a.form.removeEventListener("submit",l))}if(a.seedButton&&a.seedInput){let l=()=>{a.seedInput.click()},h=()=>{let V=Array.from(a.seedInput.files||[]);a.seedInput.value="",O(V)};a.seedButton.addEventListener("click",l),a.seedInput.addEventListener("change",h),m(()=>{a.seedButton.removeEventListener("click",l),a.seedInput.removeEventListener("change",h)})}if(a.pauseButton){let l=()=>{d.selectedTorrent&&typeof d.selectedTorrent.pause=="function"&&(d.selectedTorrent.pause(),E())};a.pauseButton.addEventListener("click",l),m(()=>a.pauseButton.removeEventListener("click",l))}if(a.resumeButton){let l=()=>{d.selectedTorrent&&typeof d.selectedTorrent.resume=="function"&&(d.selectedTorrent.resume(),E())};a.resumeButton.addEventListener("click",l),m(()=>a.resumeButton.removeEventListener("click",l))}if(a.downloadAllButton){let l=()=>g(d.selectedTorrent);a.downloadAllButton.addEventListener("click",l),m(()=>a.downloadAllButton.removeEventListener("click",l))}if(a.removeButton){let l=()=>H(d.selectedTorrent);a.removeButton.addEventListener("click",l),m(()=>a.removeButton.removeEventListener("click",l))}if(a.copyMagnetButton){let l=()=>C(d.selectedTorrent);a.copyMagnetButton.addEventListener("click",l),m(()=>a.copyMagnetButton.removeEventListener("click",l))}let s=l=>{b.error("[beacon] Torrent client error",l),n?.error(l?.message||String(l)),A(!1)};c.on("error",s),m(()=>c.removeListener("error",s));let i=l=>{if(c.torrents&&c.torrents.length>0)return l.preventDefault(),l.returnValue="Transfers are in progress. Are you sure you want to leave or refresh?",l.returnValue};r&&typeof r.addEventListener=="function"&&(r.addEventListener("beforeunload",i),m(()=>r.removeEventListener("beforeunload",i))),u?.render(y(),d.selectedTorrent),E(),N(),A(!1);let p=r.setInterval(()=>{u?.render(y(),d.selectedTorrent),E(),N()},1e3);w.push(p);let f=r?.location?.hash;typeof f=="string"&&f.length>1&&P(f.slice(1))}function Q(){w.forEach(s=>r.clearInterval(s)),w.length=0,L.forEach(s=>{try{s()}catch(i){S.warn("[beacon] Cleanup task failed",i)}}),L.length=0,u?.destroy();try{c.destroy()}catch(s){S.warn("[beacon] Failed to destroy client",s)}}return{mount:G,destroy:Q}}var Se="../../config/instance-config.js";function dt(){return typeof window<"u"&&window||typeof globalThis<"u"&&globalThis||null}function ut(){let e=dt();if(e&&typeof e.WebTorrent=="function")return e.WebTorrent;throw new Error("WebTorrent runtime is not available on the global scope")}var $=null,ft=async()=>{try{let e=await import(Se);if(e&&typeof e.THEME_ACCENT_OVERRIDES<"u")return e.THEME_ACCENT_OVERRIDES}catch(e){S.warn(`[beacon] Failed to load theme accent overrides from ${Se}`,e)}return null},pt=async()=>{try{let e=await ft();e&&ue(e)}catch(e){S.warn("[beacon] Unable to hydrate theme accent overrides",e)}try{fe()}catch(e){S.warn("[beacon] Failed to initialize theme controller",e)}};pt();function we(){if($)return S.info("[beacon] Reusing existing beacon app instance"),$;if(typeof document>"u")throw new Error("Beacon runtime requires a document environment");let e=ut();return S.info("[beacon] Creating beacon app instance"),$=_e({documentRef:document,WebTorrentCtor:e}),$.mount(),$}if(typeof document<"u")if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",()=>{try{we()}catch(e){b.error("[beacon] Failed to mount app",e)}});else try{we()}catch(e){b.error("[beacon] Failed to mount app",e)}export{_e as createBeaconApp,we as mountBeaconApp}; diff --git a/dist/vendor/floating-ui.dom.bundle.min.js b/dist/vendor/floating-ui.dom.bundle.min.js index 41865e7e..aa3ba55a 100644 --- a/dist/vendor/floating-ui.dom.bundle.min.js +++ b/dist/vendor/floating-ui.dom.bundle.min.js @@ -1 +1 @@ -var H=Math.min,B=Math.max,ot=Math.round,it=Math.floor,L=t=>({x:t,y:t}),qt={left:"right",right:"left",bottom:"top",top:"bottom"},Ut={start:"end",end:"start"};function lt(t,e,n){return B(t,H(e,n))}function U(t,e){return typeof t=="function"?t(e):t}function V(t){return t.split("-")[0]}function K(t){return t.split("-")[1]}function pt(t){return t==="x"?"y":"x"}function at(t){return t==="y"?"height":"width"}var Kt=new Set(["top","bottom"]);function W(t){return Kt.has(V(t))?"y":"x"}function ft(t){return pt(W(t))}function Ot(t,e,n){n===void 0&&(n=!1);let o=K(t),i=ft(t),r=at(i),s=i==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=nt(s)),[s,nt(s)]}function Rt(t){let e=nt(t);return[ct(t),e,ct(e)]}function ct(t){return t.replace(/start|end/g,e=>Ut[e])}var bt=["left","right"],At=["right","left"],Gt=["top","bottom"],Jt=["bottom","top"];function Qt(t,e,n){switch(t){case"top":case"bottom":return n?e?At:bt:e?bt:At;case"left":case"right":return e?Gt:Jt;default:return[]}}function St(t,e,n,o){let i=K(t),r=Qt(V(t),n==="start",o);return i&&(r=r.map(s=>s+"-"+i),e&&(r=r.concat(r.map(ct)))),r}function nt(t){return t.replace(/left|right|bottom|top/g,e=>qt[e])}function Zt(t){return{top:0,right:0,bottom:0,left:0,...t}}function wt(t){return typeof t!="number"?Zt(t):{top:t,right:t,bottom:t,left:t}}function X(t){let{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function Ct(t,e,n){let{reference:o,floating:i}=t,r=W(e),s=ft(e),c=at(s),a=V(e),l=r==="y",d=o.x+o.width/2-i.width/2,u=o.y+o.height/2-i.height/2,g=o[c]/2-i[c]/2,f;switch(a){case"top":f={x:d,y:o.y-i.height};break;case"bottom":f={x:d,y:o.y+o.height};break;case"right":f={x:o.x+o.width,y:u};break;case"left":f={x:o.x-i.width,y:u};break;default:f={x:o.x,y:o.y}}switch(K(e)){case"start":f[s]-=g*(n&&l?-1:1);break;case"end":f[s]+=g*(n&&l?-1:1);break}return f}var Pt=async(t,e,n)=>{let{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:s}=n,c=r.filter(Boolean),a=await(s.isRTL==null?void 0:s.isRTL(e)),l=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:d,y:u}=Ct(l,o,a),g=o,f={},m=0;for(let h=0;h({name:"arrow",options:t,async fn(e){let{x:n,y:o,placement:i,rects:r,platform:s,elements:c,middlewareData:a}=e,{element:l,padding:d=0}=U(t,e)||{};if(l==null)return{};let u=wt(d),g={x:n,y:o},f=ft(i),m=at(f),h=await s.getDimensions(l),w=f==="y",p=w?"top":"left",x=w?"bottom":"right",y=w?"clientHeight":"clientWidth",b=r.reference[m]+r.reference[f]-g[f]-r.floating[m],v=g[f]-r.reference[f],M=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l)),R=M?M[y]:0;(!R||!await(s.isElement==null?void 0:s.isElement(M)))&&(R=c.floating[y]||r.floating[m]);let Z=b/2-v/2,_=R/2-h[m]/2-1,F=H(u[p],_),tt=H(u[x],_),z=F,et=R-h[m]-tt,A=R/2-h[m]/2+Z,I=lt(z,A,et),k=!a.arrow&&K(i)!=null&&A!==I&&r.reference[m]/2-(AA<=0)){var tt,z;let A=(((tt=r.flip)==null?void 0:tt.index)||0)+1,I=R[A];if(I&&(!(u==="alignment"?x!==W(I):!1)||F.every(T=>W(T.placement)===x?T.overflows[0]>0:!0)))return{data:{index:A,overflows:F},reset:{placement:I}};let k=(z=F.filter(P=>P.overflows[0]<=0).sort((P,T)=>P.overflows[1]-T.overflows[1])[0])==null?void 0:z.placement;if(!k)switch(f){case"bestFit":{var et;let P=(et=F.filter(T=>{if(M){let $=W(T.placement);return $===x||$==="y"}return!0}).map(T=>[T.placement,T.overflows.filter($=>$>0).reduce(($,Yt)=>$+Yt,0)]).sort((T,$)=>T[1]-$[1])[0])==null?void 0:et[0];P&&(k=P);break}case"initialPlacement":k=c;break}if(i!==k)return{reset:{placement:k}}}return{}}}};var te=new Set(["left","top"]);async function ee(t,e){let{placement:n,platform:o,elements:i}=t,r=await(o.isRTL==null?void 0:o.isRTL(i.floating)),s=V(n),c=K(n),a=W(n)==="y",l=te.has(s)?-1:1,d=r&&a?-1:1,u=U(e,t),{mainAxis:g,crossAxis:f,alignmentAxis:m}=typeof u=="number"?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return c&&typeof m=="number"&&(f=c==="end"?m*-1:m),a?{x:f*d,y:g*l}:{x:g*l,y:f*d}}var Et=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,o;let{x:i,y:r,placement:s,middlewareData:c}=e,a=await ee(e,t);return s===((n=c.offset)==null?void 0:n.placement)&&(o=c.arrow)!=null&&o.alignmentOffset?{}:{x:i+a.x,y:r+a.y,data:{...a,placement:s}}}}},Dt=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){let{x:n,y:o,placement:i}=e,{mainAxis:r=!0,crossAxis:s=!1,limiter:c={fn:w=>{let{x:p,y:x}=w;return{x:p,y:x}}},...a}=U(t,e),l={x:n,y:o},d=await xt(e,a),u=W(V(i)),g=pt(u),f=l[g],m=l[u];if(r){let w=g==="y"?"top":"left",p=g==="y"?"bottom":"right",x=f+d[w],y=f-d[p];f=lt(x,f,y)}if(s){let w=u==="y"?"top":"left",p=u==="y"?"bottom":"right",x=m+d[w],y=m-d[p];m=lt(x,m,y)}let h=c.fn({...e,[g]:f,[u]:m});return{...h,data:{x:h.x-n,y:h.y-o,enabled:{[g]:r,[u]:s}}}}}};function ut(){return typeof window<"u"}function j(t){return Ft(t)?(t.nodeName||"").toLowerCase():"#document"}function O(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function E(t){var e;return(e=(Ft(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Ft(t){return ut()?t instanceof Node||t instanceof O(t).Node:!1}function S(t){return ut()?t instanceof Element||t instanceof O(t).Element:!1}function D(t){return ut()?t instanceof HTMLElement||t instanceof O(t).HTMLElement:!1}function Mt(t){return!ut()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof O(t).ShadowRoot}var ne=new Set(["inline","contents"]);function J(t){let{overflow:e,overflowX:n,overflowY:o,display:i}=C(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!ne.has(i)}var oe=new Set(["table","td","th"]);function kt(t){return oe.has(j(t))}var ie=[":popover-open",":modal"];function st(t){return ie.some(e=>{try{return t.matches(e)}catch{return!1}})}var se=["transform","translate","scale","rotate","perspective"],re=["transform","translate","scale","rotate","perspective","filter"],ce=["paint","layout","strict","content"];function dt(t){let e=mt(),n=S(t)?C(t):t;return se.some(o=>n[o]?n[o]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||re.some(o=>(n.willChange||"").includes(o))||ce.some(o=>(n.contain||"").includes(o))}function Bt(t){let e=N(t);for(;D(e)&&!Y(e);){if(dt(e))return e;if(st(e))return null;e=N(e)}return null}function mt(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var le=new Set(["html","body","#document"]);function Y(t){return le.has(j(t))}function C(t){return O(t).getComputedStyle(t)}function rt(t){return S(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function N(t){if(j(t)==="html")return t;let e=t.assignedSlot||t.parentNode||Mt(t)&&t.host||E(t);return Mt(e)?e.host:e}function Wt(t){let e=N(t);return Y(e)?t.ownerDocument?t.ownerDocument.body:t.body:D(e)&&J(e)?e:Wt(e)}function G(t,e,n){var o;e===void 0&&(e=[]),n===void 0&&(n=!0);let i=Wt(t),r=i===((o=t.ownerDocument)==null?void 0:o.body),s=O(i);if(r){let c=gt(s);return e.concat(s,s.visualViewport||[],J(i)?i:[],c&&n?G(c):[])}return e.concat(i,G(i,[],n))}function gt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Vt(t){let e=C(t),n=parseFloat(e.width)||0,o=parseFloat(e.height)||0,i=D(t),r=i?t.offsetWidth:n,s=i?t.offsetHeight:o,c=ot(n)!==r||ot(o)!==s;return c&&(n=r,o=s),{width:n,height:o,$:c}}function vt(t){return S(t)?t:t.contextElement}function Q(t){let e=vt(t);if(!D(e))return L(1);let n=e.getBoundingClientRect(),{width:o,height:i,$:r}=Vt(e),s=(r?ot(n.width):n.width)/o,c=(r?ot(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!c||!Number.isFinite(c))&&(c=1),{x:s,y:c}}var ae=L(0);function _t(t){let e=O(t);return!mt()||!e.visualViewport?ae:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function fe(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==O(t)?!1:e}function q(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);let i=t.getBoundingClientRect(),r=vt(t),s=L(1);e&&(o?S(o)&&(s=Q(o)):s=Q(t));let c=fe(r,n,o)?_t(r):L(0),a=(i.left+c.x)/s.x,l=(i.top+c.y)/s.y,d=i.width/s.x,u=i.height/s.y;if(r){let g=O(r),f=o&&S(o)?O(o):o,m=g,h=gt(m);for(;h&&o&&f!==m;){let w=Q(h),p=h.getBoundingClientRect(),x=C(h),y=p.left+(h.clientLeft+parseFloat(x.paddingLeft))*w.x,b=p.top+(h.clientTop+parseFloat(x.paddingTop))*w.y;a*=w.x,l*=w.y,d*=w.x,u*=w.y,a+=y,l+=b,m=O(h),h=gt(m)}}return X({width:d,height:u,x:a,y:l})}function ht(t,e){let n=rt(t).scrollLeft;return e?e.left+n:q(E(t)).left+n}function zt(t,e){let n=t.getBoundingClientRect(),o=n.left+e.scrollLeft-ht(t,n),i=n.top+e.scrollTop;return{x:o,y:i}}function ue(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t,r=i==="fixed",s=E(o),c=e?st(e.floating):!1;if(o===s||c&&r)return n;let a={scrollLeft:0,scrollTop:0},l=L(1),d=L(0),u=D(o);if((u||!u&&!r)&&((j(o)!=="body"||J(s))&&(a=rt(o)),D(o))){let f=q(o);l=Q(o),d.x=f.x+o.clientLeft,d.y=f.y+o.clientTop}let g=s&&!u&&!r?zt(s,a):L(0);return{width:n.width*l.x,height:n.height*l.y,x:n.x*l.x-a.scrollLeft*l.x+d.x+g.x,y:n.y*l.y-a.scrollTop*l.y+d.y+g.y}}function de(t){return Array.from(t.getClientRects())}function me(t){let e=E(t),n=rt(t),o=t.ownerDocument.body,i=B(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),r=B(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight),s=-n.scrollLeft+ht(t),c=-n.scrollTop;return C(o).direction==="rtl"&&(s+=B(e.clientWidth,o.clientWidth)-i),{width:i,height:r,x:s,y:c}}var Nt=25;function ge(t,e){let n=O(t),o=E(t),i=n.visualViewport,r=o.clientWidth,s=o.clientHeight,c=0,a=0;if(i){r=i.width,s=i.height;let d=mt();(!d||d&&e==="fixed")&&(c=i.offsetLeft,a=i.offsetTop)}let l=ht(o);if(l<=0){let d=o.ownerDocument,u=d.body,g=getComputedStyle(u),f=d.compatMode==="CSS1Compat"&&parseFloat(g.marginLeft)+parseFloat(g.marginRight)||0,m=Math.abs(o.clientWidth-u.clientWidth-f);m<=Nt&&(r-=m)}else l<=Nt&&(r+=l);return{width:r,height:s,x:c,y:a}}var he=new Set(["absolute","fixed"]);function pe(t,e){let n=q(t,!0,e==="fixed"),o=n.top+t.clientTop,i=n.left+t.clientLeft,r=D(t)?Q(t):L(1),s=t.clientWidth*r.x,c=t.clientHeight*r.y,a=i*r.x,l=o*r.y;return{width:s,height:c,x:a,y:l}}function $t(t,e,n){let o;if(e==="viewport")o=ge(t,n);else if(e==="document")o=me(E(t));else if(S(e))o=pe(e,n);else{let i=_t(t);o={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return X(o)}function It(t,e){let n=N(t);return n===e||!S(n)||Y(n)?!1:C(n).position==="fixed"||It(n,e)}function we(t,e){let n=e.get(t);if(n)return n;let o=G(t,[],!1).filter(c=>S(c)&&j(c)!=="body"),i=null,r=C(t).position==="fixed",s=r?N(t):t;for(;S(s)&&!Y(s);){let c=C(s),a=dt(s);!a&&c.position==="fixed"&&(i=null),(r?!a&&!i:!a&&c.position==="static"&&!!i&&he.has(i.position)||J(s)&&!a&&It(t,s))?o=o.filter(d=>d!==s):i=c,s=N(s)}return e.set(t,o),o}function xe(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t,s=[...n==="clippingAncestors"?st(e)?[]:we(e,this._c):[].concat(n),o],c=s[0],a=s.reduce((l,d)=>{let u=$t(e,d,i);return l.top=B(u.top,l.top),l.right=H(u.right,l.right),l.bottom=H(u.bottom,l.bottom),l.left=B(u.left,l.left),l},$t(e,c,i));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}}function ye(t){let{width:e,height:n}=Vt(t);return{width:e,height:n}}function ve(t,e,n){let o=D(e),i=E(e),r=n==="fixed",s=q(t,!0,r,e),c={scrollLeft:0,scrollTop:0},a=L(0);function l(){a.x=ht(i)}if(o||!o&&!r)if((j(e)!=="body"||J(i))&&(c=rt(e)),o){let f=q(e,!0,r,e);a.x=f.x+e.clientLeft,a.y=f.y+e.clientTop}else i&&l();r&&!o&&i&&l();let d=i&&!o&&!r?zt(i,c):L(0),u=s.left+c.scrollLeft-a.x-d.x,g=s.top+c.scrollTop-a.y-d.y;return{x:u,y:g,width:s.width,height:s.height}}function yt(t){return C(t).position==="static"}function Ht(t,e){if(!D(t)||C(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return E(t)===n&&(n=n.ownerDocument.body),n}function Xt(t,e){let n=O(t);if(st(t))return n;if(!D(t)){let i=N(t);for(;i&&!Y(i);){if(S(i)&&!yt(i))return i;i=N(i)}return n}let o=Ht(t,e);for(;o&&kt(o)&&yt(o);)o=Ht(o,e);return o&&Y(o)&&yt(o)&&!dt(o)?n:o||Bt(t)||n}var be=async function(t){let e=this.getOffsetParent||Xt,n=this.getDimensions,o=await n(t.floating);return{reference:ve(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function Ae(t){return C(t).direction==="rtl"}var Oe={convertOffsetParentRelativeRectToViewportRelativeRect:ue,getDocumentElement:E,getClippingRect:xe,getOffsetParent:Xt,getElementRects:be,getClientRects:de,getDimensions:ye,getScale:Q,isElement:S,isRTL:Ae};function jt(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function Re(t,e){let n=null,o,i=E(t);function r(){var c;clearTimeout(o),(c=n)==null||c.disconnect(),n=null}function s(c,a){c===void 0&&(c=!1),a===void 0&&(a=1),r();let l=t.getBoundingClientRect(),{left:d,top:u,width:g,height:f}=l;if(c||e(),!g||!f)return;let m=it(u),h=it(i.clientWidth-(d+g)),w=it(i.clientHeight-(u+f)),p=it(d),y={rootMargin:-m+"px "+-h+"px "+-w+"px "+-p+"px",threshold:B(0,H(1,a))||1},b=!0;function v(M){let R=M[0].intersectionRatio;if(R!==a){if(!b)return s();R?s(!1,R):o=setTimeout(()=>{s(!1,1e-7)},1e3)}R===1&&!jt(l,t.getBoundingClientRect())&&s(),b=!1}try{n=new IntersectionObserver(v,{...y,root:i.ownerDocument})}catch{n=new IntersectionObserver(v,y)}n.observe(t)}return s(!0),r}function Se(t,e,n,o){o===void 0&&(o={});let{ancestorScroll:i=!0,ancestorResize:r=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:c=typeof IntersectionObserver=="function",animationFrame:a=!1}=o,l=vt(t),d=i||r?[...l?G(l):[],...G(e)]:[];d.forEach(p=>{i&&p.addEventListener("scroll",n,{passive:!0}),r&&p.addEventListener("resize",n)});let u=l&&c?Re(l,n):null,g=-1,f=null;s&&(f=new ResizeObserver(p=>{let[x]=p;x&&x.target===l&&f&&(f.unobserve(e),cancelAnimationFrame(g),g=requestAnimationFrame(()=>{var y;(y=f)==null||y.observe(e)})),n()}),l&&!a&&f.observe(l),f.observe(e));let m,h=a?q(t):null;a&&w();function w(){let p=q(t);h&&!jt(h,p)&&n(),h=p,m=requestAnimationFrame(w)}return n(),()=>{var p;d.forEach(x=>{i&&x.removeEventListener("scroll",n),r&&x.removeEventListener("resize",n)}),u?.(),(p=f)==null||p.disconnect(),f=null,a&&cancelAnimationFrame(m)}}var Ce=Et;var Pe=Dt,Te=Lt;var Le=Tt;var Ee=(t,e,n)=>{let o=new Map,i={platform:Oe,...n},r={...i.platform,_c:o};return Pt(t,e,{...i,platform:r})};export{Le as arrow,Se as autoUpdate,Ee as computePosition,Te as flip,Ce as offset,Pe as shift}; +var $=Math.min,B=Math.max,ot=Math.round,it=Math.floor,E=t=>({x:t,y:t}),qt={left:"right",right:"left",bottom:"top",top:"bottom"},Ut={start:"end",end:"start"};function lt(t,e,n){return B(t,$(e,n))}function U(t,e){return typeof t=="function"?t(e):t}function V(t){return t.split("-")[0]}function K(t){return t.split("-")[1]}function pt(t){return t==="x"?"y":"x"}function at(t){return t==="y"?"height":"width"}var Kt=new Set(["top","bottom"]);function W(t){return Kt.has(V(t))?"y":"x"}function ft(t){return pt(W(t))}function At(t,e,n){n===void 0&&(n=!1);let o=K(t),i=ft(t),r=at(i),s=i==="x"?o===(n?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[r]>e.floating[r]&&(s=nt(s)),[s,nt(s)]}function Ot(t){let e=nt(t);return[ct(t),e,ct(e)]}function ct(t){return t.replace(/start|end/g,e=>Ut[e])}var vt=["left","right"],bt=["right","left"],Gt=["top","bottom"],Jt=["bottom","top"];function Qt(t,e,n){switch(t){case"top":case"bottom":return n?e?bt:vt:e?vt:bt;case"left":case"right":return e?Gt:Jt;default:return[]}}function Rt(t,e,n,o){let i=K(t),r=Qt(V(t),n==="start",o);return i&&(r=r.map(s=>s+"-"+i),e&&(r=r.concat(r.map(ct)))),r}function nt(t){return t.replace(/left|right|bottom|top/g,e=>qt[e])}function Zt(t){return{top:0,right:0,bottom:0,left:0,...t}}function wt(t){return typeof t!="number"?Zt(t):{top:t,right:t,bottom:t,left:t}}function X(t){let{x:e,y:n,width:o,height:i}=t;return{width:o,height:i,top:n,left:e,right:e+o,bottom:n+i,x:e,y:n}}function St(t,e,n){let{reference:o,floating:i}=t,r=W(e),s=ft(e),c=at(s),l=V(e),a=r==="y",d=o.x+o.width/2-i.width/2,u=o.y+o.height/2-i.height/2,m=o[c]/2-i[c]/2,f;switch(l){case"top":f={x:d,y:o.y-i.height};break;case"bottom":f={x:d,y:o.y+o.height};break;case"right":f={x:o.x+o.width,y:u};break;case"left":f={x:o.x-i.width,y:u};break;default:f={x:o.x,y:o.y}}switch(K(e)){case"start":f[s]-=m*(n&&a?-1:1);break;case"end":f[s]+=m*(n&&a?-1:1);break}return f}async function Ct(t,e){var n;e===void 0&&(e={});let{x:o,y:i,platform:r,rects:s,elements:c,strategy:l}=t,{boundary:a="clippingAncestors",rootBoundary:d="viewport",elementContext:u="floating",altBoundary:m=!1,padding:f=0}=U(e,t),g=wt(f),w=c[m?u==="floating"?"reference":"floating":u],h=X(await r.getClippingRect({element:(n=await(r.isElement==null?void 0:r.isElement(w)))==null||n?w:w.contextElement||await(r.getDocumentElement==null?void 0:r.getDocumentElement(c.floating)),boundary:a,rootBoundary:d,strategy:l})),x=u==="floating"?{x:o,y:i,width:s.floating.width,height:s.floating.height}:s.reference,y=await(r.getOffsetParent==null?void 0:r.getOffsetParent(c.floating)),v=await(r.isElement==null?void 0:r.isElement(y))?await(r.getScale==null?void 0:r.getScale(y))||{x:1,y:1}:{x:1,y:1},O=X(r.convertOffsetParentRelativeRectToViewportRelativeRect?await r.convertOffsetParentRelativeRectToViewportRelativeRect({elements:c,rect:x,offsetParent:y,strategy:l}):x);return{top:(h.top-O.top+g.top)/v.y,bottom:(O.bottom-h.bottom+g.bottom)/v.y,left:(h.left-O.left+g.left)/v.x,right:(O.right-h.right+g.right)/v.x}}var Pt=async(t,e,n)=>{let{placement:o="bottom",strategy:i="absolute",middleware:r=[],platform:s}=n,c=r.filter(Boolean),l=await(s.isRTL==null?void 0:s.isRTL(e)),a=await s.getElementRects({reference:t,floating:e,strategy:i}),{x:d,y:u}=St(a,o,l),m=o,f={},g=0;for(let w=0;w({name:"arrow",options:t,async fn(e){let{x:n,y:o,placement:i,rects:r,platform:s,elements:c,middlewareData:l}=e,{element:a,padding:d=0}=U(t,e)||{};if(a==null)return{};let u=wt(d),m={x:n,y:o},f=ft(i),g=at(f),p=await s.getDimensions(a),w=f==="y",h=w?"top":"left",x=w?"bottom":"right",y=w?"clientHeight":"clientWidth",v=r.reference[g]+r.reference[f]-m[f]-r.floating[g],O=m[f]-r.reference[f],b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(a)),S=b?b[y]:0;(!S||!await(s.isElement==null?void 0:s.isElement(b)))&&(S=c.floating[y]||r.floating[g]);let Z=v/2-O/2,z=S/2-p[g]/2-1,F=$(u[h],z),tt=$(u[x],z),_=F,et=S-p[g]-tt,A=S/2-p[g]/2+Z,I=lt(_,A,et),k=!l.arrow&&K(i)!=null&&A!==I&&r.reference[g]/2-(A<_?F:tt)-p[g]/2<0,T=k?A<_?A-_:A-et:0;return{[f]:m[f]+T,data:{[f]:I,centerOffset:A-I-T,...k&&{alignmentOffset:T}},reset:k}}});var Lt=function(t){return t===void 0&&(t={}),{name:"flip",options:t,async fn(e){var n,o;let{placement:i,middlewareData:r,rects:s,initialPlacement:c,platform:l,elements:a}=e,{mainAxis:d=!0,crossAxis:u=!0,fallbackPlacements:m,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:g="none",flipAlignment:p=!0,...w}=U(t,e);if((n=r.arrow)!=null&&n.alignmentOffset)return{};let h=V(i),x=W(c),y=V(c)===c,v=await(l.isRTL==null?void 0:l.isRTL(a.floating)),O=m||(y||!p?[nt(c)]:Ot(c)),b=g!=="none";!m&&b&&O.push(...Rt(c,p,g,v));let S=[c,...O],Z=await l.detectOverflow(e,w),z=[],F=((o=r.flip)==null?void 0:o.overflows)||[];if(d&&z.push(Z[h]),u){let A=At(i,s,v);z.push(Z[A[0]],Z[A[1]])}if(F=[...F,{placement:i,overflows:z}],!z.every(A=>A<=0)){var tt,_;let A=(((tt=r.flip)==null?void 0:tt.index)||0)+1,I=S[A];if(I&&(!(u==="alignment"?x!==W(I):!1)||F.every(L=>W(L.placement)===x?L.overflows[0]>0:!0)))return{data:{index:A,overflows:F},reset:{placement:I}};let k=(_=F.filter(T=>T.overflows[0]<=0).sort((T,L)=>T.overflows[1]-L.overflows[1])[0])==null?void 0:_.placement;if(!k)switch(f){case"bestFit":{var et;let T=(et=F.filter(L=>{if(b){let H=W(L.placement);return H===x||H==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(H=>H>0).reduce((H,Yt)=>H+Yt,0)]).sort((L,H)=>L[1]-H[1])[0])==null?void 0:et[0];T&&(k=T);break}case"initialPlacement":k=c;break}if(i!==k)return{reset:{placement:k}}}return{}}}};var te=new Set(["left","top"]);async function ee(t,e){let{placement:n,platform:o,elements:i}=t,r=await(o.isRTL==null?void 0:o.isRTL(i.floating)),s=V(n),c=K(n),l=W(n)==="y",a=te.has(s)?-1:1,d=r&&l?-1:1,u=U(e,t),{mainAxis:m,crossAxis:f,alignmentAxis:g}=typeof u=="number"?{mainAxis:u,crossAxis:0,alignmentAxis:null}:{mainAxis:u.mainAxis||0,crossAxis:u.crossAxis||0,alignmentAxis:u.alignmentAxis};return c&&typeof g=="number"&&(f=c==="end"?g*-1:g),l?{x:f*d,y:m*a}:{x:m*a,y:f*d}}var Et=function(t){return t===void 0&&(t=0),{name:"offset",options:t,async fn(e){var n,o;let{x:i,y:r,placement:s,middlewareData:c}=e,l=await ee(e,t);return s===((n=c.offset)==null?void 0:n.placement)&&(o=c.arrow)!=null&&o.alignmentOffset?{}:{x:i+l.x,y:r+l.y,data:{...l,placement:s}}}}},Dt=function(t){return t===void 0&&(t={}),{name:"shift",options:t,async fn(e){let{x:n,y:o,placement:i,platform:r}=e,{mainAxis:s=!0,crossAxis:c=!1,limiter:l={fn:h=>{let{x,y}=h;return{x,y}}},...a}=U(t,e),d={x:n,y:o},u=await r.detectOverflow(e,a),m=W(V(i)),f=pt(m),g=d[f],p=d[m];if(s){let h=f==="y"?"top":"left",x=f==="y"?"bottom":"right",y=g+u[h],v=g-u[x];g=lt(y,g,v)}if(c){let h=m==="y"?"top":"left",x=m==="y"?"bottom":"right",y=p+u[h],v=p-u[x];p=lt(y,p,v)}let w=l.fn({...e,[f]:g,[m]:p});return{...w,data:{x:w.x-n,y:w.y-o,enabled:{[f]:s,[m]:c}}}}}};function ut(){return typeof window<"u"}function j(t){return Ft(t)?(t.nodeName||"").toLowerCase():"#document"}function R(t){var e;return(t==null||(e=t.ownerDocument)==null?void 0:e.defaultView)||window}function D(t){var e;return(e=(Ft(t)?t.ownerDocument:t.document)||window.document)==null?void 0:e.documentElement}function Ft(t){return ut()?t instanceof Node||t instanceof R(t).Node:!1}function C(t){return ut()?t instanceof Element||t instanceof R(t).Element:!1}function M(t){return ut()?t instanceof HTMLElement||t instanceof R(t).HTMLElement:!1}function Mt(t){return!ut()||typeof ShadowRoot>"u"?!1:t instanceof ShadowRoot||t instanceof R(t).ShadowRoot}var ne=new Set(["inline","contents"]);function J(t){let{overflow:e,overflowX:n,overflowY:o,display:i}=P(t);return/auto|scroll|overlay|hidden|clip/.test(e+o+n)&&!ne.has(i)}var oe=new Set(["table","td","th"]);function kt(t){return oe.has(j(t))}var ie=[":popover-open",":modal"];function st(t){return ie.some(e=>{try{return t.matches(e)}catch{return!1}})}var se=["transform","translate","scale","rotate","perspective"],re=["transform","translate","scale","rotate","perspective","filter"],ce=["paint","layout","strict","content"];function dt(t){let e=mt(),n=C(t)?P(t):t;return se.some(o=>n[o]?n[o]!=="none":!1)||(n.containerType?n.containerType!=="normal":!1)||!e&&(n.backdropFilter?n.backdropFilter!=="none":!1)||!e&&(n.filter?n.filter!=="none":!1)||re.some(o=>(n.willChange||"").includes(o))||ce.some(o=>(n.contain||"").includes(o))}function Bt(t){let e=N(t);for(;M(e)&&!Y(e);){if(dt(e))return e;if(st(e))return null;e=N(e)}return null}function mt(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}var le=new Set(["html","body","#document"]);function Y(t){return le.has(j(t))}function P(t){return R(t).getComputedStyle(t)}function rt(t){return C(t)?{scrollLeft:t.scrollLeft,scrollTop:t.scrollTop}:{scrollLeft:t.scrollX,scrollTop:t.scrollY}}function N(t){if(j(t)==="html")return t;let e=t.assignedSlot||t.parentNode||Mt(t)&&t.host||D(t);return Mt(e)?e.host:e}function Wt(t){let e=N(t);return Y(e)?t.ownerDocument?t.ownerDocument.body:t.body:M(e)&&J(e)?e:Wt(e)}function G(t,e,n){var o;e===void 0&&(e=[]),n===void 0&&(n=!0);let i=Wt(t),r=i===((o=t.ownerDocument)==null?void 0:o.body),s=R(i);if(r){let c=gt(s);return e.concat(s,s.visualViewport||[],J(i)?i:[],c&&n?G(c):[])}return e.concat(i,G(i,[],n))}function gt(t){return t.parent&&Object.getPrototypeOf(t.parent)?t.frameElement:null}function Vt(t){let e=P(t),n=parseFloat(e.width)||0,o=parseFloat(e.height)||0,i=M(t),r=i?t.offsetWidth:n,s=i?t.offsetHeight:o,c=ot(n)!==r||ot(o)!==s;return c&&(n=r,o=s),{width:n,height:o,$:c}}function yt(t){return C(t)?t:t.contextElement}function Q(t){let e=yt(t);if(!M(e))return E(1);let n=e.getBoundingClientRect(),{width:o,height:i,$:r}=Vt(e),s=(r?ot(n.width):n.width)/o,c=(r?ot(n.height):n.height)/i;return(!s||!Number.isFinite(s))&&(s=1),(!c||!Number.isFinite(c))&&(c=1),{x:s,y:c}}var ae=E(0);function zt(t){let e=R(t);return!mt()||!e.visualViewport?ae:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function fe(t,e,n){return e===void 0&&(e=!1),!n||e&&n!==R(t)?!1:e}function q(t,e,n,o){e===void 0&&(e=!1),n===void 0&&(n=!1);let i=t.getBoundingClientRect(),r=yt(t),s=E(1);e&&(o?C(o)&&(s=Q(o)):s=Q(t));let c=fe(r,n,o)?zt(r):E(0),l=(i.left+c.x)/s.x,a=(i.top+c.y)/s.y,d=i.width/s.x,u=i.height/s.y;if(r){let m=R(r),f=o&&C(o)?R(o):o,g=m,p=gt(g);for(;p&&o&&f!==g;){let w=Q(p),h=p.getBoundingClientRect(),x=P(p),y=h.left+(p.clientLeft+parseFloat(x.paddingLeft))*w.x,v=h.top+(p.clientTop+parseFloat(x.paddingTop))*w.y;l*=w.x,a*=w.y,d*=w.x,u*=w.y,l+=y,a+=v,g=R(p),p=gt(g)}}return X({width:d,height:u,x:l,y:a})}function ht(t,e){let n=rt(t).scrollLeft;return e?e.left+n:q(D(t)).left+n}function _t(t,e){let n=t.getBoundingClientRect(),o=n.left+e.scrollLeft-ht(t,n),i=n.top+e.scrollTop;return{x:o,y:i}}function ue(t){let{elements:e,rect:n,offsetParent:o,strategy:i}=t,r=i==="fixed",s=D(o),c=e?st(e.floating):!1;if(o===s||c&&r)return n;let l={scrollLeft:0,scrollTop:0},a=E(1),d=E(0),u=M(o);if((u||!u&&!r)&&((j(o)!=="body"||J(s))&&(l=rt(o)),M(o))){let f=q(o);a=Q(o),d.x=f.x+o.clientLeft,d.y=f.y+o.clientTop}let m=s&&!u&&!r?_t(s,l):E(0);return{width:n.width*a.x,height:n.height*a.y,x:n.x*a.x-l.scrollLeft*a.x+d.x+m.x,y:n.y*a.y-l.scrollTop*a.y+d.y+m.y}}function de(t){return Array.from(t.getClientRects())}function me(t){let e=D(t),n=rt(t),o=t.ownerDocument.body,i=B(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),r=B(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight),s=-n.scrollLeft+ht(t),c=-n.scrollTop;return P(o).direction==="rtl"&&(s+=B(e.clientWidth,o.clientWidth)-i),{width:i,height:r,x:s,y:c}}var Nt=25;function ge(t,e){let n=R(t),o=D(t),i=n.visualViewport,r=o.clientWidth,s=o.clientHeight,c=0,l=0;if(i){r=i.width,s=i.height;let d=mt();(!d||d&&e==="fixed")&&(c=i.offsetLeft,l=i.offsetTop)}let a=ht(o);if(a<=0){let d=o.ownerDocument,u=d.body,m=getComputedStyle(u),f=d.compatMode==="CSS1Compat"&&parseFloat(m.marginLeft)+parseFloat(m.marginRight)||0,g=Math.abs(o.clientWidth-u.clientWidth-f);g<=Nt&&(r-=g)}else a<=Nt&&(r+=a);return{width:r,height:s,x:c,y:l}}var he=new Set(["absolute","fixed"]);function pe(t,e){let n=q(t,!0,e==="fixed"),o=n.top+t.clientTop,i=n.left+t.clientLeft,r=M(t)?Q(t):E(1),s=t.clientWidth*r.x,c=t.clientHeight*r.y,l=i*r.x,a=o*r.y;return{width:s,height:c,x:l,y:a}}function Ht(t,e,n){let o;if(e==="viewport")o=ge(t,n);else if(e==="document")o=me(D(t));else if(C(e))o=pe(e,n);else{let i=zt(t);o={x:e.x-i.x,y:e.y-i.y,width:e.width,height:e.height}}return X(o)}function It(t,e){let n=N(t);return n===e||!C(n)||Y(n)?!1:P(n).position==="fixed"||It(n,e)}function we(t,e){let n=e.get(t);if(n)return n;let o=G(t,[],!1).filter(c=>C(c)&&j(c)!=="body"),i=null,r=P(t).position==="fixed",s=r?N(t):t;for(;C(s)&&!Y(s);){let c=P(s),l=dt(s);!l&&c.position==="fixed"&&(i=null),(r?!l&&!i:!l&&c.position==="static"&&!!i&&he.has(i.position)||J(s)&&!l&&It(t,s))?o=o.filter(d=>d!==s):i=c,s=N(s)}return e.set(t,o),o}function xe(t){let{element:e,boundary:n,rootBoundary:o,strategy:i}=t,s=[...n==="clippingAncestors"?st(e)?[]:we(e,this._c):[].concat(n),o],c=s[0],l=s.reduce((a,d)=>{let u=Ht(e,d,i);return a.top=B(u.top,a.top),a.right=$(u.right,a.right),a.bottom=$(u.bottom,a.bottom),a.left=B(u.left,a.left),a},Ht(e,c,i));return{width:l.right-l.left,height:l.bottom-l.top,x:l.left,y:l.top}}function ye(t){let{width:e,height:n}=Vt(t);return{width:e,height:n}}function ve(t,e,n){let o=M(e),i=D(e),r=n==="fixed",s=q(t,!0,r,e),c={scrollLeft:0,scrollTop:0},l=E(0);function a(){l.x=ht(i)}if(o||!o&&!r)if((j(e)!=="body"||J(i))&&(c=rt(e)),o){let f=q(e,!0,r,e);l.x=f.x+e.clientLeft,l.y=f.y+e.clientTop}else i&&a();r&&!o&&i&&a();let d=i&&!o&&!r?_t(i,c):E(0),u=s.left+c.scrollLeft-l.x-d.x,m=s.top+c.scrollTop-l.y-d.y;return{x:u,y:m,width:s.width,height:s.height}}function xt(t){return P(t).position==="static"}function $t(t,e){if(!M(t)||P(t).position==="fixed")return null;if(e)return e(t);let n=t.offsetParent;return D(t)===n&&(n=n.ownerDocument.body),n}function Xt(t,e){let n=R(t);if(st(t))return n;if(!M(t)){let i=N(t);for(;i&&!Y(i);){if(C(i)&&!xt(i))return i;i=N(i)}return n}let o=$t(t,e);for(;o&&kt(o)&&xt(o);)o=$t(o,e);return o&&Y(o)&&xt(o)&&!dt(o)?n:o||Bt(t)||n}var be=async function(t){let e=this.getOffsetParent||Xt,n=this.getDimensions,o=await n(t.floating);return{reference:ve(t.reference,await e(t.floating),t.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function Ae(t){return P(t).direction==="rtl"}var Oe={convertOffsetParentRelativeRectToViewportRelativeRect:ue,getDocumentElement:D,getClippingRect:xe,getOffsetParent:Xt,getElementRects:be,getClientRects:de,getDimensions:ye,getScale:Q,isElement:C,isRTL:Ae};function jt(t,e){return t.x===e.x&&t.y===e.y&&t.width===e.width&&t.height===e.height}function Re(t,e){let n=null,o,i=D(t);function r(){var c;clearTimeout(o),(c=n)==null||c.disconnect(),n=null}function s(c,l){c===void 0&&(c=!1),l===void 0&&(l=1),r();let a=t.getBoundingClientRect(),{left:d,top:u,width:m,height:f}=a;if(c||e(),!m||!f)return;let g=it(u),p=it(i.clientWidth-(d+m)),w=it(i.clientHeight-(u+f)),h=it(d),y={rootMargin:-g+"px "+-p+"px "+-w+"px "+-h+"px",threshold:B(0,$(1,l))||1},v=!0;function O(b){let S=b[0].intersectionRatio;if(S!==l){if(!v)return s();S?s(!1,S):o=setTimeout(()=>{s(!1,1e-7)},1e3)}S===1&&!jt(a,t.getBoundingClientRect())&&s(),v=!1}try{n=new IntersectionObserver(O,{...y,root:i.ownerDocument})}catch{n=new IntersectionObserver(O,y)}n.observe(t)}return s(!0),r}function Se(t,e,n,o){o===void 0&&(o={});let{ancestorScroll:i=!0,ancestorResize:r=!0,elementResize:s=typeof ResizeObserver=="function",layoutShift:c=typeof IntersectionObserver=="function",animationFrame:l=!1}=o,a=yt(t),d=i||r?[...a?G(a):[],...G(e)]:[];d.forEach(h=>{i&&h.addEventListener("scroll",n,{passive:!0}),r&&h.addEventListener("resize",n)});let u=a&&c?Re(a,n):null,m=-1,f=null;s&&(f=new ResizeObserver(h=>{let[x]=h;x&&x.target===a&&f&&(f.unobserve(e),cancelAnimationFrame(m),m=requestAnimationFrame(()=>{var y;(y=f)==null||y.observe(e)})),n()}),a&&!l&&f.observe(a),f.observe(e));let g,p=l?q(t):null;l&&w();function w(){let h=q(t);p&&!jt(p,h)&&n(),p=h,g=requestAnimationFrame(w)}return n(),()=>{var h;d.forEach(x=>{i&&x.removeEventListener("scroll",n),r&&x.removeEventListener("resize",n)}),u?.(),(h=f)==null||h.disconnect(),f=null,l&&cancelAnimationFrame(g)}}var Ce=Et;var Pe=Dt,Te=Lt;var Le=Tt;var Ee=(t,e,n)=>{let o=new Map,i={platform:Oe,...n},r={...i.platform,_c:o};return Pt(t,e,{...i,platform:r})};export{Le as arrow,Se as autoUpdate,Ee as computePosition,Te as flip,Ce as offset,Pe as shift};