import { H as C, a9 as B, M as b, y as X, aJ as Z, a as Y, _ as K, Z as _, I as j } from "./index.B_XvPxIW.js"; import { i as J } from "./media.CtajaVnR.js"; import { P as E } from "./initialize.lazy.DYuWBGl3.js"; import { s as U, o as z, p as F, c as V, b as G, a as Q } from "./index.BlwoYJNp.js"; import { aN as tt } from "./VirtualKeyboard.x9bo5ETV.js"; import { u as I } from "./jsxRuntime.module.92xvPm7T.js"; import { j as et, m as ot, e as nt } from "./goober-should-forward-prop.modern.BENVY72G.js"; const w = F( G(Q()), V((t) => t === void 0 || t === "auto" || t.endsWith("px"), "only auto or px is allowed") ), rt = z({ top: w, bottom: w, left: w, right: w }), P = (t) => `uniweb-custom-position-${t ? "sp" : "pc"}`, x = tt({ delay: 1e3 }, (t, r) => { localStorage && (localStorage == null || localStorage.setItem(P(r), JSON.stringify(t))); }), st = (t, r) => { if (!localStorage) return; const o = localStorage.getItem(P(r)); if (!o) return; const s = Z(o); if (s.isErr() || it(s.value, t)) { L(r); return; } const l = U(rt, s.value); if (!l.success) { L(r); return; } return l.output; }, L = (t) => { localStorage && localStorage.removeItem(P(t)); }, it = (t, r) => r === E.HORIZONTAL ? t.left !== void 0 && t.right !== void 0 : t.top !== void 0 || t.bottom !== void 0, ct = (t) => { let r; return () => { if (r) return r; if (!t.current) return { tx: 0, ty: 0 }; const s = window.getComputedStyle(t.current).transform.match(/matrix\(([^)]+)\)/), l = s == null ? void 0 : s[1]; if (!l) return { tx: 0, ty: 0 }; const d = l.split(/,\s*/).map(Number), y = d[4], v = d[5]; return r = { tx: y, ty: v }, r; }; }, bt = (t, r) => { const o = C(null), s = J(window.innerWidth), l = ct(o), d = (e, n, i) => { var m, h, g, f; const { ty: c } = l(), p = Math.round(i / 2); if (e / 2 < n) { const a = Math.round(e - n - p + c), u = `${a < c ? c : a}px`; (m = o.current) == null || m.style.setProperty("top", "auto"), (h = o.current) == null || h.style.setProperty("bottom", u), x({ bottom: u, top: "auto" }, s); } else { const a = Math.round(n - p - c), u = `${a < -c ? -c : a}px`; (g = o.current) == null || g.style.setProperty("top", u), (f = o.current) == null || f.style.setProperty("bottom", "auto"), x({ top: u, bottom: "auto" }, s); } }, y = (e, n, i) => { var m, h, g, f; const { tx: c } = l(), p = Math.round(i / 2); if (e / 2 < n) { const a = Math.round(e - n - p + c), u = `${a < c ? c : a}px`; (m = o.current) == null || m.style.setProperty("left", "auto"), (h = o.current) == null || h.style.setProperty("right", u), x({ right: u, left: "auto" }, s); } else { const a = Math.round(n - p - c), u = `${a < -c ? -c : a}px`; (g = o.current) == null || g.style.setProperty("left", u), (f = o.current) == null || f.style.setProperty("right", "auto"), x({ left: u, right: "auto" }, s); } }, v = () => o.current ? Number.parseInt(window.getComputedStyle(o.current).height) : 50, $ = () => o.current ? Number.parseInt(window.getComputedStyle(o.current).width) : 50, H = (e) => { e.preventDefault(), e.stopPropagation(); const n = document.documentElement.clientWidth, i = e.clientX; y(n, i, $()); }, N = (e) => { e.preventDefault(), e.stopPropagation(); const n = document.documentElement.clientHeight, i = e.clientY; d(n, i, v()); }, R = (e) => { e.preventDefault(), e.stopPropagation(); const n = document.documentElement.clientWidth, i = e.changedTouches[0].clientX; y(n, i, $()); }, W = (e) => { e.preventDefault(), e.stopPropagation(); const n = document.documentElement.clientHeight, i = e.changedTouches[0].clientY; d(n, i, v()); }, M = B([r, s]).with([b.BOOKMARK, !0], () => t.widgetIcon.bookmark.sp.positionDirection).with([b.BOOKMARK, !1], () => t.widgetIcon.bookmark.pc.positionDirection).with([b.ROUND, !0], () => t.widgetIcon.round.sp.positionDirection).with([b.ROUND, !1], () => t.widgetIcon.round.pc.positionDirection).exhaustive(), k = (e) => { var i; (i = o.current) == null || i.setAttribute("data-moving", "true"), (M === E.HORIZONTAL ? N : H)(e); }, q = () => { let e = !0; document.addEventListener("mouseup", () => { e = !1; }), setTimeout(() => { var n; e && (document.addEventListener("mousemove", k), document.addEventListener("mouseup", S), (n = o.current) == null || n.style.setProperty("transition", "none")); }, 100); }, S = () => { var e; document.removeEventListener("mousemove", k), document.removeEventListener("mouseup", S), (e = o.current) == null || e.style.removeProperty("transition"), setTimeout(() => { var n; (n = o.current) == null || n.removeAttribute("data-moving"); }, 100); }, D = M === E.HORIZONTAL ? W : R, A = () => { var e; document.addEventListener("touchmove", D, { passive: !1 }), document.addEventListener("touchend", T), (e = o.current) == null || e.style.setProperty("transition", "none"); }, T = () => { var e; document.removeEventListener("touchmove", D), document.removeEventListener("touchend", T), (e = o.current) == null || e.style.removeProperty("transition"); }; return X(() => { var e, n; return (e = o.current) == null || e.addEventListener("mousedown", q), (n = o.current) == null || n.addEventListener("touchstart", A, { passive: !1 }), () => { S(), T(); }; }), { buttonRef: o, savedPosition: st(M, s) }; }, at = { sp: 499 }, ut = { sp: `@media (max-width: ${at.sp}px)` }; ot( K, void 0, void 0, nt((t) => t[0] !== "$") ); const O = et.bind({ target: Y() }), lt = () => /* @__PURE__ */ I( "svg", { xmlns: "http://www.w3.org/2000/svg", height: "24", viewBox: "0 -960 960 960", width: "24", role: "presentation", children: /* @__PURE__ */ I("path", { d: "m424-296 282-282-56-56-226 226-114-114-56 56 170 170Zm56 216q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Z" }) } ), wt = O("button", j)` position: fixed; display: flex; padding: 0; text-align: center; z-index: ${_.WIDGET_ICON}; transition: all 0.1s ease 0s; cursor: pointer; border: 0; outline-offset: 3px; opacity: 1; visibility: visible; &[aria-hidden='true'] { opacity: 0; visibility: hidden; transition: initial; transition: opacity 0.3s ease, visibility 0s 1s; } `, xt = O("span")` display: flex; height: 100%; width: 100%; align-items: center; justify-content: center; background: transparent; svg { transition: transform 0.15s ease; height: 60%; width: 60%; fill: ${({ $theme: t }) => t.palette.iconFg}; } `, dt = O("span")` display: flex; fill: ${(t) => t.$theme.palette.checkMarkBg}; background-color: ${(t) => t.$theme.palette.checkMarkFg}; border-radius: 50%; position: absolute; box-shadow: 0 0 3px rgba(0, 0, 0, 0.5); width: fit-content; ${(t) => t.$pcPosition} ${ut.sp} { ${(t) => t.$spPosition} } `, It = (t) => /* @__PURE__ */ I(dt, { ...t, children: /* @__PURE__ */ I(lt, {}) }); export { It as C, xt as I, wt as a, ut as m, O as s, bt as u };