@eva/plugin-renderer-mask 1.2.7 → 1.2.8-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  window.EVA = window.EVA || {};
4
4
  window.EVA.plugin = window.EVA.plugin || {};
@@ -430,9 +430,10 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
430
430
  if (changed.prop.prop[0] === 'type') {
431
431
  this.changedCache[changed.gameObject.id] = true;
432
432
 
433
- if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1) {
433
+ if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1 || component._lastType !== component.type) {
434
434
  this.remove(changed);
435
435
  this.add(changed);
436
+ component._lastType = component.type;
436
437
  } else {
437
438
  this.redrawGraphics(changed);
438
439
  }
@@ -1 +1 @@
1
- function _extends(){return(_extends=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{},window.EVA.plugin.renderer=window.EVA.plugin.renderer||{};var _EVA_IIFE_mask=function(e,t,r,n){"use strict";var o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function i(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function a(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a}function c(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function c(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,c)}s((n=n.apply(e,t||[])).next())}))}function s(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function p(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}function l(e){return function(t,r){var n=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,r);n.key=r,n.type=e}}e.MASK_TYPE=void 0,function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(e.MASK_TYPE||(e.MASK_TYPE={}));var u,h=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.style={},t.resource="",t.spriteName="",t}return i(t,e),t.prototype.init=function(e){_extends(this,e)},t.componentName="Mask",a([l("string")],t.prototype,"resource",void 0),a([l("string")],t.prototype,"spriteName",void 0),t}(t.Component),d={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},y={Circle:"drawCircle",Ellipse:"drawEllipse",Rect:"drawRect",RoundedRect:"drawRoundedRect",Polygon:"drawPolygon"};!function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(u||(u={}));var f=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="Mask",t.changedCache={},t.maskSpriteCache={},t}return i(o,e),o.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(){this.changedCache={}},o.prototype.componentChanged=function(e){if("Mask"===e.component.name)switch(e.type){case t.OBSERVER_TYPE.ADD:this.add(e);break;case t.OBSERVER_TYPE.REMOVE:this.remove(e);break;case t.OBSERVER_TYPE.CHANGE:this.change(e)}},o.prototype.add=function(e){var t,r=e.component;if(!(r.type in u))throw new Error("no have Mask type: "+r.type);if(!r.style)throw new Error("no have Mask style: "+r.type);switch(r.type){case u.Circle:case u.Ellipse:case u.Rect:case u.RoundedRect:case u.Polygon:t=this.createGraphics(r);break;case u.Img:case u.Sprite:t=this.createSprite(r)}if(!t)throw new Error("no have mask instance, check your mask params: "+r.type);var n=this.containerManager.getContainer(e.gameObject.id);n.mask=t,n.addChild(t)},o.prototype.remove=function(e){var t=this.containerManager.getContainer(e.gameObject.id);t.removeChild(t.mask),t.mask.destroy({children:!0}),t.mask=null,delete this.maskSpriteCache[e.gameObject.id]},o.prototype.change=function(e){if(!this.changedCache[e.gameObject.id]){var t=e.component;"type"===e.prop.prop[0]?(this.changedCache[e.gameObject.id]=!0,[u.Sprite,u.Img].indexOf(t.type)>-1?(this.remove(e),this.add(e)):this.redrawGraphics(e)):"style"===e.prop.prop[0]?[u.Sprite,u.Img].indexOf(t.type)>-1?this.changeSpriteStyle(t):this.redrawGraphics(e):("resource"===e.prop.prop[0]||"spriteName"===e.prop.prop[0])&&(this.changedCache[e.gameObject.id]=!0,this.changeSprite(t))}},o.prototype.createGraphics=function(e){var t=new n.Graphics;return this.draw(t,e),t},o.prototype.redrawGraphics=function(e){var t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)},o.prototype.draw=function(e,t){var r,n,o=[];try{for(var i=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(d[t.type]),a=i.next();!a.done;a=i.next()){var c=a.value;o.push(t.style[c])}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}e.beginFill(0,1),e[y[t.type]].apply(e,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(p(arguments[t]));return e}(o)),e.endFill()},o.prototype.createSprite=function(e){var t=new n.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite},o.prototype.changeSpriteStyle=function(e){var t=this.maskSpriteCache[e.gameObject.id];t.sprite.width=e.style.width,t.sprite.height=e.style.height,t.sprite.position.x=e.style.x,t.sprite.position.y=e.style.y},o.prototype.changeSprite=function(e){var t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)},o.prototype.setSprite=function(e,r){return c(this,void 0,void 0,(function(){var n,o,i,a;return s(this,(function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),o=this.increaseAsyncId(e.gameObject.id),[4,t.resource.getResource(e.resource)];case 1:return n=c.sent(),this.validateAsyncId(e.gameObject.id,o)?[3,3]:[2];case 2:throw c.sent(),new Error("mask resource load error");case 3:return e.type===u.Sprite?(i=e.resource+"_s|r|c_"+e.spriteName,a=n.instance[i],r.image=a):r.image=n.data.image,r.sprite.width=e.style.width,r.sprite.height=e.style.height,r.sprite.position.x=e.style.x,r.sprite.position.y=e.style.y,[2]}}))}))},o.systemName="Mask",o=a([t.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],o)}(r.Renderer);return e.Mask=h,e.MaskSystem=f,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter);window.EVA.plugin.renderer.mask=window.EVA.plugin.renderer.mask||_EVA_IIFE_mask;
1
+ function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},_extends.apply(this,arguments)}window.EVA=window.EVA||{},window.EVA.plugin=window.EVA.plugin||{},window.EVA.plugin.renderer=window.EVA.plugin.renderer||{};var _EVA_IIFE_mask=function(e,t,r,n){"use strict";var o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])},o(e,t)};function i(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function a(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a}function c(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{s(n.next(e))}catch(e){i(e)}}function c(e){try{s(n.throw(e))}catch(e){i(e)}}function s(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,c)}s((n=n.apply(e,t||[])).next())}))}function s(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function p(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}function l(e){return function(t,r){var n=function(e,t){return e.constructor.IDEProps||(e.constructor.IDEProps={}),e.constructor.IDEProps[t]||(e.constructor.IDEProps[t]={}),e.constructor.IDEProps[t]}(t,r);n.key=r,n.type=e}}e.MASK_TYPE=void 0,function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(e.MASK_TYPE||(e.MASK_TYPE={}));var u,h=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.style={},t.resource="",t.spriteName="",t}return i(t,e),t.prototype.init=function(e){_extends(this,e)},t.componentName="Mask",a([l("string")],t.prototype,"resource",void 0),a([l("string")],t.prototype,"spriteName",void 0),t}(t.Component),d=h,y={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},f={Circle:"drawCircle",Ellipse:"drawEllipse",Rect:"drawRect",RoundedRect:"drawRoundedRect",Polygon:"drawPolygon"};!function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(u||(u={}));var g=function(e){function o(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="Mask",t.changedCache={},t.maskSpriteCache={},t}return i(o,e),o.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(){this.changedCache={}},o.prototype.componentChanged=function(e){if("Mask"===e.component.name)switch(e.type){case t.OBSERVER_TYPE.ADD:this.add(e);break;case t.OBSERVER_TYPE.REMOVE:this.remove(e);break;case t.OBSERVER_TYPE.CHANGE:this.change(e)}},o.prototype.add=function(e){var t,r=e.component;if(!(r.type in u))throw new Error("no have Mask type: "+r.type);if(!r.style)throw new Error("no have Mask style: "+r.type);switch(r.type){case u.Circle:case u.Ellipse:case u.Rect:case u.RoundedRect:case u.Polygon:t=this.createGraphics(r);break;case u.Img:case u.Sprite:t=this.createSprite(r)}if(!t)throw new Error("no have mask instance, check your mask params: "+r.type);var n=this.containerManager.getContainer(e.gameObject.id);n.mask=t,n.addChild(t)},o.prototype.remove=function(e){var t=this.containerManager.getContainer(e.gameObject.id);t.removeChild(t.mask),t.mask.destroy({children:!0}),t.mask=null,delete this.maskSpriteCache[e.gameObject.id]},o.prototype.change=function(e){if(!this.changedCache[e.gameObject.id]){var t=e.component;"type"===e.prop.prop[0]?(this.changedCache[e.gameObject.id]=!0,[u.Sprite,u.Img].indexOf(t.type)>-1||t._lastType!==t.type?(this.remove(e),this.add(e),t._lastType=t.type):this.redrawGraphics(e)):"style"===e.prop.prop[0]?[u.Sprite,u.Img].indexOf(t.type)>-1?this.changeSpriteStyle(t):this.redrawGraphics(e):("resource"===e.prop.prop[0]||"spriteName"===e.prop.prop[0])&&(this.changedCache[e.gameObject.id]=!0,this.changeSprite(t))}},o.prototype.createGraphics=function(e){var t=new n.Graphics;return this.draw(t,e),t},o.prototype.redrawGraphics=function(e){var t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)},o.prototype.draw=function(e,t){var r,n,o=[];try{for(var i=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(y[t.type]),a=i.next();!a.done;a=i.next()){var c=a.value;o.push(t.style[c])}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}e.beginFill(0,1),e[f[t.type]].apply(e,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(p(arguments[t]));return e}(o)),e.endFill()},o.prototype.createSprite=function(e){var t=new n.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite},o.prototype.changeSpriteStyle=function(e){var t=this.maskSpriteCache[e.gameObject.id];t.sprite.width=e.style.width,t.sprite.height=e.style.height,t.sprite.position.x=e.style.x,t.sprite.position.y=e.style.y},o.prototype.changeSprite=function(e){var t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)},o.prototype.setSprite=function(e,r){return c(this,void 0,void 0,(function(){var n,o,i,a;return s(this,(function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),o=this.increaseAsyncId(e.gameObject.id),[4,t.resource.getResource(e.resource)];case 1:return n=c.sent(),this.validateAsyncId(e.gameObject.id,o)?[3,3]:[2];case 2:throw c.sent(),new Error("mask resource load error");case 3:return e.type===u.Sprite?(i=e.resource+"_s|r|c_"+e.spriteName,a=n.instance[i],r.image=a):r.image=n.data.image,r.sprite.width=e.style.width,r.sprite.height=e.style.height,r.sprite.position.x=e.style.x,r.sprite.position.y=e.style.y,[2]}}))}))},o.systemName="Mask",o=a([t.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],o)}(r.Renderer),m=g;return e.Mask=d,e.MaskSystem=m,Object.defineProperty(e,"__esModule",{value:!0}),e}({},EVA,EVA.plugin.renderer,EVA.rendererAdapter);window.EVA.plugin.renderer.mask=window.EVA.plugin.renderer.mask||_EVA_IIFE_mask;
@@ -1,4 +1,4 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import { __extends, __decorate, __values, __spread, __awaiter, __generator } from 'tslib';
4
4
  import { Component, OBSERVER_TYPE, resource, decorators } from '@eva/eva.js/dist/miniprogram';
@@ -178,9 +178,10 @@ var Mask = function (_super) {
178
178
  if (changed.prop.prop[0] === 'type') {
179
179
  this.changedCache[changed.gameObject.id] = true;
180
180
 
181
- if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1) {
181
+ if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1 || component._lastType !== component.type) {
182
182
  this.remove(changed);
183
183
  this.add(changed);
184
+ component._lastType = component.type;
184
185
  } else {
185
186
  this.redrawGraphics(changed);
186
187
  }
@@ -255,9 +255,11 @@ var Mask = (function (_super) {
255
255
  var component = changed.component;
256
256
  if (changed.prop.prop[0] === 'type') {
257
257
  this.changedCache[changed.gameObject.id] = true;
258
- if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1) {
258
+ if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1 ||
259
+ component._lastType !== component.type) {
259
260
  this.remove(changed);
260
261
  this.add(changed);
262
+ component._lastType = component.type;
261
263
  }
262
264
  else {
263
265
  this.redrawGraphics(changed);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),r=require("@eva/plugin-renderer"),n=require("@eva/renderer-adapter"),o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};function i(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function a(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a}function c(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function s(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}exports.MASK_TYPE=void 0,function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(exports.MASK_TYPE||(exports.MASK_TYPE={}));var p,l=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.style={},t.resource="",t.spriteName="",t}return i(r,e),r.prototype.init=function(e){Object.assign(this,e)},r.componentName="Mask",a([t.type("string")],r.prototype,"resource",void 0),a([t.type("string")],r.prototype,"spriteName",void 0),r}(e.Component),h={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},u={Circle:"drawCircle",Ellipse:"drawEllipse",Rect:"drawRect",RoundedRect:"drawRoundedRect",Polygon:"drawPolygon"};!function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(p||(p={}));var y=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="Mask",e.changedCache={},e.maskSpriteCache={},e}return i(o,t),o.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(){this.changedCache={}},o.prototype.componentChanged=function(t){if("Mask"===t.component.name)switch(t.type){case e.OBSERVER_TYPE.ADD:this.add(t);break;case e.OBSERVER_TYPE.REMOVE:this.remove(t);break;case e.OBSERVER_TYPE.CHANGE:this.change(t)}},o.prototype.add=function(e){var t,r=e.component;if(!(r.type in p))throw new Error("no have Mask type: "+r.type);if(!r.style)throw new Error("no have Mask style: "+r.type);switch(r.type){case p.Circle:case p.Ellipse:case p.Rect:case p.RoundedRect:case p.Polygon:t=this.createGraphics(r);break;case p.Img:case p.Sprite:t=this.createSprite(r)}if(!t)throw new Error("no have mask instance, check your mask params: "+r.type);var n=this.containerManager.getContainer(e.gameObject.id);n.mask=t,n.addChild(t)},o.prototype.remove=function(e){var t=this.containerManager.getContainer(e.gameObject.id);t.removeChild(t.mask),t.mask.destroy({children:!0}),t.mask=null,delete this.maskSpriteCache[e.gameObject.id]},o.prototype.change=function(e){if(!this.changedCache[e.gameObject.id]){var t=e.component;"type"===e.prop.prop[0]?(this.changedCache[e.gameObject.id]=!0,[p.Sprite,p.Img].indexOf(t.type)>-1?(this.remove(e),this.add(e)):this.redrawGraphics(e)):"style"===e.prop.prop[0]?[p.Sprite,p.Img].indexOf(t.type)>-1?this.changeSpriteStyle(t):this.redrawGraphics(e):("resource"===e.prop.prop[0]||"spriteName"===e.prop.prop[0])&&(this.changedCache[e.gameObject.id]=!0,this.changeSprite(t))}},o.prototype.createGraphics=function(e){var t=new n.Graphics;return this.draw(t,e),t},o.prototype.redrawGraphics=function(e){var t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)},o.prototype.draw=function(e,t){var r,n,o=[];try{for(var i=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}(h[t.type]),a=i.next();!a.done;a=i.next()){var c=a.value;o.push(t.style[c])}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}e.beginFill(0,1),e[u[t.type]].apply(e,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(s(arguments[t]));return e}(o)),e.endFill()},o.prototype.createSprite=function(e){var t=new n.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite},o.prototype.changeSpriteStyle=function(e){var t=this.maskSpriteCache[e.gameObject.id];t.sprite.width=e.style.width,t.sprite.height=e.style.height,t.sprite.position.x=e.style.x,t.sprite.position.y=e.style.y},o.prototype.changeSprite=function(e){var t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)},o.prototype.setSprite=function(t,r){return n=this,o=void 0,a=function(){var n,o,i,a;return c(this,(function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),o=this.increaseAsyncId(t.gameObject.id),[4,e.resource.getResource(t.resource)];case 1:return n=c.sent(),this.validateAsyncId(t.gameObject.id,o)?[3,3]:[2];case 2:throw c.sent(),new Error("mask resource load error");case 3:return t.type===p.Sprite?(i=t.resource+"_s|r|c_"+t.spriteName,a=n.instance[i],r.image=a):r.image=n.data.image,r.sprite.width=t.style.width,r.sprite.height=t.style.height,r.sprite.position.x=t.style.x,r.sprite.position.y=t.style.y,[2]}}))},new((i=void 0)||(i=Promise))((function(e,t){function r(e){try{s(a.next(e))}catch(e){t(e)}}function c(e){try{s(a.throw(e))}catch(e){t(e)}}function s(t){t.done?e(t.value):new i((function(e){e(t.value)})).then(r,c)}s((a=a.apply(n,o||[])).next())}));var n,o,i,a},o.systemName="Mask",o=a([e.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],o)}(r.Renderer);exports.Mask=l,exports.MaskSystem=y;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@eva/eva.js"),t=require("@eva/inspector-decorator"),r=require("@eva/plugin-renderer"),n=require("@eva/renderer-adapter"),o=function(e,t){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])},o(e,t)};function i(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function a(e,t,r,n){var o,i=arguments.length,a=i<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,r):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,r,n);else for(var c=e.length-1;c>=0;c--)(o=e[c])&&(a=(i<3?o(a):i>3?o(t,r,a):o(t,r))||a);return i>3&&a&&Object.defineProperty(t,r,a),a}function c(e,t){var r,n,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(i){return function(c){return function(i){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(o=2&i[0]?n.return:i[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,i[1])).done)return o;switch(n=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,n=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],n=0}finally{r=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,c])}}}function s(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}exports.MASK_TYPE=void 0,function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(exports.MASK_TYPE||(exports.MASK_TYPE={}));var p,l=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.style={},t.resource="",t.spriteName="",t}return i(r,e),r.prototype.init=function(e){Object.assign(this,e)},r.componentName="Mask",a([t.type("string")],r.prototype,"resource",void 0),a([t.type("string")],r.prototype,"spriteName",void 0),r}(e.Component),h=l,u={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},y={Circle:"drawCircle",Ellipse:"drawEllipse",Rect:"drawRect",RoundedRect:"drawRoundedRect",Polygon:"drawPolygon"};!function(e){e.Circle="Circle",e.Ellipse="Ellipse",e.Rect="Rect",e.RoundedRect="RoundedRect",e.Polygon="Polygon",e.Img="Img",e.Sprite="Sprite"}(p||(p={}));var d=function(t){function o(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="Mask",e.changedCache={},e.maskSpriteCache={},e}return i(o,t),o.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},o.prototype.rendererUpdate=function(){this.changedCache={}},o.prototype.componentChanged=function(t){if("Mask"===t.component.name)switch(t.type){case e.OBSERVER_TYPE.ADD:this.add(t);break;case e.OBSERVER_TYPE.REMOVE:this.remove(t);break;case e.OBSERVER_TYPE.CHANGE:this.change(t)}},o.prototype.add=function(e){var t,r=e.component;if(!(r.type in p))throw new Error("no have Mask type: "+r.type);if(!r.style)throw new Error("no have Mask style: "+r.type);switch(r.type){case p.Circle:case p.Ellipse:case p.Rect:case p.RoundedRect:case p.Polygon:t=this.createGraphics(r);break;case p.Img:case p.Sprite:t=this.createSprite(r)}if(!t)throw new Error("no have mask instance, check your mask params: "+r.type);var n=this.containerManager.getContainer(e.gameObject.id);n.mask=t,n.addChild(t)},o.prototype.remove=function(e){var t=this.containerManager.getContainer(e.gameObject.id);t.removeChild(t.mask),t.mask.destroy({children:!0}),t.mask=null,delete this.maskSpriteCache[e.gameObject.id]},o.prototype.change=function(e){if(!this.changedCache[e.gameObject.id]){var t=e.component;"type"===e.prop.prop[0]?(this.changedCache[e.gameObject.id]=!0,[p.Sprite,p.Img].indexOf(t.type)>-1||t._lastType!==t.type?(this.remove(e),this.add(e),t._lastType=t.type):this.redrawGraphics(e)):"style"===e.prop.prop[0]?[p.Sprite,p.Img].indexOf(t.type)>-1?this.changeSpriteStyle(t):this.redrawGraphics(e):("resource"===e.prop.prop[0]||"spriteName"===e.prop.prop[0])&&(this.changedCache[e.gameObject.id]=!0,this.changeSprite(t))}},o.prototype.createGraphics=function(e){var t=new n.Graphics;return this.draw(t,e),t},o.prototype.redrawGraphics=function(e){var t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)},o.prototype.draw=function(e,t){var r,n,o=[];try{for(var i=function(e){var t="function"==typeof Symbol&&e[Symbol.iterator],r=0;return t?t.call(e):{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}(u[t.type]),a=i.next();!a.done;a=i.next()){var c=a.value;o.push(t.style[c])}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}e.beginFill(0,1),e[y[t.type]].apply(e,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(s(arguments[t]));return e}(o)),e.endFill()},o.prototype.createSprite=function(e){var t=new n.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite},o.prototype.changeSpriteStyle=function(e){var t=this.maskSpriteCache[e.gameObject.id];t.sprite.width=e.style.width,t.sprite.height=e.style.height,t.sprite.position.x=e.style.x,t.sprite.position.y=e.style.y},o.prototype.changeSprite=function(e){var t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)},o.prototype.setSprite=function(t,r){return n=this,o=void 0,a=function(){var n,o,i,a;return c(this,(function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),o=this.increaseAsyncId(t.gameObject.id),[4,e.resource.getResource(t.resource)];case 1:return n=c.sent(),this.validateAsyncId(t.gameObject.id,o)?[3,3]:[2];case 2:throw c.sent(),new Error("mask resource load error");case 3:return t.type===p.Sprite?(i=t.resource+"_s|r|c_"+t.spriteName,a=n.instance[i],r.image=a):r.image=n.data.image,r.sprite.width=t.style.width,r.sprite.height=t.style.height,r.sprite.position.x=t.style.x,r.sprite.position.y=t.style.y,[2]}}))},new((i=void 0)||(i=Promise))((function(e,t){function r(e){try{s(a.next(e))}catch(e){t(e)}}function c(e){try{s(a.throw(e))}catch(e){t(e)}}function s(t){t.done?e(t.value):new i((function(e){e(t.value)})).then(r,c)}s((a=a.apply(n,o||[])).next())}));var n,o,i,a},o.systemName="Mask",o=a([e.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],o)}(r.Renderer);exports.Mask=h,exports.MaskSystem=d;
@@ -1,5 +1,4 @@
1
1
  /// <reference types="pixi.js" />
2
-
3
2
  import { Component } from '@eva/eva.js';
4
3
  import { ComponentChanged } from '@eva/eva.js';
5
4
  import { ContainerManager } from '@eva/plugin-renderer';
@@ -11,6 +10,7 @@ import { Sprite } from '@eva/renderer-adapter';
11
10
 
12
11
  export declare class Mask extends Component<MaskParams> {
13
12
  static componentName: string;
13
+ _lastType: MaskParams['type'];
14
14
  type: MaskParams['type'];
15
15
  style?: MaskParams['style'];
16
16
  resource?: string;
@@ -251,9 +251,11 @@ var Mask = (function (_super) {
251
251
  var component = changed.component;
252
252
  if (changed.prop.prop[0] === 'type') {
253
253
  this.changedCache[changed.gameObject.id] = true;
254
- if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1) {
254
+ if ([MASK_TYPE.Sprite, MASK_TYPE.Img].indexOf(component.type) > -1 ||
255
+ component._lastType !== component.type) {
255
256
  this.remove(changed);
256
257
  this.add(changed);
258
+ component._lastType = component.type;
257
259
  }
258
260
  else {
259
261
  this.redrawGraphics(changed);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-mask",
3
- "version": "1.2.7",
3
+ "version": "1.2.8-alpha.0",
4
4
  "description": "@eva/plugin-renderer-mask",
5
5
  "main": "index.js",
6
6
  "module": "dist/plugin-renderer-mask.esm.js",
@@ -19,9 +19,9 @@
19
19
  "homepage": "https://eva.js.org",
20
20
  "dependencies": {
21
21
  "@eva/inspector-decorator": "^0.0.5",
22
- "@eva/plugin-renderer": "1.2.7",
23
- "@eva/renderer-adapter": "1.2.7",
24
- "@eva/eva.js": "1.2.7",
22
+ "@eva/plugin-renderer": "1.2.8-alpha.0",
23
+ "@eva/renderer-adapter": "1.2.8-alpha.0",
24
+ "@eva/eva.js": "1.2.8-alpha.0",
25
25
  "pixi.js": "^4.8.7"
26
26
  }
27
27
  }