| 1499 | */var z1=KU(),t76=Rr6(),ni_={left:"low",top:"low",low:"low",center:"centre",centre:"centre",right:"high",bottom:"high",high:"high"},ii_=["failOn","limitInputPixels","unlimited","animated","autoOrient","density","ignoreIcc","page","pages","sequentialRead","jp2","openSlide","pdf","raw","svg","tiff","failOnError","openSlideLevel","pdfBackground","tiffSubifd"];function zX4(q){let K=ii_.filter((_)=>z1.defined(q[_])).map((_)=>[_,q[_]]);return K.length?Object.fromEntries(K):void 0}function ri_(q,K,_){let z={autoOrient:!1,failOn:"warning",limitInputPixels:268402689,ignoreIcc:!1,unlimited:!1,sequentialRead:!0};if(z1.string(q))z.file=q;else if(z1.buffer(q)){if(q.length===0)throw Error("Input Buffer is empty");z.buffer=q}else if(z1.arrayBuffer(q)){if(q.byteLength===0)throw Error("Input bit Array is empty");z.buffer=Buffer.from(q,0,q.byteLength)}else if(z1.typedArray(q)){if(q.length===0)throw Error("Input Bit Array is empty");z.buffer=Buffer.from(q.buffer,q.byteOffset,q.byteLength)}else if(z1.plainObject(q)&&!z1.defined(K)){if(K=q,zX4(K))z.buffer=[]}else if(!z1.defined(q)&&!z1.defined(K)&&z1.object(_)&&_.allowStream)z.buffer=[];else if(Array.isArray(q))if(q.length>1)if(!this.options.joining)this.options.joining=!0,this.options.join=q.map((Y)=>this._createInputDescriptor(Y));else throw Error("Recursive join is unsupported");else throw Error("Expected at least two images to join");else throw Error(`Unsupported input '${q}' of type ${typeof q}${z1.defined(K)?` when also providing options of type ${typeof K}`:""}`);if(z1.object(K)){if(z1.defined(K.failOnError))if(z1.bool(K.failOnError))z.failOn=K.failOnError?"warning":"none";else throw z1.invalidParameterError("failOnError","boolean",K.failOnError);if(z1.defined(K.failOn))if(z1.string(K.failOn)&&z1.inArray(K.failOn,["none","truncated","error","warning"]))z.failOn=K.failOn;else throw z1.invalidParameterError("failOn","one of: none, truncated, error, warning",K.failOn);if(z1.defined(K.autoOrient))if(z1.bool(K.autoOrient))z.autoOrient=K.autoOrient;else throw z1.invalidParameterError("autoOrient","boolean",K.autoOrient);if(z1.defined(K.density))if(z1.inRange(K.density,1,1e5))z.density=K.density;else throw z1.invalidParameterError("density","number between 1 and 100000",K.density);if(z1.defined(K.ignoreIcc))if(z1.bool(K.ignoreIcc))z.ignoreIcc=K.ignoreIcc;else throw z1.invalidParameterError("ignoreIcc","boolean",K.ignoreIcc);if(z1.defined(K.limitInputPixels))if(z1.bool(K.limitInputPixels))z.limitInputPixels=K.limitInputPixels?268402689:0;else if(z1.integer(K.limitInputPixels)&&z1.inRange(K.limitInputPixels,0,Number.MAX_SAFE_INTEGER))z.limitInputPixels=K.limitInputPixels;else throw z1.invalidParameterError("limitInputPixels","positive integer",K.limitInputPixels);if(z1.defined(K.unlimited))if(z1.bool(K.unlimited))z.unlimited=K.unlimited;else throw z1.invalidParameterError("unlimited","boolean",K.unlimited);if(z1.defined(K.sequentialRead))if(z1.bool(K.sequentialRead))z.sequentialRead=K.sequentialRead;else throw z1.invalidParameterError("sequentialRead","boolean",K.sequentialRead);if(z1.defined(K.raw)){if(z1.object(K.raw)&&z1.integer(K.raw.width)&&K.raw.width>0&&z1.integer(K.raw.height)&&K.raw.height>0&&z1.integer(K.raw.channels)&&z1.inRange(K.raw.channels,1,4))switch(z.rawWidth=K.raw.width,z.rawHeight=K.raw.height,z.rawChannels=K.raw.channels,q.constructor){case Uint8Array:case Uint8ClampedArray:z.rawDepth="uchar";break;case Int8Array:z.rawDepth="char";break;case Uint16Array:z.rawDepth="ushort";break;case Int16Array:z.rawDepth="short";break;case Uint32Array:z.rawDepth="uint";break;case Int32Array:z.rawDepth="int";break;case Float32Array:z.rawDepth="float";break;case Float64Array:z.rawDepth="double";break;default:z.rawDepth="uchar";break}else throw Error("Expected width, height and channels for raw pixel input");if(z.rawPremultiplied=!1,z1.defined(K.raw.premultiplied))if(z1.bool(K.raw.premultiplied))z.rawPremultiplied=K.raw.premultiplied;else throw z1.invalidParameterError("raw.premultiplied","boolean",K.raw.premultiplied);if(z.rawPageHeight=0,z1.defined(K.raw.pageHeight))if(z1.integer(K.raw.pageHeight)&&K.raw.pageHeight>0&&K.raw.pageHeight<=K.raw.height){if(K.raw.height%K.raw.pageHeight!==0)throw Error(`Expected raw.height ${K.raw.height} to be a multiple of raw.pageHeight ${K.raw.pageHeight}`);z.rawPageHeight=K.raw.pageHeight}else throw z1.invalidParameterError("raw.pageHeight","positive integer",K.raw.pageHeight)}if(z1.defined(K.animated))if(z1.bool(K.animated))z.pages=K.animated?-1:1;else throw z1.invalidParameterError("animated","boolean",K.animated);if(z1.defined(K.pages))if(z1.integer(K.pages)&&z1.inRange(K.pages,-1,1e5))z.pages=K.pages;else throw z1.invalidParameterError("pages","integer between -1 and 100000",K.pages);if(z1.defined(K.page))if(z1.integer(K.page)&&z1.inRange(K.page,0,1e5))z.page=K.page;else throw z1.invalidParameterError("page","integer between 0 and 100000",K.page);if(z1.object(K.openSlide)&&z1.defined(K.openSlide.level))if(z1.integer(K.openSlide.level)&&z1.inRange(K.openSlide.level,0,256))z.openSlideLevel=K.openSlide.level;else throw z1.invalidParameterError("openSlide.level","integer between 0 and 256",K.openSlide.level);else if(z1.defined(K.level))if(z1.integer(K.level)&&z1.inRange(K.level,0,256))z.openSlideLevel=K.level;else throw z1.invalidParameterError("level","integer between 0 and 256",K.level);if(z1.object(K.tiff)&&z1.defined(K.tiff.subifd))if(z1.integer(K.tiff.subifd)&&z1.inRange(K.tiff.subifd,-1,1e5))z.tiffSubifd=K.tiff.subifd;else throw z1.invalidParameterError("tiff.subifd","integer between -1 and 100000",K.tiff.subifd);else if(z1.defined(K.subifd))if(z1.integer(K.subifd)&&z1.inRange(K.subifd,-1,1e5))z.tiffSubifd=K.subifd;else throw z1.invalidParameterError("subifd","integer between -1 and 100000",K.subifd);if(z1.object(K.svg)){if(z1.defined(K.svg.stylesheet))if(z1.string(K.svg.stylesheet))z.svgStylesheet=K.svg.stylesheet;else throw z1.invalidParameterError("svg.stylesheet","string",K.svg.stylesheet);if(z1.defined(K.svg.highBitdepth))if(z1.bool(K.svg.highBitdepth))z.svgHighBitdepth=K.svg.highBitdepth;else throw z1.invalidParameterError("svg.highBitdepth","boolean",K.svg.highBitdepth)}if(z1.object(K.pdf)&&z1.defined(K.pdf.background))z.pdfBackground=this._getBackgroundColourOption(K.pdf.background);else if(z1.defined(K.pdfBackground))z.pdfBackground=this._getBackgroundColourOption(K.pdfBackground);if(z1.object(K.jp2)&&z1.defined(K.jp2.oneshot))if(z1.bool(K.jp2.oneshot))z.jp2Oneshot=K.jp2.oneshot;else throw z1.invalidParameterError("jp2.oneshot","boolean",K.jp2.oneshot);if(z1.defined(K.create))if(z1.object(K.create)&&z1.integer(K.create.width)&&K.create.width>0&&z1.integer(K.create.height)&&K.create.height>0&&z1.integer(K.create.channels)){if(z.createWidth=K.create.width,z.createHeight=K.create.height,z.createChannels=K.create.channels,z.createPageHeight=0,z1.defined(K.create.pageHeight))if(z1.integer(K.create.pageHeight)&&K.create.pageHeight>0&&K.create.pageHeight<=K.create.height){if(K.create.height%K.create.pageHeight!==0)throw Error(`Expected create.height ${K.create.height} to be a multiple of create.pageHeight ${K.create.pageHeight}`);z.createPageHeight=K.create.pageHeight}else throw z1.invalidParameterError("create.pageHeight","positive integer",K.create.pageHeight);if(z1.defined(K.create.noise)){if(!z1.object(K.create.noise))throw Error("Expected noise to be an object");if(K.create.noise.type!=="gaussian")throw Error("Only gaussian noise is supported at the moment");if(z.createNoiseType=K.create.noise.type,!z1.inRange(K.create.channels,1,4))throw z1.invalidParameterError("create.channels","number between 1 and 4",K.create.channels);if(z.createNoiseMean=128,z1.defined(K.create.noise.mean))if(z1.number(K.create.noise.mean)&&z1.inRange(K.create.noise.mean,0,1e4))z.createNoiseMean=K.create.noise.mean;else throw z1.invalidParameterError("create.noise.mean","number between 0 and 10000",K.create.noise.mean);if(z.createNoiseSigma=30,z1.defined(K.create.noise.sigma))if(z1.number(K.create.noise.sigma)&&z1.inRange(K.create.noise.sigma,0,1e4))z.createNoiseSigma=K.create.noise.sigma;else throw z1.invalidParameterError("create.noise.sigma","number between 0 and 10000",K.create.noise.sigma)}else if(z1.defined(K.create.background)){if(!z1.inRange(K.create.channels,3,4))throw z1.invalidParameterError("create.channels","number between 3 and 4",K.create.channels);z.createBackground=this._getBackgroundColourOption(K.create.background)}else throw Error("Expected valid noise or background to create a new input image");delete z.buffer}else throw Error("Expected valid width, height and channels to create a new input image");if(z1.defined(K.text))if(z1.object(K.text)&&z1.string(K.text.text)){if(z.textValue=K.text.text,z1.defined(K.text.height)&&z1.defined(K.text.dpi))throw Error("Expected only one of dpi or height");if(z1.defined(K.text.font))if(z1.string(K.text.font))z.textFont=K.text.font;else throw z1.invalidParameterError("text.font","string",K.text.font);if(z1.defined(K.text.fontfile))if(z1.string(K.text.fontfile))z.textFontfile=K.text.fontfile;else throw z1.invalidParameterError("text.fontfile","string",K.text.fontfile);if(z1.defined(K.text.width))if(z1.integer(K.text.width)&&K.text.width>0)z.textWidth=K.text.width;else throw z1.invalidParameterError("text.width","positive integer",K.text.width);if(z1.defined(K.text.height))if(z1.integer(K.text.height)&&K.text.height>0)z.textHeight=K.text.height;else throw z1.invalidParameterError("text.height","positive integer",K.text.height);if(z1.defined(K.text.align))if(z1.string(K.text.align)&&z1.string(this.constructor.align[K.text.align]))z.textAlign=this.constructor.align[K.text.align];else throw z1.invalidParameterError("text.align","valid alignment",K.text.align);if(z1.defined(K.text.justify))if(z1.bool(K.text.justify))z.textJustify=K.text.justify;else throw z1.invalidParameterError("text.justify","boolean",K.text.justify);if(z1.defined(K.text.dpi))if(z1.integer(K.text.dpi)&&z1.inRange(K.text.dpi,1,1e6))z.textDpi=K.text.dpi;else throw z1.invalidParameterError("text.dpi","integer between 1 and 1000000",K.text.dpi);if(z1.defined(K.text.rgba))if(z1.bool(K.text.rgba))z.textRgba=K.text.rgba;else throw z1.invalidParameterError("text.rgba","bool",K.text.rgba);if(z1.defined(K.text.spacing))if(z1.integer(K.text.spacing)&&z1.inRange(K.text.spacing,-1e6,1e6))z.textSpacing=K.text.spacing;else throw z1.invalidParameterError("text.spacing","integer between -1000000 and 1000000",K.text.spacing);if(z1.defined(K.text.wrap))if(z1.string(K.text.wrap)&&z1.inArray(K.text.wrap,["word","char","word-char","none"]))z.textWrap=K.text.wrap;else throw z1.invalidParameterError("text.wrap","one of: word, char, word-char, none",K.text.wrap);delete z.buffer}else throw Error("Expected a valid string to create an image with text.");if(z1.defined(K.join))if(z1.defined(this.options.join)){if(z1.defined(K.join.animated))if(z1.bool(K.join.animated))z.joinAnimated=K.join.animated;else throw z1.invalidParameterError("join.animated","boolean",K.join.animated);if(z1.defined(K.join.across))if(z1.integer(K.join.across)&&z1.inRange(K.join.across,1,1e6))z.joinAcross=K.join.across;else throw z1.invalidParameterError("join.across","integer between 1 and 100000",K.join.across);if(z1.defined(K.join.shim))if(z1.integer(K.join.shim)&&z1.inRange(K.join.shim,0,1e6))z.joinShim=K.join.shim;else throw z1.invalidParameterError("join.shim","integer between 0 and 100000",K.join.shim);if(z1.defined(K.join.background))z.joinBackground=this._getBackgroundColourOption(K.join.background);if(z1.defined(K.join.halign))if(z1.string(K.join.halign)&&z1.string(this.constructor.align[K.join.halign]))z.joinHalign=this.constructor.align[K.join.halign];else throw z1.invalidParameterError("join.halign","valid alignment",K.join.halign);if(z1.defined(K.join.valign))if(z1.string(K.join.valign)&&z1.string(this.constructor.align[K.join.valign]))z.joinValign=this.constructor.align[K.join.valign];else throw z1.invalidParameterError("join.valign","valid alignment",K.join.valign)}else throw Error("Expected input to be an array of images to join")}else if(z1.defined(K))throw Error(`Invalid input options ${K}`);return z}function oi_(q,K,_){if(Array.isArray(this.options.input.buffer))if(z1.buffer(q)){if(this.options.input.buffer.length===0)this.on("finish",()=>{this.streamInFinished=!0});this.options.input.buffer.push(q),_()}else _(Error("Non-Buffer data on Writable Stream"));else _(Error("Unexpected data on Writable Stream"))}function ai_(){if(this._isStreamInput())this.options.input.buffer=Buffer.concat(this.options.input.buffer)}function si_(){return Array.isArray(this.options.input.buffer)}function ti_(q){let K=Error();if(z1.fn(q)){if(this._isStreamInput())this.on("finish",()=>{this._flattenBufferIn(),t76.metadata(this.options,(_,z)=>{if(_)q(z1.nativeError(_,K));else q(null,z)})});else t76.metadata(this.options,(_,z)=>{if(_)q(z1.nativeError(_,K));else q(null,z)});return this}else if(this._isStreamInput())return new Promise((_,z)=>{let Y=()=>{this._flattenBufferIn(),t76.metadata(this.options,($,A)=>{if($)z(z1.nativeError($,K));else _(A)})};if(this.writableFinished)Y();else this.once("finish",Y)});else return new Promise((_,z)=>{t76.metadata(this.options,(Y,$)=>{if(Y)z(z1.nativeError(Y,K));else _($)})})}function ei_(q){let K=Error();if(z1.fn(q)){if(this._isStreamInput())this.on("finish",()=>{this._flattenBufferIn(),t76.stats(this.options,(_,z)=>{if(_)q(z1.nativeError(_,K));else q(null,z)})});else t76.stats(this.options,(_,z)=>{if(_)q(z1.nativeError(_,K));else q(null,z)});return this}else if(this._isStreamInput())return new Promise((_,z)=>{this.on("finish",function(){this._flattenBufferIn(),t76.stats(this.options,(Y,$)=>{if(Y)z(z1.nativeError(Y,K));else _($)})})});else return new Promise((_,z)=>{t76.stats(this.options,(Y,$)=>{if(Y)z(z1.nativeError(Y,K));else _($)})})}YX4.exports=(q)=>{Object.assign(q.prototype,{_inputOptionsFromObject:zX4,_createInputDescriptor:ri_,_write:oi_,_flattenBufferIn:ai_,_isStreamInput:si_,metadata:ti_,stats:ei_}),q.align=ni_}});var JX4=m((V6O,HX4)=>{/*! |
| 1502 | */var UK=KU(),OX4={center:0,centre:0,north:1,east:2,south:3,west:4,northeast:5,southeast:6,southwest:7,northwest:8},wX4={top:1,right:2,bottom:3,left:4,"right top":5,"right bottom":6,"left bottom":7,"left top":8},AX4={background:"background",copy:"copy",repeat:"repeat",mirror:"mirror"},jX4={entropy:16,attention:17},gI1={nearest:"nearest",linear:"linear",cubic:"cubic",mitchell:"mitchell",lanczos2:"lanczos2",lanczos3:"lanczos3",mks2013:"mks2013",mks2021:"mks2021"},qr_={contain:"contain",cover:"cover",fill:"fill",inside:"inside",outside:"outside"},Kr_={contain:"embed",cover:"crop",fill:"ignore_aspect",inside:"max",outside:"min"};function FI1(q){return q.angle%360!==0||q.rotationAngle!==0}function wV8(q){return q.width!==-1||q.height!==-1}function _r_(q,K,_){if(wV8(this.options))this.options.debuglog("ignoring previous resize options");if(this.options.widthPost!==-1)this.options.debuglog("operation order will be: extract, resize, extract");if(UK.defined(q))if(UK.object(q)&&!UK.defined(_))_=q;else if(UK.integer(q)&&q>0)this.options.width=q;else throw UK.invalidParameterError("width","positive integer",q);else this.options.width=-1;if(UK.defined(K))if(UK.integer(K)&&K>0)this.options.height=K;else throw UK.invalidParameterError("height","positive integer",K);else this.options.height=-1;if(UK.object(_)){if(UK.defined(_.width))if(UK.integer(_.width)&&_.width>0)this.options.width=_.width;else throw UK.invalidParameterError("width","positive integer",_.width);if(UK.defined(_.height))if(UK.integer(_.height)&&_.height>0)this.options.height=_.height;else throw UK.invalidParameterError("height","positive integer",_.height);if(UK.defined(_.fit)){let z=Kr_[_.fit];if(UK.string(z))this.options.canvas=z;else throw UK.invalidParameterError("fit","valid fit",_.fit)}if(UK.defined(_.position)){let z=UK.integer(_.position)?_.position:jX4[_.position]||wX4[_.position]||OX4[_.position];if(UK.integer(z)&&(UK.inRange(z,0,8)||UK.inRange(z,16,17)))this.options.position=z;else throw UK.invalidParameterError("position","valid position/gravity/strategy",_.position)}if(this._setBackgroundColourOption("resizeBackground",_.background),UK.defined(_.kernel))if(UK.string(gI1[_.kernel]))this.options.kernel=gI1[_.kernel];else throw UK.invalidParameterError("kernel","valid kernel name",_.kernel);if(UK.defined(_.withoutEnlargement))this._setBooleanOption("withoutEnlargement",_.withoutEnlargement);if(UK.defined(_.withoutReduction))this._setBooleanOption("withoutReduction",_.withoutReduction);if(UK.defined(_.fastShrinkOnLoad))this._setBooleanOption("fastShrinkOnLoad",_.fastShrinkOnLoad)}if(FI1(this.options)&&wV8(this.options))this.options.rotateBefore=!0;return this}function zr_(q){if(UK.integer(q)&&q>0)this.options.extendTop=q,this.options.extendBottom=q,this.options.extendLeft=q,this.options.extendRight=q;else if(UK.object(q)){if(UK.defined(q.top))if(UK.integer(q.top)&&q.top>=0)this.options.extendTop=q.top;else throw UK.invalidParameterError("top","positive integer",q.top);if(UK.defined(q.bottom))if(UK.integer(q.bottom)&&q.bottom>=0)this.options.extendBottom=q.bottom;else throw UK.invalidParameterError("bottom","positive integer",q.bottom);if(UK.defined(q.left))if(UK.integer(q.left)&&q.left>=0)this.options.extendLeft=q.left;else throw UK.invalidParameterError("left","positive integer",q.left);if(UK.defined(q.right))if(UK.integer(q.right)&&q.right>=0)this.options.extendRight=q.right;else throw UK.invalidParameterError("right","positive integer",q.right);if(this._setBackgroundColourOption("extendBackground",q.background),UK.defined(q.extendWith))if(UK.string(AX4[q.extendWith]))this.options.extendWith=AX4[q.extendWith];else throw UK.invalidParameterError("extendWith","one of: background, copy, repeat, mirror",q.extendWith)}else throw UK.invalidParameterError("extend","integer or object",q);return this}function Yr_(q){let K=wV8(this.options)||this.options.widthPre!==-1?"Post":"Pre";if(this.options[`width${K}`]!==-1)this.options.debuglog("ignoring previous extract options");if(["left","top","width","height"].forEach(function(_){let z=q[_];if(UK.integer(z)&&z>=0)this.options[_+(_==="left"||_==="top"?"Offset":"")+K]=z;else throw UK.invalidParameterError(_,"integer",z)},this),FI1(this.options)&&!wV8(this.options)){if(this.options.widthPre===-1||this.options.widthPost===-1)this.options.rotateBefore=!0}if(this.options.input.autoOrient)this.options.orientBefore=!0;return this}function $r_(q){if(this.options.trimThreshold=10,UK.defined(q))if(UK.object(q)){if(UK.defined(q.background))this._setBackgroundColourOption("trimBackground",q.background);if(UK.defined(q.threshold))if(UK.number(q.threshold)&&q.threshold>=0)this.options.trimThreshold=q.threshold;else throw UK.invalidParameterError("threshold","positive number",q.threshold);if(UK.defined(q.lineArt))this._setBooleanOption("trimLineArt",q.lineArt)}else throw UK.invalidParameterError("trim","object",q);if(FI1(this.options))this.options.rotateBefore=!0;return this}HX4.exports=(q)=>{Object.assign(q.prototype,{resize:_r_,extend:zr_,extract:Yr_,trim:$r_}),q.gravity=OX4,q.strategy=jX4,q.kernel=gI1,q.fit=qr_,q.position=wX4}});var XX4=m((N6O,MX4)=>{/*! |