UNPKG

filerobot-image-editor

Version:

Vanilla Javascript bridged version of filerobot image editor (FIE).

1 lines 3.74 kB
import _typeof from"@babel/runtime/helpers/typeof";import _classCallCheck from"@babel/runtime/helpers/classCallCheck";import _createClass from"@babel/runtime/helpers/createClass";import _defineProperty from"@babel/runtime/helpers/defineProperty";function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}function _classPrivateFieldInitSpec(a,b,c){_checkPrivateRedeclaration(a,b),b.set(a,c)}function _checkPrivateRedeclaration(a,b){if(b.has(a))throw new TypeError("Cannot initialize the same private elements twice on an object")}function _classPrivateFieldGet(b,c){return b.get(_assertClassBrand(b,c))}function _classPrivateFieldSet(b,c,a){return b.set(_assertClassBrand(b,c),a),a}function _assertClassBrand(a,b,c){if("function"==typeof a?a===b:a.has(b))return 3>arguments.length?b:c;throw new TypeError("Private element is not present on this object")}import{createElement}from"react";import{createRoot}from"react-dom/client";import AssemblyPoint,{TOOLS,TABS}from"react-filerobot-image-editor";import deepMerge from"react-filerobot-image-editor/lib/utils/deepMerge";var _root=new WeakMap,_getCurrentImgDataFnRef=new WeakMap,_updateStateFnRef=new WeakMap,FilerobotImageEditor=function(){function a(b){var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(_classCallCheck(this,a),_classPrivateFieldInitSpec(this,_root,void 0),_classPrivateFieldInitSpec(this,_getCurrentImgDataFnRef,void 0),_classPrivateFieldInitSpec(this,_updateStateFnRef,void 0),this.container=b,this.config=c,!b||!(b instanceof HTMLElement))throw new Error("`container` (argument 0) is required to initialize the image editor plugin.");_classPrivateFieldSet(_root,this,createRoot(this.container)),_classPrivateFieldSet(_getCurrentImgDataFnRef,this,{}),_classPrivateFieldSet(_updateStateFnRef,this,{}),this.getCurrentImgData=this.getCurrentImgData.bind(this),this.render=this.render.bind(this),this.terminate=this.terminate.bind(this),this.updateState=this.updateState.bind(this)}return _createClass(a,[{key:"render",value:function render(a){"object"===_typeof(a)&&(this.config=this.config=deepMerge(this.config||{},a)),this.config=_objectSpread(_objectSpread({},this.config),{},{getCurrentImgDataFnRef:_classPrivateFieldGet(_getCurrentImgDataFnRef,this),updateStateFnRef:_classPrivateFieldGet(_updateStateFnRef,this)}),_classPrivateFieldGet(_root,this)._internalRoot||_classPrivateFieldSet(_root,this,createRoot(this.container)),_classPrivateFieldGet(_root,this).render(createElement(AssemblyPoint,this.config))}},{key:"terminate",value:function terminate(){_classPrivateFieldGet(_root,this).unmount()}},{key:"getCurrentImgData",value:function getCurrentImgData(a,b,c){var d,e;return(null===(d=_classPrivateFieldGet(_getCurrentImgDataFnRef,this))||void 0===d||null===(e=d.current)||void 0===e?void 0:e.call(d,a,b,c))||{}}},{key:"updateState",value:function updateState(a){var b,c;null===(b=_classPrivateFieldGet(_updateStateFnRef,this))||void 0===b||null===(c=b.current)||void 0===c||c.call(b,a)}}])}();_defineProperty(FilerobotImageEditor,"TABS",TABS),_defineProperty(FilerobotImageEditor,"TOOLS",TOOLS),FilerobotImageEditor.TABS=TABS,FilerobotImageEditor.TOOLS=TOOLS;export default FilerobotImageEditor;