Skip to content

Commit 6980608

Browse files
authored
feat(Watermark): add protected logic (#5135)
* feat: 增加 Protected 参数支持 * feat: 增加 Protected 参数支持 * refactor: 移除参数 * chore: bump version 9.2.8-beta05 * refactor: 精简代码
1 parent cf6aaab commit 6980608

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.2.8-beta04</Version>
4+
<Version>9.2.8-beta05</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Watermark/Watermark.razor.js

+72-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const createWatermark = watermark => {
8484
const div = document.createElement('div');
8585
const { base64, styleSize } = bg;
8686
div.style.backgroundImage = `url(${base64})`;
87-
div.style.backgroundSize = `${styleSize}px ${styleSize}px`;
87+
div.style.backgroundSize = `${styleSize.toFixed(3)}px ${styleSize.toFixed(3)}px`;
8888
div.style.backgroundRepeat = 'repeat';
8989
div.style.pointerEvents = 'none';
9090
div.style.opacity = '1';
@@ -98,6 +98,77 @@ const createWatermark = watermark => {
9898
mark.remove();
9999
}
100100
el.appendChild(div);
101+
102+
options.bg = bg;
103+
requestAnimationFrame(() => monitor(watermark));
104+
}
105+
106+
const monitor = watermark => {
107+
const { el, options, ob } = watermark;
108+
if (el === null) {
109+
return;
110+
}
111+
112+
if (el.children.length !== 2) {
113+
clearWatermark(watermark);
114+
return;
115+
}
116+
117+
const mark = el.children[1];
118+
if (mark.className !== 'bb-watermark-bg') {
119+
clearWatermark(watermark);
120+
return;
121+
}
122+
123+
const style = getComputedStyle(mark);
124+
const { display, opacity, position, inset, zIndex, zoom, transform, backgroundRepeat, backgroundImage, backgroundSize } = style;
125+
if (display !== 'block') {
126+
clearWatermark(watermark);
127+
return;
128+
}
129+
if (opacity !== '1') {
130+
clearWatermark(watermark);
131+
return;
132+
}
133+
if (position !== 'absolute') {
134+
clearWatermark(watermark);
135+
return;
136+
}
137+
if (inset !== '0px') {
138+
clearWatermark(watermark);
139+
return;
140+
}
141+
if (zIndex !== '999') {
142+
clearWatermark(watermark);
143+
return;
144+
}
145+
if (zoom !== '1') {
146+
clearWatermark(watermark);
147+
return;
148+
}
149+
if (transform !== 'none') {
150+
clearWatermark(watermark);
151+
return;
152+
}
153+
if (backgroundRepeat !== 'repeat') {
154+
clearWatermark(watermark);
155+
return;
156+
}
157+
if (backgroundImage !== `url("${options.bg.base64}")`) {
158+
clearWatermark(watermark);
159+
return;
160+
}
161+
if (backgroundSize !== `${options.bg.styleSize.toFixed(3)}px ${options.bg.styleSize.toFixed(3)}px`) {
162+
clearWatermark(watermark);
163+
return;
164+
}
165+
requestAnimationFrame(() => monitor(watermark));
166+
}
167+
168+
const clearWatermark = watermark => {
169+
const { el, ob } = watermark;
170+
ob.disconnect();
171+
el.innerHTML = '';
101172
}
102173

103174
const getWatermark = props => {

0 commit comments

Comments
 (0)