sculp-js 1.13.3-beta.0 → 1.13.6

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.
Files changed (119) hide show
  1. package/dist/cjs/_virtual/_commonjsHelpers.js +3 -3
  2. package/dist/cjs/array.js +36 -46
  3. package/dist/cjs/async.js +41 -43
  4. package/dist/cjs/base64.js +77 -66
  5. package/dist/cjs/clipboard.js +54 -53
  6. package/dist/cjs/cloneDeep.js +90 -91
  7. package/dist/cjs/cookie.js +27 -30
  8. package/dist/cjs/date.js +101 -98
  9. package/dist/cjs/dom.js +114 -121
  10. package/dist/cjs/download.js +77 -78
  11. package/dist/cjs/easing.js +29 -32
  12. package/dist/cjs/file.js +147 -152
  13. package/dist/cjs/func.js +64 -78
  14. package/dist/cjs/index.js +1 -3
  15. package/dist/cjs/math.js +32 -38
  16. package/dist/cjs/node_modules/bezier-easing/src/index.js +35 -23
  17. package/dist/cjs/number.js +58 -61
  18. package/dist/cjs/object.js +112 -126
  19. package/dist/cjs/path.js +39 -43
  20. package/dist/cjs/qs.js +34 -41
  21. package/dist/cjs/random.js +31 -34
  22. package/dist/cjs/string.js +62 -63
  23. package/dist/cjs/tooltip.js +66 -69
  24. package/dist/cjs/tree.js +265 -263
  25. package/dist/cjs/type.js +42 -46
  26. package/dist/cjs/unique.js +39 -42
  27. package/dist/cjs/url.js +47 -48
  28. package/dist/cjs/validator.js +38 -38
  29. package/dist/cjs/variable.js +27 -21
  30. package/dist/cjs/watermark.js +78 -67
  31. package/dist/esm/array.js +36 -46
  32. package/dist/esm/async.js +41 -43
  33. package/dist/esm/base64.js +77 -66
  34. package/dist/esm/clipboard.js +55 -54
  35. package/dist/esm/cloneDeep.js +90 -91
  36. package/dist/esm/cookie.js +27 -30
  37. package/dist/esm/date.js +101 -98
  38. package/dist/esm/dom.js +114 -121
  39. package/dist/esm/download.js +78 -79
  40. package/dist/esm/easing.js +29 -32
  41. package/dist/esm/file.js +147 -152
  42. package/dist/esm/func.js +64 -78
  43. package/dist/esm/index.js +96 -8
  44. package/dist/esm/math.js +32 -38
  45. package/dist/esm/number.js +58 -61
  46. package/dist/esm/object.js +124 -127
  47. package/dist/esm/path.js +39 -43
  48. package/dist/esm/qs.js +34 -41
  49. package/dist/esm/random.js +31 -34
  50. package/dist/esm/string.js +74 -64
  51. package/dist/esm/tooltip.js +66 -69
  52. package/dist/esm/tree.js +265 -263
  53. package/dist/esm/type.js +68 -47
  54. package/dist/esm/unique.js +39 -42
  55. package/dist/esm/url.js +47 -48
  56. package/dist/esm/validator.js +56 -39
  57. package/dist/esm/variable.js +27 -21
  58. package/dist/esm/watermark.js +79 -68
  59. package/dist/types/array.d.ts +0 -1
  60. package/dist/types/async.d.ts +0 -1
  61. package/dist/types/base64.d.ts +0 -1
  62. package/dist/types/clipboard.d.ts +0 -1
  63. package/dist/types/cloneDeep.d.ts +0 -1
  64. package/dist/types/cookie.d.ts +0 -1
  65. package/dist/types/date.d.ts +0 -1
  66. package/dist/types/dom.d.ts +0 -1
  67. package/dist/types/download.d.ts +0 -1
  68. package/dist/types/easing.d.ts +0 -1
  69. package/dist/types/file.d.ts +0 -1
  70. package/dist/types/func.d.ts +0 -1
  71. package/dist/types/index.d.ts +0 -1
  72. package/dist/types/math.d.ts +0 -1
  73. package/dist/types/number.d.ts +0 -1
  74. package/dist/types/object.d.ts +0 -1
  75. package/dist/types/path.d.ts +0 -1
  76. package/dist/types/qs.d.ts +0 -1
  77. package/dist/types/random.d.ts +0 -1
  78. package/dist/types/string.d.ts +0 -1
  79. package/dist/types/tooltip.d.ts +0 -1
  80. package/dist/types/tree.d.ts +2 -2
  81. package/dist/types/type.d.ts +0 -1
  82. package/dist/types/unique.d.ts +0 -1
  83. package/dist/types/url.d.ts +0 -1
  84. package/dist/types/validator.d.ts +0 -1
  85. package/dist/types/variable.d.ts +0 -1
  86. package/dist/types/watermark.d.ts +0 -1
  87. package/dist/umd/index.min.js +2 -2
  88. package/package.json +12 -6
  89. package/dist/types/array.d.ts.map +0 -1
  90. package/dist/types/async.d.ts.map +0 -1
  91. package/dist/types/base64.d.ts.map +0 -1
  92. package/dist/types/clipboard.d.ts.map +0 -1
  93. package/dist/types/cloneDeep.d.ts.map +0 -1
  94. package/dist/types/cookie.d.ts.map +0 -1
  95. package/dist/types/core-index.d.ts +0 -17
  96. package/dist/types/core-index.d.ts.map +0 -1
  97. package/dist/types/date.d.ts.map +0 -1
  98. package/dist/types/dom.d.ts.map +0 -1
  99. package/dist/types/download.d.ts.map +0 -1
  100. package/dist/types/easing.d.ts.map +0 -1
  101. package/dist/types/file.d.ts.map +0 -1
  102. package/dist/types/func.d.ts.map +0 -1
  103. package/dist/types/index.d.ts.map +0 -1
  104. package/dist/types/index.js +0 -3278
  105. package/dist/types/math.d.ts.map +0 -1
  106. package/dist/types/number.d.ts.map +0 -1
  107. package/dist/types/object.d.ts.map +0 -1
  108. package/dist/types/path.d.ts.map +0 -1
  109. package/dist/types/qs.d.ts.map +0 -1
  110. package/dist/types/random.d.ts.map +0 -1
  111. package/dist/types/string.d.ts.map +0 -1
  112. package/dist/types/tooltip.d.ts.map +0 -1
  113. package/dist/types/tree.d.ts.map +0 -1
  114. package/dist/types/type.d.ts.map +0 -1
  115. package/dist/types/unique.d.ts.map +0 -1
  116. package/dist/types/url.d.ts.map +0 -1
  117. package/dist/types/validator.d.ts.map +0 -1
  118. package/dist/types/variable.d.ts.map +0 -1
  119. package/dist/types/watermark.d.ts.map +0 -1
package/dist/esm/date.js CHANGED
@@ -1,38 +1,34 @@
1
1
  /*!
2
- * sculp-js v1.13.3-beta.0
2
+ * sculp-js v1.13.6
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
7
  import { isDate, isNaN, isString } from './type.js';
8
8
 
9
- const isValidDate = (any) => isDate(any) && !isNaN(any.getTime());
9
+ const isValidDate = any => isDate(any) && !isNaN(any.getTime());
10
10
  /* istanbul ignore next */
11
- const guessDateSeparator = (value) => {
12
- if (!isString(value))
13
- return;
14
- const value2 = value.replace(/-/g, '/');
15
- return new Date(value2);
11
+ const guessDateSeparator = value => {
12
+ if (!isString(value)) return;
13
+ const value2 = value.replace(/-/g, '/');
14
+ return new Date(value2);
16
15
  };
17
16
  /* istanbul ignore next */
18
- const guessDateTimezone = (value) => {
19
- if (!isString(value))
20
- return;
21
- const re = /([+-])(\d\d)(\d\d)$/;
22
- const matches = re.exec(value);
23
- if (!matches)
24
- return;
25
- const value2 = value.replace(re, 'Z');
26
- const d = new Date(value2);
27
- if (!isValidDate(d))
28
- return;
29
- const [, flag, hours, minutes] = matches;
30
- const hours2 = parseInt(hours, 10);
31
- const minutes2 = parseInt(minutes, 10);
32
- const offset = (a, b) => (flag === '+' ? a - b : a + b);
33
- d.setHours(offset(d.getHours(), hours2));
34
- d.setMinutes(offset(d.getMinutes(), minutes2));
35
- return d;
17
+ const guessDateTimezone = value => {
18
+ if (!isString(value)) return;
19
+ const re = /([+-])(\d\d)(\d\d)$/;
20
+ const matches = re.exec(value);
21
+ if (!matches) return;
22
+ const value2 = value.replace(re, 'Z');
23
+ const d = new Date(value2);
24
+ if (!isValidDate(d)) return;
25
+ const [, flag, hours, minutes] = matches;
26
+ const hours2 = parseInt(hours, 10);
27
+ const minutes2 = parseInt(minutes, 10);
28
+ const offset = (a, b) => (flag === '+' ? a - b : a + b);
29
+ d.setHours(offset(d.getHours(), hours2));
30
+ d.setMinutes(offset(d.getMinutes(), minutes2));
31
+ return d;
36
32
  };
37
33
  /**
38
34
  * 解析为Date对象
@@ -40,24 +36,21 @@ const guessDateTimezone = (value) => {
40
36
  * @returns {Date} - 转换后的目标Date
41
37
  */
42
38
  function dateParse(value) {
43
- const d1 = new Date(value);
44
- if (isValidDate(d1))
45
- return d1;
46
- // safari 浏览器的日期解析有问题
47
- // new Date('2020-06-26 18:06:15') 返回值是一个非法日期对象
48
- /* istanbul ignore next */
49
- const d2 = guessDateSeparator(value);
50
- /* istanbul ignore next */
51
- if (isValidDate(d2))
52
- return d2;
53
- // safari 浏览器的日期解析有问题
54
- // new Date('2020-06-26T18:06:15.000+0800') 返回值是一个非法日期对象
55
- /* istanbul ignore next */
56
- const d3 = guessDateTimezone(value);
57
- /* istanbul ignore next */
58
- if (isValidDate(d3))
59
- return d3;
60
- throw new SyntaxError(`${value.toString()} 不是一个合法的日期描述`);
39
+ const d1 = new Date(value);
40
+ if (isValidDate(d1)) return d1;
41
+ // safari 浏览器的日期解析有问题
42
+ // new Date('2020-06-26 18:06:15') 返回值是一个非法日期对象
43
+ /* istanbul ignore next */
44
+ const d2 = guessDateSeparator(value);
45
+ /* istanbul ignore next */
46
+ if (isValidDate(d2)) return d2;
47
+ // safari 浏览器的日期解析有问题
48
+ // new Date('2020-06-26T18:06:15.000+0800') 返回值是一个非法日期对象
49
+ /* istanbul ignore next */
50
+ const d3 = guessDateTimezone(value);
51
+ /* istanbul ignore next */
52
+ if (isValidDate(d3)) return d3;
53
+ throw new SyntaxError(`${value.toString()} 不是一个合法的日期描述`);
61
54
  }
62
55
  /**
63
56
  * 格式化为日期对象(带自定义格式化模板)
@@ -104,8 +97,8 @@ function dateParse(value) {
104
97
  * @returns {Date}
105
98
  */
106
99
  function dateToStart(value) {
107
- const d = dateParse(value);
108
- return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0);
100
+ const d = dateParse(value);
101
+ return new Date(d.getFullYear(), d.getMonth(), d.getDate(), 0, 0, 0, 0);
109
102
  }
110
103
  /**
111
104
  * 将日期转换为一天的结束时间,即23点59分59秒999毫秒
@@ -113,9 +106,9 @@ function dateToStart(value) {
113
106
  * @returns {Date}
114
107
  */
115
108
  function dateToEnd(value) {
116
- const d = dateToStart(value);
117
- d.setDate(d.getDate() + 1);
118
- return dateParse(d.getTime() - 1);
109
+ const d = dateToStart(value);
110
+ d.setDate(d.getDate() + 1);
111
+ return dateParse(d.getTime() - 1);
119
112
  }
120
113
  /**
121
114
  * 格式化为日期对象(带自定义格式化模板)
@@ -134,29 +127,29 @@ function dateToEnd(value) {
134
127
  * @returns {string} 格式化后的日期字符串
135
128
  */
136
129
  function formatDate(value, format = 'YYYY-MM-DD HH:mm:ss') {
137
- const date = dateParse(value);
138
- let fmt = format;
139
- let ret;
140
- const opt = {
141
- 'Y+': `${date.getFullYear()}`,
142
- 'y+': `${date.getFullYear()}`,
143
- 'M+': `${date.getMonth() + 1}`,
144
- 'D+': `${date.getDate()}`,
145
- 'd+': `${date.getDate()}`,
146
- 'H+': `${date.getHours()}`,
147
- 'm+': `${date.getMinutes()}`,
148
- 's+': `${date.getSeconds()}`,
149
- 'S+': `${date.getMilliseconds()}`,
150
- 'w+': ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][date.getDay()] // 周
151
- // 有其他格式化字符需求可以继续添加,必须转化成字符串
152
- };
153
- for (const k in opt) {
154
- ret = new RegExp('(' + k + ')').exec(fmt);
155
- if (ret) {
156
- fmt = fmt.replace(ret[1], ret[1].length === 1 ? opt[k] : opt[k].padStart(ret[1].length, '0'));
157
- }
130
+ const date = dateParse(value);
131
+ let fmt = format;
132
+ let ret;
133
+ const opt = {
134
+ 'Y+': `${date.getFullYear()}`,
135
+ 'y+': `${date.getFullYear()}`,
136
+ 'M+': `${date.getMonth() + 1}`,
137
+ 'D+': `${date.getDate()}`,
138
+ 'd+': `${date.getDate()}`,
139
+ 'H+': `${date.getHours()}`,
140
+ 'm+': `${date.getMinutes()}`,
141
+ 's+': `${date.getSeconds()}`,
142
+ 'S+': `${date.getMilliseconds()}`,
143
+ 'w+': ['周日', '周一', '周二', '周三', '周四', '周五', '周六'][date.getDay()] // 周
144
+ // 有其他格式化字符需求可以继续添加,必须转化成字符串
145
+ };
146
+ for (const k in opt) {
147
+ ret = new RegExp('(' + k + ')').exec(fmt);
148
+ if (ret) {
149
+ fmt = fmt.replace(ret[1], ret[1].length === 1 ? opt[k] : opt[k].padStart(ret[1].length, '0'));
158
150
  }
159
- return fmt;
151
+ }
152
+ return fmt;
160
153
  }
161
154
  /**
162
155
  * 计算向前或向后N天的具体日期
@@ -166,17 +159,18 @@ function formatDate(value, format = 'YYYY-MM-DD HH:mm:ss') {
166
159
  * @returns {string} 计算后的目标日期
167
160
  */
168
161
  function calculateDate(originDate, n, sep = '-') {
169
- //originDate 为字符串日期 如:'2019-01-01' n为你要传入的参数,当前为0,前一天为-1,后一天为1
170
- const date = new Date(originDate); //这边给定一个特定时间
171
- const newDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
172
- const millisecondGap = newDate.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
173
- const targetDate = new Date(millisecondGap);
174
- const finalNewDate = targetDate.getFullYear() +
175
- sep +
176
- String(targetDate.getMonth() + 1).padStart(2, '0') +
177
- '-' +
178
- String(targetDate.getDate()).padStart(2, '0');
179
- return finalNewDate;
162
+ //originDate 为字符串日期 如:'2019-01-01' n为你要传入的参数,当前为0,前一天为-1,后一天为1
163
+ const date = new Date(originDate); //这边给定一个特定时间
164
+ const newDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
165
+ const millisecondGap = newDate.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
166
+ const targetDate = new Date(millisecondGap);
167
+ const finalNewDate =
168
+ targetDate.getFullYear() +
169
+ sep +
170
+ String(targetDate.getMonth() + 1).padStart(2, '0') +
171
+ '-' +
172
+ String(targetDate.getDate()).padStart(2, '0');
173
+ return finalNewDate;
180
174
  }
181
175
  /**
182
176
  * 计算向前或向后N天的具体日期时间
@@ -187,23 +181,32 @@ function calculateDate(originDate, n, sep = '-') {
187
181
  * @returns {string} 转换后的目标日期时间
188
182
  */
189
183
  function calculateDateTime(originDateTime, n, dateSep = '-', timeSep = ':') {
190
- const date = new Date(originDateTime);
191
- const separator1 = dateSep;
192
- const separator2 = timeSep;
193
- const dateTime = new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds());
194
- const millisecondGap = dateTime.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
195
- const targetDateTime = new Date(millisecondGap);
196
- return (targetDateTime.getFullYear() +
197
- separator1 +
198
- String(targetDateTime.getMonth() + 1).padStart(2, '0') +
199
- separator1 +
200
- String(targetDateTime.getDate()).padStart(2, '0') +
201
- ' ' +
202
- String(targetDateTime.getHours()).padStart(2, '0') +
203
- separator2 +
204
- String(targetDateTime.getMinutes()).padStart(2, '0') +
205
- separator2 +
206
- String(targetDateTime.getSeconds()).padStart(2, '0'));
184
+ const date = new Date(originDateTime);
185
+ const separator1 = dateSep;
186
+ const separator2 = timeSep;
187
+ const dateTime = new Date(
188
+ date.getFullYear(),
189
+ date.getMonth(),
190
+ date.getDate(),
191
+ date.getHours(),
192
+ date.getMinutes(),
193
+ date.getSeconds()
194
+ );
195
+ const millisecondGap = dateTime.getTime() + 1000 * 60 * 60 * 24 * parseInt(String(n)); //计算前几天用减,计算后几天用加,最后一个就是多少天的数量
196
+ const targetDateTime = new Date(millisecondGap);
197
+ return (
198
+ targetDateTime.getFullYear() +
199
+ separator1 +
200
+ String(targetDateTime.getMonth() + 1).padStart(2, '0') +
201
+ separator1 +
202
+ String(targetDateTime.getDate()).padStart(2, '0') +
203
+ ' ' +
204
+ String(targetDateTime.getHours()).padStart(2, '0') +
205
+ separator2 +
206
+ String(targetDateTime.getMinutes()).padStart(2, '0') +
207
+ separator2 +
208
+ String(targetDateTime.getSeconds()).padStart(2, '0')
209
+ );
207
210
  }
208
211
 
209
212
  export { calculateDate, calculateDateTime, dateParse, dateToEnd, dateToStart, formatDate, isValidDate };
package/dist/esm/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * sculp-js v1.13.3-beta.0
2
+ * sculp-js v1.13.6
3
3
  * (c) 2023-present chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -17,13 +17,12 @@ import { isObject, isString } from './type.js';
17
17
  * @returns {boolean}
18
18
  */
19
19
  function hasClass(el, className) {
20
- if (className.indexOf(' ') !== -1)
21
- throw new Error('className should not contain space.');
22
- return el.classList.contains(className);
20
+ if (className.indexOf(' ') !== -1) throw new Error('className should not contain space.');
21
+ return el.classList.contains(className);
23
22
  }
24
23
  const eachClassName = (classNames, func) => {
25
- const classNameList = classNames.split(/\s+/g);
26
- classNameList.forEach(func);
24
+ const classNameList = classNames.split(/\s+/g);
25
+ classNameList.forEach(func);
27
26
  };
28
27
  /**
29
28
  * 给元素增加样式名
@@ -31,7 +30,7 @@ const eachClassName = (classNames, func) => {
31
30
  * @param {string} classNames
32
31
  */
33
32
  function addClass(el, classNames) {
34
- eachClassName(classNames, className => el.classList.add(className));
33
+ eachClassName(classNames, className => el.classList.add(className));
35
34
  }
36
35
  /**
37
36
  * 给元素移除样式名
@@ -39,7 +38,7 @@ function addClass(el, classNames) {
39
38
  * @param {string} classNames
40
39
  */
41
40
  function removeClass(el, classNames) {
42
- eachClassName(classNames, className => el.classList.remove(className));
41
+ eachClassName(classNames, className => el.classList.remove(className));
43
42
  }
44
43
  /**
45
44
  * 设置元素样式
@@ -48,14 +47,13 @@ function removeClass(el, classNames) {
48
47
  * @param {string} val
49
48
  */
50
49
  const setStyle = (el, key, val) => {
51
- if (isObject(key)) {
52
- objectEach(key, (val1, key1) => {
53
- setStyle(el, key1, val1);
54
- });
55
- }
56
- else {
57
- el.style.setProperty(stringKebabCase(key), val);
58
- }
50
+ if (isObject(key)) {
51
+ objectEach(key, (val1, key1) => {
52
+ setStyle(el, key1, val1);
53
+ });
54
+ } else {
55
+ el.style.setProperty(stringKebabCase(key), val);
56
+ }
59
57
  };
60
58
  /**
61
59
  * 获取元素样式
@@ -64,57 +62,54 @@ const setStyle = (el, key, val) => {
64
62
  * @returns {string}
65
63
  */
66
64
  function getStyle(el, key) {
67
- return getComputedStyle(el).getPropertyValue(key);
65
+ return getComputedStyle(el).getPropertyValue(key);
68
66
  }
69
67
  function smoothScroll(options) {
70
- return new Promise(resolve => {
71
- const defaults = {
72
- el: document,
73
- to: 0,
74
- duration: 567,
75
- easing: 'ease'
76
- };
77
- const { el, to, duration, easing } = objectAssign(defaults, options);
78
- const htmlEl = document.documentElement;
79
- const bodyEl = document.body;
80
- const globalMode = el === window || el === document || el === htmlEl || el === bodyEl;
81
- const els = globalMode ? [htmlEl, bodyEl] : [el];
82
- const query = () => {
83
- let value = 0;
84
- arrayEach(els, el => {
85
- if ('scrollTop' in el) {
86
- value = el.scrollTop;
87
- return false;
88
- }
89
- });
90
- return value;
91
- };
92
- const update = (val) => {
93
- els.forEach(el => {
94
- if ('scrollTop' in el) {
95
- el.scrollTop = val;
96
- }
97
- });
98
- };
99
- let startTime;
100
- const startValue = query();
101
- const length = to - startValue;
102
- const easingFn = easingFunctional(easing);
103
- const render = () => {
104
- const now = performance.now();
105
- const passingTime = startTime ? now - startTime : 0;
106
- const t = passingTime / duration;
107
- const p = easingFn(t);
108
- if (!startTime)
109
- startTime = now;
110
- update(startValue + length * p);
111
- if (t >= 1)
112
- resolve();
113
- else
114
- requestAnimationFrame(render);
115
- };
116
- render();
117
- });
68
+ return new Promise(resolve => {
69
+ const defaults = {
70
+ el: document,
71
+ to: 0,
72
+ duration: 567,
73
+ easing: 'ease'
74
+ };
75
+ const { el, to, duration, easing } = objectAssign(defaults, options);
76
+ const htmlEl = document.documentElement;
77
+ const bodyEl = document.body;
78
+ const globalMode = el === window || el === document || el === htmlEl || el === bodyEl;
79
+ const els = globalMode ? [htmlEl, bodyEl] : [el];
80
+ const query = () => {
81
+ let value = 0;
82
+ arrayEach(els, el => {
83
+ if ('scrollTop' in el) {
84
+ value = el.scrollTop;
85
+ return false;
86
+ }
87
+ });
88
+ return value;
89
+ };
90
+ const update = val => {
91
+ els.forEach(el => {
92
+ if ('scrollTop' in el) {
93
+ el.scrollTop = val;
94
+ }
95
+ });
96
+ };
97
+ let startTime;
98
+ const startValue = query();
99
+ const length = to - startValue;
100
+ const easingFn = easingFunctional(easing);
101
+ const render = () => {
102
+ const now = performance.now();
103
+ const passingTime = startTime ? now - startTime : 0;
104
+ const t = passingTime / duration;
105
+ const p = easingFn(t);
106
+ if (!startTime) startTime = now;
107
+ update(startValue + length * p);
108
+ if (t >= 1) resolve();
109
+ else requestAnimationFrame(render);
110
+ };
111
+ render();
112
+ });
118
113
  }
119
114
  /**
120
115
  * 获取元素样式属性的计算值
@@ -124,8 +119,8 @@ function smoothScroll(options) {
124
119
  * @returns {string|number}
125
120
  */
126
121
  function getComputedCssVal(el, property, reNumber = true) {
127
- const originVal = getComputedStyle(el).getPropertyValue(property) ?? '';
128
- return reNumber ? Number(originVal.replace(/([0-9]*)(.*)/g, '$1')) : originVal;
122
+ const originVal = getComputedStyle(el).getPropertyValue(property) ?? '';
123
+ return reNumber ? Number(originVal.replace(/([0-9]*)(.*)/g, '$1')) : originVal;
129
124
  }
130
125
  /**
131
126
  * 字符串的像素宽度
@@ -135,31 +130,31 @@ function getComputedCssVal(el, property, reNumber = true) {
135
130
  * @returns {*}
136
131
  */
137
132
  function getStrWidthPx(str, fontSize = 14, isRemove = true) {
138
- let strWidth = 0;
139
- console.assert(isString(str), `${str} 不是有效的字符串`);
140
- if (isString(str) && str.length > 0) {
141
- const id = 'getStrWidth1494304949567';
142
- let getEle = document.querySelector(`#${id}`);
143
- if (!getEle) {
144
- const _ele = document.createElement('span');
145
- _ele.id = id;
146
- _ele.style.fontSize = fontSize + 'px';
147
- _ele.style.whiteSpace = 'nowrap';
148
- _ele.style.visibility = 'hidden';
149
- _ele.style.position = 'absolute';
150
- _ele.style.top = '-9999px';
151
- _ele.style.left = '-9999px';
152
- _ele.textContent = str;
153
- document.body.appendChild(_ele);
154
- getEle = _ele;
155
- }
156
- getEle.textContent = str;
157
- strWidth = getEle.offsetWidth;
158
- if (isRemove) {
159
- getEle.remove();
160
- }
133
+ let strWidth = 0;
134
+ console.assert(isString(str), `${str} 不是有效的字符串`);
135
+ if (isString(str) && str.length > 0) {
136
+ const id = 'getStrWidth1494304949567';
137
+ let getEle = document.querySelector(`#${id}`);
138
+ if (!getEle) {
139
+ const _ele = document.createElement('span');
140
+ _ele.id = id;
141
+ _ele.style.fontSize = fontSize + 'px';
142
+ _ele.style.whiteSpace = 'nowrap';
143
+ _ele.style.visibility = 'hidden';
144
+ _ele.style.position = 'absolute';
145
+ _ele.style.top = '-9999px';
146
+ _ele.style.left = '-9999px';
147
+ _ele.textContent = str;
148
+ document.body.appendChild(_ele);
149
+ getEle = _ele;
150
+ }
151
+ getEle.textContent = str;
152
+ strWidth = getEle.offsetWidth;
153
+ if (isRemove) {
154
+ getEle.remove();
161
155
  }
162
- return strWidth;
156
+ }
157
+ return strWidth;
163
158
  }
164
159
  /**
165
160
  * Programmatically select the text of a HTML element
@@ -168,39 +163,37 @@ function getStrWidthPx(str, fontSize = 14, isRemove = true) {
168
163
  * @returns
169
164
  */
170
165
  function select(element) {
171
- let selectedText;
172
- if (element.nodeName === 'SELECT') {
173
- element.focus();
174
- // @ts-ignore
175
- selectedText = element.value;
166
+ let selectedText;
167
+ if (element.nodeName === 'SELECT') {
168
+ element.focus();
169
+ // @ts-ignore
170
+ selectedText = element.value;
171
+ } else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
172
+ const isReadOnly = element.hasAttribute('readonly');
173
+ if (!isReadOnly) {
174
+ element.setAttribute('readonly', '');
176
175
  }
177
- else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
178
- const isReadOnly = element.hasAttribute('readonly');
179
- if (!isReadOnly) {
180
- element.setAttribute('readonly', '');
181
- }
182
- // @ts-ignore
183
- element.select();
184
- // @ts-ignore
185
- element.setSelectionRange(0, element.value.length);
186
- if (!isReadOnly) {
187
- element.removeAttribute('readonly');
188
- }
189
- // @ts-ignore
190
- selectedText = element.value;
176
+ // @ts-ignore
177
+ element.select();
178
+ // @ts-ignore
179
+ element.setSelectionRange(0, element.value.length);
180
+ if (!isReadOnly) {
181
+ element.removeAttribute('readonly');
191
182
  }
192
- else {
193
- if (element.hasAttribute('contenteditable')) {
194
- element.focus();
195
- }
196
- const selection = window.getSelection();
197
- const range = document.createRange();
198
- range.selectNodeContents(element);
199
- selection.removeAllRanges();
200
- selection.addRange(range);
201
- selectedText = selection.toString();
183
+ // @ts-ignore
184
+ selectedText = element.value;
185
+ } else {
186
+ if (element.hasAttribute('contenteditable')) {
187
+ element.focus();
202
188
  }
203
- return selectedText;
189
+ const selection = window.getSelection();
190
+ const range = document.createRange();
191
+ range.selectNodeContents(element);
192
+ selection.removeAllRanges();
193
+ selection.addRange(range);
194
+ selectedText = selection.toString();
195
+ }
196
+ return selectedText;
204
197
  }
205
198
 
206
199
  export { addClass, getComputedCssVal, getStrWidthPx, getStyle, hasClass, removeClass, select, setStyle, smoothScroll };