EASYAIuniappNewUI/node_modules/.vite/deps/@tuniao_tnui-vue3-uniapp_hooks.js
2025-02-08 18:50:38 +08:00

497 lines
15 KiB
JavaScript

import {
debugWarn,
isEmptyVariableInDefault,
isNumber
} from "./chunk-7X6NDDPW.js";
import "./chunk-Y2F7D3TJ.js";
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-namespace/index.ts
import { computed, inject, ref, unref } from "vue";
var defaultNamespace = "tn";
var _bem = (namespace, block, blockSuffix, element, modifier) => {
let cls = `${namespace}-${block}`;
if (blockSuffix) {
cls += `-${blockSuffix}`;
}
if (element) {
cls += `__${element}`;
}
if (modifier) {
cls += `--${modifier}`;
}
return cls;
};
var namespaceContextKey = Symbol("localContextKey");
var useGetDerivedNamespace = () => {
const derivedNamespace = inject(namespaceContextKey, ref(defaultNamespace));
const namespace = computed(() => {
return unref(derivedNamespace) || defaultNamespace;
});
return namespace;
};
var useNamespace = (block) => {
const namespace = useGetDerivedNamespace();
const b = (blockSuffix = "") => _bem(namespace.value, block, blockSuffix, "", "");
const e = (element) => element ? _bem(namespace.value, block, "", element, "") : "";
const m = (modifier) => modifier ? _bem(namespace.value, block, "", "", modifier) : "";
const be = (blockSuffix, element) => blockSuffix && element ? _bem(namespace.value, block, blockSuffix, element, "") : "";
const em = (element, modifier) => element && modifier ? _bem(namespace.value, block, "", element, modifier) : "";
const bm = (blockSuffix, modifier) => blockSuffix && modifier ? _bem(namespace.value, block, blockSuffix, "", modifier) : "";
const bem = (blockSuffix, element, modifier) => blockSuffix && element && modifier ? _bem(namespace.value, block, blockSuffix, element, modifier) : "";
const is = (name, ...args) => {
const state = args.length >= 1 ? args[0] : true;
return name && state ? `is-${name}` : "";
};
const cssVar = (object) => {
const styles = {};
for (const key in object) {
if (object[key]) {
styles[`--${namespace.value}-${key}`] = object[key];
}
}
return styles;
};
const cssVarBlock = (object) => {
const styles = {};
for (const key in object) {
if (object[key]) {
styles[`--${namespace.value}-${block}-${key}`] = object[key];
}
}
return styles;
};
const cssVarName = (name) => `--${namespace.value}-${name}`;
const cssVarBlockName = (name) => `--${namespace.value}-${block}-${name}`;
return {
namespace,
b,
e,
m,
be,
em,
bm,
bem,
is,
// css
cssVar,
cssVarName,
cssVarBlock,
cssVarBlockName
};
};
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-component-color/index.ts
import { ref as ref2, watch } from "vue";
var useComponentColor = (prop, type = "") => {
const classColor = ref2("");
const styleColor = ref2("");
const innerColorReg = /^(tn-|gradient)/;
const styleColorReg = /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{8}|[A-Fa-f0-9]{3})$|^rgb\(\d{1,3}(,\s?\d{1,3}){2}\)$|^rgba\(\d{1,3}(,\s?\d{1,3}){2},\s?0?\.?\d{1,}\)|transparent/i;
const handleColorValue = (value) => {
classColor.value = "";
styleColor.value = "";
if (value === void 0)
return;
if (innerColorReg.test(value)) {
if (type === "bg" && /.*gradient.*/.test(value)) {
const gradientValue = value.split("__")[1];
classColor.value = `tn-gradient-bg__${gradientValue}`;
return;
}
classColor.value = `${value}_${type}`;
}
if (styleColorReg.test(value)) {
styleColor.value = value;
}
};
handleColorValue(prop.value);
watch(
() => prop.value,
(val) => {
handleColorValue(val);
}
);
const updateColor = (value) => {
handleColorValue(value);
};
return [classColor, styleColor, updateColor];
};
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-component-size/index.ts
import { computed as computed2 } from "vue";
// node_modules/@tuniao/tnui-vue3-uniapp/constants/size.ts
var componentSizes = ["", "sm", "lg", "xl"];
// node_modules/@tuniao/tnui-vue3-uniapp/constants/key.ts
var INSTALLED_KEY = Symbol("INSTALLED_KEY");
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-component-size/index.ts
var componentSizeTypes = ["none", "inner", "custom"];
var useComponentSize = (size) => {
const sizeType = computed2(() => {
if (!size)
return "none";
return componentSizes.includes(size) ? "inner" : "custom";
});
return {
sizeType
};
};
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-prop/index.ts
import { computed as computed3, getCurrentInstance } from "vue";
var useProp = (name) => {
const vm = getCurrentInstance();
return computed3(
() => {
var _a;
return isEmptyVariableInDefault((_a = vm == null ? void 0 : vm.proxy) == null ? void 0 : _a.$props)[name];
}
);
};
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-selector-query/index.ts
import { getCurrentInstance as getCurrentInstance2 } from "vue";
var useSelectorQuery = (instance) => {
let query = null;
if (!instance) {
instance = getCurrentInstance2();
}
if (!instance) {
debugWarn("useSelectorQuery", "useSelectorQuery必须在setup函数中使用");
}
query = uni.createSelectorQuery().in(instance);
const getSelectorNodeInfo = (selector) => {
return new Promise((resolve, reject) => {
if (query) {
query.select(selector).boundingClientRect((res) => {
const selectRes = res;
if (selectRes) {
resolve(selectRes);
} else {
reject(new Error(`未找到对应节点: ${selector}`));
}
}).exec();
} else {
reject(new Error("未找到对应的SelectorQuery实例"));
}
});
};
const getSelectorNodeInfos = (selector) => {
return new Promise((resolve, reject) => {
if (query) {
query.selectAll(selector).boundingClientRect((res) => {
const selectRes = res;
if (selectRes && selectRes.length > 0) {
resolve(selectRes);
} else {
reject(new Error(`未找到对应节点: ${selector}`));
}
}).exec();
} else {
reject(new Error("未找到对应的SelectorQuery实例"));
}
});
};
return {
query,
getSelectorNodeInfo,
getSelectorNodeInfos
};
};
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-toggle/index.ts
import { ref as ref3 } from "vue";
var useToggle = (initState) => {
const state = ref3(initState);
const toggle = () => {
state.value = !state.value;
};
return [state, toggle];
};
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-touch/index.ts
import { ref as ref4 } from "vue";
var useTouch = () => {
const options = {
disabled: false,
left: 0,
right: 0,
top: 0,
bottom: 0,
faultTolerance: 10
};
const startX = ref4(0);
const startY = ref4(0);
const currentX = ref4(0);
const currentY = ref4(0);
const deltaX = ref4(0);
const deltaY = ref4(0);
const distanceX = ref4(0);
const distanceY = ref4(0);
const isVertical = ref4(false);
const isHorizontal = ref4(false);
const isClick = ref4(false);
let touchFlag;
const updateOptions = (newOptions) => {
Object.assign(options, newOptions);
};
const onTouchStart = (event) => {
if (options.disabled || !event.changedTouches[0])
return;
startX.value = _edgeProcessing(event.changedTouches[0].pageX, "x");
startY.value = _edgeProcessing(event.changedTouches[0].pageY, "y");
touchFlag = "touch";
};
const onTouchMove = (event) => {
if (options.disabled || !event.changedTouches[0])
return;
currentX.value = _edgeProcessing(event.changedTouches[0].pageX, "x");
currentY.value = _edgeProcessing(event.changedTouches[0].pageY, "y");
updateDistanceInfo();
touchFlag = "moving";
};
const onTouchEnd = (event) => {
if (options.disabled || !event.changedTouches[0] || touchFlag === "end")
return;
currentX.value = _edgeProcessing(event.changedTouches[0].pageX, "x");
currentY.value = _edgeProcessing(event.changedTouches[0].pageY, "y");
updateDistanceInfo();
isVertical.value = distanceX.value < options.faultTolerance && distanceY.value >= options.faultTolerance;
isHorizontal.value = distanceX.value >= options.faultTolerance && distanceY.value < options.faultTolerance;
isClick.value = !isHorizontal.value && !isVertical.value;
touchFlag = "end";
};
const updateDistanceInfo = () => {
deltaX.value = currentX.value - startX.value;
deltaY.value = currentY.value - startY.value;
distanceX.value = Math.abs(deltaX.value);
distanceY.value = Math.abs(deltaY.value);
};
const _edgeProcessing = (touchPosition, direction) => {
const { left, right, top, bottom } = options;
if (direction === "x") {
if (touchPosition < left)
return 0;
if (touchPosition > right)
return right - left;
return touchPosition - left;
} else {
if (touchPosition < top)
return 0;
if (touchPosition > bottom)
return bottom - top;
return touchPosition - top;
}
};
return {
startX,
startY,
currentX,
currentY,
deltaX,
deltaY,
distanceX,
distanceY,
isVertical,
isHorizontal,
isClick,
updateOptions,
onTouchStart,
onTouchMove,
onTouchEnd
};
};
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-uniapp-system-rect-info/index.ts
import { reactive } from "vue";
var DEFAULT_STATUS_BAR_HEIGHT = 45;
var DEFAULT_NAVBAR_BOUNDING_WIDTH = 87;
var DEFAULT_NAVBAR_BOUNDING_HEIGHT = 32;
var DEFAULT_NAVBAR_BOUNDING_RIGHT = 7;
var DEFAULT_NAVBAR_BOUNDING_TOP = 4;
var useUniAppSystemRectInfo = () => {
const navBarInfo = reactive({
height: 0,
statusHeight: DEFAULT_STATUS_BAR_HEIGHT
});
const navBarBoundingInfo = reactive({
width: 0,
height: 32,
top: 0,
right: 0,
bottom: 0,
left: 0,
marginRight: 0
});
const systemScreenInfo = reactive({
width: 0,
height: 0,
operationHeight: 0
});
const getSystemRectInfo = () => {
try {
const uniSystemInfo = uni.getSystemInfoSync();
const { statusBarHeight, windowWidth, windowHeight, titleBarHeight } = uniSystemInfo;
let height = 0;
height = (statusBarHeight || 0) + DEFAULT_STATUS_BAR_HEIGHT;
navBarBoundingInfo.width = DEFAULT_NAVBAR_BOUNDING_WIDTH;
navBarBoundingInfo.height = DEFAULT_NAVBAR_BOUNDING_HEIGHT;
navBarBoundingInfo.right = windowWidth - DEFAULT_NAVBAR_BOUNDING_RIGHT;
navBarBoundingInfo.left = windowWidth - DEFAULT_NAVBAR_BOUNDING_RIGHT - DEFAULT_NAVBAR_BOUNDING_WIDTH;
navBarBoundingInfo.top = DEFAULT_NAVBAR_BOUNDING_TOP;
navBarBoundingInfo.bottom = DEFAULT_NAVBAR_BOUNDING_TOP + DEFAULT_NAVBAR_BOUNDING_HEIGHT;
navBarBoundingInfo.marginRight = DEFAULT_NAVBAR_BOUNDING_RIGHT;
navBarInfo.height = height;
navBarInfo.statusHeight = statusBarHeight;
systemScreenInfo.width = windowWidth;
systemScreenInfo.height = windowHeight;
systemScreenInfo.operationHeight = windowHeight - height;
} catch (err) {
debugWarn(
"useUniAppSystemRectInfo",
`[TnGetSystemRectInfo]获取系统容器信息失败: ${err}`
);
}
};
getSystemRectInfo();
return {
navBarInfo,
navBarBoundingInfo,
systemScreenInfo,
getSystemRectInfo
};
};
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-z-index/index.ts
import { computed as computed4, inject as inject2, ref as ref5, unref as unref2 } from "vue";
var zIndex = ref5(0);
var defaultInitialZIndex = 2e3;
var zIndexContextKey = Symbol("zIndexContextKey");
var useZIndex = () => {
const zIndexInjection = inject2(zIndexContextKey, void 0);
const initialZIndex = computed4(() => {
const zIndexFromInjection = unref2(zIndexInjection);
return isNumber(zIndexFromInjection) ? zIndexFromInjection : defaultInitialZIndex;
});
const currentZIndex = computed4(() => initialZIndex.value + zIndex.value);
const nextZIndex = () => {
zIndex.value++;
return currentZIndex.value;
};
const prevZIndex = () => {
zIndex.value--;
return currentZIndex.value;
};
return {
initialZIndex,
currentZIndex,
nextZIndex,
prevZIndex
};
};
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-ordered-children/index.ts
import { shallowRef } from "vue";
var useOrderedChildren = () => {
const children = {};
const orderedChildren = shallowRef([]);
const addChild = (child) => {
children[child.uid] = child;
orderedChildren.value.push(child);
};
const removeChild = (uid) => {
delete children[uid];
orderedChildren.value = orderedChildren.value.filter(
(child) => child.uid !== uid
);
};
return {
children: orderedChildren,
addChild,
removeChild
};
};
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-observer/index.ts
import { getCurrentInstance as getCurrentInstance3 } from "vue";
var useObserver = (instance) => {
var _a;
if (!instance) {
instance = getCurrentInstance3();
}
instance = (_a = instance == null ? void 0 : instance.proxy) == null ? void 0 : _a.$parent;
if (!instance) {
debugWarn("useObserver", "请在 setup 中使用 useObserver");
}
let observerInstance = null;
const connectObserver = (selector, fn, fnOptions, options) => {
disconnectObserver();
observerInstance = uni.createIntersectionObserver(instance, options);
if (fnOptions.type === "relativeTo")
observerInstance.relativeTo((fnOptions == null ? void 0 : fnOptions.selector) || "", fnOptions.margins);
else if (fnOptions.type === "relativeToViewport")
observerInstance.relativeToViewport(fnOptions.margins);
observerInstance.observe(selector, (res) => {
fn && fn(res);
});
};
const disconnectObserver = () => {
if (observerInstance) {
observerInstance.disconnect();
observerInstance = null;
}
};
return {
connectObserver,
disconnectObserver
};
};
// node_modules/@tuniao/tnui-vue3-uniapp/hooks/use-long-press/index.ts
var useLongPress = (event, enabled, longPressIntervel = 250) => {
let longPressTimer = null;
const clearLongPressTimer = () => {
if (longPressTimer) {
clearInterval(longPressTimer);
longPressTimer = null;
}
};
const handleLongPressEvent = (...args) => {
if (enabled.value) {
event(...args);
clearLongPressTimer();
longPressTimer = setInterval(() => {
event(...args);
}, longPressIntervel);
} else {
event(...args);
}
};
return {
handleLongPressEvent,
clearLongPressTimer
};
};
export {
componentSizeTypes,
defaultNamespace,
namespaceContextKey,
useComponentColor,
useComponentSize,
useGetDerivedNamespace,
useLongPress,
useNamespace,
useObserver,
useOrderedChildren,
useProp,
useSelectorQuery,
useToggle,
useTouch,
useUniAppSystemRectInfo,
useZIndex,
zIndexContextKey
};
//# sourceMappingURL=@tuniao_tnui-vue3-uniapp_hooks.js.map