@eva/plugin-renderer-mask 1.2.7-editor.4 → 1.2.7-editor.5

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.
@@ -361,6 +361,8 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
361
361
  };
362
362
  }
363
363
 
364
+ var _a;
365
+
364
366
  exports.MASK_TYPE = void 0;
365
367
 
366
368
  (function (MASK_TYPE) {
@@ -373,6 +375,41 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
373
375
  MASK_TYPE["Sprite"] = "Sprite";
374
376
  })(exports.MASK_TYPE || (exports.MASK_TYPE = {}));
375
377
 
378
+ var MaskStyle = function () {
379
+ function MaskStyle() {}
380
+
381
+ __decorate([Field({
382
+ step: 1
383
+ }), __metadata("design:type", Number)], MaskStyle.prototype, "x", void 0);
384
+
385
+ __decorate([Field({
386
+ step: 1
387
+ }), __metadata("design:type", Number)], MaskStyle.prototype, "y", void 0);
388
+
389
+ __decorate([Field({
390
+ step: 0.1,
391
+ if: function _if(mask) {
392
+ return mask.type === exports.MASK_TYPE.Circle || mask.type === exports.MASK_TYPE.RoundedRect;
393
+ }
394
+ }), __metadata("design:type", Number)], MaskStyle.prototype, "radius", void 0);
395
+
396
+ __decorate([Field({
397
+ step: 1,
398
+ if: function _if(mask) {
399
+ return mask.type !== exports.MASK_TYPE.Circle;
400
+ }
401
+ }), __metadata("design:type", Number)], MaskStyle.prototype, "width", void 0);
402
+
403
+ __decorate([Field({
404
+ step: 1,
405
+ if: function _if(mask) {
406
+ return mask.type !== exports.MASK_TYPE.Circle;
407
+ }
408
+ }), __metadata("design:type", Number)], MaskStyle.prototype, "height", void 0);
409
+
410
+ return MaskStyle;
411
+ }();
412
+
376
413
  var Mask$2 = function (_super) {
377
414
  __extends(Mask, _super);
378
415
 
@@ -391,9 +428,23 @@ var _EVA_IIFE_mask = function (exports, eva_js, pluginRenderer, rendererAdapter)
391
428
 
392
429
  Mask.componentName = 'Mask';
393
430
 
394
- __decorate([Field(), __metadata("design:type", String)], Mask.prototype, "resource", void 0);
395
-
396
- __decorate([Field(), __metadata("design:type", String)], Mask.prototype, "spriteName", void 0);
431
+ __decorate([Field({
432
+ type: 'selector',
433
+ options: (_a = {}, _a[exports.MASK_TYPE.Circle] = exports.MASK_TYPE.Circle, _a[exports.MASK_TYPE.Ellipse] = exports.MASK_TYPE.Ellipse, _a[exports.MASK_TYPE.Img] = exports.MASK_TYPE.Img, _a[exports.MASK_TYPE.Rect] = exports.MASK_TYPE.Rect, _a[exports.MASK_TYPE.RoundedRect] = exports.MASK_TYPE.RoundedRect, _a),
434
+ alias: 'type',
435
+ default: exports.MASK_TYPE.Circle
436
+ }), __metadata("design:type", String)], Mask.prototype, "mask_type", void 0);
437
+
438
+ __decorate([Field(function () {
439
+ return MaskStyle;
440
+ }), __metadata("design:type", Object)], Mask.prototype, "style", void 0);
441
+
442
+ __decorate([Field({
443
+ type: 'resource',
444
+ if: function _if(mask) {
445
+ return mask.type === exports.MASK_TYPE.Img || exports.MASK_TYPE.Sprite;
446
+ }
447
+ }), __metadata("design:type", String)], Mask.prototype, "resource", void 0);
397
448
 
398
449
  return Mask;
399
450
  }(eva_js.Component);
@@ -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},_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)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},o(e,t)};function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function c(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 s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function p(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 l(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 u(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}var y=function(e){function t(){var t=this.constructor,r=e.call(this,"Symbol keys are not supported yet!")||this;return Object.setPrototypeOf(r,t.prototype),r}return i(t,e),t}(Error);!function(e){function t(){var t=this.constructor,r=e.call(this,"getProperties is not a function!")||this;return Object.setPrototypeOf(r,t.prototype),r}i(t,e)}(Error);var h="IDE_PROPERTY_METADATA";function d(e,t,r,n){var o=Reflect.getMetadata("design:type",e,t),i=o===Array,c=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(o);if("unknown"!==c&&(o=c),n){var s=n();Array.isArray(s)?(i=!0,o=s[0]):o=s}var p=Reflect.getMetadata(h,e.constructor)||{};p[t]=a({type:o,isArray:i},r),Reflect.defineMetadata(h,p,e.constructor)}function f(e,t){return function(r,n){if("symbol"==typeof n)throw new y;var o=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(e,t);d(r,n,o.options,o.returnTypeFunc)}}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 g,m=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",c([f(),s("design:type",String)],t.prototype,"resource",void 0),c([f(),s("design:type",String)],t.prototype,"spriteName",void 0),t}(t.Component),w=m,v={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},b={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"}(g||(g={}));var E=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 g))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 g.Circle:case g.Ellipse:case g.Rect:case g.RoundedRect:case g.Polygon:t=this.createGraphics(r);break;case g.Img:case g.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,[g.Sprite,g.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]?[g.Sprite,g.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.")}(v[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[b[t.type]].apply(e,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(u(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 p(this,void 0,void 0,(function(){var n,o,i,a;return l(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===g.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=c([t.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],o)}(r.Renderer),S=E;return e.Mask=w,e.MaskSystem=S,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||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)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},o(e,t)};function i(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function c(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 s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function p(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 u(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 l(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}var y=function(e){function t(){var t=this.constructor,r=e.call(this,"Symbol keys are not supported yet!")||this;return Object.setPrototypeOf(r,t.prototype),r}return i(t,e),t}(Error);!function(e){function t(){var t=this.constructor,r=e.call(this,"getProperties is not a function!")||this;return Object.setPrototypeOf(r,t.prototype),r}i(t,e)}(Error);var d,h="IDE_PROPERTY_METADATA";function f(e,t,r,n){var o=Reflect.getMetadata("design:type",e,t),i=o===Array,c=function(e){return e===String?"string":e===Number?"number":e===Boolean?"boolean":"unknown"}(o);if("unknown"!==c&&(o=c),n){var s=n();Array.isArray(s)?(i=!0,o=s[0]):o=s}var p=Reflect.getMetadata(h,e.constructor)||{};p[t]=a({type:o,isArray:i},r),Reflect.defineMetadata(h,p,e.constructor)}function g(e,t){return function(r,n){if("symbol"==typeof n)throw new y;var o=function(e,t){return"function"==typeof e?{returnTypeFunc:e,options:t||{}}:{options:e||{}}}(e,t);f(r,n,o.options,o.returnTypeFunc)}}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 m,v=function(){function t(){}return c([g({step:1}),s("design:type",Number)],t.prototype,"x",void 0),c([g({step:1}),s("design:type",Number)],t.prototype,"y",void 0),c([g({step:.1,if:function(t){return t.type===e.MASK_TYPE.Circle||t.type===e.MASK_TYPE.RoundedRect}}),s("design:type",Number)],t.prototype,"radius",void 0),c([g({step:1,if:function(t){return t.type!==e.MASK_TYPE.Circle}}),s("design:type",Number)],t.prototype,"width",void 0),c([g({step:1,if:function(t){return t.type!==e.MASK_TYPE.Circle}}),s("design:type",Number)],t.prototype,"height",void 0),t}(),w=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e.style={},e.resource="",e.spriteName="",e}return i(r,t),r.prototype.init=function(e){_extends(this,e)},r.componentName="Mask",c([g({type:"selector",options:(d={},d[e.MASK_TYPE.Circle]=e.MASK_TYPE.Circle,d[e.MASK_TYPE.Ellipse]=e.MASK_TYPE.Ellipse,d[e.MASK_TYPE.Img]=e.MASK_TYPE.Img,d[e.MASK_TYPE.Rect]=e.MASK_TYPE.Rect,d[e.MASK_TYPE.RoundedRect]=e.MASK_TYPE.RoundedRect,d),alias:"type",default:e.MASK_TYPE.Circle}),s("design:type",String)],r.prototype,"mask_type",void 0),c([g((function(){return v})),s("design:type",Object)],r.prototype,"style",void 0),c([g({type:"resource",if:function(t){return t.type===e.MASK_TYPE.Img||e.MASK_TYPE.Sprite}}),s("design:type",String)],r.prototype,"resource",void 0),r}(t.Component),E=w,S={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},b={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"}(m||(m={}));var R=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 m))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 m.Circle:case m.Ellipse:case m.Rect:case m.RoundedRect:case m.Polygon:t=this.createGraphics(r);break;case m.Img:case m.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,[m.Sprite,m.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]?[m.Sprite,m.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.")}(S[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[b[t.type]].apply(e,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(l(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 p(this,void 0,void 0,(function(){var n,o,i,a;return u(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===m.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=c([t.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],o)}(r.Renderer),_=R;return e.Mask=E,e.MaskSystem=_,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,10 +1,13 @@
1
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); }
2
2
 
3
- import { __extends, __decorate, __metadata, __values, __spread, __awaiter, __generator } from 'tslib';
3
+ import { __decorate, __metadata, __extends, __values, __spread, __awaiter, __generator } from 'tslib';
4
4
  import { Component, OBSERVER_TYPE, resource, decorators } from '@eva/eva.js/dist/miniprogram';
5
5
  import { Field } from '@eva/inspector-decorator';
6
6
  import { RendererSystem, Renderer } from '@eva/plugin-renderer/dist/miniprogram';
7
7
  import { Graphics, Sprite } from '@eva/renderer-adapter/dist/miniprogram';
8
+
9
+ var _a;
10
+
8
11
  var MASK_TYPE$1;
9
12
 
10
13
  (function (MASK_TYPE) {
@@ -17,6 +20,41 @@ var MASK_TYPE$1;
17
20
  MASK_TYPE["Sprite"] = "Sprite";
18
21
  })(MASK_TYPE$1 || (MASK_TYPE$1 = {}));
19
22
 
23
+ var MaskStyle = function () {
24
+ function MaskStyle() {}
25
+
26
+ __decorate([Field({
27
+ step: 1
28
+ }), __metadata("design:type", Number)], MaskStyle.prototype, "x", void 0);
29
+
30
+ __decorate([Field({
31
+ step: 1
32
+ }), __metadata("design:type", Number)], MaskStyle.prototype, "y", void 0);
33
+
34
+ __decorate([Field({
35
+ step: 0.1,
36
+ if: function _if(mask) {
37
+ return mask.type === MASK_TYPE$1.Circle || mask.type === MASK_TYPE$1.RoundedRect;
38
+ }
39
+ }), __metadata("design:type", Number)], MaskStyle.prototype, "radius", void 0);
40
+
41
+ __decorate([Field({
42
+ step: 1,
43
+ if: function _if(mask) {
44
+ return mask.type !== MASK_TYPE$1.Circle;
45
+ }
46
+ }), __metadata("design:type", Number)], MaskStyle.prototype, "width", void 0);
47
+
48
+ __decorate([Field({
49
+ step: 1,
50
+ if: function _if(mask) {
51
+ return mask.type !== MASK_TYPE$1.Circle;
52
+ }
53
+ }), __metadata("design:type", Number)], MaskStyle.prototype, "height", void 0);
54
+
55
+ return MaskStyle;
56
+ }();
57
+
20
58
  var Mask$2 = function (_super) {
21
59
  __extends(Mask, _super);
22
60
 
@@ -35,9 +73,23 @@ var Mask$2 = function (_super) {
35
73
 
36
74
  Mask.componentName = 'Mask';
37
75
 
38
- __decorate([Field(), __metadata("design:type", String)], Mask.prototype, "resource", void 0);
39
-
40
- __decorate([Field(), __metadata("design:type", String)], Mask.prototype, "spriteName", void 0);
76
+ __decorate([Field({
77
+ type: 'selector',
78
+ options: (_a = {}, _a[MASK_TYPE$1.Circle] = MASK_TYPE$1.Circle, _a[MASK_TYPE$1.Ellipse] = MASK_TYPE$1.Ellipse, _a[MASK_TYPE$1.Img] = MASK_TYPE$1.Img, _a[MASK_TYPE$1.Rect] = MASK_TYPE$1.Rect, _a[MASK_TYPE$1.RoundedRect] = MASK_TYPE$1.RoundedRect, _a),
79
+ alias: 'type',
80
+ default: MASK_TYPE$1.Circle
81
+ }), __metadata("design:type", String)], Mask.prototype, "mask_type", void 0);
82
+
83
+ __decorate([Field(function () {
84
+ return MaskStyle;
85
+ }), __metadata("design:type", Object)], Mask.prototype, "style", void 0);
86
+
87
+ __decorate([Field({
88
+ type: 'resource',
89
+ if: function _if(mask) {
90
+ return mask.type === MASK_TYPE$1.Img || MASK_TYPE$1.Sprite;
91
+ }
92
+ }), __metadata("design:type", String)], Mask.prototype, "resource", void 0);
41
93
 
42
94
  return Mask;
43
95
  }(Component);
@@ -118,6 +118,7 @@ function __spread() {
118
118
  return ar;
119
119
  }
120
120
 
121
+ var _a;
121
122
  exports.MASK_TYPE = void 0;
122
123
  (function (MASK_TYPE) {
123
124
  MASK_TYPE["Circle"] = "Circle";
@@ -128,6 +129,31 @@ exports.MASK_TYPE = void 0;
128
129
  MASK_TYPE["Img"] = "Img";
129
130
  MASK_TYPE["Sprite"] = "Sprite";
130
131
  })(exports.MASK_TYPE || (exports.MASK_TYPE = {}));
132
+ var MaskStyle = (function () {
133
+ function MaskStyle() {
134
+ }
135
+ __decorate([
136
+ inspectorDecorator.Field({ step: 1 }),
137
+ __metadata("design:type", Number)
138
+ ], MaskStyle.prototype, "x", void 0);
139
+ __decorate([
140
+ inspectorDecorator.Field({ step: 1 }),
141
+ __metadata("design:type", Number)
142
+ ], MaskStyle.prototype, "y", void 0);
143
+ __decorate([
144
+ inspectorDecorator.Field({ step: 0.1, if: function (mask) { return mask.type === exports.MASK_TYPE.Circle || mask.type === exports.MASK_TYPE.RoundedRect; } }),
145
+ __metadata("design:type", Number)
146
+ ], MaskStyle.prototype, "radius", void 0);
147
+ __decorate([
148
+ inspectorDecorator.Field({ step: 1, if: function (mask) { return mask.type !== exports.MASK_TYPE.Circle; } }),
149
+ __metadata("design:type", Number)
150
+ ], MaskStyle.prototype, "width", void 0);
151
+ __decorate([
152
+ inspectorDecorator.Field({ step: 1, if: function (mask) { return mask.type !== exports.MASK_TYPE.Circle; } }),
153
+ __metadata("design:type", Number)
154
+ ], MaskStyle.prototype, "height", void 0);
155
+ return MaskStyle;
156
+ }());
131
157
  var Mask$2 = (function (_super) {
132
158
  __extends(Mask, _super);
133
159
  function Mask() {
@@ -142,13 +168,31 @@ var Mask$2 = (function (_super) {
142
168
  };
143
169
  Mask.componentName = 'Mask';
144
170
  __decorate([
145
- inspectorDecorator.Field(),
171
+ inspectorDecorator.Field({
172
+ type: 'selector',
173
+ options: (_a = {},
174
+ _a[exports.MASK_TYPE.Circle] = exports.MASK_TYPE.Circle,
175
+ _a[exports.MASK_TYPE.Ellipse] = exports.MASK_TYPE.Ellipse,
176
+ _a[exports.MASK_TYPE.Img] = exports.MASK_TYPE.Img,
177
+ _a[exports.MASK_TYPE.Rect] = exports.MASK_TYPE.Rect,
178
+ _a[exports.MASK_TYPE.RoundedRect] = exports.MASK_TYPE.RoundedRect,
179
+ _a),
180
+ alias: 'type',
181
+ default: exports.MASK_TYPE.Circle,
182
+ }),
146
183
  __metadata("design:type", String)
147
- ], Mask.prototype, "resource", void 0);
184
+ ], Mask.prototype, "mask_type", void 0);
148
185
  __decorate([
149
- inspectorDecorator.Field(),
186
+ inspectorDecorator.Field(function () { return MaskStyle; }),
187
+ __metadata("design:type", Object)
188
+ ], Mask.prototype, "style", void 0);
189
+ __decorate([
190
+ inspectorDecorator.Field({
191
+ type: 'resource',
192
+ if: function (mask) { return mask.type === exports.MASK_TYPE.Img || exports.MASK_TYPE.Sprite; },
193
+ }),
150
194
  __metadata("design:type", String)
151
- ], Mask.prototype, "spriteName", void 0);
195
+ ], Mask.prototype, "resource", void 0);
152
196
  return Mask;
153
197
  }(eva_js.Component));
154
198
  var Mask$3 = Mask$2;
@@ -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"),i=function(e,t){return i=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])},i(e,t)};function o(e,t){function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function a(e,t,r,n){var i,o=arguments.length,a=o<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--)(i=e[c])&&(a=(o<3?i(a):o>3?i(t,r,a):i(t,r))||a);return o>3&&a&&Object.defineProperty(t,r,a),a}function c(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function s(e,t){var r,n,i,o,a={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function c(o){return function(c){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,c])}}}function p(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.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 l,u=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.style={},t.resource="",t.spriteName="",t}return o(r,e),r.prototype.init=function(e){Object.assign(this,e)},r.componentName="Mask",a([t.Field(),c("design:type",String)],r.prototype,"resource",void 0),a([t.Field(),c("design:type",String)],r.prototype,"spriteName",void 0),r}(e.Component),h=u,y={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},d={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"}(l||(l={}));var f=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e.name="Mask",e.changedCache={},e.maskSpriteCache={},e}return o(i,t),i.prototype.init=function(){this.renderSystem=this.game.getSystem(r.RendererSystem),this.renderSystem.rendererManager.register(this)},i.prototype.rendererUpdate=function(){this.changedCache={}},i.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)}},i.prototype.add=function(e){var t,r=e.component;if(!(r.type in l))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 l.Circle:case l.Ellipse:case l.Rect:case l.RoundedRect:case l.Polygon:t=this.createGraphics(r);break;case l.Img:case l.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)},i.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]},i.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,[l.Sprite,l.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]?[l.Sprite,l.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))}},i.prototype.createGraphics=function(e){var t=new n.Graphics;return this.draw(t,e),t},i.prototype.redrawGraphics=function(e){var t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)},i.prototype.draw=function(e,t){var r,n,i=[];try{for(var o=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}}}}(y[t.type]),a=o.next();!a.done;a=o.next()){var c=a.value;i.push(t.style[c])}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}e.beginFill(0,1),e[d[t.type]].apply(e,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(p(arguments[t]));return e}(i)),e.endFill()},i.prototype.createSprite=function(e){var t=new n.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite},i.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},i.prototype.changeSprite=function(e){var t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)},i.prototype.setSprite=function(t,r){return n=this,i=void 0,a=function(){var n,i,o,a;return s(this,(function(c){switch(c.label){case 0:return c.trys.push([0,2,,3]),i=this.increaseAsyncId(t.gameObject.id),[4,e.resource.getResource(t.resource)];case 1:return n=c.sent(),this.validateAsyncId(t.gameObject.id,i)?[3,3]:[2];case 2:throw c.sent(),new Error("mask resource load error");case 3:return t.type===l.Sprite?(o=t.resource+"_s|r|c_"+t.spriteName,a=n.instance[o],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((o=void 0)||(o=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 o((function(e){e(t.value)})).then(r,c)}s((a=a.apply(n,i||[])).next())}));var n,i,o,a},i.systemName="Mask",i=a([e.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],i)}(r.Renderer);exports.Mask=h,exports.MaskSystem=f;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("@eva/eva.js"),r=require("@eva/inspector-decorator"),n=require("@eva/plugin-renderer"),o=require("@eva/renderer-adapter"),i=function(e,t){return i=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])},i(e,t)};function a(e,t){function r(){this.constructor=e}i(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function p(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 p=e.length-1;p>=0;p--)(o=e[p])&&(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 s(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}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:p(0),throw:p(1),return:p(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function p(i){return function(p){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,p])}}}function l(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 u,y=function(){function e(){}return p([r.Field({step:1}),s("design:type",Number)],e.prototype,"x",void 0),p([r.Field({step:1}),s("design:type",Number)],e.prototype,"y",void 0),p([r.Field({step:.1,if:function(e){return e.type===exports.MASK_TYPE.Circle||e.type===exports.MASK_TYPE.RoundedRect}}),s("design:type",Number)],e.prototype,"radius",void 0),p([r.Field({step:1,if:function(e){return e.type!==exports.MASK_TYPE.Circle}}),s("design:type",Number)],e.prototype,"width",void 0),p([r.Field({step:1,if:function(e){return e.type!==exports.MASK_TYPE.Circle}}),s("design:type",Number)],e.prototype,"height",void 0),e}(),d=function(t){function n(){var e=null!==t&&t.apply(this,arguments)||this;return e.style={},e.resource="",e.spriteName="",e}return a(n,t),n.prototype.init=function(e){Object.assign(this,e)},n.componentName="Mask",p([r.Field({type:"selector",options:(e={},e[exports.MASK_TYPE.Circle]=exports.MASK_TYPE.Circle,e[exports.MASK_TYPE.Ellipse]=exports.MASK_TYPE.Ellipse,e[exports.MASK_TYPE.Img]=exports.MASK_TYPE.Img,e[exports.MASK_TYPE.Rect]=exports.MASK_TYPE.Rect,e[exports.MASK_TYPE.RoundedRect]=exports.MASK_TYPE.RoundedRect,e),alias:"type",default:exports.MASK_TYPE.Circle}),s("design:type",String)],n.prototype,"mask_type",void 0),p([r.Field((function(){return y})),s("design:type",Object)],n.prototype,"style",void 0),p([r.Field({type:"resource",if:function(e){return e.type===exports.MASK_TYPE.Img||exports.MASK_TYPE.Sprite}}),s("design:type",String)],n.prototype,"resource",void 0),n}(t.Component),h=d,f={Circle:["x","y","radius"],Ellipse:["x","y","width","height"],Rect:["x","y","width","height"],RoundedRect:["x","y","width","height","radius"],Polygon:["paths"]},g={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 m=function(e){function r(){var t=null!==e&&e.apply(this,arguments)||this;return t.name="Mask",t.changedCache={},t.maskSpriteCache={},t}return a(r,e),r.prototype.init=function(){this.renderSystem=this.game.getSystem(n.RendererSystem),this.renderSystem.rendererManager.register(this)},r.prototype.rendererUpdate=function(){this.changedCache={}},r.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)}},r.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)},r.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]},r.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))}},r.prototype.createGraphics=function(e){var t=new o.Graphics;return this.draw(t,e),t},r.prototype.redrawGraphics=function(e){var t=this.containerManager.getContainer(e.gameObject.id).mask;t.clear(),this.draw(t,e.component)},r.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}}}}(f[t.type]),a=i.next();!a.done;a=i.next()){var p=a.value;o.push(t.style[p])}}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[g[t.type]].apply(e,function(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(l(arguments[t]));return e}(o)),e.endFill()},r.prototype.createSprite=function(e){var t=new o.Sprite(null);return this.maskSpriteCache[e.gameObject.id]=t,this.setSprite(e,t),t.sprite},r.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},r.prototype.changeSprite=function(e){var t=this.maskSpriteCache[e.gameObject.id];this.setSprite(e,t)},r.prototype.setSprite=function(e,r){return n=this,o=void 0,a=function(){var n,o,i,a;return c(this,(function(p){switch(p.label){case 0:return p.trys.push([0,2,,3]),o=this.increaseAsyncId(e.gameObject.id),[4,t.resource.getResource(e.resource)];case 1:return n=p.sent(),this.validateAsyncId(e.gameObject.id,o)?[3,3]:[2];case 2:throw p.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]}}))},new((i=void 0)||(i=Promise))((function(e,t){function r(e){try{s(a.next(e))}catch(e){t(e)}}function p(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,p)}s((a=a.apply(n,o||[])).next())}));var n,o,i,a},r.systemName="Mask",r=p([t.decorators.componentObserver({Mask:["type",{prop:["style"],deep:!0},"resource","spriteName"]})],r)}(n.Renderer),v=m;exports.Mask=h,exports.MaskSystem=v;
@@ -12,6 +12,7 @@ import { Sprite } from '@eva/renderer-adapter';
12
12
  export declare class Mask extends Component<MaskParams> {
13
13
  static componentName: string;
14
14
  _lastType: MaskParams['type'];
15
+ mask_type: string;
15
16
  type: MaskParams['type'];
16
17
  style?: MaskParams['style'];
17
18
  resource?: string;
@@ -114,6 +114,7 @@ function __spread() {
114
114
  return ar;
115
115
  }
116
116
 
117
+ var _a;
117
118
  var MASK_TYPE$1;
118
119
  (function (MASK_TYPE) {
119
120
  MASK_TYPE["Circle"] = "Circle";
@@ -124,6 +125,31 @@ var MASK_TYPE$1;
124
125
  MASK_TYPE["Img"] = "Img";
125
126
  MASK_TYPE["Sprite"] = "Sprite";
126
127
  })(MASK_TYPE$1 || (MASK_TYPE$1 = {}));
128
+ var MaskStyle = (function () {
129
+ function MaskStyle() {
130
+ }
131
+ __decorate([
132
+ Field({ step: 1 }),
133
+ __metadata("design:type", Number)
134
+ ], MaskStyle.prototype, "x", void 0);
135
+ __decorate([
136
+ Field({ step: 1 }),
137
+ __metadata("design:type", Number)
138
+ ], MaskStyle.prototype, "y", void 0);
139
+ __decorate([
140
+ Field({ step: 0.1, if: function (mask) { return mask.type === MASK_TYPE$1.Circle || mask.type === MASK_TYPE$1.RoundedRect; } }),
141
+ __metadata("design:type", Number)
142
+ ], MaskStyle.prototype, "radius", void 0);
143
+ __decorate([
144
+ Field({ step: 1, if: function (mask) { return mask.type !== MASK_TYPE$1.Circle; } }),
145
+ __metadata("design:type", Number)
146
+ ], MaskStyle.prototype, "width", void 0);
147
+ __decorate([
148
+ Field({ step: 1, if: function (mask) { return mask.type !== MASK_TYPE$1.Circle; } }),
149
+ __metadata("design:type", Number)
150
+ ], MaskStyle.prototype, "height", void 0);
151
+ return MaskStyle;
152
+ }());
127
153
  var Mask$2 = (function (_super) {
128
154
  __extends(Mask, _super);
129
155
  function Mask() {
@@ -138,13 +164,31 @@ var Mask$2 = (function (_super) {
138
164
  };
139
165
  Mask.componentName = 'Mask';
140
166
  __decorate([
141
- Field(),
167
+ Field({
168
+ type: 'selector',
169
+ options: (_a = {},
170
+ _a[MASK_TYPE$1.Circle] = MASK_TYPE$1.Circle,
171
+ _a[MASK_TYPE$1.Ellipse] = MASK_TYPE$1.Ellipse,
172
+ _a[MASK_TYPE$1.Img] = MASK_TYPE$1.Img,
173
+ _a[MASK_TYPE$1.Rect] = MASK_TYPE$1.Rect,
174
+ _a[MASK_TYPE$1.RoundedRect] = MASK_TYPE$1.RoundedRect,
175
+ _a),
176
+ alias: 'type',
177
+ default: MASK_TYPE$1.Circle,
178
+ }),
142
179
  __metadata("design:type", String)
143
- ], Mask.prototype, "resource", void 0);
180
+ ], Mask.prototype, "mask_type", void 0);
144
181
  __decorate([
145
- Field(),
182
+ Field(function () { return MaskStyle; }),
183
+ __metadata("design:type", Object)
184
+ ], Mask.prototype, "style", void 0);
185
+ __decorate([
186
+ Field({
187
+ type: 'resource',
188
+ if: function (mask) { return mask.type === MASK_TYPE$1.Img || MASK_TYPE$1.Sprite; },
189
+ }),
146
190
  __metadata("design:type", String)
147
- ], Mask.prototype, "spriteName", void 0);
191
+ ], Mask.prototype, "resource", void 0);
148
192
  return Mask;
149
193
  }(Component));
150
194
  var Mask$3 = Mask$2;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eva/plugin-renderer-mask",
3
- "version": "1.2.7-editor.4",
3
+ "version": "1.2.7-editor.5",
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.1.0-alpha.1",
22
- "@eva/plugin-renderer": "1.2.7-editor.4",
23
- "@eva/renderer-adapter": "1.2.7-editor.4",
24
- "@eva/eva.js": "1.2.7-editor.4",
22
+ "@eva/plugin-renderer": "1.2.7-editor.5",
23
+ "@eva/renderer-adapter": "1.2.7-editor.5",
24
+ "@eva/eva.js": "1.2.7-editor.5",
25
25
  "pixi.js": "^4.8.7"
26
26
  }
27
27
  }