leafer-x-watermark 3.0.0 → 3.1.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 {
@@ -91,7 +91,9 @@ declare abstract class ProcessorDataBase extends RectData implements IProcessDat
91
91
 
92
92
  declare abstract class WatermarkBase<TConstructorData = IWatermarkInputData> extends Rect<TConstructorData> implements IWatermark {
93
93
  __: ProcessorDataBase;
94
- get tileURL(): string;
94
+ constructor(data?: TConstructorData);
95
+ syncParentSize(e?: PropertyEvent): void;
96
+ destroy(): void;
95
97
  }
96
98
 
97
99
  declare class ProcessorDataAsync extends ProcessorDataBase {
@@ -108,6 +110,7 @@ declare class WatermarkAsync<TConstructorData = IWatermarkInputData> extends Wat
108
110
  tileGap: number | ITileGap;
109
111
  tileStagger: IStagger;
110
112
  tileRotation: number;
113
+ get tileURL(): string;
111
114
  }
112
115
 
113
116
  declare class ProcessorData$1 extends ProcessorDataBase {
@@ -124,13 +127,14 @@ declare class WatermarkSync<TConstructorData = IWatermarkInputData> extends Wate
124
127
  tileGap: number | ITileGap;
125
128
  tileStagger: IStagger;
126
129
  tileRotation: number;
130
+ get tileURL(): string;
127
131
  }
128
132
 
129
133
  declare class ProcessorData extends ProcessorDataBase {
130
134
  __leaf: WatermarkURL;
131
135
  regenerateImage(): void;
132
136
  }
133
- declare class WatermarkURL<TConstructorData = IWatermarkInputData> extends Rect<TConstructorData> implements IWatermark {
137
+ declare class WatermarkURL<TConstructorData = IWatermarkInputData> extends WatermarkBase<TConstructorData> {
134
138
  get __tag(): string;
135
139
  __: ProcessorData;
136
140
  tileURL?: string;
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
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
4
  class ProcessorDataBase extends RectData {
@@ -22,6 +22,8 @@ class ProcessorDataBase extends RectData {
22
22
  setTileMode(value) {
23
23
  this._tileMode = value;
24
24
  this.updateFill();
25
+ if (value && this.__leaf.syncParentSize)
26
+ this.__leaf.syncParentSize();
25
27
  }
26
28
  setTileSize(value) {
27
29
  this._tileSize = value;
@@ -125,8 +127,29 @@ class ProcessorDataBase extends RectData {
125
127
  }
126
128
 
127
129
  class WatermarkBase extends Rect {
128
- get tileURL() {
129
- return this.__._cachedUrl;
130
+ constructor(data) {
131
+ super(data);
132
+ this.syncParentSize = this.syncParentSize.bind(this);
133
+ this.waitParent(() => {
134
+ this.parent.on(PropertyEvent.CHANGE, this.syncParentSize);
135
+ this.syncParentSize();
136
+ });
137
+ }
138
+ syncParentSize(e) {
139
+ if (e && !["width", "height"].includes(e.attrName)) {
140
+ return;
141
+ }
142
+ if (this.__._tileMode && this.parent) {
143
+ this.width = this.parent.width;
144
+ this.height = this.parent.height;
145
+ this.y = this.x = 0;
146
+ }
147
+ }
148
+ destroy() {
149
+ if (this.parent) {
150
+ this.parent.off(PropertyEvent.CHANGE, this.syncParentSize);
151
+ }
152
+ super.destroy();
130
153
  }
131
154
  }
132
155
 
@@ -166,6 +189,9 @@ let WatermarkAsync = class extends WatermarkBase {
166
189
  get __tag() {
167
190
  return "WatermarkAsync";
168
191
  }
192
+ get tileURL() {
193
+ return this.__._cachedUrl;
194
+ }
169
195
  };
170
196
  __decorateClass$2([
171
197
  dataProcessor(ProcessorDataAsync)
@@ -235,6 +261,9 @@ let WatermarkSync = class extends WatermarkBase {
235
261
  get __tag() {
236
262
  return "WatermarkSync";
237
263
  }
264
+ get tileURL() {
265
+ return this.__._cachedUrl;
266
+ }
238
267
  };
239
268
  __decorateClass$1([
240
269
  dataProcessor(ProcessorData$1)
@@ -303,7 +332,7 @@ class ProcessorData extends ProcessorDataBase {
303
332
  });
304
333
  }
305
334
  }
306
- let WatermarkURL = class extends Rect {
335
+ let WatermarkURL = class extends WatermarkBase {
307
336
  get __tag() {
308
337
  return "WatermarkURL";
309
338
  }
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.1.0",
5
5
  "packageManager": "pnpm@10.14.0",
6
6
  "description": "Leafer 水印插件",
7
7
  "author": "XiaDeYu <1579883916@qq.com>",