-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoint.format.raster.min.js
More file actions
14 lines (8 loc) · 4 KB
/
joint.format.raster.min.js
File metadata and controls
14 lines (8 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*! Rappid v3.1.1 - HTML5 Diagramming Framework - TRIAL VERSION
Copyright (c) 2015 client IO
2020-06-11
This Source Code Form is subject to the terms of the Rappid Trial License
, v. 2.0. If a copy of the Rappid License was not distributed with this
file, You can obtain one at http://jointjs.com/license/rappid_v2.txt
or from the Rappid archive as was distributed by client IO. See the LICENSE file.*/
this.joint=this.joint||{},function(t,l,i){"use strict";function n(t,h,s){if(void 0===s&&(s={}),void 0===t)throw new Error("The the dia.Paper is a mandatory argument.");var u=s.canvg||("undefined"!=typeof canvg?canvg:void 0),e=function(t,e){var i=function(t){var e=l.util.normalizeSides(t.padding);t.width&&t.height&&(e.left+e.right>=t.width&&(e.left=e.right=0),e.top+e.bottom>=t.height&&(e.top=e.bottom=0));return e}(e),r=l.g.rect({x:-i.left,y:-i.top,width:i.left+i.right,height:i.top+i.bottom});if(e.width&&e.height){var n=t.width+i.left+i.right,a=t.height+i.top+i.bottom;r.scale(n/e.width,a/e.height)}return l.g.Rect(t).moveAndExpand(r)}(s.area||t.paperToLocalRect(t.getContentBBox()),s),c=function(t,e){return{width:Math.max(Math.round(t.width*e),1),height:Math.max(Math.round(t.height*e),1)}}(l.util.isNumber(s.width)&&l.util.isNumber(s.height)?s:e,function(t){var e=1;if(void 0!==t&&(e=parseFloat(t),!Number.isFinite(e)||0===e))throw new Error("dia.Paper: invalid raster size ("+t+")");return e}(s.size));if(!function(t,e){var i=document.createElement("canvas");i.width=t,i.height=e;var r=t-1,n=e-1,a=i.getContext("2d");try{a.fillStyle="rgb(1,1,1)",a.fillRect(r,n,1,1);var o=a.getImageData(r,n,1,1).data;if(1!==o[0]||1!==o[1]||1!==o[2])return!1}catch(t){return!1}return!0}(c.width,c.height))throw new Error("dia.Paper: raster size exceeded.");var d,g=new Image;g.onload=function(){var t,e,i;function r(){(i=document.createElement("canvas")).width=c.width,i.height=c.height,(e=i.getContext("2d")).fillStyle=s.backgroundColor||"white",e.fillRect(0,0,c.width,c.height)}function n(){t=i.toDataURL(s.type,s.quality),h(t),a()}function a(){i.svg&&l.util.isFunction(i.svg.stop)&&setTimeout(i.svg.stop,1)}r();try{e.drawImage(g,0,0,c.width,c.height),n()}catch(t){if(void 0===u)return void console.error("Canvas tainted. Canvg library required.");r();var o={ignoreDimensions:!0,ignoreClear:!0,ignoreMouse:!0,ignoreAnimation:!0,offsetX:0,offsetY:0,useCORS:!0};u(i,d,l.util.assign(o,{forceRedraw:function(){return!this.called&&(this.called=!0)}.bind({called:!1}),renderCallback:function(){try{n()}catch(t){a(),d=function(t){return t.replace(/<image[^>]*>/g,function(t){var e=t.match(/href="([^"]*)"/),i=e&&e[1],r="data:image/svg+xml";if(i&&i.substr(0,r.length)===r){var n=atob(i.substr(i.indexOf(",")+1));return n.substr(n.indexOf("<svg"))}return t})}(d),r(),u(i,d,l.util.assign(o,{renderCallback:n}))}}}))}},i.toSVG(t,function(t){d=t,g.src="data:image/svg+xml,"+encodeURIComponent(t)},{paper:t,convertImagesToDataUris:!0,beforeSerialize:s.beforeSerialize,area:e,useComputedStyles:s.useComputedStyles,stylesheet:s.stylesheet,preserveDimensions:{width:c.width,height:c.height}})}function a(t,e,i){(i=i||{}).type="image/png",n(t,e,i)}function o(t,e,i){(i=i||{}).type="image/jpeg",n(t,e,i)}function r(t,e){var i=l.util.uniqueId("png_output");a(t,function(t){window.open("",i,"menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes").document.write('<img src="'+t+'"/>')},l.util.assign({padding:10},e))}l.dia.Paper.prototype.openAsPNG=function(t){for(var e=arguments.length,i=Array(e);e--;)i[e]=arguments[e];return r.apply(this,[this].concat(i))},l.dia.Paper.prototype.toJPEG=function(t,e){for(var i=arguments.length,r=Array(i);i--;)r[i]=arguments[i];return o.apply(this,[this].concat(r))},l.dia.Paper.prototype.toPNG=function(t,e){for(var i=arguments.length,r=Array(i);i--;)r[i]=arguments[i];return a.apply(this,[this].concat(r))},l.dia.Paper.prototype.toDataURL=function(t,e){for(var i=arguments.length,r=Array(i);i--;)r[i]=arguments[i];return n.apply(this,[this].concat(r))},t.openAsPNG=r,t.toDataURL=n,t.toJPEG=o,t.toPNG=a}(this.joint.format=this.joint.format||{},joint,joint.format);