sh-tools 1.2.0 → 1.2.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.
- package/lib/sh-tools.common.js +37049 -0
- package/lib/sh-tools.common.js.gz +0 -0
- package/lib/sh-tools.umd.js +37060 -0
- package/lib/sh-tools.umd.js.gz +0 -0
- package/lib/sh-tools.umd.min.js +17 -0
- package/lib/sh-tools.umd.min.js.gz +0 -0
- package/package.json +4 -4
- package/packages/api/index.js +0 -88
- package/packages/api/smSecret/base64.js +0 -168
- package/packages/api/smSecret/hex.js +0 -92
- package/packages/api/smSecret/index.js +0 -13
- package/packages/api/smSecret/sm3.js +0 -276
- package/packages/api/smSecret/util.js +0 -92
- package/packages/index.js +0 -5
- package/packages/utils/boolean.js +0 -10
- package/packages/utils/color.js +0 -395
- package/packages/utils/dom.js +0 -111
- package/packages/utils/index.js +0 -25
- package/packages/utils/number.js +0 -24
- package/packages/utils/object.js +0 -1
- package/packages/utils/other.js +0 -310
- package/packages/utils/pattern.js +0 -43
- package/packages/utils/string.js +0 -227
- package/packages/utils/time.js +0 -1
- package/packages/utils/validate.js +0 -139
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
*
|
|
3
|
-
* 字节流转换工具js
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
/*
|
|
8
|
-
* 数组复制
|
|
9
|
-
*/
|
|
10
|
-
export const arrayCopy = (src, pos1, dest, pos2, len) => {
|
|
11
|
-
var realLen = len
|
|
12
|
-
if (pos1 + len > src.length && pos2 + len <= dest.length) {
|
|
13
|
-
realLen = src.length - pos1
|
|
14
|
-
} else if (pos2 + len > dest.length && pos1 + len <= src.length) {
|
|
15
|
-
realLen = dest.length - pos2
|
|
16
|
-
} else if (pos1 + len <= src.length && pos2 + len <= dest.length) {
|
|
17
|
-
realLen = len
|
|
18
|
-
} else if (dest.length < src.length) {
|
|
19
|
-
realLen = dest.length - pos2
|
|
20
|
-
} else {
|
|
21
|
-
realLen = src.length - pos2
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
for (var i = 0; i < realLen; i++) {
|
|
25
|
-
dest[i + pos2] = src[i + pos1]
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/*
|
|
30
|
-
* 长整型转成字节,一个长整型为8字节
|
|
31
|
-
* 返回:字节数组
|
|
32
|
-
*/
|
|
33
|
-
export const longToByte = num => {
|
|
34
|
-
// TODO 这里目前只转换了低四字节,因为js没有长整型,得要封装
|
|
35
|
-
return new Array(0, 0, 0, 0, (num >> 24) & 0x000000ff, (num >> 16) & 0x000000ff, (num >> 8) & 0x000000ff, num & 0x000000ff)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/*
|
|
39
|
-
* int数转成byte数组
|
|
40
|
-
* 事实上只不过转成byte大小的数,实际占用空间还是4字节
|
|
41
|
-
* 返回:字节数组
|
|
42
|
-
*/
|
|
43
|
-
export const intToByte = num => {
|
|
44
|
-
return new Array((num >> 24) & 0x000000ff, (num >> 16) & 0x000000ff, (num >> 8) & 0x000000ff, num & 0x000000ff)
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/*
|
|
48
|
-
* int数组转成byte数组,一个int数值转成四个byte
|
|
49
|
-
* 返回:byte数组
|
|
50
|
-
*/
|
|
51
|
-
export const intArrayToByteArray = nums => {
|
|
52
|
-
var b = new Array(nums.length * 4)
|
|
53
|
-
|
|
54
|
-
for (var i = 0; i < nums.length; i++) {
|
|
55
|
-
arrayCopy(intToByte(nums[i]), 0, b, i * 4, 4)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return b
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/*
|
|
62
|
-
* byte数组转成int数值
|
|
63
|
-
* 返回:int数值
|
|
64
|
-
*/
|
|
65
|
-
export const byteToInt = (b, pos) => {
|
|
66
|
-
if (pos + 3 < b.length) {
|
|
67
|
-
return (b[pos] << 24) | (b[pos + 1] << 16) | (b[pos + 2] << 8) | b[pos + 3]
|
|
68
|
-
} else if (pos + 2 < b.length) {
|
|
69
|
-
return (b[pos + 1] << 16) | (b[pos + 2] << 8) | b[pos + 3]
|
|
70
|
-
} else if (pos + 1 < b.length) {
|
|
71
|
-
return (b[pos] << 8) | b[pos + 1]
|
|
72
|
-
} else {
|
|
73
|
-
return b[pos]
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/*
|
|
78
|
-
* byte数组转成int数组,每四个字节转成一个int数值
|
|
79
|
-
*
|
|
80
|
-
*/
|
|
81
|
-
export const byteArrayToIntArray = b => {
|
|
82
|
-
// var arrLen = b.length%4==0 ? b.length/4:b.length/4+1;
|
|
83
|
-
var arrLen = Math.ceil(b.length / 4) // 向上取整
|
|
84
|
-
var out = new Array(arrLen)
|
|
85
|
-
for (let i = 0; i < b.length; i++) {
|
|
86
|
-
b[i] = b[i] & 0xff // 避免负数造成影响
|
|
87
|
-
}
|
|
88
|
-
for (let i = 0; i < out.length; i++) {
|
|
89
|
-
out[i] = byteToInt(b, i * 4)
|
|
90
|
-
}
|
|
91
|
-
return out
|
|
92
|
-
}
|
package/packages/index.js
DELETED
package/packages/utils/color.js
DELETED
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
const colorKeywords = new Map([
|
|
2
|
-
['transparent', 'rgba(0,0,0,0)'],
|
|
3
|
-
['black', '#000000'],
|
|
4
|
-
['silver', '#C0C0C0'],
|
|
5
|
-
['gray', '#808080'],
|
|
6
|
-
['white', '#FFFFFF'],
|
|
7
|
-
['maroon', '#800000'],
|
|
8
|
-
['red', '#FF0000'],
|
|
9
|
-
['purple', '#800080'],
|
|
10
|
-
['fuchsia', '#FF00FF'],
|
|
11
|
-
['green', '#008000'],
|
|
12
|
-
['lime', '#00FF00'],
|
|
13
|
-
['olive', '#808000'],
|
|
14
|
-
['yellow', '#FFFF00'],
|
|
15
|
-
['navy', '#000080'],
|
|
16
|
-
['blue', '#0000FF'],
|
|
17
|
-
['teal', '#008080'],
|
|
18
|
-
['aqua', '#00FFFF'],
|
|
19
|
-
['aliceblue', '#f0f8ff'],
|
|
20
|
-
['antiquewhite', '#faebd7'],
|
|
21
|
-
['aquamarine', '#7fffd4'],
|
|
22
|
-
['azure', '#f0ffff'],
|
|
23
|
-
['beige', '#f5f5dc'],
|
|
24
|
-
['bisque', '#ffe4c4'],
|
|
25
|
-
['blanchedalmond', '#ffebcd'],
|
|
26
|
-
['blueviolet', '#8a2be2'],
|
|
27
|
-
['brown', '#a52a2a'],
|
|
28
|
-
['burlywood', '#deb887'],
|
|
29
|
-
['cadetblue', '#5f9ea0'],
|
|
30
|
-
['chartreuse', '#7fff00'],
|
|
31
|
-
['chocolate', '#d2691e'],
|
|
32
|
-
['coral', '#ff7f50'],
|
|
33
|
-
['cornflowerblue', '#6495ed'],
|
|
34
|
-
['cornsilk', '#fff8dc'],
|
|
35
|
-
['crimson', '#dc143c'],
|
|
36
|
-
['cyan', '#00ffff'],
|
|
37
|
-
['darkblue', '#00008b'],
|
|
38
|
-
['darkcyan', '#008b8b'],
|
|
39
|
-
['darkgoldenrod', '#b8860b'],
|
|
40
|
-
['darkgray', '#a9a9a9'],
|
|
41
|
-
['darkgreen', '#006400'],
|
|
42
|
-
['darkgrey', '#a9a9a9'],
|
|
43
|
-
['darkkhaki', '#bdb76b'],
|
|
44
|
-
['darkmagenta', '#8b008b'],
|
|
45
|
-
['darkolivegreen', '#556b2f'],
|
|
46
|
-
['darkorange', '#ff8c00'],
|
|
47
|
-
['darkorchid', '#9932cc'],
|
|
48
|
-
['darkred', '#8b0000'],
|
|
49
|
-
['darksalmon', '#e9967a'],
|
|
50
|
-
['darkseagreen', '#8fbc8f'],
|
|
51
|
-
['darkslateblue', '#483d8b'],
|
|
52
|
-
['darkslategray', '#2f4f4f'],
|
|
53
|
-
['darkslategrey', '#2f4f4f'],
|
|
54
|
-
['darkturquoise', '#00ced1'],
|
|
55
|
-
['darkviolet', '#9400d3'],
|
|
56
|
-
['deeppink', '#ff1493'],
|
|
57
|
-
['deepskyblue', '#00bfff'],
|
|
58
|
-
['dimgray', '#696969'],
|
|
59
|
-
['dimgrey', '#696969'],
|
|
60
|
-
['dodgerblue', '#1e90ff'],
|
|
61
|
-
['firebrick', '#b22222'],
|
|
62
|
-
['floralwhite', '#fffaf0'],
|
|
63
|
-
['forestgreen', '#228b22'],
|
|
64
|
-
['gainsboro', '#dcdcdc'],
|
|
65
|
-
['ghostwhite', '#f8f8ff'],
|
|
66
|
-
['gold', '#ffd700'],
|
|
67
|
-
['goldenrod', '#daa520'],
|
|
68
|
-
['greenyellow', '#adff2f'],
|
|
69
|
-
['grey', '#808080'],
|
|
70
|
-
['honeydew', '#f0fff0'],
|
|
71
|
-
['hotpink', '#ff69b4'],
|
|
72
|
-
['indianred', '#cd5c5c'],
|
|
73
|
-
['indigo', '#4b0082'],
|
|
74
|
-
['ivory', '#fffff0'],
|
|
75
|
-
['khaki', '#f0e68c'],
|
|
76
|
-
['lavender', '#e6e6fa'],
|
|
77
|
-
['lavenderblush', '#fff0f5'],
|
|
78
|
-
['lawngreen', '#7cfc00'],
|
|
79
|
-
['lemonchiffon', '#fffacd'],
|
|
80
|
-
['lightblue', '#add8e6'],
|
|
81
|
-
['lightcoral', '#f08080'],
|
|
82
|
-
['lightcyan', '#e0ffff'],
|
|
83
|
-
['lightgoldenrodyellow', '#fafad2'],
|
|
84
|
-
['lightgray', '#d3d3d3'],
|
|
85
|
-
['lightgreen', '#90ee90'],
|
|
86
|
-
['lightgrey', '#d3d3d3'],
|
|
87
|
-
['lightpink', '#ffb6c1'],
|
|
88
|
-
['lightsalmon', '#ffa07a'],
|
|
89
|
-
['lightseagreen', '#20b2aa'],
|
|
90
|
-
['lightskyblue', '#87cefa'],
|
|
91
|
-
['lightslategray', '#778899'],
|
|
92
|
-
['lightslategrey', '#778899'],
|
|
93
|
-
['lightsteelblue', '#b0c4de'],
|
|
94
|
-
['lightyellow', '#ffffe0'],
|
|
95
|
-
['limegreen', '#32cd32'],
|
|
96
|
-
['linen', '#faf0e6'],
|
|
97
|
-
['magenta', '#ff00ff'],
|
|
98
|
-
['mediumaquamarine', '#66cdaa'],
|
|
99
|
-
['mediumblue', '#0000cd'],
|
|
100
|
-
['mediumorchid', '#ba55d3'],
|
|
101
|
-
['mediumpurple', '#9370db'],
|
|
102
|
-
['mediumseagreen', '#3cb371'],
|
|
103
|
-
['mediumslateblue', '#7b68ee'],
|
|
104
|
-
['mediumspringgreen', '#00fa9a'],
|
|
105
|
-
['mediumturquoise', '#48d1cc'],
|
|
106
|
-
['mediumvioletred', '#c71585'],
|
|
107
|
-
['midnightblue', '#191970'],
|
|
108
|
-
['mintcream', '#f5fffa'],
|
|
109
|
-
['mistyrose', '#ffe4e1'],
|
|
110
|
-
['moccasin', '#ffe4b5'],
|
|
111
|
-
['navajowhite', '#ffdead'],
|
|
112
|
-
['oldlace', '#fdf5e6'],
|
|
113
|
-
['olivedrab', '#6b8e23'],
|
|
114
|
-
['orange', '#ffa500'],
|
|
115
|
-
['orangered', '#ff4500'],
|
|
116
|
-
['orchid', '#da70d6'],
|
|
117
|
-
['palegoldenrod', '#eee8aa'],
|
|
118
|
-
['palegreen', '#98fb98'],
|
|
119
|
-
['paleturquoise', '#afeeee'],
|
|
120
|
-
['palevioletred', '#db7093'],
|
|
121
|
-
['papayawhip', '#ffefd5'],
|
|
122
|
-
['peachpuff', '#ffdab9'],
|
|
123
|
-
['peru', '#cd853f'],
|
|
124
|
-
['pink', '#ffc0cb'],
|
|
125
|
-
['plum', '#dda0dd'],
|
|
126
|
-
['powderblue', '#b0e0e6'],
|
|
127
|
-
['rosybrown', '#bc8f8f'],
|
|
128
|
-
['royalblue', '#4169e1'],
|
|
129
|
-
['saddlebrown', '#8b4513'],
|
|
130
|
-
['salmon', '#fa8072'],
|
|
131
|
-
['sandybrown', '#f4a460'],
|
|
132
|
-
['seagreen', '#2e8b57'],
|
|
133
|
-
['seashell', '#fff5ee'],
|
|
134
|
-
['sienna', '#a0522d'],
|
|
135
|
-
['skyblue', '#87ceeb'],
|
|
136
|
-
['slateblue', '#6a5acd'],
|
|
137
|
-
['slategray', '#708090'],
|
|
138
|
-
['slategrey', '#708090'],
|
|
139
|
-
['snow', '#fffafa'],
|
|
140
|
-
['springgreen', '#00ff7f'],
|
|
141
|
-
['steelblue', '#4682b4'],
|
|
142
|
-
['tan', '#d2b48c'],
|
|
143
|
-
['thistle', '#d8bfd8'],
|
|
144
|
-
['tomato', '#ff6347'],
|
|
145
|
-
['turquoise', '#40e0d0'],
|
|
146
|
-
['violet', '#ee82ee'],
|
|
147
|
-
['wheat', '#f5deb3'],
|
|
148
|
-
['whitesmoke', '#f5f5f5'],
|
|
149
|
-
['yellowgreen', '#9acd32']
|
|
150
|
-
])
|
|
151
|
-
|
|
152
|
-
const hexReg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/
|
|
153
|
-
const rgbReg = /^(rgb|rgba|RGB|RGBA)/
|
|
154
|
-
const rgbaReg = /^(rgba|RGBA)/
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* @description Color validator
|
|
158
|
-
* @param {String} color Hex|Rgb|Rgba color or color keyword
|
|
159
|
-
* @return {String|Boolean} Valid color Or false
|
|
160
|
-
*/
|
|
161
|
-
function validator(color) {
|
|
162
|
-
const isHex = hexReg.test(color)
|
|
163
|
-
const isRgb = rgbReg.test(color)
|
|
164
|
-
if (isHex || isRgb) return color
|
|
165
|
-
color = getColorByKeyword(color)
|
|
166
|
-
if (!color) {
|
|
167
|
-
console.error('Color: Invalid color!')
|
|
168
|
-
return false
|
|
169
|
-
}
|
|
170
|
-
return color
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* @description Get color by keyword
|
|
175
|
-
* @param {String} keyword Color keyword like red, green and etc.
|
|
176
|
-
* @return {String|Boolean} Hex or rgba color (Invalid keyword will return false)
|
|
177
|
-
*/
|
|
178
|
-
function getColorByKeyword(keyword) {
|
|
179
|
-
if (!keyword) {
|
|
180
|
-
console.error('getColorByKeywords: Missing parameters!')
|
|
181
|
-
return false
|
|
182
|
-
}
|
|
183
|
-
if (!colorKeywords.has(keyword)) return false
|
|
184
|
-
return colorKeywords.get(keyword)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* @description Get the Rgb value of the color
|
|
189
|
-
* @param {String} color Hex|Rgb|Rgba color or color keyword
|
|
190
|
-
* @return {Array<Number>|Boolean} Rgb value of the color (Invalid input will return false)
|
|
191
|
-
*/
|
|
192
|
-
export function getRgbValue(color) {
|
|
193
|
-
if (!color) {
|
|
194
|
-
console.error('getRgbValue: Missing parameters!')
|
|
195
|
-
return false
|
|
196
|
-
}
|
|
197
|
-
color = validator(color)
|
|
198
|
-
if (!color) return false
|
|
199
|
-
const isHex = hexReg.test(color)
|
|
200
|
-
const isRgb = rgbReg.test(color)
|
|
201
|
-
const lowerColor = color.toLowerCase()
|
|
202
|
-
if (isHex) return getRgbValueFromHex(lowerColor)
|
|
203
|
-
if (isRgb) return getRgbValueFromRgb(lowerColor)
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* @description Get the rgb value of the hex color
|
|
208
|
-
* @param {String} color Hex color
|
|
209
|
-
* @return {Array<Number>} Rgb value of the color
|
|
210
|
-
*/
|
|
211
|
-
function getRgbValueFromHex(color) {
|
|
212
|
-
color = color.replace('#', '')
|
|
213
|
-
if (color.length === 3)
|
|
214
|
-
color = Array.from(color)
|
|
215
|
-
.map(hexNum => hexNum + hexNum)
|
|
216
|
-
.join('')
|
|
217
|
-
color = color.split('')
|
|
218
|
-
return new Array(3).fill(0).map((t, i) => parseInt(`0x${color[i * 2]}${color[i * 2 + 1]}`))
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* @description Get the rgb value of the rgb/rgba color
|
|
223
|
-
* @param {String} color Hex color
|
|
224
|
-
* @return {Array} Rgb value of the color
|
|
225
|
-
*/
|
|
226
|
-
function getRgbValueFromRgb(color) {
|
|
227
|
-
return color
|
|
228
|
-
.replace(/rgb\(|rgba\(|\)/g, '')
|
|
229
|
-
.split(',')
|
|
230
|
-
.slice(0, 3)
|
|
231
|
-
.map(n => parseInt(n))
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* @description Get the Rgba value of the color
|
|
236
|
-
* @param {String} color Hex|Rgb|Rgba color or color keyword
|
|
237
|
-
* @return {Array<Number>|Boolean} Rgba value of the color (Invalid input will return false)
|
|
238
|
-
*/
|
|
239
|
-
export function getRgbaValue(color) {
|
|
240
|
-
if (!color) {
|
|
241
|
-
console.error('getRgbaValue: Missing parameters!')
|
|
242
|
-
return false
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const colorValue = getRgbValue(color)
|
|
246
|
-
if (!colorValue) return false
|
|
247
|
-
colorValue.push(getOpacity(color))
|
|
248
|
-
return colorValue
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* @description Get the opacity of color
|
|
253
|
-
* @param {String} color Hex|Rgb|Rgba color or color keyword
|
|
254
|
-
* @return {Number|Boolean} Color opacity (Invalid input will return false)
|
|
255
|
-
*/
|
|
256
|
-
export function getOpacity(color) {
|
|
257
|
-
if (!color) {
|
|
258
|
-
console.error('getOpacity: Missing parameters!')
|
|
259
|
-
return false
|
|
260
|
-
}
|
|
261
|
-
color = validator(color)
|
|
262
|
-
if (!color) return false
|
|
263
|
-
const isRgba = rgbaReg.test(color)
|
|
264
|
-
if (!isRgba) return 1
|
|
265
|
-
color = color.toLowerCase()
|
|
266
|
-
return Number(
|
|
267
|
-
color
|
|
268
|
-
.split(',')
|
|
269
|
-
.slice(-1)[0]
|
|
270
|
-
.replace(/[)|\s]/g, '')
|
|
271
|
-
)
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* @description Convert color to Rgb|Rgba color
|
|
276
|
-
* @param {String} color Hex|Rgb|Rgba color or color keyword
|
|
277
|
-
* @param {Number} opacity The opacity of color
|
|
278
|
-
* @return {String|Boolean} Rgb|Rgba color (Invalid input will return false)
|
|
279
|
-
*/
|
|
280
|
-
export function toRgb(color, opacity) {
|
|
281
|
-
if (!color) {
|
|
282
|
-
console.error('toRgb: Missing parameters!')
|
|
283
|
-
return false
|
|
284
|
-
}
|
|
285
|
-
const rgbValue = getRgbValue(color)
|
|
286
|
-
if (!rgbValue) return false
|
|
287
|
-
const addOpacity = typeof opacity === 'number'
|
|
288
|
-
if (addOpacity) return 'rgba(' + rgbValue.join(',') + `,${opacity})`
|
|
289
|
-
return 'rgb(' + rgbValue.join(',') + ')'
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
/**
|
|
293
|
-
* @description Convert color to Hex color
|
|
294
|
-
* @param {String} color Hex|Rgb|Rgba color or color keyword
|
|
295
|
-
* @return {String|Boolean} Hex color (Invalid input will return false)
|
|
296
|
-
*/
|
|
297
|
-
export function toHex(color) {
|
|
298
|
-
if (!color) {
|
|
299
|
-
console.error('toHex: Missing parameters!')
|
|
300
|
-
return false
|
|
301
|
-
}
|
|
302
|
-
if (hexReg.test(color)) return color
|
|
303
|
-
color = getRgbValue(color)
|
|
304
|
-
if (!color) return false
|
|
305
|
-
return (
|
|
306
|
-
'#' +
|
|
307
|
-
color
|
|
308
|
-
.map(n => Number(n).toString(16))
|
|
309
|
-
.map(n => (n === '0' ? '00' : n))
|
|
310
|
-
.join('')
|
|
311
|
-
)
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* @description Get Color from Rgb|Rgba value
|
|
316
|
-
* @param {Array<Number>} value Rgb|Rgba color value
|
|
317
|
-
* @return {String|Boolean} Rgb|Rgba color (Invalid input will return false)
|
|
318
|
-
*/
|
|
319
|
-
export function getColorFromRgbValue(value) {
|
|
320
|
-
if (!value) {
|
|
321
|
-
console.error('getColorFromRgbValue: Missing parameters!')
|
|
322
|
-
return false
|
|
323
|
-
}
|
|
324
|
-
const valueLength = value.length
|
|
325
|
-
if (valueLength !== 3 && valueLength !== 4) {
|
|
326
|
-
console.error('getColorFromRgbValue: Value is illegal!')
|
|
327
|
-
return false
|
|
328
|
-
}
|
|
329
|
-
let color = valueLength === 3 ? 'rgb(' : 'rgba('
|
|
330
|
-
color += value.join(',') + ')'
|
|
331
|
-
return color
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* @description Deepen color
|
|
336
|
-
* @param {String} color Hex|Rgb|Rgba color or color keyword
|
|
337
|
-
* @return {Number} Percent of Deepen (1-100)
|
|
338
|
-
* @return {String|Boolean} Rgba color (Invalid input will return false)
|
|
339
|
-
*/
|
|
340
|
-
export function darken(color, percent = 0) {
|
|
341
|
-
if (!color) {
|
|
342
|
-
console.error('darken: Missing parameters!')
|
|
343
|
-
return false
|
|
344
|
-
}
|
|
345
|
-
let rgbaValue = getRgbaValue(color)
|
|
346
|
-
if (!rgbaValue) return false
|
|
347
|
-
rgbaValue = rgbaValue.map((v, i) => (i === 3 ? v : v - Math.ceil(2.55 * percent))).map(v => (v < 0 ? 0 : v))
|
|
348
|
-
return getColorFromRgbValue(rgbaValue)
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* @description Brighten color
|
|
353
|
-
* @param {String} color Hex|Rgb|Rgba color or color keyword
|
|
354
|
-
* @return {Number} Percent of brighten (1-100)
|
|
355
|
-
* @return {String|Boolean} Rgba color (Invalid input will return false)
|
|
356
|
-
*/
|
|
357
|
-
export function lighten(color, percent = 0) {
|
|
358
|
-
if (!color) {
|
|
359
|
-
console.error('lighten: Missing parameters!')
|
|
360
|
-
return false
|
|
361
|
-
}
|
|
362
|
-
let rgbaValue = getRgbaValue(color)
|
|
363
|
-
if (!rgbaValue) return false
|
|
364
|
-
rgbaValue = rgbaValue.map((v, i) => (i === 3 ? v : v + Math.ceil(2.55 * percent))).map(v => (v > 255 ? 255 : v))
|
|
365
|
-
return getColorFromRgbValue(rgbaValue)
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* @description Adjust color opacity
|
|
370
|
-
* @param {String} color Hex|Rgb|Rgba color or color keyword
|
|
371
|
-
* @param {Number} percent of opacity
|
|
372
|
-
* @return {String|Boolean} Rgba color (Invalid input will return false)
|
|
373
|
-
*/
|
|
374
|
-
export function fade(color, percent = 100) {
|
|
375
|
-
if (!color) {
|
|
376
|
-
console.error('fade: Missing parameters!')
|
|
377
|
-
return false
|
|
378
|
-
}
|
|
379
|
-
const rgbValue = getRgbValue(color)
|
|
380
|
-
if (!rgbValue) return false
|
|
381
|
-
const rgbaValue = [...rgbValue, percent / 100]
|
|
382
|
-
return getColorFromRgbValue(rgbaValue)
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
export default {
|
|
386
|
-
fade,
|
|
387
|
-
toHex,
|
|
388
|
-
toRgb,
|
|
389
|
-
darken,
|
|
390
|
-
lighten,
|
|
391
|
-
getOpacity,
|
|
392
|
-
getRgbValue,
|
|
393
|
-
getRgbaValue,
|
|
394
|
-
getColorFromRgbValue
|
|
395
|
-
}
|
package/packages/utils/dom.js
DELETED
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
const getScrollEventTarget = element => {
|
|
2
|
-
let currentNode = element
|
|
3
|
-
while (currentNode && currentNode.tagName !== 'HTML' && currentNode.nodeType === 1) {
|
|
4
|
-
const overflowY = window.getComputedStyle(currentNode).overflowY
|
|
5
|
-
if (overflowY === 'scroll' || overflowY === 'auto') {
|
|
6
|
-
return currentNode
|
|
7
|
-
}
|
|
8
|
-
currentNode = currentNode.parentNode
|
|
9
|
-
}
|
|
10
|
-
return window
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const getScrollTop = element => {
|
|
14
|
-
if (element === window) {
|
|
15
|
-
return Math.max(window.pageYOffset || 0, document.documentElement.scrollTop)
|
|
16
|
-
} else {
|
|
17
|
-
return element.scrollTop
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const getOffset = el => {
|
|
22
|
-
const box = el.getBoundingClientRect()
|
|
23
|
-
const body = document.body
|
|
24
|
-
const clientTop = el.clientTop || body.clientTop || 0
|
|
25
|
-
const clientLeft = el.clientLeft || body.clientLeft || 0
|
|
26
|
-
const scrollTop = window.pageYOffset || el.scrollTop
|
|
27
|
-
const scrollLeft = window.pageXOffset || el.scrollLeft
|
|
28
|
-
return {
|
|
29
|
-
top: box.top + scrollTop - clientTop,
|
|
30
|
-
left: box.left + scrollLeft - clientLeft
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const transitionEnd = (el, fun) => {
|
|
35
|
-
const arr = ['msTransitionEnd', 'mozTransitionEnd', 'oTransitionEnd', 'webkitTransitionEnd', 'transitionend']
|
|
36
|
-
const handler = {
|
|
37
|
-
handleEvent(event) {
|
|
38
|
-
arr.forEach(function (eventName) {
|
|
39
|
-
el.removeEventListener(eventName, handler, false)
|
|
40
|
-
})
|
|
41
|
-
fun.apply(el, arguments)
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
arr.forEach(function (eventName) {
|
|
45
|
-
el.addEventListener(eventName, handler, false)
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const hasClass = (el, cls) => {
|
|
50
|
-
if (!el || !cls) return false
|
|
51
|
-
if (cls.indexOf(' ') !== -1) throw new Error('className should not contain space.')
|
|
52
|
-
if (el.classList) {
|
|
53
|
-
return el.classList.contains(cls)
|
|
54
|
-
} else {
|
|
55
|
-
return (' ' + el.className + ' ').indexOf(' ' + cls + ' ') > -1
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const addClass = (el, cls) => {
|
|
60
|
-
if (!el) return
|
|
61
|
-
var curClass = el.className
|
|
62
|
-
var classes = (cls || '').split(' ')
|
|
63
|
-
|
|
64
|
-
for (var i = 0, j = classes.length; i < j; i++) {
|
|
65
|
-
var clsName = classes[i]
|
|
66
|
-
if (!clsName) continue
|
|
67
|
-
|
|
68
|
-
if (el.classList) {
|
|
69
|
-
el.classList.add(clsName)
|
|
70
|
-
} else {
|
|
71
|
-
if (!hasClass(el, clsName)) {
|
|
72
|
-
curClass += ' ' + clsName
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
if (!el.classList) {
|
|
77
|
-
el.className = curClass
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const removeClass = (el, cls) => {
|
|
82
|
-
if (!el || !cls) return
|
|
83
|
-
var classes = cls.split(' ')
|
|
84
|
-
var curClass = ' ' + el.className + ' '
|
|
85
|
-
|
|
86
|
-
for (var i = 0, j = classes.length; i < j; i++) {
|
|
87
|
-
var clsName = classes[i]
|
|
88
|
-
if (!clsName) continue
|
|
89
|
-
|
|
90
|
-
if (el.classList) {
|
|
91
|
-
el.classList.remove(clsName)
|
|
92
|
-
} else {
|
|
93
|
-
if (hasClass(el, clsName)) {
|
|
94
|
-
curClass = curClass.replace(' ' + clsName + ' ', ' ')
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
if (!el.classList) {
|
|
99
|
-
el.className = curClass ? curClass.trim() : curClass
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export default {
|
|
104
|
-
getScrollEventTarget,
|
|
105
|
-
getScrollTop,
|
|
106
|
-
getOffset,
|
|
107
|
-
transitionEnd,
|
|
108
|
-
hasClass,
|
|
109
|
-
addClass,
|
|
110
|
-
removeClass
|
|
111
|
-
}
|
package/packages/utils/index.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
|
|
3
|
-
XEUtils.setup({})
|
|
4
|
-
|
|
5
|
-
import number from './number'
|
|
6
|
-
import string from './string'
|
|
7
|
-
import boolean from './boolean'
|
|
8
|
-
import color from './color'
|
|
9
|
-
import dom from './dom'
|
|
10
|
-
import other from './other'
|
|
11
|
-
import validate from './validate'
|
|
12
|
-
import pattern from './pattern'
|
|
13
|
-
|
|
14
|
-
XEUtils.mixin({
|
|
15
|
-
...number,
|
|
16
|
-
...string,
|
|
17
|
-
...boolean,
|
|
18
|
-
...color,
|
|
19
|
-
...dom,
|
|
20
|
-
...other,
|
|
21
|
-
...validate,
|
|
22
|
-
...pattern
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
export default XEUtils
|
package/packages/utils/number.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
import stringUtil from './string'
|
|
3
|
-
import { Parser } from 'hot-formula-parser'
|
|
4
|
-
const formulaParser = new Parser()
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
truncate(num, digits) {
|
|
8
|
-
if (num < 0) {
|
|
9
|
-
let rnum = '-' + XEUtils.floor(String(num).replace('-', ''), digits)
|
|
10
|
-
return Number(rnum)
|
|
11
|
-
} else {
|
|
12
|
-
return XEUtils.floor(num, digits)
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
|
|
16
|
-
calculate(formula, data) {
|
|
17
|
-
if (!formula) return ''
|
|
18
|
-
if (data && XEUtils.isPlainObject(data)) {
|
|
19
|
-
formula = stringUtil.format(formula, data)
|
|
20
|
-
}
|
|
21
|
-
let { result } = formulaParser.parse(formula)
|
|
22
|
-
return result
|
|
23
|
-
}
|
|
24
|
-
}
|
package/packages/utils/object.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default {}
|