vant
Version:
Mobile UI Components built on Vue
1,615 lines • 625 kB
JavaScript
(function(global, factory) {
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("vue")) : typeof define === "function" && define.amd ? define(["exports", "vue"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.vant = {}, global.Vue));
})(this, function(exports2, __WEBPACK_EXTERNAL_MODULE_vue__) {
"use strict";
function _interopNamespaceDefault(e) {
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
if (e) {
for (const k in e) {
if (k !== "default") {
const d = Object.getOwnPropertyDescriptor(e, k);
Object.defineProperty(n, k, d.get ? d : {
enumerable: true,
get: () => e[k]
});
}
}
}
n.default = e;
return Object.freeze(n);
}
const __WEBPACK_EXTERNAL_MODULE_vue____namespace = /* @__PURE__ */ _interopNamespaceDefault(__WEBPACK_EXTERNAL_MODULE_vue__);
function noop() {
}
const extend = Object.assign;
const inBrowser$1 = typeof window !== "undefined";
const isObject$1 = (val) => val !== null && typeof val === "object";
const isDef = (val) => val !== void 0 && val !== null;
const isFunction = (val) => typeof val === "function";
const isPromise = (val) => isObject$1(val) && isFunction(val.then) && isFunction(val.catch);
const isDate = (val) => Object.prototype.toString.call(val) === "[object Date]" && !Number.isNaN(val.getTime());
function isMobile(value) {
value = value.replace(/[^-|\d]/g, "");
return /^((\+86)|(86))?(1)\d{10}$/.test(value) || /^0[0-9-]{10,13}$/.test(value);
}
const isNumeric = (val) => typeof val === "number" || /^\d+(\.\d+)?$/.test(val);
const isIOS$1 = () => inBrowser$1 ? /ios|iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()) : false;
function get(object, path) {
const keys = path.split(".");
let result = object;
keys.forEach((key) => {
var _a;
result = isObject$1(result) ? (_a = result[key]) != null ? _a : "" : "";
});
return result;
}
function pick(obj, keys, ignoreUndefined) {
return keys.reduce(
(ret, key) => {
if (!ignoreUndefined || obj[key] !== void 0) {
ret[key] = obj[key];
}
return ret;
},
{}
);
}
const isSameValue = (newValue, oldValue) => JSON.stringify(newValue) === JSON.stringify(oldValue);
const toArray = (item) => Array.isArray(item) ? item : [item];
const flat = (arr) => arr.reduce((acc, val) => acc.concat(val), []);
const unknownProp = null;
const numericProp = [Number, String];
const truthProp = {
type: Boolean,
default: true
};
const makeRequiredProp = (type) => ({
type,
required: true
});
const makeArrayProp = () => ({
type: Array,
default: () => []
});
const makeNumberProp = (defaultVal) => ({
type: Number,
default: defaultVal
});
const makeNumericProp = (defaultVal) => ({
type: numericProp,
default: defaultVal
});
const makeStringProp = (defaultVal) => ({
type: String,
default: defaultVal
});
const inBrowser = "undefined" != typeof window;
function raf(fn) {
return inBrowser ? requestAnimationFrame(fn) : -1;
}
function cancelRaf(id) {
if (inBrowser) cancelAnimationFrame(id);
}
function doubleRaf(fn) {
raf(() => raf(fn));
}
const isWindow = (val) => val === window;
const makeDOMRect = (width, height) => ({
top: 0,
left: 0,
right: width,
bottom: height,
width,
height
});
const useRect = (elementOrRef) => {
const element = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.unref)(elementOrRef);
if (isWindow(element)) {
const width = element.innerWidth;
const height = element.innerHeight;
return makeDOMRect(width, height);
}
if (null == element ? void 0 : element.getBoundingClientRect) return element.getBoundingClientRect();
return makeDOMRect(0, 0);
};
function useToggle(defaultValue = false) {
const state = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.ref)(defaultValue);
const toggle = (value = !state.value) => {
state.value = value;
};
return [
state,
toggle
];
}
function useParent(key) {
const parent = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.inject)(key, null);
if (parent) {
const instance2 = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.getCurrentInstance)();
const { link, unlink, internalChildren } = parent;
link(instance2);
(0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.onUnmounted)(() => unlink(instance2));
const index = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.computed)(() => internalChildren.indexOf(instance2));
return {
parent,
index
};
}
return {
parent: null,
index: (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.ref)(-1)
};
}
function flattenVNodes(children) {
const result = [];
const traverse = (children2) => {
if (Array.isArray(children2)) children2.forEach((child) => {
if ((0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.isVNode)(child)) {
var _child_component;
result.push(child);
if (null == (_child_component = child.component) ? void 0 : _child_component.subTree) {
result.push(child.component.subTree);
traverse(child.component.subTree.children);
}
if (child.children) traverse(child.children);
}
});
};
traverse(children);
return result;
}
const findVNodeIndex = (vnodes, vnode) => {
const index = vnodes.indexOf(vnode);
if (-1 === index) return vnodes.findIndex((item) => void 0 !== vnode.key && null !== vnode.key && item.type === vnode.type && item.key === vnode.key);
return index;
};
function sortChildren(parent, publicChildren, internalChildren) {
const vnodes = flattenVNodes(parent.subTree.children);
internalChildren.sort((a, b) => findVNodeIndex(vnodes, a.vnode) - findVNodeIndex(vnodes, b.vnode));
const orderedPublicChildren = internalChildren.map((item) => item.proxy);
publicChildren.sort((a, b) => {
const indexA = orderedPublicChildren.indexOf(a);
const indexB = orderedPublicChildren.indexOf(b);
return indexA - indexB;
});
}
function useChildren(key) {
const publicChildren = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.reactive)([]);
const internalChildren = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.reactive)([]);
const parent = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.getCurrentInstance)();
const linkChildren = (value) => {
const link = (child) => {
if (child.proxy) {
internalChildren.push(child);
publicChildren.push(child.proxy);
sortChildren(parent, publicChildren, internalChildren);
}
};
const unlink = (child) => {
const index = internalChildren.indexOf(child);
publicChildren.splice(index, 1);
internalChildren.splice(index, 1);
};
(0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.provide)(key, Object.assign({
link,
unlink,
children: publicChildren,
internalChildren
}, value));
};
return {
children: publicChildren,
linkChildren
};
}
const SECOND = 1e3;
const MINUTE = 60 * SECOND;
const HOUR = 60 * MINUTE;
const DAY = 24 * HOUR;
function parseTime(time) {
const days = Math.floor(time / DAY);
const hours = Math.floor(time % DAY / HOUR);
const minutes = Math.floor(time % HOUR / MINUTE);
const seconds = Math.floor(time % MINUTE / SECOND);
const milliseconds = Math.floor(time % SECOND);
return {
total: time,
days,
hours,
minutes,
seconds,
milliseconds
};
}
function isSameSecond(time1, time2) {
return Math.floor(time1 / 1e3) === Math.floor(time2 / 1e3);
}
function useCountDown(options) {
let rafId;
let endTime;
let counting;
let deactivated;
const remain = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.ref)(options.time);
const current2 = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.computed)(() => parseTime(remain.value));
const pause = () => {
counting = false;
cancelRaf(rafId);
};
const getCurrentRemain = () => Math.max(endTime - Date.now(), 0);
const setRemain = (value) => {
var _options_onChange;
remain.value = value;
null == (_options_onChange = options.onChange) || _options_onChange.call(options, current2.value);
if (0 === value) {
var _options_onFinish;
pause();
null == (_options_onFinish = options.onFinish) || _options_onFinish.call(options);
}
};
const microTick = () => {
rafId = raf(() => {
if (counting) {
setRemain(getCurrentRemain());
if (remain.value > 0) microTick();
}
});
};
const macroTick = () => {
rafId = raf(() => {
if (counting) {
const remainRemain = getCurrentRemain();
if (!isSameSecond(remainRemain, remain.value) || 0 === remainRemain) setRemain(remainRemain);
if (remain.value > 0) macroTick();
}
});
};
const tick = () => {
if (!inBrowser) return;
if (options.millisecond) microTick();
else macroTick();
};
const start2 = () => {
if (!counting) {
endTime = Date.now() + remain.value;
counting = true;
tick();
}
};
const reset = (totalTime = options.time) => {
pause();
remain.value = totalTime;
};
(0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.onBeforeUnmount)(pause);
(0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.onActivated)(() => {
if (deactivated) {
counting = true;
deactivated = false;
tick();
}
});
(0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.onDeactivated)(() => {
if (counting) {
pause();
deactivated = true;
}
});
return {
start: start2,
pause,
reset,
current: current2
};
}
function onMountedOrActivated(hook) {
let mounted;
(0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.onMounted)(() => {
hook();
(0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.nextTick)(() => {
mounted = true;
});
});
(0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.onActivated)(() => {
if (mounted) hook();
});
}
function useEventListener(type, listener, options = {}) {
if (!inBrowser) return;
const { target = window, passive: passive2 = false, capture = false } = options;
let cleaned = false;
let attached;
const add = (target2) => {
if (cleaned) return;
const element = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.unref)(target2);
if (element && !attached) {
element.addEventListener(type, listener, {
capture,
passive: passive2
});
attached = true;
}
};
const remove2 = (target2) => {
if (cleaned) return;
const element = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.unref)(target2);
if (element && attached) {
element.removeEventListener(type, listener, capture);
attached = false;
}
};
(0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.onUnmounted)(() => remove2(target));
(0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.onDeactivated)(() => remove2(target));
onMountedOrActivated(() => add(target));
let stopWatch;
if ((0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.isRef)(target)) stopWatch = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.watch)(target, (val, oldVal) => {
remove2(oldVal);
add(val);
});
return () => {
null == stopWatch || stopWatch();
remove2(target);
cleaned = true;
};
}
function useClickAway(target, listener, options = {}) {
if (!inBrowser) return;
const { eventName = "click" } = options;
const onClick = (event) => {
const targets = Array.isArray(target) ? target : [
target
];
const isClickAway = targets.every((item) => {
const element = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.unref)(item);
return element && !element.contains(event.target);
});
if (isClickAway) listener(event);
};
useEventListener(eventName, onClick, {
target: document
});
}
let useWindowSize_width;
let useWindowSize_height;
function useWindowSize() {
if (!useWindowSize_width) {
useWindowSize_width = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.ref)(0);
useWindowSize_height = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.ref)(0);
if (inBrowser) {
const update = () => {
useWindowSize_width.value = window.innerWidth;
useWindowSize_height.value = window.innerHeight;
};
update();
window.addEventListener("resize", update, {
passive: true
});
window.addEventListener("orientationchange", update, {
passive: true
});
}
}
return {
width: useWindowSize_width,
height: useWindowSize_height
};
}
const overflowScrollReg = /scroll|auto|overlay/i;
const defaultRoot = inBrowser ? window : void 0;
function isElement$1(node) {
const ELEMENT_NODE_TYPE = 1;
return "HTML" !== node.tagName && "BODY" !== node.tagName && node.nodeType === ELEMENT_NODE_TYPE;
}
function getScrollParent$1(el, root = defaultRoot) {
let node = el;
while (node && node !== root && isElement$1(node)) {
const { overflowY } = window.getComputedStyle(node);
if (overflowScrollReg.test(overflowY)) return node;
node = node.parentNode;
}
return root;
}
function useScrollParent(el, root = defaultRoot) {
const scrollParent = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.ref)();
(0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.onMounted)(() => {
if (el.value) scrollParent.value = getScrollParent$1(el.value, root);
});
return scrollParent;
}
let visibility;
function usePageVisibility() {
if (!visibility) {
visibility = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.ref)("visible");
if (inBrowser) {
const update = () => {
visibility.value = document.hidden ? "hidden" : "visible";
};
update();
window.addEventListener("visibilitychange", update);
}
}
return visibility;
}
const CUSTOM_FIELD_INJECTION_KEY = Symbol("van-field");
function useCustomFieldValue(customValue) {
const field = (0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.inject)(CUSTOM_FIELD_INJECTION_KEY, null);
if (field && !field.customValue.value) {
field.customValue.value = customValue;
(0, __WEBPACK_EXTERNAL_MODULE_vue____namespace.watch)(customValue, () => {
field.resetValidation();
field.validateWithTrigger("onChange");
});
}
}
function getScrollTop(el) {
const top = "scrollTop" in el ? el.scrollTop : el.pageYOffset;
return Math.max(top, 0);
}
function setScrollTop(el, value) {
if ("scrollTop" in el) {
el.scrollTop = value;
} else {
el.scrollTo(el.scrollX, value);
}
}
function getRootScrollTop() {
return window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
}
function setRootScrollTop(value) {
setScrollTop(window, value);
setScrollTop(document.body, value);
}
function getElementTop(el, scroller) {
if (el === window) {
return 0;
}
const scrollTop = scroller ? getScrollTop(scroller) : getRootScrollTop();
return useRect(el).top + scrollTop;
}
const isIOS = isIOS$1();
function resetScroll() {
if (isIOS) {
setRootScrollTop(getRootScrollTop());
}
}
const stopPropagation = (event) => event.stopPropagation();
function preventDefault(event, isStopPropagation) {
if (typeof event.cancelable !== "boolean" || event.cancelable) {
event.preventDefault();
}
if (isStopPropagation) {
stopPropagation(event);
}
}
function isHidden(elementRef) {
const el = __WEBPACK_EXTERNAL_MODULE_vue__.unref(elementRef);
if (!el) {
return false;
}
const style = window.getComputedStyle(el);
const hidden = style.display === "none";
const parentHidden = el.offsetParent === null && style.position !== "fixed";
return hidden || parentHidden;
}
const { width: windowWidth, height: windowHeight } = useWindowSize();
function isContainingBlock(el) {
const css = window.getComputedStyle(el);
return css.transform !== "none" || css.perspective !== "none" || ["transform", "perspective", "filter"].some(
(value) => (css.willChange || "").includes(value)
);
}
function getContainingBlock$1(el) {
let node = el.parentElement;
while (node) {
if (node && node.tagName !== "HTML" && node.tagName !== "BODY" && isContainingBlock(node)) {
return node;
}
node = node.parentElement;
}
return null;
}
function addUnit(value) {
if (isDef(value)) {
return isNumeric(value) ? `${value}px` : String(value);
}
return void 0;
}
function getSizeStyle(originSize) {
if (isDef(originSize)) {
if (Array.isArray(originSize)) {
return {
width: addUnit(originSize[0]),
height: addUnit(originSize[1])
};
}
const size = addUnit(originSize);
return {
width: size,
height: size
};
}
}
function getZIndexStyle(zIndex) {
const style = {};
if (zIndex !== void 0) {
style.zIndex = +zIndex;
}
return style;
}
let rootFontSize;
function getRootFontSize() {
if (!rootFontSize) {
const doc = document.documentElement;
const fontSize = doc.style.fontSize || window.getComputedStyle(doc).fontSize;
rootFontSize = parseFloat(fontSize);
}
return rootFontSize;
}
function convertRem(value) {
value = value.replace(/rem/g, "");
return +value * getRootFontSize();
}
function convertVw(value) {
value = value.replace(/vw/g, "");
return +value * windowWidth.value / 100;
}
function convertVh(value) {
value = value.replace(/vh/g, "");
return +value * windowHeight.value / 100;
}
function unitToPx(value) {
if (typeof value === "number") {
return value;
}
if (inBrowser$1) {
if (value.includes("rem")) {
return convertRem(value);
}
if (value.includes("vw")) {
return convertVw(value);
}
if (value.includes("vh")) {
return convertVh(value);
}
}
return parseFloat(value);
}
const camelizeRE = /-(\w)/g;
const camelize = (str) => str.replace(camelizeRE, (_, c) => c.toUpperCase());
const kebabCase = (str) => str.replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "");
function padZero(num, targetLength = 2) {
let str = num + "";
while (str.length < targetLength) {
str = "0" + str;
}
return str;
}
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
function trimExtraChar(value, char, regExp) {
const index = value.indexOf(char);
if (index === -1) {
return value;
}
if (char === "-" && index !== 0) {
return value.slice(0, index);
}
return value.slice(0, index + 1) + value.slice(index).replace(regExp, "");
}
function formatNumber(value, allowDot = true, allowMinus = true) {
if (allowDot) {
value = trimExtraChar(value, ".", /\./g);
} else {
value = value.split(".")[0];
}
if (allowMinus) {
value = trimExtraChar(value, "-", /-/g);
} else {
value = value.replace(/-/, "");
}
const regExp = allowDot ? /[^-0-9.]/g : /[^-0-9]/g;
return value.replace(regExp, "");
}
function addNumber(num1, num2) {
const cardinal = 10 ** 10;
return Math.round((num1 + num2) * cardinal) / cardinal;
}
const { hasOwnProperty } = Object.prototype;
function assignKey(to, from, key) {
const val = from[key];
if (!isDef(val)) {
return;
}
if (!hasOwnProperty.call(to, key) || !isObject$1(val)) {
to[key] = val;
} else {
to[key] = deepAssign(Object(to[key]), val);
}
}
function deepAssign(to, from) {
Object.keys(from).forEach((key) => {
assignKey(to, from, key);
});
return to;
}
var stdin_default$1W = {
name: "姓名",
tel: "电话",
save: "保存",
clear: "清空",
cancel: "取消",
confirm: "确认",
delete: "删除",
loading: "加载中...",
noCoupon: "暂无优惠券",
nameEmpty: "请填写姓名",
addContact: "添加联系人",
telInvalid: "请填写正确的电话",
vanCalendar: {
end: "结束",
start: "开始",
title: "日期选择",
weekdays: ["日", "一", "二", "三", "四", "五", "六"],
monthTitle: (year, month) => `${year}年${month}月`,
rangePrompt: (maxRange) => `最多选择 ${maxRange} 天`
},
vanCascader: {
select: "请选择"
},
vanPagination: {
prev: "上一页",
next: "下一页"
},
vanPullRefresh: {
pulling: "下拉即可刷新...",
loosing: "释放即可刷新..."
},
vanSubmitBar: {
label: "合计:"
},
vanCoupon: {
unlimited: "无门槛",
discount: (discount) => `${discount}折`,
condition: (condition) => `满${condition}元可用`
},
vanCouponCell: {
title: "优惠券",
count: (count) => `${count}张可用`
},
vanCouponList: {
exchange: "兑换",
close: "不使用",
enable: "可用",
disabled: "不可用",
placeholder: "输入优惠码"
},
vanAddressEdit: {
area: "地区",
areaEmpty: "请选择地区",
addressEmpty: "请填写详细地址",
addressDetail: "详细地址",
defaultAddress: "设为默认收货地址"
},
vanAddressList: {
add: "新增地址"
}
};
const lang = __WEBPACK_EXTERNAL_MODULE_vue__.ref("zh-CN");
const messages = __WEBPACK_EXTERNAL_MODULE_vue__.reactive({
"zh-CN": stdin_default$1W
});
const Locale = {
messages() {
return messages[lang.value];
},
use(newLang, newMessages) {
lang.value = newLang;
this.add({ [newLang]: newMessages });
},
add(newMessages = {}) {
deepAssign(messages, newMessages);
}
};
const useCurrentLang = () => lang;
var stdin_default$1V = Locale;
function createTranslate(name2) {
const prefix = camelize(name2) + ".";
return (path, ...args) => {
const messages2 = stdin_default$1V.messages();
const message = get(messages2, prefix + path) || get(messages2, path);
return isFunction(message) ? message(...args) : message;
};
}
function genBem(name2, mods) {
if (!mods) {
return "";
}
if (typeof mods === "string") {
return ` ${name2}--${mods}`;
}
if (Array.isArray(mods)) {
return mods.reduce(
(ret, item) => ret + genBem(name2, item),
""
);
}
return Object.keys(mods).reduce(
(ret, key) => ret + (mods[key] ? genBem(name2, key) : ""),
""
);
}
function createBEM(name2) {
return (el, mods) => {
if (el && typeof el !== "string") {
mods = el;
el = "";
}
el = el ? `${name2}__${el}` : name2;
return `${el}${genBem(el, mods)}`;
};
}
function createNamespace(name2) {
const prefixedName = `van-${name2}`;
return [
prefixedName,
createBEM(prefixedName),
createTranslate(prefixedName)
];
}
const BORDER = "van-hairline";
const BORDER_TOP = `${BORDER}--top`;
const BORDER_LEFT = `${BORDER}--left`;
const BORDER_RIGHT = `${BORDER}--right`;
const BORDER_BOTTOM = `${BORDER}--bottom`;
const BORDER_SURROUND = `${BORDER}--surround`;
const BORDER_TOP_BOTTOM = `${BORDER}--top-bottom`;
const BORDER_UNSET_TOP_BOTTOM = `${BORDER}-unset--top-bottom`;
const HAPTICS_FEEDBACK = "van-haptics-feedback";
const FORM_KEY = Symbol("van-form");
const LONG_PRESS_START_TIME = 500;
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();
}
}
function withInstall(options) {
options.install = (app) => {
const { name: name2 } = options;
if (name2) {
app.component(name2, options);
app.component(camelize(`-${name2}`), options);
}
};
return options;
}
function closest(arr, target) {
return arr.reduce(
(pre, cur) => Math.abs(pre - target) < Math.abs(cur - target) ? pre : cur
);
}
const POPUP_TOGGLE_KEY = Symbol();
function onPopupReopen(callback) {
const popupToggleStatus = __WEBPACK_EXTERNAL_MODULE_vue__.inject(POPUP_TOGGLE_KEY, null);
if (popupToggleStatus) {
__WEBPACK_EXTERNAL_MODULE_vue__.watch(popupToggleStatus, (show) => {
if (show) {
callback();
}
});
}
}
const useHeight = (element, withSafeArea) => {
const height = __WEBPACK_EXTERNAL_MODULE_vue__.ref();
const setHeight = () => {
height.value = useRect(element).height;
};
__WEBPACK_EXTERNAL_MODULE_vue__.onMounted(() => {
__WEBPACK_EXTERNAL_MODULE_vue__.nextTick(setHeight);
if (withSafeArea) {
for (let i = 1; i <= 3; i++) {
setTimeout(setHeight, 100 * i);
}
}
});
onPopupReopen(() => __WEBPACK_EXTERNAL_MODULE_vue__.nextTick(setHeight));
__WEBPACK_EXTERNAL_MODULE_vue__.watch([windowWidth, windowHeight], setHeight);
return height;
};
function usePlaceholder(contentRef, bem2) {
const height = useHeight(contentRef, true);
return (renderContent) => __WEBPACK_EXTERNAL_MODULE_vue__.createVNode("div", {
"class": bem2("placeholder"),
"style": {
height: height.value ? `${height.value}px` : void 0
}
}, [renderContent()]);
}
const [name$1K, bem$1F] = createNamespace("action-bar");
const ACTION_BAR_KEY = Symbol(name$1K);
const actionBarProps = {
placeholder: Boolean,
safeAreaInsetBottom: truthProp
};
var stdin_default$1U = __WEBPACK_EXTERNAL_MODULE_vue__.defineComponent({
name: name$1K,
props: actionBarProps,
setup(props2, {
slots
}) {
const root = __WEBPACK_EXTERNAL_MODULE_vue__.ref();
const renderPlaceholder = usePlaceholder(root, bem$1F);
const {
linkChildren
} = useChildren(ACTION_BAR_KEY);
linkChildren();
const renderActionBar = () => {
var _a;
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode("div", {
"ref": root,
"class": [bem$1F(), {
"van-safe-area-bottom": props2.safeAreaInsetBottom
}]
}, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
};
return () => {
if (props2.placeholder) {
return renderPlaceholder(renderActionBar);
}
return renderActionBar();
};
}
});
const ActionBar = withInstall(stdin_default$1U);
function useExpose(apis) {
const instance2 = __WEBPACK_EXTERNAL_MODULE_vue__.getCurrentInstance();
if (instance2) {
extend(instance2.proxy, apis);
}
}
const routeProps = {
to: [String, Object],
url: String,
replace: Boolean
};
function route({
to,
url,
replace,
$router: router
}) {
if (to && router) {
router[replace ? "replace" : "push"](to);
} else if (url) {
replace ? location.replace(url) : location.href = url;
}
}
function useRoute() {
const vm = __WEBPACK_EXTERNAL_MODULE_vue__.getCurrentInstance().proxy;
return () => route(vm);
}
const [name$1J, bem$1E] = 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$1T = __WEBPACK_EXTERNAL_MODULE_vue__.defineComponent({
name: name$1J,
props: badgeProps,
setup(props2, {
slots
}) {
const hasContent = () => {
if (slots.content) {
return true;
}
const {
content,
showZero
} = props2;
return isDef(content) && content !== "" && (showZero || content !== 0 && content !== "0");
};
const renderContent = () => {
const {
dot,
max,
content
} = props2;
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 = __WEBPACK_EXTERNAL_MODULE_vue__.computed(() => {
const style2 = {
background: props2.color
};
if (props2.offset) {
const [x, y] = props2.offset;
const {
position
} = props2;
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() || props2.dot) {
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode("div", {
"class": bem$1E([props2.position, {
dot: props2.dot,
fixed: !!slots.default
}]),
"style": style.value
}, [renderContent()]);
}
};
return () => {
if (slots.default) {
const {
tag
} = props2;
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode(tag, {
"class": bem$1E("wrapper")
}, {
default: () => [slots.default(), renderBadge()]
});
}
return renderBadge();
};
}
});
const Badge = withInstall(stdin_default$1T);
let globalZIndex = 2e3;
const useGlobalZIndex = () => ++globalZIndex;
const setGlobalZIndex = (val) => {
globalZIndex = val;
};
const [name$1I, bem$1D] = createNamespace("config-provider");
const CONFIG_PROVIDER_KEY = Symbol(name$1I);
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;
}
function syncThemeVarsOnRoot(newStyle = {}, oldStyle = {}) {
Object.keys(newStyle).forEach((key) => {
if (newStyle[key] !== oldStyle[key]) {
document.documentElement.style.setProperty(key, newStyle[key]);
}
});
Object.keys(oldStyle).forEach((key) => {
if (!newStyle[key]) {
document.documentElement.style.removeProperty(key);
}
});
}
var stdin_default$1S = __WEBPACK_EXTERNAL_MODULE_vue__.defineComponent({
name: name$1I,
props: configProviderProps,
setup(props2, {
slots
}) {
const style = __WEBPACK_EXTERNAL_MODULE_vue__.computed(() => mapThemeVarsToCSSVars(extend({}, props2.themeVars, props2.theme === "dark" ? props2.themeVarsDark : props2.themeVarsLight)));
if (inBrowser$1) {
const addTheme = () => {
document.documentElement.classList.add(`van-theme-${props2.theme}`);
};
const removeTheme = (theme = props2.theme) => {
document.documentElement.classList.remove(`van-theme-${theme}`);
};
__WEBPACK_EXTERNAL_MODULE_vue__.watch(() => props2.theme, (newVal, oldVal) => {
if (oldVal) {
removeTheme(oldVal);
}
addTheme();
}, {
immediate: true
});
__WEBPACK_EXTERNAL_MODULE_vue__.onActivated(addTheme);
__WEBPACK_EXTERNAL_MODULE_vue__.onDeactivated(removeTheme);
__WEBPACK_EXTERNAL_MODULE_vue__.onBeforeUnmount(removeTheme);
__WEBPACK_EXTERNAL_MODULE_vue__.watch(style, (newStyle, oldStyle) => {
if (props2.themeVarsScope === "global") {
syncThemeVarsOnRoot(newStyle, oldStyle);
}
});
__WEBPACK_EXTERNAL_MODULE_vue__.watch(() => props2.themeVarsScope, (newScope, oldScope) => {
if (oldScope === "global") {
syncThemeVarsOnRoot({}, style.value);
}
if (newScope === "global") {
syncThemeVarsOnRoot(style.value, {});
}
});
if (props2.themeVarsScope === "global") {
syncThemeVarsOnRoot(style.value, {});
}
}
__WEBPACK_EXTERNAL_MODULE_vue__.provide(CONFIG_PROVIDER_KEY, props2);
__WEBPACK_EXTERNAL_MODULE_vue__.watchEffect(() => {
if (props2.zIndex !== void 0) {
setGlobalZIndex(props2.zIndex);
}
});
return () => __WEBPACK_EXTERNAL_MODULE_vue__.createVNode(props2.tag, {
"class": bem$1D(),
"style": props2.themeVarsScope === "local" ? style.value : void 0
}, {
default: () => {
var _a;
return [(_a = slots.default) == null ? void 0 : _a.call(slots)];
}
});
}
});
const [name$1H, bem$1C] = createNamespace("icon");
const isImage$1 = (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$1R = __WEBPACK_EXTERNAL_MODULE_vue__.defineComponent({
name: name$1H,
props: iconProps,
setup(props2, {
slots
}) {
const config = __WEBPACK_EXTERNAL_MODULE_vue__.inject(CONFIG_PROVIDER_KEY, null);
const classPrefix = __WEBPACK_EXTERNAL_MODULE_vue__.computed(() => props2.classPrefix || (config == null ? void 0 : config.iconPrefix) || bem$1C());
return () => {
const {
tag,
dot,
name: name2,
size,
badge,
color
} = props2;
const isImageIcon = isImage$1(name2);
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode(Badge, __WEBPACK_EXTERNAL_MODULE_vue__.mergeProps({
"dot": dot,
"tag": tag,
"class": [classPrefix.value, isImageIcon ? "" : `${classPrefix.value}-${name2}`],
"style": {
color,
fontSize: addUnit(size)
},
"content": badge
}, props2.badgeProps), {
default: () => {
var _a;
return [(_a = slots.default) == null ? void 0 : _a.call(slots), isImageIcon && __WEBPACK_EXTERNAL_MODULE_vue__.createVNode("img", {
"class": bem$1C("image"),
"src": name2
}, null)];
}
});
};
}
});
const Icon = withInstall(stdin_default$1R);
var stdin_default$1Q = Icon;
const [name$1G, bem$1B] = createNamespace("loading");
const SpinIcon = Array(12).fill(null).map((_, index) => __WEBPACK_EXTERNAL_MODULE_vue__.createVNode("i", {
"class": bem$1B("line", String(index + 1))
}, null));
const CircularIcon = __WEBPACK_EXTERNAL_MODULE_vue__.createVNode("svg", {
"class": bem$1B("circular"),
"viewBox": "25 25 50 50"
}, [__WEBPACK_EXTERNAL_MODULE_vue__.createVNode("circle", {
"cx": "50",
"cy": "50",
"r": "20",
"fill": "none"
}, null)]);
const loadingProps = {
size: numericProp,
type: makeStringProp("circular"),
color: String,
vertical: Boolean,
textSize: numericProp,
textColor: String
};
var stdin_default$1P = __WEBPACK_EXTERNAL_MODULE_vue__.defineComponent({
name: name$1G,
props: loadingProps,
setup(props2, {
slots
}) {
const spinnerStyle = __WEBPACK_EXTERNAL_MODULE_vue__.computed(() => extend({
color: props2.color
}, getSizeStyle(props2.size)));
const renderIcon = () => {
const DefaultIcon = props2.type === "spinner" ? SpinIcon : CircularIcon;
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode("span", {
"class": bem$1B("spinner", props2.type),
"style": spinnerStyle.value
}, [slots.icon ? slots.icon() : DefaultIcon]);
};
const renderText = () => {
var _a;
if (slots.default) {
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode("span", {
"class": bem$1B("text"),
"style": {
fontSize: addUnit(props2.textSize),
color: (_a = props2.textColor) != null ? _a : props2.color
}
}, [slots.default()]);
}
};
return () => {
const {
type,
vertical
} = props2;
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode("div", {
"class": bem$1B([type, {
vertical
}]),
"aria-live": "polite",
"aria-busy": true
}, [renderIcon(), renderText()]);
};
}
});
const Loading = withInstall(stdin_default$1P);
const [name$1F, bem$1A] = createNamespace("button");
const buttonProps = extend({}, routeProps, {
tag: makeStringProp("button"),
text: String,
icon: String,
type: makeStringProp("default"),
size: makeStringProp("normal"),
color: String,
block: Boolean,
plain: Boolean,
round: Boolean,
square: Boolean,
loading: Boolean,
hairline: Boolean,
disabled: Boolean,
iconPrefix: String,
nativeType: makeStringProp("button"),
loadingSize: numericProp,
loadingText: String,
loadingType: String,
iconPosition: makeStringProp("left")
});
var stdin_default$1O = __WEBPACK_EXTERNAL_MODULE_vue__.defineComponent({
name: name$1F,
props: buttonProps,
emits: ["click"],
setup(props2, {
emit,
slots
}) {
const route2 = useRoute();
const renderLoadingIcon = () => {
if (slots.loading) {
return slots.loading();
}
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode(Loading, {
"size": props2.loadingSize,
"type": props2.loadingType,
"class": bem$1A("loading")
}, null);
};
const renderIcon = () => {
if (props2.loading) {
return renderLoadingIcon();
}
if (slots.icon) {
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode("div", {
"class": bem$1A("icon")
}, [slots.icon()]);
}
if (props2.icon) {
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode(Icon, {
"name": props2.icon,
"class": bem$1A("icon"),
"classPrefix": props2.iconPrefix
}, null);
}
};
const renderText = () => {
let text;
if (props2.loading) {
text = props2.loadingText;
} else {
text = slots.default ? slots.default() : props2.text;
}
if (text) {
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode("span", {
"class": bem$1A("text")
}, [text]);
}
};
const getStyle = () => {
const {
color,
plain
} = props2;
if (color) {
const style = {
color: plain ? color : "white"
};
if (!plain) {
style.background = color;
}
if (color.includes("gradient")) {
style.border = 0;
} else {
style.borderColor = color;
}
return style;
}
};
const onClick = (event) => {
if (props2.loading) {
preventDefault(event);
} else if (!props2.disabled) {
emit("click", event);
route2();
}
};
return () => {
const {
tag,
type,
size,
block,
round: round2,
plain,
square,
loading,
disabled,
hairline,
nativeType,
iconPosition
} = props2;
const classes = [bem$1A([type, size, {
plain,
block,
round: round2,
square,
loading,
disabled,
hairline
}]), {
[BORDER_SURROUND]: hairline
}];
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode(tag, {
"type": nativeType,
"class": classes,
"style": getStyle(),
"disabled": disabled,
"onClick": onClick
}, {
default: () => [__WEBPACK_EXTERNAL_MODULE_vue__.createVNode("div", {
"class": bem$1A("content")
}, [iconPosition === "left" && renderIcon(), renderText(), iconPosition === "right" && renderIcon()])]
});
};
}
});
const Button = withInstall(stdin_default$1O);
const [name$1E, bem$1z] = createNamespace("action-bar-button");
const actionBarButtonProps = extend({}, routeProps, {
type: String,
text: String,
icon: String,
color: String,
loading: Boolean,
disabled: Boolean
});
var stdin_default$1N = __WEBPACK_EXTERNAL_MODULE_vue__.defineComponent({
name: name$1E,
props: actionBarButtonProps,
setup(props2, {
slots
}) {
const route2 = useRoute();
const {
parent,
index
} = useParent(ACTION_BAR_KEY);
const isFirst = __WEBPACK_EXTERNAL_MODULE_vue__.computed(() => {
if (parent) {
const prev = parent.children[index.value - 1];
return !(prev && "isButton" in prev);
}
});
const isLast = __WEBPACK_EXTERNAL_MODULE_vue__.computed(() => {
if (parent) {
const next = parent.children[index.value + 1];
return !(next && "isButton" in next);
}
});
useExpose({
isButton: true
});
return () => {
const {
type,
icon,
text,
color,
loading,
disabled
} = props2;
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode(Button, {
"class": bem$1z([type, {
last: isLast.value,
first: isFirst.value
}]),
"size": "large",
"type": type,
"icon": icon,
"color": color,
"loading": loading,
"disabled": disabled,
"onClick": route2
}, {
default: () => [slots.default ? slots.default() : text]
});
};
}
});
const ActionBarButton = withInstall(stdin_default$1N);
const [name$1D, bem$1y] = createNamespace("action-bar-icon");
const actionBarIconProps = extend({}, routeProps, {
dot: Boolean,
text: String,
icon: String,
color: String,
badge: numericProp,
iconClass: unknownProp,
badgeProps: Object,
iconPrefix: String
});
var stdin_default$1M = __WEBPACK_EXTERNAL_MODULE_vue__.defineComponent({
name: name$1D,
props: actionBarIconProps,
setup(props2, {
slots
}) {
const route2 = useRoute();
useParent(ACTION_BAR_KEY);
const renderIcon = () => {
const {
dot,
badge,
icon,
color,
iconClass,
badgeProps: badgeProps2,
iconPrefix
} = props2;
if (slots.icon) {
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode(Badge, __WEBPACK_EXTERNAL_MODULE_vue__.mergeProps({
"dot": dot,
"class": bem$1y("icon"),
"content": badge
}, badgeProps2), {
default: slots.icon
});
}
return __WEBPACK_EXTERNAL_MODULE_vue__.createVNode(Icon, {
"tag": "div",
"dot": dot,
"name": icon,
"badge": badge,
"color": color,
"class": [bem$1y("icon"), iconClass],
"badgeProps": badgeProps2,
"classPrefix": iconPrefix
}, null);
};
return () => __WEBPACK_EXTERNAL_MODULE_vue__.createVNode("div", {
"role": "button",
"class": bem$1y(),
"tabindex": 0,
"onClick": route2
}, [renderIcon(), slots.default ? slots.default() : props2.text]);
}
});
const ActionBarIcon = withInstall(stdin_default$1M);
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 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 getDirection(x, y) {
if (x > y) {
return "horizontal";
}
if (y > x) {
return "vertical";
}
return "";
}
function useTouch() {
const startX = __WEBPACK_EXTERNAL_MODULE_vue__.ref(0);
const startY = __WEBPACK_EXTERNAL_MODULE_vue__.ref(0);
const deltaX = __WEBPACK_EXTERNAL_MODULE_vue__.ref(0);
const deltaY = __WEBPACK_EXTERNAL_MODULE_vue__.ref(0);
const offsetX = __WEBPACK_EXTERNAL_MODULE_vue__.ref(0);
const offsetY = __WEBPACK_EXTERNAL_MODULE_vue__.ref(0);
const direction = __WEBPACK_EXTERNAL_MODULE_vue__.ref("");
const isTap = __WEBPACK_EXTERNAL_MODULE_vue__.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 start2 = (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: start2,
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$1(
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, true);
}
};
const lock = () => {
document.addEventListener("touchstart", touch.start);
document.addEventListener("touchmove", onTouchMove, { passive: false });
if (!totalLockCount) {
document.body.classList.add(BODY_LOCK_CLASS);
}
totalLockCount++;
};
const unlock = () => {
if (totalLockCount) {
document.removeEventListener("touchstart", touch.start);
document.removeEventListener("touchmove", onTouchMove);
totalLockCount--;
if (!totalLockCount) {
document.body.classList.remove(BODY_LOCK_CLASS);