@rindo/core 1.8.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (463) hide show
  1. package/LICENSE.md +27 -0
  2. package/bin/rindo +22 -0
  3. package/build-conditionals/index.d.ts +2 -0
  4. package/build-conditionals/index.mjs +66 -0
  5. package/build-conditionals/package.json +6 -0
  6. package/compiler/index.js +2 -0
  7. package/compiler/package.json +6 -0
  8. package/compiler/rindo.js +6765 -0
  9. package/dist/cli/index.js +6068 -0
  10. package/dist/client/css-shim-14a9812e.js +656 -0
  11. package/dist/client/css-shim-69821662.js +658 -0
  12. package/dist/client/declarations/rindo.core.d.ts +1347 -0
  13. package/dist/client/dom-68c8fe31.js +139 -0
  14. package/dist/client/dom-af01458a.js +137 -0
  15. package/dist/client/index.js +2937 -0
  16. package/dist/client/index.mjs +2820 -0
  17. package/dist/client/polyfills/core-js.js +10 -0
  18. package/dist/client/polyfills/css-shim.js +656 -0
  19. package/dist/client/polyfills/dom.js +146 -0
  20. package/dist/client/polyfills/es5-html-element.js +18 -0
  21. package/dist/client/polyfills/index.js +35 -0
  22. package/dist/client/polyfills/promise.js +9 -0
  23. package/dist/client/polyfills/system.js +6 -0
  24. package/dist/client/shadow-css-6ef31c68.js +386 -0
  25. package/dist/client/shadow-css-8fd1a9e4.js +388 -0
  26. package/dist/compiler/app-core/app-es5-disabled.d.ts +2 -0
  27. package/dist/compiler/app-core/app-polyfills.d.ts +3 -0
  28. package/dist/compiler/app-core/build-conditionals.d.ts +6 -0
  29. package/dist/compiler/app-core/bundle-app-core.d.ts +6 -0
  30. package/dist/compiler/app-core/component-styles.d.ts +4 -0
  31. package/dist/compiler/app-core/format-component-runtime-meta.d.ts +4 -0
  32. package/dist/compiler/app-core/optimize-module.d.ts +7 -0
  33. package/dist/compiler/browser/build-conditionals-client.d.ts +3 -0
  34. package/dist/compiler/browser/compile-options.d.ts +12 -0
  35. package/dist/compiler/browser/compile.d.ts +2 -0
  36. package/dist/compiler/browser/create-compiler.d.ts +14 -0
  37. package/dist/compiler/browser/index.d.ts +11 -0
  38. package/dist/compiler/build/build-ctx.d.ts +74 -0
  39. package/dist/compiler/build/build-finish.d.ts +3 -0
  40. package/dist/compiler/build/build-hmr.d.ts +2 -0
  41. package/dist/compiler/build/build-results.d.ts +2 -0
  42. package/dist/compiler/build/build-stats.d.ts +3 -0
  43. package/dist/compiler/build/build.d.ts +2 -0
  44. package/dist/compiler/build/cache-stats.d.ts +4 -0
  45. package/dist/compiler/build/compiler-build-id.d.ts +6 -0
  46. package/dist/compiler/build/compiler-ctx.d.ts +44 -0
  47. package/dist/compiler/build/init-index-html.d.ts +2 -0
  48. package/dist/compiler/build/validate-files.d.ts +2 -0
  49. package/dist/compiler/build/write-build.d.ts +2 -0
  50. package/dist/compiler/cache.d.ts +22 -0
  51. package/dist/compiler/compiler.d.ts +27 -0
  52. package/dist/compiler/component-hydrate/bundle-hydrate-factory.d.ts +3 -0
  53. package/dist/compiler/component-hydrate/generate-hydrate-app.d.ts +2 -0
  54. package/dist/compiler/component-hydrate/hydrate-factory-closure.d.ts +2 -0
  55. package/dist/compiler/component-hydrate/update-to-hydrate-components.d.ts +2 -0
  56. package/dist/compiler/component-hydrate/write-hydrate-outputs.d.ts +3 -0
  57. package/dist/compiler/component-lazy/generate-cjs.d.ts +3 -0
  58. package/dist/compiler/component-lazy/generate-esm-browser.d.ts +3 -0
  59. package/dist/compiler/component-lazy/generate-esm.d.ts +3 -0
  60. package/dist/compiler/component-lazy/generate-lazy-app.d.ts +3 -0
  61. package/dist/compiler/component-lazy/generate-lazy-module.d.ts +4 -0
  62. package/dist/compiler/component-lazy/generate-system.d.ts +3 -0
  63. package/dist/compiler/component-lazy/update-to-lazy-component.d.ts +2 -0
  64. package/dist/compiler/component-lazy/write-lazy-entry-module.d.ts +2 -0
  65. package/dist/compiler/component-native/update-to-native-component.d.ts +2 -0
  66. package/dist/compiler/config/config-reload.d.ts +3 -0
  67. package/dist/compiler/config/config-utils.d.ts +4 -0
  68. package/dist/compiler/config/validate-config.d.ts +4 -0
  69. package/dist/compiler/config/validate-copy.d.ts +2 -0
  70. package/dist/compiler/config/validate-dev-server.d.ts +2 -0
  71. package/dist/compiler/config/validate-docs.d.ts +2 -0
  72. package/dist/compiler/config/validate-namespace.d.ts +3 -0
  73. package/dist/compiler/config/validate-output-stats.d.ts +2 -0
  74. package/dist/compiler/config/validate-outputs-angular.d.ts +2 -0
  75. package/dist/compiler/config/validate-outputs-custom.d.ts +2 -0
  76. package/dist/compiler/config/validate-outputs-dist-module.d.ts +2 -0
  77. package/dist/compiler/config/validate-outputs-dist.d.ts +2 -0
  78. package/dist/compiler/config/validate-outputs-hydrate-script.d.ts +2 -0
  79. package/dist/compiler/config/validate-outputs-www.d.ts +2 -0
  80. package/dist/compiler/config/validate-outputs.d.ts +2 -0
  81. package/dist/compiler/config/validate-paths.d.ts +2 -0
  82. package/dist/compiler/config/validate-plugins.d.ts +2 -0
  83. package/dist/compiler/config/validate-prerender.d.ts +2 -0
  84. package/dist/compiler/config/validate-rollup-config.d.ts +2 -0
  85. package/dist/compiler/config/validate-service-worker.d.ts +2 -0
  86. package/dist/compiler/config/validate-testing.d.ts +2 -0
  87. package/dist/compiler/config/validate-workers.d.ts +2 -0
  88. package/dist/compiler/copy/assets-copy-tasks.d.ts +3 -0
  89. package/dist/compiler/copy/hashed-copy.d.ts +2 -0
  90. package/dist/compiler/copy/local-copy-tasks.d.ts +3 -0
  91. package/dist/compiler/docs/constants.d.ts +2 -0
  92. package/dist/compiler/docs/custom/index.d.ts +2 -0
  93. package/dist/compiler/docs/docs.d.ts +2 -0
  94. package/dist/compiler/docs/generate-doc-data.d.ts +3 -0
  95. package/dist/compiler/docs/json/index.d.ts +3 -0
  96. package/dist/compiler/docs/readme/docs-util.d.ts +13 -0
  97. package/dist/compiler/docs/readme/index.d.ts +3 -0
  98. package/dist/compiler/docs/readme/markdown-css-props.d.ts +2 -0
  99. package/dist/compiler/docs/readme/markdown-dependencies.d.ts +2 -0
  100. package/dist/compiler/docs/readme/markdown-events.d.ts +2 -0
  101. package/dist/compiler/docs/readme/markdown-methods.d.ts +2 -0
  102. package/dist/compiler/docs/readme/markdown-props.d.ts +2 -0
  103. package/dist/compiler/docs/readme/markdown-slots.d.ts +2 -0
  104. package/dist/compiler/docs/readme/markdown-usage.d.ts +6 -0
  105. package/dist/compiler/docs/readme/output-docs.d.ts +3 -0
  106. package/dist/compiler/docs/style-docs.d.ts +2 -0
  107. package/dist/compiler/docs/vscode/index.d.ts +2 -0
  108. package/dist/compiler/entries/component-bundles.d.ts +3 -0
  109. package/dist/compiler/entries/component-graph.d.ts +2 -0
  110. package/dist/compiler/entries/default-bundles.d.ts +3 -0
  111. package/dist/compiler/entries/entry-modules.d.ts +6 -0
  112. package/dist/compiler/entries/resolve-component-dependencies.d.ts +2 -0
  113. package/dist/compiler/events.d.ts +15 -0
  114. package/dist/compiler/fs-watch/fs-watch-init.d.ts +2 -0
  115. package/dist/compiler/fs-watch/fs-watch-log.d.ts +2 -0
  116. package/dist/compiler/fs-watch/fs-watch-rebuild.d.ts +7 -0
  117. package/dist/compiler/html/inject-module-preloads.d.ts +3 -0
  118. package/dist/compiler/html/inject-sw-script.d.ts +4 -0
  119. package/dist/compiler/html/inline-esm-import.d.ts +2 -0
  120. package/dist/compiler/html/inline-style-sheets.d.ts +2 -0
  121. package/dist/compiler/html/update-global-styles-link.d.ts +2 -0
  122. package/dist/compiler/html/used-components.d.ts +2 -0
  123. package/dist/compiler/html/utils.d.ts +2 -0
  124. package/dist/compiler/html/validate-manifest-json.d.ts +2 -0
  125. package/dist/compiler/index.d.ts +10 -0
  126. package/dist/compiler/index.js +18008 -0
  127. package/dist/compiler/output-targets/empty-dir.d.ts +6 -0
  128. package/dist/compiler/output-targets/index.d.ts +2 -0
  129. package/dist/compiler/output-targets/output-angular.d.ts +4 -0
  130. package/dist/compiler/output-targets/output-app.d.ts +4 -0
  131. package/dist/compiler/output-targets/output-collection.d.ts +3 -0
  132. package/dist/compiler/output-targets/output-copy.d.ts +2 -0
  133. package/dist/compiler/output-targets/output-custom.d.ts +2 -0
  134. package/dist/compiler/output-targets/output-docs.d.ts +2 -0
  135. package/dist/compiler/output-targets/output-hydrate.d.ts +2 -0
  136. package/dist/compiler/output-targets/output-lazy-loader.d.ts +2 -0
  137. package/dist/compiler/output-targets/output-module.d.ts +4 -0
  138. package/dist/compiler/output-targets/output-prerender.d.ts +2 -0
  139. package/dist/compiler/output-targets/output-service-workers.d.ts +2 -0
  140. package/dist/compiler/output-targets/output-types.d.ts +2 -0
  141. package/dist/compiler/output-targets/output-utils.d.ts +54 -0
  142. package/dist/compiler/output-targets/output-www.d.ts +2 -0
  143. package/dist/compiler/plugin/plugin.d.ts +6 -0
  144. package/dist/compiler/polyfills.d.ts +0 -0
  145. package/dist/compiler/prerender/crawl-urls.d.ts +3 -0
  146. package/dist/compiler/prerender/host-config.d.ts +12 -0
  147. package/dist/compiler/prerender/prerender-config.d.ts +2 -0
  148. package/dist/compiler/prerender/prerender-main.d.ts +2 -0
  149. package/dist/compiler/prerender/prerender-queue.d.ts +3 -0
  150. package/dist/compiler/prerender/prerender-template-html.d.ts +2 -0
  151. package/dist/compiler/prerender/prerendered-write-path.d.ts +2 -0
  152. package/dist/compiler/prerender/robots-txt.d.ts +2 -0
  153. package/dist/compiler/prerender/sitemap-xml.d.ts +3 -0
  154. package/dist/compiler/rollup-plugins/component-entry.d.ts +3 -0
  155. package/dist/compiler/rollup-plugins/css-transformer.d.ts +3 -0
  156. package/dist/compiler/rollup-plugins/global-scripts.d.ts +4 -0
  157. package/dist/compiler/rollup-plugins/image-plugin.d.ts +3 -0
  158. package/dist/compiler/rollup-plugins/in-memory-fs-read.d.ts +3 -0
  159. package/dist/compiler/rollup-plugins/loader.d.ts +4 -0
  160. package/dist/compiler/rollup-plugins/plugin-helper.d.ts +5 -0
  161. package/dist/compiler/rollup-plugins/rindo-build-conditionals.d.ts +7 -0
  162. package/dist/compiler/rollup-plugins/rindo-client.d.ts +3 -0
  163. package/dist/compiler/rollup-plugins/rindo-external-runtime.d.ts +2 -0
  164. package/dist/compiler/rollup-plugins/rindo-hydrate.d.ts +3 -0
  165. package/dist/compiler/rollup-plugins/rindo-public-plugin.d.ts +2 -0
  166. package/dist/compiler/service-worker/generate-sw.d.ts +7 -0
  167. package/dist/compiler/service-worker/service-worker-util.d.ts +2 -0
  168. package/dist/compiler/style/cached-styles.d.ts +5 -0
  169. package/dist/compiler/style/component-styles.d.ts +2 -0
  170. package/dist/compiler/style/css-imports.d.ts +9 -0
  171. package/dist/compiler/style/css-to-esm.d.ts +5 -0
  172. package/dist/compiler/style/generate-styles.d.ts +2 -0
  173. package/dist/compiler/style/global-styles.d.ts +3 -0
  174. package/dist/compiler/style/normalize-styles.d.ts +2 -0
  175. package/dist/compiler/style/optimize-css.d.ts +2 -0
  176. package/dist/compiler/style/scope-css.d.ts +3 -0
  177. package/dist/compiler/style/style-utils.d.ts +10 -0
  178. package/dist/compiler/transformers/add-component-meta-proxy.d.ts +3 -0
  179. package/dist/compiler/transformers/add-component-meta-static.d.ts +4 -0
  180. package/dist/compiler/transformers/add-imports.d.ts +3 -0
  181. package/dist/compiler/transformers/collections/add-external-import.d.ts +2 -0
  182. package/dist/compiler/transformers/collections/parse-collection-components.d.ts +2 -0
  183. package/dist/compiler/transformers/collections/parse-collection-deprecated.d.ts +2 -0
  184. package/dist/compiler/transformers/collections/parse-collection-manifest.d.ts +7 -0
  185. package/dist/compiler/transformers/collections/parse-collection-module.d.ts +2 -0
  186. package/dist/compiler/transformers/component-build-conditionals.d.ts +2 -0
  187. package/dist/compiler/transformers/component-hydrate/hydrate-component.d.ts +3 -0
  188. package/dist/compiler/transformers/component-hydrate/hydrate-runtime-cmp-meta.d.ts +3 -0
  189. package/dist/compiler/transformers/component-hydrate/tranform-to-hydrate-component.d.ts +2 -0
  190. package/dist/compiler/transformers/component-lazy/lazy-component.d.ts +3 -0
  191. package/dist/compiler/transformers/component-lazy/lazy-constructor.d.ts +3 -0
  192. package/dist/compiler/transformers/component-lazy/lazy-element-getter.d.ts +3 -0
  193. package/dist/compiler/transformers/component-lazy/transform-lazy-component.d.ts +4 -0
  194. package/dist/compiler/transformers/component-native/native-component.d.ts +3 -0
  195. package/dist/compiler/transformers/component-native/native-connected-callback.d.ts +3 -0
  196. package/dist/compiler/transformers/component-native/native-constructor.d.ts +3 -0
  197. package/dist/compiler/transformers/component-native/native-element-getter.d.ts +3 -0
  198. package/dist/compiler/transformers/component-native/native-static-style.d.ts +3 -0
  199. package/dist/compiler/transformers/component-native/tranform-to-native-component.d.ts +4 -0
  200. package/dist/compiler/transformers/core-runtime-apis.d.ts +30 -0
  201. package/dist/compiler/transformers/create-event.d.ts +3 -0
  202. package/dist/compiler/transformers/decorators-to-static/component-decorator.d.ts +3 -0
  203. package/dist/compiler/transformers/decorators-to-static/convert-decorators.d.ts +3 -0
  204. package/dist/compiler/transformers/decorators-to-static/decorator-utils.d.ts +10 -0
  205. package/dist/compiler/transformers/decorators-to-static/element-decorator.d.ts +3 -0
  206. package/dist/compiler/transformers/decorators-to-static/event-decorator.d.ts +4 -0
  207. package/dist/compiler/transformers/decorators-to-static/listen-decorator.d.ts +6 -0
  208. package/dist/compiler/transformers/decorators-to-static/method-decorator.d.ts +3 -0
  209. package/dist/compiler/transformers/decorators-to-static/prop-decorator.d.ts +4 -0
  210. package/dist/compiler/transformers/decorators-to-static/state-decorator.d.ts +3 -0
  211. package/dist/compiler/transformers/decorators-to-static/style-to-static.d.ts +3 -0
  212. package/dist/compiler/transformers/decorators-to-static/watch-decorator.d.ts +3 -0
  213. package/dist/compiler/transformers/define-custom-element.d.ts +3 -0
  214. package/dist/compiler/transformers/host-data-transform.d.ts +3 -0
  215. package/dist/compiler/transformers/legacy-props.d.ts +3 -0
  216. package/dist/compiler/transformers/remove-static-meta-properties.d.ts +2 -0
  217. package/dist/compiler/transformers/reserved-public-members.d.ts +3 -0
  218. package/dist/compiler/transformers/rindo-import-path.d.ts +3 -0
  219. package/dist/compiler/transformers/static-to-meta/call-expression.d.ts +3 -0
  220. package/dist/compiler/transformers/static-to-meta/class-methods.d.ts +3 -0
  221. package/dist/compiler/transformers/static-to-meta/component.d.ts +3 -0
  222. package/dist/compiler/transformers/static-to-meta/element-ref.d.ts +2 -0
  223. package/dist/compiler/transformers/static-to-meta/encapsulation.d.ts +3 -0
  224. package/dist/compiler/transformers/static-to-meta/events.d.ts +3 -0
  225. package/dist/compiler/transformers/static-to-meta/import.d.ts +3 -0
  226. package/dist/compiler/transformers/static-to-meta/listeners.d.ts +3 -0
  227. package/dist/compiler/transformers/static-to-meta/methods.d.ts +3 -0
  228. package/dist/compiler/transformers/static-to-meta/props.d.ts +3 -0
  229. package/dist/compiler/transformers/static-to-meta/states.d.ts +3 -0
  230. package/dist/compiler/transformers/static-to-meta/string-literal.d.ts +3 -0
  231. package/dist/compiler/transformers/static-to-meta/styles.d.ts +3 -0
  232. package/dist/compiler/transformers/static-to-meta/vdom.d.ts +3 -0
  233. package/dist/compiler/transformers/static-to-meta/visitor.d.ts +3 -0
  234. package/dist/compiler/transformers/static-to-meta/watchers.d.ts +3 -0
  235. package/dist/compiler/transformers/style-imports.d.ts +3 -0
  236. package/dist/compiler/transformers/transform-utils.d.ts +31 -0
  237. package/dist/compiler/transformers/update-component-class.d.ts +3 -0
  238. package/dist/compiler/transformers/update-rindo-core-import.d.ts +3 -0
  239. package/dist/compiler/transformers/watcher-meta-transform.d.ts +3 -0
  240. package/dist/compiler/transpile/compiler-options.d.ts +4 -0
  241. package/dist/compiler/transpile/transpile-app.d.ts +2 -0
  242. package/dist/compiler/transpile/transpile-module.d.ts +5 -0
  243. package/dist/compiler/transpile/transpile-service.d.ts +3 -0
  244. package/dist/compiler/transpile/transpile-to-es5-main.d.ts +2 -0
  245. package/dist/compiler/transpile/validate-types-main.d.ts +2 -0
  246. package/dist/compiler/types/generate-app-types.d.ts +2 -0
  247. package/dist/compiler/types/generate-component-types.d.ts +8 -0
  248. package/dist/compiler/types/generate-event-types.d.ts +2 -0
  249. package/dist/compiler/types/generate-method-types.d.ts +2 -0
  250. package/dist/compiler/types/generate-prop-types.d.ts +2 -0
  251. package/dist/compiler/types/generate-types.d.ts +2 -0
  252. package/dist/compiler/types/rindo-types.d.ts +3 -0
  253. package/dist/compiler/types/types-utils.d.ts +4 -0
  254. package/dist/compiler/types/update-import-refs.d.ts +11 -0
  255. package/dist/compiler/types/validate-package-json.d.ts +9 -0
  256. package/dist/declarations/assets.d.ts +17 -0
  257. package/dist/declarations/browser-compile.d.ts +47 -0
  258. package/dist/declarations/build-conditionals.d.ts +91 -0
  259. package/dist/declarations/build-events.d.ts +19 -0
  260. package/dist/declarations/build.d.ts +247 -0
  261. package/dist/declarations/cache.d.ts +11 -0
  262. package/dist/declarations/collection-manifest.d.ts +106 -0
  263. package/dist/declarations/collection.d.ts +139 -0
  264. package/dist/declarations/compiler.d.ts +53 -0
  265. package/dist/declarations/component-compiler-meta.d.ts +198 -0
  266. package/dist/declarations/component-constructor.d.ts +61 -0
  267. package/dist/declarations/component-interfaces.d.ts +123 -0
  268. package/dist/declarations/config.d.ts +409 -0
  269. package/dist/declarations/css-var-shim.d.ts +9 -0
  270. package/dist/declarations/decorators.d.ts +150 -0
  271. package/dist/declarations/dev-server.d.ts +135 -0
  272. package/dist/declarations/diagnostics.d.ts +21 -0
  273. package/dist/declarations/docs.d.ts +101 -0
  274. package/dist/declarations/entry.d.ts +28 -0
  275. package/dist/declarations/events.d.ts +13 -0
  276. package/dist/declarations/file-system.d.ts +91 -0
  277. package/dist/declarations/fs-watch.d.ts +15 -0
  278. package/dist/declarations/host-element.d.ts +53 -0
  279. package/dist/declarations/hydrate.d.ts +99 -0
  280. package/dist/declarations/in-memory-fs.d.ts +59 -0
  281. package/dist/declarations/index.d.ts +45 -0
  282. package/dist/declarations/jsdoc.d.ts +16 -0
  283. package/dist/declarations/jsx.d.ts +1050 -0
  284. package/dist/declarations/logger.d.ts +25 -0
  285. package/dist/declarations/minify-js.d.ts +11 -0
  286. package/dist/declarations/module.d.ts +35 -0
  287. package/dist/declarations/optimize-css.d.ts +12 -0
  288. package/dist/declarations/output-targets.d.ts +189 -0
  289. package/dist/declarations/plugin.d.ts +23 -0
  290. package/dist/declarations/prerender.d.ts +79 -0
  291. package/dist/declarations/render.d.ts +62 -0
  292. package/dist/declarations/runtime.d.ts +92 -0
  293. package/dist/declarations/screenshots.d.ts +192 -0
  294. package/dist/declarations/server.d.ts +19 -0
  295. package/dist/declarations/style.d.ts +35 -0
  296. package/dist/declarations/system.d.ts +174 -0
  297. package/dist/declarations/testing.d.ts +523 -0
  298. package/dist/declarations/transpile.d.ts +24 -0
  299. package/dist/declarations/types.d.ts +24 -0
  300. package/dist/declarations/vdom.d.ts +55 -0
  301. package/dist/declarations/worker.d.ts +33 -0
  302. package/dist/dev-server/content-type-db.json +1 -0
  303. package/dist/dev-server/index.js +887 -0
  304. package/dist/dev-server/static/app-error.css +257 -0
  305. package/dist/dev-server/static/dev-server-client.html +13 -0
  306. package/dist/dev-server/static/favicon.ico +0 -0
  307. package/dist/dev-server/templates/directory-index.html +132 -0
  308. package/dist/dev-server/templates/initial-load.html +160 -0
  309. package/dist/hydrate/index.d.ts +101 -0
  310. package/dist/hydrate/index.mjs +1281 -0
  311. package/dist/hydrate/platform.mjs +347 -0
  312. package/dist/index.d.ts +99 -0
  313. package/dist/index.js +1 -0
  314. package/dist/mock-doc/index.d.ts +851 -0
  315. package/dist/mock-doc/index.js +3982 -0
  316. package/dist/mock-doc/index.mjs +3954 -0
  317. package/dist/runtime/index.js +2576 -0
  318. package/dist/runtime/index.mjs +2521 -0
  319. package/dist/runtime/shadow-css-6ef31c68.js +386 -0
  320. package/dist/runtime/shadow-css-8fd1a9e4.js +388 -0
  321. package/dist/screenshot/connector-base.d.ts +42 -0
  322. package/dist/screenshot/connector-local.d.ts +7 -0
  323. package/dist/screenshot/index.d.ts +3 -0
  324. package/dist/screenshot/index.js +520 -0
  325. package/dist/screenshot/pixel-match.d.ts +1 -0
  326. package/dist/screenshot/screenshot-fs.d.ts +15 -0
  327. package/dist/sys/node/graceful-fs.js +975 -0
  328. package/dist/sys/node/index.js +33545 -0
  329. package/dist/sys/node/node-fetch.js +1779 -0
  330. package/dist/sys/node/open-in-editor.js +734 -0
  331. package/dist/sys/node/sys-worker.js +67035 -0
  332. package/dist/sys/node/visualstudio.vbs +82 -0
  333. package/dist/sys/node/websocket.js +3728 -0
  334. package/dist/sys/node/xdg-open +1066 -0
  335. package/dist/testing/build-conditionals.d.ts +4 -0
  336. package/dist/testing/build-conditionals.js +43 -0
  337. package/dist/testing/core.d.ts +35 -0
  338. package/dist/testing/core.js +52 -0
  339. package/dist/testing/index.d.ts +13 -0
  340. package/dist/testing/index.js +40511 -0
  341. package/dist/testing/jest/jest-config.d.ts +4 -0
  342. package/dist/testing/jest/jest-environment.d.ts +12 -0
  343. package/dist/testing/jest/jest-preprocessor.d.ts +10 -0
  344. package/dist/testing/jest/jest-runner.d.ts +5 -0
  345. package/dist/testing/jest/jest-screenshot.d.ts +2 -0
  346. package/dist/testing/jest/jest-serializer.d.ts +5 -0
  347. package/dist/testing/jest/jest-setup-test-framework.d.ts +1 -0
  348. package/dist/testing/matchers/attributes.d.ts +14 -0
  349. package/dist/testing/matchers/class-list.d.ts +12 -0
  350. package/dist/testing/matchers/events.d.ts +13 -0
  351. package/dist/testing/matchers/html.d.ts +12 -0
  352. package/dist/testing/matchers/index.d.ts +21 -0
  353. package/dist/testing/matchers/screenshot.d.ts +5 -0
  354. package/dist/testing/matchers/text.d.ts +4 -0
  355. package/dist/testing/mock-fetch.d.ts +46 -0
  356. package/dist/testing/mocks.d.ts +12 -0
  357. package/dist/testing/platform.d.ts +23 -0
  358. package/dist/testing/platform.js +321 -0
  359. package/dist/testing/puppeteer/puppeteer-browser.d.ts +6 -0
  360. package/dist/testing/puppeteer/puppeteer-declarations.d.ts +396 -0
  361. package/dist/testing/puppeteer/puppeteer-element.d.ts +65 -0
  362. package/dist/testing/puppeteer/puppeteer-emulate.d.ts +2 -0
  363. package/dist/testing/puppeteer/puppeteer-events.d.ts +21 -0
  364. package/dist/testing/puppeteer/puppeteer-find.d.ts +5 -0
  365. package/dist/testing/puppeteer/puppeteer-page.d.ts +2 -0
  366. package/dist/testing/puppeteer/puppeteer-screenshot.d.ts +4 -0
  367. package/dist/testing/spec-page.d.ts +5 -0
  368. package/dist/testing/task-queue.d.ts +15 -0
  369. package/dist/testing/test-transpile.d.ts +5 -0
  370. package/dist/testing/testing-fs.d.ts +31 -0
  371. package/dist/testing/testing-logger.d.ts +23 -0
  372. package/dist/testing/testing-sys.d.ts +19 -0
  373. package/dist/testing/testing-utils.d.ts +5 -0
  374. package/dist/testing/testing.d.ts +12 -0
  375. package/dist/utils/index.js +1575 -0
  376. package/dist/utils/index.mjs +1511 -0
  377. package/internal/client/build-conditionals.mjs +82 -0
  378. package/internal/client/css-shim.rindo-client.mjs +656 -0
  379. package/internal/client/dom.rindo-client.mjs +137 -0
  380. package/internal/client/index.mjs +2859 -0
  381. package/internal/client/polyfills/core-js.js +10 -0
  382. package/internal/client/polyfills/css-shim.js +656 -0
  383. package/internal/client/polyfills/dom.js +146 -0
  384. package/internal/client/polyfills/es5-html-element.js +18 -0
  385. package/internal/client/polyfills/index.js +35 -0
  386. package/internal/client/polyfills/promise.js +9 -0
  387. package/internal/client/polyfills/system.js +6 -0
  388. package/internal/client/shadow-css.rindo-client.mjs +386 -0
  389. package/internal/images.d.ts +5 -0
  390. package/internal/index.d.ts +18 -0
  391. package/internal/index.js +1 -0
  392. package/internal/package.json +6 -0
  393. package/mock-doc/index.js +2 -0
  394. package/mock-doc/package.json +10 -0
  395. package/package.json +186 -0
  396. package/readme.md +174 -0
  397. package/runtime/package.json +5 -0
  398. package/screenshot/compare/assets/favicon.ico +0 -0
  399. package/screenshot/compare/assets/logo.png +0 -0
  400. package/screenshot/compare/build/app.css +1 -0
  401. package/screenshot/compare/build/app.esm.js +1 -0
  402. package/screenshot/compare/build/app.js +818 -0
  403. package/screenshot/compare/build/p-020f8d73.js +1 -0
  404. package/screenshot/compare/build/p-09qdknbg.system.entry.js +1 -0
  405. package/screenshot/compare/build/p-0a13mpsc.system.entry.js +1 -0
  406. package/screenshot/compare/build/p-113f7459.js +1 -0
  407. package/screenshot/compare/build/p-168ec2c4.system.js +1 -0
  408. package/screenshot/compare/build/p-2ab1fdf1.system.js +1 -0
  409. package/screenshot/compare/build/p-2pxcsgrj.entry.js +1 -0
  410. package/screenshot/compare/build/p-42fb7034.system.js +1 -0
  411. package/screenshot/compare/build/p-54d9d7c2.system.js +1 -0
  412. package/screenshot/compare/build/p-67c1f911.js +1 -0
  413. package/screenshot/compare/build/p-68613371.system.js +1 -0
  414. package/screenshot/compare/build/p-7dvsjpu0.entry.js +1 -0
  415. package/screenshot/compare/build/p-aa67fb06.js +1 -0
  416. package/screenshot/compare/build/p-aeb3cec1.system.js +1 -0
  417. package/screenshot/compare/build/p-b6e44a24.js +1 -0
  418. package/screenshot/compare/build/p-c1c25b8a.js +1 -0
  419. package/screenshot/compare/build/p-c9bopbjy.system.entry.js +1 -0
  420. package/screenshot/compare/build/p-c9iqz1pp.system.entry.js +1 -0
  421. package/screenshot/compare/build/p-dizjz8rg.entry.js +1 -0
  422. package/screenshot/compare/build/p-dnta0rwp.system.entry.js +1 -0
  423. package/screenshot/compare/build/p-e9670d22.system.js +1 -0
  424. package/screenshot/compare/build/p-efb0eac6.js +1 -0
  425. package/screenshot/compare/build/p-ei9jkpd0.system.entry.js +1 -0
  426. package/screenshot/compare/build/p-ejpsp3kx.js +1 -0
  427. package/screenshot/compare/build/p-ejwcppol.entry.js +1 -0
  428. package/screenshot/compare/build/p-f6612d5d.system.js +1 -0
  429. package/screenshot/compare/build/p-foiivsfc.css +1 -0
  430. package/screenshot/compare/build/p-gpjjyogx.entry.js +1 -0
  431. package/screenshot/compare/build/p-howklem2.system.entry.js +1 -0
  432. package/screenshot/compare/build/p-knv9wvoc.entry.js +1 -0
  433. package/screenshot/compare/build/p-nsqsfhhy.entry.js +1 -0
  434. package/screenshot/compare/build/p-ojt278pp.entry.js +1 -0
  435. package/screenshot/compare/build/p-oywass99.entry.js +1 -0
  436. package/screenshot/compare/build/p-q3ujhub6.entry.js +1 -0
  437. package/screenshot/compare/build/p-qw4xnmxv.entry.js +1 -0
  438. package/screenshot/compare/build/p-t1wvevhc.system.entry.js +1 -0
  439. package/screenshot/compare/build/p-tnjarrex.system.entry.js +1 -0
  440. package/screenshot/compare/build/p-vhfpd6kk.system.entry.js +1 -0
  441. package/screenshot/compare/build/p-vk6rhemd.system.entry.js +1 -0
  442. package/screenshot/compare/build/p-w6bnm16k.entry.js +1 -0
  443. package/screenshot/compare/build/p-xje6d7zl.system.entry.js +1 -0
  444. package/screenshot/compare/build/p-y5jlrcha.system.entry.js +1 -0
  445. package/screenshot/compare/build/p-yh170wkt.entry.js +1 -0
  446. package/screenshot/compare/host.config.json +15 -0
  447. package/screenshot/compare/index.html +1 -0
  448. package/screenshot/compare/manifest.json +13 -0
  449. package/screenshot/connector.js +3 -0
  450. package/screenshot/index.js +2 -0
  451. package/screenshot/local-connector.js +3 -0
  452. package/screenshot/package.json +13 -0
  453. package/screenshot/pixel-match.js +2660 -0
  454. package/sys/node/index.js +2 -0
  455. package/sys/node/package.json +5 -0
  456. package/testing/index.js +2 -0
  457. package/testing/jest-environment.js +3 -0
  458. package/testing/jest-preprocessor.js +3 -0
  459. package/testing/jest-preset.js +40 -0
  460. package/testing/jest-runner.js +3 -0
  461. package/testing/jest-setuptestframework.js +3 -0
  462. package/testing/jest.preprocessor.js +7 -0
  463. package/testing/package.json +6 -0
@@ -0,0 +1,2660 @@
1
+ 'use strict';
2
+
3
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
4
+
5
+ var fs = _interopDefault(require('../dist/sys/node/graceful-fs.js'));
6
+ var util = _interopDefault(require('util'));
7
+ var stream = _interopDefault(require('stream'));
8
+ var zlib = _interopDefault(require('zlib'));
9
+ var assert = _interopDefault(require('assert'));
10
+ var buffer = _interopDefault(require('buffer'));
11
+
12
+ var pixelmatch_1 = pixelmatch;
13
+
14
+ function pixelmatch(img1, img2, output, width, height, options) {
15
+
16
+ if (!options) options = {};
17
+
18
+ var threshold = options.threshold === undefined ? 0.1 : options.threshold;
19
+
20
+ // maximum acceptable square distance between two colors;
21
+ // 35215 is the maximum possible value for the YIQ difference metric
22
+ var maxDelta = 35215 * threshold * threshold,
23
+ diff = 0;
24
+
25
+ // compare each pixel of one image against the other one
26
+ for (var y = 0; y < height; y++) {
27
+ for (var x = 0; x < width; x++) {
28
+
29
+ var pos = (y * width + x) * 4;
30
+
31
+ // squared YUV distance between colors at this pixel position
32
+ var delta = colorDelta(img1, img2, pos, pos);
33
+
34
+ // the color difference is above the threshold
35
+ if (delta > maxDelta) {
36
+ // check it's a real rendering difference or just anti-aliasing
37
+ if (!options.includeAA && (antialiased(img1, x, y, width, height, img2) ||
38
+ antialiased(img2, x, y, width, height, img1))) {
39
+ // one of the pixels is anti-aliasing; draw as yellow and do not count as difference
40
+ if (output) drawPixel(output, pos, 255, 255, 0);
41
+
42
+ } else {
43
+ // found substantial difference not caused by anti-aliasing; draw it as red
44
+ if (output) drawPixel(output, pos, 255, 0, 0);
45
+ diff++;
46
+ }
47
+
48
+ } else if (output) {
49
+ // pixels are similar; draw background as grayscale image blended with white
50
+ var val = blend(grayPixel(img1, pos), 0.1);
51
+ drawPixel(output, pos, val, val, val);
52
+ }
53
+ }
54
+ }
55
+
56
+ // return the number of different pixels
57
+ return diff;
58
+ }
59
+
60
+ // check if a pixel is likely a part of anti-aliasing;
61
+ // based on "Anti-aliased Pixel and Intensity Slope Detector" paper by V. Vysniauskas, 2009
62
+
63
+ function antialiased(img, x1, y1, width, height, img2) {
64
+ var x0 = Math.max(x1 - 1, 0),
65
+ y0 = Math.max(y1 - 1, 0),
66
+ x2 = Math.min(x1 + 1, width - 1),
67
+ y2 = Math.min(y1 + 1, height - 1),
68
+ pos = (y1 * width + x1) * 4,
69
+ zeroes = 0,
70
+ positives = 0,
71
+ negatives = 0,
72
+ min = 0,
73
+ max = 0,
74
+ minX, minY, maxX, maxY;
75
+
76
+ // go through 8 adjacent pixels
77
+ for (var x = x0; x <= x2; x++) {
78
+ for (var y = y0; y <= y2; y++) {
79
+ if (x === x1 && y === y1) continue;
80
+
81
+ // brightness delta between the center pixel and adjacent one
82
+ var delta = colorDelta(img, img, pos, (y * width + x) * 4, true);
83
+
84
+ // count the number of equal, darker and brighter adjacent pixels
85
+ if (delta === 0) zeroes++;
86
+ else if (delta < 0) negatives++;
87
+ else if (delta > 0) positives++;
88
+
89
+ // if found more than 2 equal siblings, it's definitely not anti-aliasing
90
+ if (zeroes > 2) return false;
91
+
92
+ if (!img2) continue;
93
+
94
+ // remember the darkest pixel
95
+ if (delta < min) {
96
+ min = delta;
97
+ minX = x;
98
+ minY = y;
99
+ }
100
+ // remember the brightest pixel
101
+ if (delta > max) {
102
+ max = delta;
103
+ maxX = x;
104
+ maxY = y;
105
+ }
106
+ }
107
+ }
108
+
109
+ if (!img2) return true;
110
+
111
+ // if there are no both darker and brighter pixels among siblings, it's not anti-aliasing
112
+ if (negatives === 0 || positives === 0) return false;
113
+
114
+ // if either the darkest or the brightest pixel has more than 2 equal siblings in both images
115
+ // (definitely not anti-aliased), this pixel is anti-aliased
116
+ return (!antialiased(img, minX, minY, width, height) && !antialiased(img2, minX, minY, width, height)) ||
117
+ (!antialiased(img, maxX, maxY, width, height) && !antialiased(img2, maxX, maxY, width, height));
118
+ }
119
+
120
+ // calculate color difference according to the paper "Measuring perceived color difference
121
+ // using YIQ NTSC transmission color space in mobile applications" by Y. Kotsarenko and F. Ramos
122
+
123
+ function colorDelta(img1, img2, k, m, yOnly) {
124
+ var a1 = img1[k + 3] / 255,
125
+ a2 = img2[m + 3] / 255,
126
+
127
+ r1 = blend(img1[k + 0], a1),
128
+ g1 = blend(img1[k + 1], a1),
129
+ b1 = blend(img1[k + 2], a1),
130
+
131
+ r2 = blend(img2[m + 0], a2),
132
+ g2 = blend(img2[m + 1], a2),
133
+ b2 = blend(img2[m + 2], a2),
134
+
135
+ y = rgb2y(r1, g1, b1) - rgb2y(r2, g2, b2);
136
+
137
+ if (yOnly) return y; // brightness difference only
138
+
139
+ var i = rgb2i(r1, g1, b1) - rgb2i(r2, g2, b2),
140
+ q = rgb2q(r1, g1, b1) - rgb2q(r2, g2, b2);
141
+
142
+ return 0.5053 * y * y + 0.299 * i * i + 0.1957 * q * q;
143
+ }
144
+
145
+ function rgb2y(r, g, b) { return r * 0.29889531 + g * 0.58662247 + b * 0.11448223; }
146
+ function rgb2i(r, g, b) { return r * 0.59597799 - g * 0.27417610 - b * 0.32180189; }
147
+ function rgb2q(r, g, b) { return r * 0.21147017 - g * 0.52261711 + b * 0.31114694; }
148
+
149
+ // blend semi-transparent color with white
150
+ function blend(c, a) {
151
+ return 255 + (c - 255) * a;
152
+ }
153
+
154
+ function drawPixel(output, pos, r, g, b) {
155
+ output[pos + 0] = r;
156
+ output[pos + 1] = g;
157
+ output[pos + 2] = b;
158
+ output[pos + 3] = 255;
159
+ }
160
+
161
+ function grayPixel(img, i) {
162
+ var a = img[i + 3] / 255,
163
+ r = blend(img[i + 0], a),
164
+ g = blend(img[i + 1], a),
165
+ b = blend(img[i + 2], a);
166
+ return rgb2y(r, g, b);
167
+ }
168
+
169
+ function createCommonjsModule(fn, module) {
170
+ return module = { exports: {} }, fn(module, module.exports), module.exports;
171
+ }
172
+
173
+ var chunkstream = createCommonjsModule(function (module) {
174
+
175
+
176
+
177
+
178
+
179
+
180
+ var ChunkStream = module.exports = function() {
181
+ stream.call(this);
182
+
183
+ this._buffers = [];
184
+ this._buffered = 0;
185
+
186
+ this._reads = [];
187
+ this._paused = false;
188
+
189
+ this._encoding = 'utf8';
190
+ this.writable = true;
191
+ };
192
+ util.inherits(ChunkStream, stream);
193
+
194
+
195
+ ChunkStream.prototype.read = function(length, callback) {
196
+
197
+ this._reads.push({
198
+ length: Math.abs(length), // if length < 0 then at most this length
199
+ allowLess: length < 0,
200
+ func: callback
201
+ });
202
+
203
+ process.nextTick(function() {
204
+ this._process();
205
+
206
+ // its paused and there is not enought data then ask for more
207
+ if (this._paused && this._reads.length > 0) {
208
+ this._paused = false;
209
+
210
+ this.emit('drain');
211
+ }
212
+ }.bind(this));
213
+ };
214
+
215
+ ChunkStream.prototype.write = function(data, encoding) {
216
+
217
+ if (!this.writable) {
218
+ this.emit('error', new Error('Stream not writable'));
219
+ return false;
220
+ }
221
+
222
+ var dataBuffer;
223
+ if (Buffer.isBuffer(data)) {
224
+ dataBuffer = data;
225
+ }
226
+ else {
227
+ dataBuffer = new Buffer(data, encoding || this._encoding);
228
+ }
229
+
230
+ this._buffers.push(dataBuffer);
231
+ this._buffered += dataBuffer.length;
232
+
233
+ this._process();
234
+
235
+ // ok if there are no more read requests
236
+ if (this._reads && this._reads.length === 0) {
237
+ this._paused = true;
238
+ }
239
+
240
+ return this.writable && !this._paused;
241
+ };
242
+
243
+ ChunkStream.prototype.end = function(data, encoding) {
244
+
245
+ if (data) {
246
+ this.write(data, encoding);
247
+ }
248
+
249
+ this.writable = false;
250
+
251
+ // already destroyed
252
+ if (!this._buffers) {
253
+ return;
254
+ }
255
+
256
+ // enqueue or handle end
257
+ if (this._buffers.length === 0) {
258
+ this._end();
259
+ }
260
+ else {
261
+ this._buffers.push(null);
262
+ this._process();
263
+ }
264
+ };
265
+
266
+ ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
267
+
268
+ ChunkStream.prototype._end = function() {
269
+
270
+ if (this._reads.length > 0) {
271
+ this.emit('error',
272
+ new Error('Unexpected end of input')
273
+ );
274
+ }
275
+
276
+ this.destroy();
277
+ };
278
+
279
+ ChunkStream.prototype.destroy = function() {
280
+
281
+ if (!this._buffers) {
282
+ return;
283
+ }
284
+
285
+ this.writable = false;
286
+ this._reads = null;
287
+ this._buffers = null;
288
+
289
+ this.emit('close');
290
+ };
291
+
292
+ ChunkStream.prototype._processReadAllowingLess = function(read) {
293
+ // ok there is any data so that we can satisfy this request
294
+ this._reads.shift(); // == read
295
+
296
+ // first we need to peek into first buffer
297
+ var smallerBuf = this._buffers[0];
298
+
299
+ // ok there is more data than we need
300
+ if (smallerBuf.length > read.length) {
301
+
302
+ this._buffered -= read.length;
303
+ this._buffers[0] = smallerBuf.slice(read.length);
304
+
305
+ read.func.call(this, smallerBuf.slice(0, read.length));
306
+
307
+ }
308
+ else {
309
+ // ok this is less than maximum length so use it all
310
+ this._buffered -= smallerBuf.length;
311
+ this._buffers.shift(); // == smallerBuf
312
+
313
+ read.func.call(this, smallerBuf);
314
+ }
315
+ };
316
+
317
+ ChunkStream.prototype._processRead = function(read) {
318
+ this._reads.shift(); // == read
319
+
320
+ var pos = 0;
321
+ var count = 0;
322
+ var data = new Buffer(read.length);
323
+
324
+ // create buffer for all data
325
+ while (pos < read.length) {
326
+
327
+ var buf = this._buffers[count++];
328
+ var len = Math.min(buf.length, read.length - pos);
329
+
330
+ buf.copy(data, pos, 0, len);
331
+ pos += len;
332
+
333
+ // last buffer wasn't used all so just slice it and leave
334
+ if (len !== buf.length) {
335
+ this._buffers[--count] = buf.slice(len);
336
+ }
337
+ }
338
+
339
+ // remove all used buffers
340
+ if (count > 0) {
341
+ this._buffers.splice(0, count);
342
+ }
343
+
344
+ this._buffered -= read.length;
345
+
346
+ read.func.call(this, data);
347
+ };
348
+
349
+ ChunkStream.prototype._process = function() {
350
+
351
+ try {
352
+ // as long as there is any data and read requests
353
+ while (this._buffered > 0 && this._reads && this._reads.length > 0) {
354
+
355
+ var read = this._reads[0];
356
+
357
+ // read any data (but no more than length)
358
+ if (read.allowLess) {
359
+ this._processReadAllowingLess(read);
360
+
361
+ }
362
+ else if (this._buffered >= read.length) {
363
+ // ok we can meet some expectations
364
+
365
+ this._processRead(read);
366
+ }
367
+ else {
368
+ // not enought data to satisfy first request in queue
369
+ // so we need to wait for more
370
+ break;
371
+ }
372
+ }
373
+
374
+ if (this._buffers && !this.writable) {
375
+ this._end();
376
+ }
377
+ }
378
+ catch (ex) {
379
+ this.emit('error', ex);
380
+ }
381
+ };
382
+ });
383
+
384
+ // Adam 7
385
+ // 0 1 2 3 4 5 6 7
386
+ // 0 x 6 4 6 x 6 4 6
387
+ // 1 7 7 7 7 7 7 7 7
388
+ // 2 5 6 5 6 5 6 5 6
389
+ // 3 7 7 7 7 7 7 7 7
390
+ // 4 3 6 4 6 3 6 4 6
391
+ // 5 7 7 7 7 7 7 7 7
392
+ // 6 5 6 5 6 5 6 5 6
393
+ // 7 7 7 7 7 7 7 7 7
394
+
395
+
396
+ var imagePasses = [
397
+ { // pass 1 - 1px
398
+ x: [0],
399
+ y: [0]
400
+ },
401
+ { // pass 2 - 1px
402
+ x: [4],
403
+ y: [0]
404
+ },
405
+ { // pass 3 - 2px
406
+ x: [0, 4],
407
+ y: [4]
408
+ },
409
+ { // pass 4 - 4px
410
+ x: [2, 6],
411
+ y: [0, 4]
412
+ },
413
+ { // pass 5 - 8px
414
+ x: [0, 2, 4, 6],
415
+ y: [2, 6]
416
+ },
417
+ { // pass 6 - 16px
418
+ x: [1, 3, 5, 7],
419
+ y: [0, 2, 4, 6]
420
+ },
421
+ { // pass 7 - 32px
422
+ x: [0, 1, 2, 3, 4, 5, 6, 7],
423
+ y: [1, 3, 5, 7]
424
+ }
425
+ ];
426
+
427
+ var getImagePasses = function(width, height) {
428
+ var images = [];
429
+ var xLeftOver = width % 8;
430
+ var yLeftOver = height % 8;
431
+ var xRepeats = (width - xLeftOver) / 8;
432
+ var yRepeats = (height - yLeftOver) / 8;
433
+ for (var i = 0; i < imagePasses.length; i++) {
434
+ var pass = imagePasses[i];
435
+ var passWidth = xRepeats * pass.x.length;
436
+ var passHeight = yRepeats * pass.y.length;
437
+ for (var j = 0; j < pass.x.length; j++) {
438
+ if (pass.x[j] < xLeftOver) {
439
+ passWidth++;
440
+ }
441
+ else {
442
+ break;
443
+ }
444
+ }
445
+ for (j = 0; j < pass.y.length; j++) {
446
+ if (pass.y[j] < yLeftOver) {
447
+ passHeight++;
448
+ }
449
+ else {
450
+ break;
451
+ }
452
+ }
453
+ if (passWidth > 0 && passHeight > 0) {
454
+ images.push({ width: passWidth, height: passHeight, index: i });
455
+ }
456
+ }
457
+ return images;
458
+ };
459
+
460
+ var getInterlaceIterator = function(width) {
461
+ return function(x, y, pass) {
462
+ var outerXLeftOver = x % imagePasses[pass].x.length;
463
+ var outerX = (((x - outerXLeftOver) / imagePasses[pass].x.length) * 8) + imagePasses[pass].x[outerXLeftOver];
464
+ var outerYLeftOver = y % imagePasses[pass].y.length;
465
+ var outerY = (((y - outerYLeftOver) / imagePasses[pass].y.length) * 8) + imagePasses[pass].y[outerYLeftOver];
466
+ return (outerX * 4) + (outerY * width * 4);
467
+ };
468
+ };
469
+
470
+ var interlace = {
471
+ getImagePasses: getImagePasses,
472
+ getInterlaceIterator: getInterlaceIterator
473
+ };
474
+
475
+ var paethPredictor = function paethPredictor(left, above, upLeft) {
476
+
477
+ var paeth = left + above - upLeft;
478
+ var pLeft = Math.abs(paeth - left);
479
+ var pAbove = Math.abs(paeth - above);
480
+ var pUpLeft = Math.abs(paeth - upLeft);
481
+
482
+ if (pLeft <= pAbove && pLeft <= pUpLeft) {
483
+ return left;
484
+ }
485
+ if (pAbove <= pUpLeft) {
486
+ return above;
487
+ }
488
+ return upLeft;
489
+ };
490
+
491
+ var filterParse = createCommonjsModule(function (module) {
492
+
493
+
494
+
495
+
496
+ function getByteWidth(width, bpp, depth) {
497
+ var byteWidth = width * bpp;
498
+ if (depth !== 8) {
499
+ byteWidth = Math.ceil(byteWidth / (8 / depth));
500
+ }
501
+ return byteWidth;
502
+ }
503
+
504
+ var Filter = module.exports = function(bitmapInfo, dependencies) {
505
+
506
+ var width = bitmapInfo.width;
507
+ var height = bitmapInfo.height;
508
+ var interlace$1 = bitmapInfo.interlace;
509
+ var bpp = bitmapInfo.bpp;
510
+ var depth = bitmapInfo.depth;
511
+
512
+ this.read = dependencies.read;
513
+ this.write = dependencies.write;
514
+ this.complete = dependencies.complete;
515
+
516
+ this._imageIndex = 0;
517
+ this._images = [];
518
+ if (interlace$1) {
519
+ var passes = interlace.getImagePasses(width, height);
520
+ for (var i = 0; i < passes.length; i++) {
521
+ this._images.push({
522
+ byteWidth: getByteWidth(passes[i].width, bpp, depth),
523
+ height: passes[i].height,
524
+ lineIndex: 0
525
+ });
526
+ }
527
+ }
528
+ else {
529
+ this._images.push({
530
+ byteWidth: getByteWidth(width, bpp, depth),
531
+ height: height,
532
+ lineIndex: 0
533
+ });
534
+ }
535
+
536
+ // when filtering the line we look at the pixel to the left
537
+ // the spec also says it is done on a byte level regardless of the number of pixels
538
+ // so if the depth is byte compatible (8 or 16) we subtract the bpp in order to compare back
539
+ // a pixel rather than just a different byte part. However if we are sub byte, we ignore.
540
+ if (depth === 8) {
541
+ this._xComparison = bpp;
542
+ }
543
+ else if (depth === 16) {
544
+ this._xComparison = bpp * 2;
545
+ }
546
+ else {
547
+ this._xComparison = 1;
548
+ }
549
+ };
550
+
551
+ Filter.prototype.start = function() {
552
+ this.read(this._images[this._imageIndex].byteWidth + 1, this._reverseFilterLine.bind(this));
553
+ };
554
+
555
+ Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
556
+
557
+ var xComparison = this._xComparison;
558
+ var xBiggerThan = xComparison - 1;
559
+
560
+ for (var x = 0; x < byteWidth; x++) {
561
+ var rawByte = rawData[1 + x];
562
+ var f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
563
+ unfilteredLine[x] = rawByte + f1Left;
564
+ }
565
+ };
566
+
567
+ Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
568
+
569
+ var lastLine = this._lastLine;
570
+
571
+ for (var x = 0; x < byteWidth; x++) {
572
+ var rawByte = rawData[1 + x];
573
+ var f2Up = lastLine ? lastLine[x] : 0;
574
+ unfilteredLine[x] = rawByte + f2Up;
575
+ }
576
+ };
577
+
578
+ Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
579
+
580
+ var xComparison = this._xComparison;
581
+ var xBiggerThan = xComparison - 1;
582
+ var lastLine = this._lastLine;
583
+
584
+ for (var x = 0; x < byteWidth; x++) {
585
+ var rawByte = rawData[1 + x];
586
+ var f3Up = lastLine ? lastLine[x] : 0;
587
+ var f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
588
+ var f3Add = Math.floor((f3Left + f3Up) / 2);
589
+ unfilteredLine[x] = rawByte + f3Add;
590
+ }
591
+ };
592
+
593
+ Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
594
+
595
+ var xComparison = this._xComparison;
596
+ var xBiggerThan = xComparison - 1;
597
+ var lastLine = this._lastLine;
598
+
599
+ for (var x = 0; x < byteWidth; x++) {
600
+ var rawByte = rawData[1 + x];
601
+ var f4Up = lastLine ? lastLine[x] : 0;
602
+ var f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
603
+ var f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
604
+ var f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
605
+ unfilteredLine[x] = rawByte + f4Add;
606
+ }
607
+ };
608
+
609
+ Filter.prototype._reverseFilterLine = function(rawData) {
610
+
611
+ var filter = rawData[0];
612
+ var unfilteredLine;
613
+ var currentImage = this._images[this._imageIndex];
614
+ var byteWidth = currentImage.byteWidth;
615
+
616
+ if (filter === 0) {
617
+ unfilteredLine = rawData.slice(1, byteWidth + 1);
618
+ }
619
+ else {
620
+
621
+ unfilteredLine = new Buffer(byteWidth);
622
+
623
+ switch (filter) {
624
+ case 1:
625
+ this._unFilterType1(rawData, unfilteredLine, byteWidth);
626
+ break;
627
+ case 2:
628
+ this._unFilterType2(rawData, unfilteredLine, byteWidth);
629
+ break;
630
+ case 3:
631
+ this._unFilterType3(rawData, unfilteredLine, byteWidth);
632
+ break;
633
+ case 4:
634
+ this._unFilterType4(rawData, unfilteredLine, byteWidth);
635
+ break;
636
+ default:
637
+ throw new Error('Unrecognised filter type - ' + filter);
638
+ }
639
+ }
640
+
641
+ this.write(unfilteredLine);
642
+
643
+ currentImage.lineIndex++;
644
+ if (currentImage.lineIndex >= currentImage.height) {
645
+ this._lastLine = null;
646
+ this._imageIndex++;
647
+ currentImage = this._images[this._imageIndex];
648
+ }
649
+ else {
650
+ this._lastLine = unfilteredLine;
651
+ }
652
+
653
+ if (currentImage) {
654
+ // read, using the byte width that may be from the new current image
655
+ this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
656
+ }
657
+ else {
658
+ this._lastLine = null;
659
+ this.complete();
660
+ }
661
+ };
662
+ });
663
+
664
+ var filterParseAsync = createCommonjsModule(function (module) {
665
+
666
+
667
+
668
+
669
+
670
+
671
+ var FilterAsync = module.exports = function(bitmapInfo) {
672
+ chunkstream.call(this);
673
+
674
+ var buffers = [];
675
+ var that = this;
676
+ this._filter = new filterParse(bitmapInfo, {
677
+ read: this.read.bind(this),
678
+ write: function(buffer) {
679
+ buffers.push(buffer);
680
+ },
681
+ complete: function() {
682
+ that.emit('complete', Buffer.concat(buffers));
683
+ }
684
+ });
685
+
686
+ this._filter.start();
687
+ };
688
+ util.inherits(FilterAsync, chunkstream);
689
+ });
690
+
691
+ var constants = {
692
+
693
+ PNG_SIGNATURE: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a],
694
+
695
+ TYPE_IHDR: 0x49484452,
696
+ TYPE_IEND: 0x49454e44,
697
+ TYPE_IDAT: 0x49444154,
698
+ TYPE_PLTE: 0x504c5445,
699
+ TYPE_tRNS: 0x74524e53, // eslint-disable-line camelcase
700
+ TYPE_gAMA: 0x67414d41, // eslint-disable-line camelcase
701
+
702
+ // color-type bits
703
+ COLORTYPE_GRAYSCALE: 0,
704
+ COLORTYPE_PALETTE: 1,
705
+ COLORTYPE_COLOR: 2,
706
+ COLORTYPE_ALPHA: 4, // e.g. grayscale and alpha
707
+
708
+ // color-type combinations
709
+ COLORTYPE_PALETTE_COLOR: 3,
710
+ COLORTYPE_COLOR_ALPHA: 6,
711
+
712
+ COLORTYPE_TO_BPP_MAP: {
713
+ 0: 1,
714
+ 2: 3,
715
+ 3: 1,
716
+ 4: 2,
717
+ 6: 4
718
+ },
719
+
720
+ GAMMA_DIVISION: 100000
721
+ };
722
+
723
+ var crc = createCommonjsModule(function (module) {
724
+
725
+ var crcTable = [];
726
+
727
+ (function() {
728
+ for (var i = 0; i < 256; i++) {
729
+ var currentCrc = i;
730
+ for (var j = 0; j < 8; j++) {
731
+ if (currentCrc & 1) {
732
+ currentCrc = 0xedb88320 ^ (currentCrc >>> 1);
733
+ }
734
+ else {
735
+ currentCrc = currentCrc >>> 1;
736
+ }
737
+ }
738
+ crcTable[i] = currentCrc;
739
+ }
740
+ }());
741
+
742
+ var CrcCalculator = module.exports = function() {
743
+ this._crc = -1;
744
+ };
745
+
746
+ CrcCalculator.prototype.write = function(data) {
747
+
748
+ for (var i = 0; i < data.length; i++) {
749
+ this._crc = crcTable[(this._crc ^ data[i]) & 0xff] ^ (this._crc >>> 8);
750
+ }
751
+ return true;
752
+ };
753
+
754
+ CrcCalculator.prototype.crc32 = function() {
755
+ return this._crc ^ -1;
756
+ };
757
+
758
+
759
+ CrcCalculator.crc32 = function(buf) {
760
+
761
+ var crc = -1;
762
+ for (var i = 0; i < buf.length; i++) {
763
+ crc = crcTable[(crc ^ buf[i]) & 0xff] ^ (crc >>> 8);
764
+ }
765
+ return crc ^ -1;
766
+ };
767
+ });
768
+
769
+ var parser = createCommonjsModule(function (module) {
770
+
771
+
772
+
773
+
774
+
775
+ var Parser = module.exports = function(options, dependencies) {
776
+
777
+ this._options = options;
778
+ options.checkCRC = options.checkCRC !== false;
779
+
780
+ this._hasIHDR = false;
781
+ this._hasIEND = false;
782
+ this._emittedHeadersFinished = false;
783
+
784
+ // input flags/metadata
785
+ this._palette = [];
786
+ this._colorType = 0;
787
+
788
+ this._chunks = {};
789
+ this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
790
+ this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
791
+ this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
792
+ this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
793
+ this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
794
+ this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
795
+
796
+ this.read = dependencies.read;
797
+ this.error = dependencies.error;
798
+ this.metadata = dependencies.metadata;
799
+ this.gamma = dependencies.gamma;
800
+ this.transColor = dependencies.transColor;
801
+ this.palette = dependencies.palette;
802
+ this.parsed = dependencies.parsed;
803
+ this.inflateData = dependencies.inflateData;
804
+ this.finished = dependencies.finished;
805
+ this.simpleTransparency = dependencies.simpleTransparency;
806
+ this.headersFinished = dependencies.headersFinished || function() {};
807
+ };
808
+
809
+ Parser.prototype.start = function() {
810
+ this.read(constants.PNG_SIGNATURE.length,
811
+ this._parseSignature.bind(this)
812
+ );
813
+ };
814
+
815
+ Parser.prototype._parseSignature = function(data) {
816
+
817
+ var signature = constants.PNG_SIGNATURE;
818
+
819
+ for (var i = 0; i < signature.length; i++) {
820
+ if (data[i] !== signature[i]) {
821
+ this.error(new Error('Invalid file signature'));
822
+ return;
823
+ }
824
+ }
825
+ this.read(8, this._parseChunkBegin.bind(this));
826
+ };
827
+
828
+ Parser.prototype._parseChunkBegin = function(data) {
829
+
830
+ // chunk content length
831
+ var length = data.readUInt32BE(0);
832
+
833
+ // chunk type
834
+ var type = data.readUInt32BE(4);
835
+ var name = '';
836
+ for (var i = 4; i < 8; i++) {
837
+ name += String.fromCharCode(data[i]);
838
+ }
839
+
840
+ //console.log('chunk ', name, length);
841
+
842
+ // chunk flags
843
+ var ancillary = Boolean(data[4] & 0x20); // or critical
844
+ // priv = Boolean(data[5] & 0x20), // or public
845
+ // safeToCopy = Boolean(data[7] & 0x20); // or unsafe
846
+
847
+ if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
848
+ this.error(new Error('Expected IHDR on beggining'));
849
+ return;
850
+ }
851
+
852
+ this._crc = new crc();
853
+ this._crc.write(new Buffer(name));
854
+
855
+ if (this._chunks[type]) {
856
+ return this._chunks[type](length);
857
+ }
858
+
859
+ if (!ancillary) {
860
+ this.error(new Error('Unsupported critical chunk type ' + name));
861
+ return;
862
+ }
863
+
864
+ this.read(length + 4, this._skipChunk.bind(this));
865
+ };
866
+
867
+ Parser.prototype._skipChunk = function(/*data*/) {
868
+ this.read(8, this._parseChunkBegin.bind(this));
869
+ };
870
+
871
+ Parser.prototype._handleChunkEnd = function() {
872
+ this.read(4, this._parseChunkEnd.bind(this));
873
+ };
874
+
875
+ Parser.prototype._parseChunkEnd = function(data) {
876
+
877
+ var fileCrc = data.readInt32BE(0);
878
+ var calcCrc = this._crc.crc32();
879
+
880
+ // check CRC
881
+ if (this._options.checkCRC && calcCrc !== fileCrc) {
882
+ this.error(new Error('Crc error - ' + fileCrc + ' - ' + calcCrc));
883
+ return;
884
+ }
885
+
886
+ if (!this._hasIEND) {
887
+ this.read(8, this._parseChunkBegin.bind(this));
888
+ }
889
+ };
890
+
891
+ Parser.prototype._handleIHDR = function(length) {
892
+ this.read(length, this._parseIHDR.bind(this));
893
+ };
894
+ Parser.prototype._parseIHDR = function(data) {
895
+
896
+ this._crc.write(data);
897
+
898
+ var width = data.readUInt32BE(0);
899
+ var height = data.readUInt32BE(4);
900
+ var depth = data[8];
901
+ var colorType = data[9]; // bits: 1 palette, 2 color, 4 alpha
902
+ var compr = data[10];
903
+ var filter = data[11];
904
+ var interlace = data[12];
905
+
906
+ // console.log(' width', width, 'height', height,
907
+ // 'depth', depth, 'colorType', colorType,
908
+ // 'compr', compr, 'filter', filter, 'interlace', interlace
909
+ // );
910
+
911
+ if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
912
+ this.error(new Error('Unsupported bit depth ' + depth));
913
+ return;
914
+ }
915
+ if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
916
+ this.error(new Error('Unsupported color type'));
917
+ return;
918
+ }
919
+ if (compr !== 0) {
920
+ this.error(new Error('Unsupported compression method'));
921
+ return;
922
+ }
923
+ if (filter !== 0) {
924
+ this.error(new Error('Unsupported filter method'));
925
+ return;
926
+ }
927
+ if (interlace !== 0 && interlace !== 1) {
928
+ this.error(new Error('Unsupported interlace method'));
929
+ return;
930
+ }
931
+
932
+ this._colorType = colorType;
933
+
934
+ var bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
935
+
936
+ this._hasIHDR = true;
937
+
938
+ this.metadata({
939
+ width: width,
940
+ height: height,
941
+ depth: depth,
942
+ interlace: Boolean(interlace),
943
+ palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
944
+ color: Boolean(colorType & constants.COLORTYPE_COLOR),
945
+ alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
946
+ bpp: bpp,
947
+ colorType: colorType
948
+ });
949
+
950
+ this._handleChunkEnd();
951
+ };
952
+
953
+
954
+ Parser.prototype._handlePLTE = function(length) {
955
+ this.read(length, this._parsePLTE.bind(this));
956
+ };
957
+ Parser.prototype._parsePLTE = function(data) {
958
+
959
+ this._crc.write(data);
960
+
961
+ var entries = Math.floor(data.length / 3);
962
+ // console.log('Palette:', entries);
963
+
964
+ for (var i = 0; i < entries; i++) {
965
+ this._palette.push([
966
+ data[i * 3],
967
+ data[i * 3 + 1],
968
+ data[i * 3 + 2],
969
+ 0xff
970
+ ]);
971
+ }
972
+
973
+ this.palette(this._palette);
974
+
975
+ this._handleChunkEnd();
976
+ };
977
+
978
+ Parser.prototype._handleTRNS = function(length) {
979
+ this.simpleTransparency();
980
+ this.read(length, this._parseTRNS.bind(this));
981
+ };
982
+ Parser.prototype._parseTRNS = function(data) {
983
+
984
+ this._crc.write(data);
985
+
986
+ // palette
987
+ if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
988
+ if (this._palette.length === 0) {
989
+ this.error(new Error('Transparency chunk must be after palette'));
990
+ return;
991
+ }
992
+ if (data.length > this._palette.length) {
993
+ this.error(new Error('More transparent colors than palette size'));
994
+ return;
995
+ }
996
+ for (var i = 0; i < data.length; i++) {
997
+ this._palette[i][3] = data[i];
998
+ }
999
+ this.palette(this._palette);
1000
+ }
1001
+
1002
+ // for colorType 0 (grayscale) and 2 (rgb)
1003
+ // there might be one gray/color defined as transparent
1004
+ if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
1005
+ // grey, 2 bytes
1006
+ this.transColor([data.readUInt16BE(0)]);
1007
+ }
1008
+ if (this._colorType === constants.COLORTYPE_COLOR) {
1009
+ this.transColor([data.readUInt16BE(0), data.readUInt16BE(2), data.readUInt16BE(4)]);
1010
+ }
1011
+
1012
+ this._handleChunkEnd();
1013
+ };
1014
+
1015
+ Parser.prototype._handleGAMA = function(length) {
1016
+ this.read(length, this._parseGAMA.bind(this));
1017
+ };
1018
+ Parser.prototype._parseGAMA = function(data) {
1019
+
1020
+ this._crc.write(data);
1021
+ this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
1022
+
1023
+ this._handleChunkEnd();
1024
+ };
1025
+
1026
+ Parser.prototype._handleIDAT = function(length) {
1027
+ if (!this._emittedHeadersFinished) {
1028
+ this._emittedHeadersFinished = true;
1029
+ this.headersFinished();
1030
+ }
1031
+ this.read(-length, this._parseIDAT.bind(this, length));
1032
+ };
1033
+ Parser.prototype._parseIDAT = function(length, data) {
1034
+
1035
+ this._crc.write(data);
1036
+
1037
+ if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
1038
+ throw new Error('Expected palette not found');
1039
+ }
1040
+
1041
+ this.inflateData(data);
1042
+ var leftOverLength = length - data.length;
1043
+
1044
+ if (leftOverLength > 0) {
1045
+ this._handleIDAT(leftOverLength);
1046
+ }
1047
+ else {
1048
+ this._handleChunkEnd();
1049
+ }
1050
+ };
1051
+
1052
+ Parser.prototype._handleIEND = function(length) {
1053
+ this.read(length, this._parseIEND.bind(this));
1054
+ };
1055
+ Parser.prototype._parseIEND = function(data) {
1056
+
1057
+ this._crc.write(data);
1058
+
1059
+ this._hasIEND = true;
1060
+ this._handleChunkEnd();
1061
+
1062
+ if (this.finished) {
1063
+ this.finished();
1064
+ }
1065
+ };
1066
+ });
1067
+
1068
+ var pixelBppMapper = [
1069
+ // 0 - dummy entry
1070
+ function() {},
1071
+
1072
+ // 1 - L
1073
+ // 0: 0, 1: 0, 2: 0, 3: 0xff
1074
+ function(pxData, data, pxPos, rawPos) {
1075
+ if (rawPos === data.length) {
1076
+ throw new Error('Ran out of data');
1077
+ }
1078
+
1079
+ var pixel = data[rawPos];
1080
+ pxData[pxPos] = pixel;
1081
+ pxData[pxPos + 1] = pixel;
1082
+ pxData[pxPos + 2] = pixel;
1083
+ pxData[pxPos + 3] = 0xff;
1084
+ },
1085
+
1086
+ // 2 - LA
1087
+ // 0: 0, 1: 0, 2: 0, 3: 1
1088
+ function(pxData, data, pxPos, rawPos) {
1089
+ if (rawPos + 1 >= data.length) {
1090
+ throw new Error('Ran out of data');
1091
+ }
1092
+
1093
+ var pixel = data[rawPos];
1094
+ pxData[pxPos] = pixel;
1095
+ pxData[pxPos + 1] = pixel;
1096
+ pxData[pxPos + 2] = pixel;
1097
+ pxData[pxPos + 3] = data[rawPos + 1];
1098
+ },
1099
+
1100
+ // 3 - RGB
1101
+ // 0: 0, 1: 1, 2: 2, 3: 0xff
1102
+ function(pxData, data, pxPos, rawPos) {
1103
+ if (rawPos + 2 >= data.length) {
1104
+ throw new Error('Ran out of data');
1105
+ }
1106
+
1107
+ pxData[pxPos] = data[rawPos];
1108
+ pxData[pxPos + 1] = data[rawPos + 1];
1109
+ pxData[pxPos + 2] = data[rawPos + 2];
1110
+ pxData[pxPos + 3] = 0xff;
1111
+ },
1112
+
1113
+ // 4 - RGBA
1114
+ // 0: 0, 1: 1, 2: 2, 3: 3
1115
+ function(pxData, data, pxPos, rawPos) {
1116
+ if (rawPos + 3 >= data.length) {
1117
+ throw new Error('Ran out of data');
1118
+ }
1119
+
1120
+ pxData[pxPos] = data[rawPos];
1121
+ pxData[pxPos + 1] = data[rawPos + 1];
1122
+ pxData[pxPos + 2] = data[rawPos + 2];
1123
+ pxData[pxPos + 3] = data[rawPos + 3];
1124
+ }
1125
+ ];
1126
+
1127
+ var pixelBppCustomMapper = [
1128
+ // 0 - dummy entry
1129
+ function() {},
1130
+
1131
+ // 1 - L
1132
+ // 0: 0, 1: 0, 2: 0, 3: 0xff
1133
+ function(pxData, pixelData, pxPos, maxBit) {
1134
+ var pixel = pixelData[0];
1135
+ pxData[pxPos] = pixel;
1136
+ pxData[pxPos + 1] = pixel;
1137
+ pxData[pxPos + 2] = pixel;
1138
+ pxData[pxPos + 3] = maxBit;
1139
+ },
1140
+
1141
+ // 2 - LA
1142
+ // 0: 0, 1: 0, 2: 0, 3: 1
1143
+ function(pxData, pixelData, pxPos) {
1144
+ var pixel = pixelData[0];
1145
+ pxData[pxPos] = pixel;
1146
+ pxData[pxPos + 1] = pixel;
1147
+ pxData[pxPos + 2] = pixel;
1148
+ pxData[pxPos + 3] = pixelData[1];
1149
+ },
1150
+
1151
+ // 3 - RGB
1152
+ // 0: 0, 1: 1, 2: 2, 3: 0xff
1153
+ function(pxData, pixelData, pxPos, maxBit) {
1154
+ pxData[pxPos] = pixelData[0];
1155
+ pxData[pxPos + 1] = pixelData[1];
1156
+ pxData[pxPos + 2] = pixelData[2];
1157
+ pxData[pxPos + 3] = maxBit;
1158
+ },
1159
+
1160
+ // 4 - RGBA
1161
+ // 0: 0, 1: 1, 2: 2, 3: 3
1162
+ function(pxData, pixelData, pxPos) {
1163
+ pxData[pxPos] = pixelData[0];
1164
+ pxData[pxPos + 1] = pixelData[1];
1165
+ pxData[pxPos + 2] = pixelData[2];
1166
+ pxData[pxPos + 3] = pixelData[3];
1167
+ }
1168
+ ];
1169
+
1170
+ function bitRetriever(data, depth) {
1171
+
1172
+ var leftOver = [];
1173
+ var i = 0;
1174
+
1175
+ function split() {
1176
+ if (i === data.length) {
1177
+ throw new Error('Ran out of data');
1178
+ }
1179
+ var byte = data[i];
1180
+ i++;
1181
+ var byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
1182
+ switch (depth) {
1183
+ default:
1184
+ throw new Error('unrecognised depth');
1185
+ case 16:
1186
+ byte2 = data[i];
1187
+ i++;
1188
+ leftOver.push(((byte << 8) + byte2));
1189
+ break;
1190
+ case 4:
1191
+ byte2 = byte & 0x0f;
1192
+ byte1 = byte >> 4;
1193
+ leftOver.push(byte1, byte2);
1194
+ break;
1195
+ case 2:
1196
+ byte4 = byte & 3;
1197
+ byte3 = byte >> 2 & 3;
1198
+ byte2 = byte >> 4 & 3;
1199
+ byte1 = byte >> 6 & 3;
1200
+ leftOver.push(byte1, byte2, byte3, byte4);
1201
+ break;
1202
+ case 1:
1203
+ byte8 = byte & 1;
1204
+ byte7 = byte >> 1 & 1;
1205
+ byte6 = byte >> 2 & 1;
1206
+ byte5 = byte >> 3 & 1;
1207
+ byte4 = byte >> 4 & 1;
1208
+ byte3 = byte >> 5 & 1;
1209
+ byte2 = byte >> 6 & 1;
1210
+ byte1 = byte >> 7 & 1;
1211
+ leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
1212
+ break;
1213
+ }
1214
+ }
1215
+
1216
+ return {
1217
+ get: function(count) {
1218
+ while (leftOver.length < count) {
1219
+ split();
1220
+ }
1221
+ var returner = leftOver.slice(0, count);
1222
+ leftOver = leftOver.slice(count);
1223
+ return returner;
1224
+ },
1225
+ resetAfterLine: function() {
1226
+ leftOver.length = 0;
1227
+ },
1228
+ end: function() {
1229
+ if (i !== data.length) {
1230
+ throw new Error('extra data found');
1231
+ }
1232
+ }
1233
+ };
1234
+ }
1235
+
1236
+ function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) { // eslint-disable-line max-params
1237
+ var imageWidth = image.width;
1238
+ var imageHeight = image.height;
1239
+ var imagePass = image.index;
1240
+ for (var y = 0; y < imageHeight; y++) {
1241
+ for (var x = 0; x < imageWidth; x++) {
1242
+ var pxPos = getPxPos(x, y, imagePass);
1243
+ pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
1244
+ rawPos += bpp; //eslint-disable-line no-param-reassign
1245
+ }
1246
+ }
1247
+ return rawPos;
1248
+ }
1249
+
1250
+ function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) { // eslint-disable-line max-params
1251
+ var imageWidth = image.width;
1252
+ var imageHeight = image.height;
1253
+ var imagePass = image.index;
1254
+ for (var y = 0; y < imageHeight; y++) {
1255
+ for (var x = 0; x < imageWidth; x++) {
1256
+ var pixelData = bits.get(bpp);
1257
+ var pxPos = getPxPos(x, y, imagePass);
1258
+ pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
1259
+ }
1260
+ bits.resetAfterLine();
1261
+ }
1262
+ }
1263
+
1264
+ var dataToBitMap = function(data, bitmapInfo) {
1265
+
1266
+ var width = bitmapInfo.width;
1267
+ var height = bitmapInfo.height;
1268
+ var depth = bitmapInfo.depth;
1269
+ var bpp = bitmapInfo.bpp;
1270
+ var interlace$1 = bitmapInfo.interlace;
1271
+
1272
+ if (depth !== 8) {
1273
+ var bits = bitRetriever(data, depth);
1274
+ }
1275
+ var pxData;
1276
+ if (depth <= 8) {
1277
+ pxData = new Buffer(width * height * 4);
1278
+ }
1279
+ else {
1280
+ pxData = new Uint16Array(width * height * 4);
1281
+ }
1282
+ var maxBit = Math.pow(2, depth) - 1;
1283
+ var rawPos = 0;
1284
+ var images;
1285
+ var getPxPos;
1286
+
1287
+ if (interlace$1) {
1288
+ images = interlace.getImagePasses(width, height);
1289
+ getPxPos = interlace.getInterlaceIterator(width, height);
1290
+ }
1291
+ else {
1292
+ var nonInterlacedPxPos = 0;
1293
+ getPxPos = function() {
1294
+ var returner = nonInterlacedPxPos;
1295
+ nonInterlacedPxPos += 4;
1296
+ return returner;
1297
+ };
1298
+ images = [{ width: width, height: height }];
1299
+ }
1300
+
1301
+ for (var imageIndex = 0; imageIndex < images.length; imageIndex++) {
1302
+ if (depth === 8) {
1303
+ rawPos = mapImage8Bit(images[imageIndex], pxData, getPxPos, bpp, data, rawPos);
1304
+ }
1305
+ else {
1306
+ mapImageCustomBit(images[imageIndex], pxData, getPxPos, bpp, bits, maxBit);
1307
+ }
1308
+ }
1309
+ if (depth === 8) {
1310
+ if (rawPos !== data.length) {
1311
+ throw new Error('extra data found');
1312
+ }
1313
+ }
1314
+ else {
1315
+ bits.end();
1316
+ }
1317
+
1318
+ return pxData;
1319
+ };
1320
+
1321
+ var bitmapper = {
1322
+ dataToBitMap: dataToBitMap
1323
+ };
1324
+
1325
+ function dePalette(indata, outdata, width, height, palette) {
1326
+ var pxPos = 0;
1327
+ // use values from palette
1328
+ for (var y = 0; y < height; y++) {
1329
+ for (var x = 0; x < width; x++) {
1330
+ var color = palette[indata[pxPos]];
1331
+
1332
+ if (!color) {
1333
+ throw new Error('index ' + indata[pxPos] + ' not in palette');
1334
+ }
1335
+
1336
+ for (var i = 0; i < 4; i++) {
1337
+ outdata[pxPos + i] = color[i];
1338
+ }
1339
+ pxPos += 4;
1340
+ }
1341
+ }
1342
+ }
1343
+
1344
+ function replaceTransparentColor(indata, outdata, width, height, transColor) {
1345
+ var pxPos = 0;
1346
+ for (var y = 0; y < height; y++) {
1347
+ for (var x = 0; x < width; x++) {
1348
+ var makeTrans = false;
1349
+
1350
+ if (transColor.length === 1) {
1351
+ if (transColor[0] === indata[pxPos]) {
1352
+ makeTrans = true;
1353
+ }
1354
+ }
1355
+ else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
1356
+ makeTrans = true;
1357
+ }
1358
+ if (makeTrans) {
1359
+ for (var i = 0; i < 4; i++) {
1360
+ outdata[pxPos + i] = 0;
1361
+ }
1362
+ }
1363
+ pxPos += 4;
1364
+ }
1365
+ }
1366
+ }
1367
+
1368
+ function scaleDepth(indata, outdata, width, height, depth) {
1369
+ var maxOutSample = 255;
1370
+ var maxInSample = Math.pow(2, depth) - 1;
1371
+ var pxPos = 0;
1372
+
1373
+ for (var y = 0; y < height; y++) {
1374
+ for (var x = 0; x < width; x++) {
1375
+ for (var i = 0; i < 4; i++) {
1376
+ outdata[pxPos + i] = Math.floor((indata[pxPos + i] * maxOutSample) / maxInSample + 0.5);
1377
+ }
1378
+ pxPos += 4;
1379
+ }
1380
+ }
1381
+ }
1382
+
1383
+ var formatNormaliser = function(indata, imageData) {
1384
+
1385
+ var depth = imageData.depth;
1386
+ var width = imageData.width;
1387
+ var height = imageData.height;
1388
+ var colorType = imageData.colorType;
1389
+ var transColor = imageData.transColor;
1390
+ var palette = imageData.palette;
1391
+
1392
+ var outdata = indata; // only different for 16 bits
1393
+
1394
+ if (colorType === 3) { // paletted
1395
+ dePalette(indata, outdata, width, height, palette);
1396
+ }
1397
+ else {
1398
+ if (transColor) {
1399
+ replaceTransparentColor(indata, outdata, width, height, transColor);
1400
+ }
1401
+ // if it needs scaling
1402
+ if (depth !== 8) {
1403
+ // if we need to change the buffer size
1404
+ if (depth === 16) {
1405
+ outdata = new Buffer(width * height * 4);
1406
+ }
1407
+ scaleDepth(indata, outdata, width, height, depth);
1408
+ }
1409
+ }
1410
+ return outdata;
1411
+ };
1412
+
1413
+ var parserAsync = createCommonjsModule(function (module) {
1414
+
1415
+
1416
+
1417
+
1418
+
1419
+
1420
+
1421
+
1422
+
1423
+ var ParserAsync = module.exports = function(options) {
1424
+ chunkstream.call(this);
1425
+
1426
+ this._parser = new parser(options, {
1427
+ read: this.read.bind(this),
1428
+ error: this._handleError.bind(this),
1429
+ metadata: this._handleMetaData.bind(this),
1430
+ gamma: this.emit.bind(this, 'gamma'),
1431
+ palette: this._handlePalette.bind(this),
1432
+ transColor: this._handleTransColor.bind(this),
1433
+ finished: this._finished.bind(this),
1434
+ inflateData: this._inflateData.bind(this),
1435
+ simpleTransparency: this._simpleTransparency.bind(this),
1436
+ headersFinished: this._headersFinished.bind(this)
1437
+ });
1438
+ this._options = options;
1439
+ this.writable = true;
1440
+
1441
+ this._parser.start();
1442
+ };
1443
+ util.inherits(ParserAsync, chunkstream);
1444
+
1445
+
1446
+ ParserAsync.prototype._handleError = function(err) {
1447
+
1448
+ this.emit('error', err);
1449
+
1450
+ this.writable = false;
1451
+
1452
+ this.destroy();
1453
+
1454
+ if (this._inflate && this._inflate.destroy) {
1455
+ this._inflate.destroy();
1456
+ }
1457
+
1458
+ if (this._filter) {
1459
+ this._filter.destroy();
1460
+ // For backward compatibility with Node 7 and below.
1461
+ // Suppress errors due to _inflate calling write() even after
1462
+ // it's destroy()'ed.
1463
+ this._filter.on('error', function() {});
1464
+ }
1465
+
1466
+ this.errord = true;
1467
+ };
1468
+
1469
+ ParserAsync.prototype._inflateData = function(data) {
1470
+ if (!this._inflate) {
1471
+ if (this._bitmapInfo.interlace) {
1472
+ this._inflate = zlib.createInflate();
1473
+
1474
+ this._inflate.on('error', this.emit.bind(this, 'error'));
1475
+ this._filter.on('complete', this._complete.bind(this));
1476
+
1477
+ this._inflate.pipe(this._filter);
1478
+ }
1479
+ else {
1480
+ var rowSize = ((this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7) >> 3) + 1;
1481
+ var imageSize = rowSize * this._bitmapInfo.height;
1482
+ var chunkSize = Math.max(imageSize, zlib.Z_MIN_CHUNK);
1483
+
1484
+ this._inflate = zlib.createInflate({ chunkSize: chunkSize });
1485
+ var leftToInflate = imageSize;
1486
+
1487
+ var emitError = this.emit.bind(this, 'error');
1488
+ this._inflate.on('error', function(err) {
1489
+ if (!leftToInflate) {
1490
+ return;
1491
+ }
1492
+
1493
+ emitError(err);
1494
+ });
1495
+ this._filter.on('complete', this._complete.bind(this));
1496
+
1497
+ var filterWrite = this._filter.write.bind(this._filter);
1498
+ this._inflate.on('data', function(chunk) {
1499
+ if (!leftToInflate) {
1500
+ return;
1501
+ }
1502
+
1503
+ if (chunk.length > leftToInflate) {
1504
+ chunk = chunk.slice(0, leftToInflate);
1505
+ }
1506
+
1507
+ leftToInflate -= chunk.length;
1508
+
1509
+ filterWrite(chunk);
1510
+ });
1511
+
1512
+ this._inflate.on('end', this._filter.end.bind(this._filter));
1513
+ }
1514
+ }
1515
+ this._inflate.write(data);
1516
+ };
1517
+
1518
+ ParserAsync.prototype._handleMetaData = function(metaData) {
1519
+ this._metaData = metaData;
1520
+ this._bitmapInfo = Object.create(metaData);
1521
+
1522
+ this._filter = new filterParseAsync(this._bitmapInfo);
1523
+ };
1524
+
1525
+ ParserAsync.prototype._handleTransColor = function(transColor) {
1526
+ this._bitmapInfo.transColor = transColor;
1527
+ };
1528
+
1529
+ ParserAsync.prototype._handlePalette = function(palette) {
1530
+ this._bitmapInfo.palette = palette;
1531
+ };
1532
+
1533
+ ParserAsync.prototype._simpleTransparency = function() {
1534
+ this._metaData.alpha = true;
1535
+ };
1536
+
1537
+ ParserAsync.prototype._headersFinished = function() {
1538
+ // Up until this point, we don't know if we have a tRNS chunk (alpha)
1539
+ // so we can't emit metadata any earlier
1540
+ this.emit('metadata', this._metaData);
1541
+ };
1542
+
1543
+ ParserAsync.prototype._finished = function() {
1544
+ if (this.errord) {
1545
+ return;
1546
+ }
1547
+
1548
+ if (!this._inflate) {
1549
+ this.emit('error', 'No Inflate block');
1550
+ }
1551
+ else {
1552
+ // no more data to inflate
1553
+ this._inflate.end();
1554
+ }
1555
+ this.destroySoon();
1556
+ };
1557
+
1558
+ ParserAsync.prototype._complete = function(filteredData) {
1559
+
1560
+ if (this.errord) {
1561
+ return;
1562
+ }
1563
+
1564
+ try {
1565
+ var bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
1566
+
1567
+ var normalisedBitmapData = formatNormaliser(bitmapData, this._bitmapInfo);
1568
+ bitmapData = null;
1569
+ }
1570
+ catch (ex) {
1571
+ this._handleError(ex);
1572
+ return;
1573
+ }
1574
+
1575
+ this.emit('parsed', normalisedBitmapData);
1576
+ };
1577
+ });
1578
+
1579
+ var bitpacker = function(dataIn, width, height, options) {
1580
+ var outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(options.colorType) !== -1;
1581
+ if (options.colorType === options.inputColorType) {
1582
+ var bigEndian = (function() {
1583
+ var buffer = new ArrayBuffer(2);
1584
+ new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
1585
+ // Int16Array uses the platform's endianness.
1586
+ return new Int16Array(buffer)[0] !== 256;
1587
+ })();
1588
+ // If no need to convert to grayscale and alpha is present/absent in both, take a fast route
1589
+ if (options.bitDepth === 8 || (options.bitDepth === 16 && bigEndian)) {
1590
+ return dataIn;
1591
+ }
1592
+ }
1593
+
1594
+ // map to a UInt16 array if data is 16bit, fix endianness below
1595
+ var data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
1596
+
1597
+ var maxValue = 255;
1598
+ var inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
1599
+ if (inBpp === 4 && !options.inputHasAlpha) {
1600
+ inBpp = 3;
1601
+ }
1602
+ var outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
1603
+ if (options.bitDepth === 16) {
1604
+ maxValue = 65535;
1605
+ outBpp *= 2;
1606
+ }
1607
+ var outData = new Buffer(width * height * outBpp);
1608
+
1609
+ var inIndex = 0;
1610
+ var outIndex = 0;
1611
+
1612
+ var bgColor = options.bgColor || {};
1613
+ if (bgColor.red === undefined) {
1614
+ bgColor.red = maxValue;
1615
+ }
1616
+ if (bgColor.green === undefined) {
1617
+ bgColor.green = maxValue;
1618
+ }
1619
+ if (bgColor.blue === undefined) {
1620
+ bgColor.blue = maxValue;
1621
+ }
1622
+
1623
+ function getRGBA() {
1624
+ var red;
1625
+ var green;
1626
+ var blue;
1627
+ var alpha = maxValue;
1628
+ switch (options.inputColorType) {
1629
+ case constants.COLORTYPE_COLOR_ALPHA:
1630
+ alpha = data[inIndex + 3];
1631
+ red = data[inIndex];
1632
+ green = data[inIndex + 1];
1633
+ blue = data[inIndex + 2];
1634
+ break;
1635
+ case constants.COLORTYPE_COLOR:
1636
+ red = data[inIndex];
1637
+ green = data[inIndex + 1];
1638
+ blue = data[inIndex + 2];
1639
+ break;
1640
+ case constants.COLORTYPE_ALPHA:
1641
+ alpha = data[inIndex + 1];
1642
+ red = data[inIndex];
1643
+ green = red;
1644
+ blue = red;
1645
+ break;
1646
+ case constants.COLORTYPE_GRAYSCALE:
1647
+ red = data[inIndex];
1648
+ green = red;
1649
+ blue = red;
1650
+ break;
1651
+ default:
1652
+ throw new Error('input color type:' + options.inputColorType + ' is not supported at present');
1653
+ }
1654
+
1655
+ if (options.inputHasAlpha) {
1656
+ if (!outHasAlpha) {
1657
+ alpha /= maxValue;
1658
+ red = Math.min(Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0), maxValue);
1659
+ green = Math.min(Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0), maxValue);
1660
+ blue = Math.min(Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0), maxValue);
1661
+ }
1662
+ }
1663
+ return { red: red, green: green, blue: blue, alpha: alpha };
1664
+ }
1665
+
1666
+ for (var y = 0; y < height; y++) {
1667
+ for (var x = 0; x < width; x++) {
1668
+ var rgba = getRGBA();
1669
+
1670
+ switch (options.colorType) {
1671
+ case constants.COLORTYPE_COLOR_ALPHA:
1672
+ case constants.COLORTYPE_COLOR:
1673
+ if (options.bitDepth === 8) {
1674
+ outData[outIndex] = rgba.red;
1675
+ outData[outIndex + 1] = rgba.green;
1676
+ outData[outIndex + 2] = rgba.blue;
1677
+ if (outHasAlpha) {
1678
+ outData[outIndex + 3] = rgba.alpha;
1679
+ }
1680
+ }
1681
+ else {
1682
+ outData.writeUInt16BE(rgba.red, outIndex);
1683
+ outData.writeUInt16BE(rgba.green, outIndex + 2);
1684
+ outData.writeUInt16BE(rgba.blue, outIndex + 4);
1685
+ if (outHasAlpha) {
1686
+ outData.writeUInt16BE(rgba.alpha, outIndex + 6);
1687
+ }
1688
+ }
1689
+ break;
1690
+ case constants.COLORTYPE_ALPHA:
1691
+ case constants.COLORTYPE_GRAYSCALE:
1692
+ // Convert to grayscale and alpha
1693
+ var grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
1694
+ if (options.bitDepth === 8) {
1695
+ outData[outIndex] = grayscale;
1696
+ if (outHasAlpha) {
1697
+ outData[outIndex + 1] = rgba.alpha;
1698
+ }
1699
+ }
1700
+ else {
1701
+ outData.writeUInt16BE(grayscale, outIndex);
1702
+ if (outHasAlpha) {
1703
+ outData.writeUInt16BE(rgba.alpha, outIndex + 2);
1704
+ }
1705
+ }
1706
+ break;
1707
+ default:
1708
+ throw new Error('unrecognised color Type ' + options.colorType);
1709
+ }
1710
+
1711
+ inIndex += inBpp;
1712
+ outIndex += outBpp;
1713
+ }
1714
+ }
1715
+
1716
+ return outData;
1717
+ };
1718
+
1719
+ function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
1720
+
1721
+ for (var x = 0; x < byteWidth; x++) {
1722
+ rawData[rawPos + x] = pxData[pxPos + x];
1723
+ }
1724
+ }
1725
+
1726
+ function filterSumNone(pxData, pxPos, byteWidth) {
1727
+
1728
+ var sum = 0;
1729
+ var length = pxPos + byteWidth;
1730
+
1731
+ for (var i = pxPos; i < length; i++) {
1732
+ sum += Math.abs(pxData[i]);
1733
+ }
1734
+ return sum;
1735
+ }
1736
+
1737
+ function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1738
+
1739
+ for (var x = 0; x < byteWidth; x++) {
1740
+
1741
+ var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1742
+ var val = pxData[pxPos + x] - left;
1743
+
1744
+ rawData[rawPos + x] = val;
1745
+ }
1746
+ }
1747
+
1748
+ function filterSumSub(pxData, pxPos, byteWidth, bpp) {
1749
+
1750
+ var sum = 0;
1751
+ for (var x = 0; x < byteWidth; x++) {
1752
+
1753
+ var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1754
+ var val = pxData[pxPos + x] - left;
1755
+
1756
+ sum += Math.abs(val);
1757
+ }
1758
+
1759
+ return sum;
1760
+ }
1761
+
1762
+ function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
1763
+
1764
+ for (var x = 0; x < byteWidth; x++) {
1765
+
1766
+ var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1767
+ var val = pxData[pxPos + x] - up;
1768
+
1769
+ rawData[rawPos + x] = val;
1770
+ }
1771
+ }
1772
+
1773
+ function filterSumUp(pxData, pxPos, byteWidth) {
1774
+
1775
+ var sum = 0;
1776
+ var length = pxPos + byteWidth;
1777
+ for (var x = pxPos; x < length; x++) {
1778
+
1779
+ var up = pxPos > 0 ? pxData[x - byteWidth] : 0;
1780
+ var val = pxData[x] - up;
1781
+
1782
+ sum += Math.abs(val);
1783
+ }
1784
+
1785
+ return sum;
1786
+ }
1787
+
1788
+ function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1789
+
1790
+ for (var x = 0; x < byteWidth; x++) {
1791
+
1792
+ var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1793
+ var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1794
+ var val = pxData[pxPos + x] - ((left + up) >> 1);
1795
+
1796
+ rawData[rawPos + x] = val;
1797
+ }
1798
+ }
1799
+
1800
+ function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
1801
+
1802
+ var sum = 0;
1803
+ for (var x = 0; x < byteWidth; x++) {
1804
+
1805
+ var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1806
+ var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1807
+ var val = pxData[pxPos + x] - ((left + up) >> 1);
1808
+
1809
+ sum += Math.abs(val);
1810
+ }
1811
+
1812
+ return sum;
1813
+ }
1814
+
1815
+ function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
1816
+
1817
+ for (var x = 0; x < byteWidth; x++) {
1818
+
1819
+ var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1820
+ var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1821
+ var upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1822
+ var val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1823
+
1824
+ rawData[rawPos + x] = val;
1825
+ }
1826
+ }
1827
+
1828
+ function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
1829
+ var sum = 0;
1830
+ for (var x = 0; x < byteWidth; x++) {
1831
+
1832
+ var left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
1833
+ var up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
1834
+ var upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
1835
+ var val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
1836
+
1837
+ sum += Math.abs(val);
1838
+ }
1839
+
1840
+ return sum;
1841
+ }
1842
+
1843
+ var filters = {
1844
+ 0: filterNone,
1845
+ 1: filterSub,
1846
+ 2: filterUp,
1847
+ 3: filterAvg,
1848
+ 4: filterPaeth
1849
+ };
1850
+
1851
+ var filterSums = {
1852
+ 0: filterSumNone,
1853
+ 1: filterSumSub,
1854
+ 2: filterSumUp,
1855
+ 3: filterSumAvg,
1856
+ 4: filterSumPaeth
1857
+ };
1858
+
1859
+ var filterPack = function(pxData, width, height, options, bpp) {
1860
+
1861
+ var filterTypes;
1862
+ if (!('filterType' in options) || options.filterType === -1) {
1863
+ filterTypes = [0, 1, 2, 3, 4];
1864
+ }
1865
+ else if (typeof options.filterType === 'number') {
1866
+ filterTypes = [options.filterType];
1867
+ }
1868
+ else {
1869
+ throw new Error('unrecognised filter types');
1870
+ }
1871
+
1872
+ if (options.bitDepth === 16) {
1873
+ bpp *= 2;
1874
+ }
1875
+ var byteWidth = width * bpp;
1876
+ var rawPos = 0;
1877
+ var pxPos = 0;
1878
+ var rawData = new Buffer((byteWidth + 1) * height);
1879
+
1880
+ var sel = filterTypes[0];
1881
+
1882
+ for (var y = 0; y < height; y++) {
1883
+
1884
+ if (filterTypes.length > 1) {
1885
+ // find best filter for this line (with lowest sum of values)
1886
+ var min = Infinity;
1887
+
1888
+ for (var i = 0; i < filterTypes.length; i++) {
1889
+ var sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
1890
+ if (sum < min) {
1891
+ sel = filterTypes[i];
1892
+ min = sum;
1893
+ }
1894
+ }
1895
+ }
1896
+
1897
+ rawData[rawPos] = sel;
1898
+ rawPos++;
1899
+ filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
1900
+ rawPos += byteWidth;
1901
+ pxPos += byteWidth;
1902
+ }
1903
+ return rawData;
1904
+ };
1905
+
1906
+ var packer = createCommonjsModule(function (module) {
1907
+
1908
+
1909
+
1910
+
1911
+
1912
+
1913
+
1914
+ var Packer = module.exports = function(options) {
1915
+ this._options = options;
1916
+
1917
+ options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
1918
+ options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
1919
+ options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
1920
+ options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
1921
+ options.deflateFactory = options.deflateFactory || zlib.createDeflate;
1922
+ options.bitDepth = options.bitDepth || 8;
1923
+ // This is outputColorType
1924
+ options.colorType = (typeof options.colorType === 'number') ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
1925
+ options.inputColorType = (typeof options.inputColorType === 'number') ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
1926
+
1927
+ if ([
1928
+ constants.COLORTYPE_GRAYSCALE,
1929
+ constants.COLORTYPE_COLOR,
1930
+ constants.COLORTYPE_COLOR_ALPHA,
1931
+ constants.COLORTYPE_ALPHA
1932
+ ].indexOf(options.colorType) === -1) {
1933
+ throw new Error('option color type:' + options.colorType + ' is not supported at present');
1934
+ }
1935
+ if ([
1936
+ constants.COLORTYPE_GRAYSCALE,
1937
+ constants.COLORTYPE_COLOR,
1938
+ constants.COLORTYPE_COLOR_ALPHA,
1939
+ constants.COLORTYPE_ALPHA
1940
+ ].indexOf(options.inputColorType) === -1) {
1941
+ throw new Error('option input color type:' + options.inputColorType + ' is not supported at present');
1942
+ }
1943
+ if (options.bitDepth !== 8 && options.bitDepth !== 16) {
1944
+ throw new Error('option bit depth:' + options.bitDepth + ' is not supported at present');
1945
+ }
1946
+ };
1947
+
1948
+ Packer.prototype.getDeflateOptions = function() {
1949
+ return {
1950
+ chunkSize: this._options.deflateChunkSize,
1951
+ level: this._options.deflateLevel,
1952
+ strategy: this._options.deflateStrategy
1953
+ };
1954
+ };
1955
+
1956
+ Packer.prototype.createDeflate = function() {
1957
+ return this._options.deflateFactory(this.getDeflateOptions());
1958
+ };
1959
+
1960
+ Packer.prototype.filterData = function(data, width, height) {
1961
+ // convert to correct format for filtering (e.g. right bpp and bit depth)
1962
+ var packedData = bitpacker(data, width, height, this._options);
1963
+
1964
+ // filter pixel data
1965
+ var bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
1966
+ var filteredData = filterPack(packedData, width, height, this._options, bpp);
1967
+ return filteredData;
1968
+ };
1969
+
1970
+ Packer.prototype._packChunk = function(type, data) {
1971
+
1972
+ var len = (data ? data.length : 0);
1973
+ var buf = new Buffer(len + 12);
1974
+
1975
+ buf.writeUInt32BE(len, 0);
1976
+ buf.writeUInt32BE(type, 4);
1977
+
1978
+ if (data) {
1979
+ data.copy(buf, 8);
1980
+ }
1981
+
1982
+ buf.writeInt32BE(crc.crc32(buf.slice(4, buf.length - 4)), buf.length - 4);
1983
+ return buf;
1984
+ };
1985
+
1986
+ Packer.prototype.packGAMA = function(gamma) {
1987
+ var buf = new Buffer(4);
1988
+ buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
1989
+ return this._packChunk(constants.TYPE_gAMA, buf);
1990
+ };
1991
+
1992
+ Packer.prototype.packIHDR = function(width, height) {
1993
+
1994
+ var buf = new Buffer(13);
1995
+ buf.writeUInt32BE(width, 0);
1996
+ buf.writeUInt32BE(height, 4);
1997
+ buf[8] = this._options.bitDepth; // Bit depth
1998
+ buf[9] = this._options.colorType; // colorType
1999
+ buf[10] = 0; // compression
2000
+ buf[11] = 0; // filter
2001
+ buf[12] = 0; // interlace
2002
+
2003
+ return this._packChunk(constants.TYPE_IHDR, buf);
2004
+ };
2005
+
2006
+ Packer.prototype.packIDAT = function(data) {
2007
+ return this._packChunk(constants.TYPE_IDAT, data);
2008
+ };
2009
+
2010
+ Packer.prototype.packIEND = function() {
2011
+ return this._packChunk(constants.TYPE_IEND, null);
2012
+ };
2013
+ });
2014
+
2015
+ var packerAsync = createCommonjsModule(function (module) {
2016
+
2017
+
2018
+
2019
+
2020
+
2021
+
2022
+ var PackerAsync = module.exports = function(opt) {
2023
+ stream.call(this);
2024
+
2025
+ var options = opt || {};
2026
+
2027
+ this._packer = new packer(options);
2028
+ this._deflate = this._packer.createDeflate();
2029
+
2030
+ this.readable = true;
2031
+ };
2032
+ util.inherits(PackerAsync, stream);
2033
+
2034
+
2035
+ PackerAsync.prototype.pack = function(data, width, height, gamma) {
2036
+ // Signature
2037
+ this.emit('data', new Buffer(constants.PNG_SIGNATURE));
2038
+ this.emit('data', this._packer.packIHDR(width, height));
2039
+
2040
+ if (gamma) {
2041
+ this.emit('data', this._packer.packGAMA(gamma));
2042
+ }
2043
+
2044
+ var filteredData = this._packer.filterData(data, width, height);
2045
+
2046
+ // compress it
2047
+ this._deflate.on('error', this.emit.bind(this, 'error'));
2048
+
2049
+ this._deflate.on('data', function(compressedData) {
2050
+ this.emit('data', this._packer.packIDAT(compressedData));
2051
+ }.bind(this));
2052
+
2053
+ this._deflate.on('end', function() {
2054
+ this.emit('data', this._packer.packIEND());
2055
+ this.emit('end');
2056
+ }.bind(this));
2057
+
2058
+ this._deflate.end(filteredData);
2059
+ };
2060
+ });
2061
+
2062
+ var syncInflate = createCommonjsModule(function (module, exports) {
2063
+
2064
+ var assert$1 = assert.ok;
2065
+
2066
+
2067
+
2068
+ var kMaxLength = buffer.kMaxLength;
2069
+
2070
+ function Inflate(opts) {
2071
+ if (!(this instanceof Inflate)) {
2072
+ return new Inflate(opts);
2073
+ }
2074
+
2075
+ if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
2076
+ opts.chunkSize = zlib.Z_MIN_CHUNK;
2077
+ }
2078
+
2079
+ zlib.Inflate.call(this, opts);
2080
+
2081
+ // Node 8 --> 9 compatibility check
2082
+ this._offset = this._offset === undefined ? this._outOffset : this._offset;
2083
+ this._buffer = this._buffer || this._outBuffer;
2084
+
2085
+ if (opts && opts.maxLength != null) {
2086
+ this._maxLength = opts.maxLength;
2087
+ }
2088
+ }
2089
+
2090
+ function createInflate(opts) {
2091
+ return new Inflate(opts);
2092
+ }
2093
+
2094
+ function _close(engine, callback) {
2095
+ if (callback) {
2096
+ process.nextTick(callback);
2097
+ }
2098
+
2099
+ // Caller may invoke .close after a zlib error (which will null _handle).
2100
+ if (!engine._handle) {
2101
+ return;
2102
+ }
2103
+
2104
+ engine._handle.close();
2105
+ engine._handle = null;
2106
+ }
2107
+
2108
+ Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
2109
+ if (typeof asyncCb === 'function') {
2110
+ return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
2111
+ }
2112
+
2113
+ var self = this;
2114
+
2115
+ var availInBefore = chunk && chunk.length;
2116
+ var availOutBefore = this._chunkSize - this._offset;
2117
+ var leftToInflate = this._maxLength;
2118
+ var inOff = 0;
2119
+
2120
+ var buffers = [];
2121
+ var nread = 0;
2122
+
2123
+ var error;
2124
+ this.on('error', function(err) {
2125
+ error = err;
2126
+ });
2127
+
2128
+ function handleChunk(availInAfter, availOutAfter) {
2129
+ if (self._hadError) {
2130
+ return;
2131
+ }
2132
+
2133
+ var have = availOutBefore - availOutAfter;
2134
+ assert$1(have >= 0, 'have should not go down');
2135
+
2136
+ if (have > 0) {
2137
+ var out = self._buffer.slice(self._offset, self._offset + have);
2138
+ self._offset += have;
2139
+
2140
+ if (out.length > leftToInflate) {
2141
+ out = out.slice(0, leftToInflate);
2142
+ }
2143
+
2144
+ buffers.push(out);
2145
+ nread += out.length;
2146
+ leftToInflate -= out.length;
2147
+
2148
+ if (leftToInflate === 0) {
2149
+ return false;
2150
+ }
2151
+ }
2152
+
2153
+ if (availOutAfter === 0 || self._offset >= self._chunkSize) {
2154
+ availOutBefore = self._chunkSize;
2155
+ self._offset = 0;
2156
+ self._buffer = Buffer.allocUnsafe(self._chunkSize);
2157
+ }
2158
+
2159
+ if (availOutAfter === 0) {
2160
+ inOff += (availInBefore - availInAfter);
2161
+ availInBefore = availInAfter;
2162
+
2163
+ return true;
2164
+ }
2165
+
2166
+ return false;
2167
+ }
2168
+
2169
+ assert$1(this._handle, 'zlib binding closed');
2170
+ do {
2171
+ var res = this._handle.writeSync(flushFlag,
2172
+ chunk, // in
2173
+ inOff, // in_off
2174
+ availInBefore, // in_len
2175
+ this._buffer, // out
2176
+ this._offset, //out_off
2177
+ availOutBefore); // out_len
2178
+ // Node 8 --> 9 compatibility check
2179
+ res = res || this._writeState;
2180
+ } while (!this._hadError && handleChunk(res[0], res[1]));
2181
+
2182
+ if (this._hadError) {
2183
+ throw error;
2184
+ }
2185
+
2186
+ if (nread >= kMaxLength) {
2187
+ _close(this);
2188
+ throw new RangeError('Cannot create final Buffer. It would be larger than 0x' + kMaxLength.toString(16) + ' bytes');
2189
+ }
2190
+
2191
+ var buf = Buffer.concat(buffers, nread);
2192
+ _close(this);
2193
+
2194
+ return buf;
2195
+ };
2196
+
2197
+ util.inherits(Inflate, zlib.Inflate);
2198
+
2199
+ function zlibBufferSync(engine, buffer) {
2200
+ if (typeof buffer === 'string') {
2201
+ buffer = Buffer.from(buffer);
2202
+ }
2203
+ if (!(buffer instanceof Buffer)) {
2204
+ throw new TypeError('Not a string or buffer');
2205
+ }
2206
+
2207
+ var flushFlag = engine._finishFlushFlag;
2208
+ if (flushFlag == null) {
2209
+ flushFlag = zlib.Z_FINISH;
2210
+ }
2211
+
2212
+ return engine._processChunk(buffer, flushFlag);
2213
+ }
2214
+
2215
+ function inflateSync(buffer, opts) {
2216
+ return zlibBufferSync(new Inflate(opts), buffer);
2217
+ }
2218
+
2219
+ module.exports = exports = inflateSync;
2220
+ exports.Inflate = Inflate;
2221
+ exports.createInflate = createInflate;
2222
+ exports.inflateSync = inflateSync;
2223
+ });
2224
+ var syncInflate_1 = syncInflate.Inflate;
2225
+ var syncInflate_2 = syncInflate.createInflate;
2226
+ var syncInflate_3 = syncInflate.inflateSync;
2227
+
2228
+ var syncReader = createCommonjsModule(function (module) {
2229
+
2230
+ var SyncReader = module.exports = function(buffer) {
2231
+
2232
+ this._buffer = buffer;
2233
+ this._reads = [];
2234
+ };
2235
+
2236
+ SyncReader.prototype.read = function(length, callback) {
2237
+
2238
+ this._reads.push({
2239
+ length: Math.abs(length), // if length < 0 then at most this length
2240
+ allowLess: length < 0,
2241
+ func: callback
2242
+ });
2243
+ };
2244
+
2245
+ SyncReader.prototype.process = function() {
2246
+
2247
+ // as long as there is any data and read requests
2248
+ while (this._reads.length > 0 && this._buffer.length) {
2249
+
2250
+ var read = this._reads[0];
2251
+
2252
+ if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
2253
+
2254
+ // ok there is any data so that we can satisfy this request
2255
+ this._reads.shift(); // == read
2256
+
2257
+ var buf = this._buffer;
2258
+
2259
+ this._buffer = buf.slice(read.length);
2260
+
2261
+ read.func.call(this, buf.slice(0, read.length));
2262
+
2263
+ }
2264
+ else {
2265
+ break;
2266
+ }
2267
+
2268
+ }
2269
+
2270
+ if (this._reads.length > 0) {
2271
+ return new Error('There are some read requests waitng on finished stream');
2272
+ }
2273
+
2274
+ if (this._buffer.length > 0) {
2275
+ return new Error('unrecognised content at end of stream');
2276
+ }
2277
+
2278
+ };
2279
+ });
2280
+
2281
+ var process_1 = function(inBuffer, bitmapInfo) {
2282
+
2283
+ var outBuffers = [];
2284
+ var reader = new syncReader(inBuffer);
2285
+ var filter = new filterParse(bitmapInfo, {
2286
+ read: reader.read.bind(reader),
2287
+ write: function(bufferPart) {
2288
+ outBuffers.push(bufferPart);
2289
+ },
2290
+ complete: function() {
2291
+ }
2292
+ });
2293
+
2294
+ filter.start();
2295
+ reader.process();
2296
+
2297
+ return Buffer.concat(outBuffers);
2298
+ };
2299
+
2300
+ var filterParseSync = {
2301
+ process: process_1
2302
+ };
2303
+
2304
+ var hasSyncZlib = true;
2305
+
2306
+
2307
+ if (!zlib.deflateSync) {
2308
+ hasSyncZlib = false;
2309
+ }
2310
+
2311
+
2312
+
2313
+
2314
+
2315
+
2316
+
2317
+ var parserSync = function(buffer, options) {
2318
+
2319
+ if (!hasSyncZlib) {
2320
+ throw new Error('To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0');
2321
+ }
2322
+
2323
+ var err;
2324
+ function handleError(_err_) {
2325
+ err = _err_;
2326
+ }
2327
+
2328
+ var metaData;
2329
+ function handleMetaData(_metaData_) {
2330
+ metaData = _metaData_;
2331
+ }
2332
+
2333
+ function handleTransColor(transColor) {
2334
+ metaData.transColor = transColor;
2335
+ }
2336
+
2337
+ function handlePalette(palette) {
2338
+ metaData.palette = palette;
2339
+ }
2340
+
2341
+ function handleSimpleTransparency() {
2342
+ metaData.alpha = true;
2343
+ }
2344
+
2345
+ var gamma;
2346
+ function handleGamma(_gamma_) {
2347
+ gamma = _gamma_;
2348
+ }
2349
+
2350
+ var inflateDataList = [];
2351
+ function handleInflateData(inflatedData) {
2352
+ inflateDataList.push(inflatedData);
2353
+ }
2354
+
2355
+ var reader = new syncReader(buffer);
2356
+
2357
+ var parser$1 = new parser(options, {
2358
+ read: reader.read.bind(reader),
2359
+ error: handleError,
2360
+ metadata: handleMetaData,
2361
+ gamma: handleGamma,
2362
+ palette: handlePalette,
2363
+ transColor: handleTransColor,
2364
+ inflateData: handleInflateData,
2365
+ simpleTransparency: handleSimpleTransparency
2366
+ });
2367
+
2368
+ parser$1.start();
2369
+ reader.process();
2370
+
2371
+ if (err) {
2372
+ throw err;
2373
+ }
2374
+
2375
+ //join together the inflate datas
2376
+ var inflateData = Buffer.concat(inflateDataList);
2377
+ inflateDataList.length = 0;
2378
+
2379
+ var inflatedData;
2380
+ if (metaData.interlace) {
2381
+ inflatedData = zlib.inflateSync(inflateData);
2382
+ }
2383
+ else {
2384
+ var rowSize = ((metaData.width * metaData.bpp * metaData.depth + 7) >> 3) + 1;
2385
+ var imageSize = rowSize * metaData.height;
2386
+ inflatedData = syncInflate(inflateData, { chunkSize: imageSize, maxLength: imageSize });
2387
+ }
2388
+ inflateData = null;
2389
+
2390
+ if (!inflatedData || !inflatedData.length) {
2391
+ throw new Error('bad png - invalid inflate data response');
2392
+ }
2393
+
2394
+ var unfilteredData = filterParseSync.process(inflatedData, metaData);
2395
+ inflateData = null;
2396
+
2397
+ var bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
2398
+ unfilteredData = null;
2399
+
2400
+ var normalisedBitmapData = formatNormaliser(bitmapData, metaData);
2401
+
2402
+ metaData.data = normalisedBitmapData;
2403
+ metaData.gamma = gamma || 0;
2404
+
2405
+ return metaData;
2406
+ };
2407
+
2408
+ var hasSyncZlib$1 = true;
2409
+
2410
+ if (!zlib.deflateSync) {
2411
+ hasSyncZlib$1 = false;
2412
+ }
2413
+
2414
+
2415
+
2416
+ var packerSync = function(metaData, opt) {
2417
+
2418
+ if (!hasSyncZlib$1) {
2419
+ throw new Error('To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0');
2420
+ }
2421
+
2422
+ var options = opt || {};
2423
+
2424
+ var packer$1 = new packer(options);
2425
+
2426
+ var chunks = [];
2427
+
2428
+ // Signature
2429
+ chunks.push(new Buffer(constants.PNG_SIGNATURE));
2430
+
2431
+ // Header
2432
+ chunks.push(packer$1.packIHDR(metaData.width, metaData.height));
2433
+
2434
+ if (metaData.gamma) {
2435
+ chunks.push(packer$1.packGAMA(metaData.gamma));
2436
+ }
2437
+
2438
+ var filteredData = packer$1.filterData(metaData.data, metaData.width, metaData.height);
2439
+
2440
+ // compress it
2441
+ var compressedData = zlib.deflateSync(filteredData, packer$1.getDeflateOptions());
2442
+ filteredData = null;
2443
+
2444
+ if (!compressedData || !compressedData.length) {
2445
+ throw new Error('bad png - invalid compressed data response');
2446
+ }
2447
+ chunks.push(packer$1.packIDAT(compressedData));
2448
+
2449
+ // End
2450
+ chunks.push(packer$1.packIEND());
2451
+
2452
+ return Buffer.concat(chunks);
2453
+ };
2454
+
2455
+ var read = function(buffer, options) {
2456
+
2457
+ return parserSync(buffer, options || {});
2458
+ };
2459
+
2460
+ var write = function(png, options) {
2461
+
2462
+ return packerSync(png, options);
2463
+ };
2464
+
2465
+ var pngSync = {
2466
+ read: read,
2467
+ write: write
2468
+ };
2469
+
2470
+ var png = createCommonjsModule(function (module, exports) {
2471
+
2472
+
2473
+
2474
+
2475
+
2476
+
2477
+
2478
+
2479
+ var PNG = exports.PNG = function(options) {
2480
+ stream.call(this);
2481
+
2482
+ options = options || {}; // eslint-disable-line no-param-reassign
2483
+
2484
+ // coerce pixel dimensions to integers (also coerces undefined -> 0):
2485
+ this.width = options.width | 0;
2486
+ this.height = options.height | 0;
2487
+
2488
+ this.data = this.width > 0 && this.height > 0 ?
2489
+ new Buffer(4 * this.width * this.height) : null;
2490
+
2491
+ if (options.fill && this.data) {
2492
+ this.data.fill(0);
2493
+ }
2494
+
2495
+ this.gamma = 0;
2496
+ this.readable = this.writable = true;
2497
+
2498
+ this._parser = new parserAsync(options);
2499
+
2500
+ this._parser.on('error', this.emit.bind(this, 'error'));
2501
+ this._parser.on('close', this._handleClose.bind(this));
2502
+ this._parser.on('metadata', this._metadata.bind(this));
2503
+ this._parser.on('gamma', this._gamma.bind(this));
2504
+ this._parser.on('parsed', function(data) {
2505
+ this.data = data;
2506
+ this.emit('parsed', data);
2507
+ }.bind(this));
2508
+
2509
+ this._packer = new packerAsync(options);
2510
+ this._packer.on('data', this.emit.bind(this, 'data'));
2511
+ this._packer.on('end', this.emit.bind(this, 'end'));
2512
+ this._parser.on('close', this._handleClose.bind(this));
2513
+ this._packer.on('error', this.emit.bind(this, 'error'));
2514
+
2515
+ };
2516
+ util.inherits(PNG, stream);
2517
+
2518
+ PNG.sync = pngSync;
2519
+
2520
+ PNG.prototype.pack = function() {
2521
+
2522
+ if (!this.data || !this.data.length) {
2523
+ this.emit('error', 'No data provided');
2524
+ return this;
2525
+ }
2526
+
2527
+ process.nextTick(function() {
2528
+ this._packer.pack(this.data, this.width, this.height, this.gamma);
2529
+ }.bind(this));
2530
+
2531
+ return this;
2532
+ };
2533
+
2534
+
2535
+ PNG.prototype.parse = function(data, callback) {
2536
+
2537
+ if (callback) {
2538
+ var onParsed, onError;
2539
+
2540
+ onParsed = function(parsedData) {
2541
+ this.removeListener('error', onError);
2542
+
2543
+ this.data = parsedData;
2544
+ callback(null, this);
2545
+ }.bind(this);
2546
+
2547
+ onError = function(err) {
2548
+ this.removeListener('parsed', onParsed);
2549
+
2550
+ callback(err, null);
2551
+ }.bind(this);
2552
+
2553
+ this.once('parsed', onParsed);
2554
+ this.once('error', onError);
2555
+ }
2556
+
2557
+ this.end(data);
2558
+ return this;
2559
+ };
2560
+
2561
+ PNG.prototype.write = function(data) {
2562
+ this._parser.write(data);
2563
+ return true;
2564
+ };
2565
+
2566
+ PNG.prototype.end = function(data) {
2567
+ this._parser.end(data);
2568
+ };
2569
+
2570
+ PNG.prototype._metadata = function(metadata) {
2571
+ this.width = metadata.width;
2572
+ this.height = metadata.height;
2573
+
2574
+ this.emit('metadata', metadata);
2575
+ };
2576
+
2577
+ PNG.prototype._gamma = function(gamma) {
2578
+ this.gamma = gamma;
2579
+ };
2580
+
2581
+ PNG.prototype._handleClose = function() {
2582
+ if (!this._parser.writable && !this._packer.readable) {
2583
+ this.emit('close');
2584
+ }
2585
+ };
2586
+
2587
+
2588
+ PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) { // eslint-disable-line max-params
2589
+ // coerce pixel dimensions to integers (also coerces undefined -> 0):
2590
+ /* eslint-disable no-param-reassign */
2591
+ srcX |= 0;
2592
+ srcY |= 0;
2593
+ width |= 0;
2594
+ height |= 0;
2595
+ deltaX |= 0;
2596
+ deltaY |= 0;
2597
+ /* eslint-enable no-param-reassign */
2598
+
2599
+ if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
2600
+ throw new Error('bitblt reading outside image');
2601
+ }
2602
+
2603
+ if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
2604
+ throw new Error('bitblt writing outside image');
2605
+ }
2606
+
2607
+ for (var y = 0; y < height; y++) {
2608
+ src.data.copy(dst.data,
2609
+ ((deltaY + y) * dst.width + deltaX) << 2,
2610
+ ((srcY + y) * src.width + srcX) << 2,
2611
+ ((srcY + y) * src.width + srcX + width) << 2
2612
+ );
2613
+ }
2614
+ };
2615
+
2616
+
2617
+ PNG.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) { // eslint-disable-line max-params
2618
+
2619
+ PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
2620
+ return this;
2621
+ };
2622
+
2623
+ PNG.adjustGamma = function(src) {
2624
+ if (src.gamma) {
2625
+ for (var y = 0; y < src.height; y++) {
2626
+ for (var x = 0; x < src.width; x++) {
2627
+ var idx = (src.width * y + x) << 2;
2628
+
2629
+ for (var i = 0; i < 3; i++) {
2630
+ var sample = src.data[idx + i] / 255;
2631
+ sample = Math.pow(sample, 1 / 2.2 / src.gamma);
2632
+ src.data[idx + i] = Math.round(sample * 255);
2633
+ }
2634
+ }
2635
+ }
2636
+ src.gamma = 0;
2637
+ }
2638
+ };
2639
+
2640
+ PNG.prototype.adjustGamma = function() {
2641
+ PNG.adjustGamma(this);
2642
+ };
2643
+ });
2644
+ var png_1 = png.PNG;
2645
+
2646
+ function getMismatchedPixels(pixelMatchInput) {
2647
+ const imgA = fs.createReadStream(pixelMatchInput.imageAPath).pipe(new png_1()).on('parsed', doneReading);
2648
+ const imgB = fs.createReadStream(pixelMatchInput.imageBPath).pipe(new png_1()).on('parsed', doneReading);
2649
+ let filesRead = 0;
2650
+ function doneReading() {
2651
+ if (++filesRead < 2)
2652
+ return;
2653
+ const mismatchedPixels = pixelmatch_1(imgA.data, imgB.data, null, pixelMatchInput.width, pixelMatchInput.height, {
2654
+ threshold: pixelMatchInput.pixelmatchThreshold,
2655
+ includeAA: false
2656
+ });
2657
+ process.send(mismatchedPixels);
2658
+ }
2659
+ }
2660
+ process.on('message', getMismatchedPixels);