sculp-js 1.13.1 → 1.13.3-beta.0

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 (127) hide show
  1. package/README.md +10 -11
  2. package/dist/cjs/_virtual/_commonjsHelpers.js +13 -0
  3. package/{lib → dist}/cjs/array.js +1 -1
  4. package/{lib → dist}/cjs/async.js +1 -1
  5. package/{lib/cjs/we-decode.js → dist/cjs/base64.js} +53 -44
  6. package/{lib → dist}/cjs/clipboard.js +4 -2
  7. package/{lib → dist}/cjs/cloneDeep.js +1 -1
  8. package/{lib → dist}/cjs/cookie.js +1 -1
  9. package/{lib → dist}/cjs/date.js +1 -1
  10. package/{lib → dist}/cjs/dom.js +1 -1
  11. package/{lib → dist}/cjs/download.js +4 -2
  12. package/dist/cjs/easing.js +75 -0
  13. package/{lib → dist}/cjs/file.js +7 -3
  14. package/{lib → dist}/cjs/func.js +1 -1
  15. package/{lib → dist}/cjs/index.js +11 -8
  16. package/{lib → dist}/cjs/math.js +1 -1
  17. package/dist/cjs/node_modules/bezier-easing/src/index.js +123 -0
  18. package/{lib → dist}/cjs/number.js +1 -1
  19. package/{lib → dist}/cjs/object.js +1 -1
  20. package/{lib → dist}/cjs/path.js +1 -1
  21. package/{lib → dist}/cjs/qs.js +1 -1
  22. package/{lib → dist}/cjs/random.js +1 -1
  23. package/{lib → dist}/cjs/string.js +1 -1
  24. package/{lib → dist}/cjs/tooltip.js +5 -2
  25. package/{lib → dist}/cjs/tree.js +9 -23
  26. package/{lib → dist}/cjs/type.js +8 -1
  27. package/{lib → dist}/cjs/unique.js +1 -1
  28. package/{lib → dist}/cjs/url.js +1 -1
  29. package/{lib → dist}/cjs/validator.js +1 -1
  30. package/{lib → dist}/cjs/variable.js +1 -1
  31. package/{lib → dist}/cjs/watermark.js +4 -2
  32. package/{lib/es → dist/esm}/array.js +1 -1
  33. package/{lib/es → dist/esm}/async.js +1 -1
  34. package/{lib/es/we-decode.js → dist/esm/base64.js} +52 -45
  35. package/{lib/es → dist/esm}/clipboard.js +4 -2
  36. package/{lib/es → dist/esm}/cloneDeep.js +1 -1
  37. package/{lib/es → dist/esm}/cookie.js +1 -1
  38. package/{lib/es → dist/esm}/date.js +1 -1
  39. package/{lib/es → dist/esm}/dom.js +1 -1
  40. package/{lib/es → dist/esm}/download.js +4 -2
  41. package/{lib/es → dist/esm}/easing.js +34 -2
  42. package/{lib/es → dist/esm}/file.js +7 -3
  43. package/{lib/es → dist/esm}/func.js +1 -1
  44. package/{lib/es → dist/esm}/index.js +4 -5
  45. package/{lib/es → dist/esm}/math.js +1 -1
  46. package/{lib/es → dist/esm}/number.js +1 -1
  47. package/{lib/es → dist/esm}/object.js +1 -1
  48. package/{lib/es → dist/esm}/path.js +1 -1
  49. package/{lib/es → dist/esm}/qs.js +1 -1
  50. package/{lib/es → dist/esm}/random.js +1 -1
  51. package/{lib/es → dist/esm}/string.js +1 -1
  52. package/{lib/es → dist/esm}/tooltip.js +5 -2
  53. package/{lib/es → dist/esm}/tree.js +10 -24
  54. package/{lib/es → dist/esm}/type.js +8 -2
  55. package/{lib/es → dist/esm}/unique.js +1 -1
  56. package/{lib/es → dist/esm}/url.js +1 -1
  57. package/{lib/es → dist/esm}/validator.js +1 -1
  58. package/{lib/es → dist/esm}/variable.js +1 -1
  59. package/{lib/es → dist/esm}/watermark.js +4 -2
  60. package/dist/types/array.d.ts +50 -0
  61. package/dist/types/array.d.ts.map +1 -0
  62. package/dist/types/async.d.ts +37 -0
  63. package/dist/types/async.d.ts.map +1 -0
  64. package/dist/types/base64.d.ts +25 -0
  65. package/dist/types/base64.d.ts.map +1 -0
  66. package/dist/types/clipboard.d.ts +20 -0
  67. package/dist/types/clipboard.d.ts.map +1 -0
  68. package/dist/types/cloneDeep.d.ts +12 -0
  69. package/dist/types/cloneDeep.d.ts.map +1 -0
  70. package/dist/types/cookie.d.ts +19 -0
  71. package/dist/types/cookie.d.ts.map +1 -0
  72. package/dist/types/core-index.d.ts +17 -0
  73. package/dist/types/core-index.d.ts.map +1 -0
  74. package/dist/types/date.d.ts +74 -0
  75. package/dist/types/date.d.ts.map +1 -0
  76. package/dist/types/dom.d.ts +74 -0
  77. package/dist/types/dom.d.ts.map +1 -0
  78. package/dist/types/download.d.ts +47 -0
  79. package/dist/types/download.d.ts.map +1 -0
  80. package/dist/types/easing.d.ts +32 -0
  81. package/dist/types/easing.d.ts.map +1 -0
  82. package/dist/types/file.d.ts +44 -0
  83. package/dist/types/file.d.ts.map +1 -0
  84. package/dist/types/func.d.ts +50 -0
  85. package/dist/types/func.d.ts.map +1 -0
  86. package/dist/types/index.d.ts +28 -0
  87. package/dist/types/index.d.ts.map +1 -0
  88. package/dist/types/index.js +3278 -0
  89. package/dist/types/math.d.ts +36 -0
  90. package/dist/types/math.d.ts.map +1 -0
  91. package/dist/types/number.d.ts +49 -0
  92. package/dist/types/number.d.ts.map +1 -0
  93. package/dist/types/object.d.ts +70 -0
  94. package/dist/types/object.d.ts.map +1 -0
  95. package/dist/types/path.d.ts +14 -0
  96. package/dist/types/path.d.ts.map +1 -0
  97. package/dist/types/qs.d.ts +22 -0
  98. package/dist/types/qs.d.ts.map +1 -0
  99. package/dist/types/random.d.ts +27 -0
  100. package/dist/types/random.d.ts.map +1 -0
  101. package/dist/types/string.d.ts +67 -0
  102. package/dist/types/string.d.ts.map +1 -0
  103. package/dist/types/tooltip.d.ts +36 -0
  104. package/dist/types/tooltip.d.ts.map +1 -0
  105. package/dist/types/tree.d.ts +99 -0
  106. package/dist/types/tree.d.ts.map +1 -0
  107. package/dist/types/type.d.ts +128 -0
  108. package/dist/types/type.d.ts.map +1 -0
  109. package/dist/types/unique.d.ts +21 -0
  110. package/dist/types/unique.d.ts.map +1 -0
  111. package/dist/types/url.d.ts +46 -0
  112. package/dist/types/url.d.ts.map +1 -0
  113. package/dist/types/validator.d.ts +67 -0
  114. package/dist/types/validator.d.ts.map +1 -0
  115. package/dist/types/variable.d.ts +71 -0
  116. package/dist/types/variable.d.ts.map +1 -0
  117. package/dist/types/watermark.d.ts +19 -0
  118. package/dist/types/watermark.d.ts.map +1 -0
  119. package/dist/umd/index.min.js +6 -0
  120. package/package.json +234 -17
  121. package/lib/cjs/base64.js +0 -62
  122. package/lib/cjs/easing.js +0 -40
  123. package/lib/cjs/isEqual.js +0 -133
  124. package/lib/es/base64.js +0 -59
  125. package/lib/es/isEqual.js +0 -131
  126. package/lib/index.d.ts +0 -1214
  127. package/lib/umd/index.js +0 -6
package/lib/cjs/easing.js DELETED
@@ -1,40 +0,0 @@
1
- /*!
2
- * sculp-js v1.13.1
3
- * (c) 2023-present chandq
4
- * Released under the MIT License.
5
- */
6
-
7
- 'use strict';
8
-
9
- var bezier = require('bezier-easing');
10
- var type = require('./type.js');
11
-
12
- // @ref https://cubic-bezier.com/
13
- const easingDefines = {
14
- linear: [0, 0, 1, 1],
15
- ease: [0.25, 0.1, 0.25, 1],
16
- 'ease-in': [0.42, 0, 1, 1],
17
- 'ease-out': [0, 0, 0.58, 1],
18
- 'ease-in-out': [0.42, 0, 0.58, 1]
19
- };
20
- /**
21
- * 缓冲函数化,用于 js 计算缓冲进度
22
- * @param {EasingNameOrDefine} [name=linear]
23
- * @returns {EasingFunction}
24
- */
25
- function easingFunctional(name) {
26
- let fn;
27
- if (type.isArray(name)) {
28
- fn = bezier(...name);
29
- }
30
- else {
31
- const define = easingDefines[name];
32
- if (!define) {
33
- throw new Error(`${name} 缓冲函数未定义`);
34
- }
35
- fn = bezier(...define);
36
- }
37
- return (input) => fn(Math.max(0, Math.min(input, 1)));
38
- }
39
-
40
- exports.easingFunctional = easingFunctional;
@@ -1,133 +0,0 @@
1
- /*!
2
- * sculp-js v1.13.1
3
- * (c) 2023-present chandq
4
- * Released under the MIT License.
5
- */
6
-
7
- 'use strict';
8
-
9
- var type = require('./type.js');
10
-
11
- /**
12
- * 比较两值是否相等,适用所有数据类型
13
- * @param {Comparable} a
14
- * @param {Comparable} b
15
- * @returns {boolean}
16
- */
17
- function isEqual(a, b) {
18
- return deepEqual(a, b);
19
- }
20
- function deepEqual(a, b, compared = new WeakMap()) {
21
- // 相同值快速返回
22
- if (Object.is(a, b))
23
- return true;
24
- // 类型不同直接返回false
25
- const typeA = Object.prototype.toString.call(a);
26
- const typeB = Object.prototype.toString.call(b);
27
- if (typeA !== typeB)
28
- return false;
29
- // 只缓存对象类型
30
- if (type.isObject(a) && type.isObject(b)) {
31
- if (compared.has(a))
32
- return compared.get(a) === b;
33
- compared.set(a, b);
34
- compared.set(b, a);
35
- }
36
- // 处理特殊对象类型
37
- switch (typeA) {
38
- case '[object Date]':
39
- return a.getTime() === b.getTime();
40
- case '[object RegExp]':
41
- return a.toString() === b.toString();
42
- case '[object Map]':
43
- return compareMap(a, b, compared);
44
- case '[object Set]':
45
- return compareSet(a, b, compared);
46
- case '[object ArrayBuffer]':
47
- return compareArrayBuffer(a, b);
48
- case '[object DataView]':
49
- return compareDataView(a, b, compared);
50
- case '[object Int8Array]':
51
- case '[object Uint8Array]':
52
- case '[object Uint8ClampedArray]':
53
- case '[object Int16Array]':
54
- case '[object Uint16Array]':
55
- case '[object Int32Array]':
56
- case '[object Uint32Array]':
57
- case '[object Float32Array]':
58
- case '[object Float64Array]':
59
- return compareTypedArray(a, b, compared);
60
- case '[object Object]':
61
- return compareObjects(a, b, compared);
62
- case '[object Array]':
63
- return compareArrays(a, b, compared);
64
- }
65
- return false;
66
- }
67
- // 辅助比较函数
68
- function compareMap(a, b, compared) {
69
- if (a.size !== b.size)
70
- return false;
71
- for (const [key, value] of a) {
72
- if (!b.has(key) || !deepEqual(value, b.get(key), compared))
73
- return false;
74
- }
75
- return true;
76
- }
77
- function compareSet(a, b, compared) {
78
- if (a.size !== b.size)
79
- return false;
80
- for (const value of a) {
81
- let found = false;
82
- for (const bValue of b) {
83
- if (deepEqual(value, bValue, compared)) {
84
- found = true;
85
- break;
86
- }
87
- }
88
- if (!found)
89
- return false;
90
- }
91
- return true;
92
- }
93
- function compareArrayBuffer(a, b) {
94
- if (a.byteLength !== b.byteLength)
95
- return false;
96
- return new DataView(a).getInt32(0) === new DataView(b).getInt32(0);
97
- }
98
- function compareDataView(a, b, compared) {
99
- return a.byteLength === b.byteLength && deepEqual(new Uint8Array(a.buffer), new Uint8Array(b.buffer), compared);
100
- }
101
- function compareTypedArray(a, b, compared) {
102
- return a.byteLength === b.byteLength && deepEqual(Array.from(a), Array.from(b), compared);
103
- }
104
- function compareObjects(a, b, compared) {
105
- const keysA = Reflect.ownKeys(a);
106
- const keysB = Reflect.ownKeys(b);
107
- if (keysA.length !== keysB.length)
108
- return false;
109
- for (const key of keysA) {
110
- if (!keysB.includes(key))
111
- return false;
112
- if (!deepEqual(a[key], b[key], compared))
113
- return false;
114
- }
115
- // 原型链比较
116
- return Object.getPrototypeOf(a) === Object.getPrototypeOf(b);
117
- }
118
- function compareArrays(a, b, compared) {
119
- // 增加有效索引检查
120
- const keysA = Object.keys(a).map(Number);
121
- const keysB = Object.keys(b).map(Number);
122
- if (keysA.length !== keysB.length)
123
- return false;
124
- // 递归比较每个元素
125
- for (let i = 0, len = a.length; i < len; i++) {
126
- if (!deepEqual(a[i], b[i], compared))
127
- return false;
128
- }
129
- // 比较数组对象的其他属性
130
- return compareObjects(a, b, compared);
131
- }
132
-
133
- exports.isEqual = isEqual;
package/lib/es/base64.js DELETED
@@ -1,59 +0,0 @@
1
- /*!
2
- * sculp-js v1.13.1
3
- * (c) 2023-present chandq
4
- * Released under the MIT License.
5
- */
6
-
7
- import { getGlobal } from './func.js';
8
- import { isNullOrUnDef } from './type.js';
9
- import { weAtob, weBtoa } from './we-decode.js';
10
-
11
- function stringToUint8Array(str) {
12
- const utf8 = encodeURIComponent(str); // 将字符串转换为 UTF-8 编码
13
- const uint8Array = new Uint8Array(utf8.length); // 创建 Uint8Array
14
- for (let i = 0; i < utf8.length; i++) {
15
- uint8Array[i] = utf8.charCodeAt(i); // 填充 Uint8Array
16
- }
17
- return uint8Array;
18
- }
19
- function uint8ArrayToString(uint8Array) {
20
- const utf8 = String.fromCharCode.apply(null, uint8Array); // 将 Uint8Array 转为字符串
21
- return decodeURIComponent(utf8); // 将 UTF-8 字符串解码回正常字符串
22
- }
23
- /**
24
- * 将base64编码的字符串转换为原始字符串,包括对中文内容的处理(高性能,且支持Web、Node、小程序等任意平台)
25
- * @param base64 base64编码的字符串
26
- * @returns 原始字符串,包括中文内容
27
- */
28
- function decodeFromBase64(base64) {
29
- const binaryString = !isNullOrUnDef(getGlobal('atob')) ? getGlobal('atob')(base64) : weAtob(base64);
30
- const len = binaryString.length;
31
- const bytes = new Uint8Array(len);
32
- for (let i = 0; i < len; i++) {
33
- bytes[i] = binaryString.charCodeAt(i);
34
- }
35
- // 使用TextDecoder将Uint8Array转换为原始字符串,包括中文内容
36
- return !isNullOrUnDef(getGlobal('TextDecoder'))
37
- ? new (getGlobal('TextDecoder'))('utf-8').decode(bytes)
38
- : uint8ArrayToString(bytes);
39
- }
40
- /**
41
- * 将原始字符串,包括中文内容,转换为base64编码的字符串(高性能,且支持Web、Node、小程序等任意平台)
42
- * @param rawStr 原始字符串,包括中文内容
43
- * @returns base64编码的字符串
44
- */
45
- function encodeToBase64(rawStr) {
46
- const utf8Array = !isNullOrUnDef(getGlobal('TextEncoder'))
47
- ? new (getGlobal('TextEncoder'))().encode(rawStr)
48
- : stringToUint8Array(rawStr);
49
- // 将 Uint8Array 转换为二进制字符串
50
- let binaryString = '';
51
- const len = utf8Array.length;
52
- for (let i = 0; i < len; i++) {
53
- binaryString += String.fromCharCode(utf8Array[i]);
54
- }
55
- // 将二进制字符串转换为base64编码的字符串
56
- return !isNullOrUnDef(getGlobal('btoa')) ? getGlobal('btoa')(binaryString) : weBtoa(binaryString);
57
- }
58
-
59
- export { decodeFromBase64, encodeToBase64 };
package/lib/es/isEqual.js DELETED
@@ -1,131 +0,0 @@
1
- /*!
2
- * sculp-js v1.13.1
3
- * (c) 2023-present chandq
4
- * Released under the MIT License.
5
- */
6
-
7
- import { isObject } from './type.js';
8
-
9
- /**
10
- * 比较两值是否相等,适用所有数据类型
11
- * @param {Comparable} a
12
- * @param {Comparable} b
13
- * @returns {boolean}
14
- */
15
- function isEqual(a, b) {
16
- return deepEqual(a, b);
17
- }
18
- function deepEqual(a, b, compared = new WeakMap()) {
19
- // 相同值快速返回
20
- if (Object.is(a, b))
21
- return true;
22
- // 类型不同直接返回false
23
- const typeA = Object.prototype.toString.call(a);
24
- const typeB = Object.prototype.toString.call(b);
25
- if (typeA !== typeB)
26
- return false;
27
- // 只缓存对象类型
28
- if (isObject(a) && isObject(b)) {
29
- if (compared.has(a))
30
- return compared.get(a) === b;
31
- compared.set(a, b);
32
- compared.set(b, a);
33
- }
34
- // 处理特殊对象类型
35
- switch (typeA) {
36
- case '[object Date]':
37
- return a.getTime() === b.getTime();
38
- case '[object RegExp]':
39
- return a.toString() === b.toString();
40
- case '[object Map]':
41
- return compareMap(a, b, compared);
42
- case '[object Set]':
43
- return compareSet(a, b, compared);
44
- case '[object ArrayBuffer]':
45
- return compareArrayBuffer(a, b);
46
- case '[object DataView]':
47
- return compareDataView(a, b, compared);
48
- case '[object Int8Array]':
49
- case '[object Uint8Array]':
50
- case '[object Uint8ClampedArray]':
51
- case '[object Int16Array]':
52
- case '[object Uint16Array]':
53
- case '[object Int32Array]':
54
- case '[object Uint32Array]':
55
- case '[object Float32Array]':
56
- case '[object Float64Array]':
57
- return compareTypedArray(a, b, compared);
58
- case '[object Object]':
59
- return compareObjects(a, b, compared);
60
- case '[object Array]':
61
- return compareArrays(a, b, compared);
62
- }
63
- return false;
64
- }
65
- // 辅助比较函数
66
- function compareMap(a, b, compared) {
67
- if (a.size !== b.size)
68
- return false;
69
- for (const [key, value] of a) {
70
- if (!b.has(key) || !deepEqual(value, b.get(key), compared))
71
- return false;
72
- }
73
- return true;
74
- }
75
- function compareSet(a, b, compared) {
76
- if (a.size !== b.size)
77
- return false;
78
- for (const value of a) {
79
- let found = false;
80
- for (const bValue of b) {
81
- if (deepEqual(value, bValue, compared)) {
82
- found = true;
83
- break;
84
- }
85
- }
86
- if (!found)
87
- return false;
88
- }
89
- return true;
90
- }
91
- function compareArrayBuffer(a, b) {
92
- if (a.byteLength !== b.byteLength)
93
- return false;
94
- return new DataView(a).getInt32(0) === new DataView(b).getInt32(0);
95
- }
96
- function compareDataView(a, b, compared) {
97
- return a.byteLength === b.byteLength && deepEqual(new Uint8Array(a.buffer), new Uint8Array(b.buffer), compared);
98
- }
99
- function compareTypedArray(a, b, compared) {
100
- return a.byteLength === b.byteLength && deepEqual(Array.from(a), Array.from(b), compared);
101
- }
102
- function compareObjects(a, b, compared) {
103
- const keysA = Reflect.ownKeys(a);
104
- const keysB = Reflect.ownKeys(b);
105
- if (keysA.length !== keysB.length)
106
- return false;
107
- for (const key of keysA) {
108
- if (!keysB.includes(key))
109
- return false;
110
- if (!deepEqual(a[key], b[key], compared))
111
- return false;
112
- }
113
- // 原型链比较
114
- return Object.getPrototypeOf(a) === Object.getPrototypeOf(b);
115
- }
116
- function compareArrays(a, b, compared) {
117
- // 增加有效索引检查
118
- const keysA = Object.keys(a).map(Number);
119
- const keysB = Object.keys(b).map(Number);
120
- if (keysA.length !== keysB.length)
121
- return false;
122
- // 递归比较每个元素
123
- for (let i = 0, len = a.length; i < len; i++) {
124
- if (!deepEqual(a[i], b[i], compared))
125
- return false;
126
- }
127
- // 比较数组对象的其他属性
128
- return compareObjects(a, b, compared);
129
- }
130
-
131
- export { isEqual };