dragonfly_chrome_headless 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +4 -0
  5. data/README.md +53 -0
  6. data/Rakefile +10 -0
  7. data/bin/console +14 -0
  8. data/bin/setup +8 -0
  9. data/dragonfly_chrome_headless.gemspec +27 -0
  10. data/lib/dragonfly_chrome_headless.rb +9 -0
  11. data/lib/dragonfly_chrome_headless/plugin.rb +17 -0
  12. data/lib/dragonfly_chrome_headless/processors/rasterize.rb +33 -0
  13. data/lib/dragonfly_chrome_headless/version.rb +3 -0
  14. data/node_modules/.bin/chrome-remote-interface +1 -0
  15. data/node_modules/.bin/mkdirp +1 -0
  16. data/node_modules/.bin/rimraf +1 -0
  17. data/node_modules/@types/core-js/LICENSE +21 -0
  18. data/node_modules/@types/core-js/README.md +16 -0
  19. data/node_modules/@types/core-js/index.d.ts +2452 -0
  20. data/node_modules/@types/core-js/package.json +85 -0
  21. data/node_modules/@types/mkdirp/README.md +18 -0
  22. data/node_modules/@types/mkdirp/index.d.ts +14 -0
  23. data/node_modules/@types/mkdirp/package.json +77 -0
  24. data/node_modules/@types/mkdirp/types-metadata.json +25 -0
  25. data/node_modules/@types/node/README.md +16 -0
  26. data/node_modules/@types/node/index.d.ts +4132 -0
  27. data/node_modules/@types/node/package.json +84 -0
  28. data/node_modules/balanced-match/.npmignore +5 -0
  29. data/node_modules/balanced-match/LICENSE.md +21 -0
  30. data/node_modules/balanced-match/README.md +91 -0
  31. data/node_modules/balanced-match/index.js +59 -0
  32. data/node_modules/balanced-match/package.json +112 -0
  33. data/node_modules/brace-expansion/README.md +123 -0
  34. data/node_modules/brace-expansion/index.js +201 -0
  35. data/node_modules/brace-expansion/package.json +114 -0
  36. data/node_modules/chrome-launcher/.clang-format +6 -0
  37. data/node_modules/chrome-launcher/.npmignore +11 -0
  38. data/node_modules/chrome-launcher/README.md +123 -0
  39. data/node_modules/chrome-launcher/ask.js +32 -0
  40. data/node_modules/chrome-launcher/ask.ts +35 -0
  41. data/node_modules/chrome-launcher/chrome-finder.js +157 -0
  42. data/node_modules/chrome-launcher/chrome-finder.ts +186 -0
  43. data/node_modules/chrome-launcher/chrome-launcher.js +245 -0
  44. data/node_modules/chrome-launcher/chrome-launcher.ts +312 -0
  45. data/node_modules/chrome-launcher/compiled-check.js +14 -0
  46. data/node_modules/chrome-launcher/flags.js +27 -0
  47. data/node_modules/chrome-launcher/flags.ts +26 -0
  48. data/node_modules/chrome-launcher/index.js +7 -0
  49. data/node_modules/chrome-launcher/index.ts +1 -0
  50. data/node_modules/chrome-launcher/manual-chrome-launcher.js +30 -0
  51. data/node_modules/chrome-launcher/package.json +116 -0
  52. data/node_modules/chrome-launcher/random-port.js +24 -0
  53. data/node_modules/chrome-launcher/random-port.ts +23 -0
  54. data/node_modules/chrome-launcher/tsconfig.json +19 -0
  55. data/node_modules/chrome-launcher/utils.js +52 -0
  56. data/node_modules/chrome-launcher/utils.ts +44 -0
  57. data/node_modules/chrome-launcher/yarn.lock +1486 -0
  58. data/node_modules/chrome-remote-interface/LICENSE +18 -0
  59. data/node_modules/chrome-remote-interface/README.md +849 -0
  60. data/node_modules/chrome-remote-interface/bin/client.js +337 -0
  61. data/node_modules/chrome-remote-interface/chrome-remote-interface.js +11 -0
  62. data/node_modules/chrome-remote-interface/index.js +39 -0
  63. data/node_modules/chrome-remote-interface/lib/api.js +84 -0
  64. data/node_modules/chrome-remote-interface/lib/chrome.js +307 -0
  65. data/node_modules/chrome-remote-interface/lib/defaults.js +4 -0
  66. data/node_modules/chrome-remote-interface/lib/devtools.js +245 -0
  67. data/node_modules/chrome-remote-interface/lib/external-request.js +28 -0
  68. data/node_modules/chrome-remote-interface/lib/protocol.json +13780 -0
  69. data/node_modules/chrome-remote-interface/lib/websocket-wrapper.js +32 -0
  70. data/node_modules/chrome-remote-interface/package.json +128 -0
  71. data/node_modules/chrome-remote-interface/webpack.config.js +55 -0
  72. data/node_modules/commander/Readme.md +195 -0
  73. data/node_modules/commander/index.js +851 -0
  74. data/node_modules/commander/package.json +92 -0
  75. data/node_modules/concat-map/.travis.yml +4 -0
  76. data/node_modules/concat-map/LICENSE +18 -0
  77. data/node_modules/concat-map/README.markdown +62 -0
  78. data/node_modules/concat-map/example/map.js +6 -0
  79. data/node_modules/concat-map/index.js +13 -0
  80. data/node_modules/concat-map/package.json +117 -0
  81. data/node_modules/concat-map/test/map.js +39 -0
  82. data/node_modules/debug/.coveralls.yml +1 -0
  83. data/node_modules/debug/.eslintrc +11 -0
  84. data/node_modules/debug/.npmignore +9 -0
  85. data/node_modules/debug/.travis.yml +14 -0
  86. data/node_modules/debug/CHANGELOG.md +357 -0
  87. data/node_modules/debug/LICENSE +19 -0
  88. data/node_modules/debug/Makefile +50 -0
  89. data/node_modules/debug/Readme.md +312 -0
  90. data/node_modules/debug/component.json +19 -0
  91. data/node_modules/debug/karma.conf.js +70 -0
  92. data/node_modules/debug/node.js +1 -0
  93. data/node_modules/debug/package.json +124 -0
  94. data/node_modules/debug/src/browser.js +185 -0
  95. data/node_modules/debug/src/debug.js +202 -0
  96. data/node_modules/debug/src/index.js +10 -0
  97. data/node_modules/debug/src/node.js +246 -0
  98. data/node_modules/fs.realpath/LICENSE +43 -0
  99. data/node_modules/fs.realpath/README.md +33 -0
  100. data/node_modules/fs.realpath/index.js +66 -0
  101. data/node_modules/fs.realpath/old.js +303 -0
  102. data/node_modules/fs.realpath/package.json +94 -0
  103. data/node_modules/glob/LICENSE +15 -0
  104. data/node_modules/glob/README.md +368 -0
  105. data/node_modules/glob/changelog.md +67 -0
  106. data/node_modules/glob/common.js +240 -0
  107. data/node_modules/glob/glob.js +790 -0
  108. data/node_modules/glob/package.json +112 -0
  109. data/node_modules/glob/sync.js +486 -0
  110. data/node_modules/html-pdf-chrome/.npmignore +9 -0
  111. data/node_modules/html-pdf-chrome/LICENSE +21 -0
  112. data/node_modules/html-pdf-chrome/README.md +165 -0
  113. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.d.ts +87 -0
  114. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js +4 -0
  115. data/node_modules/html-pdf-chrome/lib/src/ChromePrintOptions.js.map +1 -0
  116. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.d.ts +120 -0
  117. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js +206 -0
  118. data/node_modules/html-pdf-chrome/lib/src/CompletionTrigger.js.map +1 -0
  119. data/node_modules/html-pdf-chrome/lib/src/CreateResult.d.ts +70 -0
  120. data/node_modules/html-pdf-chrome/lib/src/CreateResult.js +98 -0
  121. data/node_modules/html-pdf-chrome/lib/src/CreateResult.js.map +1 -0
  122. data/node_modules/html-pdf-chrome/lib/src/index.d.ts +72 -0
  123. data/node_modules/html-pdf-chrome/lib/src/index.js +123 -0
  124. data/node_modules/html-pdf-chrome/lib/src/index.js.map +1 -0
  125. data/node_modules/html-pdf-chrome/package.json +133 -0
  126. data/node_modules/html-pdf-chrome/src/ChromePrintOptions.ts +99 -0
  127. data/node_modules/html-pdf-chrome/src/CompletionTrigger.ts +201 -0
  128. data/node_modules/html-pdf-chrome/src/CreateResult.ts +100 -0
  129. data/node_modules/html-pdf-chrome/src/index.ts +179 -0
  130. data/node_modules/inflight/LICENSE +15 -0
  131. data/node_modules/inflight/README.md +37 -0
  132. data/node_modules/inflight/inflight.js +54 -0
  133. data/node_modules/inflight/package.json +105 -0
  134. data/node_modules/inherits/LICENSE +16 -0
  135. data/node_modules/inherits/README.md +42 -0
  136. data/node_modules/inherits/inherits.js +7 -0
  137. data/node_modules/inherits/inherits_browser.js +23 -0
  138. data/node_modules/inherits/package.json +97 -0
  139. data/node_modules/lighthouse-logger/README.md +4 -0
  140. data/node_modules/lighthouse-logger/index.js +212 -0
  141. data/node_modules/lighthouse-logger/package.json +69 -0
  142. data/node_modules/lighthouse-logger/yarn.lock +13 -0
  143. data/node_modules/minimatch/LICENSE +15 -0
  144. data/node_modules/minimatch/README.md +209 -0
  145. data/node_modules/minimatch/minimatch.js +923 -0
  146. data/node_modules/minimatch/package.json +99 -0
  147. data/node_modules/minimist/.travis.yml +4 -0
  148. data/node_modules/minimist/LICENSE +18 -0
  149. data/node_modules/minimist/example/parse.js +2 -0
  150. data/node_modules/minimist/index.js +187 -0
  151. data/node_modules/minimist/package.json +101 -0
  152. data/node_modules/minimist/readme.markdown +73 -0
  153. data/node_modules/minimist/test/dash.js +24 -0
  154. data/node_modules/minimist/test/default_bool.js +20 -0
  155. data/node_modules/minimist/test/dotted.js +16 -0
  156. data/node_modules/minimist/test/long.js +31 -0
  157. data/node_modules/minimist/test/parse.js +318 -0
  158. data/node_modules/minimist/test/parse_modified.js +9 -0
  159. data/node_modules/minimist/test/short.js +67 -0
  160. data/node_modules/minimist/test/whitespace.js +8 -0
  161. data/node_modules/mkdirp/.travis.yml +8 -0
  162. data/node_modules/mkdirp/LICENSE +21 -0
  163. data/node_modules/mkdirp/bin/cmd.js +33 -0
  164. data/node_modules/mkdirp/bin/usage.txt +12 -0
  165. data/node_modules/mkdirp/examples/pow.js +6 -0
  166. data/node_modules/mkdirp/index.js +98 -0
  167. data/node_modules/mkdirp/package.json +93 -0
  168. data/node_modules/mkdirp/readme.markdown +100 -0
  169. data/node_modules/mkdirp/test/chmod.js +41 -0
  170. data/node_modules/mkdirp/test/clobber.js +38 -0
  171. data/node_modules/mkdirp/test/mkdirp.js +28 -0
  172. data/node_modules/mkdirp/test/opts_fs.js +29 -0
  173. data/node_modules/mkdirp/test/opts_fs_sync.js +27 -0
  174. data/node_modules/mkdirp/test/perm.js +32 -0
  175. data/node_modules/mkdirp/test/perm_sync.js +36 -0
  176. data/node_modules/mkdirp/test/race.js +37 -0
  177. data/node_modules/mkdirp/test/rel.js +32 -0
  178. data/node_modules/mkdirp/test/return.js +25 -0
  179. data/node_modules/mkdirp/test/return_sync.js +24 -0
  180. data/node_modules/mkdirp/test/root.js +19 -0
  181. data/node_modules/mkdirp/test/sync.js +32 -0
  182. data/node_modules/mkdirp/test/umask.js +28 -0
  183. data/node_modules/mkdirp/test/umask_sync.js +32 -0
  184. data/node_modules/ms/README.md +51 -0
  185. data/node_modules/ms/index.js +152 -0
  186. data/node_modules/ms/license.md +21 -0
  187. data/node_modules/ms/package.json +109 -0
  188. data/node_modules/once/LICENSE +15 -0
  189. data/node_modules/once/README.md +79 -0
  190. data/node_modules/once/once.js +42 -0
  191. data/node_modules/once/package.json +101 -0
  192. data/node_modules/path-is-absolute/index.js +20 -0
  193. data/node_modules/path-is-absolute/license +21 -0
  194. data/node_modules/path-is-absolute/package.json +111 -0
  195. data/node_modules/path-is-absolute/readme.md +59 -0
  196. data/node_modules/rimraf/LICENSE +15 -0
  197. data/node_modules/rimraf/README.md +101 -0
  198. data/node_modules/rimraf/bin.js +50 -0
  199. data/node_modules/rimraf/package.json +99 -0
  200. data/node_modules/rimraf/rimraf.js +363 -0
  201. data/node_modules/ultron/LICENSE +22 -0
  202. data/node_modules/ultron/index.js +138 -0
  203. data/node_modules/ultron/package.json +112 -0
  204. data/node_modules/wrappy/LICENSE +15 -0
  205. data/node_modules/wrappy/README.md +36 -0
  206. data/node_modules/wrappy/package.json +97 -0
  207. data/node_modules/wrappy/wrappy.js +33 -0
  208. data/node_modules/ws/LICENSE +21 -0
  209. data/node_modules/ws/README.md +259 -0
  210. data/node_modules/ws/SECURITY.md +33 -0
  211. data/node_modules/ws/index.js +15 -0
  212. data/node_modules/ws/lib/BufferUtil.fallback.js +56 -0
  213. data/node_modules/ws/lib/BufferUtil.js +15 -0
  214. data/node_modules/ws/lib/ErrorCodes.js +28 -0
  215. data/node_modules/ws/lib/EventTarget.js +158 -0
  216. data/node_modules/ws/lib/Extensions.js +69 -0
  217. data/node_modules/ws/lib/PerMessageDeflate.js +339 -0
  218. data/node_modules/ws/lib/Receiver.js +520 -0
  219. data/node_modules/ws/lib/Sender.js +438 -0
  220. data/node_modules/ws/lib/Validation.fallback.js +9 -0
  221. data/node_modules/ws/lib/Validation.js +17 -0
  222. data/node_modules/ws/lib/WebSocket.js +705 -0
  223. data/node_modules/ws/lib/WebSocketServer.js +336 -0
  224. data/node_modules/ws/package.json +122 -0
  225. data/package.json +26 -0
  226. data/samples/sample.html +13 -0
  227. data/script/rasterize.js +18 -0
  228. metadata +325 -0
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["src/CompletionTrigger.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;AAEb;;;;;;GAMG;AACH;IAEE;;;;;OAKG;IACH,YACY,UAAU,IAAI,EACd,iBAAiB,8BAA8B;QAD/C,YAAO,GAAP,OAAO,CAAO;QACd,mBAAc,GAAd,cAAc,CAAiC;IACxD,CAAC;CAWL;AAtBD,8CAsBC;AAED;;;;;;GAMG;AACH,WAAmB,SAAQ,iBAAiB;IAE1C;;;;OAIG;IACH,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAEY,IAAI,CAAC,MAAW;;YAC3B,MAAM,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO;gBACzB,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACpC,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AAhBD,sBAgBC;AAED;;;;;;GAMG;AACH,WAAmB,SAAQ,iBAAiB;IAE1C;;;;;;;OAOG;IACH,YAAsB,KAAa,EAAY,WAAoB,EAAE,OAAgB;QACnF,KAAK,CAAC,OAAO,CAAC,CAAC;QADK,UAAK,GAAL,KAAK,CAAQ;QAAY,gBAAW,GAAX,WAAW,CAAS;IAEnE,CAAC;IAEY,IAAI,CAAC,MAAW;;YAC3B,MAAM,EAAC,OAAO,EAAC,GAAG,MAAM,CAAC;YACzB,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,GAAG,kBAAkB,IAAI,CAAC,WAAW,IAAI,GAAG,MAAM,CAAC;YACpF,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;g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SAAQ,iBAAiB;IAE7C;;;;;;OAMG;IACH,YAAsB,YAAqB,EAAE,OAAgB;QAC3D,KAAK,CAAC,OAAO,CAAC,CAAC;QADK,iBAAY,GAAZ,YAAY,CAAS;IAE3C,CAAC;IAEY,IAAI,CAAC,MAAW;;YAC3B,MAAM,EAAC,OAAO,EAAC,GAAG,MAAM,CAAC;YACzB,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,IAAI,aAAa,CAAC;YACnD,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC;gBACtB,YAAY,EAAE,IAAI;gBAClB,UAAU,EAAE;;2CAEyB,OAAO;;;qCAGb,IAAI,CAAC,cAAc,OAAO,IAAI,CAAC,OAAO;WAChE;aACN,CAAC,CAAC;QACL,CAAC;KAAA;CACF;AA3BD,4BA2BC","file":"CompletionTrigger.js","sourcesContent":["'use strict';\n\n/**\n * Defines a trigger that signifies page render completion.\n *\n * @export\n * @abstract\n * @class CompletionTrigger\n */\nexport abstract class CompletionTrigger {\n\n /**\n * Creates an instance of CompletionTrigger.\n * @param {number} [timeout=1000] milliseconds until timing out.\n * @param {string} [timeoutMessage='CompletionTrigger timed out.'] The timeout message.\n * @memberof CompletionTrigger\n */\n constructor(\n protected timeout = 1000,\n protected timeoutMessage = 'CompletionTrigger timed out.',\n ) {}\n\n /**\n * Abstracts away the trigger logic.\n *\n * @abstract\n * @param {*} client the Chrome connection information.\n * @returns {Promise<any>} resolves if triggered, rejects on error or timeout.\n * @memberof CompletionTrigger\n */\n public abstract async wait(client: any): Promise<any>;\n}\n\n/**\n * Waits for a specified amount of time.\n *\n * @export\n * @class Timer\n * @extends {CompletionTrigger}\n */\nexport class Timer extends CompletionTrigger {\n\n /**\n * Creates an instance of the Timer CompletionTrigger.\n * @param {number} timeout ms to wait until timing out.\n * @memberof Timer\n */\n constructor(timeout: number) {\n super(timeout);\n }\n\n public async wait(client: any): Promise<any> {\n return new Promise((resolve) => {\n setTimeout(resolve, this.timeout);\n });\n }\n}\n\n/**\n * Waits for an Event to fire.\n *\n * @export\n * @class Event\n * @extends {CompletionTrigger}\n */\nexport class Event extends CompletionTrigger {\n\n /**\n * Creates an instance of the Event CompletionTrigger.\n * @param {string} event the name of the event to listen for.\n * @param {string} [cssSelector] the CSS selector of the element to listen on.\n * Defaults to body.\n * @param {number} [timeout] ms to wait until timing out.\n * @memberof Event\n */\n constructor(protected event: string, protected cssSelector?: string, timeout?: number) {\n super(timeout);\n }\n\n public async wait(client: any): Promise<any> {\n const {Runtime} = client;\n const selector = this.cssSelector ? `querySelector('${this.cssSelector}')` : 'body';\n return Runtime.evaluate({\n awaitPromise: true,\n expression: `\n new Promise((resolve, reject) => {\n document.${selector}.addEventListener('${this.event}', resolve, { once: true });\n setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});\n })`,\n });\n }\n}\n\n/**\n * Waits for a callback to be called.\n *\n * @export\n * @class Callback\n * @extends {CompletionTrigger}\n */\nexport class Callback extends CompletionTrigger {\n\n /**\n * Creates an instance of the Callback CompletionTrigger.\n * @param {string} [callbackName] the name of the callback to listen for.\n * Defaults to htmlPdfCb.\n * @param {number} [timeout] ms to wait until timing out.\n * @memberof Callback\n */\n constructor(protected callbackName?: string, timeout?: number) {\n super(timeout);\n }\n\n public async wait(client: any): Promise<any> {\n const {Runtime} = client;\n const cbName = this.callbackName || 'htmlPdfCb';\n return Runtime.evaluate({\n awaitPromise: true,\n expression: `\n new Promise((resolve, reject) => {\n ${cbName} = resolve;\n setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});\n })`,\n });\n }\n}\n\n/**\n * Waits for a DOM element to appear.\n *\n * @export\n * @class Element\n * @extends {CompletionTrigger}\n */\nexport class Element extends CompletionTrigger {\n\n /**\n * Creates an instance of the Element CompletionTrigger.\n * @param {string} cssSelector the element to listen for.\n * @param {number} [timeout] ms to wait until timing out.\n * @memberof Element\n */\n constructor(protected cssSelector: string, timeout?: number) {\n super(timeout);\n }\n\n public async wait(client: any): Promise<any> {\n const {Runtime} = client;\n return Runtime.evaluate({\n awaitPromise: true,\n expression: `\n new Promise((resolve, reject) => {\n new MutationObserver((mutations, observer) => {\n mutations.forEach((mutation) => {\n if ([...mutation.addedNodes].find((node) => node.matches('${this.cssSelector}'))) {\n observer.disconnect();\n resolve();\n }\n });\n }).observe(document.body, { childList: true });\n setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});\n })`,\n });\n }\n}\n\n/**\n * Waits for a variable to be true.\n *\n * @export\n * @class Variable\n * @extends {CompletionTrigger}\n */\nexport class Variable extends CompletionTrigger {\n\n /**\n * Creates an instance of the Variable CompletionTrigger.\n * @param {string} [variableName] the variable to listen on.\n * Defaults to htmlPdfDone.\n * @param {number} [timeout] ms to wait until timing out.\n * @memberof Variable\n */\n constructor(protected variableName?: string, timeout?: number) {\n super(timeout);\n }\n\n public async wait(client: any): Promise<any> {\n const {Runtime} = client;\n const varName = this.variableName || 'htmlPdfDone';\n return Runtime.evaluate({\n awaitPromise: true,\n expression: `\n new Promise((resolve, reject) => {\n Object.defineProperty(window, '${varName}', {\n set: (val) => { if (val === true) resolve(); }\n });\n setTimeout(() => reject('${this.timeoutMessage}'), ${this.timeout});\n })`,\n });\n }\n}\n"],"sourceRoot":"../.."}
@@ -0,0 +1,70 @@
1
+ /// <reference types="node" />
2
+ import { Stream } from 'stream';
3
+ /**
4
+ * Allows exporting of PDF data to multiple formats.
5
+ *
6
+ * @export
7
+ * @class CreateResult
8
+ */
9
+ export declare class CreateResult {
10
+ /**
11
+ * Writes the given data Buffer to the specified file location.
12
+ *
13
+ * @private
14
+ * @static
15
+ * @param {string} filename the file name to write to.
16
+ * @param {Buffer} data the data to write.
17
+ * @returns {Promise<void>}
18
+ *
19
+ * @memberof CreateResult
20
+ */
21
+ private static writeFile(filename, data);
22
+ /**
23
+ * Base64-encoded PDF data.
24
+ *
25
+ * @private
26
+ * @type {string}
27
+ * @memberof CreateResult
28
+ */
29
+ private data;
30
+ /**
31
+ * Creates an instance of CreateResult.
32
+ * @param {string} data base64 PDF data
33
+ *
34
+ * @memberof CreateResult
35
+ */
36
+ constructor(data: string);
37
+ /**
38
+ * Get the base64 PDF data.
39
+ *
40
+ * @returns {string} base64 PDF data.
41
+ *
42
+ * @memberof CreateResult
43
+ */
44
+ toBase64(): string;
45
+ /**
46
+ * Get a Buffer of the PDF data.
47
+ *
48
+ * @returns {Buffer} PDF data.
49
+ *
50
+ * @memberof CreateResult
51
+ */
52
+ toBuffer(): Buffer;
53
+ /**
54
+ * Get a Stream of the PDF data.
55
+ *
56
+ * @returns {Stream} Stream of PDF data.
57
+ *
58
+ * @memberof CreateResult
59
+ */
60
+ toStream(): Stream;
61
+ /**
62
+ * Saves the PDF to a file.
63
+ *
64
+ * @param {string} filename the filename.
65
+ * @returns {Promise<void>} resolves upon successful create.
66
+ *
67
+ * @memberof CreateResult
68
+ */
69
+ toFile(filename: string): Promise<void>;
70
+ }
@@ -0,0 +1,98 @@
1
+ 'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ const fs = require("fs");
12
+ const stream_1 = require("stream");
13
+ /**
14
+ * Allows exporting of PDF data to multiple formats.
15
+ *
16
+ * @export
17
+ * @class CreateResult
18
+ */
19
+ class CreateResult {
20
+ /**
21
+ * Writes the given data Buffer to the specified file location.
22
+ *
23
+ * @private
24
+ * @static
25
+ * @param {string} filename the file name to write to.
26
+ * @param {Buffer} data the data to write.
27
+ * @returns {Promise<void>}
28
+ *
29
+ * @memberof CreateResult
30
+ */
31
+ static writeFile(filename, data) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ return new Promise((resolve, reject) => {
34
+ fs.writeFile(filename, data, (err) => {
35
+ err ? reject(err) : resolve();
36
+ });
37
+ });
38
+ });
39
+ }
40
+ /**
41
+ * Creates an instance of CreateResult.
42
+ * @param {string} data base64 PDF data
43
+ *
44
+ * @memberof CreateResult
45
+ */
46
+ constructor(data) {
47
+ this.data = data;
48
+ }
49
+ /**
50
+ * Get the base64 PDF data.
51
+ *
52
+ * @returns {string} base64 PDF data.
53
+ *
54
+ * @memberof CreateResult
55
+ */
56
+ toBase64() {
57
+ return this.data;
58
+ }
59
+ /**
60
+ * Get a Buffer of the PDF data.
61
+ *
62
+ * @returns {Buffer} PDF data.
63
+ *
64
+ * @memberof CreateResult
65
+ */
66
+ toBuffer() {
67
+ return Buffer.from(this.data, 'base64');
68
+ }
69
+ /**
70
+ * Get a Stream of the PDF data.
71
+ *
72
+ * @returns {Stream} Stream of PDF data.
73
+ *
74
+ * @memberof CreateResult
75
+ */
76
+ toStream() {
77
+ const stream = new stream_1.Readable();
78
+ stream.push(this.data, 'base64');
79
+ stream.push(null);
80
+ return stream;
81
+ }
82
+ /**
83
+ * Saves the PDF to a file.
84
+ *
85
+ * @param {string} filename the filename.
86
+ * @returns {Promise<void>} resolves upon successful create.
87
+ *
88
+ * @memberof CreateResult
89
+ */
90
+ toFile(filename) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ yield CreateResult.writeFile(filename, this.toBuffer());
93
+ });
94
+ }
95
+ }
96
+ exports.CreateResult = CreateResult;
97
+
98
+ //# sourceMappingURL=CreateResult.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["src/CreateResult.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;AAEb,yBAAyB;AACzB,mCAA0C;AAE1C;;;;;GAKG;AACH;IAEE;;;;;;;;;;OAUG;IACK,MAAM,CAAO,SAAS,CAAC,QAAgB,EAAE,IAAY;;YAC3D,MAAM,CAAC,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM;gBACvC,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,GAAG;oBAC/B,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,EAAE,CAAC;gBAChC,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KAAA;IAWD;;;;;OAKG;IACH,YAAmB,IAAY;QAC7B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACI,QAAQ;QACb,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACI,QAAQ;QACb,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;;OAMG;IACI,QAAQ;QACb,MAAM,MAAM,GAAG,IAAI,iBAAQ,EAAE,CAAC;QAC9B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QACjC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClB,MAAM,CAAC,MAAM,CAAC;IAChB,CAAC;IAED;;;;;;;OAOG;IACU,MAAM,CAAC,QAAgB;;YAClC,MAAM,YAAY,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC1D,CAAC;KAAA;CAEF;AAxFD,oCAwFC","file":"CreateResult.js","sourcesContent":["'use strict';\n\nimport * as fs from 'fs';\nimport { Readable, Stream } from 'stream';\n\n/**\n * Allows exporting of PDF data to multiple formats.\n *\n * @export\n * @class CreateResult\n */\nexport class CreateResult {\n\n /**\n * Writes the given data Buffer to the specified file location.\n *\n * @private\n * @static\n * @param {string} filename the file name to write to.\n * @param {Buffer} data the data to write.\n * @returns {Promise<void>}\n *\n * @memberof CreateResult\n */\n private static async writeFile(filename: string, data: Buffer): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n fs.writeFile(filename, data, (err) => {\n err ? reject(err) : resolve();\n });\n });\n }\n\n /**\n * Base64-encoded PDF data.\n *\n * @private\n * @type {string}\n * @memberof CreateResult\n */\n private data: string;\n\n /**\n * Creates an instance of CreateResult.\n * @param {string} data base64 PDF data\n *\n * @memberof CreateResult\n */\n public constructor(data: string) {\n this.data = data;\n }\n\n /**\n * Get the base64 PDF data.\n *\n * @returns {string} base64 PDF data.\n *\n * @memberof CreateResult\n */\n public toBase64(): string {\n return this.data;\n }\n\n /**\n * Get a Buffer of the PDF data.\n *\n * @returns {Buffer} PDF data.\n *\n * @memberof CreateResult\n */\n public toBuffer(): Buffer {\n return Buffer.from(this.data, 'base64');\n }\n\n /**\n * Get a Stream of the PDF data.\n *\n * @returns {Stream} Stream of PDF data.\n *\n * @memberof CreateResult\n */\n public toStream(): Stream {\n const stream = new Readable();\n stream.push(this.data, 'base64');\n stream.push(null);\n return stream;\n }\n\n /**\n * Saves the PDF to a file.\n *\n * @param {string} filename the filename.\n * @returns {Promise<void>} resolves upon successful create.\n *\n * @memberof CreateResult\n */\n public async toFile(filename: string): Promise<void> {\n await CreateResult.writeFile(filename, this.toBuffer());\n }\n\n}\n"],"sourceRoot":"../.."}
@@ -0,0 +1,72 @@
1
+ import { ChromePrintOptions } from './ChromePrintOptions';
2
+ import * as CompletionTrigger from './CompletionTrigger';
3
+ import { CreateResult } from './CreateResult';
4
+ export { CompletionTrigger, CreateResult };
5
+ /**
6
+ * PDF generation options.
7
+ *
8
+ * @export
9
+ * @interface CreateOptions
10
+ */
11
+ export interface CreateOptions {
12
+ /**
13
+ * The host to connect to Chrome at.
14
+ * If set, it attempts to connect to Chrome.
15
+ * If this and port are not set, it spawns
16
+ * Chrome for the duration of the PDF generation.
17
+ *
18
+ * @type {string}
19
+ * @memberof CreateOptions
20
+ */
21
+ host?: string;
22
+ /**
23
+ * The port to connect to Chrome with.
24
+ * If set, it attempts to connect to Chrome.
25
+ * If this and host are not set, it spawns
26
+ * Chrome for the duration of the PDF generation.
27
+ *
28
+ * @type {number}
29
+ * @memberof CreateOptions
30
+ */
31
+ port?: number;
32
+ /**
33
+ * The explicit path of the intended Chrome binary.
34
+ *
35
+ * @type {string}
36
+ * @memberof CreateOptions
37
+ */
38
+ chromePath?: string;
39
+ /**
40
+ * The options to pass to Chrome's Page.printToPDF.
41
+ * Note: these require Chrome >= 60.
42
+ *
43
+ * @type {ChromePrintOptions}
44
+ * @memberof CreateOptions
45
+ */
46
+ printOptions?: ChromePrintOptions;
47
+ /**
48
+ * An optional CompletionTrigger to wait for before
49
+ * printing the rendered page to a PDF.
50
+ *
51
+ * @type {CompletionTrigger.CompletionTrigger}
52
+ * @memberof CreateOptions
53
+ */
54
+ completionTrigger?: CompletionTrigger.CompletionTrigger;
55
+ /**
56
+ * The time in milliseconds to wait until timing out.
57
+ */
58
+ timeout?: number;
59
+ /**
60
+ * A private flag to signify the operation has been canceled.
61
+ */
62
+ _canceled?: boolean;
63
+ }
64
+ /**
65
+ * Generates a PDF from the given HTML string, launching Chrome as necessary.
66
+ *
67
+ * @export
68
+ * @param {string} html the HTML string.
69
+ * @param {Options} [options] the generation options.
70
+ * @returns {Promise<CreateResult>} the generated PDF data.
71
+ */
72
+ export declare function create(html: string, options?: CreateOptions): Promise<CreateResult>;
@@ -0,0 +1,123 @@
1
+ 'use strict';
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ const chrome_launcher_1 = require("chrome-launcher");
12
+ const CDP = require("chrome-remote-interface");
13
+ const CompletionTrigger = require("./CompletionTrigger");
14
+ exports.CompletionTrigger = CompletionTrigger;
15
+ const CreateResult_1 = require("./CreateResult");
16
+ exports.CreateResult = CreateResult_1.CreateResult;
17
+ /**
18
+ * Generates a PDF from the given HTML string, launching Chrome as necessary.
19
+ *
20
+ * @export
21
+ * @param {string} html the HTML string.
22
+ * @param {Options} [options] the generation options.
23
+ * @returns {Promise<CreateResult>} the generated PDF data.
24
+ */
25
+ function create(html, options) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const myOptions = Object.assign({}, options);
28
+ let chrome;
29
+ myOptions._canceled = false;
30
+ if (myOptions.timeout >= 0) {
31
+ setTimeout(() => {
32
+ myOptions._canceled = true;
33
+ }, myOptions.timeout);
34
+ }
35
+ yield throwIfCanceled(myOptions);
36
+ if (!myOptions.host && !myOptions.port) {
37
+ yield throwIfCanceled(myOptions);
38
+ chrome = yield launchChrome(myOptions);
39
+ }
40
+ try {
41
+ return yield generate(html, myOptions);
42
+ }
43
+ finally {
44
+ if (chrome) {
45
+ yield chrome.kill();
46
+ }
47
+ }
48
+ });
49
+ }
50
+ exports.create = create;
51
+ /**
52
+ * Connects to Chrome and generates a PDF from HTML or a URL.
53
+ *
54
+ * @param {string} html the HTML string or URL.
55
+ * @param {CreateOptions} options the generation options.
56
+ * @returns {Promise<CreateResult>} the generated PDF data.
57
+ */
58
+ function generate(html, options) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ yield throwIfCanceled(options);
61
+ const client = yield CDP(options);
62
+ try {
63
+ const { Page } = client;
64
+ yield Page.enable(); // Enable Page events
65
+ const url = /^(https?|file|data):/i.test(html) ? html : `data:text/html,${html}`;
66
+ yield throwIfCanceled(options);
67
+ yield Page.navigate({ url });
68
+ yield throwIfCanceled(options);
69
+ yield Page.loadEventFired();
70
+ if (options.completionTrigger) {
71
+ yield throwIfCanceled(options);
72
+ const waitResult = yield options.completionTrigger.wait(client);
73
+ if (waitResult && waitResult.exceptionDetails) {
74
+ yield throwIfCanceled(options);
75
+ throw new Error(waitResult.result.value);
76
+ }
77
+ }
78
+ yield throwIfCanceled(options);
79
+ // https://chromedevtools.github.io/debugger-protocol-viewer/tot/Page/#method-printToPDF
80
+ const pdf = yield Page.printToPDF(options.printOptions);
81
+ yield throwIfCanceled(options);
82
+ return new CreateResult_1.CreateResult(pdf.data);
83
+ }
84
+ finally {
85
+ client.close();
86
+ }
87
+ });
88
+ }
89
+ /**
90
+ * Throws an exception if the operation has been canceled.
91
+ *
92
+ * @param {CreateOptions} options the options which track cancellation.
93
+ * @returns {Promise<void>} reject if cancelled, resolve if not.
94
+ */
95
+ function throwIfCanceled(options) {
96
+ return __awaiter(this, void 0, void 0, function* () {
97
+ if (options._canceled) {
98
+ throw new Error('HtmlPdf.create() timed out.');
99
+ }
100
+ });
101
+ }
102
+ /**
103
+ * Launches Chrome with the specified options.
104
+ *
105
+ * @param {CreateOptions} options the options for Chrome.
106
+ * @returns {Promise<LaunchedChrome>} The launched Chrome instance.
107
+ */
108
+ function launchChrome(options) {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const chrome = yield chrome_launcher_1.launch({
111
+ port: options.port,
112
+ chromePath: options.chromePath,
113
+ chromeFlags: [
114
+ '--disable-gpu',
115
+ '--headless',
116
+ ],
117
+ });
118
+ options.port = chrome.port;
119
+ return chrome;
120
+ });
121
+ }
122
+
123
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["src/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;AAEb,qDAAyD;AACzD,+CAA+C;AAK/C,yDAAyD;AAGhD,8CAAiB;AAF1B,iDAA8C;AAElB,uBAFnB,2BAAY,CAEmB;AAoExC;;;;;;;GAOG;AACH,gBAA6B,IAAY,EAAE,OAAuB;;QAChE,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,O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,EAAE;gBACX,eAAe;gBACf,YAAY;aACb;SACF,CAAC,CAAC;QACH,OAAO,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QAC3B,MAAM,CAAC,MAAM,CAAC;IAChB,CAAC;CAAA","file":"index.js","sourcesContent":["'use strict';\n\nimport { launch, LaunchedChrome } from 'chrome-launcher';\nimport * as CDP from 'chrome-remote-interface';\nimport * as fs from 'fs';\nimport { Readable, Stream } from 'stream';\n\nimport { ChromePrintOptions } from './ChromePrintOptions';\nimport * as CompletionTrigger from './CompletionTrigger';\nimport { CreateResult } from './CreateResult';\n\nexport { CompletionTrigger, CreateResult };\n\n/**\n * PDF generation options.\n *\n * @export\n * @interface CreateOptions\n */\nexport interface CreateOptions {\n /**\n * The host to connect to Chrome at.\n * If set, it attempts to connect to Chrome.\n * If this and port are not set, it spawns\n * Chrome for the duration of the PDF generation.\n *\n * @type {string}\n * @memberof CreateOptions\n */\n host?: string;\n\n /**\n * The port to connect to Chrome with.\n * If set, it attempts to connect to Chrome.\n * If this and host are not set, it spawns\n * Chrome for the duration of the PDF generation.\n *\n * @type {number}\n * @memberof CreateOptions\n */\n port?: number;\n\n /**\n * The explicit path of the intended Chrome binary.\n *\n * @type {string}\n * @memberof CreateOptions\n */\n chromePath?: string;\n\n /**\n * The options to pass to Chrome's Page.printToPDF.\n * Note: these require Chrome >= 60.\n *\n * @type {ChromePrintOptions}\n * @memberof CreateOptions\n */\n printOptions?: ChromePrintOptions;\n\n /**\n * An optional CompletionTrigger to wait for before\n * printing the rendered page to a PDF.\n *\n * @type {CompletionTrigger.CompletionTrigger}\n * @memberof CreateOptions\n */\n completionTrigger?: CompletionTrigger.CompletionTrigger;\n\n /**\n * The time in milliseconds to wait until timing out.\n */\n timeout?: number;\n\n /**\n * A private flag to signify the operation has been canceled.\n */\n _canceled?: boolean;\n}\n\n/**\n * Generates a PDF from the given HTML string, launching Chrome as necessary.\n *\n * @export\n * @param {string} html the HTML string.\n * @param {Options} [options] the generation options.\n * @returns {Promise<CreateResult>} the generated PDF data.\n */\nexport async function create(html: string, options?: CreateOptions): Promise<CreateResult> {\n const myOptions = Object.assign({}, options);\n let chrome: LaunchedChrome;\n\n myOptions._canceled = false;\n if (myOptions.timeout >= 0) {\n setTimeout(() => {\n myOptions._canceled = true;\n }, myOptions.timeout);\n }\n\n await throwIfCanceled(myOptions);\n if (!myOptions.host && !myOptions.port) {\n await throwIfCanceled(myOptions);\n chrome = await launchChrome(myOptions);\n }\n\n try {\n return await generate(html, myOptions);\n } finally {\n if (chrome) {\n await chrome.kill();\n }\n }\n}\n\n/**\n * Connects to Chrome and generates a PDF from HTML or a URL.\n *\n * @param {string} html the HTML string or URL.\n * @param {CreateOptions} options the generation options.\n * @returns {Promise<CreateResult>} the generated PDF data.\n */\nasync function generate(html: string, options: CreateOptions): Promise<CreateResult> {\n await throwIfCanceled(options);\n const client = await CDP(options);\n try {\n const {Page} = client;\n await Page.enable(); // Enable Page events\n const url = /^(https?|file|data):/i.test(html) ? html : `data:text/html,${html}`;\n await throwIfCanceled(options);\n await Page.navigate({url});\n await throwIfCanceled(options);\n await Page.loadEventFired();\n if (options.completionTrigger) {\n await throwIfCanceled(options);\n const waitResult = await options.completionTrigger.wait(client);\n if (waitResult && waitResult.exceptionDetails) {\n await throwIfCanceled(options);\n throw new Error(waitResult.result.value);\n }\n }\n await throwIfCanceled(options);\n // https://chromedevtools.github.io/debugger-protocol-viewer/tot/Page/#method-printToPDF\n const pdf = await Page.printToPDF(options.printOptions);\n await throwIfCanceled(options);\n return new CreateResult(pdf.data);\n } finally {\n client.close();\n }\n}\n\n/**\n * Throws an exception if the operation has been canceled.\n *\n * @param {CreateOptions} options the options which track cancellation.\n * @returns {Promise<void>} reject if cancelled, resolve if not.\n */\nasync function throwIfCanceled(options: CreateOptions): Promise<void> {\n if (options._canceled) {\n throw new Error('HtmlPdf.create() timed out.');\n }\n}\n\n/**\n * Launches Chrome with the specified options.\n *\n * @param {CreateOptions} options the options for Chrome.\n * @returns {Promise<LaunchedChrome>} The launched Chrome instance.\n */\nasync function launchChrome(options: CreateOptions): Promise<LaunchedChrome> {\n const chrome = await launch({\n port: options.port,\n chromePath: options.chromePath,\n chromeFlags: [\n '--disable-gpu',\n '--headless',\n ],\n });\n options.port = chrome.port;\n return chrome;\n}\n"],"sourceRoot":"../.."}
@@ -0,0 +1,133 @@
1
+ {
2
+ "_args": [
3
+ [
4
+ {
5
+ "raw": "html-pdf-chrome@0.2.0",
6
+ "scope": null,
7
+ "escapedName": "html-pdf-chrome",
8
+ "name": "html-pdf-chrome",
9
+ "rawSpec": "0.2.0",
10
+ "spec": "0.2.0",
11
+ "type": "version"
12
+ },
13
+ "/Users/tomascelizna/Devel/dragonfly_chrome_headless"
14
+ ]
15
+ ],
16
+ "_from": "html-pdf-chrome@0.2.0",
17
+ "_id": "html-pdf-chrome@0.2.0",
18
+ "_inCache": true,
19
+ "_location": "/html-pdf-chrome",
20
+ "_nodeVersion": "8.1.3",
21
+ "_npmOperationalInternal": {
22
+ "host": "s3://npm-registry-packages",
23
+ "tmp": "tmp/html-pdf-chrome-0.2.0.tgz_1500014130431_0.5509805970359594"
24
+ },
25
+ "_npmUser": {
26
+ "name": "westy92",
27
+ "email": "seth@sethwestphal.com"
28
+ },
29
+ "_npmVersion": "5.0.3",
30
+ "_phantomChildren": {},
31
+ "_requested": {
32
+ "raw": "html-pdf-chrome@0.2.0",
33
+ "scope": null,
34
+ "escapedName": "html-pdf-chrome",
35
+ "name": "html-pdf-chrome",
36
+ "rawSpec": "0.2.0",
37
+ "spec": "0.2.0",
38
+ "type": "version"
39
+ },
40
+ "_requiredBy": [
41
+ "/"
42
+ ],
43
+ "_resolved": "https://registry.npmjs.org/html-pdf-chrome/-/html-pdf-chrome-0.2.0.tgz",
44
+ "_shasum": "76c7e0a07e3e216a4aaffc057413fb8263b00408",
45
+ "_shrinkwrap": null,
46
+ "_spec": "html-pdf-chrome@0.2.0",
47
+ "_where": "/Users/tomascelizna/Devel/dragonfly_chrome_headless",
48
+ "author": {
49
+ "name": "Seth Westphal",
50
+ "email": "seth@sethwestphal.com",
51
+ "url": "http://www.sethwestphal.com/"
52
+ },
53
+ "bugs": {
54
+ "url": "https://github.com/westy92/html-pdf-chrome/issues"
55
+ },
56
+ "dependencies": {
57
+ "chrome-launcher": "^0.3.1",
58
+ "chrome-remote-interface": "^0.24.1"
59
+ },
60
+ "description": "HTML to PDF converter via Chrome/Chromium",
61
+ "devDependencies": {
62
+ "@types/chai": "^3.5.2",
63
+ "@types/chai-string": "^1.1.30",
64
+ "@types/mocha": "^2.2.41",
65
+ "@types/mock-fs": "^3.6.30",
66
+ "@types/node": "^8.0.9",
67
+ "@types/sinon": "^2.3.2",
68
+ "@types/sinon-chai": "^2.7.27",
69
+ "chai": "^3.5.0",
70
+ "chai-string": "^1.3.0",
71
+ "codecov": "^2.2.0",
72
+ "del": "^3.0.0",
73
+ "gulp": "^3.9.1",
74
+ "gulp-sourcemaps": "^2.6.0",
75
+ "gulp-spawn-mocha": "^3.3.0",
76
+ "gulp-tslint": "^8.0.0",
77
+ "gulp-typescript": "^3.2.0",
78
+ "mocha": "^3.3.0",
79
+ "mock-fs": "^4.3.0",
80
+ "pdf2json": "^1.1.7",
81
+ "remap-istanbul": "^0.9.5",
82
+ "sinon": "^2.3.8",
83
+ "sinon-chai": "^2.10.0",
84
+ "tcp-port-used": "^0.1.2",
85
+ "tslint": "^5.5.0",
86
+ "tslint-microsoft-contrib": "^5.0.1",
87
+ "typescript": "^2.4.1"
88
+ },
89
+ "directories": {},
90
+ "dist": {
91
+ "integrity": "sha512-/UYrYgnU8wBdXbHLf3BSuisRXaGy88UTdz3BNQf7p0IEnv1YfTUMuS8+SdPhNZNOX05WYJDPNMuPgO2j+NUPAQ==",
92
+ "shasum": "76c7e0a07e3e216a4aaffc057413fb8263b00408",
93
+ "tarball": "https://registry.npmjs.org/html-pdf-chrome/-/html-pdf-chrome-0.2.0.tgz"
94
+ },
95
+ "engines": {
96
+ "node": ">= 6"
97
+ },
98
+ "gitHead": "899bd0b6c870487284ee490357581dbc4ebe2bd1",
99
+ "homepage": "https://github.com/westy92/html-pdf-chrome",
100
+ "keywords": [
101
+ "html",
102
+ "pdf",
103
+ "html-pdf",
104
+ "chrome",
105
+ "chromium",
106
+ "headless",
107
+ "typescript",
108
+ "windows",
109
+ "mac",
110
+ "linux",
111
+ "nodejs"
112
+ ],
113
+ "license": "MIT",
114
+ "main": "lib/src/index.js",
115
+ "maintainers": [
116
+ {
117
+ "name": "westy92",
118
+ "email": "seth@sethwestphal.com"
119
+ }
120
+ ],
121
+ "name": "html-pdf-chrome",
122
+ "optionalDependencies": {},
123
+ "readme": "ERROR: No README data found!",
124
+ "repository": {
125
+ "type": "git",
126
+ "url": "git://github.com/westy92/html-pdf-chrome.git"
127
+ },
128
+ "scripts": {
129
+ "test": "gulp"
130
+ },
131
+ "typings": "lib/src/index.d.ts",
132
+ "version": "0.2.0"
133
+ }