!function(e,t){"object"==typeofexports&&"undefined"!=typeofmodule?module.exports=t():"function"==typeofdefine&&define.amd?define(t):(e="undefined"!=typeofglobalThis?globalThis:e||self).ID3Writer=t()}(this,function(){"use strict";functionr(e){returnString(e).split("").map(function(e){returne.charCodeAt(0)})}functiono(e){returnnewUint8Array(r(e))}functionc(e){vart=newUint8Array(2*e.length);returnnewUint16Array(t.buffer).set(r(e)),t}functionu(e){vart=255;return[e>>>24&t,e>>>16&t,e>>>8&t,e&t]}returnfunction(){vare=t.prototype;functiont(e){if(!(e&&"object"==typeofe&&"byteLength"ine))thrownewError("First argument should be an instance of ArrayBuffer or Buffer");this.arrayBuffer=e,this.padding=4096,this.frames=[],this.url="",this.separateWithNull=!1}returne._setIntegerFrame=function(e,t){t="TDAT"===e?String(parseInt(t,10)).padStart(4,"0"):parseInt(t,10);this.frames.push({name:e,value:t,size:11+t.toString().length,__type__:"Integer"})},e._setStringFrame=function(e,t){t=t.toString();this.frames.push({name:e,value:t,size:13+2*t.length,__type__:"String"})},e._setPictureFrame=function(e,t,r,a){varn=function(e){if(!e||!e.length)returnnull;if(255===e[0]&&216===e[1]&&255===e[2])return"image/jpeg";if(137===e[0]&&80===e[1]&&78===e[2]&&71===e[3])return"image/png";if(71===e[0]&&73===e[1]&&70===e[2])return"image/gif";if(87===e[8]&&69===e[9]&&66===e[10]&&80===e[11])return"image/webp";vart=73===e[0]&&73===e[1]&&42===e[2]&&0===e[3],r=77===e[0]&&77===e[1]&&0===e[2]&&42===e[3];returnt||r?"image/tiff":66===e[0]&&77===e[1]?"image/bmp":0===e[0]&&0===e[1]&&1===e[2]&&0===e[3]?"image/x-icon":null}(newUint8Array(t)),i=r.toString();if(!n)thrownewError("Unknown picture MIME type");r||(a=!1),this.frames.push({name:"APIC",value:t,pictureType:e,mimeType:n,useUnicodeEncoding:a,description:i,size:(t=t.byteLength,n=n.length,i=i.length,11+n+1+1+(a?2+2*(i+1):i+1)+t),__type__:"Picture"})},e._setLyricsFrame=function(e,t,r){e=e.split("").map(function(e){returne.charCodeAt(0)}),t=t.toString(),r=r.toString();this.frames.push({name:"USLT",value:r,language:e,description:t,size:(t=t.length,r=r.length,16+2*t+2+2+2*r),__type__:"Lyrics"})},e._setCommentFrame=function(e,t,r){e=e.split("").map(function(e){returne.charCodeAt(0)}),t=t.toString(),r=r.toString();this.frames.push({name:"COMM",value:r,language:e,description:t,size:(t=t.length,r=r.length,16+2*t+2+2+2*r),__type__:"Comment"})},e._setPrivateFrame=function(e,t){e=e.toString();this.frames.push({name:"PRIV",value:t,id:e,size:(e=e.length,t=t.byteLength,10+e+1+t),__type__:"Private"})},e._setUserStringFrame=function(e,t){e=e.toString(),t=t.toString();this.frames.push({name:"TXXX",description:e,value:t,size:(e=e.length,t=t.length,13+2*e+2+2+2*t),__type__:"UserString"})},e._setUrlLinkFrame=function(e,t){t=t.toString();this.frames.push({name:e,value:t,size:10+t.length,__type__:"UrlLink"})},e._setPairedTextFrame=function(e,t){varr;this.frames.push({name:e,value:t,size:(r=0,t.forEach(function(e){r+=2+2*e[0].length+2+2+2*e[1].length+2}),11+r),__type__:"PairedText"})},e._setSynchronisedLyricsFrame=function(e,t,r,a,n){vari,n=n.toString(),a=a.split("").map(function(e){returne.charCodeAt(0)});this.frames.push({name:"SYLT",value:t,language:a,description:n,type:e,timestampFormat:r,size:(n=n.length,n*=2,i=0,t.forEach(function(e){i+=2+2*e[0].length+2+4}),18+n+2+i),__type__:"SynchronisedLyrics"})},e._setPopularimeterFrame=function(e,t,r){vara=e.toString();t=parseInt(t,10),void0!==r&&(r=parseInt(Math.abs(r),10)),this.frames.push({name:"POPM",value:t,email:a,count:r,size:10+e.length+1+1+(e=void(e=0)!==(r=r)?Math.max(Math.ceil(Math.log2(r+1)/8),4):e),__type__:"PopularimeterFrame"})},e.setFrame=function(e,t){switch(e){case"TPE1":case"TCOM":case"TPE2":case"TCON":if(!Array.isArray(t))thrownewError(e+" frame value should be an array of strings");varr=this.separateWithNull?String.fromCharCode(0):"TCON"===e?";":"/",r=t.join(r);this._setStringFrame(e,r);break;case"TLAN":case"TIT1":case"TIT2":case"TIT3":case"TALB":case"TPE3":case"TPE4":case"TRCK":case"TPOS":case"TMED":case"TPUB":case"TCOP":case"TCMP":case"T