test02/node_modules/@vuepress/theme-default/lib/client/composables/useUpdateDeviceStatus.js
罗佳鸿 6aa1ebe342
Some checks are pending
部署文档 / deploy-gh-pages (push) Waiting to run
first commit
2024-08-13 10:11:19 +08:00

27 lines
891 B
JavaScript

import { useEventListener } from '@vueuse/core';
import { onMounted } from 'vue';
import cssVariables from '../styles/_variables.module.scss';
export var DeviceType;
(function (DeviceType) {
DeviceType["MOBILE"] = "mobile";
})(DeviceType || (DeviceType = {}));
const DeviceTypeMap = {
[DeviceType.MOBILE]: Number.parseInt(cssVariables.mobile.replace('px', ''), 10),
};
/**
* add listener to detect screen though device type
*/
export const useUpdateDeviceStatus = (deviceType, callback) => {
const width = DeviceTypeMap[deviceType];
if (!Number.isInteger(width)) {
if (__VUEPRESS_DEV__)
throw new Error('device width must be a integer');
return;
}
useEventListener('orientationchange', () => callback(width), false);
useEventListener('resize', () => callback(width), false);
onMounted(() => {
callback(width);
});
};