utils.js 1.2 KB

123456789101112131415161718192021222324252627282930
  1. /** converting camel-cased strings to be lowercase and link it with Separato */
  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. /** Rotate with the watermark as the center point */
  13. export function rotateWatermark(ctx, rotateX, rotateY, rotate) {
  14. ctx.translate(rotateX, rotateY);
  15. ctx.rotate(Math.PI / 180 * Number(rotate));
  16. ctx.translate(-rotateX, -rotateY);
  17. }
  18. /** Whether to re-render the watermark */
  19. export const reRendering = (mutation, watermarkElement) => {
  20. let flag = false;
  21. // Whether to delete the watermark node
  22. if (mutation.removedNodes.length) {
  23. flag = Array.from(mutation.removedNodes).some(node => node === watermarkElement);
  24. }
  25. // Whether the watermark dom property value has been modified
  26. if (mutation.type === 'attributes' && mutation.target === watermarkElement) {
  27. flag = true;
  28. }
  29. return flag;
  30. };