@bestime/utils_browser 1.0.1 → 1.0.2
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.
|
@@ -14,6 +14,148 @@ declare function getWindowSize(): {
|
|
|
14
14
|
*/
|
|
15
15
|
declare function addClass(el: HTMLElement, name: string | string[]): void;
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* 监听DOM尺寸变化
|
|
19
|
+
* @param element - dom元素
|
|
20
|
+
* @param handler - 变换回调函数
|
|
21
|
+
* @param type - 监听类型。默认width+height
|
|
22
|
+
* @param interval - 多久检查一次。默认值:500
|
|
23
|
+
* @returns 销毁方法
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
declare function observeDomResize(
|
|
27
|
+
element: HTMLElement,
|
|
28
|
+
handler: (element: HTMLElement) => void,
|
|
29
|
+
type?: ('width' | 'height' | 'position')[],
|
|
30
|
+
interval?: number
|
|
31
|
+
): () => void;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 下载 url 文件
|
|
35
|
+
* @param url - 文件地址
|
|
36
|
+
* @param fileName - 文件名
|
|
37
|
+
*/
|
|
38
|
+
declare function downloadFileByUrl(url: string, fileName: string): void;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 下载ArrayBuffer文件
|
|
42
|
+
* @param data - ArrayBuffer格式的数据
|
|
43
|
+
* @param fileName - 文件名
|
|
44
|
+
*/
|
|
45
|
+
declare function downloadFileByArrayBuffer(data: ArrayBuffer, fileName: string): void;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 移除Dom节点
|
|
49
|
+
* @param dom - 待移除的dom元素
|
|
50
|
+
*/
|
|
51
|
+
declare function removeElement(el: HTMLElement): void;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 移除Dom节点
|
|
55
|
+
* @param ev - 事件
|
|
56
|
+
* @param bubble - 阻止冒泡. 默认 true
|
|
57
|
+
* @param stop - 阻止穿透. 默认 true
|
|
58
|
+
*/
|
|
59
|
+
declare function prevent(ev: Event, bubble: boolean, stop: boolean): void;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param key - 获取的键
|
|
63
|
+
* @returns 保存的值
|
|
64
|
+
*/
|
|
65
|
+
declare function getStorage(key: string): string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param key - 删除的键
|
|
69
|
+
* @returns 保存的值
|
|
70
|
+
*/
|
|
71
|
+
declare function removeStorage(key: string): void;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 设置localstorage
|
|
75
|
+
* @param key - 保存的键
|
|
76
|
+
* @param value - 保存的值
|
|
77
|
+
*/
|
|
78
|
+
declare function setStorage(key: string, value: any): void;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 获取dom相对位置
|
|
82
|
+
* @param el - dom
|
|
83
|
+
* @returns 信息
|
|
84
|
+
*/
|
|
85
|
+
declare function getRelativePos(el: HTMLElement): {
|
|
86
|
+
x: number;
|
|
87
|
+
y: number;
|
|
88
|
+
height: number;
|
|
89
|
+
width: number;
|
|
90
|
+
clientWidth: number;
|
|
91
|
+
clientHeight: number;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 获取当前js所在路径
|
|
96
|
+
* @param tir - 向上取几级目录,默认0,当前目录
|
|
97
|
+
* @returns 相对路径
|
|
98
|
+
*/
|
|
99
|
+
declare function getJsFileBaseUrl(tir: number): string;
|
|
100
|
+
|
|
101
|
+
interface LibraryFileConfig {
|
|
102
|
+
type: 'js' | 'css';
|
|
103
|
+
url: string;
|
|
104
|
+
module: string;
|
|
105
|
+
dependencies?: LibraryFileConfig[];
|
|
106
|
+
with?: LibraryFileConfig[];
|
|
107
|
+
attribute?: Record<string, string>;
|
|
108
|
+
}
|
|
109
|
+
type SuccessCallback = (...args: any[]) => void;
|
|
110
|
+
/**
|
|
111
|
+
* js和css文件加载器
|
|
112
|
+
* @param files - 文件配置
|
|
113
|
+
* @param callback - 加载成功回调
|
|
114
|
+
*/
|
|
115
|
+
declare function libraryFile(
|
|
116
|
+
files: LibraryFileConfig | LibraryFileConfig[],
|
|
117
|
+
callback: SuccessCallback
|
|
118
|
+
): void;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 设置cookie。默认path="/"
|
|
122
|
+
* @param key - 设置的键名
|
|
123
|
+
* @param value - 设置的值
|
|
124
|
+
* @param expiredTime - 单位(毫秒)
|
|
125
|
+
*/
|
|
126
|
+
declare function setCookie(key: string, value: string, expiredTime?: number): void;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param key - 获取的键
|
|
130
|
+
* @param target - 来源,默认document.cookie
|
|
131
|
+
* @returns 保存的值
|
|
132
|
+
*/
|
|
133
|
+
declare function getCookie(key: string, target?: string): string;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 删除cookie
|
|
137
|
+
*
|
|
138
|
+
* @param key - 键名
|
|
139
|
+
*/
|
|
140
|
+
declare function removeCookie(key: string): void;
|
|
141
|
+
|
|
142
|
+
export {
|
|
143
|
+
addClass,
|
|
144
|
+
downloadFileByArrayBuffer,
|
|
145
|
+
downloadFileByUrl,
|
|
146
|
+
getCookie,
|
|
147
|
+
getJsFileBaseUrl,
|
|
148
|
+
getRelativePos,
|
|
149
|
+
getStorage,
|
|
150
|
+
getWindowSize,
|
|
151
|
+
libraryFile,
|
|
152
|
+
observeDomResize,
|
|
153
|
+
prevent,
|
|
154
|
+
removeCookie,
|
|
155
|
+
removeElement,
|
|
156
|
+
removeStorage,
|
|
157
|
+
setCookie,
|
|
158
|
+
setStorage
|
|
159
|
+
};
|
|
18
160
|
|
|
19
161
|
export default undefined;
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* @QQ 1174295440
|
|
4
4
|
* @author Bestime
|
|
5
5
|
* @see https://github.com/bestime/tool
|
|
6
|
-
* @update 2023-11-05
|
|
6
|
+
* @update 2023-11-05 17:29:17
|
|
7
7
|
*/
|
|
8
|
-
import{isArray,forEach}from"@bestime/utils_base";function getWindowSize(){return{width:document.documentElement.clientWidth||document.body.clientWidth||window.innerWidth||0,height:document.documentElement.clientHeight||document.body.clientHeight||window.innerHeight||0}}function addClass(i,t){
|
|
8
|
+
import{isArray,forEach,defaultValue,isString,variableHasValue}from"@bestime/utils_base";function getWindowSize(){return{width:document.documentElement.clientWidth||document.body.clientWidth||window.innerWidth||0,height:document.documentElement.clientHeight||document.body.clientHeight||window.innerHeight||0}}function addClass(t,e){isArray(e)?forEach(e,function(e){t.classList.add(e)}):t.classList.add(e)}var timer,htivId=0,idName="",isStart=!1,records={};function stop(){isStart=!1,clearInterval(timer),timer=undefined}function startRun(){clearInterval(timer),isStart=!0,timer=setInterval(function(){for(var e in records){var t=records[e];t.current=+new Date,t.current-t.start>=t.interval&&(t.start=t.current,records[e].handler())}},17)}function add(e,t){return idName="HI-"+ ++htivId,records[idName]={start:+new Date,current:0,handler:e,interval:t},isStart||startRun(),idName}function remove(e){delete records[e],0===Object.keys(records).length&&stop()}var hpInterval={add:add,remove:remove};function observeDomResize(n,o,r,e){var i=[0,0,!1],l=[0,0,!1],a=[0,0,!1],d=[0,0,!1],t=hpInterval.add(c,e=e||500);function c(){var e,t;document.body.contains(n)?(e=!1,null!=r&&r.includes("position")&&(t=n.getBoundingClientRect(),a[0]=t.left,a[2]=a[0]!==a[1],d[0]=t.top,d[2]=d[0]!==d[1]),i[0]=n.offsetWidth,i[2]=i[0]!==i[1],l[0]=n.offsetHeight,l[2]=l[0]!==l[1],i[2]&&(i[1]=i[0],null!=r&&r.includes("width")&&(e=!0)),l[2]&&(l[1]=l[0],null!=r&&r.includes("height")&&(e=!0)),(d[2]||a[2])&&(d[1]=d[0],a[1]=a[0],null!=r&&r.includes("position")&&(e=!0)),r&&0!==r.length||(i[2]||l[2]||d[2]||a[2])&&(e=!0),e&&o(n)):u()}function u(){hpInterval.remove(t),i=undefined,l=undefined}return c(),u}function downloadFileByUrl(e,t){var n=document.createElement("a");n.style.display="none",n.download=t,n.setAttribute("href",e),n.setAttribute("target","_blank"),n.setAttribute("download",t),document.body.appendChild(n),n.click(),n.remove()}var $undefinedValue=void 0,$decodeURIComponent=decodeURIComponent,$isBroswer="undefined"!=typeof document&&document.getElementById!==undefined,$browserGlobal="undefined"!=typeof window?window:$undefinedValue,$headElement=$isBroswer?document.getElementsByTagName("head")[0]:undefined;function downloadFileByArrayBuffer(e,t){var n;$isBroswer&&(downloadFileByUrl(e=(n=$browserGlobal.URL).createObjectURL(new Blob([e])),t),n.revokeObjectURL(e),undefined)}function removeElement(e){e.parentNode&&e.parentNode.removeChild(e)}function prevent(e,t,n){$isBroswer&&(e=e||$browserGlobal.event,n=!1!==n,(t=!1!==t)&&$browserGlobal.event?$browserGlobal.event.cancelBubble=!0:e.stopPropagation(),n&&$browserGlobal.event?$browserGlobal.event.returnValue=!1:e.preventDefault())}function getStorage(e){e=localStorage.getItem(e);return defaultValue(e,"")}function removeStorage(e){localStorage.removeItem(e)}function hpSetStringValue(e){return e=isString(e)?e:JSON.stringify(e)}function setStorage(e,t){localStorage.setItem(e,hpSetStringValue(t))}function getRelativePos(e){var t=e.getBoundingClientRect();return{x:t.left,y:t.top,height:e.offsetHeight,width:e.offsetWidth,clientWidth:e.clientWidth,clientHeight:e.clientHeight}}function getJsFileBaseUrl(e){e=e||0;for(var t="/[^/]*",n=document.scripts,o=0;o<e;o++)t+=t;return n[n.length-1].src.replace(new RegExp(t+"$"),"")}function hpCreateFileLoaderElement(e,t,n,o){if($headElement){var r;if("js"===e?(r=document.createElement("script")).src=t:((r=document.createElement("link")).setAttribute("rel","stylesheet"),r.href=t),o)for(var i in o)r.setAttribute(i,o[i]);r.onload=r.onerror=n,$headElement.appendChild(r)}}var cache={};function loadMultiple(n,o){for(var r=[],i=0,e=0;e<n.length;e++)!function(t){loadSingle(n[t],function(e){r[t]=e,++i===n.length&&o.apply($undefinedValue,r)})}(e)}function loadSingle(e,t){var n=e.dependencies&&e.dependencies.length,o=e["with"]&&e["with"].length,r=(cache[e.url]||(cache[e.url]={count:0,dependencies:!n,"with":!o,complete:!1,create:!1,url:e.url}),cache[e.url]);function i(){r.complete&&r.dependencies&&r["with"]&&(e.module?t($browserGlobal[e.module]):t())}r.count++,!r.dependencies&&n?(r.dependencies=!0,loadMultiple(e.dependencies,function(){loadSingle(e,t)})):!r["with"]&&o?(r["with"]=!0,loadMultiple(e["with"].concat(e),i)):r.create?variableHasValue(function(){return r.complete},i,300):(r.create=!0,hpCreateFileLoaderElement(e.type,e.url,function(){r.complete=!0,i()},e.attribute))}function libraryFile(e,t){console.log("加载器",e,cache),(e instanceof Array?loadMultiple:loadSingle)(e,t)}function setObjectToString(e){return e=isString(e)?e:JSON.stringify(e)}function setCookie(e,t,n){t=setObjectToString(t);e=e+"="+encodeURI(t)+";path=/;";"number"==typeof n&&((t=new Date).setTime(t.getTime()+n),e+="expires="+t.toUTCString()),document.cookie=e}function getCookie(e,t){t=t||document.cookie;var o="";return t.replace(new RegExp("(^|;\\s)"+e+"=(.*?)($|(;\\s))"),function(e,t,n){o=$decodeURIComponent(n)}),o}function removeCookie(e){setCookie(e,"",-1)}export{addClass,downloadFileByArrayBuffer,downloadFileByUrl,getCookie,getJsFileBaseUrl,getRelativePos,getStorage,getWindowSize,libraryFile,observeDomResize,prevent,removeCookie,removeElement,removeStorage,setCookie,setStorage};
|
|
@@ -14,12 +14,154 @@ declare function getWindowSize(): {
|
|
|
14
14
|
*/
|
|
15
15
|
declare function addClass(el: HTMLElement, name: string | string[]): void;
|
|
16
16
|
|
|
17
|
+
/**
|
|
18
|
+
* 监听DOM尺寸变化
|
|
19
|
+
* @param element - dom元素
|
|
20
|
+
* @param handler - 变换回调函数
|
|
21
|
+
* @param type - 监听类型。默认width+height
|
|
22
|
+
* @param interval - 多久检查一次。默认值:500
|
|
23
|
+
* @returns 销毁方法
|
|
24
|
+
*
|
|
25
|
+
*/
|
|
26
|
+
declare function observeDomResize(
|
|
27
|
+
element: HTMLElement,
|
|
28
|
+
handler: (element: HTMLElement) => void,
|
|
29
|
+
type?: ('width' | 'height' | 'position')[],
|
|
30
|
+
interval?: number
|
|
31
|
+
): () => void;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 下载 url 文件
|
|
35
|
+
* @param url - 文件地址
|
|
36
|
+
* @param fileName - 文件名
|
|
37
|
+
*/
|
|
38
|
+
declare function downloadFileByUrl(url: string, fileName: string): void;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 下载ArrayBuffer文件
|
|
42
|
+
* @param data - ArrayBuffer格式的数据
|
|
43
|
+
* @param fileName - 文件名
|
|
44
|
+
*/
|
|
45
|
+
declare function downloadFileByArrayBuffer(data: ArrayBuffer, fileName: string): void;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 移除Dom节点
|
|
49
|
+
* @param dom - 待移除的dom元素
|
|
50
|
+
*/
|
|
51
|
+
declare function removeElement(el: HTMLElement): void;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* 移除Dom节点
|
|
55
|
+
* @param ev - 事件
|
|
56
|
+
* @param bubble - 阻止冒泡. 默认 true
|
|
57
|
+
* @param stop - 阻止穿透. 默认 true
|
|
58
|
+
*/
|
|
59
|
+
declare function prevent(ev: Event, bubble: boolean, stop: boolean): void;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @param key - 获取的键
|
|
63
|
+
* @returns 保存的值
|
|
64
|
+
*/
|
|
65
|
+
declare function getStorage(key: string): string;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param key - 删除的键
|
|
69
|
+
* @returns 保存的值
|
|
70
|
+
*/
|
|
71
|
+
declare function removeStorage(key: string): void;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 设置localstorage
|
|
75
|
+
* @param key - 保存的键
|
|
76
|
+
* @param value - 保存的值
|
|
77
|
+
*/
|
|
78
|
+
declare function setStorage(key: string, value: any): void;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 获取dom相对位置
|
|
82
|
+
* @param el - dom
|
|
83
|
+
* @returns 信息
|
|
84
|
+
*/
|
|
85
|
+
declare function getRelativePos(el: HTMLElement): {
|
|
86
|
+
x: number;
|
|
87
|
+
y: number;
|
|
88
|
+
height: number;
|
|
89
|
+
width: number;
|
|
90
|
+
clientWidth: number;
|
|
91
|
+
clientHeight: number;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* 获取当前js所在路径
|
|
96
|
+
* @param tir - 向上取几级目录,默认0,当前目录
|
|
97
|
+
* @returns 相对路径
|
|
98
|
+
*/
|
|
99
|
+
declare function getJsFileBaseUrl(tir: number): string;
|
|
100
|
+
|
|
101
|
+
interface LibraryFileConfig {
|
|
102
|
+
type: 'js' | 'css';
|
|
103
|
+
url: string;
|
|
104
|
+
module: string;
|
|
105
|
+
dependencies?: LibraryFileConfig[];
|
|
106
|
+
with?: LibraryFileConfig[];
|
|
107
|
+
attribute?: Record<string, string>;
|
|
108
|
+
}
|
|
109
|
+
type SuccessCallback = (...args: any[]) => void;
|
|
110
|
+
/**
|
|
111
|
+
* js和css文件加载器
|
|
112
|
+
* @param files - 文件配置
|
|
113
|
+
* @param callback - 加载成功回调
|
|
114
|
+
*/
|
|
115
|
+
declare function libraryFile(
|
|
116
|
+
files: LibraryFileConfig | LibraryFileConfig[],
|
|
117
|
+
callback: SuccessCallback
|
|
118
|
+
): void;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* 设置cookie。默认path="/"
|
|
122
|
+
* @param key - 设置的键名
|
|
123
|
+
* @param value - 设置的值
|
|
124
|
+
* @param expiredTime - 单位(毫秒)
|
|
125
|
+
*/
|
|
126
|
+
declare function setCookie(key: string, value: string, expiredTime?: number): void;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param key - 获取的键
|
|
130
|
+
* @param target - 来源,默认document.cookie
|
|
131
|
+
* @returns 保存的值
|
|
132
|
+
*/
|
|
133
|
+
declare function getCookie(key: string, target?: string): string;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* 删除cookie
|
|
137
|
+
*
|
|
138
|
+
* @param key - 键名
|
|
139
|
+
*/
|
|
140
|
+
declare function removeCookie(key: string): void;
|
|
141
|
+
|
|
17
142
|
declare global {
|
|
18
143
|
/**
|
|
19
144
|
* 该声明文件用于全局声明(不用npm安装时拷贝到项目中直接使用)
|
|
20
145
|
*/
|
|
21
146
|
namespace jUtilsBrowser {
|
|
22
|
-
export {
|
|
147
|
+
export {
|
|
148
|
+
addClass,
|
|
149
|
+
downloadFileByArrayBuffer,
|
|
150
|
+
downloadFileByUrl,
|
|
151
|
+
getCookie,
|
|
152
|
+
getJsFileBaseUrl,
|
|
153
|
+
getRelativePos,
|
|
154
|
+
getStorage,
|
|
155
|
+
getWindowSize,
|
|
156
|
+
libraryFile,
|
|
157
|
+
observeDomResize,
|
|
158
|
+
prevent,
|
|
159
|
+
removeCookie,
|
|
160
|
+
removeElement,
|
|
161
|
+
removeStorage,
|
|
162
|
+
setCookie,
|
|
163
|
+
setStorage
|
|
164
|
+
};
|
|
23
165
|
}
|
|
24
166
|
}
|
|
25
167
|
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
* @QQ 1174295440
|
|
4
4
|
* @author Bestime
|
|
5
5
|
* @see https://github.com/bestime/tool
|
|
6
|
-
* @update 2023-11-05
|
|
6
|
+
* @update 2023-11-05 17:29:17
|
|
7
7
|
*/
|
|
8
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@bestime/utils_base")):"function"==typeof define&&define.amd?define(["exports","@bestime/utils_base"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jUtilsBrowser={},e.jUtilsBase)}(this,function(e,
|
|
8
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@bestime/utils_base")):"function"==typeof define&&define.amd?define(["exports","@bestime/utils_base"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).jUtilsBrowser={},e.jUtilsBase)}(this,function(e,a){"use strict";var n,i,o=0,r=!1,c={};var s={add:function(e,t){return n="HI-"+ ++o,c[n]={start:+new Date,current:0,handler:e,interval:t},r||(clearInterval(i),r=!0,i=setInterval(function(){for(var e in c){var t=c[e];t.current=+new Date,t.current-t.start>=t.interval&&(t.start=t.current,c[e].handler())}},17)),n},remove:function(e){delete c[e],0===Object.keys(c).length&&(r=!1,clearInterval(i),i=undefined)}};function d(e,t){var n=document.createElement("a");n.style.display="none",n.download=t,n.setAttribute("href",e),n.setAttribute("target","_blank"),n.setAttribute("download",t),document.body.appendChild(n),n.click(),n.remove()}var l=void 0,u=decodeURIComponent,f="undefined"!=typeof document&&document.getElementById!==undefined,m="undefined"!=typeof window?window:l,h=f?document.getElementsByTagName("head")[0]:undefined;var g={};function p(n,i){for(var o=[],r=0,e=0;e<n.length;e++)!function(t){v(n[t],function(e){o[t]=e,++r===n.length&&i.apply(l,o)})}(e)}function v(e,t){var n=e.dependencies&&e.dependencies.length,i=e["with"]&&e["with"].length,o=(g[e.url]||(g[e.url]={count:0,dependencies:!n,"with":!i,complete:!1,create:!1,url:e.url}),g[e.url]);function r(){o.complete&&o.dependencies&&o["with"]&&(e.module?t(m[e.module]):t())}if(o.count++,!o.dependencies&&n)o.dependencies=!0,p(e.dependencies,function(){v(e,t)});else if(!o["with"]&&i)o["with"]=!0,p(e["with"].concat(e),r);else if(o.create)a.variableHasValue(function(){return o.complete},r,300);else{o.create=!0;var c,n=e.type,i=e.url,d=function(){o.complete=!0,r()},l=e.attribute;if(h){if("js"===n?(c=document.createElement("script")).src=i:((c=document.createElement("link")).setAttribute("rel","stylesheet"),c.href=i),l)for(var u in l)c.setAttribute(u,l[u]);c.onload=c.onerror=d,h.appendChild(c)}}}function t(e,t,n){i=t,t=i=a.isString(i)?i:JSON.stringify(i);var i=e+"="+encodeURI(t)+";path=/;";"number"==typeof n&&((e=new Date).setTime(e.getTime()+n),i+="expires="+e.toUTCString()),document.cookie=i}e.addClass=function(t,e){a.isArray(e)?a.forEach(e,function(e){t.classList.add(e)}):t.classList.add(e)},e.downloadFileByArrayBuffer=function(e,t){var n;f&&(d(e=(n=m.URL).createObjectURL(new Blob([e])),t),n.revokeObjectURL(e),undefined)},e.downloadFileByUrl=d,e.getCookie=function(e,t){t=t||document.cookie;var i="";return t.replace(new RegExp("(^|;\\s)"+e+"=(.*?)($|(;\\s))"),function(e,t,n){i=u(n)}),i},e.getJsFileBaseUrl=function(e){e=e||0;for(var t="/[^/]*",n=document.scripts,i=0;i<e;i++)t+=t;return n[n.length-1].src.replace(new RegExp(t+"$"),"")},e.getRelativePos=function(e){var t=e.getBoundingClientRect();return{x:t.left,y:t.top,height:e.offsetHeight,width:e.offsetWidth,clientWidth:e.clientWidth,clientHeight:e.clientHeight}},e.getStorage=function(e){return e=localStorage.getItem(e),a.defaultValue(e,"")},e.getWindowSize=function(){return{width:document.documentElement.clientWidth||document.body.clientWidth||window.innerWidth||0,height:document.documentElement.clientHeight||document.body.clientHeight||window.innerHeight||0}},e.libraryFile=function(e,t){console.log("加载器",e,g),(e instanceof Array?p:v)(e,t)},e.observeDomResize=function(n,i,o,e){var r=[0,0,!1],c=[0,0,!1],d=[0,0,!1],l=[0,0,!1],t=s.add(u,e=e||500);function u(){var e,t;document.body.contains(n)?(e=!1,null!=o&&o.includes("position")&&(t=n.getBoundingClientRect(),d[0]=t.left,d[2]=d[0]!==d[1],l[0]=t.top,l[2]=l[0]!==l[1]),r[0]=n.offsetWidth,r[2]=r[0]!==r[1],c[0]=n.offsetHeight,c[2]=c[0]!==c[1],r[2]&&(r[1]=r[0],null!=o&&o.includes("width")&&(e=!0)),c[2]&&(c[1]=c[0],null!=o&&o.includes("height")&&(e=!0)),(l[2]||d[2])&&(l[1]=l[0],d[1]=d[0],null!=o&&o.includes("position")&&(e=!0)),o&&0!==o.length||(r[2]||c[2]||l[2]||d[2])&&(e=!0),e&&i(n)):a()}function a(){s.remove(t),r=undefined,c=undefined}return u(),a},e.prevent=function(e,t,n){f&&(e=e||m.event,n=!1!==n,(t=!1!==t)&&m.event?m.event.cancelBubble=!0:e.stopPropagation(),n&&m.event?m.event.returnValue=!1:e.preventDefault())},e.removeCookie=function(e){t(e,"",-1)},e.removeElement=function(e){e.parentNode&&e.parentNode.removeChild(e)},e.removeStorage=function(e){localStorage.removeItem(e)},e.setCookie=t,e.setStorage=function(e,t){localStorage.setItem(e,(e=t,e=a.isString(e)?e:JSON.stringify(e)))}});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bestime/utils_browser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "./dist/jUtilsBrowser.esm.min.mjs",
|
|
5
5
|
"module": "./dist/jUtilsBrowser.esm.min.mjs",
|
|
6
6
|
"types": "./dist/jUtilsBrowser.esm.d.ts",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"build": "rollup --config rollup.config.prod.js",
|
|
14
14
|
"serve": "rollup --config rollup.config.dev.js --watch"
|
|
15
15
|
},
|
|
16
|
+
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@bestime/utils_base": "^1.0.3"
|
|
19
|
+
},
|
|
16
20
|
"devDependencies": {
|
|
17
21
|
"@babel/core": "7.18.6",
|
|
18
22
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
@@ -48,8 +52,5 @@
|
|
|
48
52
|
"homepage": "https://github.com/bestime/tool",
|
|
49
53
|
"publishConfig": {
|
|
50
54
|
"access": "public"
|
|
51
|
-
},
|
|
52
|
-
"dependencies": {
|
|
53
|
-
"@bestime/utils_base": "^1.0.1"
|
|
54
55
|
}
|
|
55
56
|
}
|