print-js.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. import {
  2. __commonJS
  3. } from "./chunk-2LSFTFF7.js";
  4. // node_modules/.pnpm/print-js@1.6.0/node_modules/print-js/dist/print.js
  5. var require_print = __commonJS({
  6. "node_modules/.pnpm/print-js@1.6.0/node_modules/print-js/dist/print.js"(exports, module) {
  7. (function webpackUniversalModuleDefinition(root, factory) {
  8. if (typeof exports === "object" && typeof module === "object")
  9. module.exports = factory();
  10. else if (typeof define === "function" && define.amd)
  11. define([], factory);
  12. else if (typeof exports === "object")
  13. exports["printJS"] = factory();
  14. else
  15. root["printJS"] = factory();
  16. })(window, function() {
  17. return (
  18. /******/
  19. function(modules) {
  20. var installedModules = {};
  21. function __webpack_require__(moduleId) {
  22. if (installedModules[moduleId]) {
  23. return installedModules[moduleId].exports;
  24. }
  25. var module2 = installedModules[moduleId] = {
  26. /******/
  27. i: moduleId,
  28. /******/
  29. l: false,
  30. /******/
  31. exports: {}
  32. /******/
  33. };
  34. modules[moduleId].call(module2.exports, module2, module2.exports, __webpack_require__);
  35. module2.l = true;
  36. return module2.exports;
  37. }
  38. __webpack_require__.m = modules;
  39. __webpack_require__.c = installedModules;
  40. __webpack_require__.d = function(exports2, name, getter) {
  41. if (!__webpack_require__.o(exports2, name)) {
  42. Object.defineProperty(exports2, name, { enumerable: true, get: getter });
  43. }
  44. };
  45. __webpack_require__.r = function(exports2) {
  46. if (typeof Symbol !== "undefined" && Symbol.toStringTag) {
  47. Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
  48. }
  49. Object.defineProperty(exports2, "__esModule", { value: true });
  50. };
  51. __webpack_require__.t = function(value, mode) {
  52. if (mode & 1)
  53. value = __webpack_require__(value);
  54. if (mode & 8)
  55. return value;
  56. if (mode & 4 && typeof value === "object" && value && value.__esModule)
  57. return value;
  58. var ns = /* @__PURE__ */ Object.create(null);
  59. __webpack_require__.r(ns);
  60. Object.defineProperty(ns, "default", { enumerable: true, value });
  61. if (mode & 2 && typeof value != "string")
  62. for (var key in value)
  63. __webpack_require__.d(ns, key, function(key2) {
  64. return value[key2];
  65. }.bind(null, key));
  66. return ns;
  67. };
  68. __webpack_require__.n = function(module2) {
  69. var getter = module2 && module2.__esModule ? (
  70. /******/
  71. function getDefault() {
  72. return module2["default"];
  73. }
  74. ) : (
  75. /******/
  76. function getModuleExports() {
  77. return module2;
  78. }
  79. );
  80. __webpack_require__.d(getter, "a", getter);
  81. return getter;
  82. };
  83. __webpack_require__.o = function(object, property) {
  84. return Object.prototype.hasOwnProperty.call(object, property);
  85. };
  86. __webpack_require__.p = "";
  87. return __webpack_require__(__webpack_require__.s = 0);
  88. }({
  89. /***/
  90. "./src/index.js": (
  91. /*!**********************!*\
  92. !*** ./src/index.js ***!
  93. \**********************/
  94. /*! exports provided: default */
  95. /***/
  96. function(module2, __webpack_exports__, __webpack_require__) {
  97. "use strict";
  98. __webpack_require__.r(__webpack_exports__);
  99. var _sass_index_scss__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
  100. /*! ./sass/index.scss */
  101. "./src/sass/index.scss"
  102. );
  103. var _sass_index_scss__WEBPACK_IMPORTED_MODULE_0___default = __webpack_require__.n(_sass_index_scss__WEBPACK_IMPORTED_MODULE_0__);
  104. var _js_init__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
  105. /*! ./js/init */
  106. "./src/js/init.js"
  107. );
  108. var printJS = _js_init__WEBPACK_IMPORTED_MODULE_1__["default"].init;
  109. if (typeof window !== "undefined") {
  110. window.printJS = printJS;
  111. }
  112. __webpack_exports__["default"] = printJS;
  113. }
  114. ),
  115. /***/
  116. "./src/js/browser.js": (
  117. /*!***************************!*\
  118. !*** ./src/js/browser.js ***!
  119. \***************************/
  120. /*! exports provided: default */
  121. /***/
  122. function(module2, __webpack_exports__, __webpack_require__) {
  123. "use strict";
  124. __webpack_require__.r(__webpack_exports__);
  125. var Browser = {
  126. // Firefox 1.0+
  127. isFirefox: function isFirefox() {
  128. return typeof InstallTrigger !== "undefined";
  129. },
  130. // Internet Explorer 6-11
  131. isIE: function isIE() {
  132. return navigator.userAgent.indexOf("MSIE") !== -1 || !!document.documentMode;
  133. },
  134. // Edge 20+
  135. isEdge: function isEdge() {
  136. return !Browser.isIE() && !!window.StyleMedia;
  137. },
  138. // Chrome 1+
  139. isChrome: function isChrome() {
  140. var context = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window;
  141. return !!context.chrome;
  142. },
  143. // At least Safari 3+: "[object HTMLElementConstructor]"
  144. isSafari: function isSafari() {
  145. return Object.prototype.toString.call(window.HTMLElement).indexOf("Constructor") > 0 || navigator.userAgent.toLowerCase().indexOf("safari") !== -1;
  146. },
  147. // IOS Chrome
  148. isIOSChrome: function isIOSChrome() {
  149. return navigator.userAgent.toLowerCase().indexOf("crios") !== -1;
  150. }
  151. };
  152. __webpack_exports__["default"] = Browser;
  153. }
  154. ),
  155. /***/
  156. "./src/js/functions.js": (
  157. /*!*****************************!*\
  158. !*** ./src/js/functions.js ***!
  159. \*****************************/
  160. /*! exports provided: addWrapper, capitalizePrint, collectStyles, addHeader, cleanUp, isRawHTML */
  161. /***/
  162. function(module2, __webpack_exports__, __webpack_require__) {
  163. "use strict";
  164. __webpack_require__.r(__webpack_exports__);
  165. __webpack_require__.d(__webpack_exports__, "addWrapper", function() {
  166. return addWrapper;
  167. });
  168. __webpack_require__.d(__webpack_exports__, "capitalizePrint", function() {
  169. return capitalizePrint;
  170. });
  171. __webpack_require__.d(__webpack_exports__, "collectStyles", function() {
  172. return collectStyles;
  173. });
  174. __webpack_require__.d(__webpack_exports__, "addHeader", function() {
  175. return addHeader;
  176. });
  177. __webpack_require__.d(__webpack_exports__, "cleanUp", function() {
  178. return cleanUp;
  179. });
  180. __webpack_require__.d(__webpack_exports__, "isRawHTML", function() {
  181. return isRawHTML;
  182. });
  183. var _modal__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
  184. /*! ./modal */
  185. "./src/js/modal.js"
  186. );
  187. var _browser__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
  188. /*! ./browser */
  189. "./src/js/browser.js"
  190. );
  191. function _typeof(obj) {
  192. "@babel/helpers - typeof";
  193. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  194. _typeof = function _typeof2(obj2) {
  195. return typeof obj2;
  196. };
  197. } else {
  198. _typeof = function _typeof2(obj2) {
  199. return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
  200. };
  201. }
  202. return _typeof(obj);
  203. }
  204. function addWrapper(htmlData, params) {
  205. var bodyStyle = "font-family:" + params.font + " !important; font-size: " + params.font_size + " !important; width:100%;";
  206. return '<div style="' + bodyStyle + '">' + htmlData + "</div>";
  207. }
  208. function capitalizePrint(obj) {
  209. return obj.charAt(0).toUpperCase() + obj.slice(1);
  210. }
  211. function collectStyles(element, params) {
  212. var win = document.defaultView || window;
  213. var elementStyle = "";
  214. var styles = win.getComputedStyle(element, "");
  215. for (var key = 0; key < styles.length; key++) {
  216. if (params.targetStyles.indexOf("*") !== -1 || params.targetStyle.indexOf(styles[key]) !== -1 || targetStylesMatch(params.targetStyles, styles[key])) {
  217. if (styles.getPropertyValue(styles[key]))
  218. elementStyle += styles[key] + ":" + styles.getPropertyValue(styles[key]) + ";";
  219. }
  220. }
  221. elementStyle += "max-width: " + params.maxWidth + "px !important; font-size: " + params.font_size + " !important;";
  222. return elementStyle;
  223. }
  224. function targetStylesMatch(styles, value) {
  225. for (var i = 0; i < styles.length; i++) {
  226. if (_typeof(value) === "object" && value.indexOf(styles[i]) !== -1)
  227. return true;
  228. }
  229. return false;
  230. }
  231. function addHeader(printElement, params) {
  232. var headerContainer = document.createElement("div");
  233. if (isRawHTML(params.header)) {
  234. headerContainer.innerHTML = params.header;
  235. } else {
  236. var headerElement = document.createElement("h1");
  237. var headerNode = document.createTextNode(params.header);
  238. headerElement.appendChild(headerNode);
  239. headerElement.setAttribute("style", params.headerStyle);
  240. headerContainer.appendChild(headerElement);
  241. }
  242. printElement.insertBefore(headerContainer, printElement.childNodes[0]);
  243. }
  244. function cleanUp(params) {
  245. if (params.showModal)
  246. _modal__WEBPACK_IMPORTED_MODULE_0__["default"].close();
  247. if (params.onLoadingEnd)
  248. params.onLoadingEnd();
  249. if (params.showModal || params.onLoadingStart)
  250. window.URL.revokeObjectURL(params.printable);
  251. var event = "mouseover";
  252. if (_browser__WEBPACK_IMPORTED_MODULE_1__["default"].isChrome() || _browser__WEBPACK_IMPORTED_MODULE_1__["default"].isFirefox()) {
  253. event = "focus";
  254. }
  255. var handler = function handler2() {
  256. window.removeEventListener(event, handler2);
  257. params.onPrintDialogClose();
  258. var iframe = document.getElementById(params.frameId);
  259. if (iframe) {
  260. iframe.remove();
  261. }
  262. };
  263. window.addEventListener(event, handler);
  264. }
  265. function isRawHTML(raw) {
  266. var regexHtml = new RegExp("<([A-Za-z][A-Za-z0-9]*)\\b[^>]*>(.*?)</\\1>");
  267. return regexHtml.test(raw);
  268. }
  269. }
  270. ),
  271. /***/
  272. "./src/js/html.js": (
  273. /*!************************!*\
  274. !*** ./src/js/html.js ***!
  275. \************************/
  276. /*! exports provided: default */
  277. /***/
  278. function(module2, __webpack_exports__, __webpack_require__) {
  279. "use strict";
  280. __webpack_require__.r(__webpack_exports__);
  281. var _functions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
  282. /*! ./functions */
  283. "./src/js/functions.js"
  284. );
  285. var _print__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
  286. /*! ./print */
  287. "./src/js/print.js"
  288. );
  289. function _typeof(obj) {
  290. "@babel/helpers - typeof";
  291. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  292. _typeof = function _typeof2(obj2) {
  293. return typeof obj2;
  294. };
  295. } else {
  296. _typeof = function _typeof2(obj2) {
  297. return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
  298. };
  299. }
  300. return _typeof(obj);
  301. }
  302. __webpack_exports__["default"] = {
  303. print: function print(params, printFrame) {
  304. var printElement = isHtmlElement(params.printable) ? params.printable : document.getElementById(params.printable);
  305. if (!printElement) {
  306. window.console.error("Invalid HTML element id: " + params.printable);
  307. return;
  308. }
  309. params.printableElement = cloneElement(printElement, params);
  310. if (params.header) {
  311. Object(_functions__WEBPACK_IMPORTED_MODULE_0__["addHeader"])(params.printableElement, params);
  312. }
  313. _print__WEBPACK_IMPORTED_MODULE_1__["default"].send(params, printFrame);
  314. }
  315. };
  316. function cloneElement(element, params) {
  317. var clone = element.cloneNode();
  318. var childNodesArray = Array.prototype.slice.call(element.childNodes);
  319. for (var i = 0; i < childNodesArray.length; i++) {
  320. if (params.ignoreElements.indexOf(childNodesArray[i].id) !== -1) {
  321. continue;
  322. }
  323. var clonedChild = cloneElement(childNodesArray[i], params);
  324. clone.appendChild(clonedChild);
  325. }
  326. if (params.scanStyles && element.nodeType === 1) {
  327. clone.setAttribute("style", Object(_functions__WEBPACK_IMPORTED_MODULE_0__["collectStyles"])(element, params));
  328. }
  329. switch (element.tagName) {
  330. case "SELECT":
  331. clone.value = element.value;
  332. break;
  333. case "CANVAS":
  334. clone.getContext("2d").drawImage(element, 0, 0);
  335. break;
  336. }
  337. return clone;
  338. }
  339. function isHtmlElement(printable) {
  340. return _typeof(printable) === "object" && printable && (printable instanceof HTMLElement || printable.nodeType === 1);
  341. }
  342. }
  343. ),
  344. /***/
  345. "./src/js/image.js": (
  346. /*!*************************!*\
  347. !*** ./src/js/image.js ***!
  348. \*************************/
  349. /*! exports provided: default */
  350. /***/
  351. function(module2, __webpack_exports__, __webpack_require__) {
  352. "use strict";
  353. __webpack_require__.r(__webpack_exports__);
  354. var _functions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
  355. /*! ./functions */
  356. "./src/js/functions.js"
  357. );
  358. var _print__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
  359. /*! ./print */
  360. "./src/js/print.js"
  361. );
  362. var _browser__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(
  363. /*! ./browser */
  364. "./src/js/browser.js"
  365. );
  366. __webpack_exports__["default"] = {
  367. print: function print(params, printFrame) {
  368. if (params.printable.constructor !== Array) {
  369. params.printable = [params.printable];
  370. }
  371. params.printableElement = document.createElement("div");
  372. params.printable.forEach(function(src) {
  373. var img = document.createElement("img");
  374. img.setAttribute("style", params.imageStyle);
  375. img.src = src;
  376. if (_browser__WEBPACK_IMPORTED_MODULE_2__["default"].isFirefox()) {
  377. var fullyQualifiedSrc = img.src;
  378. img.src = fullyQualifiedSrc;
  379. }
  380. var imageWrapper = document.createElement("div");
  381. imageWrapper.appendChild(img);
  382. params.printableElement.appendChild(imageWrapper);
  383. });
  384. if (params.header)
  385. Object(_functions__WEBPACK_IMPORTED_MODULE_0__["addHeader"])(params.printableElement, params);
  386. _print__WEBPACK_IMPORTED_MODULE_1__["default"].send(params, printFrame);
  387. }
  388. };
  389. }
  390. ),
  391. /***/
  392. "./src/js/init.js": (
  393. /*!************************!*\
  394. !*** ./src/js/init.js ***!
  395. \************************/
  396. /*! exports provided: default */
  397. /***/
  398. function(module2, __webpack_exports__, __webpack_require__) {
  399. "use strict";
  400. __webpack_require__.r(__webpack_exports__);
  401. var _browser__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
  402. /*! ./browser */
  403. "./src/js/browser.js"
  404. );
  405. var _modal__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
  406. /*! ./modal */
  407. "./src/js/modal.js"
  408. );
  409. var _pdf__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(
  410. /*! ./pdf */
  411. "./src/js/pdf.js"
  412. );
  413. var _html__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(
  414. /*! ./html */
  415. "./src/js/html.js"
  416. );
  417. var _raw_html__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(
  418. /*! ./raw-html */
  419. "./src/js/raw-html.js"
  420. );
  421. var _image__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(
  422. /*! ./image */
  423. "./src/js/image.js"
  424. );
  425. var _json__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(
  426. /*! ./json */
  427. "./src/js/json.js"
  428. );
  429. function _typeof(obj) {
  430. "@babel/helpers - typeof";
  431. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  432. _typeof = function _typeof2(obj2) {
  433. return typeof obj2;
  434. };
  435. } else {
  436. _typeof = function _typeof2(obj2) {
  437. return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
  438. };
  439. }
  440. return _typeof(obj);
  441. }
  442. var printTypes = ["pdf", "html", "image", "json", "raw-html"];
  443. __webpack_exports__["default"] = {
  444. init: function init() {
  445. var params = {
  446. printable: null,
  447. fallbackPrintable: null,
  448. type: "pdf",
  449. header: null,
  450. headerStyle: "font-weight: 300;",
  451. maxWidth: 800,
  452. properties: null,
  453. gridHeaderStyle: "font-weight: bold; padding: 5px; border: 1px solid #dddddd;",
  454. gridStyle: "border: 1px solid lightgray; margin-bottom: -1px;",
  455. showModal: false,
  456. onError: function onError(error) {
  457. throw error;
  458. },
  459. onLoadingStart: null,
  460. onLoadingEnd: null,
  461. onPrintDialogClose: function onPrintDialogClose() {
  462. },
  463. onIncompatibleBrowser: function onIncompatibleBrowser() {
  464. },
  465. modalMessage: "Retrieving Document...",
  466. frameId: "printJS",
  467. printableElement: null,
  468. documentTitle: "Document",
  469. targetStyle: ["clear", "display", "width", "min-width", "height", "min-height", "max-height"],
  470. targetStyles: ["border", "box", "break", "text-decoration"],
  471. ignoreElements: [],
  472. repeatTableHeader: true,
  473. css: null,
  474. style: null,
  475. scanStyles: true,
  476. base64: false,
  477. // Deprecated
  478. onPdfOpen: null,
  479. font: "TimesNewRoman",
  480. font_size: "12pt",
  481. honorMarginPadding: true,
  482. honorColor: false,
  483. imageStyle: "max-width: 100%;"
  484. };
  485. var args = arguments[0];
  486. if (args === void 0) {
  487. throw new Error("printJS expects at least 1 attribute.");
  488. }
  489. switch (_typeof(args)) {
  490. case "string":
  491. params.printable = encodeURI(args);
  492. params.fallbackPrintable = params.printable;
  493. params.type = arguments[1] || params.type;
  494. break;
  495. case "object":
  496. params.printable = args.printable;
  497. params.fallbackPrintable = typeof args.fallbackPrintable !== "undefined" ? args.fallbackPrintable : params.printable;
  498. params.fallbackPrintable = params.base64 ? "data:application/pdf;base64,".concat(params.fallbackPrintable) : params.fallbackPrintable;
  499. for (var k in params) {
  500. if (k === "printable" || k === "fallbackPrintable")
  501. continue;
  502. params[k] = typeof args[k] !== "undefined" ? args[k] : params[k];
  503. }
  504. break;
  505. default:
  506. throw new Error('Unexpected argument type! Expected "string" or "object", got ' + _typeof(args));
  507. }
  508. if (!params.printable)
  509. throw new Error("Missing printable information.");
  510. if (!params.type || typeof params.type !== "string" || printTypes.indexOf(params.type.toLowerCase()) === -1) {
  511. throw new Error("Invalid print type. Available types are: pdf, html, image and json.");
  512. }
  513. if (params.showModal)
  514. _modal__WEBPACK_IMPORTED_MODULE_1__["default"].show(params);
  515. if (params.onLoadingStart)
  516. params.onLoadingStart();
  517. var usedFrame = document.getElementById(params.frameId);
  518. if (usedFrame)
  519. usedFrame.parentNode.removeChild(usedFrame);
  520. var printFrame = document.createElement("iframe");
  521. if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isFirefox()) {
  522. printFrame.setAttribute("style", "width: 1px; height: 100px; position: fixed; left: 0; top: 0; opacity: 0; border-width: 0; margin: 0; padding: 0");
  523. } else {
  524. printFrame.setAttribute("style", "visibility: hidden; height: 0; width: 0; position: absolute; border: 0");
  525. }
  526. printFrame.setAttribute("id", params.frameId);
  527. if (params.type !== "pdf") {
  528. printFrame.srcdoc = "<html><head><title>" + params.documentTitle + "</title>";
  529. if (params.css) {
  530. if (!Array.isArray(params.css))
  531. params.css = [params.css];
  532. params.css.forEach(function(file) {
  533. printFrame.srcdoc += '<link rel="stylesheet" href="' + file + '">';
  534. });
  535. }
  536. printFrame.srcdoc += "</head><body></body></html>";
  537. }
  538. switch (params.type) {
  539. case "pdf":
  540. if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isIE()) {
  541. try {
  542. console.info("Print.js doesn't support PDF printing in Internet Explorer.");
  543. var win = window.open(params.fallbackPrintable, "_blank");
  544. win.focus();
  545. params.onIncompatibleBrowser();
  546. } catch (error) {
  547. params.onError(error);
  548. } finally {
  549. if (params.showModal)
  550. _modal__WEBPACK_IMPORTED_MODULE_1__["default"].close();
  551. if (params.onLoadingEnd)
  552. params.onLoadingEnd();
  553. }
  554. } else {
  555. _pdf__WEBPACK_IMPORTED_MODULE_2__["default"].print(params, printFrame);
  556. }
  557. break;
  558. case "image":
  559. _image__WEBPACK_IMPORTED_MODULE_5__["default"].print(params, printFrame);
  560. break;
  561. case "html":
  562. _html__WEBPACK_IMPORTED_MODULE_3__["default"].print(params, printFrame);
  563. break;
  564. case "raw-html":
  565. _raw_html__WEBPACK_IMPORTED_MODULE_4__["default"].print(params, printFrame);
  566. break;
  567. case "json":
  568. _json__WEBPACK_IMPORTED_MODULE_6__["default"].print(params, printFrame);
  569. break;
  570. }
  571. }
  572. };
  573. }
  574. ),
  575. /***/
  576. "./src/js/json.js": (
  577. /*!************************!*\
  578. !*** ./src/js/json.js ***!
  579. \************************/
  580. /*! exports provided: default */
  581. /***/
  582. function(module2, __webpack_exports__, __webpack_require__) {
  583. "use strict";
  584. __webpack_require__.r(__webpack_exports__);
  585. var _functions__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
  586. /*! ./functions */
  587. "./src/js/functions.js"
  588. );
  589. var _print__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
  590. /*! ./print */
  591. "./src/js/print.js"
  592. );
  593. function _typeof(obj) {
  594. "@babel/helpers - typeof";
  595. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  596. _typeof = function _typeof2(obj2) {
  597. return typeof obj2;
  598. };
  599. } else {
  600. _typeof = function _typeof2(obj2) {
  601. return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2;
  602. };
  603. }
  604. return _typeof(obj);
  605. }
  606. __webpack_exports__["default"] = {
  607. print: function print(params, printFrame) {
  608. if (_typeof(params.printable) !== "object") {
  609. throw new Error("Invalid javascript data object (JSON).");
  610. }
  611. if (typeof params.repeatTableHeader !== "boolean") {
  612. throw new Error("Invalid value for repeatTableHeader attribute (JSON).");
  613. }
  614. if (!params.properties || !Array.isArray(params.properties)) {
  615. throw new Error("Invalid properties array for your JSON data.");
  616. }
  617. params.properties = params.properties.map(function(property) {
  618. return {
  619. field: _typeof(property) === "object" ? property.field : property,
  620. displayName: _typeof(property) === "object" ? property.displayName : property,
  621. columnSize: _typeof(property) === "object" && property.columnSize ? property.columnSize + ";" : 100 / params.properties.length + "%;"
  622. };
  623. });
  624. params.printableElement = document.createElement("div");
  625. if (params.header) {
  626. Object(_functions__WEBPACK_IMPORTED_MODULE_0__["addHeader"])(params.printableElement, params);
  627. }
  628. params.printableElement.innerHTML += jsonToHTML(params);
  629. _print__WEBPACK_IMPORTED_MODULE_1__["default"].send(params, printFrame);
  630. }
  631. };
  632. function jsonToHTML(params) {
  633. var data = params.printable;
  634. var properties = params.properties;
  635. var htmlData = '<table style="border-collapse: collapse; width: 100%;">';
  636. if (params.repeatTableHeader) {
  637. htmlData += "<thead>";
  638. }
  639. htmlData += "<tr>";
  640. for (var a = 0; a < properties.length; a++) {
  641. htmlData += '<th style="width:' + properties[a].columnSize + ";" + params.gridHeaderStyle + '">' + Object(_functions__WEBPACK_IMPORTED_MODULE_0__["capitalizePrint"])(properties[a].displayName) + "</th>";
  642. }
  643. htmlData += "</tr>";
  644. if (params.repeatTableHeader) {
  645. htmlData += "</thead>";
  646. }
  647. htmlData += "<tbody>";
  648. for (var i = 0; i < data.length; i++) {
  649. htmlData += "<tr>";
  650. for (var n = 0; n < properties.length; n++) {
  651. var stringData = data[i];
  652. var property = properties[n].field.split(".");
  653. if (property.length > 1) {
  654. for (var p = 0; p < property.length; p++) {
  655. stringData = stringData[property[p]];
  656. }
  657. } else {
  658. stringData = stringData[properties[n].field];
  659. }
  660. htmlData += '<td style="width:' + properties[n].columnSize + params.gridStyle + '">' + stringData + "</td>";
  661. }
  662. htmlData += "</tr>";
  663. }
  664. htmlData += "</tbody></table>";
  665. return htmlData;
  666. }
  667. }
  668. ),
  669. /***/
  670. "./src/js/modal.js": (
  671. /*!*************************!*\
  672. !*** ./src/js/modal.js ***!
  673. \*************************/
  674. /*! exports provided: default */
  675. /***/
  676. function(module2, __webpack_exports__, __webpack_require__) {
  677. "use strict";
  678. __webpack_require__.r(__webpack_exports__);
  679. var Modal = {
  680. show: function show(params) {
  681. var modalStyle = "font-family:sans-serif; display:table; text-align:center; font-weight:300; font-size:30px; left:0; top:0;position:fixed; z-index: 9990;color: #0460B5; width: 100%; height: 100%; background-color:rgba(255,255,255,.9);transition: opacity .3s ease;";
  682. var printModal = document.createElement("div");
  683. printModal.setAttribute("style", modalStyle);
  684. printModal.setAttribute("id", "printJS-Modal");
  685. var contentDiv = document.createElement("div");
  686. contentDiv.setAttribute("style", "display:table-cell; vertical-align:middle; padding-bottom:100px;");
  687. var closeButton = document.createElement("div");
  688. closeButton.setAttribute("class", "printClose");
  689. closeButton.setAttribute("id", "printClose");
  690. contentDiv.appendChild(closeButton);
  691. var spinner = document.createElement("span");
  692. spinner.setAttribute("class", "printSpinner");
  693. contentDiv.appendChild(spinner);
  694. var messageNode = document.createTextNode(params.modalMessage);
  695. contentDiv.appendChild(messageNode);
  696. printModal.appendChild(contentDiv);
  697. document.getElementsByTagName("body")[0].appendChild(printModal);
  698. document.getElementById("printClose").addEventListener("click", function() {
  699. Modal.close();
  700. });
  701. },
  702. close: function close() {
  703. var printModal = document.getElementById("printJS-Modal");
  704. if (printModal) {
  705. printModal.parentNode.removeChild(printModal);
  706. }
  707. }
  708. };
  709. __webpack_exports__["default"] = Modal;
  710. }
  711. ),
  712. /***/
  713. "./src/js/pdf.js": (
  714. /*!***********************!*\
  715. !*** ./src/js/pdf.js ***!
  716. \***********************/
  717. /*! exports provided: default */
  718. /***/
  719. function(module2, __webpack_exports__, __webpack_require__) {
  720. "use strict";
  721. __webpack_require__.r(__webpack_exports__);
  722. var _print__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
  723. /*! ./print */
  724. "./src/js/print.js"
  725. );
  726. var _functions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
  727. /*! ./functions */
  728. "./src/js/functions.js"
  729. );
  730. __webpack_exports__["default"] = {
  731. print: function print(params, printFrame) {
  732. if (params.base64) {
  733. var bytesArray = Uint8Array.from(atob(params.printable), function(c) {
  734. return c.charCodeAt(0);
  735. });
  736. createBlobAndPrint(params, printFrame, bytesArray);
  737. return;
  738. }
  739. params.printable = /^(blob|http|\/\/)/i.test(params.printable) ? params.printable : window.location.origin + (params.printable.charAt(0) !== "/" ? "/" + params.printable : params.printable);
  740. var req = new window.XMLHttpRequest();
  741. req.responseType = "arraybuffer";
  742. req.addEventListener("error", function() {
  743. Object(_functions__WEBPACK_IMPORTED_MODULE_1__["cleanUp"])(params);
  744. params.onError(req.statusText, req);
  745. });
  746. req.addEventListener("load", function() {
  747. if ([200, 201].indexOf(req.status) === -1) {
  748. Object(_functions__WEBPACK_IMPORTED_MODULE_1__["cleanUp"])(params);
  749. params.onError(req.statusText, req);
  750. return;
  751. }
  752. createBlobAndPrint(params, printFrame, req.response);
  753. });
  754. req.open("GET", params.printable, true);
  755. req.send();
  756. }
  757. };
  758. function createBlobAndPrint(params, printFrame, data) {
  759. var localPdf = new window.Blob([data], {
  760. type: "application/pdf"
  761. });
  762. localPdf = window.URL.createObjectURL(localPdf);
  763. printFrame.setAttribute("src", localPdf);
  764. _print__WEBPACK_IMPORTED_MODULE_0__["default"].send(params, printFrame);
  765. }
  766. }
  767. ),
  768. /***/
  769. "./src/js/print.js": (
  770. /*!*************************!*\
  771. !*** ./src/js/print.js ***!
  772. \*************************/
  773. /*! exports provided: default */
  774. /***/
  775. function(module2, __webpack_exports__, __webpack_require__) {
  776. "use strict";
  777. __webpack_require__.r(__webpack_exports__);
  778. var _browser__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
  779. /*! ./browser */
  780. "./src/js/browser.js"
  781. );
  782. var _functions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(
  783. /*! ./functions */
  784. "./src/js/functions.js"
  785. );
  786. var Print = {
  787. send: function send(params, printFrame) {
  788. document.getElementsByTagName("body")[0].appendChild(printFrame);
  789. var iframeElement = document.getElementById(params.frameId);
  790. iframeElement.onload = function() {
  791. if (params.type === "pdf") {
  792. if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isFirefox()) {
  793. setTimeout(function() {
  794. return performPrint(iframeElement, params);
  795. }, 1e3);
  796. } else {
  797. performPrint(iframeElement, params);
  798. }
  799. return;
  800. }
  801. var printDocument = iframeElement.contentWindow || iframeElement.contentDocument;
  802. if (printDocument.document)
  803. printDocument = printDocument.document;
  804. printDocument.body.appendChild(params.printableElement);
  805. if (params.type !== "pdf" && params.style) {
  806. var style = document.createElement("style");
  807. style.innerHTML = params.style;
  808. printDocument.head.appendChild(style);
  809. }
  810. var images = printDocument.getElementsByTagName("img");
  811. if (images.length > 0) {
  812. loadIframeImages(Array.from(images)).then(function() {
  813. return performPrint(iframeElement, params);
  814. });
  815. } else {
  816. performPrint(iframeElement, params);
  817. }
  818. };
  819. }
  820. };
  821. function performPrint(iframeElement, params) {
  822. try {
  823. iframeElement.focus();
  824. if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isEdge() || _browser__WEBPACK_IMPORTED_MODULE_0__["default"].isIE()) {
  825. try {
  826. iframeElement.contentWindow.document.execCommand("print", false, null);
  827. } catch (e) {
  828. iframeElement.contentWindow.print();
  829. }
  830. } else {
  831. iframeElement.contentWindow.print();
  832. }
  833. } catch (error) {
  834. params.onError(error);
  835. } finally {
  836. if (_browser__WEBPACK_IMPORTED_MODULE_0__["default"].isFirefox()) {
  837. iframeElement.style.visibility = "hidden";
  838. iframeElement.style.left = "-1px";
  839. }
  840. Object(_functions__WEBPACK_IMPORTED_MODULE_1__["cleanUp"])(params);
  841. }
  842. }
  843. function loadIframeImages(images) {
  844. var promises = images.map(function(image) {
  845. if (image.src && image.src !== window.location.href) {
  846. return loadIframeImage(image);
  847. }
  848. });
  849. return Promise.all(promises);
  850. }
  851. function loadIframeImage(image) {
  852. return new Promise(function(resolve) {
  853. var pollImage = function pollImage2() {
  854. !image || typeof image.naturalWidth === "undefined" || image.naturalWidth === 0 || !image.complete ? setTimeout(pollImage2, 500) : resolve();
  855. };
  856. pollImage();
  857. });
  858. }
  859. __webpack_exports__["default"] = Print;
  860. }
  861. ),
  862. /***/
  863. "./src/js/raw-html.js": (
  864. /*!****************************!*\
  865. !*** ./src/js/raw-html.js ***!
  866. \****************************/
  867. /*! exports provided: default */
  868. /***/
  869. function(module2, __webpack_exports__, __webpack_require__) {
  870. "use strict";
  871. __webpack_require__.r(__webpack_exports__);
  872. var _print__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
  873. /*! ./print */
  874. "./src/js/print.js"
  875. );
  876. __webpack_exports__["default"] = {
  877. print: function print(params, printFrame) {
  878. params.printableElement = document.createElement("div");
  879. params.printableElement.setAttribute("style", "width:100%");
  880. params.printableElement.innerHTML = params.printable;
  881. _print__WEBPACK_IMPORTED_MODULE_0__["default"].send(params, printFrame);
  882. }
  883. };
  884. }
  885. ),
  886. /***/
  887. "./src/sass/index.scss": (
  888. /*!*****************************!*\
  889. !*** ./src/sass/index.scss ***!
  890. \*****************************/
  891. /*! no static exports found */
  892. /***/
  893. function(module2, exports2, __webpack_require__) {
  894. }
  895. ),
  896. /***/
  897. 0: (
  898. /*!****************************!*\
  899. !*** multi ./src/index.js ***!
  900. \****************************/
  901. /*! no static exports found */
  902. /***/
  903. function(module2, exports2, __webpack_require__) {
  904. module2.exports = __webpack_require__(
  905. /*! ./src/index.js */
  906. "./src/index.js"
  907. );
  908. }
  909. )
  910. /******/
  911. })["default"]
  912. );
  913. });
  914. }
  915. });
  916. export default require_print();
  917. //# sourceMappingURL=print-js.js.map