@wzyjs/utils 0.0.15 → 0.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,3 +3,4 @@ export { cloneDeep, debounce, isBoolean, isEqual, isFunction, isNumber, isObject
3
3
  export * as consola from 'consola';
4
4
  export * from './tools';
5
5
  export * from './types';
6
+ export { default as lodash } from 'lodash';
@@ -0,0 +1,2 @@
1
+ import dayjs from 'dayjs';
2
+ export default dayjs;
@@ -0,0 +1,9 @@
1
+ export declare const scrollIntoView: (el: Element, option?: ScrollIntoViewOptions) => void;
2
+ export declare const getElement: (el: string | Element) => {
3
+ element: null;
4
+ originalStyle: {};
5
+ } | {
6
+ element: Element;
7
+ originalStyle: CSSStyleDeclaration;
8
+ };
9
+ export declare const isElementInViewport: (el: string | Element) => boolean | undefined;
@@ -1,8 +1,8 @@
1
1
  import md5 from 'md5';
2
- import dayjs from 'dayjs';
3
2
  import classnames from 'classnames';
4
3
  import copy from 'copy-to-clipboard';
5
- export { copy, classnames, dayjs, md5 };
4
+ import anime from 'animejs';
5
+ export { copy, classnames, md5, anime };
6
6
  export declare const localforage: {
7
7
  config: {
8
8
  (options: LocalForageOptions): boolean;
@@ -13,3 +13,6 @@ export declare const localforage: {
13
13
  getItem: <T_1>(key: string, callback?: ((err: any, value: T_1 | null) => void) | undefined) => Promise<T_1 | null>;
14
14
  removeItem: (key: string, callback?: ((err: any) => void) | undefined) => Promise<void>;
15
15
  };
16
+ export * from './style';
17
+ export * from './element';
18
+ export { default as dayjs } from './dayjs';
@@ -0,0 +1,10 @@
1
+ export declare const hexToRgba: (hexColor: string, a?: number) => {
2
+ nums: {
3
+ red: number;
4
+ green: number;
5
+ blue: number;
6
+ };
7
+ text: string;
8
+ };
9
+ export declare const flashBackground: (el: string | Element, color: string, a?: number) => void;
10
+ export declare const flashBorder: (el: string | Element, color: string, a?: number) => void;
@@ -68,6 +68,7 @@ Object.defineProperty(exports, 'isString', {
68
68
  enumerable: true,
69
69
  get: function () { return lodash.isString; }
70
70
  });
71
+ exports.lodash = lodash;
71
72
  Object.defineProperty(exports, 'merge', {
72
73
  enumerable: true,
73
74
  get: function () { return lodash.merge; }
@@ -3,3 +3,4 @@ export { cloneDeep, debounce, isBoolean, isEqual, isFunction, isNumber, isObject
3
3
  export * as consola from 'consola';
4
4
  export * from './tools';
5
5
  export * from './types';
6
+ export { default as lodash } from 'lodash';
@@ -0,0 +1,2 @@
1
+ import dayjs from 'dayjs';
2
+ export default dayjs;
@@ -0,0 +1,9 @@
1
+ import dayjs from 'dayjs';
2
+ export { default } from 'dayjs';
3
+ import isBetween from 'dayjs/plugin/isBetween';
4
+ import weekday from 'dayjs/plugin/weekday';
5
+ import localeData from 'dayjs/plugin/localeData';
6
+
7
+ dayjs.extend(isBetween);
8
+ dayjs.extend(weekday);
9
+ dayjs.extend(localeData);
@@ -0,0 +1,9 @@
1
+ export declare const scrollIntoView: (el: Element, option?: ScrollIntoViewOptions) => void;
2
+ export declare const getElement: (el: string | Element) => {
3
+ element: null;
4
+ originalStyle: {};
5
+ } | {
6
+ element: Element;
7
+ originalStyle: CSSStyleDeclaration;
8
+ };
9
+ export declare const isElementInViewport: (el: string | Element) => boolean | undefined;
@@ -0,0 +1,36 @@
1
+ // 滚动到让指定元素显示出来的位置
2
+ const scrollIntoView = (el, option) => {
3
+ if (!el) {
4
+ return;
5
+ }
6
+ el.scrollIntoView({ behavior: 'smooth', block: 'start', ...option });
7
+ };
8
+ // 获取指定元素 已经元素原始的样式
9
+ const getElement = (el) => {
10
+ const element = typeof el === 'string' ? document.querySelector(el) : el;
11
+ if (!element) {
12
+ return {
13
+ element: null,
14
+ originalStyle: {},
15
+ };
16
+ }
17
+ // 获取元素原始的样式
18
+ return {
19
+ element,
20
+ originalStyle: window.getComputedStyle(element),
21
+ };
22
+ };
23
+ // 判断元素是否在可见范围内
24
+ const isElementInViewport = (el) => {
25
+ const { element } = getElement(el);
26
+ if (!element) {
27
+ return;
28
+ }
29
+ const rect = element.getBoundingClientRect();
30
+ return (rect.top >= 0 &&
31
+ rect.left >= 0 &&
32
+ rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
33
+ rect.right <= (window.innerWidth || document.documentElement.clientWidth));
34
+ };
35
+
36
+ export { getElement, isElementInViewport, scrollIntoView };
@@ -1,8 +1,8 @@
1
1
  import md5 from 'md5';
2
- import dayjs from 'dayjs';
3
2
  import classnames from 'classnames';
4
3
  import copy from 'copy-to-clipboard';
5
- export { copy, classnames, dayjs, md5 };
4
+ import anime from 'animejs';
5
+ export { copy, classnames, md5, anime };
6
6
  export declare const localforage: {
7
7
  config: {
8
8
  (options: LocalForageOptions): boolean;
@@ -13,3 +13,6 @@ export declare const localforage: {
13
13
  getItem: <T_1>(key: string, callback?: ((err: any, value: T_1 | null) => void) | undefined) => Promise<T_1 | null>;
14
14
  removeItem: (key: string, callback?: ((err: any) => void) | undefined) => Promise<void>;
15
15
  };
16
+ export * from './style';
17
+ export * from './element';
18
+ export { default as dayjs } from './dayjs';
@@ -1,8 +1,9 @@
1
1
  export { default as md5 } from 'md5';
2
- export { default as dayjs } from 'dayjs';
3
2
  export { default as classnames } from 'classnames';
4
3
  export { default as copy } from 'copy-to-clipboard';
5
4
  import { config, setItem, getItem, removeItem } from 'localforage';
5
+ export { default as anime } from 'animejs';
6
+ import './dayjs.js';
6
7
 
7
8
  const localforage = {
8
9
  config,
@@ -0,0 +1,10 @@
1
+ export declare const hexToRgba: (hexColor: string, a?: number) => {
2
+ nums: {
3
+ red: number;
4
+ green: number;
5
+ blue: number;
6
+ };
7
+ text: string;
8
+ };
9
+ export declare const flashBackground: (el: string | Element, color: string, a?: number) => void;
10
+ export declare const flashBorder: (el: string | Element, color: string, a?: number) => void;
@@ -0,0 +1,45 @@
1
+ import anime from 'animejs';
2
+ import { getElement } from './element.js';
3
+
4
+ // 颜色值转换
5
+ const hexToRgba = (hexColor, a = 1) => {
6
+ let red = parseInt(hexColor.substr(1, 2), 16);
7
+ let green = parseInt(hexColor.substr(3, 2), 16);
8
+ let blue = parseInt(hexColor.substr(5, 2), 16);
9
+ return {
10
+ nums: { red, green, blue },
11
+ text: `rgba(${red}, ${green}, ${blue}, ${a})`,
12
+ };
13
+ };
14
+ // 背景颜色闪动
15
+ const flashBackground = (el, color, a = 1) => {
16
+ const { element, originalStyle } = getElement(el);
17
+ if (!element) {
18
+ return;
19
+ }
20
+ anime({
21
+ targets: element,
22
+ backgroundColor: [hexToRgba(color, a).text, originalStyle.backgroundColor],
23
+ duration: 1500,
24
+ easing: 'easeInOutSine',
25
+ direction: 'alternate',
26
+ loop: false,
27
+ });
28
+ };
29
+ // 边框闪动
30
+ const flashBorder = (el, color, a = 1) => {
31
+ const { element } = getElement(el);
32
+ if (!element) {
33
+ return;
34
+ }
35
+ anime({
36
+ targets: element,
37
+ border: [`1px solid ${hexToRgba(color, a).text}`, 'none'],
38
+ duration: 1500,
39
+ easing: 'easeInOutSine',
40
+ direction: 'alternate',
41
+ loop: false,
42
+ });
43
+ };
44
+
45
+ export { flashBackground, flashBorder, hexToRgba };
package/dist/esm/index.js CHANGED
@@ -1,11 +1,15 @@
1
- export { cloneDeep, debounce, isBoolean, isEmpty, isEqual, isError, isFunction, isNumber, isObject, isString, merge, omit, pick, uniq, uniqBy, uniqWith } from 'lodash';
1
+ export { cloneDeep, debounce, isBoolean, isEmpty, isEqual, isError, isFunction, isNumber, isObject, isString, default as lodash, merge, omit, pick, uniq, uniqBy, uniqWith } from 'lodash';
2
2
  import * as consola from 'consola';
3
3
  export { consola };
4
4
  export { getChineseByStr, getStrLength, jsonParse, replaceAll, replaceByRules } from './common/tools/string.js';
5
5
  export { checkAttr } from './common/tools/object.js';
6
6
  export { executePromise, handleParams, handleRes2List } from './common/tools/other.js';
7
7
  export { localforage } from './fe/index.js';
8
+ import './fe/dayjs.js';
9
+ export { default as dayjs } from 'dayjs';
10
+ export { flashBackground, flashBorder, hexToRgba } from './fe/style.js';
11
+ export { getElement, isElementInViewport, scrollIntoView } from './fe/element.js';
8
12
  export { default as copy } from 'copy-to-clipboard';
9
13
  export { default as classnames } from 'classnames';
10
- export { default as dayjs } from 'dayjs';
11
14
  export { default as md5 } from 'md5';
15
+ export { default as anime } from 'animejs';
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@wzyjs/utils",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "description",
5
5
  "author": "wzy",
6
6
  "license": "ISC",
7
7
  "main": "dist/cjs/index_c.js",
8
8
  "module": "dist/esm/index.js",
9
- "typings": "dist/esm/index.d.ts",
9
+ "typings": "dist/cjs/index_c.d.ts",
10
10
  "scripts": {
11
11
  "dev": "rollup -c -w --bundleConfigAsCjs",
12
12
  "build": "rollup -c --bundleConfigAsCjs"
@@ -16,6 +16,8 @@
16
16
  ],
17
17
  "dependencies": {
18
18
  "@cloudbase/node-sdk": "^2.9.1",
19
+ "@types/animejs": "^3.1.6",
20
+ "animejs": "^3.2.1",
19
21
  "classnames": "^2.3.2",
20
22
  "consola": "^2.15.3",
21
23
  "copy-to-clipboard": "^3.3.3",
@@ -42,5 +44,5 @@
42
44
  "type": "git",
43
45
  "url": "https://gitee.com/wang-zhenyu/app.git"
44
46
  },
45
- "gitHead": "49f41af470bbc27eb90b4d15bf170d79bf6f9529"
47
+ "gitHead": "f07be747da894f607f30c2be97c23abac5712bc2"
46
48
  }