zmdms-utils 0.0.37 → 0.0.39

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/dist/es/pdf.d.ts CHANGED
@@ -39,4 +39,4 @@ interface IImgToPdfConfig {
39
39
  waterConfig?: IWaterResult;
40
40
  }
41
41
 
42
- export { imgToPdf };
42
+ export { IImgToPdfConfig, imgToPdf };
@@ -15,6 +15,7 @@ declare function mergeWaterConfig(waterConfig?: IWaterConfig): {
15
15
  rotate: number;
16
16
  zIndex: number;
17
17
  content: string | string[];
18
+ lineSpacing: number;
18
19
  font: {
19
20
  color: string | CanvasGradient | CanvasPattern;
20
21
  fontSize: number;
@@ -32,6 +33,7 @@ interface IWaterConfig {
32
33
  zIndex?: number;
33
34
  image?: string;
34
35
  content?: string | string[];
36
+ lineSpacing?: number;
35
37
  font?: {
36
38
  color?: CanvasFillStrokeStyles["fillStyle"];
37
39
  fontSize?: number;
package/dist/es/water.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * 创建水印
3
3
  */
4
4
  function createWater(config) {
5
- var _a = mergeWaterConfig(config), width = _a.width, height = _a.height, rotate = _a.rotate, content = _a.content, font = _a.font;
5
+ var _a = mergeWaterConfig(config), width = _a.width, height = _a.height, rotate = _a.rotate, content = _a.content, font = _a.font, lineSpacing = _a.lineSpacing;
6
6
  // 创建canvas元素
7
7
  var canvas = document.createElement("canvas");
8
8
  canvas.width = width * 2;
@@ -21,7 +21,7 @@ function createWater(config) {
21
21
  if (Array.isArray(textLines)) {
22
22
  // 多行文本
23
23
  textLines.forEach(function (line, index) {
24
- ctx.fillText(line, 0, index * font.fontSize);
24
+ ctx.fillText(line, 0, index * (font.fontSize + lineSpacing));
25
25
  });
26
26
  }
27
27
  else {
@@ -47,13 +47,14 @@ function mergeWaterConfig(waterConfig) {
47
47
  var _a, _b, _c, _d, _e, _f;
48
48
  return {
49
49
  width: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.width) || 200,
50
- height: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.height) || 60,
51
- rotate: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.rotate) || -22,
50
+ height: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.height) || 200,
51
+ rotate: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.rotate) || -20,
52
52
  zIndex: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.zIndex) || 10,
53
53
  content: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.content) || "交投集团",
54
+ lineSpacing: 4,
54
55
  font: {
55
- color: ((_a = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _a === void 0 ? void 0 : _a.color) || "rgba(0, 0, 0, 0.1)",
56
- fontSize: ((_b = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _b === void 0 ? void 0 : _b.fontSize) || 18,
56
+ color: ((_a = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _a === void 0 ? void 0 : _a.color) || "rgba(0, 0, 0, 0.2)",
57
+ fontSize: ((_b = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _b === void 0 ? void 0 : _b.fontSize) || 14,
57
58
  fontWeight: ((_c = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _c === void 0 ? void 0 : _c.fontWeight) || "normal",
58
59
  fontStyle: ((_d = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _d === void 0 ? void 0 : _d.fontStyle) || "normal",
59
60
  fontFamily: ((_e = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _e === void 0 ? void 0 : _e.fontFamily) || "微软雅黑",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-utils",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/pdf.ts CHANGED
@@ -122,7 +122,7 @@ export function addImageWater(
122
122
  }
123
123
  }
124
124
 
125
- interface IImgToPdfConfig {
125
+ export interface IImgToPdfConfig {
126
126
  /** 图片 base64字符串 */
127
127
  image: string | HTMLImageElement | HTMLCanvasElement | Uint8Array | RGBAData;
128
128
  width: number;
package/src/water.ts CHANGED
@@ -2,7 +2,8 @@
2
2
  * 创建水印
3
3
  */
4
4
  export function createWater(config: IWaterConfig) {
5
- const { width, height, rotate, content, font } = mergeWaterConfig(config);
5
+ const { width, height, rotate, content, font, lineSpacing } =
6
+ mergeWaterConfig(config);
6
7
 
7
8
  // 创建canvas元素
8
9
  const canvas = document.createElement("canvas");
@@ -24,7 +25,7 @@ export function createWater(config: IWaterConfig) {
24
25
  if (Array.isArray(textLines)) {
25
26
  // 多行文本
26
27
  textLines.forEach((line, index) => {
27
- ctx.fillText(line, 0, index * font.fontSize);
28
+ ctx.fillText(line, 0, index * (font.fontSize + lineSpacing));
28
29
  });
29
30
  } else {
30
31
  // 单行文本
@@ -52,13 +53,14 @@ export function createWater(config: IWaterConfig) {
52
53
  export function mergeWaterConfig(waterConfig?: IWaterConfig) {
53
54
  return {
54
55
  width: waterConfig?.width || 200,
55
- height: waterConfig?.height || 60,
56
- rotate: waterConfig?.rotate || -22,
56
+ height: waterConfig?.height || 200,
57
+ rotate: waterConfig?.rotate || -20,
57
58
  zIndex: waterConfig?.zIndex || 10,
58
59
  content: waterConfig?.content || "交投集团",
60
+ lineSpacing: 4,
59
61
  font: {
60
- color: waterConfig?.font?.color || "rgba(0, 0, 0, 0.1)",
61
- fontSize: waterConfig?.font?.fontSize || 18,
62
+ color: waterConfig?.font?.color || "rgba(0, 0, 0, 0.2)",
63
+ fontSize: waterConfig?.font?.fontSize || 14,
62
64
  fontWeight: waterConfig?.font?.fontWeight || "normal",
63
65
  fontStyle: waterConfig?.font?.fontStyle || "normal",
64
66
  fontFamily: waterConfig?.font?.fontFamily || "微软雅黑",
@@ -82,6 +84,8 @@ export interface IWaterConfig {
82
84
  image?: string;
83
85
  // 文本水印内容
84
86
  content?: string | string[];
87
+ // 多行文本时,每行文本的间距
88
+ lineSpacing?: number;
85
89
  // 水印字体大小
86
90
  font?: {
87
91
  color?: CanvasFillStrokeStyles["fillStyle"];