@qxs-bns/utils 0.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/index.cjs +1 -0
- package/index.js +19 -0
- package/package.json +18 -0
- package/src/device.cjs +1 -0
- package/src/device.js +20 -0
- package/src/media.cjs +1 -0
- package/src/media.js +6 -0
- package/src/storage.cjs +1 -0
- package/src/storage.js +74 -0
- package/src/types.cjs +1 -0
- package/src/types.js +16 -0
- package/src/watermark.cjs +31 -0
- package/src/watermark.js +157 -0
- package/types/index.d.ts +103 -0
package/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./src/device.cjs"),t=require("./src/media.cjs"),i=require("./src/storage.cjs"),e=require("./src/types.cjs"),s=require("./src/watermark.cjs"),o=require("vue");exports.isMobile=r.isMobile;exports.isImageByMimeType=t.isImageByMimeType;exports.initStorage=i.initStorage;exports.useStorage=i.useStorage;exports.isBoolean=e.isBoolean;exports.isElement=e.isElement;exports.isNumber=e.isNumber;exports.isUndefined=e.isUndefined;exports.isWindow=e.isWindow;exports.watermark=s.watermark;Object.defineProperty(exports,"isVNode",{enumerable:!0,get:()=>o.isVNode});
|
package/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isMobile as r } from "./src/device.js";
|
|
2
|
+
import { isImageByMimeType as m } from "./src/media.js";
|
|
3
|
+
import { initStorage as s, useStorage as f } from "./src/storage.js";
|
|
4
|
+
import { isBoolean as a, isElement as n, isNumber as x, isUndefined as d, isWindow as g } from "./src/types.js";
|
|
5
|
+
import { watermark as b } from "./src/watermark.js";
|
|
6
|
+
import { isVNode as w } from "vue";
|
|
7
|
+
export {
|
|
8
|
+
s as initStorage,
|
|
9
|
+
a as isBoolean,
|
|
10
|
+
n as isElement,
|
|
11
|
+
m as isImageByMimeType,
|
|
12
|
+
r as isMobile,
|
|
13
|
+
x as isNumber,
|
|
14
|
+
d as isUndefined,
|
|
15
|
+
w as isVNode,
|
|
16
|
+
g as isWindow,
|
|
17
|
+
f as useStorage,
|
|
18
|
+
b as watermark
|
|
19
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qxs-bns/utils",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "./index.cjs",
|
|
5
|
+
"module": "./index.js",
|
|
6
|
+
"types": "./types/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./types/index.d.ts",
|
|
10
|
+
"import": "./index.js",
|
|
11
|
+
"require": "./index.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public",
|
|
16
|
+
"registry": "https://registry.npmjs.org/"
|
|
17
|
+
}
|
|
18
|
+
}
|
package/src/device.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(){const i=navigator.userAgent,n=["Android","iPhone","SymbianOS","Windows Phone","iPad","iPod"];let t=!1;for(let e=0;e<n.length;e++)if(i.indexOf(n[e])>0){t=!0;break}return t}exports.isMobile=o;
|
package/src/device.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function i() {
|
|
2
|
+
const t = navigator.userAgent, n = [
|
|
3
|
+
"Android",
|
|
4
|
+
"iPhone",
|
|
5
|
+
"SymbianOS",
|
|
6
|
+
"Windows Phone",
|
|
7
|
+
"iPad",
|
|
8
|
+
"iPod"
|
|
9
|
+
];
|
|
10
|
+
let o = !1;
|
|
11
|
+
for (let e = 0; e < n.length; e++)
|
|
12
|
+
if (t.indexOf(n[e]) > 0) {
|
|
13
|
+
o = !0;
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
return o;
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
i as isMobile
|
|
20
|
+
};
|
package/src/media.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function t(e){return e.type.startsWith("image/")}exports.isImageByMimeType=t;
|
package/src/media.js
ADDED
package/src/storage.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var m=Object.defineProperty;var h=(r,e,t)=>e in r?m(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>h(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let o=null;class i{constructor(e){n(this,"prefix");n(this,"local",{has:e=>Object.prototype.hasOwnProperty.call(localStorage,`${this.prefix}${e}`),get:e=>localStorage.getItem(`${this.prefix}${e}`),set:(e,t)=>{localStorage.setItem(`${this.prefix}${e}`,t)},remove:e=>{localStorage.removeItem(`${this.prefix}${e}`)},clear:()=>{localStorage.clear()}});n(this,"session",{has:e=>Object.prototype.hasOwnProperty.call(sessionStorage,`${this.prefix}${e}`),get:e=>sessionStorage.getItem(`${this.prefix}${e}`),set:(e,t)=>{sessionStorage.setItem(`${this.prefix}${e}`,t)},remove:e=>{sessionStorage.removeItem(`${this.prefix}${e}`)},clear:()=>{sessionStorage.clear()}});n(this,"cookie",{has:e=>new RegExp(`(^|;)\\s*${e}=`).test(document.cookie),get:e=>{const t=document.cookie.match(new RegExp(`(^|;)\\s*${e}=([^;]*)`));return t?decodeURIComponent(t[2]):null},set:(e,t,a=1,l="/",c=this.getTopLevelDomain())=>{const s=new Date;s.setTime(s.getTime()+a*24*60*60*1e3);const p=`;expires=${s.toUTCString()}`,$=`;path=${l}`,g=c?`;domain=${c}`:"";document.cookie=`${e}=${encodeURIComponent(t)}${p}${$}${g}`},remove:(e,t="/",a=this.getTopLevelDomain())=>{const l=`;expires=${new Date(0).toUTCString()}`,c=`;path=${t}`,s=a?`;domain=${a}`:"";document.cookie=`${e}=;${l}${c}${s}`},clear:()=>{const e=document.cookie.match(/[^ =;]+(?==)/g);e&&e.forEach(t=>{document.cookie=`${t}=;expires=${new Date(0).toUTCString()};path=/`})}});this.prefix=e}static init(e="qxs_"){return o||(o=new i(e),o)}static getInstance(){return o||(o=new i("qxs_")),o}getTopLevelDomain(e=window.location.hostname){const t=e.split(".");return t.length>2?t.slice(-2).join("."):e}}const u=i.init,S=i.getInstance;exports.initStorage=u;exports.useStorage=S;
|
package/src/storage.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var m = Object.defineProperty;
|
|
2
|
+
var h = (r, e, t) => e in r ? m(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var n = (r, e, t) => h(r, typeof e != "symbol" ? e + "" : e, t);
|
|
4
|
+
let o = null;
|
|
5
|
+
class i {
|
|
6
|
+
constructor(e) {
|
|
7
|
+
n(this, "prefix");
|
|
8
|
+
n(this, "local", {
|
|
9
|
+
has: (e) => Object.prototype.hasOwnProperty.call(localStorage, `${this.prefix}${e}`),
|
|
10
|
+
get: (e) => localStorage.getItem(`${this.prefix}${e}`),
|
|
11
|
+
set: (e, t) => {
|
|
12
|
+
localStorage.setItem(`${this.prefix}${e}`, t);
|
|
13
|
+
},
|
|
14
|
+
remove: (e) => {
|
|
15
|
+
localStorage.removeItem(`${this.prefix}${e}`);
|
|
16
|
+
},
|
|
17
|
+
clear: () => {
|
|
18
|
+
localStorage.clear();
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
n(this, "session", {
|
|
22
|
+
has: (e) => Object.prototype.hasOwnProperty.call(sessionStorage, `${this.prefix}${e}`),
|
|
23
|
+
get: (e) => sessionStorage.getItem(`${this.prefix}${e}`),
|
|
24
|
+
set: (e, t) => {
|
|
25
|
+
sessionStorage.setItem(`${this.prefix}${e}`, t);
|
|
26
|
+
},
|
|
27
|
+
remove: (e) => {
|
|
28
|
+
sessionStorage.removeItem(`${this.prefix}${e}`);
|
|
29
|
+
},
|
|
30
|
+
clear: () => {
|
|
31
|
+
sessionStorage.clear();
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
n(this, "cookie", {
|
|
35
|
+
has: (e) => new RegExp(`(^|;)\\s*${e}=`).test(document.cookie),
|
|
36
|
+
get: (e) => {
|
|
37
|
+
const t = document.cookie.match(new RegExp(`(^|;)\\s*${e}=([^;]*)`));
|
|
38
|
+
return t ? decodeURIComponent(t[2]) : null;
|
|
39
|
+
},
|
|
40
|
+
set: (e, t, c = 1, p = "/", a = this.getTopLevelDomain()) => {
|
|
41
|
+
const s = /* @__PURE__ */ new Date();
|
|
42
|
+
s.setTime(s.getTime() + c * 24 * 60 * 60 * 1e3);
|
|
43
|
+
const $ = `;expires=${s.toUTCString()}`, l = `;path=${p}`, g = a ? `;domain=${a}` : "";
|
|
44
|
+
document.cookie = `${e}=${encodeURIComponent(t)}${$}${l}${g}`;
|
|
45
|
+
},
|
|
46
|
+
remove: (e, t = "/", c = this.getTopLevelDomain()) => {
|
|
47
|
+
const p = `;expires=${(/* @__PURE__ */ new Date(0)).toUTCString()}`, a = `;path=${t}`, s = c ? `;domain=${c}` : "";
|
|
48
|
+
document.cookie = `${e}=;${p}${a}${s}`;
|
|
49
|
+
},
|
|
50
|
+
clear: () => {
|
|
51
|
+
const e = document.cookie.match(/[^ =;]+(?==)/g);
|
|
52
|
+
e && e.forEach((t) => {
|
|
53
|
+
document.cookie = `${t}=;expires=${(/* @__PURE__ */ new Date(0)).toUTCString()};path=/`;
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
this.prefix = e;
|
|
58
|
+
}
|
|
59
|
+
static init(e = "qxs_") {
|
|
60
|
+
return o || (o = new i(e), o);
|
|
61
|
+
}
|
|
62
|
+
static getInstance() {
|
|
63
|
+
return o || (o = new i("qxs_")), o;
|
|
64
|
+
}
|
|
65
|
+
getTopLevelDomain(e = window.location.hostname) {
|
|
66
|
+
const t = e.split(".");
|
|
67
|
+
return t.length > 2 ? t.slice(-2).join(".") : e;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const x = i.init, S = i.getInstance;
|
|
71
|
+
export {
|
|
72
|
+
x as initStorage,
|
|
73
|
+
S as useStorage
|
|
74
|
+
};
|
package/src/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("vue"),i=e=>e===void 0,o=e=>typeof e=="boolean",t=e=>typeof e=="number";function s(e){return typeof Element=="undefined"?!1:e instanceof Element}function r(e){return e===window}Object.defineProperty(exports,"isVNode",{enumerable:!0,get:()=>n.isVNode});exports.isBoolean=o;exports.isElement=s;exports.isNumber=t;exports.isUndefined=i;exports.isWindow=r;
|
package/src/types.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isVNode as d } from "vue";
|
|
2
|
+
const n = (e) => e === void 0, o = (e) => typeof e == "boolean", t = (e) => typeof e == "number";
|
|
3
|
+
function i(e) {
|
|
4
|
+
return typeof Element == "undefined" ? !1 : e instanceof Element;
|
|
5
|
+
}
|
|
6
|
+
function f(e) {
|
|
7
|
+
return e === window;
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
o as isBoolean,
|
|
11
|
+
i as isElement,
|
|
12
|
+
t as isNumber,
|
|
13
|
+
n as isUndefined,
|
|
14
|
+
d as isVNode,
|
|
15
|
+
f as isWindow
|
|
16
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";var B=Object.defineProperty;var k=Object.getOwnPropertySymbols;var E=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var _=(t,e,n)=>e in t?B(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,$=(t,e)=>{for(var n in e||(e={}))E.call(e,n)&&_(t,n,e[n]);if(k)for(var n of k(e))D.call(e,n)&&_(t,n,e[n]);return t};Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const z={id:"wm_div_id",prefix:"mask_div_id",text:"测试水印",x:0,y:0,rows:0,cols:0,width:0,height:0,x_space:100,y_space:40,font:"微软雅黑",color:"black",fontsize:"18px",alpha:.15,angle:15,parent_width:0,parent_height:0,parent_node:null,monitor:!0};function S(t,e,n){const u=document.createElement("canvas").getContext("2d");if(!u)return{width:100,height:100};u.font=`${n} ${e}`;const c=u.measureText(t.trim()),l=Number.parseFloat(n),p=c.actualBoundingBoxAscent!==void 0&&c.actualBoundingBoxDescent!==void 0?c.actualBoundingBoxAscent+c.actualBoundingBoxDescent:l;return{width:Math.ceil(c.width),height:Math.ceil(p)}}function W(){const t=$({},z);let e=!1;const n=new MutationObserver(C),w=new ResizeObserver(()=>{e||l(t)});function u(a,i){const h=a-t.x,o=i-t.y,s=t.x_space||20,d=t.y_space||20,m=Math.ceil(h/(t.width+s)),g=Math.ceil(o/(t.height+d));return{cols:m,rows:g,x_space:s,y_space:d}}function c(a,i,h){const o=document.createElement("div");return o.textContent=t.text,o.id=`${t.prefix}${h}`,o.style.cssText=`
|
|
2
|
+
transform: rotate(-${t.angle}deg);
|
|
3
|
+
position: absolute;
|
|
4
|
+
left: ${a}px;
|
|
5
|
+
top: ${i}px;
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
z-index: 9999999;
|
|
8
|
+
opacity: ${t.alpha};
|
|
9
|
+
font-size: ${t.fontsize};
|
|
10
|
+
font-family: ${t.font};
|
|
11
|
+
color: ${t.color};
|
|
12
|
+
text-align: center;
|
|
13
|
+
width: ${t.width}px;
|
|
14
|
+
height: ${t.height}px;
|
|
15
|
+
line-height: ${t.height}px;
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
justify-content: center;
|
|
19
|
+
user-select: none;
|
|
20
|
+
visibility: visible;
|
|
21
|
+
`.replace(/\s+/g," ").trim(),o}function l(a){if(p(),Object.assign(t,a),t.width===0&&t.height===0||t.width===0||t.height===0){const r=S(t.text,t.font,t.fontsize),f=10;t.width===0&&(t.width=r.width+f),t.height===0&&(t.height=r.height+f)}const i=t.parent_node||document.body,h=Math.max(i.scrollWidth,i.clientWidth),o=Math.max(i.scrollHeight,i.clientHeight),s=document.createElement("div");s.id=t.id,i.closest("body")&&getComputedStyle(i).position==="static"&&(i.style.position="relative"),s.style.cssText=`
|
|
22
|
+
pointer-events: none;
|
|
23
|
+
display: block;
|
|
24
|
+
position: absolute;
|
|
25
|
+
top: 0;
|
|
26
|
+
left: 0;
|
|
27
|
+
width: 100%;
|
|
28
|
+
height: 100%;
|
|
29
|
+
z-index: 9999999;
|
|
30
|
+
overflow: hidden;
|
|
31
|
+
`.replace(/\s+/g," ").trim();const d=s.attachShadow?s.attachShadow({mode:"open"}):s;i.appendChild(s);const{cols:m,rows:g,x_space:v,y_space:y}=u(h,o);t.cols=m,t.rows=g,t.x_space=v,t.y_space=y;const b=document.createDocumentFragment();for(let r=0;r<g;r++){const f=t.y+(t.height+y)*r;for(let x=0;x<m;x++){const M=t.x+(t.width+v)*x;b.appendChild(c(M,f,r*m+x))}}if(d.appendChild(b),t.monitor){w.observe(i);const r={attributes:!0,childList:!0,subtree:!0,characterData:!0};n.observe(s,r),d!==s&&n.observe(d,r)}}function p(){var i;const a=document.getElementById(t.id);n.disconnect(),a&&((i=a.parentNode)==null||i.removeChild(a))}function C(a){if(e){e=!1;return}if(!document.getElementById(t.id)){l(t);return}a.some(o=>o.type==="childList"||o.type==="attributes"||o.type==="characterData")&&l(t)}return{addMark:l,removeMark:()=>{e=!0,p()}}}exports.watermark=W;
|
package/src/watermark.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
var B = Object.defineProperty;
|
|
2
|
+
var _ = Object.getOwnPropertySymbols;
|
|
3
|
+
var E = Object.prototype.hasOwnProperty, D = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var k = (t, e, n) => e in t ? B(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n, $ = (t, e) => {
|
|
5
|
+
for (var n in e || (e = {}))
|
|
6
|
+
E.call(e, n) && k(t, n, e[n]);
|
|
7
|
+
if (_)
|
|
8
|
+
for (var n of _(e))
|
|
9
|
+
D.call(e, n) && k(t, n, e[n]);
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
const z = {
|
|
13
|
+
id: "wm_div_id",
|
|
14
|
+
prefix: "mask_div_id",
|
|
15
|
+
text: "测试水印",
|
|
16
|
+
x: 0,
|
|
17
|
+
y: 0,
|
|
18
|
+
rows: 0,
|
|
19
|
+
cols: 0,
|
|
20
|
+
width: 0,
|
|
21
|
+
height: 0,
|
|
22
|
+
x_space: 100,
|
|
23
|
+
y_space: 40,
|
|
24
|
+
font: "微软雅黑",
|
|
25
|
+
color: "black",
|
|
26
|
+
fontsize: "18px",
|
|
27
|
+
alpha: 0.15,
|
|
28
|
+
angle: 15,
|
|
29
|
+
parent_width: 0,
|
|
30
|
+
parent_height: 0,
|
|
31
|
+
parent_node: null,
|
|
32
|
+
monitor: !0
|
|
33
|
+
};
|
|
34
|
+
function W(t, e, n) {
|
|
35
|
+
const u = document.createElement("canvas").getContext("2d");
|
|
36
|
+
if (!u)
|
|
37
|
+
return { width: 100, height: 100 };
|
|
38
|
+
u.font = `${n} ${e}`;
|
|
39
|
+
const r = u.measureText(t.trim()), l = Number.parseFloat(n), p = r.actualBoundingBoxAscent !== void 0 && r.actualBoundingBoxDescent !== void 0 ? r.actualBoundingBoxAscent + r.actualBoundingBoxDescent : l;
|
|
40
|
+
return {
|
|
41
|
+
width: Math.ceil(r.width),
|
|
42
|
+
height: Math.ceil(p)
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function H() {
|
|
46
|
+
const t = $({}, z);
|
|
47
|
+
let e = !1;
|
|
48
|
+
const n = new MutationObserver(C), w = new ResizeObserver(() => {
|
|
49
|
+
e || l(t);
|
|
50
|
+
});
|
|
51
|
+
function u(a, i) {
|
|
52
|
+
const h = a - t.x, o = i - t.y, s = t.x_space || 20, d = t.y_space || 20, m = Math.ceil(h / (t.width + s)), f = Math.ceil(o / (t.height + d));
|
|
53
|
+
return {
|
|
54
|
+
cols: m,
|
|
55
|
+
rows: f,
|
|
56
|
+
x_space: s,
|
|
57
|
+
y_space: d
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function r(a, i, h) {
|
|
61
|
+
const o = document.createElement("div");
|
|
62
|
+
return o.textContent = t.text, o.id = `${t.prefix}${h}`, o.style.cssText = `
|
|
63
|
+
transform: rotate(-${t.angle}deg);
|
|
64
|
+
position: absolute;
|
|
65
|
+
left: ${a}px;
|
|
66
|
+
top: ${i}px;
|
|
67
|
+
overflow: hidden;
|
|
68
|
+
z-index: 9999999;
|
|
69
|
+
opacity: ${t.alpha};
|
|
70
|
+
font-size: ${t.fontsize};
|
|
71
|
+
font-family: ${t.font};
|
|
72
|
+
color: ${t.color};
|
|
73
|
+
text-align: center;
|
|
74
|
+
width: ${t.width}px;
|
|
75
|
+
height: ${t.height}px;
|
|
76
|
+
line-height: ${t.height}px;
|
|
77
|
+
display: flex;
|
|
78
|
+
align-items: center;
|
|
79
|
+
justify-content: center;
|
|
80
|
+
user-select: none;
|
|
81
|
+
visibility: visible;
|
|
82
|
+
`.replace(/\s+/g, " ").trim(), o;
|
|
83
|
+
}
|
|
84
|
+
function l(a) {
|
|
85
|
+
if (p(), Object.assign(t, a), t.width === 0 && t.height === 0 || t.width === 0 || t.height === 0) {
|
|
86
|
+
const c = W(
|
|
87
|
+
t.text,
|
|
88
|
+
t.font,
|
|
89
|
+
t.fontsize
|
|
90
|
+
), g = 10;
|
|
91
|
+
t.width === 0 && (t.width = c.width + g), t.height === 0 && (t.height = c.height + g);
|
|
92
|
+
}
|
|
93
|
+
const i = t.parent_node || document.body, h = Math.max(i.scrollWidth, i.clientWidth), o = Math.max(i.scrollHeight, i.clientHeight), s = document.createElement("div");
|
|
94
|
+
s.id = t.id, i.closest("body") && getComputedStyle(i).position === "static" && (i.style.position = "relative"), s.style.cssText = `
|
|
95
|
+
pointer-events: none;
|
|
96
|
+
display: block;
|
|
97
|
+
position: absolute;
|
|
98
|
+
top: 0;
|
|
99
|
+
left: 0;
|
|
100
|
+
width: 100%;
|
|
101
|
+
height: 100%;
|
|
102
|
+
z-index: 9999999;
|
|
103
|
+
overflow: hidden;
|
|
104
|
+
`.replace(/\s+/g, " ").trim();
|
|
105
|
+
const d = s.attachShadow ? s.attachShadow({ mode: "open" }) : s;
|
|
106
|
+
i.appendChild(s);
|
|
107
|
+
const { cols: m, rows: f, x_space: v, y_space: y } = u(h, o);
|
|
108
|
+
t.cols = m, t.rows = f, t.x_space = v, t.y_space = y;
|
|
109
|
+
const b = document.createDocumentFragment();
|
|
110
|
+
for (let c = 0; c < f; c++) {
|
|
111
|
+
const g = t.y + (t.height + y) * c;
|
|
112
|
+
for (let x = 0; x < m; x++) {
|
|
113
|
+
const M = t.x + (t.width + v) * x;
|
|
114
|
+
b.appendChild(r(M, g, c * m + x));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
if (d.appendChild(b), t.monitor) {
|
|
118
|
+
w.observe(i);
|
|
119
|
+
const c = {
|
|
120
|
+
attributes: !0,
|
|
121
|
+
// 监听属性变化
|
|
122
|
+
childList: !0,
|
|
123
|
+
// 监听子元素变化
|
|
124
|
+
subtree: !0,
|
|
125
|
+
// 监听子树变化
|
|
126
|
+
characterData: !0
|
|
127
|
+
// 监听文本内容变化
|
|
128
|
+
};
|
|
129
|
+
n.observe(s, c), d !== s && n.observe(d, c);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function p() {
|
|
133
|
+
var i;
|
|
134
|
+
const a = document.getElementById(t.id);
|
|
135
|
+
n.disconnect(), a && ((i = a.parentNode) == null || i.removeChild(a));
|
|
136
|
+
}
|
|
137
|
+
function C(a) {
|
|
138
|
+
if (e) {
|
|
139
|
+
e = !1;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (!document.getElementById(t.id)) {
|
|
143
|
+
l(t);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
a.some((o) => o.type === "childList" || o.type === "attributes" || o.type === "characterData") && l(t);
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
addMark: l,
|
|
150
|
+
removeMark: () => {
|
|
151
|
+
e = !0, p();
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
export {
|
|
156
|
+
H as watermark
|
|
157
|
+
};
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { isVNode } from 'vue';
|
|
2
|
+
|
|
3
|
+
export declare const initStorage: typeof Storage_2.init;
|
|
4
|
+
|
|
5
|
+
export declare const isBoolean: (val: any) => val is boolean;
|
|
6
|
+
|
|
7
|
+
export declare function isElement(e: unknown): e is Element;
|
|
8
|
+
|
|
9
|
+
export declare function isImageByMimeType(file: File): boolean;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 判断是移动端还是pc端
|
|
13
|
+
*/
|
|
14
|
+
export declare function isMobile(): boolean;
|
|
15
|
+
|
|
16
|
+
export declare const isNumber: (val: any) => val is number;
|
|
17
|
+
|
|
18
|
+
export declare const isUndefined: (val: any) => val is undefined;
|
|
19
|
+
|
|
20
|
+
export { isVNode }
|
|
21
|
+
|
|
22
|
+
export declare function isWindow(val: unknown): val is Window;
|
|
23
|
+
|
|
24
|
+
declare interface SettingsType {
|
|
25
|
+
/** 水印总体的id */
|
|
26
|
+
id?: string;
|
|
27
|
+
/** 小水印的id前缀 */
|
|
28
|
+
prefix?: string;
|
|
29
|
+
/** 水印文案 */
|
|
30
|
+
text?: string;
|
|
31
|
+
/** 水印起始位置x轴坐标 */
|
|
32
|
+
x?: number;
|
|
33
|
+
/** 水印起始位置Y轴坐标 */
|
|
34
|
+
y?: number;
|
|
35
|
+
/** 水印行数 */
|
|
36
|
+
rows?: number;
|
|
37
|
+
/** 水印列数 */
|
|
38
|
+
cols?: number;
|
|
39
|
+
/** 水印x轴间隔 */
|
|
40
|
+
x_space?: number;
|
|
41
|
+
/** 水印y轴间隔 */
|
|
42
|
+
y_space?: number;
|
|
43
|
+
/** 水印字体 */
|
|
44
|
+
font?: string;
|
|
45
|
+
/** 水印字体颜色 */
|
|
46
|
+
color?: string;
|
|
47
|
+
/** 水印字体大小 */
|
|
48
|
+
fontsize?: string;
|
|
49
|
+
/** 水印透明度,要求设置在大于等于0.005 */
|
|
50
|
+
alpha?: number;
|
|
51
|
+
/** 水印宽度 */
|
|
52
|
+
width?: number;
|
|
53
|
+
/** 水印长度 */
|
|
54
|
+
height?: number;
|
|
55
|
+
/** 水印倾斜度数 */
|
|
56
|
+
angle?: number;
|
|
57
|
+
/** 水印的总体宽度(默认值:body的scrollWidth和clientWidth的较大值) */
|
|
58
|
+
parent_width?: number;
|
|
59
|
+
/** 水印的总体高度(默认值:body的scrollHeight和clientHeight的较大值) */
|
|
60
|
+
parent_height?: number;
|
|
61
|
+
/** 水印插件挂载的父元素element,不输入则默认挂在body */
|
|
62
|
+
parent_node?: HTMLElement | null;
|
|
63
|
+
/** 是否监控,true: 不可删除水印; false: 可删水印 */
|
|
64
|
+
monitor?: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
declare class Storage_2 {
|
|
68
|
+
private readonly prefix;
|
|
69
|
+
private constructor();
|
|
70
|
+
static init(prefix?: string): Storage_2;
|
|
71
|
+
static getInstance(): Storage_2;
|
|
72
|
+
private getTopLevelDomain;
|
|
73
|
+
local: {
|
|
74
|
+
has: (key: string) => boolean;
|
|
75
|
+
get: (key: string) => string | null;
|
|
76
|
+
set: (key: string, value: string) => void;
|
|
77
|
+
remove: (key: string) => void;
|
|
78
|
+
clear: () => void;
|
|
79
|
+
};
|
|
80
|
+
session: {
|
|
81
|
+
has: (key: string) => boolean;
|
|
82
|
+
get: (key: string) => string | null;
|
|
83
|
+
set: (key: string, value: string) => void;
|
|
84
|
+
remove: (key: string) => void;
|
|
85
|
+
clear: () => void;
|
|
86
|
+
};
|
|
87
|
+
cookie: {
|
|
88
|
+
has: (key: string) => boolean;
|
|
89
|
+
get: (key: string) => string | null;
|
|
90
|
+
set: (key: string, value: string, expires?: number, path?: string, domain?: string) => void;
|
|
91
|
+
remove: (key: string, path?: string, domain?: string) => void;
|
|
92
|
+
clear: () => void;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export declare const useStorage: typeof Storage_2.getInstance;
|
|
97
|
+
|
|
98
|
+
export declare function watermark(): {
|
|
99
|
+
addMark: (settings: Partial<SettingsType>) => void;
|
|
100
|
+
removeMark: () => void;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export { }
|