UNPKG

uaeengine

Version:

基于MVVM和canvas的图形框架

1 lines 35.8 kB
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Uae=e():t.Uae=e()}(window,function(){return n=[function(t,e,n){"use strict";function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&f(t,e)}function c(n){var i=u();return function(){var t,e=o(n);return function(t,e){{if(e&&("object"===y(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined")}return s(t)}(this,i?(t=o(this).constructor,Reflect.construct(e,arguments,t)):e.apply(this,arguments))}}function s(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function a(e,t){var n,i=Object.keys(e);return Object.getOwnPropertySymbols&&(n=Object.getOwnPropertySymbols(e),t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),i.push.apply(i,n)),i}function i(i){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?a(Object(o),!0).forEach(function(t){var e,n;e=i,t=o[n=t],n in e?Object.defineProperty(e,n,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[n]=t}):Object.getOwnPropertyDescriptors?Object.defineProperties(i,Object.getOwnPropertyDescriptors(o)):a(Object(o)).forEach(function(t){Object.defineProperty(i,t,Object.getOwnPropertyDescriptor(o,t))})}return i}function h(t,e,n){return(h=u()?Reflect.construct:function(t,e,n){var i=[null];i.push.apply(i,e);i=new(Function.bind.apply(t,i));return n&&f(i,n.prototype),i}).apply(null,arguments)}function u(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}function f(t,e){return(f=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function l(t){return function(t){if(Array.isArray(t))return p(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return p(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Map"===(n="Object"===n&&t.constructor?t.constructor.name:n)||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?p(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function p(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function d(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function $(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function v(t,e,n){return e&&$(t.prototype,e),n&&$(t,n),t}function y(t){return(y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}n.r(e);var m={},g={},_=[],w={1:[],2:[],3:[]},b=!1;function x(t){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:3;t.pri=2<arguments.length&&void 0!==arguments[2]?arguments[2]:0,w[e].push(t),b||(b=!0,Promise.resolve().then(function(){for(var t=w[1];t.length;){var e=t.sort(function(t,e){return t.pri-e.pri}),n=e.length;e.forEach(function(t){t()}),t.splice(0,n)}for(var i=w[2];i.length;){var o=i.sort(function(t,e){return t.pri-e.pri}),r=o.length;o.forEach(function(t){t()}),i.splice(0,r)}setTimeout(function(){for(var t=w[3];t.length;){var e=t.sort(function(t,e){return t.pri-e.pri}),n=e.length;e.forEach(function(t){try{t()}catch(t){console.error(t)}}),t.splice(0,n)}}),b=!1}))}function C(){}var k=0,E=function(){function e(){d(this,e),this.id=k++,this.watchers=new Set}return v(e,[{key:"removeWatcher",value:function(t){this.watchers.delete(t)}},{key:"depend",value:function(){var t=e.target;t&&(this.watchers.add(t),t.addDep(this))}},{key:"notify",value:function(){this.watchers.forEach(function(t){return t.update()})}}]),e}(),O=0,j=[],P={deep:!1,immediate:!1,lazy:!1},X=function(){function o(t,e,n){var i=3<arguments.length&&void 0!==arguments[3]?arguments[3]:P;d(this,o),this.id=O++,this.um=t,this.expOrFn=e,this.callback="function"==typeof n?n:C,this.options=i,this.initGetter(),i.lazy?(this.dirty=!0,this.deps=new Set):this.run()}return v(o,[{key:"initGetter",value:function(){var e=this;"function"==typeof this.expOrFn?this.getter=function(){try{return e.expOrFn.call(e.um)}catch(t){console.error("component ".concat(e.um.$tag," computed error"),t)}}:this.getter=function(){try{return new Function("with(this) {return ".concat(e.expOrFn,"}")).call(e.um)}catch(t){console.error("component ".concat(e.um.$tag," watch[").concat(e.expOrFn,"] error"),t)}}}},{key:"run",value:function(){j.push(this),(E.target=this).deps=new Set,this.value=this.getter(),this.dirty=!1,this.options.deep&&function e(n){"object"===y(n)&&Object.keys(n).forEach(function(t){return e(n[t])})}(this.value),j.pop(),E.target=j[j.length-1]}},{key:"update",value:function(){var t=this;this.options.lazy?this.dirty=!0:this.options.immediate?this.notify():this.updating||(this.updating=!0,x(function(){t.updating=!1,t._isDestroyed||t.notify()},1,this.id))}},{key:"notify",value:function(){var e=this,t=this.value,n=this.deps;this.run(),n.forEach(function(t){e.deps.has(t)||t.removeWatcher(e)}),(this.value!==t||Array.isArray(t)||this.options.deep)&&this.callback.call(this.um,this.value,t)}},{key:"depend",value:function(){this.deps.forEach(function(t){return t.depend()})}},{key:"addDep",value:function(t){this.deps.add(t)}},{key:"removeDep",value:function(t){this.deps.delete(t)}},{key:"destroy",value:function(){var e=this;this.deps.forEach(function(t){return t.removeWatcher(e)}),this.deps=null,this.um=null,this.expOrFn=null,this.callback=null,this._isDestroyed=!0}}]),o}(),Y=function(){function s(e,t,n){var i;d(this,s),this.um=e,this.key=t;var o=Object.prototype.toString.call(n),r="[object Function]"===o?(i=function(){return n.call(e,e)},C):"[object Object]"===o?(i="function"==typeof n.get?function(){return n.get.call(e,e)}:C,"function"==typeof n.set?n.set:C):(i=function(){return n},C),c=new X(e,i,C,{lazy:!0});this.watcher=c,Object.defineProperty(e,t,{enumerable:!1,configurable:!0,get:function(){return c.dirty&&c.run(),E.target&&c.depend(),c.value},set:function(t){r.call(e,t)}})}return v(s,[{key:"destroy",value:function(){this.watcher.destroy(),this.watcher=null,delete this.um[this.key],this.um=null,this.key=null}}]),s}();function S(u,h){var r,t;u&&"object"===y(u)&&!u.__uob__&&(Array.isArray(u)&&!u.__dep__?(r=u.__proto__,t=Object.create(r),["push","pop","shift","unshift","sort","reverse","splice"].forEach(function(o){t[o]=function(){for(var t=arguments.length,e=new Array(t),n=0;n<t;n++)e[n]=arguments[n];var i=r[o].apply(this,e);return["push","unshift"].includes(o)&&!h&&e.forEach(function(t){return S(t)}),"splice"!==o||h||e.slice(2).forEach(function(t){return S(t)}),this.__dep__.notify(),i}}),Object.defineProperty(u,"__dep__",{value:new E,enumerable:!1}),u.__proto__=t,h||u.forEach(function(t){return S(t)})):Object.keys(u).forEach(function(t){var e,n,i,o,r,c,s,a;"__ob__"!==t&&(e=u[t],o=e,r=h,a=new E(n=u,i=t),(t=Object.getOwnPropertyDescriptor(n,i))&&!1===t.configurable||(c=t&&t.get,s=t&&t.set,c&&"uaeGetter"===c.name||Object.defineProperty(n,i,{enumerable:!0,configurable:!0,get:function(){var t=c?c.call(n):o;return E.target&&(a.depend(),Array.isArray(t)&&t.__dep__.depend()),t},set:function(t){t===o||t!=t&&o!=o||(s&&s.call(n,t),"object"===y(o=t)&&(r?Array.isArray(o)&&S(o,!0):S(o)),a.notify())}})),h?Array.isArray(e)&&S(e,!0):S(e))}),Object.defineProperty(u,"__uob__",{value:!0,enumerable:!1}))}function F(t,e,n){Object.defineProperty(t,n,{enumerable:!0,configurable:!0,get:function(){return this[e][n]},set:function(t){this[e][n]=t}})}function D(t){for(var e=0<arguments.length&&void 0!==t?t:"",n=/^\s*([^\s"'<>/=]+)(?:\s*(=)\s*(?:"([^"]*)"+|'([^']*)'+|([^\s"'=<>`]+)))?/,t="[a-zA-Z_][\\-\\.0-9_a-zA-Z".concat(/a-zA-Z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD/.source,"]*"),t="((?:".concat(t,"\\:)?").concat(t,")"),i=new RegExp("^<".concat(t)),o=/^\s*(\/?)>/,r=new RegExp("^<\\/".concat(t,"[^>]*>")),c=[],s=[];e=e.trim();){var a=e.match(i);if(a){var u={tag:a[1],attr:[],attrMap:{},children:[]};s.push(u);for(var e=e.substring(a[0].length),h=void 0,f=void 0;!(h=e.match(o))&&(f=e.match(n));)u.attr.push({key:f[1],value:f[3]}),u.attrMap[f[1]]=f[3],e=e.substring(f[0].length);h&&(e=e.substring(h[0].length),"/>"===h[0].trim()&&(1<s.length?s[s.length-1].children:c).push(s.pop()))}else e.match(r)?(a=e.match(r),e=e.substring(a[0].length),(1<s.length?s[s.length-1].children:c).push(s.pop())):e=e.substring(e.indexOf("<"))}return c}function A(t,e,n,i,o){var r=this;o?(r.beginPath(),r.moveTo(t+o,e),r.lineTo(t+n-o,e),o&&r.arcTo(t+n,e,t+n,e+o,o),r.lineTo(t+n,e+i-o),o&&r.arcTo(t+n,e+i,t+n-o,e+i,o),r.lineTo(t+o,e+i),o&&r.arcTo(t,e+i,t,e+i-o,o),r.lineTo(t,e+o),o&&r.arcTo(t,e,t+o,e,o)):r.rect(t,e,n,i)}function I(e,t){var n;t.$show&&(!0===t.$offscreen?(t.$canvas&&t.$visible&&e.drawImage(t.$canvas,t.$x,t.$y),t._children.length&&(e.save(),e.translate(t.$x,t.$y),e.scale(t.$scale,t.$scale),e.translate(t.$offsetX,t.$offsetY),t._children.forEach(function(t){return I(e,t)}),e.restore())):(t._draw&&t.$visible&&(e.save(),e.beginPath(),e.rect(t.$x,t.$y,t.$width,t.$height),e.clip(),e.closePath(),e.translate(t.$x,t.$y),e.scale(t.$scale,t.$scale),e.translate(t.$offsetX,t.$offsetY),n=t.$ctx,(t.$ctx=e).save(),t._draw(),e.restore(),t.$ctx=n,e.restore()),t._children.length&&(e.save(),"hidden"===t.$overflow&&(e.beginPath(),e.rect(t.$x,t.$y,t.$width,t.$height),e.clip(),e.closePath()),e.translate(t.$x,t.$y),e.scale(t.$scale,t.$scale),e.translate(t.$offsetX,t.$offsetY),t._children.forEach(function(t){return I(e,t)}),e.restore())),z.config.guide&&(e.save(),e.lineWidth=.2,e.strokeStyle="red",e.strokeRect(t.$x+.5,t.$y+.5,t.$width-1,t.$height-1),e.restore()))}var M=document.createElement("canvas").getContext("2d");M.roundRect=A;var R=function(){function t(){d(this,t)}return v(t,[{key:"_init",value:function(){this._initBaseData(),this._beforeCreate(),this._initProps(),this._initData(),this._created(),this._initMethods(),this._initComputed(),this._initConfig(),this._beforeMount(),this._initChildrenDef(),this._initChildren(),this._childrenInited(),this._initCanvas(),this._initDraw(),this._mixChildGraph(),this._initWatch(),this._mounted(),this._isMounted=!0}},{key:"_initBaseData",value:function(){var t,e=this;this._watchers=[],this._computeds=[],this._redrawRects=[],this._configs={},this._mixins=[],(t=this._mixins).push.apply(t,_),this._options.mixins&&(n=this._mixins).push.apply(n,l(this._options.mixins)),this._mixins.push(this._options),this._mixins.forEach(function(t){t.config&&"function"!=typeof t.config&&Object.assign(e._configs,t.config),"function"==typeof t.isHere&&(e._isHere=t.isHere),"function"==typeof t.draw&&(e._draw=t.draw)});var n={$children:[]};this._property=n,Object.keys(n).forEach(function(t){F(e,"_property",t)}),S(n,!0)}},{key:"_beforeCreate",value:function(){var e=this;this._mixins.forEach(function(t){return"function"==typeof t.beforeCreate&&t.beforeCreate.call(e)})}},{key:"_created",value:function(){var e=this;this._mixins.forEach(function(t){return"function"==typeof t.created&&t.created.call(e)})}},{key:"_beforeMount",value:function(){var e=this;this._mixins.forEach(function(t){return"function"==typeof t.beforeMount&&t.beforeMount.call(e)})}},{key:"_mounted",value:function(){var e=this;this._mixins.forEach(function(t){return"function"==typeof t.mounted&&t.mounted.call(e)})}},{key:"_beforeDestroy",value:function(){var e=this;this._mixins.forEach(function(t){return"function"==typeof t.beforeDestroy&&t.beforeDestroy.call(e)})}},{key:"_destroyed",value:function(){var e=this;this._mixins.forEach(function(t){return"function"==typeof t.destroyed&&t.destroyed.call(e)})}},{key:"_initProps",value:function(){var e,n=this;this.$parent&&(this._props=e={},this._mixins.forEach(function(t){Array.isArray(t.props)&&t.props.forEach(function(t){e[t]=n.$attr[t]})}),Object.keys(e).forEach(function(t){F(n,"_props",t)}),S(e,!0))}},{key:"_initData",value:function(){var e=this,n={};this._mixins.forEach(function(t){t.data&&Object.assign(n,"function"==typeof t.data?t.data.call(e):t.data)}),this.$data=this._data=n,Object.keys(n).forEach(function(t){F(e,"_data",t)}),S(n)}},{key:"_initMethods",value:function(){var n=this;this._mixins.forEach(function(e){e.methods&&Object.keys(e.methods).forEach(function(t){n[t]=e.methods[t]})})}},{key:"_initComputed",value:function(){var e=this,n={};this._mixins.forEach(function(e){e.computed&&Object.keys(e.computed).forEach(function(t){n[t]=e.computed[t]})}),Object.keys(n).forEach(function(t){e._computeds.push(new Y(e,t,n[t]))})}},{key:"_getConfig",value:function(t){t=this._configs[t];return"function"==typeof t?t.call(this,this):t}},{key:"_initConfig",value:function(){var h=this;this._computeds.push(new Y(this,"$viewport",function(){return{x:h.$toCanvasX(0),y:h.$toCanvasY(0),width:h.$width,height:h.$height}})),this._computeds.push(new Y(this,"$zIndexToComps",function(){var n={};return h.$children.forEach(function(t){var e;n[t.$zIndex]=null!==(e=n[t.$zIndex])&&void 0!==e?e:[],n[t.$zIndex].push(t)}),n})),this._computeds.push(new Y(this,"$sortComps",function(){var e=[],n=h.$zIndexToComps;return Object.keys(n).sort(function(t,e){return Number(t)-Number(e)}).forEach(function(t){return e.push.apply(e,l(n[t]))}),e})),this._computeds.push(new Y(this,"_children",function(){var e=[];if(!h.$parent)return[];var n=h.$zIndexToComps,t=Object.keys(n).sort(function(t,e){return Number(t)-Number(e)});return!0===h.$offscreen&&"visible"!==h.$overflow||t.forEach(function(t){return e.push.apply(e,l(n[t]))}),e})),this._computeds.push(new Y(this,"$offsetX",function(){var t=h._getConfig("offsetX");return"number"==typeof t?t:0})),this._computeds.push(new Y(this,"$offsetY",function(){var t=h._getConfig("offsetY");return"number"==typeof t?t:0})),this.$parent?(this._computeds.push(new Y(this,"$show",function(){var t=h._getConfig("show");return"boolean"!=typeof t||t})),this._computeds.push(new Y(this,"$x",function(){var t=h._getConfig("x");return"number"==typeof t?t:0})),this._computeds.push(new Y(this,"$y",function(){var t=h._getConfig("y");return"number"==typeof t?t:0})),this._computeds.push(new Y(this,"$width",function(){var t=h._getConfig("width");return"number"==typeof t?t:h.$parent.$width})),this._computeds.push(new Y(this,"$height",function(){var t=h._getConfig("height");return"number"==typeof t?t:h.$parent.$height})),this._computeds.push(new Y(this,"$zIndex",function(){var t=h._getConfig("zIndex");return"number"==typeof t?t:0})),this._computeds.push(new Y(this,"$overflow",function(){var t=h._getConfig("overflow");return["hidden","visible"].includes(t)?t:"hidden"})),this._computeds.push(new Y(this,"$visible",function(){for(var t=h.$x,e=h.$y,n=h.$width,i=h.$height,o=h.$parent;"visible"===o.$overflow;)t=o.$toOriginalX(t)+o.$x,e=o.$toOriginalY(e)+o.$y,n*=o.$scale,i*=o.$scale,o=o.$parent;var r=o.$viewport;return t<=r.x+r.width&&e<=r.y+r.height&&t+n>=r.x&&e+i>=r.y||("number"!=typeof h._getConfig("width")||"number"!=typeof h._getConfig("height"))})),this._computeds.push(new Y(this,"$cScale",function(){if(!0===h.$offscreen)return 1;if(!1===h.$offscreen)return 0;var t=1e4/(h.$width*h.$height);return 1<t?1:Math.sqrt(t)})),this._computeds.push(new Y(this,"$bounds",function(){var s=h.$x,a=h.$y,u=[{x:s,y:a,width:h.$width,height:h.$height}];return"visible"===h.$overflow&&h.$children.forEach(function(t){t.$bounds.forEach(function(t){for(var e=h.$toOriginalX(t.x)+s,n=h.$toOriginalY(t.x+t.width)+s,i=h.$toOriginalX(t.y)+a,o=h.$toOriginalY(t.y+t.height)+a,r=0;r<u.length;r++){var c=u[r];if(e<=c.x&&i<=c.y&&n>=c.x+c.width&&o>=c.y+c.height){u[r]={x:e,y:i,width:n-e,height:o-i};break}if(!(c.x<=e&&c.y<=i&&c.x+c.width>=n&&c.y+c.height>=o)){u.push({x:e,y:i,width:n-e,height:o-i});break}}})}),u})),this._computeds.push(new Y(this,"$offscreen",function(){if(!1===h.$root._configs.offscreen)return!1;var t=h._configs.offscreen;return"boolean"==typeof t?t:void 0})),this._computeds.push(new Y(this,"$scale",function(){var t=h._getConfig("scale");return"number"==typeof t?t:1}))):(this.$x=0,this.$y=0,this._computeds.push(new Y(this,"$scale",function(){var t="number"==typeof(t=h._getConfig("scale"))?t:1;return t*=h.$ratio})),this._computeds.push(new Y(this,"$width",function(){return h.$canvas.width/h.$scale})),this._computeds.push(new Y(this,"$height",function(){return h.$canvas.height/h.$scale})),this.$zIndex=0,this.$overflow="hidden",this.$visible=!0,this.$offscreen=!0)}},{key:"_initWatch",value:function(){var n=this,i={};this._mixins.forEach(function(e){e.watch&&Object.keys(e.watch).forEach(function(t){i[t]=e.watch[t]})}),Object.keys(i).forEach(function(t){var e;"function"==typeof i[t]?n._watchers.push(new X(n,t,i[t])):"object"===y(i[t])?(e=i[t],n._watchers.push(new X(n,t,e.handler||C,{deep:e.deep||!1,immediate:e.immediate||!1,lazy:e.lazy||!1}))):console.warn("watcher can not support this type value",i[t])})}},{key:"_initChildrenDef",value:function(){var t,e=this,n=this._mixins.filter(function(t){return t.template}).map(function(t){return t.template}).join("");this.$parent?(m[n]=null!==(t=m[n])&&void 0!==t?t:D(n),this._childDefs=m[n]):this._childDefs=D(n);var i=[];this._childDefs.forEach(function(t){var e;t.attrMap["v-if"]&&(e=t.attrMap["v-if"].trim(),i.push(e)),t.attrMap["v-for"]&&(t=t.attrMap["v-for"].split(" in ")[1].trim(),i.push(t))}),i.length&&this._watchers.push(new X(this,"{".concat(i.map(function(t){return'"'.concat(t,'":').concat(t)}).join(","),"}"),function(){e._initChildren()}))}},{key:"_initChildren",value:function(){var c,s,a,u=this;0<this._childDefs.length&&(c=this.$children,s=c.filter(function(t){return t._vForItem}),a=s.map(function(t){return t._vForItem}),this._tempChildren=[],this._childDefs.forEach(function(t,e){if(t.attrMap["v-if"]){var n=t.attrMap["v-if"].trim();if(!new Function("with(this) {return ".concat(n,"}")).call(u))return}var i,o,r;t.attrMap["v-for"]?(n=(i=t.attrMap["v-for"].split(" in "))[0],i=i[1].trim(),(n=n.startsWith("(")?n.substring(1):n).endsWith(")")&&(n=n.substr(0,n.length-1)),new Function("def","vForComps","vForItems","with(this) {\n let idx = 0;\n ".concat(i,".forEach((").concat(n,") => {\n let comp = vForComps[vForItems.indexOf(").concat(n.split(",")[0],")];\n const _index = '").concat(e,".' + idx;\n if (!comp) {\n comp = _createComp(def, {").concat(n,"});\n _bindCompEvent(comp, def, {").concat(n,"});\n comp._vForItem = ").concat(n.split(",")[0],";\n } else if (comp._index !== _index) {\n const attr = this._getAttr(def, {").concat(n,"});\n for (let key in comp._props) {\n if (comp[key] !== attr[key]) {\n comp[key] = attr[key];\n }\n }\n _bindCompEvent(comp, def, {").concat(n,"}, true);\n }\n comp._index = _index;\n _tempChildren.push(comp);\n idx++;\n })\n }")).call(u,t,s,a)):(r="".concat(e),c.forEach(function(t){if(t._index===r)return o=t,!1}),o||(o=u._createComp(t),u._bindCompEvent(o,t),o._index=r),u._tempChildren.push(o))}),this._tempChildren.forEach(function(t){u._isMounted&&!c.includes(t)&&u._redraw.apply(u,l(t.$bounds))}),c.forEach(function(t){u._tempChildren.includes(t)||(u._redraw.apply(u,l(t.$bounds)),t.$destroy())}),this.$children=this._tempChildren,this._tempChildren=null)}},{key:"_childrenInited",value:function(){var i=this;this.$parent?this._watchers.push(new X(this,function(){return{width:i.$width,height:i.$height,offsetX:i.$offsetX,offsetY:i.$offsetY,scale:i.$scale}},function(){i.$canvas&&(i.$canvas.width=i.$width*i.$cScale,i.$canvas.height=i.$height*i.$cScale,i.$ctx.scale(i.$scale*i.$cScale,i.$scale*i.$cScale),i.$ctx.translate(i.$offsetX,i.$offsetY)),i._redraw(i.$viewport)}),new X(this,"$show",function(){var t;(t=i.$parent)._redraw.apply(t,l(i.$bounds))}),new X(this,function(){return{zIndex:i.$zIndex,bounds:i.$bounds}},function(t,e){var n;(n=i.$parent)._redraw.apply(n,l(t.bounds).concat(l(e.bounds)))})):this._watchers.push(new X(this,function(){return{offsetX:i.$offsetX,offsetY:i.$offsetY,scale:i.$scale}},function(){i.$ctx&&(i.$canvas.width=i.$canvas.width,i.$ctx.scale(i.$scale,i.$scale),i.$ctx.translate(i.$offsetX,i.$offsetY)),i._redraw(i.$viewport)}))}},{key:"_initCanvas",value:function(){if(!this.$parent)return this.$ctx.scale(this.$scale,this.$scale),void this.$ctx.translate(this.$offsetX,this.$offsetY);!1!==this.$offscreen&&(this.$canvas=document.createElement("canvas"),this.$ctx=this.$canvas.getContext("2d"),this.$ctx.roundRect=A,this.$canvas.width=this.$width*this.$cScale,this.$canvas.height=this.$height*this.$cScale,this.$ctx.scale(this.$scale*this.$cScale,this.$scale*this.$cScale),this.$ctx.translate(this.$offsetX,this.$offsetY))}},{key:"_initDraw",value:function(){var e=this;this._draw&&this._watchers.push(new X(this,function(){return e.$ctx?(e.$ctx.clearRect(-e.$offsetX,-e.$offsetY,e.$width,e.$height),e.$ctx.beginPath(),e._draw()):(e.$ctx=M,e.$ctx.beginPath(),e._draw(),e.$ctx=null),Symbol("draw")},function(){var t;e._mixChildGraph([e.$viewport]),e.$parent&&(t=e.$parent)._redraw.apply(t,l(e.$bounds))}))}},{key:"_mixChildGraph",value:function(){var e,n=this,i=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];0===this._children.length&&(e=this.$zIndexToComps,Object.keys(e).sort(function(t,e){return Number(t)-Number(e)}).forEach(function(t){e[t].forEach(function(t){(!i.length||function(t,e){for(var n=0;n<t.length;n++)for(var i=t[n],o=i.y,r=i.x+i.width,c=i.y+i.height,s=i.x,a=0;a<e.length;a++){var u=e[a];if(r>=u.x&&s<=u.x+u.width&&c>=u.y&&o<=u.y+u.height)return 1}}(t.$bounds,i))&&I(n.$ctx,t)})}))}},{key:"_getAttr",value:function(t){var i=this,o=t.attrMap,r=t.tag,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c={},s=Object.keys(e),a=s.map(function(t){return e[t]});return Object.keys(o).forEach(function(e){var n=o[e];if("v-for"!==e&&"v-if"!==e&&!e.startsWith("@")){if(e.startsWith(":")){e=e.substring(1);try{var t,n=(t=h(Function,l(s).concat(["with(this) {return ".concat(n,"}")]))).call.apply(t,[i].concat(l(a)))}catch(t){console.error("component ".concat(i.$tag," template ").concat(r," attribute ").concat(e," value is wrong"),t),n=void 0}}c[e]=n}}),c}},{key:"_getEvents",value:function(t){var i=this,o=t.attrMap,r=t.tag,e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},c={},s=Object.keys(e),a=s.map(function(t){return e[t]}),u=/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/;return Object.keys(o).forEach(function(e){var t,n=o[e];if(e.startsWith("@"))if(e=e.substring(1),u.test(n))try{c[e]=(t=h(Function,l(s).concat(["with(this) {return ".concat(n,"}")]))).call.apply(t,[i].concat(l(a)))}catch(t){console.error("component ".concat(i.$tag," template ").concat(r," attribute ").concat(e," value is wrong"),t)}else c[e]=function(){var t;(t=h(Function,l(s).concat(["with(this) {return ".concat(n,"}")]))).call.apply(t,[i].concat(l(a)))}}),c}},{key:"_createComp",value:function(t,e){var n,i,o=this,r=new X(this,function(){return i=o._getAttr(t,e),Symbol("attr")},function(){Object.keys(n._props).forEach(function(t){n[t]!==i[t]&&(n[t]=i[t])})}),c={};return Object.assign(c,i,{_is:"component"===t.tag?i.is:t.tag,_root:this.$root,_parent:this}),(n=new B(c))._watchers.push(r),n}},{key:"_bindCompEvent",value:function(e,t,n){var i=3<arguments.length&&void 0!==arguments[3]&&arguments[3],o=this._getEvents(t,n);Object.keys(o).forEach(function(t){e.$on(t,o[t],i)})}},{key:"_isPointInHere",value:function(t,e){return!(!this.$visible||!this.$show)&&(this._isHere?this._isHere(t,e):this.$isPointInHere(t,e))}},{key:"_redraw",value:function(){for(var t,a,u=this,e=arguments.length,n=new Array(e),i=0;i<e;i++)n[i]=arguments[i];this.$parent&&(t=this.$parent)._redraw.apply(t,l(n.map(function(t){return{x:u.$toOriginalX(t.x)+u.$x,y:u.$toOriginalY(t.y)+u.$y,width:t.width*u.$scale,height:t.height*u.$scale}}))),!0===this.$offscreen&&"visible"!==this.$overflow&&(a=this.$viewport,n.forEach(function(t){var e,n,i,o,r,c,s;(t=function(t,e){var n=t.y,i=t.x+t.width,o=t.y+t.height,r=t.x,c=e.y,s=e.x+e.width,t=e.y+e.height,e=e.x;if(!(i<e||s<r||o<c||t<n)){e=Math.max(r,e),c=Math.max(n,c);return{x:e,y:c,width:Math.min(i,s)-e,height:Math.min(o,t)-c}}}(t,a))&&(e=(i=t).x,n=i.y,t=i.width,i=i.height,--n,t+=2,i+=2,o=u._getLowPixelX(--e),r=u._getLowPixelY(n),c=u._getLowPixelX(e+t)-o,s=u._getLowPixelY(n+i)-r,0===u._redrawRects.filter(function(t){return t.x===o&&t.y===r&&t.width===c&&t.height===s}).length&&u._redrawRects.push({x:o,y:r,width:c,height:s}))}),this._redrawing||(this._redrawing=!0,x(function(){u._redrawing=!1;var t=u._redrawRects,e=t.length,n=u.$ctx;n.save(),n.beginPath(),t.forEach(function(t){n.rect(t.x,t.y,t.width,t.height)}),n.clip(),n.closePath(),n.clearRect(-u.$offsetX,-u.$offsetY,u.$width,u.$height),u._draw&&(n.save(),u._draw(),n.restore()),u._mixChildGraph(t),n.restore(),u._redrawRects.splice(0,e)},2,this.$deep)))}},{key:"_getLowPixelX",value:function(t){var e=t+this.$offsetX,n=this.$scale;return t-(e*n-Math.floor(e*n))/n}},{key:"_getHighPixelX",value:function(t){var e=t+this.$offsetX,n=this.$scale;return t+(1-e*n+Math.floor(e*n))/n}},{key:"_getLowPixelY",value:function(t){var e=t+this.$offsetY,n=this.$scale;return t-(e*n-Math.floor(e*n))/n}},{key:"_getHighPixelY",value:function(t){var e=t+this.$offsetY,n=this.$scale;return t+(1-e*n+Math.floor(e*n))/n}},{key:"$toCanvasX",value:function(t){return t/this.$scale-this.$offsetX}},{key:"$toCanvasY",value:function(t){return t/this.$scale-this.$offsetY}},{key:"$toOriginalX",value:function(t){return(t+this.$offsetX)*this.$scale}},{key:"$toOriginalY",value:function(t){return(t+this.$offsetY)*this.$scale}},{key:"$nextTick",value:function(t){var e=this;x(function(){return t.call(e)})}},{key:"$findCompById",value:function(t){if(t){var e=this.$children;if((e=!e||!e.length?this._tempChildren:e)&&e.length)for(var n=e.length-1;0<=n;n--){var i=e[n];if(i.$id===t)return i;if(i=i.$findCompById(t))return i}}}},{key:"$findCompByRect",value:function(e,n,i,o){return this.$children.filter(function(t){return t.$show&&e<=t.$x&&n<=t.$y&&e+i>=t.$x+t.$width&&n+o>=t.$y+t.$height})}},{key:"$findCompByPoint",value:function(t,e){if(0!==this.$children.length)for(var n=this.$sortComps,i=n.length-1;0<=i;i--){var o=n[i],r=o.$toCanvasX(t-o.$x),c=o.$toCanvasY(e-o.$y),s=o.$isPointInBox(r,c);if(o.$show&&("visible"===o.$overflow||s)){var a=o.$findCompByPoint(r,c);if(a)return a}if(s&&o._isPointInHere(r,c))return o}}},{key:"$findCompAndCoorByPoint",value:function(t,e){if(0!==this.$children.length)for(var n=this.$sortComps,i=n.length-1;0<=i;i--){var o=n[i],r=o.$toCanvasX(t-o.$x),c=o.$toCanvasY(e-o.$y),s=o.$isPointInBox(r,c);if(o.$show&&("visible"===o.$overflow||s)){var a=o.$findCompAndCoorByPoint(r,c);if(a)return a}if(s&&o._isPointInHere(r,c))return{comp:o,compCx:r,compCy:c}}}},{key:"$isPointInHere",value:function(t,e){if(this.$ctx)for(var t=this.$toOriginalX(t)*this.$cScale,e=this.$toOriginalY(e)*this.$cScale,n=this.$ctx.getImageData(t,e,1,1),i=n.data.length,o=3;o<i;o+=4)if(n.data[o])return!0;return!1}},{key:"$isPointInBox",value:function(t,e){t=this.$toOriginalX(t),e=this.$toOriginalY(e);return 0<=t&&t<=this.$width&&0<=e&&e<=this.$height}},{key:"$destroy",value:function(){var t=!this.$parent;this._beforeDestroy(),this.$children.forEach(function(t){return t.$destroy()}),t&&(document.removeEventListener(z.config.focusEvent,this.mouseup),this.$events=null),this._computeds.forEach(function(t){return t.destroy()}),this._computeds=[],this._watchers.forEach(function(t){return t.destroy()}),this._watchers=[],this.$children=[],this.$ctx=null,this.$canvas=null,this._destroyed(),this._isDestroyed=!0}},{key:"$on",value:function(t,e){var n,i,o=2<arguments.length&&void 0!==arguments[2]&&arguments[2];t&&"function"==typeof e&&(this.$events=null!==(n=this.$events)&&void 0!==n?n:{},this.$events[t]=!o&&null!==(i=this.$events[t])&&void 0!==i?i:[],this.$events[t].push(e))}},{key:"$off",value:function(t,n){var e,i,o,r=this;t&&n?-1!==(i=(e=null!==(i=null===(e=this.$events)||void 0===e?void 0:e[t])&&void 0!==i?i:[]).indexOf(n))&&e.splice(i,1):t?null===(i=this.$events)||void 0===i||null!==(o=i[t])&&void 0!==o&&o.splice(0):n?Object.keys(null!==(o=this.$events)&&void 0!==o?o:{}).forEach(function(t){var t=null!==(e=null===(e=r.$events)||void 0===e?void 0:e[t])&&void 0!==e?e:[],e=t.indexOf(n);-1!==e&&t.splice(e,1)}):this.$events=null}},{key:"$emit",value:function(t){for(var e,n=this,i=arguments.length,o=new Array(1<i?i-1:0),r=1;r<i;r++)o[r-1]=arguments[r];null===(e=this.$events)||void 0===e||null!==(t=e[t])&&void 0!==t&&t.forEach(function(t){return t.call.apply(t,[null!==(t=n.$parent)&&void 0!==t?t:n].concat(o))})}},{key:"$getComponentDefinition",value:function(t){return t?g[t]:i({},g)}}]),t}(),z=function(){r(o,R);var n=c(o);function o(t){var e;d(this,o),(e=n.call(this))._options=t,e.$canvas=t.canvas,e.$ctx=e.$canvas.getContext("2d"),e.$ctx.roundRect=A,e.$root=s(e),e.$tag="root",e.$deep=0,e._index="root";t=(t=e.$ctx).backingStorePixelRatio||t.webkitBackingStorePixelRatio||t.mozBackingStorePixelRatio||t.msBackingStorePixelRatio||t.oBackingStorePixelRatio||t.backingStorePixelRatio||1,t=(window.devicePixelRatio||1)/t;return e.$canvas.style.width="".concat(e.$canvas.width,"px"),e.$canvas.style.height="".concat(e.$canvas.height,"px"),e.$canvas.width*=t,e.$canvas.height*=t,e.$ratio=t,e._init(),e._bind(),e}return v(o,[{key:"_bind",value:function(){var $,s,v,y,m=this,g=this.$canvas,_=!1,i={mousemove:function(t){var e=m.$toCanvasX(t.offsetX*m.$ratio),n=m.$toCanvasY(t.offsetY*m.$ratio),i=null!==(r=m.$findCompAndCoorByPoint(e,n))&&void 0!==r?r:{},o=i.comp,r=i.compCx,i=i.compCy;s=r,v=i,o!==$?($&&($.$emit("mouseleave"),_&&$.$emit("dragleave")),($=o)&&(o={e:t,comp:$,x:r,y:i},$.$emit("mouseenter",o),_&&$.$emit("dragenter",o))):$&&(i={e:t,comp:$,x:r,y:i},$.$emit("mousemove",i),_&&$.$emit("dragover",i)),m.$emit("mousemove",{e:t,comp:$,x:e,y:n})},click:function(t){var e=m.$toCanvasX(t.offsetX*m.$ratio),n=m.$toCanvasY(t.offsetY*m.$ratio);$&&$.$emit("click",{e:t,comp:$,x:s,y:v}),m.$emit("click",{e:t,comp:$,x:e,y:n})},dblclick:function(t){var e=m.$toCanvasX(t.offsetX*m.$ratio),n=m.$toCanvasY(t.offsetY*m.$ratio);$&&$.$emit("dblclick",{e:t,comp:$,x:s,y:v}),m.$emit("dblclick",{e:t,comp:$,x:e,y:n})},contextmenu:function(t){var e=m.$toCanvasX(t.offsetX*m.$ratio),n=m.$toCanvasY(t.offsetY*m.$ratio);$&&$.$emit("contextmenu",{e:t,comp:$,x:s,y:v}),m.$emit("contextmenu",{e:t,comp:$,x:e,y:n})},mousedown:function(t){var a=t.offsetX*m.$ratio,u=t.offsetY*m.$ratio,h=m.$toCanvasX(a),f=m.$toCanvasY(u),e=null!==(n=m.$findCompAndCoorByPoint(h,f))&&void 0!==n?n:{},l=e.comp,n=e.compCx,e=e.compCy;null!=l&&l.$emit("mousedown",{e:t,comp:l,x:n,y:e}),m.$emit("mousedown",{e:t,comp:l,x:h,y:f});function c(t){var e=t.offsetX*m.$ratio,n=t.offsetY*m.$ratio,i=m.$toCanvasX(e),o=m.$toCanvasY(n),r=(e-a)/m.$scale,c=(n-u)/m.$scale,s=r-p,e=c-d;d=c,((p=r)||c)&&(_||(_=!0,n={e:t,comp:y=l,x:h,y:f},y&&(y.$dragging=!0,y.$emit("dragstart",n)),m.$emit("dragstart",n)),o={e:t,comp:y,hComp:$,dx:r,dy:c,ddx:s,ddy:e,x:i,y:o},null!==y&&void 0!==y&&y.$emit("drag",o),m.$emit("drag",o))}var p=0,d=0,t=function t(e){var n,i,o,r;g.removeEventListener("mousemove",c),document.removeEventListener("mouseup",t),_&&(i=e.offsetX*m.$ratio,o=e.offsetY*m.$ratio,n=m.$toCanvasX(i),r=m.$toCanvasY(o),i=(i-a)/m.$scale,o=(o-u)/m.$scale,r={e:e,comp:y,hcomp:$,hoverComp:$,dx:i,dy:o,ddx:i-p,ddy:o-d,x:n,y:r},y&&(y.$dragging=!1,y.$emit("dragend",r)),null!==$&&void 0!==$&&$.$emit("drop",{e:e,comp:$,x:s,y:v}),m.$emit("dragend",r),y=null,_=!1)};g.addEventListener("mousemove",c),document.addEventListener("mouseup",t)},mouseenter:function(t){var e=m.$toCanvasX(t.offsetX*m.$ratio),n=m.$toCanvasY(t.offsetY*m.$ratio),i=m.$findCompByPoint(e,n);m.$emit("mouseenter",{e:t,hComp:i,x:e,y:n})}};g.addEventListener("mousemove",i.mousemove),g.addEventListener("click",i.click),g.addEventListener("dblclick",i.dblclick),g.addEventListener("contextmenu",i.contextmenu),g.addEventListener("mousedown",i.mousedown),g.addEventListener("mouseenter",i.mouseenter),this.mouseup=function(t){var e=window.getComputedStyle(m.$canvas).display;""!==e&&"none"!==e&&t.target===m.$canvas?m.focus=!0:m.focus=!1},document.addEventListener(o.config.focusEvent,this.mouseup),this.$trigger=function(t,e){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};null!==(t=i[t])&&void 0!==t&&t.call(i,e),void 0!==n.dcomp&&($=n.dcomp),void 0!==n.hComp&&($=n.hComp),void 0!==n.hcompCx&&($=n.hcompCx),void 0!==n.hcompCy&&($=n.hcompCy)}}}]),o}(),B=function(){r(i,R);var n=c(i);function i(t){var e;if(d(this,i),(e=n.call(this)).$tag=t._is,e.$id=t.id,e.$parent=t._parent,e.$root=t._root,e.$attr=t,e.$deep=e.$parent.$deep-1,e._options=g[t._is],!e._options)throw new Error("组件".concat(e.$tag,"没有定义,请排查组件").concat(e.$parent.$tag,"下的template定义是否有错"));return e._init(),e}return i}();z.component=function(n,t){if(n&&t){if(g[n]&&(m[n]=null,console.warn("component ".concat(n," has registry, will cover old component"))),t.data&&"function"!=typeof t.data)throw new Error("".concat(n,":data must is a function"));if("function"==typeof t.config)throw new Error("".concat(n,":钩子函数config已经废弃,请使用config键值对对象进行配置"));t.mixins&&t.mixins.forEach(function(t,e){if(t.data&&"function"!=typeof t.data)throw new Error("".concat(n,": mixins[").concat(e,"] data must is a function"));if("function"==typeof t.config)throw new Error("".concat(n,":mixins[").concat(e,"],钩子函数config已经废弃,请使用config键值对对象配置"))}),g[n]=t}},z.getComponentDefinition=function(t){return t?g[t]:i({},g)},z.mixin=function(t){if("function"==typeof t.config)throw new Error("mixin:钩子函数config已经废弃,请使用config键值对对象进行配置");_.push(t)},z.config={focusEvent:"mouseup"},z.nextTick=x,e.default=z}],i={},o.m=n,o.c=i,o.d=function(t,e,n){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(e,t){if(1&t&&(e=o(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)o.d(n,i,function(t){return e[t]}.bind(null,i));return n},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=0).default;function o(t){if(i[t])return i[t].exports;var e=i[t]={i:t,l:!1,exports:{}};return n[t].call(e.exports,e,e.exports,o),e.l=!0,e.exports}var n,i});