mirror of
https://github.com/danbulant/pngjs
synced 2026-05-19 04:08:44 +00:00
Fix relative import exports
This commit is contained in:
parent
8eabb688fe
commit
31f3472b34
21 changed files with 100 additions and 73 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
module.exports = {
|
||||
export default {
|
||||
PNG_SIGNATURE: [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a],
|
||||
|
||||
TYPE_IHDR: 0x49484452,
|
||||
|
|
|
|||
|
|
@ -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++) {
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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, {
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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({
|
||||
|
|
|
|||
Loading…
Reference in a new issue