sculp-js 1.9.0 → 1.10.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.
- package/lib/cjs/array.js +1 -1
- package/lib/cjs/async.js +1 -1
- package/lib/cjs/base64.js +1 -1
- package/lib/cjs/clipboard.js +1 -1
- package/lib/cjs/cloneDeep.js +1 -1
- package/lib/cjs/cookie.js +1 -1
- package/lib/cjs/date.js +1 -1
- package/lib/cjs/dom.js +11 -7
- package/lib/cjs/download.js +1 -1
- package/lib/cjs/easing.js +1 -1
- package/lib/cjs/file.js +1 -1
- package/lib/cjs/func.js +1 -1
- package/lib/cjs/index.js +1 -1
- package/lib/cjs/isEqual.js +1 -1
- package/lib/cjs/math.js +1 -1
- package/lib/cjs/number.js +10 -4
- package/lib/cjs/object.js +1 -1
- package/lib/cjs/path.js +1 -1
- package/lib/cjs/qs.js +1 -1
- package/lib/cjs/random.js +1 -1
- package/lib/cjs/string.js +1 -1
- package/lib/cjs/tooltip.js +20 -16
- package/lib/cjs/tree.js +1 -1
- package/lib/cjs/type.js +1 -1
- package/lib/cjs/unique.js +1 -1
- package/lib/cjs/url.js +1 -1
- package/lib/cjs/validator.js +1 -1
- package/lib/cjs/variable.js +1 -1
- package/lib/cjs/watermark.js +20 -19
- package/lib/cjs/we-decode.js +1 -1
- package/lib/es/array.js +1 -1
- package/lib/es/async.js +1 -1
- package/lib/es/base64.js +1 -1
- package/lib/es/clipboard.js +1 -1
- package/lib/es/cloneDeep.js +1 -1
- package/lib/es/cookie.js +1 -1
- package/lib/es/date.js +1 -1
- package/lib/es/dom.js +11 -7
- package/lib/es/download.js +1 -1
- package/lib/es/easing.js +1 -1
- package/lib/es/file.js +1 -1
- package/lib/es/func.js +1 -1
- package/lib/es/index.js +1 -1
- package/lib/es/isEqual.js +1 -1
- package/lib/es/math.js +1 -1
- package/lib/es/number.js +10 -4
- package/lib/es/object.js +1 -1
- package/lib/es/path.js +1 -1
- package/lib/es/qs.js +1 -1
- package/lib/es/random.js +1 -1
- package/lib/es/string.js +1 -1
- package/lib/es/tooltip.js +20 -16
- package/lib/es/tree.js +1 -1
- package/lib/es/type.js +1 -1
- package/lib/es/unique.js +1 -1
- package/lib/es/url.js +1 -1
- package/lib/es/validator.js +1 -1
- package/lib/es/variable.js +1 -1
- package/lib/es/watermark.js +20 -19
- package/lib/es/we-decode.js +1 -1
- package/lib/index.d.ts +24 -21
- package/lib/umd/index.js +55 -43
- package/package.json +2 -1
package/lib/cjs/array.js
CHANGED
package/lib/cjs/async.js
CHANGED
package/lib/cjs/base64.js
CHANGED
package/lib/cjs/clipboard.js
CHANGED
package/lib/cjs/cloneDeep.js
CHANGED
package/lib/cjs/cookie.js
CHANGED
package/lib/cjs/date.js
CHANGED
package/lib/cjs/dom.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
2
|
+
* sculp-js v1.10.0
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -133,28 +133,32 @@ function getComputedCssVal(el, property, reNumber = true) {
|
|
|
133
133
|
* 字符串的像素宽度
|
|
134
134
|
* @param {string} str 目标字符串
|
|
135
135
|
* @param {number} fontSize 字符串字体大小
|
|
136
|
-
* @param {boolean}
|
|
136
|
+
* @param {boolean} isRemove 计算后是否移除创建的dom元素
|
|
137
137
|
* @returns {*}
|
|
138
138
|
*/
|
|
139
|
-
function getStrWidthPx(str, fontSize = 14,
|
|
139
|
+
function getStrWidthPx(str, fontSize = 14, isRemove = true) {
|
|
140
140
|
let strWidth = 0;
|
|
141
141
|
console.assert(type.isString(str), `${str} 不是有效的字符串`);
|
|
142
142
|
if (type.isString(str) && str.length > 0) {
|
|
143
|
-
|
|
143
|
+
const id = 'getStrWidth1494304949567';
|
|
144
|
+
let getEle = document.querySelector(`#${id}`);
|
|
144
145
|
if (!getEle) {
|
|
145
146
|
const _ele = document.createElement('span');
|
|
146
|
-
_ele.id =
|
|
147
|
+
_ele.id = id;
|
|
147
148
|
_ele.style.fontSize = fontSize + 'px';
|
|
148
149
|
_ele.style.whiteSpace = 'nowrap';
|
|
149
150
|
_ele.style.visibility = 'hidden';
|
|
151
|
+
_ele.style.position = 'absolute';
|
|
152
|
+
_ele.style.top = '-9999px';
|
|
153
|
+
_ele.style.left = '-9999px';
|
|
150
154
|
_ele.textContent = str;
|
|
151
155
|
document.body.appendChild(_ele);
|
|
152
156
|
getEle = _ele;
|
|
153
157
|
}
|
|
154
158
|
getEle.textContent = str;
|
|
155
159
|
strWidth = getEle.offsetWidth;
|
|
156
|
-
if (
|
|
157
|
-
|
|
160
|
+
if (isRemove) {
|
|
161
|
+
getEle.remove();
|
|
158
162
|
}
|
|
159
163
|
}
|
|
160
164
|
return strWidth;
|
package/lib/cjs/download.js
CHANGED
package/lib/cjs/easing.js
CHANGED
package/lib/cjs/file.js
CHANGED
package/lib/cjs/func.js
CHANGED
package/lib/cjs/index.js
CHANGED
package/lib/cjs/isEqual.js
CHANGED
package/lib/cjs/math.js
CHANGED
package/lib/cjs/number.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
2
|
+
* sculp-js v1.10.0
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -78,11 +78,17 @@ const numberAbbr = (num, units, options = { ratio: 1000, decimals: 0, separator:
|
|
|
78
78
|
* ['Byte', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']
|
|
79
79
|
* @returns
|
|
80
80
|
*/
|
|
81
|
-
function humanFileSize(num, options) {
|
|
82
|
-
const { decimals = 0, si = false, separator = ' ', maxUnit } = options;
|
|
83
|
-
|
|
81
|
+
function humanFileSize(num, options = { decimals: 0, si: false, separator: ' ' }) {
|
|
82
|
+
const { decimals = 0, si = false, separator = ' ', baseUnit, maxUnit } = options;
|
|
83
|
+
let units = si
|
|
84
84
|
? ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
85
85
|
: ['Byte', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];
|
|
86
|
+
if (!type.isNullOrUnDef(baseUnit)) {
|
|
87
|
+
const targetIndex = units.findIndex(el => el === baseUnit);
|
|
88
|
+
if (targetIndex !== -1) {
|
|
89
|
+
units = units.slice(targetIndex);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
86
92
|
if (!type.isNullOrUnDef(maxUnit)) {
|
|
87
93
|
const targetIndex = units.findIndex(el => el === maxUnit);
|
|
88
94
|
if (targetIndex !== -1) {
|
package/lib/cjs/object.js
CHANGED
package/lib/cjs/path.js
CHANGED
package/lib/cjs/qs.js
CHANGED
package/lib/cjs/random.js
CHANGED
package/lib/cjs/string.js
CHANGED
package/lib/cjs/tooltip.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
2
|
+
* sculp-js v1.10.0
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -7,51 +7,55 @@
|
|
|
7
7
|
'use strict';
|
|
8
8
|
|
|
9
9
|
var dom = require('./dom.js');
|
|
10
|
+
var type = require('./type.js');
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @title tooltip
|
|
13
14
|
* @Desc 自定义的tooltip方法, 支持拖动悬浮提示
|
|
14
15
|
* Created by chendeqiao on 2017/5/8.
|
|
15
16
|
* @example
|
|
16
|
-
* <span onmouseleave="handleMouseLeave('#root')" onmousemove="handleMouseEnter({
|
|
17
|
-
* onmouseenter="handleMouseEnter({'#root', title: 'title content', event: event})">title content </span>
|
|
17
|
+
* <span onmouseleave="handleMouseLeave('#root')" onmousemove="handleMouseEnter({rootContainer: '#root', title: 'title content', event: event})"
|
|
18
|
+
* onmouseenter="handleMouseEnter({rootContainer:'#root', title: 'title content', event: event})">title content </span>
|
|
18
19
|
*/
|
|
19
20
|
/**
|
|
20
21
|
* 自定义title提示功能的mouseenter事件句柄
|
|
21
22
|
* @param {ITooltipParams} param1
|
|
22
23
|
* @returns {*}
|
|
23
24
|
*/
|
|
24
|
-
function handleMouseEnter({
|
|
25
|
+
function handleMouseEnter({ rootContainer = '#root', title, event, bgColor = '#000', color = '#fff' }) {
|
|
25
26
|
try {
|
|
26
|
-
const $rootEl = document.querySelector(
|
|
27
|
-
|
|
27
|
+
const $rootEl = type.isString(rootContainer) ? document.querySelector(rootContainer) : rootContainer;
|
|
28
|
+
if (!$rootEl) {
|
|
29
|
+
throw new Error(`${rootContainer} is not valid Html Element or element selector`);
|
|
30
|
+
}
|
|
28
31
|
let $customTitle = null;
|
|
32
|
+
const styleId = 'style-tooltip-inner1494304949567';
|
|
29
33
|
// 动态创建class样式,并加入到head中
|
|
30
|
-
if (!document.querySelector(
|
|
34
|
+
if (!document.querySelector(`#${styleId}`)) {
|
|
31
35
|
const tooltipWrapperClass = document.createElement('style');
|
|
32
36
|
tooltipWrapperClass.type = 'text/css';
|
|
37
|
+
tooltipWrapperClass.id = styleId;
|
|
33
38
|
tooltipWrapperClass.innerHTML = `
|
|
34
39
|
.tooltip-inner1494304949567 {
|
|
35
40
|
max-width: 250px;
|
|
36
41
|
padding: 3px 8px;
|
|
37
|
-
color:
|
|
42
|
+
color: ${color};
|
|
38
43
|
text-decoration: none;
|
|
39
44
|
border-radius: 4px;
|
|
40
45
|
text-align: left;
|
|
46
|
+
background-color: ${bgColor};
|
|
41
47
|
}
|
|
42
48
|
`;
|
|
43
49
|
document.querySelector('head').appendChild(tooltipWrapperClass);
|
|
44
50
|
}
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
$customTitle = document.querySelector('#customTitle1494304949567');
|
|
52
|
+
if ($customTitle) {
|
|
47
53
|
mouseenter($customTitle, title, event);
|
|
48
54
|
}
|
|
49
55
|
else {
|
|
50
56
|
const $contentContainer = document.createElement('div');
|
|
51
|
-
$contentContainer.className = 'customTitle';
|
|
52
57
|
$contentContainer.id = 'customTitle1494304949567';
|
|
53
|
-
$contentContainer.
|
|
54
|
-
$contentContainer.style.cssText = 'z-index: 99999999; visibility: hidden;';
|
|
58
|
+
$contentContainer.style.cssText = 'z-index: 99999999; visibility: hidden; position: absolute;';
|
|
55
59
|
$contentContainer.innerHTML =
|
|
56
60
|
'<div class="tooltip-inner1494304949567" style="word-wrap: break-word; max-width: 44px;">皮肤</div>';
|
|
57
61
|
$rootEl.appendChild($contentContainer);
|
|
@@ -104,11 +108,11 @@ function mouseenter($customTitle, title, e) {
|
|
|
104
108
|
}
|
|
105
109
|
/**
|
|
106
110
|
* 移除提示文案dom的事件句柄
|
|
107
|
-
* @param {string}
|
|
111
|
+
* @param {string} rootContainer
|
|
108
112
|
* @returns {*}
|
|
109
113
|
*/
|
|
110
|
-
function handleMouseLeave(
|
|
111
|
-
const rootEl = document.querySelector(
|
|
114
|
+
function handleMouseLeave(rootContainer = '#root') {
|
|
115
|
+
const rootEl = type.isString(rootContainer) ? document.querySelector(rootContainer) : rootContainer, titleEl = document.querySelector('#customTitle1494304949567');
|
|
112
116
|
if (rootEl && titleEl) {
|
|
113
117
|
rootEl.removeChild(titleEl);
|
|
114
118
|
}
|
package/lib/cjs/tree.js
CHANGED
package/lib/cjs/type.js
CHANGED
package/lib/cjs/unique.js
CHANGED
package/lib/cjs/url.js
CHANGED
package/lib/cjs/validator.js
CHANGED
package/lib/cjs/variable.js
CHANGED
package/lib/cjs/watermark.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
2
|
+
* sculp-js v1.10.0
|
|
3
3
|
* (c) 2023-present 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
|
+
|
|
9
11
|
/*
|
|
10
12
|
* @created: Saturday, 2020-04-18 14:38:23
|
|
11
13
|
* @author: chendq
|
|
@@ -17,15 +19,14 @@
|
|
|
17
19
|
* @param {ICanvasWM} canvasWM
|
|
18
20
|
* @example genCanvasWM({ content: 'QQMusicFE' })
|
|
19
21
|
*/
|
|
20
|
-
function genCanvasWM(canvasWM) {
|
|
21
|
-
const {
|
|
22
|
+
function genCanvasWM(content = '请勿外传', canvasWM) {
|
|
23
|
+
const { rootContainer = document.body, width = '300px', height = '150px', textAlign = 'center', textBaseline = 'middle', font = '20px PingFangSC-Medium,PingFang SC',
|
|
22
24
|
// fontWeight = 500,
|
|
23
|
-
fillStyle = 'rgba(189, 177, 167, .3)',
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const args = canvasWM;
|
|
25
|
+
fillStyle = 'rgba(189, 177, 167, .3)', rotate = -20, zIndex = 2147483647, watermarkId = '__wm' } = type.isNullOrUnDef(canvasWM) ? {} : canvasWM;
|
|
26
|
+
const container = type.isString(rootContainer) ? document.querySelector(rootContainer) : rootContainer;
|
|
27
|
+
if (!container) {
|
|
28
|
+
throw new Error(`${rootContainer} is not valid Html Element or element selector`);
|
|
29
|
+
}
|
|
29
30
|
const canvas = document.createElement('canvas');
|
|
30
31
|
canvas.setAttribute('width', width);
|
|
31
32
|
canvas.setAttribute('height', height);
|
|
@@ -38,36 +39,36 @@ function genCanvasWM(canvasWM) {
|
|
|
38
39
|
ctx.rotate((Math.PI / 180) * rotate);
|
|
39
40
|
ctx.fillText(content, parseFloat(width) / 4, parseFloat(height) / 2);
|
|
40
41
|
const base64Url = canvas.toDataURL();
|
|
41
|
-
const __wm = document.querySelector(
|
|
42
|
+
const __wm = document.querySelector(`#${watermarkId}`);
|
|
42
43
|
const watermarkDiv = __wm || document.createElement('div');
|
|
43
44
|
const styleStr = `opacity: 1 !important; display: block !important; visibility: visible !important; position:absolute; left:0; top:0; width:100%; height:100%; z-index:${zIndex}; pointer-events:none; background-repeat:repeat; background-image:url('${base64Url}')`;
|
|
44
45
|
watermarkDiv.setAttribute('style', styleStr);
|
|
45
|
-
watermarkDiv.
|
|
46
|
+
watermarkDiv.setAttribute('id', watermarkId);
|
|
46
47
|
watermarkDiv.classList.add('nav-height');
|
|
47
48
|
if (!__wm) {
|
|
48
49
|
container.style.position = 'relative';
|
|
49
50
|
container.appendChild(watermarkDiv);
|
|
50
51
|
}
|
|
51
52
|
const getMutableStyle = (ele) => {
|
|
52
|
-
const
|
|
53
|
+
const computedStyle = getComputedStyle(ele);
|
|
53
54
|
return {
|
|
54
|
-
opacity:
|
|
55
|
-
zIndex:
|
|
56
|
-
display:
|
|
57
|
-
visibility:
|
|
55
|
+
opacity: computedStyle.getPropertyValue('opacity'),
|
|
56
|
+
zIndex: computedStyle.getPropertyValue('z-index'),
|
|
57
|
+
display: computedStyle.getPropertyValue('display'),
|
|
58
|
+
visibility: computedStyle.getPropertyValue('visibility')
|
|
58
59
|
};
|
|
59
60
|
};
|
|
60
61
|
//@ts-ignore
|
|
61
62
|
const MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
|
|
62
63
|
if (MutationObserver) {
|
|
63
64
|
let mo = new MutationObserver(function () {
|
|
64
|
-
const __wm = document.querySelector(
|
|
65
|
+
const __wm = document.querySelector(`#${watermarkId}`); // 只在__wm元素变动才重新调用 __canvasWM
|
|
65
66
|
if (!__wm) {
|
|
66
67
|
// 避免一直触发
|
|
67
68
|
// console.log('regenerate watermark by delete::')
|
|
68
69
|
mo.disconnect();
|
|
69
70
|
mo = null;
|
|
70
|
-
genCanvasWM(
|
|
71
|
+
genCanvasWM(content, canvasWM);
|
|
71
72
|
}
|
|
72
73
|
else {
|
|
73
74
|
const { opacity, zIndex, display, visibility } = getMutableStyle(__wm);
|
|
@@ -79,7 +80,7 @@ function genCanvasWM(canvasWM) {
|
|
|
79
80
|
mo.disconnect();
|
|
80
81
|
mo = null;
|
|
81
82
|
container.removeChild(__wm);
|
|
82
|
-
genCanvasWM(
|
|
83
|
+
genCanvasWM(content, canvasWM);
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
});
|
package/lib/cjs/we-decode.js
CHANGED
package/lib/es/array.js
CHANGED
package/lib/es/async.js
CHANGED
package/lib/es/base64.js
CHANGED
package/lib/es/clipboard.js
CHANGED
package/lib/es/cloneDeep.js
CHANGED
package/lib/es/cookie.js
CHANGED
package/lib/es/date.js
CHANGED
package/lib/es/dom.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js v1.
|
|
2
|
+
* sculp-js v1.10.0
|
|
3
3
|
* (c) 2023-present chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -131,28 +131,32 @@ function getComputedCssVal(el, property, reNumber = true) {
|
|
|
131
131
|
* 字符串的像素宽度
|
|
132
132
|
* @param {string} str 目标字符串
|
|
133
133
|
* @param {number} fontSize 字符串字体大小
|
|
134
|
-
* @param {boolean}
|
|
134
|
+
* @param {boolean} isRemove 计算后是否移除创建的dom元素
|
|
135
135
|
* @returns {*}
|
|
136
136
|
*/
|
|
137
|
-
function getStrWidthPx(str, fontSize = 14,
|
|
137
|
+
function getStrWidthPx(str, fontSize = 14, isRemove = true) {
|
|
138
138
|
let strWidth = 0;
|
|
139
139
|
console.assert(isString(str), `${str} 不是有效的字符串`);
|
|
140
140
|
if (isString(str) && str.length > 0) {
|
|
141
|
-
|
|
141
|
+
const id = 'getStrWidth1494304949567';
|
|
142
|
+
let getEle = document.querySelector(`#${id}`);
|
|
142
143
|
if (!getEle) {
|
|
143
144
|
const _ele = document.createElement('span');
|
|
144
|
-
_ele.id =
|
|
145
|
+
_ele.id = id;
|
|
145
146
|
_ele.style.fontSize = fontSize + 'px';
|
|
146
147
|
_ele.style.whiteSpace = 'nowrap';
|
|
147
148
|
_ele.style.visibility = 'hidden';
|
|
149
|
+
_ele.style.position = 'absolute';
|
|
150
|
+
_ele.style.top = '-9999px';
|
|
151
|
+
_ele.style.left = '-9999px';
|
|
148
152
|
_ele.textContent = str;
|
|
149
153
|
document.body.appendChild(_ele);
|
|
150
154
|
getEle = _ele;
|
|
151
155
|
}
|
|
152
156
|
getEle.textContent = str;
|
|
153
157
|
strWidth = getEle.offsetWidth;
|
|
154
|
-
if (
|
|
155
|
-
|
|
158
|
+
if (isRemove) {
|
|
159
|
+
getEle.remove();
|
|
156
160
|
}
|
|
157
161
|
}
|
|
158
162
|
return strWidth;
|
package/lib/es/download.js
CHANGED
package/lib/es/easing.js
CHANGED
package/lib/es/file.js
CHANGED
package/lib/es/func.js
CHANGED
package/lib/es/index.js
CHANGED
package/lib/es/isEqual.js
CHANGED
package/lib/es/math.js
CHANGED