4873f2e3636f2d3b604fe9af2abc55d2.json
10.9 KB
{"ast":null,"code":"/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview Image flip module\r\n */\nimport snippet from 'tui-code-snippet';\nimport { Promise } from '../util';\nimport Component from '../interface/component';\nimport { componentNames, rejectMessages } from '../consts';\n/**\r\n * Flip\r\n * @class Flip\r\n * @param {Graphics} graphics - Graphics instance\r\n * @extends {Component}\r\n * @ignore\r\n */\n\nclass Flip extends Component {\n constructor(graphics) {\n super(componentNames.FLIP, graphics);\n }\n /**\r\n * Get current flip settings\r\n * @returns {{flipX: Boolean, flipY: Boolean}}\r\n */\n\n\n getCurrentSetting() {\n const canvasImage = this.getCanvasImage();\n return {\n flipX: canvasImage.flipX,\n flipY: canvasImage.flipY\n };\n }\n /**\r\n * Set flipX, flipY\r\n * @param {{flipX: Boolean, flipY: Boolean}} newSetting - Flip setting\r\n * @returns {Promise}\r\n */\n\n\n set(newSetting) {\n const setting = this.getCurrentSetting();\n const isChangingFlipX = setting.flipX !== newSetting.flipX;\n const isChangingFlipY = setting.flipY !== newSetting.flipY;\n\n if (!isChangingFlipX && !isChangingFlipY) {\n return Promise.reject(rejectMessages.flip);\n }\n\n snippet.extend(setting, newSetting);\n this.setImageProperties(setting, true);\n\n this._invertAngle(isChangingFlipX, isChangingFlipY);\n\n this._flipObjects(isChangingFlipX, isChangingFlipY);\n\n return Promise.resolve({\n flipX: setting.flipX,\n flipY: setting.flipY,\n angle: this.getCanvasImage().angle\n });\n }\n /**\r\n * Invert image angle for flip\r\n * @param {boolean} isChangingFlipX - Change flipX\r\n * @param {boolean} isChangingFlipY - Change flipY\r\n */\n\n\n _invertAngle(isChangingFlipX, isChangingFlipY) {\n const canvasImage = this.getCanvasImage();\n let {\n angle\n } = canvasImage;\n\n if (isChangingFlipX) {\n angle *= -1;\n }\n\n if (isChangingFlipY) {\n angle *= -1;\n }\n\n canvasImage.rotate(parseFloat(angle)).setCoords(); // parseFloat for -0 to 0\n }\n /**\r\n * Flip objects\r\n * @param {boolean} isChangingFlipX - Change flipX\r\n * @param {boolean} isChangingFlipY - Change flipY\r\n * @private\r\n */\n\n\n _flipObjects(isChangingFlipX, isChangingFlipY) {\n const canvas = this.getCanvas();\n\n if (isChangingFlipX) {\n canvas.forEachObject(obj => {\n obj.set({\n angle: parseFloat(obj.angle * -1),\n // parseFloat for -0 to 0\n flipX: !obj.flipX,\n left: canvas.width - obj.left\n }).setCoords();\n });\n }\n\n if (isChangingFlipY) {\n canvas.forEachObject(obj => {\n obj.set({\n angle: parseFloat(obj.angle * -1),\n // parseFloat for -0 to 0\n flipY: !obj.flipY,\n top: canvas.height - obj.top\n }).setCoords();\n });\n }\n\n canvas.renderAll();\n }\n /**\r\n * Reset flip settings\r\n * @returns {Promise}\r\n */\n\n\n reset() {\n return this.set({\n flipX: false,\n flipY: false\n });\n }\n /**\r\n * Flip x\r\n * @returns {Promise}\r\n */\n\n\n flipX() {\n const current = this.getCurrentSetting();\n return this.set({\n flipX: !current.flipX,\n flipY: current.flipY\n });\n }\n /**\r\n * Flip y\r\n * @returns {Promise}\r\n */\n\n\n flipY() {\n const current = this.getCurrentSetting();\n return this.set({\n flipX: current.flipX,\n flipY: !current.flipY\n });\n }\n\n}\n\nexport default Flip;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/src/js/component/flip.js"],"names":["snippet","Promise","Component","componentNames","rejectMessages","Flip","constructor","graphics","FLIP","getCurrentSetting","canvasImage","getCanvasImage","flipX","flipY","set","newSetting","setting","isChangingFlipX","isChangingFlipY","reject","flip","extend","setImageProperties","_invertAngle","_flipObjects","resolve","angle","rotate","parseFloat","setCoords","canvas","getCanvas","forEachObject","obj","left","width","top","height","renderAll","reset","current"],"mappings":"AAAA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,kBAApB;AACA,SAASC,OAAT,QAAwB,SAAxB;AACA,OAAOC,SAAP,MAAsB,wBAAtB;AACA,SAASC,cAAT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AMGP,SANH;AAOD,OARD;AASD;;AACDC,IAAAA,MAAM,CAACQ,SAAP;AACD;AAED;AACF;AACA;AACA;;;AACEC,EAAAA,KAAK,GAAG;AACN,WAAO,KAAKzB,GAAL,CAAS;AACdF,MAAAA,KAAK,EAAE,KADO;AAEdC,MAAAA,KAAK,EAAE;AAFO,KAAT,CAAP;AAID;AAED;AACF;AACA;AACA;;;AACED,EAAAA,KAAK,GAAG;AACN,UAAM4B,OAAO,GAAG,KAAK/B,iBAAL,EAAhB;AAEA,WAAO,KAAKK,GAAL,CAAS;AACdF,MAAAA,KAAK,EAAE,CAAC4B,OAAO,CAAC5B,KADF;AAEdC,MAAAA,KAAK,EAAE2B,OAAO,CAAC3B;AAFD,KAAT,CAAP;AAID;AAED;AACF;AACA;AACA;;;AACEA,EAAAA,KAAK,GAAG;AACN,UAAM2B,OAAO,GAAG,KAAK/B,iBAAL,EAAhB;AAEA,WAAO,KAAKK,GAAL,CAAS;AACdF,MAAAA,KAAK,EAAE4B,OAAO,CAAC5B,KADD;AAEdC,MAAAA,KAAK,EAAE,CAAC2B,OAAO,CAAC3B;AAFF,KAAT,CAAP;AAID;;AAnI0B;;AAsI7B,eAAeR,IAAf","sourcesContent":["/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview Image flip module\r\n */\r\nimport snippet from 'tui-code-snippet';\r\nimport { Promise } from '../util';\r\nimport Component from '../interface/component';\r\nimport { componentNames, rejectMessages } from '../consts';\r\n\r\n/**\r\n * Flip\r\n * @class Flip\r\n * @param {Graphics} graphics - Graphics instance\r\n * @extends {Component}\r\n * @ignore\r\n */\r\nclass Flip extends Component {\r\n constructor(graphics) {\r\n super(componentNames.FLIP, graphics);\r\n }\r\n\r\n /**\r\n * Get current flip settings\r\n * @returns {{flipX: Boolean, flipY: Boolean}}\r\n */\r\n getCurrentSetting() {\r\n const canvasImage = this.getCanvasImage();\r\n\r\n return {\r\n flipX: canvasImage.flipX,\r\n flipY: canvasImage.flipY,\r\n };\r\n }\r\n\r\n /**\r\n * Set flipX, flipY\r\n * @param {{flipX: Boolean, flipY: Boolean}} newSetting - Flip setting\r\n * @returns {Promise}\r\n */\r\n set(newSetting) {\r\n const setting = this.getCurrentSetting();\r\n const isChangingFlipX = setting.flipX !== newSetting.flipX;\r\n const isChangingFlipY = setting.flipY !== newSetting.flipY;\r\n\r\n if (!isChangingFlipX && !isChangingFlipY) {\r\n return Promise.reject(rejectMessages.flip);\r\n }\r\n\r\n snippet.extend(setting, newSetting);\r\n this.setImageProperties(setting, true);\r\n this._invertAngle(isChangingFlipX, isChangingFlipY);\r\n this._flipObjects(isChangingFlipX, isChangingFlipY);\r\n\r\n return Promise.resolve({\r\n flipX: setting.flipX,\r\n flipY: setting.flipY,\r\n angle: this.getCanvasImage().angle,\r\n });\r\n }\r\n\r\n /**\r\n * Invert image angle for flip\r\n * @param {boolean} isChangingFlipX - Change flipX\r\n * @param {boolean} isChangingFlipY - Change flipY\r\n */\r\n _invertAngle(isChangingFlipX, isChangingFlipY) {\r\n const canvasImage = this.getCanvasImage();\r\n let { angle } = canvasImage;\r\n\r\n if (isChangingFlipX) {\r\n angle *= -1;\r\n }\r\n if (isChangingFlipY) {\r\n angle *= -1;\r\n }\r\n canvasImage.rotate(parseFloat(angle)).setCoords(); // parseFloat for -0 to 0\r\n }\r\n\r\n /**\r\n * Flip objects\r\n * @param {boolean} isChangingFlipX - Change flipX\r\n * @param {boolean} isChangingFlipY - Change flipY\r\n * @private\r\n */\r\n _flipObjects(isChangingFlipX, isChangingFlipY) {\r\n const canvas = this.getCanvas();\r\n\r\n if (isChangingFlipX) {\r\n canvas.forEachObject((obj) => {\r\n obj\r\n .set({\r\n angle: parseFloat(obj.angle * -1), // parseFloat for -0 to 0\r\n flipX: !obj.flipX,\r\n left: canvas.width - obj.left,\r\n })\r\n .setCoords();\r\n });\r\n }\r\n if (isChangingFlipY) {\r\n canvas.forEachObject((obj) => {\r\n obj\r\n .set({\r\n angle: parseFloat(obj.angle * -1), // parseFloat for -0 to 0\r\n flipY: !obj.flipY,\r\n top: canvas.height - obj.top,\r\n })\r\n .setCoords();\r\n });\r\n }\r\n canvas.renderAll();\r\n }\r\n\r\n /**\r\n * Reset flip settings\r\n * @returns {Promise}\r\n */\r\n reset() {\r\n return this.set({\r\n flipX: false,\r\n flipY: false,\r\n });\r\n }\r\n\r\n /**\r\n * Flip x\r\n * @returns {Promise}\r\n */\r\n flipX() {\r\n const current = this.getCurrentSetting();\r\n\r\n return this.set({\r\n flipX: !current.flipX,\r\n flipY: current.flipY,\r\n });\r\n }\r\n\r\n /**\r\n * Flip y\r\n * @returns {Promise}\r\n */\r\n flipY() {\r\n const current = this.getCurrentSetting();\r\n\r\n return this.set({\r\n flipX: current.flipX,\r\n flipY: !current.flipY,\r\n });\r\n }\r\n}\r\n\r\nexport default Flip;\r\n"]},"metadata":{},"sourceType":"module"}