@stencil/core 4.43.2 → 5.0.0-next.0
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.
- package/bin/stencil.mjs +2 -0
- package/dist/chunk-ClPoSABd.mjs +21 -0
- package/dist/client-DR9zhmKG.mjs +4449 -0
- package/dist/compiler/index.d.mts +187 -0
- package/dist/compiler/index.mjs +9 -0
- package/dist/compiler/utils/index.d.mts +3 -0
- package/dist/compiler/utils/index.mjs +5 -0
- package/dist/declarations/stencil-public-compiler.d.ts +4401 -0
- package/dist/declarations/stencil-public-compiler.js +53 -0
- package/dist/declarations/stencil-public-runtime.d.ts +1857 -0
- package/dist/index-Bxo2jCf6.d.mts +77 -0
- package/dist/index-szczUd2l.d.mts +6851 -0
- package/{internal/stencil-core/index.d.ts → dist/index.d.mts} +7 -3
- package/dist/index.mjs +4 -0
- package/dist/mock-doc.d.mts +1 -0
- package/dist/mock-doc.mjs +3 -0
- package/dist/node-sys-BGURUNOZ.mjs +1954 -0
- package/{internal → dist/runtime}/app-data/index.d.ts +11 -7
- package/dist/runtime/app-data/index.js +100 -0
- package/dist/runtime/app-globals/index.d.ts +5 -0
- package/dist/runtime/app-globals/index.js +6 -0
- package/dist/runtime/client/index.d.ts +2286 -0
- package/dist/runtime/client/index.js +4839 -0
- package/dist/runtime/index.d.ts +221 -0
- package/dist/runtime/index.js +4819 -0
- package/dist/runtime/server/index.d.mts +1277 -0
- package/dist/runtime/server/index.mjs +5376 -0
- package/dist/runtime/server/runner.d.mts +298 -0
- package/dist/runtime/server/runner.mjs +1976 -0
- package/dist/serialize-BJvhE9aQ.mjs +775 -0
- package/dist/stencil-private-Cgcr414u.d.ts +1893 -0
- package/dist/sys/node/index.d.mts +33 -0
- package/dist/sys/node/index.mjs +7 -0
- package/dist/sys/node/worker.d.mts +1 -0
- package/dist/sys/node/worker.mjs +60 -0
- package/dist/testing/index.d.mts +207 -0
- package/dist/testing/index.mjs +1188 -0
- package/dist/transpile-CJQcQEVa.mjs +21854 -0
- package/dist/validation-BdcPruW_.mjs +1451 -0
- package/package.json +88 -232
- package/bin/stencil +0 -57
- package/cli/config-flags.d.ts +0 -132
- package/cli/index.cjs +0 -5816
- package/cli/index.d.ts +0 -19
- package/cli/index.js +0 -5809
- package/cli/package.json +0 -14
- package/compiler/lib.d.ts +0 -22
- package/compiler/lib.decorators.d.ts +0 -384
- package/compiler/lib.decorators.legacy.d.ts +0 -22
- package/compiler/lib.dom.asynciterable.d.ts +0 -41
- package/compiler/lib.dom.d.ts +0 -29610
- package/compiler/lib.dom.iterable.d.ts +0 -493
- package/compiler/lib.es2015.collection.d.ts +0 -147
- package/compiler/lib.es2015.core.d.ts +0 -597
- package/compiler/lib.es2015.d.ts +0 -28
- package/compiler/lib.es2015.generator.d.ts +0 -77
- package/compiler/lib.es2015.iterable.d.ts +0 -605
- package/compiler/lib.es2015.promise.d.ts +0 -81
- package/compiler/lib.es2015.proxy.d.ts +0 -128
- package/compiler/lib.es2015.reflect.d.ts +0 -144
- package/compiler/lib.es2015.symbol.d.ts +0 -46
- package/compiler/lib.es2015.symbol.wellknown.d.ts +0 -326
- package/compiler/lib.es2016.array.include.d.ts +0 -116
- package/compiler/lib.es2016.d.ts +0 -21
- package/compiler/lib.es2016.full.d.ts +0 -23
- package/compiler/lib.es2016.intl.d.ts +0 -31
- package/compiler/lib.es2017.arraybuffer.d.ts +0 -21
- package/compiler/lib.es2017.d.ts +0 -26
- package/compiler/lib.es2017.date.d.ts +0 -31
- package/compiler/lib.es2017.full.d.ts +0 -23
- package/compiler/lib.es2017.intl.d.ts +0 -44
- package/compiler/lib.es2017.object.d.ts +0 -49
- package/compiler/lib.es2017.sharedmemory.d.ts +0 -135
- package/compiler/lib.es2017.string.d.ts +0 -45
- package/compiler/lib.es2017.typedarrays.d.ts +0 -53
- package/compiler/lib.es2018.asyncgenerator.d.ts +0 -77
- package/compiler/lib.es2018.asynciterable.d.ts +0 -53
- package/compiler/lib.es2018.d.ts +0 -24
- package/compiler/lib.es2018.full.d.ts +0 -24
- package/compiler/lib.es2018.intl.d.ts +0 -83
- package/compiler/lib.es2018.promise.d.ts +0 -30
- package/compiler/lib.es2018.regexp.d.ts +0 -37
- package/compiler/lib.es2019.array.d.ts +0 -79
- package/compiler/lib.es2019.d.ts +0 -24
- package/compiler/lib.es2019.full.d.ts +0 -24
- package/compiler/lib.es2019.intl.d.ts +0 -23
- package/compiler/lib.es2019.object.d.ts +0 -33
- package/compiler/lib.es2019.string.d.ts +0 -37
- package/compiler/lib.es2019.symbol.d.ts +0 -24
- package/compiler/lib.es2020.bigint.d.ts +0 -765
- package/compiler/lib.es2020.d.ts +0 -27
- package/compiler/lib.es2020.date.d.ts +0 -42
- package/compiler/lib.es2020.full.d.ts +0 -24
- package/compiler/lib.es2020.intl.d.ts +0 -474
- package/compiler/lib.es2020.number.d.ts +0 -28
- package/compiler/lib.es2020.promise.d.ts +0 -47
- package/compiler/lib.es2020.sharedmemory.d.ts +0 -99
- package/compiler/lib.es2020.string.d.ts +0 -44
- package/compiler/lib.es2020.symbol.wellknown.d.ts +0 -41
- package/compiler/lib.es2021.d.ts +0 -23
- package/compiler/lib.es2021.full.d.ts +0 -24
- package/compiler/lib.es2021.intl.d.ts +0 -166
- package/compiler/lib.es2021.promise.d.ts +0 -48
- package/compiler/lib.es2021.string.d.ts +0 -33
- package/compiler/lib.es2021.weakref.d.ts +0 -78
- package/compiler/lib.es2022.array.d.ts +0 -121
- package/compiler/lib.es2022.d.ts +0 -25
- package/compiler/lib.es2022.error.d.ts +0 -75
- package/compiler/lib.es2022.full.d.ts +0 -24
- package/compiler/lib.es2022.intl.d.ts +0 -121
- package/compiler/lib.es2022.object.d.ts +0 -26
- package/compiler/lib.es2022.regexp.d.ts +0 -39
- package/compiler/lib.es2022.string.d.ts +0 -25
- package/compiler/lib.es2023.array.d.ts +0 -924
- package/compiler/lib.es2023.collection.d.ts +0 -21
- package/compiler/lib.es2023.d.ts +0 -22
- package/compiler/lib.es2023.full.d.ts +0 -24
- package/compiler/lib.es2023.intl.d.ts +0 -56
- package/compiler/lib.es2024.arraybuffer.d.ts +0 -65
- package/compiler/lib.es2024.collection.d.ts +0 -29
- package/compiler/lib.es2024.d.ts +0 -26
- package/compiler/lib.es2024.full.d.ts +0 -24
- package/compiler/lib.es2024.object.d.ts +0 -29
- package/compiler/lib.es2024.promise.d.ts +0 -35
- package/compiler/lib.es2024.regexp.d.ts +0 -25
- package/compiler/lib.es2024.sharedmemory.d.ts +0 -68
- package/compiler/lib.es2024.string.d.ts +0 -29
- package/compiler/lib.es5.d.ts +0 -4594
- package/compiler/lib.es6.d.ts +0 -23
- package/compiler/lib.esnext.array.d.ts +0 -35
- package/compiler/lib.esnext.collection.d.ts +0 -96
- package/compiler/lib.esnext.d.ts +0 -27
- package/compiler/lib.esnext.decorators.d.ts +0 -28
- package/compiler/lib.esnext.disposable.d.ts +0 -193
- package/compiler/lib.esnext.float16.d.ts +0 -443
- package/compiler/lib.esnext.full.d.ts +0 -24
- package/compiler/lib.esnext.intl.d.ts +0 -21
- package/compiler/lib.esnext.iterator.d.ts +0 -148
- package/compiler/lib.esnext.promise.d.ts +0 -34
- package/compiler/lib.scripthost.d.ts +0 -322
- package/compiler/lib.webworker.asynciterable.d.ts +0 -41
- package/compiler/lib.webworker.d.ts +0 -9894
- package/compiler/lib.webworker.importscripts.d.ts +0 -23
- package/compiler/lib.webworker.iterable.d.ts +0 -287
- package/compiler/package.json +0 -8
- package/compiler/stencil.d.ts +0 -73
- package/compiler/stencil.js +0 -287816
- package/compiler/sys/in-memory-fs.d.ts +0 -227
- package/compiler/transpile.d.ts +0 -32
- package/dev-server/client/app-error.d.ts +0 -20
- package/dev-server/client/events.d.ts +0 -6
- package/dev-server/client/hmr-components.d.ts +0 -12
- package/dev-server/client/hmr-external-styles.d.ts +0 -1
- package/dev-server/client/hmr-images.d.ts +0 -1
- package/dev-server/client/hmr-inline-styles.d.ts +0 -1
- package/dev-server/client/hmr-util.d.ts +0 -39
- package/dev-server/client/hmr-window.d.ts +0 -10
- package/dev-server/client/index.d.ts +0 -6
- package/dev-server/client/index.js +0 -793
- package/dev-server/client/logger.d.ts +0 -6
- package/dev-server/client/package.json +0 -8
- package/dev-server/client/progress.d.ts +0 -3
- package/dev-server/client/status.d.ts +0 -4
- package/dev-server/client/test/hmr-util.spec.d.ts +0 -1
- package/dev-server/client/test/status.spec.d.ts +0 -1
- package/dev-server/connector.html +0 -6
- package/dev-server/index.d.ts +0 -3
- package/dev-server/index.js +0 -247
- package/dev-server/package.json +0 -8
- package/dev-server/server-process.js +0 -12095
- package/dev-server/server-worker-thread.js +0 -39
- package/dev-server/static/favicon.ico +0 -0
- package/dev-server/templates/directory-index.html +0 -176
- package/dev-server/templates/initial-load.html +0 -168
- package/dev-server/visualstudio.vbs +0 -82
- package/dev-server/xdg-open +0 -1066
- package/internal/app-data/index.cjs +0 -119
- package/internal/app-data/index.js +0 -92
- package/internal/app-data/package.json +0 -15
- package/internal/app-globals/index.d.ts +0 -2
- package/internal/app-globals/index.js +0 -14
- package/internal/app-globals/package.json +0 -14
- package/internal/child_process.d.ts +0 -7
- package/internal/client/index.js +0 -4736
- package/internal/client/package.json +0 -10
- package/internal/client/patch-browser.js +0 -45
- package/internal/client/polyfills/core-js.js +0 -11
- package/internal/client/polyfills/dom.js +0 -79
- package/internal/client/polyfills/es5-html-element.js +0 -1
- package/internal/client/polyfills/index.js +0 -34
- package/internal/client/polyfills/system.js +0 -6
- package/internal/client/shadow-css.js +0 -414
- package/internal/hydrate/index.js +0 -6671
- package/internal/hydrate/package.json +0 -7
- package/internal/hydrate/runner.d.ts +0 -287
- package/internal/hydrate/runner.js +0 -17950
- package/internal/index.d.ts +0 -4
- package/internal/index.js +0 -2
- package/internal/package.json +0 -9
- package/internal/stencil-core/index.cjs +0 -1
- package/internal/stencil-core/index.js +0 -18
- package/internal/stencil-core/jsx-dev-runtime.cjs +0 -7
- package/internal/stencil-core/jsx-dev-runtime.d.ts +0 -41
- package/internal/stencil-core/jsx-dev-runtime.js +0 -2
- package/internal/stencil-core/jsx-runtime.cjs +0 -8
- package/internal/stencil-core/jsx-runtime.d.ts +0 -40
- package/internal/stencil-core/jsx-runtime.js +0 -2
- package/internal/stencil-private.d.ts +0 -2549
- package/internal/stencil-public-compiler.d.ts +0 -2867
- package/internal/stencil-public-runtime.d.ts +0 -1860
- package/internal/testing/index.js +0 -6528
- package/internal/testing/jsx-dev-runtime.d.ts +0 -2
- package/internal/testing/jsx-dev-runtime.js +0 -8
- package/internal/testing/jsx-runtime.d.ts +0 -2
- package/internal/testing/jsx-runtime.js +0 -9
- package/internal/testing/package.json +0 -7
- package/internal/utils/index.d.ts +0 -1
- package/internal/utils/result.d.ts +0 -112
- package/mock-doc/index.cjs +0 -10165
- package/mock-doc/index.d.ts +0 -1172
- package/mock-doc/index.js +0 -10144
- package/mock-doc/package.json +0 -15
- package/readme.md +0 -94
- package/screenshot/compare/assets/favicon.ico +0 -0
- package/screenshot/compare/assets/logo.png +0 -0
- package/screenshot/compare/build/app.css +0 -1
- package/screenshot/compare/build/app.esm.js +0 -1
- package/screenshot/compare/build/app.js +0 -33
- package/screenshot/compare/build/p-081b0641.js +0 -1
- package/screenshot/compare/build/p-227a1e18.entry.js +0 -1
- package/screenshot/compare/build/p-2c298727.entry.js +0 -1
- package/screenshot/compare/build/p-5479268c.entry.js +0 -1
- package/screenshot/compare/build/p-573ec8a4.entry.js +0 -1
- package/screenshot/compare/build/p-6ba08604.entry.js +0 -1
- package/screenshot/compare/build/p-6bc63295.entry.js +0 -1
- package/screenshot/compare/build/p-7a3759fd.entry.js +0 -1
- package/screenshot/compare/build/p-7b4e3ba7.js +0 -1
- package/screenshot/compare/build/p-988eb362.css +0 -1
- package/screenshot/compare/build/p-9b6a9315.js +0 -1
- package/screenshot/compare/build/p-b4cc611c.entry.js +0 -1
- package/screenshot/compare/build/p-d1bf53f5.entry.js +0 -1
- package/screenshot/compare/build/p-e2efe0df.js +0 -1
- package/screenshot/compare/build/p-e8ca6d97.entry.js +0 -1
- package/screenshot/compare/build/p-ec2f13e0.entry.js +0 -1
- package/screenshot/compare/build/p-f0b99977.entry.js +0 -1
- package/screenshot/compare/build/p-f4745c2f.entry.js +0 -1
- package/screenshot/compare/build/p-fbbae598.js +0 -1
- package/screenshot/compare/host.config.json +0 -15
- package/screenshot/compare/index.html +0 -1
- package/screenshot/compare/manifest.json +0 -13
- package/screenshot/connector-base.d.ts +0 -42
- package/screenshot/connector-local.d.ts +0 -7
- package/screenshot/connector.js +0 -2
- package/screenshot/index.d.ts +0 -3
- package/screenshot/index.js +0 -2433
- package/screenshot/local-connector.js +0 -2
- package/screenshot/package.json +0 -15
- package/screenshot/pixel-match.d.ts +0 -1
- package/screenshot/pixel-match.js +0 -2315
- package/screenshot/screenshot-compare.d.ts +0 -20
- package/screenshot/screenshot-fs.d.ts +0 -14
- package/sys/node/460.node-fetch.js +0 -451
- package/sys/node/autoprefixer.js +0 -9
- package/sys/node/glob.js +0 -1
- package/sys/node/graceful-fs.js +0 -1
- package/sys/node/index.d.ts +0 -39
- package/sys/node/index.js +0 -64
- package/sys/node/node-fetch.js +0 -12
- package/sys/node/package.json +0 -8
- package/sys/node/prompts.js +0 -1
- package/sys/node/worker.js +0 -4
- package/testing/index.d.ts +0 -9
- package/testing/index.js +0 -13064
- package/testing/jest/jest-27-and-under/jest-config.d.ts +0 -16
- package/testing/jest/jest-27-and-under/jest-environment.d.ts +0 -2
- package/testing/jest/jest-27-and-under/jest-facade.d.ts +0 -155
- package/testing/jest/jest-27-and-under/jest-preprocessor.d.ts +0 -59
- package/testing/jest/jest-27-and-under/jest-preset.d.ts +0 -3
- package/testing/jest/jest-27-and-under/jest-runner.d.ts +0 -11
- package/testing/jest/jest-27-and-under/jest-screenshot.d.ts +0 -2
- package/testing/jest/jest-27-and-under/jest-serializer.d.ts +0 -4
- package/testing/jest/jest-27-and-under/jest-setup-test-framework.d.ts +0 -9
- package/testing/jest/jest-27-and-under/matchers/attributes.d.ts +0 -14
- package/testing/jest/jest-27-and-under/matchers/class-list.d.ts +0 -12
- package/testing/jest/jest-27-and-under/matchers/events.d.ts +0 -25
- package/testing/jest/jest-27-and-under/matchers/html.d.ts +0 -13
- package/testing/jest/jest-27-and-under/matchers/index.d.ts +0 -24
- package/testing/jest/jest-27-and-under/matchers/screenshot.d.ts +0 -5
- package/testing/jest/jest-27-and-under/matchers/text.d.ts +0 -4
- package/testing/jest/jest-27-and-under/test/jest-config.spec.d.ts +0 -1
- package/testing/jest/jest-27-and-under/test/jest-preprocessor.spec.d.ts +0 -1
- package/testing/jest/jest-27-and-under/test/jest-runner.spec.d.ts +0 -1
- package/testing/jest/jest-27-and-under/test/jest-serializer.spec.d.ts +0 -1
- package/testing/jest/jest-27-and-under/test/jest-setup-test-framework.spec.d.ts +0 -1
- package/testing/jest/jest-28/jest-config.d.ts +0 -16
- package/testing/jest/jest-28/jest-environment.d.ts +0 -2
- package/testing/jest/jest-28/jest-facade.d.ts +0 -134
- package/testing/jest/jest-28/jest-preprocessor.d.ts +0 -35
- package/testing/jest/jest-28/jest-preset.d.ts +0 -3
- package/testing/jest/jest-28/jest-runner.d.ts +0 -11
- package/testing/jest/jest-28/jest-screenshot.d.ts +0 -2
- package/testing/jest/jest-28/jest-serializer.d.ts +0 -4
- package/testing/jest/jest-28/jest-setup-test-framework.d.ts +0 -9
- package/testing/jest/jest-28/matchers/attributes.d.ts +0 -14
- package/testing/jest/jest-28/matchers/class-list.d.ts +0 -12
- package/testing/jest/jest-28/matchers/events.d.ts +0 -25
- package/testing/jest/jest-28/matchers/html.d.ts +0 -13
- package/testing/jest/jest-28/matchers/index.d.ts +0 -24
- package/testing/jest/jest-28/matchers/screenshot.d.ts +0 -5
- package/testing/jest/jest-28/matchers/text.d.ts +0 -4
- package/testing/jest/jest-28/test/jest-config.spec.d.ts +0 -1
- package/testing/jest/jest-28/test/jest-preprocessor.spec.d.ts +0 -1
- package/testing/jest/jest-28/test/jest-runner.spec.d.ts +0 -1
- package/testing/jest/jest-28/test/jest-serializer.spec.d.ts +0 -1
- package/testing/jest/jest-28/test/jest-setup-test-framework.spec.d.ts +0 -1
- package/testing/jest/jest-29/jest-config.d.ts +0 -16
- package/testing/jest/jest-29/jest-environment.d.ts +0 -2
- package/testing/jest/jest-29/jest-facade.d.ts +0 -136
- package/testing/jest/jest-29/jest-preprocessor.d.ts +0 -35
- package/testing/jest/jest-29/jest-preset.d.ts +0 -3
- package/testing/jest/jest-29/jest-runner.d.ts +0 -11
- package/testing/jest/jest-29/jest-screenshot.d.ts +0 -2
- package/testing/jest/jest-29/jest-serializer.d.ts +0 -4
- package/testing/jest/jest-29/jest-setup-test-framework.d.ts +0 -9
- package/testing/jest/jest-29/matchers/attributes.d.ts +0 -14
- package/testing/jest/jest-29/matchers/class-list.d.ts +0 -12
- package/testing/jest/jest-29/matchers/events.d.ts +0 -25
- package/testing/jest/jest-29/matchers/html.d.ts +0 -13
- package/testing/jest/jest-29/matchers/index.d.ts +0 -24
- package/testing/jest/jest-29/matchers/screenshot.d.ts +0 -5
- package/testing/jest/jest-29/matchers/text.d.ts +0 -4
- package/testing/jest/jest-29/test/jest-config.spec.d.ts +0 -1
- package/testing/jest/jest-29/test/jest-preprocessor.spec.d.ts +0 -1
- package/testing/jest/jest-29/test/jest-runner.spec.d.ts +0 -1
- package/testing/jest/jest-29/test/jest-serializer.spec.d.ts +0 -1
- package/testing/jest/jest-29/test/jest-setup-test-framework.spec.d.ts +0 -1
- package/testing/jest/jest-apis.d.ts +0 -86
- package/testing/jest/jest-facade.d.ts +0 -74
- package/testing/jest/jest-stencil-connector.d.ts +0 -65
- package/testing/jest/test/jest-stencil-connector.spec.d.ts +0 -1
- package/testing/jest-environment.js +0 -3
- package/testing/jest-preprocessor.js +0 -3
- package/testing/jest-preset.js +0 -2
- package/testing/jest-runner.js +0 -3
- package/testing/jest-setuptestframework.js +0 -3
- package/testing/mock-fetch.d.ts +0 -11
- package/testing/mocks.d.ts +0 -56
- package/testing/package.json +0 -8
- package/testing/puppeteer/index.d.ts +0 -2
- package/testing/puppeteer/puppeteer-browser.d.ts +0 -6
- package/testing/puppeteer/puppeteer-declarations.d.ts +0 -414
- package/testing/puppeteer/puppeteer-element.d.ts +0 -67
- package/testing/puppeteer/puppeteer-emulate.d.ts +0 -2
- package/testing/puppeteer/puppeteer-events.d.ts +0 -21
- package/testing/puppeteer/puppeteer-page.d.ts +0 -2
- package/testing/puppeteer/puppeteer-screenshot.d.ts +0 -27
- package/testing/puppeteer/test/puppeteer-screenshot.spec.d.ts +0 -1
- package/testing/reset-build-conditionals.d.ts +0 -12
- package/testing/spec-page.d.ts +0 -7
- package/testing/test/testing-utils.spec.d.ts +0 -1
- package/testing/test-transpile.d.ts +0 -2
- package/testing/testing-logger.d.ts +0 -26
- package/testing/testing-sys.d.ts +0 -6
- package/testing/testing-utils.d.ts +0 -80
- package/testing/testing.d.ts +0 -2
- /package/{internal → dist/declarations}/stencil-ext-modules.d.ts +0 -0
- /package/{internal → dist/declarations}/stencil-public-docs.d.ts +0 -0
- /package/{screenshot/compare/build/index.esm.js → dist/declarations/stencil-public-runtime.js} +0 -0
|
@@ -1,2315 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Stencil Screenshot Pixel Match v4.43.2 | MIT Licensed | https://stenciljs.com
|
|
3
|
-
*/
|
|
4
|
-
"use strict";
|
|
5
|
-
var __create = Object.create;
|
|
6
|
-
var __defProp = Object.defineProperty;
|
|
7
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
8
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
12
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
-
};
|
|
14
|
-
var __copyProps = (to, from, except, desc) => {
|
|
15
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
-
for (let key of __getOwnPropNames(from))
|
|
17
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
-
mod
|
|
29
|
-
));
|
|
30
|
-
|
|
31
|
-
// node_modules/pixelmatch/index.js
|
|
32
|
-
var require_pixelmatch = __commonJS({
|
|
33
|
-
"node_modules/pixelmatch/index.js"(exports2, module2) {
|
|
34
|
-
"use strict";
|
|
35
|
-
module2.exports = pixelmatch2;
|
|
36
|
-
var defaultOptions = {
|
|
37
|
-
threshold: 0.1,
|
|
38
|
-
// matching threshold (0 to 1); smaller is more sensitive
|
|
39
|
-
includeAA: false,
|
|
40
|
-
// whether to skip anti-aliasing detection
|
|
41
|
-
alpha: 0.1,
|
|
42
|
-
// opacity of original image in diff output
|
|
43
|
-
aaColor: [255, 255, 0],
|
|
44
|
-
// color of anti-aliased pixels in diff output
|
|
45
|
-
diffColor: [255, 0, 0],
|
|
46
|
-
// color of different pixels in diff output
|
|
47
|
-
diffColorAlt: null,
|
|
48
|
-
// whether to detect dark on light differences between img1 and img2 and set an alternative color to differentiate between the two
|
|
49
|
-
diffMask: false
|
|
50
|
-
// draw the diff over a transparent background (a mask)
|
|
51
|
-
};
|
|
52
|
-
function pixelmatch2(img1, img2, output, width, height, options) {
|
|
53
|
-
if (!isPixelData(img1) || !isPixelData(img2) || output && !isPixelData(output))
|
|
54
|
-
throw new Error("Image data: Uint8Array, Uint8ClampedArray or Buffer expected.");
|
|
55
|
-
if (img1.length !== img2.length || output && output.length !== img1.length)
|
|
56
|
-
throw new Error("Image sizes do not match.");
|
|
57
|
-
if (img1.length !== width * height * 4) throw new Error("Image data size does not match width/height.");
|
|
58
|
-
options = Object.assign({}, defaultOptions, options);
|
|
59
|
-
const len = width * height;
|
|
60
|
-
const a32 = new Uint32Array(img1.buffer, img1.byteOffset, len);
|
|
61
|
-
const b32 = new Uint32Array(img2.buffer, img2.byteOffset, len);
|
|
62
|
-
let identical = true;
|
|
63
|
-
for (let i = 0; i < len; i++) {
|
|
64
|
-
if (a32[i] !== b32[i]) {
|
|
65
|
-
identical = false;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (identical) {
|
|
70
|
-
if (output && !options.diffMask) {
|
|
71
|
-
for (let i = 0; i < len; i++) drawGrayPixel(img1, 4 * i, options.alpha, output);
|
|
72
|
-
}
|
|
73
|
-
return 0;
|
|
74
|
-
}
|
|
75
|
-
const maxDelta = 35215 * options.threshold * options.threshold;
|
|
76
|
-
let diff = 0;
|
|
77
|
-
for (let y = 0; y < height; y++) {
|
|
78
|
-
for (let x = 0; x < width; x++) {
|
|
79
|
-
const pos = (y * width + x) * 4;
|
|
80
|
-
const delta = colorDelta(img1, img2, pos, pos);
|
|
81
|
-
if (Math.abs(delta) > maxDelta) {
|
|
82
|
-
if (!options.includeAA && (antialiased(img1, x, y, width, height, img2) || antialiased(img2, x, y, width, height, img1))) {
|
|
83
|
-
if (output && !options.diffMask) drawPixel(output, pos, ...options.aaColor);
|
|
84
|
-
} else {
|
|
85
|
-
if (output) {
|
|
86
|
-
drawPixel(output, pos, ...delta < 0 && options.diffColorAlt || options.diffColor);
|
|
87
|
-
}
|
|
88
|
-
diff++;
|
|
89
|
-
}
|
|
90
|
-
} else if (output) {
|
|
91
|
-
if (!options.diffMask) drawGrayPixel(img1, pos, options.alpha, output);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return diff;
|
|
96
|
-
}
|
|
97
|
-
function isPixelData(arr) {
|
|
98
|
-
return ArrayBuffer.isView(arr) && arr.constructor.BYTES_PER_ELEMENT === 1;
|
|
99
|
-
}
|
|
100
|
-
function antialiased(img, x1, y1, width, height, img2) {
|
|
101
|
-
const x0 = Math.max(x1 - 1, 0);
|
|
102
|
-
const y0 = Math.max(y1 - 1, 0);
|
|
103
|
-
const x2 = Math.min(x1 + 1, width - 1);
|
|
104
|
-
const y2 = Math.min(y1 + 1, height - 1);
|
|
105
|
-
const pos = (y1 * width + x1) * 4;
|
|
106
|
-
let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
|
|
107
|
-
let min = 0;
|
|
108
|
-
let max = 0;
|
|
109
|
-
let minX, minY, maxX, maxY;
|
|
110
|
-
for (let x = x0; x <= x2; x++) {
|
|
111
|
-
for (let y = y0; y <= y2; y++) {
|
|
112
|
-
if (x === x1 && y === y1) continue;
|
|
113
|
-
const delta = colorDelta(img, img, pos, (y * width + x) * 4, true);
|
|
114
|
-
if (delta === 0) {
|
|
115
|
-
zeroes++;
|
|
116
|
-
if (zeroes > 2) return false;
|
|
117
|
-
} else if (delta < min) {
|
|
118
|
-
min = delta;
|
|
119
|
-
minX = x;
|
|
120
|
-
minY = y;
|
|
121
|
-
} else if (delta > max) {
|
|
122
|
-
max = delta;
|
|
123
|
-
maxX = x;
|
|
124
|
-
maxY = y;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (min === 0 || max === 0) return false;
|
|
129
|
-
return hasManySiblings(img, minX, minY, width, height) && hasManySiblings(img2, minX, minY, width, height) || hasManySiblings(img, maxX, maxY, width, height) && hasManySiblings(img2, maxX, maxY, width, height);
|
|
130
|
-
}
|
|
131
|
-
function hasManySiblings(img, x1, y1, width, height) {
|
|
132
|
-
const x0 = Math.max(x1 - 1, 0);
|
|
133
|
-
const y0 = Math.max(y1 - 1, 0);
|
|
134
|
-
const x2 = Math.min(x1 + 1, width - 1);
|
|
135
|
-
const y2 = Math.min(y1 + 1, height - 1);
|
|
136
|
-
const pos = (y1 * width + x1) * 4;
|
|
137
|
-
let zeroes = x1 === x0 || x1 === x2 || y1 === y0 || y1 === y2 ? 1 : 0;
|
|
138
|
-
for (let x = x0; x <= x2; x++) {
|
|
139
|
-
for (let y = y0; y <= y2; y++) {
|
|
140
|
-
if (x === x1 && y === y1) continue;
|
|
141
|
-
const pos2 = (y * width + x) * 4;
|
|
142
|
-
if (img[pos] === img[pos2] && img[pos + 1] === img[pos2 + 1] && img[pos + 2] === img[pos2 + 2] && img[pos + 3] === img[pos2 + 3]) zeroes++;
|
|
143
|
-
if (zeroes > 2) return true;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
function colorDelta(img1, img2, k, m, yOnly) {
|
|
149
|
-
let r1 = img1[k + 0];
|
|
150
|
-
let g1 = img1[k + 1];
|
|
151
|
-
let b1 = img1[k + 2];
|
|
152
|
-
let a1 = img1[k + 3];
|
|
153
|
-
let r2 = img2[m + 0];
|
|
154
|
-
let g2 = img2[m + 1];
|
|
155
|
-
let b2 = img2[m + 2];
|
|
156
|
-
let a2 = img2[m + 3];
|
|
157
|
-
if (a1 === a2 && r1 === r2 && g1 === g2 && b1 === b2) return 0;
|
|
158
|
-
if (a1 < 255) {
|
|
159
|
-
a1 /= 255;
|
|
160
|
-
r1 = blend(r1, a1);
|
|
161
|
-
g1 = blend(g1, a1);
|
|
162
|
-
b1 = blend(b1, a1);
|
|
163
|
-
}
|
|
164
|
-
if (a2 < 255) {
|
|
165
|
-
a2 /= 255;
|
|
166
|
-
r2 = blend(r2, a2);
|
|
167
|
-
g2 = blend(g2, a2);
|
|
168
|
-
b2 = blend(b2, a2);
|
|
169
|
-
}
|
|
170
|
-
const y1 = rgb2y(r1, g1, b1);
|
|
171
|
-
const y2 = rgb2y(r2, g2, b2);
|
|
172
|
-
const y = y1 - y2;
|
|
173
|
-
if (yOnly) return y;
|
|
174
|
-
const i = rgb2i(r1, g1, b1) - rgb2i(r2, g2, b2);
|
|
175
|
-
const q = rgb2q(r1, g1, b1) - rgb2q(r2, g2, b2);
|
|
176
|
-
const delta = 0.5053 * y * y + 0.299 * i * i + 0.1957 * q * q;
|
|
177
|
-
return y1 > y2 ? -delta : delta;
|
|
178
|
-
}
|
|
179
|
-
function rgb2y(r, g, b) {
|
|
180
|
-
return r * 0.29889531 + g * 0.58662247 + b * 0.11448223;
|
|
181
|
-
}
|
|
182
|
-
function rgb2i(r, g, b) {
|
|
183
|
-
return r * 0.59597799 - g * 0.2741761 - b * 0.32180189;
|
|
184
|
-
}
|
|
185
|
-
function rgb2q(r, g, b) {
|
|
186
|
-
return r * 0.21147017 - g * 0.52261711 + b * 0.31114694;
|
|
187
|
-
}
|
|
188
|
-
function blend(c, a) {
|
|
189
|
-
return 255 + (c - 255) * a;
|
|
190
|
-
}
|
|
191
|
-
function drawPixel(output, pos, r, g, b) {
|
|
192
|
-
output[pos + 0] = r;
|
|
193
|
-
output[pos + 1] = g;
|
|
194
|
-
output[pos + 2] = b;
|
|
195
|
-
output[pos + 3] = 255;
|
|
196
|
-
}
|
|
197
|
-
function drawGrayPixel(img, i, alpha, output) {
|
|
198
|
-
const r = img[i + 0];
|
|
199
|
-
const g = img[i + 1];
|
|
200
|
-
const b = img[i + 2];
|
|
201
|
-
const val = blend(rgb2y(r, g, b), alpha * img[i + 3] / 255);
|
|
202
|
-
drawPixel(output, i, val, val, val);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
// node_modules/pngjs/lib/chunkstream.js
|
|
208
|
-
var require_chunkstream = __commonJS({
|
|
209
|
-
"node_modules/pngjs/lib/chunkstream.js"(exports2, module2) {
|
|
210
|
-
"use strict";
|
|
211
|
-
var util = require("util");
|
|
212
|
-
var Stream = require("stream");
|
|
213
|
-
var ChunkStream = module2.exports = function() {
|
|
214
|
-
Stream.call(this);
|
|
215
|
-
this._buffers = [];
|
|
216
|
-
this._buffered = 0;
|
|
217
|
-
this._reads = [];
|
|
218
|
-
this._paused = false;
|
|
219
|
-
this._encoding = "utf8";
|
|
220
|
-
this.writable = true;
|
|
221
|
-
};
|
|
222
|
-
util.inherits(ChunkStream, Stream);
|
|
223
|
-
ChunkStream.prototype.read = function(length, callback) {
|
|
224
|
-
this._reads.push({
|
|
225
|
-
length: Math.abs(length),
|
|
226
|
-
// if length < 0 then at most this length
|
|
227
|
-
allowLess: length < 0,
|
|
228
|
-
func: callback
|
|
229
|
-
});
|
|
230
|
-
process.nextTick(
|
|
231
|
-
(function() {
|
|
232
|
-
this._process();
|
|
233
|
-
if (this._paused && this._reads && this._reads.length > 0) {
|
|
234
|
-
this._paused = false;
|
|
235
|
-
this.emit("drain");
|
|
236
|
-
}
|
|
237
|
-
}).bind(this)
|
|
238
|
-
);
|
|
239
|
-
};
|
|
240
|
-
ChunkStream.prototype.write = function(data, encoding) {
|
|
241
|
-
if (!this.writable) {
|
|
242
|
-
this.emit("error", new Error("Stream not writable"));
|
|
243
|
-
return false;
|
|
244
|
-
}
|
|
245
|
-
let dataBuffer;
|
|
246
|
-
if (Buffer.isBuffer(data)) {
|
|
247
|
-
dataBuffer = data;
|
|
248
|
-
} else {
|
|
249
|
-
dataBuffer = Buffer.from(data, encoding || this._encoding);
|
|
250
|
-
}
|
|
251
|
-
this._buffers.push(dataBuffer);
|
|
252
|
-
this._buffered += dataBuffer.length;
|
|
253
|
-
this._process();
|
|
254
|
-
if (this._reads && this._reads.length === 0) {
|
|
255
|
-
this._paused = true;
|
|
256
|
-
}
|
|
257
|
-
return this.writable && !this._paused;
|
|
258
|
-
};
|
|
259
|
-
ChunkStream.prototype.end = function(data, encoding) {
|
|
260
|
-
if (data) {
|
|
261
|
-
this.write(data, encoding);
|
|
262
|
-
}
|
|
263
|
-
this.writable = false;
|
|
264
|
-
if (!this._buffers) {
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
if (this._buffers.length === 0) {
|
|
268
|
-
this._end();
|
|
269
|
-
} else {
|
|
270
|
-
this._buffers.push(null);
|
|
271
|
-
this._process();
|
|
272
|
-
}
|
|
273
|
-
};
|
|
274
|
-
ChunkStream.prototype.destroySoon = ChunkStream.prototype.end;
|
|
275
|
-
ChunkStream.prototype._end = function() {
|
|
276
|
-
if (this._reads.length > 0) {
|
|
277
|
-
this.emit("error", new Error("Unexpected end of input"));
|
|
278
|
-
}
|
|
279
|
-
this.destroy();
|
|
280
|
-
};
|
|
281
|
-
ChunkStream.prototype.destroy = function() {
|
|
282
|
-
if (!this._buffers) {
|
|
283
|
-
return;
|
|
284
|
-
}
|
|
285
|
-
this.writable = false;
|
|
286
|
-
this._reads = null;
|
|
287
|
-
this._buffers = null;
|
|
288
|
-
this.emit("close");
|
|
289
|
-
};
|
|
290
|
-
ChunkStream.prototype._processReadAllowingLess = function(read) {
|
|
291
|
-
this._reads.shift();
|
|
292
|
-
let smallerBuf = this._buffers[0];
|
|
293
|
-
if (smallerBuf.length > read.length) {
|
|
294
|
-
this._buffered -= read.length;
|
|
295
|
-
this._buffers[0] = smallerBuf.slice(read.length);
|
|
296
|
-
read.func.call(this, smallerBuf.slice(0, read.length));
|
|
297
|
-
} else {
|
|
298
|
-
this._buffered -= smallerBuf.length;
|
|
299
|
-
this._buffers.shift();
|
|
300
|
-
read.func.call(this, smallerBuf);
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
ChunkStream.prototype._processRead = function(read) {
|
|
304
|
-
this._reads.shift();
|
|
305
|
-
let pos = 0;
|
|
306
|
-
let count = 0;
|
|
307
|
-
let data = Buffer.alloc(read.length);
|
|
308
|
-
while (pos < read.length) {
|
|
309
|
-
let buf = this._buffers[count++];
|
|
310
|
-
let len = Math.min(buf.length, read.length - pos);
|
|
311
|
-
buf.copy(data, pos, 0, len);
|
|
312
|
-
pos += len;
|
|
313
|
-
if (len !== buf.length) {
|
|
314
|
-
this._buffers[--count] = buf.slice(len);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
if (count > 0) {
|
|
318
|
-
this._buffers.splice(0, count);
|
|
319
|
-
}
|
|
320
|
-
this._buffered -= read.length;
|
|
321
|
-
read.func.call(this, data);
|
|
322
|
-
};
|
|
323
|
-
ChunkStream.prototype._process = function() {
|
|
324
|
-
try {
|
|
325
|
-
while (this._buffered > 0 && this._reads && this._reads.length > 0) {
|
|
326
|
-
let read = this._reads[0];
|
|
327
|
-
if (read.allowLess) {
|
|
328
|
-
this._processReadAllowingLess(read);
|
|
329
|
-
} else if (this._buffered >= read.length) {
|
|
330
|
-
this._processRead(read);
|
|
331
|
-
} else {
|
|
332
|
-
break;
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
if (this._buffers && !this.writable) {
|
|
336
|
-
this._end();
|
|
337
|
-
}
|
|
338
|
-
} catch (ex) {
|
|
339
|
-
this.emit("error", ex);
|
|
340
|
-
}
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
// node_modules/pngjs/lib/interlace.js
|
|
346
|
-
var require_interlace = __commonJS({
|
|
347
|
-
"node_modules/pngjs/lib/interlace.js"(exports2) {
|
|
348
|
-
"use strict";
|
|
349
|
-
var imagePasses = [
|
|
350
|
-
{
|
|
351
|
-
// pass 1 - 1px
|
|
352
|
-
x: [0],
|
|
353
|
-
y: [0]
|
|
354
|
-
},
|
|
355
|
-
{
|
|
356
|
-
// pass 2 - 1px
|
|
357
|
-
x: [4],
|
|
358
|
-
y: [0]
|
|
359
|
-
},
|
|
360
|
-
{
|
|
361
|
-
// pass 3 - 2px
|
|
362
|
-
x: [0, 4],
|
|
363
|
-
y: [4]
|
|
364
|
-
},
|
|
365
|
-
{
|
|
366
|
-
// pass 4 - 4px
|
|
367
|
-
x: [2, 6],
|
|
368
|
-
y: [0, 4]
|
|
369
|
-
},
|
|
370
|
-
{
|
|
371
|
-
// pass 5 - 8px
|
|
372
|
-
x: [0, 2, 4, 6],
|
|
373
|
-
y: [2, 6]
|
|
374
|
-
},
|
|
375
|
-
{
|
|
376
|
-
// pass 6 - 16px
|
|
377
|
-
x: [1, 3, 5, 7],
|
|
378
|
-
y: [0, 2, 4, 6]
|
|
379
|
-
},
|
|
380
|
-
{
|
|
381
|
-
// pass 7 - 32px
|
|
382
|
-
x: [0, 1, 2, 3, 4, 5, 6, 7],
|
|
383
|
-
y: [1, 3, 5, 7]
|
|
384
|
-
}
|
|
385
|
-
];
|
|
386
|
-
exports2.getImagePasses = function(width, height) {
|
|
387
|
-
let images = [];
|
|
388
|
-
let xLeftOver = width % 8;
|
|
389
|
-
let yLeftOver = height % 8;
|
|
390
|
-
let xRepeats = (width - xLeftOver) / 8;
|
|
391
|
-
let yRepeats = (height - yLeftOver) / 8;
|
|
392
|
-
for (let i = 0; i < imagePasses.length; i++) {
|
|
393
|
-
let pass = imagePasses[i];
|
|
394
|
-
let passWidth = xRepeats * pass.x.length;
|
|
395
|
-
let passHeight = yRepeats * pass.y.length;
|
|
396
|
-
for (let j = 0; j < pass.x.length; j++) {
|
|
397
|
-
if (pass.x[j] < xLeftOver) {
|
|
398
|
-
passWidth++;
|
|
399
|
-
} else {
|
|
400
|
-
break;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
for (let j = 0; j < pass.y.length; j++) {
|
|
404
|
-
if (pass.y[j] < yLeftOver) {
|
|
405
|
-
passHeight++;
|
|
406
|
-
} else {
|
|
407
|
-
break;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
if (passWidth > 0 && passHeight > 0) {
|
|
411
|
-
images.push({ width: passWidth, height: passHeight, index: i });
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
return images;
|
|
415
|
-
};
|
|
416
|
-
exports2.getInterlaceIterator = function(width) {
|
|
417
|
-
return function(x, y, pass) {
|
|
418
|
-
let outerXLeftOver = x % imagePasses[pass].x.length;
|
|
419
|
-
let outerX = (x - outerXLeftOver) / imagePasses[pass].x.length * 8 + imagePasses[pass].x[outerXLeftOver];
|
|
420
|
-
let outerYLeftOver = y % imagePasses[pass].y.length;
|
|
421
|
-
let outerY = (y - outerYLeftOver) / imagePasses[pass].y.length * 8 + imagePasses[pass].y[outerYLeftOver];
|
|
422
|
-
return outerX * 4 + outerY * width * 4;
|
|
423
|
-
};
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
// node_modules/pngjs/lib/paeth-predictor.js
|
|
429
|
-
var require_paeth_predictor = __commonJS({
|
|
430
|
-
"node_modules/pngjs/lib/paeth-predictor.js"(exports2, module2) {
|
|
431
|
-
"use strict";
|
|
432
|
-
module2.exports = function paethPredictor(left, above, upLeft) {
|
|
433
|
-
let paeth = left + above - upLeft;
|
|
434
|
-
let pLeft = Math.abs(paeth - left);
|
|
435
|
-
let pAbove = Math.abs(paeth - above);
|
|
436
|
-
let pUpLeft = Math.abs(paeth - upLeft);
|
|
437
|
-
if (pLeft <= pAbove && pLeft <= pUpLeft) {
|
|
438
|
-
return left;
|
|
439
|
-
}
|
|
440
|
-
if (pAbove <= pUpLeft) {
|
|
441
|
-
return above;
|
|
442
|
-
}
|
|
443
|
-
return upLeft;
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
// node_modules/pngjs/lib/filter-parse.js
|
|
449
|
-
var require_filter_parse = __commonJS({
|
|
450
|
-
"node_modules/pngjs/lib/filter-parse.js"(exports2, module2) {
|
|
451
|
-
"use strict";
|
|
452
|
-
var interlaceUtils = require_interlace();
|
|
453
|
-
var paethPredictor = require_paeth_predictor();
|
|
454
|
-
function getByteWidth(width, bpp, depth) {
|
|
455
|
-
let byteWidth = width * bpp;
|
|
456
|
-
if (depth !== 8) {
|
|
457
|
-
byteWidth = Math.ceil(byteWidth / (8 / depth));
|
|
458
|
-
}
|
|
459
|
-
return byteWidth;
|
|
460
|
-
}
|
|
461
|
-
var Filter = module2.exports = function(bitmapInfo, dependencies) {
|
|
462
|
-
let width = bitmapInfo.width;
|
|
463
|
-
let height = bitmapInfo.height;
|
|
464
|
-
let interlace = bitmapInfo.interlace;
|
|
465
|
-
let bpp = bitmapInfo.bpp;
|
|
466
|
-
let depth = bitmapInfo.depth;
|
|
467
|
-
this.read = dependencies.read;
|
|
468
|
-
this.write = dependencies.write;
|
|
469
|
-
this.complete = dependencies.complete;
|
|
470
|
-
this._imageIndex = 0;
|
|
471
|
-
this._images = [];
|
|
472
|
-
if (interlace) {
|
|
473
|
-
let passes = interlaceUtils.getImagePasses(width, height);
|
|
474
|
-
for (let i = 0; i < passes.length; i++) {
|
|
475
|
-
this._images.push({
|
|
476
|
-
byteWidth: getByteWidth(passes[i].width, bpp, depth),
|
|
477
|
-
height: passes[i].height,
|
|
478
|
-
lineIndex: 0
|
|
479
|
-
});
|
|
480
|
-
}
|
|
481
|
-
} else {
|
|
482
|
-
this._images.push({
|
|
483
|
-
byteWidth: getByteWidth(width, bpp, depth),
|
|
484
|
-
height,
|
|
485
|
-
lineIndex: 0
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
|
-
if (depth === 8) {
|
|
489
|
-
this._xComparison = bpp;
|
|
490
|
-
} else if (depth === 16) {
|
|
491
|
-
this._xComparison = bpp * 2;
|
|
492
|
-
} else {
|
|
493
|
-
this._xComparison = 1;
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
Filter.prototype.start = function() {
|
|
497
|
-
this.read(
|
|
498
|
-
this._images[this._imageIndex].byteWidth + 1,
|
|
499
|
-
this._reverseFilterLine.bind(this)
|
|
500
|
-
);
|
|
501
|
-
};
|
|
502
|
-
Filter.prototype._unFilterType1 = function(rawData, unfilteredLine, byteWidth) {
|
|
503
|
-
let xComparison = this._xComparison;
|
|
504
|
-
let xBiggerThan = xComparison - 1;
|
|
505
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
506
|
-
let rawByte = rawData[1 + x];
|
|
507
|
-
let f1Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
|
|
508
|
-
unfilteredLine[x] = rawByte + f1Left;
|
|
509
|
-
}
|
|
510
|
-
};
|
|
511
|
-
Filter.prototype._unFilterType2 = function(rawData, unfilteredLine, byteWidth) {
|
|
512
|
-
let lastLine = this._lastLine;
|
|
513
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
514
|
-
let rawByte = rawData[1 + x];
|
|
515
|
-
let f2Up = lastLine ? lastLine[x] : 0;
|
|
516
|
-
unfilteredLine[x] = rawByte + f2Up;
|
|
517
|
-
}
|
|
518
|
-
};
|
|
519
|
-
Filter.prototype._unFilterType3 = function(rawData, unfilteredLine, byteWidth) {
|
|
520
|
-
let xComparison = this._xComparison;
|
|
521
|
-
let xBiggerThan = xComparison - 1;
|
|
522
|
-
let lastLine = this._lastLine;
|
|
523
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
524
|
-
let rawByte = rawData[1 + x];
|
|
525
|
-
let f3Up = lastLine ? lastLine[x] : 0;
|
|
526
|
-
let f3Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
|
|
527
|
-
let f3Add = Math.floor((f3Left + f3Up) / 2);
|
|
528
|
-
unfilteredLine[x] = rawByte + f3Add;
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
Filter.prototype._unFilterType4 = function(rawData, unfilteredLine, byteWidth) {
|
|
532
|
-
let xComparison = this._xComparison;
|
|
533
|
-
let xBiggerThan = xComparison - 1;
|
|
534
|
-
let lastLine = this._lastLine;
|
|
535
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
536
|
-
let rawByte = rawData[1 + x];
|
|
537
|
-
let f4Up = lastLine ? lastLine[x] : 0;
|
|
538
|
-
let f4Left = x > xBiggerThan ? unfilteredLine[x - xComparison] : 0;
|
|
539
|
-
let f4UpLeft = x > xBiggerThan && lastLine ? lastLine[x - xComparison] : 0;
|
|
540
|
-
let f4Add = paethPredictor(f4Left, f4Up, f4UpLeft);
|
|
541
|
-
unfilteredLine[x] = rawByte + f4Add;
|
|
542
|
-
}
|
|
543
|
-
};
|
|
544
|
-
Filter.prototype._reverseFilterLine = function(rawData) {
|
|
545
|
-
let filter = rawData[0];
|
|
546
|
-
let unfilteredLine;
|
|
547
|
-
let currentImage = this._images[this._imageIndex];
|
|
548
|
-
let byteWidth = currentImage.byteWidth;
|
|
549
|
-
if (filter === 0) {
|
|
550
|
-
unfilteredLine = rawData.slice(1, byteWidth + 1);
|
|
551
|
-
} else {
|
|
552
|
-
unfilteredLine = Buffer.alloc(byteWidth);
|
|
553
|
-
switch (filter) {
|
|
554
|
-
case 1:
|
|
555
|
-
this._unFilterType1(rawData, unfilteredLine, byteWidth);
|
|
556
|
-
break;
|
|
557
|
-
case 2:
|
|
558
|
-
this._unFilterType2(rawData, unfilteredLine, byteWidth);
|
|
559
|
-
break;
|
|
560
|
-
case 3:
|
|
561
|
-
this._unFilterType3(rawData, unfilteredLine, byteWidth);
|
|
562
|
-
break;
|
|
563
|
-
case 4:
|
|
564
|
-
this._unFilterType4(rawData, unfilteredLine, byteWidth);
|
|
565
|
-
break;
|
|
566
|
-
default:
|
|
567
|
-
throw new Error("Unrecognised filter type - " + filter);
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
this.write(unfilteredLine);
|
|
571
|
-
currentImage.lineIndex++;
|
|
572
|
-
if (currentImage.lineIndex >= currentImage.height) {
|
|
573
|
-
this._lastLine = null;
|
|
574
|
-
this._imageIndex++;
|
|
575
|
-
currentImage = this._images[this._imageIndex];
|
|
576
|
-
} else {
|
|
577
|
-
this._lastLine = unfilteredLine;
|
|
578
|
-
}
|
|
579
|
-
if (currentImage) {
|
|
580
|
-
this.read(currentImage.byteWidth + 1, this._reverseFilterLine.bind(this));
|
|
581
|
-
} else {
|
|
582
|
-
this._lastLine = null;
|
|
583
|
-
this.complete();
|
|
584
|
-
}
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
|
|
589
|
-
// node_modules/pngjs/lib/filter-parse-async.js
|
|
590
|
-
var require_filter_parse_async = __commonJS({
|
|
591
|
-
"node_modules/pngjs/lib/filter-parse-async.js"(exports2, module2) {
|
|
592
|
-
"use strict";
|
|
593
|
-
var util = require("util");
|
|
594
|
-
var ChunkStream = require_chunkstream();
|
|
595
|
-
var Filter = require_filter_parse();
|
|
596
|
-
var FilterAsync = module2.exports = function(bitmapInfo) {
|
|
597
|
-
ChunkStream.call(this);
|
|
598
|
-
let buffers = [];
|
|
599
|
-
let that = this;
|
|
600
|
-
this._filter = new Filter(bitmapInfo, {
|
|
601
|
-
read: this.read.bind(this),
|
|
602
|
-
write: function(buffer) {
|
|
603
|
-
buffers.push(buffer);
|
|
604
|
-
},
|
|
605
|
-
complete: function() {
|
|
606
|
-
that.emit("complete", Buffer.concat(buffers));
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
this._filter.start();
|
|
610
|
-
};
|
|
611
|
-
util.inherits(FilterAsync, ChunkStream);
|
|
612
|
-
}
|
|
613
|
-
});
|
|
614
|
-
|
|
615
|
-
// node_modules/pngjs/lib/constants.js
|
|
616
|
-
var require_constants = __commonJS({
|
|
617
|
-
"node_modules/pngjs/lib/constants.js"(exports2, module2) {
|
|
618
|
-
"use strict";
|
|
619
|
-
module2.exports = {
|
|
620
|
-
PNG_SIGNATURE: [137, 80, 78, 71, 13, 10, 26, 10],
|
|
621
|
-
TYPE_IHDR: 1229472850,
|
|
622
|
-
TYPE_IEND: 1229278788,
|
|
623
|
-
TYPE_IDAT: 1229209940,
|
|
624
|
-
TYPE_PLTE: 1347179589,
|
|
625
|
-
TYPE_tRNS: 1951551059,
|
|
626
|
-
// eslint-disable-line camelcase
|
|
627
|
-
TYPE_gAMA: 1732332865,
|
|
628
|
-
// eslint-disable-line camelcase
|
|
629
|
-
// color-type bits
|
|
630
|
-
COLORTYPE_GRAYSCALE: 0,
|
|
631
|
-
COLORTYPE_PALETTE: 1,
|
|
632
|
-
COLORTYPE_COLOR: 2,
|
|
633
|
-
COLORTYPE_ALPHA: 4,
|
|
634
|
-
// e.g. grayscale and alpha
|
|
635
|
-
// color-type combinations
|
|
636
|
-
COLORTYPE_PALETTE_COLOR: 3,
|
|
637
|
-
COLORTYPE_COLOR_ALPHA: 6,
|
|
638
|
-
COLORTYPE_TO_BPP_MAP: {
|
|
639
|
-
0: 1,
|
|
640
|
-
2: 3,
|
|
641
|
-
3: 1,
|
|
642
|
-
4: 2,
|
|
643
|
-
6: 4
|
|
644
|
-
},
|
|
645
|
-
GAMMA_DIVISION: 1e5
|
|
646
|
-
};
|
|
647
|
-
}
|
|
648
|
-
});
|
|
649
|
-
|
|
650
|
-
// node_modules/pngjs/lib/crc.js
|
|
651
|
-
var require_crc = __commonJS({
|
|
652
|
-
"node_modules/pngjs/lib/crc.js"(exports2, module2) {
|
|
653
|
-
"use strict";
|
|
654
|
-
var crcTable = [];
|
|
655
|
-
(function() {
|
|
656
|
-
for (let i = 0; i < 256; i++) {
|
|
657
|
-
let currentCrc = i;
|
|
658
|
-
for (let j = 0; j < 8; j++) {
|
|
659
|
-
if (currentCrc & 1) {
|
|
660
|
-
currentCrc = 3988292384 ^ currentCrc >>> 1;
|
|
661
|
-
} else {
|
|
662
|
-
currentCrc = currentCrc >>> 1;
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
crcTable[i] = currentCrc;
|
|
666
|
-
}
|
|
667
|
-
})();
|
|
668
|
-
var CrcCalculator = module2.exports = function() {
|
|
669
|
-
this._crc = -1;
|
|
670
|
-
};
|
|
671
|
-
CrcCalculator.prototype.write = function(data) {
|
|
672
|
-
for (let i = 0; i < data.length; i++) {
|
|
673
|
-
this._crc = crcTable[(this._crc ^ data[i]) & 255] ^ this._crc >>> 8;
|
|
674
|
-
}
|
|
675
|
-
return true;
|
|
676
|
-
};
|
|
677
|
-
CrcCalculator.prototype.crc32 = function() {
|
|
678
|
-
return this._crc ^ -1;
|
|
679
|
-
};
|
|
680
|
-
CrcCalculator.crc32 = function(buf) {
|
|
681
|
-
let crc = -1;
|
|
682
|
-
for (let i = 0; i < buf.length; i++) {
|
|
683
|
-
crc = crcTable[(crc ^ buf[i]) & 255] ^ crc >>> 8;
|
|
684
|
-
}
|
|
685
|
-
return crc ^ -1;
|
|
686
|
-
};
|
|
687
|
-
}
|
|
688
|
-
});
|
|
689
|
-
|
|
690
|
-
// node_modules/pngjs/lib/parser.js
|
|
691
|
-
var require_parser = __commonJS({
|
|
692
|
-
"node_modules/pngjs/lib/parser.js"(exports2, module2) {
|
|
693
|
-
"use strict";
|
|
694
|
-
var constants = require_constants();
|
|
695
|
-
var CrcCalculator = require_crc();
|
|
696
|
-
var Parser = module2.exports = function(options, dependencies) {
|
|
697
|
-
this._options = options;
|
|
698
|
-
options.checkCRC = options.checkCRC !== false;
|
|
699
|
-
this._hasIHDR = false;
|
|
700
|
-
this._hasIEND = false;
|
|
701
|
-
this._emittedHeadersFinished = false;
|
|
702
|
-
this._palette = [];
|
|
703
|
-
this._colorType = 0;
|
|
704
|
-
this._chunks = {};
|
|
705
|
-
this._chunks[constants.TYPE_IHDR] = this._handleIHDR.bind(this);
|
|
706
|
-
this._chunks[constants.TYPE_IEND] = this._handleIEND.bind(this);
|
|
707
|
-
this._chunks[constants.TYPE_IDAT] = this._handleIDAT.bind(this);
|
|
708
|
-
this._chunks[constants.TYPE_PLTE] = this._handlePLTE.bind(this);
|
|
709
|
-
this._chunks[constants.TYPE_tRNS] = this._handleTRNS.bind(this);
|
|
710
|
-
this._chunks[constants.TYPE_gAMA] = this._handleGAMA.bind(this);
|
|
711
|
-
this.read = dependencies.read;
|
|
712
|
-
this.error = dependencies.error;
|
|
713
|
-
this.metadata = dependencies.metadata;
|
|
714
|
-
this.gamma = dependencies.gamma;
|
|
715
|
-
this.transColor = dependencies.transColor;
|
|
716
|
-
this.palette = dependencies.palette;
|
|
717
|
-
this.parsed = dependencies.parsed;
|
|
718
|
-
this.inflateData = dependencies.inflateData;
|
|
719
|
-
this.finished = dependencies.finished;
|
|
720
|
-
this.simpleTransparency = dependencies.simpleTransparency;
|
|
721
|
-
this.headersFinished = dependencies.headersFinished || function() {
|
|
722
|
-
};
|
|
723
|
-
};
|
|
724
|
-
Parser.prototype.start = function() {
|
|
725
|
-
this.read(constants.PNG_SIGNATURE.length, this._parseSignature.bind(this));
|
|
726
|
-
};
|
|
727
|
-
Parser.prototype._parseSignature = function(data) {
|
|
728
|
-
let signature = constants.PNG_SIGNATURE;
|
|
729
|
-
for (let i = 0; i < signature.length; i++) {
|
|
730
|
-
if (data[i] !== signature[i]) {
|
|
731
|
-
this.error(new Error("Invalid file signature"));
|
|
732
|
-
return;
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
this.read(8, this._parseChunkBegin.bind(this));
|
|
736
|
-
};
|
|
737
|
-
Parser.prototype._parseChunkBegin = function(data) {
|
|
738
|
-
let length = data.readUInt32BE(0);
|
|
739
|
-
let type = data.readUInt32BE(4);
|
|
740
|
-
let name = "";
|
|
741
|
-
for (let i = 4; i < 8; i++) {
|
|
742
|
-
name += String.fromCharCode(data[i]);
|
|
743
|
-
}
|
|
744
|
-
let ancillary = Boolean(data[4] & 32);
|
|
745
|
-
if (!this._hasIHDR && type !== constants.TYPE_IHDR) {
|
|
746
|
-
this.error(new Error("Expected IHDR on beggining"));
|
|
747
|
-
return;
|
|
748
|
-
}
|
|
749
|
-
this._crc = new CrcCalculator();
|
|
750
|
-
this._crc.write(Buffer.from(name));
|
|
751
|
-
if (this._chunks[type]) {
|
|
752
|
-
return this._chunks[type](length);
|
|
753
|
-
}
|
|
754
|
-
if (!ancillary) {
|
|
755
|
-
this.error(new Error("Unsupported critical chunk type " + name));
|
|
756
|
-
return;
|
|
757
|
-
}
|
|
758
|
-
this.read(length + 4, this._skipChunk.bind(this));
|
|
759
|
-
};
|
|
760
|
-
Parser.prototype._skipChunk = function() {
|
|
761
|
-
this.read(8, this._parseChunkBegin.bind(this));
|
|
762
|
-
};
|
|
763
|
-
Parser.prototype._handleChunkEnd = function() {
|
|
764
|
-
this.read(4, this._parseChunkEnd.bind(this));
|
|
765
|
-
};
|
|
766
|
-
Parser.prototype._parseChunkEnd = function(data) {
|
|
767
|
-
let fileCrc = data.readInt32BE(0);
|
|
768
|
-
let calcCrc = this._crc.crc32();
|
|
769
|
-
if (this._options.checkCRC && calcCrc !== fileCrc) {
|
|
770
|
-
this.error(new Error("Crc error - " + fileCrc + " - " + calcCrc));
|
|
771
|
-
return;
|
|
772
|
-
}
|
|
773
|
-
if (!this._hasIEND) {
|
|
774
|
-
this.read(8, this._parseChunkBegin.bind(this));
|
|
775
|
-
}
|
|
776
|
-
};
|
|
777
|
-
Parser.prototype._handleIHDR = function(length) {
|
|
778
|
-
this.read(length, this._parseIHDR.bind(this));
|
|
779
|
-
};
|
|
780
|
-
Parser.prototype._parseIHDR = function(data) {
|
|
781
|
-
this._crc.write(data);
|
|
782
|
-
let width = data.readUInt32BE(0);
|
|
783
|
-
let height = data.readUInt32BE(4);
|
|
784
|
-
let depth = data[8];
|
|
785
|
-
let colorType = data[9];
|
|
786
|
-
let compr = data[10];
|
|
787
|
-
let filter = data[11];
|
|
788
|
-
let interlace = data[12];
|
|
789
|
-
if (depth !== 8 && depth !== 4 && depth !== 2 && depth !== 1 && depth !== 16) {
|
|
790
|
-
this.error(new Error("Unsupported bit depth " + depth));
|
|
791
|
-
return;
|
|
792
|
-
}
|
|
793
|
-
if (!(colorType in constants.COLORTYPE_TO_BPP_MAP)) {
|
|
794
|
-
this.error(new Error("Unsupported color type"));
|
|
795
|
-
return;
|
|
796
|
-
}
|
|
797
|
-
if (compr !== 0) {
|
|
798
|
-
this.error(new Error("Unsupported compression method"));
|
|
799
|
-
return;
|
|
800
|
-
}
|
|
801
|
-
if (filter !== 0) {
|
|
802
|
-
this.error(new Error("Unsupported filter method"));
|
|
803
|
-
return;
|
|
804
|
-
}
|
|
805
|
-
if (interlace !== 0 && interlace !== 1) {
|
|
806
|
-
this.error(new Error("Unsupported interlace method"));
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
|
-
this._colorType = colorType;
|
|
810
|
-
let bpp = constants.COLORTYPE_TO_BPP_MAP[this._colorType];
|
|
811
|
-
this._hasIHDR = true;
|
|
812
|
-
this.metadata({
|
|
813
|
-
width,
|
|
814
|
-
height,
|
|
815
|
-
depth,
|
|
816
|
-
interlace: Boolean(interlace),
|
|
817
|
-
palette: Boolean(colorType & constants.COLORTYPE_PALETTE),
|
|
818
|
-
color: Boolean(colorType & constants.COLORTYPE_COLOR),
|
|
819
|
-
alpha: Boolean(colorType & constants.COLORTYPE_ALPHA),
|
|
820
|
-
bpp,
|
|
821
|
-
colorType
|
|
822
|
-
});
|
|
823
|
-
this._handleChunkEnd();
|
|
824
|
-
};
|
|
825
|
-
Parser.prototype._handlePLTE = function(length) {
|
|
826
|
-
this.read(length, this._parsePLTE.bind(this));
|
|
827
|
-
};
|
|
828
|
-
Parser.prototype._parsePLTE = function(data) {
|
|
829
|
-
this._crc.write(data);
|
|
830
|
-
let entries = Math.floor(data.length / 3);
|
|
831
|
-
for (let i = 0; i < entries; i++) {
|
|
832
|
-
this._palette.push([data[i * 3], data[i * 3 + 1], data[i * 3 + 2], 255]);
|
|
833
|
-
}
|
|
834
|
-
this.palette(this._palette);
|
|
835
|
-
this._handleChunkEnd();
|
|
836
|
-
};
|
|
837
|
-
Parser.prototype._handleTRNS = function(length) {
|
|
838
|
-
this.simpleTransparency();
|
|
839
|
-
this.read(length, this._parseTRNS.bind(this));
|
|
840
|
-
};
|
|
841
|
-
Parser.prototype._parseTRNS = function(data) {
|
|
842
|
-
this._crc.write(data);
|
|
843
|
-
if (this._colorType === constants.COLORTYPE_PALETTE_COLOR) {
|
|
844
|
-
if (this._palette.length === 0) {
|
|
845
|
-
this.error(new Error("Transparency chunk must be after palette"));
|
|
846
|
-
return;
|
|
847
|
-
}
|
|
848
|
-
if (data.length > this._palette.length) {
|
|
849
|
-
this.error(new Error("More transparent colors than palette size"));
|
|
850
|
-
return;
|
|
851
|
-
}
|
|
852
|
-
for (let i = 0; i < data.length; i++) {
|
|
853
|
-
this._palette[i][3] = data[i];
|
|
854
|
-
}
|
|
855
|
-
this.palette(this._palette);
|
|
856
|
-
}
|
|
857
|
-
if (this._colorType === constants.COLORTYPE_GRAYSCALE) {
|
|
858
|
-
this.transColor([data.readUInt16BE(0)]);
|
|
859
|
-
}
|
|
860
|
-
if (this._colorType === constants.COLORTYPE_COLOR) {
|
|
861
|
-
this.transColor([
|
|
862
|
-
data.readUInt16BE(0),
|
|
863
|
-
data.readUInt16BE(2),
|
|
864
|
-
data.readUInt16BE(4)
|
|
865
|
-
]);
|
|
866
|
-
}
|
|
867
|
-
this._handleChunkEnd();
|
|
868
|
-
};
|
|
869
|
-
Parser.prototype._handleGAMA = function(length) {
|
|
870
|
-
this.read(length, this._parseGAMA.bind(this));
|
|
871
|
-
};
|
|
872
|
-
Parser.prototype._parseGAMA = function(data) {
|
|
873
|
-
this._crc.write(data);
|
|
874
|
-
this.gamma(data.readUInt32BE(0) / constants.GAMMA_DIVISION);
|
|
875
|
-
this._handleChunkEnd();
|
|
876
|
-
};
|
|
877
|
-
Parser.prototype._handleIDAT = function(length) {
|
|
878
|
-
if (!this._emittedHeadersFinished) {
|
|
879
|
-
this._emittedHeadersFinished = true;
|
|
880
|
-
this.headersFinished();
|
|
881
|
-
}
|
|
882
|
-
this.read(-length, this._parseIDAT.bind(this, length));
|
|
883
|
-
};
|
|
884
|
-
Parser.prototype._parseIDAT = function(length, data) {
|
|
885
|
-
this._crc.write(data);
|
|
886
|
-
if (this._colorType === constants.COLORTYPE_PALETTE_COLOR && this._palette.length === 0) {
|
|
887
|
-
throw new Error("Expected palette not found");
|
|
888
|
-
}
|
|
889
|
-
this.inflateData(data);
|
|
890
|
-
let leftOverLength = length - data.length;
|
|
891
|
-
if (leftOverLength > 0) {
|
|
892
|
-
this._handleIDAT(leftOverLength);
|
|
893
|
-
} else {
|
|
894
|
-
this._handleChunkEnd();
|
|
895
|
-
}
|
|
896
|
-
};
|
|
897
|
-
Parser.prototype._handleIEND = function(length) {
|
|
898
|
-
this.read(length, this._parseIEND.bind(this));
|
|
899
|
-
};
|
|
900
|
-
Parser.prototype._parseIEND = function(data) {
|
|
901
|
-
this._crc.write(data);
|
|
902
|
-
this._hasIEND = true;
|
|
903
|
-
this._handleChunkEnd();
|
|
904
|
-
if (this.finished) {
|
|
905
|
-
this.finished();
|
|
906
|
-
}
|
|
907
|
-
};
|
|
908
|
-
}
|
|
909
|
-
});
|
|
910
|
-
|
|
911
|
-
// node_modules/pngjs/lib/bitmapper.js
|
|
912
|
-
var require_bitmapper = __commonJS({
|
|
913
|
-
"node_modules/pngjs/lib/bitmapper.js"(exports2) {
|
|
914
|
-
"use strict";
|
|
915
|
-
var interlaceUtils = require_interlace();
|
|
916
|
-
var pixelBppMapper = [
|
|
917
|
-
// 0 - dummy entry
|
|
918
|
-
function() {
|
|
919
|
-
},
|
|
920
|
-
// 1 - L
|
|
921
|
-
// 0: 0, 1: 0, 2: 0, 3: 0xff
|
|
922
|
-
function(pxData, data, pxPos, rawPos) {
|
|
923
|
-
if (rawPos === data.length) {
|
|
924
|
-
throw new Error("Ran out of data");
|
|
925
|
-
}
|
|
926
|
-
let pixel = data[rawPos];
|
|
927
|
-
pxData[pxPos] = pixel;
|
|
928
|
-
pxData[pxPos + 1] = pixel;
|
|
929
|
-
pxData[pxPos + 2] = pixel;
|
|
930
|
-
pxData[pxPos + 3] = 255;
|
|
931
|
-
},
|
|
932
|
-
// 2 - LA
|
|
933
|
-
// 0: 0, 1: 0, 2: 0, 3: 1
|
|
934
|
-
function(pxData, data, pxPos, rawPos) {
|
|
935
|
-
if (rawPos + 1 >= data.length) {
|
|
936
|
-
throw new Error("Ran out of data");
|
|
937
|
-
}
|
|
938
|
-
let pixel = data[rawPos];
|
|
939
|
-
pxData[pxPos] = pixel;
|
|
940
|
-
pxData[pxPos + 1] = pixel;
|
|
941
|
-
pxData[pxPos + 2] = pixel;
|
|
942
|
-
pxData[pxPos + 3] = data[rawPos + 1];
|
|
943
|
-
},
|
|
944
|
-
// 3 - RGB
|
|
945
|
-
// 0: 0, 1: 1, 2: 2, 3: 0xff
|
|
946
|
-
function(pxData, data, pxPos, rawPos) {
|
|
947
|
-
if (rawPos + 2 >= data.length) {
|
|
948
|
-
throw new Error("Ran out of data");
|
|
949
|
-
}
|
|
950
|
-
pxData[pxPos] = data[rawPos];
|
|
951
|
-
pxData[pxPos + 1] = data[rawPos + 1];
|
|
952
|
-
pxData[pxPos + 2] = data[rawPos + 2];
|
|
953
|
-
pxData[pxPos + 3] = 255;
|
|
954
|
-
},
|
|
955
|
-
// 4 - RGBA
|
|
956
|
-
// 0: 0, 1: 1, 2: 2, 3: 3
|
|
957
|
-
function(pxData, data, pxPos, rawPos) {
|
|
958
|
-
if (rawPos + 3 >= data.length) {
|
|
959
|
-
throw new Error("Ran out of data");
|
|
960
|
-
}
|
|
961
|
-
pxData[pxPos] = data[rawPos];
|
|
962
|
-
pxData[pxPos + 1] = data[rawPos + 1];
|
|
963
|
-
pxData[pxPos + 2] = data[rawPos + 2];
|
|
964
|
-
pxData[pxPos + 3] = data[rawPos + 3];
|
|
965
|
-
}
|
|
966
|
-
];
|
|
967
|
-
var pixelBppCustomMapper = [
|
|
968
|
-
// 0 - dummy entry
|
|
969
|
-
function() {
|
|
970
|
-
},
|
|
971
|
-
// 1 - L
|
|
972
|
-
// 0: 0, 1: 0, 2: 0, 3: 0xff
|
|
973
|
-
function(pxData, pixelData, pxPos, maxBit) {
|
|
974
|
-
let pixel = pixelData[0];
|
|
975
|
-
pxData[pxPos] = pixel;
|
|
976
|
-
pxData[pxPos + 1] = pixel;
|
|
977
|
-
pxData[pxPos + 2] = pixel;
|
|
978
|
-
pxData[pxPos + 3] = maxBit;
|
|
979
|
-
},
|
|
980
|
-
// 2 - LA
|
|
981
|
-
// 0: 0, 1: 0, 2: 0, 3: 1
|
|
982
|
-
function(pxData, pixelData, pxPos) {
|
|
983
|
-
let pixel = pixelData[0];
|
|
984
|
-
pxData[pxPos] = pixel;
|
|
985
|
-
pxData[pxPos + 1] = pixel;
|
|
986
|
-
pxData[pxPos + 2] = pixel;
|
|
987
|
-
pxData[pxPos + 3] = pixelData[1];
|
|
988
|
-
},
|
|
989
|
-
// 3 - RGB
|
|
990
|
-
// 0: 0, 1: 1, 2: 2, 3: 0xff
|
|
991
|
-
function(pxData, pixelData, pxPos, maxBit) {
|
|
992
|
-
pxData[pxPos] = pixelData[0];
|
|
993
|
-
pxData[pxPos + 1] = pixelData[1];
|
|
994
|
-
pxData[pxPos + 2] = pixelData[2];
|
|
995
|
-
pxData[pxPos + 3] = maxBit;
|
|
996
|
-
},
|
|
997
|
-
// 4 - RGBA
|
|
998
|
-
// 0: 0, 1: 1, 2: 2, 3: 3
|
|
999
|
-
function(pxData, pixelData, pxPos) {
|
|
1000
|
-
pxData[pxPos] = pixelData[0];
|
|
1001
|
-
pxData[pxPos + 1] = pixelData[1];
|
|
1002
|
-
pxData[pxPos + 2] = pixelData[2];
|
|
1003
|
-
pxData[pxPos + 3] = pixelData[3];
|
|
1004
|
-
}
|
|
1005
|
-
];
|
|
1006
|
-
function bitRetriever(data, depth) {
|
|
1007
|
-
let leftOver = [];
|
|
1008
|
-
let i = 0;
|
|
1009
|
-
function split() {
|
|
1010
|
-
if (i === data.length) {
|
|
1011
|
-
throw new Error("Ran out of data");
|
|
1012
|
-
}
|
|
1013
|
-
let byte = data[i];
|
|
1014
|
-
i++;
|
|
1015
|
-
let byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
|
|
1016
|
-
switch (depth) {
|
|
1017
|
-
default:
|
|
1018
|
-
throw new Error("unrecognised depth");
|
|
1019
|
-
case 16:
|
|
1020
|
-
byte2 = data[i];
|
|
1021
|
-
i++;
|
|
1022
|
-
leftOver.push((byte << 8) + byte2);
|
|
1023
|
-
break;
|
|
1024
|
-
case 4:
|
|
1025
|
-
byte2 = byte & 15;
|
|
1026
|
-
byte1 = byte >> 4;
|
|
1027
|
-
leftOver.push(byte1, byte2);
|
|
1028
|
-
break;
|
|
1029
|
-
case 2:
|
|
1030
|
-
byte4 = byte & 3;
|
|
1031
|
-
byte3 = byte >> 2 & 3;
|
|
1032
|
-
byte2 = byte >> 4 & 3;
|
|
1033
|
-
byte1 = byte >> 6 & 3;
|
|
1034
|
-
leftOver.push(byte1, byte2, byte3, byte4);
|
|
1035
|
-
break;
|
|
1036
|
-
case 1:
|
|
1037
|
-
byte8 = byte & 1;
|
|
1038
|
-
byte7 = byte >> 1 & 1;
|
|
1039
|
-
byte6 = byte >> 2 & 1;
|
|
1040
|
-
byte5 = byte >> 3 & 1;
|
|
1041
|
-
byte4 = byte >> 4 & 1;
|
|
1042
|
-
byte3 = byte >> 5 & 1;
|
|
1043
|
-
byte2 = byte >> 6 & 1;
|
|
1044
|
-
byte1 = byte >> 7 & 1;
|
|
1045
|
-
leftOver.push(byte1, byte2, byte3, byte4, byte5, byte6, byte7, byte8);
|
|
1046
|
-
break;
|
|
1047
|
-
}
|
|
1048
|
-
}
|
|
1049
|
-
return {
|
|
1050
|
-
get: function(count) {
|
|
1051
|
-
while (leftOver.length < count) {
|
|
1052
|
-
split();
|
|
1053
|
-
}
|
|
1054
|
-
let returner = leftOver.slice(0, count);
|
|
1055
|
-
leftOver = leftOver.slice(count);
|
|
1056
|
-
return returner;
|
|
1057
|
-
},
|
|
1058
|
-
resetAfterLine: function() {
|
|
1059
|
-
leftOver.length = 0;
|
|
1060
|
-
},
|
|
1061
|
-
end: function() {
|
|
1062
|
-
if (i !== data.length) {
|
|
1063
|
-
throw new Error("extra data found");
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
};
|
|
1067
|
-
}
|
|
1068
|
-
function mapImage8Bit(image, pxData, getPxPos, bpp, data, rawPos) {
|
|
1069
|
-
let imageWidth = image.width;
|
|
1070
|
-
let imageHeight = image.height;
|
|
1071
|
-
let imagePass = image.index;
|
|
1072
|
-
for (let y = 0; y < imageHeight; y++) {
|
|
1073
|
-
for (let x = 0; x < imageWidth; x++) {
|
|
1074
|
-
let pxPos = getPxPos(x, y, imagePass);
|
|
1075
|
-
pixelBppMapper[bpp](pxData, data, pxPos, rawPos);
|
|
1076
|
-
rawPos += bpp;
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
return rawPos;
|
|
1080
|
-
}
|
|
1081
|
-
function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) {
|
|
1082
|
-
let imageWidth = image.width;
|
|
1083
|
-
let imageHeight = image.height;
|
|
1084
|
-
let imagePass = image.index;
|
|
1085
|
-
for (let y = 0; y < imageHeight; y++) {
|
|
1086
|
-
for (let x = 0; x < imageWidth; x++) {
|
|
1087
|
-
let pixelData = bits.get(bpp);
|
|
1088
|
-
let pxPos = getPxPos(x, y, imagePass);
|
|
1089
|
-
pixelBppCustomMapper[bpp](pxData, pixelData, pxPos, maxBit);
|
|
1090
|
-
}
|
|
1091
|
-
bits.resetAfterLine();
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
exports2.dataToBitMap = function(data, bitmapInfo) {
|
|
1095
|
-
let width = bitmapInfo.width;
|
|
1096
|
-
let height = bitmapInfo.height;
|
|
1097
|
-
let depth = bitmapInfo.depth;
|
|
1098
|
-
let bpp = bitmapInfo.bpp;
|
|
1099
|
-
let interlace = bitmapInfo.interlace;
|
|
1100
|
-
let bits;
|
|
1101
|
-
if (depth !== 8) {
|
|
1102
|
-
bits = bitRetriever(data, depth);
|
|
1103
|
-
}
|
|
1104
|
-
let pxData;
|
|
1105
|
-
if (depth <= 8) {
|
|
1106
|
-
pxData = Buffer.alloc(width * height * 4);
|
|
1107
|
-
} else {
|
|
1108
|
-
pxData = new Uint16Array(width * height * 4);
|
|
1109
|
-
}
|
|
1110
|
-
let maxBit = Math.pow(2, depth) - 1;
|
|
1111
|
-
let rawPos = 0;
|
|
1112
|
-
let images;
|
|
1113
|
-
let getPxPos;
|
|
1114
|
-
if (interlace) {
|
|
1115
|
-
images = interlaceUtils.getImagePasses(width, height);
|
|
1116
|
-
getPxPos = interlaceUtils.getInterlaceIterator(width, height);
|
|
1117
|
-
} else {
|
|
1118
|
-
let nonInterlacedPxPos = 0;
|
|
1119
|
-
getPxPos = function() {
|
|
1120
|
-
let returner = nonInterlacedPxPos;
|
|
1121
|
-
nonInterlacedPxPos += 4;
|
|
1122
|
-
return returner;
|
|
1123
|
-
};
|
|
1124
|
-
images = [{ width, height }];
|
|
1125
|
-
}
|
|
1126
|
-
for (let imageIndex = 0; imageIndex < images.length; imageIndex++) {
|
|
1127
|
-
if (depth === 8) {
|
|
1128
|
-
rawPos = mapImage8Bit(
|
|
1129
|
-
images[imageIndex],
|
|
1130
|
-
pxData,
|
|
1131
|
-
getPxPos,
|
|
1132
|
-
bpp,
|
|
1133
|
-
data,
|
|
1134
|
-
rawPos
|
|
1135
|
-
);
|
|
1136
|
-
} else {
|
|
1137
|
-
mapImageCustomBit(
|
|
1138
|
-
images[imageIndex],
|
|
1139
|
-
pxData,
|
|
1140
|
-
getPxPos,
|
|
1141
|
-
bpp,
|
|
1142
|
-
bits,
|
|
1143
|
-
maxBit
|
|
1144
|
-
);
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
if (depth === 8) {
|
|
1148
|
-
if (rawPos !== data.length) {
|
|
1149
|
-
throw new Error("extra data found");
|
|
1150
|
-
}
|
|
1151
|
-
} else {
|
|
1152
|
-
bits.end();
|
|
1153
|
-
}
|
|
1154
|
-
return pxData;
|
|
1155
|
-
};
|
|
1156
|
-
}
|
|
1157
|
-
});
|
|
1158
|
-
|
|
1159
|
-
// node_modules/pngjs/lib/format-normaliser.js
|
|
1160
|
-
var require_format_normaliser = __commonJS({
|
|
1161
|
-
"node_modules/pngjs/lib/format-normaliser.js"(exports2, module2) {
|
|
1162
|
-
"use strict";
|
|
1163
|
-
function dePalette(indata, outdata, width, height, palette) {
|
|
1164
|
-
let pxPos = 0;
|
|
1165
|
-
for (let y = 0; y < height; y++) {
|
|
1166
|
-
for (let x = 0; x < width; x++) {
|
|
1167
|
-
let color = palette[indata[pxPos]];
|
|
1168
|
-
if (!color) {
|
|
1169
|
-
throw new Error("index " + indata[pxPos] + " not in palette");
|
|
1170
|
-
}
|
|
1171
|
-
for (let i = 0; i < 4; i++) {
|
|
1172
|
-
outdata[pxPos + i] = color[i];
|
|
1173
|
-
}
|
|
1174
|
-
pxPos += 4;
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
function replaceTransparentColor(indata, outdata, width, height, transColor) {
|
|
1179
|
-
let pxPos = 0;
|
|
1180
|
-
for (let y = 0; y < height; y++) {
|
|
1181
|
-
for (let x = 0; x < width; x++) {
|
|
1182
|
-
let makeTrans = false;
|
|
1183
|
-
if (transColor.length === 1) {
|
|
1184
|
-
if (transColor[0] === indata[pxPos]) {
|
|
1185
|
-
makeTrans = true;
|
|
1186
|
-
}
|
|
1187
|
-
} else if (transColor[0] === indata[pxPos] && transColor[1] === indata[pxPos + 1] && transColor[2] === indata[pxPos + 2]) {
|
|
1188
|
-
makeTrans = true;
|
|
1189
|
-
}
|
|
1190
|
-
if (makeTrans) {
|
|
1191
|
-
for (let i = 0; i < 4; i++) {
|
|
1192
|
-
outdata[pxPos + i] = 0;
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
pxPos += 4;
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
function scaleDepth(indata, outdata, width, height, depth) {
|
|
1200
|
-
let maxOutSample = 255;
|
|
1201
|
-
let maxInSample = Math.pow(2, depth) - 1;
|
|
1202
|
-
let pxPos = 0;
|
|
1203
|
-
for (let y = 0; y < height; y++) {
|
|
1204
|
-
for (let x = 0; x < width; x++) {
|
|
1205
|
-
for (let i = 0; i < 4; i++) {
|
|
1206
|
-
outdata[pxPos + i] = Math.floor(
|
|
1207
|
-
indata[pxPos + i] * maxOutSample / maxInSample + 0.5
|
|
1208
|
-
);
|
|
1209
|
-
}
|
|
1210
|
-
pxPos += 4;
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
module2.exports = function(indata, imageData, skipRescale = false) {
|
|
1215
|
-
let depth = imageData.depth;
|
|
1216
|
-
let width = imageData.width;
|
|
1217
|
-
let height = imageData.height;
|
|
1218
|
-
let colorType = imageData.colorType;
|
|
1219
|
-
let transColor = imageData.transColor;
|
|
1220
|
-
let palette = imageData.palette;
|
|
1221
|
-
let outdata = indata;
|
|
1222
|
-
if (colorType === 3) {
|
|
1223
|
-
dePalette(indata, outdata, width, height, palette);
|
|
1224
|
-
} else {
|
|
1225
|
-
if (transColor) {
|
|
1226
|
-
replaceTransparentColor(indata, outdata, width, height, transColor);
|
|
1227
|
-
}
|
|
1228
|
-
if (depth !== 8 && !skipRescale) {
|
|
1229
|
-
if (depth === 16) {
|
|
1230
|
-
outdata = Buffer.alloc(width * height * 4);
|
|
1231
|
-
}
|
|
1232
|
-
scaleDepth(indata, outdata, width, height, depth);
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
return outdata;
|
|
1236
|
-
};
|
|
1237
|
-
}
|
|
1238
|
-
});
|
|
1239
|
-
|
|
1240
|
-
// node_modules/pngjs/lib/parser-async.js
|
|
1241
|
-
var require_parser_async = __commonJS({
|
|
1242
|
-
"node_modules/pngjs/lib/parser-async.js"(exports2, module2) {
|
|
1243
|
-
"use strict";
|
|
1244
|
-
var util = require("util");
|
|
1245
|
-
var zlib = require("zlib");
|
|
1246
|
-
var ChunkStream = require_chunkstream();
|
|
1247
|
-
var FilterAsync = require_filter_parse_async();
|
|
1248
|
-
var Parser = require_parser();
|
|
1249
|
-
var bitmapper = require_bitmapper();
|
|
1250
|
-
var formatNormaliser = require_format_normaliser();
|
|
1251
|
-
var ParserAsync = module2.exports = function(options) {
|
|
1252
|
-
ChunkStream.call(this);
|
|
1253
|
-
this._parser = new Parser(options, {
|
|
1254
|
-
read: this.read.bind(this),
|
|
1255
|
-
error: this._handleError.bind(this),
|
|
1256
|
-
metadata: this._handleMetaData.bind(this),
|
|
1257
|
-
gamma: this.emit.bind(this, "gamma"),
|
|
1258
|
-
palette: this._handlePalette.bind(this),
|
|
1259
|
-
transColor: this._handleTransColor.bind(this),
|
|
1260
|
-
finished: this._finished.bind(this),
|
|
1261
|
-
inflateData: this._inflateData.bind(this),
|
|
1262
|
-
simpleTransparency: this._simpleTransparency.bind(this),
|
|
1263
|
-
headersFinished: this._headersFinished.bind(this)
|
|
1264
|
-
});
|
|
1265
|
-
this._options = options;
|
|
1266
|
-
this.writable = true;
|
|
1267
|
-
this._parser.start();
|
|
1268
|
-
};
|
|
1269
|
-
util.inherits(ParserAsync, ChunkStream);
|
|
1270
|
-
ParserAsync.prototype._handleError = function(err) {
|
|
1271
|
-
this.emit("error", err);
|
|
1272
|
-
this.writable = false;
|
|
1273
|
-
this.destroy();
|
|
1274
|
-
if (this._inflate && this._inflate.destroy) {
|
|
1275
|
-
this._inflate.destroy();
|
|
1276
|
-
}
|
|
1277
|
-
if (this._filter) {
|
|
1278
|
-
this._filter.destroy();
|
|
1279
|
-
this._filter.on("error", function() {
|
|
1280
|
-
});
|
|
1281
|
-
}
|
|
1282
|
-
this.errord = true;
|
|
1283
|
-
};
|
|
1284
|
-
ParserAsync.prototype._inflateData = function(data) {
|
|
1285
|
-
if (!this._inflate) {
|
|
1286
|
-
if (this._bitmapInfo.interlace) {
|
|
1287
|
-
this._inflate = zlib.createInflate();
|
|
1288
|
-
this._inflate.on("error", this.emit.bind(this, "error"));
|
|
1289
|
-
this._filter.on("complete", this._complete.bind(this));
|
|
1290
|
-
this._inflate.pipe(this._filter);
|
|
1291
|
-
} else {
|
|
1292
|
-
let rowSize = (this._bitmapInfo.width * this._bitmapInfo.bpp * this._bitmapInfo.depth + 7 >> 3) + 1;
|
|
1293
|
-
let imageSize = rowSize * this._bitmapInfo.height;
|
|
1294
|
-
let chunkSize = Math.max(imageSize, zlib.Z_MIN_CHUNK);
|
|
1295
|
-
this._inflate = zlib.createInflate({ chunkSize });
|
|
1296
|
-
let leftToInflate = imageSize;
|
|
1297
|
-
let emitError = this.emit.bind(this, "error");
|
|
1298
|
-
this._inflate.on("error", function(err) {
|
|
1299
|
-
if (!leftToInflate) {
|
|
1300
|
-
return;
|
|
1301
|
-
}
|
|
1302
|
-
emitError(err);
|
|
1303
|
-
});
|
|
1304
|
-
this._filter.on("complete", this._complete.bind(this));
|
|
1305
|
-
let filterWrite = this._filter.write.bind(this._filter);
|
|
1306
|
-
this._inflate.on("data", function(chunk) {
|
|
1307
|
-
if (!leftToInflate) {
|
|
1308
|
-
return;
|
|
1309
|
-
}
|
|
1310
|
-
if (chunk.length > leftToInflate) {
|
|
1311
|
-
chunk = chunk.slice(0, leftToInflate);
|
|
1312
|
-
}
|
|
1313
|
-
leftToInflate -= chunk.length;
|
|
1314
|
-
filterWrite(chunk);
|
|
1315
|
-
});
|
|
1316
|
-
this._inflate.on("end", this._filter.end.bind(this._filter));
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
this._inflate.write(data);
|
|
1320
|
-
};
|
|
1321
|
-
ParserAsync.prototype._handleMetaData = function(metaData) {
|
|
1322
|
-
this._metaData = metaData;
|
|
1323
|
-
this._bitmapInfo = Object.create(metaData);
|
|
1324
|
-
this._filter = new FilterAsync(this._bitmapInfo);
|
|
1325
|
-
};
|
|
1326
|
-
ParserAsync.prototype._handleTransColor = function(transColor) {
|
|
1327
|
-
this._bitmapInfo.transColor = transColor;
|
|
1328
|
-
};
|
|
1329
|
-
ParserAsync.prototype._handlePalette = function(palette) {
|
|
1330
|
-
this._bitmapInfo.palette = palette;
|
|
1331
|
-
};
|
|
1332
|
-
ParserAsync.prototype._simpleTransparency = function() {
|
|
1333
|
-
this._metaData.alpha = true;
|
|
1334
|
-
};
|
|
1335
|
-
ParserAsync.prototype._headersFinished = function() {
|
|
1336
|
-
this.emit("metadata", this._metaData);
|
|
1337
|
-
};
|
|
1338
|
-
ParserAsync.prototype._finished = function() {
|
|
1339
|
-
if (this.errord) {
|
|
1340
|
-
return;
|
|
1341
|
-
}
|
|
1342
|
-
if (!this._inflate) {
|
|
1343
|
-
this.emit("error", "No Inflate block");
|
|
1344
|
-
} else {
|
|
1345
|
-
this._inflate.end();
|
|
1346
|
-
}
|
|
1347
|
-
};
|
|
1348
|
-
ParserAsync.prototype._complete = function(filteredData) {
|
|
1349
|
-
if (this.errord) {
|
|
1350
|
-
return;
|
|
1351
|
-
}
|
|
1352
|
-
let normalisedBitmapData;
|
|
1353
|
-
try {
|
|
1354
|
-
let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo);
|
|
1355
|
-
normalisedBitmapData = formatNormaliser(
|
|
1356
|
-
bitmapData,
|
|
1357
|
-
this._bitmapInfo,
|
|
1358
|
-
this._options.skipRescale
|
|
1359
|
-
);
|
|
1360
|
-
bitmapData = null;
|
|
1361
|
-
} catch (ex) {
|
|
1362
|
-
this._handleError(ex);
|
|
1363
|
-
return;
|
|
1364
|
-
}
|
|
1365
|
-
this.emit("parsed", normalisedBitmapData);
|
|
1366
|
-
};
|
|
1367
|
-
}
|
|
1368
|
-
});
|
|
1369
|
-
|
|
1370
|
-
// node_modules/pngjs/lib/bitpacker.js
|
|
1371
|
-
var require_bitpacker = __commonJS({
|
|
1372
|
-
"node_modules/pngjs/lib/bitpacker.js"(exports2, module2) {
|
|
1373
|
-
"use strict";
|
|
1374
|
-
var constants = require_constants();
|
|
1375
|
-
module2.exports = function(dataIn, width, height, options) {
|
|
1376
|
-
let outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf(
|
|
1377
|
-
options.colorType
|
|
1378
|
-
) !== -1;
|
|
1379
|
-
if (options.colorType === options.inputColorType) {
|
|
1380
|
-
let bigEndian = (function() {
|
|
1381
|
-
let buffer = new ArrayBuffer(2);
|
|
1382
|
-
new DataView(buffer).setInt16(
|
|
1383
|
-
0,
|
|
1384
|
-
256,
|
|
1385
|
-
true
|
|
1386
|
-
/* littleEndian */
|
|
1387
|
-
);
|
|
1388
|
-
return new Int16Array(buffer)[0] !== 256;
|
|
1389
|
-
})();
|
|
1390
|
-
if (options.bitDepth === 8 || options.bitDepth === 16 && bigEndian) {
|
|
1391
|
-
return dataIn;
|
|
1392
|
-
}
|
|
1393
|
-
}
|
|
1394
|
-
let data = options.bitDepth !== 16 ? dataIn : new Uint16Array(dataIn.buffer);
|
|
1395
|
-
let maxValue = 255;
|
|
1396
|
-
let inBpp = constants.COLORTYPE_TO_BPP_MAP[options.inputColorType];
|
|
1397
|
-
if (inBpp === 4 && !options.inputHasAlpha) {
|
|
1398
|
-
inBpp = 3;
|
|
1399
|
-
}
|
|
1400
|
-
let outBpp = constants.COLORTYPE_TO_BPP_MAP[options.colorType];
|
|
1401
|
-
if (options.bitDepth === 16) {
|
|
1402
|
-
maxValue = 65535;
|
|
1403
|
-
outBpp *= 2;
|
|
1404
|
-
}
|
|
1405
|
-
let outData = Buffer.alloc(width * height * outBpp);
|
|
1406
|
-
let inIndex = 0;
|
|
1407
|
-
let outIndex = 0;
|
|
1408
|
-
let bgColor = options.bgColor || {};
|
|
1409
|
-
if (bgColor.red === void 0) {
|
|
1410
|
-
bgColor.red = maxValue;
|
|
1411
|
-
}
|
|
1412
|
-
if (bgColor.green === void 0) {
|
|
1413
|
-
bgColor.green = maxValue;
|
|
1414
|
-
}
|
|
1415
|
-
if (bgColor.blue === void 0) {
|
|
1416
|
-
bgColor.blue = maxValue;
|
|
1417
|
-
}
|
|
1418
|
-
function getRGBA() {
|
|
1419
|
-
let red;
|
|
1420
|
-
let green;
|
|
1421
|
-
let blue;
|
|
1422
|
-
let alpha = maxValue;
|
|
1423
|
-
switch (options.inputColorType) {
|
|
1424
|
-
case constants.COLORTYPE_COLOR_ALPHA:
|
|
1425
|
-
alpha = data[inIndex + 3];
|
|
1426
|
-
red = data[inIndex];
|
|
1427
|
-
green = data[inIndex + 1];
|
|
1428
|
-
blue = data[inIndex + 2];
|
|
1429
|
-
break;
|
|
1430
|
-
case constants.COLORTYPE_COLOR:
|
|
1431
|
-
red = data[inIndex];
|
|
1432
|
-
green = data[inIndex + 1];
|
|
1433
|
-
blue = data[inIndex + 2];
|
|
1434
|
-
break;
|
|
1435
|
-
case constants.COLORTYPE_ALPHA:
|
|
1436
|
-
alpha = data[inIndex + 1];
|
|
1437
|
-
red = data[inIndex];
|
|
1438
|
-
green = red;
|
|
1439
|
-
blue = red;
|
|
1440
|
-
break;
|
|
1441
|
-
case constants.COLORTYPE_GRAYSCALE:
|
|
1442
|
-
red = data[inIndex];
|
|
1443
|
-
green = red;
|
|
1444
|
-
blue = red;
|
|
1445
|
-
break;
|
|
1446
|
-
default:
|
|
1447
|
-
throw new Error(
|
|
1448
|
-
"input color type:" + options.inputColorType + " is not supported at present"
|
|
1449
|
-
);
|
|
1450
|
-
}
|
|
1451
|
-
if (options.inputHasAlpha) {
|
|
1452
|
-
if (!outHasAlpha) {
|
|
1453
|
-
alpha /= maxValue;
|
|
1454
|
-
red = Math.min(
|
|
1455
|
-
Math.max(Math.round((1 - alpha) * bgColor.red + alpha * red), 0),
|
|
1456
|
-
maxValue
|
|
1457
|
-
);
|
|
1458
|
-
green = Math.min(
|
|
1459
|
-
Math.max(Math.round((1 - alpha) * bgColor.green + alpha * green), 0),
|
|
1460
|
-
maxValue
|
|
1461
|
-
);
|
|
1462
|
-
blue = Math.min(
|
|
1463
|
-
Math.max(Math.round((1 - alpha) * bgColor.blue + alpha * blue), 0),
|
|
1464
|
-
maxValue
|
|
1465
|
-
);
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
return { red, green, blue, alpha };
|
|
1469
|
-
}
|
|
1470
|
-
for (let y = 0; y < height; y++) {
|
|
1471
|
-
for (let x = 0; x < width; x++) {
|
|
1472
|
-
let rgba = getRGBA(data, inIndex);
|
|
1473
|
-
switch (options.colorType) {
|
|
1474
|
-
case constants.COLORTYPE_COLOR_ALPHA:
|
|
1475
|
-
case constants.COLORTYPE_COLOR:
|
|
1476
|
-
if (options.bitDepth === 8) {
|
|
1477
|
-
outData[outIndex] = rgba.red;
|
|
1478
|
-
outData[outIndex + 1] = rgba.green;
|
|
1479
|
-
outData[outIndex + 2] = rgba.blue;
|
|
1480
|
-
if (outHasAlpha) {
|
|
1481
|
-
outData[outIndex + 3] = rgba.alpha;
|
|
1482
|
-
}
|
|
1483
|
-
} else {
|
|
1484
|
-
outData.writeUInt16BE(rgba.red, outIndex);
|
|
1485
|
-
outData.writeUInt16BE(rgba.green, outIndex + 2);
|
|
1486
|
-
outData.writeUInt16BE(rgba.blue, outIndex + 4);
|
|
1487
|
-
if (outHasAlpha) {
|
|
1488
|
-
outData.writeUInt16BE(rgba.alpha, outIndex + 6);
|
|
1489
|
-
}
|
|
1490
|
-
}
|
|
1491
|
-
break;
|
|
1492
|
-
case constants.COLORTYPE_ALPHA:
|
|
1493
|
-
case constants.COLORTYPE_GRAYSCALE: {
|
|
1494
|
-
let grayscale = (rgba.red + rgba.green + rgba.blue) / 3;
|
|
1495
|
-
if (options.bitDepth === 8) {
|
|
1496
|
-
outData[outIndex] = grayscale;
|
|
1497
|
-
if (outHasAlpha) {
|
|
1498
|
-
outData[outIndex + 1] = rgba.alpha;
|
|
1499
|
-
}
|
|
1500
|
-
} else {
|
|
1501
|
-
outData.writeUInt16BE(grayscale, outIndex);
|
|
1502
|
-
if (outHasAlpha) {
|
|
1503
|
-
outData.writeUInt16BE(rgba.alpha, outIndex + 2);
|
|
1504
|
-
}
|
|
1505
|
-
}
|
|
1506
|
-
break;
|
|
1507
|
-
}
|
|
1508
|
-
default:
|
|
1509
|
-
throw new Error("unrecognised color Type " + options.colorType);
|
|
1510
|
-
}
|
|
1511
|
-
inIndex += inBpp;
|
|
1512
|
-
outIndex += outBpp;
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
return outData;
|
|
1516
|
-
};
|
|
1517
|
-
}
|
|
1518
|
-
});
|
|
1519
|
-
|
|
1520
|
-
// node_modules/pngjs/lib/filter-pack.js
|
|
1521
|
-
var require_filter_pack = __commonJS({
|
|
1522
|
-
"node_modules/pngjs/lib/filter-pack.js"(exports2, module2) {
|
|
1523
|
-
"use strict";
|
|
1524
|
-
var paethPredictor = require_paeth_predictor();
|
|
1525
|
-
function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
1526
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
1527
|
-
rawData[rawPos + x] = pxData[pxPos + x];
|
|
1528
|
-
}
|
|
1529
|
-
}
|
|
1530
|
-
function filterSumNone(pxData, pxPos, byteWidth) {
|
|
1531
|
-
let sum = 0;
|
|
1532
|
-
let length = pxPos + byteWidth;
|
|
1533
|
-
for (let i = pxPos; i < length; i++) {
|
|
1534
|
-
sum += Math.abs(pxData[i]);
|
|
1535
|
-
}
|
|
1536
|
-
return sum;
|
|
1537
|
-
}
|
|
1538
|
-
function filterSub(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
1539
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
1540
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
1541
|
-
let val = pxData[pxPos + x] - left;
|
|
1542
|
-
rawData[rawPos + x] = val;
|
|
1543
|
-
}
|
|
1544
|
-
}
|
|
1545
|
-
function filterSumSub(pxData, pxPos, byteWidth, bpp) {
|
|
1546
|
-
let sum = 0;
|
|
1547
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
1548
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
1549
|
-
let val = pxData[pxPos + x] - left;
|
|
1550
|
-
sum += Math.abs(val);
|
|
1551
|
-
}
|
|
1552
|
-
return sum;
|
|
1553
|
-
}
|
|
1554
|
-
function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) {
|
|
1555
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
1556
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
1557
|
-
let val = pxData[pxPos + x] - up;
|
|
1558
|
-
rawData[rawPos + x] = val;
|
|
1559
|
-
}
|
|
1560
|
-
}
|
|
1561
|
-
function filterSumUp(pxData, pxPos, byteWidth) {
|
|
1562
|
-
let sum = 0;
|
|
1563
|
-
let length = pxPos + byteWidth;
|
|
1564
|
-
for (let x = pxPos; x < length; x++) {
|
|
1565
|
-
let up = pxPos > 0 ? pxData[x - byteWidth] : 0;
|
|
1566
|
-
let val = pxData[x] - up;
|
|
1567
|
-
sum += Math.abs(val);
|
|
1568
|
-
}
|
|
1569
|
-
return sum;
|
|
1570
|
-
}
|
|
1571
|
-
function filterAvg(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
1572
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
1573
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
1574
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
1575
|
-
let val = pxData[pxPos + x] - (left + up >> 1);
|
|
1576
|
-
rawData[rawPos + x] = val;
|
|
1577
|
-
}
|
|
1578
|
-
}
|
|
1579
|
-
function filterSumAvg(pxData, pxPos, byteWidth, bpp) {
|
|
1580
|
-
let sum = 0;
|
|
1581
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
1582
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
1583
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
1584
|
-
let val = pxData[pxPos + x] - (left + up >> 1);
|
|
1585
|
-
sum += Math.abs(val);
|
|
1586
|
-
}
|
|
1587
|
-
return sum;
|
|
1588
|
-
}
|
|
1589
|
-
function filterPaeth(pxData, pxPos, byteWidth, rawData, rawPos, bpp) {
|
|
1590
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
1591
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
1592
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
1593
|
-
let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
|
|
1594
|
-
let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
|
|
1595
|
-
rawData[rawPos + x] = val;
|
|
1596
|
-
}
|
|
1597
|
-
}
|
|
1598
|
-
function filterSumPaeth(pxData, pxPos, byteWidth, bpp) {
|
|
1599
|
-
let sum = 0;
|
|
1600
|
-
for (let x = 0; x < byteWidth; x++) {
|
|
1601
|
-
let left = x >= bpp ? pxData[pxPos + x - bpp] : 0;
|
|
1602
|
-
let up = pxPos > 0 ? pxData[pxPos + x - byteWidth] : 0;
|
|
1603
|
-
let upleft = pxPos > 0 && x >= bpp ? pxData[pxPos + x - (byteWidth + bpp)] : 0;
|
|
1604
|
-
let val = pxData[pxPos + x] - paethPredictor(left, up, upleft);
|
|
1605
|
-
sum += Math.abs(val);
|
|
1606
|
-
}
|
|
1607
|
-
return sum;
|
|
1608
|
-
}
|
|
1609
|
-
var filters = {
|
|
1610
|
-
0: filterNone,
|
|
1611
|
-
1: filterSub,
|
|
1612
|
-
2: filterUp,
|
|
1613
|
-
3: filterAvg,
|
|
1614
|
-
4: filterPaeth
|
|
1615
|
-
};
|
|
1616
|
-
var filterSums = {
|
|
1617
|
-
0: filterSumNone,
|
|
1618
|
-
1: filterSumSub,
|
|
1619
|
-
2: filterSumUp,
|
|
1620
|
-
3: filterSumAvg,
|
|
1621
|
-
4: filterSumPaeth
|
|
1622
|
-
};
|
|
1623
|
-
module2.exports = function(pxData, width, height, options, bpp) {
|
|
1624
|
-
let filterTypes;
|
|
1625
|
-
if (!("filterType" in options) || options.filterType === -1) {
|
|
1626
|
-
filterTypes = [0, 1, 2, 3, 4];
|
|
1627
|
-
} else if (typeof options.filterType === "number") {
|
|
1628
|
-
filterTypes = [options.filterType];
|
|
1629
|
-
} else {
|
|
1630
|
-
throw new Error("unrecognised filter types");
|
|
1631
|
-
}
|
|
1632
|
-
if (options.bitDepth === 16) {
|
|
1633
|
-
bpp *= 2;
|
|
1634
|
-
}
|
|
1635
|
-
let byteWidth = width * bpp;
|
|
1636
|
-
let rawPos = 0;
|
|
1637
|
-
let pxPos = 0;
|
|
1638
|
-
let rawData = Buffer.alloc((byteWidth + 1) * height);
|
|
1639
|
-
let sel = filterTypes[0];
|
|
1640
|
-
for (let y = 0; y < height; y++) {
|
|
1641
|
-
if (filterTypes.length > 1) {
|
|
1642
|
-
let min = Infinity;
|
|
1643
|
-
for (let i = 0; i < filterTypes.length; i++) {
|
|
1644
|
-
let sum = filterSums[filterTypes[i]](pxData, pxPos, byteWidth, bpp);
|
|
1645
|
-
if (sum < min) {
|
|
1646
|
-
sel = filterTypes[i];
|
|
1647
|
-
min = sum;
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
}
|
|
1651
|
-
rawData[rawPos] = sel;
|
|
1652
|
-
rawPos++;
|
|
1653
|
-
filters[sel](pxData, pxPos, byteWidth, rawData, rawPos, bpp);
|
|
1654
|
-
rawPos += byteWidth;
|
|
1655
|
-
pxPos += byteWidth;
|
|
1656
|
-
}
|
|
1657
|
-
return rawData;
|
|
1658
|
-
};
|
|
1659
|
-
}
|
|
1660
|
-
});
|
|
1661
|
-
|
|
1662
|
-
// node_modules/pngjs/lib/packer.js
|
|
1663
|
-
var require_packer = __commonJS({
|
|
1664
|
-
"node_modules/pngjs/lib/packer.js"(exports2, module2) {
|
|
1665
|
-
"use strict";
|
|
1666
|
-
var constants = require_constants();
|
|
1667
|
-
var CrcStream = require_crc();
|
|
1668
|
-
var bitPacker = require_bitpacker();
|
|
1669
|
-
var filter = require_filter_pack();
|
|
1670
|
-
var zlib = require("zlib");
|
|
1671
|
-
var Packer = module2.exports = function(options) {
|
|
1672
|
-
this._options = options;
|
|
1673
|
-
options.deflateChunkSize = options.deflateChunkSize || 32 * 1024;
|
|
1674
|
-
options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9;
|
|
1675
|
-
options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3;
|
|
1676
|
-
options.inputHasAlpha = options.inputHasAlpha != null ? options.inputHasAlpha : true;
|
|
1677
|
-
options.deflateFactory = options.deflateFactory || zlib.createDeflate;
|
|
1678
|
-
options.bitDepth = options.bitDepth || 8;
|
|
1679
|
-
options.colorType = typeof options.colorType === "number" ? options.colorType : constants.COLORTYPE_COLOR_ALPHA;
|
|
1680
|
-
options.inputColorType = typeof options.inputColorType === "number" ? options.inputColorType : constants.COLORTYPE_COLOR_ALPHA;
|
|
1681
|
-
if ([
|
|
1682
|
-
constants.COLORTYPE_GRAYSCALE,
|
|
1683
|
-
constants.COLORTYPE_COLOR,
|
|
1684
|
-
constants.COLORTYPE_COLOR_ALPHA,
|
|
1685
|
-
constants.COLORTYPE_ALPHA
|
|
1686
|
-
].indexOf(options.colorType) === -1) {
|
|
1687
|
-
throw new Error(
|
|
1688
|
-
"option color type:" + options.colorType + " is not supported at present"
|
|
1689
|
-
);
|
|
1690
|
-
}
|
|
1691
|
-
if ([
|
|
1692
|
-
constants.COLORTYPE_GRAYSCALE,
|
|
1693
|
-
constants.COLORTYPE_COLOR,
|
|
1694
|
-
constants.COLORTYPE_COLOR_ALPHA,
|
|
1695
|
-
constants.COLORTYPE_ALPHA
|
|
1696
|
-
].indexOf(options.inputColorType) === -1) {
|
|
1697
|
-
throw new Error(
|
|
1698
|
-
"option input color type:" + options.inputColorType + " is not supported at present"
|
|
1699
|
-
);
|
|
1700
|
-
}
|
|
1701
|
-
if (options.bitDepth !== 8 && options.bitDepth !== 16) {
|
|
1702
|
-
throw new Error(
|
|
1703
|
-
"option bit depth:" + options.bitDepth + " is not supported at present"
|
|
1704
|
-
);
|
|
1705
|
-
}
|
|
1706
|
-
};
|
|
1707
|
-
Packer.prototype.getDeflateOptions = function() {
|
|
1708
|
-
return {
|
|
1709
|
-
chunkSize: this._options.deflateChunkSize,
|
|
1710
|
-
level: this._options.deflateLevel,
|
|
1711
|
-
strategy: this._options.deflateStrategy
|
|
1712
|
-
};
|
|
1713
|
-
};
|
|
1714
|
-
Packer.prototype.createDeflate = function() {
|
|
1715
|
-
return this._options.deflateFactory(this.getDeflateOptions());
|
|
1716
|
-
};
|
|
1717
|
-
Packer.prototype.filterData = function(data, width, height) {
|
|
1718
|
-
let packedData = bitPacker(data, width, height, this._options);
|
|
1719
|
-
let bpp = constants.COLORTYPE_TO_BPP_MAP[this._options.colorType];
|
|
1720
|
-
let filteredData = filter(packedData, width, height, this._options, bpp);
|
|
1721
|
-
return filteredData;
|
|
1722
|
-
};
|
|
1723
|
-
Packer.prototype._packChunk = function(type, data) {
|
|
1724
|
-
let len = data ? data.length : 0;
|
|
1725
|
-
let buf = Buffer.alloc(len + 12);
|
|
1726
|
-
buf.writeUInt32BE(len, 0);
|
|
1727
|
-
buf.writeUInt32BE(type, 4);
|
|
1728
|
-
if (data) {
|
|
1729
|
-
data.copy(buf, 8);
|
|
1730
|
-
}
|
|
1731
|
-
buf.writeInt32BE(
|
|
1732
|
-
CrcStream.crc32(buf.slice(4, buf.length - 4)),
|
|
1733
|
-
buf.length - 4
|
|
1734
|
-
);
|
|
1735
|
-
return buf;
|
|
1736
|
-
};
|
|
1737
|
-
Packer.prototype.packGAMA = function(gamma) {
|
|
1738
|
-
let buf = Buffer.alloc(4);
|
|
1739
|
-
buf.writeUInt32BE(Math.floor(gamma * constants.GAMMA_DIVISION), 0);
|
|
1740
|
-
return this._packChunk(constants.TYPE_gAMA, buf);
|
|
1741
|
-
};
|
|
1742
|
-
Packer.prototype.packIHDR = function(width, height) {
|
|
1743
|
-
let buf = Buffer.alloc(13);
|
|
1744
|
-
buf.writeUInt32BE(width, 0);
|
|
1745
|
-
buf.writeUInt32BE(height, 4);
|
|
1746
|
-
buf[8] = this._options.bitDepth;
|
|
1747
|
-
buf[9] = this._options.colorType;
|
|
1748
|
-
buf[10] = 0;
|
|
1749
|
-
buf[11] = 0;
|
|
1750
|
-
buf[12] = 0;
|
|
1751
|
-
return this._packChunk(constants.TYPE_IHDR, buf);
|
|
1752
|
-
};
|
|
1753
|
-
Packer.prototype.packIDAT = function(data) {
|
|
1754
|
-
return this._packChunk(constants.TYPE_IDAT, data);
|
|
1755
|
-
};
|
|
1756
|
-
Packer.prototype.packIEND = function() {
|
|
1757
|
-
return this._packChunk(constants.TYPE_IEND, null);
|
|
1758
|
-
};
|
|
1759
|
-
}
|
|
1760
|
-
});
|
|
1761
|
-
|
|
1762
|
-
// node_modules/pngjs/lib/packer-async.js
|
|
1763
|
-
var require_packer_async = __commonJS({
|
|
1764
|
-
"node_modules/pngjs/lib/packer-async.js"(exports2, module2) {
|
|
1765
|
-
"use strict";
|
|
1766
|
-
var util = require("util");
|
|
1767
|
-
var Stream = require("stream");
|
|
1768
|
-
var constants = require_constants();
|
|
1769
|
-
var Packer = require_packer();
|
|
1770
|
-
var PackerAsync = module2.exports = function(opt) {
|
|
1771
|
-
Stream.call(this);
|
|
1772
|
-
let options = opt || {};
|
|
1773
|
-
this._packer = new Packer(options);
|
|
1774
|
-
this._deflate = this._packer.createDeflate();
|
|
1775
|
-
this.readable = true;
|
|
1776
|
-
};
|
|
1777
|
-
util.inherits(PackerAsync, Stream);
|
|
1778
|
-
PackerAsync.prototype.pack = function(data, width, height, gamma) {
|
|
1779
|
-
this.emit("data", Buffer.from(constants.PNG_SIGNATURE));
|
|
1780
|
-
this.emit("data", this._packer.packIHDR(width, height));
|
|
1781
|
-
if (gamma) {
|
|
1782
|
-
this.emit("data", this._packer.packGAMA(gamma));
|
|
1783
|
-
}
|
|
1784
|
-
let filteredData = this._packer.filterData(data, width, height);
|
|
1785
|
-
this._deflate.on("error", this.emit.bind(this, "error"));
|
|
1786
|
-
this._deflate.on(
|
|
1787
|
-
"data",
|
|
1788
|
-
(function(compressedData) {
|
|
1789
|
-
this.emit("data", this._packer.packIDAT(compressedData));
|
|
1790
|
-
}).bind(this)
|
|
1791
|
-
);
|
|
1792
|
-
this._deflate.on(
|
|
1793
|
-
"end",
|
|
1794
|
-
(function() {
|
|
1795
|
-
this.emit("data", this._packer.packIEND());
|
|
1796
|
-
this.emit("end");
|
|
1797
|
-
}).bind(this)
|
|
1798
|
-
);
|
|
1799
|
-
this._deflate.end(filteredData);
|
|
1800
|
-
};
|
|
1801
|
-
}
|
|
1802
|
-
});
|
|
1803
|
-
|
|
1804
|
-
// node_modules/pngjs/lib/sync-inflate.js
|
|
1805
|
-
var require_sync_inflate = __commonJS({
|
|
1806
|
-
"node_modules/pngjs/lib/sync-inflate.js"(exports2, module2) {
|
|
1807
|
-
"use strict";
|
|
1808
|
-
var assert = require("assert").ok;
|
|
1809
|
-
var zlib = require("zlib");
|
|
1810
|
-
var util = require("util");
|
|
1811
|
-
var kMaxLength = require("buffer").kMaxLength;
|
|
1812
|
-
function Inflate(opts) {
|
|
1813
|
-
if (!(this instanceof Inflate)) {
|
|
1814
|
-
return new Inflate(opts);
|
|
1815
|
-
}
|
|
1816
|
-
if (opts && opts.chunkSize < zlib.Z_MIN_CHUNK) {
|
|
1817
|
-
opts.chunkSize = zlib.Z_MIN_CHUNK;
|
|
1818
|
-
}
|
|
1819
|
-
zlib.Inflate.call(this, opts);
|
|
1820
|
-
this._offset = this._offset === void 0 ? this._outOffset : this._offset;
|
|
1821
|
-
this._buffer = this._buffer || this._outBuffer;
|
|
1822
|
-
if (opts && opts.maxLength != null) {
|
|
1823
|
-
this._maxLength = opts.maxLength;
|
|
1824
|
-
}
|
|
1825
|
-
}
|
|
1826
|
-
function createInflate(opts) {
|
|
1827
|
-
return new Inflate(opts);
|
|
1828
|
-
}
|
|
1829
|
-
function _close(engine, callback) {
|
|
1830
|
-
if (callback) {
|
|
1831
|
-
process.nextTick(callback);
|
|
1832
|
-
}
|
|
1833
|
-
if (!engine._handle) {
|
|
1834
|
-
return;
|
|
1835
|
-
}
|
|
1836
|
-
engine._handle.close();
|
|
1837
|
-
engine._handle = null;
|
|
1838
|
-
}
|
|
1839
|
-
Inflate.prototype._processChunk = function(chunk, flushFlag, asyncCb) {
|
|
1840
|
-
if (typeof asyncCb === "function") {
|
|
1841
|
-
return zlib.Inflate._processChunk.call(this, chunk, flushFlag, asyncCb);
|
|
1842
|
-
}
|
|
1843
|
-
let self = this;
|
|
1844
|
-
let availInBefore = chunk && chunk.length;
|
|
1845
|
-
let availOutBefore = this._chunkSize - this._offset;
|
|
1846
|
-
let leftToInflate = this._maxLength;
|
|
1847
|
-
let inOff = 0;
|
|
1848
|
-
let buffers = [];
|
|
1849
|
-
let nread = 0;
|
|
1850
|
-
let error;
|
|
1851
|
-
this.on("error", function(err) {
|
|
1852
|
-
error = err;
|
|
1853
|
-
});
|
|
1854
|
-
function handleChunk(availInAfter, availOutAfter) {
|
|
1855
|
-
if (self._hadError) {
|
|
1856
|
-
return;
|
|
1857
|
-
}
|
|
1858
|
-
let have = availOutBefore - availOutAfter;
|
|
1859
|
-
assert(have >= 0, "have should not go down");
|
|
1860
|
-
if (have > 0) {
|
|
1861
|
-
let out = self._buffer.slice(self._offset, self._offset + have);
|
|
1862
|
-
self._offset += have;
|
|
1863
|
-
if (out.length > leftToInflate) {
|
|
1864
|
-
out = out.slice(0, leftToInflate);
|
|
1865
|
-
}
|
|
1866
|
-
buffers.push(out);
|
|
1867
|
-
nread += out.length;
|
|
1868
|
-
leftToInflate -= out.length;
|
|
1869
|
-
if (leftToInflate === 0) {
|
|
1870
|
-
return false;
|
|
1871
|
-
}
|
|
1872
|
-
}
|
|
1873
|
-
if (availOutAfter === 0 || self._offset >= self._chunkSize) {
|
|
1874
|
-
availOutBefore = self._chunkSize;
|
|
1875
|
-
self._offset = 0;
|
|
1876
|
-
self._buffer = Buffer.allocUnsafe(self._chunkSize);
|
|
1877
|
-
}
|
|
1878
|
-
if (availOutAfter === 0) {
|
|
1879
|
-
inOff += availInBefore - availInAfter;
|
|
1880
|
-
availInBefore = availInAfter;
|
|
1881
|
-
return true;
|
|
1882
|
-
}
|
|
1883
|
-
return false;
|
|
1884
|
-
}
|
|
1885
|
-
assert(this._handle, "zlib binding closed");
|
|
1886
|
-
let res;
|
|
1887
|
-
do {
|
|
1888
|
-
res = this._handle.writeSync(
|
|
1889
|
-
flushFlag,
|
|
1890
|
-
chunk,
|
|
1891
|
-
// in
|
|
1892
|
-
inOff,
|
|
1893
|
-
// in_off
|
|
1894
|
-
availInBefore,
|
|
1895
|
-
// in_len
|
|
1896
|
-
this._buffer,
|
|
1897
|
-
// out
|
|
1898
|
-
this._offset,
|
|
1899
|
-
//out_off
|
|
1900
|
-
availOutBefore
|
|
1901
|
-
);
|
|
1902
|
-
res = res || this._writeState;
|
|
1903
|
-
} while (!this._hadError && handleChunk(res[0], res[1]));
|
|
1904
|
-
if (this._hadError) {
|
|
1905
|
-
throw error;
|
|
1906
|
-
}
|
|
1907
|
-
if (nread >= kMaxLength) {
|
|
1908
|
-
_close(this);
|
|
1909
|
-
throw new RangeError(
|
|
1910
|
-
"Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes"
|
|
1911
|
-
);
|
|
1912
|
-
}
|
|
1913
|
-
let buf = Buffer.concat(buffers, nread);
|
|
1914
|
-
_close(this);
|
|
1915
|
-
return buf;
|
|
1916
|
-
};
|
|
1917
|
-
util.inherits(Inflate, zlib.Inflate);
|
|
1918
|
-
function zlibBufferSync(engine, buffer) {
|
|
1919
|
-
if (typeof buffer === "string") {
|
|
1920
|
-
buffer = Buffer.from(buffer);
|
|
1921
|
-
}
|
|
1922
|
-
if (!(buffer instanceof Buffer)) {
|
|
1923
|
-
throw new TypeError("Not a string or buffer");
|
|
1924
|
-
}
|
|
1925
|
-
let flushFlag = engine._finishFlushFlag;
|
|
1926
|
-
if (flushFlag == null) {
|
|
1927
|
-
flushFlag = zlib.Z_FINISH;
|
|
1928
|
-
}
|
|
1929
|
-
return engine._processChunk(buffer, flushFlag);
|
|
1930
|
-
}
|
|
1931
|
-
function inflateSync(buffer, opts) {
|
|
1932
|
-
return zlibBufferSync(new Inflate(opts), buffer);
|
|
1933
|
-
}
|
|
1934
|
-
module2.exports = exports2 = inflateSync;
|
|
1935
|
-
exports2.Inflate = Inflate;
|
|
1936
|
-
exports2.createInflate = createInflate;
|
|
1937
|
-
exports2.inflateSync = inflateSync;
|
|
1938
|
-
}
|
|
1939
|
-
});
|
|
1940
|
-
|
|
1941
|
-
// node_modules/pngjs/lib/sync-reader.js
|
|
1942
|
-
var require_sync_reader = __commonJS({
|
|
1943
|
-
"node_modules/pngjs/lib/sync-reader.js"(exports2, module2) {
|
|
1944
|
-
"use strict";
|
|
1945
|
-
var SyncReader = module2.exports = function(buffer) {
|
|
1946
|
-
this._buffer = buffer;
|
|
1947
|
-
this._reads = [];
|
|
1948
|
-
};
|
|
1949
|
-
SyncReader.prototype.read = function(length, callback) {
|
|
1950
|
-
this._reads.push({
|
|
1951
|
-
length: Math.abs(length),
|
|
1952
|
-
// if length < 0 then at most this length
|
|
1953
|
-
allowLess: length < 0,
|
|
1954
|
-
func: callback
|
|
1955
|
-
});
|
|
1956
|
-
};
|
|
1957
|
-
SyncReader.prototype.process = function() {
|
|
1958
|
-
while (this._reads.length > 0 && this._buffer.length) {
|
|
1959
|
-
let read = this._reads[0];
|
|
1960
|
-
if (this._buffer.length && (this._buffer.length >= read.length || read.allowLess)) {
|
|
1961
|
-
this._reads.shift();
|
|
1962
|
-
let buf = this._buffer;
|
|
1963
|
-
this._buffer = buf.slice(read.length);
|
|
1964
|
-
read.func.call(this, buf.slice(0, read.length));
|
|
1965
|
-
} else {
|
|
1966
|
-
break;
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1969
|
-
if (this._reads.length > 0) {
|
|
1970
|
-
throw new Error("There are some read requests waitng on finished stream");
|
|
1971
|
-
}
|
|
1972
|
-
if (this._buffer.length > 0) {
|
|
1973
|
-
throw new Error("unrecognised content at end of stream");
|
|
1974
|
-
}
|
|
1975
|
-
};
|
|
1976
|
-
}
|
|
1977
|
-
});
|
|
1978
|
-
|
|
1979
|
-
// node_modules/pngjs/lib/filter-parse-sync.js
|
|
1980
|
-
var require_filter_parse_sync = __commonJS({
|
|
1981
|
-
"node_modules/pngjs/lib/filter-parse-sync.js"(exports2) {
|
|
1982
|
-
"use strict";
|
|
1983
|
-
var SyncReader = require_sync_reader();
|
|
1984
|
-
var Filter = require_filter_parse();
|
|
1985
|
-
exports2.process = function(inBuffer, bitmapInfo) {
|
|
1986
|
-
let outBuffers = [];
|
|
1987
|
-
let reader = new SyncReader(inBuffer);
|
|
1988
|
-
let filter = new Filter(bitmapInfo, {
|
|
1989
|
-
read: reader.read.bind(reader),
|
|
1990
|
-
write: function(bufferPart) {
|
|
1991
|
-
outBuffers.push(bufferPart);
|
|
1992
|
-
},
|
|
1993
|
-
complete: function() {
|
|
1994
|
-
}
|
|
1995
|
-
});
|
|
1996
|
-
filter.start();
|
|
1997
|
-
reader.process();
|
|
1998
|
-
return Buffer.concat(outBuffers);
|
|
1999
|
-
};
|
|
2000
|
-
}
|
|
2001
|
-
});
|
|
2002
|
-
|
|
2003
|
-
// node_modules/pngjs/lib/parser-sync.js
|
|
2004
|
-
var require_parser_sync = __commonJS({
|
|
2005
|
-
"node_modules/pngjs/lib/parser-sync.js"(exports2, module2) {
|
|
2006
|
-
"use strict";
|
|
2007
|
-
var hasSyncZlib = true;
|
|
2008
|
-
var zlib = require("zlib");
|
|
2009
|
-
var inflateSync = require_sync_inflate();
|
|
2010
|
-
if (!zlib.deflateSync) {
|
|
2011
|
-
hasSyncZlib = false;
|
|
2012
|
-
}
|
|
2013
|
-
var SyncReader = require_sync_reader();
|
|
2014
|
-
var FilterSync = require_filter_parse_sync();
|
|
2015
|
-
var Parser = require_parser();
|
|
2016
|
-
var bitmapper = require_bitmapper();
|
|
2017
|
-
var formatNormaliser = require_format_normaliser();
|
|
2018
|
-
module2.exports = function(buffer, options) {
|
|
2019
|
-
if (!hasSyncZlib) {
|
|
2020
|
-
throw new Error(
|
|
2021
|
-
"To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
|
|
2022
|
-
);
|
|
2023
|
-
}
|
|
2024
|
-
let err;
|
|
2025
|
-
function handleError(_err_) {
|
|
2026
|
-
err = _err_;
|
|
2027
|
-
}
|
|
2028
|
-
let metaData;
|
|
2029
|
-
function handleMetaData(_metaData_) {
|
|
2030
|
-
metaData = _metaData_;
|
|
2031
|
-
}
|
|
2032
|
-
function handleTransColor(transColor) {
|
|
2033
|
-
metaData.transColor = transColor;
|
|
2034
|
-
}
|
|
2035
|
-
function handlePalette(palette) {
|
|
2036
|
-
metaData.palette = palette;
|
|
2037
|
-
}
|
|
2038
|
-
function handleSimpleTransparency() {
|
|
2039
|
-
metaData.alpha = true;
|
|
2040
|
-
}
|
|
2041
|
-
let gamma;
|
|
2042
|
-
function handleGamma(_gamma_) {
|
|
2043
|
-
gamma = _gamma_;
|
|
2044
|
-
}
|
|
2045
|
-
let inflateDataList = [];
|
|
2046
|
-
function handleInflateData(inflatedData2) {
|
|
2047
|
-
inflateDataList.push(inflatedData2);
|
|
2048
|
-
}
|
|
2049
|
-
let reader = new SyncReader(buffer);
|
|
2050
|
-
let parser = new Parser(options, {
|
|
2051
|
-
read: reader.read.bind(reader),
|
|
2052
|
-
error: handleError,
|
|
2053
|
-
metadata: handleMetaData,
|
|
2054
|
-
gamma: handleGamma,
|
|
2055
|
-
palette: handlePalette,
|
|
2056
|
-
transColor: handleTransColor,
|
|
2057
|
-
inflateData: handleInflateData,
|
|
2058
|
-
simpleTransparency: handleSimpleTransparency
|
|
2059
|
-
});
|
|
2060
|
-
parser.start();
|
|
2061
|
-
reader.process();
|
|
2062
|
-
if (err) {
|
|
2063
|
-
throw err;
|
|
2064
|
-
}
|
|
2065
|
-
let inflateData = Buffer.concat(inflateDataList);
|
|
2066
|
-
inflateDataList.length = 0;
|
|
2067
|
-
let inflatedData;
|
|
2068
|
-
if (metaData.interlace) {
|
|
2069
|
-
inflatedData = zlib.inflateSync(inflateData);
|
|
2070
|
-
} else {
|
|
2071
|
-
let rowSize = (metaData.width * metaData.bpp * metaData.depth + 7 >> 3) + 1;
|
|
2072
|
-
let imageSize = rowSize * metaData.height;
|
|
2073
|
-
inflatedData = inflateSync(inflateData, {
|
|
2074
|
-
chunkSize: imageSize,
|
|
2075
|
-
maxLength: imageSize
|
|
2076
|
-
});
|
|
2077
|
-
}
|
|
2078
|
-
inflateData = null;
|
|
2079
|
-
if (!inflatedData || !inflatedData.length) {
|
|
2080
|
-
throw new Error("bad png - invalid inflate data response");
|
|
2081
|
-
}
|
|
2082
|
-
let unfilteredData = FilterSync.process(inflatedData, metaData);
|
|
2083
|
-
inflateData = null;
|
|
2084
|
-
let bitmapData = bitmapper.dataToBitMap(unfilteredData, metaData);
|
|
2085
|
-
unfilteredData = null;
|
|
2086
|
-
let normalisedBitmapData = formatNormaliser(
|
|
2087
|
-
bitmapData,
|
|
2088
|
-
metaData,
|
|
2089
|
-
options.skipRescale
|
|
2090
|
-
);
|
|
2091
|
-
metaData.data = normalisedBitmapData;
|
|
2092
|
-
metaData.gamma = gamma || 0;
|
|
2093
|
-
return metaData;
|
|
2094
|
-
};
|
|
2095
|
-
}
|
|
2096
|
-
});
|
|
2097
|
-
|
|
2098
|
-
// node_modules/pngjs/lib/packer-sync.js
|
|
2099
|
-
var require_packer_sync = __commonJS({
|
|
2100
|
-
"node_modules/pngjs/lib/packer-sync.js"(exports2, module2) {
|
|
2101
|
-
"use strict";
|
|
2102
|
-
var hasSyncZlib = true;
|
|
2103
|
-
var zlib = require("zlib");
|
|
2104
|
-
if (!zlib.deflateSync) {
|
|
2105
|
-
hasSyncZlib = false;
|
|
2106
|
-
}
|
|
2107
|
-
var constants = require_constants();
|
|
2108
|
-
var Packer = require_packer();
|
|
2109
|
-
module2.exports = function(metaData, opt) {
|
|
2110
|
-
if (!hasSyncZlib) {
|
|
2111
|
-
throw new Error(
|
|
2112
|
-
"To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0"
|
|
2113
|
-
);
|
|
2114
|
-
}
|
|
2115
|
-
let options = opt || {};
|
|
2116
|
-
let packer = new Packer(options);
|
|
2117
|
-
let chunks = [];
|
|
2118
|
-
chunks.push(Buffer.from(constants.PNG_SIGNATURE));
|
|
2119
|
-
chunks.push(packer.packIHDR(metaData.width, metaData.height));
|
|
2120
|
-
if (metaData.gamma) {
|
|
2121
|
-
chunks.push(packer.packGAMA(metaData.gamma));
|
|
2122
|
-
}
|
|
2123
|
-
let filteredData = packer.filterData(
|
|
2124
|
-
metaData.data,
|
|
2125
|
-
metaData.width,
|
|
2126
|
-
metaData.height
|
|
2127
|
-
);
|
|
2128
|
-
let compressedData = zlib.deflateSync(
|
|
2129
|
-
filteredData,
|
|
2130
|
-
packer.getDeflateOptions()
|
|
2131
|
-
);
|
|
2132
|
-
filteredData = null;
|
|
2133
|
-
if (!compressedData || !compressedData.length) {
|
|
2134
|
-
throw new Error("bad png - invalid compressed data response");
|
|
2135
|
-
}
|
|
2136
|
-
chunks.push(packer.packIDAT(compressedData));
|
|
2137
|
-
chunks.push(packer.packIEND());
|
|
2138
|
-
return Buffer.concat(chunks);
|
|
2139
|
-
};
|
|
2140
|
-
}
|
|
2141
|
-
});
|
|
2142
|
-
|
|
2143
|
-
// node_modules/pngjs/lib/png-sync.js
|
|
2144
|
-
var require_png_sync = __commonJS({
|
|
2145
|
-
"node_modules/pngjs/lib/png-sync.js"(exports2) {
|
|
2146
|
-
"use strict";
|
|
2147
|
-
var parse = require_parser_sync();
|
|
2148
|
-
var pack = require_packer_sync();
|
|
2149
|
-
exports2.read = function(buffer, options) {
|
|
2150
|
-
return parse(buffer, options || {});
|
|
2151
|
-
};
|
|
2152
|
-
exports2.write = function(png, options) {
|
|
2153
|
-
return pack(png, options);
|
|
2154
|
-
};
|
|
2155
|
-
}
|
|
2156
|
-
});
|
|
2157
|
-
|
|
2158
|
-
// node_modules/pngjs/lib/png.js
|
|
2159
|
-
var require_png = __commonJS({
|
|
2160
|
-
"node_modules/pngjs/lib/png.js"(exports2) {
|
|
2161
|
-
"use strict";
|
|
2162
|
-
var util = require("util");
|
|
2163
|
-
var Stream = require("stream");
|
|
2164
|
-
var Parser = require_parser_async();
|
|
2165
|
-
var Packer = require_packer_async();
|
|
2166
|
-
var PNGSync = require_png_sync();
|
|
2167
|
-
var PNG2 = exports2.PNG = function(options) {
|
|
2168
|
-
Stream.call(this);
|
|
2169
|
-
options = options || {};
|
|
2170
|
-
this.width = options.width | 0;
|
|
2171
|
-
this.height = options.height | 0;
|
|
2172
|
-
this.data = this.width > 0 && this.height > 0 ? Buffer.alloc(4 * this.width * this.height) : null;
|
|
2173
|
-
if (options.fill && this.data) {
|
|
2174
|
-
this.data.fill(0);
|
|
2175
|
-
}
|
|
2176
|
-
this.gamma = 0;
|
|
2177
|
-
this.readable = this.writable = true;
|
|
2178
|
-
this._parser = new Parser(options);
|
|
2179
|
-
this._parser.on("error", this.emit.bind(this, "error"));
|
|
2180
|
-
this._parser.on("close", this._handleClose.bind(this));
|
|
2181
|
-
this._parser.on("metadata", this._metadata.bind(this));
|
|
2182
|
-
this._parser.on("gamma", this._gamma.bind(this));
|
|
2183
|
-
this._parser.on(
|
|
2184
|
-
"parsed",
|
|
2185
|
-
(function(data) {
|
|
2186
|
-
this.data = data;
|
|
2187
|
-
this.emit("parsed", data);
|
|
2188
|
-
}).bind(this)
|
|
2189
|
-
);
|
|
2190
|
-
this._packer = new Packer(options);
|
|
2191
|
-
this._packer.on("data", this.emit.bind(this, "data"));
|
|
2192
|
-
this._packer.on("end", this.emit.bind(this, "end"));
|
|
2193
|
-
this._parser.on("close", this._handleClose.bind(this));
|
|
2194
|
-
this._packer.on("error", this.emit.bind(this, "error"));
|
|
2195
|
-
};
|
|
2196
|
-
util.inherits(PNG2, Stream);
|
|
2197
|
-
PNG2.sync = PNGSync;
|
|
2198
|
-
PNG2.prototype.pack = function() {
|
|
2199
|
-
if (!this.data || !this.data.length) {
|
|
2200
|
-
this.emit("error", "No data provided");
|
|
2201
|
-
return this;
|
|
2202
|
-
}
|
|
2203
|
-
process.nextTick(
|
|
2204
|
-
(function() {
|
|
2205
|
-
this._packer.pack(this.data, this.width, this.height, this.gamma);
|
|
2206
|
-
}).bind(this)
|
|
2207
|
-
);
|
|
2208
|
-
return this;
|
|
2209
|
-
};
|
|
2210
|
-
PNG2.prototype.parse = function(data, callback) {
|
|
2211
|
-
if (callback) {
|
|
2212
|
-
let onParsed, onError;
|
|
2213
|
-
onParsed = (function(parsedData) {
|
|
2214
|
-
this.removeListener("error", onError);
|
|
2215
|
-
this.data = parsedData;
|
|
2216
|
-
callback(null, this);
|
|
2217
|
-
}).bind(this);
|
|
2218
|
-
onError = (function(err) {
|
|
2219
|
-
this.removeListener("parsed", onParsed);
|
|
2220
|
-
callback(err, null);
|
|
2221
|
-
}).bind(this);
|
|
2222
|
-
this.once("parsed", onParsed);
|
|
2223
|
-
this.once("error", onError);
|
|
2224
|
-
}
|
|
2225
|
-
this.end(data);
|
|
2226
|
-
return this;
|
|
2227
|
-
};
|
|
2228
|
-
PNG2.prototype.write = function(data) {
|
|
2229
|
-
this._parser.write(data);
|
|
2230
|
-
return true;
|
|
2231
|
-
};
|
|
2232
|
-
PNG2.prototype.end = function(data) {
|
|
2233
|
-
this._parser.end(data);
|
|
2234
|
-
};
|
|
2235
|
-
PNG2.prototype._metadata = function(metadata) {
|
|
2236
|
-
this.width = metadata.width;
|
|
2237
|
-
this.height = metadata.height;
|
|
2238
|
-
this.emit("metadata", metadata);
|
|
2239
|
-
};
|
|
2240
|
-
PNG2.prototype._gamma = function(gamma) {
|
|
2241
|
-
this.gamma = gamma;
|
|
2242
|
-
};
|
|
2243
|
-
PNG2.prototype._handleClose = function() {
|
|
2244
|
-
if (!this._parser.writable && !this._packer.readable) {
|
|
2245
|
-
this.emit("close");
|
|
2246
|
-
}
|
|
2247
|
-
};
|
|
2248
|
-
PNG2.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) {
|
|
2249
|
-
srcX |= 0;
|
|
2250
|
-
srcY |= 0;
|
|
2251
|
-
width |= 0;
|
|
2252
|
-
height |= 0;
|
|
2253
|
-
deltaX |= 0;
|
|
2254
|
-
deltaY |= 0;
|
|
2255
|
-
if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
|
|
2256
|
-
throw new Error("bitblt reading outside image");
|
|
2257
|
-
}
|
|
2258
|
-
if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
|
|
2259
|
-
throw new Error("bitblt writing outside image");
|
|
2260
|
-
}
|
|
2261
|
-
for (let y = 0; y < height; y++) {
|
|
2262
|
-
src.data.copy(
|
|
2263
|
-
dst.data,
|
|
2264
|
-
(deltaY + y) * dst.width + deltaX << 2,
|
|
2265
|
-
(srcY + y) * src.width + srcX << 2,
|
|
2266
|
-
(srcY + y) * src.width + srcX + width << 2
|
|
2267
|
-
);
|
|
2268
|
-
}
|
|
2269
|
-
};
|
|
2270
|
-
PNG2.prototype.bitblt = function(dst, srcX, srcY, width, height, deltaX, deltaY) {
|
|
2271
|
-
PNG2.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
|
|
2272
|
-
return this;
|
|
2273
|
-
};
|
|
2274
|
-
PNG2.adjustGamma = function(src) {
|
|
2275
|
-
if (src.gamma) {
|
|
2276
|
-
for (let y = 0; y < src.height; y++) {
|
|
2277
|
-
for (let x = 0; x < src.width; x++) {
|
|
2278
|
-
let idx = src.width * y + x << 2;
|
|
2279
|
-
for (let i = 0; i < 3; i++) {
|
|
2280
|
-
let sample = src.data[idx + i] / 255;
|
|
2281
|
-
sample = Math.pow(sample, 1 / 2.2 / src.gamma);
|
|
2282
|
-
src.data[idx + i] = Math.round(sample * 255);
|
|
2283
|
-
}
|
|
2284
|
-
}
|
|
2285
|
-
}
|
|
2286
|
-
src.gamma = 0;
|
|
2287
|
-
}
|
|
2288
|
-
};
|
|
2289
|
-
PNG2.prototype.adjustGamma = function() {
|
|
2290
|
-
PNG2.adjustGamma(this);
|
|
2291
|
-
};
|
|
2292
|
-
}
|
|
2293
|
-
});
|
|
2294
|
-
|
|
2295
|
-
// src/screenshot/pixel-match.ts
|
|
2296
|
-
var import_fs = __toESM(require("fs"));
|
|
2297
|
-
var import_pixelmatch = __toESM(require_pixelmatch());
|
|
2298
|
-
var import_pngjs = __toESM(require_png());
|
|
2299
|
-
function getMismatchedPixels(pixelMatchInput) {
|
|
2300
|
-
const imgA = import_fs.default.createReadStream(pixelMatchInput.imageAPath).pipe(new import_pngjs.PNG()).on("parsed", doneReading);
|
|
2301
|
-
const imgB = import_fs.default.createReadStream(pixelMatchInput.imageBPath).pipe(new import_pngjs.PNG()).on("parsed", doneReading);
|
|
2302
|
-
let filesRead = 0;
|
|
2303
|
-
function doneReading() {
|
|
2304
|
-
if (++filesRead < 2) return;
|
|
2305
|
-
const mismatchedPixels = (0, import_pixelmatch.default)(imgA.data, imgB.data, null, pixelMatchInput.width, pixelMatchInput.height, {
|
|
2306
|
-
threshold: pixelMatchInput.pixelmatchThreshold,
|
|
2307
|
-
includeAA: false
|
|
2308
|
-
});
|
|
2309
|
-
if (typeof process.send !== "function") {
|
|
2310
|
-
throw new Error("`getMismatchedPixels` must be run in a child process.");
|
|
2311
|
-
}
|
|
2312
|
-
process.send(mismatchedPixels);
|
|
2313
|
-
}
|
|
2314
|
-
}
|
|
2315
|
-
process.on("message", getMismatchedPixels);
|