import { defineComponent, createVNode, mergeProps, nextTick, inject, computed, provide, watchEffect, ref, Transition, Teleport, watch, Fragment, withDirectives, vShow, getCurrentInstance, onActivated } from 'vue'; import { e as extend, c as createNamespace, w as withInstall, p as pick, t as truthProp, u as unknownProp, n as numericProp, m as makeStringProp, a as makeArrayProp, b as addUnit, s as stdin_default$5, i as isDef, d as isNumeric, k as kebabCase, g as getZIndexStyle, f as isPromise, h as noop } from './index-Cr7WIrmx.mjs'; function onMountedOrActivated(hook) { onActivated(() => { }); } var width; var height; function useWindowSize() { if (!width) { width = ref(0); height = ref(0); } return { width, height }; } var overflowScrollReg = /scroll|auto|overlay/i; var defaultRoot = void 0; function isElement(node) { const ELEMENT_NODE_TYPE = 1; return node.tagName !== "HTML" && node.tagName !== "BODY" && node.nodeType === ELEMENT_NODE_TYPE; } function getScrollParent(el, root = defaultRoot) { let node = el; while (node && node !== root && isElement(node)) { const { overflowY } = (void 0).getComputedStyle(node); if (overflowScrollReg.test(overflowY)) { return node; } node = node.parentNode; } return root; } const stopPropagation = (event) => event.stopPropagation(); function preventDefault(event, isStopPropagation) { if (typeof event.cancelable !== "boolean" || event.cancelable) { event.preventDefault(); } { stopPropagation(event); } } useWindowSize(); const HAPTICS_FEEDBACK = "van-haptics-feedback"; const TAP_OFFSET = 5; function callInterceptor(interceptor, { args = [], done, canceled, error }) { if (interceptor) { const returnVal = interceptor.apply(null, args); if (isPromise(returnVal)) { returnVal.then((value) => { if (value) { done(); } else if (canceled) { canceled(); } }).catch(error || noop); } else if (returnVal) { done(); } else if (canceled) { canceled(); } } else { done(); } } const [name$5, bem$5] = createNamespace("badge"); const badgeProps = { dot: Boolean, max: numericProp, tag: makeStringProp("div"), color: String, offset: Array, content: numericProp, showZero: truthProp, position: makeStringProp("top-right") }; var stdin_default$4 = defineComponent({ name: name$5, props: badgeProps, setup(props, { slots }) { const hasContent = () => { if (slots.content) { return true; } const { content, showZero } = props; return isDef(content) && content !== "" && (showZero || content !== 0 && content !== "0"); }; const renderContent = () => { const { dot, max, content } = props; if (!dot && hasContent()) { if (slots.content) { return slots.content(); } if (isDef(max) && isNumeric(content) && +content > +max) { return `${max}+`; } return content; } }; const getOffsetWithMinusString = (val) => val.startsWith("-") ? val.replace("-", "") : `-${val}`; const style = computed(() => { const style2 = { background: props.color }; if (props.offset) { const [x, y] = props.offset; const { position } = props; const [offsetY, offsetX] = position.split("-"); if (slots.default) { if (typeof y === "number") { style2[offsetY] = addUnit(offsetY === "top" ? y : -y); } else { style2[offsetY] = offsetY === "top" ? addUnit(y) : getOffsetWithMinusString(y); } if (typeof x === "number") { style2[offsetX] = addUnit(offsetX === "left" ? x : -x); } else { style2[offsetX] = offsetX === "left" ? addUnit(x) : getOffsetWithMinusString(x); } } else { style2.marginTop = addUnit(y); style2.marginLeft = addUnit(x); } } return style2; }); const renderBadge = () => { if (hasContent() || props.dot) { return createVNode("div", { "class": bem$5([props.position, { dot: props.dot, fixed: !!slots.default }]), "style": style.value }, [renderContent()]); } }; return () => { if (slots.default) { const { tag } = props; return createVNode(tag, { "class": bem$5("wrapper") }, { default: () => [slots.default(), renderBadge()] }); } return renderBadge(); }; } }); const Badge = withInstall(stdin_default$4); let globalZIndex = 2e3; const useGlobalZIndex = () => ++globalZIndex; const setGlobalZIndex = (val) => { globalZIndex = val; }; const [name$4, bem$4] = createNamespace("config-provider"); const CONFIG_PROVIDER_KEY = Symbol(name$4); const configProviderProps = { tag: makeStringProp("div"), theme: makeStringProp("light"), zIndex: Number, themeVars: Object, themeVarsDark: Object, themeVarsLight: Object, themeVarsScope: makeStringProp("local"), iconPrefix: String }; function insertDash(str) { return str.replace(/([a-zA-Z])(\d)/g, "$1-$2"); } function mapThemeVarsToCSSVars(themeVars) { const cssVars = {}; Object.keys(themeVars).forEach((key) => { const formattedKey = insertDash(kebabCase(key)); cssVars[`--van-${formattedKey}`] = themeVars[key]; }); return cssVars; } defineComponent({ name: name$4, props: configProviderProps, setup(props, { slots }) { const style = computed(() => mapThemeVarsToCSSVars(extend({}, props.themeVars, props.theme === "dark" ? props.themeVarsDark : props.themeVarsLight))); provide(CONFIG_PROVIDER_KEY, props); watchEffect(() => { if (props.zIndex !== void 0) { setGlobalZIndex(props.zIndex); } }); return () => createVNode(props.tag, { "class": bem$4(), "style": props.themeVarsScope === "local" ? style.value : void 0 }, { default: () => { var _a; return [(_a = slots.default) == null ? void 0 : _a.call(slots)]; } }); } }); const [name$3, bem$3] = createNamespace("icon"); const isImage = (name2) => name2 == null ? void 0 : name2.includes("/"); const iconProps = { dot: Boolean, tag: makeStringProp("i"), name: String, size: numericProp, badge: numericProp, color: String, badgeProps: Object, classPrefix: String }; var stdin_default$3 = defineComponent({ name: name$3, props: iconProps, setup(props, { slots }) { const config = inject(CONFIG_PROVIDER_KEY, null); const classPrefix = computed(() => props.classPrefix || (config == null ? void 0 : config.iconPrefix) || bem$3()); return () => { const { tag, dot, name: name2, size, badge, color } = props; const isImageIcon = isImage(name2); return createVNode(Badge, mergeProps({ "dot": dot, "tag": tag, "class": [classPrefix.value, isImageIcon ? "" : `${classPrefix.value}-${name2}`], "style": { color, fontSize: addUnit(size) }, "content": badge }, props.badgeProps), { default: () => { var _a; return [(_a = slots.default) == null ? void 0 : _a.call(slots), isImageIcon && createVNode("img", { "class": bem$3("image"), "src": name2 }, null)]; } }); }; } }); const Icon = withInstall(stdin_default$3); const popupSharedProps = { // whether to show popup show: Boolean, // z-index zIndex: numericProp, // whether to show overlay overlay: truthProp, // transition duration duration: numericProp, // teleport teleport: [String, Object], // prevent body scroll lockScroll: truthProp, // whether to lazy render lazyRender: truthProp, // callback function before close beforeClose: Function, // overlay props overlayProps: Object, // overlay custom style overlayStyle: Object, // overlay custom class name overlayClass: unknownProp, // Initial rendering animation transitionAppear: Boolean, // whether to close popup when overlay is clicked closeOnClickOverlay: truthProp }; const popupSharedPropKeys = Object.keys( popupSharedProps ); function useExpose(apis) { const instance = getCurrentInstance(); if (instance) { extend(instance.proxy, apis); } } function getDirection(x, y) { if (x > y) { return "horizontal"; } if (y > x) { return "vertical"; } return ""; } function useTouch() { const startX = ref(0); const startY = ref(0); const deltaX = ref(0); const deltaY = ref(0); const offsetX = ref(0); const offsetY = ref(0); const direction = ref(""); const isTap = ref(true); const isVertical = () => direction.value === "vertical"; const isHorizontal = () => direction.value === "horizontal"; const reset = () => { deltaX.value = 0; deltaY.value = 0; offsetX.value = 0; offsetY.value = 0; direction.value = ""; isTap.value = true; }; const start = (event) => { reset(); startX.value = event.touches[0].clientX; startY.value = event.touches[0].clientY; }; const move = (event) => { const touch = event.touches[0]; deltaX.value = (touch.clientX < 0 ? 0 : touch.clientX) - startX.value; deltaY.value = touch.clientY - startY.value; offsetX.value = Math.abs(deltaX.value); offsetY.value = Math.abs(deltaY.value); const LOCK_DIRECTION_DISTANCE = 10; if (!direction.value || offsetX.value < LOCK_DIRECTION_DISTANCE && offsetY.value < LOCK_DIRECTION_DISTANCE) { direction.value = getDirection(offsetX.value, offsetY.value); } if (isTap.value && (offsetX.value > TAP_OFFSET || offsetY.value > TAP_OFFSET)) { isTap.value = false; } }; return { move, start, reset, startX, startY, deltaX, deltaY, offsetX, offsetY, direction, isVertical, isHorizontal, isTap }; } let totalLockCount = 0; const BODY_LOCK_CLASS = "van-overflow-hidden"; function useLockScroll(rootRef, shouldLock) { const touch = useTouch(); const DIRECTION_UP = "01"; const DIRECTION_DOWN = "10"; const onTouchMove = (event) => { touch.move(event); const direction = touch.deltaY.value > 0 ? DIRECTION_DOWN : DIRECTION_UP; const el = getScrollParent( event.target, rootRef.value ); const { scrollHeight, offsetHeight, scrollTop } = el; let status = "11"; if (scrollTop === 0) { status = offsetHeight >= scrollHeight ? "00" : "01"; } else if (scrollTop + offsetHeight >= scrollHeight) { status = "10"; } if (status !== "11" && touch.isVertical() && !(parseInt(status, 2) & parseInt(direction, 2))) { preventDefault(event); } }; const lock = () => { (void 0).addEventListener("touchstart", touch.start); (void 0).addEventListener("touchmove", onTouchMove, { passive: false }); if (!totalLockCount) { (void 0).body.classList.add(BODY_LOCK_CLASS); } totalLockCount++; }; const unlock = () => { if (totalLockCount) { (void 0).removeEventListener("touchstart", touch.start); (void 0).removeEventListener("touchmove", onTouchMove); totalLockCount--; if (!totalLockCount) { (void 0).body.classList.remove(BODY_LOCK_CLASS); } } }; onMountedOrActivated(); watch(shouldLock, (value) => { value ? lock() : unlock(); }); } function useLazyRender(show) { const inited = ref(false); watch( show, (value) => { if (value) { inited.value = value; } }, { immediate: true } ); return (render) => () => inited.value ? render() : null; } const POPUP_TOGGLE_KEY = Symbol(); const useScopeId = () => { var _a; const { scopeId } = ((_a = getCurrentInstance()) == null ? void 0 : _a.vnode) || {}; return scopeId ? { [scopeId]: "" } : null; }; const [name$2, bem$2] = createNamespace("overlay"); const overlayProps = { show: Boolean, zIndex: numericProp, duration: numericProp, className: unknownProp, lockScroll: truthProp, lazyRender: truthProp, customStyle: Object, teleport: [String, Object] }; var stdin_default$2 = defineComponent({ name: name$2, inheritAttrs: false, props: overlayProps, setup(props, { attrs, slots }) { const root = ref(); const lazyRender = useLazyRender(() => props.show || !props.lazyRender); const renderOverlay = lazyRender(() => { var _a; const style = extend(getZIndexStyle(props.zIndex), props.customStyle); if (isDef(props.duration)) { style.animationDuration = `${props.duration}s`; } return withDirectives(createVNode("div", mergeProps({ "ref": root, "style": style, "class": [bem$2(), props.className] }, attrs), [(_a = slots.default) == null ? void 0 : _a.call(slots)]), [[vShow, props.show]]); }); return () => { const Content = createVNode(Transition, { "name": "van-fade", "appear": true }, { default: renderOverlay }); if (props.teleport) { return createVNode(Teleport, { "to": props.teleport }, { default: () => [Content] }); } return Content; }; } }); const Overlay = withInstall(stdin_default$2); const popupProps = extend({}, popupSharedProps, { round: Boolean, position: makeStringProp("center"), closeIcon: makeStringProp("cross"), closeable: Boolean, transition: String, iconPrefix: String, closeOnPopstate: Boolean, closeIconPosition: makeStringProp("top-right"), destroyOnClose: Boolean, safeAreaInsetTop: Boolean, safeAreaInsetBottom: Boolean }); const [name$1, bem$1] = createNamespace("popup"); var stdin_default$1 = defineComponent({ name: name$1, inheritAttrs: false, props: popupProps, emits: ["open", "close", "opened", "closed", "keydown", "update:show", "clickOverlay", "clickCloseIcon"], setup(props, { emit, attrs, slots }) { let opened; const zIndex = ref(); const popupRef = ref(); const lazyRender = useLazyRender(() => props.show || !props.lazyRender); const style = computed(() => { const style2 = { zIndex: zIndex.value }; if (isDef(props.duration)) { const key = props.position === "center" ? "animationDuration" : "transitionDuration"; style2[key] = `${props.duration}s`; } return style2; }); const open = () => { if (!opened) { opened = true; zIndex.value = props.zIndex !== void 0 ? +props.zIndex : useGlobalZIndex(); emit("open"); } }; const close = () => { if (opened) { callInterceptor(props.beforeClose, { done() { opened = false; emit("close"); emit("update:show", false); } }); } }; const onClickOverlay = (event) => { emit("clickOverlay", event); if (props.closeOnClickOverlay) { close(); } }; const renderOverlay = () => { if (props.overlay) { const overlayProps2 = extend({ show: props.show, class: props.overlayClass, zIndex: zIndex.value, duration: props.duration, customStyle: props.overlayStyle, role: props.closeOnClickOverlay ? "button" : void 0, tabindex: props.closeOnClickOverlay ? 0 : void 0 }, props.overlayProps); return createVNode(Overlay, mergeProps(overlayProps2, useScopeId(), { "onClick": onClickOverlay }), { default: slots["overlay-content"] }); } }; const onClickCloseIcon = (event) => { emit("clickCloseIcon", event); close(); }; const renderCloseIcon = () => { if (props.closeable) { return createVNode(Icon, { "role": "button", "tabindex": 0, "name": props.closeIcon, "class": [bem$1("close-icon", props.closeIconPosition), HAPTICS_FEEDBACK], "classPrefix": props.iconPrefix, "onClick": onClickCloseIcon }, null); } }; let timer; const onOpened = () => { if (timer) clearTimeout(timer); timer = setTimeout(() => { emit("opened"); }); }; const onClosed = () => emit("closed"); const onKeydown = (event) => emit("keydown", event); const renderPopup = lazyRender(() => { var _a; const { destroyOnClose, round, position, safeAreaInsetTop, safeAreaInsetBottom, show } = props; if (!show && destroyOnClose) { return; } return withDirectives(createVNode("div", mergeProps({ "ref": popupRef, "style": style.value, "role": "dialog", "tabindex": 0, "class": [bem$1({ round, [position]: position }), { "van-safe-area-top": safeAreaInsetTop, "van-safe-area-bottom": safeAreaInsetBottom }], "onKeydown": onKeydown }, attrs, useScopeId()), [(_a = slots.default) == null ? void 0 : _a.call(slots), renderCloseIcon()]), [[vShow, show]]); }); const renderTransition = () => { const { position, transition, transitionAppear } = props; const name2 = position === "center" ? "van-fade" : `van-popup-slide-${position}`; return createVNode(Transition, { "name": transition || name2, "appear": transitionAppear, "onAfterEnter": onOpened, "onAfterLeave": onClosed }, { default: renderPopup }); }; watch(() => props.show, (show) => { if (show && !opened) { open(); if (attrs.tabindex === 0) { nextTick(() => { var _a; (_a = popupRef.value) == null ? void 0 : _a.focus(); }); } } if (!show && opened) { opened = false; emit("close"); } }); useExpose({ popupRef }); useLockScroll(popupRef, () => props.show && props.lockScroll); provide(POPUP_TOGGLE_KEY, () => props.show); return () => { if (props.teleport) { return createVNode(Teleport, { "to": props.teleport }, { default: () => [renderOverlay(), renderTransition()] }); } return createVNode(Fragment, null, [renderOverlay(), renderTransition()]); }; } }); const Popup = withInstall(stdin_default$1); const Loading = withInstall(stdin_default$5); const [name, bem] = createNamespace("action-sheet"); const actionSheetProps = extend({}, popupSharedProps, { title: String, round: truthProp, actions: makeArrayProp(), closeIcon: makeStringProp("cross"), closeable: truthProp, cancelText: String, description: String, closeOnPopstate: truthProp, closeOnClickAction: Boolean, safeAreaInsetBottom: truthProp }); const popupInheritKeys = [...popupSharedPropKeys, "round", "closeOnPopstate", "safeAreaInsetBottom"]; var stdin_default = defineComponent({ name, props: actionSheetProps, emits: ["select", "cancel", "update:show"], setup(props, { slots, emit }) { const updateShow = (show) => emit("update:show", show); const onCancel = () => { updateShow(false); emit("cancel"); }; const renderHeader = () => { if (props.title) { return createVNode("div", { "class": bem("header") }, [props.title, props.closeable && createVNode(Icon, { "name": props.closeIcon, "class": [bem("close"), HAPTICS_FEEDBACK], "onClick": onCancel }, null)]); } }; const renderCancel = () => { if (slots.cancel || props.cancelText) { return [createVNode("div", { "class": bem("gap") }, null), createVNode("button", { "type": "button", "class": bem("cancel"), "onClick": onCancel }, [slots.cancel ? slots.cancel() : props.cancelText])]; } }; const renderIcon = (action) => { if (action.icon) { return createVNode(Icon, { "class": bem("item-icon"), "name": action.icon }, null); } }; const renderActionContent = (action, index) => { if (action.loading) { return createVNode(Loading, { "class": bem("loading-icon") }, null); } if (slots.action) { return slots.action({ action, index }); } return [createVNode("span", { "class": bem("name") }, [action.name]), action.subname && createVNode("div", { "class": bem("subname") }, [action.subname])]; }; const renderAction = (action, index) => { const { color, loading, callback, disabled, className } = action; const onClick = () => { if (disabled || loading) { return; } if (callback) { callback(action); } if (props.closeOnClickAction) { updateShow(false); } nextTick(() => emit("select", action, index)); }; return createVNode("button", { "type": "button", "style": { color }, "class": [bem("item", { loading, disabled }), className], "onClick": onClick }, [renderIcon(action), renderActionContent(action, index)]); }; const renderDescription = () => { if (props.description || slots.description) { const content = slots.description ? slots.description() : props.description; return createVNode("div", { "class": bem("description") }, [content]); } }; return () => createVNode(Popup, mergeProps({ "class": bem(), "position": "bottom", "onUpdate:show": updateShow }, pick(props, popupInheritKeys)), { default: () => { var _a; return [renderHeader(), renderDescription(), createVNode("div", { "class": bem("content") }, [props.actions.map(renderAction), (_a = slots.default) == null ? void 0 : _a.call(slots)]), renderCancel()]; } }); } }); export { stdin_default as s }; //# sourceMappingURL=index-BVAEX5Zf.mjs.map