'use strict'; // src/plugins/popout.ts function isPopoutSupported() { return typeof window !== "undefined" && window.documentPictureInPicture !== void 0; } function copyStylesInto(pipWindow, source) { for (const sheet of Array.from(source.styleSheets)) { const owner = sheet.ownerNode; if (!owner) continue; try { const rules = Array.from(sheet.cssRules).map((rule) => rule.cssText).join("\n"); const style = pipWindow.document.createElement("style"); style.textContent = rules; pipWindow.document.head.append(style); } catch { if (owner instanceof HTMLLinkElement && owner.href) { const link = pipWindow.document.createElement("link"); link.rel = "stylesheet"; link.href = owner.href; pipWindow.document.head.append(link); } } } } async function popout(wm, id, content, options = {}) { const win = wm.get(id); if (!win) throw new Error(`wmkit: cannot pop out unknown window "${id}"`); const api = typeof window !== "undefined" ? window.documentPictureInPicture : void 0; if (!api) throw new Error("wmkit: Document Picture-in-Picture is not supported in this browser"); const pipWindow = await api.requestWindow({ width: options.width ?? Math.round(win.bounds.width), height: options.height ?? Math.round(win.bounds.height) }); if (options.copyStyles !== false) copyStylesInto(pipWindow, content.ownerDocument); const parent = content.parentNode; const marker = content.ownerDocument.createComment("wmkit-popout"); parent?.insertBefore(marker, content); pipWindow.document.body.append(content); pipWindow.document.title = win.title; const minimizeWhilePopped = options.minimizeWhilePopped !== false; if (minimizeWhilePopped) wm.minimize(id); let closed = false; function handleReturn() { if (closed) return; closed = true; if (marker.parentNode) { marker.parentNode.insertBefore(content, marker); marker.remove(); } if (minimizeWhilePopped && wm.get(id)) wm.restore(id); } pipWindow.addEventListener("pagehide", handleReturn); return { pipWindow, close() { pipWindow.close(); handleReturn(); } }; } exports.isPopoutSupported = isPopoutSupported; exports.popout = popout; //# sourceMappingURL=popout.cjs.map //# sourceMappingURL=popout.cjs.map