utils.js 952 B

123456789101112131415161718192021222324
  1. /** converting camel-cased strings to be lowercase and link it with Separator */
  2. export function toLowercaseSeparator(key) {
  3. return key.replace(/([A-Z])/g, '-$1').toLowerCase();
  4. }
  5. export function getStyleStr(style) {
  6. return Object.keys(style).map(key => `${toLowercaseSeparator(key)}: ${style[key]};`).join(' ');
  7. }
  8. /** Returns the ratio of the device's physical pixel resolution to the css pixel resolution */
  9. export function getPixelRatio() {
  10. return window.devicePixelRatio || 1;
  11. }
  12. /** Whether to re-render the watermark */
  13. export const reRendering = (mutation, isWatermarkEle) => {
  14. let flag = false;
  15. // Whether to delete the watermark node
  16. if (mutation.removedNodes.length) {
  17. flag = Array.from(mutation.removedNodes).some(node => isWatermarkEle(node));
  18. }
  19. // Whether the watermark dom property value has been modified
  20. if (mutation.type === 'attributes' && isWatermarkEle(mutation.target)) {
  21. flag = true;
  22. }
  23. return flag;
  24. };