import { Node } from '@antv/x6';

export * from './hander';

/**
 * 打印图片
 * @param imgUri 图片地址
 */
export const printHandle = (imgUri: string) => {
  const iframe = document.createElement("iframe");
  iframe.style.height = "0";
  iframe.style.visibility = "hidden";
  iframe.style.width = "0";
  const str = `<html>
            <style media='print'>
                 @page{size:A4 landscape};margin:0mm;padding:0}
            </style>
            <body>
                 <img src="${imgUri}"/>
            </body>
	</html>
	`;
  iframe.setAttribute("srcdoc", str);
  document.body.appendChild(iframe);
  iframe.addEventListener("load", () => {
    iframe?.contentWindow?.print();
  });
  iframe?.contentWindow?.addEventListener("afterprint", function () {
    iframe?.parentNode?.removeChild(iframe);
  });
};

/* uuid */
export function uuid() {
  return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
    var r = (Math.random() * 16) | 0,
      v = c === "x" ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });
}