{"version":3,"file":"printWindow.mjs","sources":["../../../../../../packages/components/controls/print/printWindow.ts"],"sourcesContent":["/*\n * @Author: zouyaoji@https://github.com/zouyaoji\n * @Date: 2021-10-27 15:54:13\n * @LastEditTime: 2022-04-06 16:01:23\n * @LastEditors: zouyaoji\n * @Description:\n * @FilePath: \\vue-cesium@next\\packages\\components\\controls\\print\\printWindow.ts\n */\nimport defer from 'casc-cesium-utils/defer'\n\n/**\n * Tells the web browser to print a given window, which my be an iframe window, and\n * returns a promise that resolves when printing is safely over so that, for example\n * the window can be removed.\n * @param {Window} windowToPrint The window to print.\n * @returns {Promise} A promise that resolves when printing is safely over. The prommise is rejected if\n *                    there is no indication that the browser's print\n */\nfunction printWindow(windowToPrint) {\n  const deferred = defer()\n  let printInProgressCount = 0\n\n  const timeout = setTimeout(function () {\n    deferred.reject(false)\n  }, 10000)\n\n  function cancelTimeout() {\n    clearTimeout(timeout)\n  }\n\n  function resolveIfZero() {\n    if (printInProgressCount <= 0) {\n      deferred.resolve()\n    }\n  }\n\n  if (windowToPrint.matchMedia) {\n    windowToPrint.matchMedia('print').addListener(function (evt) {\n      cancelTimeout()\n      if (evt.matches) {\n        ++printInProgressCount\n      } else {\n        --printInProgressCount\n        resolveIfZero()\n      }\n    })\n  }\n\n  windowToPrint.onbeforeprint = function () {\n    cancelTimeout()\n    ++printInProgressCount\n  }\n  windowToPrint.onafterprint = function () {\n    cancelTimeout()\n    --printInProgressCount\n    resolveIfZero()\n  }\n\n  // First try printing with execCommand, because, in IE11, `printWindow.print()`\n  // prints the entire page instead of just the embedded iframe (if the window\n  // is an iframe, anyway).\n  const result = windowToPrint.document.execCommand('print', true, null)\n  if (!result) {\n    windowToPrint.print()\n  }\n\n  return deferred.promise\n}\n\nexport default printWindow\n"],"names":[],"mappings":";;AACA,SAAS,WAAW,CAAC,aAAa,EAAE;AACpC,EAAE,MAAM,QAAQ,GAAG,KAAK,EAAE,CAAC;AAC3B,EAAE,IAAI,oBAAoB,GAAG,CAAC,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