tinyjs-plugin-ninepatch
Advanced tools
Sorry, the diff of this file is not supported yet
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>tinyjs - 九宫格图片</title> | ||
| <meta content="yes" name="apple-mobile-web-app-capable" /> | ||
| <meta content="yes" name="apple-touch-fullscreen" /> | ||
| <meta content="telephone=no,email=no" name="format-detection" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" /> | ||
| <script src="https://gw.alipayobjects.com/as/g/tiny/tiny/1.1.5/tiny.js"></script> | ||
| <script src="../dist/index.debug.js"></script> | ||
| <style> | ||
| html, | ||
| body, | ||
| p, | ||
| div { | ||
| margin: 0; | ||
| padding: 0; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <script type="text/javascript"> | ||
| var config = { | ||
| showFPS: false, // 显示帧频 | ||
| dpi: 1, // 分辨率 | ||
| width: 320, | ||
| height: 568, | ||
| fixSize: true, | ||
| renderOptions: { | ||
| backgroundColor: 0x2a3145 // 0xffffff // 画布背景色 | ||
| } | ||
| }; | ||
| function setTitle(title, container) { | ||
| var title = new Tiny.Text(title, { | ||
| fontSize: '18px', | ||
| fill: 'white', | ||
| }); | ||
| title.position.set(Tiny.WIN_SIZE.width / 2, 30); | ||
| title.anchor.set(0.5, 0); | ||
| container.addChild(title); | ||
| } | ||
| var app = new Tiny.Application(config); | ||
| function initGame() { | ||
| container = new Tiny.Container(); | ||
| setTitle('tinyjs - 九宫格 - 提示气泡', container); | ||
| sprite = new Tiny.NinePatch.Sprite( | ||
| Tiny.Loader.resources['tip_bubble_png'].texture, | ||
| 300, | ||
| 100, | ||
| [95, 35, 2, 5] | ||
| ); | ||
| sprite.x = 10; | ||
| sprite.y = 100; | ||
| container.addChild(sprite); | ||
| app.run(container); | ||
| var yoyo = false; | ||
| app.onUpdate(function () { | ||
| if (sprite.width == 300) { | ||
| yoyo = true; | ||
| } else if (sprite.width == 200) { | ||
| yoyo = false; | ||
| } | ||
| if (yoyo) { | ||
| sprite.width--; | ||
| sprite.height--; | ||
| } else { | ||
| sprite.width++; | ||
| sprite.height++; | ||
| } | ||
| }) | ||
| } | ||
| Tiny.Loader | ||
| .add('tip_bubble_png', 'assets/tip-bubble.png') | ||
| .load(function () { | ||
| initGame(); | ||
| }); | ||
| console.log(Tiny.NinePatch); | ||
| </script> | ||
| </body> | ||
| </html> |
+6
-0
@@ -0,1 +1,7 @@ | ||
| ## 0.2.2 | ||
| `2018-02-13` | ||
| 1. 增加 demo/tip-bubble.html 示例 | ||
| 2. 增加容错机制 防止 九宫格尺寸设置异常,尺寸小于素材尺寸的时候 计算九宫格的异常 | ||
| ## 0.2.1 | ||
@@ -2,0 +8,0 @@ |
+4
-0
@@ -25,2 +25,6 @@ <!DOCTYPE html> | ||
| </a> | ||
| <a href="tip-bubble.html" class="am-list-item"> | ||
| <div class="am-list-content">tip bubble</div> | ||
| <div class="am-list-arrow"><span class="am-icon arrow horizontal"></span></div> | ||
| </a> | ||
| </div> | ||
@@ -27,0 +31,0 @@ </div> |
@@ -69,3 +69,3 @@ <!DOCTYPE html> | ||
| app.onUpdate(function () { | ||
| if (sprite.width == 310) { | ||
| if (sprite.width == 300) { | ||
| yoyo = true; | ||
@@ -72,0 +72,0 @@ } else if (sprite.width == 130) { |
@@ -5,3 +5,3 @@ /*! | ||
| * Author: 清扬陌客 | ||
| * Version: v0.2.1 | ||
| * Version: v0.2.2 | ||
| * Github: https://github.com/qingyangmoke/tinyjs-plugin-ninepatch.git | ||
@@ -261,2 +261,5 @@ */ | ||
| var realWidth = Math.max(this.width, this._gridTexture.width); | ||
| var realHeight = Math.max(this.height, this._gridTexture.height); | ||
| var scale9Grid = this._scale9Grid; | ||
@@ -283,6 +286,6 @@ var w1 = scale9Grid[0]; | ||
| if (frame.width > 0 && frame.height > 0) { | ||
| var w = col === 0 || col === 2 ? wArr[col] : Math.max(0, this.width - wArr[0] - wArr[2]); | ||
| var h = row === 0 || row === 2 ? hArr[row] : Math.max(0, this.height - hArr[0] - hArr[2]); | ||
| var x = col === 0 ? 0 : col === 1 ? wArr[0] : Math.max(0, this.width - wArr[2]); | ||
| var y = row === 0 ? 0 : row === 1 ? hArr[0] : Math.max(0, this.height - hArr[2]); | ||
| var w = col === 0 || col === 2 ? wArr[col] : Math.max(0, realWidth - wArr[0] - wArr[2]); | ||
| var h = row === 0 || row === 2 ? hArr[row] : Math.max(0, realHeight - hArr[0] - hArr[2]); | ||
| var x = col === 0 ? 0 : col === 1 ? wArr[0] : Math.max(0, realWidth - wArr[2]); | ||
| var y = row === 0 ? 0 : row === 1 ? hArr[0] : Math.max(0, realHeight - hArr[2]); | ||
| if (w > 0 && h > 0) { | ||
@@ -289,0 +292,0 @@ this._textures[i].frame = frame; |
+2
-2
@@ -5,5 +5,5 @@ /*! | ||
| * Author: 清扬陌客 | ||
| * Version: v0.2.1 | ||
| * Version: v0.2.2 | ||
| * Github: https://github.com/qingyangmoke/tinyjs-plugin-ninepatch.git | ||
| */ | ||
| !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.NinePatch=e():(t.Tiny=t.Tiny||{},t.Tiny.NinePatch=e())}(this,function(){return function(t){function e(r){if(i[r])return i[r].exports;var n=i[r]={exports:{},id:r,loaded:!1};return t[r].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var i={};return e.m=t,e.c=i,e.p="/Users/song/Develop/github/tinyjs-plugin-ninepatch/dist",e(0)}([function(t,e,i){t.exports=i(1)},function(t,e,i){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),e.Sprite=void 0;var n=i(2),u=r(n);e.Sprite=u.default},function(t,e){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0});var u=function(){function t(t,e){for(var i=0;i<e.length;i++){var r=e[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,i,r){return i&&t(e.prototype,i),r&&t(e,r),e}}(),s=function(t){function e(t,n,u,s){i(this,e);var h=r(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return h._gridTexture=t,h._debugDraw=!1,h._textures=[],h._gridSprites=[],h._targetWidth=n||0,h._targetHeight=u||0,h._textureOrigFrame=new Tiny.Rectangle(0,0,h._gridTexture.width,h._gridTexture.height),h._scale9Grid=null,h._inited=!1,h._init(),h.scale9Grid=s,h._gridTexture.baseTexture.hasLoaded?h._onGridTextureUpdate():h._gridTexture.once("update",h._onGridTextureUpdate,h),h}return n(e,t),u(e,[{key:"_onGridTextureUpdate",value:function(){this._update()}},{key:"_init",value:function(){if(!this._inited){this._inited=!0;for(var t=0;t<9;t++){var e=new Tiny.Texture(this._gridTexture,new Tiny.Rectangle(0,0,this._gridTexture.width,this._gridTexture.height),new Tiny.Rectangle(0,0,this._gridTexture.width,this._gridTexture.height),null,0);this._textures.push(e);var i=new Tiny.Sprite(e);i.visible=!1,this._gridSprites.push(i),this.addChild(i)}}}},{key:"resize",value:function(t,e){this._targetWidth=t,this._targetHeight=e,this._update(t,e)}},{key:"_update",value:function(){if(this._gridTexture){(this.width<this._gridTexture.width||this.height<this._gridTexture.height)&&console.warn("九宫格尺寸设置异常,尺寸不能小于素材尺寸");for(var t=this._scale9Grid,e=t[0],i=Math.max(0,t[2]),r=Math.max(0,this._gridTexture.width-e-i),n=t[1],u=Math.max(0,t[3]),s=Math.max(0,this._gridTexture.height-n-u),h=[e,i,r],o=[0,e,e+i],a=[n,u,s],d=[0,n,n+u],c=0;c<3;c++)for(var f=0;f<3;f++){var l=3*c+f,_=this._gridSprites[l],g=new Tiny.Rectangle(o[f],d[c],h[f],a[c]);if(g.width>0&&g.height>0){var p=0===f||2===f?h[f]:Math.max(0,this.width-h[0]-h[2]),x=0===c||2===c?a[c]:Math.max(0,this.height-a[0]-a[2]),y=0===f?0:1===f?h[0]:Math.max(0,this.width-h[2]),T=0===c?0:1===c?a[0]:Math.max(0,this.height-a[2]);p>0&&x>0?(this._textures[l].frame=g,_.anchor.set(0,0),_.x=y,_.y=T,_.alpha=this._debugDraw?.1+.05*l:1,_.width=p,_.height=x,_.visible=!0):_.visible=!1}else _.visible=!1}this.emit("resize")}}},{key:"debug",get:function(){return this._debugDraw},set:function(t){this._debugDraw=t,this._update()}},{key:"scale9Grid",get:function(){return this._scale9Grid},set:function(t){if(t){var e="string"==typeof t?t.split(","):t;if(4!==e.length)return void console.error("error scale9Grid format",t);e=e.map(function(t){return parseFloat(t)}),this._scale9Grid=e}else this._scale9Grid=[0,0,0,0];this._update()}},{key:"width",get:function(){return this._targetWidth||this._gridTexture.width},set:function(t){this._targetWidth=t,this._update()}},{key:"height",get:function(){return this._targetHeight||this._gridTexture.height},set:function(t){this._targetHeight=t,this._update()}}]),e}(Tiny.Sprite);e.default=s}])}); | ||
| !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.NinePatch=e():(t.Tiny=t.Tiny||{},t.Tiny.NinePatch=e())}(this,function(){return function(t){function e(r){if(i[r])return i[r].exports;var n=i[r]={exports:{},id:r,loaded:!1};return t[r].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var i={};return e.m=t,e.c=i,e.p="/Users/song/Develop/github/tinyjs-plugin-ninepatch/dist",e(0)}([function(t,e,i){t.exports=i(1)},function(t,e,i){"use strict";function r(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),e.Sprite=void 0;var n=i(2),u=r(n);e.Sprite=u.default},function(t,e){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function r(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}function n(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}Object.defineProperty(e,"__esModule",{value:!0});var u=function(){function t(t,e){for(var i=0;i<e.length;i++){var r=e[i];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}return function(e,i,r){return i&&t(e.prototype,i),r&&t(e,r),e}}(),a=function(t){function e(t,n,u,a){i(this,e);var h=r(this,(e.__proto__||Object.getPrototypeOf(e)).call(this));return h._gridTexture=t,h._debugDraw=!1,h._textures=[],h._gridSprites=[],h._targetWidth=n||0,h._targetHeight=u||0,h._textureOrigFrame=new Tiny.Rectangle(0,0,h._gridTexture.width,h._gridTexture.height),h._scale9Grid=null,h._inited=!1,h._init(),h.scale9Grid=a,h._gridTexture.baseTexture.hasLoaded?h._onGridTextureUpdate():h._gridTexture.once("update",h._onGridTextureUpdate,h),h}return n(e,t),u(e,[{key:"_onGridTextureUpdate",value:function(){this._update()}},{key:"_init",value:function(){if(!this._inited){this._inited=!0;for(var t=0;t<9;t++){var e=new Tiny.Texture(this._gridTexture,new Tiny.Rectangle(0,0,this._gridTexture.width,this._gridTexture.height),new Tiny.Rectangle(0,0,this._gridTexture.width,this._gridTexture.height),null,0);this._textures.push(e);var i=new Tiny.Sprite(e);i.visible=!1,this._gridSprites.push(i),this.addChild(i)}}}},{key:"resize",value:function(t,e){this._targetWidth=t,this._targetHeight=e,this._update(t,e)}},{key:"_update",value:function(){if(this._gridTexture){(this.width<this._gridTexture.width||this.height<this._gridTexture.height)&&console.warn("九宫格尺寸设置异常,尺寸不能小于素材尺寸");for(var t=Math.max(this.width,this._gridTexture.width),e=Math.max(this.height,this._gridTexture.height),i=this._scale9Grid,r=i[0],n=Math.max(0,i[2]),u=Math.max(0,this._gridTexture.width-r-n),a=i[1],h=Math.max(0,i[3]),s=Math.max(0,this._gridTexture.height-a-h),o=[r,n,u],d=[0,r,r+n],c=[a,h,s],f=[0,a,a+h],_=0;_<3;_++)for(var l=0;l<3;l++){var g=3*_+l,p=this._gridSprites[g],x=new Tiny.Rectangle(d[l],f[_],o[l],c[_]);if(x.width>0&&x.height>0){var y=0===l||2===l?o[l]:Math.max(0,t-o[0]-o[2]),T=0===_||2===_?c[_]:Math.max(0,e-c[0]-c[2]),b=0===l?0:1===l?o[0]:Math.max(0,t-o[2]),w=0===_?0:1===_?c[0]:Math.max(0,e-c[2]);y>0&&T>0?(this._textures[g].frame=x,p.anchor.set(0,0),p.x=b,p.y=w,p.alpha=this._debugDraw?.1+.05*g:1,p.width=y,p.height=T,p.visible=!0):p.visible=!1}else p.visible=!1}this.emit("resize")}}},{key:"debug",get:function(){return this._debugDraw},set:function(t){this._debugDraw=t,this._update()}},{key:"scale9Grid",get:function(){return this._scale9Grid},set:function(t){if(t){var e="string"==typeof t?t.split(","):t;if(4!==e.length)return void console.error("error scale9Grid format",t);e=e.map(function(t){return parseFloat(t)}),this._scale9Grid=e}else this._scale9Grid=[0,0,0,0];this._update()}},{key:"width",get:function(){return this._targetWidth||this._gridTexture.width},set:function(t){this._targetWidth=t,this._update()}},{key:"height",get:function(){return this._targetHeight||this._gridTexture.height},set:function(t){this._targetHeight=t,this._update()}}]),e}(Tiny.Sprite);e.default=a}])}); |
+1
-1
| { | ||
| "name": "tinyjs-plugin-ninepatch", | ||
| "version": "0.2.1", | ||
| "version": "0.2.2", | ||
| "author": "清扬陌客", | ||
@@ -5,0 +5,0 @@ "description": "Tinyjs 九宫格图", |
+5
-2
@@ -17,4 +17,4 @@ # tinyjs-plugin-ninepatch | ||
| - https://gw.alipayobjects.com/as/g/tiny-plugins/tinyjs-plugin-ninepatch/0.2.1/index.debug.js | ||
| - https://gw.alipayobjects.com/as/g/tiny-plugins/tinyjs-plugin-ninepatch/0.2.1/index.js | ||
| - https://gw.alipayobjects.com/as/g/tiny-plugins/tinyjs-plugin-ninepatch/0.2.2/index.debug.js | ||
| - https://gw.alipayobjects.com/as/g/tiny-plugins/tinyjs-plugin-ninepatch/0.2.2/index.js | ||
@@ -57,3 +57,6 @@ ## 起步 | ||
| ## 注意事项 | ||
| 1. **sprite的宽高不要小于九宫格图片的尺寸** | ||
| ## 依赖 | ||
@@ -60,0 +63,0 @@ - `Tiny.js`: [Link](http://tinyjs.net/#/docs/api) |
+7
-4
@@ -190,2 +190,5 @@ /** | ||
| const realWidth = Math.max(this.width, this._gridTexture.width); | ||
| const realHeight = Math.max(this.height, this._gridTexture.height); | ||
| const scale9Grid = this._scale9Grid; | ||
@@ -212,6 +215,6 @@ const w1 = scale9Grid[0]; | ||
| if (frame.width > 0 && frame.height > 0) { | ||
| const w = (col === 0 || col === 2) ? wArr[col] : Math.max(0, this.width - wArr[0] - wArr[2]); | ||
| const h = (row === 0 || row === 2) ? hArr[row] : Math.max(0, this.height - hArr[0] - hArr[2]); | ||
| const x = col === 0 ? 0 : col === 1 ? wArr[0] : Math.max(0, this.width - wArr[2]); | ||
| const y = row === 0 ? 0 : row === 1 ? hArr[0] : Math.max(0, this.height - hArr[2]); | ||
| const w = (col === 0 || col === 2) ? wArr[col] : Math.max(0, realWidth - wArr[0] - wArr[2]); | ||
| const h = (row === 0 || row === 2) ? hArr[row] : Math.max(0, realHeight - hArr[0] - hArr[2]); | ||
| const x = col === 0 ? 0 : col === 1 ? wArr[0] : Math.max(0, realWidth - wArr[2]); | ||
| const y = row === 0 ? 0 : row === 1 ? hArr[0] : Math.max(0, realHeight - hArr[2]); | ||
| if (w > 0 && h > 0) { | ||
@@ -218,0 +221,0 @@ this._textures[i].frame = frame; |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
1075906
0.41%19
11.76%28888
0.01%69
4.55%