UNPKG

@artmate/chat

Version:

**开箱即用的AI组件库(基于 Vue3 + ElementPlus)**

207 lines (206 loc) 6.07 kB
import { tryOnMounted as I, noop as x, isIOS as T, isClient as W, tryOnScopeDispose as k, toArray as O, watchImmediate as L, isObject as $ } from "./node_modules/@vueuse/shared/index.js"; import { getLifeCycleTarget as K } from "./node_modules/@vueuse/shared/index.js"; import { computed as R, shallowRef as C, watch as B, toValue as w, getCurrentInstance as z, onMounted as F, unref as H } from "vue"; const M = W ? window : void 0; function b(t) { var r; const a = w(t); return (r = a == null ? void 0 : a.$el) != null ? r : a; } function y(...t) { const r = [], a = () => { r.forEach((o) => o()), r.length = 0; }, c = (o, s, i, d) => (o.addEventListener(s, i, d), () => o.removeEventListener(s, i, d)), p = R(() => { const o = O(w(t[0])).filter((s) => s != null); return o.every((s) => typeof s != "string") ? o : void 0; }), m = L( () => { var o, s; return [ (s = (o = p.value) == null ? void 0 : o.map((i) => b(i))) != null ? s : [M].filter((i) => i != null), O(w(p.value ? t[1] : t[0])), O(H(p.value ? t[2] : t[1])), // @ts-expect-error - TypeScript gets the correct types, but somehow still complains w(p.value ? t[3] : t[2]) ]; }, ([o, s, i, d]) => { if (a(), !(o != null && o.length) || !(s != null && s.length) || !(i != null && i.length)) return; const n = $(d) ? { ...d } : d; r.push( ...o.flatMap( (l) => s.flatMap( (v) => i.map((g) => c(l, v, g, n)) ) ) ); }, { flush: "post" } ), f = () => { m(), a(); }; return k(a), f; } let S = !1; function N(t, r, a = {}) { const { window: c = M, ignore: p = [], capture: m = !0, detectIframe: f = !1, controls: o = !1 } = a; if (!c) return o ? { stop: x, cancel: x, trigger: x } : x; if (T && !S) { S = !0; const e = { passive: !0 }; Array.from(c.document.body.children).forEach((u) => y(u, "click", x, e)), y(c.document.documentElement, "click", x, e); } let s = !0; const i = (e) => w(p).some((u) => { if (typeof u == "string") return Array.from(c.document.querySelectorAll(u)).some((h) => h === e.target || e.composedPath().includes(h)); { const h = b(u); return h && (e.target === h || e.composedPath().includes(h)); } }); function d(e) { const u = w(e); return u && u.$.subTree.shapeFlag === 16; } function n(e, u) { const h = w(e), A = h.$.subTree && h.$.subTree.children; return A == null || !Array.isArray(A) ? !1 : A.some((P) => P.el === u.target || u.composedPath().includes(P.el)); } const l = (e) => { const u = b(t); if (e.target != null && !(!(u instanceof Element) && d(t) && n(t, e)) && !(!u || u === e.target || e.composedPath().includes(u))) { if ("detail" in e && e.detail === 0 && (s = !i(e)), !s) { s = !0; return; } r(e); } }; let v = !1; const g = [ y(c, "click", (e) => { v || (v = !0, setTimeout(() => { v = !1; }, 0), l(e)); }, { passive: !0, capture: m }), y(c, "pointerdown", (e) => { const u = b(t); s = !i(e) && !!(u && !e.composedPath().includes(u)); }, { passive: !0 }), f && y(c, "blur", (e) => { setTimeout(() => { var u; const h = b(t); ((u = c.document.activeElement) == null ? void 0 : u.tagName) === "IFRAME" && !(h != null && h.contains(c.document.activeElement)) && r(e); }, 0); }, { passive: !0 }) ].filter(Boolean), E = () => g.forEach((e) => e()); return o ? { stop: E, cancel: () => { s = !1; }, trigger: (e) => { s = !0, l(e), s = !1; } } : E; } function V() { const t = C(!1), r = z(); return r && F(() => { t.value = !0; }, r), t; } function j(t) { const r = V(); return R(() => (r.value, !!t())); } function q(t, r, a = {}) { const { window: c = M, ...p } = a; let m; const f = j(() => c && "ResizeObserver" in c), o = () => { m && (m.disconnect(), m = void 0); }, s = R(() => { const n = w(t); return Array.isArray(n) ? n.map((l) => b(l)) : [b(n)]; }), i = B( s, (n) => { if (o(), f.value && c) { m = new ResizeObserver(r); for (const l of n) l && m.observe(l, p); } }, { immediate: !0, flush: "post" } ), d = () => { o(), i(); }; return k(d), { isSupported: f, stop: d }; } function U(t, r = { width: 0, height: 0 }, a = {}) { const { window: c = M, box: p = "content-box" } = a, m = R(() => { var n, l; return (l = (n = b(t)) == null ? void 0 : n.namespaceURI) == null ? void 0 : l.includes("svg"); }), f = C(r.width), o = C(r.height), { stop: s } = q( t, ([n]) => { const l = p === "border-box" ? n.borderBoxSize : p === "content-box" ? n.contentBoxSize : n.devicePixelContentBoxSize; if (c && m.value) { const v = b(t); if (v) { const g = v.getBoundingClientRect(); f.value = g.width, o.value = g.height; } } else if (l) { const v = O(l); f.value = v.reduce((g, { inlineSize: E }) => g + E, 0), o.value = v.reduce((g, { blockSize: E }) => g + E, 0); } else f.value = n.contentRect.width, o.value = n.contentRect.height; }, a ); I(() => { const n = b(t); n && (f.value = "offsetWidth" in n ? n.offsetWidth : r.width, o.value = "offsetHeight" in n ? n.offsetHeight : r.height); }); const i = B( () => b(t), (n) => { f.value = n ? r.width : 0, o.value = n ? r.height : 0; } ); function d() { s(), i(); } return { width: f, height: o, stop: d }; } export { M as defaultWindow, K as getLifeCycleTarget, W as isClient, T as isIOS, $ as isObject, x as noop, N as onClickOutside, O as toArray, I as tryOnMounted, k as tryOnScopeDispose, b as unrefElement, U as useElementSize, y as useEventListener, V as useMounted, q as useResizeObserver, j as useSupported, L as watchImmediate };