tdesign-mobile-vue
Version:
tdesign-mobile-vue
259 lines (255 loc) • 9.29 kB
JavaScript
/**
* tdesign v1.7.0
* (c) 2024 TDesign Group
* @license MIT
*/
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { defineComponent, ref, computed, onMounted, watch, createVNode, mergeProps } from 'vue';
import config from '../config.js';
import FabProps from './props.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import { usePrefixClass } from '../hooks/useClass.js';
import { Button } from '../button/index.js';
import 'lodash/isFunction';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../hooks/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isString';
import 'lodash/isObject';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import 'lodash/isArray';
import '../_common/js/global-config/mobile/default-config.js';
import '../_common/js/global-config/mobile/locale/zh_CN.js';
import '../_chunks/dep-6c582337.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-38637d40.js';
import 'dayjs';
import '../_chunks/dep-959cdc59.js';
import '../config-provider/type.js';
import '../button/button.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/set-style.js';
import '../_common/js/utils/helper.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isNumber';
import '../loading/icon/spinner.js';
import '../loading/props.js';
import '../shared/dom.js';
import '../shared/index.js';
import '../shared/functions.js';
import '../shared/util.js';
import '../shared/component.js';
import '../shared/constants.js';
import '../shared/render.js';
import '../shared/render-tnode.js';
import '../shared/useToggle/index.js';
import '../shared/useCountDown/index.js';
import '@babel/runtime/helpers/asyncToGenerator';
import '@babel/runtime/regenerator';
import '@vueuse/core';
import '../shared/useCountDown/utils.js';
import '../shared/useDefault/index.js';
import '../shared/useChildSlots/index.js';
import '../shared/useVModel/index.js';
import '../shared/useTouch/index.js';
import '../shared/useScrollParent/index.js';
import '../shared/useExpose/index.js';
import '../shared/useTest/index.js';
import '../shared/useClickAway/index.js';
import '../shared/useGesture/index.js';
import '@use-gesture/vanilla';
import '../shared/hover.js';
import '../loading/style';
import '../loading/type.js';
import '../loading/plugin.js';
import '../button/props.js';
import '../form/hooks.js';
import 'lodash/isBoolean';
import '../button/style';
import '../button/type.js';
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var prefix = config.prefix;
var getNumber = function getNumber(num) {
return num.replace(/[^\d]/g, "");
};
var _Fab = defineComponent({
name: "".concat(prefix, "-fab"),
props: FabProps,
setup: function setup(props) {
var renderTNodeJSX = useTNodeJSX();
var fabClass = usePrefixClass("fab");
var fabRef = ref();
var fabButtonRef = ref();
var handleClick = function handleClick(e) {
var _props$onClick;
(_props$onClick = props.onClick) === null || _props$onClick === void 0 || _props$onClick.call(props, {
e: e
});
};
var mounted = ref(false);
var fabButtonSize = ref({
width: 48,
height: 48
});
var btnSwitchPos = ref({
x: 16,
y: 32
});
var switchPos = ref({
hasMoved: false,
x: btnSwitchPos.value.x,
y: btnSwitchPos.value.y,
startX: 0,
startY: 0,
endX: 0,
endY: 0
});
var onTouchStart = function onTouchStart(e) {
switchPos.value.startX = e.touches[0].pageX;
switchPos.value.startY = e.touches[0].pageY;
};
var onTouchMove = function onTouchMove(e) {
e.stopPropagation();
e.preventDefault();
if (!props.draggable) {
return;
}
if (e.touches.length <= 0) {
return;
}
var offsetX = e.touches[0].pageX - switchPos.value.startX;
var offsetY = e.touches[0].pageY - switchPos.value.startY;
var x = Math.floor(switchPos.value.x - offsetX);
var y = Math.floor(switchPos.value.y - offsetY);
var _getSwitchButtonSafeA = getSwitchButtonSafeAreaXY(x, y);
var _getSwitchButtonSafeA2 = _slicedToArray(_getSwitchButtonSafeA, 2);
x = _getSwitchButtonSafeA2[0];
y = _getSwitchButtonSafeA2[1];
btnSwitchPos.value.x = x;
btnSwitchPos.value.y = y;
switchPos.value.endX = x;
switchPos.value.endY = y;
switchPos.value.hasMoved = true;
};
var getSwitchButtonSafeAreaXY = function getSwitchButtonSafeAreaXY(x, y) {
var bottomThreshold = 0;
var top = 0;
var windowTop = 0;
var windowBottom = 0;
var windowWidth = Math.min(window.innerWidth, document.documentElement.clientWidth, screen.width);
var windowHeight = Math.min(window.innerHeight, document.documentElement.clientHeight, screen.height);
var docWidth = windowWidth;
var docHeight = windowHeight - top;
if (x + fabButtonSize.value.width > docWidth) {
x = docWidth - fabButtonSize.value.width;
}
if (y + fabButtonSize.value.height - windowTop > docHeight) {
y = docHeight - fabButtonSize.value.height + windowTop;
}
if (x < 0) {
x = 0;
}
if (y < bottomThreshold + windowBottom) {
y = bottomThreshold + windowBottom;
}
return [x, y];
};
var onTouchEnd = function onTouchEnd(e) {
if (!switchPos.value.hasMoved) {
return;
}
switchPos.value.startX = 0;
switchPos.value.startY = 0;
switchPos.value.hasMoved = false;
setSwitchPosition(switchPos.value.endX, switchPos.value.endY);
};
var setSwitchPosition = function setSwitchPosition(switchX, switchY) {
var _getSwitchButtonSafeA3 = getSwitchButtonSafeAreaXY(switchX, switchY);
var _getSwitchButtonSafeA4 = _slicedToArray(_getSwitchButtonSafeA3, 2);
switchX = _getSwitchButtonSafeA4[0];
switchY = _getSwitchButtonSafeA4[1];
switchPos.value.x = switchX;
switchPos.value.y = switchY;
btnSwitchPos.value.x = switchX;
btnSwitchPos.value.y = switchY;
};
var fabStyle = computed(function () {
return {
right: "".concat(btnSwitchPos.value.x, "px"),
bottom: "".concat(btnSwitchPos.value.y, "px")
};
});
onMounted(function () {
mounted.value = true;
resetDraggableParams();
var info = window.getComputedStyle(fabButtonRef.value.$el);
fabButtonSize.value.height = +getNumber(info.height);
fabButtonSize.value.width = +getNumber(info.width);
});
var getFabOriginStyle = function getFabOriginStyle() {
var info = window.getComputedStyle(fabRef.value);
var _ref = info || {},
right = _ref.right,
bottom = _ref.bottom;
return {
right: +(getNumber(right) || 0),
bottom: +(getNumber(bottom) || 0)
};
};
var resetDraggableParams = function resetDraggableParams() {
var _getFabOriginStyle = getFabOriginStyle(),
right = _getFabOriginStyle.right,
bottom = _getFabOriginStyle.bottom;
btnSwitchPos.value.x = right;
btnSwitchPos.value.y = bottom;
switchPos.value.x = right;
switchPos.value.y = bottom;
};
watch(function () {
return props.style;
}, function () {
resetDraggableParams();
});
return function () {
var icon = function icon() {
return renderTNodeJSX("icon");
};
return createVNode("div", {
"class": fabClass.value,
"style": mounted.value && props.draggable ? _objectSpread({}, fabStyle.value) : props.style,
"onClick": handleClick,
"onTouchstart": onTouchStart,
"onTouchmove": onTouchMove,
"onTouchend": onTouchEnd,
"ref": fabRef
}, [createVNode(Button, mergeProps({
"size": "large",
"theme": "primary",
"shape": props.text ? "round" : "circle",
"class": "".concat(fabClass.value, "__button")
}, props.buttonProps, {
"icon": icon,
"ref": fabButtonRef
}), {
default: function _default() {
return [props.text];
}
})]);
};
}
});
export { _Fab as default };
//# sourceMappingURL=fab.js.map