{"version":3,"file":"background-lock.cjs","names":[],"sources":["../../../src/overlay/shared/background-lock.ts"],"sourcesContent":["/**\n * Shared background-lock utility for overlay components (dialog, drawer, etc.).\n *\n * Uses a reference count so that multiple stacked overlays each call\n * lock / unlock independently without interfering with each other. The `inert`\n * attribute is applied once when the first overlay opens and removed once the\n * last one closes.\n *\n * The factory pattern (`createBackgroundLock`) provides test-isolated instances.\n * The module-level `lockBackground` / `unlockBackground` are the defaults used\n * by all runtime components.\n */\n\nexport type BackgroundLock = {\n  lock(host: Element): void;\n  unlock(): void;\n};\n\nexport function createBackgroundLock(): BackgroundLock {\n  let lockCount = 0;\n  let lockedEls: Element[] = [];\n\n  return {\n    lock(host: Element): void {\n      if (lockCount === 0) {\n        let ancestor: Element = host;\n\n        while (ancestor.parentElement && ancestor.parentElement !== document.body) {\n          ancestor = ancestor.parentElement;\n        }\n\n        lockedEls = Array.from(document.body.children).filter((el) => el !== ancestor && !el.hasAttribute('inert'));\n\n        for (const el of lockedEls) el.setAttribute('inert', '');\n      }\n\n      lockCount++;\n    },\n\n    unlock(): void {\n      lockCount = Math.max(0, lockCount - 1);\n\n      if (lockCount === 0) {\n        for (const el of lockedEls) el.removeAttribute('inert');\n        lockedEls = [];\n      }\n    },\n  };\n}\n\nconst _default = createBackgroundLock();\n\n/** Marks sibling elements as inert. Safe to call from multiple concurrent overlays. */\nexport const lockBackground = (host: Element): void => _default.lock(host);\n\n/** Releases the background lock. Removes inert when all overlays have closed. */\nexport const unlockBackground = (): void => _default.unlock();\n"],"mappings":"AAkBA,SAAgB,GAAuC,CACrD,IAAI,EAAY,EACZ,EAAuB,CAAC,EAE5B,MAAO,CACL,KAAK,EAAqB,CACxB,GAAI,IAAc,EAAG,CACnB,IAAI,EAAoB,EAExB,KAAO,EAAS,eAAiB,EAAS,gBAAkB,SAAS,MACnE,EAAW,EAAS,cAGtB,EAAY,MAAM,KAAK,SAAS,KAAK,QAAQ,CAAC,CAAC,OAAQ,GAAO,IAAO,GAAY,CAAC,EAAG,aAAa,OAAO,CAAC,EAE1G,IAAK,IAAM,KAAM,EAAW,EAAG,aAAa,QAAS,EAAE,CACzD,CAEA,GACF,EAEA,QAAe,CAGb,GAFA,EAAY,KAAK,IAAI,EAAG,EAAY,CAAC,EAEjC,IAAc,EAAG,CACnB,IAAK,IAAM,KAAM,EAAW,EAAG,gBAAgB,OAAO,EACtD,EAAY,CAAC,CACf,CACF,CACF,CACF"}