c9f961da4e9858ede3b2eb604cff2d93.json 8.08 KB
{"ast":null,"code":"/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview Apply a filter into an image\r\n */\nimport snippet from 'tui-code-snippet';\nimport commandFactory from '../factory/command';\nimport { componentNames, rejectMessages, commandNames } from '../consts';\nconst {\n  FILTER\n} = componentNames;\n/**\r\n * Chched data for undo\r\n * @type {Object}\r\n */\n\nlet chchedUndoDataForSilent = null;\n/**\r\n * Make undoData\r\n * @param {string} type - Filter type\r\n * @param {Object} prevfilterOption - prev Filter options\r\n * @param {Object} options - Filter options\r\n * @returns {object} - undo data\r\n */\n\nfunction makeUndoData(type, prevfilterOption, options) {\n  const undoData = {};\n\n  if (type === 'mask') {\n    undoData.object = options.mask;\n  }\n\n  undoData.options = prevfilterOption;\n  return undoData;\n}\n\nconst command = {\n  name: commandNames.APPLY_FILTER,\n\n  /**\r\n   * Apply a filter into an image\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @param {string} type - Filter type\r\n   * @param {Object} options - Filter options\r\n   *  @param {number} options.maskObjId - masking image object id\r\n   * @param {boolean} isSilent - is silent execution or not\r\n   * @returns {Promise}\r\n   */\n  execute(graphics, type, options, isSilent) {\n    const filterComp = graphics.getComponent(FILTER);\n\n    if (type === 'mask') {\n      const maskObj = graphics.getObject(options.maskObjId);\n\n      if (!(maskObj && maskObj.isType('image'))) {\n        return Promise.reject(rejectMessages.invalidParameters);\n      }\n\n      snippet.extend(options, {\n        mask: maskObj\n      });\n      graphics.remove(options.mask);\n    }\n\n    if (!this.isRedo) {\n      const prevfilterOption = filterComp.getOptions(type);\n      const undoData = makeUndoData(type, prevfilterOption, options);\n      chchedUndoDataForSilent = this.setUndoData(undoData, chchedUndoDataForSilent, isSilent);\n    }\n\n    return filterComp.add(type, options);\n  },\n\n  /**\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @param {string} type - Filter type\r\n   * @returns {Promise}\r\n   */\n  undo(graphics, type) {\n    const filterComp = graphics.getComponent(FILTER);\n\n    if (type === 'mask') {\n      const mask = this.undoData.object;\n      graphics.add(mask);\n      graphics.setActiveObject(mask);\n      return filterComp.remove(type);\n    } // options changed case\n\n\n    if (this.undoData.options) {\n      return filterComp.add(type, this.undoData.options);\n    } // filter added case\n\n\n    return filterComp.remove(type);\n  }\n\n};\ncommandFactory.register(command);\nexport default command;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/src/js/command/applyFilter.js"],"names":["snippet","commandFactory","componentNames","rejectMessages","commandNames","FILTER","chchedUndoDataForSilent","makeUndoData","type","prevfilterOption","options","undoData","object","mask","command","name","APPLY_FILTER","execute","graphics","isSilent","filterComp","getComponent","maskObj","getObject","maskObjId","isType","Promise","reject","invalidParameters","extend","remove","isRedo","getOptions","setUndoData","add","undo","setActiveObject","register"],"mappings":"AAAA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,kBAApB;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,SAASC,cAAT,EAAyBC,cAAzB,EAAyCC,YAAzC,QAA6D,WAA7D;AAEA,MAAM;AAAEC,EAAAA;AAAF,IAAaH,cAAnB;AAEA;AACA;AACA;AACA;;AACA,IAAII,uBAAuB,GAAG,IAA9B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,YAAT,CAAsBC,IAAtB,EAA4BC,gBAA5B,EAA8CC,OAA9C,EAAuD;AACrD,QAAMC,QAAQ,GAAG,EAAjB;;AAEA,MAAIH,IAAI,KAAK,MAAb,EAAqB;AACnBG,IAAAA,QAAQ,CAACC,MAAT,GAAkBF,OAAO,CAACG,IAA1B;AACD;;AAEDF,EAAAA,QAAQ,CAACD,OAAT,GAAmBD,gBAAnB;AAEA,SAAOE,QAAP;AACD;;AAED,MAAMG,OAAO,GAAG;AACdC,EAAAA,IAAI,EAAEX,YAAY,CAACY,YADL;;AAGd;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACEC,EAAAA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AAT,CAAarB,IAAb;AACAK,MAAAA,QAAQ,CAACkB,eAAT,CAAyBvB,IAAzB;AAEA,aAAOO,UAAU,CAACU,MAAX,CAAkBtB,IAAlB,CAAP;AACD,KATkB,CAWnB;;;AACA,QAAI,KAAKG,QAAL,CAAcD,OAAlB,EAA2B;AACzB,aAAOU,UAAU,CAACc,GAAX,CAAe1B,IAAf,EAAqB,KAAKG,QAAL,CAAcD,OAAnC,CAAP;AACD,KAdkB,CAgBnB;;;AACA,WAAOU,UAAU,CAACU,MAAX,CAAkBtB,IAAlB,CAAP;AACD;;AAzDa,CAAhB;AA4DAP,cAAc,CAACoC,QAAf,CAAwBvB,OAAxB;AAEA,eAAeA,OAAf","sourcesContent":["/**\r\n * @author NHN Ent. FE Development Team <dl_javascript@nhn.com>\r\n * @fileoverview Apply a filter into an image\r\n */\r\nimport snippet from 'tui-code-snippet';\r\nimport commandFactory from '../factory/command';\r\nimport { componentNames, rejectMessages, commandNames } from '../consts';\r\n\r\nconst { FILTER } = componentNames;\r\n\r\n/**\r\n * Chched data for undo\r\n * @type {Object}\r\n */\r\nlet chchedUndoDataForSilent = null;\r\n\r\n/**\r\n * Make undoData\r\n * @param {string} type - Filter type\r\n * @param {Object} prevfilterOption - prev Filter options\r\n * @param {Object} options - Filter options\r\n * @returns {object} - undo data\r\n */\r\nfunction makeUndoData(type, prevfilterOption, options) {\r\n  const undoData = {};\r\n\r\n  if (type === 'mask') {\r\n    undoData.object = options.mask;\r\n  }\r\n\r\n  undoData.options = prevfilterOption;\r\n\r\n  return undoData;\r\n}\r\n\r\nconst command = {\r\n  name: commandNames.APPLY_FILTER,\r\n\r\n  /**\r\n   * Apply a filter into an image\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @param {string} type - Filter type\r\n   * @param {Object} options - Filter options\r\n   *  @param {number} options.maskObjId - masking image object id\r\n   * @param {boolean} isSilent - is silent execution or not\r\n   * @returns {Promise}\r\n   */\r\n  execute(graphics, type, options, isSilent) {\r\n    const filterComp = graphics.getComponent(FILTER);\r\n\r\n    if (type === 'mask') {\r\n      const maskObj = graphics.getObject(options.maskObjId);\r\n\r\n      if (!(maskObj && maskObj.isType('image'))) {\r\n        return Promise.reject(rejectMessages.invalidParameters);\r\n      }\r\n\r\n      snippet.extend(options, { mask: maskObj });\r\n      graphics.remove(options.mask);\r\n    }\r\n    if (!this.isRedo) {\r\n      const prevfilterOption = filterComp.getOptions(type);\r\n      const undoData = makeUndoData(type, prevfilterOption, options);\r\n\r\n      chchedUndoDataForSilent = this.setUndoData(undoData, chchedUndoDataForSilent, isSilent);\r\n    }\r\n\r\n    return filterComp.add(type, options);\r\n  },\r\n  /**\r\n   * @param {Graphics} graphics - Graphics instance\r\n   * @param {string} type - Filter type\r\n   * @returns {Promise}\r\n   */\r\n  undo(graphics, type) {\r\n    const filterComp = graphics.getComponent(FILTER);\r\n\r\n    if (type === 'mask') {\r\n      const mask = this.undoData.object;\r\n      graphics.add(mask);\r\n      graphics.setActiveObject(mask);\r\n\r\n      return filterComp.remove(type);\r\n    }\r\n\r\n    // options changed case\r\n    if (this.undoData.options) {\r\n      return filterComp.add(type, this.undoData.options);\r\n    }\r\n\r\n    // filter added case\r\n    return filterComp.remove(type);\r\n  },\r\n};\r\n\r\ncommandFactory.register(command);\r\n\r\nexport default command;\r\n"]},"metadata":{},"sourceType":"module"}