sculp-js 1.3.2 → 1.4.1

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 (52) hide show
  1. package/README.md +1 -1
  2. package/lib/cjs/array.js +1 -1
  3. package/lib/cjs/async.js +1 -1
  4. package/lib/cjs/clipboard.js +1 -1
  5. package/lib/cjs/cookie.js +1 -1
  6. package/lib/cjs/date.js +1 -1
  7. package/lib/cjs/dom.js +32 -1
  8. package/lib/cjs/download.js +1 -1
  9. package/lib/cjs/easing.js +1 -1
  10. package/lib/cjs/file.js +1 -1
  11. package/lib/cjs/func.js +1 -1
  12. package/lib/cjs/index.js +6 -2
  13. package/lib/cjs/number.js +1 -1
  14. package/lib/cjs/object.js +1 -1
  15. package/lib/cjs/path.js +1 -1
  16. package/lib/cjs/qs.js +1 -1
  17. package/lib/cjs/random.js +1 -1
  18. package/lib/cjs/string.js +17 -29
  19. package/lib/cjs/tooltip.js +5 -5
  20. package/lib/cjs/tree.js +80 -1
  21. package/lib/cjs/type.js +16 -1
  22. package/lib/cjs/unique.js +1 -1
  23. package/lib/cjs/url.js +1 -1
  24. package/lib/cjs/watermark.js +1 -1
  25. package/lib/cjs/we-decode.js +1 -1
  26. package/lib/es/array.js +1 -1
  27. package/lib/es/async.js +1 -1
  28. package/lib/es/clipboard.js +1 -1
  29. package/lib/es/cookie.js +1 -1
  30. package/lib/es/date.js +1 -1
  31. package/lib/es/dom.js +33 -3
  32. package/lib/es/download.js +1 -1
  33. package/lib/es/easing.js +1 -1
  34. package/lib/es/file.js +1 -1
  35. package/lib/es/func.js +1 -1
  36. package/lib/es/index.js +5 -5
  37. package/lib/es/number.js +1 -1
  38. package/lib/es/object.js +1 -1
  39. package/lib/es/path.js +1 -1
  40. package/lib/es/qs.js +1 -1
  41. package/lib/es/random.js +1 -1
  42. package/lib/es/string.js +17 -29
  43. package/lib/es/tooltip.js +2 -2
  44. package/lib/es/tree.js +79 -2
  45. package/lib/es/type.js +16 -2
  46. package/lib/es/unique.js +1 -1
  47. package/lib/es/url.js +1 -1
  48. package/lib/es/watermark.js +1 -1
  49. package/lib/es/we-decode.js +1 -1
  50. package/lib/index.d.ts +39 -7
  51. package/lib/umd/index.js +142 -27
  52. package/package.json +1 -1
package/README.md CHANGED
@@ -34,8 +34,8 @@
34
34
  - forEachDeep 高性能的深度优先遍历函数, 支持continue、break,可定制id、children
35
35
  - forEachMap 高性能的深度优先遍历的Map函数, 支持continue、break,可定制id、children
36
36
  - searchTreeById 在树中找到 id 为某个值的节点,并返回上游的所有父级节点
37
- - buildTree 根据 id 与 parentId 从对象数组中构建对应的树
38
37
  - formatTree 高性能的数组转树函数
38
+ - fuzzySearchTree 模糊搜索函数,返回包含搜索字符的节点及其祖先节点的树
39
39
 
40
40
  - Object
41
41
 
package/lib/cjs/array.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/async.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/cookie.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/date.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -154,9 +154,40 @@ function getComputedCssVal(el, property, reNumber = true) {
154
154
  const originVal = getComputedStyle(el).getPropertyValue(property) ?? '';
155
155
  return reNumber ? Number(originVal.replace(/([0-9]*)(.*)/g, '$1')) : originVal;
156
156
  }
157
+ /**
158
+ * 字符串的像素宽度
159
+ * @param {string} str 目标字符串
160
+ * @param {number} fontSize 字符串字体大小
161
+ * @param {boolean} isRemoveDom 计算后是否移除中间dom元素
162
+ * @returns {*}
163
+ */
164
+ function getStrWidthPx(str, fontSize = 14, isRemoveDom = false) {
165
+ let strWidth = 0;
166
+ console.assert(type.isString(str), `${str} 不是有效的字符串`);
167
+ if (type.isString(str) && str.length > 0) {
168
+ let getEle = document.querySelector('#getStrWidth1494304949567');
169
+ if (!getEle) {
170
+ const _ele = document.createElement('span');
171
+ _ele.id = 'getStrWidth1494304949567';
172
+ _ele.style.fontSize = fontSize + 'px';
173
+ _ele.style.whiteSpace = 'nowrap';
174
+ _ele.style.visibility = 'hidden';
175
+ _ele.textContent = str;
176
+ document.body.appendChild(_ele);
177
+ getEle = _ele;
178
+ }
179
+ getEle.textContent = str;
180
+ strWidth = getEle.offsetWidth;
181
+ if (isRemoveDom) {
182
+ document.body.appendChild(getEle);
183
+ }
184
+ }
185
+ return strWidth;
186
+ }
157
187
 
158
188
  exports.addClass = addClass;
159
189
  exports.getComputedCssVal = getComputedCssVal;
190
+ exports.getStrWidthPx = getStrWidthPx;
160
191
  exports.getStyle = getStyle;
161
192
  exports.hasClass = hasClass;
162
193
  exports.isDomReady = isDomReady;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/easing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/file.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -49,6 +49,7 @@ exports.formatDate = date.formatDate;
49
49
  exports.isValidDate = date.isValidDate;
50
50
  exports.addClass = dom.addClass;
51
51
  exports.getComputedCssVal = dom.getComputedCssVal;
52
+ exports.getStrWidthPx = dom.getStrWidthPx;
52
53
  exports.getStyle = dom.getStyle;
53
54
  exports.hasClass = dom.hasClass;
54
55
  exports.isDomReady = dom.isDomReady;
@@ -79,7 +80,7 @@ exports.qsStringify = qs.qsStringify;
79
80
  exports.STRING_ARABIC_NUMERALS = string.STRING_ARABIC_NUMERALS;
80
81
  exports.STRING_LOWERCASE_ALPHA = string.STRING_LOWERCASE_ALPHA;
81
82
  exports.STRING_UPPERCASE_ALPHA = string.STRING_UPPERCASE_ALPHA;
82
- exports.getStrWidthPx = string.getStrWidthPx;
83
+ exports.parseQueryParams = string.parseQueryParams;
83
84
  exports.stringAssign = string.stringAssign;
84
85
  exports.stringCamelCase = string.stringCamelCase;
85
86
  exports.stringEscapeHtml = string.stringEscapeHtml;
@@ -92,6 +93,7 @@ exports.isBoolean = type.isBoolean;
92
93
  exports.isDate = type.isDate;
93
94
  exports.isError = type.isError;
94
95
  exports.isFunction = type.isFunction;
96
+ exports.isJsonString = type.isJsonString;
95
97
  exports.isNaN = type.isNaN;
96
98
  exports.isNull = type.isNull;
97
99
  exports.isNullOrUnDef = type.isNullOrUnDef;
@@ -131,9 +133,11 @@ exports.uniqueNumber = unique.uniqueNumber;
131
133
  exports.uniqueString = unique.uniqueString;
132
134
  exports.tooltipEvent = tooltip.tooltipEvent;
133
135
  exports.buildTree = tree.buildTree;
136
+ exports.flatTree = tree.flatTree;
134
137
  exports.forEachDeep = tree.forEachDeep;
135
138
  exports.forEachMap = tree.forEachMap;
136
139
  exports.formatTree = tree.formatTree;
140
+ exports.fuzzySearchTree = tree.fuzzySearchTree;
137
141
  exports.searchTreeById = tree.searchTreeById;
138
142
  exports.weAppJwtDecode = weDecode.weAppJwtDecode;
139
143
  exports.weAtob = weDecode.weAtob;
package/lib/cjs/number.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/object.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/path.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/qs.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/random.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/string.js CHANGED
@@ -1,13 +1,11 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
7
  'use strict';
8
8
 
9
- var type = require('./type.js');
10
-
11
9
  /**
12
10
  * 将字符串转换为驼峰格式
13
11
  * @param {string} string
@@ -125,40 +123,30 @@ const stringEscapeHtml = (html) => {
125
123
  */
126
124
  const stringFill = (length, value = ' ') => new Array(length).fill(value).join('');
127
125
  /**
128
- * 字符串的像素宽度
129
- * @param {string} str 目标字符串
130
- * @param {number} fontSize 字符串字体大小
131
- * @param {boolean} isRemoveDom 计算后是否移除中间dom元素
132
- * @returns {*}
126
+ * 解析URL查询参数
127
+ * @param {string} searchStr
128
+ * @return {Record<string, string | string[]>}
133
129
  */
134
- function getStrWidthPx(str, fontSize = 14, isRemoveDom = false) {
135
- let strWidth = 0;
136
- console.assert(type.isString(str), `${str} 不是有效的字符串`);
137
- if (type.isString(str) && str.length > 0) {
138
- let getEle = document.querySelector('#getStrWidth1494304949567');
139
- if (!getEle) {
140
- const _ele = document.createElement('span');
141
- _ele.id = 'getStrWidth1494304949567';
142
- _ele.style.fontSize = fontSize + 'px';
143
- _ele.style.whiteSpace = 'nowrap';
144
- _ele.style.visibility = 'hidden';
145
- _ele.textContent = str;
146
- document.body.appendChild(_ele);
147
- getEle = _ele;
130
+ function parseQueryParams(searchStr = location.search) {
131
+ const queryObj = {};
132
+ Array.from(searchStr.matchAll(/[&?]?([^=&]+)=?([^=&]*)/g)).forEach((item, i) => {
133
+ if (!queryObj[item[1]]) {
134
+ queryObj[item[1]] = item[2];
148
135
  }
149
- getEle.textContent = str;
150
- strWidth = getEle.offsetWidth;
151
- if (isRemoveDom) {
152
- document.body.appendChild(getEle);
136
+ else if (typeof queryObj[item[1]] === 'string') {
137
+ queryObj[item[1]] = [queryObj[item[1]], item[2]];
153
138
  }
154
- }
155
- return strWidth;
139
+ else {
140
+ queryObj[item[1]].push(item[2]);
141
+ }
142
+ });
143
+ return queryObj;
156
144
  }
157
145
 
158
146
  exports.STRING_ARABIC_NUMERALS = STRING_ARABIC_NUMERALS;
159
147
  exports.STRING_LOWERCASE_ALPHA = STRING_LOWERCASE_ALPHA;
160
148
  exports.STRING_UPPERCASE_ALPHA = STRING_UPPERCASE_ALPHA;
161
- exports.getStrWidthPx = getStrWidthPx;
149
+ exports.parseQueryParams = parseQueryParams;
162
150
  exports.stringAssign = stringAssign;
163
151
  exports.stringCamelCase = stringCamelCase;
164
152
  exports.stringEscapeHtml = stringEscapeHtml;
@@ -1,12 +1,12 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
6
6
 
7
7
  'use strict';
8
8
 
9
- var string = require('./string.js');
9
+ var dom = require('./dom.js');
10
10
 
11
11
  /**
12
12
  * @title tooltip
@@ -79,10 +79,10 @@ function mouseenter($customTitle, title, e) {
79
79
  let x = 13;
80
80
  const y = 23;
81
81
  const $contentEle = $customTitle.children[0];
82
- if (string.getStrWidthPx(title, 12) < 180 + 50) {
82
+ if (dom.getStrWidthPx(title, 12) < 180 + 50) {
83
83
  //【弹出div自适应字符串宽度】若显示的字符串占用宽度小于180,则设置弹出div的宽度为“符串占用宽度”+20
84
- $contentEle.style.maxWidth = string.getStrWidthPx(title, 12) + 20 + 50 + 'px';
85
- diffValueX = e.clientX + (string.getStrWidthPx(title, 12) + 50) - document.body.offsetWidth;
84
+ $contentEle.style.maxWidth = dom.getStrWidthPx(title, 12) + 20 + 50 + 'px';
85
+ diffValueX = e.clientX + (dom.getStrWidthPx(title, 12) + 50) - document.body.offsetWidth;
86
86
  }
87
87
  else {
88
88
  $contentEle.style.maxWidth = '250px';
package/lib/cjs/tree.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -7,6 +7,11 @@
7
7
  'use strict';
8
8
 
9
9
  const defaultFieldOptions = { keyField: 'key', childField: 'children', pidField: 'pid' };
10
+ const defaultSearchTreeOptions = {
11
+ childField: 'children',
12
+ nameField: 'name',
13
+ ignoreEmptyChild: false
14
+ };
10
15
  /**
11
16
  * 深度优先遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
12
17
  * @param {ArrayLike<V>} tree 树形数据
@@ -271,9 +276,83 @@ function formatTree(list, options = defaultFieldOptions) {
271
276
  });
272
277
  return treeArr;
273
278
  }
279
+ /**
280
+ * 树形结构转扁平化
281
+ * @param {any} treeList
282
+ * @param {IFieldOptions} options
283
+ * @return {*}
284
+ */
285
+ function flatTree(treeList, options = defaultFieldOptions) {
286
+ const { childField, keyField, pidField } = options;
287
+ return treeList.reduce((res, node) => {
288
+ const item = {
289
+ ...node,
290
+ [childField]: [] // 清空子级
291
+ };
292
+ item.hasOwnProperty([childField]) && delete item[childField];
293
+ res.push(item);
294
+ if (node[childField]) {
295
+ const children = node[childField].map(item => ({
296
+ ...item,
297
+ [pidField]: node[keyField] || item.pid // 给子级设置pid
298
+ }));
299
+ res = res.concat(flatTree(children, options));
300
+ }
301
+ return res;
302
+ }, []);
303
+ }
304
+ /**
305
+ * 模糊搜索函数,返回包含搜索字符的节点及其祖先节点, 适用于树型组件的字符过滤功能
306
+ * @param {any[]} nodes
307
+ * @param {string} query
308
+ * @param {ISearchTreeOpts} options
309
+ * @return {any[]}
310
+ */
311
+ function fuzzySearchTree(nodes, query, options = defaultSearchTreeOptions) {
312
+ const result = [];
313
+ for (const node of nodes) {
314
+ // 递归检查子节点是否匹配
315
+ const matchedChildren = node[options.childField] && node[options.childField].length > 0
316
+ ? fuzzySearchTree(node[options.childField] || [], query, options)
317
+ : [];
318
+ // 检查当前节点是否匹配或者有匹配的子节点
319
+ if (node[options.nameField].toLowerCase().includes(query.toLowerCase()) || matchedChildren.length > 0) {
320
+ // 将当前节点加入结果中
321
+ if (node[options.childField]) {
322
+ if (matchedChildren.length > 0) {
323
+ result.push({
324
+ ...node,
325
+ [options.childField]: matchedChildren // 包含匹配的子节点
326
+ });
327
+ }
328
+ else if (options.ignoreEmptyChild) {
329
+ node[options.childField] && delete node[options.childField];
330
+ result.push({
331
+ ...node
332
+ });
333
+ }
334
+ else {
335
+ result.push({
336
+ ...node,
337
+ ...{ [options.childField]: [] }
338
+ });
339
+ }
340
+ }
341
+ else {
342
+ node[options.childField] && delete node[options.childField];
343
+ result.push({
344
+ ...node
345
+ });
346
+ }
347
+ }
348
+ }
349
+ return result;
350
+ }
274
351
 
275
352
  exports.buildTree = buildTree;
353
+ exports.flatTree = flatTree;
276
354
  exports.forEachDeep = forEachDeep;
277
355
  exports.forEachMap = forEachMap;
278
356
  exports.formatTree = formatTree;
357
+ exports.fuzzySearchTree = fuzzySearchTree;
279
358
  exports.searchTreeById = searchTreeById;
package/lib/cjs/type.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -40,6 +40,20 @@ const isNaN = (any) => Number.isNaN(any);
40
40
  const isDate = (any) => typeIs(any) === 'Date';
41
41
  const isError = (any) => typeIs(any) === 'Error';
42
42
  const isRegExp = (any) => typeIs(any) === 'RegExp';
43
+ /**
44
+ * 判断一个字符串是否为有效的 JSON, 若有效则返回有效的JSON对象,否则false
45
+ * @param {string} str
46
+ * @return {Object | boolean}
47
+ */
48
+ function isJsonString(str) {
49
+ try {
50
+ const parsed = JSON.parse(str);
51
+ return typeof parsed === 'object' && parsed !== null ? parsed : false;
52
+ }
53
+ catch (e) {
54
+ return false;
55
+ }
56
+ }
43
57
 
44
58
  exports.default = typeIs;
45
59
  exports.isArray = isArray;
@@ -48,6 +62,7 @@ exports.isBoolean = isBoolean;
48
62
  exports.isDate = isDate;
49
63
  exports.isError = isError;
50
64
  exports.isFunction = isFunction;
65
+ exports.isJsonString = isJsonString;
51
66
  exports.isNaN = isNaN;
52
67
  exports.isNull = isNull;
53
68
  exports.isNullOrUnDef = isNullOrUnDef;
package/lib/cjs/unique.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/cjs/url.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/array.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/async.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/cookie.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/date.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/dom.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -8,7 +8,7 @@ import { arrayEach } from './array.js';
8
8
  import { easingFunctional } from './easing.js';
9
9
  import { objectEach, objectAssign } from './object.js';
10
10
  import { stringKebabCase } from './string.js';
11
- import { isObject } from './type.js';
11
+ import { isObject, isString } from './type.js';
12
12
 
13
13
  /**
14
14
  * 判断元素是否包含某个样式名
@@ -152,5 +152,35 @@ function getComputedCssVal(el, property, reNumber = true) {
152
152
  const originVal = getComputedStyle(el).getPropertyValue(property) ?? '';
153
153
  return reNumber ? Number(originVal.replace(/([0-9]*)(.*)/g, '$1')) : originVal;
154
154
  }
155
+ /**
156
+ * 字符串的像素宽度
157
+ * @param {string} str 目标字符串
158
+ * @param {number} fontSize 字符串字体大小
159
+ * @param {boolean} isRemoveDom 计算后是否移除中间dom元素
160
+ * @returns {*}
161
+ */
162
+ function getStrWidthPx(str, fontSize = 14, isRemoveDom = false) {
163
+ let strWidth = 0;
164
+ console.assert(isString(str), `${str} 不是有效的字符串`);
165
+ if (isString(str) && str.length > 0) {
166
+ let getEle = document.querySelector('#getStrWidth1494304949567');
167
+ if (!getEle) {
168
+ const _ele = document.createElement('span');
169
+ _ele.id = 'getStrWidth1494304949567';
170
+ _ele.style.fontSize = fontSize + 'px';
171
+ _ele.style.whiteSpace = 'nowrap';
172
+ _ele.style.visibility = 'hidden';
173
+ _ele.textContent = str;
174
+ document.body.appendChild(_ele);
175
+ getEle = _ele;
176
+ }
177
+ getEle.textContent = str;
178
+ strWidth = getEle.offsetWidth;
179
+ if (isRemoveDom) {
180
+ document.body.appendChild(getEle);
181
+ }
182
+ }
183
+ return strWidth;
184
+ }
155
185
 
156
- export { addClass, getComputedCssVal, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll };
186
+ export { addClass, getComputedCssVal, getStrWidthPx, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll };
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/easing.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/file.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/func.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
@@ -8,13 +8,13 @@ export { arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove }
8
8
  export { copyText } from './clipboard.js';
9
9
  export { cookieDel, cookieGet, cookieSet } from './cookie.js';
10
10
  export { calculateDate, calculateDateTime, dateParse, dateToEnd, dateToStart, formatDate, isValidDate } from './date.js';
11
- export { addClass, getComputedCssVal, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll } from './dom.js';
11
+ export { addClass, getComputedCssVal, getStrWidthPx, getStyle, hasClass, isDomReady, onDomReady, removeClass, setStyle, smoothScroll } from './dom.js';
12
12
  export { downloadBlob, downloadData, downloadHref, downloadURL } from './download.js';
13
13
  export { cloneDeep, isPlainObject, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick } from './object.js';
14
14
  export { pathJoin, pathNormalize } from './path.js';
15
15
  export { qsParse, qsStringify } from './qs.js';
16
- export { STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_UPPERCASE_ALPHA, getStrWidthPx, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase } from './string.js';
17
- export { isArray, isBigInt, isBoolean, isDate, isError, isFunction, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, typeIs } from './type.js';
16
+ export { STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_UPPERCASE_ALPHA, parseQueryParams, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase } from './string.js';
17
+ export { isArray, isBigInt, isBoolean, isDate, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, typeIs } from './type.js';
18
18
  export { urlDelParams, urlParse, urlSetParams, urlStringify } from './url.js';
19
19
  export { asyncMap, wait } from './async.js';
20
20
  export { chooseLocalFile, compressImg, supportCanvas } from './file.js';
@@ -24,5 +24,5 @@ export { STRING_POOL, randomNumber, randomString, randomUuid } from './random.js
24
24
  export { HEX_POOL, formatNumber, numberAbbr, numberToHex } from './number.js';
25
25
  export { UNIQUE_NUMBER_SAFE_LENGTH, uniqueNumber, uniqueString } from './unique.js';
26
26
  export { tooltipEvent } from './tooltip.js';
27
- export { buildTree, forEachDeep, forEachMap, formatTree, searchTreeById } from './tree.js';
27
+ export { buildTree, flatTree, forEachDeep, forEachMap, formatTree, fuzzySearchTree, searchTreeById } from './tree.js';
28
28
  export { weAppJwtDecode, weAtob, weBtoa } from './we-decode.js';
package/lib/es/number.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */
package/lib/es/object.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * core v1.3.1
2
+ * sculp-js v1.4.1
3
3
  * (c) 2023-2024 chandq
4
4
  * Released under the MIT License.
5
5
  */