leafer-x-watermark 3.0.0 → 3.2.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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { IRectData, IUI, IRectInputData, IObject, IJSONOptions } from '@leafer-ui/interface';
2
- import { RectData, Rect } from '@leafer-ui/core';
2
+ import { RectData, Rect, PropertyEvent } from '@leafer-ui/core';
3
3
 
4
4
  type IStaggerType = 'x' | 'y';
5
5
  interface IStaggerData {
@@ -17,6 +17,7 @@ declare module '@leafer-ui/interface' {
17
17
  }
18
18
  }
19
19
 
20
+ type ITileContentParser = (content: string) => object | null;
20
21
  interface ITileGap {
21
22
  x?: number;
22
23
  y?: number;
@@ -48,6 +49,7 @@ interface IProcessDataType extends IRectData {
48
49
  }
49
50
  interface IWatermark extends IWatermarkAttrData, IUI {
50
51
  __: IProcessDataType;
52
+ tileContentParser?: ITileContentParser;
51
53
  }
52
54
  interface IWatermarkInputData extends IWatermarkAttrData, IRectInputData {
53
55
  }
@@ -91,7 +93,10 @@ declare abstract class ProcessorDataBase extends RectData implements IProcessDat
91
93
 
92
94
  declare abstract class WatermarkBase<TConstructorData = IWatermarkInputData> extends Rect<TConstructorData> implements IWatermark {
93
95
  __: ProcessorDataBase;
94
- get tileURL(): string;
96
+ tileContentParser?: ITileContentParser;
97
+ constructor(data?: TConstructorData);
98
+ syncParentSize(e?: PropertyEvent): void;
99
+ destroy(): void;
95
100
  }
96
101
 
97
102
  declare class ProcessorDataAsync extends ProcessorDataBase {
@@ -108,6 +113,7 @@ declare class WatermarkAsync<TConstructorData = IWatermarkInputData> extends Wat
108
113
  tileGap: number | ITileGap;
109
114
  tileStagger: IStagger;
110
115
  tileRotation: number;
116
+ get tileURL(): string;
111
117
  }
112
118
 
113
119
  declare class ProcessorData$1 extends ProcessorDataBase {
@@ -124,13 +130,14 @@ declare class WatermarkSync<TConstructorData = IWatermarkInputData> extends Wate
124
130
  tileGap: number | ITileGap;
125
131
  tileStagger: IStagger;
126
132
  tileRotation: number;
133
+ get tileURL(): string;
127
134
  }
128
135
 
129
136
  declare class ProcessorData extends ProcessorDataBase {
130
137
  __leaf: WatermarkURL;
131
138
  regenerateImage(): void;
132
139
  }
133
- declare class WatermarkURL<TConstructorData = IWatermarkInputData> extends Rect<TConstructorData> implements IWatermark {
140
+ declare class WatermarkURL<TConstructorData = IWatermarkInputData> extends WatermarkBase<TConstructorData> {
134
141
  get __tag(): string;
135
142
  __: ProcessorData;
136
143
  tileURL?: string;
@@ -146,4 +153,4 @@ declare function installStaggerPattern(): void;
146
153
  declare function processStaggerData(paint: any): INormalizedStagger | null;
147
154
 
148
155
  export { WatermarkAsync, WatermarkSync, WatermarkURL, installStaggerPattern, normalizeStagger, processStaggerData };
149
- export type { INormalizedStagger, IProcessDataType, IStagger, IStaggerData, IStaggerType, ITileGap, IWatermark, IWatermarkAttrData, IWatermarkInputData };
156
+ export type { INormalizedStagger, IProcessDataType, IStagger, IStaggerData, IStaggerType, ITileContentParser, ITileGap, IWatermark, IWatermarkAttrData, IWatermarkInputData };
package/dist/index.mjs CHANGED
@@ -1,6 +1,14 @@
1
- import { Debug, RectData, isObject, UICreator, Rect, dataProcessor, boundsType, registerUI, Plugin, Creator, MatrixHelper, MathHelper, PaintImage, Platform } from '@leafer-ui/core';
1
+ import { Debug, RectData, isObject, UICreator, Rect, PropertyEvent, dataProcessor, boundsType, registerUI, Plugin, Creator, MatrixHelper, MathHelper, PaintImage, Platform } from '@leafer-ui/core';
2
2
 
3
3
  const console = Debug.get("leafer-x-watermark");
4
+ function defaultTileContentParser(content) {
5
+ try {
6
+ return JSON.parse(content);
7
+ } catch (e) {
8
+ console.error("Invalid tileContent JSON:", e);
9
+ return null;
10
+ }
11
+ }
4
12
  class ProcessorDataBase extends RectData {
5
13
  _cachedUrl;
6
14
  _cachedBounds;
@@ -22,6 +30,8 @@ class ProcessorDataBase extends RectData {
22
30
  setTileMode(value) {
23
31
  this._tileMode = value;
24
32
  this.updateFill();
33
+ if (value && this.__leaf.syncParentSize)
34
+ this.__leaf.syncParentSize();
25
35
  }
26
36
  setTileSize(value) {
27
37
  this._tileSize = value;
@@ -102,12 +112,8 @@ class ProcessorDataBase extends RectData {
102
112
  this.__leaf.fill = void 0;
103
113
  return null;
104
114
  }
105
- try {
106
- return JSON.parse(_tileContent);
107
- } catch (e) {
108
- console.error("Invalid tileContent JSON:", e);
109
- return null;
110
- }
115
+ const parser = this.__leaf.tileContentParser || defaultTileContentParser;
116
+ return parser(_tileContent);
111
117
  }
112
118
  updateLeafDimensions(bounds) {
113
119
  const leaf = this.__leaf;
@@ -125,8 +131,30 @@ class ProcessorDataBase extends RectData {
125
131
  }
126
132
 
127
133
  class WatermarkBase extends Rect {
128
- get tileURL() {
129
- return this.__._cachedUrl;
134
+ tileContentParser;
135
+ constructor(data) {
136
+ super(data);
137
+ this.syncParentSize = this.syncParentSize.bind(this);
138
+ this.waitParent(() => {
139
+ this.parent.on(PropertyEvent.CHANGE, this.syncParentSize);
140
+ this.syncParentSize();
141
+ });
142
+ }
143
+ syncParentSize(e) {
144
+ if (e && !["width", "height"].includes(e.attrName)) {
145
+ return;
146
+ }
147
+ if (this.__._tileMode && this.parent) {
148
+ this.width = this.parent.width;
149
+ this.height = this.parent.height;
150
+ this.y = this.x = 0;
151
+ }
152
+ }
153
+ destroy() {
154
+ if (this.parent) {
155
+ this.parent.off(PropertyEvent.CHANGE, this.syncParentSize);
156
+ }
157
+ super.destroy();
130
158
  }
131
159
  }
132
160
 
@@ -166,6 +194,9 @@ let WatermarkAsync = class extends WatermarkBase {
166
194
  get __tag() {
167
195
  return "WatermarkAsync";
168
196
  }
197
+ get tileURL() {
198
+ return this.__._cachedUrl;
199
+ }
169
200
  };
170
201
  __decorateClass$2([
171
202
  dataProcessor(ProcessorDataAsync)
@@ -235,6 +266,9 @@ let WatermarkSync = class extends WatermarkBase {
235
266
  get __tag() {
236
267
  return "WatermarkSync";
237
268
  }
269
+ get tileURL() {
270
+ return this.__._cachedUrl;
271
+ }
238
272
  };
239
273
  __decorateClass$1([
240
274
  dataProcessor(ProcessorData$1)
@@ -303,7 +337,7 @@ class ProcessorData extends ProcessorDataBase {
303
337
  });
304
338
  }
305
339
  }
306
- let WatermarkURL = class extends Rect {
340
+ let WatermarkURL = class extends WatermarkBase {
307
341
  get __tag() {
308
342
  return "WatermarkURL";
309
343
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "leafer-x-watermark",
3
3
  "type": "module",
4
- "version": "3.0.0",
4
+ "version": "3.2.0",
5
5
  "packageManager": "pnpm@10.14.0",
6
6
  "description": "Leafer 水印插件",
7
7
  "author": "XiaDeYu <1579883916@qq.com>",