PageSourceSearch

https://pixoeditor.com/editor/scripts/bridge.m.js

js pixoeditor.com collected 2026-10-04 00:09:40 UTC 18,609 bytes, 1 lines download raw bytes

1function extend(e){for(var t=1,i=arguments.length;t<i;t++){var o=arguments[t];if(o&&"object"==typeof o)for(var n in o)o.hasOwnProperty(n)&&(e[n]&&o[n]&&"object"==typeof e[n]&&e[n].constructor.toString()==o[n].constructor.toString()?e[n]=extend(e[n],o[n]):o[n]&&["functionObject(){[nativecode]}","functionArray(){[nativecode]}"].indexOf(o[n].constructor.toString().replace(/\s+/g,""))>-1?e[n]=extend(new o[n].constructor,o[n]):e[n]=o[n])}return e}function generateID(){return(1e7*Math.random()*Date.now()).toString(36).substr(0,12)}function padLeft(e,t,i){t=void 0===t?2:Number(t),i=void 0===i?"0":String(i);var o=t-(e=String(e)).length+1;return o<=0?e:new Array(o).join(i)+e}function parseURL(e){const t=document.createElement("a");return t.href=e,t.toString=t.toJSON=function(){return e},t}function dataURItoBlob(e,t){t=t||512;const i=e.split(","),o=i[1],n=i[0].match(/:(.*?);/)[1],r=atob(o),s=[];for(let e=0;e<r.length;e+=t){const i=r.slice(e,e+t),o=new Array(i.length);for(let e=0;e<i.length;e++)o[e]=i.charCodeAt(e);const n=new Uint8Array(o);s.push(n)}return new Blob(s,{type:n})}"undefined"!=typeof module&&module.exports&&(module.exports=extend),"undefined"!=typeof module&&(module.exports=generateID),"undefined"!=typeof module&&module.exports&&(module.exports=padLeft),Pixo=window.Pixo||{},function(){function e(e){const t=[].slice.call(arguments,1);for(let i=0,o=t.length;i<o;i++)e=e.replace("%s",t[i]);return e}const t=Pixo.ACTIONS={SAVE_CLOSE:{caption:e("Save"),action:"SAVEANDCLOSE",icon:"download2"},CLOSE:{caption:e("Cancel"),action:"CLOSE",icon:"exit"},UNDO:{caption:e("Undo"),action:"UNDO",icon:"undo2"},REDO:{caption:e("Redo"),action:"REDO",icon:"redo2"},TOGGLE_GRID:{caption:e("Grid"),action:"TOGGLE_GRID",icon:"frame-contract"}};Pixo.ACTIONS_MENU=[t.SAVE_CLOSE,t.UNDO,t.REDO,t.TOGGLE_GRID,t.CLOSE]}(),function(){const e={undefined:"https://pixoeditor.com",default:"https://pixoeditor.com",US:"https://pixoeditor.com",NY:"https://pixoeditor.com",EU:"https://eu.pixoeditor.com",IN:"https://in.pixoeditor.com"},t=["modal","window","child"],i=["auto","input","png","jpeg","webp"],o=parseURL(document.querySelector('script[src*="pixoeditor.com/editor/scripts/bridge.m.js"]').src).hostname.split(".")[0].toUpperCase();function n(){return e[window.PIXO_LOCATION||o]||e.US}function r(){return n()+"/editor/"}const s=document.querySelector('script[src^="'+n()+'"]');if(s){const e=new RegExp("^"+n()+":\\d{2,5}\\/");e.test(s.src)&&window.console&&window.console.warn(["Pixo.Bridge is loaded from a deprecated URL.","Correct URL is:",s.src.replace(e,n()+"/"),"The deprecated URL is:%c",s.src,"%cPlease update all your references to the correct source URL."].join(" "),"text-decoration: line-through","text-decoration: none")}function a(e){var t=new ClipboardEvent("").clipboardData||new DataTransfer;for(let i=0,o=e.length;i<o;i++)t.items.add(e[i]);return t.files}function c(e){return new Promise((function(t,i){const o=function(e){switch(e.constructor.toString().replace("function ","").split("()")[0].trim()){case"HTMLImageElement":return"element";case"String":return/^https?:\/\//.test(e)?"url":/^\{.+\}$/.test(e)?"json":"base64";case"File":case"Blob":return"file";case"Object":return"object"}}(e);switch(o){case"object":e=JSON.stringify(e);case"json":case"base64":return t(e);case"url":const i=e;(e=new Image).src=i;case"element":if(!e.src)throw new Error("The image you are trying to open in Pixo does not have src attribute");return t(e.src);case"file":const o=new FileReader;return o.onload=function(e){t(e.target.result)},o.readAsDataURL(e)}}))}Pixo=window.Pixo||{},Pixo.Bridge=function(e){if(!e||"object"!=typeof e)throw new Error("Pixo.Bridge expects valid configuration parameter");if(!e.apikey)throw new Error("Pixo.Bridge expects valid API key in constructor config");if(this.callbacks={},!(e=extend({type:"window",propertypanel:{collapsible:!0,collapsed:!0},language:"en-US",output:{format:"auto",quality:.65,optimize:!1},usewebgl:!0,sessionrestore:{saved:!0,unsaved:!0}},e)).actions||"object"==typeof e.actions&&e.actions.length||delete e.actions,!~t.indexOf(e.type))throw new Error("Pixo.Bridge expects valid type in constructor config - one of "+t);if("child"===e.type&&("string"==typeof e.parent&&(e.parent=document.getElementById(e.parent)||document.body.querySelector(e.parent)),!(e.parent instanceof Element)))throw new Error('Pixo.Bridge expects DOM element as "parent" in constructor config');if(!e.output)throw new Error("Pixo.Bridge expects valid output (object) in constructor config");if(!~i.indexOf(e.output.format))throw new Error("Pixo.Bridge expects valid output format in constructor config - one of "+i);if(isNaN(Number(e.output.quality))||e.output.quality<0||e.output.quality>1)throw new Error("Pixo.Bridge expects valid output quality in constructor config (between 0 and 1)");e.width=Number(e.width)?e.width+"px":e.width||"100%",e.height=Number(e.height)?e.height+"px":e.height||"100%",["onSave","onCancel","onClose","onStateChange"].forEach((function(t){"function"!=typeof e[t]&&(e[t]=function(){})})),Object.defineProperties(this,{config:{value:e},id:{value:generateID()},fileinputs:{value:[]}}),m.call(this,e),this.operations=[];const o=this;this.readyPromise=new Promise((function(e){o.resolveReadyPromise=e})),e.fileinput&&("string"==typeof e.fileinput?(this.globalOnChange=({target:t})=>{t.matches(e.fileinput)&&this.attachToFileInput(t)},window.addEventListener("change",this.globalOnChange,!0)):this.attachToFileInput(e.fileinput))},Pixo.Bridge.prototype.edit=function(e){if(!e)throw new Error("Pixo.Bridge::edit expects valid source element (Image, String, File) or array of sources");if(this.destroyed)throw new Error("Pixo instance is destroyed. Create new instance");Promise.all([].slice.call(arguments).map((function(e){return e=e&&e.length&&"object"==typeof e?[].slice.call(e):e,Promise.all([].
1concat(e).map(c))}))).then(d.bind(this),alert)},Pixo.Bridge.prototype.attachToFileInput=function(e){if("string"==typeof e&&(e=document.getElementById(e)||document.body.querySelectorAll(e)),!e||!e instanceof NodeList&&(!e instanceof HTMLInputElement||"file"!==e.type))throw new Error('Pixo.Bridge::attachToFileInput expects valid <input type="file" /> element');if(e.length>=0)return e.forEach(this.attachToFileInput,this);const t=this;if(~t.fileinputs.indexOf(e))return;t.fileinputs.push(e);const i=t.onFileInputChange=function(o){if(!e.files.length)return;o.stopPropagation();const n=t.config.onSave;t.config.onSave=function(){const r=[].map.call(arguments,(e=>e.toBlob()));e.files=new a(r.map((function(t,i){const o=t.type.includes("jpeg")?"jpg":"png",n=e.files[i].name.split(".").slice(0,-1).join(".");return new File([t],n+"."+o,{type:t.type})}))),n.apply(null,arguments),t.config.onSave=n,e.removeEventListener("change",i,!0),e.dispatchEvent(o),e.addEventListener("change",i,!0)};const r=t.config.onCancel;t.config.onCancel=function(){r&&r.apply(null,arguments),t.config.onCancel=r,e.removeEventListener("change",i,!0),e.dispatchEvent(o),e.addEventListener("change",i,!0)},t.edit.apply(t,[e.multiple?Array.from(e.files):e.files[0]].flat())};e.addEventListener("change",i,!0)},Pixo.Bridge.prototype.detachFromFileInput=function(e){if("string"==typeof e&&(e=document.getElementById(e)||document.body.querySelectorAll(e)),!e||!e instanceof NodeList&&(!e instanceof HTMLInputElement||"file"!==e.type))throw new Error('Pixo.Bridge::detachFromFileInput expects valid <input type="file" /> element');if(e.length)return e.forEach(this.detachFromFileInput.bind(this));e.removeEventListener("change",this.onFileInputChange,!0);const t=this.fileinputs.indexOf(e);~t&&this.fileinputs.splice(t,1)},Pixo.Bridge.prototype.cancelEditing=function(){if(this.destroyed)throw new Error("Pixo instance is destroyed. Create new instance");x.call(this,this.config)},Pixo.Bridge.prototype.destroy=function(){if(this.destroyed)throw new Error("Pixo instance is already destroyed");x.call(this,this.config),Object.defineProperty(this,"destroyed",{value:!0}),y.call(this),window.removeEventListener("change",this.globalOnChange,!0)},Pixo.Bridge.prototype.filterStickers=function(e){if(!this.plugindata)return window.console&&window.console.warn("Invalid call of filterStickers: Pixo editor not yet ready. Use configuration function instead."),[];const t=this.plugindata.stickers=e([].concat(this.plugindata.stickers));return this.editor&&this.editor.postMessage(JSON.stringify({cmd:"configure_stickers",stickers:t}),n()),t},Pixo.Bridge.prototype.filterFrames=function(e){if(!this.plugindata)return window.console&&window.console.warn("Invalid call of filterFrames: Pixo editor not yet ready. Use configuration function instead."),[];const t=this.plugindata.frame=e([].concat(this.plugindata.frame));return this.editor&&this.editor.postMessage(JSON.stringify({cmd:"configure_frames",frames:t}),n()),t},Pixo.Bridge.prototype.filterCropSizes=function(e){if(!this.plugindata)return window.console&&window.console.warn("Invalid call of filterCropSizes: Pixo editor not yet ready. Use configuration function instead."),[];const t=this.plugindata.crop=e([].concat(this.plugindata.crop));return this.editor&&this.editor.postMessage(JSON.stringify({cmd:"configure_crop",crop:t}),n()),t},Pixo.Bridge.prototype.filterFonts=function(e){if(!this.plugindata)return window.console&&window.console.warn("Invalid call of filterFonts: Pixo editor not yet ready. Use configuration function instead."),[];const t=this.plugindata.text=e([].concat(this.plugindata.text));return this.editor&&this.editor.postMessage(JSON.stringify({cmd:"configure_text",text:t}),n()),t},Pixo.Bridge.prototype.filterTextStickers=function(e){if(!this.plugindata)return window.console&&window.console.warn("Invalid call of filterTextStickers: Pixo editor not yet ready. Use configuration function instead."),[];const t=this.plugindata.textstickers=e([].concat(this.plugindata.textstickers));return this.editor&&this.editor.postMessage(JSON.stringify({cmd:"configure_textstickers",stickers:t}),n()),t},Pixo.Bridge.prototype.filterMedia=function(e){if(!this.plugindata)return window.console&&window.console.warn("Invalid call of filterMedia: Pixo editor not yet ready. Use configuration function instead."),[];const t=this.plugindata.media=e([].concat(this.plugindata.media));return this.editor&&this.editor.postMessage(JSON.stringify({cmd:"configure_media",media:t}),n()),t},Pixo.Bridge.prototype.filterCovers=function(e){if(!this.plugindata)return window.console&&window.console.warn("Invalid call of filterCovers: Pixo editor not yet ready. Use configuration function instead."),[];const t=this.plugindata.covers=e([].concat(this.plugindata.covers));return this.editor&&this.editor.postMessage(JSON.stringify({cmd:"configure_covers",covers:t}),n()),t},Pixo.Bridge.prototype.saveAndClose=function(e){if(!this.callbacks.SAVEANDCLOSE){const t=this;this.callbacks.SAVEANDCLOSE=function(){t.callbacks.SAVEANDCLOSE=null,"function"==typeof e&&e.apply(null,arguments)}}this.editor.postMessage(JSON.stringify({cmd:"SAVEANDCLOSE"}),n())},Pixo.Bridge.prototype.exec=function(e,t){const i=this,o={};o.promise=new Promise((function(e){o.resolve=e})),(this.operations[this.operations.length-1]||{promise:this.readyPromise}).promise.then((function(){i.editor.postMessage(JSON.stringify(extend({},t,{cmd:e})),n())})),this.operations.push(o);const r=o.promise.then;return o.promise.then=function(){const e=r.apply(this,arguments);return e.exec=i.exec.bind(i),e},o.promise.exec=i.exec.bind(i),o.promise},Pixo.Bridge.prototype.enableWebGL=function(){this.editor.postMessage(JSON.stringify({cmd:"configure_fabric",usewebgl:!0}),n())},Pixo.Bridge.prototype.disableWebGL=function(){this.editor.postMessage(JSON.stringify({cmd:"configure_fabric",usewebgl:!1}),n())},Pixo.Bridge.prototype.setOutput=function(e){this.editor.postMessage(JSON.stringify({cmd:"configure_output",output:e}),n())};const l=["logosrc","canvasbgcolor","editmenubgcolor","actionsmenubgcolor","propertiespanelbgcolor","textcolor","editmenutextcolor","actionsmenutextcolor","propertiespaneltextcolor","buttonstextcolor","buttonsbgcolor","css","url"];function d(e){if(this.editor)return this.editor.postMessage(JSON.stringify({cmd:"update",src:e,id:this.id}),n());this.initPromise=new Promise((function(t){t(e)}));const t=this.config,i=[t.apikey];let o=null;if(t.theme&&(o={theme:t.theme}),t.styles){o=extend(o||{},t.styles);for(let e in t.styles)!t.styles.hasOwnProperty(e)||~l.indexOf(e)&&t.styles[e]||delete o[e]}o&&i.push(encodeURIComponent(JSON.stringify(o)));const s=r()+i.join(",");switch(t.type){case"window":default:return this.editor=u.call(this,s,t);case"modal":return this.editor=p.call(this,s,t);case"child":return this.editor=f.call(this,s,t)}}function u(e,t){var i="";if("100%"!==t.width){var o=~t.width.indexOf("%")?screen.width*parseFloat(t.width)/100:parseFloat(t.width);i+=",width="+o+",left="+(screen.width-o)/2}if("100%"!==t.height){var n=~t.height.indexOf("%")?screen.height*parseFloat(t.height)/100:parseFloat(t.height);i+=",height="+n+",top="+(screen.height-n)/2}const r="pixo-"+generateID(),s=window.open("about:blank",r,"menubar=0,toolbar=0,location=0,status=0,titlebar=0"+i),a=document.createElement("a");
1return a.href=e,a.target=r,a.referrerPolicy="strict-origin-when-cross-origin",a.click(),s}function p(e,t){let i=null;if(t.overlay){const e="rgba( 0, 0, 0, .3 )",o="object"==typeof t.overlay&&t.overlay.color||e;i=this.overlay=document.body.appendChild(document.createElement("div")),i.className="pixo-overlay",i.setAttribute("style",["background: "+o].join(";"))}return h.call(this,document.body,e,t,"pixo-modal")}function f(e,t){return h.call(this,t.parent,e,t)}function h(e,t,i,o){const n=this.wrapper=e.appendChild(document.createElement("div"));n.className=["pixo-wrapper"].concat(o).join(" "),n.setAttribute("style",["width: "+i.width,"height: "+i.height].join(";"));const r=n.appendChild(document.createElement("iframe"));return r.referrerPolicy="strict-origin-when-cross-origin",r.className="pixo-iframe",r.setAttribute("scrolling","no"),r.src=t,r.contentWindow}const g={};function m(e){g[this.id]=w.bind(this,e)}function y(){delete g[this.id]}function w(e,t){const i=this,o={};try{extend(o,JSON.parse(t.data))}catch(e){}switch(o.cmd){case"init":if(!i.editor)return;i.plugindata=o.plugindata,i.initPromise.then((function(t){i.editor.postMessage(JSON.stringify({...e,parent:null,cmd:"init",src:t,id:i.id,propertypanel:e.propertypanel||{},actions:e.actions?e.actions.map((function(e){let t;if("function"==typeof e.onClick){const o=generateID();i.callbacks[o]=e.onClick,t=o}return extend({},e,{onClick:t})})):void 0}),n()),i.resolveReadyPromise(),"function"==typeof e.filterStickers&&i.filterStickers(e.filterStickers),"function"==typeof e.filterFrames&&i.filterFrames(e.filterFrames),"function"==typeof e.filterCropSizes&&i.filterCropSizes(e.filterCropSizes),"function"==typeof e.filterFonts&&i.filterFonts(e.filterFonts),"function"==typeof e.filterTextStickers&&i.filterTextStickers(e.filterTextStickers),"function"==typeof e.filterMedia&&i.filterMedia(e.filterMedia),"function"==typeof e.filterCovers&&i.filterCovers(e.filterCovers)}));break;case"saveandclose":if(o.id!==i.id)return;i.wrapper&&(i.wrapper.style.display="none"),i.overlay&&(i.overlay.style.display="none");const t=o.data.map(v);e.onSave.apply(null,t),this.callbacks.SAVEANDCLOSE&&this.callbacks.SAVEANDCLOSE.apply(null,t);break;case"save":if(o.id!==i.id)return;const r=o.data.map(v);(i.operations.shift()||{resolve:function(){}}).resolve(r.length>1?r:r[0]),e.onSave.apply(null,r);break;case"cancel":if(o.id!==i.id)return;x.call(i,e),e.onCancel(),e.onClose(o.sessions);break;case"close":if(o.id!==i.id)return;x.call(i,e),e.onClose(o.sessions);break;case"update":if(o.id!==i.id)return;(i.operations.shift()||{resolve:function(){}}).resolve(o.state);break;case"statechange":if(o.id!==i.id)return;e.onStateChange.call(this,o.state);break;case"onClick":if(o.id!==i.id)return;i.callbacks[o.callback].call(i,o.value)}}function x(e){if(!this.editor)return;this.wrapper&&this.wrapper.parentNode.removeChild(this.wrapper),this.overlay&&this.overlay.parentNode.removeChild(this.overlay),"window"===e.type&&this.editor.close(),this.editor=this.wrapper=this.overlay=null;const t=this;this.readyPromise=new Promise((function(e){t.resolveReadyPromise=e}))}function b(e,t="download"){const i=document.createElement("a");i.href=URL.createObjectURL(e),i.download=t+"."+e.type.split("/")[1],document.body.appendChild(i),i.dispatchEvent(new MouseEvent("click",{bubbles:!0,cancelable:!0,view:window})),document.body.removeChild(i)}function v(e){return{toImage:function(){const t=new Image;return t.src=e[0].base64||e[0],t},toDataURL:function(){return e[0].base64||e[0]},toBlob:function(){return dataURItoBlob(e[0].base64||e[0])},toJSON:function(){return e[0].json},toBase64:function(){return(e[0].base64||e[0]||"").split(",")[1]},download:function(t){for(let i=0,o=e.length;i<o;i++)b(dataURItoBlob(e[0].base64||e[0]),t)},toImages:function(){return e.map((function(e){const t=new Image;return t.src=e.base64||e,t}))},toDataURLs:function(){return e.map((function(e){return e.base64||e}))},toBlobs:function(){return e.map((function(e){return dataURItoBlob(e.base64||e)}))},toJSONs:function(){return e.map((function(e){return dataURItoBlob(e.json)}))},toBase64s:function(){return e.map((function(e){return(e.base64||e||"").split(",")[1]}))},downloadAll:function t(){if(!window.JSZip){const e=document.head.appendChild(document.createElement("script"));return e.onload=t,void(e.src=r()+"scripts/zip.m.js")}const i=new JSZip;for(let t=0,o=e.length;t<o;t++){const o=dataURItoBlob(e[0].base64||e[0]);i.file("image"+padLeft(t+1+"")+"."+o.type.split("/")[1],o)}i.generateAsync({type:"blob"}).then(b)}}}window.addEventListener("message",(function(e){for(let t in g)g.hasOwnProperty(t)&&g[t](e)}));function S(e,t){return e+"{"+t.join(";")+"}"}document.head.appendChild(document.createElement("style")).innerHTML=function(e){let t=[];for(let i in e)e.hasOwnProperty(i)&&t.push(S(i,e[i]));return t.join("")}({".pixo-overlay":["position: fixed","left: 0","right: 0","top: 0","bottom: 0","width: 100%","height: 100%"],".pixo-wrapper":["position: relative","background: #bfbfbf"],".pixo-modal":["position: fixed","left: 50%","top: 50%","transform: translate(-50%, -50%)"],".pixo-wrapper:before":["position: absolute","left: 0","right: 0","top: 0","bottom: 0","z-index: 1","display: flex","align-items: center","justify-content: center","height: 100%",'content: "Loading..."',"color: white"],".pixo-iframe":["position: relative","z-index: 2","width: 1px","min-width: 100%","height: 100%","border: 0 none"]})}();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.