Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pixi-multistyle-text

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pixi-multistyle-text - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

0

Gruntfile.js

@@ -0,0 +0,0 @@ module.exports = function(grunt) {

@@ -0,0 +0,0 @@ The MIT License (MIT)

9

package.json
{
"name": "pixi-multistyle-text",
"version": "0.2.2",
"version": "0.3.0",
"description": "Multi-Style Text for pixi.js",

@@ -31,6 +31,7 @@ "main": "pixi-multistyle-text.js",

"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-uglify": "^0.6.0"
"uglify-js": "^2.7.4"
},
"scripts": {
"build": "uglifyjs pixi-multistyle-text.js --compress --mangle --output pixi-multistyle-text.min.js"
}
}
/**
* @license
* pixi-multistyle-text - v0.2.0
* Copyright (c) 2014, Tommy Leunen <tommy.leunen@gmail.com> (http://tommyleunen.com/)
* Released under the MIT license
* See https://github.com/tleunen/pixi-multistyle-text for more details

@@ -83,13 +79,15 @@ */

for(var styleId in styles) {
if(styles.hasOwnProperty(styleId)) {
setDefaultTextStyle(styles[styleId]);
if(styles.hasOwnProperty(styleId) && typeof styles[styleId].fill == "number") {
// only change the fill if appropriate
styles[styleId].fill = PIXI.utils.hex2string(styles[styleId].fill);
}
}
// we need a `def` style
// we need a `def` style, which must contain all properties
if(!styles.def) {
styles.def = {};
setDefaultTextStyle(styles.def);
}
setDefaultTextStyle(styles.def);
this.textStyles = styles;

@@ -122,3 +120,3 @@ this.dirty = true;

var currentStyle = this.textStyles.def;
var styleStack = [Object.assign({}, this.textStyles.def)];

@@ -136,3 +134,3 @@ // determine the group of word for each line

if(!matches.length) {
lineTextData.push(createTextData(lines[i], currentStyle));
lineTextData.push(createTextData(lines[i], styleStack[styleStack.length - 1]));
}

@@ -149,10 +147,16 @@ else {

lines[i].substring(currentSearchIdx, matches[j].index),
currentStyle
styleStack[styleStack.length - 1]
));
}
// reset the style if end of tag
if(matches[j][0][1] == '/') currentStyle = this.textStyles.def;
// set the current style
else currentStyle = this.textStyles[matches[j][1]] || this.textStyles.def;
if (matches[j][0][1] == "/") {
// pop back to the last style, if appropriate
// note that we don't actually check which tag is closed
if (styleStack.length > 0) {
styleStack.pop();
}
} else {
// push a new style, updating the top of the stack to reflect changes only
styleStack.push(Object.assign({}, styleStack[styleStack.length - 1], this.textStyles[matches[j][1]]));
}

@@ -167,3 +171,3 @@ // update the current search index

text: lines[i].substring(currentSearchIdx),
style: currentStyle
style: styleStack[styleStack.length - 1]
});

@@ -237,3 +241,3 @@ }

var maxStrokeThickness = stylesArray.reduce(function(prev, curr) {
return Math.max(prev, curr.strokeThickness);
return Math.max(prev, curr.strokeThickness || 0);
}, 0);

@@ -336,2 +340,2 @@ var maxDropShadowDistance = stylesArray.reduce(function(prev, curr) {

}).call(this);
}).call(this);

@@ -1,8 +0,1 @@

/**
* @license
* pixi-multistyle-text - v0.2.0
* Copyright (c) 2014, Tommy Leunen <tommy.leunen@gmail.com> (http://tommyleunen.com/)
* Released under the MIT license
* See https://github.com/tleunen/pixi-multistyle-text for more details
*/
(function(){function a(a){a=a||{},a.font=a.font||"bold 20pt Arial",a.fill=a.fill||"black",a.stroke=a.stroke||"black",a.strokeThickness=a.strokeThickness||0,a.dropShadow=a.dropShadow||!1,a.dropShadowAngle=a.dropShadowAngle||Math.PI/6,a.dropShadowDistance=a.dropShadowDistance||4,a.dropShadowColor=a.dropShadowColor||"black"}function b(a,b){return{text:a,style:b,width:0,height:0,fontProperties:null}}var c=this,d=c.PIXI;if(d){var e=function(a,b,c){d.Text.call(this,a,c),this.setTextStyles(b)};e.prototype=Object.create(d.Text.prototype),e.prototype.constructor=e,e.prototype.setAlignmentStyle=e.prototype.setStyle=function(a){a=a||{},a.align=a.align||"left",a.wordWrap=a.wordWrap||!1,a.wordWrapWidth=a.wordWrapWidth||100,this.style=a,this.dirty=!0},e.prototype.setTextStyles=function(b){for(var c in b)b.hasOwnProperty(c)&&a(b[c]);b.def||(b.def={},a(b.def)),this.textStyles=b,this.dirty=!0},e.prototype._getTextDataPerLine=function(a){for(var c=[],d=Object.keys(this.textStyles).join("|"),e=new RegExp("</?("+d+")>","g"),f=this.textStyles.def,g=0;g<a.length;g++){for(var h,i=[],j=[];null!==(h=e.exec(a[g]))&&j.push(h););if(j.length){for(var k=0,l=0;l<j.length;l++)j[l].index>k&&i.push(b(a[g].substring(k,j[l].index),f)),f="/"==j[l][0][1]?this.textStyles.def:this.textStyles[j[l][1]]||this.textStyles.def,k=j[l].index+j[l][0].length;k<a[g].length&&i.push({text:a[g].substring(k),style:this.textStyles.def})}else i.push(b(a[g],f));c.push(i)}return c},e.prototype.updateText=function(){this.texture.baseTexture.resolution=this.resolution;var a,b,c=this.text,d=this.textStyles;this.style.wordWrap&&(c=this.wordWrap(this.text));var e=c.split(/(?:\r\n|\r|\n)/),f=this._getTextDataPerLine(e),g=[],h=[],i=0;for(a=0;a<e.length;a++){var j=0,k=0;for(b=0;b<f[a].length;b++)this.context.font=f[a][b].style.font,f[a][b].width=this.context.measureText(f[a][b].text).width,j+=f[a][b].width,f[a][b].fontProperties=this.determineFontProperties(f[a][b].style.font),f[a][b].height=f[a][b].fontProperties.fontSize+f[a][b].style.strokeThickness,k=Math.max(k,f[a][b].height);g[a]=j,h[a]=k,i=Math.max(i,j)}var l=Object.keys(d).map(function(a){return d[a]}),m=l.reduce(function(a,b){return Math.max(a,b.strokeThickness)},0),n=l.reduce(function(a,b){var c=b.dropShadow?b.dropShadowDistance:0;return Math.max(a,c)},0),o=i+m+n,p=Math.max.apply(null,h)*e.length+n;this.canvas.width=(o+this.context.lineWidth)*this.resolution,this.canvas.height=p*this.resolution,this.context.scale(this.resolution,this.resolution),navigator.isCocoonJS&&this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.context.textBaseline="alphabetic",this.context.lineJoin="round";var q,r;for(a=0;a<f.length;a++){var s=f[a];for(q=0,b=0;b<s.length;b++){var t=s[b].style,u=s[b].text,v=s[b].fontProperties;if(this.context.font=t.font,this.context.strokeStyle=t.stroke,this.context.lineWidth=t.strokeThickness,q+=m/2,r=m/2+a*h[a]+v.ascent,"right"===this.style.align?q+=i-g[a]:"center"===this.style.align&&(q+=(i-g[a])/2),"bottom"===t.valign?r+=h[a]-s[b].height-(m-t.strokeThickness)/2:"middle"===t.valign&&(r+=(h[a]-s[b].height)/2-(m-t.strokeThickness)/2),t.dropShadow){this.context.fillStyle=t.dropShadowColor;var w=Math.sin(t.dropShadowAngle)*t.dropShadowDistance,x=Math.cos(t.dropShadowAngle)*t.dropShadowDistance;t.fill&&this.context.fillText(u,q+w,r+x)}this.context.fillStyle=t.fill,t.stroke&&t.strokeThickness&&this.context.strokeText(u,q,r),t.fill&&this.context.fillText(u,q,r),q+=s[b].width,q-=m/2}}this.updateTexture()},d.MultiStyleText=e}}).call(this);
(function(){function t(t){t=t||{},t.font=t.font||"bold 20pt Arial",t.fill=t.fill||"black",t.stroke=t.stroke||"black",t.strokeThickness=t.strokeThickness||0,t.dropShadow=t.dropShadow||!1,t.dropShadowAngle=t.dropShadowAngle||Math.PI/6,t.dropShadowDistance=t.dropShadowDistance||4,t.dropShadowColor=t.dropShadowColor||"black"}function e(t,e){return{text:t,style:e,width:0,height:0,fontProperties:null}}var o=this,i=o.PIXI;if(i){var s=function(t,e,o){i.Text.call(this,t,o),this.setTextStyles(e)};s.prototype=Object.create(i.Text.prototype),s.prototype.constructor=s,s.prototype.setAlignmentStyle=s.prototype.setStyle=function(t){t=t||{},t.align=t.align||"left",t.wordWrap=t.wordWrap||!1,t.wordWrapWidth=t.wordWrapWidth||100,this.style=t,this.dirty=!0},s.prototype.setTextStyles=function(e){for(var o in e)e.hasOwnProperty(o)&&"number"==typeof e[o].fill&&(e[o].fill=i.utils.hex2string(e[o].fill));e.def||(e.def={}),t(e.def),this.textStyles=e,this.dirty=!0},s.prototype._getTextDataPerLine=function(t){for(var o=[],i=Object.keys(this.textStyles).join("|"),s=new RegExp("</?("+i+")>","g"),n=[Object.assign({},this.textStyles.def)],r=0;r<t.length;r++){for(var h,l=[],a=[];null!==(h=s.exec(t[r]))&&a.push(h););if(a.length){for(var c=0,d=0;d<a.length;d++)a[d].index>c&&l.push(e(t[r].substring(c,a[d].index),n[n.length-1])),"/"==a[d][0][1]?n.length>0&&n.pop():n.push(Object.assign({},n[n.length-1],this.textStyles[a[d][1]])),c=a[d].index+a[d][0].length;c<t[r].length&&l.push({text:t[r].substring(c),style:n[n.length-1]})}else l.push(e(t[r],n[n.length-1]));o.push(l)}return o},s.prototype.updateText=function(){this.texture.baseTexture.resolution=this.resolution;var t,e,o=this.text,i=this.textStyles;this.style.wordWrap&&(o=this.wordWrap(this.text));var s=o.split(/(?:\r\n|\r|\n)/),n=this._getTextDataPerLine(s),r=[],h=[],l=0;for(t=0;t<s.length;t++){var a=0,c=0;for(e=0;e<n[t].length;e++)this.context.font=n[t][e].style.font,n[t][e].width=this.context.measureText(n[t][e].text).width,a+=n[t][e].width,n[t][e].fontProperties=this.determineFontProperties(n[t][e].style.font),n[t][e].height=n[t][e].fontProperties.fontSize+n[t][e].style.strokeThickness,c=Math.max(c,n[t][e].height);r[t]=a,h[t]=c,l=Math.max(l,a)}var d=Object.keys(i).map(function(t){return i[t]}),p=d.reduce(function(t,e){return Math.max(t,e.strokeThickness||0)},0),x=d.reduce(function(t,e){var o=e.dropShadow?e.dropShadowDistance:0;return Math.max(t,o)},0),f=l+p+x,u=Math.max.apply(null,h)*s.length+x;this.canvas.width=(f+this.context.lineWidth)*this.resolution,this.canvas.height=u*this.resolution,this.context.scale(this.resolution,this.resolution),navigator.isCocoonJS&&this.context.clearRect(0,0,this.canvas.width,this.canvas.height),this.context.textBaseline="alphabetic",this.context.lineJoin="round";var g,y;for(t=0;t<n.length;t++){var w=n[t];for(g=0,e=0;e<w.length;e++){var S=w[e].style,k=w[e].text,v=w[e].fontProperties;if(this.context.font=S.font,this.context.strokeStyle=S.stroke,this.context.lineWidth=S.strokeThickness,g+=p/2,y=p/2+t*h[t]+v.ascent,"right"===this.style.align?g+=l-r[t]:"center"===this.style.align&&0===g&&(g+=(l-r[t])/2),"bottom"===S.valign?y+=h[t]-w[e].height-(p-S.strokeThickness)/2:"middle"===S.valign&&(y+=(h[t]-w[e].height)/2-(p-S.strokeThickness)/2),S.dropShadow){this.context.fillStyle=S.dropShadowColor;var T=Math.sin(S.dropShadowAngle)*S.dropShadowDistance,b=Math.cos(S.dropShadowAngle)*S.dropShadowDistance;S.fill&&this.context.fillText(k,g+T,y+b)}this.context.fillStyle=S.fill,S.stroke&&S.strokeThickness&&this.context.strokeText(k,g,y),S.fill&&this.context.fillText(k,g,y),g+=w[e].width,g-=p/2}}this.updateTexture()},i.MultiStyleText=s}}).call(this);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc