UNPKG

@imagemagick/magick-wasm

Version:
42 lines 237 kB
(function(I,ze){typeof exports=="object"&&typeof module<"u"?ze(exports):typeof define=="function"&&define.amd?define(["exports"],ze):(I=typeof globalThis<"u"?globalThis:I||self,ze(I["magick-wasm"]={}))})(this,function(I){"use strict";function ze(S){return S instanceof Int8Array||S instanceof Uint8Array||S instanceof Uint8ClampedArray}class Ut{fileName;data;constructor(a,o){this.fileName=a,this.data=o}}const vi={XmlResourceFiles:{log:`<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE logmap [ <!ELEMENT logmap (log)+> <!ELEMENT log (#PCDATA)> <!ATTLIST log events CDATA #IMPLIED> <!ATTLIST log output CDATA #IMPLIED> <!ATTLIST log filename CDATA #IMPLIED> <!ATTLIST log generations CDATA #IMPLIED> <!ATTLIST log limit CDATA #IMPLIED> <!ATTLIST log format CDATA #IMPLIED> ]> <logmap> <log events="None"/> <log output="Debug"/> <log filename="Magick-%g.log"/> <log generations="3"/> <log limit="2000"/> <log format="%t %r %u %v %d %c[%p]: %m/%f/%l/%d %e"/> </logmap> `,policy:`<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE policymap [ <!ELEMENT policymap (policy)*> <!ATTLIST policymap xmlns CDATA #FIXED ""> <!ELEMENT policy EMPTY> <!ATTLIST policy xmlns CDATA #FIXED ""> <!ATTLIST policy domain NMTOKEN #REQUIRED> <!ATTLIST policy name NMTOKEN #IMPLIED> <!ATTLIST policy pattern CDATA #IMPLIED> <!ATTLIST policy rights NMTOKEN #IMPLIED> <!ATTLIST policy stealth NMTOKEN #IMPLIED> <!ATTLIST policy value CDATA #IMPLIED> ]> <policymap> <policy domain="cache" name="shared-secret" value="passphrase"/> <policy domain="coder" rights="none" pattern="EPHEMERAL" /> <policy domain="coder" rights="none" pattern="MVG" /> <policy domain="coder" rights="none" pattern="MSL" /> <policy domain="path" rights="none" pattern="@*" /> <policy domain="path" rights="none" pattern="|*" /> </policymap> `}};class pt{constructor(){this.log=new Ut("log.xml",vi.XmlResourceFiles.log),this.policy=new Ut("policy.xml",vi.XmlResourceFiles.policy)}static default=new pt;*all(){yield this.log,yield this.policy}log;policy}class Mt{constructor(a,o,i){this.format=a,this.name=o,this.value=i}format;name;value}class wi{format;constructor(a){this.format=a}createDefine(a,o){return typeof o=="boolean"?new Mt(this.format,a,o?"true":"false"):typeof o=="string"?new Mt(this.format,a,o):new Mt(this.format,a,o.toString())}hasValue(a){return a!=null}}class aa{_x;_y;_paintMethod;constructor(a,o,i){this._x=a,this._y=o,this._paintMethod=i}draw(a){a.color(this._x,this._y,this._paintMethod)}}class Ii{_color;constructor(a){this._color=a}draw(a){a.fillColor(this._color)}}class yi{_opacity;constructor(a){this._opacity=a}draw(a){a.fillOpacity(this._opacity.toDouble()/100)}}class Ci{_pointSize;constructor(a){this._pointSize=a}draw(a){a.fontPointSize(this._pointSize)}}class Di{constructor(a,o){this.eventType=a,this.message=o??""}eventType;message}const Pi={Undefined:0,Activate:1,Associate:2,Background:3,Copy:4,Deactivate:5,Discrete:6,Disassociate:7,Extract:8,Off:9,On:10,Opaque:11,Remove:12,Set:13,Shape:14,Transparent:15,OffIfOpaque:16},L={Red:0,Cyan:0,Gray:0,Green:1,Magenta:1,Blue:2,Yellow:2,Black:3,Alpha:4,Index:5,Meta0:10,Meta1:11,Meta2:12,Meta3:13,Meta4:14,Meta5:15,Meta6:16,Meta7:17,Meta8:18,Meta9:19,Meta10:20,Meta11:21,Meta12:22,Meta13:23,Meta14:24,Meta15:25,Meta16:26,Meta17:27,Meta18:28,Meta19:29,Meta20:30,Meta21:31,Meta22:32,Meta23:33,Meta24:34,Meta25:35,Meta26:36,Meta27:37,Meta28:38,Meta29:39,Meta30:40,Meta31:41,Meta32:42,Meta33:43,Meta34:44,Meta35:45,Meta36:46,Meta37:47,Meta38:48,Meta39:49,Meta40:50,Meta41:51,Meta42:52,Meta43:53,Meta44:54,Meta45:55,Meta46:56,Meta47:57,Meta48:58,Meta49:59,Meta50:60,Meta51:61,Meta52:62,Composite:64},X={Undefined:0,Red:1,Gray:1,Cyan:1,Green:2,Magenta:2,Blue:4,Yellow:4,Black:8,Alpha:16,Opacity:16,Index:32,Composite:31,TrueAlpha:256,get RGB(){return this.Red|this.Green|this.Blue},get CMYK(){return this.Cyan|this.Magenta|this.Yellow|this.Black},get CMYKA(){return this.Cyan|this.Magenta|this.Yellow|this.Black|this.Alpha},Meta0:1<<L.Meta0,Meta1:1<<L.Meta1,Meta2:1<<L.Meta2,Meta3:1<<L.Meta3,Meta4:1<<L.Meta4,Meta5:1<<L.Meta5,Meta6:1<<L.Meta6,Meta7:1<<L.Meta7,Meta8:1<<L.Meta8,Meta9:1<<L.Meta9,Meta10:1<<L.Meta10,Meta11:1<<L.Meta11,Meta12:1<<L.Meta12,Meta13:1<<L.Meta13,Meta14:1<<L.Meta14,Meta15:1<<L.Meta15,Meta16:1<<L.Meta16,Meta17:1<<L.Meta17,Meta18:1<<L.Meta18,Meta19:1<<L.Meta19,Meta20:1<<L.Meta20,Meta21:1<<L.Meta21,All:134217727};class Ei{constructor(a,o,i,g){this.red=a,this.green=o,this.blue=i,this.white=g}red;green;blue;white}const T={Undefined:0,CMY:1,CMYK:2,Gray:3,HCL:4,HCLp:5,HSB:6,HSI:7,HSL:8,HSV:9,HWB:10,Lab:11,LCH:12,LCHab:13,LCHuv:14,Log:15,LMS:16,Luv:17,OHTA:18,Rec601YCbCr:19,Rec709YCbCr:20,RGB:21,scRGB:22,sRGB:23,Transparent:24,XyY:25,XYZ:26,YCbCr:27,YCC:28,YDbDr:29,YIQ:30,YPbPr:31,YUV:32,LinearGray:33,Jzazbz:34,DisplayP3:35,Adobe98:36,ProPhoto:37,Oklab:38,Oklch:39,CAT02LMSC:40},jt={[T.Undefined]:"Undefined",[T.CMY]:"CMY",[T.CMYK]:"CMYK",[T.Gray]:"Gray",[T.HCL]:"HCL",[T.HCLp]:"HCLp",[T.HSB]:"HSB",[T.HSI]:"HSI",[T.HSL]:"HSL",[T.HSV]:"HSV",[T.HWB]:"HWB",[T.Lab]:"Lab",[T.LCH]:"LCH",[T.LCHab]:"LCHab",[T.LCHuv]:"LCHuv",[T.Log]:"Log",[T.LMS]:"LMS",[T.Luv]:"Luv",[T.OHTA]:"OHTA",[T.Rec601YCbCr]:"Rec601YCbCr",[T.Rec709YCbCr]:"Rec709YCbCr",[T.RGB]:"RGB",[T.scRGB]:"scRGB",[T.sRGB]:"sRGB",[T.Transparent]:"Transparent",[T.XyY]:"XyY",[T.XYZ]:"XYZ",[T.YCbCr]:"YCbCr",[T.YCC]:"YCC",[T.YDbDr]:"YDbDr",[T.YIQ]:"YIQ",[T.YPbPr]:"YPbPr",[T.YUV]:"YUV",[T.LinearGray]:"LinearGray",[T.Jzazbz]:"Jzazbz",[T.DisplayP3]:"DisplayP3",[T.Adobe98]:"Adobe98",[T.ProPhoto]:"ProPhoto",[T.Oklab]:"Oklab",[T.Oklch]:"Oklch",[T.CAT02LMSC]:"CAT02LMS"};class na{colorSpace=T.Undefined;copyright=null;description=null;manufacturer=null;model=null}class oa{_data;_index;constructor(a){this._data=a,this._index=0,this.isLittleEndian=!1}get index(){return this._index}isLittleEndian;readLong(){return this.canRead(4)?this.isLittleEndian?this.readLongLSB():this.readLongMSB():null}readString(a){if(a==0)return"";if(!this.canRead(a))return null;let i=new TextDecoder("utf-8").decode(this._data.subarray(this._index,this._index+a));const g=i.indexOf("\0");return g!=-1&&(i=i.substring(0,g)),this._index+=a,i}seek(a){return a>=this._data.length?!1:(this._index=a,!0)}skip(a){return this._index+a>=this._data.length?!1:(this._index+=a,!0)}canRead(a){return a>this._data.length?!1:this._index+a<=this._data.length}readLongLSB(){let a=this._data[this._index];return a|=this._data[this._index+1]<<8,a|=this._data[this._index+2]<<16,a|=this._data[this._index+3]<<24,this._index+=4,a}readLongMSB(){let a=this._data[this._index]<<24;return a|=this._data[this._index+1]<<16,a|=this._data[this._index+2]<<8,a|=this._data[this._index+3],this._index+=4,a}}class Yt{_data=new na;_reader;constructor(a){this._reader=new oa(a)}static read(a){const o=new Yt(a);return o.readColorSpace(),o.readTagTable(),o._data}readColorSpace(){this._reader.seek(16);const a=this._reader.readString(4);a!=null&&(this._data.colorSpace=this.determineColorSpace(a.trimEnd()))}determineColorSpace(a){switch(a){case"CMY":return T.CMY;case"CMYK":return T.CMYK;case"GRAY":return T.Gray;case"HSL":return T.HSL;case"HSV":return T.HSV;case"Lab":return T.Lab;case"Luv":return T.Luv;case"RGB":return T.sRGB;case"XYZ":return T.XYZ;case"YCbr":return T.YCbCr;default:return T.Undefined}}readTagTable(){if(!this._reader.seek(128))return;const a=this._reader.readLong();if(a!=null)for(let o=0;o<a;o++)switch(this._reader.readLong()){case 1668313716:this._data.copyright=this.readTag();break;case 1684370275:this._data.description=this.readTag();break;case 1684893284:this._data.manufacturer=this.readTag();break;case 1684890724:this._data.model=this.readTag();break;default:this._reader.skip(8);break}}readTag(){const a=this._reader.readLong(),o=this._reader.readLong();if(a===null||o===null)return null;const i=this._reader.index;if(!this._reader.seek(a))return null;const g=this.readTagValue(o);return this._reader.seek(i),g}readTagValue(a){switch(this._reader.readString(4)){case"desc":return this.readTextDescriptionTypeValue();case"text":return this.readTextTypeValue(a);default:return null}}readTextDescriptionTypeValue(){if(!this._reader.skip(4))return null;const a=this._reader.readLong();return a==null?null:this._reader.readString(a)}readTextTypeValue(a){return this._reader.skip(4)?this._reader.readString(a):null}}class Vt{constructor(a,o){this.name=a,this.data=o}name;data}class Ti extends Vt{_data;constructor(a){super("icc",a)}get colorSpace(){return this.initialize(),this._data.colorSpace}get copyright(){return this.initialize(),this._data.copyright}get description(){return this.initialize(),this._data.description}get manufacturer(){return this.initialize(),this._data.manufacturer}get model(){return this.initialize(),this._data.model}initialize(){this._data||(this._data=Yt.read(this.data))}}const Xt={HighRes:0,Quantum:1};class kt{constructor(a,o){this.distortion=a,this.difference=o}difference;distortion;static _create(a,o){return new kt(a,o)}}class bi{constructor(a){this.metric=a}metric;highlightColor;lowlightColor;masklightColor;_setArtifacts(a){this.highlightColor!==void 0&&a.setArtifact("compare:highlight-color",this.highlightColor),this.lowlightColor!==void 0&&a.setArtifact("compare:lowlight-color",this.lowlightColor),this.masklightColor!==void 0&&a.setArtifact("compare:masklight-color",this.masklightColor)}}const St={Undefined:0,Alpha:1,Atop:2,Blend:3,Blur:4,Bumpmap:5,ChangeMask:6,Clear:7,ColorBurn:8,ColorDodge:9,Colorize:10,CopyBlack:11,CopyBlue:12,Copy:13,CopyCyan:14,CopyGreen:15,CopyMagenta:16,CopyAlpha:17,CopyRed:18,CopyYellow:19,Darken:20,DarkenIntensity:21,Difference:22,Displace:23,Dissolve:24,Distort:25,DivideDst:26,DivideSrc:27,DstAtop:28,Dst:29,DstIn:30,DstOut:31,DstOver:32,Exclusion:33,HardLight:34,HardMix:35,Hue:36,In:37,Intensity:38,Lighten:39,LightenIntensity:40,LinearBurn:41,LinearDodge:42,LinearLight:43,Luminize:44,Mathematics:45,MinusDst:46,MinusSrc:47,Modulate:48,ModulusAdd:49,ModulusSubtract:50,Multiply:51,No:52,Out:53,Over:54,Overlay:55,PegtopLight:56,PinLight:57,Plus:58,Replace:59,Saturate:60,Screen:61,SoftLight:62,SrcAtop:63,Src:64,SrcIn:65,SrcOut:66,SrcOver:67,Threshold:68,VividLight:69,Xor:70,Stereo:71,Freeze:72,Interpolate:73,Negate:74,Reflect:75,SoftBurn:76,SoftDodge:77,Stamp:78,RMSE:79,SaliencyBlend:80,SeamlessBlend:81},vt={Warning:300,ResourceLimitWarning:300,TypeWarning:305,OptionWarning:310,DelegateWarning:315,MissingDelegateWarning:320,CorruptImageWarning:325,FileOpenWarning:330,BlobWarning:335,StreamWarning:340,CacheWarning:345,CoderWarning:350,FilterWarning:352,ModuleWarning:355,DrawWarning:360,ImageWarning:365,WandWarning:370,RandomWarning:375,XServerWarning:380,MonitorWarning:385,RegistryWarning:390,ConfigureWarning:395,PolicyWarning:399,Error:400,ResourceLimitError:400,TypeError:405,OptionError:410,DelegateError:415,MissingDelegateError:420,CorruptImageError:425,FileOpenError:430,BlobError:435,StreamError:440,CacheError:445,CoderError:450,FilterError:452,ModuleError:455,DrawError:460,ImageError:465,WandError:470,RandomError:475,XServerError:480,MonitorError:485,RegistryError:490,ConfigureError:495,PolicyError:499};class z extends Error{_relatedErrors=[];constructor(a,o=vt.Error){super(a),this.severity=o}severity;get relatedErrors(){return this._relatedErrors}_setRelatedErrors(a){this._relatedErrors=a}}class Fe{static get depth(){return l._api._Quantum_Depth_Get()}static get max(){return l._api._Quantum_Max_Get()}}function ge(S,a){return S===0?a??null:l._api.UTF8ToString(S)}function sa(S,a){const o=ge(a);return S._MagickMemory_Relinquish(a),o}function qt(S,a,o){const i=S.lengthBytesUTF8(a)+1,g=S._malloc(i);try{return S.stringToUTF8(a,g,i),o(g)}finally{S._free(g)}}function A(S,a){return S===null?a(0):qt(l._api,S,a)}class k{constructor(a,o,i,g,m){if(a!==void 0)if(typeof a=="string"){let f=0;try{f=l._api._MagickColor_Create(),A(a,M=>{if(l._api._MagickColor_Initialize(f,M)===0)throw new z("invalid color specified");this.initialize(f)})}finally{l._api._free(f)}}else this.r=a,this.g=o??0,this.b=i??0,m===void 0?this.a=g??Fe.max:(this.k=g??0,this.a=m,this.isCmyk=!0)}r=0;g=0;b=0;a=0;k=0;isCmyk=!1;static _create(a){const o=new k;return o.initialize(a),o}toShortString(){return this.a!==Fe.max?this.toString():this.isCmyk?`cmyka(${this.r},${this.g},${this.b},${this.k})`:`#${this.toHex(this.r)}${this.toHex(this.g)}${this.toHex(this.b)}`}toString(){return this.isCmyk?`cmyka(${this.r},${this.g},${this.b},${this.k},${(this.a/Fe.max).toFixed(4)})`:`#${this.toHex(this.r)}${this.toHex(this.g)}${this.toHex(this.b)}${this.toHex(this.a)}`}_use(a){let o=0;try{o=l._api._MagickColor_Create(),l._api._MagickColor_Red_Set(o,this.r),l._api._MagickColor_Green_Set(o,this.g),l._api._MagickColor_Blue_Set(o,this.b),l._api._MagickColor_Alpha_Set(o,this.a),l._api._MagickColor_IsCMYK_Set(o,this.isCmyk?1:0),a(o)}finally{l._api._free(o)}}initialize(a){this.r=l._api._MagickColor_Red_Get(a),this.g=l._api._MagickColor_Green_Get(a),this.b=l._api._MagickColor_Blue_Get(a),this.a=l._api._MagickColor_Alpha_Get(a),this.isCmyk=l._api._MagickColor_IsCMYK_Get(a)===1}toHex(a){return a.toString(16).padStart(2,"0")}}var Ie=(S=>(S[S.NoValue=0]="NoValue",S[S.PercentValue=4096]="PercentValue",S[S.IgnoreAspectRatio=8192]="IgnoreAspectRatio",S[S.Less=16384]="Less",S[S.Greater=32768]="Greater",S[S.FillArea=65536]="FillArea",S[S.LimitPixels=131072]="LimitPixels",S[S.AspectRatio=1048576]="AspectRatio",S))(Ie||{});class _e{_includeXyInToString;_width=0;_height=0;_x=0;_y=0;_aspectRatio=!1;_fillArea=!1;_greater=!1;_isPercentage=!1;_ignoreAspectRatio=!1;_less=!1;_limitPixels=!1;constructor(a,o,i,g){if(typeof a=="number"){if(i!==void 0&&g!==void 0?(this._width=i,this._height=g,this._x=a,this._y=o??0,this._includeXyInToString=!0):(this._width=a,this._height=o??this._width,this._x=0,this._y=0,this._includeXyInToString=!1),this._width<0)throw new z("negative width is not allowed");if(this._height<0)throw new z("negative height is not allowed")}else{this._includeXyInToString=a.indexOf("+")>=0||a.indexOf("-")>=0;const m=l._api._MagickGeometry_Create();try{A(a,f=>{const M=l._api._MagickGeometry_Initialize(m,f);if(M===Ie.NoValue)throw new z("invalid geometry specified");this.hasFlag(M,Ie.AspectRatio)?this.initializeFromAspectRation(m,a):this.initialize(m,M)})}finally{l._api._MagickGeometry_Dispose(m)}}}get aspectRatio(){return this._aspectRatio}get fillArea(){return this._fillArea}set fillArea(a){this._fillArea=a}get greater(){return this._greater}set greater(a){this._greater=a}get height(){return this._height}set height(a){this._height=a}get ignoreAspectRatio(){return this._ignoreAspectRatio}set ignoreAspectRatio(a){this._ignoreAspectRatio=a}get isPercentage(){return this._isPercentage}set isPercentage(a){this._isPercentage=a}get less(){return this._less}set less(a){this._less=a}get limitPixels(){return this._limitPixels}set limitPixels(a){this._limitPixels=a}get width(){return this._width}set width(a){this._width=a}get x(){return this._x}set x(a){this._x=a}get y(){return this._y}set y(a){this._y=a}toString(){if(this._aspectRatio)return this._width+":"+this._height;let a="";return this._width==0&&this._height==0?a+="0x0":(this._width>0&&(a+=this._width.toString()),this._height>0?a+="x"+this._height.toString():a+="x"),(this._x!=0||this._y!=0||this._includeXyInToString)&&(this._x>=0&&(a+="+"),a+=this._x,this.y>=0&&(a+="+"),a+=this.y),this._fillArea&&(a+="^"),this._greater&&(a+=">"),this._isPercentage&&(a+="%"),this._ignoreAspectRatio&&(a+="!"),this._less&&(a+="<"),this._limitPixels&&(a+="@"),a}static _fromRectangle(a){if(a===0)throw new z("unable to allocate memory");try{const o=l._api._MagickRectangle_Width_Get(a),i=l._api._MagickRectangle_Height_Get(a),g=l._api._MagickRectangle_X_Get(a),m=l._api._MagickRectangle_Y_Get(a);return new _e(g,m,o,i)}finally{l._api._MagickRectangle_Dispose(a)}}_toRectangle(a){const o=l._api._MagickRectangle_Create();if(o===0)throw new z("unable to allocate memory");try{l._api._MagickRectangle_Width_Set(o,this._width),l._api._MagickRectangle_Height_Set(o,this._height),l._api._MagickRectangle_X_Set(o,this._x),l._api._MagickRectangle_Y_Set(o,this._y),a(o)}finally{l._api._MagickRectangle_Dispose(o)}}initialize(a,o){this._width=l._api._MagickGeometry_Width_Get(a),this._height=l._api._MagickGeometry_Height_Get(a),this._x=l._api._MagickGeometry_X_Get(a),this._y=l._api._MagickGeometry_Y_Get(a),this._ignoreAspectRatio=this.hasFlag(o,Ie.IgnoreAspectRatio),this._isPercentage=this.hasFlag(o,Ie.PercentValue),this._fillArea=this.hasFlag(o,Ie.FillArea),this._greater=this.hasFlag(o,Ie.Greater),this._less=this.hasFlag(o,Ie.Less),this._limitPixels=this.hasFlag(o,Ie.LimitPixels)}initializeFromAspectRation(a,o){this._aspectRatio=!0;const i=o.split(":");this._width=this.parseNumber(i[0]),this._height=this.parseNumber(i[1]),this._x=l._api._MagickGeometry_X_Get(a),this._y=l._api._MagickGeometry_Y_Get(a)}parseNumber(a){let o=0;for(;o<a.length&&!this.isNumber(a[o]);)o++;const i=o;for(;o<a.length&&this.isNumber(a[o]);)o++;return parseInt(a.substr(i,o-i))}isNumber(a){return a>="0"&&a<="9"}hasFlag(a,o){return(a&o)===o}}class ke{constructor(a,o){this.x=a,this.y=o??a}x;y;static _create(a){return a===0?new ke(0,0):new ke(l._api._PointInfo_X_Get(a),l._api._PointInfo_Y_Get(a))}}class wt{constructor(a){this.area=l._api._ConnectedComponent_GetArea(a),this.centroid=ke._create(l._api._ConnectedComponent_GetCentroid(a)),this.color=k._create(l._api._ConnectedComponent_GetColor(a)),this.height=l._api._ConnectedComponent_GetHeight(a),this.id=l._api._ConnectedComponent_GetId(a),this.width=l._api._ConnectedComponent_GetWidth(a),this.x=l._api._ConnectedComponent_GetX(a),this.y=l._api._ConnectedComponent_GetY(a)}area;centroid;color;height;id;width;x;y;static _create(a,o){const i=[];if(a===0)return i;for(let g=0;g<o;g++){const m=l._api._ConnectedComponent_GetInstance(a,g);m===0||l._api._ConnectedComponent_GetArea(m)<Number.EPSILON||i.push(new wt(m))}return i}toGeometry(){return new _e(this.x,this.y,this.width,this.height)}}class Gi{angleThreshold;areaThreshold;circularityThreshold;connectivity;diameterThreshold;eccentricityThreshold;majorAxisThreshold;meanColor;minorAxisThreshold;perimeterThreshold;constructor(a){this.connectivity=a}_setArtifacts(a){this.angleThreshold!==void 0&&a.setArtifact("connected-components:angle-threshold",this.angleThreshold.toString()),this.areaThreshold!==void 0&&a.setArtifact("connected-components:area-threshold",this.areaThreshold.toString()),this.circularityThreshold!==void 0&&a.setArtifact("connected-components:circularity-threshold",this.circularityThreshold.toString()),this.diameterThreshold!==void 0&&a.setArtifact("connected-components:diameter-threshold",this.diameterThreshold.toString()),this.eccentricityThreshold!==void 0&&a.setArtifact("connected-components:eccentricity-threshold",this.eccentricityThreshold.toString()),this.majorAxisThreshold!==void 0&&a.setArtifact("connected-components:major-axis-threshold",this.majorAxisThreshold.toString()),this.meanColor!==void 0&&a.setArtifact("connected-components:mean-color",this.meanColor.toString()),this.minorAxisThreshold!==void 0&&a.setArtifact("connected-components:minor-axis-threshold",this.minorAxisThreshold.toString()),this.perimeterThreshold!==void 0&&a.setArtifact("connected-components:perimeter-threshold",this.perimeterThreshold.toString())}}const xe={Undefined:0,PixelsPerInch:1,PixelsPerCentimeter:2};class Ne{constructor(a,o,i){o===void 0?(this.x=a,this.y=a,this.units=xe.PixelsPerInch):i!==void 0?(this.x=a,this.y=o,this.units=i):(this.x=a,this.y=a,this.units=o)}x;y;units;toString(a){return a==this.units||a===xe.Undefined||a===void 0?Ne.toString(this.x,this.y,a??xe.Undefined):this.units==xe.PixelsPerCentimeter&&a==xe.PixelsPerInch?Ne.toString(this.x*2.54,this.y*2.54,a):Ne.toString(this.x/2.54,this.y/2.54,a)}static toString(a,o,i){let g=`${a}x${o}`;switch(i){case xe.PixelsPerCentimeter:g+="cm";break;case xe.PixelsPerInch:g+="inch";break}return g}}class le{static _disposeAfterExecution(a,o){try{const i=o(a);return i instanceof Promise?Promise.resolve(i).then(g=>(a.dispose(),le.checkResult(a,g),g)):(a.dispose(),le.checkResult(a,i),i)}catch(i){throw a.dispose(),i}}static checkResult(a,o){if(o===a)throw new z("The result of the function cannot be the instance that has been disposed.");return o}}class Ai{_pointer;_bytes;_func;constructor(a,o,i){this._pointer=a,this._func=i,this._bytes=l._api.HEAPU8.subarray(a,a+o)}func(a){return a._bytes===void 0?a._func(new Uint8Array):a._func(a._bytes)}dispose(){this._pointer=l._api._MagickMemory_Relinquish(this._pointer)}}class Le{disposeMethod;instance;constructor(a,o){this.instance=a,this.disposeMethod=o}get _instance(){if(this.instance>0)return this.instance;throw this.instance===-1&&this._instanceNotInitialized(),new z("instance is disposed")}set _instance(a){this.disposeInstance(this.instance),this.instance=a}dispose(){this.instance=this.disposeInstance(this.instance)}_instanceNotInitialized(){throw new z("instance is not initialized")}_setInstance(a,o){return o.check(()=>this.instance===0?!1:(this.dispose(),this.instance=a,!0),()=>(this.disposeInstance(a),!0))}disposeInstance(a){return a>0&&(this.onDispose!==void 0&&this.onDispose(),this.disposeMethod(a)),0}}class _a extends Le{constructor(a){const o=l._api._DrawingSettings_Create(),i=l._api._DrawingSettings_Dispose;if(super(o,i),a.fillColor!==void 0&&a.fillColor._use(g=>{l._api._DrawingSettings_FillColor_Set(this._instance,g)}),a.font!==void 0){const g=we._getFontFileName(a.font);A(g,m=>{l._api._DrawingSettings_Font_Set(this._instance,m)})}a.fontPointsize!==void 0&&l._api._DrawingSettings_FontPointsize_Set(this._instance,a.fontPointsize),a.strokeColor!==void 0&&a.strokeColor._use(g=>{l._api._DrawingSettings_StrokeColor_Set(this._instance,g)}),a.strokeWidth!==void 0&&l._api._DrawingSettings_StrokeWidth_Set(this._instance,a.strokeWidth)}}class It{backgroundColor;fillColor;font;fontPointsize;strokeColor;strokeWidth;static _create(a){const o=new It;return o.fillColor=a.fillColor,o.font=a.font,o.fontPointsize=a.fontPointsize,o.strokeColor=a.strokeColor,o.strokeWidth=a.strokeWidth,o}_use(a){const o=new _a(this);return le._disposeAfterExecution(o,a)}}class Ri{instance;type;constructor(a,o){this.instance=l._api._malloc(a),this.type=o,l._api.setValue(this.instance,0,this.type)}get ptr(){return this.instance}get value(){return l._api.getValue(this.instance,this.type)}}class ye extends Ri{constructor(){super(4,"i32")}static use(a){const o=new ye;try{return a(o)}finally{l._api._free(o.ptr)}}}class b{pointer;constructor(a){this.pointer=a}get ptr(){return this.pointer.ptr}check(a,o){return this.isError()?o():a()}static usePointer(a,o){return ye.use(i=>{const g=a(i.ptr);return b.checkException(i,g,o)})}static use(a,o){return ye.use(i=>{const g=a(new b(i));return b.checkException(i,g,o)})}static checkException(a,o,i){if(!b.isRaised(a))return o;const g=b.getErrorSeverity(a.value);if(g>=vt.Error)b.throw(a,g);else if(i!==void 0){const m=b.createError(a.value,g);i(m)}else b.dispose(a);return o}isError(){return b.isRaised(this.pointer)?b.getErrorSeverity(this.pointer.value)>=vt.Error:!1}static getErrorSeverity(a){return l._api._MagickExceptionHelper_Severity(a)}static isRaised(a){return a.value!==0}static throw(a,o){const i=b.createError(a.value,o);throw b.dispose(a),i}static createError(a,o){const i=b.getMessage(a),g=new z(i,o),m=l._api._MagickExceptionHelper_RelatedCount(a);if(m===0)return g;const f=[];for(let M=0;M<m;M++){const y=l._api._MagickExceptionHelper_Related(a,M),F=b.getErrorSeverity(y),N=b.createError(y,F);f.push(N)}return g._setRelatedErrors(f),g}static getMessage(a){const o=l._api._MagickExceptionHelper_Message(a),i=l._api._MagickExceptionHelper_Description(a);let g=ge(o,"Unknown error");return i!==0&&(g+=`(${l._api.UTF8ToString(i)})`),g}static dispose(a){l._api._MagickExceptionHelper_Dispose(a.value)}}class yt{constructor(a,o,i,g,m,f,M){this.ascent=a,this.descent=o,this.maxHorizontalAdvance=i,this.textHeight=g,this.textWidth=m,this.underlinePosition=f,this.underlineThickness=M}ascent;descent;maxHorizontalAdvance;textHeight;textWidth;underlinePosition;underlineThickness;static _create(a){if(a==0)return null;try{const o=l._api._TypeMetric_Ascent_Get(a),i=l._api._TypeMetric_Descent_Get(a),g=l._api._TypeMetric_MaxHorizontalAdvance_Get(a),m=l._api._TypeMetric_TextHeight_Get(a),f=l._api._TypeMetric_TextWidth_Get(a),M=l._api._TypeMetric_UnderlinePosition_Get(a),y=l._api._TypeMetric_UnderlineThickness_Get(a);return new yt(o,i,g,m,f,M,y)}finally{l._api._TypeMetric_Dispose(a)}}}class st extends Le{constructor(a,o){const g=It._create(o)._use(f=>l._api._DrawingWand_Create(a._instance,f._instance)),m=l._api._DrawingWand_Dispose;super(g,m)}color(a,o,i){b.usePointer(g=>{l._api._DrawingWand_Color(this._instance,a,o,i,g)})}draw(a){a.forEach(o=>{o.draw(this)}),b.usePointer(o=>{l._api._DrawingWand_Render(this._instance,o)})}fillColor(a){b.usePointer(o=>{a._use(i=>{l._api._DrawingWand_FillColor(this._instance,i,o)})})}fillOpacity(a){b.usePointer(o=>{l._api._DrawingWand_FillOpacity(this._instance,a,o)})}font(a){b.usePointer(o=>{A(a,i=>{l._api._DrawingWand_Font(this._instance,i,o)})})}fontPointSize(a){b.usePointer(o=>{l._api._DrawingWand_FontPointSize(this._instance,a,o)})}fontTypeMetrics(a,o){return b.usePointer(i=>A(a,g=>{const m=l._api._DrawingWand_FontTypeMetrics(this._instance,g,o?1:0,i);return yt._create(m)}))}gravity(a){b.usePointer(o=>{l._api._DrawingWand_Gravity(this._instance,a,o)})}line(a,o,i,g){b.usePointer(m=>{l._api._DrawingWand_Line(this._instance,a,o,i,g,m)})}point(a,o){b.usePointer(i=>{l._api._DrawingWand_Point(this._instance,a,o,i)})}rectangle(a,o,i,g){b.usePointer(m=>{l._api._DrawingWand_Rectangle(this._instance,a,o,i,g,m)})}roundRectangle(a,o,i,g,m,f){b.usePointer(M=>{l._api._DrawingWand_RoundRectangle(this._instance,a,o,i,g,m,f,M)})}strokeColor(a){b.usePointer(o=>{a._use(i=>{l._api._DrawingWand_StrokeColor(this._instance,i,o)})})}strokeWidth(a){b.usePointer(o=>{l._api._DrawingWand_StrokeWidth(this._instance,a,o)})}text(a,o,i){b.usePointer(g=>{A(i,m=>{l._api._DrawingWand_Text(this._instance,a,o,m,g)})})}textAlignment(a){b.usePointer(o=>{l._api._DrawingWand_TextAlignment(this._instance,a,o)})}textAntialias(a){b.usePointer(o=>{l._api._DrawingWand_TextAntialias(this._instance,a?1:0,o)})}textDecoration(a){b.usePointer(o=>{l._api._DrawingWand_TextDecoration(this._instance,a,o)})}textInterlineSpacing(a){b.usePointer(o=>{l._api._DrawingWand_TextInterlineSpacing(this._instance,a,o)})}textInterwordspacing(a){b.usePointer(o=>{l._api._DrawingWand_TextInterwordSpacing(this._instance,a,o)})}textKerning(a){b.usePointer(o=>{l._api._DrawingWand_TextKerning(this._instance,a,o)})}textUnderColor(a){b.usePointer(o=>{a._use(i=>{l._api._DrawingWand_TextUnderColor(this._instance,i,o)})})}static _use(a,o){const i=new st(a,a.settings);return le._disposeAfterExecution(i,o)}}class Ot extends Ri{constructor(){super(8,"double")}static use(a){const o=new Ot;try{return a(o)}finally{l._api._free(o.ptr)}}}const ue={Undefined:0,Forget:0,Northwest:1,North:2,Northeast:3,West:4,Center:5,East:6,Southwest:7,South:8,Southeast:9};function*Fi(S){for(const a of S)switch(a){case ue.North:yield"north";break;case ue.Northeast:yield"north",yield"east";break;case ue.Northwest:yield"north",yield"west";break;case ue.East:yield"east";break;case ue.West:yield"west";break;case ue.South:yield"south";break;case ue.Southeast:yield"south",yield"east";break;case ue.Southwest:yield"south",yield"west"}}class _t{constructor(a,o,i){this.meanErrorPerPixel=a,this.normalizedMeanError=o,this.normalizedMaximumError=i}meanErrorPerPixel;normalizedMaximumError;normalizedMeanError;static _create(a){const o=l._api._MagickImage_MeanErrorPerPixel_Get(a._instance),i=l._api._MagickImage_NormalizedMeanError_Get(a._instance),g=l._api._MagickImage_NormalizedMaximumError_Get(a._instance);return new _t(o,i,g)}}const Ce={Unknown:"UNKNOWN",ThreeFr:"3FR",ThreeG2:"3G2",ThreeGp:"3GP",A:"A",Aai:"AAI",Ai:"AI",APng:"APNG",Art:"ART",Arw:"ARW",Ashlar:"ASHLAR",Avci:"AVCI",Avi:"AVI",Avif:"AVIF",Avs:"AVS",B:"B",Bayer:"BAYER",Bayera:"BAYERA",Bgr:"BGR",Bgra:"BGRA",Bgro:"BGRO",Bmp:"BMP",Bmp2:"BMP2",Bmp3:"BMP3",Brf:"BRF",C:"C",Cal:"CAL",Cals:"CALS",Canvas:"CANVAS",Caption:"CAPTION",Cin:"CIN",Cip:"CIP",Clip:"CLIP",Cmyk:"CMYK",Cmyka:"CMYKA",Cr2:"CR2",Cr3:"CR3",Crw:"CRW",Cube:"CUBE",Cur:"CUR",Cut:"CUT",Data:"DATA",Dcm:"DCM",Dcr:"DCR",Dcraw:"DCRAW",Dcx:"DCX",Dds:"DDS",Dfont:"DFONT",Dng:"DNG",Dpx:"DPX",Dxt1:"DXT1",Dxt5:"DXT5",Epdf:"EPDF",Epi:"EPI",Eps:"EPS",Eps2:"EPS2",Eps3:"EPS3",Epsf:"EPSF",Epsi:"EPSI",Ept:"EPT",Ept2:"EPT2",Ept3:"EPT3",Erf:"ERF",Exr:"EXR",Farbfeld:"FARBFELD",Fax:"FAX",Ff:"FF",Fff:"FFF",File:"FILE",Fits:"FITS",Fl32:"FL32",Flv:"FLV",Fractal:"FRACTAL",Ftp:"FTP",Fts:"FTS",Ftxt:"FTXT",G:"G",G3:"G3",G4:"G4",Gif:"GIF",Gif87:"GIF87",Gradient:"GRADIENT",Gray:"GRAY",Graya:"GRAYA",Group4:"GROUP4",Hald:"HALD",Hdr:"HDR",Heic:"HEIC",Heif:"HEIF",Histogram:"HISTOGRAM",Hrz:"HRZ",Htm:"HTM",Html:"HTML",Http:"HTTP",Https:"HTTPS",Icb:"ICB",Ico:"ICO",Icon:"ICON",Iiq:"IIQ",Info:"INFO",Inline:"INLINE",Ipl:"IPL",Isobrl:"ISOBRL",Isobrl6:"ISOBRL6",J2c:"J2C",J2k:"J2K",Jng:"JNG",Jnx:"JNX",Jp2:"JP2",Jpc:"JPC",Jpe:"JPE",Jpeg:"JPEG",Jpg:"JPG",Jpm:"JPM",Jps:"JPS",Jpt:"JPT",Json:"JSON",Jxl:"JXL",K:"K",K25:"K25",Kdc:"KDC",Label:"LABEL",M:"M",M2v:"M2V",M4v:"M4V",Mac:"MAC",Map:"MAP",Mask:"MASK",Mat:"MAT",Matte:"MATTE",Mdc:"MDC",Mef:"MEF",Miff:"MIFF",Mkv:"MKV",Mng:"MNG",Mono:"MONO",Mov:"MOV",Mos:"MOS",Mp4:"MP4",Mpc:"MPC",Mpeg:"MPEG",Mpg:"MPG",Mpo:"MPO",Mrw:"MRW",Msl:"MSL",Msvg:"MSVG",Mtv:"MTV",Mvg:"MVG",Nef:"NEF",Nrw:"NRW",Null:"NULL",O:"O",Ora:"ORA",Orf:"ORF",Otb:"OTB",Otf:"OTF",Pal:"PAL",Palm:"PALM",Pam:"PAM",Pango:"PANGO",Pattern:"PATTERN",Pbm:"PBM",Pcd:"PCD",Pcds:"PCDS",Pcl:"PCL",Pct:"PCT",Pcx:"PCX",Pdb:"PDB",Pdf:"PDF",Pdfa:"PDFA",Pef:"PEF",Pes:"PES",Pfa:"PFA",Pfb:"PFB",Pfm:"PFM",Pgm:"PGM",Pgx:"PGX",Phm:"PHM",Picon:"PICON",Pict:"PICT",Pix:"PIX",Pjpeg:"PJPEG",Plasma:"PLASMA",Png:"PNG",Png00:"PNG00",Png24:"PNG24",Png32:"PNG32",Png48:"PNG48",Png64:"PNG64",Png8:"PNG8",Pnm:"PNM",Pocketmod:"POCKETMOD",Ppm:"PPM",Ps:"PS",Ps2:"PS2",Ps3:"PS3",Psb:"PSB",Psd:"PSD",Ptif:"PTIF",Pwp:"PWP",Qoi:"QOI",R:"R",RadialGradient:"RADIAL-GRADIENT",Raf:"RAF",Ras:"RAS",Raw:"RAW",Rgb:"RGB",Rgb565:"RGB565",Rgba:"RGBA",Rgbo:"RGBO",Rgf:"RGF",Rla:"RLA",Rle:"RLE",Rmf:"RMF",Rw2:"RW2",Rwl:"RWL",Scr:"SCR",Screenshot:"SCREENSHOT",Sct:"SCT",Sfw:"SFW",Sgi:"SGI",Shtml:"SHTML",Six:"SIX",Sixel:"SIXEL",SparseColor:"SPARSE-COLOR",Sr2:"SR2",Srf:"SRF",Srw:"SRW",Stegano:"STEGANO",Sti:"STI",StrImg:"STRIMG",Sun:"SUN",Svg:"SVG",Svgz:"SVGZ",Text:"TEXT",Tga:"TGA",Thumbnail:"THUMBNAIL",Tif:"TIF",Tiff:"TIFF",Tiff64:"TIFF64",Tile:"TILE",Tim:"TIM",Tm2:"TM2",Ttc:"TTC",Ttf:"TTF",Txt:"TXT",Ubrl:"UBRL",Ubrl6:"UBRL6",Uil:"UIL",Uyvy:"UYVY",Vda:"VDA",Vicar:"VICAR",Vid:"VID",Viff:"VIFF",Vips:"VIPS",Vst:"VST",WebM:"WEBM",WebP:"WEBP",Wbmp:"WBMP",Wmv:"WMV",Wpg:"WPG",X3f:"X3F",Xbm:"XBM",Xc:"XC",Xcf:"XCF",Xpm:"XPM",Xps:"XPS",Xv:"XV",Y:"Y",Yaml:"YAML",Ycbcr:"YCBCR",Ycbcra:"YCBCRA",Yuv:"YUV"},Ct={Merge:13,Flatten:14,Mosaic:15,Trimbounds:16};class xi extends Le{constructor(a){const o=l._api._MagickSettings_Create(),i=l._api._MagickSettings_Dispose;if(super(o,i),a._fileName!==void 0&&A(a._fileName,g=>{l._api._MagickSettings_SetFileName(this._instance,g)}),a._ping&&l._api._MagickSettings_SetPing(this._instance,1),a._quality!==void 0&&l._api._MagickSettings_SetQuality(this._instance,a._quality),a.antiAlias!==void 0&&l._api._MagickSettings_AntiAlias_Set(this._instance,a.antiAlias?1:0),a.backgroundColor!==void 0&&a.backgroundColor._use(g=>{l._api._MagickSettings_BackgroundColor_Set(this._instance,g)}),a.colorSpace!==void 0&&l._api._MagickSettings_ColorSpace_Set(this._instance,a.colorSpace),a.colorType!==void 0&&l._api._MagickSettings_ColorType_Set(this._instance,a.colorType),a.compression!==void 0&&l._api._MagickSettings_Compression_Set(this._instance,a.compression),a.debug!==void 0&&l._api._MagickSettings_Debug_Set(this._instance,a.debug?1:0),a.density!==void 0){const g=a.density.toString();A(g,m=>{l._api._MagickSettings_Density_Set(this._instance,m)})}if(a.depth!==void 0&&l._api._MagickSettings_Depth_Set(this._instance,a.depth),a.endian!==void 0&&l._api._MagickSettings_Endian_Set(this._instance,a.endian),a.fillColor!==void 0&&this.setOption("fill",a.fillColor.toString()),a.font!==void 0){const g=we._getFontFileName(a.font);A(g,m=>{l._api._MagickSettings_SetFont(this._instance,m)})}a.fontPointsize!==void 0&&l._api._MagickSettings_FontPointsize_Set(this._instance,a.fontPointsize),a.format!==void 0&&A(a.format,g=>{l._api._MagickSettings_Format_Set(this._instance,g)}),a.interlace!==void 0&&l._api._MagickSettings_Interlace_Set(this._instance,a.interlace),a.strokeColor!==void 0&&this.setOption("stroke",a.strokeColor.toString()),a.strokeWidth!==void 0&&this.setOption("strokeWidth",a.strokeWidth.toString()),a.textInterlineSpacing!==void 0&&this.setOption("interline-spacing",a.textInterlineSpacing.toString()),a.textKerning!==void 0&&this.setOption("kerning",a.textKerning.toString());for(const g in a._options)this.setOption(g,a._options[g])}setOption(a,o){A(a,i=>{A(o,g=>{l._api._MagickSettings_SetOption(this._instance,i,g)})})}}class Oe{_options={};_fileName;_ping=!1;_quality;antiAlias;backgroundColor;colorSpace;colorType;compression;debug;density;depth;endian;fillColor;font;fontPointsize;format;interlace;strokeColor;strokeWidth;textInterlineSpacing;textKerning;getDefine(a,o){return o!==void 0?this._options[`${a}:${o}`]??null:this._options[a]??null}setDefine(a,o,i){if(i===void 0)this._options[a]=o;else{const g=this.parseDefine(a,o);typeof i=="string"?this._options[g]=i:typeof i=="number"?this._options[g]=i.toString():this._options[g]=i?"true":"false"}}setDefines(a){a.getDefines().forEach(o=>{o!==void 0&&this.setDefine(o.format,o.name,o.value)})}_clone(){const a=new Oe;return Object.assign(a,this),a}_use(a){const o=new xi(this);return le._disposeAfterExecution(o,a)}parseDefine(a,o){return a===Ce.Unknown?o:`${a}:${o}`}}class Se extends Oe{constructor(a){super(),Object.assign(this,a)}extractArea;frameIndex;frameCount;height;get syncImageWithExifProfile(){const a=this.getDefine("exif:sync-image");return a===null?!0:a.toLowerCase()==="true"}set syncImageWithExifProfile(a){this.setDefine("exif:sync-image",a.toString())}get syncImageWithTiffProperties(){const a=this.getDefine("tiff:sync-image");return a===null?!0:a.toLowerCase()==="true"}set syncImageWithTiffProperties(a){this.setDefine("tiff:sync-image",a.toString())}width;_use(a){const o=new xi(this),i=this.getSize();if(i!==""&&A(i,g=>{l._api._MagickSettings_SetSize(o._instance,g)}),this.frameIndex!==void 0||this.frameCount!==void 0){const g=this.frameIndex??0,m=this.frameCount??1;l._api._MagickSettings_SetScene(o._instance,g),l._api._MagickSettings_SetNumberScenes(o._instance,m);const f=this.frameCount!==void 0?`${g}-${g+m}`:g.toString();A(f.toString(),M=>{l._api._MagickSettings_SetScenes(o._instance,M)})}return this.extractArea!==void 0&&A(this.extractArea.toString(),g=>{l._api._MagickSettings_Extract_Set(o._instance,g)}),le._disposeAfterExecution(o,a)}getSize(){return this.width!==void 0&&this.height!==void 0?`${this.width}x${this.height}`:this.width!==void 0?`${this.width}x`:this.height!==void 0?`x${this.height}`:""}}const Qt={Undefined:0,No:1,Riemersma:2,FloydSteinberg:3};class ca extends Le{constructor(a){const o=l._api._QuantizeSettings_Create(),i=l._api._QuantizeSettings_Dispose;super(o,i),l._api._QuantizeSettings_SetColors(this._instance,a.colors),l._api._QuantizeSettings_SetColorSpace(this._instance,a.colorSpace),l._api._QuantizeSettings_SetDitherMethod(this._instance,a.ditherMethod??Qt.No),l._api._QuantizeSettings_SetMeasureErrors(this._instance,a.measureErrors?1:0),l._api._QuantizeSettings_SetTreeDepth(this._instance,a.treeDepth)}}class Dt{constructor(){this.colors=256,this.colorSpace=T.Undefined,this.ditherMethod=Qt.Riemersma,this.measureErrors=!1,this.treeDepth=0}colors;colorSpace;ditherMethod;measureErrors;treeDepth;_use(a){const o=new ca(this);return le._disposeAfterExecution(o,a)}}class De{_image;_names=[];constructor(a){this._image=a}setArtifact(a,o){this._names.push(a),this._image.setArtifact(a,o)}static use(a,o){const i=new De(a);try{return o(i)}finally{i.dispose()}}dispose(){for(const a of this._names)this._image.removeArtifact(a)}}function Li(S,a){if(S.byteLength===0)throw new z("The specified array cannot be empty");let o=0;try{return o=l._api._malloc(S.byteLength),l._api.HEAPU8.set(S,o),a(o)}finally{o!==0&&l._api._free(o)}}function Wi(S,a){if(S.length===0)throw new z("The specified array cannot be empty");const o=S.length*8;let i=0;try{i=l._api._malloc(o);const g=new ArrayBuffer(o),m=new Float64Array(g);for(let f=0;f<S.length;f++)m[f]=S[f];return l._api.HEAPU8.set(new Int8Array(g),i),a(i)}finally{i!==0&&l._api._free(i)}}function la(S,a){if(S.byteLength===0)throw new z("The specified array cannot be empty");let o=0;try{return o=l._api._malloc(S.byteLength),l._api.HEAPU8.set(S,o),a(o)}finally{o!==0&&l._api._free(o)}}class ve extends Array{constructor(){super()}static create(a){const o=ve.createObject();return a!==void 0&&o.read(a),o}dispose(){let a=this.pop();for(;a!==void 0;)a.dispose(),a=this.pop()}appendHorizontally(a){return this.createImage((o,i)=>l._api._MagickImageCollection_Append(o,0,i.ptr),a)}appendVertically(a){return this.createImage((o,i)=>l._api._MagickImageCollection_Append(o,1,i.ptr),a)}clone(a){const o=ve.create();for(let i=0;i<this.length;i++)o.push(te._clone(this[i]));return o._use(a)}coalesce(){this.replaceImages((a,o)=>l._api._MagickImageCollection_Coalesce(a,o.ptr))}combine(a,o){let i=o,g=T.sRGB;return typeof a=="number"?g=a:i=a,this.createImage((m,f)=>l._api._MagickImageCollection_Combine(m,g,f.ptr),i)}complex(a,o){return De.use(this[0],i=>(a._setArtifacts(i),this.createImage((g,m)=>l._api._MagickImageCollection_Complex(g,a.complexOperator,m.ptr),o)))}deconstruct(){this.replaceImages((a,o)=>l._api._MagickImageCollection_Deconstruct(a,o.ptr))}evaluate(a,o){return this.createImage((i,g)=>l._api._MagickImageCollection_Evaluate(i,a,g.ptr),o)}flatten(a){return this.mergeImages(Ct.Flatten,a)}fx(a,o,i){this.throwIfEmpty();let g=X.All,m=i;return typeof o=="number"?g=o:m=o,A(a,f=>this.createImage((M,y)=>l._api._MagickImageCollection_Fx(M,f,g,y.ptr),m))}merge(a){return this.mergeImages(Ct.Merge,a)}montage(a,o){return this.throwIfEmpty(),this.attachImages(i=>{const g=a._use(m=>b.use(f=>{const M=l._api._MagickImageCollection_Montage(i,m._instance,f.ptr);return this.checkResult(M,f)}));return ve._createFromImages(g,this.getSettings())._use(m=>{const f=a.transparentColor;return f!==void 0&&m.forEach(M=>{M.transparent(f)}),m.merge(o)})})}morph(a){if(this.length<2)throw new z("operation requires at least two images");this.replaceImages((o,i)=>l._api._MagickImageCollection_Morph(o,a,i.ptr))}mosaic(a){return this.mergeImages(Ct.Mosaic,a)}optimize(){this.replaceImages((a,o)=>l._api._MagickImageCollection_Optimize(a,o.ptr))}optimizePlus(){this.replaceImages((a,o)=>l._api._MagickImageCollection_OptimizePlus(a,o.ptr))}optimizeTransparency(){this.throwIfEmpty(),this.attachImages(a=>{b.usePointer(o=>{l._api._MagickImageCollection_OptimizeTransparency(a,o)})})}ping(a,o){this.readOrPing(!0,a,o)}polynomial(a,o){return this.createImage((i,g)=>Wi(a,m=>l._api._MagickImageCollection_Polynomial(i,m,a.length,g.ptr)),o)}quantize(a){this.throwIfEmpty();const o=a===void 0?new Dt:a;return this.attachImages(i=>{o._use(g=>{b.usePointer(m=>{l._api._MagickImageCollection_Quantize(i,g._instance,m)})})}),o.measureErrors?_t._create(this[0]):null}read(a,o){this.readOrPing(!1,a,o)}remap(a,o){this.throwIfEmpty();const i=o===void 0?new Dt:o;this.attachImages(g=>{i._use(m=>{b.use(f=>{l._api._MagickImageCollection_Remap(g,m._instance,a._instance,f.ptr)})})})}resetPage(){this.forEach(a=>{a.resetPage()})}smushHorizontal(a,o){return this.smush(a,!1,o)}smushVertical(a,o){return this.smush(a,!0,o)}trimBounds(){this.mergeImages(Ct.Trimbounds,()=>{})}write(a,o){this.throwIfEmpty();let i=0,g=0;const m=this[0],f=this.getSettings();o!==void 0?f.format=a:(o=a,f.format=m.format),b.use(y=>{ye.use(F=>{f._use(N=>{this.attachImages(ee=>{i=l._api._MagickImage_WriteBlob(ee,N._instance,F.ptr,y.ptr),g=F.value})})})});const M=new Ai(i,g,o);return le._disposeAfterExecution(M,M.func)}static _createFromImages(a,o){const i=ve.createObject();return i.addImages(a,o._clone()),i}_use(a){return le._disposeAfterExecution(this,a)}addImages(a,o){o.format=Ce.Unknown;let i=a;for(;i!==0;){const g=l._api._MagickImage_GetNext(i);l._api._MagickImage_SetNext(i,0),this.push(te._createFromImage(i,o)),i=g}}attachImages(a){try{for(let o=0;o<this.length-1;o++)l._api._MagickImage_SetNext(this[o]._instance,this[o+1]._instance);return a(this[0]._instance)}finally{for(let o=0;o<this.length-1;o++)l._api._MagickImage_SetNext(this[o]._instance,0)}}checkResult(a,o){return o.check(()=>a,()=>(l._api._MagickImageCollection_Dispose(a),0))}static createObject(){return Object.create(ve.prototype)}createImage(a,o){this.throwIfEmpty();const i=this.attachImages(m=>b.use(f=>{const M=a(m,f);return this.checkResult(M,f)}));return te._createFromImage(i,this.getSettings())._use(o)}getSettings(){return this[0]._getSettings()._clone()}mergeImages(a,o){return this.createImage((i,g)=>l._api._MagickImageCollection_Merge(i,a,g.ptr),o)}readOrPing(a,o,i){this.dispose(),b.use(g=>{const m=i===void 0?new Se:new Se(i);m._ping=a,typeof o=="string"?(m._fileName=o,m._use(f=>{const M=l._api._MagickImageCollection_ReadFile(f._instance,g.ptr);this.addImages(M,m)})):m._use(f=>{const M=o.byteLength;let y=0;try{y=l._api._malloc(M),l._api.HEAPU8.set(o,y);const F=l._api._MagickImageCollection_ReadBlob(f._instance,y,0,M,g.ptr);this.addImages(F,m)}finally{y!==0&&l._api._free(y)}})})}replaceImages(a){this.throwIfEmpty();const o=this.attachImages(g=>b.use(m=>{const f=a(g,m);return this.checkResult(f,m)})),i=this.getSettings()._clone();this.dispose(),this.addImages(o,i)}smush(a,o,i){return this.createImage((g,m)=>l._api._MagickImageCollection_Smush(g,a,o?1:0,m.ptr),i)}throwIfEmpty(){if(this.length===0)throw new z("operation requires at least one image")}}class Z{_value;constructor(a){this._value=a}static _fromQuantum(a){return new Z(a/Fe.max*100)}multiply(a){return a*this._value/100}toDouble(){return this._value}toString(){return`${parseFloat(this._value.toFixed(2))}%`}_toQuantum(){return Fe.max*(this._value/100)}}class Bi{static use(a,o,i){const g=l._api._MagickRectangle_Create();try{l._api._MagickRectangle_X_Set(g,o.x),l._api._MagickRectangle_Y_Set(g,o.y);let m=o.width,f=o.height;return o.isPercentage&&(m=new Z(o.width).multiply(a.width),f=new Z(o.height).multiply(a.height)),l._api._MagickRectangle_Width_Set(g,m),l._api._MagickRectangle_Height_Set(g,f),i(g)}finally{l._api._MagickRectangle_Dispose(g)}}}class zi{_values;constructor(){this._values=new Array(7).fill(0)}get(a){return this._values[a]}set(a,o){this._values[a]=o}}class He{_huPhashes=new Map;_hash="";channel;constructor(a,o,i){if(this.channel=a,typeof i=="number")for(let g=0;g<o.length;g++){const m=new zi;for(let f=0;f<7;f++){const M=l._api._ChannelPerceptualHash_GetHuPhash(i,g,f);m.set(f,M)}this._huPhashes.set(o[g],m)}else this.parseHash(o,i)}huPhash(a,o){if(o<0||o>6)throw new z("Invalid index specified");const i=this._huPhashes.get(a);if(i===void 0)throw new z("Invalid color space specified");return i.get(o)}sumSquaredDistance(a){let o=0;return this._huPhashes.forEach((i,g)=>{for(let m=0;m<7;m++){const f=i.get(m),M=a.huPhash(g,m);o+=(f-M)*(f-M)}}),o}toString(){return this._hash==""&&this.setHash(),this._hash}parseHash(a,o){this._hash=o;let i=0;for(const g of a){const m=new zi;for(let f=0;f<7;f++,i+=5){const M=Number.parseInt(o.substring(i,i+5),16);if(isNaN(M))throw new z("Invalid hash specified");let y=M/He.powerOfTen(M>>17);M&65536&&(y=-y),m.set(f,y)}this._huPhashes.set(g,m)}}static powerOfTen(a){switch(a){case 2:return 100;case 3:return 1e3;case 4:return 1e4;case 5:return 1e5;case 6:return 1e6;default:return 10}}setHash(){this._hash="",this._huPhashes.forEach(a=>{for(let o=0;o<7;o++){let i=a.get(o),g=0;for(;g<7&&Math.abs(i*10)<65356;)i*=10,g++;g<<=1,g<0&&(g|=1),g=(g<<16)+Math.floor(i<0?-(i-.5):i+.5),this._hash+=g.toString(16)}})}}class fe{_red;_green;_blue;constructor(a,o,i){if(typeof a=="string"){const g=o??fe._defaultColorspaces();fe._validateColorSpaces(g);const m=35*g.length;if(a.length!==3*m)throw new z("Invalid hash size");this._red=new He(L.Red,g,a.substring(0,m)),this._blue=new He(L.Blue,g,a.substring(m,m+m)),this._green=new He(L.Green,g,a.substring(m+m))}else this._red=a,this._green=o,this._blue=i}static _create(a,o,i){if(i===0)throw new z("The native operation failed to create an instance");const g=fe.createChannel(a,o,i,L.Red),m=fe.createChannel(a,o,i,L.Green),f=fe.createChannel(a,o,i,L.Blue);return new fe(g,m,f)}static _defaultColorspaces(){return[T.XyY,T.HSB]}static _validateColorSpaces(a){if(a.length<1||a.length>6)throw new z("Invalid number of colorspaces, the minimum is 1 and the maximum is 6");if(new Set(a).size!==a.length)throw new z("Specifying the same colorspace more than once is not allowed")}getChannel(a){switch(a){case L.Red:return this._red;case L.Green:return this._green;case L.Blue:return this._blue;default:return null}}sumSquaredDistance(a){const o=a.getChannel(L.Red),i=a.getChannel(L.Green),g=a.getChannel(L.Blue);if(o===null||i===null||g===null)throw new z("The other perceptual hash should contain a red, green and blue channel.");return this._red.sumSquaredDistance(o)+this._green.sumSquaredDistance(i)+this._blue.sumSquaredDistance(g)}toString(){return this._red.toString()+this._green.toString()+this._blue.toString()}static createChannel(a,o,i,g){const m=l._api._PerceptualHash_GetInstance(a._instance,i,g);return new He(g,o,m)}}class $e extends Le{image;constructor(a){const o=b.usePointer(g=>l._api._PixelCollection_Create(a._instance,g)),i=l._api._PixelCollection_Dispose;super(o,i),this.image=a}static _create(a){return new $e(a)}static _use(a,o){const i=new $e(a);return le._disposeAfterExecution(i,o)}static _map(a,o,i){const g=new $e(a);try{g.use(0,0,a.width,a.height,o,m=>{i(m)})}finally{g.dispose()}}getArea(a,o,i,g){return b.usePointer(m=>{const f=l._api._PixelCollection_GetArea(this._instance,a,o,i,g,m),M=i*g*this.image.channelCount;return l._api.HEAPU8.subarray(f,f+M)})}getPixel(a,o){return this.getArea(a,o,1,1)}setArea(a,o,i,g,m){b.usePointer(f=>{const M=m instanceof Uint8Array?m:new Uint8Array(m);la(M,y=>{l._api._PixelCollection_SetArea(this._instance,a,o,i,g,y,M.length,f)})})}setPixel(a,o,i){i instanceof Uint8Array?this.setArea(a,o,1,1,i):this.setArea(a,o,1,1,i)}toByteArray(a,o,i,g,m){return this.use(a,o,i,g,m,f=>{if(f===0)return null;const M=i*g*m.length;return l._api.HEAPU8.slice(f,f+M)})}use(a,o,i,g,m,f){return A(m,M=>b.use(y=>{let F=l._api._PixelCollection_ToByteArray(this._instance,a,o,i,g,M,y.ptr);return y.check(()=>{const N=f(F);return F=l._api._MagickMemory_Relinquish(F),N},()=>(F=l._api._MagickMemory_Relinquish(F),null))}))}}const Ni={Undefined:0,Average:1,Brightness:2,Lightness:3,MS:4,Rec601Luma:5,Rec601Luminance:6,Rec709Luma:7,Rec709Luminance:8,RMS:9};class We{constructor(a,o,i){this.x=a,this.y=o,this.z=i}x;y;z;static _create(a){return a===0?new We(0,0,0):new We(l._api._PrimaryInfo_X_Get(a),l._api._PrimaryInfo_Y_Get(a),l._api._PrimaryInfo_Z_Get(a))}_use(a){let o=0;try{o=l._api._PrimaryInfo_Create(),l._api._PrimaryInfo_X_Set(o,this.x),l._api._PrimaryInfo_Y_Set(o,this.y),l._api._PrimaryInfo_Z_Set(o,this.z),a(o)}finally{l._api._free(o)}}}class Hi{channel;depth;entropy;kurtosis;maximum;mean;minimum;skewness;standardDeviation;constructor(a,o){this.channel=a,this.depth=l._api._ChannelStatistics_Depth_Get(o),this.entropy=l._api._ChannelStatistics_Entropy_Get(o),this.kurtosis=l._api._ChannelStatistics_Kurtosis_Get(o),this.maximum=l._api._ChannelStatistics_Maximum_Get(o),this.mean=l._api._ChannelStatistics_Mean_Get(o),this.minimum=l._api._ChannelStatistics_Minimum_Get(o),this.skewness=l._api._ChannelStatistics_Skewness_Get(o),this.standardDeviation=l._api._ChannelStatistics_StandardDeviation_Get(o)}}class Pt{_channels=new Map;get channels(){return Array.from(this._channels.keys())}composite(){return this._channels.get(L.Composite)}getChannel(a){const o=this._channels.get(a);return o!==void 0?o:null}static _create(a,o,i){const g=new Pt;return a.channels.forEach(m=>{i>>m&1&&g.addChannel(o,m)}),g.addChannel(o,L.Composite),g}addChannel(a,o){const i=l._api._Statistics_GetInstance(a,o);i!==0&&this._channels.set(o,new Hi(o,i))}}class ga{static toArray(a){if(a===0)return null;const o=l._api._StringInfo_Datum_Get(a),i=l._api._StringInfo_Length_Get(a);return l._api.HEAPU8.subarray(o,o+i)}}class Kt{constructor(a){this.error=a}error}class te extends Le{_settings;_progress;_warning;constructor(a,o){super(a,l._api._MagickImage_Dispose),this._settings=o}get animationDelay(){return l._api._MagickImage_AnimationDelay_Get(this._instance)}set animationDelay(a){l._api._MagickImage_AnimationDelay_Set(this._instance,a)}get animationIterations(){return l._api._MagickImage_AnimationIterations_Get(this._instance)}set animationIterations(a){l._api._MagickImage_AnimationIterations_Set(this._instance,a)}get animationTicksPerSecond(){return l._api._MagickImage_AnimationTicksPerSecond_Get(this._instance)}set animationTicksPerSecond(a){l._api._MagickImage_AnimationTicksPerSecond_Set(this._instance,a)}get artifactNames(){const a=[];l._api._MagickImage_ResetArtifactIterator(this._instance);let o=l._api._MagickImage_GetNextArtifactName(this._instance);for(;o!==0;)a.push(l._api.UTF8ToString(o)),o=l._api._MagickImage_GetNextArtifactName(this._instance);return a}get attributeNames(){const a=[];l._api._MagickImage_ResetAttributeIterator(this._instance);let o=l._api._MagickImage_GetNextAttributeName(this._instance);for(;o!==0;)a.push(l._api.UTF8ToString(o)),o=l._api._MagickImage_GetNextAttributeName(this._instance);return a}get backgroundColor(){const a=l._api._MagickImage_BackgroundColor_Get(this._instance);return k._create(a)}set backgroundColor(a){a._use