sculp-js 0.1.1 → 1.0.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.
- package/README.md +3 -0
- package/lib/cjs/array.js +56 -36
- package/lib/cjs/async.js +3 -3
- package/lib/cjs/clipboard.js +3 -3
- package/lib/cjs/cookie.js +5 -5
- package/lib/cjs/date.js +130 -12
- package/lib/cjs/dom.js +13 -11
- package/lib/cjs/download.js +9 -9
- package/lib/cjs/easing.js +1 -1
- package/lib/cjs/file.js +5 -4
- package/lib/cjs/func.js +1 -1
- package/lib/cjs/index.js +9 -3
- package/lib/cjs/number.js +4 -4
- package/lib/cjs/object.js +11 -9
- package/lib/cjs/path.js +1 -1
- package/lib/cjs/qs.js +5 -5
- package/lib/cjs/random.js +1 -1
- package/lib/cjs/string.js +8 -8
- package/lib/cjs/tooltip.js +118 -0
- package/lib/cjs/type.js +11 -2
- package/lib/cjs/unique.js +1 -1
- package/lib/cjs/url.js +1 -1
- package/lib/cjs/watermark.js +8 -9
- package/lib/es/array.js +55 -35
- package/lib/es/async.js +3 -3
- package/lib/es/clipboard.js +3 -3
- package/lib/es/cookie.js +5 -5
- package/lib/es/date.js +127 -13
- package/lib/es/dom.js +13 -11
- package/lib/es/download.js +9 -9
- package/lib/es/easing.js +1 -1
- package/lib/es/file.js +5 -4
- package/lib/es/func.js +1 -1
- package/lib/es/index.js +4 -3
- package/lib/es/number.js +4 -4
- package/lib/es/object.js +11 -9
- package/lib/es/path.js +1 -1
- package/lib/es/qs.js +5 -5
- package/lib/es/random.js +1 -1
- package/lib/es/string.js +8 -8
- package/lib/es/tooltip.js +116 -0
- package/lib/es/type.js +11 -2
- package/lib/es/unique.js +1 -1
- package/lib/es/url.js +1 -1
- package/lib/es/watermark.js +8 -9
- package/lib/index.d.ts +155 -66
- package/lib/tsdoc-metadata.json +11 -0
- package/lib/umd/index.js +365 -108
- package/package.json +3 -2
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* sculp-js v1.0.0
|
|
3
|
+
* (c) 2023-2023 chandq
|
|
4
|
+
* Released under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { getStrWidthPx } from './string.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @title tooltip
|
|
11
|
+
* @Desc 自定义的tooltip方法, 支持拖动悬浮提示
|
|
12
|
+
* Created by chendeqiao on 2017/5/8.
|
|
13
|
+
* @example
|
|
14
|
+
* <span onmouseleave="handleMouseLeave('#root')" onmousemove="handleMouseEnter({rootElId: '#root', title: 'title content', event: event})"
|
|
15
|
+
* onmouseenter="handleMouseEnter({'#root', title: 'title content', event: event})">title content </span>
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* 自定义title提示功能的mouseenter事件句柄
|
|
19
|
+
* @param {ITooltipParams} param1
|
|
20
|
+
* @returns {*}
|
|
21
|
+
*/
|
|
22
|
+
function handleMouseEnter({ rootElId = '#root', title, event }) {
|
|
23
|
+
try {
|
|
24
|
+
const $rootEl = document.querySelector(rootElId);
|
|
25
|
+
console.assert($rootEl !== null, `未找到id为 ${rootElId} 的dom元素`);
|
|
26
|
+
let $customTitle = null;
|
|
27
|
+
// 动态创建class样式,并加入到head中
|
|
28
|
+
if (!document.querySelector('.tooltip-inner1494304949567')) {
|
|
29
|
+
const tooltipWrapperClass = document.createElement('style');
|
|
30
|
+
tooltipWrapperClass.type = 'text/css';
|
|
31
|
+
tooltipWrapperClass.innerHTML = `
|
|
32
|
+
.tooltip-inner1494304949567 {
|
|
33
|
+
max-width: 250px;
|
|
34
|
+
padding: 3px 8px;
|
|
35
|
+
color: #fff;
|
|
36
|
+
text-decoration: none;
|
|
37
|
+
border-radius: 4px;
|
|
38
|
+
text-align: left;
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
document.querySelector('head').appendChild(tooltipWrapperClass);
|
|
42
|
+
}
|
|
43
|
+
if (document.querySelector('#customTitle1494304949567')) {
|
|
44
|
+
$customTitle = document.querySelector('#customTitle1494304949567');
|
|
45
|
+
mouseenter($customTitle, title, event);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const $contentContainer = document.createElement('div');
|
|
49
|
+
$contentContainer.className = 'customTitle';
|
|
50
|
+
$contentContainer.id = 'customTitle1494304949567';
|
|
51
|
+
$contentContainer.className = 'tooltip';
|
|
52
|
+
$contentContainer.style.cssText = 'z-index: 99999999; visibility: hidden;';
|
|
53
|
+
$contentContainer.innerHTML =
|
|
54
|
+
'<div class="tooltip-inner1494304949567" style="word-wrap: break-word; max-width: 44px;">皮肤</div>';
|
|
55
|
+
$rootEl.appendChild($contentContainer);
|
|
56
|
+
$customTitle = document.querySelector('#customTitle1494304949567');
|
|
57
|
+
if (title) {
|
|
58
|
+
//判断div显示的内容是否为空
|
|
59
|
+
mouseenter($customTitle, title, event);
|
|
60
|
+
$customTitle.style.visibility = 'visible';
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.error(e.message);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 提示文案dom渲染的处理函数
|
|
70
|
+
* @param {HTMLDivElement} customTitle
|
|
71
|
+
* @param {string} title 提示的字符串
|
|
72
|
+
* @param {PointerEvent} e 事件对象
|
|
73
|
+
* @returns {*}
|
|
74
|
+
*/
|
|
75
|
+
function mouseenter($customTitle, title, e) {
|
|
76
|
+
let diffValueX = 200 + 50; //默认设置弹出div的宽度为250px
|
|
77
|
+
let x = 13;
|
|
78
|
+
const y = 23;
|
|
79
|
+
const $contentEle = $customTitle.children[0];
|
|
80
|
+
if (getStrWidthPx(title, 12) < 180 + 50) {
|
|
81
|
+
//【弹出div自适应字符串宽度】若显示的字符串占用宽度小于180,则设置弹出div的宽度为“符串占用宽度”+20
|
|
82
|
+
$contentEle.style.maxWidth = getStrWidthPx(title, 12) + 20 + 50 + 'px';
|
|
83
|
+
diffValueX = e.clientX + (getStrWidthPx(title, 12) + 50) - document.body.offsetWidth;
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
$contentEle.style.maxWidth = '250px';
|
|
87
|
+
diffValueX = e.clientX + 230 - document.body.offsetWidth; //计算div水平方向显示的内容超出屏幕多少宽度
|
|
88
|
+
}
|
|
89
|
+
$contentEle.innerHTML = title; //html方法可解析内容中换行标签,text方法不能
|
|
90
|
+
if (diffValueX > 0) {
|
|
91
|
+
//水平方向超出可见区域时
|
|
92
|
+
x -= diffValueX;
|
|
93
|
+
}
|
|
94
|
+
$customTitle.style.top = e.clientY + y + 'px';
|
|
95
|
+
$customTitle.style.left = e.clientX + x + 'px';
|
|
96
|
+
$customTitle.style.maxWidth = '250px';
|
|
97
|
+
const diffValueY = $customTitle.getBoundingClientRect().top + $contentEle.offsetHeight - document.body.offsetHeight;
|
|
98
|
+
if (diffValueY > 0) {
|
|
99
|
+
//垂直方向超出可见区域时
|
|
100
|
+
$customTitle.style.top = e.clientY - diffValueY + 'px';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 移除提示文案dom的事件句柄
|
|
105
|
+
* @param {string} rootElId
|
|
106
|
+
* @returns {*}
|
|
107
|
+
*/
|
|
108
|
+
function handleMouseLeave(rootElId = '#root') {
|
|
109
|
+
const rootEl = document.querySelector(rootElId), titleEl = document.querySelector('#customTitle1494304949567');
|
|
110
|
+
if (rootEl && titleEl) {
|
|
111
|
+
rootEl.removeChild(titleEl);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const tooltipEvent = { handleMouseEnter, handleMouseLeave };
|
|
115
|
+
|
|
116
|
+
export { tooltipEvent };
|
package/lib/es/type.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js
|
|
2
|
+
* sculp-js v1.0.0
|
|
3
3
|
* (c) 2023-2023 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* 判断任意值的数据类型
|
|
9
|
+
* @param {unknown} any
|
|
10
|
+
* @returns {string}
|
|
11
|
+
*/
|
|
7
12
|
const typeIs = (any) => Object.prototype.toString.call(any).slice(8, -1);
|
|
8
13
|
// 基本数据类型判断
|
|
9
14
|
const isString = (any) => typeof any === 'string';
|
|
@@ -17,7 +22,11 @@ const isPrimitive = (any) => any === null || typeof any !== 'object';
|
|
|
17
22
|
// 复合数据类型判断
|
|
18
23
|
const isObject = (any) => typeIs(any) === 'Object';
|
|
19
24
|
const isArray = (any) => Array.isArray(any);
|
|
20
|
-
|
|
25
|
+
/**
|
|
26
|
+
* 判断是否为函数
|
|
27
|
+
* @param {unknown} any
|
|
28
|
+
* @returns {boolean}
|
|
29
|
+
*/
|
|
21
30
|
const isFunction = (any) => typeof any === 'function';
|
|
22
31
|
// 对象类型判断
|
|
23
32
|
const isNaN = (any) => Number.isNaN(any);
|
package/lib/es/unique.js
CHANGED
package/lib/es/url.js
CHANGED
package/lib/es/watermark.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* sculp-js
|
|
2
|
+
* sculp-js v1.0.0
|
|
3
3
|
* (c) 2023-2023 chandq
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
@@ -11,17 +11,18 @@
|
|
|
11
11
|
* @desc 网页加水印的工具类
|
|
12
12
|
*/
|
|
13
13
|
/**
|
|
14
|
-
* canvas 实现
|
|
14
|
+
* canvas 实现 水印, 具备防删除功能
|
|
15
15
|
* @param {ICanvasWM} canvasWM
|
|
16
|
+
* @example genCanvasWM({ content: 'QQMusicFE' })
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
|
+
function genCanvasWM(canvasWM) {
|
|
18
19
|
const { container = document.body, width = '300px', height = '200px', textAlign = 'center', textBaseline = 'middle', font = '20px PingFangSC-Medium,PingFang SC',
|
|
19
20
|
// fontWeight = 500,
|
|
20
21
|
fillStyle = 'rgba(189, 177, 167, .3)', content = '请勿外传', rotate = 30, zIndex = 2147483647 } = canvasWM;
|
|
21
22
|
// 仅限主页面添加水印
|
|
22
|
-
if (!location.pathname.includes('/home')) {
|
|
23
|
-
|
|
24
|
-
}
|
|
23
|
+
// if (!location.pathname.includes('/home')) {
|
|
24
|
+
// return;
|
|
25
|
+
// }
|
|
25
26
|
const args = canvasWM;
|
|
26
27
|
const canvas = document.createElement('canvas');
|
|
27
28
|
canvas.setAttribute('width', width);
|
|
@@ -82,8 +83,6 @@ const genCanvasWM = (canvasWM) => {
|
|
|
82
83
|
});
|
|
83
84
|
mo.observe(container, { attributes: true, subtree: true, childList: true });
|
|
84
85
|
}
|
|
85
|
-
}
|
|
86
|
-
// 调用
|
|
87
|
-
// __canvasWM({ content: 'QQMusicFE' })
|
|
86
|
+
}
|
|
88
87
|
|
|
89
88
|
export { genCanvasWM };
|