Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@tntd/react-watermark

Package Overview
Dependencies
Maintainers
8
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tntd/react-watermark - npm Package Compare versions

Comparing version
1.1.0
to
1.1.1
+28
-4
dist/components/Watermark.js

@@ -14,2 +14,3 @@ var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();

fontSize: 12,
fontFamily: "serif",
fontAjust: 1.2,

@@ -42,2 +43,18 @@ offsetX: 0,

// 获取字符串长度,汉字记为1.3个字符,大写字母记为1个字符,其它记为0.5个字符
var getStrLen = function getStrLen(str) {
var len = 0;
for (var i = 0; i < str.length; i++) {
var a = str.charAt(i);
if (a.match(/[\u4e00-\u9fa5]/g) !== null) {
len += 1.3;
} else if (a.match(/[A-Z]/g) !== null) {
len += 1;
} else {
len += 0.5;
}
}
return parseInt(len);
};
var drawerWatermark = function drawerWatermark() {

@@ -60,2 +77,4 @@ if (!text) {

fontSize = _options$fontSize === undefined ? defaultOptions.fontSize : _options$fontSize,
_options$fontFamily = options.fontFamily,
fontFamily = _options$fontFamily === undefined ? defaultOptions.fontFamily : _options$fontFamily,
_options$fontAjust = options.fontAjust,

@@ -69,3 +88,3 @@ fontAjust = _options$fontAjust === undefined ? defaultOptions.fontAjust : _options$fontAjust,

var ctx = canvas.getContext("2d");
var textLength = text.length * fontSize * fontAjust;
var textLength = getStrLen(text) * fontSize * fontAjust;
var rotatePI = Number(rotate) / 180 * Math.PI;

@@ -76,5 +95,8 @@ var calcWidth = parseInt(textLength * Math.cos(rotatePI)) + offsetX;

if (subtext && subtext !== "") {
var subtextLength = subtext.length * fontSize * fontAjust;
var subtextLength = getStrLen(subtext) * fontSize * fontAjust;
var subCalcWidth = parseInt(subtextLength * Math.cos(rotatePI)) + offsetX;
var subCalcHeight = parseInt(subtextLength * Math.cos(rotatePI)) + offsetY;
console.log("subtextLength", getStrLen(subtext));
console.log("textLength", getStrLen(text));
var subtextAlign = {

@@ -88,6 +110,8 @@ x: calcWidth > subCalcWidth ? calcWidth / 2 - subCalcWidth / 2 : 0,

};
console.log("subtextAlign", subtextAlign);
console.log("textAlign", textAlign);
canvas.width = Math.max(calcWidth, subCalcWidth);
canvas.height = calcHeight + subCalcHeight;
ctx.font = fontSize + "px serif";
ctx.font = fontSize + "px " + fontFamily;
ctx.rotate(-("" + rotate) * Math.PI / 180); // 逆时针方向

@@ -104,3 +128,3 @@ ctx.fillStyle = color;

canvas.height = calcHeight;
ctx.font = fontSize + "px serif";
ctx.font = fontSize + "px " + fontFamily;
ctx.rotate(-("" + rotate) * Math.PI / 180); // 逆时针方向

@@ -107,0 +131,0 @@ ctx.fillStyle = color;

+1
-1
{
"name": "@tntd/react-watermark",
"version": "1.1.0",
"version": "1.1.1",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "module": "dist/index.js",

@@ -22,2 +22,3 @@ ## 水印插件

fontSize: 16,
fontFamily: "黑体",
fontAjust: 1,

@@ -47,2 +48,3 @@ offsetX: 100,

fontSize: 12,
fontFamily: "黑体",
fontAjust: 1.2,

@@ -49,0 +51,0 @@ offsetX: 0,