Skip to content

Commit

Permalink
feat: add monitorProtection
Browse files Browse the repository at this point in the history
  • Loading branch information
zhensherlock committed Sep 28, 2024
1 parent b387a90 commit b99ba1e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changeset/slow-sheep-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@watermark-design/core': minor
'@watermark-design/dom': minor
---

add monitorProtection
1 change: 1 addition & 0 deletions packages/core/src/initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const initialOptions: WatermarkOptions = {
globalAlpha: 0.5,
mode: 'default',
mutationObserve: true,
monitorProtection: false,
movable: false,
parent: 'body',
onSuccess: () => {},
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ export interface WatermarkOptions {
globalAlpha: number;
zIndex: number;
mutationObserve: boolean;
monitorProtection: boolean;
movable: boolean;
mode: CreateWatermarkModeType;
parent: Element | string;
Expand Down
5 changes: 3 additions & 2 deletions packages/dom/src/watermark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
renderLayout,
WatermarkCanvas,
} from '@watermark-design/core';
// import bootstrap from '../utils/bootstrap'
import protection from '../utils/protection';

/**
* Watermark class
Expand Down Expand Up @@ -36,7 +36,7 @@ class Watermark {
};
this.changeParentElement(this.options.parent);
this.watermarkCanvas = new WatermarkCanvas(this.props, this.options);
// bootstrap()
protection(this.options.monitorProtection);
}

/**
Expand All @@ -51,6 +51,7 @@ class Watermark {
redraw: boolean = true
): Promise<void> {
this.initConfigData(args, mode);
protection(this.options.monitorProtection);
if (redraw) {
this.remove();
await this.create();
Expand Down
15 changes: 15 additions & 0 deletions packages/dom/utils/protection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default (need: boolean) => {
if (typeof window === 'undefined') {
return;
}
if (need) {
Object.defineProperty(window, 'MutationObserver', {
writable: false,
configurable: false,
});
Object.defineProperty(window, 'requestAnimationFrame', {
writable: false,
configurable: false,
});
}
};

0 comments on commit b99ba1e

Please sign in to comment.