diff --git a/cache/ImageEffects-min.js b/cache/ImageEffects-min.js new file mode 100644 index 0000000..7c27a23 --- /dev/null +++ b/cache/ImageEffects-min.js @@ -0,0 +1 @@ +!function(t){"use strict";if(!t.extensions.unsandboxed)throw new Error("Image Effects must run unsandboxed");function e(t){return[parseInt(t.slice(1,3),16),parseInt(t.slice(3,5),16),parseInt(t.slice(5,7),16),9===t.length?parseInt(t.slice(7,9),16)/255:255]}t.extensions.register(new class{constructor(){this.cutPos=[0,0],this.scale=[100,100],this.cutoutDirection=90,this.softness=10,this.allShards=[]}getInfo(){return{id:"imgEffectsSP",name:"Image Effects",color1:"#9966FF",color2:"#774DCB",blocks:[{blockType:t.BlockType.LABEL,text:"Effects"},{opcode:"convertHexToRGB",blockType:t.BlockType.REPORTER,text:"convert [HEX] to [CHANNEL]",hideFromPalette:!0,arguments:{HEX:{type:t.ArgumentType.COLOR,defaultValue:"#ff0000"},CHANNEL:{type:t.ArgumentType.STRING,menu:"CHANNELS"}}},{opcode:"applyHueEffect",blockType:t.BlockType.REPORTER,text:"apply hue [COLOR] to URI [SVG]",arguments:{SVG:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},COLOR:{type:t.ArgumentType.COLOR,defaultValue:"#ff0000"}}},"---",{opcode:"deleteColor",blockType:t.BlockType.REPORTER,text:"remove color [COLOR] from [DATA_URI]",arguments:{COLOR:{type:t.ArgumentType.COLOR,defaultValue:"#ff0000"},DATA_URI:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"}}},{opcode:"replaceColor",blockType:t.BlockType.REPORTER,text:"replace color [COLOR] with [REPLACE] from [DATA_URI]",arguments:{COLOR:{type:t.ArgumentType.COLOR,defaultValue:"#ff0000"},REPLACE:{type:t.ArgumentType.COLOR,defaultValue:"#00ff00"},DATA_URI:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"}}},{opcode:"setSoftness",blockType:t.BlockType.COMMAND,text:"set softness of color detection to [AMT]%",arguments:{AMT:{type:t.ArgumentType.NUMBER,defaultValue:10}}},"---",{opcode:"applyEffect",blockType:t.BlockType.REPORTER,text:"set [EFFECT] effect of URI [SVG] to [PERCENTAGE]%",arguments:{EFFECT:{type:t.ArgumentType.STRING,menu:"EFFECTS"},SVG:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},PERCENTAGE:{type:t.ArgumentType.NUMBER,defaultValue:50}}},{opcode:"applyBulgeEffect",blockType:t.BlockType.REPORTER,text:"set bulge effect of URI [SVG] to [STRENGTH]% at x [CENTER_X] y [CENTER_Y]",arguments:{SVG:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},STRENGTH:{type:t.ArgumentType.NUMBER,defaultValue:50},CENTER_X:{type:t.ArgumentType.NUMBER,defaultValue:0},CENTER_Y:{type:t.ArgumentType.NUMBER,defaultValue:0}}},{opcode:"applyWaveEffect",blockType:t.BlockType.REPORTER,text:"set wave effect of URI [SVG] to amplitude x [AMPX] y [AMPY] and frequency x [FREQX] y [FREQY]",arguments:{SVG:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},AMPX:{type:t.ArgumentType.NUMBER,defaultValue:50},AMPY:{type:t.ArgumentType.NUMBER,defaultValue:50},FREQX:{type:t.ArgumentType.NUMBER,defaultValue:5},FREQY:{type:t.ArgumentType.NUMBER,defaultValue:5}}},{opcode:"applyLineGlitchEffect",blockType:t.BlockType.REPORTER,text:"set line glitch of URI [SVG] to [PERCENTAGE]% on [DIRECT] axis and line width [WIDTH]",arguments:{SVG:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},PERCENTAGE:{type:t.ArgumentType.NUMBER,defaultValue:50},DIRECT:{type:t.ArgumentType.STRING,menu:"POSITIONS"},WIDTH:{type:t.ArgumentType.NUMBER,defaultValue:5}}},{opcode:"applyAbberationEffect",blockType:t.BlockType.REPORTER,text:"set abberation of URI [SVG] to colors [COLOR1] and [COLOR2] at [PERCENTAGE]% on [DIRECT] axis",arguments:{SVG:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},PERCENTAGE:{type:t.ArgumentType.NUMBER,defaultValue:5},COLOR1:{type:t.ArgumentType.COLOR,defaultValue:"#ff0000"},COLOR2:{type:t.ArgumentType.COLOR,defaultValue:"#00f7ff"},DIRECT:{type:t.ArgumentType.STRING,menu:"POSITIONS"}}},"---",{opcode:"removeTransparencyEffect",blockType:t.BlockType.REPORTER,text:"remove pixels from URI [SVG] [REMOVE] [THRESHOLD]% transparency",arguments:{SVG:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},THRESHOLD:{type:t.ArgumentType.NUMBER,defaultValue:50},REMOVE:{type:t.ArgumentType.STRING,menu:"REMOVAL"}}},{opcode:"applyEdgeOutlineEffect",blockType:t.BlockType.REPORTER,text:"add outline to URI [SVG] with thickness [THICKNESS] and color [COLOR] opacity [A]%",arguments:{SVG:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},THICKNESS:{type:t.ArgumentType.NUMBER,defaultValue:1},COLOR:{type:t.ArgumentType.COLOR,defaultValue:"#ff0000"},A:{type:t.ArgumentType.NUMBER,defaultValue:100}}},{blockType:t.BlockType.LABEL,text:"Clipping"},{opcode:"clipImage",blockType:t.BlockType.REPORTER,text:"clip [CUTOUT] from [MAIN]",arguments:{MAIN:{type:t.ArgumentType.STRING,defaultValue:"source-here"},CUTOUT:{type:t.ArgumentType.STRING,defaultValue:"cutout-here"}}},{opcode:"overlayImage",blockType:t.BlockType.REPORTER,text:"clip [CUTOUT] onto [MAIN]",arguments:{MAIN:{type:t.ArgumentType.STRING,defaultValue:"source-here"},CUTOUT:{type:t.ArgumentType.STRING,defaultValue:"cutout-here"}}},"---",{opcode:"setCutout",blockType:t.BlockType.COMMAND,text:"set clipping position to x [X] y [Y]",arguments:{X:{type:t.ArgumentType.NUMBER,defaultValue:0},Y:{type:t.ArgumentType.NUMBER,defaultValue:0}}},{opcode:"changeCutout",blockType:t.BlockType.COMMAND,text:"change clipping position by x [X] y [Y]",arguments:{X:{type:t.ArgumentType.NUMBER,defaultValue:10},Y:{type:t.ArgumentType.NUMBER,defaultValue:0}}},{opcode:"currentCut",blockType:t.BlockType.REPORTER,text:"clipping [POS]",disableMonitor:!0,arguments:{POS:{type:t.ArgumentType.STRING,menu:"POSITIONS"}}},"---",{opcode:"setScale",blockType:t.BlockType.COMMAND,text:"set clipping size to x [SIZE] y [Y]",arguments:{SIZE:{type:t.ArgumentType.NUMBER,defaultValue:100},Y:{type:t.ArgumentType.NUMBER,defaultValue:100}}},{opcode:"changeScale",blockType:t.BlockType.COMMAND,text:"change clipping size by x [SIZE] y [Y]",arguments:{SIZE:{type:t.ArgumentType.NUMBER,defaultValue:10},Y:{type:t.ArgumentType.NUMBER,defaultValue:0}}},{opcode:"currentScale",blockType:t.BlockType.REPORTER,text:"clipping size [POS]",disableMonitor:!0,arguments:{POS:{type:t.ArgumentType.STRING,menu:"POSITIONS"}}},"---",{opcode:"setDirection",blockType:t.BlockType.COMMAND,text:"set clipping direction to [ANGLE]",arguments:{ANGLE:{type:t.ArgumentType.ANGLE,defaultValue:90}}},{opcode:"changeDirection",blockType:t.BlockType.COMMAND,text:"change clipping direction by [ANGLE]",arguments:{ANGLE:{type:t.ArgumentType.ANGLE,defaultValue:15}}},{opcode:"currentDir",blockType:t.BlockType.REPORTER,text:"clipping direction"},"---",{opcode:"crackImage",blockType:t.BlockType.COMMAND,text:"crack [URI] into [SHARDS] shards",arguments:{URI:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},SHARDS:{type:t.ArgumentType.NUMBER,defaultValue:5}}},{opcode:"getShard",blockType:t.BlockType.REPORTER,text:"get shard #[SHARD]",arguments:{SHARD:{type:t.ArgumentType.NUMBER,defaultValue:1}}},{blockType:t.BlockType.LABEL,text:"Pixels"},{opcode:"numPixels",blockType:t.BlockType.REPORTER,text:"number of pixels [TYPE] in [URI]",arguments:{URI:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},TYPE:{type:t.ArgumentType.STRING,menu:"PIXELTYPE"}}},{opcode:"getPixel",blockType:t.BlockType.REPORTER,text:"get hex of pixel #[NUM] in [URI]",arguments:{URI:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},NUM:{type:t.ArgumentType.NUMBER,defaultValue:1}}},{opcode:"setPixel",blockType:t.BlockType.REPORTER,text:"set color of pixel #[NUM] to [COLOR] in [URI]",arguments:{URI:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},NUM:{type:t.ArgumentType.NUMBER,defaultValue:1},COLOR:{type:t.ArgumentType.COLOR,defaultValue:"#ff0000"}}},{opcode:"setPixels",blockType:t.BlockType.REPORTER,text:"set color of pixels from #[NUM] to [NUM2] to [COLOR] in [URI]",arguments:{URI:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},NUM:{type:t.ArgumentType.NUMBER,defaultValue:1},NUM2:{type:t.ArgumentType.NUMBER,defaultValue:10},COLOR:{type:t.ArgumentType.COLOR,defaultValue:"#ff0000"}}},{blockType:t.BlockType.LABEL,text:"Image Conversions"},{opcode:"svgToBitmap",blockType:t.BlockType.REPORTER,text:"convert svg content [SVG] to bitmap with width [WIDTH] height [HEIGHT]",arguments:{SVG:{type:t.ArgumentType.STRING,defaultValue:""},WIDTH:{type:t.ArgumentType.NUMBER,defaultValue:100},HEIGHT:{type:t.ArgumentType.NUMBER,defaultValue:100}}},{opcode:"convertImageToSVG",blockType:t.BlockType.REPORTER,text:"convert bitmap URI [URI] to svg [TYPE]",arguments:{URI:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},TYPE:{type:t.ArgumentType.STRING,menu:"fileType"}}},{opcode:"makeSVGimage",blockType:t.BlockType.REPORTER,text:"make new svg with image URI [URI] to svg [TYPE]",arguments:{URI:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},TYPE:{type:t.ArgumentType.STRING,menu:"fileType"}}},{opcode:"upscaleImage",blockType:t.BlockType.REPORTER,text:"upscale image URI [URI] by [NUM] %",arguments:{URI:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},NUM:{type:t.ArgumentType.NUMBER,defaultValue:5}}},"---",{opcode:"stretchImg",blockType:t.BlockType.REPORTER,text:"stretch URI [URI] to width [W] height [H]",arguments:{URI:{type:t.ArgumentType.STRING,defaultValue:"svg/data-uri"},W:{type:t.ArgumentType.NUMBER,defaultValue:200},H:{type:t.ArgumentType.NUMBER,defaultValue:100}}},"---",{opcode:"audioToImage",blockType:t.BlockType.REPORTER,text:"convert audio URI [AUDIO_URI] to PNG with width [W] height [H]",arguments:{AUDIO_URI:{type:t.ArgumentType.STRING,defaultValue:"audio_uri_here"},W:{type:t.ArgumentType.NUMBER,defaultValue:100},H:{type:t.ArgumentType.NUMBER,defaultValue:100}}},{opcode:"skewSVG",blockType:t.BlockType.REPORTER,text:"skew SVG content [SVG] at x [Y] y [X] as [TYPE]",arguments:{SVG:{type:t.ArgumentType.STRING,defaultValue:""},X:{type:t.ArgumentType.NUMBER,defaultValue:0},Y:{type:t.ArgumentType.NUMBER,defaultValue:0},TYPE:{type:t.ArgumentType.STRING,menu:"fileType"}}},{opcode:"removeThorns",blockType:t.BlockType.REPORTER,text:"remove vector thorns from [SVG]",arguments:{SVG:{type:t.ArgumentType.STRING,defaultValue:""}}}],menus:{CHANNELS:{acceptReporters:!0,items:["R","G","B"]},POSITIONS:["X","Y"],PIXELTYPE:["total","per line","per row"],REMOVAL:["under","over","equal to"],fileType:["content","dataURI"],EFFECTS:{acceptReporters:!0,items:["Saturation","Glitch","Chunk Glitch","Clip Glitch","Vignette","Ripple","Displacement","Posterize","Blur","Scanlines","Grain","Cubism"]}}}}setCutout(e){this.cutPos=[t.Cast.toNumber(e.X),t.Cast.toNumber(e.Y)]}changeCutout(e){this.cutPos=[this.cutPos[0]+t.Cast.toNumber(e.X),this.cutPos[1]+t.Cast.toNumber(e.Y)]}currentCut(t){return this.cutPos["X"===t.POS?0:1]}setScale(e){this.scale=[t.Cast.toNumber(e.SIZE),t.Cast.toNumber(e.Y)]}changeScale(e){this.scale=[this.scale[0]+t.Cast.toNumber(e.SIZE),this.scale[1]+t.Cast.toNumber(e.Y)]}currentScale(t){return this.scale["X"===t.POS?0:1]}setDirection(e){this.cutoutDirection=t.Cast.toNumber(e.ANGLE)}changeDirection(e){let a=this.cutoutDirection+t.Cast.toNumber(e.ANGLE);a>180&&(a=-180+t.Cast.toNumber(e.ANGLE)),a<-180&&(a=180+t.Cast.toNumber(e.ANGLE)),this.cutoutDirection=a}currentDir(){return this.cutoutDirection}clipImage(t){return new Promise(((e,a)=>{const o=new Image;o.onload=()=>{const a=new Image;a.onload=()=>{const t=document.createElement("canvas");t.width=o.width,t.height=o.height;const n=t.getContext("2d"),r=a.width+this.scale[0],s=a.height+this.scale[1],l=this.cutPos[0]+o.width/2-r/2,i=this.cutPos[1]-o.height/2+s/2;n.drawImage(o,0,0),n.globalCompositeOperation="destination-in";const c=(this.cutoutDirection+270)*Math.PI/180;n.translate(l+r/2,-1*i+s/2),n.rotate(c),n.drawImage(a,-r/2,-s/2,r,s),n.setTransform(1,0,0,1,0,0),n.globalCompositeOperation="source-over",e(t.toDataURL("image/png"))},a.src=this.confirmAsset(t.CUTOUT,"png")},o.src=this.confirmAsset(t.MAIN,"png")}))}overlayImage(t){return new Promise(((e,a)=>{const o=new Image;o.onload=()=>{const a=new Image;a.onload=()=>{const t=document.createElement("canvas");t.width=Math.max(o.width,a.width),t.height=Math.max(o.height,a.height);const n=t.getContext("2d");n.drawImage(o,0,0);const r=a.width+this.scale[0],s=a.height+this.scale[1],l=this.cutPos[0]+o.width/2-r/2,i=this.cutPos[1]-o.height/2+s/2;n.translate(l+r/2,-1*i+s/2),n.rotate((this.cutoutDirection+270)*Math.PI/180),n.drawImage(a,-r/2,-s/2,r,s),n.setTransform(1,0,0,1,0,0),e(t.toDataURL("image/png"))},a.src=this.confirmAsset(t.CUTOUT,"png")},o.src=this.confirmAsset(t.MAIN,"png")}))}setSoftness(e){this.softness=t.Cast.toNumber(e.AMT)}convertHexToRGB(t){const e=t.HEX,a={R:1,G:3,B:5}[t.CHANNEL];return parseInt(e.substring(a,a+2),16)}applyHueEffect(t){return new Promise((a=>{const o=e(t.COLOR),n=new Image;n.onload=async()=>{const t=this.printImg(n);await this.applyHue(t,o[0],o[1],o[2]),a(this.exportImg(n,t))},n.src=this.confirmAsset(t.SVG,"png")}))}applyHue(t,e,a,o){const n=t;for(let t=0;t{const n=new Image;n.onload=()=>{const t=this.printImg(n);for(let e=0;et>=e-this.softness&&t<=e+this.softness;l(n,a[0])&&l(r,a[1])&&l(s,a[2])&&t.set(o,e)}e(this.exportImg(n,t))},n.src=this.confirmAsset(t.DATA_URI,"png")}))}applyEffect(e){return new Promise((a=>{const o=t.Cast.toNumber(e.PERCENTAGE)+1||101,n=new Image;n.onload=async()=>{const r=document.createElement("canvas");r.width=n.width,r.height=n.height;const s=r.getContext("2d");s.drawImage(n,0,0);let l=s.getImageData(0,0,r.width,r.height);const i=this[`apply${t.Cast.toString(e.EFFECT).replaceAll(" ","")}`];i&&"function"==typeof i?await i(l,o-1):this.applySaturation(l,o-1),s.putImageData(l,0,0),a(r.toDataURL())},n.src=this.confirmAsset(e.SVG,"png")}))}applySaturation(e,a){const o=e.data,n=t.Cast.toNumber(a)/100;for(let t=0;t(Math.random()-.5)*n*3;for(let a=0;a<3;a++)o[t+a]=(o[t+a]+e())%256}}applyVignette(e,a){const o=e.data,n=e.width,r=e.height;let s=[n/2,r/2];const l=Math.sqrt(s[0]*s[0]+s[1]*s[1]),i=t.Cast.toNumber(a);for(let t=0;t=0&&g=0&&m0?a.copyWithin(i,t,t+4):a[i+3]=0}else a[i+3]=0}}applyDisplacement(t,e){const a=t.data,o=t.width,n=t.height,r=new Uint8ClampedArray(a.length);for(let t=0;t=0&&l=0&&i{let o=t.Cast.toNumber(e.CENTER_X)/100||0,n=t.Cast.toNumber(e.CENTER_Y)/-100||0;const r=t.Cast.toNumber(e.STRENGTH)/100||0,s=new Image;s.onload=()=>{const t=document.createElement("canvas");t.width=s.width,t.height=s.height,o+=s.width/200,n+=s.height/200;const e=t.getContext("2d");e.drawImage(s,0,0);let l=e.getImageData(0,0,t.width,t.height);this.applyBulge(l,o,n,r),e.putImageData(l,0,0),a(t.toDataURL())},s.src=this.confirmAsset(e.SVG,"png")}))}applyBulge(t,e,a,o){const n=t.data,r=t.width,s=t.height,l=new Uint8ClampedArray(n.length);for(let t=0;t=0&&g=0&&m{const o=t.Cast.toNumber(e.AMPX)/10||0,n=t.Cast.toNumber(e.AMPY)/10||0,r=t.Cast.toNumber(e.FREQX)/100||0,s=t.Cast.toNumber(e.FREQY)/100||0,l=new Image;l.onload=()=>{const t=document.createElement("canvas");t.width=l.width,t.height=l.height;const e=t.getContext("2d");e.drawImage(l,0,0);let i=e.getImageData(0,0,t.width,t.height);this.applyWave(i,o,n,r,s),e.putImageData(i,0,0),a(t.toDataURL())},l.src=this.confirmAsset(e.SVG,"png")}))}applyWave(t,e,a,o,n){const r=t.data,s=t.width,l=t.height,i=new Uint8ClampedArray(r.length);for(let t=0;t=0&&p=0&&h=0&&r=0&&p0)for(let t=0;t<4;t++)a[i+t]=s[t]/l}}applyChunkGlitch(t,e){const a=e/10,o=t.data,n=t.width,r=t.height,s=Math.floor(1*n);for(let t=0;t=0&&t{const o=t.Cast.toNumber(e.THRESHOLD)/100||0,n=e.REMOVE,r=new Image;r.onload=()=>{const t=document.createElement("canvas");t.width=r.width,t.height=r.height;const e=t.getContext("2d");e.drawImage(r,0,0);let s=e.getImageData(0,0,t.width,t.height);this.applyTransparencyRemoval(s,o,n),e.putImageData(s,0,0),a(t.toDataURL())},r.src=this.confirmAsset(e.SVG,"png")}))}applyTransparencyRemoval(t,e,a){const o=t.data,n=o.length/4;for(let t=0;te||"equal to"===a&&n>e-.01&&n{const o=t.Cast.toNumber(e.PERCENTAGE)/100||0,n=e.DIRECT,r=t.Cast.toNumber(e.WIDTH)/50||0,s=new Image;s.onload=()=>{const t=document.createElement("canvas");t.width=s.width,t.height=s.height;const e=t.getContext("2d");e.drawImage(s,0,0);let l=e.getImageData(0,0,t.width,t.height);this.applyLineGlitch(l,o,n,r),e.putImageData(l,0,0),a(t.toDataURL())},s.src=this.confirmAsset(e.SVG,"png")}))}applyLineGlitch(t,e,a,o){const n=t.data,r=t.width,s=t.height,l=Math.floor(s*e);for(let t=0;t=0&&e=0&&l{const n=Math.ceil(t.Cast.toNumber(a.THICKNESS)/4),r=e(a.COLOR),s=2.55*Math.min(Math.max(a.A,0),100),l=new Image;l.onload=()=>{const t=document.createElement("canvas");t.width=l.width,t.height=l.height;const e=t.getContext("2d");e.drawImage(l,0,0);let a=e.getImageData(0,0,t.width,t.height);this.applyOutline(a,n,r[0],r[1],r[2],s),e.putImageData(a,0,0),o(t.toDataURL())},l.src=this.confirmAsset(a.SVG,"png")}))}applyOutline(t,e,a,o,n,r){const s=t.data,l=t.width,i=t.height,c=new Uint8ClampedArray(s);for(let t=0;t=0&&e=0&&m=0&&i=0&&c{const a=t.PERCENTAGE,o=new Image;o.onload=()=>{const n=document.createElement("canvas");n.width=o.width+5*Math.abs(a),n.height=o.height+5*Math.abs(a);const r=n.getContext("2d");r.drawImage(o,2.5*Math.abs(a),2.5*Math.abs(a));let s=r.getImageData(0,0,n.width,n.height);this.applyChromAb(s,t.COLOR1,t.COLOR2,a,t.DIRECT),r.putImageData(s,0,0),e(n.toDataURL())},o.src=this.confirmAsset(t.SVG,"png")}))}applyChromAb(t,a,o,n,r){const s=t.data;let l=t.width,i=t.height;const c=new Uint8ClampedArray(s.length),p=new Uint8ClampedArray(s.length),h=e(a),u=e(o);for(let t=0;t{const n=new Image;n.onload=()=>{o(this.exportImg(n,this.printImg(n,e,a),e,a))},n.src=t}))}svgToBitmap(e){return this.stretch(this.confirmAsset(e.SVG,"png"),Math.abs(t.Cast.toNumber(e.WIDTH)),Math.abs(t.Cast.toNumber(e.HEIGHT)))}stretchImg(e){return this.stretch(this.confirmAsset(e.URI,"png"),Math.abs(t.Cast.toNumber(e.W)),Math.abs(t.Cast.toNumber(e.H)))}convertImageToSVG(t){return new Promise((e=>{const a=new Image;a.src=this.confirmAsset(t.URI,"png"),a.onload=()=>{const o=document.createElement("canvas");o.width=a.width,o.height=a.height;const n=o.getContext("2d");n.drawImage(a,0,0,a.width,a.height);const r=document.createElementNS("http://www.w3.org/2000/svg","svg");r.setAttribute("version","1.1"),r.setAttribute("xmlns","http://www.w3.org/2000/svg"),r.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),r.setAttribute("width",a.width.toFixed(5)),r.setAttribute("height",a.height.toFixed(5)),r.setAttribute("viewBox",`0,0,${a.width.toFixed(5)},${a.height.toFixed(5)}`);const s=new Map;for(let t=0;t{const a=document.createElementNS("http://www.w3.org/2000/svg","rect");a.setAttribute("x",t.x1.toFixed(5)),a.setAttribute("y",t.y1.toFixed(5)),a.setAttribute("width",(t.x2-t.x1+1).toFixed(5)),a.setAttribute("height",(t.y2-t.y1+1).toFixed(5)),a.setAttribute("fill",e),r.appendChild(a)})),s.clear()}let l=(new XMLSerializer).serializeToString(r);"dataURI"===t.TYPE&&(l=`data:image/svg+xml;base64,${btoa(l)}`),e(l)}}))}async makeSVGimage(t){return t.URI.startsWith("data:image/")?await new Promise(((e,a)=>{const o=new Image;o.onload=()=>{const a=o.width,n=o.height,r=`\n \n `;e("dataURI"===t.TYPE?`data:image/svg+xml;base64,${btoa(r)}`:r)},o.onerror=a,o.src=this.confirmAsset(t.URI,"png")})):t.URI}upscaleImage(t){return new Promise((e=>{const a=new Image;a.onload=()=>{const o=this.printImg(a),n=document.createElement("canvas");n.width=a.width,n.height=a.height;const r=n.getContext("2d");r.putImageData(new ImageData(new Uint8ClampedArray(o),a.width,a.height),0,0);const s=(10*t.NUM||0)/100,l=[0,-s,0,-s,1+4*s,-s,0,-s,0];this.sharpen(r,a.width,a.height,l,25),e(this.exportImg(a,r.getImageData(0,0,a.width,a.height).data))},a.src=this.confirmAsset(t.URI,"png")}))}sharpen(t,e,a,o,n){const r=t.getImageData(0,0,e,a).data,s=Math.round(Math.sqrt(o.length)),l=Math.floor(s/2),i=t.createImageData(e,a),c=i.data;for(let t=0;tn/50?(c[p]=this.clamp(h,0,255),c[p+1]=this.clamp(u,0,255),c[p+2]=this.clamp(g,0,255),c[p+3]=255):c[p+3]=0}t.putImageData(i,0,0)}clamp(t,e,a){return Math.min(a,Math.max(e,t))}audioToImage(e){const a=e.AUDIO_URI,o=Math.abs(t.Cast.toString(e.W)),n=document.createElement("canvas"),r=n.getContext("2d");n.width=o,n.height=Math.abs(t.Cast.toString(e.H));for(let t=0;tt.Cast.toNumber(e))),a=t.Cast.toNumber(a),o.length>3&&(e=(e=(e=(e=e.replace(/viewBox="([^"]+)"/,`viewBox="${o[0]},${o[1]},${o[2]+2*a},${o[3]+2*a}"`)).replace(/width="([^"]+)"/,`width="${o[2]+2*a}"`)).replace(/height="([^"]+)"/,`height="${o[3]+2*a}"`)).replace(/{e.onload=()=>{const o=this.printImg(e);a("total"===t.TYPE?o.length/4:"per line"===t.TYPE?e.width:e.height)}}))}setPixel(t){return this.setPixels(t)}setPixels(a){const o=new Image;return o.src=this.confirmAsset(a.URI,"png"),new Promise((n=>{o.onload=()=>{const r=t.Cast.toNumber(a.NUM),s=t.Cast.toNumber(a.NUM2)||r,l=this.printImg(o);for(let t=r;t<=s&&t<=l.length/4;t++){const o=e(a.COLOR);for(let e=0;e<4;e++)l[4*(t-1)+e]=o[e]}n(this.exportImg(o,l))}}))}getPixel(e){const a=new Image;return a.src=this.confirmAsset(e.URI,"png"),new Promise((o=>{a.onload=()=>{const n=t.Cast.toNumber(e.NUM),r=this.printImg(a);if(n>=1&&n<=r.length/4){const t=4*(n-1),e=r.slice(t,t+4);o(function(t,e,a,o){const n=void 0!==o?Math.round(o).toString(16).padStart(2,"0"):"";return`#${(1<<24|t<<16|e<<8|a).toString(16).slice(1)}${n}`}(e[0],e[1],e[2],e[3]))}else o("#00000000")}}))}crackImage(t){const e=Math.max(2,t.SHARDS),a=new Image;a.src=this.confirmAsset(t.URI,"png");const o=4*a.width,n=4*a.height;return this.allShards=[],new Promise((r=>{a.onload=()=>{for(let r=0;r=t.SHARDS);r++)for(let r=0;r=t.SHARDS);r++){const t=document.createElement("canvas"),r=o/e,s=n/e;t.width=r,t.height=s;const l=t.getContext("2d");l.clearRect(0,0,r,s),l.beginPath(),l.moveTo(Math.random()*r,Math.random()*s);for(let t=0;t<10*Math.random()+3;t++)l.lineTo(Math.random()*r,Math.random()*s);l.closePath(),l.clip();const i=Math.random()*(o-r),c=Math.random()*(n-s);l.drawImage(a,-i,-c,o,n);const p=this.printImg(t);this.allShards.push(this.exportImg(t,p))}r()}}))}getShard(t){return this.allShards[t.SHARD-1]||""}printImg(t,e,a){const o=document.createElement("canvas");o.width=e||t.width,o.height=a||t.height;const n=o.getContext("2d");return n.drawImage(t,0,0,o.width,o.height),n.getImageData(0,0,o.width,o.height).data}exportImg(t,e,a,o){const n=document.createElement("canvas");n.width=a||t.width,n.height=o||t.height;return n.getContext("2d").putImageData(new ImageData(new Uint8ClampedArray(e),n.width,n.height),0,0),n.toDataURL()}confirmAsset(t,e){return t&&(t.startsWith("data:image/")||t.startsWith("