(function () { "use strict"; const ROOT_ID = "__web_to_pixso_picker_root__"; const BOX_ID = "__web_to_pixso_picker_box__"; const LABEL_ID = "__web_to_pixso_picker_label__"; const ATTR = "data-web-to-pixso-selection-id"; const STORAGE_KEY = "__web_to_pixso_island_position__"; let currentElement = null; let currentSettings = null; let mode = "toolbar"; let dragging = null; function removePicker() { document.getElementById(ROOT_ID)?.remove(); document.getElementById(BOX_ID)?.remove(); document.getElementById(LABEL_ID)?.remove(); document.removeEventListener("mousemove", onMouseMove, true); document.removeEventListener("click", onClick, true); document.removeEventListener("keydown", onKeyDown, true); document.removeEventListener("pointermove", onDragMove, true); document.removeEventListener("pointerup", onDragEnd, true); currentElement = null; mode = "toolbar"; dragging = null; } function elementName(element) { if (!element) return ""; const tag = element.tagName ? element.tagName.toLowerCase() : "element"; const id = element.id ? `#${element.id}` : ""; const className = String(element.className || "") .trim() .split(/\s+/) .filter(Boolean) .slice(0, 2) .map(item => `.${item}`) .join(""); return `${tag}${id}${className}`; } function icon(type) { if (type === "screen") { return ''; } if (type === "select") { return ''; } if (type === "copy") { return ''; } return ''; } function rootCss() { return ` #${ROOT_ID} { color-scheme: light; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; left: 50%; position: fixed; top: 24px; transform: translateX(-50%); user-select: none; z-index: 2147483647; } #${ROOT_ID} .w2p-island { align-items: stretch; background: rgba(36, 36, 38, 0.97); border-radius: 22px; box-shadow: 0 8px 24px rgba(0,0,0,.22); color: white; display: flex; min-height: 56px; overflow: hidden; } #${ROOT_ID} .w2p-action, #${ROOT_ID} .w2p-close, #${ROOT_ID} .w2p-cancel { align-items: center; background: transparent; border: 0; color: white; cursor: pointer; display: flex; font: inherit; gap: 10px; justify-content: center; min-height: 56px; padding: 0 18px; white-space: nowrap; } #${ROOT_ID} .w2p-action { border-right: 1px solid rgba(255,255,255,.14); font-size: 16px; font-weight: 650; } #${ROOT_ID} .w2p-action:hover, #${ROOT_ID} .w2p-close:hover, #${ROOT_ID} .w2p-cancel:hover { background: rgba(255,255,255,.1); } #${ROOT_ID} .w2p-action.active { background: rgba(255,255,255,.12); } #${ROOT_ID} svg { fill: none; height: 20px; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2; width: 20px; } #${ROOT_ID} .w2p-close { min-width: 56px; padding: 0 16px; } #${ROOT_ID} .w2p-status { align-items: center; display: flex; gap: 12px; min-height: 56px; padding: 0 20px; } #${ROOT_ID} .w2p-text { font-size: 16px; font-weight: 650; white-space: nowrap; } #${ROOT_ID} .w2p-spinner { animation: w2p-spin .9s linear infinite; border: 2px solid rgba(255,255,255,.32); border-radius: 50%; border-top-color: #fff; height: 20px; width: 20px; } #${ROOT_ID} .w2p-cancel { border-left: 1px solid rgba(255,255,255,.14); font-size: 15px; padding: 0 18px; } #${BOX_ID} { background: rgba(46, 156, 255, .16); border: 2px dashed #1593ff; border-radius: 6px; box-sizing: border-box; display: none; left: 0; pointer-events: none; position: fixed; top: 0; z-index: 2147483646; } #${LABEL_ID} { background: #fff; border-radius: 6px; box-shadow: 0 8px 22px rgba(0,0,0,.2); color: #333; display: none; font: 14px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; max-width: 280px; overflow: hidden; padding: 8px 10px; pointer-events: none; position: fixed; text-overflow: ellipsis; white-space: nowrap; z-index: 2147483647; } @keyframes w2p-spin { to { transform: rotate(360deg); } } `; } function ensureBase() { document.getElementById(ROOT_ID)?.remove(); const root = document.createElement("div"); root.id = ROOT_ID; const style = document.createElement("style"); style.textContent = rootCss(); root.appendChild(style); document.documentElement.appendChild(root); let box = document.getElementById(BOX_ID); if (!box) { box = document.createElement("div"); box.id = BOX_ID; document.documentElement.appendChild(box); } let label = document.getElementById(LABEL_ID); if (!label) { label = document.createElement("div"); label.id = LABEL_ID; document.documentElement.appendChild(label); } restorePosition(root); root.addEventListener("pointerdown", onDragStart, true); return root; } function restorePosition(root) { try { const saved = JSON.parse(sessionStorage.getItem(STORAGE_KEY) || "null"); if (saved && Number.isFinite(saved.left) && Number.isFinite(saved.top)) { root.style.left = `${saved.left}px`; root.style.top = `${saved.top}px`; root.style.transform = "none"; } } catch { // Keep the default centered position when storage is unavailable. } } function savePosition(root) { const rect = root.getBoundingClientRect(); try { sessionStorage.setItem(STORAGE_KEY, JSON.stringify({ left: Math.round(rect.left), top: Math.round(rect.top) })); } catch { // Position persistence is only a convenience. } } function clampIsland(root, snap) { const rect = root.getBoundingClientRect(); let left = rect.left; let top = rect.top; const gap = 10; left = Math.max(gap, Math.min(window.innerWidth - rect.width - gap, left)); top = Math.max(gap, Math.min(window.innerHeight - rect.height - gap, top)); if (snap) { const distances = [ { side: "left", value: left }, { side: "right", value: window.innerWidth - left - rect.width }, { side: "top", value: top }, { side: "bottom", value: window.innerHeight - top - rect.height } ].sort((a, b) => a.value - b.value); if (distances[0].value < 96) { if (distances[0].side === "left") left = gap; if (distances[0].side === "right") left = window.innerWidth - rect.width - gap; if (distances[0].side === "top") top = gap; if (distances[0].side === "bottom") top = window.innerHeight - rect.height - gap; } } root.style.left = `${Math.round(left)}px`; root.style.top = `${Math.round(top)}px`; root.style.transform = "none"; savePosition(root); } function onDragStart(event) { const target = event.target; if (target?.closest?.("button")) return; const root = document.getElementById(ROOT_ID); if (!root) return; const rect = root.getBoundingClientRect(); dragging = { offsetX: event.clientX - rect.left, offsetY: event.clientY - rect.top }; root.style.transform = "none"; document.addEventListener("pointermove", onDragMove, true); document.addEventListener("pointerup", onDragEnd, true); } function onDragMove(event) { if (!dragging) return; event.preventDefault(); const root = document.getElementById(ROOT_ID); if (!root) return; root.style.left = `${event.clientX - dragging.offsetX}px`; root.style.top = `${event.clientY - dragging.offsetY}px`; } function onDragEnd() { const root = document.getElementById(ROOT_ID); dragging = null; document.removeEventListener("pointermove", onDragMove, true); document.removeEventListener("pointerup", onDragEnd, true); if (root) clampIsland(root, true); } function setToolbarStatus(text, busy = true) { const root = document.getElementById(ROOT_ID) || ensureBase(); root.innerHTML = `