cdc2bf8e8ae37c4f84934731148cccf9.json 7.3 KB
{"ast":null,"code":"import Submenu from './submenuBase';\nimport { assignmentForDestroy, isSupportFileApi } from '../util';\nimport templateHtml from './template/submenu/mask';\n/**\r\n * Mask ui class\r\n * @class\r\n * @ignore\r\n */\n\nclass Mask extends Submenu {\n  constructor(subMenuElement, {\n    locale,\n    makeSvgIcon,\n    menuBarPosition,\n    usageStatistics\n  }) {\n    super(subMenuElement, {\n      locale,\n      name: 'mask',\n      makeSvgIcon,\n      menuBarPosition,\n      templateHtml,\n      usageStatistics\n    });\n    this._els = {\n      applyButton: this.selector('.tie-mask-apply'),\n      maskImageButton: this.selector('.tie-mask-image-file')\n    };\n  }\n  /**\r\n   * Destroys the instance.\r\n   */\n\n\n  destroy() {\n    this._removeEvent();\n\n    assignmentForDestroy(this);\n  }\n  /**\r\n   * Add event for mask\r\n   * @param {Object} actions - actions for crop\r\n   *   @param {Function} actions.loadImageFromURL - load image action\r\n   *   @param {Function} actions.applyFilter - apply filter action\r\n   */\n\n\n  addEvent(actions) {\n    const loadMaskFile = this._loadMaskFile.bind(this);\n\n    const applyMask = this._applyMask.bind(this);\n\n    this.eventHandler = {\n      loadMaskFile,\n      applyMask\n    };\n    this.actions = actions;\n\n    this._els.maskImageButton.addEventListener('change', loadMaskFile);\n\n    this._els.applyButton.addEventListener('click', applyMask);\n  }\n  /**\r\n   * Remove event\r\n   * @private\r\n   */\n\n\n  _removeEvent() {\n    this._els.maskImageButton.removeEventListener('change', this.eventHandler.loadMaskFile);\n\n    this._els.applyButton.removeEventListener('click', this.eventHandler.applyMask);\n  }\n  /**\r\n   * Apply mask\r\n   * @private\r\n   */\n\n\n  _applyMask() {\n    this.actions.applyFilter();\n\n    this._els.applyButton.classList.remove('active');\n  }\n  /**\r\n   * Load mask file\r\n   * @param {object} event - File change event object\r\n   * @private\r\n   */\n\n\n  _loadMaskFile(event) {\n    let imgUrl;\n\n    if (!isSupportFileApi()) {\n      alert('This browser does not support file-api');\n    }\n\n    const [file] = event.target.files;\n\n    if (file) {\n      imgUrl = URL.createObjectURL(file);\n      this.actions.loadImageFromURL(imgUrl, file);\n\n      this._els.applyButton.classList.add('active');\n    }\n  }\n\n}\n\nexport default Mask;","map":{"version":3,"sources":["C:/Users/kkwan_000/Desktop/git/2017110269/minsung/src/js/ui/mask.js"],"names":["Submenu","assignmentForDestroy","isSupportFileApi","templateHtml","Mask","constructor","subMenuElement","locale","makeSvgIcon","menuBarPosition","usageStatistics","name","_els","applyButton","selector","maskImageButton","destroy","_removeEvent","addEvent","actions","loadMaskFile","_loadMaskFile","bind","applyMask","_applyMask","eventHandler","addEventListener","removeEventListener","applyFilter","classList","remove","event","imgUrl","alert","file","target","files","URL","createObjectURL","loadImageFromURL","add"],"mappings":"AAAA,OAAOA,OAAP,MAAoB,eAApB;AACA,SAASC,oBAAT,EAA+BC,gBAA/B,QAAuD,SAAvD;AACA,OAAOC,YAAP,MAAyB,yBAAzB;AAEA;AACA;AACA;AACA;AACA;;AACA,MAAMC,IAAN,SAAmBJ,OAAnB,CAA2B;AACzBK,EAAAA,WAAW,CAACC,cAAD,EAAiB;AAAEC,IAAAA,MAAF;AAAUC,IAAAA,WAAV;AAAuBC,IAAAA,eAAvB;AAAwCC,IAAAA;AAAxC,GAAjB,EAA4E;AACrF,UAAMJ,cAAN,EAAsB;AACpBC,MAAAA,MADoB;AAEpBI,MAAAA,IAAI,EAAE,MAFc;AAGpBH,MAAAA,WAHoB;AAIpBC,MAAAA,eAJoB;AAKpBN,MAAAA,YALoB;AAMpBO,MAAAA;AANoB,KAAtB;AASA,SAAKE,IAAL,GAAY;AACVC,MAAAA,WAAW,EAAE,KAAKC,QAAL,CAAc,iBAAd,CADH;AAEVC,MAAAA,eAAe,EAAE,KAAKD,QAAL,CAAc,sBAAd;AAFP,KAAZ;AAID;AAED;AACF;AACA;;;AACEE,EAAAA,OAAO,GAAG;AACR,SAAKC,YAAL;;AAEAhB,IAAAA,oBAAoB,CAAC,IAAD,CAApB;A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,CAAT;AACA,WAAKf,OAAL,CAAaoB,gBAAb,CAA8BP,MAA9B,EAAsCE,IAAtC;;AACA,WAAKtB,IAAL,CAAUC,WAAV,CAAsBgB,SAAtB,CAAgCW,GAAhC,CAAoC,QAApC;AACD;AACF;;AAnFwB;;AAsF3B,eAAepC,IAAf","sourcesContent":["import Submenu from './submenuBase';\r\nimport { assignmentForDestroy, isSupportFileApi } from '../util';\r\nimport templateHtml from './template/submenu/mask';\r\n\r\n/**\r\n * Mask ui class\r\n * @class\r\n * @ignore\r\n */\r\nclass Mask extends Submenu {\r\n  constructor(subMenuElement, { locale, makeSvgIcon, menuBarPosition, usageStatistics }) {\r\n    super(subMenuElement, {\r\n      locale,\r\n      name: 'mask',\r\n      makeSvgIcon,\r\n      menuBarPosition,\r\n      templateHtml,\r\n      usageStatistics,\r\n    });\r\n\r\n    this._els = {\r\n      applyButton: this.selector('.tie-mask-apply'),\r\n      maskImageButton: this.selector('.tie-mask-image-file'),\r\n    };\r\n  }\r\n\r\n  /**\r\n   * Destroys the instance.\r\n   */\r\n  destroy() {\r\n    this._removeEvent();\r\n\r\n    assignmentForDestroy(this);\r\n  }\r\n\r\n  /**\r\n   * Add event for mask\r\n   * @param {Object} actions - actions for crop\r\n   *   @param {Function} actions.loadImageFromURL - load image action\r\n   *   @param {Function} actions.applyFilter - apply filter action\r\n   */\r\n  addEvent(actions) {\r\n    const loadMaskFile = this._loadMaskFile.bind(this);\r\n    const applyMask = this._applyMask.bind(this);\r\n\r\n    this.eventHandler = {\r\n      loadMaskFile,\r\n      applyMask,\r\n    };\r\n\r\n    this.actions = actions;\r\n    this._els.maskImageButton.addEventListener('change', loadMaskFile);\r\n    this._els.applyButton.addEventListener('click', applyMask);\r\n  }\r\n\r\n  /**\r\n   * Remove event\r\n   * @private\r\n   */\r\n  _removeEvent() {\r\n    this._els.maskImageButton.removeEventListener('change', this.eventHandler.loadMaskFile);\r\n    this._els.applyButton.removeEventListener('click', this.eventHandler.applyMask);\r\n  }\r\n\r\n  /**\r\n   * Apply mask\r\n   * @private\r\n   */\r\n  _applyMask() {\r\n    this.actions.applyFilter();\r\n    this._els.applyButton.classList.remove('active');\r\n  }\r\n\r\n  /**\r\n   * Load mask file\r\n   * @param {object} event - File change event object\r\n   * @private\r\n   */\r\n  _loadMaskFile(event) {\r\n    let imgUrl;\r\n\r\n    if (!isSupportFileApi()) {\r\n      alert('This browser does not support file-api');\r\n    }\r\n\r\n    const [file] = event.target.files;\r\n\r\n    if (file) {\r\n      imgUrl = URL.createObjectURL(file);\r\n      this.actions.loadImageFromURL(imgUrl, file);\r\n      this._els.applyButton.classList.add('active');\r\n    }\r\n  }\r\n}\r\n\r\nexport default Mask;\r\n"]},"metadata":{},"sourceType":"module"}