jb-mobile-ui
Version:
JinBiWuYe Mobile UI Components base on Vant
1,818 lines • 272 kB
JavaScript
import { ref, onMounted, reactive, getCurrentInstance, nextTick, onActivated, onUnmounted, onDeactivated, isRef, watch, inject, computed, provide, unref, isVNode, defineComponent, createVNode, onBeforeUnmount, watchEffect, mergeProps, Transition, Teleport, withDirectives, vShow, Fragment, onBeforeUpdate, Comment, createApp, useAttrs, useSlots, createBlock, openBlock, createSlots, renderList, withCtx, renderSlot, normalizeProps, guardReactiveProps, createElementVNode, createElementBlock, createCommentVNode, normalizeClass as normalizeClass$1, toDisplayString, normalizeStyle as normalizeStyle$1, createTextVNode, vModelDynamic, customRef } from "vue";
import { showToast as showToast$1 } from "vant";
import dayjs from "dayjs";
import weekOfYear from "dayjs/plugin/weekOfYear";
import quarterOfYear from "dayjs/plugin/quarterOfYear";
import weekday from "dayjs/plugin/weekday";
function noop() {
}
const extend = Object.assign;
const inBrowser$1 = typeof window !== "undefined";
const isObject$2 = (val) => val !== null && typeof val === "object";
const isDef = (val) => val !== void 0 && val !== null;
const isFunction = (val) => typeof val === "function";
const isPromise = (val) => isObject$2(val) && isFunction(val.then) && isFunction(val.catch);
const isDate = (val) => Object.prototype.toString.call(val) === "[object Date]" && !Number.isNaN(val.getTime());
const isNumeric = (val) => typeof val === "number" || /^\d+(\.\d+)?$/.test(val);
const isIOS = () => 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$2(result) ? (_a = result[key]) != null ? _a : "" : "";
});
return result;
}
function pick(obj, keys, ignoreUndefined) {
return keys.reduce(
(ret, key) => {
{
ret[key] = obj[key];
}
return ret;
},
{}
);
}
const isSameValue = (newValue, oldValue) => JSON.stringify(newValue) === JSON.stringify(oldValue);
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
});
var inBrowser = typeof window !== "undefined";
function raf(fn) {
return inBrowser ? requestAnimationFrame(fn) : -1;
}
function cancelRaf(id) {
if (inBrowser) {
cancelAnimationFrame(id);
}
}
function doubleRaf(fn) {
raf(() => raf(fn));
}
var isWindow = (val) => val === window;
var makeDOMRect = (width2, height2) => ({
top: 0,
left: 0,
right: width2,
bottom: height2,
width: width2,
height: height2
});
var useRect = (elementOrRef) => {
const element = unref(elementOrRef);
if (isWindow(element)) {
const width2 = element.innerWidth;
const height2 = element.innerHeight;
return makeDOMRect(width2, height2);
}
if (element == null ? void 0 : element.getBoundingClientRect) {
return element.getBoundingClientRect();
}
return makeDOMRect(0, 0);
};
function useToggle(defaultValue = false) {
const state = ref(defaultValue);
const toggle = (value = !state.value) => {
state.value = value;
};
return [state, toggle];
}
function useParent(key) {
const parent = inject(key, null);
if (parent) {
const instance = getCurrentInstance();
const { link, unlink, internalChildren } = parent;
link(instance);
onUnmounted(() => unlink(instance));
const index = computed(() => internalChildren.indexOf(instance));
return {
parent,
index
};
}
return {
parent: null,
index: ref(-1)
};
}
function flattenVNodes(children) {
const result = [];
const traverse = (children2) => {
if (Array.isArray(children2)) {
children2.forEach((child) => {
var _a;
if (isVNode(child)) {
result.push(child);
if ((_a = child.component) == null ? void 0 : _a.subTree) {
result.push(child.component.subTree);
traverse(child.component.subTree.children);
}
if (child.children) {
traverse(child.children);
}
}
});
}
};
traverse(children);
return result;
}
var findVNodeIndex = (vnodes, vnode) => {
const index = vnodes.indexOf(vnode);
if (index === -1) {
return vnodes.findIndex(
(item) => vnode.key !== void 0 && vnode.key !== null && 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 = reactive([]);
const internalChildren = reactive([]);
const parent = 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);
};
provide(
key,
Object.assign(
{
link,
unlink,
children: publicChildren,
internalChildren
},
value
)
);
};
return {
children: publicChildren,
linkChildren
};
}
function onMountedOrActivated(hook) {
let mounted;
onMounted(() => {
hook();
nextTick(() => {
mounted = true;
});
});
onActivated(() => {
if (mounted) {
hook();
}
});
}
function useEventListener(type, listener, options = {}) {
if (!inBrowser) {
return;
}
const { target = window, passive = false, capture = false } = options;
let cleaned = false;
let attached;
const add = (target2) => {
if (cleaned) {
return;
}
const element = unref(target2);
if (element && !attached) {
element.addEventListener(type, listener, {
capture,
passive
});
attached = true;
}
};
const remove = (target2) => {
if (cleaned) {
return;
}
const element = unref(target2);
if (element && attached) {
element.removeEventListener(type, listener, capture);
attached = false;
}
};
onUnmounted(() => remove(target));
onDeactivated(() => remove(target));
onMountedOrActivated(() => add(target));
let stopWatch;
if (isRef(target)) {
stopWatch = watch(target, (val, oldVal) => {
remove(oldVal);
add(val);
});
}
return () => {
stopWatch == null ? void 0 : stopWatch();
remove(target);
cleaned = true;
};
}
var width;
var height;
function useWindowSize() {
if (!width) {
width = ref(0);
height = ref(0);
if (inBrowser) {
const update = () => {
width.value = window.innerWidth;
height.value = window.innerHeight;
};
update();
window.addEventListener("resize", update, { passive: true });
window.addEventListener("orientationchange", update, { passive: true });
}
}
return { width, height };
}
var overflowScrollReg = /scroll|auto|overlay/i;
var defaultRoot = inBrowser ? window : 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, root2 = defaultRoot) {
let node = el;
while (node && node !== root2 && isElement(node)) {
const { overflowY } = window.getComputedStyle(node);
if (overflowScrollReg.test(overflowY)) {
return node;
}
node = node.parentNode;
}
return root2;
}
function useScrollParent(el, root2 = defaultRoot) {
const scrollParent = ref();
onMounted(() => {
if (el.value) {
scrollParent.value = getScrollParent(el.value, root2);
}
});
return scrollParent;
}
var visibility;
function usePageVisibility() {
if (!visibility) {
visibility = ref("visible");
if (inBrowser) {
const update = () => {
visibility.value = document.hidden ? "hidden" : "visible";
};
update();
window.addEventListener("visibilitychange", update);
}
}
return visibility;
}
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;
}
isIOS();
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 = 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 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(/^-/, "");
const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
const { hasOwnProperty: hasOwnProperty$1 } = Object.prototype;
function assignKey(to, from, key) {
const val = from[key];
if (!isDef(val)) {
return;
}
if (!hasOwnProperty$1.call(to, key) || !isObject$2(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$k = {
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 = ref("zh-CN");
const messages = reactive({
"zh-CN": stdin_default$k
});
const Locale = {
messages() {
return messages[lang.value];
},
use(newLang, newMessages) {
lang.value = newLang;
this.add({ [newLang]: newMessages });
},
add(newMessages = {}) {
deepAssign(messages, newMessages);
}
};
var stdin_default$j = Locale;
function createTranslate(name2) {
const prefix = camelize(name2) + ".";
return (path, ...args) => {
const messages2 = stdin_default$j.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_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 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;
}
const POPUP_TOGGLE_KEY = Symbol();
function onPopupReopen(callback) {
const popupToggleStatus = inject(POPUP_TOGGLE_KEY, null);
if (popupToggleStatus) {
watch(popupToggleStatus, (show) => {
if (show) {
callback();
}
});
}
}
const useHeight = (element, withSafeArea) => {
const height2 = ref();
const setHeight = () => {
height2.value = useRect(element).height;
};
onMounted(() => {
nextTick(setHeight);
});
onPopupReopen(() => nextTick(setHeight));
watch([windowWidth, windowHeight], setHeight);
return height2;
};
function useExpose(apis) {
const instance = getCurrentInstance();
if (instance) {
extend(instance.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 = getCurrentInstance().proxy;
return () => route(vm);
}
const [name$m, bem$i] = 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$i = defineComponent({
name: name$m,
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$i([props.position, {
dot: props.dot,
fixed: !!slots.default
}]),
"style": style.value
}, [renderContent()]);
}
};
return () => {
if (slots.default) {
const {
tag
} = props;
return createVNode(tag, {
"class": bem$i("wrapper")
}, {
default: () => [slots.default(), renderBadge()]
});
}
return renderBadge();
};
}
});
const Badge = withInstall(stdin_default$i);
let globalZIndex = 2e3;
const useGlobalZIndex = () => ++globalZIndex;
const setGlobalZIndex = (val) => {
globalZIndex = val;
};
const [name$l, bem$h] = createNamespace("config-provider");
const CONFIG_PROVIDER_KEY = Symbol(name$l);
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);
}
});
}
defineComponent({
name: name$l,
props: configProviderProps,
setup(props, {
slots
}) {
const style = computed(() => mapThemeVarsToCSSVars(extend({}, props.themeVars, props.theme === "dark" ? props.themeVarsDark : props.themeVarsLight)));
if (inBrowser$1) {
const addTheme = () => {
document.documentElement.classList.add(`van-theme-${props.theme}`);
};
const removeTheme = (theme = props.theme) => {
document.documentElement.classList.remove(`van-theme-${theme}`);
};
watch(() => props.theme, (newVal, oldVal) => {
if (oldVal) {
removeTheme(oldVal);
}
addTheme();
}, {
immediate: true
});
onActivated(addTheme);
onDeactivated(removeTheme);
onBeforeUnmount(removeTheme);
watch(style, (newStyle, oldStyle) => {
if (props.themeVarsScope === "global") {
syncThemeVarsOnRoot(newStyle, oldStyle);
}
});
watch(() => props.themeVarsScope, (newScope, oldScope) => {
if (oldScope === "global") {
syncThemeVarsOnRoot({}, style.value);
}
if (newScope === "global") {
syncThemeVarsOnRoot(style.value, {});
}
});
if (props.themeVarsScope === "global") {
syncThemeVarsOnRoot(style.value, {});
}
}
provide(CONFIG_PROVIDER_KEY, props);
watchEffect(() => {
if (props.zIndex !== void 0) {
setGlobalZIndex(props.zIndex);
}
});
return () => createVNode(props.tag, {
"class": bem$h(),
"style": props.themeVarsScope === "local" ? style.value : void 0
}, {
default: () => {
var _a;
return [(_a = slots.default) == null ? void 0 : _a.call(slots)];
}
});
}
});
const [name$k, bem$g] = 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$h = defineComponent({
name: name$k,
props: iconProps,
setup(props, {
slots
}) {
const config = inject(CONFIG_PROVIDER_KEY, null);
const classPrefix = computed(() => props.classPrefix || (config == null ? void 0 : config.iconPrefix) || bem$g());
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$g("image"),
"src": name2
}, null)];
}
});
};
}
});
const Icon = withInstall(stdin_default$h);
const [name$j, bem$f] = createNamespace("loading");
const SpinIcon = Array(12).fill(null).map((_, index) => createVNode("i", {
"class": bem$f("line", String(index + 1))
}, null));
const CircularIcon = createVNode("svg", {
"class": bem$f("circular"),
"viewBox": "25 25 50 50"
}, [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$g = defineComponent({
name: name$j,
props: loadingProps,
setup(props, {
slots
}) {
const spinnerStyle = computed(() => extend({
color: props.color
}, getSizeStyle(props.size)));
const renderIcon = () => {
const DefaultIcon = props.type === "spinner" ? SpinIcon : CircularIcon;
return createVNode("span", {
"class": bem$f("spinner", props.type),
"style": spinnerStyle.value
}, [slots.icon ? slots.icon() : DefaultIcon]);
};
const renderText = () => {
var _a;
if (slots.default) {
return createVNode("span", {
"class": bem$f("text"),
"style": {
fontSize: addUnit(props.textSize),
color: (_a = props.textColor) != null ? _a : props.color
}
}, [slots.default()]);
}
};
return () => {
const {
type,
vertical
} = props;
return createVNode("div", {
"class": bem$f([type, {
vertical
}]),
"aria-live": "polite",
"aria-busy": true
}, [renderIcon(), renderText()]);
};
}
});
const Loading = withInstall(stdin_default$g);
const [name$i, bem$e] = 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$f = defineComponent({
name: name$i,
props: buttonProps,
emits: ["click"],
setup(props, {
emit,
slots
}) {
const route2 = useRoute();
const renderLoadingIcon = () => {
if (slots.loading) {
return slots.loading();
}
return createVNode(Loading, {
"size": props.loadingSize,
"type": props.loadingType,
"class": bem$e("loading")
}, null);
};
const renderIcon = () => {
if (props.loading) {
return renderLoadingIcon();
}
if (slots.icon) {
return createVNode("div", {
"class": bem$e("icon")
}, [slots.icon()]);
}
if (props.icon) {
return createVNode(Icon, {
"name": props.icon,
"class": bem$e("icon"),
"classPrefix": props.iconPrefix
}, null);
}
};
const renderText = () => {
let text;
if (props.loading) {
text = props.loadingText;
} else {
text = slots.default ? slots.default() : props.text;
}
if (text) {
return createVNode("span", {
"class": bem$e("text")
}, [text]);
}
};
const getStyle = () => {
const {
color,
plain
} = props;
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 (props.loading) {
preventDefault(event);
} else if (!props.disabled) {
emit("click", event);
route2();
}
};
return () => {
const {
tag,
type,
size,
block,
round,
plain,
square,
loading,
disabled,
hairline,
nativeType,
iconPosition
} = props;
const classes = [bem$e([type, size, {
plain,
block,
round,
square,
loading,
disabled,
hairline
}]), {
[BORDER_SURROUND]: hairline
}];
return createVNode(tag, {
"type": nativeType,
"class": classes,
"style": getStyle(),
"disabled": disabled,
"onClick": onClick
}, {
default: () => [createVNode("div", {
"class": bem$e("content")
}, [iconPosition === "left" && renderIcon(), renderText(), iconPosition === "right" && renderIcon()])]
});
};
}
});
const Button = withInstall(stdin_default$f);
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
};
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, 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);
}
}
};
const init = () => shouldLock() && lock();
const destroy = () => shouldLock() && unlock();
onMountedOrActivated(init);
onDeactivated(destroy);
onBeforeUnmount(destroy);
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 useScopeId = () => {
var _a;
const { scopeId } = ((_a = getCurrentInstance()) == null ? void 0 : _a.vnode) || {};
return scopeId ? { [scopeId]: "" } : null;
};
const [name$h, bem$d] = createNamespace("overlay");
const overlayProps = {
show: Boolean,
zIndex: numericProp,
duration: numericProp,
className: unknownProp,
lockScroll: truthProp,
lazyRender: truthProp,
customStyle: Object,
teleport: [String, Object]
};
var stdin_default$e = defineComponent({
name: name$h,
inheritAttrs: false,
props: overlayProps,
setup(props, {
attrs,
slots
}) {
const root2 = ref();
const lazyRender = useLazyRender(() => props.show || !props.lazyRender);
const onTouchMove = (event) => {
if (props.lockScroll) {
preventDefault(event, true);
}
};
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": root2,
"style": style,
"class": [bem$d(), props.className]
}, attrs), [(_a = slots.default) == null ? void 0 : _a.call(slots)]), [[vShow, props.show]]);
});
useEventListener("touchmove", onTouchMove, {
target: root2
});
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$e);
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$g, bem$c] = createNamespace("popup");
var stdin_default$d = defineComponent({
name: name$g,
inheritAttrs: false,
props: popupProps,
emits: ["open", "close", "opened", "closed", "keydown", "update:show", "clickOverlay", "clickCloseIcon"],
setup(props, {
emit,
attrs,
slots
}) {
let opened;
let shouldReopen;
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) {
return createVNode(Overlay, mergeProps({
"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
}, 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$c("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$c({
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);
useEventListener("popstate", () => {
if (props.closeOnPopstate) {
close();
shouldReopen = false;
}
});
onMounted(() => {
if (props.show) {
open();
}
});
onActivated(() => {
if (shouldReopen) {
emit("update:show", true);
shouldReopen = false;
}
});
onDeactivated(() => {
if (props.show && props.teleport) {
close();
shouldReopen = true;
}
});
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$d);
const [name$f, bem$b, t$1] = createNamespace("picker");
const getFirstEnabledOption = (options) => options.find((option) => !option.disabled) || options[0];
function getColumnsType(columns, fields) {
const firstColumn = columns[0];
if (firstColumn) {
if (Array.isArray(firstColumn)) {
return "multiple";
}
if (fields.children in firstColumn) {
return "cascade";
}
}
return "default";
}
function findIndexOfEnabledOption(options, index) {
index = clamp(index, 0, options.length);
for (let i = index; i < options.length; i++) {
if (!options[i].disabled) return i;
}
for (let i = index - 1; i >= 0; i--) {
if (!options[i].disabled) return i;
}
return 0;
}
const isOptionExist = (options, value, fields) => value !== void 0 && options.some((option) => option[fields.value] === value);
function findOptionByValue(options, value, fields) {
const index = options.findIndex((option) => option[fields.value] === value);
const enabledIndex = findIndexOfEnabledOption(options, index);
return options[enabledIndex];
}
function formatCascadeColumns(columns, fields, selectedValues) {
const formatted = [];
let cursor = {
[fields.children]: columns
};
let columnIndex = 0;
while (cursor && cursor[fields.children]) {
const options = cursor[fields.children];
const value = selectedValues.value[columnIndex];
cursor = isDef(value) ? findOptionByValue(options, value, fields) : void 0;
if (!cursor && options.length) {
const firstValue = getFirstEnabledOption(options)[fields.value];
cursor = findOptionByValue(options, firstValue, fields);
}
columnIndex++;
formatted.push(options);
}
return formatted;
}
function getElementTranslateY(element) {
const { transform } = window.getComputedStyle(element);
const translateY = transform.slice(7, transform.length - 1).split(", ")[5];
return Number(translateY);
}
function assignDefaultFields(fields) {
return extend(
{
text: "text",
value: "value",
children: "children"
},
fields
);
}
const DEFAULT_DURATION = 200;
const MOMENTUM_TIME = 300;
const MOMENTUM_DISTANCE = 15;
const [name$e, bem$a] = createNamespace("picker-column");
const PICKER_KEY = Symbol(name$e);
var stdin_default$c = defineComponent({
name: name$e,
props: {
value: numericProp,
fields: makeRequiredProp(Object),
options: makeArrayProp(),
readonly: Boolean,
allowHtml: Boolean,
optionHeight: makeRequiredProp(Number),
swipeDuration: makeRequiredProp(numericProp),
visibleOptionNum: makeRequiredProp(numericProp)
},
emits: ["change", "clickOption", "scrollInto"],
setup(props, {
emit,
slots
}) {
let moving;
let startOffset;
let touchStartTime;
let momentumOffset;
let transitionEndTrigger;
const root2 = ref();
const wrapper = ref();
const currentOffset = ref(0);
const currentDuration = ref(0);
const touch = useTouch();
const count = () => props.options.length;
const baseOffset = () => props.optionHeight * (+props.visibleOptionNum - 1) / 2;
const updateValueByIndex = (index) => {
let enabledIndex = findIndexOfEnabledOption(props.options, index);
const offset = -enabledIndex * props.optionHeight;
const trigger = () => {
if (enabledIndex > count() - 1) {
enabledIndex = findIndexOfEnabledOption(props.options, index);
}
const value = props.options[enabledIndex][props.fields.value];
if (value !== props.value) {
emit("change", value);
}
};
if (moving && offset !== currentOffset.value) {
transitionEndTrigger = trigger;
} else {
trigger();
}
currentOffset.value = offset;
};
const isReadonly = () => props.readonly || !props.options.length;
const onClickOption = (index) => {
if (moving || isReadonly()) {
return;
}
transitionEndTrigger = null;
currentDuration.value = DEFAULT_DURATION;
updateValueByIndex(index);
emit("clickOption", props.options[index]);
};
const getIndexByOffset = (offset) => clamp(Math.round(-offset / props.optionHeight), 0, count() - 1);
const currentIndex = computed(() => getIndexByOffset(currentOffset.value));
const momentum = (distance, duration) => {
const speed = Math.abs(distance / duration);
distance = currentOffset.value + speed / 3e-3 * (distance < 0 ? -1 : 1);
const index = getIndexByOffset(distance);
currentDuration.value = +props.swipeDuration;
updateValueByIndex(index);
};
const stopMomentum = () => {
moving = false;
currentDuration.value = 0;
if (transitionEndTrigger) {
transitionEndTrigger();
transitionEndTrigger = null;
}
};
const onTouchStart = (event) => {
if (isReadonly()) {
return;
}
touch.start(event);
if (moving) {
const translateY = getElementTranslateY(wrapper.value);
currentOffset.value = Math.min(0, translateY - baseOffset());
}
currentDuration.value = 0;
startOffset = currentOffset.value;
touchStartTime = Date.now();
momentumOffset = startOffset;
transitionEndTrigger = null;
};
const onTouchMove = (event) => {
if (isReadonly()) {
return;
}
touch.move(event);
if (touch.isVertical()) {
moving = true;
preventDefault(event, true);
}
const newOffset = clamp(startOffset + touch.deltaY.value, -(count() * props.optionHeight), props.optionHeight);
const newIndex = getIndexByOffset(newOffset);
if (newIndex !== currentIndex.value) {
emit("scrollInto", props.options[newIndex]);
}
currentOffset.value = newOffset;
const now2 = Date.now();
if (now2 - touchStartTime > MOMENTUM_TIME) {
touchStartTime = now2;
momentumOffset = newOffset;
}
};
const onTouchEnd = () => {
if (isReadonly()) {
return;
}
const distance = currentOffset.value - momentumOffset;
const duration = Date.now() - touchStartTime;
const startMomentum = duration < MOMENTUM_TIME && Math.abs(distance) > MOMENTUM_DISTANCE;
if (startMomentum) {
momentum(distance, duration);
return;
}
const index = getIndexByOffset(currentOffset.value);
currentDuration.value = DEFAULT_DURATION;
updateValueByIndex(index);
setTimeout(() => {
moving = false;
}, 0);
};
const renderOptions = () => {
const optionStyle = {
height: `${props.optionHeight}px`
};
return props.options.map((option, index) => {
const text = option[props.fields.text];
const {
disabled
} = option;
const value = option[props.fields.value];
const data = {
role: "button",
style: optionStyle,
tabindex: disabled ? -1 : 0,
class: [bem$a("item", {
disabled,
selected: value === props.value
}), option.className],
onClick: () => onClickOption(index)
};
const childData = {
class: "van-ellipsis",
[props.allowHtml ? "innerHTML" : "textContent"]: text
};
return createVNode("li", data, [slots.option ? slots.option(option, index) : createVNode("div", childData, null)]);
});
};
useParent(PICKER_KEY);
useExpose({
stopMomentum
});
watchEffect(() => {
const index = moving ? Math.floor(-currentOffset.value / props.optionHeight) : props.options.findIndex((option) => option[props.fields.value] === props.value);
const enabledIndex = findIndexOfEnabledOption(props.options, index);
const offset = -enabledIndex * props.optionHeight;
if (moving && enabledIndex < index) stopMomentum();
currentOffset.value = offset;
});
useEventListener("touchmove", onTouchMove, {
target: root2
});
return () => createVNode("div", {
"ref": root2,
"class": bem$a(),
"onTouchstartPassive": onTouchStart,
"onTouchend": onTouchEnd,
"onTouchcancel": onTouchEnd
}, [createVNode("ul", {
"ref": wrapper,
"style": {
transform: `translate3d(0, ${currentOffset.value + baseOffset()}px, 0)`,
transitionDuration: `${currentDuration.value}ms`,
transitionProperty: currentDuration.value ? "all" : "none"
},
"class": bem$a("wrapper"),
"onTransitionend": stopMomentum
}, [renderOptions()])]);
}
});
const [name$d] = createNamespace("picker-toolbar");
const pickerToolbarProps = {
title: String,
cancelButtonText: String,
confirmButtonText: String
};
const pickerToolbarSlots = ["cancel", "confirm", "title", "toolbar"];
const pickerToolbarPropKeys = Object.keys(pickerToolbarProps);
var stdin_default$b = defineComponent({
name: name$d,
props: pickerToolbarProps,
emits: ["confirm", "cancel"],
setup(props, {
emit,
slots
})