UNPKG

@loaders.gl/textures

Version:

Framework-independent loaders for compressed and super compressed (basis) textures

1,529 lines (1,514 loc) 1.99 MB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to2, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to2, key) && key !== except) __defProp(to2, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to2; }; var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default")); var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); // ../../node_modules/contentstream/node_modules/isarray/index.js var require_isarray = __commonJS({ "../../node_modules/contentstream/node_modules/isarray/index.js"(exports, module2) { module2.exports = Array.isArray || function(arr) { return Object.prototype.toString.call(arr) == "[object Array]"; }; } }); // ../../node_modules/core-util-is/lib/util.js var require_util = __commonJS({ "../../node_modules/core-util-is/lib/util.js"(exports) { function isArray(arg) { if (Array.isArray) { return Array.isArray(arg); } return objectToString(arg) === "[object Array]"; } exports.isArray = isArray; function isBoolean3(arg) { return typeof arg === "boolean"; } exports.isBoolean = isBoolean3; function isNull(arg) { return arg === null; } exports.isNull = isNull; function isNullOrUndefined(arg) { return arg == null; } exports.isNullOrUndefined = isNullOrUndefined; function isNumber(arg) { return typeof arg === "number"; } exports.isNumber = isNumber; function isString(arg) { return typeof arg === "string"; } exports.isString = isString; function isSymbol(arg) { return typeof arg === "symbol"; } exports.isSymbol = isSymbol; function isUndefined(arg) { return arg === void 0; } exports.isUndefined = isUndefined; function isRegExp(re2) { return objectToString(re2) === "[object RegExp]"; } exports.isRegExp = isRegExp; function isObject3(arg) { return typeof arg === "object" && arg !== null; } exports.isObject = isObject3; function isDate(d2) { return objectToString(d2) === "[object Date]"; } exports.isDate = isDate; function isError(e2) { return objectToString(e2) === "[object Error]" || e2 instanceof Error; } exports.isError = isError; function isFunction3(arg) { return typeof arg === "function"; } exports.isFunction = isFunction3; function isPrimitive(arg) { return arg === null || typeof arg === "boolean" || typeof arg === "number" || typeof arg === "string" || typeof arg === "symbol" || // ES6 symbol typeof arg === "undefined"; } exports.isPrimitive = isPrimitive; exports.isBuffer = require("buffer").Buffer.isBuffer; function objectToString(o2) { return Object.prototype.toString.call(o2); } } }); // ../../node_modules/inherits/inherits_browser.js var require_inherits_browser = __commonJS({ "../../node_modules/inherits/inherits_browser.js"(exports, module2) { if (typeof Object.create === "function") { module2.exports = function inherits(ctor, superCtor) { if (superCtor) { ctor.super_ = superCtor; ctor.prototype = Object.create(superCtor.prototype, { constructor: { value: ctor, enumerable: false, writable: true, configurable: true } }); } }; } else { module2.exports = function inherits(ctor, superCtor) { if (superCtor) { ctor.super_ = superCtor; var TempCtor = function() { }; TempCtor.prototype = superCtor.prototype; ctor.prototype = new TempCtor(); ctor.prototype.constructor = ctor; } }; } } }); // ../../node_modules/inherits/inherits.js var require_inherits = __commonJS({ "../../node_modules/inherits/inherits.js"(exports, module2) { try { util = require("util"); if (typeof util.inherits !== "function") throw ""; module2.exports = util.inherits; } catch (e2) { module2.exports = require_inherits_browser(); } var util; } }); // ../../node_modules/contentstream/node_modules/string_decoder/index.js var require_string_decoder = __commonJS({ "../../node_modules/contentstream/node_modules/string_decoder/index.js"(exports) { var Buffer2 = require("buffer").Buffer; var isBufferEncoding = Buffer2.isEncoding || function(encoding) { switch (encoding && encoding.toLowerCase()) { case "hex": case "utf8": case "utf-8": case "ascii": case "binary": case "base64": case "ucs2": case "ucs-2": case "utf16le": case "utf-16le": case "raw": return true; default: return false; } }; function assertEncoding(encoding) { if (encoding && !isBufferEncoding(encoding)) { throw new Error("Unknown encoding: " + encoding); } } var StringDecoder = exports.StringDecoder = function(encoding) { this.encoding = (encoding || "utf8").toLowerCase().replace(/[-_]/, ""); assertEncoding(encoding); switch (this.encoding) { case "utf8": this.surrogateSize = 3; break; case "ucs2": case "utf16le": this.surrogateSize = 2; this.detectIncompleteChar = utf16DetectIncompleteChar; break; case "base64": this.surrogateSize = 3; this.detectIncompleteChar = base64DetectIncompleteChar; break; default: this.write = passThroughWrite; return; } this.charBuffer = new Buffer2(6); this.charReceived = 0; this.charLength = 0; }; StringDecoder.prototype.write = function(buffer) { var charStr = ""; while (this.charLength) { var available = buffer.length >= this.charLength - this.charReceived ? this.charLength - this.charReceived : buffer.length; buffer.copy(this.charBuffer, this.charReceived, 0, available); this.charReceived += available; if (this.charReceived < this.charLength) { return ""; } buffer = buffer.slice(available, buffer.length); charStr = this.charBuffer.slice(0, this.charLength).toString(this.encoding); var charCode = charStr.charCodeAt(charStr.length - 1); if (charCode >= 55296 && charCode <= 56319) { this.charLength += this.surrogateSize; charStr = ""; continue; } this.charReceived = this.charLength = 0; if (buffer.length === 0) { return charStr; } break; } this.detectIncompleteChar(buffer); var end = buffer.length; if (this.charLength) { buffer.copy(this.charBuffer, 0, buffer.length - this.charReceived, end); end -= this.charReceived; } charStr += buffer.toString(this.encoding, 0, end); var end = charStr.length - 1; var charCode = charStr.charCodeAt(end); if (charCode >= 55296 && charCode <= 56319) { var size = this.surrogateSize; this.charLength += size; this.charReceived += size; this.charBuffer.copy(this.charBuffer, size, 0, size); buffer.copy(this.charBuffer, 0, 0, size); return charStr.substring(0, end); } return charStr; }; StringDecoder.prototype.detectIncompleteChar = function(buffer) { var i2 = buffer.length >= 3 ? 3 : buffer.length; for (; i2 > 0; i2--) { var c2 = buffer[buffer.length - i2]; if (i2 == 1 && c2 >> 5 == 6) { this.charLength = 2; break; } if (i2 <= 2 && c2 >> 4 == 14) { this.charLength = 3; break; } if (i2 <= 3 && c2 >> 3 == 30) { this.charLength = 4; break; } } this.charReceived = i2; }; StringDecoder.prototype.end = function(buffer) { var res = ""; if (buffer && buffer.length) res = this.write(buffer); if (this.charReceived) { var cr2 = this.charReceived; var buf = this.charBuffer; var enc = this.encoding; res += buf.slice(0, cr2).toString(enc); } return res; }; function passThroughWrite(buffer) { return buffer.toString(this.encoding); } function utf16DetectIncompleteChar(buffer) { this.charReceived = buffer.length % 2; this.charLength = this.charReceived ? 2 : 0; } function base64DetectIncompleteChar(buffer) { this.charReceived = buffer.length % 3; this.charLength = this.charReceived ? 3 : 0; } } }); // ../../node_modules/contentstream/node_modules/readable-stream/lib/_stream_readable.js var require_stream_readable = __commonJS({ "../../node_modules/contentstream/node_modules/readable-stream/lib/_stream_readable.js"(exports, module2) { module2.exports = Readable5; var isArray = require_isarray(); var Buffer2 = require("buffer").Buffer; Readable5.ReadableState = ReadableState; var EE = require("events").EventEmitter; if (!EE.listenerCount) EE.listenerCount = function(emitter, type) { return emitter.listeners(type).length; }; var Stream3 = require("stream"); var util = require_util(); util.inherits = require_inherits(); var StringDecoder; util.inherits(Readable5, Stream3); function ReadableState(options, stream2) { options = options || {}; var hwm = options.highWaterMark; this.highWaterMark = hwm || hwm === 0 ? hwm : 16 * 1024; this.highWaterMark = ~~this.highWaterMark; this.buffer = []; this.length = 0; this.pipes = null; this.pipesCount = 0; this.flowing = false; this.ended = false; this.endEmitted = false; this.reading = false; this.calledRead = false; this.sync = true; this.needReadable = false; this.emittedReadable = false; this.readableListening = false; this.objectMode = !!options.objectMode; this.defaultEncoding = options.defaultEncoding || "utf8"; this.ranOut = false; this.awaitDrain = 0; this.readingMore = false; this.decoder = null; this.encoding = null; if (options.encoding) { if (!StringDecoder) StringDecoder = require_string_decoder().StringDecoder; this.decoder = new StringDecoder(options.encoding); this.encoding = options.encoding; } } function Readable5(options) { if (!(this instanceof Readable5)) return new Readable5(options); this._readableState = new ReadableState(options, this); this.readable = true; Stream3.call(this); } Readable5.prototype.push = function(chunk, encoding) { var state = this._readableState; if (typeof chunk === "string" && !state.objectMode) { encoding = encoding || state.defaultEncoding; if (encoding !== state.encoding) { chunk = new Buffer2(chunk, encoding); encoding = ""; } } return readableAddChunk(this, state, chunk, encoding, false); }; Readable5.prototype.unshift = function(chunk) { var state = this._readableState; return readableAddChunk(this, state, chunk, "", true); }; function readableAddChunk(stream2, state, chunk, encoding, addToFront) { var er2 = chunkInvalid(state, chunk); if (er2) { stream2.emit("error", er2); } else if (chunk === null || chunk === void 0) { state.reading = false; if (!state.ended) onEofChunk(stream2, state); } else if (state.objectMode || chunk && chunk.length > 0) { if (state.ended && !addToFront) { var e2 = new Error("stream.push() after EOF"); stream2.emit("error", e2); } else if (state.endEmitted && addToFront) { var e2 = new Error("stream.unshift() after end event"); stream2.emit("error", e2); } else { if (state.decoder && !addToFront && !encoding) chunk = state.decoder.write(chunk); state.length += state.objectMode ? 1 : chunk.length; if (addToFront) { state.buffer.unshift(chunk); } else { state.reading = false; state.buffer.push(chunk); } if (state.needReadable) emitReadable(stream2); maybeReadMore(stream2, state); } } else if (!addToFront) { state.reading = false; } return needMoreData(state); } function needMoreData(state) { return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0); } Readable5.prototype.setEncoding = function(enc) { if (!StringDecoder) StringDecoder = require_string_decoder().StringDecoder; this._readableState.decoder = new StringDecoder(enc); this._readableState.encoding = enc; }; var MAX_HWM = 8388608; function roundUpToNextPowerOf2(n2) { if (n2 >= MAX_HWM) { n2 = MAX_HWM; } else { n2--; for (var p2 = 1; p2 < 32; p2 <<= 1) n2 |= n2 >> p2; n2++; } return n2; } function howMuchToRead(n2, state) { if (state.length === 0 && state.ended) return 0; if (state.objectMode) return n2 === 0 ? 0 : 1; if (n2 === null || isNaN(n2)) { if (state.flowing && state.buffer.length) return state.buffer[0].length; else return state.length; } if (n2 <= 0) return 0; if (n2 > state.highWaterMark) state.highWaterMark = roundUpToNextPowerOf2(n2); if (n2 > state.length) { if (!state.ended) { state.needReadable = true; return 0; } else return state.length; } return n2; } Readable5.prototype.read = function(n2) { var state = this._readableState; state.calledRead = true; var nOrig = n2; var ret; if (typeof n2 !== "number" || n2 > 0) state.emittedReadable = false; if (n2 === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) { emitReadable(this); return null; } n2 = howMuchToRead(n2, state); if (n2 === 0 && state.ended) { ret = null; if (state.length > 0 && state.decoder) { ret = fromList(n2, state); state.length -= ret.length; } if (state.length === 0) endReadable(this); return ret; } var doRead = state.needReadable; if (state.length - n2 <= state.highWaterMark) doRead = true; if (state.ended || state.reading) doRead = false; if (doRead) { state.reading = true; state.sync = true; if (state.length === 0) state.needReadable = true; this._read(state.highWaterMark); state.sync = false; } if (doRead && !state.reading) n2 = howMuchToRead(nOrig, state); if (n2 > 0) ret = fromList(n2, state); else ret = null; if (ret === null) { state.needReadable = true; n2 = 0; } state.length -= n2; if (state.length === 0 && !state.ended) state.needReadable = true; if (state.ended && !state.endEmitted && state.length === 0) endReadable(this); return ret; }; function chunkInvalid(state, chunk) { var er2 = null; if (!Buffer2.isBuffer(chunk) && "string" !== typeof chunk && chunk !== null && chunk !== void 0 && !state.objectMode) { er2 = new TypeError("Invalid non-string/buffer chunk"); } return er2; } function onEofChunk(stream2, state) { if (state.decoder && !state.ended) { var chunk = state.decoder.end(); if (chunk && chunk.length) { state.buffer.push(chunk); state.length += state.objectMode ? 1 : chunk.length; } } state.ended = true; if (state.length > 0) emitReadable(stream2); else endReadable(stream2); } function emitReadable(stream2) { var state = stream2._readableState; state.needReadable = false; if (state.emittedReadable) return; state.emittedReadable = true; if (state.sync) process.nextTick(function() { emitReadable_(stream2); }); else emitReadable_(stream2); } function emitReadable_(stream2) { stream2.emit("readable"); } function maybeReadMore(stream2, state) { if (!state.readingMore) { state.readingMore = true; process.nextTick(function() { maybeReadMore_(stream2, state); }); } } function maybeReadMore_(stream2, state) { var len = state.length; while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) { stream2.read(0); if (len === state.length) break; else len = state.length; } state.readingMore = false; } Readable5.prototype._read = function(n2) { this.emit("error", new Error("not implemented")); }; Readable5.prototype.pipe = function(dest, pipeOpts) { var src = this; var state = this._readableState; switch (state.pipesCount) { case 0: state.pipes = dest; break; case 1: state.pipes = [state.pipes, dest]; break; default: state.pipes.push(dest); break; } state.pipesCount += 1; var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; var endFn = doEnd ? onend : cleanup; if (state.endEmitted) process.nextTick(endFn); else src.once("end", endFn); dest.on("unpipe", onunpipe); function onunpipe(readable) { if (readable !== src) return; cleanup(); } function onend() { dest.end(); } var ondrain = pipeOnDrain(src); dest.on("drain", ondrain); function cleanup() { dest.removeListener("close", onclose); dest.removeListener("finish", onfinish); dest.removeListener("drain", ondrain); dest.removeListener("error", onerror); dest.removeListener("unpipe", onunpipe); src.removeListener("end", onend); src.removeListener("end", cleanup); if (!dest._writableState || dest._writableState.needDrain) ondrain(); } function onerror(er2) { unpipe(); dest.removeListener("error", onerror); if (EE.listenerCount(dest, "error") === 0) dest.emit("error", er2); } if (!dest._events || !dest._events.error) dest.on("error", onerror); else if (isArray(dest._events.error)) dest._events.error.unshift(onerror); else dest._events.error = [onerror, dest._events.error]; function onclose() { dest.removeListener("finish", onfinish); unpipe(); } dest.once("close", onclose); function onfinish() { dest.removeListener("close", onclose); unpipe(); } dest.once("finish", onfinish); function unpipe() { src.unpipe(dest); } dest.emit("pipe", src); if (!state.flowing) { this.on("readable", pipeOnReadable); state.flowing = true; process.nextTick(function() { flow(src); }); } return dest; }; function pipeOnDrain(src) { return function() { var dest = this; var state = src._readableState; state.awaitDrain--; if (state.awaitDrain === 0) flow(src); }; } function flow(src) { var state = src._readableState; var chunk; state.awaitDrain = 0; function write(dest, i2, list) { var written = dest.write(chunk); if (false === written) { state.awaitDrain++; } } while (state.pipesCount && null !== (chunk = src.read())) { if (state.pipesCount === 1) write(state.pipes, 0, null); else forEach2(state.pipes, write); src.emit("data", chunk); if (state.awaitDrain > 0) return; } if (state.pipesCount === 0) { state.flowing = false; if (EE.listenerCount(src, "data") > 0) emitDataEvents(src); return; } state.ranOut = true; } function pipeOnReadable() { if (this._readableState.ranOut) { this._readableState.ranOut = false; flow(this); } } Readable5.prototype.unpipe = function(dest) { var state = this._readableState; if (state.pipesCount === 0) return this; if (state.pipesCount === 1) { if (dest && dest !== state.pipes) return this; if (!dest) dest = state.pipes; state.pipes = null; state.pipesCount = 0; this.removeListener("readable", pipeOnReadable); state.flowing = false; if (dest) dest.emit("unpipe", this); return this; } if (!dest) { var dests = state.pipes; var len = state.pipesCount; state.pipes = null; state.pipesCount = 0; this.removeListener("readable", pipeOnReadable); state.flowing = false; for (var i2 = 0; i2 < len; i2++) dests[i2].emit("unpipe", this); return this; } var i2 = indexOf(state.pipes, dest); if (i2 === -1) return this; state.pipes.splice(i2, 1); state.pipesCount -= 1; if (state.pipesCount === 1) state.pipes = state.pipes[0]; dest.emit("unpipe", this); return this; }; Readable5.prototype.on = function(ev, fn) { var res = Stream3.prototype.on.call(this, ev, fn); if (ev === "data" && !this._readableState.flowing) emitDataEvents(this); if (ev === "readable" && this.readable) { var state = this._readableState; if (!state.readableListening) { state.readableListening = true; state.emittedReadable = false; state.needReadable = true; if (!state.reading) { this.read(0); } else if (state.length) { emitReadable(this, state); } } } return res; }; Readable5.prototype.addListener = Readable5.prototype.on; Readable5.prototype.resume = function() { emitDataEvents(this); this.read(0); this.emit("resume"); }; Readable5.prototype.pause = function() { emitDataEvents(this, true); this.emit("pause"); }; function emitDataEvents(stream2, startPaused) { var state = stream2._readableState; if (state.flowing) { throw new Error("Cannot switch to old mode now."); } var paused = startPaused || false; var readable = false; stream2.readable = true; stream2.pipe = Stream3.prototype.pipe; stream2.on = stream2.addListener = Stream3.prototype.on; stream2.on("readable", function() { readable = true; var c2; while (!paused && null !== (c2 = stream2.read())) stream2.emit("data", c2); if (c2 === null) { readable = false; stream2._readableState.needReadable = true; } }); stream2.pause = function() { paused = true; this.emit("pause"); }; stream2.resume = function() { paused = false; if (readable) process.nextTick(function() { stream2.emit("readable"); }); else this.read(0); this.emit("resume"); }; stream2.emit("readable"); } Readable5.prototype.wrap = function(stream2) { var state = this._readableState; var paused = false; var self2 = this; stream2.on("end", function() { if (state.decoder && !state.ended) { var chunk = state.decoder.end(); if (chunk && chunk.length) self2.push(chunk); } self2.push(null); }); stream2.on("data", function(chunk) { if (state.decoder) chunk = state.decoder.write(chunk); if (state.objectMode && (chunk === null || chunk === void 0)) return; else if (!state.objectMode && (!chunk || !chunk.length)) return; var ret = self2.push(chunk); if (!ret) { paused = true; stream2.pause(); } }); for (var i2 in stream2) { if (typeof stream2[i2] === "function" && typeof this[i2] === "undefined") { this[i2] = function(method) { return function() { return stream2[method].apply(stream2, arguments); }; }(i2); } } var events = ["error", "close", "destroy", "pause", "resume"]; forEach2(events, function(ev) { stream2.on(ev, self2.emit.bind(self2, ev)); }); self2._read = function(n2) { if (paused) { paused = false; stream2.resume(); } }; return self2; }; Readable5._fromList = fromList; function fromList(n2, state) { var list = state.buffer; var length = state.length; var stringMode = !!state.decoder; var objectMode = !!state.objectMode; var ret; if (list.length === 0) return null; if (length === 0) ret = null; else if (objectMode) ret = list.shift(); else if (!n2 || n2 >= length) { if (stringMode) ret = list.join(""); else ret = Buffer2.concat(list, length); list.length = 0; } else { if (n2 < list[0].length) { var buf = list[0]; ret = buf.slice(0, n2); list[0] = buf.slice(n2); } else if (n2 === list[0].length) { ret = list.shift(); } else { if (stringMode) ret = ""; else ret = new Buffer2(n2); var c2 = 0; for (var i2 = 0, l2 = list.length; i2 < l2 && c2 < n2; i2++) { var buf = list[0]; var cpy = Math.min(n2 - c2, buf.length); if (stringMode) ret += buf.slice(0, cpy); else buf.copy(ret, c2, 0, cpy); if (cpy < buf.length) list[0] = buf.slice(cpy); else list.shift(); c2 += cpy; } } } return ret; } function endReadable(stream2) { var state = stream2._readableState; if (state.length > 0) throw new Error("endReadable called on non-empty stream"); if (!state.endEmitted && state.calledRead) { state.ended = true; process.nextTick(function() { if (!state.endEmitted && state.length === 0) { state.endEmitted = true; stream2.readable = false; stream2.emit("end"); } }); } } function forEach2(xs, f2) { for (var i2 = 0, l2 = xs.length; i2 < l2; i2++) { f2(xs[i2], i2); } } function indexOf(xs, x2) { for (var i2 = 0, l2 = xs.length; i2 < l2; i2++) { if (xs[i2] === x2) return i2; } return -1; } } }); // ../../node_modules/contentstream/node_modules/readable-stream/lib/_stream_duplex.js var require_stream_duplex = __commonJS({ "../../node_modules/contentstream/node_modules/readable-stream/lib/_stream_duplex.js"(exports, module2) { module2.exports = Duplex; var objectKeys = Object.keys || function(obj) { var keys = []; for (var key in obj) keys.push(key); return keys; }; var util = require_util(); util.inherits = require_inherits(); var Readable5 = require_stream_readable(); var Writable = require_stream_writable(); util.inherits(Duplex, Readable5); forEach2(objectKeys(Writable.prototype), function(method) { if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; }); function Duplex(options) { if (!(this instanceof Duplex)) return new Duplex(options); Readable5.call(this, options); Writable.call(this, options); if (options && options.readable === false) this.readable = false; if (options && options.writable === false) this.writable = false; this.allowHalfOpen = true; if (options && options.allowHalfOpen === false) this.allowHalfOpen = false; this.once("end", onend); } function onend() { if (this.allowHalfOpen || this._writableState.ended) return; process.nextTick(this.end.bind(this)); } function forEach2(xs, f2) { for (var i2 = 0, l2 = xs.length; i2 < l2; i2++) { f2(xs[i2], i2); } } } }); // ../../node_modules/contentstream/node_modules/readable-stream/lib/_stream_writable.js var require_stream_writable = __commonJS({ "../../node_modules/contentstream/node_modules/readable-stream/lib/_stream_writable.js"(exports, module2) { module2.exports = Writable; var Buffer2 = require("buffer").Buffer; Writable.WritableState = WritableState; var util = require_util(); util.inherits = require_inherits(); var Stream3 = require("stream"); util.inherits(Writable, Stream3); function WriteReq(chunk, encoding, cb) { this.chunk = chunk; this.encoding = encoding; this.callback = cb; } function WritableState(options, stream2) { options = options || {}; var hwm = options.highWaterMark; this.highWaterMark = hwm || hwm === 0 ? hwm : 16 * 1024; this.objectMode = !!options.objectMode; this.highWaterMark = ~~this.highWaterMark; this.needDrain = false; this.ending = false; this.ended = false; this.finished = false; var noDecode = options.decodeStrings === false; this.decodeStrings = !noDecode; this.defaultEncoding = options.defaultEncoding || "utf8"; this.length = 0; this.writing = false; this.sync = true; this.bufferProcessing = false; this.onwrite = function(er2) { onwrite(stream2, er2); }; this.writecb = null; this.writelen = 0; this.buffer = []; this.errorEmitted = false; } function Writable(options) { var Duplex = require_stream_duplex(); if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options); this._writableState = new WritableState(options, this); this.writable = true; Stream3.call(this); } Writable.prototype.pipe = function() { this.emit("error", new Error("Cannot pipe. Not readable.")); }; function writeAfterEnd(stream2, state, cb) { var er2 = new Error("write after end"); stream2.emit("error", er2); process.nextTick(function() { cb(er2); }); } function validChunk(stream2, state, chunk, cb) { var valid = true; if (!Buffer2.isBuffer(chunk) && "string" !== typeof chunk && chunk !== null && chunk !== void 0 && !state.objectMode) { var er2 = new TypeError("Invalid non-string/buffer chunk"); stream2.emit("error", er2); process.nextTick(function() { cb(er2); }); valid = false; } return valid; } Writable.prototype.write = function(chunk, encoding, cb) { var state = this._writableState; var ret = false; if (typeof encoding === "function") { cb = encoding; encoding = null; } if (Buffer2.isBuffer(chunk)) encoding = "buffer"; else if (!encoding) encoding = state.defaultEncoding; if (typeof cb !== "function") cb = function() { }; if (state.ended) writeAfterEnd(this, state, cb); else if (validChunk(this, state, chunk, cb)) ret = writeOrBuffer(this, state, chunk, encoding, cb); return ret; }; function decodeChunk(state, chunk, encoding) { if (!state.objectMode && state.decodeStrings !== false && typeof chunk === "string") { chunk = new Buffer2(chunk, encoding); } return chunk; } function writeOrBuffer(stream2, state, chunk, encoding, cb) { chunk = decodeChunk(state, chunk, encoding); if (Buffer2.isBuffer(chunk)) encoding = "buffer"; var len = state.objectMode ? 1 : chunk.length; state.length += len; var ret = state.length < state.highWaterMark; if (!ret) state.needDrain = true; if (state.writing) state.buffer.push(new WriteReq(chunk, encoding, cb)); else doWrite(stream2, state, len, chunk, encoding, cb); return ret; } function doWrite(stream2, state, len, chunk, encoding, cb) { state.writelen = len; state.writecb = cb; state.writing = true; state.sync = true; stream2._write(chunk, encoding, state.onwrite); state.sync = false; } function onwriteError(stream2, state, sync, er2, cb) { if (sync) process.nextTick(function() { cb(er2); }); else cb(er2); stream2._writableState.errorEmitted = true; stream2.emit("error", er2); } function onwriteStateUpdate(state) { state.writing = false; state.writecb = null; state.length -= state.writelen; state.writelen = 0; } function onwrite(stream2, er2) { var state = stream2._writableState; var sync = state.sync; var cb = state.writecb; onwriteStateUpdate(state); if (er2) onwriteError(stream2, state, sync, er2, cb); else { var finished2 = needFinish(stream2, state); if (!finished2 && !state.bufferProcessing && state.buffer.length) clearBuffer(stream2, state); if (sync) { process.nextTick(function() { afterWrite(stream2, state, finished2, cb); }); } else { afterWrite(stream2, state, finished2, cb); } } } function afterWrite(stream2, state, finished2, cb) { if (!finished2) onwriteDrain(stream2, state); cb(); if (finished2) finishMaybe(stream2, state); } function onwriteDrain(stream2, state) { if (state.length === 0 && state.needDrain) { state.needDrain = false; stream2.emit("drain"); } } function clearBuffer(stream2, state) { state.bufferProcessing = true; for (var c2 = 0; c2 < state.buffer.length; c2++) { var entry = state.buffer[c2]; var chunk = entry.chunk; var encoding = entry.encoding; var cb = entry.callback; var len = state.objectMode ? 1 : chunk.length; doWrite(stream2, state, len, chunk, encoding, cb); if (state.writing) { c2++; break; } } state.bufferProcessing = false; if (c2 < state.buffer.length) state.buffer = state.buffer.slice(c2); else state.buffer.length = 0; } Writable.prototype._write = function(chunk, encoding, cb) { cb(new Error("not implemented")); }; Writable.prototype.end = function(chunk, encoding, cb) { var state = this._writableState; if (typeof chunk === "function") { cb = chunk; chunk = null; encoding = null; } else if (typeof encoding === "function") { cb = encoding; encoding = null; } if (typeof chunk !== "undefined" && chunk !== null) this.write(chunk, encoding); if (!state.ending && !state.finished) endWritable(this, state, cb); }; function needFinish(stream2, state) { return state.ending && state.length === 0 && !state.finished && !state.writing; } function finishMaybe(stream2, state) { var need = needFinish(stream2, state); if (need) { state.finished = true; stream2.emit("finish"); } return need; } function endWritable(stream2, state, cb) { state.ending = true; finishMaybe(stream2, state); if (cb) { if (state.finished) process.nextTick(cb); else stream2.once("finish", cb); } state.ended = true; } } }); // ../../node_modules/contentstream/node_modules/readable-stream/lib/_stream_transform.js var require_stream_transform = __commonJS({ "../../node_modules/contentstream/node_modules/readable-stream/lib/_stream_transform.js"(exports, module2) { module2.exports = Transform; var Duplex = require_stream_duplex(); var util = require_util(); util.inherits = require_inherits(); util.inherits(Transform, Duplex); function TransformState(options, stream2) { this.afterTransform = function(er2, data) { return afterTransform(stream2, er2, data); }; this.needTransform = false; this.transforming = false; this.writecb = null; this.writechunk = null; } function afterTransform(stream2, er2, data) { var ts = stream2._transformState; ts.transforming = false; var cb = ts.writecb; if (!cb) return stream2.emit("error", new Error("no writecb in Transform class")); ts.writechunk = null; ts.writecb = null; if (data !== null && data !== void 0) stream2.push(data); if (cb) cb(er2); var rs = stream2._readableState; rs.reading = false; if (rs.needReadable || rs.length < rs.highWaterMark) { stream2._read(rs.highWaterMark); } } function Transform(options) { if (!(this instanceof Transform)) return new Transform(options); Duplex.call(this, options); var ts = this._transformState = new TransformState(options, this); var stream2 = this; this._readableState.needReadable = true; this._readableState.sync = false; this.once("finish", function() { if ("function" === typeof this._flush) this._flush(function(er2) { done(stream2, er2); }); else done(stream2); }); } Transform.prototype.push = function(chunk, encoding) { this._transformState.needTransform = false; return Duplex.prototype.push.call(this, chunk, encoding); }; Transform.prototype._transform = function(chunk, encoding, cb) { throw new Error("not implemented"); }; Transform.prototype._write = function(chunk, encoding, cb) { var ts = this._transformState; ts.writecb = cb; ts.writechunk = chunk; ts.writeencoding = encoding; if (!ts.transforming) { var rs = this._readableState; if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark); } }; Transform.prototype._read = function(n2) { var ts = this._transformState; if (ts.writechunk !== null && ts.writecb && !ts.transforming) { ts.transforming = true; this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); } else { ts.needTransform = true; } }; function done(stream2, er2) { if (er2) return stream2.emit("error", er2); var ws = stream2._writableState; var rs = stream2._readableState; var ts = stream2._transformState; if (ws.length) throw new Error("calling transform done when ws.length != 0"); if (ts.transforming) throw new Error("calling transform done when still transforming"); return stream2.push(null); } } }); // ../../node_modules/contentstream/node_modules/readable-stream/lib/_stream_passthrough.js var require_stream_passthrough = __commonJS({ "../../node_modules/contentstream/node_modules/readable-stream/lib/_stream_passthrough.js"(exports, module2) { module2.exports = PassThrough; var Transform = require_stream_transform(); var util = require_util(); util.inherits = require_inherits(); util.inherits(PassThrough, Transform); function PassThrough(options) { if (!(this instanceof PassThrough)) return new PassThrough(options); Transform.call(this, options); } PassThrough.prototype._transform = function(chunk, encoding, cb) { cb(null, chunk); }; } }); // ../../node_modules/contentstream/node_modules/readable-stream/readable.js var require_readable = __commonJS({ "../../node_modules/contentstream/node_modules/readable-stream/readable.js"(exports, module2) { var Stream3 = require("stream"); exports = module2.exports = require_stream_readable(); exports.Stream = Stream3; exports.Readable = exports; exports.Writable = require_stream_writable(); exports.Duplex = require_stream_duplex(); exports.Transform = require_stream_transform(); exports.PassThrough = require_stream_passthrough(); if (!process.browser && process.env.READABLE_STREAM === "disable") { module2.exports = require("stream"); } } }); // ../../node_modules/contentstream/index.js var require_contentstream = __commonJS({ "../../node_modules/contentstream/index.js"(exports, module2) { "use strict"; var Readable5 = require_readable().Readable; var util = require("util"); module2.exports = ContentStream; function ContentStream(obj, options) { if (!(this instanceof ContentStream)) { return new ContentStream(obj, options); } Readable5.call(this, options); if (obj === null || obj === void 0) { obj = String(obj); } this._obj = obj; } util.inherits(ContentStream, Readable5); ContentStream.prototype._read = function(n2) { var obj = this._obj; if (typeof obj === "string") { this.push(new Buffer(obj)); } else if (Buffer.isBuffer(obj)) { this.push(obj); } else { this.push(new Buffer(JSON.stringify(obj))); } this.push(null); }; } }); // ../../node_modules/gif-encoder/node_modules/isarray/index.js var require_isarray2 = __commonJS({ "../../node_modules/gif-encoder/node_modules/isarray/index.js"(exports, module2) { module2.exports = Array.isArray || function(arr) { return Object.prototype.toString.call(arr) == "[object Array]"; }; } }); // ../../node_modules/gif-encoder/node_modules/readable-stream/lib/_stream_writable.js var require_stream_writable2 = __commonJS({ "../../node_modules/gif-encoder/node_modules/readable-stream/lib/_stream_writable.js"(exports, module2) { module2.exports = Writable; var Buffer2 = require("buffer").Buffer; Writable.WritableState = WritableState; var util = require_util(); util.inherits = require_inherits(); var Stream3 = require("stream"); util.inherits(Writable, Stream3); function WriteReq(chunk, encoding, cb) { this.chunk = chunk; this.encoding = encoding; this.callback = cb; } function WritableState(options, stream2) { var Duplex = require_stream_duplex2(); options = options || {}; var hwm = options.highWaterMark; var defaultHwm = options.objectMode ? 16 : 16 * 1024; this.highWaterMark = hwm || hwm === 0 ? hwm : defaultHwm; this.objectMode = !!options.objectMode; if (stream2 instanceof Duplex) this.objectMode = this.objectMode || !!options.writableObjectMode; this.highWaterMark = ~~this.highWaterMark; this.needDrain = false; this.ending = false; this.ended = false; this.finished = false; var noDecode = options.decodeStrings === false; this.decodeStrings = !noDecode; this.defaultEncoding = options.defaultEncoding || "utf8"; this.length = 0; this.writing = false; this.corked = 0; this.sync = true; this.bufferProcessing = false; this.onwrite = function(er2) { onwrite(stream2, er2); }; this.writecb = null; this.writelen = 0; this.buffer = []; this.pendingcb = 0; this.prefinished = false; this.errorEmitted = false; } function Writable(options) { var Duplex = require_stream_duplex2(); if (!(this instanceof Writable) && !(this instanceof Duplex)) return new Writable(options); this._writableState = new WritableState(options, this); this.writable = true; Stream3.call(this); } Writable.prototype.pipe = function() { this.emit("error", new Error("Cannot pipe. Not readable.")); }; function writeAfterEnd(stream2, state, cb) { var er2 = new Error("write after end"); stream2.emit("error", er2); process.nextTick(function() { cb(er2); }); } function validChunk(stream2, state, chunk, cb) { var valid = true; if (!util.isBuffer(chunk) && !util.isString(chunk) && !util.isNullOrUndefined(chunk) && !state.objectMode) { var er2 = new TypeError("Invalid non-string/buffer chunk"); stream2.emit("error", er2); process.nextTick(function() { cb(er2); }); valid = false; } return valid; } Writable.prototype.write = function(chunk, encoding, cb) { var state = this._writableState; var ret = false; if (util.isFunction(encoding)) { cb = encoding; encoding = null; } if (util.isBuffer(chunk)) encoding = "buffer"; else if (!encoding) encoding = state.defaultEncoding; if (!util.isFunction(cb)) cb = function() { }; if (state.ended) writeAfterEnd(this, state, cb); else if (validChunk(this, state, chunk, cb)) { state.pendingcb++; ret = writeOrBuffer(this, state, chunk, encoding, cb); } return ret; }; Writable.prototype.cork = function() { var state = this._writableState; state.corked++; }; Writable.prototype.uncork = function() { var state = this._writableState; if (state.corked) { state.corked--; if (!state.writing && !state.corked && !state.finished && !state.bufferProcessing && state.buffer.length) clearBuffer(this, state); } }; function decodeChunk(state, chunk, encoding) { if (!state.objectMode && state.decodeStrings !== false && util.isString(chunk)) { chunk = new Buffer2(chunk, encoding); } return chunk; } function writeOrBuffer(stream2, state, chunk, encoding, cb) { chunk = decodeChunk(state, chunk, encoding); if (util.isBuffer(chunk)) encoding = "buffer"; var len = state.objectMode ? 1 : chunk.length; state.length += len; var ret = state.length < state.highWaterMark; if (!ret) state.needDrain = true; if (state.writing || state.corked) state.buffer.push(new WriteReq(chunk, encoding, cb)); else doWrite(stream2, state, false, len, chunk, encoding, cb); return ret; } function doWrite(stream2, state, writev, len, chunk, encoding, cb) { state.writelen = len; state.writecb = cb; state.writing = true; state.sync = true; if (writev) stream2._writev(chunk, state.onwrite); else stream2._write(chunk, encoding, state.onwrite); state.sync = false; } function onwriteError(stream2, state, sync, er2, cb) { if (sync) process.nextTick(function() { state.pendingcb--; cb(er2); }); else { state.pendingcb--; cb(er2); } stream2._writableState.errorEmitted = true; stream2.emit("error", er2); } function onwriteStateUpdate(state) { state.writing = false; state.writecb = null; state.length -= state.writelen; state.writelen = 0; } function onwrite(stream2, er2) { var state = stream2._writableState; var sync = state.sync; var cb = state.writecb; onwriteStateUpdate(state); if (er2) onwriteError(stream2, state, sync, er2, cb); else { var finished2 = needFinish(stream2, state); if (!finished2 && !state.corked && !state.bufferProcessing && state.buffer.length) { clearBuffer(stream2, state); } if (sync) {