utils.mjs 994 B

1234567891011121314151617181920212223
  1. //#region ../../packages/components/watermark/src/utils.ts
  2. /** converting camel-cased strings to be lowercase and link it with Separator */
  3. function toLowercaseSeparator(key) {
  4. return key.replace(/([A-Z])/g, "-$1").toLowerCase();
  5. }
  6. function getStyleStr(style) {
  7. return Object.keys(style).map((key) => `${toLowercaseSeparator(key)}: ${style[key]};`).join(" ");
  8. }
  9. /** Returns the ratio of the device's physical pixel resolution to the css pixel resolution */
  10. function getPixelRatio() {
  11. return window.devicePixelRatio || 1;
  12. }
  13. /** Whether to re-render the watermark */
  14. const reRendering = (mutation, watermarkElement) => {
  15. let flag = false;
  16. if (mutation.removedNodes.length && watermarkElement) flag = Array.from(mutation.removedNodes).includes(watermarkElement);
  17. if (mutation.type === "attributes" && mutation.target === watermarkElement) flag = true;
  18. return flag;
  19. };
  20. //#endregion
  21. export { getPixelRatio, getStyleStr, reRendering, toLowercaseSeparator };
  22. //# sourceMappingURL=utils.mjs.map