-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoint.format.print.min.js
More file actions
14 lines (8 loc) · 4.66 KB
/
joint.format.print.min.js
File metadata and controls
14 lines (8 loc) · 4.66 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.*/
!function(v,y){"use strict";v=v&&v.hasOwnProperty("default")?v.default:v;y.dia.Paper.prototype.print=function(i){var t=h(i),e=a.call(this,t),r={sheetSizePx:x(t)};t.ready(e,function(t){n.call(this,t,i)}.bind(this),r)},y.dia.Paper.prototype.preparePrintArea=function(t,i){this.trigger("beforeprint",i);var e=v("<div/>").addClass("printarea"),r=v("<div/>").addClass(y.util.addClassNamePrefix("print-paper")).css("position","relative");i.size&&e.addClass("printarea-size-"+i.size);var n=y.V(this.svg).clone(),a=n.findOne("."+y.util.addClassNamePrefix("layers"));r.append(n.node);var h=x(i),s=this.getArea(),o=this.scale(),d=o.sx,l=o.sy,p=this.translate(),u=p.tx,c=p.ty,f=y.V.createSVGMatrix().translate(u/d,c/l),m=z(s,t,h),g=m.scaleToFit,w=m.bBox;return r.css({left:0,top:0}),n.attr({width:w.width*g,height:w.height*g,style:"position:relative",viewBox:[w.x,w.y,w.width,w.height].join(" ")}),a.attr("transform",y.V.matrixToTransformString(f)),e.append([r.append([n.node])]),e.addClass("preview"),{$el:e,sheetSizePx:h}};var n=function(t,i){if(t){var e=v(document.body);e.addClass("joint-print");var r=this.$el.children().detach();t.forEach(function(t){t.removeClass("preview").addClass("print-ready").appendTo(e)});var n=!1,a=function(){n||(n=!0,e.removeClass("joint-print"),t.forEach(function(t){t.remove()}),this.$el.append(r),v("#print-styles").remove(),this.trigger("afterprint",i),v(window).off("afterprint",a))}.bind(this);v(window).one("afterprint",a),setTimeout(a,200),window.print()}},a=function(t){var i,e=d.call(this,t),r=[];if(t.poster)for(var n=p(e,t.poster),a=l(e,n),h=0;h<a.length;h++)i=this.preparePrintArea(a[h],t),r.push(i.$el);else i=this.preparePrintArea(e,t),r.push(i.$el);if(i){var s={width:i.sheetSizePx.cssWidth,height:i.sheetSizePx.cssHeight};o(s,t)}return r},x=function(t){var i=y.util.normalizeSides(t.margin),e=t.sheet;i.unit=t.marginUnit,e.unit=t.sheetUnit;var r="calc("+e.width+e.unit+" - "+(i.left+i.right)+i.unit+")",n="calc("+e.height+e.unit+" - "+(i.top+i.bottom)+i.unit+")",a=s.measure(r,n,"");return{cssWidth:r,cssHeight:n,width:a.width,height:a.height}},z=function(t,i,e){var r=new y.g.Rect({x:i.x-t.x,y:i.y-t.y,width:i.width,height:i.height}),n=r.width/r.height,a=e.width/e.height;return{bBox:r,scaleToFit:a<n?e.width/r.width:e.height/r.height,fitHorizontal:a<n}},h=function(t){var i=y.util.defaultsDeep({},t,{area:null,poster:!1,sheet:{width:210,height:297},sheetUnit:"mm",ready:function(t,i,e){i(t)},margin:.4,marginUnit:"in",padding:5});return i.area||(i.printingAll=!0),i},o=function(t,i){var e=function(i){return Object.keys(i).map(function(t){return t+":"+i[t]}).join(";")+";"}(t),r=y.util.normalizeSides(i.margin),n=i.marginUnit;!function(t){var i=v("#print-styles"),e='<style type="text/css" id="print-styles">'+t+"</style>";i.length?i.html(t):v("head").append(e)}(["@media print {",".printarea.print-ready {",e,"}","@page {","margin:"+[r.top+n,r.right+n,r.bottom+n,r.left+n].join(" ")+";","size:"+(i.sheet.width+i.sheet.unit)+" "+(i.sheet.height+i.sheet.unit),"}",".printarea.preview {",e,"}","}"].join(""))},d=function(t){var i=t.area;if(!i){var e=y.util.normalizeSides(t.padding);i=this.getContentArea().moveAndExpand({x:-e.left,y:-e.top,width:e.left+e.right,height:e.top+e.bottom})}return i},l=function(t,i){for(var e,r=i.width,n=i.height,a=[],h=0,s=0,o=0,d=0;h<t.height;){for(;s<t.width&&(e=y.g.Rect(t.x+s,t.y+h,r,n),a.push(e),s+=r,!(200<d));)d++;if(d=s=0,h+=n,200<o)break;o++}return a},p=function(t,i){var e={width:i.width,height:i.height};return e.width||(e.width=Math.ceil(t.width/(i.columns||1))),e.height||(e.height=Math.ceil(t.height/(i.rows||1))),e},s={supportedUnits:{px:function(t){return t},mm:function(t){return this.millimeterSize*t},cm:function(t){return this.millimeterSize*t*10},in:function(t){return this.millimeterSize*t*25.4},pt:function(t){return this.millimeterSize*(25.4*t/72)},pc:function(t){return this.millimeterSize*(25.4*t/6)}},measure:function(t,i,e){e=e||"";var r=v("<div/>").css({display:"inline-block",position:"absolute",left:-15e3,top:-15e3,width:t+e,height:i+e}).appendTo(document.body),n={width:r.width(),height:r.height()};return r.remove(),n},toPx:function(t,i){if(this.millimeterSize||(this.millimeterSize=this.measure(1,1,"mm").width),i=(i||"").toLowerCase(),!this.supportedUnits[i])throw new Error("Unsupportted unit "+i);return this.supportedUnits[i].call(this,t)}}}($,joint);