"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");exports.__esModule=!0,exports.defineAnimation=defineAnimation,exports.definePlugin=definePlugin;var _executer=require("./executer"),_defineReactive=_interopRequireDefault(require("../common/define-reactive"));function definePlugin(a,b){return(c={})=>{let d,e="function"==typeof b.render;const f=a=>{e&&b.render.call(d,a)};let g=()=>{"function"==typeof b.destroyed&&b.destroyed.call(d),e&&(0,_executer.removeRender)(f)};const h=a=>(d=b.setup(c,a),e&&(0,_executer.onRender)(f),d);return h.key=a,h.type="plugin",h.dispose=()=>{g&&g()},h}}function defineAnimation(a,b){const c=b=>"string"==typeof a?b.type===a:"function"==typeof a?a(b):a.test(b.type),d=async(a,d)=>{c(a)||void 0,"optimize"in a.model&&"function"==typeof a.model.optimize&&(await a.model.optimize(!1));let e=b(a,d||{});return(0,_defineReactive.default)(e,{get:(b,c)=>{if("function"==typeof b[c]){let d=async(...d)=>{let f;try{f=await b[c].apply(e,d)}catch(a){}return"optimize"in a.model&&"function"==typeof a.model.optimize&&(await a.model.optimize(!0)),f};return d}return b[c]}})};return{type:"animation",name:a,isMatch:c,apply:d}}