@0x30/vue-navigation
Version:
392 lines (391 loc) • 11.5 kB
JavaScript
import { getCurrentInstance as p, onUnmounted as ce, createApp as ie, ref as pe, onMounted as T, createVNode as le, Transition as de, mergeProps as ue, defineComponent as fe } from "vue";
const K = () => document.querySelector("#___disable_all_pointerevents"), A = () => {
const e = K();
e.style.display = "block";
}, P = () => {
const e = K();
e.style.display = "none";
}, _e = () => {
const e = document.createElement("div");
e.id = "___disable_all_pointerevents", e.style.position = "fixed", e.style.top = "0", e.style.right = "0", e.style.bottom = "0", e.style.left = "0", e.style.opacity = "0", e.style.display = "none", e.style.zIndex = "99999999", document.body.appendChild(e);
}, q = () => `_${Math.random().toString(32).slice(2)}`, X = (e, t) => {
e == null || e.forEach((n) => n == null ? void 0 : n(...t ?? []));
}, Y = q(), i = [];
let Z;
const B = (e) => Z = e, H = () => Z;
let F;
const ee = (e) => F = e, ve = () => F, y = () => i[i.length - 1], z = {}, he = (e, t) => {
ee(e), z[e] = () => {
delete z[e], F = void 0, t();
};
}, Ce = (e) => {
var t;
e && ((t = z[e]) == null || t.apply(null));
};
var a = /* @__PURE__ */ ((e) => (e.onEnter = "_vn_oe", e.onLeave = "_vn_ol", e.close = "_vn_c", e.onLeaveBefore = "_vn_olb", e.onWillAppear = "_vn_owa", e.onWillDisappear = "_vn_owd", e.onDidAppear = "_vn_oda", e.onDidDisappear = "_vn_odd", e.cancelBatchId = "_vn_cbi", e.ExtData = "_vn_ed", e.onAfterEnter = "_vn_oae", e.onAfterLeave = "_vn_oal", e.onBeforeEnter = "_vn_obe", e.onBeforeLeave = "_vn_obl", e.ProgressExitAnimated = "_vn_p_e_a", e))(a || {});
const E = (e, t, n) => {
e && (e[t] = n);
}, x = (e, t, n) => {
if (e) {
const s = e[t] ?? [];
e[t] = [...s, n];
}
}, m = (e, t) => {
if (e)
return e[t];
}, te = (e, t) => {
const n = Q(e) ?? {};
E(e, "_vn_ed", {
...n,
...t
});
}, Q = (e) => m(
e,
"_vn_ed"
/* ExtData */
), ke = (e) => {
var t;
N((t = p()) == null ? void 0 : t.appContext, e), ce(() => {
var n;
N((n = p()) == null ? void 0 : n.appContext, void 0);
});
}, ne = (e) => m(
e,
a.onLeaveBefore
), N = (e, t) => E(e, a.onLeaveBefore, t), Se = () => {
var e;
te((e = p()) == null ? void 0 : e.appContext, { __is_quiet_page: !0 });
}, b = (e) => {
var t;
return ((t = Q(e)) == null ? void 0 : t.__is_quiet_page) === !0;
}, Ie = (e) => {
var t;
x(
(t = p()) == null ? void 0 : t.appContext,
a.onWillAppear,
e
);
}, Me = (e) => {
var t;
x(
(t = p()) == null ? void 0 : t.appContext,
a.onWillDisappear,
e
);
}, We = (e) => {
var t;
x(
(t = p()) == null ? void 0 : t.appContext,
a.onDidAppear,
e
);
}, Te = (e) => {
var t;
x(
(t = p()) == null ? void 0 : t.appContext,
a.onDidDisappear,
e
);
}, C = (e, t, n) => {
const s = m(
e,
t
);
X(s, [n]);
}, ze = (e) => {
var s;
const t = (s = p()) == null ? void 0 : s.appContext, n = S(t) ?? {};
te(t, { __pageMateInfo: { ...n, ...e } });
}, S = (e) => {
var t;
return (t = Q(e)) == null ? void 0 : t.__pageMateInfo;
}, V = /* @__PURE__ */ new Set(), Ne = (e, t) => {
const n = [e, t];
return V.add(n), () => V.delete(n);
}, $ = (e, t) => {
V.forEach(([n, s]) => {
const r = S(e), c = S(t);
(((s == null ? void 0 : s.isEvery) ?? !1) || /// 如果任何页面都收集
r !== void 0 && c !== void 0) && n.apply(null, [r, c]);
});
}, Ve = () => {
var e;
return S((e = y()) == null ? void 0 : e._context);
}, xe = (e, t) => (E(e, a.cancelBatchId, t), t), me = (e) => m(e, a.cancelBatchId), Ge = (e) => {
var t;
E(
(t = p()) == null ? void 0 : t.appContext,
a.onEnter,
e
);
}, Re = (e) => {
var t;
E(
(t = p()) == null ? void 0 : t.appContext,
a.onLeave,
e
);
}, we = (e, t) => {
E(e, a.close, t);
}, ye = (e) => m(
e,
a.close
), oe = (e, t, n, s) => new Promise((r) => {
const c = m(t, e);
c ? c == null || c.apply(null, [{ from: n, to: s }, r]) : r();
}), Ee = (e, t, n) => oe(a.onEnter, e, t, n), ge = (e, t, n) => oe(a.onLeave, e, t, n), W = (e) => {
window.dispatchEvent(
new CustomEvent(
"onNativateIosScreenEdgePanEvent",
{ detail: e }
)
);
};
function ae() {
window.ScreenEdgePanGestureRecognizerStart = () => {
A(), W({
state: 0
/* began */
});
}, window.ScreenEdgePanGestureRecognizerChange = (t) => {
W({ state: 1, progress: t });
}, window.ScreenEdgePanGestureRecognizerEnded = (t) => {
W({ state: 2, isFinish: t }), P();
};
const e = (t) => (t == null ? void 0 : t.childElementCount) === 1 ? t.children[0] : t;
window.addEventListener("onNativateIosScreenEdgePanEvent", (t) => {
if (i.length < 2) return;
const n = i[i.length - 1];
if (ne(n._context) !== void 0) {
be();
return;
}
const r = e(n._container), c = e(i[i.length - 2]._container);
switch (t.detail.state) {
case 0:
break;
case 1:
j({ from: r, to: c }, t.detail.progress);
break;
default:
j({ from: r, to: c }, 0, t.detail.isFinish);
break;
}
});
}
const qe = (e) => {
var t;
E(
(t = p()) == null ? void 0 : t.appContext,
a.ProgressExitAnimated,
e
);
}, j = (e, t, n) => {
var r;
const s = m(
(r = i[i.length - 1]) == null ? void 0 : r._context,
a.ProgressExitAnimated
);
s == null || s.apply(null, [e, t, n]);
}, Fe = (e) => {
var t;
x(
(t = p()) == null ? void 0 : t.appContext,
a.onAfterEnter,
e
);
}, Qe = (e) => {
var t;
x(
(t = p()) == null ? void 0 : t.appContext,
a.onAfterLeave,
e
);
}, Oe = (e) => {
var t;
x(
(t = p()) == null ? void 0 : t.appContext,
a.onBeforeEnter,
e
);
}, Ue = (e) => {
var t;
x(
(t = p()) == null ? void 0 : t.appContext,
a.onBeforeLeave,
e
);
}, D = (e, t) => {
const n = m(e, t);
X(n);
};
let k;
const $e = (e) => {
k = e;
}, G = (e, t, n, s) => {
var c;
if (n === void 0) return;
const r = () => {
var l;
n.unmount(), n._container instanceof Element && ((l = n._container.parentElement) == null || l.removeChild(n._container)), t && (P(), Ce(s));
};
e ? (c = ye(n._context)) == null || c(() => r()) : r();
}, J = (e) => (e == null ? void 0 : e.childElementCount) === 1 ? e.children[0] : e, se = (e, t, n) => new Promise((s) => {
const r = document.createElement("div");
document.body.appendChild(r);
const c = () => {
t !== !1 && G(!1, !1, i.splice(i.length - 2, 1)[0]);
}, {
onAfterEnter: l,
onAfterLeave: _,
onBeforeEnter: v,
onBeforeLeave: h,
...f
} = n ?? {}, u = ie({
setup: () => {
var U;
const w = pe(!0);
let g;
const L = (U = y()) == null ? void 0 : U._context;
let o = p();
return T(() => {
o = p(), we(o == null ? void 0 : o.appContext, (d) => {
g = d, w.value = !1;
});
}), () => le(de, ue({
appear: !0,
onEnter: async (d, I) => {
const M = J(L.app._container);
await Ee(o == null ? void 0 : o.appContext, M, d), c(), s(u), I();
},
onLeave: async (d, I) => {
A();
const M = J(y()._container);
await ge(o == null ? void 0 : o.appContext, d, M), g ? g() : P(), I();
},
onBeforeEnter: (d) => {
v == null || v(d), D(o == null ? void 0 : o.appContext, a.onBeforeEnter), !b(o == null ? void 0 : o.appContext) && (C(L, a.onWillDisappear), C(o == null ? void 0 : o.appContext, a.onWillAppear, !0));
},
onAfterEnter: (d) => {
l == null || l(d), D(o == null ? void 0 : o.appContext, a.onAfterEnter), !b(o == null ? void 0 : o.appContext) && (C(L, a.onDidDisappear), C(o == null ? void 0 : o.appContext, a.onDidAppear, !0), $(o == null ? void 0 : o.appContext, L));
},
onBeforeLeave: (d) => {
h == null || h(d), D(o == null ? void 0 : o.appContext, a.onBeforeLeave), !b(o == null ? void 0 : o.appContext) && (C(o == null ? void 0 : o.appContext, a.onWillDisappear), C(y()._context, a.onWillAppear, !1));
},
onAfterLeave: (d) => {
_ == null || _(d), D(o == null ? void 0 : o.appContext, a.onAfterLeave), !b(o == null ? void 0 : o.appContext) && (C(o == null ? void 0 : o.appContext, a.onDidDisappear), C(y()._context, a.onDidAppear, !1), $(o == null ? void 0 : o.appContext, y()._context));
}
}, f), {
default: () => [w.value ? e : null]
});
}
});
k == null || k(u), u.mount(r), t === !1 && window.history.pushState(B({
index: i.length,
session: Y
}), ""), i.push(u);
}), Be = (e, t) => {
const n = y(), s = n == null ? void 0 : n._context, r = xe(s, q()), c = () => me(s) === r, l = ne(s);
if (l === void 0) return Promise.resolve();
const { index: _, session: v } = H(), h = _ - e + 1;
for (let f = 0; f < e; f++)
window.history.pushState(B({ index: h + f, session: v }), "");
return new Promise(async () => {
const f = () => {
ee(t), N(s, void 0), window.history.go(-e);
}, u = l();
typeof u == "boolean" ? u && c() && f() : await u === !0 && c() && f();
});
};
let R = !1;
const Ae = () => {
R = !0;
}, re = (e, t = !1) => {
_e(), i.push(e);
const n = B({ index: 0, session: Y });
t ? window.history.replaceState(n, "") : window.history.pushState(n, "");
const s = async (r) => {
const c = H();
if (!c || r.state.session !== c.session) return;
const l = r.state.index - c.index;
if (l === 0) return;
if (l > 0) return window.history.go(-l);
const _ = ve();
if (R) {
R = !1;
const v = Math.abs(l), h = i.length - v - 1;
i.splice(h, v).forEach((u, w, g) => {
G(!1, w === g.length - 1, u, _);
});
} else
await Be(-l, _), i.splice(i.length - Math.abs(l)).forEach((h, f, u) => {
const w = f === u.length - 1;
G(w, w, h, _);
});
i.length === 0 ? B() : B(window.history.state);
};
return {
add: () => window.addEventListener("popstate", s),
remove: () => window.removeEventListener("popstate", s)
};
}, Pe = async (e, t) => {
A();
const n = await se(e, !1, t);
return P(), n;
}, Le = async (e, t) => {
A();
const n = await se(e, !0, t);
return P(), n;
}, O = (e = 1) => (A(), new Promise((t) => {
he(q(), t);
const n = typeof e == "number" ? e : 1;
window.history.go(-Math.abs(n));
})), be = () => O(1), je = (e) => e ? Le : Pe, Je = async (e) => {
Ae(), await O(e);
}, Ke = async () => {
await O(i.length - 1);
}, Xe = fe({
name: "NavigatorController",
setup: (e, { slots: t }) => {
const { add: n } = re(p().appContext.app, !0);
return T(n), T(ae), () => {
var s;
return (s = t.default) == null ? void 0 : s.call(t);
};
}
}), Ye = {
install(e) {
const { add: t } = re(e, !0);
t(), ae();
}
};
export {
Xe as Navigator,
be as back,
Ke as backToHome,
Je as blackBoxBack,
A as disableBodyPointerEvents,
P as enableBodyPointerEvents,
Ve as getCurrentPageMate,
O as goBack,
Ye as navigation,
We as onDidAppear,
Te as onDidDisappear,
Fe as onPageAfterEnter,
Qe as onPageAfterLeave,
Oe as onPageBeforeEnter,
Ue as onPageBeforeLeave,
Ne as onPageChange,
Ie as onWillAppear,
Me as onWillDisappear,
Pe as push,
Le as replace,
je as to,
$e as useAppBeforeMount,
ke as useLeaveBefore,
ze as usePageMate,
qe as useProgressExitAnimated,
Se as useQuietPage,
Ge as useTransitionEnter,
Re as useTransitionLeave
};