leafer-x-watermark 1.2.0 → 1.3.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 +8 -3
- package/dist/index.mjs +23 -10
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as _leafer_ui_interface from '@leafer-ui/interface';
|
|
1
2
|
import { IRectData, IUI, IRectInputData, IObject, IJSONOptions } from '@leafer-ui/interface';
|
|
2
3
|
import { RectData, Rect } from '@leafer-ui/core';
|
|
3
4
|
|
|
@@ -42,7 +43,7 @@ interface IProcessDataType extends IRectData {
|
|
|
42
43
|
height: number;
|
|
43
44
|
};
|
|
44
45
|
updateFill: () => void;
|
|
45
|
-
regenerateImage: () =>
|
|
46
|
+
regenerateImage: () => void;
|
|
46
47
|
}
|
|
47
48
|
interface IWatermark extends IWatermarkAttrData, IUI {
|
|
48
49
|
__: IProcessDataType;
|
|
@@ -57,7 +58,7 @@ declare class ProcessorData extends RectData implements IProcessDataType {
|
|
|
57
58
|
width: number;
|
|
58
59
|
height: number;
|
|
59
60
|
};
|
|
60
|
-
setTileContent(value: string):
|
|
61
|
+
setTileContent(value: string): void;
|
|
61
62
|
_tileMode?: boolean;
|
|
62
63
|
setTileMode(value: boolean): void;
|
|
63
64
|
_tileSize?: number;
|
|
@@ -72,7 +73,11 @@ declare class ProcessorData extends RectData implements IProcessDataType {
|
|
|
72
73
|
__getData(): IObject;
|
|
73
74
|
__getInputData(names?: string[] | IObject, options?: IJSONOptions): IObject;
|
|
74
75
|
private createTileItem;
|
|
75
|
-
regenerateImage():
|
|
76
|
+
regenerateImage(): void;
|
|
77
|
+
_simpleExport(ui: IUI): {
|
|
78
|
+
url: string;
|
|
79
|
+
bounds: _leafer_ui_interface.IBoundsData;
|
|
80
|
+
};
|
|
76
81
|
}
|
|
77
82
|
declare class Watermark<TConstructorData = IWatermarkInputData> extends Rect<TConstructorData> implements IWatermark {
|
|
78
83
|
get __tag(): string;
|
package/dist/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ var __decorateClass = (decorators, target, key, kind) => {
|
|
|
10
10
|
if (kind && result) __defProp(target, key, result);
|
|
11
11
|
return result;
|
|
12
12
|
};
|
|
13
|
-
const
|
|
13
|
+
const console = Debug.get("leafer-x-watermark");
|
|
14
14
|
class ProcessorData extends RectData {
|
|
15
15
|
_tileContent = "";
|
|
16
16
|
_cachedUrl;
|
|
@@ -99,7 +99,7 @@ class ProcessorData extends RectData {
|
|
|
99
99
|
around: "center"
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
|
-
|
|
102
|
+
regenerateImage() {
|
|
103
103
|
const leaf = this.__leaf;
|
|
104
104
|
const { _tileContent } = this;
|
|
105
105
|
const { width, height } = leaf;
|
|
@@ -113,25 +113,37 @@ class ProcessorData extends RectData {
|
|
|
113
113
|
try {
|
|
114
114
|
itemData = JSON.parse(_tileContent);
|
|
115
115
|
} catch (e) {
|
|
116
|
-
|
|
116
|
+
console.error("Invalid tileContent JSON:", e);
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
const tempItem = this.createTileItem(itemData);
|
|
120
|
-
const bounds =
|
|
120
|
+
const { url, bounds } = this._simpleExport(tempItem);
|
|
121
121
|
if (!width || !height) {
|
|
122
122
|
leaf.width = bounds.width;
|
|
123
123
|
leaf.height = bounds.height;
|
|
124
124
|
}
|
|
125
|
-
const exportWidth = 1e3;
|
|
126
|
-
const { data: url } = await tempItem.export("png", {
|
|
127
|
-
blob: false,
|
|
128
|
-
size: { width: exportWidth }
|
|
129
|
-
});
|
|
130
125
|
this._cachedUrl = url;
|
|
131
|
-
this._cachedBounds =
|
|
126
|
+
this._cachedBounds = bounds;
|
|
132
127
|
tempItem.destroy();
|
|
133
128
|
this.updateFill();
|
|
134
129
|
}
|
|
130
|
+
_simpleExport(ui) {
|
|
131
|
+
const exportWidth = 1e3;
|
|
132
|
+
const bounds = ui.getBounds("render", "local");
|
|
133
|
+
const scaleRatio = exportWidth / bounds.width;
|
|
134
|
+
const scaledWidth = Math.floor(bounds.width * scaleRatio);
|
|
135
|
+
const scaledHeight = Math.floor(bounds.height * scaleRatio);
|
|
136
|
+
const canvas = UICreator.get("Canvas", {
|
|
137
|
+
x: 0,
|
|
138
|
+
y: 0,
|
|
139
|
+
width: scaledWidth,
|
|
140
|
+
height: scaledHeight
|
|
141
|
+
});
|
|
142
|
+
canvas.draw(ui, void 0, scaleRatio);
|
|
143
|
+
const url = canvas.canvas.toDataURL("image/png");
|
|
144
|
+
canvas.destroy();
|
|
145
|
+
return { url, bounds };
|
|
146
|
+
}
|
|
135
147
|
}
|
|
136
148
|
let Watermark = class extends Rect {
|
|
137
149
|
get __tag() {
|
|
@@ -142,6 +154,7 @@ let Watermark = class extends Rect {
|
|
|
142
154
|
}
|
|
143
155
|
constructor(data) {
|
|
144
156
|
super(data);
|
|
157
|
+
console.log(this.tileURL);
|
|
145
158
|
}
|
|
146
159
|
};
|
|
147
160
|
__decorateClass([
|