2022-12-13 15:47:57 +08:00
|
|
|
/** converting camel-cased strings to be lowercase and link it with Separato */
|
|
|
|
export function toLowercaseSeparator(key: string) {
|
|
|
|
return key.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getStyleStr(style: React.CSSProperties): string {
|
|
|
|
return Object.keys(style)
|
|
|
|
.map((key: keyof React.CSSProperties) => `${toLowercaseSeparator(key)}: ${style[key]};`)
|
|
|
|
.join(' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Returns the ratio of the device's physical pixel resolution to the css pixel resolution */
|
|
|
|
export function getPixelRatio() {
|
|
|
|
return window.devicePixelRatio || 1;
|
|
|
|
}
|
|
|
|
|
2023-01-10 10:56:54 +08:00
|
|
|
/** Whether to re-render the watermark */
|
2023-12-31 23:51:31 +08:00
|
|
|
export const reRendering = (mutation: MutationRecord, isWatermarkEle: (ele: Node) => boolean) => {
|
2023-01-10 10:56:54 +08:00
|
|
|
let flag = false;
|
|
|
|
// Whether to delete the watermark node
|
|
|
|
if (mutation.removedNodes.length) {
|
2023-12-31 23:51:31 +08:00
|
|
|
flag = Array.from<Node>(mutation.removedNodes).some((node) => isWatermarkEle(node));
|
2023-01-10 10:56:54 +08:00
|
|
|
}
|
|
|
|
// Whether the watermark dom property value has been modified
|
2023-08-08 16:48:26 +08:00
|
|
|
if (mutation.type === 'attributes' && isWatermarkEle(mutation.target)) {
|
2023-01-10 10:56:54 +08:00
|
|
|
flag = true;
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
};
|