all files / action/ export.js

96.98% Statements 386/398
81.16% Branches 112/138
100% Functions 28/28
96.97% Lines 384/396
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516   324× 324×   616× 308×   308×   324× 324×   308× 308×   473× 473× 473×   19× 19×   19× 19×             6550×   473× 473× 473×     19× 19× 19× 19× 19× 18× 18× 18× 18× 18×   18×   18× 18×     18× 18× 18× 18× 18× 18× 18×     17×   18× 18× 18× 18× 18× 18× 18× 18× 18×                 17× 17× 17× 17× 17×   17× 17× 17× 17× 17× 17× 17×     37× 37× 37× 37× 37× 37× 37× 37× 37× 37× 37× 37×   37×         34×     27× 27×   37× 37×   37× 37× 37× 33× 33× 33× 33× 33×   37×     37× 37× 37× 37× 37×   37× 37× 37× 37× 37× 37× 37× 37×   37×     37× 37×     37× 37× 37× 37× 19×   37×             37×   38× 38× 38× 38× 38× 38× 38×         38× 38× 38×                                                 18× 18×           38× 38× 38× 38× 38×   38× 38× 38×   38×         37×     37×     18× 18× 18× 18× 18× 18× 18×   12× 12× 10×             10× 10× 10× 10× 10× 10× 10×         21× 21× 21× 21× 21× 21×   10× 10× 10×                     10×   10× 10× 10× 10×   10× 10× 10×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-popups"], function (require, exports, ej2_base_1, ej2_popups_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var Export = (function () {
        function Export(parent) {
            this.parent = parent;
            this.addEventListener();
        }
        Export.prototype.destroy = function () {
            if (this.parent.isDestroyed) {
                return;
            }
            this.removeEventListener();
        };
        Export.prototype.addEventListener = function () {
            this.parent.on('export', this.export, this);
            this.parent.on('destroyed', this.destroy, this);
        };
        Export.prototype.removeEventListener = function () {
            this.parent.off('export', this.export);
            this.parent.off('destroyed', this.destroy);
        };
        Export.prototype.export = function (args) {
            this.parent.notify('toolbar', { prop: 'refreshShapeDrawing', onPropertyChange: false });
            this.updatePvtVar();
            switch (args.prop) {
                case 'export':
                    this.exportImg(args.value['type'], args.value['fileName'], args.value['imgQuality']);
                    break;
                case 'exportToCanvas':
                    this.exportToCanvas(args.value['object']);
                    break;
                case 'updateSaveContext':
                    this.updateSaveContext(args.value['context']);
                    break;
                case 'setImageQuality':
                    this.imageQuality = args.value['value'];
                    break;
                case 'drawAnnotation':
                    this.drawAnnotation(args.value['context'], args.value['ratio']);
                    break;
                case 'downScaleImgCanvas':
                    this.downScaleImgCanvas(args.value['canvas'], args.value['width'], args.value['height']);
                    break;
            }
        };
        Export.prototype.getModuleName = function () {
            return 'export';
        };
        Export.prototype.updatePvtVar = function () {
            var parent = this.parent;
            Eif (parent.lowerCanvas) {
                this.lowerContext = parent.lowerCanvas.getContext('2d');
            }
        };
        Export.prototype.exportImg = function (type, fileName, imgQuality) {
            var parent = this.parent;
            var obj = { fileName: '' };
            parent.notify('draw', { prop: 'getFileName', onPropertyChange: false, value: { obj: obj } });
            var imageName = obj['fileName'];
            if (!parent.disabled && parent.isImageLoaded) {
                parent.notify('shape', { prop: 'applyActObj', onPropertyChange: false, value: { isMouseDown: null } });
                var obj_1 = { canvasFilter: this.parent.canvasFilter };
                this.lowerContext.filter = obj_1['canvasFilter'];
                type = type ? type : 'Png';
                parent.notify('shape', { prop: 'redrawActObj', onPropertyChange: false,
                    value: { x: null, y: null, isMouseDown: null } });
                var beforeSave = { cancel: false, fileName: fileName ? fileName : imageName,
                    fileType: type, imageQuality: imgQuality };
                parent.trigger('beforeSave', beforeSave);
                this.beforeSaveEvent(beforeSave, type, fileName, imageName, imgQuality);
            }
        };
        Export.prototype.beforeSaveEvent = function (observableSaveArgs, type, fileName, imageName, imgQuality) {
            var parent = this.parent;
            Eif (!observableSaveArgs.cancel) {
                parent.currObjType.isSave = true;
                fileName = observableSaveArgs.fileName ? observableSaveArgs.fileName : fileName;
                var lowerCaseType = type.toLowerCase();
                fileName = fileName || imageName;
                if (lowerCaseType === 'svg') {
                    this.toSVGImg(fileName);
                }
                else {
                    this.toBlobFn(fileName, lowerCaseType, observableSaveArgs.imageQuality || imgQuality);
                }
                var saved = { fileName: fileName ? fileName : imageName, fileType: type };
                parent.trigger('saved', saved);
                var actionArgs = { action: 'save', actionEventArgs: saved };
                parent.triggerEditCompleteEvent(actionArgs);
                parent.notify('toolbar', { prop: 'refresh-main-toolbar', onPropertyChange: false });
                parent.lowerCanvas.style.left = parent.upperCanvas.style.left = '';
                parent.lowerCanvas.style.top = parent.upperCanvas.style.top = '';
                parent.lowerCanvas.style.maxWidth = parent.upperCanvas.style.maxWidth = '';
                parent.lowerCanvas.style.maxHeight = parent.upperCanvas.style.maxHeight = '';
            }
        };
        Export.prototype.toSVGImg = function (fileName) {
            var parent = this.parent;
            ej2_popups_1.showSpinner(parent.element);
            parent.element.style.opacity = '0.5';
            var tempCanvas = this.exportToCanvas();
            var dataUrl = tempCanvas.toDataURL();
            ej2_popups_1.hideSpinner(parent.element);
            parent.element.style.opacity = '1';
            var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
            svg.setAttribute('width', tempCanvas.style.maxWidth);
            svg.setAttribute('height', tempCanvas.style.maxHeight);
            var XLinkNS = 'http://www.w3.org/1999/xlink';
            var img = document.createElementNS('http://www.w3.org/2000/svg', 'image');
            img.setAttributeNS(null, 'height', tempCanvas.height.toString());
            img.setAttributeNS(null, 'width', tempCanvas.width.toString());
            img.setAttributeNS(XLinkNS, 'xlink:href', dataUrl);
            svg.appendChild(img);
            var prefix = 'data:image/svg+xml;base64,';
            var header = '<svg' + ' xmlns="http://www.w3.org/2000/svg"' + ' xmlns:xlink="http://www.w3.org/1999/xlink"'
                + (" width=\"" + tempCanvas.width + "\"") + (" height=\"" + tempCanvas.height + "\"") + '>';
            var footer = '</svg>';
            var body = svg.innerHTML;
            var data = header + body + footer;
            var svgDataUrl = prefix + btoa(data);
            Iif (fileName === null) {
                return svgDataUrl;
            }
            else {
                this.downloadImg(svgDataUrl, fileName + '.' + 'svg');
                return null;
            }
        };
        Export.prototype.toBlobFn = function (fileName, type, imgQuality) {
            var proxy = this;
            var parent = this.parent;
            ej2_popups_1.showSpinner(parent.element);
            parent.element.style.opacity = '0.5';
            if (!ej2_base_1.isNullOrUndefined(imgQuality)) {
                imgQuality = imgQuality > 1 ? 1 : (imgQuality <= 0 ? 0.01 : imgQuality);
                this.imageQuality = imgQuality ? imgQuality : null;
            }
            var tempCanvas = this.exportToCanvas();
            var imagetype = (type === 'jpeg' ? 'image/jpeg' : (type === 'webp' ? 'image/webp' : 'image/png'));
            tempCanvas.toBlob(function (blob) {
                var blobUrl = URL.createObjectURL(blob);
                proxy.downloadImg(blobUrl, fileName + '.' + type);
                ej2_popups_1.hideSpinner(parent.element);
                parent.element.style.opacity = '1';
            }, imagetype, this.imageQuality ? this.imageQuality : null);
        };
        Export.prototype.exportToCanvas = function (object) {
            var parent = this.parent;
            var width;
            var height;
            var tempCropObj = ej2_base_1.extend({}, parent.cropObj, {}, true);
            var tempObj = { currObj: {} };
            parent.notify('filter', { prop: 'getCurrentObj', onPropertyChange: false, value: { object: tempObj } });
            var prevObj = tempObj['currObj'];
            prevObj.objColl = ej2_base_1.extend([], parent.objColl, [], true);
            prevObj.pointColl = ej2_base_1.extend([], parent.pointColl, [], true);
            prevObj.afterCropActions = ej2_base_1.extend([], parent.afterCropActions, [], true);
            var selPointCollObj = { selPointColl: null };
            parent.notify('freehand-draw', { prop: 'getSelPointColl', onPropertyChange: false,
                value: { obj: selPointCollObj } });
            if (this.parent.aspectWidth) {
                parent.notify('undo-redo', { prop: 'setPreventUR', value: { bool: true } });
                parent.notify('toolbar', { prop: 'resizeClick', value: { bool: false } });
                parent.okBtn();
                if (parent.transform.degree % 90 === 0 && parent.transform.degree % 180 !== 0) {
                    width = this.parent.aspectHeight;
                    height = this.parent.aspectWidth;
                }
                else {
                    width = this.parent.aspectWidth;
                    height = this.parent.aspectHeight;
                }
                parent.notify('undo-redo', { prop: 'setPreventUR', value: { bool: false } });
            }
            else if (parent.currSelectionPoint) {
                width = parent.img.srcWidth;
                height = parent.img.srcHeight;
            }
            else {
                width = parent.baseImgCanvas.width;
                height = parent.baseImgCanvas.height;
            }
            var obj = { width: 0, height: 0 };
            parent.notify('crop', { prop: 'calcRatio', onPropertyChange: false,
                value: { obj: obj, dimension: { width: width, height: height } } });
            var ratio = obj;
            var tempContextFilter = this.lowerContext.filter;
            if (this.lowerContext.filter !== 'none') {
                var splitWords = this.lowerContext.filter.split(' ');
                var value = parseFloat(splitWords[5].split('(')[1]);
                value *= ((ratio.width + ratio.height) / 2);
                splitWords[5] = 'blur(' + value + 'px)';
                this.lowerContext.filter = splitWords.join(' ');
            }
            var tempCanvas = parent.createElement('canvas', {
                id: parent.element.id + '_tempCanvas', attrs: { name: 'canvasImage' }
            });
            var tempContext = tempCanvas.getContext('2d');
            tempCanvas.width = width;
            tempCanvas.height = height;
            var dimObj = { width: 0, height: 0 };
            parent.notify('transform', { prop: 'calcMaxDimension', onPropertyChange: false,
                value: { width: width, height: height, obj: dimObj } });
            var maxDimension = dimObj;
            tempCanvas.style.maxWidth = maxDimension.width + 'px';
            tempCanvas.style.maxHeight = maxDimension.height + 'px';
            var temp = this.lowerContext.filter;
            tempContext.filter = this.lowerContext.filter;
            this.downScaleImgCanvas(tempContext, width, height);
            this.lowerContext.filter = temp;
            if (parent.transform.degree !== 0 || parent.transform.currFlipState !== '' || parent.transform.straighten !== 0) {
                this.updateSaveContext(tempContext);
                this.exportTransformedImage(tempContext);
            }
            Iif (parent.isSafari) {
                parent.notify('filter', { prop: 'apply-filter', onPropertyChange: false, value: { context: tempContext } });
            }
            this.drawAnnotation(tempContext, ratio);
            if (parent.isCircleCrop) {
                parent.notify('crop', { prop: 'cropCircle', onPropertyChange: false,
                    value: { context: tempContext, isSave: true, isFlip: null } });
            }
            this.updateFrame(tempContext, true);
            this.lowerContext.filter = tempContextFilter;
            parent.canvasFilter = tempContextFilter;
            if (object) {
                object['canvas'] = tempCanvas;
            }
            if (parent.aspectWidth) {
                parent.objColl = [];
                parent.pointColl = [];
                parent.freehandCounter = 0;
                parent.notify('freehand-draw', { prop: 'setSelPointColl', onPropertyChange: false,
                    value: { obj: { selPointColl: [] } } });
                parent.notify('draw', { prop: 'setCurrentObj', onPropertyChange: false, value: { obj: prevObj } });
                prevObj.selPointColl = ej2_base_1.extend([], selPointCollObj['selPointColl'], [], true);
                parent.notify('freehand-draw', { prop: 'setSelPointColl', onPropertyChange: false,
                    value: { obj: { selPointColl: prevObj.selPointColl } } });
                parent.cropObj = tempCropObj;
                parent.objColl = ej2_base_1.extend([], prevObj.objColl, [], true);
                parent.pointColl = ej2_base_1.extend([], prevObj.pointColl, [], true);
                parent.freehandCounter = parent.pointColl.length;
                parent.transform.straighten = 0;
                this.lowerContext.filter = 'none';
                parent.notify('shape', { prop: 'drawAnnotations', onPropertyChange: false,
                    value: { ctx: this.lowerContext, shape: 'zoom', pen: 'zoom', isPreventApply: null } });
                this.lowerContext.filter = prevObj.filter;
                parent.notify('draw', { prop: 'clearOuterCanvas', onPropertyChange: false, value: { context: this.lowerContext } });
                if (parent.isCircleCrop || (parent.currSelectionPoint && parent.currSelectionPoint.shape === 'crop-circle')) {
                    parent.notify('crop', { prop: 'cropCircle', onPropertyChange: false,
                        value: { context: this.lowerContext, isSave: null, isFlip: null } });
                }
            }
            return tempCanvas;
        };
        Export.prototype.drawAnnotation = function (tempContext, ratio) {
            var parent = this.parent;
            var tempObjColl = ej2_base_1.extend([], parent.objColl, [], true);
            var tempPointColl = ej2_base_1.extend([], parent.pointColl, [], true);
            var nonRedact = parent.shapeColl.filter(function (item) { return item.shape !== 'redact'; });
            var redact = parent.shapeColl.filter(function (item) { return item.shape === 'redact'; });
            parent.shapeColl = redact.concat(nonRedact);
            for (var i = 0; i < parent.shapeColl.length; i++) {
                Eif (parent.shapeColl[i].order) {
                    if (parent.shapeColl[i].currIndex && parent.shapeColl[i].currIndex.indexOf('shape') > -1) {
                        parent.objColl = [];
                        parent.objColl.push(ej2_base_1.extend({}, parent.shapeColl[i], {}, true));
                        this.drawShape(tempContext, ratio);
                    }
                    else Eif (parent.shapeColl[i].id && parent.shapeColl[i].id.indexOf('pen') > -1) {
                        parent.pointColl = [];
                        parent.freehandCounter = 0;
                        parent.pointColl.push(ej2_base_1.extend({}, parent.shapeColl[i], {}, true));
                        parent.freehandCounter = parent.pointColl.length;
                        this.drawPen(tempContext, ratio);
                    }
                }
            }
            parent.objColl = tempObjColl;
            parent.pointColl = tempPointColl;
            parent.freehandCounter = parent.pointColl.length;
        };
        Export.prototype.drawShape = function (tempContext, ratio) {
            var parent = this.parent;
            Eif (parent.objColl.length > 0) {
                var temp = tempContext.filter;
                tempContext.filter = 'none';
                var indexObj = { index: null };
                parent.notify('shape', { prop: 'getSmallestIndex', onPropertyChange: false, value: { obj: indexObj } });
                var index = indexObj['index'];
                var objColl = ej2_base_1.extend([], parent.objColl, [], true);
                var tempObjColl = ej2_base_1.extend([], parent.objColl, [], true);
                while (objColl.length > 0) {
                    var found = false;
                    for (var i = 0; i < objColl.length; i++) {
                        var currentObj = objColl[i];
                        Iif (ej2_base_1.isNullOrUndefined(currentObj.order)) {
                            objColl.splice(i, 1);
                            i--;
                            continue;
                        }
                        Eif (currentObj.order === index) {
                            var temp_1 = tempContext.filter;
                            tempContext.filter = 'none';
                            var currObj = objColl[i];
                            var activePoint = currObj.activePoint;
                            activePoint.startX -= parent.img.destLeft;
                            activePoint.startY -= parent.img.destTop;
                            activePoint.endX -= parent.img.destLeft;
                            activePoint.endY -= parent.img.destTop;
                            activePoint.width = activePoint.endX - activePoint.startX;
                            activePoint.height = activePoint.endY - activePoint.startY;
                            activePoint.startX *= ratio.width;
                            activePoint.startY *= ratio.height;
                            activePoint.endX *= ratio.width;
                            activePoint.endY *= ratio.height;
                            activePoint.width = activePoint.endX - activePoint.startX;
                            activePoint.height = activePoint.endY - activePoint.startY;
                            currObj.strokeSettings.strokeWidth *= ((ratio.width + ratio.height) / 2);
                            Iif (currObj.shape === 'text') {
                                currObj.textSettings.fontSize *= ((ratio.width + ratio.height) / 2);
                            }
                            else if (currObj.shape === 'path') {
                                for (var l = 0; l < currObj.pointColl.length; l++) {
                                    currObj.pointColl[l].x =
                                        (currObj.pointColl[l].x - parent.img.destLeft) * ratio.width;
                                    currObj.pointColl[l].y =
                                        (currObj.pointColl[l].y - parent.img.destTop) * ratio.height;
                                }
                            }
                            else Iif (currObj.shape === 'image') {
                                parent.activeObj = ej2_base_1.extend({}, objColl[i], {}, true);
                                parent.notify('selection', { prop: 'upgradeImageQuality', onPropertyChange: false });
                                objColl[i] = ej2_base_1.extend({}, parent.activeObj, {}, true);
                            }
                            parent.notify('draw', { prop: 'drawObject', onPropertyChange: false, value: { canvas: 'saveContext', obj: objColl[i], isCropRatio: null,
                                    points: null, isPreventDrag: true, saveContext: tempContext, isPreventSelection: null } });
                            tempContext.filter = temp_1;
                            parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
                            index++;
                            var indexBool = { bool: false };
                            parent.notify('shape', { prop: 'isIndexInObjColl', onPropertyChange: false, value: { obj: indexBool, index: index } });
                            Eif (!indexBool['bool']) {
                                index++;
                            }
                            objColl.splice(i, 1);
                            found = true;
                            break;
                        }
                    }
                    Iif (!found) {
                        break;
                    }
                }
                tempContext.filter = temp;
                parent.notify('shape', { prop: 'refreshActiveObj', onPropertyChange: false });
                parent.objColl = tempObjColl;
            }
        };
        Export.prototype.drawPen = function (tempContext, ratio) {
            var parent = this.parent;
            Eif (parent.freehandCounter > 0) {
                var widthObj = { penStrokeWidth: null };
                parent.notify('freehand-draw', { prop: 'getPenStrokeWidth', onPropertyChange: false, value: { obj: widthObj } });
                var tempPointColl = ej2_base_1.extend({}, parent.pointColl, {}, true);
                for (var n = 0; n < parent.freehandCounter; n++) {
                    parent.points = ej2_base_1.extend([], parent.pointColl[n].points, []);
                    parent.notify('freehand-draw', { prop: 'setPointCounter', onPropertyChange: false, value: { value: 0 } });
                    var len = parent.points.length;
                    parent.pointColl[n].strokeWidth *= ((ratio.width + ratio.height) / 2);
                    for (var l = 0; l < len; l++) {
                        parent.points[l].x = (parent.points[l].x - parent.img.destLeft) * ratio.width;
                        parent.points[l].y = (parent.points[l].y - parent.img.destTop) * ratio.height;
                    }
                }
                parent.notify('freehand-draw', { prop: 'freehandRedraw', onPropertyChange: false,
                    value: { context: tempContext, points: null } });
                parent.pointColl = tempPointColl;
                parent.notify('freehand-draw', { prop: 'setPenStrokeWidth', onPropertyChange: false, value: { value: widthObj['penStrokeWidth'] } });
            }
        };
        Export.prototype.downScaleImgCanvas = function (ctx, width, height) {
            var parent = this.parent;
            var canvas = parent.baseImgCanvas;
            var img = parent.baseImg;
            var obj = { width: 0, height: 0 };
            parent.notify('transform', { prop: 'calcMaxDimension', onPropertyChange: false,
                value: { width: img.width, height: img.height, obj: obj, isImgShape: null } });
            var bgObj = { color: null };
            parent.notify('draw', { prop: 'getImageBackgroundColor', value: { obj: bgObj } });
            if (bgObj['color'] !== '') {
                ctx.fillStyle = bgObj['color'];
                ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
            }
            if (obj['width'] > width && obj['height'] > height) {
                var tempCanvas = parent.createElement('canvas', {
                    id: parent.element.id + '_downScaleCanvas', attrs: { name: 'canvasImage' }
                });
                tempCanvas.width = this.parent.img.srcWidth;
                tempCanvas.height = this.parent.img.srcHeight;
                tempCanvas.getContext('2d').drawImage(canvas, parent.img.srcLeft, parent.img.srcTop, parent.img.srcWidth, parent.img.srcHeight, 0, 0, tempCanvas.width, tempCanvas.height);
                parent.notify('draw', { prop: 'downScale', value: { canvas: tempCanvas, width: width, height: height } });
                ctx.drawImage(tempCanvas, 0, 0);
            }
            else {
                ctx.drawImage(parent.baseImgCanvas, parent.img.srcLeft, parent.img.srcTop, parent.img.srcWidth, parent.img.srcHeight, 0, 0, width, height);
            }
        };
        Export.prototype.updateFrame = function (tempContext, isAnnotation) {
            if (this.parent.frameObj.type !== 'none') {
                var temp = tempContext.filter;
                tempContext.filter = 'none';
                this.parent.notify('draw', { prop: 'applyFrame', value: { ctx: tempContext, frame: this.parent.frameObj.type, preventImg: isAnnotation } });
                tempContext.filter = temp;
            }
        };
        Export.prototype.downloadImg = function (blob, fileName) {
            var a = document.createElement('a');
            a.href = blob;
            a.target = '_parent';
            a.download = fileName;
            (document.body || document.documentElement).appendChild(a);
            a.click();
            a.parentNode.removeChild(a);
        };
        Export.prototype.exportTransformedImage = function (tempContext) {
            var parent = this.parent;
            var degree = parent.transform.degree;
            Eif (parent.rotateFlipColl.length > 0) {
                for (var i = 0, len = parent.rotateFlipColl.length; i < len; i++) {
                    var flip = parent.rotateFlipColl[i];
                    if (typeof flip === 'number') {
                        this.exportRotate(tempContext, flip);
                    }
                    else if (flip === 'horizontal') {
                        this.exportFlip(tempContext, true, false);
                    }
                    else Eif (flip === 'vertical') {
                        this.exportFlip(tempContext, false, true);
                    }
                }
            }
            parent.transform.degree = degree;
        };
        Export.prototype.exportRotate = function (tempContext, degree) {
            var parent = this.parent;
            tempContext.clearRect(0, 0, tempContext.canvas.width, tempContext.canvas.height);
            this.setMaxDim(parent.transform.degree, tempContext.canvas);
            tempContext.translate(tempContext.canvas.width / 2, tempContext.canvas.height / 2);
            tempContext.rotate(Math.PI / 180 * degree);
            tempContext.drawImage(parent.inMemoryCanvas, -tempContext.canvas.height / 2, -tempContext.canvas.width / 2, tempContext.canvas.height, tempContext.canvas.width);
            this.updateSaveContext(tempContext);
        };
        Export.prototype.exportFlip = function (tempContext, flipHorizontal, flipVertical) {
            tempContext.clearRect(0, 0, tempContext.canvas.width, tempContext.canvas.height);
            if (flipHorizontal) {
                tempContext.translate(tempContext.canvas.width, 0);
                tempContext.scale(-1, 1);
            }
            if (flipVertical) {
                tempContext.translate(0, tempContext.canvas.height);
                tempContext.scale(1, -1);
            }
            tempContext.drawImage(this.parent.inMemoryCanvas, 0, 0);
            this.updateSaveContext(tempContext);
        };
        Export.prototype.updateSaveContext = function (tempContext) {
            var inMemoryContext = this.parent.inMemoryCanvas.getContext('2d');
            tempContext.setTransform(1, 0, 0, 1, 0, 0);
            var imageData = tempContext.getImageData(0, 0, tempContext.canvas.width, tempContext.canvas.height);
            this.parent.inMemoryCanvas.width = imageData.width;
            this.parent.inMemoryCanvas.height = imageData.height;
            inMemoryContext.putImageData(imageData, 0, 0);
        };
        Export.prototype.setMaxDim = function (degree, tempCanvas) {
            var newWidth;
            var newHeight;
            if (degree % 90 === 0 && degree % 180 !== 0) {
                if (ej2_base_1.isNullOrUndefined(this.parent.currSelectionPoint)) {
                    newWidth = this.parent.baseImgCanvas.height;
                    newHeight = this.parent.baseImgCanvas.width;
                }
                else {
                    newWidth = this.parent.img.srcHeight;
                    newHeight = this.parent.img.srcWidth;
                }
            }
            else Eif (degree % 180 === 0 || degree === 0) {
                Iif (ej2_base_1.isNullOrUndefined(this.parent.currSelectionPoint)) {
                    newWidth = this.parent.baseImgCanvas.width;
                    newHeight = this.parent.baseImgCanvas.height;
                }
                else {
                    newWidth = this.parent.img.srcWidth;
                    newHeight = this.parent.img.srcHeight;
                }
            }
            if (!ej2_base_1.isNullOrUndefined(this.parent.aspectWidth)) {
                newWidth = this.parent.aspectWidth;
                newHeight = this.parent.aspectHeight;
            }
            tempCanvas.width = newWidth;
            tempCanvas.height = newHeight;
            var obj = { width: 0, height: 0 };
            this.parent.notify('transform', { prop: 'calcMaxDimension', onPropertyChange: false,
                value: { width: newWidth, height: newHeight, obj: obj, isImgShape: null } });
            var maxDimension = obj;
            tempCanvas.style.maxWidth = maxDimension.width + 'px';
            tempCanvas.style.maxHeight = maxDimension.height + 'px';
        };
        return Export;
    }());
    exports.Export = Export;
});