From 31f3472b34012253fdf9c038e8350ffdad12dbfc Mon Sep 17 00:00:00 2001 From: Daniel Bulant Date: Fri, 29 May 2020 19:23:47 +0200 Subject: [PATCH] Fix relative import exports --- lib/bitmapper.js | 4 ++-- lib/bitpacker.js | 4 ++-- lib/chunkstream.js | 7 +++++-- lib/constants.js | 2 +- lib/crc.js | 6 ++++-- lib/filter-pack.js | 4 ++-- lib/filter-parse-async.js | 10 ++++++---- lib/filter-parse-sync.js | 6 +++--- lib/filter-parse.js | 10 ++++++---- lib/format-normaliser.js | 2 +- lib/interlace.js | 9 +++++++-- lib/packer-async.js | 11 +++++++---- lib/packer-sync.js | 10 ++++------ lib/packer.js | 15 +++++++++------ lib/paeth-predictor.js | 2 +- lib/parser-async.js | 19 +++++++++++-------- lib/parser-sync.js | 15 ++++++++------- lib/png-sync.js | 13 +++++++++---- lib/png.js | 7 ++++--- lib/sync-inflate.js | 11 ++++------- lib/sync-reader.js | 6 ++++-- 21 files changed, 100 insertions(+), 73 deletions(-) diff --git a/lib/bitmapper.js b/lib/bitmapper.js index b6cc7c9..41ad5e6 100644 --- a/lib/bitmapper.js +++ b/lib/bitmapper.js @@ -1,4 +1,4 @@ -let interlaceUtils = require("./interlace"); +import interlaceUtils from "./interlace.js"; let pixelBppMapper = [ // 0 - dummy entry @@ -197,7 +197,7 @@ function mapImageCustomBit(image, pxData, getPxPos, bpp, bits, maxBit) { } } -exports.dataToBitMap = function (data, bitmapInfo) { +export default function (data, bitmapInfo) { let width = bitmapInfo.width; let height = bitmapInfo.height; let depth = bitmapInfo.depth; diff --git a/lib/bitpacker.js b/lib/bitpacker.js index d7e4915..bd865ec 100644 --- a/lib/bitpacker.js +++ b/lib/bitpacker.js @@ -1,6 +1,6 @@ -let constants = require("./constants"); +import constants from "./constants.js"; -module.exports = function (dataIn, width, height, options) { +export default function (dataIn, width, height, options) { let outHasAlpha = [constants.COLORTYPE_COLOR_ALPHA, constants.COLORTYPE_ALPHA].indexOf( options.colorType diff --git a/lib/chunkstream.js b/lib/chunkstream.js index bb50c7e..72e6207 100644 --- a/lib/chunkstream.js +++ b/lib/chunkstream.js @@ -1,7 +1,7 @@ let util = require("util"); let Stream = require("stream"); -let ChunkStream = (module.exports = function () { +let ChunkStream = function () { Stream.call(this); this._buffers = []; @@ -12,7 +12,10 @@ let ChunkStream = (module.exports = function () { this._encoding = "utf8"; this.writable = true; -}); +}; + +export default ChunkStream; + util.inherits(ChunkStream, Stream); ChunkStream.prototype.read = function (length, callback) { diff --git a/lib/constants.js b/lib/constants.js index f569a37..5a3f5fc 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -1,4 +1,4 @@ -module.exports = { +export default { PNG_SIGNATURE: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a], TYPE_IHDR: 0x49484452, diff --git a/lib/crc.js b/lib/crc.js index f6c3f62..2d616bb 100644 --- a/lib/crc.js +++ b/lib/crc.js @@ -14,9 +14,11 @@ let crcTable = []; } })(); -let CrcCalculator = (module.exports = function () { +let CrcCalculator = function () { this._crc = -1; -}); +}; + +export default CrcCalculator; CrcCalculator.prototype.write = function (data) { for (let i = 0; i < data.length; i++) { diff --git a/lib/filter-pack.js b/lib/filter-pack.js index 0c25282..ba41358 100644 --- a/lib/filter-pack.js +++ b/lib/filter-pack.js @@ -1,4 +1,4 @@ -let paethPredictor = require("./paeth-predictor"); +import paethPredictor from "./paeth-predictor.js"; function filterNone(pxData, pxPos, byteWidth, rawData, rawPos) { for (let x = 0; x < byteWidth; x++) { @@ -125,7 +125,7 @@ let filterSums = { 4: filterSumPaeth, }; -module.exports = function (pxData, width, height, options, bpp) { +export default function (pxData, width, height, options, bpp) { let filterTypes; if (!("filterType" in options) || options.filterType === -1) { filterTypes = [0, 1, 2, 3, 4]; diff --git a/lib/filter-parse-async.js b/lib/filter-parse-async.js index d2e1b2b..9652652 100644 --- a/lib/filter-parse-async.js +++ b/lib/filter-parse-async.js @@ -1,8 +1,8 @@ +import ChunkStream from "./chunkstream.js"; +import Filter from "./filter-parse.js"; let util = require("util"); -let ChunkStream = require("./chunkstream"); -let Filter = require("./filter-parse"); -let FilterAsync = (module.exports = function (bitmapInfo) { +let FilterAsync = function (bitmapInfo) { ChunkStream.call(this); let buffers = []; @@ -18,5 +18,7 @@ let FilterAsync = (module.exports = function (bitmapInfo) { }); this._filter.start(); -}); +}; util.inherits(FilterAsync, ChunkStream); + +export default FilterAsync; \ No newline at end of file diff --git a/lib/filter-parse-sync.js b/lib/filter-parse-sync.js index bb86849..01e57ff 100644 --- a/lib/filter-parse-sync.js +++ b/lib/filter-parse-sync.js @@ -1,7 +1,7 @@ -let SyncReader = require("./sync-reader"); -let Filter = require("./filter-parse"); +import SyncReader from "./sync-reader.js"; +import Filter from "./filter-parse.js"; -exports.process = function (inBuffer, bitmapInfo) { +export default function (inBuffer, bitmapInfo) { let outBuffers = []; let reader = new SyncReader(inBuffer); let filter = new Filter(bitmapInfo, { diff --git a/lib/filter-parse.js b/lib/filter-parse.js index 4e29ef2..44ac8ee 100644 --- a/lib/filter-parse.js +++ b/lib/filter-parse.js @@ -1,5 +1,5 @@ -let interlaceUtils = require("./interlace"); -let paethPredictor = require("./paeth-predictor"); +import interlaceUtils from "./interlace.js"; +import paethPredictor from "./paeth-predictor.js"; function getByteWidth(width, bpp, depth) { let byteWidth = width * bpp; @@ -9,7 +9,7 @@ function getByteWidth(width, bpp, depth) { return byteWidth; } -let Filter = (module.exports = function (bitmapInfo, dependencies) { +let Filter = function (bitmapInfo, dependencies) { let width = bitmapInfo.width; let height = bitmapInfo.height; let interlace = bitmapInfo.interlace; @@ -50,7 +50,9 @@ let Filter = (module.exports = function (bitmapInfo, dependencies) { } else { this._xComparison = 1; } -}); +}; + +export default Filter; Filter.prototype.start = function () { this.read( diff --git a/lib/format-normaliser.js b/lib/format-normaliser.js index d3525ab..5c0bdbc 100644 --- a/lib/format-normaliser.js +++ b/lib/format-normaliser.js @@ -61,7 +61,7 @@ function scaleDepth(indata, outdata, width, height, depth) { } } -module.exports = function (indata, imageData) { +export default function (indata, imageData) { let depth = imageData.depth; let width = imageData.width; let height = imageData.height; diff --git a/lib/interlace.js b/lib/interlace.js index 8ced51a..1319747 100644 --- a/lib/interlace.js +++ b/lib/interlace.js @@ -47,7 +47,7 @@ let imagePasses = [ }, ]; -exports.getImagePasses = function (width, height) { +export var getImagePasses = function (width, height) { let images = []; let xLeftOver = width % 8; let yLeftOver = height % 8; @@ -78,7 +78,7 @@ exports.getImagePasses = function (width, height) { return images; }; -exports.getInterlaceIterator = function (width) { +export var getInterlaceIterator = function (width) { return function (x, y, pass) { let outerXLeftOver = x % imagePasses[pass].x.length; let outerX = @@ -91,3 +91,8 @@ exports.getInterlaceIterator = function (width) { return outerX * 4 + outerY * width * 4; }; }; + +export default { + getImagePasses, + getInterlaceIterator +} \ No newline at end of file diff --git a/lib/packer-async.js b/lib/packer-async.js index a70c1e5..2a78ee1 100644 --- a/lib/packer-async.js +++ b/lib/packer-async.js @@ -1,9 +1,10 @@ let util = require("util"); let Stream = require("stream"); -let constants = require("./constants"); -let Packer = require("./packer"); -let PackerAsync = (module.exports = function (opt) { +import constants from "./constants.js"; +import Packer from "./packer.js"; + +let PackerAsync = function (opt) { Stream.call(this); let options = opt || {}; @@ -12,9 +13,11 @@ let PackerAsync = (module.exports = function (opt) { this._deflate = this._packer.createDeflate(); this.readable = true; -}); +}; util.inherits(PackerAsync, Stream); +export default PackerAsync; + PackerAsync.prototype.pack = function (data, width, height, gamma) { // Signature this.emit("data", Buffer.from(constants.PNG_SIGNATURE)); diff --git a/lib/packer-sync.js b/lib/packer-sync.js index 9eeb64f..1e67873 100644 --- a/lib/packer-sync.js +++ b/lib/packer-sync.js @@ -1,12 +1,10 @@ +import constants from "./constants.js"; +import Packer from "./packer.js"; + let hasSyncZlib = true; let zlib = require("zlib"); -if (!zlib.deflateSync) { - hasSyncZlib = false; -} -let constants = require("./constants"); -let Packer = require("./packer"); -module.exports = function (metaData, opt) { +export default function (metaData, opt) { if (!hasSyncZlib) { throw new Error( "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0" diff --git a/lib/packer.js b/lib/packer.js index 1632681..d0fb65a 100644 --- a/lib/packer.js +++ b/lib/packer.js @@ -1,10 +1,11 @@ -let constants = require("./constants"); -let CrcStream = require("./crc"); -let bitPacker = require("./bitpacker"); -let filter = require("./filter-pack"); +import constants from "./constants.js"; +import CrcStream from "./crc.js"; +import bitPacker from "./bitpacker.js"; +import filter from "./filter-pack.js"; + let zlib = require("zlib"); -let Packer = (module.exports = function (options) { +let Packer = function (options) { this._options = options; options.deflateChunkSize = options.deflateChunkSize || 32 * 1024; @@ -57,7 +58,9 @@ let Packer = (module.exports = function (options) { "option bit depth:" + options.bitDepth + " is not supported at present" ); } -}); +}; + +export default Packer; Packer.prototype.getDeflateOptions = function () { return { diff --git a/lib/paeth-predictor.js b/lib/paeth-predictor.js index 1af2996..99737de 100644 --- a/lib/paeth-predictor.js +++ b/lib/paeth-predictor.js @@ -1,4 +1,4 @@ -module.exports = function paethPredictor(left, above, upLeft) { +export default function paethPredictor(left, above, upLeft) { let paeth = left + above - upLeft; let pLeft = Math.abs(paeth - left); let pAbove = Math.abs(paeth - above); diff --git a/lib/parser-async.js b/lib/parser-async.js index 481b00a..afe3d1e 100644 --- a/lib/parser-async.js +++ b/lib/parser-async.js @@ -1,12 +1,13 @@ +import ChunkStream from "./chunkstream.js"; +import FilterAsync from "./filter-parse-async.js"; +import Parser from "./parser.js"; +import bitmapper from "./bitmapper.js"; +import formatNormaliser from "./format-normaliser.js"; + let util = require("util"); let zlib = require("zlib"); -let ChunkStream = require("./chunkstream"); -let FilterAsync = require("./filter-parse-async"); -let Parser = require("./parser"); -let bitmapper = require("./bitmapper"); -let formatNormaliser = require("./format-normaliser"); -let ParserAsync = (module.exports = function (options) { +let ParserAsync = function (options) { ChunkStream.call(this); this._parser = new Parser(options, { @@ -25,9 +26,11 @@ let ParserAsync = (module.exports = function (options) { this.writable = true; this._parser.start(); -}); +}; util.inherits(ParserAsync, ChunkStream); +export default ParserAsync; + ParserAsync.prototype._handleError = function (err) { this.emit("error", err); @@ -150,7 +153,7 @@ ParserAsync.prototype._complete = function (filteredData) { let normalisedBitmapData; try { - let bitmapData = bitmapper.dataToBitMap(filteredData, this._bitmapInfo); + let bitmapData = bitmapper(filteredData, this._bitmapInfo); normalisedBitmapData = formatNormaliser(bitmapData, this._bitmapInfo); bitmapData = null; diff --git a/lib/parser-sync.js b/lib/parser-sync.js index b6a0a48..2220b37 100644 --- a/lib/parser-sync.js +++ b/lib/parser-sync.js @@ -1,16 +1,17 @@ +import inflateSync from "./sync-inflate.js"; +import SyncReader from "./sync-reader.js"; +import FilterSync from "./filter-parse-sync.js"; +import bitmapper from "./bitmapper.js"; +import formatNormaliser from "./format-normaliser.js"; +import Parser from "./parser.js"; + let hasSyncZlib = true; let zlib = require("zlib"); -let inflateSync = require("./sync-inflate"); if (!zlib.deflateSync) { hasSyncZlib = false; } -let SyncReader = require("./sync-reader"); -let FilterSync = require("./filter-parse-sync"); -let Parser = require("./parser"); -let bitmapper = require("./bitmapper"); -let formatNormaliser = require("./format-normaliser"); -module.exports = function (buffer, options) { +export default function (buffer, options) { if (!hasSyncZlib) { throw new Error( "To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0" diff --git a/lib/png-sync.js b/lib/png-sync.js index f3080e5..778f6b5 100644 --- a/lib/png-sync.js +++ b/lib/png-sync.js @@ -1,10 +1,15 @@ -let parse = require("./parser-sync"); -let pack = require("./packer-sync"); +import parse from "./parser-sync.js"; +import pack from "./packer-sync.js"; -exports.read = function (buffer, options) { +export var read = function (buffer, options) { return parse(buffer, options || {}); }; -exports.write = function (png, options) { +export var write = function (png, options) { return pack(png, options); }; + +export default { + read, + write +} \ No newline at end of file diff --git a/lib/png.js b/lib/png.js index 1a36874..3e2fc09 100644 --- a/lib/png.js +++ b/lib/png.js @@ -1,8 +1,9 @@ +import Parser from "./parser-async.js"; +import Packer from "./packer-async.js"; +import PNGSync from "./png-sync.js"; + let util = require("util"); let Stream = require("stream"); -let Parser = require("./parser-async"); -let Packer = require("./packer-async"); -let PNGSync = require("./png-sync"); let PNG = (exports.PNG = function (options) { Stream.call(this); diff --git a/lib/sync-inflate.js b/lib/sync-inflate.js index 24e9c00..cff61e8 100644 --- a/lib/sync-inflate.js +++ b/lib/sync-inflate.js @@ -4,7 +4,7 @@ let util = require("util"); let kMaxLength = require("buffer").kMaxLength; -function Inflate(opts) { +export function Inflate(opts) { if (!(this instanceof Inflate)) { return new Inflate(opts); } @@ -24,7 +24,7 @@ function Inflate(opts) { } } -function createInflate(opts) { +export function createInflate(opts) { return new Inflate(opts); } @@ -156,11 +156,8 @@ function zlibBufferSync(engine, buffer) { return engine._processChunk(buffer, flushFlag); } -function inflateSync(buffer, opts) { +export function inflateSync(buffer, opts) { return zlibBufferSync(new Inflate(opts), buffer); } -module.exports = exports = inflateSync; -exports.Inflate = Inflate; -exports.createInflate = createInflate; -exports.inflateSync = inflateSync; +export default inflateSync; diff --git a/lib/sync-reader.js b/lib/sync-reader.js index c82d659..1ef66db 100644 --- a/lib/sync-reader.js +++ b/lib/sync-reader.js @@ -1,7 +1,9 @@ -let SyncReader = (module.exports = function (buffer) { +let SyncReader = function (buffer) { this._buffer = buffer; this._reads = []; -}); +}; + +export default SyncReader; SyncReader.prototype.read = function (length, callback) { this._reads.push({