utils.js 1.2 KB

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