0bf002e1dbc444f5e267c1479831daf5.json
46.3 KB
{"ast":null,"code":"import { extend } from 'tui-code-snippet';\nimport { isSupportFileApi, base64ToBlob, toInteger } from './util';\nimport Imagetracer from './helper/imagetracer';\nexport default {\n /**\r\n * Get ui actions\r\n * @returns {Object} actions for ui\r\n * @private\r\n */\n getActions() {\n return {\n main: this._mainAction(),\n shape: this._shapeAction(),\n crop: this._cropAction(),\n flip: this._flipAction(),\n rotate: this._rotateAction(),\n text: this._textAction(),\n mask: this._maskAction(),\n draw: this._drawAction(),\n icon: this._iconAction(),\n filter: this._filterAction()\n };\n },\n\n /**\r\n * Main Action\r\n * @returns {Object} actions for ui main\r\n * @private\r\n */\n _mainAction() {\n const exitCropOnAction = () => {\n if (this.ui.submenu === 'crop') {\n this.stopDrawingMode();\n this.ui.changeMenu('crop');\n }\n };\n\n const setAngleRangeBarOnAction = angle => {\n if (this.ui.submenu === 'rotate') {\n this.ui.rotate.setRangeBarAngle('setAngle', angle);\n }\n };\n\n const setFilterStateRangeBarOnAction = filterOptions => {\n if (this.ui.submenu === 'filter') {\n this.ui.filter.setFilterState(filterOptions);\n }\n };\n\n const onEndUndoRedo = result => {\n setAngleRangeBarOnAction(result);\n setFilterStateRangeBarOnAction(result);\n return result;\n };\n\n return extend({\n initLoadImage: (imagePath, imageName) => this.loadImageFromURL(imagePath, imageName).then(sizeValue => {\n exitCropOnAction();\n this.ui.initializeImgUrl = imagePath;\n this.ui.resizeEditor({\n imageSize: sizeValue\n });\n this.clearUndoStack();\n }),\n undo: () => {\n if (!this.isEmptyUndoStack()) {\n exitCropOnAction();\n this.deactivateAll();\n this.undo().then(onEndUndoRedo);\n }\n },\n redo: () => {\n if (!this.isEmptyRedoStack()) {\n exitCropOnAction();\n this.deactivateAll();\n this.redo().then(onEndUndoRedo);\n }\n },\n reset: () => {\n exitCropOnAction();\n this.loadImageFromURL(this.ui.initializeImgUrl, 'resetImage').then(sizeValue => {\n exitCropOnAction();\n this.ui.resizeEditor({\n imageSize: sizeValue\n });\n this.clearUndoStack();\n });\n },\n delete: () => {\n this.ui.changeHelpButtonEnabled('delete', false);\n exitCropOnAction();\n this.removeActiveObject();\n this.activeObjectId = null;\n },\n deleteAll: () => {\n exitCropOnAction();\n this.clearObjects();\n this.ui.changeHelpButtonEnabled('delete', false);\n this.ui.changeHelpButtonEnabled('deleteAll', false);\n },\n load: file => {\n if (!isSupportFileApi()) {\n alert('This browser does not support file-api');\n }\n\n this.ui.initializeImgUrl = URL.createObjectURL(file);\n this.loadImageFromFile(file).then(sizeValue => {\n exitCropOnAction();\n this.clearUndoStack();\n this.ui.activeMenuEvent();\n this.ui.resizeEditor({\n imageSize: sizeValue\n });\n })['catch'](message => Promise.reject(message));\n },\n download: () => {\n const dataURL = this.toDataURL();\n let imageName = this.getImageName();\n let blob, type, w;\n\n if (isSupportFileApi() && window.saveAs) {\n blob = base64ToBlob(dataURL);\n type = blob.type.split('/')[1];\n\n if (imageName.split('.').pop() !== type) {\n imageName += `.${type}`;\n }\n\n saveAs(blob, imageName); // eslint-disable-line\n } else {\n w = window.open();\n w.document.body.innerHTML = `<img src='${dataURL}'>`;\n }\n }\n }, this._commonAction());\n },\n\n /**\r\n * Icon Action\r\n * @returns {Object} actions for ui icon\r\n * @private\r\n */\n _iconAction() {\n return extend({\n changeColor: color => {\n if (this.activeObjectId) {\n this.changeIconColor(this.activeObjectId, color);\n }\n },\n addIcon: (iconType, iconColor) => {\n this.startDrawingMode('ICON');\n this.setDrawingIcon(iconType, iconColor);\n },\n cancelAddIcon: () => {\n this.ui.icon.clearIconType();\n this.changeSelectableAll(true);\n this.changeCursor('default');\n this.stopDrawingMode();\n },\n registDefalutIcons: (type, path) => {\n const iconObj = {};\n iconObj[type] = path;\n this.registerIcons(iconObj);\n },\n registCustomIcon: (imgUrl, file) => {\n const imagetracer = new Imagetracer();\n imagetracer.imageToSVG(imgUrl, svgstr => {\n const [, svgPath] = svgstr.match(/path[^>]*d=\"([^\"]*)\"/);\n const iconObj = {};\n iconObj[file.name] = svgPath;\n this.registerIcons(iconObj);\n this.addIcon(file.name, {\n left: 100,\n top: 100\n });\n }, Imagetracer.tracerDefaultOption());\n }\n }, this._commonAction());\n },\n\n /**\r\n * Draw Action\r\n * @returns {Object} actions for ui draw\r\n * @private\r\n */\n _drawAction() {\n return extend({\n setDrawMode: (type, settings) => {\n this.stopDrawingMode();\n\n if (type === 'free') {\n this.startDrawingMode('FREE_DRAWING', settings);\n } else {\n this.startDrawingMode('LINE_DRAWING', settings);\n }\n },\n setColor: color => {\n this.setBrush({\n color\n });\n }\n }, this._commonAction());\n },\n\n /**\r\n * Mask Action\r\n * @returns {Object} actions for ui mask\r\n * @private\r\n */\n _maskAction() {\n return extend({\n loadImageFromURL: (imgUrl, file) => this.loadImageFromURL(this.toDataURL(), 'FilterImage').then(() => {\n this.addImageObject(imgUrl).then(() => {\n URL.revokeObjectURL(file);\n });\n }),\n applyFilter: () => {\n this.applyFilter('mask', {\n maskObjId: this.activeObjectId\n });\n }\n }, this._commonAction());\n },\n\n /**\r\n * Text Action\r\n * @returns {Object} actions for ui text\r\n * @private\r\n */\n _textAction() {\n return extend({\n changeTextStyle: (styleObj, isSilent) => {\n if (this.activeObjectId) {\n this.changeTextStyle(this.activeObjectId, styleObj, isSilent);\n }\n }\n }, this._commonAction());\n },\n\n /**\r\n * Rotate Action\r\n * @returns {Object} actions for ui rotate\r\n * @private\r\n */\n _rotateAction() {\n return extend({\n rotate: (angle, isSilent) => {\n this.rotate(angle, isSilent);\n this.ui.resizeEditor();\n this.ui.rotate.setRangeBarAngle('rotate', angle);\n },\n setAngle: (angle, isSilent) => {\n this.setAngle(angle, isSilent);\n this.ui.resizeEditor();\n this.ui.rotate.setRangeBarAngle('setAngle', angle);\n }\n }, this._commonAction());\n },\n\n /**\r\n * Shape Action\r\n * @returns {Object} actions for ui shape\r\n * @private\r\n */\n _shapeAction() {\n return extend({\n changeShape: (changeShapeObject, isSilent) => {\n if (this.activeObjectId) {\n this.changeShape(this.activeObjectId, changeShapeObject, isSilent);\n }\n },\n setDrawingShape: shapeType => {\n this.setDrawingShape(shapeType);\n }\n }, this._commonAction());\n },\n\n /**\r\n * Crop Action\r\n * @returns {Object} actions for ui crop\r\n * @private\r\n */\n _cropAction() {\n return extend({\n crop: () => {\n const cropRect = this.getCropzoneRect();\n\n if (cropRect) {\n this.crop(cropRect).then(() => {\n this.stopDrawingMode();\n this.ui.resizeEditor();\n this.ui.changeMenu('crop');\n })['catch'](message => Promise.reject(message));\n }\n },\n cancel: () => {\n this.stopDrawingMode();\n this.ui.changeMenu('crop');\n },\n\n /* eslint-disable */\n preset: presetType => {\n switch (presetType) {\n case 'preset-square':\n this.setCropzoneRect(1 / 1);\n break;\n\n case 'preset-3-2':\n this.setCropzoneRect(3 / 2);\n break;\n\n case 'preset-4-3':\n this.setCropzoneRect(4 / 3);\n break;\n\n case 'preset-5-4':\n this.setCropzoneRect(5 / 4);\n break;\n\n case 'preset-7-5':\n this.setCropzoneRect(7 / 5);\n break;\n\n case 'preset-16-9':\n this.setCropzoneRect(16 / 9);\n break;\n\n default:\n this.setCropzoneRect();\n this.ui.crop.changeApplyButtonStatus(false);\n break;\n }\n }\n }, this._commonAction());\n },\n\n /**\r\n * Flip Action\r\n * @returns {Object} actions for ui flip\r\n * @private\r\n */\n _flipAction() {\n return extend({\n flip: flipType => this[flipType]()\n }, this._commonAction());\n },\n\n /**\r\n * Filter Action\r\n * @returns {Object} actions for ui filter\r\n * @private\r\n */\n _filterAction() {\n return extend({\n applyFilter: (applying, type, options, isSilent) => {\n if (applying) {\n this.applyFilter(type, options, isSilent);\n } else if (this.hasFilter(type)) {\n this.removeFilter(type);\n }\n }\n }, this._commonAction());\n },\n\n /**\r\n * Image Editor Event Observer\r\n */\n setReAction() {\n this.on({\n undoStackChanged: length => {\n if (length) {\n this.ui.changeHelpButtonEnabled('undo', true);\n this.ui.changeHelpButtonEnabled('reset', true);\n } else {\n this.ui.changeHelpButtonEnabled('undo', false);\n this.ui.changeHelpButtonEnabled('reset', false);\n }\n\n this.ui.resizeEditor();\n },\n redoStackChanged: length => {\n if (length) {\n this.ui.changeHelpButtonEnabled('redo', true);\n } else {\n this.ui.changeHelpButtonEnabled('redo', false);\n }\n\n this.ui.resizeEditor();\n },\n\n /* eslint-disable complexity */\n objectActivated: obj => {\n this.activeObjectId = obj.id;\n this.ui.changeHelpButtonEnabled('delete', true);\n this.ui.changeHelpButtonEnabled('deleteAll', true);\n\n if (obj.type === 'cropzone') {\n this.ui.crop.changeApplyButtonStatus(true);\n } else if (['rect', 'circle', 'triangle'].indexOf(obj.type) > -1) {\n this.stopDrawingMode();\n\n if (this.ui.submenu !== 'shape') {\n this.ui.changeMenu('shape', false, false);\n }\n\n this.ui.shape.setShapeStatus({\n strokeColor: obj.stroke,\n strokeWidth: obj.strokeWidth,\n fillColor: obj.fill\n });\n this.ui.shape.setMaxStrokeValue(Math.min(obj.width, obj.height));\n } else if (obj.type === 'path' || obj.type === 'line') {\n if (this.ui.submenu !== 'draw') {\n this.ui.changeMenu('draw', false, false);\n this.ui.draw.changeStandbyMode();\n }\n } else if (['i-text', 'text'].indexOf(obj.type) > -1) {\n if (this.ui.submenu !== 'text') {\n this.ui.changeMenu('text', false, false);\n }\n\n this.ui.text.setTextStyleStateOnAction(obj);\n } else if (obj.type === 'icon') {\n this.stopDrawingMode();\n\n if (this.ui.submenu !== 'icon') {\n this.ui.changeMenu('icon', false, false);\n }\n\n this.ui.icon.setIconPickerColor(obj.fill);\n }\n },\n\n /* eslint-enable complexity */\n addText: pos => {\n const {\n textColor: fill,\n fontSize,\n fontStyle,\n fontWeight,\n underline\n } = this.ui.text;\n const fontFamily = 'Noto Sans';\n this.addText('Double Click', {\n position: pos.originPosition,\n styles: {\n fill,\n fontSize,\n fontFamily,\n fontStyle,\n fontWeight,\n underline\n }\n }).then(() => {\n this.changeCursor('default');\n });\n },\n addObjectAfter: obj => {\n if (obj.type === 'icon') {\n this.ui.icon.changeStandbyMode();\n } else if (['rect', 'circle', 'triangle'].indexOf(obj.type) > -1) {\n this.ui.shape.setMaxStrokeValue(Math.min(obj.width, obj.height));\n this.ui.shape.changeStandbyMode();\n }\n },\n objectScaled: obj => {\n if (['i-text', 'text'].indexOf(obj.type) > -1) {\n this.ui.text.fontSize = toInteger(obj.fontSize);\n } else if (['rect', 'circle', 'triangle'].indexOf(obj.type) >= 0) {\n const {\n width,\n height\n } = obj;\n const strokeValue = this.ui.shape.getStrokeValue();\n\n if (width < strokeValue) {\n this.ui.shape.setStrokeValue(width);\n }\n\n if (height < strokeValue) {\n this.ui.shape.setStrokeValue(height);\n }\n }\n },\n selectionCleared: () => {\n this.activeObjectId = null;\n\n if (this.ui.submenu === 'text') {\n this.changeCursor('text');\n } else if (this.ui.submenu !== 'draw' && this.ui.submenu !== 'crop') {\n this.stopDrawingMode();\n }\n }\n });\n },\n\n /**\r\n * Common Action\r\n * @returns {Object} common actions for ui\r\n * @private\r\n */\n _commonAction() {\n return {\n modeChange: menu => {\n switch (menu) {\n case 'text':\n this._changeActivateMode('TEXT');\n\n break;\n\n case 'crop':\n this.startDrawingMode('CROPPER');\n break;\n\n case 'shape':\n this._changeActivateMode('SHAPE');\n\n this.setDrawingShape(this.ui.shape.type, this.ui.shape.options);\n break;\n\n default:\n break;\n }\n },\n deactivateAll: this.deactivateAll.bind(this),\n changeSelectableAll: this.changeSelectableAll.bind(this),\n discardSelection: this.discardSelection.bind(this),\n stopDrawingMode: this.stopDrawingMode.bind(this)\n };\n },\n\n /**\r\n * Mixin\r\n * @param {ImageEditor} ImageEditor instance\r\n */\n mixin(ImageEditor) {\n extend(ImageEditor.prototype, this);\n }\n\n};","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/src/js/action.js"],"names":["extend","isSupportFileApi","base64ToBlob","toInteger","Imagetracer","getActions","main","_mainAction","shape","_shapeAction","crop","_cropAction","flip","_flipAction","rotate","_rotateAction","text","_textAction","mask","_maskAction","draw","_drawAction","icon","_iconAction","filter","_filterAction","exitCropOnAction","ui","submenu","stopDrawingMode","changeMenu","setAngleRangeBarOnAction","angle","setRangeBarAngle","setFilterStateRangeBarOnAction","filterOptions","setFilterState","onEndUndoRedo","result","initLoadImage","imagePath","imageName","loadImageFromURL","then","sizeValue","initializeImgUrl","resizeEditor","imageSize","clearUndoStack","undo","isEmptyUndoStack","deactivateAll","redo","isEmptyRedoStack","reset","delete","changeHelpButtonEnabled","removeActiveObject","activeObjectId","deleteAll","clearObjects","load","file","alert","URL","createObjectURL","loadImageFromFile","activeMenuEvent","message","Promise","reject","download","dataURL","toDataURL","getImageName","blob","type","w","window","saveAs","split","pop","open","document","body","innerHTML","_commonAction","changeColor","color","changeIconColor","addIcon","iconType","iconColor","startDrawingMode","setDrawingIcon","cancelAddIcon","clearIconType","changeSelectableAll","changeCursor","registDefalutIcons","path","iconObj","registerIcons","registCustomIcon","imgUrl","imagetracer","imageToSVG","svgstr","svgPath","match","name","left","top","tracerDefaultOption","setDrawMode","settings","setColor","setBrush","addImageObject","revokeObjectURL","applyFilter","maskObjId","changeTextStyle","styleObj","isSilent","setAngle","changeShape","changeShapeObject","setDrawingShape","shapeType","cropRect","getCropzoneRect","cancel","preset","presetType","setCropzoneRect","changeApplyButtonStatus","flipType","applying","options","hasFilter","removeFilter","setReAction","on","undoStackChanged","length","redoStackChanged","objectActivated","obj","id","indexOf","setShapeStatus","strokeColor","stroke","strokeWidth","fillColor","fill","setMaxStrokeValue","Math","min","width","height","changeStandbyMode","setTextStyleStateOnAction","setIconPickerColor","addText","pos","textColor","fontSize","fontStyle","fontWeight","underline","fontFamily","position","originPosition","styles","addObjectAfter","objectScaled","strokeValue","getStrokeValue","setStrokeValue","selectionCleared","modeChange","menu","_changeActivateMode","bind","discardSelection","mixin","ImageEditor","prototype"],"mappings":"AAAA,SAASA,MAAT,QAAuB,kBAAvB;AACA,SAASC,gBAAT,EAA2BC,YAA3B,EAAyCC,SAAzC,QAA0D,QAA1D;AACA,OAAOC,WAAP,MAAwB,sBA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iBAAK2F,mBAAL,CAAyB,OAAzB;;AACA,iBAAKxD,eAAL,CAAqB,KAAKrG,EAAL,CAAQnB,KAAR,CAAcoE,IAAnC,EAAyC,KAAKjD,EAAL,CAAQnB,KAAR,CAAcmI,OAAvD;AACA;;AACF;AACE;AAZJ;AAcD,OAhBI;AAiBLxF,MAAAA,aAAa,EAAE,KAAKA,aAAL,CAAmBsI,IAAnB,CAAwB,IAAxB,CAjBV;AAkBLxF,MAAAA,mBAAmB,EAAE,KAAKA,mBAAL,CAAyBwF,IAAzB,CAA8B,IAA9B,CAlBhB;AAmBLC,MAAAA,gBAAgB,EAAE,KAAKA,gBAAL,CAAsBD,IAAtB,CAA2B,IAA3B,CAnBb;AAoBL5J,MAAAA,eAAe,EAAE,KAAKA,eAAL,CAAqB4J,IAArB,CAA0B,IAA1B;AApBZ,KAAP;AAsBD,GAvgBY;;AAygBb;AACF;AACA;AACA;AACEE,EAAAA,KAAK,CAACC,WAAD,EAAc;AACjB5L,IAAAA,MAAM,CAAC4L,WAAW,CAACC,SAAb,EAAwB,IAAxB,CAAN;AACD;;AA/gBY,CAAf","sourcesContent":["import { extend } from 'tui-code-snippet';\r\nimport { isSupportFileApi, base64ToBlob, toInteger } from './util';\r\nimport Imagetracer from './helper/imagetracer';\r\n\r\nexport default {\r\n /**\r\n * Get ui actions\r\n * @returns {Object} actions for ui\r\n * @private\r\n */\r\n getActions() {\r\n return {\r\n main: this._mainAction(),\r\n shape: this._shapeAction(),\r\n crop: this._cropAction(),\r\n flip: this._flipAction(),\r\n rotate: this._rotateAction(),\r\n text: this._textAction(),\r\n mask: this._maskAction(),\r\n draw: this._drawAction(),\r\n icon: this._iconAction(),\r\n filter: this._filterAction(),\r\n };\r\n },\r\n\r\n /**\r\n * Main Action\r\n * @returns {Object} actions for ui main\r\n * @private\r\n */\r\n _mainAction() {\r\n const exitCropOnAction = () => {\r\n if (this.ui.submenu === 'crop') {\r\n this.stopDrawingMode();\r\n this.ui.changeMenu('crop');\r\n }\r\n };\r\n const setAngleRangeBarOnAction = (angle) => {\r\n if (this.ui.submenu === 'rotate') {\r\n this.ui.rotate.setRangeBarAngle('setAngle', angle);\r\n }\r\n };\r\n const setFilterStateRangeBarOnAction = (filterOptions) => {\r\n if (this.ui.submenu === 'filter') {\r\n this.ui.filter.setFilterState(filterOptions);\r\n }\r\n };\r\n const onEndUndoRedo = (result) => {\r\n setAngleRangeBarOnAction(result);\r\n setFilterStateRangeBarOnAction(result);\r\n\r\n return result;\r\n };\r\n\r\n return extend(\r\n {\r\n initLoadImage: (imagePath, imageName) =>\r\n this.loadImageFromURL(imagePath, imageName).then((sizeValue) => {\r\n exitCropOnAction();\r\n this.ui.initializeImgUrl = imagePath;\r\n this.ui.resizeEditor({ imageSize: sizeValue });\r\n this.clearUndoStack();\r\n }),\r\n undo: () => {\r\n if (!this.isEmptyUndoStack()) {\r\n exitCropOnAction();\r\n this.deactivateAll();\r\n this.undo().then(onEndUndoRedo);\r\n }\r\n },\r\n redo: () => {\r\n if (!this.isEmptyRedoStack()) {\r\n exitCropOnAction();\r\n this.deactivateAll();\r\n this.redo().then(onEndUndoRedo);\r\n }\r\n },\r\n reset: () => {\r\n exitCropOnAction();\r\n this.loadImageFromURL(this.ui.initializeImgUrl, 'resetImage').then((sizeValue) => {\r\n exitCropOnAction();\r\n this.ui.resizeEditor({ imageSize: sizeValue });\r\n this.clearUndoStack();\r\n });\r\n },\r\n delete: () => {\r\n this.ui.changeHelpButtonEnabled('delete', false);\r\n exitCropOnAction();\r\n this.removeActiveObject();\r\n this.activeObjectId = null;\r\n },\r\n deleteAll: () => {\r\n exitCropOnAction();\r\n this.clearObjects();\r\n this.ui.changeHelpButtonEnabled('delete', false);\r\n this.ui.changeHelpButtonEnabled('deleteAll', false);\r\n },\r\n load: (file) => {\r\n if (!isSupportFileApi()) {\r\n alert('This browser does not support file-api');\r\n }\r\n\r\n this.ui.initializeImgUrl = URL.createObjectURL(file);\r\n this.loadImageFromFile(file)\r\n .then((sizeValue) => {\r\n exitCropOnAction();\r\n this.clearUndoStack();\r\n this.ui.activeMenuEvent();\r\n this.ui.resizeEditor({ imageSize: sizeValue });\r\n })\r\n ['catch']((message) => Promise.reject(message));\r\n },\r\n download: () => {\r\n const dataURL = this.toDataURL();\r\n let imageName = this.getImageName();\r\n let blob, type, w;\r\n\r\n if (isSupportFileApi() && window.saveAs) {\r\n blob = base64ToBlob(dataURL);\r\n type = blob.type.split('/')[1];\r\n if (imageName.split('.').pop() !== type) {\r\n imageName += `.${type}`;\r\n }\r\n saveAs(blob, imageName); // eslint-disable-line\r\n } else {\r\n w = window.open();\r\n w.document.body.innerHTML = `<img src='${dataURL}'>`;\r\n }\r\n },\r\n },\r\n this._commonAction()\r\n );\r\n },\r\n\r\n /**\r\n * Icon Action\r\n * @returns {Object} actions for ui icon\r\n * @private\r\n */\r\n _iconAction() {\r\n return extend(\r\n {\r\n changeColor: (color) => {\r\n if (this.activeObjectId) {\r\n this.changeIconColor(this.activeObjectId, color);\r\n }\r\n },\r\n addIcon: (iconType, iconColor) => {\r\n this.startDrawingMode('ICON');\r\n this.setDrawingIcon(iconType, iconColor);\r\n },\r\n cancelAddIcon: () => {\r\n this.ui.icon.clearIconType();\r\n this.changeSelectableAll(true);\r\n this.changeCursor('default');\r\n this.stopDrawingMode();\r\n },\r\n registDefalutIcons: (type, path) => {\r\n const iconObj = {};\r\n iconObj[type] = path;\r\n this.registerIcons(iconObj);\r\n },\r\n registCustomIcon: (imgUrl, file) => {\r\n const imagetracer = new Imagetracer();\r\n imagetracer.imageToSVG(\r\n imgUrl,\r\n (svgstr) => {\r\n const [, svgPath] = svgstr.match(/path[^>]*d=\"([^\"]*)\"/);\r\n const iconObj = {};\r\n iconObj[file.name] = svgPath;\r\n this.registerIcons(iconObj);\r\n this.addIcon(file.name, {\r\n left: 100,\r\n top: 100,\r\n });\r\n },\r\n Imagetracer.tracerDefaultOption()\r\n );\r\n },\r\n },\r\n this._commonAction()\r\n );\r\n },\r\n\r\n /**\r\n * Draw Action\r\n * @returns {Object} actions for ui draw\r\n * @private\r\n */\r\n _drawAction() {\r\n return extend(\r\n {\r\n setDrawMode: (type, settings) => {\r\n this.stopDrawingMode();\r\n if (type === 'free') {\r\n this.startDrawingMode('FREE_DRAWING', settings);\r\n } else {\r\n this.startDrawingMode('LINE_DRAWING', settings);\r\n }\r\n },\r\n setColor: (color) => {\r\n this.setBrush({\r\n color,\r\n });\r\n },\r\n },\r\n this._commonAction()\r\n );\r\n },\r\n\r\n /**\r\n * Mask Action\r\n * @returns {Object} actions for ui mask\r\n * @private\r\n */\r\n _maskAction() {\r\n return extend(\r\n {\r\n loadImageFromURL: (imgUrl, file) =>\r\n this.loadImageFromURL(this.toDataURL(), 'FilterImage').then(() => {\r\n this.addImageObject(imgUrl).then(() => {\r\n URL.revokeObjectURL(file);\r\n });\r\n }),\r\n applyFilter: () => {\r\n this.applyFilter('mask', {\r\n maskObjId: this.activeObjectId,\r\n });\r\n },\r\n },\r\n this._commonAction()\r\n );\r\n },\r\n\r\n /**\r\n * Text Action\r\n * @returns {Object} actions for ui text\r\n * @private\r\n */\r\n _textAction() {\r\n return extend(\r\n {\r\n changeTextStyle: (styleObj, isSilent) => {\r\n if (this.activeObjectId) {\r\n this.changeTextStyle(this.activeObjectId, styleObj, isSilent);\r\n }\r\n },\r\n },\r\n this._commonAction()\r\n );\r\n },\r\n\r\n /**\r\n * Rotate Action\r\n * @returns {Object} actions for ui rotate\r\n * @private\r\n */\r\n _rotateAction() {\r\n return extend(\r\n {\r\n rotate: (angle, isSilent) => {\r\n this.rotate(angle, isSilent);\r\n this.ui.resizeEditor();\r\n this.ui.rotate.setRangeBarAngle('rotate', angle);\r\n },\r\n setAngle: (angle, isSilent) => {\r\n this.setAngle(angle, isSilent);\r\n this.ui.resizeEditor();\r\n this.ui.rotate.setRangeBarAngle('setAngle', angle);\r\n },\r\n },\r\n this._commonAction()\r\n );\r\n },\r\n\r\n /**\r\n * Shape Action\r\n * @returns {Object} actions for ui shape\r\n * @private\r\n */\r\n _shapeAction() {\r\n return extend(\r\n {\r\n changeShape: (changeShapeObject, isSilent) => {\r\n if (this.activeObjectId) {\r\n this.changeShape(this.activeObjectId, changeShapeObject, isSilent);\r\n }\r\n },\r\n setDrawingShape: (shapeType) => {\r\n this.setDrawingShape(shapeType);\r\n },\r\n },\r\n this._commonAction()\r\n );\r\n },\r\n\r\n /**\r\n * Crop Action\r\n * @returns {Object} actions for ui crop\r\n * @private\r\n */\r\n _cropAction() {\r\n return extend(\r\n {\r\n crop: () => {\r\n const cropRect = this.getCropzoneRect();\r\n if (cropRect) {\r\n this.crop(cropRect)\r\n .then(() => {\r\n this.stopDrawingMode();\r\n this.ui.resizeEditor();\r\n this.ui.changeMenu('crop');\r\n })\r\n ['catch']((message) => Promise.reject(message));\r\n }\r\n },\r\n cancel: () => {\r\n this.stopDrawingMode();\r\n this.ui.changeMenu('crop');\r\n },\r\n /* eslint-disable */\r\n preset: (presetType) => {\r\n switch (presetType) {\r\n case 'preset-square':\r\n this.setCropzoneRect(1 / 1);\r\n break;\r\n case 'preset-3-2':\r\n this.setCropzoneRect(3 / 2);\r\n break;\r\n case 'preset-4-3':\r\n this.setCropzoneRect(4 / 3);\r\n break;\r\n case 'preset-5-4':\r\n this.setCropzoneRect(5 / 4);\r\n break;\r\n case 'preset-7-5':\r\n this.setCropzoneRect(7 / 5);\r\n break;\r\n case 'preset-16-9':\r\n this.setCropzoneRect(16 / 9);\r\n break;\r\n default:\r\n this.setCropzoneRect();\r\n this.ui.crop.changeApplyButtonStatus(false);\r\n break;\r\n }\r\n },\r\n },\r\n this._commonAction()\r\n );\r\n },\r\n\r\n /**\r\n * Flip Action\r\n * @returns {Object} actions for ui flip\r\n * @private\r\n */\r\n _flipAction() {\r\n return extend(\r\n {\r\n flip: (flipType) => this[flipType](),\r\n },\r\n this._commonAction()\r\n );\r\n },\r\n\r\n /**\r\n * Filter Action\r\n * @returns {Object} actions for ui filter\r\n * @private\r\n */\r\n _filterAction() {\r\n return extend(\r\n {\r\n applyFilter: (applying, type, options, isSilent) => {\r\n if (applying) {\r\n this.applyFilter(type, options, isSilent);\r\n } else if (this.hasFilter(type)) {\r\n this.removeFilter(type);\r\n }\r\n },\r\n },\r\n this._commonAction()\r\n );\r\n },\r\n\r\n /**\r\n * Image Editor Event Observer\r\n */\r\n setReAction() {\r\n this.on({\r\n undoStackChanged: (length) => {\r\n if (length) {\r\n this.ui.changeHelpButtonEnabled('undo', true);\r\n this.ui.changeHelpButtonEnabled('reset', true);\r\n } else {\r\n this.ui.changeHelpButtonEnabled('undo', false);\r\n this.ui.changeHelpButtonEnabled('reset', false);\r\n }\r\n this.ui.resizeEditor();\r\n },\r\n redoStackChanged: (length) => {\r\n if (length) {\r\n this.ui.changeHelpButtonEnabled('redo', true);\r\n } else {\r\n this.ui.changeHelpButtonEnabled('redo', false);\r\n }\r\n this.ui.resizeEditor();\r\n },\r\n /* eslint-disable complexity */\r\n objectActivated: (obj) => {\r\n this.activeObjectId = obj.id;\r\n\r\n this.ui.changeHelpButtonEnabled('delete', true);\r\n this.ui.changeHelpButtonEnabled('deleteAll', true);\r\n\r\n if (obj.type === 'cropzone') {\r\n this.ui.crop.changeApplyButtonStatus(true);\r\n } else if (['rect', 'circle', 'triangle'].indexOf(obj.type) > -1) {\r\n this.stopDrawingMode();\r\n if (this.ui.submenu !== 'shape') {\r\n this.ui.changeMenu('shape', false, false);\r\n }\r\n this.ui.shape.setShapeStatus({\r\n strokeColor: obj.stroke,\r\n strokeWidth: obj.strokeWidth,\r\n fillColor: obj.fill,\r\n });\r\n\r\n this.ui.shape.setMaxStrokeValue(Math.min(obj.width, obj.height));\r\n } else if (obj.type === 'path' || obj.type === 'line') {\r\n if (this.ui.submenu !== 'draw') {\r\n this.ui.changeMenu('draw', false, false);\r\n this.ui.draw.changeStandbyMode();\r\n }\r\n } else if (['i-text', 'text'].indexOf(obj.type) > -1) {\r\n if (this.ui.submenu !== 'text') {\r\n this.ui.changeMenu('text', false, false);\r\n }\r\n\r\n this.ui.text.setTextStyleStateOnAction(obj);\r\n } else if (obj.type === 'icon') {\r\n this.stopDrawingMode();\r\n if (this.ui.submenu !== 'icon') {\r\n this.ui.changeMenu('icon', false, false);\r\n }\r\n this.ui.icon.setIconPickerColor(obj.fill);\r\n }\r\n },\r\n /* eslint-enable complexity */\r\n addText: (pos) => {\r\n const { textColor: fill, fontSize, fontStyle, fontWeight, underline } = this.ui.text;\r\n const fontFamily = 'Noto Sans';\r\n\r\n this.addText('Double Click', {\r\n position: pos.originPosition,\r\n styles: { fill, fontSize, fontFamily, fontStyle, fontWeight, underline },\r\n }).then(() => {\r\n this.changeCursor('default');\r\n });\r\n },\r\n addObjectAfter: (obj) => {\r\n if (obj.type === 'icon') {\r\n this.ui.icon.changeStandbyMode();\r\n } else if (['rect', 'circle', 'triangle'].indexOf(obj.type) > -1) {\r\n this.ui.shape.setMaxStrokeValue(Math.min(obj.width, obj.height));\r\n this.ui.shape.changeStandbyMode();\r\n }\r\n },\r\n objectScaled: (obj) => {\r\n if (['i-text', 'text'].indexOf(obj.type) > -1) {\r\n this.ui.text.fontSize = toInteger(obj.fontSize);\r\n } else if (['rect', 'circle', 'triangle'].indexOf(obj.type) >= 0) {\r\n const { width, height } = obj;\r\n const strokeValue = this.ui.shape.getStrokeValue();\r\n\r\n if (width < strokeValue) {\r\n this.ui.shape.setStrokeValue(width);\r\n }\r\n if (height < strokeValue) {\r\n this.ui.shape.setStrokeValue(height);\r\n }\r\n }\r\n },\r\n selectionCleared: () => {\r\n this.activeObjectId = null;\r\n if (this.ui.submenu === 'text') {\r\n this.changeCursor('text');\r\n } else if (this.ui.submenu !== 'draw' && this.ui.submenu !== 'crop') {\r\n this.stopDrawingMode();\r\n }\r\n },\r\n });\r\n },\r\n\r\n /**\r\n * Common Action\r\n * @returns {Object} common actions for ui\r\n * @private\r\n */\r\n _commonAction() {\r\n return {\r\n modeChange: (menu) => {\r\n switch (menu) {\r\n case 'text':\r\n this._changeActivateMode('TEXT');\r\n break;\r\n case 'crop':\r\n this.startDrawingMode('CROPPER');\r\n break;\r\n case 'shape':\r\n this._changeActivateMode('SHAPE');\r\n this.setDrawingShape(this.ui.shape.type, this.ui.shape.options);\r\n break;\r\n default:\r\n break;\r\n }\r\n },\r\n deactivateAll: this.deactivateAll.bind(this),\r\n changeSelectableAll: this.changeSelectableAll.bind(this),\r\n discardSelection: this.discardSelection.bind(this),\r\n stopDrawingMode: this.stopDrawingMode.bind(this),\r\n };\r\n },\r\n\r\n /**\r\n * Mixin\r\n * @param {ImageEditor} ImageEditor instance\r\n */\r\n mixin(ImageEditor) {\r\n extend(ImageEditor.prototype, this);\r\n },\r\n};\r\n"]},"metadata":{},"sourceType":"module"}